Initial pass at Go language support.
[deliverable/binutils-gdb.git] / gdb / dwarf2read.c
1 /* DWARF 2 debugging format support for GDB.
2
3 Copyright (C) 1994-2012 Free Software Foundation, Inc.
4
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
10 support.
11
12 This file is part of GDB.
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
30
31 #include "defs.h"
32 #include "bfd.h"
33 #include "symtab.h"
34 #include "gdbtypes.h"
35 #include "objfiles.h"
36 #include "dwarf2.h"
37 #include "buildsym.h"
38 #include "demangle.h"
39 #include "gdb-demangle.h"
40 #include "expression.h"
41 #include "filenames.h" /* for DOSish file names */
42 #include "macrotab.h"
43 #include "language.h"
44 #include "complaints.h"
45 #include "bcache.h"
46 #include "dwarf2expr.h"
47 #include "dwarf2loc.h"
48 #include "cp-support.h"
49 #include "hashtab.h"
50 #include "command.h"
51 #include "gdbcmd.h"
52 #include "block.h"
53 #include "addrmap.h"
54 #include "typeprint.h"
55 #include "jv-lang.h"
56 #include "psympriv.h"
57 #include "exceptions.h"
58 #include "gdb_stat.h"
59 #include "completer.h"
60 #include "vec.h"
61 #include "c-lang.h"
62 #include "go-lang.h"
63 #include "valprint.h"
64 #include <ctype.h>
65
66 #include <fcntl.h>
67 #include "gdb_string.h"
68 #include "gdb_assert.h"
69 #include <sys/types.h>
70 #ifdef HAVE_ZLIB_H
71 #include <zlib.h>
72 #endif
73 #ifdef HAVE_MMAP
74 #include <sys/mman.h>
75 #ifndef MAP_FAILED
76 #define MAP_FAILED ((void *) -1)
77 #endif
78 #endif
79
80 typedef struct symbol *symbolp;
81 DEF_VEC_P (symbolp);
82
83 /* When non-zero, dump DIEs after they are read in. */
84 static int dwarf2_die_debug = 0;
85
86 /* When non-zero, cross-check physname against demangler. */
87 static int check_physname = 0;
88
89 /* When non-zero, do not reject deprecated .gdb_index sections. */
90 int use_deprecated_index_sections = 0;
91
92 static int pagesize;
93
94 /* When set, the file that we're processing is known to have debugging
95 info for C++ namespaces. GCC 3.3.x did not produce this information,
96 but later versions do. */
97
98 static int processing_has_namespace_info;
99
100 static const struct objfile_data *dwarf2_objfile_data_key;
101
102 struct dwarf2_section_info
103 {
104 asection *asection;
105 gdb_byte *buffer;
106 bfd_size_type size;
107 /* Not NULL if the section was actually mmapped. */
108 void *map_addr;
109 /* Page aligned size of mmapped area. */
110 bfd_size_type map_len;
111 /* True if we have tried to read this section. */
112 int readin;
113 };
114
115 typedef struct dwarf2_section_info dwarf2_section_info_def;
116 DEF_VEC_O (dwarf2_section_info_def);
117
118 /* All offsets in the index are of this type. It must be
119 architecture-independent. */
120 typedef uint32_t offset_type;
121
122 DEF_VEC_I (offset_type);
123
124 /* A description of the mapped index. The file format is described in
125 a comment by the code that writes the index. */
126 struct mapped_index
127 {
128 /* Index data format version. */
129 int version;
130
131 /* The total length of the buffer. */
132 off_t total_size;
133
134 /* A pointer to the address table data. */
135 const gdb_byte *address_table;
136
137 /* Size of the address table data in bytes. */
138 offset_type address_table_size;
139
140 /* The symbol table, implemented as a hash table. */
141 const offset_type *symbol_table;
142
143 /* Size in slots, each slot is 2 offset_types. */
144 offset_type symbol_table_slots;
145
146 /* A pointer to the constant pool. */
147 const char *constant_pool;
148 };
149
150 /* Collection of data recorded per objfile.
151 This hangs off of dwarf2_objfile_data_key. */
152
153 struct dwarf2_per_objfile
154 {
155 struct dwarf2_section_info info;
156 struct dwarf2_section_info abbrev;
157 struct dwarf2_section_info line;
158 struct dwarf2_section_info loc;
159 struct dwarf2_section_info macinfo;
160 struct dwarf2_section_info macro;
161 struct dwarf2_section_info str;
162 struct dwarf2_section_info ranges;
163 struct dwarf2_section_info frame;
164 struct dwarf2_section_info eh_frame;
165 struct dwarf2_section_info gdb_index;
166
167 VEC (dwarf2_section_info_def) *types;
168
169 /* Back link. */
170 struct objfile *objfile;
171
172 /* Table of all the compilation units. This is used to locate
173 the target compilation unit of a particular reference. */
174 struct dwarf2_per_cu_data **all_comp_units;
175
176 /* The number of compilation units in ALL_COMP_UNITS. */
177 int n_comp_units;
178
179 /* The number of .debug_types-related CUs. */
180 int n_type_units;
181
182 /* The .debug_types-related CUs (TUs). */
183 struct dwarf2_per_cu_data **all_type_units;
184
185 /* A chain of compilation units that are currently read in, so that
186 they can be freed later. */
187 struct dwarf2_per_cu_data *read_in_chain;
188
189 /* A table mapping .debug_types signatures to its signatured_type entry.
190 This is NULL if the .debug_types section hasn't been read in yet. */
191 htab_t signatured_types;
192
193 /* A flag indicating wether this objfile has a section loaded at a
194 VMA of 0. */
195 int has_section_at_zero;
196
197 /* True if we are using the mapped index,
198 or we are faking it for OBJF_READNOW's sake. */
199 unsigned char using_index;
200
201 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
202 struct mapped_index *index_table;
203
204 /* When using index_table, this keeps track of all quick_file_names entries.
205 TUs can share line table entries with CUs or other TUs, and there can be
206 a lot more TUs than unique line tables, so we maintain a separate table
207 of all line table entries to support the sharing. */
208 htab_t quick_file_names_table;
209
210 /* Set during partial symbol reading, to prevent queueing of full
211 symbols. */
212 int reading_partial_symbols;
213
214 /* Table mapping type .debug_info DIE offsets to types.
215 This is NULL if not allocated yet.
216 It (currently) makes sense to allocate debug_types_type_hash lazily.
217 To keep things simple we allocate both lazily. */
218 htab_t debug_info_type_hash;
219
220 /* Table mapping type .debug_types DIE sect_offset to types.
221 This is NULL if not allocated yet. */
222 htab_t debug_types_type_hash;
223 };
224
225 static struct dwarf2_per_objfile *dwarf2_per_objfile;
226
227 /* Default names of the debugging sections. */
228
229 /* Note that if the debugging section has been compressed, it might
230 have a name like .zdebug_info. */
231
232 static const struct dwarf2_debug_sections dwarf2_elf_names =
233 {
234 { ".debug_info", ".zdebug_info" },
235 { ".debug_abbrev", ".zdebug_abbrev" },
236 { ".debug_line", ".zdebug_line" },
237 { ".debug_loc", ".zdebug_loc" },
238 { ".debug_macinfo", ".zdebug_macinfo" },
239 { ".debug_macro", ".zdebug_macro" },
240 { ".debug_str", ".zdebug_str" },
241 { ".debug_ranges", ".zdebug_ranges" },
242 { ".debug_types", ".zdebug_types" },
243 { ".debug_frame", ".zdebug_frame" },
244 { ".eh_frame", NULL },
245 { ".gdb_index", ".zgdb_index" },
246 23
247 };
248
249 /* local data types */
250
251 /* We hold several abbreviation tables in memory at the same time. */
252 #ifndef ABBREV_HASH_SIZE
253 #define ABBREV_HASH_SIZE 121
254 #endif
255
256 /* The data in a compilation unit header, after target2host
257 translation, looks like this. */
258 struct comp_unit_head
259 {
260 unsigned int length;
261 short version;
262 unsigned char addr_size;
263 unsigned char signed_addr_p;
264 sect_offset abbrev_offset;
265
266 /* Size of file offsets; either 4 or 8. */
267 unsigned int offset_size;
268
269 /* Size of the length field; either 4 or 12. */
270 unsigned int initial_length_size;
271
272 /* Offset to the first byte of this compilation unit header in the
273 .debug_info section, for resolving relative reference dies. */
274 sect_offset offset;
275
276 /* Offset to first die in this cu from the start of the cu.
277 This will be the first byte following the compilation unit header. */
278 cu_offset first_die_offset;
279 };
280
281 /* Type used for delaying computation of method physnames.
282 See comments for compute_delayed_physnames. */
283 struct delayed_method_info
284 {
285 /* The type to which the method is attached, i.e., its parent class. */
286 struct type *type;
287
288 /* The index of the method in the type's function fieldlists. */
289 int fnfield_index;
290
291 /* The index of the method in the fieldlist. */
292 int index;
293
294 /* The name of the DIE. */
295 const char *name;
296
297 /* The DIE associated with this method. */
298 struct die_info *die;
299 };
300
301 typedef struct delayed_method_info delayed_method_info;
302 DEF_VEC_O (delayed_method_info);
303
304 /* Internal state when decoding a particular compilation unit. */
305 struct dwarf2_cu
306 {
307 /* The objfile containing this compilation unit. */
308 struct objfile *objfile;
309
310 /* The header of the compilation unit. */
311 struct comp_unit_head header;
312
313 /* Base address of this compilation unit. */
314 CORE_ADDR base_address;
315
316 /* Non-zero if base_address has been set. */
317 int base_known;
318
319 /* The language we are debugging. */
320 enum language language;
321 const struct language_defn *language_defn;
322
323 const char *producer;
324
325 /* The generic symbol table building routines have separate lists for
326 file scope symbols and all all other scopes (local scopes). So
327 we need to select the right one to pass to add_symbol_to_list().
328 We do it by keeping a pointer to the correct list in list_in_scope.
329
330 FIXME: The original dwarf code just treated the file scope as the
331 first local scope, and all other local scopes as nested local
332 scopes, and worked fine. Check to see if we really need to
333 distinguish these in buildsym.c. */
334 struct pending **list_in_scope;
335
336 /* DWARF abbreviation table associated with this compilation unit. */
337 struct abbrev_info **dwarf2_abbrevs;
338
339 /* Storage for the abbrev table. */
340 struct obstack abbrev_obstack;
341
342 /* Hash table holding all the loaded partial DIEs
343 with partial_die->offset.SECT_OFF as hash. */
344 htab_t partial_dies;
345
346 /* Storage for things with the same lifetime as this read-in compilation
347 unit, including partial DIEs. */
348 struct obstack comp_unit_obstack;
349
350 /* When multiple dwarf2_cu structures are living in memory, this field
351 chains them all together, so that they can be released efficiently.
352 We will probably also want a generation counter so that most-recently-used
353 compilation units are cached... */
354 struct dwarf2_per_cu_data *read_in_chain;
355
356 /* Backchain to our per_cu entry if the tree has been built. */
357 struct dwarf2_per_cu_data *per_cu;
358
359 /* How many compilation units ago was this CU last referenced? */
360 int last_used;
361
362 /* A hash table of DIE cu_offset for following references with
363 die_info->offset.sect_off as hash. */
364 htab_t die_hash;
365
366 /* Full DIEs if read in. */
367 struct die_info *dies;
368
369 /* A set of pointers to dwarf2_per_cu_data objects for compilation
370 units referenced by this one. Only set during full symbol processing;
371 partial symbol tables do not have dependencies. */
372 htab_t dependencies;
373
374 /* Header data from the line table, during full symbol processing. */
375 struct line_header *line_header;
376
377 /* A list of methods which need to have physnames computed
378 after all type information has been read. */
379 VEC (delayed_method_info) *method_list;
380
381 /* To be copied to symtab->call_site_htab. */
382 htab_t call_site_htab;
383
384 /* Mark used when releasing cached dies. */
385 unsigned int mark : 1;
386
387 /* This CU references .debug_loc. See the symtab->locations_valid field.
388 This test is imperfect as there may exist optimized debug code not using
389 any location list and still facing inlining issues if handled as
390 unoptimized code. For a future better test see GCC PR other/32998. */
391 unsigned int has_loclist : 1;
392
393 /* These cache the results of producer_is_gxx_lt_4_6.
394 CHECKED_PRODUCER is set if PRODUCER_IS_GXX_LT_4_6 is valid. This
395 information is cached because profiling CU expansion showed
396 excessive time spent in producer_is_gxx_lt_4_6. */
397 unsigned int checked_producer : 1;
398 unsigned int producer_is_gxx_lt_4_6 : 1;
399 };
400
401 /* Persistent data held for a compilation unit, even when not
402 processing it. We put a pointer to this structure in the
403 read_symtab_private field of the psymtab. */
404
405 struct dwarf2_per_cu_data
406 {
407 /* The start offset and length of this compilation unit. 2**29-1
408 bytes should suffice to store the length of any compilation unit
409 - if it doesn't, GDB will fall over anyway.
410 NOTE: Unlike comp_unit_head.length, this length includes
411 initial_length_size. */
412 sect_offset offset;
413 unsigned int length : 29;
414
415 /* Flag indicating this compilation unit will be read in before
416 any of the current compilation units are processed. */
417 unsigned int queued : 1;
418
419 /* This flag will be set when reading partial DIEs if we need to load
420 absolutely all DIEs for this compilation unit, instead of just the ones
421 we think are interesting. It gets set if we look for a DIE in the
422 hash table and don't find it. */
423 unsigned int load_all_dies : 1;
424
425 /* Non-null if this CU is from .debug_types; in which case it points
426 to the section. Otherwise it's from .debug_info. */
427 struct dwarf2_section_info *debug_types_section;
428
429 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
430 of the CU cache it gets reset to NULL again. */
431 struct dwarf2_cu *cu;
432
433 /* The corresponding objfile.
434 Normally we can get the objfile from dwarf2_per_objfile.
435 However we can enter this file with just a "per_cu" handle. */
436 struct objfile *objfile;
437
438 /* When using partial symbol tables, the 'psymtab' field is active.
439 Otherwise the 'quick' field is active. */
440 union
441 {
442 /* The partial symbol table associated with this compilation unit,
443 or NULL for partial units (which do not have an associated
444 symtab). */
445 struct partial_symtab *psymtab;
446
447 /* Data needed by the "quick" functions. */
448 struct dwarf2_per_cu_quick_data *quick;
449 } v;
450 };
451
452 /* Entry in the signatured_types hash table. */
453
454 struct signatured_type
455 {
456 ULONGEST signature;
457
458 /* Offset in this TU of the type defined by this TU. */
459 cu_offset type_offset;
460
461 /* The CU(/TU) of this type. */
462 struct dwarf2_per_cu_data per_cu;
463 };
464
465 /* Struct used to pass misc. parameters to read_die_and_children, et
466 al. which are used for both .debug_info and .debug_types dies.
467 All parameters here are unchanging for the life of the call. This
468 struct exists to abstract away the constant parameters of die
469 reading. */
470
471 struct die_reader_specs
472 {
473 /* The bfd of this objfile. */
474 bfd* abfd;
475
476 /* The CU of the DIE we are parsing. */
477 struct dwarf2_cu *cu;
478
479 /* Pointer to start of section buffer.
480 This is either the start of .debug_info or .debug_types. */
481 const gdb_byte *buffer;
482 };
483
484 /* The line number information for a compilation unit (found in the
485 .debug_line section) begins with a "statement program header",
486 which contains the following information. */
487 struct line_header
488 {
489 unsigned int total_length;
490 unsigned short version;
491 unsigned int header_length;
492 unsigned char minimum_instruction_length;
493 unsigned char maximum_ops_per_instruction;
494 unsigned char default_is_stmt;
495 int line_base;
496 unsigned char line_range;
497 unsigned char opcode_base;
498
499 /* standard_opcode_lengths[i] is the number of operands for the
500 standard opcode whose value is i. This means that
501 standard_opcode_lengths[0] is unused, and the last meaningful
502 element is standard_opcode_lengths[opcode_base - 1]. */
503 unsigned char *standard_opcode_lengths;
504
505 /* The include_directories table. NOTE! These strings are not
506 allocated with xmalloc; instead, they are pointers into
507 debug_line_buffer. If you try to free them, `free' will get
508 indigestion. */
509 unsigned int num_include_dirs, include_dirs_size;
510 char **include_dirs;
511
512 /* The file_names table. NOTE! These strings are not allocated
513 with xmalloc; instead, they are pointers into debug_line_buffer.
514 Don't try to free them directly. */
515 unsigned int num_file_names, file_names_size;
516 struct file_entry
517 {
518 char *name;
519 unsigned int dir_index;
520 unsigned int mod_time;
521 unsigned int length;
522 int included_p; /* Non-zero if referenced by the Line Number Program. */
523 struct symtab *symtab; /* The associated symbol table, if any. */
524 } *file_names;
525
526 /* The start and end of the statement program following this
527 header. These point into dwarf2_per_objfile->line_buffer. */
528 gdb_byte *statement_program_start, *statement_program_end;
529 };
530
531 /* When we construct a partial symbol table entry we only
532 need this much information. */
533 struct partial_die_info
534 {
535 /* Offset of this DIE. */
536 sect_offset offset;
537
538 /* DWARF-2 tag for this DIE. */
539 ENUM_BITFIELD(dwarf_tag) tag : 16;
540
541 /* Assorted flags describing the data found in this DIE. */
542 unsigned int has_children : 1;
543 unsigned int is_external : 1;
544 unsigned int is_declaration : 1;
545 unsigned int has_type : 1;
546 unsigned int has_specification : 1;
547 unsigned int has_pc_info : 1;
548 unsigned int may_be_inlined : 1;
549
550 /* Flag set if the SCOPE field of this structure has been
551 computed. */
552 unsigned int scope_set : 1;
553
554 /* Flag set if the DIE has a byte_size attribute. */
555 unsigned int has_byte_size : 1;
556
557 /* Flag set if any of the DIE's children are template arguments. */
558 unsigned int has_template_arguments : 1;
559
560 /* Flag set if fixup_partial_die has been called on this die. */
561 unsigned int fixup_called : 1;
562
563 /* The name of this DIE. Normally the value of DW_AT_name, but
564 sometimes a default name for unnamed DIEs. */
565 char *name;
566
567 /* The linkage name, if present. */
568 const char *linkage_name;
569
570 /* The scope to prepend to our children. This is generally
571 allocated on the comp_unit_obstack, so will disappear
572 when this compilation unit leaves the cache. */
573 char *scope;
574
575 /* The location description associated with this DIE, if any. */
576 struct dwarf_block *locdesc;
577
578 /* If HAS_PC_INFO, the PC range associated with this DIE. */
579 CORE_ADDR lowpc;
580 CORE_ADDR highpc;
581
582 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
583 DW_AT_sibling, if any. */
584 /* NOTE: This member isn't strictly necessary, read_partial_die could
585 return DW_AT_sibling values to its caller load_partial_dies. */
586 gdb_byte *sibling;
587
588 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
589 DW_AT_specification (or DW_AT_abstract_origin or
590 DW_AT_extension). */
591 sect_offset spec_offset;
592
593 /* Pointers to this DIE's parent, first child, and next sibling,
594 if any. */
595 struct partial_die_info *die_parent, *die_child, *die_sibling;
596 };
597
598 /* This data structure holds the information of an abbrev. */
599 struct abbrev_info
600 {
601 unsigned int number; /* number identifying abbrev */
602 enum dwarf_tag tag; /* dwarf tag */
603 unsigned short has_children; /* boolean */
604 unsigned short num_attrs; /* number of attributes */
605 struct attr_abbrev *attrs; /* an array of attribute descriptions */
606 struct abbrev_info *next; /* next in chain */
607 };
608
609 struct attr_abbrev
610 {
611 ENUM_BITFIELD(dwarf_attribute) name : 16;
612 ENUM_BITFIELD(dwarf_form) form : 16;
613 };
614
615 /* Attributes have a name and a value. */
616 struct attribute
617 {
618 ENUM_BITFIELD(dwarf_attribute) name : 16;
619 ENUM_BITFIELD(dwarf_form) form : 15;
620
621 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
622 field should be in u.str (existing only for DW_STRING) but it is kept
623 here for better struct attribute alignment. */
624 unsigned int string_is_canonical : 1;
625
626 union
627 {
628 char *str;
629 struct dwarf_block *blk;
630 ULONGEST unsnd;
631 LONGEST snd;
632 CORE_ADDR addr;
633 struct signatured_type *signatured_type;
634 }
635 u;
636 };
637
638 /* This data structure holds a complete die structure. */
639 struct die_info
640 {
641 /* DWARF-2 tag for this DIE. */
642 ENUM_BITFIELD(dwarf_tag) tag : 16;
643
644 /* Number of attributes */
645 unsigned char num_attrs;
646
647 /* True if we're presently building the full type name for the
648 type derived from this DIE. */
649 unsigned char building_fullname : 1;
650
651 /* Abbrev number */
652 unsigned int abbrev;
653
654 /* Offset in .debug_info or .debug_types section. */
655 sect_offset offset;
656
657 /* The dies in a compilation unit form an n-ary tree. PARENT
658 points to this die's parent; CHILD points to the first child of
659 this node; and all the children of a given node are chained
660 together via their SIBLING fields. */
661 struct die_info *child; /* Its first child, if any. */
662 struct die_info *sibling; /* Its next sibling, if any. */
663 struct die_info *parent; /* Its parent, if any. */
664
665 /* An array of attributes, with NUM_ATTRS elements. There may be
666 zero, but it's not common and zero-sized arrays are not
667 sufficiently portable C. */
668 struct attribute attrs[1];
669 };
670
671 /* Get at parts of an attribute structure. */
672
673 #define DW_STRING(attr) ((attr)->u.str)
674 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
675 #define DW_UNSND(attr) ((attr)->u.unsnd)
676 #define DW_BLOCK(attr) ((attr)->u.blk)
677 #define DW_SND(attr) ((attr)->u.snd)
678 #define DW_ADDR(attr) ((attr)->u.addr)
679 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
680
681 /* Blocks are a bunch of untyped bytes. */
682 struct dwarf_block
683 {
684 unsigned int size;
685
686 /* Valid only if SIZE is not zero. */
687 gdb_byte *data;
688 };
689
690 #ifndef ATTR_ALLOC_CHUNK
691 #define ATTR_ALLOC_CHUNK 4
692 #endif
693
694 /* Allocate fields for structs, unions and enums in this size. */
695 #ifndef DW_FIELD_ALLOC_CHUNK
696 #define DW_FIELD_ALLOC_CHUNK 4
697 #endif
698
699 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
700 but this would require a corresponding change in unpack_field_as_long
701 and friends. */
702 static int bits_per_byte = 8;
703
704 /* The routines that read and process dies for a C struct or C++ class
705 pass lists of data member fields and lists of member function fields
706 in an instance of a field_info structure, as defined below. */
707 struct field_info
708 {
709 /* List of data member and baseclasses fields. */
710 struct nextfield
711 {
712 struct nextfield *next;
713 int accessibility;
714 int virtuality;
715 struct field field;
716 }
717 *fields, *baseclasses;
718
719 /* Number of fields (including baseclasses). */
720 int nfields;
721
722 /* Number of baseclasses. */
723 int nbaseclasses;
724
725 /* Set if the accesibility of one of the fields is not public. */
726 int non_public_fields;
727
728 /* Member function fields array, entries are allocated in the order they
729 are encountered in the object file. */
730 struct nextfnfield
731 {
732 struct nextfnfield *next;
733 struct fn_field fnfield;
734 }
735 *fnfields;
736
737 /* Member function fieldlist array, contains name of possibly overloaded
738 member function, number of overloaded member functions and a pointer
739 to the head of the member function field chain. */
740 struct fnfieldlist
741 {
742 char *name;
743 int length;
744 struct nextfnfield *head;
745 }
746 *fnfieldlists;
747
748 /* Number of entries in the fnfieldlists array. */
749 int nfnfields;
750
751 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
752 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
753 struct typedef_field_list
754 {
755 struct typedef_field field;
756 struct typedef_field_list *next;
757 }
758 *typedef_field_list;
759 unsigned typedef_field_list_count;
760 };
761
762 /* One item on the queue of compilation units to read in full symbols
763 for. */
764 struct dwarf2_queue_item
765 {
766 struct dwarf2_per_cu_data *per_cu;
767 struct dwarf2_queue_item *next;
768 };
769
770 /* The current queue. */
771 static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail;
772
773 /* Loaded secondary compilation units are kept in memory until they
774 have not been referenced for the processing of this many
775 compilation units. Set this to zero to disable caching. Cache
776 sizes of up to at least twenty will improve startup time for
777 typical inter-CU-reference binaries, at an obvious memory cost. */
778 static int dwarf2_max_cache_age = 5;
779 static void
780 show_dwarf2_max_cache_age (struct ui_file *file, int from_tty,
781 struct cmd_list_element *c, const char *value)
782 {
783 fprintf_filtered (file, _("The upper bound on the age of cached "
784 "dwarf2 compilation units is %s.\n"),
785 value);
786 }
787
788
789 /* Various complaints about symbol reading that don't abort the process. */
790
791 static void
792 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
793 {
794 complaint (&symfile_complaints,
795 _("statement list doesn't fit in .debug_line section"));
796 }
797
798 static void
799 dwarf2_debug_line_missing_file_complaint (void)
800 {
801 complaint (&symfile_complaints,
802 _(".debug_line section has line data without a file"));
803 }
804
805 static void
806 dwarf2_debug_line_missing_end_sequence_complaint (void)
807 {
808 complaint (&symfile_complaints,
809 _(".debug_line section has line "
810 "program sequence without an end"));
811 }
812
813 static void
814 dwarf2_complex_location_expr_complaint (void)
815 {
816 complaint (&symfile_complaints, _("location expression too complex"));
817 }
818
819 static void
820 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
821 int arg3)
822 {
823 complaint (&symfile_complaints,
824 _("const value length mismatch for '%s', got %d, expected %d"),
825 arg1, arg2, arg3);
826 }
827
828 static void
829 dwarf2_macros_too_long_complaint (struct dwarf2_section_info *section)
830 {
831 complaint (&symfile_complaints,
832 _("macro info runs off end of `%s' section"),
833 section->asection->name);
834 }
835
836 static void
837 dwarf2_macro_malformed_definition_complaint (const char *arg1)
838 {
839 complaint (&symfile_complaints,
840 _("macro debug info contains a "
841 "malformed macro definition:\n`%s'"),
842 arg1);
843 }
844
845 static void
846 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
847 {
848 complaint (&symfile_complaints,
849 _("invalid attribute class or form for '%s' in '%s'"),
850 arg1, arg2);
851 }
852
853 /* local function prototypes */
854
855 static void dwarf2_locate_sections (bfd *, asection *, void *);
856
857 static void dwarf2_create_include_psymtab (char *, struct partial_symtab *,
858 struct objfile *);
859
860 static void dwarf2_find_base_address (struct die_info *die,
861 struct dwarf2_cu *cu);
862
863 static void dwarf2_build_psymtabs_hard (struct objfile *);
864
865 static void scan_partial_symbols (struct partial_die_info *,
866 CORE_ADDR *, CORE_ADDR *,
867 int, struct dwarf2_cu *);
868
869 static void add_partial_symbol (struct partial_die_info *,
870 struct dwarf2_cu *);
871
872 static void add_partial_namespace (struct partial_die_info *pdi,
873 CORE_ADDR *lowpc, CORE_ADDR *highpc,
874 int need_pc, struct dwarf2_cu *cu);
875
876 static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
877 CORE_ADDR *highpc, int need_pc,
878 struct dwarf2_cu *cu);
879
880 static void add_partial_enumeration (struct partial_die_info *enum_pdi,
881 struct dwarf2_cu *cu);
882
883 static void add_partial_subprogram (struct partial_die_info *pdi,
884 CORE_ADDR *lowpc, CORE_ADDR *highpc,
885 int need_pc, struct dwarf2_cu *cu);
886
887 static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi,
888 gdb_byte *buffer, gdb_byte *info_ptr,
889 bfd *abfd, struct dwarf2_cu *cu);
890
891 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
892
893 static void psymtab_to_symtab_1 (struct partial_symtab *);
894
895 static void dwarf2_read_abbrevs (struct dwarf2_cu *cu);
896
897 static void dwarf2_free_abbrev_table (void *);
898
899 static unsigned int peek_abbrev_code (bfd *, gdb_byte *);
900
901 static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *,
902 struct dwarf2_cu *);
903
904 static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int,
905 struct dwarf2_cu *);
906
907 static struct partial_die_info *load_partial_dies (bfd *,
908 gdb_byte *, gdb_byte *,
909 int, struct dwarf2_cu *);
910
911 static gdb_byte *read_partial_die (struct partial_die_info *,
912 struct abbrev_info *abbrev,
913 unsigned int, bfd *,
914 gdb_byte *, gdb_byte *,
915 struct dwarf2_cu *);
916
917 static struct partial_die_info *find_partial_die (sect_offset,
918 struct dwarf2_cu *);
919
920 static void fixup_partial_die (struct partial_die_info *,
921 struct dwarf2_cu *);
922
923 static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *,
924 bfd *, gdb_byte *, struct dwarf2_cu *);
925
926 static gdb_byte *read_attribute_value (struct attribute *, unsigned,
927 bfd *, gdb_byte *, struct dwarf2_cu *);
928
929 static unsigned int read_1_byte (bfd *, gdb_byte *);
930
931 static int read_1_signed_byte (bfd *, gdb_byte *);
932
933 static unsigned int read_2_bytes (bfd *, gdb_byte *);
934
935 static unsigned int read_4_bytes (bfd *, gdb_byte *);
936
937 static ULONGEST read_8_bytes (bfd *, gdb_byte *);
938
939 static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *,
940 unsigned int *);
941
942 static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *);
943
944 static LONGEST read_checked_initial_length_and_offset
945 (bfd *, gdb_byte *, const struct comp_unit_head *,
946 unsigned int *, unsigned int *);
947
948 static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *,
949 unsigned int *);
950
951 static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int);
952
953 static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int);
954
955 static char *read_direct_string (bfd *, gdb_byte *, unsigned int *);
956
957 static char *read_indirect_string (bfd *, gdb_byte *,
958 const struct comp_unit_head *,
959 unsigned int *);
960
961 static ULONGEST read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *);
962
963 static LONGEST read_signed_leb128 (bfd *, gdb_byte *, unsigned int *);
964
965 static gdb_byte *skip_leb128 (bfd *, gdb_byte *);
966
967 static void set_cu_language (unsigned int, struct dwarf2_cu *);
968
969 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
970 struct dwarf2_cu *);
971
972 static struct attribute *dwarf2_attr_no_follow (struct die_info *,
973 unsigned int,
974 struct dwarf2_cu *);
975
976 static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
977 struct dwarf2_cu *cu);
978
979 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
980
981 static struct die_info *die_specification (struct die_info *die,
982 struct dwarf2_cu **);
983
984 static void free_line_header (struct line_header *lh);
985
986 static void add_file_name (struct line_header *, char *, unsigned int,
987 unsigned int, unsigned int);
988
989 static struct line_header *(dwarf_decode_line_header
990 (unsigned int offset,
991 bfd *abfd, struct dwarf2_cu *cu));
992
993 static void dwarf_decode_lines (struct line_header *, const char *,
994 struct dwarf2_cu *, struct partial_symtab *,
995 int);
996
997 static void dwarf2_start_subfile (char *, const char *, const char *);
998
999 static struct symbol *new_symbol (struct die_info *, struct type *,
1000 struct dwarf2_cu *);
1001
1002 static struct symbol *new_symbol_full (struct die_info *, struct type *,
1003 struct dwarf2_cu *, struct symbol *);
1004
1005 static void dwarf2_const_value (struct attribute *, struct symbol *,
1006 struct dwarf2_cu *);
1007
1008 static void dwarf2_const_value_attr (struct attribute *attr,
1009 struct type *type,
1010 const char *name,
1011 struct obstack *obstack,
1012 struct dwarf2_cu *cu, LONGEST *value,
1013 gdb_byte **bytes,
1014 struct dwarf2_locexpr_baton **baton);
1015
1016 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
1017
1018 static int need_gnat_info (struct dwarf2_cu *);
1019
1020 static struct type *die_descriptive_type (struct die_info *,
1021 struct dwarf2_cu *);
1022
1023 static void set_descriptive_type (struct type *, struct die_info *,
1024 struct dwarf2_cu *);
1025
1026 static struct type *die_containing_type (struct die_info *,
1027 struct dwarf2_cu *);
1028
1029 static struct type *lookup_die_type (struct die_info *, struct attribute *,
1030 struct dwarf2_cu *);
1031
1032 static struct type *read_type_die (struct die_info *, struct dwarf2_cu *);
1033
1034 static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *);
1035
1036 static const char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
1037
1038 static char *typename_concat (struct obstack *obs, const char *prefix,
1039 const char *suffix, int physname,
1040 struct dwarf2_cu *cu);
1041
1042 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
1043
1044 static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *);
1045
1046 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
1047
1048 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
1049
1050 static void read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu);
1051
1052 static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *,
1053 struct dwarf2_cu *, struct partial_symtab *);
1054
1055 static int dwarf2_get_pc_bounds (struct die_info *,
1056 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *,
1057 struct partial_symtab *);
1058
1059 static void get_scope_pc_bounds (struct die_info *,
1060 CORE_ADDR *, CORE_ADDR *,
1061 struct dwarf2_cu *);
1062
1063 static void dwarf2_record_block_ranges (struct die_info *, struct block *,
1064 CORE_ADDR, struct dwarf2_cu *);
1065
1066 static void dwarf2_add_field (struct field_info *, struct die_info *,
1067 struct dwarf2_cu *);
1068
1069 static void dwarf2_attach_fields_to_type (struct field_info *,
1070 struct type *, struct dwarf2_cu *);
1071
1072 static void dwarf2_add_member_fn (struct field_info *,
1073 struct die_info *, struct type *,
1074 struct dwarf2_cu *);
1075
1076 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
1077 struct type *,
1078 struct dwarf2_cu *);
1079
1080 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
1081
1082 static void read_common_block (struct die_info *, struct dwarf2_cu *);
1083
1084 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
1085
1086 static void read_module (struct die_info *die, struct dwarf2_cu *cu);
1087
1088 static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
1089
1090 static struct type *read_module_type (struct die_info *die,
1091 struct dwarf2_cu *cu);
1092
1093 static const char *namespace_name (struct die_info *die,
1094 int *is_anonymous, struct dwarf2_cu *);
1095
1096 static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
1097
1098 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
1099
1100 static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
1101 struct dwarf2_cu *);
1102
1103 static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *);
1104
1105 static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader,
1106 gdb_byte *info_ptr,
1107 gdb_byte **new_info_ptr,
1108 struct die_info *parent);
1109
1110 static struct die_info *read_die_and_children (const struct die_reader_specs *reader,
1111 gdb_byte *info_ptr,
1112 gdb_byte **new_info_ptr,
1113 struct die_info *parent);
1114
1115 static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader,
1116 gdb_byte *info_ptr,
1117 gdb_byte **new_info_ptr,
1118 struct die_info *parent);
1119
1120 static gdb_byte *read_full_die (const struct die_reader_specs *reader,
1121 struct die_info **, gdb_byte *,
1122 int *);
1123
1124 static void process_die (struct die_info *, struct dwarf2_cu *);
1125
1126 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *,
1127 struct obstack *);
1128
1129 static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
1130
1131 static const char *dwarf2_full_name (char *name,
1132 struct die_info *die,
1133 struct dwarf2_cu *cu);
1134
1135 static struct die_info *dwarf2_extension (struct die_info *die,
1136 struct dwarf2_cu **);
1137
1138 static char *dwarf_tag_name (unsigned int);
1139
1140 static char *dwarf_attr_name (unsigned int);
1141
1142 static char *dwarf_form_name (unsigned int);
1143
1144 static char *dwarf_bool_name (unsigned int);
1145
1146 static char *dwarf_type_encoding_name (unsigned int);
1147
1148 #if 0
1149 static char *dwarf_cfi_name (unsigned int);
1150 #endif
1151
1152 static struct die_info *sibling_die (struct die_info *);
1153
1154 static void dump_die_shallow (struct ui_file *, int indent, struct die_info *);
1155
1156 static void dump_die_for_error (struct die_info *);
1157
1158 static void dump_die_1 (struct ui_file *, int level, int max_level,
1159 struct die_info *);
1160
1161 /*static*/ void dump_die (struct die_info *, int max_level);
1162
1163 static void store_in_ref_table (struct die_info *,
1164 struct dwarf2_cu *);
1165
1166 static int is_ref_attr (struct attribute *);
1167
1168 static sect_offset dwarf2_get_ref_die_offset (struct attribute *);
1169
1170 static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int);
1171
1172 static struct die_info *follow_die_ref_or_sig (struct die_info *,
1173 struct attribute *,
1174 struct dwarf2_cu **);
1175
1176 static struct die_info *follow_die_ref (struct die_info *,
1177 struct attribute *,
1178 struct dwarf2_cu **);
1179
1180 static struct die_info *follow_die_sig (struct die_info *,
1181 struct attribute *,
1182 struct dwarf2_cu **);
1183
1184 static struct signatured_type *lookup_signatured_type_at_offset
1185 (struct objfile *objfile,
1186 struct dwarf2_section_info *section, sect_offset offset);
1187
1188 static void load_full_type_unit (struct dwarf2_per_cu_data *per_cu);
1189
1190 static void read_signatured_type (struct signatured_type *);
1191
1192 /* memory allocation interface */
1193
1194 static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
1195
1196 static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *);
1197
1198 static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int);
1199
1200 static void dwarf_decode_macros (struct line_header *, unsigned int,
1201 char *, bfd *, struct dwarf2_cu *,
1202 struct dwarf2_section_info *,
1203 int);
1204
1205 static int attr_form_is_block (struct attribute *);
1206
1207 static int attr_form_is_section_offset (struct attribute *);
1208
1209 static int attr_form_is_constant (struct attribute *);
1210
1211 static void fill_in_loclist_baton (struct dwarf2_cu *cu,
1212 struct dwarf2_loclist_baton *baton,
1213 struct attribute *attr);
1214
1215 static void dwarf2_symbol_mark_computed (struct attribute *attr,
1216 struct symbol *sym,
1217 struct dwarf2_cu *cu);
1218
1219 static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
1220 struct abbrev_info *abbrev,
1221 struct dwarf2_cu *cu);
1222
1223 static void free_stack_comp_unit (void *);
1224
1225 static hashval_t partial_die_hash (const void *item);
1226
1227 static int partial_die_eq (const void *item_lhs, const void *item_rhs);
1228
1229 static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit
1230 (sect_offset offset, struct objfile *objfile);
1231
1232 static void init_one_comp_unit (struct dwarf2_cu *cu,
1233 struct dwarf2_per_cu_data *per_cu);
1234
1235 static void prepare_one_comp_unit (struct dwarf2_cu *cu,
1236 struct die_info *comp_unit_die);
1237
1238 static void free_heap_comp_unit (void *);
1239
1240 static void free_cached_comp_units (void *);
1241
1242 static void age_cached_comp_units (void);
1243
1244 static void free_one_cached_comp_unit (void *);
1245
1246 static struct type *set_die_type (struct die_info *, struct type *,
1247 struct dwarf2_cu *);
1248
1249 static void create_all_comp_units (struct objfile *);
1250
1251 static int create_all_type_units (struct objfile *);
1252
1253 static void load_full_comp_unit (struct dwarf2_per_cu_data *);
1254
1255 static void process_full_comp_unit (struct dwarf2_per_cu_data *);
1256
1257 static void dwarf2_add_dependence (struct dwarf2_cu *,
1258 struct dwarf2_per_cu_data *);
1259
1260 static void dwarf2_mark (struct dwarf2_cu *);
1261
1262 static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
1263
1264 static struct type *get_die_type_at_offset (sect_offset,
1265 struct dwarf2_per_cu_data *per_cu);
1266
1267 static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
1268
1269 static void dwarf2_release_queue (void *dummy);
1270
1271 static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu);
1272
1273 static void process_queue (void);
1274
1275 static void find_file_and_directory (struct die_info *die,
1276 struct dwarf2_cu *cu,
1277 char **name, char **comp_dir);
1278
1279 static char *file_full_name (int file, struct line_header *lh,
1280 const char *comp_dir);
1281
1282 static gdb_byte *read_and_check_comp_unit_head
1283 (struct comp_unit_head *header,
1284 struct dwarf2_section_info *section, gdb_byte *info_ptr,
1285 int is_debug_types_section);
1286
1287 static void init_cu_die_reader (struct die_reader_specs *reader,
1288 struct dwarf2_cu *cu);
1289
1290 static htab_t allocate_signatured_type_table (struct objfile *objfile);
1291
1292 #if WORDS_BIGENDIAN
1293
1294 /* Convert VALUE between big- and little-endian. */
1295 static offset_type
1296 byte_swap (offset_type value)
1297 {
1298 offset_type result;
1299
1300 result = (value & 0xff) << 24;
1301 result |= (value & 0xff00) << 8;
1302 result |= (value & 0xff0000) >> 8;
1303 result |= (value & 0xff000000) >> 24;
1304 return result;
1305 }
1306
1307 #define MAYBE_SWAP(V) byte_swap (V)
1308
1309 #else
1310 #define MAYBE_SWAP(V) (V)
1311 #endif /* WORDS_BIGENDIAN */
1312
1313 /* The suffix for an index file. */
1314 #define INDEX_SUFFIX ".gdb-index"
1315
1316 static const char *dwarf2_physname (char *name, struct die_info *die,
1317 struct dwarf2_cu *cu);
1318
1319 /* Try to locate the sections we need for DWARF 2 debugging
1320 information and return true if we have enough to do something.
1321 NAMES points to the dwarf2 section names, or is NULL if the standard
1322 ELF names are used. */
1323
1324 int
1325 dwarf2_has_info (struct objfile *objfile,
1326 const struct dwarf2_debug_sections *names)
1327 {
1328 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
1329 if (!dwarf2_per_objfile)
1330 {
1331 /* Initialize per-objfile state. */
1332 struct dwarf2_per_objfile *data
1333 = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
1334
1335 memset (data, 0, sizeof (*data));
1336 set_objfile_data (objfile, dwarf2_objfile_data_key, data);
1337 dwarf2_per_objfile = data;
1338
1339 bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections,
1340 (void *) names);
1341 dwarf2_per_objfile->objfile = objfile;
1342 }
1343 return (dwarf2_per_objfile->info.asection != NULL
1344 && dwarf2_per_objfile->abbrev.asection != NULL);
1345 }
1346
1347 /* When loading sections, we look either for uncompressed section or for
1348 compressed section names. */
1349
1350 static int
1351 section_is_p (const char *section_name,
1352 const struct dwarf2_section_names *names)
1353 {
1354 if (names->normal != NULL
1355 && strcmp (section_name, names->normal) == 0)
1356 return 1;
1357 if (names->compressed != NULL
1358 && strcmp (section_name, names->compressed) == 0)
1359 return 1;
1360 return 0;
1361 }
1362
1363 /* This function is mapped across the sections and remembers the
1364 offset and size of each of the debugging sections we are interested
1365 in. */
1366
1367 static void
1368 dwarf2_locate_sections (bfd *abfd, asection *sectp, void *vnames)
1369 {
1370 const struct dwarf2_debug_sections *names;
1371
1372 if (vnames == NULL)
1373 names = &dwarf2_elf_names;
1374 else
1375 names = (const struct dwarf2_debug_sections *) vnames;
1376
1377 if (section_is_p (sectp->name, &names->info))
1378 {
1379 dwarf2_per_objfile->info.asection = sectp;
1380 dwarf2_per_objfile->info.size = bfd_get_section_size (sectp);
1381 }
1382 else if (section_is_p (sectp->name, &names->abbrev))
1383 {
1384 dwarf2_per_objfile->abbrev.asection = sectp;
1385 dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp);
1386 }
1387 else if (section_is_p (sectp->name, &names->line))
1388 {
1389 dwarf2_per_objfile->line.asection = sectp;
1390 dwarf2_per_objfile->line.size = bfd_get_section_size (sectp);
1391 }
1392 else if (section_is_p (sectp->name, &names->loc))
1393 {
1394 dwarf2_per_objfile->loc.asection = sectp;
1395 dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp);
1396 }
1397 else if (section_is_p (sectp->name, &names->macinfo))
1398 {
1399 dwarf2_per_objfile->macinfo.asection = sectp;
1400 dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp);
1401 }
1402 else if (section_is_p (sectp->name, &names->macro))
1403 {
1404 dwarf2_per_objfile->macro.asection = sectp;
1405 dwarf2_per_objfile->macro.size = bfd_get_section_size (sectp);
1406 }
1407 else if (section_is_p (sectp->name, &names->str))
1408 {
1409 dwarf2_per_objfile->str.asection = sectp;
1410 dwarf2_per_objfile->str.size = bfd_get_section_size (sectp);
1411 }
1412 else if (section_is_p (sectp->name, &names->frame))
1413 {
1414 dwarf2_per_objfile->frame.asection = sectp;
1415 dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp);
1416 }
1417 else if (section_is_p (sectp->name, &names->eh_frame))
1418 {
1419 flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
1420
1421 if (aflag & SEC_HAS_CONTENTS)
1422 {
1423 dwarf2_per_objfile->eh_frame.asection = sectp;
1424 dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp);
1425 }
1426 }
1427 else if (section_is_p (sectp->name, &names->ranges))
1428 {
1429 dwarf2_per_objfile->ranges.asection = sectp;
1430 dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp);
1431 }
1432 else if (section_is_p (sectp->name, &names->types))
1433 {
1434 struct dwarf2_section_info type_section;
1435
1436 memset (&type_section, 0, sizeof (type_section));
1437 type_section.asection = sectp;
1438 type_section.size = bfd_get_section_size (sectp);
1439
1440 VEC_safe_push (dwarf2_section_info_def, dwarf2_per_objfile->types,
1441 &type_section);
1442 }
1443 else if (section_is_p (sectp->name, &names->gdb_index))
1444 {
1445 dwarf2_per_objfile->gdb_index.asection = sectp;
1446 dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp);
1447 }
1448
1449 if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD)
1450 && bfd_section_vma (abfd, sectp) == 0)
1451 dwarf2_per_objfile->has_section_at_zero = 1;
1452 }
1453
1454 /* Decompress a section that was compressed using zlib. Store the
1455 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1456
1457 static void
1458 zlib_decompress_section (struct objfile *objfile, asection *sectp,
1459 gdb_byte **outbuf, bfd_size_type *outsize)
1460 {
1461 bfd *abfd = objfile->obfd;
1462 #ifndef HAVE_ZLIB_H
1463 error (_("Support for zlib-compressed DWARF data (from '%s') "
1464 "is disabled in this copy of GDB"),
1465 bfd_get_filename (abfd));
1466 #else
1467 bfd_size_type compressed_size = bfd_get_section_size (sectp);
1468 gdb_byte *compressed_buffer = xmalloc (compressed_size);
1469 struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer);
1470 bfd_size_type uncompressed_size;
1471 gdb_byte *uncompressed_buffer;
1472 z_stream strm;
1473 int rc;
1474 int header_size = 12;
1475
1476 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1477 || bfd_bread (compressed_buffer,
1478 compressed_size, abfd) != compressed_size)
1479 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1480 bfd_get_filename (abfd));
1481
1482 /* Read the zlib header. In this case, it should be "ZLIB" followed
1483 by the uncompressed section size, 8 bytes in big-endian order. */
1484 if (compressed_size < header_size
1485 || strncmp (compressed_buffer, "ZLIB", 4) != 0)
1486 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1487 bfd_get_filename (abfd));
1488 uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
1489 uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
1490 uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
1491 uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8;
1492 uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8;
1493 uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8;
1494 uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8;
1495 uncompressed_size += compressed_buffer[11];
1496
1497 /* It is possible the section consists of several compressed
1498 buffers concatenated together, so we uncompress in a loop. */
1499 strm.zalloc = NULL;
1500 strm.zfree = NULL;
1501 strm.opaque = NULL;
1502 strm.avail_in = compressed_size - header_size;
1503 strm.next_in = (Bytef*) compressed_buffer + header_size;
1504 strm.avail_out = uncompressed_size;
1505 uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack,
1506 uncompressed_size);
1507 rc = inflateInit (&strm);
1508 while (strm.avail_in > 0)
1509 {
1510 if (rc != Z_OK)
1511 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1512 bfd_get_filename (abfd), rc);
1513 strm.next_out = ((Bytef*) uncompressed_buffer
1514 + (uncompressed_size - strm.avail_out));
1515 rc = inflate (&strm, Z_FINISH);
1516 if (rc != Z_STREAM_END)
1517 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1518 bfd_get_filename (abfd), rc);
1519 rc = inflateReset (&strm);
1520 }
1521 rc = inflateEnd (&strm);
1522 if (rc != Z_OK
1523 || strm.avail_out != 0)
1524 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1525 bfd_get_filename (abfd), rc);
1526
1527 do_cleanups (cleanup);
1528 *outbuf = uncompressed_buffer;
1529 *outsize = uncompressed_size;
1530 #endif
1531 }
1532
1533 /* A helper function that decides whether a section is empty. */
1534
1535 static int
1536 dwarf2_section_empty_p (struct dwarf2_section_info *info)
1537 {
1538 return info->asection == NULL || info->size == 0;
1539 }
1540
1541 /* Read the contents of the section INFO from object file specified by
1542 OBJFILE, store info about the section into INFO.
1543 If the section is compressed, uncompress it before returning. */
1544
1545 static void
1546 dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
1547 {
1548 bfd *abfd = objfile->obfd;
1549 asection *sectp = info->asection;
1550 gdb_byte *buf, *retbuf;
1551 unsigned char header[4];
1552
1553 if (info->readin)
1554 return;
1555 info->buffer = NULL;
1556 info->map_addr = NULL;
1557 info->readin = 1;
1558
1559 if (dwarf2_section_empty_p (info))
1560 return;
1561
1562 /* Check if the file has a 4-byte header indicating compression. */
1563 if (info->size > sizeof (header)
1564 && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0
1565 && bfd_bread (header, sizeof (header), abfd) == sizeof (header))
1566 {
1567 /* Upon decompression, update the buffer and its size. */
1568 if (strncmp (header, "ZLIB", sizeof (header)) == 0)
1569 {
1570 zlib_decompress_section (objfile, sectp, &info->buffer,
1571 &info->size);
1572 return;
1573 }
1574 }
1575
1576 #ifdef HAVE_MMAP
1577 if (pagesize == 0)
1578 pagesize = getpagesize ();
1579
1580 /* Only try to mmap sections which are large enough: we don't want to
1581 waste space due to fragmentation. Also, only try mmap for sections
1582 without relocations. */
1583
1584 if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0)
1585 {
1586 info->buffer = bfd_mmap (abfd, 0, info->size, PROT_READ,
1587 MAP_PRIVATE, sectp->filepos,
1588 &info->map_addr, &info->map_len);
1589
1590 if ((caddr_t)info->buffer != MAP_FAILED)
1591 {
1592 #if HAVE_POSIX_MADVISE
1593 posix_madvise (info->map_addr, info->map_len, POSIX_MADV_WILLNEED);
1594 #endif
1595 return;
1596 }
1597 }
1598 #endif
1599
1600 /* If we get here, we are a normal, not-compressed section. */
1601 info->buffer = buf
1602 = obstack_alloc (&objfile->objfile_obstack, info->size);
1603
1604 /* When debugging .o files, we may need to apply relocations; see
1605 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1606 We never compress sections in .o files, so we only need to
1607 try this when the section is not compressed. */
1608 retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
1609 if (retbuf != NULL)
1610 {
1611 info->buffer = retbuf;
1612 return;
1613 }
1614
1615 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1616 || bfd_bread (buf, info->size, abfd) != info->size)
1617 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1618 bfd_get_filename (abfd));
1619 }
1620
1621 /* A helper function that returns the size of a section in a safe way.
1622 If you are positive that the section has been read before using the
1623 size, then it is safe to refer to the dwarf2_section_info object's
1624 "size" field directly. In other cases, you must call this
1625 function, because for compressed sections the size field is not set
1626 correctly until the section has been read. */
1627
1628 static bfd_size_type
1629 dwarf2_section_size (struct objfile *objfile,
1630 struct dwarf2_section_info *info)
1631 {
1632 if (!info->readin)
1633 dwarf2_read_section (objfile, info);
1634 return info->size;
1635 }
1636
1637 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1638 SECTION_NAME. */
1639
1640 void
1641 dwarf2_get_section_info (struct objfile *objfile,
1642 enum dwarf2_section_enum sect,
1643 asection **sectp, gdb_byte **bufp,
1644 bfd_size_type *sizep)
1645 {
1646 struct dwarf2_per_objfile *data
1647 = objfile_data (objfile, dwarf2_objfile_data_key);
1648 struct dwarf2_section_info *info;
1649
1650 /* We may see an objfile without any DWARF, in which case we just
1651 return nothing. */
1652 if (data == NULL)
1653 {
1654 *sectp = NULL;
1655 *bufp = NULL;
1656 *sizep = 0;
1657 return;
1658 }
1659 switch (sect)
1660 {
1661 case DWARF2_DEBUG_FRAME:
1662 info = &data->frame;
1663 break;
1664 case DWARF2_EH_FRAME:
1665 info = &data->eh_frame;
1666 break;
1667 default:
1668 gdb_assert_not_reached ("unexpected section");
1669 }
1670
1671 dwarf2_read_section (objfile, info);
1672
1673 *sectp = info->asection;
1674 *bufp = info->buffer;
1675 *sizep = info->size;
1676 }
1677
1678 \f
1679 /* DWARF quick_symbols_functions support. */
1680
1681 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1682 unique line tables, so we maintain a separate table of all .debug_line
1683 derived entries to support the sharing.
1684 All the quick functions need is the list of file names. We discard the
1685 line_header when we're done and don't need to record it here. */
1686 struct quick_file_names
1687 {
1688 /* The offset in .debug_line of the line table. We hash on this. */
1689 unsigned int offset;
1690
1691 /* The number of entries in file_names, real_names. */
1692 unsigned int num_file_names;
1693
1694 /* The file names from the line table, after being run through
1695 file_full_name. */
1696 const char **file_names;
1697
1698 /* The file names from the line table after being run through
1699 gdb_realpath. These are computed lazily. */
1700 const char **real_names;
1701 };
1702
1703 /* When using the index (and thus not using psymtabs), each CU has an
1704 object of this type. This is used to hold information needed by
1705 the various "quick" methods. */
1706 struct dwarf2_per_cu_quick_data
1707 {
1708 /* The file table. This can be NULL if there was no file table
1709 or it's currently not read in.
1710 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1711 struct quick_file_names *file_names;
1712
1713 /* The corresponding symbol table. This is NULL if symbols for this
1714 CU have not yet been read. */
1715 struct symtab *symtab;
1716
1717 /* A temporary mark bit used when iterating over all CUs in
1718 expand_symtabs_matching. */
1719 unsigned int mark : 1;
1720
1721 /* True if we've tried to read the file table and found there isn't one.
1722 There will be no point in trying to read it again next time. */
1723 unsigned int no_file_data : 1;
1724 };
1725
1726 /* Hash function for a quick_file_names. */
1727
1728 static hashval_t
1729 hash_file_name_entry (const void *e)
1730 {
1731 const struct quick_file_names *file_data = e;
1732
1733 return file_data->offset;
1734 }
1735
1736 /* Equality function for a quick_file_names. */
1737
1738 static int
1739 eq_file_name_entry (const void *a, const void *b)
1740 {
1741 const struct quick_file_names *ea = a;
1742 const struct quick_file_names *eb = b;
1743
1744 return ea->offset == eb->offset;
1745 }
1746
1747 /* Delete function for a quick_file_names. */
1748
1749 static void
1750 delete_file_name_entry (void *e)
1751 {
1752 struct quick_file_names *file_data = e;
1753 int i;
1754
1755 for (i = 0; i < file_data->num_file_names; ++i)
1756 {
1757 xfree ((void*) file_data->file_names[i]);
1758 if (file_data->real_names)
1759 xfree ((void*) file_data->real_names[i]);
1760 }
1761
1762 /* The space for the struct itself lives on objfile_obstack,
1763 so we don't free it here. */
1764 }
1765
1766 /* Create a quick_file_names hash table. */
1767
1768 static htab_t
1769 create_quick_file_names_table (unsigned int nr_initial_entries)
1770 {
1771 return htab_create_alloc (nr_initial_entries,
1772 hash_file_name_entry, eq_file_name_entry,
1773 delete_file_name_entry, xcalloc, xfree);
1774 }
1775
1776 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1777 have to be created afterwards. You should call age_cached_comp_units after
1778 processing PER_CU->CU. dw2_setup must have been already called. */
1779
1780 static void
1781 load_cu (struct dwarf2_per_cu_data *per_cu)
1782 {
1783 if (per_cu->debug_types_section)
1784 load_full_type_unit (per_cu);
1785 else
1786 load_full_comp_unit (per_cu);
1787
1788 gdb_assert (per_cu->cu != NULL);
1789
1790 dwarf2_find_base_address (per_cu->cu->dies, per_cu->cu);
1791 }
1792
1793 /* Read in the symbols for PER_CU. */
1794
1795 static void
1796 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
1797 {
1798 struct cleanup *back_to;
1799
1800 back_to = make_cleanup (dwarf2_release_queue, NULL);
1801
1802 queue_comp_unit (per_cu);
1803
1804 load_cu (per_cu);
1805
1806 process_queue ();
1807
1808 /* Age the cache, releasing compilation units that have not
1809 been used recently. */
1810 age_cached_comp_units ();
1811
1812 do_cleanups (back_to);
1813 }
1814
1815 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1816 the objfile from which this CU came. Returns the resulting symbol
1817 table. */
1818
1819 static struct symtab *
1820 dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
1821 {
1822 if (!per_cu->v.quick->symtab)
1823 {
1824 struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL);
1825 increment_reading_symtab ();
1826 dw2_do_instantiate_symtab (per_cu);
1827 do_cleanups (back_to);
1828 }
1829 return per_cu->v.quick->symtab;
1830 }
1831
1832 /* Return the CU given its index. */
1833
1834 static struct dwarf2_per_cu_data *
1835 dw2_get_cu (int index)
1836 {
1837 if (index >= dwarf2_per_objfile->n_comp_units)
1838 {
1839 index -= dwarf2_per_objfile->n_comp_units;
1840 return dwarf2_per_objfile->all_type_units[index];
1841 }
1842 return dwarf2_per_objfile->all_comp_units[index];
1843 }
1844
1845 /* A helper function that knows how to read a 64-bit value in a way
1846 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1847 otherwise. */
1848
1849 static int
1850 extract_cu_value (const char *bytes, ULONGEST *result)
1851 {
1852 if (sizeof (ULONGEST) < 8)
1853 {
1854 int i;
1855
1856 /* Ignore the upper 4 bytes if they are all zero. */
1857 for (i = 0; i < 4; ++i)
1858 if (bytes[i + 4] != 0)
1859 return 0;
1860
1861 *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE);
1862 }
1863 else
1864 *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE);
1865 return 1;
1866 }
1867
1868 /* Read the CU list from the mapped index, and use it to create all
1869 the CU objects for this objfile. Return 0 if something went wrong,
1870 1 if everything went ok. */
1871
1872 static int
1873 create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list,
1874 offset_type cu_list_elements)
1875 {
1876 offset_type i;
1877
1878 dwarf2_per_objfile->n_comp_units = cu_list_elements / 2;
1879 dwarf2_per_objfile->all_comp_units
1880 = obstack_alloc (&objfile->objfile_obstack,
1881 dwarf2_per_objfile->n_comp_units
1882 * sizeof (struct dwarf2_per_cu_data *));
1883
1884 for (i = 0; i < cu_list_elements; i += 2)
1885 {
1886 struct dwarf2_per_cu_data *the_cu;
1887 ULONGEST offset, length;
1888
1889 if (!extract_cu_value (cu_list, &offset)
1890 || !extract_cu_value (cu_list + 8, &length))
1891 return 0;
1892 cu_list += 2 * 8;
1893
1894 the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1895 struct dwarf2_per_cu_data);
1896 the_cu->offset.sect_off = offset;
1897 the_cu->length = length;
1898 the_cu->objfile = objfile;
1899 the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1900 struct dwarf2_per_cu_quick_data);
1901 dwarf2_per_objfile->all_comp_units[i / 2] = the_cu;
1902 }
1903
1904 return 1;
1905 }
1906
1907 /* Create the signatured type hash table from the index. */
1908
1909 static int
1910 create_signatured_type_table_from_index (struct objfile *objfile,
1911 struct dwarf2_section_info *section,
1912 const gdb_byte *bytes,
1913 offset_type elements)
1914 {
1915 offset_type i;
1916 htab_t sig_types_hash;
1917
1918 dwarf2_per_objfile->n_type_units = elements / 3;
1919 dwarf2_per_objfile->all_type_units
1920 = obstack_alloc (&objfile->objfile_obstack,
1921 dwarf2_per_objfile->n_type_units
1922 * sizeof (struct dwarf2_per_cu_data *));
1923
1924 sig_types_hash = allocate_signatured_type_table (objfile);
1925
1926 for (i = 0; i < elements; i += 3)
1927 {
1928 struct signatured_type *sig_type;
1929 ULONGEST offset, type_offset_in_tu, signature;
1930 void **slot;
1931
1932 if (!extract_cu_value (bytes, &offset)
1933 || !extract_cu_value (bytes + 8, &type_offset_in_tu))
1934 return 0;
1935 signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE);
1936 bytes += 3 * 8;
1937
1938 sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1939 struct signatured_type);
1940 sig_type->signature = signature;
1941 sig_type->type_offset.cu_off = type_offset_in_tu;
1942 sig_type->per_cu.debug_types_section = section;
1943 sig_type->per_cu.offset.sect_off = offset;
1944 sig_type->per_cu.objfile = objfile;
1945 sig_type->per_cu.v.quick
1946 = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1947 struct dwarf2_per_cu_quick_data);
1948
1949 slot = htab_find_slot (sig_types_hash, sig_type, INSERT);
1950 *slot = sig_type;
1951
1952 dwarf2_per_objfile->all_type_units[i / 3] = &sig_type->per_cu;
1953 }
1954
1955 dwarf2_per_objfile->signatured_types = sig_types_hash;
1956
1957 return 1;
1958 }
1959
1960 /* Read the address map data from the mapped index, and use it to
1961 populate the objfile's psymtabs_addrmap. */
1962
1963 static void
1964 create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index)
1965 {
1966 const gdb_byte *iter, *end;
1967 struct obstack temp_obstack;
1968 struct addrmap *mutable_map;
1969 struct cleanup *cleanup;
1970 CORE_ADDR baseaddr;
1971
1972 obstack_init (&temp_obstack);
1973 cleanup = make_cleanup_obstack_free (&temp_obstack);
1974 mutable_map = addrmap_create_mutable (&temp_obstack);
1975
1976 iter = index->address_table;
1977 end = iter + index->address_table_size;
1978
1979 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1980
1981 while (iter < end)
1982 {
1983 ULONGEST hi, lo, cu_index;
1984 lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
1985 iter += 8;
1986 hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
1987 iter += 8;
1988 cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE);
1989 iter += 4;
1990
1991 addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1,
1992 dw2_get_cu (cu_index));
1993 }
1994
1995 objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map,
1996 &objfile->objfile_obstack);
1997 do_cleanups (cleanup);
1998 }
1999
2000 /* The hash function for strings in the mapped index. This is the same as
2001 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2002 implementation. This is necessary because the hash function is tied to the
2003 format of the mapped index file. The hash values do not have to match with
2004 SYMBOL_HASH_NEXT.
2005
2006 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2007
2008 static hashval_t
2009 mapped_index_string_hash (int index_version, const void *p)
2010 {
2011 const unsigned char *str = (const unsigned char *) p;
2012 hashval_t r = 0;
2013 unsigned char c;
2014
2015 while ((c = *str++) != 0)
2016 {
2017 if (index_version >= 5)
2018 c = tolower (c);
2019 r = r * 67 + c - 113;
2020 }
2021
2022 return r;
2023 }
2024
2025 /* Find a slot in the mapped index INDEX for the object named NAME.
2026 If NAME is found, set *VEC_OUT to point to the CU vector in the
2027 constant pool and return 1. If NAME cannot be found, return 0. */
2028
2029 static int
2030 find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
2031 offset_type **vec_out)
2032 {
2033 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
2034 offset_type hash;
2035 offset_type slot, step;
2036 int (*cmp) (const char *, const char *);
2037
2038 if (current_language->la_language == language_cplus
2039 || current_language->la_language == language_java
2040 || current_language->la_language == language_fortran)
2041 {
2042 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2043 not contain any. */
2044 const char *paren = strchr (name, '(');
2045
2046 if (paren)
2047 {
2048 char *dup;
2049
2050 dup = xmalloc (paren - name + 1);
2051 memcpy (dup, name, paren - name);
2052 dup[paren - name] = 0;
2053
2054 make_cleanup (xfree, dup);
2055 name = dup;
2056 }
2057 }
2058
2059 /* Index version 4 did not support case insensitive searches. But the
2060 indices for case insensitive languages are built in lowercase, therefore
2061 simulate our NAME being searched is also lowercased. */
2062 hash = mapped_index_string_hash ((index->version == 4
2063 && case_sensitivity == case_sensitive_off
2064 ? 5 : index->version),
2065 name);
2066
2067 slot = hash & (index->symbol_table_slots - 1);
2068 step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1;
2069 cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp);
2070
2071 for (;;)
2072 {
2073 /* Convert a slot number to an offset into the table. */
2074 offset_type i = 2 * slot;
2075 const char *str;
2076 if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0)
2077 {
2078 do_cleanups (back_to);
2079 return 0;
2080 }
2081
2082 str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]);
2083 if (!cmp (name, str))
2084 {
2085 *vec_out = (offset_type *) (index->constant_pool
2086 + MAYBE_SWAP (index->symbol_table[i + 1]));
2087 do_cleanups (back_to);
2088 return 1;
2089 }
2090
2091 slot = (slot + step) & (index->symbol_table_slots - 1);
2092 }
2093 }
2094
2095 /* Read the index file. If everything went ok, initialize the "quick"
2096 elements of all the CUs and return 1. Otherwise, return 0. */
2097
2098 static int
2099 dwarf2_read_index (struct objfile *objfile)
2100 {
2101 char *addr;
2102 struct mapped_index *map;
2103 offset_type *metadata;
2104 const gdb_byte *cu_list;
2105 const gdb_byte *types_list = NULL;
2106 offset_type version, cu_list_elements;
2107 offset_type types_list_elements = 0;
2108 int i;
2109
2110 if (dwarf2_section_empty_p (&dwarf2_per_objfile->gdb_index))
2111 return 0;
2112
2113 /* Older elfutils strip versions could keep the section in the main
2114 executable while splitting it for the separate debug info file. */
2115 if ((bfd_get_file_flags (dwarf2_per_objfile->gdb_index.asection)
2116 & SEC_HAS_CONTENTS) == 0)
2117 return 0;
2118
2119 dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index);
2120
2121 addr = dwarf2_per_objfile->gdb_index.buffer;
2122 /* Version check. */
2123 version = MAYBE_SWAP (*(offset_type *) addr);
2124 /* Versions earlier than 3 emitted every copy of a psymbol. This
2125 causes the index to behave very poorly for certain requests. Version 3
2126 contained incomplete addrmap. So, it seems better to just ignore such
2127 indices. */
2128 if (version < 4)
2129 {
2130 static int warning_printed = 0;
2131 if (!warning_printed)
2132 {
2133 warning (_("Skipping obsolete .gdb_index section in %s."),
2134 objfile->name);
2135 warning_printed = 1;
2136 }
2137 return 0;
2138 }
2139 /* Index version 4 uses a different hash function than index version
2140 5 and later.
2141
2142 Versions earlier than 6 did not emit psymbols for inlined
2143 functions. Using these files will cause GDB not to be able to
2144 set breakpoints on inlined functions by name, so we ignore these
2145 indices unless the --use-deprecated-index-sections command line
2146 option was supplied. */
2147 if (version < 6 && !use_deprecated_index_sections)
2148 {
2149 static int warning_printed = 0;
2150 if (!warning_printed)
2151 {
2152 warning (_("Skipping deprecated .gdb_index section in %s, pass "
2153 "--use-deprecated-index-sections to use them anyway"),
2154 objfile->name);
2155 warning_printed = 1;
2156 }
2157 return 0;
2158 }
2159 /* Indexes with higher version than the one supported by GDB may be no
2160 longer backward compatible. */
2161 if (version > 6)
2162 return 0;
2163
2164 map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index);
2165 map->version = version;
2166 map->total_size = dwarf2_per_objfile->gdb_index.size;
2167
2168 metadata = (offset_type *) (addr + sizeof (offset_type));
2169
2170 i = 0;
2171 cu_list = addr + MAYBE_SWAP (metadata[i]);
2172 cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i]))
2173 / 8);
2174 ++i;
2175
2176 types_list = addr + MAYBE_SWAP (metadata[i]);
2177 types_list_elements = ((MAYBE_SWAP (metadata[i + 1])
2178 - MAYBE_SWAP (metadata[i]))
2179 / 8);
2180 ++i;
2181
2182 map->address_table = addr + MAYBE_SWAP (metadata[i]);
2183 map->address_table_size = (MAYBE_SWAP (metadata[i + 1])
2184 - MAYBE_SWAP (metadata[i]));
2185 ++i;
2186
2187 map->symbol_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i]));
2188 map->symbol_table_slots = ((MAYBE_SWAP (metadata[i + 1])
2189 - MAYBE_SWAP (metadata[i]))
2190 / (2 * sizeof (offset_type)));
2191 ++i;
2192
2193 map->constant_pool = addr + MAYBE_SWAP (metadata[i]);
2194
2195 if (!create_cus_from_index (objfile, cu_list, cu_list_elements))
2196 return 0;
2197
2198 if (types_list_elements)
2199 {
2200 struct dwarf2_section_info *section;
2201
2202 /* We can only handle a single .debug_types when we have an
2203 index. */
2204 if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) != 1)
2205 return 0;
2206
2207 section = VEC_index (dwarf2_section_info_def,
2208 dwarf2_per_objfile->types, 0);
2209
2210 if (!create_signatured_type_table_from_index (objfile, section,
2211 types_list,
2212 types_list_elements))
2213 return 0;
2214 }
2215
2216 create_addrmap_from_index (objfile, map);
2217
2218 dwarf2_per_objfile->index_table = map;
2219 dwarf2_per_objfile->using_index = 1;
2220 dwarf2_per_objfile->quick_file_names_table =
2221 create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
2222
2223 return 1;
2224 }
2225
2226 /* A helper for the "quick" functions which sets the global
2227 dwarf2_per_objfile according to OBJFILE. */
2228
2229 static void
2230 dw2_setup (struct objfile *objfile)
2231 {
2232 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
2233 gdb_assert (dwarf2_per_objfile);
2234 }
2235
2236 /* A helper for the "quick" functions which attempts to read the line
2237 table for THIS_CU. */
2238
2239 static struct quick_file_names *
2240 dw2_get_file_names (struct objfile *objfile,
2241 struct dwarf2_per_cu_data *this_cu)
2242 {
2243 bfd *abfd = objfile->obfd;
2244 struct line_header *lh;
2245 struct attribute *attr;
2246 struct cleanup *cleanups;
2247 struct die_info *comp_unit_die;
2248 struct dwarf2_section_info* sec;
2249 gdb_byte *info_ptr;
2250 int has_children, i;
2251 struct dwarf2_cu cu;
2252 unsigned int bytes_read;
2253 struct die_reader_specs reader_specs;
2254 char *name, *comp_dir;
2255 void **slot;
2256 struct quick_file_names *qfn;
2257 unsigned int line_offset;
2258
2259 if (this_cu->v.quick->file_names != NULL)
2260 return this_cu->v.quick->file_names;
2261 /* If we know there is no line data, no point in looking again. */
2262 if (this_cu->v.quick->no_file_data)
2263 return NULL;
2264
2265 init_one_comp_unit (&cu, this_cu);
2266 cleanups = make_cleanup (free_stack_comp_unit, &cu);
2267
2268 if (this_cu->debug_types_section)
2269 sec = this_cu->debug_types_section;
2270 else
2271 sec = &dwarf2_per_objfile->info;
2272 dwarf2_read_section (objfile, sec);
2273 info_ptr = sec->buffer + this_cu->offset.sect_off;
2274
2275 info_ptr = read_and_check_comp_unit_head (&cu.header, sec, info_ptr,
2276 this_cu->debug_types_section != NULL);
2277
2278 /* Skip dummy compilation units. */
2279 if (info_ptr >= (sec->buffer + sec->size)
2280 || peek_abbrev_code (abfd, info_ptr) == 0)
2281 {
2282 do_cleanups (cleanups);
2283 return NULL;
2284 }
2285
2286 dwarf2_read_abbrevs (&cu);
2287 make_cleanup (dwarf2_free_abbrev_table, &cu);
2288
2289 init_cu_die_reader (&reader_specs, &cu);
2290 read_full_die (&reader_specs, &comp_unit_die, info_ptr,
2291 &has_children);
2292
2293 lh = NULL;
2294 slot = NULL;
2295 line_offset = 0;
2296 attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu);
2297 if (attr)
2298 {
2299 struct quick_file_names find_entry;
2300
2301 line_offset = DW_UNSND (attr);
2302
2303 /* We may have already read in this line header (TU line header sharing).
2304 If we have we're done. */
2305 find_entry.offset = line_offset;
2306 slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table,
2307 &find_entry, INSERT);
2308 if (*slot != NULL)
2309 {
2310 do_cleanups (cleanups);
2311 this_cu->v.quick->file_names = *slot;
2312 return *slot;
2313 }
2314
2315 lh = dwarf_decode_line_header (line_offset, abfd, &cu);
2316 }
2317 if (lh == NULL)
2318 {
2319 do_cleanups (cleanups);
2320 this_cu->v.quick->no_file_data = 1;
2321 return NULL;
2322 }
2323
2324 qfn = obstack_alloc (&objfile->objfile_obstack, sizeof (*qfn));
2325 qfn->offset = line_offset;
2326 gdb_assert (slot != NULL);
2327 *slot = qfn;
2328
2329 find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir);
2330
2331 qfn->num_file_names = lh->num_file_names;
2332 qfn->file_names = obstack_alloc (&objfile->objfile_obstack,
2333 lh->num_file_names * sizeof (char *));
2334 for (i = 0; i < lh->num_file_names; ++i)
2335 qfn->file_names[i] = file_full_name (i + 1, lh, comp_dir);
2336 qfn->real_names = NULL;
2337
2338 free_line_header (lh);
2339 do_cleanups (cleanups);
2340
2341 this_cu->v.quick->file_names = qfn;
2342 return qfn;
2343 }
2344
2345 /* A helper for the "quick" functions which computes and caches the
2346 real path for a given file name from the line table. */
2347
2348 static const char *
2349 dw2_get_real_path (struct objfile *objfile,
2350 struct quick_file_names *qfn, int index)
2351 {
2352 if (qfn->real_names == NULL)
2353 qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack,
2354 qfn->num_file_names, sizeof (char *));
2355
2356 if (qfn->real_names[index] == NULL)
2357 qfn->real_names[index] = gdb_realpath (qfn->file_names[index]);
2358
2359 return qfn->real_names[index];
2360 }
2361
2362 static struct symtab *
2363 dw2_find_last_source_symtab (struct objfile *objfile)
2364 {
2365 int index;
2366
2367 dw2_setup (objfile);
2368 index = dwarf2_per_objfile->n_comp_units - 1;
2369 return dw2_instantiate_symtab (dw2_get_cu (index));
2370 }
2371
2372 /* Traversal function for dw2_forget_cached_source_info. */
2373
2374 static int
2375 dw2_free_cached_file_names (void **slot, void *info)
2376 {
2377 struct quick_file_names *file_data = (struct quick_file_names *) *slot;
2378
2379 if (file_data->real_names)
2380 {
2381 int i;
2382
2383 for (i = 0; i < file_data->num_file_names; ++i)
2384 {
2385 xfree ((void*) file_data->real_names[i]);
2386 file_data->real_names[i] = NULL;
2387 }
2388 }
2389
2390 return 1;
2391 }
2392
2393 static void
2394 dw2_forget_cached_source_info (struct objfile *objfile)
2395 {
2396 dw2_setup (objfile);
2397
2398 htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table,
2399 dw2_free_cached_file_names, NULL);
2400 }
2401
2402 /* Helper function for dw2_map_symtabs_matching_filename that expands
2403 the symtabs and calls the iterator. */
2404
2405 static int
2406 dw2_map_expand_apply (struct objfile *objfile,
2407 struct dwarf2_per_cu_data *per_cu,
2408 const char *name,
2409 const char *full_path, const char *real_path,
2410 int (*callback) (struct symtab *, void *),
2411 void *data)
2412 {
2413 struct symtab *last_made = objfile->symtabs;
2414
2415 /* Don't visit already-expanded CUs. */
2416 if (per_cu->v.quick->symtab)
2417 return 0;
2418
2419 /* This may expand more than one symtab, and we want to iterate over
2420 all of them. */
2421 dw2_instantiate_symtab (per_cu);
2422
2423 return iterate_over_some_symtabs (name, full_path, real_path, callback, data,
2424 objfile->symtabs, last_made);
2425 }
2426
2427 /* Implementation of the map_symtabs_matching_filename method. */
2428
2429 static int
2430 dw2_map_symtabs_matching_filename (struct objfile *objfile, const char *name,
2431 const char *full_path, const char *real_path,
2432 int (*callback) (struct symtab *, void *),
2433 void *data)
2434 {
2435 int i;
2436 const char *name_basename = lbasename (name);
2437 int name_len = strlen (name);
2438 int is_abs = IS_ABSOLUTE_PATH (name);
2439
2440 dw2_setup (objfile);
2441
2442 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2443 + dwarf2_per_objfile->n_type_units); ++i)
2444 {
2445 int j;
2446 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2447 struct quick_file_names *file_data;
2448
2449 /* We only need to look at symtabs not already expanded. */
2450 if (per_cu->v.quick->symtab)
2451 continue;
2452
2453 file_data = dw2_get_file_names (objfile, per_cu);
2454 if (file_data == NULL)
2455 continue;
2456
2457 for (j = 0; j < file_data->num_file_names; ++j)
2458 {
2459 const char *this_name = file_data->file_names[j];
2460
2461 if (FILENAME_CMP (name, this_name) == 0
2462 || (!is_abs && compare_filenames_for_search (this_name,
2463 name, name_len)))
2464 {
2465 if (dw2_map_expand_apply (objfile, per_cu,
2466 name, full_path, real_path,
2467 callback, data))
2468 return 1;
2469 }
2470
2471 /* Before we invoke realpath, which can get expensive when many
2472 files are involved, do a quick comparison of the basenames. */
2473 if (! basenames_may_differ
2474 && FILENAME_CMP (lbasename (this_name), name_basename) != 0)
2475 continue;
2476
2477 if (full_path != NULL)
2478 {
2479 const char *this_real_name = dw2_get_real_path (objfile,
2480 file_data, j);
2481
2482 if (this_real_name != NULL
2483 && (FILENAME_CMP (full_path, this_real_name) == 0
2484 || (!is_abs
2485 && compare_filenames_for_search (this_real_name,
2486 name, name_len))))
2487 {
2488 if (dw2_map_expand_apply (objfile, per_cu,
2489 name, full_path, real_path,
2490 callback, data))
2491 return 1;
2492 }
2493 }
2494
2495 if (real_path != NULL)
2496 {
2497 const char *this_real_name = dw2_get_real_path (objfile,
2498 file_data, j);
2499
2500 if (this_real_name != NULL
2501 && (FILENAME_CMP (real_path, this_real_name) == 0
2502 || (!is_abs
2503 && compare_filenames_for_search (this_real_name,
2504 name, name_len))))
2505 {
2506 if (dw2_map_expand_apply (objfile, per_cu,
2507 name, full_path, real_path,
2508 callback, data))
2509 return 1;
2510 }
2511 }
2512 }
2513 }
2514
2515 return 0;
2516 }
2517
2518 static struct symtab *
2519 dw2_lookup_symbol (struct objfile *objfile, int block_index,
2520 const char *name, domain_enum domain)
2521 {
2522 /* We do all the work in the pre_expand_symtabs_matching hook
2523 instead. */
2524 return NULL;
2525 }
2526
2527 /* A helper function that expands all symtabs that hold an object
2528 named NAME. */
2529
2530 static void
2531 dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name)
2532 {
2533 dw2_setup (objfile);
2534
2535 /* index_table is NULL if OBJF_READNOW. */
2536 if (dwarf2_per_objfile->index_table)
2537 {
2538 offset_type *vec;
2539
2540 if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
2541 name, &vec))
2542 {
2543 offset_type i, len = MAYBE_SWAP (*vec);
2544 for (i = 0; i < len; ++i)
2545 {
2546 offset_type cu_index = MAYBE_SWAP (vec[i + 1]);
2547 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index);
2548
2549 dw2_instantiate_symtab (per_cu);
2550 }
2551 }
2552 }
2553 }
2554
2555 static void
2556 dw2_pre_expand_symtabs_matching (struct objfile *objfile,
2557 enum block_enum block_kind, const char *name,
2558 domain_enum domain)
2559 {
2560 dw2_do_expand_symtabs_matching (objfile, name);
2561 }
2562
2563 static void
2564 dw2_print_stats (struct objfile *objfile)
2565 {
2566 int i, count;
2567
2568 dw2_setup (objfile);
2569 count = 0;
2570 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2571 + dwarf2_per_objfile->n_type_units); ++i)
2572 {
2573 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2574
2575 if (!per_cu->v.quick->symtab)
2576 ++count;
2577 }
2578 printf_filtered (_(" Number of unread CUs: %d\n"), count);
2579 }
2580
2581 static void
2582 dw2_dump (struct objfile *objfile)
2583 {
2584 /* Nothing worth printing. */
2585 }
2586
2587 static void
2588 dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets,
2589 struct section_offsets *delta)
2590 {
2591 /* There's nothing to relocate here. */
2592 }
2593
2594 static void
2595 dw2_expand_symtabs_for_function (struct objfile *objfile,
2596 const char *func_name)
2597 {
2598 dw2_do_expand_symtabs_matching (objfile, func_name);
2599 }
2600
2601 static void
2602 dw2_expand_all_symtabs (struct objfile *objfile)
2603 {
2604 int i;
2605
2606 dw2_setup (objfile);
2607
2608 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2609 + dwarf2_per_objfile->n_type_units); ++i)
2610 {
2611 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2612
2613 dw2_instantiate_symtab (per_cu);
2614 }
2615 }
2616
2617 static void
2618 dw2_expand_symtabs_with_filename (struct objfile *objfile,
2619 const char *filename)
2620 {
2621 int i;
2622
2623 dw2_setup (objfile);
2624
2625 /* We don't need to consider type units here.
2626 This is only called for examining code, e.g. expand_line_sal.
2627 There can be an order of magnitude (or more) more type units
2628 than comp units, and we avoid them if we can. */
2629
2630 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
2631 {
2632 int j;
2633 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2634 struct quick_file_names *file_data;
2635
2636 /* We only need to look at symtabs not already expanded. */
2637 if (per_cu->v.quick->symtab)
2638 continue;
2639
2640 file_data = dw2_get_file_names (objfile, per_cu);
2641 if (file_data == NULL)
2642 continue;
2643
2644 for (j = 0; j < file_data->num_file_names; ++j)
2645 {
2646 const char *this_name = file_data->file_names[j];
2647 if (FILENAME_CMP (this_name, filename) == 0)
2648 {
2649 dw2_instantiate_symtab (per_cu);
2650 break;
2651 }
2652 }
2653 }
2654 }
2655
2656 static const char *
2657 dw2_find_symbol_file (struct objfile *objfile, const char *name)
2658 {
2659 struct dwarf2_per_cu_data *per_cu;
2660 offset_type *vec;
2661 struct quick_file_names *file_data;
2662
2663 dw2_setup (objfile);
2664
2665 /* index_table is NULL if OBJF_READNOW. */
2666 if (!dwarf2_per_objfile->index_table)
2667 {
2668 struct symtab *s;
2669
2670 ALL_OBJFILE_SYMTABS (objfile, s)
2671 if (s->primary)
2672 {
2673 struct blockvector *bv = BLOCKVECTOR (s);
2674 const struct block *block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
2675 struct symbol *sym = lookup_block_symbol (block, name, VAR_DOMAIN);
2676
2677 if (sym)
2678 return sym->symtab->filename;
2679 }
2680 return NULL;
2681 }
2682
2683 if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
2684 name, &vec))
2685 return NULL;
2686
2687 /* Note that this just looks at the very first one named NAME -- but
2688 actually we are looking for a function. find_main_filename
2689 should be rewritten so that it doesn't require a custom hook. It
2690 could just use the ordinary symbol tables. */
2691 /* vec[0] is the length, which must always be >0. */
2692 per_cu = dw2_get_cu (MAYBE_SWAP (vec[1]));
2693
2694 file_data = dw2_get_file_names (objfile, per_cu);
2695 if (file_data == NULL)
2696 return NULL;
2697
2698 return file_data->file_names[file_data->num_file_names - 1];
2699 }
2700
2701 static void
2702 dw2_map_matching_symbols (const char * name, domain_enum namespace,
2703 struct objfile *objfile, int global,
2704 int (*callback) (struct block *,
2705 struct symbol *, void *),
2706 void *data, symbol_compare_ftype *match,
2707 symbol_compare_ftype *ordered_compare)
2708 {
2709 /* Currently unimplemented; used for Ada. The function can be called if the
2710 current language is Ada for a non-Ada objfile using GNU index. As Ada
2711 does not look for non-Ada symbols this function should just return. */
2712 }
2713
2714 static void
2715 dw2_expand_symtabs_matching
2716 (struct objfile *objfile,
2717 int (*file_matcher) (const char *, void *),
2718 int (*name_matcher) (const char *, void *),
2719 enum search_domain kind,
2720 void *data)
2721 {
2722 int i;
2723 offset_type iter;
2724 struct mapped_index *index;
2725
2726 dw2_setup (objfile);
2727
2728 /* index_table is NULL if OBJF_READNOW. */
2729 if (!dwarf2_per_objfile->index_table)
2730 return;
2731 index = dwarf2_per_objfile->index_table;
2732
2733 if (file_matcher != NULL)
2734 {
2735 struct cleanup *cleanup;
2736 htab_t visited_found, visited_not_found;
2737
2738 visited_found = htab_create_alloc (10,
2739 htab_hash_pointer, htab_eq_pointer,
2740 NULL, xcalloc, xfree);
2741 cleanup = make_cleanup_htab_delete (visited_found);
2742 visited_not_found = htab_create_alloc (10,
2743 htab_hash_pointer, htab_eq_pointer,
2744 NULL, xcalloc, xfree);
2745 make_cleanup_htab_delete (visited_not_found);
2746
2747 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2748 + dwarf2_per_objfile->n_type_units); ++i)
2749 {
2750 int j;
2751 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2752 struct quick_file_names *file_data;
2753 void **slot;
2754
2755 per_cu->v.quick->mark = 0;
2756
2757 /* We only need to look at symtabs not already expanded. */
2758 if (per_cu->v.quick->symtab)
2759 continue;
2760
2761 file_data = dw2_get_file_names (objfile, per_cu);
2762 if (file_data == NULL)
2763 continue;
2764
2765 if (htab_find (visited_not_found, file_data) != NULL)
2766 continue;
2767 else if (htab_find (visited_found, file_data) != NULL)
2768 {
2769 per_cu->v.quick->mark = 1;
2770 continue;
2771 }
2772
2773 for (j = 0; j < file_data->num_file_names; ++j)
2774 {
2775 if (file_matcher (file_data->file_names[j], data))
2776 {
2777 per_cu->v.quick->mark = 1;
2778 break;
2779 }
2780 }
2781
2782 slot = htab_find_slot (per_cu->v.quick->mark
2783 ? visited_found
2784 : visited_not_found,
2785 file_data, INSERT);
2786 *slot = file_data;
2787 }
2788
2789 do_cleanups (cleanup);
2790 }
2791
2792 for (iter = 0; iter < index->symbol_table_slots; ++iter)
2793 {
2794 offset_type idx = 2 * iter;
2795 const char *name;
2796 offset_type *vec, vec_len, vec_idx;
2797
2798 if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0)
2799 continue;
2800
2801 name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]);
2802
2803 if (! (*name_matcher) (name, data))
2804 continue;
2805
2806 /* The name was matched, now expand corresponding CUs that were
2807 marked. */
2808 vec = (offset_type *) (index->constant_pool
2809 + MAYBE_SWAP (index->symbol_table[idx + 1]));
2810 vec_len = MAYBE_SWAP (vec[0]);
2811 for (vec_idx = 0; vec_idx < vec_len; ++vec_idx)
2812 {
2813 struct dwarf2_per_cu_data *per_cu;
2814
2815 per_cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1]));
2816 if (file_matcher == NULL || per_cu->v.quick->mark)
2817 dw2_instantiate_symtab (per_cu);
2818 }
2819 }
2820 }
2821
2822 static struct symtab *
2823 dw2_find_pc_sect_symtab (struct objfile *objfile,
2824 struct minimal_symbol *msymbol,
2825 CORE_ADDR pc,
2826 struct obj_section *section,
2827 int warn_if_readin)
2828 {
2829 struct dwarf2_per_cu_data *data;
2830
2831 dw2_setup (objfile);
2832
2833 if (!objfile->psymtabs_addrmap)
2834 return NULL;
2835
2836 data = addrmap_find (objfile->psymtabs_addrmap, pc);
2837 if (!data)
2838 return NULL;
2839
2840 if (warn_if_readin && data->v.quick->symtab)
2841 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2842 paddress (get_objfile_arch (objfile), pc));
2843
2844 return dw2_instantiate_symtab (data);
2845 }
2846
2847 static void
2848 dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
2849 void *data, int need_fullname)
2850 {
2851 int i;
2852 struct cleanup *cleanup;
2853 htab_t visited = htab_create_alloc (10, htab_hash_pointer, htab_eq_pointer,
2854 NULL, xcalloc, xfree);
2855
2856 cleanup = make_cleanup_htab_delete (visited);
2857 dw2_setup (objfile);
2858
2859 /* We can ignore file names coming from already-expanded CUs. */
2860 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2861 + dwarf2_per_objfile->n_type_units); ++i)
2862 {
2863 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2864
2865 if (per_cu->v.quick->symtab)
2866 {
2867 void **slot = htab_find_slot (visited, per_cu->v.quick->file_names,
2868 INSERT);
2869
2870 *slot = per_cu->v.quick->file_names;
2871 }
2872 }
2873
2874 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2875 + dwarf2_per_objfile->n_type_units); ++i)
2876 {
2877 int j;
2878 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2879 struct quick_file_names *file_data;
2880 void **slot;
2881
2882 /* We only need to look at symtabs not already expanded. */
2883 if (per_cu->v.quick->symtab)
2884 continue;
2885
2886 file_data = dw2_get_file_names (objfile, per_cu);
2887 if (file_data == NULL)
2888 continue;
2889
2890 slot = htab_find_slot (visited, file_data, INSERT);
2891 if (*slot)
2892 {
2893 /* Already visited. */
2894 continue;
2895 }
2896 *slot = file_data;
2897
2898 for (j = 0; j < file_data->num_file_names; ++j)
2899 {
2900 const char *this_real_name;
2901
2902 if (need_fullname)
2903 this_real_name = dw2_get_real_path (objfile, file_data, j);
2904 else
2905 this_real_name = NULL;
2906 (*fun) (file_data->file_names[j], this_real_name, data);
2907 }
2908 }
2909
2910 do_cleanups (cleanup);
2911 }
2912
2913 static int
2914 dw2_has_symbols (struct objfile *objfile)
2915 {
2916 return 1;
2917 }
2918
2919 const struct quick_symbol_functions dwarf2_gdb_index_functions =
2920 {
2921 dw2_has_symbols,
2922 dw2_find_last_source_symtab,
2923 dw2_forget_cached_source_info,
2924 dw2_map_symtabs_matching_filename,
2925 dw2_lookup_symbol,
2926 dw2_pre_expand_symtabs_matching,
2927 dw2_print_stats,
2928 dw2_dump,
2929 dw2_relocate,
2930 dw2_expand_symtabs_for_function,
2931 dw2_expand_all_symtabs,
2932 dw2_expand_symtabs_with_filename,
2933 dw2_find_symbol_file,
2934 dw2_map_matching_symbols,
2935 dw2_expand_symtabs_matching,
2936 dw2_find_pc_sect_symtab,
2937 dw2_map_symbol_filenames
2938 };
2939
2940 /* Initialize for reading DWARF for this objfile. Return 0 if this
2941 file will use psymtabs, or 1 if using the GNU index. */
2942
2943 int
2944 dwarf2_initialize_objfile (struct objfile *objfile)
2945 {
2946 /* If we're about to read full symbols, don't bother with the
2947 indices. In this case we also don't care if some other debug
2948 format is making psymtabs, because they are all about to be
2949 expanded anyway. */
2950 if ((objfile->flags & OBJF_READNOW))
2951 {
2952 int i;
2953
2954 dwarf2_per_objfile->using_index = 1;
2955 create_all_comp_units (objfile);
2956 create_all_type_units (objfile);
2957 dwarf2_per_objfile->quick_file_names_table =
2958 create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
2959
2960 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2961 + dwarf2_per_objfile->n_type_units); ++i)
2962 {
2963 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2964
2965 per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2966 struct dwarf2_per_cu_quick_data);
2967 }
2968
2969 /* Return 1 so that gdb sees the "quick" functions. However,
2970 these functions will be no-ops because we will have expanded
2971 all symtabs. */
2972 return 1;
2973 }
2974
2975 if (dwarf2_read_index (objfile))
2976 return 1;
2977
2978 return 0;
2979 }
2980
2981 \f
2982
2983 /* Build a partial symbol table. */
2984
2985 void
2986 dwarf2_build_psymtabs (struct objfile *objfile)
2987 {
2988 if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0)
2989 {
2990 init_psymbol_list (objfile, 1024);
2991 }
2992
2993 dwarf2_build_psymtabs_hard (objfile);
2994 }
2995
2996 /* Return TRUE if OFFSET is within CU_HEADER. */
2997
2998 static inline int
2999 offset_in_cu_p (const struct comp_unit_head *cu_header, sect_offset offset)
3000 {
3001 sect_offset bottom = { cu_header->offset.sect_off };
3002 sect_offset top = { (cu_header->offset.sect_off + cu_header->length
3003 + cu_header->initial_length_size) };
3004
3005 return (offset.sect_off >= bottom.sect_off && offset.sect_off < top.sect_off);
3006 }
3007
3008 /* Read in the comp unit header information from the debug_info at info_ptr.
3009 NOTE: This leaves members offset, first_die_offset to be filled in
3010 by the caller. */
3011
3012 static gdb_byte *
3013 read_comp_unit_head (struct comp_unit_head *cu_header,
3014 gdb_byte *info_ptr, bfd *abfd)
3015 {
3016 int signed_addr;
3017 unsigned int bytes_read;
3018
3019 cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read);
3020 cu_header->initial_length_size = bytes_read;
3021 cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
3022 info_ptr += bytes_read;
3023 cu_header->version = read_2_bytes (abfd, info_ptr);
3024 info_ptr += 2;
3025 cu_header->abbrev_offset.sect_off = read_offset (abfd, info_ptr, cu_header,
3026 &bytes_read);
3027 info_ptr += bytes_read;
3028 cu_header->addr_size = read_1_byte (abfd, info_ptr);
3029 info_ptr += 1;
3030 signed_addr = bfd_get_sign_extend_vma (abfd);
3031 if (signed_addr < 0)
3032 internal_error (__FILE__, __LINE__,
3033 _("read_comp_unit_head: dwarf from non elf file"));
3034 cu_header->signed_addr_p = signed_addr;
3035
3036 return info_ptr;
3037 }
3038
3039 /* Subroutine of read_and_check_comp_unit_head and
3040 read_and_check_type_unit_head to simplify them.
3041 Perform various error checking on the header. */
3042
3043 static void
3044 error_check_comp_unit_head (struct comp_unit_head *header,
3045 struct dwarf2_section_info *section)
3046 {
3047 bfd *abfd = section->asection->owner;
3048 const char *filename = bfd_get_filename (abfd);
3049
3050 if (header->version != 2 && header->version != 3 && header->version != 4)
3051 error (_("Dwarf Error: wrong version in compilation unit header "
3052 "(is %d, should be 2, 3, or 4) [in module %s]"), header->version,
3053 filename);
3054
3055 if (header->abbrev_offset.sect_off
3056 >= dwarf2_section_size (dwarf2_per_objfile->objfile,
3057 &dwarf2_per_objfile->abbrev))
3058 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3059 "(offset 0x%lx + 6) [in module %s]"),
3060 (long) header->abbrev_offset.sect_off, (long) header->offset.sect_off,
3061 filename);
3062
3063 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3064 avoid potential 32-bit overflow. */
3065 if (((unsigned long) header->offset.sect_off
3066 + header->length + header->initial_length_size)
3067 > section->size)
3068 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3069 "(offset 0x%lx + 0) [in module %s]"),
3070 (long) header->length, (long) header->offset.sect_off,
3071 filename);
3072 }
3073
3074 /* Read in a CU/TU header and perform some basic error checking.
3075 The contents of the header are stored in HEADER.
3076 The result is a pointer to the start of the first DIE. */
3077
3078 static gdb_byte *
3079 read_and_check_comp_unit_head (struct comp_unit_head *header,
3080 struct dwarf2_section_info *section,
3081 gdb_byte *info_ptr,
3082 int is_debug_types_section)
3083 {
3084 gdb_byte *beg_of_comp_unit = info_ptr;
3085 bfd *abfd = section->asection->owner;
3086
3087 header->offset.sect_off = beg_of_comp_unit - section->buffer;
3088
3089 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
3090
3091 /* If we're reading a type unit, skip over the signature and
3092 type_offset fields. */
3093 if (is_debug_types_section)
3094 info_ptr += 8 /*signature*/ + header->offset_size;
3095
3096 header->first_die_offset.cu_off = info_ptr - beg_of_comp_unit;
3097
3098 error_check_comp_unit_head (header, section);
3099
3100 return info_ptr;
3101 }
3102
3103 /* Read in the types comp unit header information from .debug_types entry at
3104 types_ptr. The result is a pointer to one past the end of the header. */
3105
3106 static gdb_byte *
3107 read_and_check_type_unit_head (struct comp_unit_head *header,
3108 struct dwarf2_section_info *section,
3109 gdb_byte *info_ptr,
3110 ULONGEST *signature, cu_offset *type_offset)
3111 {
3112 gdb_byte *beg_of_comp_unit = info_ptr;
3113 bfd *abfd = section->asection->owner;
3114
3115 header->offset.sect_off = beg_of_comp_unit - section->buffer;
3116
3117 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
3118
3119 /* If we're reading a type unit, skip over the signature and
3120 type_offset fields. */
3121 if (signature != NULL)
3122 *signature = read_8_bytes (abfd, info_ptr);
3123 info_ptr += 8;
3124 if (type_offset != NULL)
3125 type_offset->cu_off = read_offset_1 (abfd, info_ptr, header->offset_size);
3126 info_ptr += header->offset_size;
3127
3128 header->first_die_offset.cu_off = info_ptr - beg_of_comp_unit;
3129
3130 error_check_comp_unit_head (header, section);
3131
3132 return info_ptr;
3133 }
3134
3135 /* Allocate a new partial symtab for file named NAME and mark this new
3136 partial symtab as being an include of PST. */
3137
3138 static void
3139 dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst,
3140 struct objfile *objfile)
3141 {
3142 struct partial_symtab *subpst = allocate_psymtab (name, objfile);
3143
3144 subpst->section_offsets = pst->section_offsets;
3145 subpst->textlow = 0;
3146 subpst->texthigh = 0;
3147
3148 subpst->dependencies = (struct partial_symtab **)
3149 obstack_alloc (&objfile->objfile_obstack,
3150 sizeof (struct partial_symtab *));
3151 subpst->dependencies[0] = pst;
3152 subpst->number_of_dependencies = 1;
3153
3154 subpst->globals_offset = 0;
3155 subpst->n_global_syms = 0;
3156 subpst->statics_offset = 0;
3157 subpst->n_static_syms = 0;
3158 subpst->symtab = NULL;
3159 subpst->read_symtab = pst->read_symtab;
3160 subpst->readin = 0;
3161
3162 /* No private part is necessary for include psymtabs. This property
3163 can be used to differentiate between such include psymtabs and
3164 the regular ones. */
3165 subpst->read_symtab_private = NULL;
3166 }
3167
3168 /* Read the Line Number Program data and extract the list of files
3169 included by the source file represented by PST. Build an include
3170 partial symtab for each of these included files. */
3171
3172 static void
3173 dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
3174 struct die_info *die,
3175 struct partial_symtab *pst)
3176 {
3177 struct objfile *objfile = cu->objfile;
3178 bfd *abfd = objfile->obfd;
3179 struct line_header *lh = NULL;
3180 struct attribute *attr;
3181
3182 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
3183 if (attr)
3184 {
3185 unsigned int line_offset = DW_UNSND (attr);
3186
3187 lh = dwarf_decode_line_header (line_offset, abfd, cu);
3188 }
3189 if (lh == NULL)
3190 return; /* No linetable, so no includes. */
3191
3192 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3193 dwarf_decode_lines (lh, pst->dirname, cu, pst, 1);
3194
3195 free_line_header (lh);
3196 }
3197
3198 static hashval_t
3199 hash_signatured_type (const void *item)
3200 {
3201 const struct signatured_type *sig_type = item;
3202
3203 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3204 return sig_type->signature;
3205 }
3206
3207 static int
3208 eq_signatured_type (const void *item_lhs, const void *item_rhs)
3209 {
3210 const struct signatured_type *lhs = item_lhs;
3211 const struct signatured_type *rhs = item_rhs;
3212
3213 return lhs->signature == rhs->signature;
3214 }
3215
3216 /* Allocate a hash table for signatured types. */
3217
3218 static htab_t
3219 allocate_signatured_type_table (struct objfile *objfile)
3220 {
3221 return htab_create_alloc_ex (41,
3222 hash_signatured_type,
3223 eq_signatured_type,
3224 NULL,
3225 &objfile->objfile_obstack,
3226 hashtab_obstack_allocate,
3227 dummy_obstack_deallocate);
3228 }
3229
3230 /* A helper function to add a signatured type CU to a table. */
3231
3232 static int
3233 add_signatured_type_cu_to_table (void **slot, void *datum)
3234 {
3235 struct signatured_type *sigt = *slot;
3236 struct dwarf2_per_cu_data ***datap = datum;
3237
3238 **datap = &sigt->per_cu;
3239 ++*datap;
3240
3241 return 1;
3242 }
3243
3244 /* Create the hash table of all entries in the .debug_types section(s).
3245 The result is zero if there are no .debug_types sections,
3246 otherwise non-zero. */
3247
3248 static int
3249 create_all_type_units (struct objfile *objfile)
3250 {
3251 htab_t types_htab = NULL;
3252 struct dwarf2_per_cu_data **iter;
3253 int ix;
3254 struct dwarf2_section_info *section;
3255
3256 if (VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types))
3257 {
3258 dwarf2_per_objfile->signatured_types = NULL;
3259 return 0;
3260 }
3261
3262 for (ix = 0;
3263 VEC_iterate (dwarf2_section_info_def, dwarf2_per_objfile->types,
3264 ix, section);
3265 ++ix)
3266 {
3267 gdb_byte *info_ptr, *end_ptr;
3268
3269 dwarf2_read_section (objfile, section);
3270 info_ptr = section->buffer;
3271
3272 if (info_ptr == NULL)
3273 continue;
3274
3275 if (types_htab == NULL)
3276 types_htab = allocate_signatured_type_table (objfile);
3277
3278 if (dwarf2_die_debug)
3279 fprintf_unfiltered (gdb_stdlog, "Signatured types:\n");
3280
3281 end_ptr = info_ptr + section->size;
3282 while (info_ptr < end_ptr)
3283 {
3284 sect_offset offset;
3285 cu_offset type_offset;
3286 ULONGEST signature;
3287 struct signatured_type *sig_type;
3288 void **slot;
3289 gdb_byte *ptr = info_ptr;
3290 struct comp_unit_head header;
3291
3292 offset.sect_off = ptr - section->buffer;
3293
3294 /* We need to read the type's signature in order to build the hash
3295 table, but we don't need anything else just yet. */
3296
3297 ptr = read_and_check_type_unit_head (&header, section, ptr,
3298 &signature, &type_offset);
3299
3300 /* Skip dummy type units. */
3301 if (ptr >= end_ptr || peek_abbrev_code (objfile->obfd, ptr) == 0)
3302 {
3303 info_ptr = info_ptr + header.initial_length_size + header.length;
3304 continue;
3305 }
3306
3307 sig_type = obstack_alloc (&objfile->objfile_obstack, sizeof (*sig_type));
3308 memset (sig_type, 0, sizeof (*sig_type));
3309 sig_type->signature = signature;
3310 sig_type->type_offset = type_offset;
3311 sig_type->per_cu.objfile = objfile;
3312 sig_type->per_cu.debug_types_section = section;
3313 sig_type->per_cu.offset = offset;
3314
3315 slot = htab_find_slot (types_htab, sig_type, INSERT);
3316 gdb_assert (slot != NULL);
3317 if (*slot != NULL)
3318 {
3319 const struct signatured_type *dup_sig = *slot;
3320
3321 complaint (&symfile_complaints,
3322 _("debug type entry at offset 0x%x is duplicate to the "
3323 "entry at offset 0x%x, signature 0x%s"),
3324 offset.sect_off, dup_sig->per_cu.offset.sect_off,
3325 phex (signature, sizeof (signature)));
3326 gdb_assert (signature == dup_sig->signature);
3327 }
3328 *slot = sig_type;
3329
3330 if (dwarf2_die_debug)
3331 fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n",
3332 offset.sect_off,
3333 phex (signature, sizeof (signature)));
3334
3335 info_ptr = info_ptr + header.initial_length_size + header.length;
3336 }
3337 }
3338
3339 dwarf2_per_objfile->signatured_types = types_htab;
3340
3341 dwarf2_per_objfile->n_type_units = htab_elements (types_htab);
3342 dwarf2_per_objfile->all_type_units
3343 = obstack_alloc (&objfile->objfile_obstack,
3344 dwarf2_per_objfile->n_type_units
3345 * sizeof (struct dwarf2_per_cu_data *));
3346 iter = &dwarf2_per_objfile->all_type_units[0];
3347 htab_traverse_noresize (types_htab, add_signatured_type_cu_to_table, &iter);
3348 gdb_assert (iter - &dwarf2_per_objfile->all_type_units[0]
3349 == dwarf2_per_objfile->n_type_units);
3350
3351 return 1;
3352 }
3353
3354 /* Lookup a signature based type for DW_FORM_ref_sig8.
3355 Returns NULL if signature SIG is not present in the table. */
3356
3357 static struct signatured_type *
3358 lookup_signatured_type (ULONGEST sig)
3359 {
3360 struct signatured_type find_entry, *entry;
3361
3362 if (dwarf2_per_objfile->signatured_types == NULL)
3363 {
3364 complaint (&symfile_complaints,
3365 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3366 return NULL;
3367 }
3368
3369 find_entry.signature = sig;
3370 entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
3371 return entry;
3372 }
3373
3374 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3375
3376 static void
3377 init_cu_die_reader (struct die_reader_specs *reader,
3378 struct dwarf2_cu *cu)
3379 {
3380 reader->abfd = cu->objfile->obfd;
3381 reader->cu = cu;
3382 if (cu->per_cu->debug_types_section)
3383 {
3384 gdb_assert (cu->per_cu->debug_types_section->readin);
3385 reader->buffer = cu->per_cu->debug_types_section->buffer;
3386 }
3387 else
3388 {
3389 gdb_assert (dwarf2_per_objfile->info.readin);
3390 reader->buffer = dwarf2_per_objfile->info.buffer;
3391 }
3392 }
3393
3394 /* Find the base address of the compilation unit for range lists and
3395 location lists. It will normally be specified by DW_AT_low_pc.
3396 In DWARF-3 draft 4, the base address could be overridden by
3397 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3398 compilation units with discontinuous ranges. */
3399
3400 static void
3401 dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
3402 {
3403 struct attribute *attr;
3404
3405 cu->base_known = 0;
3406 cu->base_address = 0;
3407
3408 attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
3409 if (attr)
3410 {
3411 cu->base_address = DW_ADDR (attr);
3412 cu->base_known = 1;
3413 }
3414 else
3415 {
3416 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
3417 if (attr)
3418 {
3419 cu->base_address = DW_ADDR (attr);
3420 cu->base_known = 1;
3421 }
3422 }
3423 }
3424
3425 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3426 to combine the common parts.
3427 Process compilation unit THIS_CU for a psymtab.
3428 SECTION is the section the CU/TU comes from,
3429 either .debug_info or .debug_types. */
3430
3431 static void
3432 process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu,
3433 struct dwarf2_section_info *section,
3434 int is_debug_types_section)
3435 {
3436 struct objfile *objfile = this_cu->objfile;
3437 bfd *abfd = objfile->obfd;
3438 gdb_byte *buffer = section->buffer;
3439 gdb_byte *info_ptr = buffer + this_cu->offset.sect_off;
3440 unsigned int buffer_size = section->size;
3441 gdb_byte *beg_of_comp_unit = info_ptr;
3442 struct die_info *comp_unit_die;
3443 struct partial_symtab *pst;
3444 CORE_ADDR baseaddr;
3445 struct cleanup *back_to_inner;
3446 struct dwarf2_cu cu;
3447 int has_children, has_pc_info;
3448 struct attribute *attr;
3449 CORE_ADDR best_lowpc = 0, best_highpc = 0;
3450 struct die_reader_specs reader_specs;
3451 const char *filename;
3452
3453 /* If this compilation unit was already read in, free the
3454 cached copy in order to read it in again. This is
3455 necessary because we skipped some symbols when we first
3456 read in the compilation unit (see load_partial_dies).
3457 This problem could be avoided, but the benefit is
3458 unclear. */
3459 if (this_cu->cu != NULL)
3460 free_one_cached_comp_unit (this_cu->cu);
3461
3462 /* Note that this is a pointer to our stack frame, being
3463 added to a global data structure. It will be cleaned up
3464 in free_stack_comp_unit when we finish with this
3465 compilation unit. */
3466 init_one_comp_unit (&cu, this_cu);
3467 back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
3468
3469 info_ptr = read_and_check_comp_unit_head (&cu.header, section, info_ptr,
3470 is_debug_types_section);
3471
3472 /* Skip dummy compilation units. */
3473 if (info_ptr >= buffer + buffer_size
3474 || peek_abbrev_code (abfd, info_ptr) == 0)
3475 {
3476 do_cleanups (back_to_inner);
3477 return;
3478 }
3479
3480 cu.list_in_scope = &file_symbols;
3481
3482 /* Read the abbrevs for this compilation unit into a table. */
3483 dwarf2_read_abbrevs (&cu);
3484 make_cleanup (dwarf2_free_abbrev_table, &cu);
3485
3486 /* Read the compilation unit die. */
3487 init_cu_die_reader (&reader_specs, &cu);
3488 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
3489 &has_children);
3490
3491 if (is_debug_types_section)
3492 {
3493 /* LENGTH has not been set yet for type units. */
3494 gdb_assert (this_cu->offset.sect_off == cu.header.offset.sect_off);
3495 this_cu->length = cu.header.length + cu.header.initial_length_size;
3496 }
3497 else if (comp_unit_die->tag == DW_TAG_partial_unit)
3498 {
3499 do_cleanups (back_to_inner);
3500 return;
3501 }
3502
3503 prepare_one_comp_unit (&cu, comp_unit_die);
3504
3505 /* Allocate a new partial symbol table structure. */
3506 attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu);
3507 if (attr == NULL || !DW_STRING (attr))
3508 filename = "";
3509 else
3510 filename = DW_STRING (attr);
3511 pst = start_psymtab_common (objfile, objfile->section_offsets,
3512 filename,
3513 /* TEXTLOW and TEXTHIGH are set below. */
3514 0,
3515 objfile->global_psymbols.next,
3516 objfile->static_psymbols.next);
3517 pst->psymtabs_addrmap_supported = 1;
3518
3519 attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu);
3520 if (attr != NULL)
3521 pst->dirname = DW_STRING (attr);
3522
3523 pst->read_symtab_private = this_cu;
3524
3525 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3526
3527 /* Store the function that reads in the rest of the symbol table. */
3528 pst->read_symtab = dwarf2_psymtab_to_symtab;
3529
3530 this_cu->v.psymtab = pst;
3531
3532 dwarf2_find_base_address (comp_unit_die, &cu);
3533
3534 /* Possibly set the default values of LOWPC and HIGHPC from
3535 `DW_AT_ranges'. */
3536 has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc,
3537 &best_highpc, &cu, pst);
3538 if (has_pc_info == 1 && best_lowpc < best_highpc)
3539 /* Store the contiguous range if it is not empty; it can be empty for
3540 CUs with no code. */
3541 addrmap_set_empty (objfile->psymtabs_addrmap,
3542 best_lowpc + baseaddr,
3543 best_highpc + baseaddr - 1, pst);
3544
3545 /* Check if comp unit has_children.
3546 If so, read the rest of the partial symbols from this comp unit.
3547 If not, there's no more debug_info for this comp unit. */
3548 if (has_children)
3549 {
3550 struct partial_die_info *first_die;
3551 CORE_ADDR lowpc, highpc;
3552
3553 lowpc = ((CORE_ADDR) -1);
3554 highpc = ((CORE_ADDR) 0);
3555
3556 first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu);
3557
3558 scan_partial_symbols (first_die, &lowpc, &highpc,
3559 ! has_pc_info, &cu);
3560
3561 /* If we didn't find a lowpc, set it to highpc to avoid
3562 complaints from `maint check'. */
3563 if (lowpc == ((CORE_ADDR) -1))
3564 lowpc = highpc;
3565
3566 /* If the compilation unit didn't have an explicit address range,
3567 then use the information extracted from its child dies. */
3568 if (! has_pc_info)
3569 {
3570 best_lowpc = lowpc;
3571 best_highpc = highpc;
3572 }
3573 }
3574 pst->textlow = best_lowpc + baseaddr;
3575 pst->texthigh = best_highpc + baseaddr;
3576
3577 pst->n_global_syms = objfile->global_psymbols.next -
3578 (objfile->global_psymbols.list + pst->globals_offset);
3579 pst->n_static_syms = objfile->static_psymbols.next -
3580 (objfile->static_psymbols.list + pst->statics_offset);
3581 sort_pst_symbols (pst);
3582
3583 if (is_debug_types_section)
3584 {
3585 /* It's not clear we want to do anything with stmt lists here.
3586 Waiting to see what gcc ultimately does. */
3587 }
3588 else
3589 {
3590 /* Get the list of files included in the current compilation unit,
3591 and build a psymtab for each of them. */
3592 dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst);
3593 }
3594
3595 do_cleanups (back_to_inner);
3596 }
3597
3598 /* Traversal function for htab_traverse_noresize.
3599 Process one .debug_types comp-unit. */
3600
3601 static int
3602 process_type_comp_unit (void **slot, void *info)
3603 {
3604 struct signatured_type *entry = (struct signatured_type *) *slot;
3605 struct dwarf2_per_cu_data *this_cu;
3606
3607 gdb_assert (info == NULL);
3608 this_cu = &entry->per_cu;
3609
3610 gdb_assert (this_cu->debug_types_section->readin);
3611 process_psymtab_comp_unit (this_cu, this_cu->debug_types_section, 1);
3612
3613 return 1;
3614 }
3615
3616 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3617 Build partial symbol tables for the .debug_types comp-units. */
3618
3619 static void
3620 build_type_psymtabs (struct objfile *objfile)
3621 {
3622 if (! create_all_type_units (objfile))
3623 return;
3624
3625 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
3626 process_type_comp_unit, NULL);
3627 }
3628
3629 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3630
3631 static void
3632 psymtabs_addrmap_cleanup (void *o)
3633 {
3634 struct objfile *objfile = o;
3635
3636 objfile->psymtabs_addrmap = NULL;
3637 }
3638
3639 /* Build the partial symbol table by doing a quick pass through the
3640 .debug_info and .debug_abbrev sections. */
3641
3642 static void
3643 dwarf2_build_psymtabs_hard (struct objfile *objfile)
3644 {
3645 struct cleanup *back_to, *addrmap_cleanup;
3646 struct obstack temp_obstack;
3647 int i;
3648
3649 dwarf2_per_objfile->reading_partial_symbols = 1;
3650
3651 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3652
3653 /* Any cached compilation units will be linked by the per-objfile
3654 read_in_chain. Make sure to free them when we're done. */
3655 back_to = make_cleanup (free_cached_comp_units, NULL);
3656
3657 build_type_psymtabs (objfile);
3658
3659 create_all_comp_units (objfile);
3660
3661 /* Create a temporary address map on a temporary obstack. We later
3662 copy this to the final obstack. */
3663 obstack_init (&temp_obstack);
3664 make_cleanup_obstack_free (&temp_obstack);
3665 objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack);
3666 addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile);
3667
3668 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
3669 {
3670 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
3671
3672 process_psymtab_comp_unit (per_cu, &dwarf2_per_objfile->info, 0);
3673 }
3674
3675 objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap,
3676 &objfile->objfile_obstack);
3677 discard_cleanups (addrmap_cleanup);
3678
3679 do_cleanups (back_to);
3680 }
3681
3682 /* Load the partial DIEs for a secondary CU into memory. */
3683
3684 static void
3685 load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu)
3686 {
3687 struct objfile *objfile = this_cu->objfile;
3688 bfd *abfd = objfile->obfd;
3689 gdb_byte *info_ptr;
3690 struct die_info *comp_unit_die;
3691 struct dwarf2_cu *cu;
3692 struct cleanup *free_abbrevs_cleanup, *free_cu_cleanup = NULL;
3693 int has_children;
3694 struct die_reader_specs reader_specs;
3695 int read_cu = 0;
3696 struct dwarf2_section_info *section = &dwarf2_per_objfile->info;
3697
3698 gdb_assert (! this_cu->debug_types_section);
3699
3700 gdb_assert (section->readin);
3701 info_ptr = section->buffer + this_cu->offset.sect_off;
3702
3703 if (this_cu->cu == NULL)
3704 {
3705 cu = xmalloc (sizeof (*cu));
3706 init_one_comp_unit (cu, this_cu);
3707
3708 read_cu = 1;
3709
3710 /* If an error occurs while loading, release our storage. */
3711 free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu);
3712
3713 info_ptr = read_and_check_comp_unit_head (&cu->header, section, info_ptr,
3714 0);
3715
3716 /* Skip dummy compilation units. */
3717 if (info_ptr >= (section->buffer + section->size)
3718 || peek_abbrev_code (abfd, info_ptr) == 0)
3719 {
3720 do_cleanups (free_cu_cleanup);
3721 return;
3722 }
3723 }
3724 else
3725 {
3726 cu = this_cu->cu;
3727 info_ptr += cu->header.first_die_offset.cu_off;
3728 }
3729
3730 /* Read the abbrevs for this compilation unit into a table. */
3731 gdb_assert (cu->dwarf2_abbrevs == NULL);
3732 dwarf2_read_abbrevs (cu);
3733 free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu);
3734
3735 /* Read the compilation unit die. */
3736 init_cu_die_reader (&reader_specs, cu);
3737 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
3738 &has_children);
3739
3740 prepare_one_comp_unit (cu, comp_unit_die);
3741
3742 /* Check if comp unit has_children.
3743 If so, read the rest of the partial symbols from this comp unit.
3744 If not, there's no more debug_info for this comp unit. */
3745 if (has_children)
3746 load_partial_dies (abfd, section->buffer, info_ptr, 0, cu);
3747
3748 do_cleanups (free_abbrevs_cleanup);
3749
3750 if (read_cu)
3751 {
3752 /* We've successfully allocated this compilation unit. Let our
3753 caller clean it up when finished with it. */
3754 discard_cleanups (free_cu_cleanup);
3755
3756 /* Link this CU into read_in_chain. */
3757 this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
3758 dwarf2_per_objfile->read_in_chain = this_cu;
3759 }
3760 }
3761
3762 /* Create a list of all compilation units in OBJFILE.
3763 This is only done for -readnow and building partial symtabs. */
3764
3765 static void
3766 create_all_comp_units (struct objfile *objfile)
3767 {
3768 int n_allocated;
3769 int n_comp_units;
3770 struct dwarf2_per_cu_data **all_comp_units;
3771 gdb_byte *info_ptr;
3772
3773 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3774 info_ptr = dwarf2_per_objfile->info.buffer;
3775
3776 n_comp_units = 0;
3777 n_allocated = 10;
3778 all_comp_units = xmalloc (n_allocated
3779 * sizeof (struct dwarf2_per_cu_data *));
3780
3781 while (info_ptr < dwarf2_per_objfile->info.buffer
3782 + dwarf2_per_objfile->info.size)
3783 {
3784 unsigned int length, initial_length_size;
3785 struct dwarf2_per_cu_data *this_cu;
3786 sect_offset offset;
3787
3788 offset.sect_off = info_ptr - dwarf2_per_objfile->info.buffer;
3789
3790 /* Read just enough information to find out where the next
3791 compilation unit is. */
3792 length = read_initial_length (objfile->obfd, info_ptr,
3793 &initial_length_size);
3794
3795 /* Save the compilation unit for later lookup. */
3796 this_cu = obstack_alloc (&objfile->objfile_obstack,
3797 sizeof (struct dwarf2_per_cu_data));
3798 memset (this_cu, 0, sizeof (*this_cu));
3799 this_cu->offset = offset;
3800 this_cu->length = length + initial_length_size;
3801 this_cu->objfile = objfile;
3802
3803 if (n_comp_units == n_allocated)
3804 {
3805 n_allocated *= 2;
3806 all_comp_units = xrealloc (all_comp_units,
3807 n_allocated
3808 * sizeof (struct dwarf2_per_cu_data *));
3809 }
3810 all_comp_units[n_comp_units++] = this_cu;
3811
3812 info_ptr = info_ptr + this_cu->length;
3813 }
3814
3815 dwarf2_per_objfile->all_comp_units
3816 = obstack_alloc (&objfile->objfile_obstack,
3817 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
3818 memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units,
3819 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
3820 xfree (all_comp_units);
3821 dwarf2_per_objfile->n_comp_units = n_comp_units;
3822 }
3823
3824 /* Process all loaded DIEs for compilation unit CU, starting at
3825 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3826 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3827 DW_AT_ranges). If NEED_PC is set, then this function will set
3828 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3829 and record the covered ranges in the addrmap. */
3830
3831 static void
3832 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
3833 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
3834 {
3835 struct partial_die_info *pdi;
3836
3837 /* Now, march along the PDI's, descending into ones which have
3838 interesting children but skipping the children of the other ones,
3839 until we reach the end of the compilation unit. */
3840
3841 pdi = first_die;
3842
3843 while (pdi != NULL)
3844 {
3845 fixup_partial_die (pdi, cu);
3846
3847 /* Anonymous namespaces or modules have no name but have interesting
3848 children, so we need to look at them. Ditto for anonymous
3849 enums. */
3850
3851 if (pdi->name != NULL || pdi->tag == DW_TAG_namespace
3852 || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type)
3853 {
3854 switch (pdi->tag)
3855 {
3856 case DW_TAG_subprogram:
3857 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
3858 break;
3859 case DW_TAG_constant:
3860 case DW_TAG_variable:
3861 case DW_TAG_typedef:
3862 case DW_TAG_union_type:
3863 if (!pdi->is_declaration)
3864 {
3865 add_partial_symbol (pdi, cu);
3866 }
3867 break;
3868 case DW_TAG_class_type:
3869 case DW_TAG_interface_type:
3870 case DW_TAG_structure_type:
3871 if (!pdi->is_declaration)
3872 {
3873 add_partial_symbol (pdi, cu);
3874 }
3875 break;
3876 case DW_TAG_enumeration_type:
3877 if (!pdi->is_declaration)
3878 add_partial_enumeration (pdi, cu);
3879 break;
3880 case DW_TAG_base_type:
3881 case DW_TAG_subrange_type:
3882 /* File scope base type definitions are added to the partial
3883 symbol table. */
3884 add_partial_symbol (pdi, cu);
3885 break;
3886 case DW_TAG_namespace:
3887 add_partial_namespace (pdi, lowpc, highpc, need_pc, cu);
3888 break;
3889 case DW_TAG_module:
3890 add_partial_module (pdi, lowpc, highpc, need_pc, cu);
3891 break;
3892 default:
3893 break;
3894 }
3895 }
3896
3897 /* If the die has a sibling, skip to the sibling. */
3898
3899 pdi = pdi->die_sibling;
3900 }
3901 }
3902
3903 /* Functions used to compute the fully scoped name of a partial DIE.
3904
3905 Normally, this is simple. For C++, the parent DIE's fully scoped
3906 name is concatenated with "::" and the partial DIE's name. For
3907 Java, the same thing occurs except that "." is used instead of "::".
3908 Enumerators are an exception; they use the scope of their parent
3909 enumeration type, i.e. the name of the enumeration type is not
3910 prepended to the enumerator.
3911
3912 There are two complexities. One is DW_AT_specification; in this
3913 case "parent" means the parent of the target of the specification,
3914 instead of the direct parent of the DIE. The other is compilers
3915 which do not emit DW_TAG_namespace; in this case we try to guess
3916 the fully qualified name of structure types from their members'
3917 linkage names. This must be done using the DIE's children rather
3918 than the children of any DW_AT_specification target. We only need
3919 to do this for structures at the top level, i.e. if the target of
3920 any DW_AT_specification (if any; otherwise the DIE itself) does not
3921 have a parent. */
3922
3923 /* Compute the scope prefix associated with PDI's parent, in
3924 compilation unit CU. The result will be allocated on CU's
3925 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3926 field. NULL is returned if no prefix is necessary. */
3927 static char *
3928 partial_die_parent_scope (struct partial_die_info *pdi,
3929 struct dwarf2_cu *cu)
3930 {
3931 char *grandparent_scope;
3932 struct partial_die_info *parent, *real_pdi;
3933
3934 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3935 then this means the parent of the specification DIE. */
3936
3937 real_pdi = pdi;
3938 while (real_pdi->has_specification)
3939 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
3940
3941 parent = real_pdi->die_parent;
3942 if (parent == NULL)
3943 return NULL;
3944
3945 if (parent->scope_set)
3946 return parent->scope;
3947
3948 fixup_partial_die (parent, cu);
3949
3950 grandparent_scope = partial_die_parent_scope (parent, cu);
3951
3952 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3953 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3954 Work around this problem here. */
3955 if (cu->language == language_cplus
3956 && parent->tag == DW_TAG_namespace
3957 && strcmp (parent->name, "::") == 0
3958 && grandparent_scope == NULL)
3959 {
3960 parent->scope = NULL;
3961 parent->scope_set = 1;
3962 return NULL;
3963 }
3964
3965 if (pdi->tag == DW_TAG_enumerator)
3966 /* Enumerators should not get the name of the enumeration as a prefix. */
3967 parent->scope = grandparent_scope;
3968 else if (parent->tag == DW_TAG_namespace
3969 || parent->tag == DW_TAG_module
3970 || parent->tag == DW_TAG_structure_type
3971 || parent->tag == DW_TAG_class_type
3972 || parent->tag == DW_TAG_interface_type
3973 || parent->tag == DW_TAG_union_type
3974 || parent->tag == DW_TAG_enumeration_type)
3975 {
3976 if (grandparent_scope == NULL)
3977 parent->scope = parent->name;
3978 else
3979 parent->scope = typename_concat (&cu->comp_unit_obstack,
3980 grandparent_scope,
3981 parent->name, 0, cu);
3982 }
3983 else
3984 {
3985 /* FIXME drow/2004-04-01: What should we be doing with
3986 function-local names? For partial symbols, we should probably be
3987 ignoring them. */
3988 complaint (&symfile_complaints,
3989 _("unhandled containing DIE tag %d for DIE at %d"),
3990 parent->tag, pdi->offset.sect_off);
3991 parent->scope = grandparent_scope;
3992 }
3993
3994 parent->scope_set = 1;
3995 return parent->scope;
3996 }
3997
3998 /* Return the fully scoped name associated with PDI, from compilation unit
3999 CU. The result will be allocated with malloc. */
4000
4001 static char *
4002 partial_die_full_name (struct partial_die_info *pdi,
4003 struct dwarf2_cu *cu)
4004 {
4005 char *parent_scope;
4006
4007 /* If this is a template instantiation, we can not work out the
4008 template arguments from partial DIEs. So, unfortunately, we have
4009 to go through the full DIEs. At least any work we do building
4010 types here will be reused if full symbols are loaded later. */
4011 if (pdi->has_template_arguments)
4012 {
4013 fixup_partial_die (pdi, cu);
4014
4015 if (pdi->name != NULL && strchr (pdi->name, '<') == NULL)
4016 {
4017 struct die_info *die;
4018 struct attribute attr;
4019 struct dwarf2_cu *ref_cu = cu;
4020
4021 /* DW_FORM_ref_addr is using section offset. */
4022 attr.name = 0;
4023 attr.form = DW_FORM_ref_addr;
4024 attr.u.unsnd = pdi->offset.sect_off;
4025 die = follow_die_ref (NULL, &attr, &ref_cu);
4026
4027 return xstrdup (dwarf2_full_name (NULL, die, ref_cu));
4028 }
4029 }
4030
4031 parent_scope = partial_die_parent_scope (pdi, cu);
4032 if (parent_scope == NULL)
4033 return NULL;
4034 else
4035 return typename_concat (NULL, parent_scope, pdi->name, 0, cu);
4036 }
4037
4038 static void
4039 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
4040 {
4041 struct objfile *objfile = cu->objfile;
4042 CORE_ADDR addr = 0;
4043 char *actual_name = NULL;
4044 CORE_ADDR baseaddr;
4045 int built_actual_name = 0;
4046
4047 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4048
4049 actual_name = partial_die_full_name (pdi, cu);
4050 if (actual_name)
4051 built_actual_name = 1;
4052
4053 if (actual_name == NULL)
4054 actual_name = pdi->name;
4055
4056 switch (pdi->tag)
4057 {
4058 case DW_TAG_subprogram:
4059 if (pdi->is_external || cu->language == language_ada)
4060 {
4061 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
4062 of the global scope. But in Ada, we want to be able to access
4063 nested procedures globally. So all Ada subprograms are stored
4064 in the global scope. */
4065 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4066 mst_text, objfile); */
4067 add_psymbol_to_list (actual_name, strlen (actual_name),
4068 built_actual_name,
4069 VAR_DOMAIN, LOC_BLOCK,
4070 &objfile->global_psymbols,
4071 0, pdi->lowpc + baseaddr,
4072 cu->language, objfile);
4073 }
4074 else
4075 {
4076 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4077 mst_file_text, objfile); */
4078 add_psymbol_to_list (actual_name, strlen (actual_name),
4079 built_actual_name,
4080 VAR_DOMAIN, LOC_BLOCK,
4081 &objfile->static_psymbols,
4082 0, pdi->lowpc + baseaddr,
4083 cu->language, objfile);
4084 }
4085 break;
4086 case DW_TAG_constant:
4087 {
4088 struct psymbol_allocation_list *list;
4089
4090 if (pdi->is_external)
4091 list = &objfile->global_psymbols;
4092 else
4093 list = &objfile->static_psymbols;
4094 add_psymbol_to_list (actual_name, strlen (actual_name),
4095 built_actual_name, VAR_DOMAIN, LOC_STATIC,
4096 list, 0, 0, cu->language, objfile);
4097 }
4098 break;
4099 case DW_TAG_variable:
4100 if (pdi->locdesc)
4101 addr = decode_locdesc (pdi->locdesc, cu);
4102
4103 if (pdi->locdesc
4104 && addr == 0
4105 && !dwarf2_per_objfile->has_section_at_zero)
4106 {
4107 /* A global or static variable may also have been stripped
4108 out by the linker if unused, in which case its address
4109 will be nullified; do not add such variables into partial
4110 symbol table then. */
4111 }
4112 else if (pdi->is_external)
4113 {
4114 /* Global Variable.
4115 Don't enter into the minimal symbol tables as there is
4116 a minimal symbol table entry from the ELF symbols already.
4117 Enter into partial symbol table if it has a location
4118 descriptor or a type.
4119 If the location descriptor is missing, new_symbol will create
4120 a LOC_UNRESOLVED symbol, the address of the variable will then
4121 be determined from the minimal symbol table whenever the variable
4122 is referenced.
4123 The address for the partial symbol table entry is not
4124 used by GDB, but it comes in handy for debugging partial symbol
4125 table building. */
4126
4127 if (pdi->locdesc || pdi->has_type)
4128 add_psymbol_to_list (actual_name, strlen (actual_name),
4129 built_actual_name,
4130 VAR_DOMAIN, LOC_STATIC,
4131 &objfile->global_psymbols,
4132 0, addr + baseaddr,
4133 cu->language, objfile);
4134 }
4135 else
4136 {
4137 /* Static Variable. Skip symbols without location descriptors. */
4138 if (pdi->locdesc == NULL)
4139 {
4140 if (built_actual_name)
4141 xfree (actual_name);
4142 return;
4143 }
4144 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4145 mst_file_data, objfile); */
4146 add_psymbol_to_list (actual_name, strlen (actual_name),
4147 built_actual_name,
4148 VAR_DOMAIN, LOC_STATIC,
4149 &objfile->static_psymbols,
4150 0, addr + baseaddr,
4151 cu->language, objfile);
4152 }
4153 break;
4154 case DW_TAG_typedef:
4155 case DW_TAG_base_type:
4156 case DW_TAG_subrange_type:
4157 add_psymbol_to_list (actual_name, strlen (actual_name),
4158 built_actual_name,
4159 VAR_DOMAIN, LOC_TYPEDEF,
4160 &objfile->static_psymbols,
4161 0, (CORE_ADDR) 0, cu->language, objfile);
4162 break;
4163 case DW_TAG_namespace:
4164 add_psymbol_to_list (actual_name, strlen (actual_name),
4165 built_actual_name,
4166 VAR_DOMAIN, LOC_TYPEDEF,
4167 &objfile->global_psymbols,
4168 0, (CORE_ADDR) 0, cu->language, objfile);
4169 break;
4170 case DW_TAG_class_type:
4171 case DW_TAG_interface_type:
4172 case DW_TAG_structure_type:
4173 case DW_TAG_union_type:
4174 case DW_TAG_enumeration_type:
4175 /* Skip external references. The DWARF standard says in the section
4176 about "Structure, Union, and Class Type Entries": "An incomplete
4177 structure, union or class type is represented by a structure,
4178 union or class entry that does not have a byte size attribute
4179 and that has a DW_AT_declaration attribute." */
4180 if (!pdi->has_byte_size && pdi->is_declaration)
4181 {
4182 if (built_actual_name)
4183 xfree (actual_name);
4184 return;
4185 }
4186
4187 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4188 static vs. global. */
4189 add_psymbol_to_list (actual_name, strlen (actual_name),
4190 built_actual_name,
4191 STRUCT_DOMAIN, LOC_TYPEDEF,
4192 (cu->language == language_cplus
4193 || cu->language == language_java)
4194 ? &objfile->global_psymbols
4195 : &objfile->static_psymbols,
4196 0, (CORE_ADDR) 0, cu->language, objfile);
4197
4198 break;
4199 case DW_TAG_enumerator:
4200 add_psymbol_to_list (actual_name, strlen (actual_name),
4201 built_actual_name,
4202 VAR_DOMAIN, LOC_CONST,
4203 (cu->language == language_cplus
4204 || cu->language == language_java)
4205 ? &objfile->global_psymbols
4206 : &objfile->static_psymbols,
4207 0, (CORE_ADDR) 0, cu->language, objfile);
4208 break;
4209 default:
4210 break;
4211 }
4212
4213 if (built_actual_name)
4214 xfree (actual_name);
4215 }
4216
4217 /* Read a partial die corresponding to a namespace; also, add a symbol
4218 corresponding to that namespace to the symbol table. NAMESPACE is
4219 the name of the enclosing namespace. */
4220
4221 static void
4222 add_partial_namespace (struct partial_die_info *pdi,
4223 CORE_ADDR *lowpc, CORE_ADDR *highpc,
4224 int need_pc, struct dwarf2_cu *cu)
4225 {
4226 /* Add a symbol for the namespace. */
4227
4228 add_partial_symbol (pdi, cu);
4229
4230 /* Now scan partial symbols in that namespace. */
4231
4232 if (pdi->has_children)
4233 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
4234 }
4235
4236 /* Read a partial die corresponding to a Fortran module. */
4237
4238 static void
4239 add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
4240 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
4241 {
4242 /* Now scan partial symbols in that module. */
4243
4244 if (pdi->has_children)
4245 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
4246 }
4247
4248 /* Read a partial die corresponding to a subprogram and create a partial
4249 symbol for that subprogram. When the CU language allows it, this
4250 routine also defines a partial symbol for each nested subprogram
4251 that this subprogram contains.
4252
4253 DIE my also be a lexical block, in which case we simply search
4254 recursively for suprograms defined inside that lexical block.
4255 Again, this is only performed when the CU language allows this
4256 type of definitions. */
4257
4258 static void
4259 add_partial_subprogram (struct partial_die_info *pdi,
4260 CORE_ADDR *lowpc, CORE_ADDR *highpc,
4261 int need_pc, struct dwarf2_cu *cu)
4262 {
4263 if (pdi->tag == DW_TAG_subprogram)
4264 {
4265 if (pdi->has_pc_info)
4266 {
4267 if (pdi->lowpc < *lowpc)
4268 *lowpc = pdi->lowpc;
4269 if (pdi->highpc > *highpc)
4270 *highpc = pdi->highpc;
4271 if (need_pc)
4272 {
4273 CORE_ADDR baseaddr;
4274 struct objfile *objfile = cu->objfile;
4275
4276 baseaddr = ANOFFSET (objfile->section_offsets,
4277 SECT_OFF_TEXT (objfile));
4278 addrmap_set_empty (objfile->psymtabs_addrmap,
4279 pdi->lowpc + baseaddr,
4280 pdi->highpc - 1 + baseaddr,
4281 cu->per_cu->v.psymtab);
4282 }
4283 }
4284
4285 if (pdi->has_pc_info || (!pdi->is_external && pdi->may_be_inlined))
4286 {
4287 if (!pdi->is_declaration)
4288 /* Ignore subprogram DIEs that do not have a name, they are
4289 illegal. Do not emit a complaint at this point, we will
4290 do so when we convert this psymtab into a symtab. */
4291 if (pdi->name)
4292 add_partial_symbol (pdi, cu);
4293 }
4294 }
4295
4296 if (! pdi->has_children)
4297 return;
4298
4299 if (cu->language == language_ada)
4300 {
4301 pdi = pdi->die_child;
4302 while (pdi != NULL)
4303 {
4304 fixup_partial_die (pdi, cu);
4305 if (pdi->tag == DW_TAG_subprogram
4306 || pdi->tag == DW_TAG_lexical_block)
4307 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
4308 pdi = pdi->die_sibling;
4309 }
4310 }
4311 }
4312
4313 /* Read a partial die corresponding to an enumeration type. */
4314
4315 static void
4316 add_partial_enumeration (struct partial_die_info *enum_pdi,
4317 struct dwarf2_cu *cu)
4318 {
4319 struct partial_die_info *pdi;
4320
4321 if (enum_pdi->name != NULL)
4322 add_partial_symbol (enum_pdi, cu);
4323
4324 pdi = enum_pdi->die_child;
4325 while (pdi)
4326 {
4327 if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL)
4328 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
4329 else
4330 add_partial_symbol (pdi, cu);
4331 pdi = pdi->die_sibling;
4332 }
4333 }
4334
4335 /* Return the initial uleb128 in the die at INFO_PTR. */
4336
4337 static unsigned int
4338 peek_abbrev_code (bfd *abfd, gdb_byte *info_ptr)
4339 {
4340 unsigned int bytes_read;
4341
4342 return read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4343 }
4344
4345 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4346 Return the corresponding abbrev, or NULL if the number is zero (indicating
4347 an empty DIE). In either case *BYTES_READ will be set to the length of
4348 the initial number. */
4349
4350 static struct abbrev_info *
4351 peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read,
4352 struct dwarf2_cu *cu)
4353 {
4354 bfd *abfd = cu->objfile->obfd;
4355 unsigned int abbrev_number;
4356 struct abbrev_info *abbrev;
4357
4358 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
4359
4360 if (abbrev_number == 0)
4361 return NULL;
4362
4363 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
4364 if (!abbrev)
4365 {
4366 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4367 abbrev_number, bfd_get_filename (abfd));
4368 }
4369
4370 return abbrev;
4371 }
4372
4373 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4374 Returns a pointer to the end of a series of DIEs, terminated by an empty
4375 DIE. Any children of the skipped DIEs will also be skipped. */
4376
4377 static gdb_byte *
4378 skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu)
4379 {
4380 struct abbrev_info *abbrev;
4381 unsigned int bytes_read;
4382
4383 while (1)
4384 {
4385 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
4386 if (abbrev == NULL)
4387 return info_ptr + bytes_read;
4388 else
4389 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
4390 }
4391 }
4392
4393 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4394 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4395 abbrev corresponding to that skipped uleb128 should be passed in
4396 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4397 children. */
4398
4399 static gdb_byte *
4400 skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
4401 struct abbrev_info *abbrev, struct dwarf2_cu *cu)
4402 {
4403 unsigned int bytes_read;
4404 struct attribute attr;
4405 bfd *abfd = cu->objfile->obfd;
4406 unsigned int form, i;
4407
4408 for (i = 0; i < abbrev->num_attrs; i++)
4409 {
4410 /* The only abbrev we care about is DW_AT_sibling. */
4411 if (abbrev->attrs[i].name == DW_AT_sibling)
4412 {
4413 read_attribute (&attr, &abbrev->attrs[i],
4414 abfd, info_ptr, cu);
4415 if (attr.form == DW_FORM_ref_addr)
4416 complaint (&symfile_complaints,
4417 _("ignoring absolute DW_AT_sibling"));
4418 else
4419 return buffer + dwarf2_get_ref_die_offset (&attr).sect_off;
4420 }
4421
4422 /* If it isn't DW_AT_sibling, skip this attribute. */
4423 form = abbrev->attrs[i].form;
4424 skip_attribute:
4425 switch (form)
4426 {
4427 case DW_FORM_ref_addr:
4428 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4429 and later it is offset sized. */
4430 if (cu->header.version == 2)
4431 info_ptr += cu->header.addr_size;
4432 else
4433 info_ptr += cu->header.offset_size;
4434 break;
4435 case DW_FORM_addr:
4436 info_ptr += cu->header.addr_size;
4437 break;
4438 case DW_FORM_data1:
4439 case DW_FORM_ref1:
4440 case DW_FORM_flag:
4441 info_ptr += 1;
4442 break;
4443 case DW_FORM_flag_present:
4444 break;
4445 case DW_FORM_data2:
4446 case DW_FORM_ref2:
4447 info_ptr += 2;
4448 break;
4449 case DW_FORM_data4:
4450 case DW_FORM_ref4:
4451 info_ptr += 4;
4452 break;
4453 case DW_FORM_data8:
4454 case DW_FORM_ref8:
4455 case DW_FORM_ref_sig8:
4456 info_ptr += 8;
4457 break;
4458 case DW_FORM_string:
4459 read_direct_string (abfd, info_ptr, &bytes_read);
4460 info_ptr += bytes_read;
4461 break;
4462 case DW_FORM_sec_offset:
4463 case DW_FORM_strp:
4464 info_ptr += cu->header.offset_size;
4465 break;
4466 case DW_FORM_exprloc:
4467 case DW_FORM_block:
4468 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4469 info_ptr += bytes_read;
4470 break;
4471 case DW_FORM_block1:
4472 info_ptr += 1 + read_1_byte (abfd, info_ptr);
4473 break;
4474 case DW_FORM_block2:
4475 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
4476 break;
4477 case DW_FORM_block4:
4478 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
4479 break;
4480 case DW_FORM_sdata:
4481 case DW_FORM_udata:
4482 case DW_FORM_ref_udata:
4483 info_ptr = skip_leb128 (abfd, info_ptr);
4484 break;
4485 case DW_FORM_indirect:
4486 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4487 info_ptr += bytes_read;
4488 /* We need to continue parsing from here, so just go back to
4489 the top. */
4490 goto skip_attribute;
4491
4492 default:
4493 error (_("Dwarf Error: Cannot handle %s "
4494 "in DWARF reader [in module %s]"),
4495 dwarf_form_name (form),
4496 bfd_get_filename (abfd));
4497 }
4498 }
4499
4500 if (abbrev->has_children)
4501 return skip_children (buffer, info_ptr, cu);
4502 else
4503 return info_ptr;
4504 }
4505
4506 /* Locate ORIG_PDI's sibling.
4507 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4508 in BUFFER. */
4509
4510 static gdb_byte *
4511 locate_pdi_sibling (struct partial_die_info *orig_pdi,
4512 gdb_byte *buffer, gdb_byte *info_ptr,
4513 bfd *abfd, struct dwarf2_cu *cu)
4514 {
4515 /* Do we know the sibling already? */
4516
4517 if (orig_pdi->sibling)
4518 return orig_pdi->sibling;
4519
4520 /* Are there any children to deal with? */
4521
4522 if (!orig_pdi->has_children)
4523 return info_ptr;
4524
4525 /* Skip the children the long way. */
4526
4527 return skip_children (buffer, info_ptr, cu);
4528 }
4529
4530 /* Expand this partial symbol table into a full symbol table. */
4531
4532 static void
4533 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
4534 {
4535 if (pst != NULL)
4536 {
4537 if (pst->readin)
4538 {
4539 warning (_("bug: psymtab for %s is already read in."),
4540 pst->filename);
4541 }
4542 else
4543 {
4544 if (info_verbose)
4545 {
4546 printf_filtered (_("Reading in symbols for %s..."),
4547 pst->filename);
4548 gdb_flush (gdb_stdout);
4549 }
4550
4551 /* Restore our global data. */
4552 dwarf2_per_objfile = objfile_data (pst->objfile,
4553 dwarf2_objfile_data_key);
4554
4555 /* If this psymtab is constructed from a debug-only objfile, the
4556 has_section_at_zero flag will not necessarily be correct. We
4557 can get the correct value for this flag by looking at the data
4558 associated with the (presumably stripped) associated objfile. */
4559 if (pst->objfile->separate_debug_objfile_backlink)
4560 {
4561 struct dwarf2_per_objfile *dpo_backlink
4562 = objfile_data (pst->objfile->separate_debug_objfile_backlink,
4563 dwarf2_objfile_data_key);
4564
4565 dwarf2_per_objfile->has_section_at_zero
4566 = dpo_backlink->has_section_at_zero;
4567 }
4568
4569 dwarf2_per_objfile->reading_partial_symbols = 0;
4570
4571 psymtab_to_symtab_1 (pst);
4572
4573 /* Finish up the debug error message. */
4574 if (info_verbose)
4575 printf_filtered (_("done.\n"));
4576 }
4577 }
4578 }
4579 \f
4580 /* Reading in full CUs. */
4581
4582 /* Add PER_CU to the queue. */
4583
4584 static void
4585 queue_comp_unit (struct dwarf2_per_cu_data *per_cu)
4586 {
4587 struct dwarf2_queue_item *item;
4588
4589 per_cu->queued = 1;
4590 item = xmalloc (sizeof (*item));
4591 item->per_cu = per_cu;
4592 item->next = NULL;
4593
4594 if (dwarf2_queue == NULL)
4595 dwarf2_queue = item;
4596 else
4597 dwarf2_queue_tail->next = item;
4598
4599 dwarf2_queue_tail = item;
4600 }
4601
4602 /* Process the queue. */
4603
4604 static void
4605 process_queue (void)
4606 {
4607 struct dwarf2_queue_item *item, *next_item;
4608
4609 /* The queue starts out with one item, but following a DIE reference
4610 may load a new CU, adding it to the end of the queue. */
4611 for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
4612 {
4613 if (dwarf2_per_objfile->using_index
4614 ? !item->per_cu->v.quick->symtab
4615 : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin))
4616 process_full_comp_unit (item->per_cu);
4617
4618 item->per_cu->queued = 0;
4619 next_item = item->next;
4620 xfree (item);
4621 }
4622
4623 dwarf2_queue_tail = NULL;
4624 }
4625
4626 /* Free all allocated queue entries. This function only releases anything if
4627 an error was thrown; if the queue was processed then it would have been
4628 freed as we went along. */
4629
4630 static void
4631 dwarf2_release_queue (void *dummy)
4632 {
4633 struct dwarf2_queue_item *item, *last;
4634
4635 item = dwarf2_queue;
4636 while (item)
4637 {
4638 /* Anything still marked queued is likely to be in an
4639 inconsistent state, so discard it. */
4640 if (item->per_cu->queued)
4641 {
4642 if (item->per_cu->cu != NULL)
4643 free_one_cached_comp_unit (item->per_cu->cu);
4644 item->per_cu->queued = 0;
4645 }
4646
4647 last = item;
4648 item = item->next;
4649 xfree (last);
4650 }
4651
4652 dwarf2_queue = dwarf2_queue_tail = NULL;
4653 }
4654
4655 /* Read in full symbols for PST, and anything it depends on. */
4656
4657 static void
4658 psymtab_to_symtab_1 (struct partial_symtab *pst)
4659 {
4660 struct dwarf2_per_cu_data *per_cu;
4661 struct cleanup *back_to;
4662 int i;
4663
4664 for (i = 0; i < pst->number_of_dependencies; i++)
4665 if (!pst->dependencies[i]->readin)
4666 {
4667 /* Inform about additional files that need to be read in. */
4668 if (info_verbose)
4669 {
4670 /* FIXME: i18n: Need to make this a single string. */
4671 fputs_filtered (" ", gdb_stdout);
4672 wrap_here ("");
4673 fputs_filtered ("and ", gdb_stdout);
4674 wrap_here ("");
4675 printf_filtered ("%s...", pst->dependencies[i]->filename);
4676 wrap_here (""); /* Flush output. */
4677 gdb_flush (gdb_stdout);
4678 }
4679 psymtab_to_symtab_1 (pst->dependencies[i]);
4680 }
4681
4682 per_cu = pst->read_symtab_private;
4683
4684 if (per_cu == NULL)
4685 {
4686 /* It's an include file, no symbols to read for it.
4687 Everything is in the parent symtab. */
4688 pst->readin = 1;
4689 return;
4690 }
4691
4692 dw2_do_instantiate_symtab (per_cu);
4693 }
4694
4695 /* Load the DIEs associated with PER_CU into memory. */
4696
4697 static void
4698 load_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
4699 {
4700 struct objfile *objfile = per_cu->objfile;
4701 bfd *abfd = objfile->obfd;
4702 struct dwarf2_cu *cu;
4703 sect_offset offset;
4704 gdb_byte *info_ptr, *beg_of_comp_unit;
4705 struct cleanup *free_cu_cleanup = NULL;
4706 struct attribute *attr;
4707 int read_cu = 0;
4708
4709 gdb_assert (! per_cu->debug_types_section);
4710
4711 /* Set local variables from the partial symbol table info. */
4712 offset = per_cu->offset;
4713
4714 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
4715 info_ptr = dwarf2_per_objfile->info.buffer + offset.sect_off;
4716 beg_of_comp_unit = info_ptr;
4717
4718 if (per_cu->cu == NULL)
4719 {
4720 cu = xmalloc (sizeof (*cu));
4721 init_one_comp_unit (cu, per_cu);
4722
4723 read_cu = 1;
4724
4725 /* If an error occurs while loading, release our storage. */
4726 free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu);
4727
4728 /* Read in the comp_unit header. */
4729 info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd);
4730
4731 /* Skip dummy compilation units. */
4732 if (info_ptr >= (dwarf2_per_objfile->info.buffer
4733 + dwarf2_per_objfile->info.size)
4734 || peek_abbrev_code (abfd, info_ptr) == 0)
4735 {
4736 do_cleanups (free_cu_cleanup);
4737 return;
4738 }
4739
4740 /* Complete the cu_header. */
4741 cu->header.offset = offset;
4742 cu->header.first_die_offset.cu_off = info_ptr - beg_of_comp_unit;
4743 }
4744 else
4745 {
4746 cu = per_cu->cu;
4747 info_ptr += cu->header.first_die_offset.cu_off;
4748 }
4749
4750 cu->dies = read_comp_unit (info_ptr, cu);
4751
4752 /* We try not to read any attributes in this function, because not
4753 all CUs needed for references have been loaded yet, and symbol
4754 table processing isn't initialized. But we have to set the CU language,
4755 or we won't be able to build types correctly. */
4756 prepare_one_comp_unit (cu, cu->dies);
4757
4758 /* Similarly, if we do not read the producer, we can not apply
4759 producer-specific interpretation. */
4760 attr = dwarf2_attr (cu->dies, DW_AT_producer, cu);
4761 if (attr)
4762 cu->producer = DW_STRING (attr);
4763
4764 if (read_cu)
4765 {
4766 /* We've successfully allocated this compilation unit. Let our
4767 caller clean it up when finished with it. */
4768 discard_cleanups (free_cu_cleanup);
4769
4770 /* Link this CU into read_in_chain. */
4771 per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
4772 dwarf2_per_objfile->read_in_chain = per_cu;
4773 }
4774 }
4775
4776 /* Add a DIE to the delayed physname list. */
4777
4778 static void
4779 add_to_method_list (struct type *type, int fnfield_index, int index,
4780 const char *name, struct die_info *die,
4781 struct dwarf2_cu *cu)
4782 {
4783 struct delayed_method_info mi;
4784 mi.type = type;
4785 mi.fnfield_index = fnfield_index;
4786 mi.index = index;
4787 mi.name = name;
4788 mi.die = die;
4789 VEC_safe_push (delayed_method_info, cu->method_list, &mi);
4790 }
4791
4792 /* A cleanup for freeing the delayed method list. */
4793
4794 static void
4795 free_delayed_list (void *ptr)
4796 {
4797 struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr;
4798 if (cu->method_list != NULL)
4799 {
4800 VEC_free (delayed_method_info, cu->method_list);
4801 cu->method_list = NULL;
4802 }
4803 }
4804
4805 /* Compute the physnames of any methods on the CU's method list.
4806
4807 The computation of method physnames is delayed in order to avoid the
4808 (bad) condition that one of the method's formal parameters is of an as yet
4809 incomplete type. */
4810
4811 static void
4812 compute_delayed_physnames (struct dwarf2_cu *cu)
4813 {
4814 int i;
4815 struct delayed_method_info *mi;
4816 for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i)
4817 {
4818 const char *physname;
4819 struct fn_fieldlist *fn_flp
4820 = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index);
4821 physname = dwarf2_physname ((char *) mi->name, mi->die, cu);
4822 fn_flp->fn_fields[mi->index].physname = physname ? physname : "";
4823 }
4824 }
4825
4826 /* Go objects should be embedded in a DW_TAG_module DIE,
4827 and it's not clear if/how imported objects will appear.
4828 To keep Go support simple until that's worked out,
4829 go back through what we've read and create something usable.
4830 We could do this while processing each DIE, and feels kinda cleaner,
4831 but that way is more invasive.
4832 This is to, for example, allow the user to type "p var" or "b main"
4833 without having to specify the package name, and allow lookups
4834 of module.object to work in contexts that use the expression
4835 parser. */
4836
4837 static void
4838 fixup_go_packaging (struct dwarf2_cu *cu)
4839 {
4840 char *package_name = NULL;
4841 struct pending *list;
4842 int i;
4843
4844 for (list = global_symbols; list != NULL; list = list->next)
4845 {
4846 for (i = 0; i < list->nsyms; ++i)
4847 {
4848 struct symbol *sym = list->symbol[i];
4849
4850 if (SYMBOL_LANGUAGE (sym) == language_go
4851 && SYMBOL_CLASS (sym) == LOC_BLOCK)
4852 {
4853 char *this_package_name = go_symbol_package_name (sym);
4854
4855 if (this_package_name == NULL)
4856 continue;
4857 if (package_name == NULL)
4858 package_name = this_package_name;
4859 else
4860 {
4861 if (strcmp (package_name, this_package_name) != 0)
4862 complaint (&symfile_complaints,
4863 _("Symtab %s has objects from two different Go packages: %s and %s"),
4864 (sym->symtab && sym->symtab->filename
4865 ? sym->symtab->filename
4866 : cu->objfile->name),
4867 this_package_name, package_name);
4868 xfree (this_package_name);
4869 }
4870 }
4871 }
4872 }
4873
4874 if (package_name != NULL)
4875 {
4876 struct objfile *objfile = cu->objfile;
4877 struct type *type = init_type (TYPE_CODE_MODULE, 0, 0,
4878 package_name, objfile);
4879 struct symbol *sym;
4880
4881 TYPE_TAG_NAME (type) = TYPE_NAME (type);
4882
4883 sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol);
4884 SYMBOL_SET_LANGUAGE (sym, language_go);
4885 SYMBOL_SET_NAMES (sym, package_name, strlen (package_name), 1, objfile);
4886 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
4887 e.g., "main" finds the "main" module and not C's main(). */
4888 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
4889 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
4890 SYMBOL_TYPE (sym) = type;
4891
4892 add_symbol_to_list (sym, &global_symbols);
4893
4894 xfree (package_name);
4895 }
4896 }
4897
4898 /* Generate full symbol information for PER_CU, whose DIEs have
4899 already been loaded into memory. */
4900
4901 static void
4902 process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
4903 {
4904 struct dwarf2_cu *cu = per_cu->cu;
4905 struct objfile *objfile = per_cu->objfile;
4906 CORE_ADDR lowpc, highpc;
4907 struct symtab *symtab;
4908 struct cleanup *back_to, *delayed_list_cleanup;
4909 CORE_ADDR baseaddr;
4910
4911 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4912
4913 buildsym_init ();
4914 back_to = make_cleanup (really_free_pendings, NULL);
4915 delayed_list_cleanup = make_cleanup (free_delayed_list, cu);
4916
4917 cu->list_in_scope = &file_symbols;
4918
4919 /* Do line number decoding in read_file_scope () */
4920 process_die (cu->dies, cu);
4921
4922 /* For now fudge the Go package. */
4923 if (cu->language == language_go)
4924 fixup_go_packaging (cu);
4925
4926 /* Now that we have processed all the DIEs in the CU, all the types
4927 should be complete, and it should now be safe to compute all of the
4928 physnames. */
4929 compute_delayed_physnames (cu);
4930 do_cleanups (delayed_list_cleanup);
4931
4932 /* Some compilers don't define a DW_AT_high_pc attribute for the
4933 compilation unit. If the DW_AT_high_pc is missing, synthesize
4934 it, by scanning the DIE's below the compilation unit. */
4935 get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
4936
4937 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
4938
4939 if (symtab != NULL)
4940 {
4941 int gcc_4_minor = producer_is_gcc_ge_4 (cu->producer);
4942
4943 /* Set symtab language to language from DW_AT_language. If the
4944 compilation is from a C file generated by language preprocessors, do
4945 not set the language if it was already deduced by start_subfile. */
4946 if (!(cu->language == language_c && symtab->language != language_c))
4947 symtab->language = cu->language;
4948
4949 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4950 produce DW_AT_location with location lists but it can be possibly
4951 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
4952 there were bugs in prologue debug info, fixed later in GCC-4.5
4953 by "unwind info for epilogues" patch (which is not directly related).
4954
4955 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4956 needed, it would be wrong due to missing DW_AT_producer there.
4957
4958 Still one can confuse GDB by using non-standard GCC compilation
4959 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4960 */
4961 if (cu->has_loclist && gcc_4_minor >= 5)
4962 symtab->locations_valid = 1;
4963
4964 if (gcc_4_minor >= 5)
4965 symtab->epilogue_unwind_valid = 1;
4966
4967 symtab->call_site_htab = cu->call_site_htab;
4968 }
4969
4970 if (dwarf2_per_objfile->using_index)
4971 per_cu->v.quick->symtab = symtab;
4972 else
4973 {
4974 struct partial_symtab *pst = per_cu->v.psymtab;
4975 pst->symtab = symtab;
4976 pst->readin = 1;
4977 }
4978
4979 do_cleanups (back_to);
4980 }
4981
4982 /* Process a die and its children. */
4983
4984 static void
4985 process_die (struct die_info *die, struct dwarf2_cu *cu)
4986 {
4987 switch (die->tag)
4988 {
4989 case DW_TAG_padding:
4990 break;
4991 case DW_TAG_compile_unit:
4992 read_file_scope (die, cu);
4993 break;
4994 case DW_TAG_type_unit:
4995 read_type_unit_scope (die, cu);
4996 break;
4997 case DW_TAG_subprogram:
4998 case DW_TAG_inlined_subroutine:
4999 read_func_scope (die, cu);
5000 break;
5001 case DW_TAG_lexical_block:
5002 case DW_TAG_try_block:
5003 case DW_TAG_catch_block:
5004 read_lexical_block_scope (die, cu);
5005 break;
5006 case DW_TAG_GNU_call_site:
5007 read_call_site_scope (die, cu);
5008 break;
5009 case DW_TAG_class_type:
5010 case DW_TAG_interface_type:
5011 case DW_TAG_structure_type:
5012 case DW_TAG_union_type:
5013 process_structure_scope (die, cu);
5014 break;
5015 case DW_TAG_enumeration_type:
5016 process_enumeration_scope (die, cu);
5017 break;
5018
5019 /* These dies have a type, but processing them does not create
5020 a symbol or recurse to process the children. Therefore we can
5021 read them on-demand through read_type_die. */
5022 case DW_TAG_subroutine_type:
5023 case DW_TAG_set_type:
5024 case DW_TAG_array_type:
5025 case DW_TAG_pointer_type:
5026 case DW_TAG_ptr_to_member_type:
5027 case DW_TAG_reference_type:
5028 case DW_TAG_string_type:
5029 break;
5030
5031 case DW_TAG_base_type:
5032 case DW_TAG_subrange_type:
5033 case DW_TAG_typedef:
5034 /* Add a typedef symbol for the type definition, if it has a
5035 DW_AT_name. */
5036 new_symbol (die, read_type_die (die, cu), cu);
5037 break;
5038 case DW_TAG_common_block:
5039 read_common_block (die, cu);
5040 break;
5041 case DW_TAG_common_inclusion:
5042 break;
5043 case DW_TAG_namespace:
5044 processing_has_namespace_info = 1;
5045 read_namespace (die, cu);
5046 break;
5047 case DW_TAG_module:
5048 processing_has_namespace_info = 1;
5049 read_module (die, cu);
5050 break;
5051 case DW_TAG_imported_declaration:
5052 case DW_TAG_imported_module:
5053 processing_has_namespace_info = 1;
5054 if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
5055 || cu->language != language_fortran))
5056 complaint (&symfile_complaints, _("Tag '%s' has unexpected children"),
5057 dwarf_tag_name (die->tag));
5058 read_import_statement (die, cu);
5059 break;
5060 default:
5061 new_symbol (die, NULL, cu);
5062 break;
5063 }
5064 }
5065
5066 /* A helper function for dwarf2_compute_name which determines whether DIE
5067 needs to have the name of the scope prepended to the name listed in the
5068 die. */
5069
5070 static int
5071 die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
5072 {
5073 struct attribute *attr;
5074
5075 switch (die->tag)
5076 {
5077 case DW_TAG_namespace:
5078 case DW_TAG_typedef:
5079 case DW_TAG_class_type:
5080 case DW_TAG_interface_type:
5081 case DW_TAG_structure_type:
5082 case DW_TAG_union_type:
5083 case DW_TAG_enumeration_type:
5084 case DW_TAG_enumerator:
5085 case DW_TAG_subprogram:
5086 case DW_TAG_member:
5087 return 1;
5088
5089 case DW_TAG_variable:
5090 case DW_TAG_constant:
5091 /* We only need to prefix "globally" visible variables. These include
5092 any variable marked with DW_AT_external or any variable that
5093 lives in a namespace. [Variables in anonymous namespaces
5094 require prefixing, but they are not DW_AT_external.] */
5095
5096 if (dwarf2_attr (die, DW_AT_specification, cu))
5097 {
5098 struct dwarf2_cu *spec_cu = cu;
5099
5100 return die_needs_namespace (die_specification (die, &spec_cu),
5101 spec_cu);
5102 }
5103
5104 attr = dwarf2_attr (die, DW_AT_external, cu);
5105 if (attr == NULL && die->parent->tag != DW_TAG_namespace
5106 && die->parent->tag != DW_TAG_module)
5107 return 0;
5108 /* A variable in a lexical block of some kind does not need a
5109 namespace, even though in C++ such variables may be external
5110 and have a mangled name. */
5111 if (die->parent->tag == DW_TAG_lexical_block
5112 || die->parent->tag == DW_TAG_try_block
5113 || die->parent->tag == DW_TAG_catch_block
5114 || die->parent->tag == DW_TAG_subprogram)
5115 return 0;
5116 return 1;
5117
5118 default:
5119 return 0;
5120 }
5121 }
5122
5123 /* Retrieve the last character from a mem_file. */
5124
5125 static void
5126 do_ui_file_peek_last (void *object, const char *buffer, long length)
5127 {
5128 char *last_char_p = (char *) object;
5129
5130 if (length > 0)
5131 *last_char_p = buffer[length - 1];
5132 }
5133
5134 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
5135 compute the physname for the object, which include a method's:
5136 - formal parameters (C++/Java),
5137 - receiver type (Go),
5138 - return type (Java).
5139
5140 The term "physname" is a bit confusing.
5141 For C++, for example, it is the demangled name.
5142 For Go, for example, it's the mangled name.
5143
5144 For Ada, return the DIE's linkage name rather than the fully qualified
5145 name. PHYSNAME is ignored..
5146
5147 The result is allocated on the objfile_obstack and canonicalized. */
5148
5149 static const char *
5150 dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
5151 int physname)
5152 {
5153 struct objfile *objfile = cu->objfile;
5154
5155 if (name == NULL)
5156 name = dwarf2_name (die, cu);
5157
5158 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
5159 compute it by typename_concat inside GDB. */
5160 if (cu->language == language_ada
5161 || (cu->language == language_fortran && physname))
5162 {
5163 /* For Ada unit, we prefer the linkage name over the name, as
5164 the former contains the exported name, which the user expects
5165 to be able to reference. Ideally, we want the user to be able
5166 to reference this entity using either natural or linkage name,
5167 but we haven't started looking at this enhancement yet. */
5168 struct attribute *attr;
5169
5170 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
5171 if (attr == NULL)
5172 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
5173 if (attr && DW_STRING (attr))
5174 return DW_STRING (attr);
5175 }
5176
5177 /* These are the only languages we know how to qualify names in. */
5178 if (name != NULL
5179 && (cu->language == language_cplus || cu->language == language_java
5180 || cu->language == language_fortran))
5181 {
5182 if (die_needs_namespace (die, cu))
5183 {
5184 long length;
5185 const char *prefix;
5186 struct ui_file *buf;
5187
5188 prefix = determine_prefix (die, cu);
5189 buf = mem_fileopen ();
5190 if (*prefix != '\0')
5191 {
5192 char *prefixed_name = typename_concat (NULL, prefix, name,
5193 physname, cu);
5194
5195 fputs_unfiltered (prefixed_name, buf);
5196 xfree (prefixed_name);
5197 }
5198 else
5199 fputs_unfiltered (name, buf);
5200
5201 /* Template parameters may be specified in the DIE's DW_AT_name, or
5202 as children with DW_TAG_template_type_param or
5203 DW_TAG_value_type_param. If the latter, add them to the name
5204 here. If the name already has template parameters, then
5205 skip this step; some versions of GCC emit both, and
5206 it is more efficient to use the pre-computed name.
5207
5208 Something to keep in mind about this process: it is very
5209 unlikely, or in some cases downright impossible, to produce
5210 something that will match the mangled name of a function.
5211 If the definition of the function has the same debug info,
5212 we should be able to match up with it anyway. But fallbacks
5213 using the minimal symbol, for instance to find a method
5214 implemented in a stripped copy of libstdc++, will not work.
5215 If we do not have debug info for the definition, we will have to
5216 match them up some other way.
5217
5218 When we do name matching there is a related problem with function
5219 templates; two instantiated function templates are allowed to
5220 differ only by their return types, which we do not add here. */
5221
5222 if (cu->language == language_cplus && strchr (name, '<') == NULL)
5223 {
5224 struct attribute *attr;
5225 struct die_info *child;
5226 int first = 1;
5227
5228 die->building_fullname = 1;
5229
5230 for (child = die->child; child != NULL; child = child->sibling)
5231 {
5232 struct type *type;
5233 LONGEST value;
5234 gdb_byte *bytes;
5235 struct dwarf2_locexpr_baton *baton;
5236 struct value *v;
5237
5238 if (child->tag != DW_TAG_template_type_param
5239 && child->tag != DW_TAG_template_value_param)
5240 continue;
5241
5242 if (first)
5243 {
5244 fputs_unfiltered ("<", buf);
5245 first = 0;
5246 }
5247 else
5248 fputs_unfiltered (", ", buf);
5249
5250 attr = dwarf2_attr (child, DW_AT_type, cu);
5251 if (attr == NULL)
5252 {
5253 complaint (&symfile_complaints,
5254 _("template parameter missing DW_AT_type"));
5255 fputs_unfiltered ("UNKNOWN_TYPE", buf);
5256 continue;
5257 }
5258 type = die_type (child, cu);
5259
5260 if (child->tag == DW_TAG_template_type_param)
5261 {
5262 c_print_type (type, "", buf, -1, 0);
5263 continue;
5264 }
5265
5266 attr = dwarf2_attr (child, DW_AT_const_value, cu);
5267 if (attr == NULL)
5268 {
5269 complaint (&symfile_complaints,
5270 _("template parameter missing "
5271 "DW_AT_const_value"));
5272 fputs_unfiltered ("UNKNOWN_VALUE", buf);
5273 continue;
5274 }
5275
5276 dwarf2_const_value_attr (attr, type, name,
5277 &cu->comp_unit_obstack, cu,
5278 &value, &bytes, &baton);
5279
5280 if (TYPE_NOSIGN (type))
5281 /* GDB prints characters as NUMBER 'CHAR'. If that's
5282 changed, this can use value_print instead. */
5283 c_printchar (value, type, buf);
5284 else
5285 {
5286 struct value_print_options opts;
5287
5288 if (baton != NULL)
5289 v = dwarf2_evaluate_loc_desc (type, NULL,
5290 baton->data,
5291 baton->size,
5292 baton->per_cu);
5293 else if (bytes != NULL)
5294 {
5295 v = allocate_value (type);
5296 memcpy (value_contents_writeable (v), bytes,
5297 TYPE_LENGTH (type));
5298 }
5299 else
5300 v = value_from_longest (type, value);
5301
5302 /* Specify decimal so that we do not depend on
5303 the radix. */
5304 get_formatted_print_options (&opts, 'd');
5305 opts.raw = 1;
5306 value_print (v, buf, &opts);
5307 release_value (v);
5308 value_free (v);
5309 }
5310 }
5311
5312 die->building_fullname = 0;
5313
5314 if (!first)
5315 {
5316 /* Close the argument list, with a space if necessary
5317 (nested templates). */
5318 char last_char = '\0';
5319 ui_file_put (buf, do_ui_file_peek_last, &last_char);
5320 if (last_char == '>')
5321 fputs_unfiltered (" >", buf);
5322 else
5323 fputs_unfiltered (">", buf);
5324 }
5325 }
5326
5327 /* For Java and C++ methods, append formal parameter type
5328 information, if PHYSNAME. */
5329
5330 if (physname && die->tag == DW_TAG_subprogram
5331 && (cu->language == language_cplus
5332 || cu->language == language_java))
5333 {
5334 struct type *type = read_type_die (die, cu);
5335
5336 c_type_print_args (type, buf, 1, cu->language);
5337
5338 if (cu->language == language_java)
5339 {
5340 /* For java, we must append the return type to method
5341 names. */
5342 if (die->tag == DW_TAG_subprogram)
5343 java_print_type (TYPE_TARGET_TYPE (type), "", buf,
5344 0, 0);
5345 }
5346 else if (cu->language == language_cplus)
5347 {
5348 /* Assume that an artificial first parameter is
5349 "this", but do not crash if it is not. RealView
5350 marks unnamed (and thus unused) parameters as
5351 artificial; there is no way to differentiate
5352 the two cases. */
5353 if (TYPE_NFIELDS (type) > 0
5354 && TYPE_FIELD_ARTIFICIAL (type, 0)
5355 && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR
5356 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type,
5357 0))))
5358 fputs_unfiltered (" const", buf);
5359 }
5360 }
5361
5362 name = ui_file_obsavestring (buf, &objfile->objfile_obstack,
5363 &length);
5364 ui_file_delete (buf);
5365
5366 if (cu->language == language_cplus)
5367 {
5368 char *cname
5369 = dwarf2_canonicalize_name (name, cu,
5370 &objfile->objfile_obstack);
5371
5372 if (cname != NULL)
5373 name = cname;
5374 }
5375 }
5376 }
5377
5378 return name;
5379 }
5380
5381 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5382 If scope qualifiers are appropriate they will be added. The result
5383 will be allocated on the objfile_obstack, or NULL if the DIE does
5384 not have a name. NAME may either be from a previous call to
5385 dwarf2_name or NULL.
5386
5387 The output string will be canonicalized (if C++/Java). */
5388
5389 static const char *
5390 dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu)
5391 {
5392 return dwarf2_compute_name (name, die, cu, 0);
5393 }
5394
5395 /* Construct a physname for the given DIE in CU. NAME may either be
5396 from a previous call to dwarf2_name or NULL. The result will be
5397 allocated on the objfile_objstack or NULL if the DIE does not have a
5398 name.
5399
5400 The output string will be canonicalized (if C++/Java). */
5401
5402 static const char *
5403 dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu)
5404 {
5405 struct objfile *objfile = cu->objfile;
5406 struct attribute *attr;
5407 const char *retval, *mangled = NULL, *canon = NULL;
5408 struct cleanup *back_to;
5409 int need_copy = 1;
5410
5411 /* In this case dwarf2_compute_name is just a shortcut not building anything
5412 on its own. */
5413 if (!die_needs_namespace (die, cu))
5414 return dwarf2_compute_name (name, die, cu, 1);
5415
5416 back_to = make_cleanup (null_cleanup, NULL);
5417
5418 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
5419 if (!attr)
5420 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
5421
5422 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5423 has computed. */
5424 if (attr && DW_STRING (attr))
5425 {
5426 char *demangled;
5427
5428 mangled = DW_STRING (attr);
5429
5430 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5431 type. It is easier for GDB users to search for such functions as
5432 `name(params)' than `long name(params)'. In such case the minimal
5433 symbol names do not match the full symbol names but for template
5434 functions there is never a need to look up their definition from their
5435 declaration so the only disadvantage remains the minimal symbol
5436 variant `long name(params)' does not have the proper inferior type.
5437 */
5438
5439 if (cu->language == language_go)
5440 {
5441 /* This is a lie, but we already lie to the caller new_symbol_full.
5442 new_symbol_full assumes we return the mangled name.
5443 This just undoes that lie until things are cleaned up. */
5444 demangled = NULL;
5445 }
5446 else
5447 {
5448 demangled = cplus_demangle (mangled,
5449 (DMGL_PARAMS | DMGL_ANSI
5450 | (cu->language == language_java
5451 ? DMGL_JAVA | DMGL_RET_POSTFIX
5452 : DMGL_RET_DROP)));
5453 }
5454 if (demangled)
5455 {
5456 make_cleanup (xfree, demangled);
5457 canon = demangled;
5458 }
5459 else
5460 {
5461 canon = mangled;
5462 need_copy = 0;
5463 }
5464 }
5465
5466 if (canon == NULL || check_physname)
5467 {
5468 const char *physname = dwarf2_compute_name (name, die, cu, 1);
5469
5470 if (canon != NULL && strcmp (physname, canon) != 0)
5471 {
5472 /* It may not mean a bug in GDB. The compiler could also
5473 compute DW_AT_linkage_name incorrectly. But in such case
5474 GDB would need to be bug-to-bug compatible. */
5475
5476 complaint (&symfile_complaints,
5477 _("Computed physname <%s> does not match demangled <%s> "
5478 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
5479 physname, canon, mangled, die->offset.sect_off, objfile->name);
5480
5481 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
5482 is available here - over computed PHYSNAME. It is safer
5483 against both buggy GDB and buggy compilers. */
5484
5485 retval = canon;
5486 }
5487 else
5488 {
5489 retval = physname;
5490 need_copy = 0;
5491 }
5492 }
5493 else
5494 retval = canon;
5495
5496 if (need_copy)
5497 retval = obsavestring (retval, strlen (retval),
5498 &objfile->objfile_obstack);
5499
5500 do_cleanups (back_to);
5501 return retval;
5502 }
5503
5504 /* Read the import statement specified by the given die and record it. */
5505
5506 static void
5507 read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
5508 {
5509 struct objfile *objfile = cu->objfile;
5510 struct attribute *import_attr;
5511 struct die_info *imported_die, *child_die;
5512 struct dwarf2_cu *imported_cu;
5513 const char *imported_name;
5514 const char *imported_name_prefix;
5515 const char *canonical_name;
5516 const char *import_alias;
5517 const char *imported_declaration = NULL;
5518 const char *import_prefix;
5519 VEC (const_char_ptr) *excludes = NULL;
5520 struct cleanup *cleanups;
5521
5522 char *temp;
5523
5524 import_attr = dwarf2_attr (die, DW_AT_import, cu);
5525 if (import_attr == NULL)
5526 {
5527 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
5528 dwarf_tag_name (die->tag));
5529 return;
5530 }
5531
5532 imported_cu = cu;
5533 imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu);
5534 imported_name = dwarf2_name (imported_die, imported_cu);
5535 if (imported_name == NULL)
5536 {
5537 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5538
5539 The import in the following code:
5540 namespace A
5541 {
5542 typedef int B;
5543 }
5544
5545 int main ()
5546 {
5547 using A::B;
5548 B b;
5549 return b;
5550 }
5551
5552 ...
5553 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5554 <52> DW_AT_decl_file : 1
5555 <53> DW_AT_decl_line : 6
5556 <54> DW_AT_import : <0x75>
5557 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5558 <59> DW_AT_name : B
5559 <5b> DW_AT_decl_file : 1
5560 <5c> DW_AT_decl_line : 2
5561 <5d> DW_AT_type : <0x6e>
5562 ...
5563 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5564 <76> DW_AT_byte_size : 4
5565 <77> DW_AT_encoding : 5 (signed)
5566
5567 imports the wrong die ( 0x75 instead of 0x58 ).
5568 This case will be ignored until the gcc bug is fixed. */
5569 return;
5570 }
5571
5572 /* Figure out the local name after import. */
5573 import_alias = dwarf2_name (die, cu);
5574
5575 /* Figure out where the statement is being imported to. */
5576 import_prefix = determine_prefix (die, cu);
5577
5578 /* Figure out what the scope of the imported die is and prepend it
5579 to the name of the imported die. */
5580 imported_name_prefix = determine_prefix (imported_die, imported_cu);
5581
5582 if (imported_die->tag != DW_TAG_namespace
5583 && imported_die->tag != DW_TAG_module)
5584 {
5585 imported_declaration = imported_name;
5586 canonical_name = imported_name_prefix;
5587 }
5588 else if (strlen (imported_name_prefix) > 0)
5589 {
5590 temp = alloca (strlen (imported_name_prefix)
5591 + 2 + strlen (imported_name) + 1);
5592 strcpy (temp, imported_name_prefix);
5593 strcat (temp, "::");
5594 strcat (temp, imported_name);
5595 canonical_name = temp;
5596 }
5597 else
5598 canonical_name = imported_name;
5599
5600 cleanups = make_cleanup (VEC_cleanup (const_char_ptr), &excludes);
5601
5602 if (die->tag == DW_TAG_imported_module && cu->language == language_fortran)
5603 for (child_die = die->child; child_die && child_die->tag;
5604 child_die = sibling_die (child_die))
5605 {
5606 /* DWARF-4: A Fortran use statement with a “rename list” may be
5607 represented by an imported module entry with an import attribute
5608 referring to the module and owned entries corresponding to those
5609 entities that are renamed as part of being imported. */
5610
5611 if (child_die->tag != DW_TAG_imported_declaration)
5612 {
5613 complaint (&symfile_complaints,
5614 _("child DW_TAG_imported_declaration expected "
5615 "- DIE at 0x%x [in module %s]"),
5616 child_die->offset.sect_off, objfile->name);
5617 continue;
5618 }
5619
5620 import_attr = dwarf2_attr (child_die, DW_AT_import, cu);
5621 if (import_attr == NULL)
5622 {
5623 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
5624 dwarf_tag_name (child_die->tag));
5625 continue;
5626 }
5627
5628 imported_cu = cu;
5629 imported_die = follow_die_ref_or_sig (child_die, import_attr,
5630 &imported_cu);
5631 imported_name = dwarf2_name (imported_die, imported_cu);
5632 if (imported_name == NULL)
5633 {
5634 complaint (&symfile_complaints,
5635 _("child DW_TAG_imported_declaration has unknown "
5636 "imported name - DIE at 0x%x [in module %s]"),
5637 child_die->offset.sect_off, objfile->name);
5638 continue;
5639 }
5640
5641 VEC_safe_push (const_char_ptr, excludes, imported_name);
5642
5643 process_die (child_die, cu);
5644 }
5645
5646 cp_add_using_directive (import_prefix,
5647 canonical_name,
5648 import_alias,
5649 imported_declaration,
5650 excludes,
5651 &objfile->objfile_obstack);
5652
5653 do_cleanups (cleanups);
5654 }
5655
5656 /* Cleanup function for read_file_scope. */
5657
5658 static void
5659 free_cu_line_header (void *arg)
5660 {
5661 struct dwarf2_cu *cu = arg;
5662
5663 free_line_header (cu->line_header);
5664 cu->line_header = NULL;
5665 }
5666
5667 static void
5668 find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu,
5669 char **name, char **comp_dir)
5670 {
5671 struct attribute *attr;
5672
5673 *name = NULL;
5674 *comp_dir = NULL;
5675
5676 /* Find the filename. Do not use dwarf2_name here, since the filename
5677 is not a source language identifier. */
5678 attr = dwarf2_attr (die, DW_AT_name, cu);
5679 if (attr)
5680 {
5681 *name = DW_STRING (attr);
5682 }
5683
5684 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
5685 if (attr)
5686 *comp_dir = DW_STRING (attr);
5687 else if (*name != NULL && IS_ABSOLUTE_PATH (*name))
5688 {
5689 *comp_dir = ldirname (*name);
5690 if (*comp_dir != NULL)
5691 make_cleanup (xfree, *comp_dir);
5692 }
5693 if (*comp_dir != NULL)
5694 {
5695 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5696 directory, get rid of it. */
5697 char *cp = strchr (*comp_dir, ':');
5698
5699 if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/')
5700 *comp_dir = cp + 1;
5701 }
5702
5703 if (*name == NULL)
5704 *name = "<unknown>";
5705 }
5706
5707 /* Handle DW_AT_stmt_list for a compilation unit or type unit.
5708 DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU.
5709 COMP_DIR is the compilation directory.
5710 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
5711
5712 static void
5713 handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
5714 const char *comp_dir, int want_line_info)
5715 {
5716 struct attribute *attr;
5717 struct objfile *objfile = cu->objfile;
5718 bfd *abfd = objfile->obfd;
5719
5720 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
5721 if (attr)
5722 {
5723 unsigned int line_offset = DW_UNSND (attr);
5724 struct line_header *line_header
5725 = dwarf_decode_line_header (line_offset, abfd, cu);
5726
5727 if (line_header)
5728 {
5729 cu->line_header = line_header;
5730 make_cleanup (free_cu_line_header, cu);
5731 dwarf_decode_lines (line_header, comp_dir, cu, NULL, want_line_info);
5732 }
5733 }
5734 }
5735
5736 /* Process DW_TAG_compile_unit. */
5737
5738 static void
5739 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
5740 {
5741 struct objfile *objfile = cu->objfile;
5742 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
5743 CORE_ADDR lowpc = ((CORE_ADDR) -1);
5744 CORE_ADDR highpc = ((CORE_ADDR) 0);
5745 struct attribute *attr;
5746 char *name = NULL;
5747 char *comp_dir = NULL;
5748 struct die_info *child_die;
5749 bfd *abfd = objfile->obfd;
5750 CORE_ADDR baseaddr;
5751
5752 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5753
5754 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
5755
5756 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5757 from finish_block. */
5758 if (lowpc == ((CORE_ADDR) -1))
5759 lowpc = highpc;
5760 lowpc += baseaddr;
5761 highpc += baseaddr;
5762
5763 find_file_and_directory (die, cu, &name, &comp_dir);
5764
5765 attr = dwarf2_attr (die, DW_AT_language, cu);
5766 if (attr)
5767 {
5768 set_cu_language (DW_UNSND (attr), cu);
5769 }
5770
5771 attr = dwarf2_attr (die, DW_AT_producer, cu);
5772 if (attr)
5773 cu->producer = DW_STRING (attr);
5774
5775 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5776 standardised yet. As a workaround for the language detection we fall
5777 back to the DW_AT_producer string. */
5778 if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL)
5779 cu->language = language_opencl;
5780
5781 /* Similar hack for Go. */
5782 if (cu->producer && strstr (cu->producer, "GNU Go ") != NULL)
5783 set_cu_language (DW_LANG_Go, cu);
5784
5785 /* We assume that we're processing GCC output. */
5786 processing_gcc_compilation = 2;
5787
5788 processing_has_namespace_info = 0;
5789
5790 start_symtab (name, comp_dir, lowpc);
5791 record_debugformat ("DWARF 2");
5792 record_producer (cu->producer);
5793
5794 /* Decode line number information if present. We do this before
5795 processing child DIEs, so that the line header table is available
5796 for DW_AT_decl_file. */
5797 handle_DW_AT_stmt_list (die, cu, comp_dir, 1);
5798
5799 /* Process all dies in compilation unit. */
5800 if (die->child != NULL)
5801 {
5802 child_die = die->child;
5803 while (child_die && child_die->tag)
5804 {
5805 process_die (child_die, cu);
5806 child_die = sibling_die (child_die);
5807 }
5808 }
5809
5810 /* Decode macro information, if present. Dwarf 2 macro information
5811 refers to information in the line number info statement program
5812 header, so we can only read it if we've read the header
5813 successfully. */
5814 attr = dwarf2_attr (die, DW_AT_GNU_macros, cu);
5815 if (attr && cu->line_header)
5816 {
5817 if (dwarf2_attr (die, DW_AT_macro_info, cu))
5818 complaint (&symfile_complaints,
5819 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
5820
5821 dwarf_decode_macros (cu->line_header, DW_UNSND (attr),
5822 comp_dir, abfd, cu,
5823 &dwarf2_per_objfile->macro, 1);
5824 }
5825 else
5826 {
5827 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
5828 if (attr && cu->line_header)
5829 {
5830 unsigned int macro_offset = DW_UNSND (attr);
5831
5832 dwarf_decode_macros (cu->line_header, macro_offset,
5833 comp_dir, abfd, cu,
5834 &dwarf2_per_objfile->macinfo, 0);
5835 }
5836 }
5837
5838 do_cleanups (back_to);
5839 }
5840
5841 /* Process DW_TAG_type_unit.
5842 For TUs we want to skip the first top level sibling if it's not the
5843 actual type being defined by this TU. In this case the first top
5844 level sibling is there to provide context only. */
5845
5846 static void
5847 read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
5848 {
5849 struct objfile *objfile = cu->objfile;
5850 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
5851 CORE_ADDR lowpc;
5852 struct attribute *attr;
5853 char *name = NULL;
5854 char *comp_dir = NULL;
5855 struct die_info *child_die;
5856 bfd *abfd = objfile->obfd;
5857
5858 /* start_symtab needs a low pc, but we don't really have one.
5859 Do what read_file_scope would do in the absence of such info. */
5860 lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5861
5862 /* Find the filename. Do not use dwarf2_name here, since the filename
5863 is not a source language identifier. */
5864 attr = dwarf2_attr (die, DW_AT_name, cu);
5865 if (attr)
5866 name = DW_STRING (attr);
5867
5868 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
5869 if (attr)
5870 comp_dir = DW_STRING (attr);
5871 else if (name != NULL && IS_ABSOLUTE_PATH (name))
5872 {
5873 comp_dir = ldirname (name);
5874 if (comp_dir != NULL)
5875 make_cleanup (xfree, comp_dir);
5876 }
5877
5878 if (name == NULL)
5879 name = "<unknown>";
5880
5881 attr = dwarf2_attr (die, DW_AT_language, cu);
5882 if (attr)
5883 set_cu_language (DW_UNSND (attr), cu);
5884
5885 /* This isn't technically needed today. It is done for symmetry
5886 with read_file_scope. */
5887 attr = dwarf2_attr (die, DW_AT_producer, cu);
5888 if (attr)
5889 cu->producer = DW_STRING (attr);
5890
5891 /* We assume that we're processing GCC output. */
5892 processing_gcc_compilation = 2;
5893
5894 processing_has_namespace_info = 0;
5895
5896 start_symtab (name, comp_dir, lowpc);
5897 record_debugformat ("DWARF 2");
5898 record_producer (cu->producer);
5899
5900 /* Decode line number information if present. We do this before
5901 processing child DIEs, so that the line header table is available
5902 for DW_AT_decl_file.
5903 We don't need the pc/line-number mapping for type units. */
5904 handle_DW_AT_stmt_list (die, cu, comp_dir, 0);
5905
5906 /* Process the dies in the type unit. */
5907 if (die->child == NULL)
5908 {
5909 dump_die_for_error (die);
5910 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5911 bfd_get_filename (abfd));
5912 }
5913
5914 child_die = die->child;
5915
5916 while (child_die && child_die->tag)
5917 {
5918 process_die (child_die, cu);
5919
5920 child_die = sibling_die (child_die);
5921 }
5922
5923 do_cleanups (back_to);
5924 }
5925
5926 /* qsort helper for inherit_abstract_dies. */
5927
5928 static int
5929 unsigned_int_compar (const void *ap, const void *bp)
5930 {
5931 unsigned int a = *(unsigned int *) ap;
5932 unsigned int b = *(unsigned int *) bp;
5933
5934 return (a > b) - (b > a);
5935 }
5936
5937 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5938 Inherit only the children of the DW_AT_abstract_origin DIE not being
5939 already referenced by DW_AT_abstract_origin from the children of the
5940 current DIE. */
5941
5942 static void
5943 inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
5944 {
5945 struct die_info *child_die;
5946 unsigned die_children_count;
5947 /* CU offsets which were referenced by children of the current DIE. */
5948 sect_offset *offsets;
5949 sect_offset *offsets_end, *offsetp;
5950 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5951 struct die_info *origin_die;
5952 /* Iterator of the ORIGIN_DIE children. */
5953 struct die_info *origin_child_die;
5954 struct cleanup *cleanups;
5955 struct attribute *attr;
5956 struct dwarf2_cu *origin_cu;
5957 struct pending **origin_previous_list_in_scope;
5958
5959 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
5960 if (!attr)
5961 return;
5962
5963 /* Note that following die references may follow to a die in a
5964 different cu. */
5965
5966 origin_cu = cu;
5967 origin_die = follow_die_ref (die, attr, &origin_cu);
5968
5969 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5970 symbols in. */
5971 origin_previous_list_in_scope = origin_cu->list_in_scope;
5972 origin_cu->list_in_scope = cu->list_in_scope;
5973
5974 if (die->tag != origin_die->tag
5975 && !(die->tag == DW_TAG_inlined_subroutine
5976 && origin_die->tag == DW_TAG_subprogram))
5977 complaint (&symfile_complaints,
5978 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5979 die->offset.sect_off, origin_die->offset.sect_off);
5980
5981 child_die = die->child;
5982 die_children_count = 0;
5983 while (child_die && child_die->tag)
5984 {
5985 child_die = sibling_die (child_die);
5986 die_children_count++;
5987 }
5988 offsets = xmalloc (sizeof (*offsets) * die_children_count);
5989 cleanups = make_cleanup (xfree, offsets);
5990
5991 offsets_end = offsets;
5992 child_die = die->child;
5993 while (child_die && child_die->tag)
5994 {
5995 /* For each CHILD_DIE, find the corresponding child of
5996 ORIGIN_DIE. If there is more than one layer of
5997 DW_AT_abstract_origin, follow them all; there shouldn't be,
5998 but GCC versions at least through 4.4 generate this (GCC PR
5999 40573). */
6000 struct die_info *child_origin_die = child_die;
6001 struct dwarf2_cu *child_origin_cu = cu;
6002
6003 while (1)
6004 {
6005 attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin,
6006 child_origin_cu);
6007 if (attr == NULL)
6008 break;
6009 child_origin_die = follow_die_ref (child_origin_die, attr,
6010 &child_origin_cu);
6011 }
6012
6013 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
6014 counterpart may exist. */
6015 if (child_origin_die != child_die)
6016 {
6017 if (child_die->tag != child_origin_die->tag
6018 && !(child_die->tag == DW_TAG_inlined_subroutine
6019 && child_origin_die->tag == DW_TAG_subprogram))
6020 complaint (&symfile_complaints,
6021 _("Child DIE 0x%x and its abstract origin 0x%x have "
6022 "different tags"), child_die->offset.sect_off,
6023 child_origin_die->offset.sect_off);
6024 if (child_origin_die->parent != origin_die)
6025 complaint (&symfile_complaints,
6026 _("Child DIE 0x%x and its abstract origin 0x%x have "
6027 "different parents"), child_die->offset.sect_off,
6028 child_origin_die->offset.sect_off);
6029 else
6030 *offsets_end++ = child_origin_die->offset;
6031 }
6032 child_die = sibling_die (child_die);
6033 }
6034 qsort (offsets, offsets_end - offsets, sizeof (*offsets),
6035 unsigned_int_compar);
6036 for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++)
6037 if (offsetp[-1].sect_off == offsetp->sect_off)
6038 complaint (&symfile_complaints,
6039 _("Multiple children of DIE 0x%x refer "
6040 "to DIE 0x%x as their abstract origin"),
6041 die->offset.sect_off, offsetp->sect_off);
6042
6043 offsetp = offsets;
6044 origin_child_die = origin_die->child;
6045 while (origin_child_die && origin_child_die->tag)
6046 {
6047 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
6048 while (offsetp < offsets_end
6049 && offsetp->sect_off < origin_child_die->offset.sect_off)
6050 offsetp++;
6051 if (offsetp >= offsets_end
6052 || offsetp->sect_off > origin_child_die->offset.sect_off)
6053 {
6054 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
6055 process_die (origin_child_die, origin_cu);
6056 }
6057 origin_child_die = sibling_die (origin_child_die);
6058 }
6059 origin_cu->list_in_scope = origin_previous_list_in_scope;
6060
6061 do_cleanups (cleanups);
6062 }
6063
6064 static void
6065 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
6066 {
6067 struct objfile *objfile = cu->objfile;
6068 struct context_stack *new;
6069 CORE_ADDR lowpc;
6070 CORE_ADDR highpc;
6071 struct die_info *child_die;
6072 struct attribute *attr, *call_line, *call_file;
6073 char *name;
6074 CORE_ADDR baseaddr;
6075 struct block *block;
6076 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
6077 VEC (symbolp) *template_args = NULL;
6078 struct template_symbol *templ_func = NULL;
6079
6080 if (inlined_func)
6081 {
6082 /* If we do not have call site information, we can't show the
6083 caller of this inlined function. That's too confusing, so
6084 only use the scope for local variables. */
6085 call_line = dwarf2_attr (die, DW_AT_call_line, cu);
6086 call_file = dwarf2_attr (die, DW_AT_call_file, cu);
6087 if (call_line == NULL || call_file == NULL)
6088 {
6089 read_lexical_block_scope (die, cu);
6090 return;
6091 }
6092 }
6093
6094 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6095
6096 name = dwarf2_name (die, cu);
6097
6098 /* Ignore functions with missing or empty names. These are actually
6099 illegal according to the DWARF standard. */
6100 if (name == NULL)
6101 {
6102 complaint (&symfile_complaints,
6103 _("missing name for subprogram DIE at %d"),
6104 die->offset.sect_off);
6105 return;
6106 }
6107
6108 /* Ignore functions with missing or invalid low and high pc attributes. */
6109 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
6110 {
6111 attr = dwarf2_attr (die, DW_AT_external, cu);
6112 if (!attr || !DW_UNSND (attr))
6113 complaint (&symfile_complaints,
6114 _("cannot get low and high bounds "
6115 "for subprogram DIE at %d"),
6116 die->offset.sect_off);
6117 return;
6118 }
6119
6120 lowpc += baseaddr;
6121 highpc += baseaddr;
6122
6123 /* If we have any template arguments, then we must allocate a
6124 different sort of symbol. */
6125 for (child_die = die->child; child_die; child_die = sibling_die (child_die))
6126 {
6127 if (child_die->tag == DW_TAG_template_type_param
6128 || child_die->tag == DW_TAG_template_value_param)
6129 {
6130 templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack,
6131 struct template_symbol);
6132 templ_func->base.is_cplus_template_function = 1;
6133 break;
6134 }
6135 }
6136
6137 new = push_context (0, lowpc);
6138 new->name = new_symbol_full (die, read_type_die (die, cu), cu,
6139 (struct symbol *) templ_func);
6140
6141 /* If there is a location expression for DW_AT_frame_base, record
6142 it. */
6143 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
6144 if (attr)
6145 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
6146 expression is being recorded directly in the function's symbol
6147 and not in a separate frame-base object. I guess this hack is
6148 to avoid adding some sort of frame-base adjunct/annex to the
6149 function's symbol :-(. The problem with doing this is that it
6150 results in a function symbol with a location expression that
6151 has nothing to do with the location of the function, ouch! The
6152 relationship should be: a function's symbol has-a frame base; a
6153 frame-base has-a location expression. */
6154 dwarf2_symbol_mark_computed (attr, new->name, cu);
6155
6156 cu->list_in_scope = &local_symbols;
6157
6158 if (die->child != NULL)
6159 {
6160 child_die = die->child;
6161 while (child_die && child_die->tag)
6162 {
6163 if (child_die->tag == DW_TAG_template_type_param
6164 || child_die->tag == DW_TAG_template_value_param)
6165 {
6166 struct symbol *arg = new_symbol (child_die, NULL, cu);
6167
6168 if (arg != NULL)
6169 VEC_safe_push (symbolp, template_args, arg);
6170 }
6171 else
6172 process_die (child_die, cu);
6173 child_die = sibling_die (child_die);
6174 }
6175 }
6176
6177 inherit_abstract_dies (die, cu);
6178
6179 /* If we have a DW_AT_specification, we might need to import using
6180 directives from the context of the specification DIE. See the
6181 comment in determine_prefix. */
6182 if (cu->language == language_cplus
6183 && dwarf2_attr (die, DW_AT_specification, cu))
6184 {
6185 struct dwarf2_cu *spec_cu = cu;
6186 struct die_info *spec_die = die_specification (die, &spec_cu);
6187
6188 while (spec_die)
6189 {
6190 child_die = spec_die->child;
6191 while (child_die && child_die->tag)
6192 {
6193 if (child_die->tag == DW_TAG_imported_module)
6194 process_die (child_die, spec_cu);
6195 child_die = sibling_die (child_die);
6196 }
6197
6198 /* In some cases, GCC generates specification DIEs that
6199 themselves contain DW_AT_specification attributes. */
6200 spec_die = die_specification (spec_die, &spec_cu);
6201 }
6202 }
6203
6204 new = pop_context ();
6205 /* Make a block for the local symbols within. */
6206 block = finish_block (new->name, &local_symbols, new->old_blocks,
6207 lowpc, highpc, objfile);
6208
6209 /* For C++, set the block's scope. */
6210 if (cu->language == language_cplus || cu->language == language_fortran)
6211 cp_set_block_scope (new->name, block, &objfile->objfile_obstack,
6212 determine_prefix (die, cu),
6213 processing_has_namespace_info);
6214
6215 /* If we have address ranges, record them. */
6216 dwarf2_record_block_ranges (die, block, baseaddr, cu);
6217
6218 /* Attach template arguments to function. */
6219 if (! VEC_empty (symbolp, template_args))
6220 {
6221 gdb_assert (templ_func != NULL);
6222
6223 templ_func->n_template_arguments = VEC_length (symbolp, template_args);
6224 templ_func->template_arguments
6225 = obstack_alloc (&objfile->objfile_obstack,
6226 (templ_func->n_template_arguments
6227 * sizeof (struct symbol *)));
6228 memcpy (templ_func->template_arguments,
6229 VEC_address (symbolp, template_args),
6230 (templ_func->n_template_arguments * sizeof (struct symbol *)));
6231 VEC_free (symbolp, template_args);
6232 }
6233
6234 /* In C++, we can have functions nested inside functions (e.g., when
6235 a function declares a class that has methods). This means that
6236 when we finish processing a function scope, we may need to go
6237 back to building a containing block's symbol lists. */
6238 local_symbols = new->locals;
6239 param_symbols = new->params;
6240 using_directives = new->using_directives;
6241
6242 /* If we've finished processing a top-level function, subsequent
6243 symbols go in the file symbol list. */
6244 if (outermost_context_p ())
6245 cu->list_in_scope = &file_symbols;
6246 }
6247
6248 /* Process all the DIES contained within a lexical block scope. Start
6249 a new scope, process the dies, and then close the scope. */
6250
6251 static void
6252 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
6253 {
6254 struct objfile *objfile = cu->objfile;
6255 struct context_stack *new;
6256 CORE_ADDR lowpc, highpc;
6257 struct die_info *child_die;
6258 CORE_ADDR baseaddr;
6259
6260 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6261
6262 /* Ignore blocks with missing or invalid low and high pc attributes. */
6263 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
6264 as multiple lexical blocks? Handling children in a sane way would
6265 be nasty. Might be easier to properly extend generic blocks to
6266 describe ranges. */
6267 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
6268 return;
6269 lowpc += baseaddr;
6270 highpc += baseaddr;
6271
6272 push_context (0, lowpc);
6273 if (die->child != NULL)
6274 {
6275 child_die = die->child;
6276 while (child_die && child_die->tag)
6277 {
6278 process_die (child_die, cu);
6279 child_die = sibling_die (child_die);
6280 }
6281 }
6282 new = pop_context ();
6283
6284 if (local_symbols != NULL || using_directives != NULL)
6285 {
6286 struct block *block
6287 = finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
6288 highpc, objfile);
6289
6290 /* Note that recording ranges after traversing children, as we
6291 do here, means that recording a parent's ranges entails
6292 walking across all its children's ranges as they appear in
6293 the address map, which is quadratic behavior.
6294
6295 It would be nicer to record the parent's ranges before
6296 traversing its children, simply overriding whatever you find
6297 there. But since we don't even decide whether to create a
6298 block until after we've traversed its children, that's hard
6299 to do. */
6300 dwarf2_record_block_ranges (die, block, baseaddr, cu);
6301 }
6302 local_symbols = new->locals;
6303 using_directives = new->using_directives;
6304 }
6305
6306 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
6307
6308 static void
6309 read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
6310 {
6311 struct objfile *objfile = cu->objfile;
6312 struct gdbarch *gdbarch = get_objfile_arch (objfile);
6313 CORE_ADDR pc, baseaddr;
6314 struct attribute *attr;
6315 struct call_site *call_site, call_site_local;
6316 void **slot;
6317 int nparams;
6318 struct die_info *child_die;
6319
6320 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6321
6322 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6323 if (!attr)
6324 {
6325 complaint (&symfile_complaints,
6326 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
6327 "DIE 0x%x [in module %s]"),
6328 die->offset.sect_off, objfile->name);
6329 return;
6330 }
6331 pc = DW_ADDR (attr) + baseaddr;
6332
6333 if (cu->call_site_htab == NULL)
6334 cu->call_site_htab = htab_create_alloc_ex (16, core_addr_hash, core_addr_eq,
6335 NULL, &objfile->objfile_obstack,
6336 hashtab_obstack_allocate, NULL);
6337 call_site_local.pc = pc;
6338 slot = htab_find_slot (cu->call_site_htab, &call_site_local, INSERT);
6339 if (*slot != NULL)
6340 {
6341 complaint (&symfile_complaints,
6342 _("Duplicate PC %s for DW_TAG_GNU_call_site "
6343 "DIE 0x%x [in module %s]"),
6344 paddress (gdbarch, pc), die->offset.sect_off, objfile->name);
6345 return;
6346 }
6347
6348 /* Count parameters at the caller. */
6349
6350 nparams = 0;
6351 for (child_die = die->child; child_die && child_die->tag;
6352 child_die = sibling_die (child_die))
6353 {
6354 if (child_die->tag != DW_TAG_GNU_call_site_parameter)
6355 {
6356 complaint (&symfile_complaints,
6357 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
6358 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6359 child_die->tag, child_die->offset.sect_off, objfile->name);
6360 continue;
6361 }
6362
6363 nparams++;
6364 }
6365
6366 call_site = obstack_alloc (&objfile->objfile_obstack,
6367 (sizeof (*call_site)
6368 + (sizeof (*call_site->parameter)
6369 * (nparams - 1))));
6370 *slot = call_site;
6371 memset (call_site, 0, sizeof (*call_site) - sizeof (*call_site->parameter));
6372 call_site->pc = pc;
6373
6374 if (dwarf2_flag_true_p (die, DW_AT_GNU_tail_call, cu))
6375 {
6376 struct die_info *func_die;
6377
6378 /* Skip also over DW_TAG_inlined_subroutine. */
6379 for (func_die = die->parent;
6380 func_die && func_die->tag != DW_TAG_subprogram
6381 && func_die->tag != DW_TAG_subroutine_type;
6382 func_die = func_die->parent);
6383
6384 /* DW_AT_GNU_all_call_sites is a superset
6385 of DW_AT_GNU_all_tail_call_sites. */
6386 if (func_die
6387 && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_call_sites, cu)
6388 && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_tail_call_sites, cu))
6389 {
6390 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
6391 not complete. But keep CALL_SITE for look ups via call_site_htab,
6392 both the initial caller containing the real return address PC and
6393 the final callee containing the current PC of a chain of tail
6394 calls do not need to have the tail call list complete. But any
6395 function candidate for a virtual tail call frame searched via
6396 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
6397 determined unambiguously. */
6398 }
6399 else
6400 {
6401 struct type *func_type = NULL;
6402
6403 if (func_die)
6404 func_type = get_die_type (func_die, cu);
6405 if (func_type != NULL)
6406 {
6407 gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC);
6408
6409 /* Enlist this call site to the function. */
6410 call_site->tail_call_next = TYPE_TAIL_CALL_LIST (func_type);
6411 TYPE_TAIL_CALL_LIST (func_type) = call_site;
6412 }
6413 else
6414 complaint (&symfile_complaints,
6415 _("Cannot find function owning DW_TAG_GNU_call_site "
6416 "DIE 0x%x [in module %s]"),
6417 die->offset.sect_off, objfile->name);
6418 }
6419 }
6420
6421 attr = dwarf2_attr (die, DW_AT_GNU_call_site_target, cu);
6422 if (attr == NULL)
6423 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
6424 SET_FIELD_DWARF_BLOCK (call_site->target, NULL);
6425 if (!attr || (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0))
6426 /* Keep NULL DWARF_BLOCK. */;
6427 else if (attr_form_is_block (attr))
6428 {
6429 struct dwarf2_locexpr_baton *dlbaton;
6430
6431 dlbaton = obstack_alloc (&objfile->objfile_obstack, sizeof (*dlbaton));
6432 dlbaton->data = DW_BLOCK (attr)->data;
6433 dlbaton->size = DW_BLOCK (attr)->size;
6434 dlbaton->per_cu = cu->per_cu;
6435
6436 SET_FIELD_DWARF_BLOCK (call_site->target, dlbaton);
6437 }
6438 else if (is_ref_attr (attr))
6439 {
6440 struct dwarf2_cu *target_cu = cu;
6441 struct die_info *target_die;
6442
6443 target_die = follow_die_ref_or_sig (die, attr, &target_cu);
6444 gdb_assert (target_cu->objfile == objfile);
6445 if (die_is_declaration (target_die, target_cu))
6446 {
6447 const char *target_physname;
6448
6449 target_physname = dwarf2_physname (NULL, target_die, target_cu);
6450 if (target_physname == NULL)
6451 complaint (&symfile_complaints,
6452 _("DW_AT_GNU_call_site_target target DIE has invalid "
6453 "physname, for referencing DIE 0x%x [in module %s]"),
6454 die->offset.sect_off, objfile->name);
6455 else
6456 SET_FIELD_PHYSNAME (call_site->target, (char *) target_physname);
6457 }
6458 else
6459 {
6460 CORE_ADDR lowpc;
6461
6462 /* DW_AT_entry_pc should be preferred. */
6463 if (!dwarf2_get_pc_bounds (target_die, &lowpc, NULL, target_cu, NULL))
6464 complaint (&symfile_complaints,
6465 _("DW_AT_GNU_call_site_target target DIE has invalid "
6466 "low pc, for referencing DIE 0x%x [in module %s]"),
6467 die->offset.sect_off, objfile->name);
6468 else
6469 SET_FIELD_PHYSADDR (call_site->target, lowpc + baseaddr);
6470 }
6471 }
6472 else
6473 complaint (&symfile_complaints,
6474 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
6475 "block nor reference, for DIE 0x%x [in module %s]"),
6476 die->offset.sect_off, objfile->name);
6477
6478 call_site->per_cu = cu->per_cu;
6479
6480 for (child_die = die->child;
6481 child_die && child_die->tag;
6482 child_die = sibling_die (child_die))
6483 {
6484 struct dwarf2_locexpr_baton *dlbaton;
6485 struct call_site_parameter *parameter;
6486
6487 if (child_die->tag != DW_TAG_GNU_call_site_parameter)
6488 {
6489 /* Already printed the complaint above. */
6490 continue;
6491 }
6492
6493 gdb_assert (call_site->parameter_count < nparams);
6494 parameter = &call_site->parameter[call_site->parameter_count];
6495
6496 /* DW_AT_location specifies the register number. Value of the data
6497 assumed for the register is contained in DW_AT_GNU_call_site_value. */
6498
6499 attr = dwarf2_attr (child_die, DW_AT_location, cu);
6500 if (!attr || !attr_form_is_block (attr))
6501 {
6502 complaint (&symfile_complaints,
6503 _("No DW_FORM_block* DW_AT_location for "
6504 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6505 child_die->offset.sect_off, objfile->name);
6506 continue;
6507 }
6508 parameter->dwarf_reg = dwarf_block_to_dwarf_reg (DW_BLOCK (attr)->data,
6509 &DW_BLOCK (attr)->data[DW_BLOCK (attr)->size]);
6510 if (parameter->dwarf_reg == -1
6511 && !dwarf_block_to_sp_offset (gdbarch, DW_BLOCK (attr)->data,
6512 &DW_BLOCK (attr)->data[DW_BLOCK (attr)->size],
6513 &parameter->fb_offset))
6514 {
6515 complaint (&symfile_complaints,
6516 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
6517 "for DW_FORM_block* DW_AT_location for "
6518 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6519 child_die->offset.sect_off, objfile->name);
6520 continue;
6521 }
6522
6523 attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_value, cu);
6524 if (!attr_form_is_block (attr))
6525 {
6526 complaint (&symfile_complaints,
6527 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
6528 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6529 child_die->offset.sect_off, objfile->name);
6530 continue;
6531 }
6532 parameter->value = DW_BLOCK (attr)->data;
6533 parameter->value_size = DW_BLOCK (attr)->size;
6534
6535 /* Parameters are not pre-cleared by memset above. */
6536 parameter->data_value = NULL;
6537 parameter->data_value_size = 0;
6538 call_site->parameter_count++;
6539
6540 attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_data_value, cu);
6541 if (attr)
6542 {
6543 if (!attr_form_is_block (attr))
6544 complaint (&symfile_complaints,
6545 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
6546 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6547 child_die->offset.sect_off, objfile->name);
6548 else
6549 {
6550 parameter->data_value = DW_BLOCK (attr)->data;
6551 parameter->data_value_size = DW_BLOCK (attr)->size;
6552 }
6553 }
6554 }
6555 }
6556
6557 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
6558 Return 1 if the attributes are present and valid, otherwise, return 0.
6559 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
6560
6561 static int
6562 dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
6563 CORE_ADDR *high_return, struct dwarf2_cu *cu,
6564 struct partial_symtab *ranges_pst)
6565 {
6566 struct objfile *objfile = cu->objfile;
6567 struct comp_unit_head *cu_header = &cu->header;
6568 bfd *obfd = objfile->obfd;
6569 unsigned int addr_size = cu_header->addr_size;
6570 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
6571 /* Base address selection entry. */
6572 CORE_ADDR base;
6573 int found_base;
6574 unsigned int dummy;
6575 gdb_byte *buffer;
6576 CORE_ADDR marker;
6577 int low_set;
6578 CORE_ADDR low = 0;
6579 CORE_ADDR high = 0;
6580 CORE_ADDR baseaddr;
6581
6582 found_base = cu->base_known;
6583 base = cu->base_address;
6584
6585 dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges);
6586 if (offset >= dwarf2_per_objfile->ranges.size)
6587 {
6588 complaint (&symfile_complaints,
6589 _("Offset %d out of bounds for DW_AT_ranges attribute"),
6590 offset);
6591 return 0;
6592 }
6593 buffer = dwarf2_per_objfile->ranges.buffer + offset;
6594
6595 /* Read in the largest possible address. */
6596 marker = read_address (obfd, buffer, cu, &dummy);
6597 if ((marker & mask) == mask)
6598 {
6599 /* If we found the largest possible address, then
6600 read the base address. */
6601 base = read_address (obfd, buffer + addr_size, cu, &dummy);
6602 buffer += 2 * addr_size;
6603 offset += 2 * addr_size;
6604 found_base = 1;
6605 }
6606
6607 low_set = 0;
6608
6609 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6610
6611 while (1)
6612 {
6613 CORE_ADDR range_beginning, range_end;
6614
6615 range_beginning = read_address (obfd, buffer, cu, &dummy);
6616 buffer += addr_size;
6617 range_end = read_address (obfd, buffer, cu, &dummy);
6618 buffer += addr_size;
6619 offset += 2 * addr_size;
6620
6621 /* An end of list marker is a pair of zero addresses. */
6622 if (range_beginning == 0 && range_end == 0)
6623 /* Found the end of list entry. */
6624 break;
6625
6626 /* Each base address selection entry is a pair of 2 values.
6627 The first is the largest possible address, the second is
6628 the base address. Check for a base address here. */
6629 if ((range_beginning & mask) == mask)
6630 {
6631 /* If we found the largest possible address, then
6632 read the base address. */
6633 base = read_address (obfd, buffer + addr_size, cu, &dummy);
6634 found_base = 1;
6635 continue;
6636 }
6637
6638 if (!found_base)
6639 {
6640 /* We have no valid base address for the ranges
6641 data. */
6642 complaint (&symfile_complaints,
6643 _("Invalid .debug_ranges data (no base address)"));
6644 return 0;
6645 }
6646
6647 if (range_beginning > range_end)
6648 {
6649 /* Inverted range entries are invalid. */
6650 complaint (&symfile_complaints,
6651 _("Invalid .debug_ranges data (inverted range)"));
6652 return 0;
6653 }
6654
6655 /* Empty range entries have no effect. */
6656 if (range_beginning == range_end)
6657 continue;
6658
6659 range_beginning += base;
6660 range_end += base;
6661
6662 if (ranges_pst != NULL)
6663 addrmap_set_empty (objfile->psymtabs_addrmap,
6664 range_beginning + baseaddr,
6665 range_end - 1 + baseaddr,
6666 ranges_pst);
6667
6668 /* FIXME: This is recording everything as a low-high
6669 segment of consecutive addresses. We should have a
6670 data structure for discontiguous block ranges
6671 instead. */
6672 if (! low_set)
6673 {
6674 low = range_beginning;
6675 high = range_end;
6676 low_set = 1;
6677 }
6678 else
6679 {
6680 if (range_beginning < low)
6681 low = range_beginning;
6682 if (range_end > high)
6683 high = range_end;
6684 }
6685 }
6686
6687 if (! low_set)
6688 /* If the first entry is an end-of-list marker, the range
6689 describes an empty scope, i.e. no instructions. */
6690 return 0;
6691
6692 if (low_return)
6693 *low_return = low;
6694 if (high_return)
6695 *high_return = high;
6696 return 1;
6697 }
6698
6699 /* Get low and high pc attributes from a die. Return 1 if the attributes
6700 are present and valid, otherwise, return 0. Return -1 if the range is
6701 discontinuous, i.e. derived from DW_AT_ranges information. */
6702
6703 static int
6704 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
6705 CORE_ADDR *highpc, struct dwarf2_cu *cu,
6706 struct partial_symtab *pst)
6707 {
6708 struct attribute *attr;
6709 CORE_ADDR low = 0;
6710 CORE_ADDR high = 0;
6711 int ret = 0;
6712
6713 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
6714 if (attr)
6715 {
6716 high = DW_ADDR (attr);
6717 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6718 if (attr)
6719 low = DW_ADDR (attr);
6720 else
6721 /* Found high w/o low attribute. */
6722 return 0;
6723
6724 /* Found consecutive range of addresses. */
6725 ret = 1;
6726 }
6727 else
6728 {
6729 attr = dwarf2_attr (die, DW_AT_ranges, cu);
6730 if (attr != NULL)
6731 {
6732 /* Value of the DW_AT_ranges attribute is the offset in the
6733 .debug_ranges section. */
6734 if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst))
6735 return 0;
6736 /* Found discontinuous range of addresses. */
6737 ret = -1;
6738 }
6739 }
6740
6741 /* read_partial_die has also the strict LOW < HIGH requirement. */
6742 if (high <= low)
6743 return 0;
6744
6745 /* When using the GNU linker, .gnu.linkonce. sections are used to
6746 eliminate duplicate copies of functions and vtables and such.
6747 The linker will arbitrarily choose one and discard the others.
6748 The AT_*_pc values for such functions refer to local labels in
6749 these sections. If the section from that file was discarded, the
6750 labels are not in the output, so the relocs get a value of 0.
6751 If this is a discarded function, mark the pc bounds as invalid,
6752 so that GDB will ignore it. */
6753 if (low == 0 && !dwarf2_per_objfile->has_section_at_zero)
6754 return 0;
6755
6756 *lowpc = low;
6757 if (highpc)
6758 *highpc = high;
6759 return ret;
6760 }
6761
6762 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6763 its low and high PC addresses. Do nothing if these addresses could not
6764 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6765 and HIGHPC to the high address if greater than HIGHPC. */
6766
6767 static void
6768 dwarf2_get_subprogram_pc_bounds (struct die_info *die,
6769 CORE_ADDR *lowpc, CORE_ADDR *highpc,
6770 struct dwarf2_cu *cu)
6771 {
6772 CORE_ADDR low, high;
6773 struct die_info *child = die->child;
6774
6775 if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL))
6776 {
6777 *lowpc = min (*lowpc, low);
6778 *highpc = max (*highpc, high);
6779 }
6780
6781 /* If the language does not allow nested subprograms (either inside
6782 subprograms or lexical blocks), we're done. */
6783 if (cu->language != language_ada)
6784 return;
6785
6786 /* Check all the children of the given DIE. If it contains nested
6787 subprograms, then check their pc bounds. Likewise, we need to
6788 check lexical blocks as well, as they may also contain subprogram
6789 definitions. */
6790 while (child && child->tag)
6791 {
6792 if (child->tag == DW_TAG_subprogram
6793 || child->tag == DW_TAG_lexical_block)
6794 dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu);
6795 child = sibling_die (child);
6796 }
6797 }
6798
6799 /* Get the low and high pc's represented by the scope DIE, and store
6800 them in *LOWPC and *HIGHPC. If the correct values can't be
6801 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6802
6803 static void
6804 get_scope_pc_bounds (struct die_info *die,
6805 CORE_ADDR *lowpc, CORE_ADDR *highpc,
6806 struct dwarf2_cu *cu)
6807 {
6808 CORE_ADDR best_low = (CORE_ADDR) -1;
6809 CORE_ADDR best_high = (CORE_ADDR) 0;
6810 CORE_ADDR current_low, current_high;
6811
6812 if (dwarf2_get_pc_bounds (die, &current_low, &current_high, cu, NULL))
6813 {
6814 best_low = current_low;
6815 best_high = current_high;
6816 }
6817 else
6818 {
6819 struct die_info *child = die->child;
6820
6821 while (child && child->tag)
6822 {
6823 switch (child->tag) {
6824 case DW_TAG_subprogram:
6825 dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu);
6826 break;
6827 case DW_TAG_namespace:
6828 case DW_TAG_module:
6829 /* FIXME: carlton/2004-01-16: Should we do this for
6830 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6831 that current GCC's always emit the DIEs corresponding
6832 to definitions of methods of classes as children of a
6833 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6834 the DIEs giving the declarations, which could be
6835 anywhere). But I don't see any reason why the
6836 standards says that they have to be there. */
6837 get_scope_pc_bounds (child, &current_low, &current_high, cu);
6838
6839 if (current_low != ((CORE_ADDR) -1))
6840 {
6841 best_low = min (best_low, current_low);
6842 best_high = max (best_high, current_high);
6843 }
6844 break;
6845 default:
6846 /* Ignore. */
6847 break;
6848 }
6849
6850 child = sibling_die (child);
6851 }
6852 }
6853
6854 *lowpc = best_low;
6855 *highpc = best_high;
6856 }
6857
6858 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6859 in DIE. */
6860
6861 static void
6862 dwarf2_record_block_ranges (struct die_info *die, struct block *block,
6863 CORE_ADDR baseaddr, struct dwarf2_cu *cu)
6864 {
6865 struct objfile *objfile = cu->objfile;
6866 struct attribute *attr;
6867
6868 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
6869 if (attr)
6870 {
6871 CORE_ADDR high = DW_ADDR (attr);
6872
6873 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6874 if (attr)
6875 {
6876 CORE_ADDR low = DW_ADDR (attr);
6877
6878 record_block_range (block, baseaddr + low, baseaddr + high - 1);
6879 }
6880 }
6881
6882 attr = dwarf2_attr (die, DW_AT_ranges, cu);
6883 if (attr)
6884 {
6885 bfd *obfd = objfile->obfd;
6886
6887 /* The value of the DW_AT_ranges attribute is the offset of the
6888 address range list in the .debug_ranges section. */
6889 unsigned long offset = DW_UNSND (attr);
6890 gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset;
6891
6892 /* For some target architectures, but not others, the
6893 read_address function sign-extends the addresses it returns.
6894 To recognize base address selection entries, we need a
6895 mask. */
6896 unsigned int addr_size = cu->header.addr_size;
6897 CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
6898
6899 /* The base address, to which the next pair is relative. Note
6900 that this 'base' is a DWARF concept: most entries in a range
6901 list are relative, to reduce the number of relocs against the
6902 debugging information. This is separate from this function's
6903 'baseaddr' argument, which GDB uses to relocate debugging
6904 information from a shared library based on the address at
6905 which the library was loaded. */
6906 CORE_ADDR base = cu->base_address;
6907 int base_known = cu->base_known;
6908
6909 gdb_assert (dwarf2_per_objfile->ranges.readin);
6910 if (offset >= dwarf2_per_objfile->ranges.size)
6911 {
6912 complaint (&symfile_complaints,
6913 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6914 offset);
6915 return;
6916 }
6917
6918 for (;;)
6919 {
6920 unsigned int bytes_read;
6921 CORE_ADDR start, end;
6922
6923 start = read_address (obfd, buffer, cu, &bytes_read);
6924 buffer += bytes_read;
6925 end = read_address (obfd, buffer, cu, &bytes_read);
6926 buffer += bytes_read;
6927
6928 /* Did we find the end of the range list? */
6929 if (start == 0 && end == 0)
6930 break;
6931
6932 /* Did we find a base address selection entry? */
6933 else if ((start & base_select_mask) == base_select_mask)
6934 {
6935 base = end;
6936 base_known = 1;
6937 }
6938
6939 /* We found an ordinary address range. */
6940 else
6941 {
6942 if (!base_known)
6943 {
6944 complaint (&symfile_complaints,
6945 _("Invalid .debug_ranges data "
6946 "(no base address)"));
6947 return;
6948 }
6949
6950 if (start > end)
6951 {
6952 /* Inverted range entries are invalid. */
6953 complaint (&symfile_complaints,
6954 _("Invalid .debug_ranges data "
6955 "(inverted range)"));
6956 return;
6957 }
6958
6959 /* Empty range entries have no effect. */
6960 if (start == end)
6961 continue;
6962
6963 record_block_range (block,
6964 baseaddr + base + start,
6965 baseaddr + base + end - 1);
6966 }
6967 }
6968 }
6969 }
6970
6971 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6972 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6973 during 4.6.0 experimental. */
6974
6975 static int
6976 producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu)
6977 {
6978 const char *cs;
6979 int major, minor, release;
6980 int result = 0;
6981
6982 if (cu->producer == NULL)
6983 {
6984 /* For unknown compilers expect their behavior is DWARF version
6985 compliant.
6986
6987 GCC started to support .debug_types sections by -gdwarf-4 since
6988 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6989 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6990 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6991 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6992
6993 return 0;
6994 }
6995
6996 if (cu->checked_producer)
6997 return cu->producer_is_gxx_lt_4_6;
6998
6999 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
7000
7001 if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) != 0)
7002 {
7003 /* For non-GCC compilers expect their behavior is DWARF version
7004 compliant. */
7005 }
7006 else
7007 {
7008 cs = &cu->producer[strlen ("GNU ")];
7009 while (*cs && !isdigit (*cs))
7010 cs++;
7011 if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3)
7012 {
7013 /* Not recognized as GCC. */
7014 }
7015 else
7016 result = major < 4 || (major == 4 && minor < 6);
7017 }
7018
7019 cu->checked_producer = 1;
7020 cu->producer_is_gxx_lt_4_6 = result;
7021
7022 return result;
7023 }
7024
7025 /* Return the default accessibility type if it is not overriden by
7026 DW_AT_accessibility. */
7027
7028 static enum dwarf_access_attribute
7029 dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu)
7030 {
7031 if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu))
7032 {
7033 /* The default DWARF 2 accessibility for members is public, the default
7034 accessibility for inheritance is private. */
7035
7036 if (die->tag != DW_TAG_inheritance)
7037 return DW_ACCESS_public;
7038 else
7039 return DW_ACCESS_private;
7040 }
7041 else
7042 {
7043 /* DWARF 3+ defines the default accessibility a different way. The same
7044 rules apply now for DW_TAG_inheritance as for the members and it only
7045 depends on the container kind. */
7046
7047 if (die->parent->tag == DW_TAG_class_type)
7048 return DW_ACCESS_private;
7049 else
7050 return DW_ACCESS_public;
7051 }
7052 }
7053
7054 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
7055 offset. If the attribute was not found return 0, otherwise return
7056 1. If it was found but could not properly be handled, set *OFFSET
7057 to 0. */
7058
7059 static int
7060 handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
7061 LONGEST *offset)
7062 {
7063 struct attribute *attr;
7064
7065 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
7066 if (attr != NULL)
7067 {
7068 *offset = 0;
7069
7070 /* Note that we do not check for a section offset first here.
7071 This is because DW_AT_data_member_location is new in DWARF 4,
7072 so if we see it, we can assume that a constant form is really
7073 a constant and not a section offset. */
7074 if (attr_form_is_constant (attr))
7075 *offset = dwarf2_get_attr_constant_value (attr, 0);
7076 else if (attr_form_is_section_offset (attr))
7077 dwarf2_complex_location_expr_complaint ();
7078 else if (attr_form_is_block (attr))
7079 *offset = decode_locdesc (DW_BLOCK (attr), cu);
7080 else
7081 dwarf2_complex_location_expr_complaint ();
7082
7083 return 1;
7084 }
7085
7086 return 0;
7087 }
7088
7089 /* Add an aggregate field to the field list. */
7090
7091 static void
7092 dwarf2_add_field (struct field_info *fip, struct die_info *die,
7093 struct dwarf2_cu *cu)
7094 {
7095 struct objfile *objfile = cu->objfile;
7096 struct gdbarch *gdbarch = get_objfile_arch (objfile);
7097 struct nextfield *new_field;
7098 struct attribute *attr;
7099 struct field *fp;
7100 char *fieldname = "";
7101
7102 /* Allocate a new field list entry and link it in. */
7103 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
7104 make_cleanup (xfree, new_field);
7105 memset (new_field, 0, sizeof (struct nextfield));
7106
7107 if (die->tag == DW_TAG_inheritance)
7108 {
7109 new_field->next = fip->baseclasses;
7110 fip->baseclasses = new_field;
7111 }
7112 else
7113 {
7114 new_field->next = fip->fields;
7115 fip->fields = new_field;
7116 }
7117 fip->nfields++;
7118
7119 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
7120 if (attr)
7121 new_field->accessibility = DW_UNSND (attr);
7122 else
7123 new_field->accessibility = dwarf2_default_access_attribute (die, cu);
7124 if (new_field->accessibility != DW_ACCESS_public)
7125 fip->non_public_fields = 1;
7126
7127 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
7128 if (attr)
7129 new_field->virtuality = DW_UNSND (attr);
7130 else
7131 new_field->virtuality = DW_VIRTUALITY_none;
7132
7133 fp = &new_field->field;
7134
7135 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
7136 {
7137 LONGEST offset;
7138
7139 /* Data member other than a C++ static data member. */
7140
7141 /* Get type of field. */
7142 fp->type = die_type (die, cu);
7143
7144 SET_FIELD_BITPOS (*fp, 0);
7145
7146 /* Get bit size of field (zero if none). */
7147 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
7148 if (attr)
7149 {
7150 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
7151 }
7152 else
7153 {
7154 FIELD_BITSIZE (*fp) = 0;
7155 }
7156
7157 /* Get bit offset of field. */
7158 if (handle_data_member_location (die, cu, &offset))
7159 SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
7160 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
7161 if (attr)
7162 {
7163 if (gdbarch_bits_big_endian (gdbarch))
7164 {
7165 /* For big endian bits, the DW_AT_bit_offset gives the
7166 additional bit offset from the MSB of the containing
7167 anonymous object to the MSB of the field. We don't
7168 have to do anything special since we don't need to
7169 know the size of the anonymous object. */
7170 SET_FIELD_BITPOS (*fp, FIELD_BITPOS (*fp) + DW_UNSND (attr));
7171 }
7172 else
7173 {
7174 /* For little endian bits, compute the bit offset to the
7175 MSB of the anonymous object, subtract off the number of
7176 bits from the MSB of the field to the MSB of the
7177 object, and then subtract off the number of bits of
7178 the field itself. The result is the bit offset of
7179 the LSB of the field. */
7180 int anonymous_size;
7181 int bit_offset = DW_UNSND (attr);
7182
7183 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7184 if (attr)
7185 {
7186 /* The size of the anonymous object containing
7187 the bit field is explicit, so use the
7188 indicated size (in bytes). */
7189 anonymous_size = DW_UNSND (attr);
7190 }
7191 else
7192 {
7193 /* The size of the anonymous object containing
7194 the bit field must be inferred from the type
7195 attribute of the data member containing the
7196 bit field. */
7197 anonymous_size = TYPE_LENGTH (fp->type);
7198 }
7199 SET_FIELD_BITPOS (*fp,
7200 (FIELD_BITPOS (*fp)
7201 + anonymous_size * bits_per_byte
7202 - bit_offset - FIELD_BITSIZE (*fp)));
7203 }
7204 }
7205
7206 /* Get name of field. */
7207 fieldname = dwarf2_name (die, cu);
7208 if (fieldname == NULL)
7209 fieldname = "";
7210
7211 /* The name is already allocated along with this objfile, so we don't
7212 need to duplicate it for the type. */
7213 fp->name = fieldname;
7214
7215 /* Change accessibility for artificial fields (e.g. virtual table
7216 pointer or virtual base class pointer) to private. */
7217 if (dwarf2_attr (die, DW_AT_artificial, cu))
7218 {
7219 FIELD_ARTIFICIAL (*fp) = 1;
7220 new_field->accessibility = DW_ACCESS_private;
7221 fip->non_public_fields = 1;
7222 }
7223 }
7224 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
7225 {
7226 /* C++ static member. */
7227
7228 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
7229 is a declaration, but all versions of G++ as of this writing
7230 (so through at least 3.2.1) incorrectly generate
7231 DW_TAG_variable tags. */
7232
7233 const char *physname;
7234
7235 /* Get name of field. */
7236 fieldname = dwarf2_name (die, cu);
7237 if (fieldname == NULL)
7238 return;
7239
7240 attr = dwarf2_attr (die, DW_AT_const_value, cu);
7241 if (attr
7242 /* Only create a symbol if this is an external value.
7243 new_symbol checks this and puts the value in the global symbol
7244 table, which we want. If it is not external, new_symbol
7245 will try to put the value in cu->list_in_scope which is wrong. */
7246 && dwarf2_flag_true_p (die, DW_AT_external, cu))
7247 {
7248 /* A static const member, not much different than an enum as far as
7249 we're concerned, except that we can support more types. */
7250 new_symbol (die, NULL, cu);
7251 }
7252
7253 /* Get physical name. */
7254 physname = dwarf2_physname (fieldname, die, cu);
7255
7256 /* The name is already allocated along with this objfile, so we don't
7257 need to duplicate it for the type. */
7258 SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
7259 FIELD_TYPE (*fp) = die_type (die, cu);
7260 FIELD_NAME (*fp) = fieldname;
7261 }
7262 else if (die->tag == DW_TAG_inheritance)
7263 {
7264 LONGEST offset;
7265
7266 /* C++ base class field. */
7267 if (handle_data_member_location (die, cu, &offset))
7268 SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
7269 FIELD_BITSIZE (*fp) = 0;
7270 FIELD_TYPE (*fp) = die_type (die, cu);
7271 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
7272 fip->nbaseclasses++;
7273 }
7274 }
7275
7276 /* Add a typedef defined in the scope of the FIP's class. */
7277
7278 static void
7279 dwarf2_add_typedef (struct field_info *fip, struct die_info *die,
7280 struct dwarf2_cu *cu)
7281 {
7282 struct objfile *objfile = cu->objfile;
7283 struct typedef_field_list *new_field;
7284 struct attribute *attr;
7285 struct typedef_field *fp;
7286 char *fieldname = "";
7287
7288 /* Allocate a new field list entry and link it in. */
7289 new_field = xzalloc (sizeof (*new_field));
7290 make_cleanup (xfree, new_field);
7291
7292 gdb_assert (die->tag == DW_TAG_typedef);
7293
7294 fp = &new_field->field;
7295
7296 /* Get name of field. */
7297 fp->name = dwarf2_name (die, cu);
7298 if (fp->name == NULL)
7299 return;
7300
7301 fp->type = read_type_die (die, cu);
7302
7303 new_field->next = fip->typedef_field_list;
7304 fip->typedef_field_list = new_field;
7305 fip->typedef_field_list_count++;
7306 }
7307
7308 /* Create the vector of fields, and attach it to the type. */
7309
7310 static void
7311 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
7312 struct dwarf2_cu *cu)
7313 {
7314 int nfields = fip->nfields;
7315
7316 /* Record the field count, allocate space for the array of fields,
7317 and create blank accessibility bitfields if necessary. */
7318 TYPE_NFIELDS (type) = nfields;
7319 TYPE_FIELDS (type) = (struct field *)
7320 TYPE_ALLOC (type, sizeof (struct field) * nfields);
7321 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
7322
7323 if (fip->non_public_fields && cu->language != language_ada)
7324 {
7325 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7326
7327 TYPE_FIELD_PRIVATE_BITS (type) =
7328 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
7329 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
7330
7331 TYPE_FIELD_PROTECTED_BITS (type) =
7332 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
7333 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
7334
7335 TYPE_FIELD_IGNORE_BITS (type) =
7336 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
7337 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
7338 }
7339
7340 /* If the type has baseclasses, allocate and clear a bit vector for
7341 TYPE_FIELD_VIRTUAL_BITS. */
7342 if (fip->nbaseclasses && cu->language != language_ada)
7343 {
7344 int num_bytes = B_BYTES (fip->nbaseclasses);
7345 unsigned char *pointer;
7346
7347 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7348 pointer = TYPE_ALLOC (type, num_bytes);
7349 TYPE_FIELD_VIRTUAL_BITS (type) = pointer;
7350 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
7351 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
7352 }
7353
7354 /* Copy the saved-up fields into the field vector. Start from the head of
7355 the list, adding to the tail of the field array, so that they end up in
7356 the same order in the array in which they were added to the list. */
7357 while (nfields-- > 0)
7358 {
7359 struct nextfield *fieldp;
7360
7361 if (fip->fields)
7362 {
7363 fieldp = fip->fields;
7364 fip->fields = fieldp->next;
7365 }
7366 else
7367 {
7368 fieldp = fip->baseclasses;
7369 fip->baseclasses = fieldp->next;
7370 }
7371
7372 TYPE_FIELD (type, nfields) = fieldp->field;
7373 switch (fieldp->accessibility)
7374 {
7375 case DW_ACCESS_private:
7376 if (cu->language != language_ada)
7377 SET_TYPE_FIELD_PRIVATE (type, nfields);
7378 break;
7379
7380 case DW_ACCESS_protected:
7381 if (cu->language != language_ada)
7382 SET_TYPE_FIELD_PROTECTED (type, nfields);
7383 break;
7384
7385 case DW_ACCESS_public:
7386 break;
7387
7388 default:
7389 /* Unknown accessibility. Complain and treat it as public. */
7390 {
7391 complaint (&symfile_complaints, _("unsupported accessibility %d"),
7392 fieldp->accessibility);
7393 }
7394 break;
7395 }
7396 if (nfields < fip->nbaseclasses)
7397 {
7398 switch (fieldp->virtuality)
7399 {
7400 case DW_VIRTUALITY_virtual:
7401 case DW_VIRTUALITY_pure_virtual:
7402 if (cu->language == language_ada)
7403 error (_("unexpected virtuality in component of Ada type"));
7404 SET_TYPE_FIELD_VIRTUAL (type, nfields);
7405 break;
7406 }
7407 }
7408 }
7409 }
7410
7411 /* Add a member function to the proper fieldlist. */
7412
7413 static void
7414 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
7415 struct type *type, struct dwarf2_cu *cu)
7416 {
7417 struct objfile *objfile = cu->objfile;
7418 struct attribute *attr;
7419 struct fnfieldlist *flp;
7420 int i;
7421 struct fn_field *fnp;
7422 char *fieldname;
7423 struct nextfnfield *new_fnfield;
7424 struct type *this_type;
7425 enum dwarf_access_attribute accessibility;
7426
7427 if (cu->language == language_ada)
7428 error (_("unexpected member function in Ada type"));
7429
7430 /* Get name of member function. */
7431 fieldname = dwarf2_name (die, cu);
7432 if (fieldname == NULL)
7433 return;
7434
7435 /* Look up member function name in fieldlist. */
7436 for (i = 0; i < fip->nfnfields; i++)
7437 {
7438 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
7439 break;
7440 }
7441
7442 /* Create new list element if necessary. */
7443 if (i < fip->nfnfields)
7444 flp = &fip->fnfieldlists[i];
7445 else
7446 {
7447 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
7448 {
7449 fip->fnfieldlists = (struct fnfieldlist *)
7450 xrealloc (fip->fnfieldlists,
7451 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
7452 * sizeof (struct fnfieldlist));
7453 if (fip->nfnfields == 0)
7454 make_cleanup (free_current_contents, &fip->fnfieldlists);
7455 }
7456 flp = &fip->fnfieldlists[fip->nfnfields];
7457 flp->name = fieldname;
7458 flp->length = 0;
7459 flp->head = NULL;
7460 i = fip->nfnfields++;
7461 }
7462
7463 /* Create a new member function field and chain it to the field list
7464 entry. */
7465 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
7466 make_cleanup (xfree, new_fnfield);
7467 memset (new_fnfield, 0, sizeof (struct nextfnfield));
7468 new_fnfield->next = flp->head;
7469 flp->head = new_fnfield;
7470 flp->length++;
7471
7472 /* Fill in the member function field info. */
7473 fnp = &new_fnfield->fnfield;
7474
7475 /* Delay processing of the physname until later. */
7476 if (cu->language == language_cplus || cu->language == language_java)
7477 {
7478 add_to_method_list (type, i, flp->length - 1, fieldname,
7479 die, cu);
7480 }
7481 else
7482 {
7483 const char *physname = dwarf2_physname (fieldname, die, cu);
7484 fnp->physname = physname ? physname : "";
7485 }
7486
7487 fnp->type = alloc_type (objfile);
7488 this_type = read_type_die (die, cu);
7489 if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC)
7490 {
7491 int nparams = TYPE_NFIELDS (this_type);
7492
7493 /* TYPE is the domain of this method, and THIS_TYPE is the type
7494 of the method itself (TYPE_CODE_METHOD). */
7495 smash_to_method_type (fnp->type, type,
7496 TYPE_TARGET_TYPE (this_type),
7497 TYPE_FIELDS (this_type),
7498 TYPE_NFIELDS (this_type),
7499 TYPE_VARARGS (this_type));
7500
7501 /* Handle static member functions.
7502 Dwarf2 has no clean way to discern C++ static and non-static
7503 member functions. G++ helps GDB by marking the first
7504 parameter for non-static member functions (which is the this
7505 pointer) as artificial. We obtain this information from
7506 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
7507 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0)
7508 fnp->voffset = VOFFSET_STATIC;
7509 }
7510 else
7511 complaint (&symfile_complaints, _("member function type missing for '%s'"),
7512 dwarf2_full_name (fieldname, die, cu));
7513
7514 /* Get fcontext from DW_AT_containing_type if present. */
7515 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
7516 fnp->fcontext = die_containing_type (die, cu);
7517
7518 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
7519 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
7520
7521 /* Get accessibility. */
7522 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
7523 if (attr)
7524 accessibility = DW_UNSND (attr);
7525 else
7526 accessibility = dwarf2_default_access_attribute (die, cu);
7527 switch (accessibility)
7528 {
7529 case DW_ACCESS_private:
7530 fnp->is_private = 1;
7531 break;
7532 case DW_ACCESS_protected:
7533 fnp->is_protected = 1;
7534 break;
7535 }
7536
7537 /* Check for artificial methods. */
7538 attr = dwarf2_attr (die, DW_AT_artificial, cu);
7539 if (attr && DW_UNSND (attr) != 0)
7540 fnp->is_artificial = 1;
7541
7542 /* Get index in virtual function table if it is a virtual member
7543 function. For older versions of GCC, this is an offset in the
7544 appropriate virtual table, as specified by DW_AT_containing_type.
7545 For everyone else, it is an expression to be evaluated relative
7546 to the object address. */
7547
7548 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
7549 if (attr)
7550 {
7551 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0)
7552 {
7553 if (DW_BLOCK (attr)->data[0] == DW_OP_constu)
7554 {
7555 /* Old-style GCC. */
7556 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
7557 }
7558 else if (DW_BLOCK (attr)->data[0] == DW_OP_deref
7559 || (DW_BLOCK (attr)->size > 1
7560 && DW_BLOCK (attr)->data[0] == DW_OP_deref_size
7561 && DW_BLOCK (attr)->data[1] == cu->header.addr_size))
7562 {
7563 struct dwarf_block blk;
7564 int offset;
7565
7566 offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref
7567 ? 1 : 2);
7568 blk.size = DW_BLOCK (attr)->size - offset;
7569 blk.data = DW_BLOCK (attr)->data + offset;
7570 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu);
7571 if ((fnp->voffset % cu->header.addr_size) != 0)
7572 dwarf2_complex_location_expr_complaint ();
7573 else
7574 fnp->voffset /= cu->header.addr_size;
7575 fnp->voffset += 2;
7576 }
7577 else
7578 dwarf2_complex_location_expr_complaint ();
7579
7580 if (!fnp->fcontext)
7581 fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0));
7582 }
7583 else if (attr_form_is_section_offset (attr))
7584 {
7585 dwarf2_complex_location_expr_complaint ();
7586 }
7587 else
7588 {
7589 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
7590 fieldname);
7591 }
7592 }
7593 else
7594 {
7595 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
7596 if (attr && DW_UNSND (attr))
7597 {
7598 /* GCC does this, as of 2008-08-25; PR debug/37237. */
7599 complaint (&symfile_complaints,
7600 _("Member function \"%s\" (offset %d) is virtual "
7601 "but the vtable offset is not specified"),
7602 fieldname, die->offset.sect_off);
7603 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7604 TYPE_CPLUS_DYNAMIC (type) = 1;
7605 }
7606 }
7607 }
7608
7609 /* Create the vector of member function fields, and attach it to the type. */
7610
7611 static void
7612 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
7613 struct dwarf2_cu *cu)
7614 {
7615 struct fnfieldlist *flp;
7616 int i;
7617
7618 if (cu->language == language_ada)
7619 error (_("unexpected member functions in Ada type"));
7620
7621 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7622 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
7623 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
7624
7625 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
7626 {
7627 struct nextfnfield *nfp = flp->head;
7628 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
7629 int k;
7630
7631 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
7632 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
7633 fn_flp->fn_fields = (struct fn_field *)
7634 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
7635 for (k = flp->length; (k--, nfp); nfp = nfp->next)
7636 fn_flp->fn_fields[k] = nfp->fnfield;
7637 }
7638
7639 TYPE_NFN_FIELDS (type) = fip->nfnfields;
7640 }
7641
7642 /* Returns non-zero if NAME is the name of a vtable member in CU's
7643 language, zero otherwise. */
7644 static int
7645 is_vtable_name (const char *name, struct dwarf2_cu *cu)
7646 {
7647 static const char vptr[] = "_vptr";
7648 static const char vtable[] = "vtable";
7649
7650 /* Look for the C++ and Java forms of the vtable. */
7651 if ((cu->language == language_java
7652 && strncmp (name, vtable, sizeof (vtable) - 1) == 0)
7653 || (strncmp (name, vptr, sizeof (vptr) - 1) == 0
7654 && is_cplus_marker (name[sizeof (vptr) - 1])))
7655 return 1;
7656
7657 return 0;
7658 }
7659
7660 /* GCC outputs unnamed structures that are really pointers to member
7661 functions, with the ABI-specified layout. If TYPE describes
7662 such a structure, smash it into a member function type.
7663
7664 GCC shouldn't do this; it should just output pointer to member DIEs.
7665 This is GCC PR debug/28767. */
7666
7667 static void
7668 quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
7669 {
7670 struct type *pfn_type, *domain_type, *new_type;
7671
7672 /* Check for a structure with no name and two children. */
7673 if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2)
7674 return;
7675
7676 /* Check for __pfn and __delta members. */
7677 if (TYPE_FIELD_NAME (type, 0) == NULL
7678 || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0
7679 || TYPE_FIELD_NAME (type, 1) == NULL
7680 || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0)
7681 return;
7682
7683 /* Find the type of the method. */
7684 pfn_type = TYPE_FIELD_TYPE (type, 0);
7685 if (pfn_type == NULL
7686 || TYPE_CODE (pfn_type) != TYPE_CODE_PTR
7687 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC)
7688 return;
7689
7690 /* Look for the "this" argument. */
7691 pfn_type = TYPE_TARGET_TYPE (pfn_type);
7692 if (TYPE_NFIELDS (pfn_type) == 0
7693 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7694 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR)
7695 return;
7696
7697 domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
7698 new_type = alloc_type (objfile);
7699 smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type),
7700 TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type),
7701 TYPE_VARARGS (pfn_type));
7702 smash_to_methodptr_type (type, new_type);
7703 }
7704
7705 /* Called when we find the DIE that starts a structure or union scope
7706 (definition) to create a type for the structure or union. Fill in
7707 the type's name and general properties; the members will not be
7708 processed until process_structure_type.
7709
7710 NOTE: we need to call these functions regardless of whether or not the
7711 DIE has a DW_AT_name attribute, since it might be an anonymous
7712 structure or union. This gets the type entered into our set of
7713 user defined types.
7714
7715 However, if the structure is incomplete (an opaque struct/union)
7716 then suppress creating a symbol table entry for it since gdb only
7717 wants to find the one with the complete definition. Note that if
7718 it is complete, we just call new_symbol, which does it's own
7719 checking about whether the struct/union is anonymous or not (and
7720 suppresses creating a symbol table entry itself). */
7721
7722 static struct type *
7723 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
7724 {
7725 struct objfile *objfile = cu->objfile;
7726 struct type *type;
7727 struct attribute *attr;
7728 char *name;
7729
7730 /* If the definition of this type lives in .debug_types, read that type.
7731 Don't follow DW_AT_specification though, that will take us back up
7732 the chain and we want to go down. */
7733 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
7734 if (attr)
7735 {
7736 struct dwarf2_cu *type_cu = cu;
7737 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
7738
7739 /* We could just recurse on read_structure_type, but we need to call
7740 get_die_type to ensure only one type for this DIE is created.
7741 This is important, for example, because for c++ classes we need
7742 TYPE_NAME set which is only done by new_symbol. Blech. */
7743 type = read_type_die (type_die, type_cu);
7744
7745 /* TYPE_CU may not be the same as CU.
7746 Ensure TYPE is recorded in CU's type_hash table. */
7747 return set_die_type (die, type, cu);
7748 }
7749
7750 type = alloc_type (objfile);
7751 INIT_CPLUS_SPECIFIC (type);
7752
7753 name = dwarf2_name (die, cu);
7754 if (name != NULL)
7755 {
7756 if (cu->language == language_cplus
7757 || cu->language == language_java)
7758 {
7759 char *full_name = (char *) dwarf2_full_name (name, die, cu);
7760
7761 /* dwarf2_full_name might have already finished building the DIE's
7762 type. If so, there is no need to continue. */
7763 if (get_die_type (die, cu) != NULL)
7764 return get_die_type (die, cu);
7765
7766 TYPE_TAG_NAME (type) = full_name;
7767 if (die->tag == DW_TAG_structure_type
7768 || die->tag == DW_TAG_class_type)
7769 TYPE_NAME (type) = TYPE_TAG_NAME (type);
7770 }
7771 else
7772 {
7773 /* The name is already allocated along with this objfile, so
7774 we don't need to duplicate it for the type. */
7775 TYPE_TAG_NAME (type) = (char *) name;
7776 if (die->tag == DW_TAG_class_type)
7777 TYPE_NAME (type) = TYPE_TAG_NAME (type);
7778 }
7779 }
7780
7781 if (die->tag == DW_TAG_structure_type)
7782 {
7783 TYPE_CODE (type) = TYPE_CODE_STRUCT;
7784 }
7785 else if (die->tag == DW_TAG_union_type)
7786 {
7787 TYPE_CODE (type) = TYPE_CODE_UNION;
7788 }
7789 else
7790 {
7791 TYPE_CODE (type) = TYPE_CODE_CLASS;
7792 }
7793
7794 if (cu->language == language_cplus && die->tag == DW_TAG_class_type)
7795 TYPE_DECLARED_CLASS (type) = 1;
7796
7797 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7798 if (attr)
7799 {
7800 TYPE_LENGTH (type) = DW_UNSND (attr);
7801 }
7802 else
7803 {
7804 TYPE_LENGTH (type) = 0;
7805 }
7806
7807 TYPE_STUB_SUPPORTED (type) = 1;
7808 if (die_is_declaration (die, cu))
7809 TYPE_STUB (type) = 1;
7810 else if (attr == NULL && die->child == NULL
7811 && producer_is_realview (cu->producer))
7812 /* RealView does not output the required DW_AT_declaration
7813 on incomplete types. */
7814 TYPE_STUB (type) = 1;
7815
7816 /* We need to add the type field to the die immediately so we don't
7817 infinitely recurse when dealing with pointers to the structure
7818 type within the structure itself. */
7819 set_die_type (die, type, cu);
7820
7821 /* set_die_type should be already done. */
7822 set_descriptive_type (type, die, cu);
7823
7824 return type;
7825 }
7826
7827 /* Finish creating a structure or union type, including filling in
7828 its members and creating a symbol for it. */
7829
7830 static void
7831 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
7832 {
7833 struct objfile *objfile = cu->objfile;
7834 struct die_info *child_die = die->child;
7835 struct type *type;
7836
7837 type = get_die_type (die, cu);
7838 if (type == NULL)
7839 type = read_structure_type (die, cu);
7840
7841 if (die->child != NULL && ! die_is_declaration (die, cu))
7842 {
7843 struct field_info fi;
7844 struct die_info *child_die;
7845 VEC (symbolp) *template_args = NULL;
7846 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
7847
7848 memset (&fi, 0, sizeof (struct field_info));
7849
7850 child_die = die->child;
7851
7852 while (child_die && child_die->tag)
7853 {
7854 if (child_die->tag == DW_TAG_member
7855 || child_die->tag == DW_TAG_variable)
7856 {
7857 /* NOTE: carlton/2002-11-05: A C++ static data member
7858 should be a DW_TAG_member that is a declaration, but
7859 all versions of G++ as of this writing (so through at
7860 least 3.2.1) incorrectly generate DW_TAG_variable
7861 tags for them instead. */
7862 dwarf2_add_field (&fi, child_die, cu);
7863 }
7864 else if (child_die->tag == DW_TAG_subprogram)
7865 {
7866 /* C++ member function. */
7867 dwarf2_add_member_fn (&fi, child_die, type, cu);
7868 }
7869 else if (child_die->tag == DW_TAG_inheritance)
7870 {
7871 /* C++ base class field. */
7872 dwarf2_add_field (&fi, child_die, cu);
7873 }
7874 else if (child_die->tag == DW_TAG_typedef)
7875 dwarf2_add_typedef (&fi, child_die, cu);
7876 else if (child_die->tag == DW_TAG_template_type_param
7877 || child_die->tag == DW_TAG_template_value_param)
7878 {
7879 struct symbol *arg = new_symbol (child_die, NULL, cu);
7880
7881 if (arg != NULL)
7882 VEC_safe_push (symbolp, template_args, arg);
7883 }
7884
7885 child_die = sibling_die (child_die);
7886 }
7887
7888 /* Attach template arguments to type. */
7889 if (! VEC_empty (symbolp, template_args))
7890 {
7891 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7892 TYPE_N_TEMPLATE_ARGUMENTS (type)
7893 = VEC_length (symbolp, template_args);
7894 TYPE_TEMPLATE_ARGUMENTS (type)
7895 = obstack_alloc (&objfile->objfile_obstack,
7896 (TYPE_N_TEMPLATE_ARGUMENTS (type)
7897 * sizeof (struct symbol *)));
7898 memcpy (TYPE_TEMPLATE_ARGUMENTS (type),
7899 VEC_address (symbolp, template_args),
7900 (TYPE_N_TEMPLATE_ARGUMENTS (type)
7901 * sizeof (struct symbol *)));
7902 VEC_free (symbolp, template_args);
7903 }
7904
7905 /* Attach fields and member functions to the type. */
7906 if (fi.nfields)
7907 dwarf2_attach_fields_to_type (&fi, type, cu);
7908 if (fi.nfnfields)
7909 {
7910 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
7911
7912 /* Get the type which refers to the base class (possibly this
7913 class itself) which contains the vtable pointer for the current
7914 class from the DW_AT_containing_type attribute. This use of
7915 DW_AT_containing_type is a GNU extension. */
7916
7917 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
7918 {
7919 struct type *t = die_containing_type (die, cu);
7920
7921 TYPE_VPTR_BASETYPE (type) = t;
7922 if (type == t)
7923 {
7924 int i;
7925
7926 /* Our own class provides vtbl ptr. */
7927 for (i = TYPE_NFIELDS (t) - 1;
7928 i >= TYPE_N_BASECLASSES (t);
7929 --i)
7930 {
7931 const char *fieldname = TYPE_FIELD_NAME (t, i);
7932
7933 if (is_vtable_name (fieldname, cu))
7934 {
7935 TYPE_VPTR_FIELDNO (type) = i;
7936 break;
7937 }
7938 }
7939
7940 /* Complain if virtual function table field not found. */
7941 if (i < TYPE_N_BASECLASSES (t))
7942 complaint (&symfile_complaints,
7943 _("virtual function table pointer "
7944 "not found when defining class '%s'"),
7945 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
7946 "");
7947 }
7948 else
7949 {
7950 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
7951 }
7952 }
7953 else if (cu->producer
7954 && strncmp (cu->producer,
7955 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7956 {
7957 /* The IBM XLC compiler does not provide direct indication
7958 of the containing type, but the vtable pointer is
7959 always named __vfp. */
7960
7961 int i;
7962
7963 for (i = TYPE_NFIELDS (type) - 1;
7964 i >= TYPE_N_BASECLASSES (type);
7965 --i)
7966 {
7967 if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0)
7968 {
7969 TYPE_VPTR_FIELDNO (type) = i;
7970 TYPE_VPTR_BASETYPE (type) = type;
7971 break;
7972 }
7973 }
7974 }
7975 }
7976
7977 /* Copy fi.typedef_field_list linked list elements content into the
7978 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7979 if (fi.typedef_field_list)
7980 {
7981 int i = fi.typedef_field_list_count;
7982
7983 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7984 TYPE_TYPEDEF_FIELD_ARRAY (type)
7985 = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i);
7986 TYPE_TYPEDEF_FIELD_COUNT (type) = i;
7987
7988 /* Reverse the list order to keep the debug info elements order. */
7989 while (--i >= 0)
7990 {
7991 struct typedef_field *dest, *src;
7992
7993 dest = &TYPE_TYPEDEF_FIELD (type, i);
7994 src = &fi.typedef_field_list->field;
7995 fi.typedef_field_list = fi.typedef_field_list->next;
7996 *dest = *src;
7997 }
7998 }
7999
8000 do_cleanups (back_to);
8001
8002 if (HAVE_CPLUS_STRUCT (type))
8003 TYPE_CPLUS_REALLY_JAVA (type) = cu->language == language_java;
8004 }
8005
8006 quirk_gcc_member_function_pointer (type, objfile);
8007
8008 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
8009 snapshots) has been known to create a die giving a declaration
8010 for a class that has, as a child, a die giving a definition for a
8011 nested class. So we have to process our children even if the
8012 current die is a declaration. Normally, of course, a declaration
8013 won't have any children at all. */
8014
8015 while (child_die != NULL && child_die->tag)
8016 {
8017 if (child_die->tag == DW_TAG_member
8018 || child_die->tag == DW_TAG_variable
8019 || child_die->tag == DW_TAG_inheritance
8020 || child_die->tag == DW_TAG_template_value_param
8021 || child_die->tag == DW_TAG_template_type_param)
8022 {
8023 /* Do nothing. */
8024 }
8025 else
8026 process_die (child_die, cu);
8027
8028 child_die = sibling_die (child_die);
8029 }
8030
8031 /* Do not consider external references. According to the DWARF standard,
8032 these DIEs are identified by the fact that they have no byte_size
8033 attribute, and a declaration attribute. */
8034 if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL
8035 || !die_is_declaration (die, cu))
8036 new_symbol (die, type, cu);
8037 }
8038
8039 /* Given a DW_AT_enumeration_type die, set its type. We do not
8040 complete the type's fields yet, or create any symbols. */
8041
8042 static struct type *
8043 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
8044 {
8045 struct objfile *objfile = cu->objfile;
8046 struct type *type;
8047 struct attribute *attr;
8048 const char *name;
8049
8050 /* If the definition of this type lives in .debug_types, read that type.
8051 Don't follow DW_AT_specification though, that will take us back up
8052 the chain and we want to go down. */
8053 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
8054 if (attr)
8055 {
8056 struct dwarf2_cu *type_cu = cu;
8057 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
8058
8059 type = read_type_die (type_die, type_cu);
8060
8061 /* TYPE_CU may not be the same as CU.
8062 Ensure TYPE is recorded in CU's type_hash table. */
8063 return set_die_type (die, type, cu);
8064 }
8065
8066 type = alloc_type (objfile);
8067
8068 TYPE_CODE (type) = TYPE_CODE_ENUM;
8069 name = dwarf2_full_name (NULL, die, cu);
8070 if (name != NULL)
8071 TYPE_TAG_NAME (type) = (char *) name;
8072
8073 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8074 if (attr)
8075 {
8076 TYPE_LENGTH (type) = DW_UNSND (attr);
8077 }
8078 else
8079 {
8080 TYPE_LENGTH (type) = 0;
8081 }
8082
8083 /* The enumeration DIE can be incomplete. In Ada, any type can be
8084 declared as private in the package spec, and then defined only
8085 inside the package body. Such types are known as Taft Amendment
8086 Types. When another package uses such a type, an incomplete DIE
8087 may be generated by the compiler. */
8088 if (die_is_declaration (die, cu))
8089 TYPE_STUB (type) = 1;
8090
8091 return set_die_type (die, type, cu);
8092 }
8093
8094 /* Given a pointer to a die which begins an enumeration, process all
8095 the dies that define the members of the enumeration, and create the
8096 symbol for the enumeration type.
8097
8098 NOTE: We reverse the order of the element list. */
8099
8100 static void
8101 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
8102 {
8103 struct type *this_type;
8104
8105 this_type = get_die_type (die, cu);
8106 if (this_type == NULL)
8107 this_type = read_enumeration_type (die, cu);
8108
8109 if (die->child != NULL)
8110 {
8111 struct die_info *child_die;
8112 struct symbol *sym;
8113 struct field *fields = NULL;
8114 int num_fields = 0;
8115 int unsigned_enum = 1;
8116 char *name;
8117 int flag_enum = 1;
8118 ULONGEST mask = 0;
8119
8120 child_die = die->child;
8121 while (child_die && child_die->tag)
8122 {
8123 if (child_die->tag != DW_TAG_enumerator)
8124 {
8125 process_die (child_die, cu);
8126 }
8127 else
8128 {
8129 name = dwarf2_name (child_die, cu);
8130 if (name)
8131 {
8132 sym = new_symbol (child_die, this_type, cu);
8133 if (SYMBOL_VALUE (sym) < 0)
8134 {
8135 unsigned_enum = 0;
8136 flag_enum = 0;
8137 }
8138 else if ((mask & SYMBOL_VALUE (sym)) != 0)
8139 flag_enum = 0;
8140 else
8141 mask |= SYMBOL_VALUE (sym);
8142
8143 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
8144 {
8145 fields = (struct field *)
8146 xrealloc (fields,
8147 (num_fields + DW_FIELD_ALLOC_CHUNK)
8148 * sizeof (struct field));
8149 }
8150
8151 FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym);
8152 FIELD_TYPE (fields[num_fields]) = NULL;
8153 SET_FIELD_ENUMVAL (fields[num_fields], SYMBOL_VALUE (sym));
8154 FIELD_BITSIZE (fields[num_fields]) = 0;
8155
8156 num_fields++;
8157 }
8158 }
8159
8160 child_die = sibling_die (child_die);
8161 }
8162
8163 if (num_fields)
8164 {
8165 TYPE_NFIELDS (this_type) = num_fields;
8166 TYPE_FIELDS (this_type) = (struct field *)
8167 TYPE_ALLOC (this_type, sizeof (struct field) * num_fields);
8168 memcpy (TYPE_FIELDS (this_type), fields,
8169 sizeof (struct field) * num_fields);
8170 xfree (fields);
8171 }
8172 if (unsigned_enum)
8173 TYPE_UNSIGNED (this_type) = 1;
8174 if (flag_enum)
8175 TYPE_FLAG_ENUM (this_type) = 1;
8176 }
8177
8178 /* If we are reading an enum from a .debug_types unit, and the enum
8179 is a declaration, and the enum is not the signatured type in the
8180 unit, then we do not want to add a symbol for it. Adding a
8181 symbol would in some cases obscure the true definition of the
8182 enum, giving users an incomplete type when the definition is
8183 actually available. Note that we do not want to do this for all
8184 enums which are just declarations, because C++0x allows forward
8185 enum declarations. */
8186 if (cu->per_cu->debug_types_section
8187 && die_is_declaration (die, cu))
8188 {
8189 struct signatured_type *sig_type;
8190
8191 sig_type
8192 = lookup_signatured_type_at_offset (dwarf2_per_objfile->objfile,
8193 cu->per_cu->debug_types_section,
8194 cu->per_cu->offset);
8195 if (sig_type->per_cu.offset.sect_off + sig_type->type_offset.cu_off
8196 != die->offset.sect_off)
8197 return;
8198 }
8199
8200 new_symbol (die, this_type, cu);
8201 }
8202
8203 /* Extract all information from a DW_TAG_array_type DIE and put it in
8204 the DIE's type field. For now, this only handles one dimensional
8205 arrays. */
8206
8207 static struct type *
8208 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
8209 {
8210 struct objfile *objfile = cu->objfile;
8211 struct die_info *child_die;
8212 struct type *type;
8213 struct type *element_type, *range_type, *index_type;
8214 struct type **range_types = NULL;
8215 struct attribute *attr;
8216 int ndim = 0;
8217 struct cleanup *back_to;
8218 char *name;
8219
8220 element_type = die_type (die, cu);
8221
8222 /* The die_type call above may have already set the type for this DIE. */
8223 type = get_die_type (die, cu);
8224 if (type)
8225 return type;
8226
8227 /* Irix 6.2 native cc creates array types without children for
8228 arrays with unspecified length. */
8229 if (die->child == NULL)
8230 {
8231 index_type = objfile_type (objfile)->builtin_int;
8232 range_type = create_range_type (NULL, index_type, 0, -1);
8233 type = create_array_type (NULL, element_type, range_type);
8234 return set_die_type (die, type, cu);
8235 }
8236
8237 back_to = make_cleanup (null_cleanup, NULL);
8238 child_die = die->child;
8239 while (child_die && child_die->tag)
8240 {
8241 if (child_die->tag == DW_TAG_subrange_type)
8242 {
8243 struct type *child_type = read_type_die (child_die, cu);
8244
8245 if (child_type != NULL)
8246 {
8247 /* The range type was succesfully read. Save it for the
8248 array type creation. */
8249 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
8250 {
8251 range_types = (struct type **)
8252 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
8253 * sizeof (struct type *));
8254 if (ndim == 0)
8255 make_cleanup (free_current_contents, &range_types);
8256 }
8257 range_types[ndim++] = child_type;
8258 }
8259 }
8260 child_die = sibling_die (child_die);
8261 }
8262
8263 /* Dwarf2 dimensions are output from left to right, create the
8264 necessary array types in backwards order. */
8265
8266 type = element_type;
8267
8268 if (read_array_order (die, cu) == DW_ORD_col_major)
8269 {
8270 int i = 0;
8271
8272 while (i < ndim)
8273 type = create_array_type (NULL, type, range_types[i++]);
8274 }
8275 else
8276 {
8277 while (ndim-- > 0)
8278 type = create_array_type (NULL, type, range_types[ndim]);
8279 }
8280
8281 /* Understand Dwarf2 support for vector types (like they occur on
8282 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
8283 array type. This is not part of the Dwarf2/3 standard yet, but a
8284 custom vendor extension. The main difference between a regular
8285 array and the vector variant is that vectors are passed by value
8286 to functions. */
8287 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
8288 if (attr)
8289 make_vector_type (type);
8290
8291 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
8292 implementation may choose to implement triple vectors using this
8293 attribute. */
8294 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8295 if (attr)
8296 {
8297 if (DW_UNSND (attr) >= TYPE_LENGTH (type))
8298 TYPE_LENGTH (type) = DW_UNSND (attr);
8299 else
8300 complaint (&symfile_complaints,
8301 _("DW_AT_byte_size for array type smaller "
8302 "than the total size of elements"));
8303 }
8304
8305 name = dwarf2_name (die, cu);
8306 if (name)
8307 TYPE_NAME (type) = name;
8308
8309 /* Install the type in the die. */
8310 set_die_type (die, type, cu);
8311
8312 /* set_die_type should be already done. */
8313 set_descriptive_type (type, die, cu);
8314
8315 do_cleanups (back_to);
8316
8317 return type;
8318 }
8319
8320 static enum dwarf_array_dim_ordering
8321 read_array_order (struct die_info *die, struct dwarf2_cu *cu)
8322 {
8323 struct attribute *attr;
8324
8325 attr = dwarf2_attr (die, DW_AT_ordering, cu);
8326
8327 if (attr) return DW_SND (attr);
8328
8329 /* GNU F77 is a special case, as at 08/2004 array type info is the
8330 opposite order to the dwarf2 specification, but data is still
8331 laid out as per normal fortran.
8332
8333 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
8334 version checking. */
8335
8336 if (cu->language == language_fortran
8337 && cu->producer && strstr (cu->producer, "GNU F77"))
8338 {
8339 return DW_ORD_row_major;
8340 }
8341
8342 switch (cu->language_defn->la_array_ordering)
8343 {
8344 case array_column_major:
8345 return DW_ORD_col_major;
8346 case array_row_major:
8347 default:
8348 return DW_ORD_row_major;
8349 };
8350 }
8351
8352 /* Extract all information from a DW_TAG_set_type DIE and put it in
8353 the DIE's type field. */
8354
8355 static struct type *
8356 read_set_type (struct die_info *die, struct dwarf2_cu *cu)
8357 {
8358 struct type *domain_type, *set_type;
8359 struct attribute *attr;
8360
8361 domain_type = die_type (die, cu);
8362
8363 /* The die_type call above may have already set the type for this DIE. */
8364 set_type = get_die_type (die, cu);
8365 if (set_type)
8366 return set_type;
8367
8368 set_type = create_set_type (NULL, domain_type);
8369
8370 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8371 if (attr)
8372 TYPE_LENGTH (set_type) = DW_UNSND (attr);
8373
8374 return set_die_type (die, set_type, cu);
8375 }
8376
8377 /* First cut: install each common block member as a global variable. */
8378
8379 static void
8380 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
8381 {
8382 struct die_info *child_die;
8383 struct attribute *attr;
8384 struct symbol *sym;
8385 CORE_ADDR base = (CORE_ADDR) 0;
8386
8387 attr = dwarf2_attr (die, DW_AT_location, cu);
8388 if (attr)
8389 {
8390 /* Support the .debug_loc offsets. */
8391 if (attr_form_is_block (attr))
8392 {
8393 base = decode_locdesc (DW_BLOCK (attr), cu);
8394 }
8395 else if (attr_form_is_section_offset (attr))
8396 {
8397 dwarf2_complex_location_expr_complaint ();
8398 }
8399 else
8400 {
8401 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8402 "common block member");
8403 }
8404 }
8405 if (die->child != NULL)
8406 {
8407 child_die = die->child;
8408 while (child_die && child_die->tag)
8409 {
8410 LONGEST offset;
8411
8412 sym = new_symbol (child_die, NULL, cu);
8413 if (sym != NULL
8414 && handle_data_member_location (child_die, cu, &offset))
8415 {
8416 SYMBOL_VALUE_ADDRESS (sym) = base + offset;
8417 add_symbol_to_list (sym, &global_symbols);
8418 }
8419 child_die = sibling_die (child_die);
8420 }
8421 }
8422 }
8423
8424 /* Create a type for a C++ namespace. */
8425
8426 static struct type *
8427 read_namespace_type (struct die_info *die, struct dwarf2_cu *cu)
8428 {
8429 struct objfile *objfile = cu->objfile;
8430 const char *previous_prefix, *name;
8431 int is_anonymous;
8432 struct type *type;
8433
8434 /* For extensions, reuse the type of the original namespace. */
8435 if (dwarf2_attr (die, DW_AT_extension, cu) != NULL)
8436 {
8437 struct die_info *ext_die;
8438 struct dwarf2_cu *ext_cu = cu;
8439
8440 ext_die = dwarf2_extension (die, &ext_cu);
8441 type = read_type_die (ext_die, ext_cu);
8442
8443 /* EXT_CU may not be the same as CU.
8444 Ensure TYPE is recorded in CU's type_hash table. */
8445 return set_die_type (die, type, cu);
8446 }
8447
8448 name = namespace_name (die, &is_anonymous, cu);
8449
8450 /* Now build the name of the current namespace. */
8451
8452 previous_prefix = determine_prefix (die, cu);
8453 if (previous_prefix[0] != '\0')
8454 name = typename_concat (&objfile->objfile_obstack,
8455 previous_prefix, name, 0, cu);
8456
8457 /* Create the type. */
8458 type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL,
8459 objfile);
8460 TYPE_NAME (type) = (char *) name;
8461 TYPE_TAG_NAME (type) = TYPE_NAME (type);
8462
8463 return set_die_type (die, type, cu);
8464 }
8465
8466 /* Read a C++ namespace. */
8467
8468 static void
8469 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
8470 {
8471 struct objfile *objfile = cu->objfile;
8472 int is_anonymous;
8473
8474 /* Add a symbol associated to this if we haven't seen the namespace
8475 before. Also, add a using directive if it's an anonymous
8476 namespace. */
8477
8478 if (dwarf2_attr (die, DW_AT_extension, cu) == NULL)
8479 {
8480 struct type *type;
8481
8482 type = read_type_die (die, cu);
8483 new_symbol (die, type, cu);
8484
8485 namespace_name (die, &is_anonymous, cu);
8486 if (is_anonymous)
8487 {
8488 const char *previous_prefix = determine_prefix (die, cu);
8489
8490 cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL,
8491 NULL, NULL, &objfile->objfile_obstack);
8492 }
8493 }
8494
8495 if (die->child != NULL)
8496 {
8497 struct die_info *child_die = die->child;
8498
8499 while (child_die && child_die->tag)
8500 {
8501 process_die (child_die, cu);
8502 child_die = sibling_die (child_die);
8503 }
8504 }
8505 }
8506
8507 /* Read a Fortran module as type. This DIE can be only a declaration used for
8508 imported module. Still we need that type as local Fortran "use ... only"
8509 declaration imports depend on the created type in determine_prefix. */
8510
8511 static struct type *
8512 read_module_type (struct die_info *die, struct dwarf2_cu *cu)
8513 {
8514 struct objfile *objfile = cu->objfile;
8515 char *module_name;
8516 struct type *type;
8517
8518 module_name = dwarf2_name (die, cu);
8519 if (!module_name)
8520 complaint (&symfile_complaints,
8521 _("DW_TAG_module has no name, offset 0x%x"),
8522 die->offset.sect_off);
8523 type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile);
8524
8525 /* determine_prefix uses TYPE_TAG_NAME. */
8526 TYPE_TAG_NAME (type) = TYPE_NAME (type);
8527
8528 return set_die_type (die, type, cu);
8529 }
8530
8531 /* Read a Fortran module. */
8532
8533 static void
8534 read_module (struct die_info *die, struct dwarf2_cu *cu)
8535 {
8536 struct die_info *child_die = die->child;
8537
8538 while (child_die && child_die->tag)
8539 {
8540 process_die (child_die, cu);
8541 child_die = sibling_die (child_die);
8542 }
8543 }
8544
8545 /* Return the name of the namespace represented by DIE. Set
8546 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
8547 namespace. */
8548
8549 static const char *
8550 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
8551 {
8552 struct die_info *current_die;
8553 const char *name = NULL;
8554
8555 /* Loop through the extensions until we find a name. */
8556
8557 for (current_die = die;
8558 current_die != NULL;
8559 current_die = dwarf2_extension (die, &cu))
8560 {
8561 name = dwarf2_name (current_die, cu);
8562 if (name != NULL)
8563 break;
8564 }
8565
8566 /* Is it an anonymous namespace? */
8567
8568 *is_anonymous = (name == NULL);
8569 if (*is_anonymous)
8570 name = CP_ANONYMOUS_NAMESPACE_STR;
8571
8572 return name;
8573 }
8574
8575 /* Extract all information from a DW_TAG_pointer_type DIE and add to
8576 the user defined type vector. */
8577
8578 static struct type *
8579 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
8580 {
8581 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
8582 struct comp_unit_head *cu_header = &cu->header;
8583 struct type *type;
8584 struct attribute *attr_byte_size;
8585 struct attribute *attr_address_class;
8586 int byte_size, addr_class;
8587 struct type *target_type;
8588
8589 target_type = die_type (die, cu);
8590
8591 /* The die_type call above may have already set the type for this DIE. */
8592 type = get_die_type (die, cu);
8593 if (type)
8594 return type;
8595
8596 type = lookup_pointer_type (target_type);
8597
8598 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
8599 if (attr_byte_size)
8600 byte_size = DW_UNSND (attr_byte_size);
8601 else
8602 byte_size = cu_header->addr_size;
8603
8604 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
8605 if (attr_address_class)
8606 addr_class = DW_UNSND (attr_address_class);
8607 else
8608 addr_class = DW_ADDR_none;
8609
8610 /* If the pointer size or address class is different than the
8611 default, create a type variant marked as such and set the
8612 length accordingly. */
8613 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
8614 {
8615 if (gdbarch_address_class_type_flags_p (gdbarch))
8616 {
8617 int type_flags;
8618
8619 type_flags = gdbarch_address_class_type_flags
8620 (gdbarch, byte_size, addr_class);
8621 gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
8622 == 0);
8623 type = make_type_with_address_space (type, type_flags);
8624 }
8625 else if (TYPE_LENGTH (type) != byte_size)
8626 {
8627 complaint (&symfile_complaints,
8628 _("invalid pointer size %d"), byte_size);
8629 }
8630 else
8631 {
8632 /* Should we also complain about unhandled address classes? */
8633 }
8634 }
8635
8636 TYPE_LENGTH (type) = byte_size;
8637 return set_die_type (die, type, cu);
8638 }
8639
8640 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
8641 the user defined type vector. */
8642
8643 static struct type *
8644 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
8645 {
8646 struct type *type;
8647 struct type *to_type;
8648 struct type *domain;
8649
8650 to_type = die_type (die, cu);
8651 domain = die_containing_type (die, cu);
8652
8653 /* The calls above may have already set the type for this DIE. */
8654 type = get_die_type (die, cu);
8655 if (type)
8656 return type;
8657
8658 if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD)
8659 type = lookup_methodptr_type (to_type);
8660 else
8661 type = lookup_memberptr_type (to_type, domain);
8662
8663 return set_die_type (die, type, cu);
8664 }
8665
8666 /* Extract all information from a DW_TAG_reference_type DIE and add to
8667 the user defined type vector. */
8668
8669 static struct type *
8670 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
8671 {
8672 struct comp_unit_head *cu_header = &cu->header;
8673 struct type *type, *target_type;
8674 struct attribute *attr;
8675
8676 target_type = die_type (die, cu);
8677
8678 /* The die_type call above may have already set the type for this DIE. */
8679 type = get_die_type (die, cu);
8680 if (type)
8681 return type;
8682
8683 type = lookup_reference_type (target_type);
8684 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8685 if (attr)
8686 {
8687 TYPE_LENGTH (type) = DW_UNSND (attr);
8688 }
8689 else
8690 {
8691 TYPE_LENGTH (type) = cu_header->addr_size;
8692 }
8693 return set_die_type (die, type, cu);
8694 }
8695
8696 static struct type *
8697 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
8698 {
8699 struct type *base_type, *cv_type;
8700
8701 base_type = die_type (die, cu);
8702
8703 /* The die_type call above may have already set the type for this DIE. */
8704 cv_type = get_die_type (die, cu);
8705 if (cv_type)
8706 return cv_type;
8707
8708 /* In case the const qualifier is applied to an array type, the element type
8709 is so qualified, not the array type (section 6.7.3 of C99). */
8710 if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY)
8711 {
8712 struct type *el_type, *inner_array;
8713
8714 base_type = copy_type (base_type);
8715 inner_array = base_type;
8716
8717 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
8718 {
8719 TYPE_TARGET_TYPE (inner_array) =
8720 copy_type (TYPE_TARGET_TYPE (inner_array));
8721 inner_array = TYPE_TARGET_TYPE (inner_array);
8722 }
8723
8724 el_type = TYPE_TARGET_TYPE (inner_array);
8725 TYPE_TARGET_TYPE (inner_array) =
8726 make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL);
8727
8728 return set_die_type (die, base_type, cu);
8729 }
8730
8731 cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
8732 return set_die_type (die, cv_type, cu);
8733 }
8734
8735 static struct type *
8736 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
8737 {
8738 struct type *base_type, *cv_type;
8739
8740 base_type = die_type (die, cu);
8741
8742 /* The die_type call above may have already set the type for this DIE. */
8743 cv_type = get_die_type (die, cu);
8744 if (cv_type)
8745 return cv_type;
8746
8747 cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
8748 return set_die_type (die, cv_type, cu);
8749 }
8750
8751 /* Extract all information from a DW_TAG_string_type DIE and add to
8752 the user defined type vector. It isn't really a user defined type,
8753 but it behaves like one, with other DIE's using an AT_user_def_type
8754 attribute to reference it. */
8755
8756 static struct type *
8757 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
8758 {
8759 struct objfile *objfile = cu->objfile;
8760 struct gdbarch *gdbarch = get_objfile_arch (objfile);
8761 struct type *type, *range_type, *index_type, *char_type;
8762 struct attribute *attr;
8763 unsigned int length;
8764
8765 attr = dwarf2_attr (die, DW_AT_string_length, cu);
8766 if (attr)
8767 {
8768 length = DW_UNSND (attr);
8769 }
8770 else
8771 {
8772 /* Check for the DW_AT_byte_size attribute. */
8773 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8774 if (attr)
8775 {
8776 length = DW_UNSND (attr);
8777 }
8778 else
8779 {
8780 length = 1;
8781 }
8782 }
8783
8784 index_type = objfile_type (objfile)->builtin_int;
8785 range_type = create_range_type (NULL, index_type, 1, length);
8786 char_type = language_string_char_type (cu->language_defn, gdbarch);
8787 type = create_string_type (NULL, char_type, range_type);
8788
8789 return set_die_type (die, type, cu);
8790 }
8791
8792 /* Handle DIES due to C code like:
8793
8794 struct foo
8795 {
8796 int (*funcp)(int a, long l);
8797 int b;
8798 };
8799
8800 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8801
8802 static struct type *
8803 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
8804 {
8805 struct objfile *objfile = cu->objfile;
8806 struct type *type; /* Type that this function returns. */
8807 struct type *ftype; /* Function that returns above type. */
8808 struct attribute *attr;
8809
8810 type = die_type (die, cu);
8811
8812 /* The die_type call above may have already set the type for this DIE. */
8813 ftype = get_die_type (die, cu);
8814 if (ftype)
8815 return ftype;
8816
8817 ftype = lookup_function_type (type);
8818
8819 /* All functions in C++, Pascal and Java have prototypes. */
8820 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
8821 if ((attr && (DW_UNSND (attr) != 0))
8822 || cu->language == language_cplus
8823 || cu->language == language_java
8824 || cu->language == language_pascal)
8825 TYPE_PROTOTYPED (ftype) = 1;
8826 else if (producer_is_realview (cu->producer))
8827 /* RealView does not emit DW_AT_prototyped. We can not
8828 distinguish prototyped and unprototyped functions; default to
8829 prototyped, since that is more common in modern code (and
8830 RealView warns about unprototyped functions). */
8831 TYPE_PROTOTYPED (ftype) = 1;
8832
8833 /* Store the calling convention in the type if it's available in
8834 the subroutine die. Otherwise set the calling convention to
8835 the default value DW_CC_normal. */
8836 attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
8837 if (attr)
8838 TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr);
8839 else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL"))
8840 TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL;
8841 else
8842 TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal;
8843
8844 /* We need to add the subroutine type to the die immediately so
8845 we don't infinitely recurse when dealing with parameters
8846 declared as the same subroutine type. */
8847 set_die_type (die, ftype, cu);
8848
8849 if (die->child != NULL)
8850 {
8851 struct type *void_type = objfile_type (objfile)->builtin_void;
8852 struct die_info *child_die;
8853 int nparams, iparams;
8854
8855 /* Count the number of parameters.
8856 FIXME: GDB currently ignores vararg functions, but knows about
8857 vararg member functions. */
8858 nparams = 0;
8859 child_die = die->child;
8860 while (child_die && child_die->tag)
8861 {
8862 if (child_die->tag == DW_TAG_formal_parameter)
8863 nparams++;
8864 else if (child_die->tag == DW_TAG_unspecified_parameters)
8865 TYPE_VARARGS (ftype) = 1;
8866 child_die = sibling_die (child_die);
8867 }
8868
8869 /* Allocate storage for parameters and fill them in. */
8870 TYPE_NFIELDS (ftype) = nparams;
8871 TYPE_FIELDS (ftype) = (struct field *)
8872 TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
8873
8874 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8875 even if we error out during the parameters reading below. */
8876 for (iparams = 0; iparams < nparams; iparams++)
8877 TYPE_FIELD_TYPE (ftype, iparams) = void_type;
8878
8879 iparams = 0;
8880 child_die = die->child;
8881 while (child_die && child_die->tag)
8882 {
8883 if (child_die->tag == DW_TAG_formal_parameter)
8884 {
8885 struct type *arg_type;
8886
8887 /* DWARF version 2 has no clean way to discern C++
8888 static and non-static member functions. G++ helps
8889 GDB by marking the first parameter for non-static
8890 member functions (which is the this pointer) as
8891 artificial. We pass this information to
8892 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8893
8894 DWARF version 3 added DW_AT_object_pointer, which GCC
8895 4.5 does not yet generate. */
8896 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
8897 if (attr)
8898 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
8899 else
8900 {
8901 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
8902
8903 /* GCC/43521: In java, the formal parameter
8904 "this" is sometimes not marked with DW_AT_artificial. */
8905 if (cu->language == language_java)
8906 {
8907 const char *name = dwarf2_name (child_die, cu);
8908
8909 if (name && !strcmp (name, "this"))
8910 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1;
8911 }
8912 }
8913 arg_type = die_type (child_die, cu);
8914
8915 /* RealView does not mark THIS as const, which the testsuite
8916 expects. GCC marks THIS as const in method definitions,
8917 but not in the class specifications (GCC PR 43053). */
8918 if (cu->language == language_cplus && !TYPE_CONST (arg_type)
8919 && TYPE_FIELD_ARTIFICIAL (ftype, iparams))
8920 {
8921 int is_this = 0;
8922 struct dwarf2_cu *arg_cu = cu;
8923 const char *name = dwarf2_name (child_die, cu);
8924
8925 attr = dwarf2_attr (die, DW_AT_object_pointer, cu);
8926 if (attr)
8927 {
8928 /* If the compiler emits this, use it. */
8929 if (follow_die_ref (die, attr, &arg_cu) == child_die)
8930 is_this = 1;
8931 }
8932 else if (name && strcmp (name, "this") == 0)
8933 /* Function definitions will have the argument names. */
8934 is_this = 1;
8935 else if (name == NULL && iparams == 0)
8936 /* Declarations may not have the names, so like
8937 elsewhere in GDB, assume an artificial first
8938 argument is "this". */
8939 is_this = 1;
8940
8941 if (is_this)
8942 arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type),
8943 arg_type, 0);
8944 }
8945
8946 TYPE_FIELD_TYPE (ftype, iparams) = arg_type;
8947 iparams++;
8948 }
8949 child_die = sibling_die (child_die);
8950 }
8951 }
8952
8953 return ftype;
8954 }
8955
8956 static struct type *
8957 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
8958 {
8959 struct objfile *objfile = cu->objfile;
8960 const char *name = NULL;
8961 struct type *this_type, *target_type;
8962
8963 name = dwarf2_full_name (NULL, die, cu);
8964 this_type = init_type (TYPE_CODE_TYPEDEF, 0,
8965 TYPE_FLAG_TARGET_STUB, NULL, objfile);
8966 TYPE_NAME (this_type) = (char *) name;
8967 set_die_type (die, this_type, cu);
8968 target_type = die_type (die, cu);
8969 if (target_type != this_type)
8970 TYPE_TARGET_TYPE (this_type) = target_type;
8971 else
8972 {
8973 /* Self-referential typedefs are, it seems, not allowed by the DWARF
8974 spec and cause infinite loops in GDB. */
8975 complaint (&symfile_complaints,
8976 _("Self-referential DW_TAG_typedef "
8977 "- DIE at 0x%x [in module %s]"),
8978 die->offset.sect_off, objfile->name);
8979 TYPE_TARGET_TYPE (this_type) = NULL;
8980 }
8981 return this_type;
8982 }
8983
8984 /* Find a representation of a given base type and install
8985 it in the TYPE field of the die. */
8986
8987 static struct type *
8988 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
8989 {
8990 struct objfile *objfile = cu->objfile;
8991 struct type *type;
8992 struct attribute *attr;
8993 int encoding = 0, size = 0;
8994 char *name;
8995 enum type_code code = TYPE_CODE_INT;
8996 int type_flags = 0;
8997 struct type *target_type = NULL;
8998
8999 attr = dwarf2_attr (die, DW_AT_encoding, cu);
9000 if (attr)
9001 {
9002 encoding = DW_UNSND (attr);
9003 }
9004 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
9005 if (attr)
9006 {
9007 size = DW_UNSND (attr);
9008 }
9009 name = dwarf2_name (die, cu);
9010 if (!name)
9011 {
9012 complaint (&symfile_complaints,
9013 _("DW_AT_name missing from DW_TAG_base_type"));
9014 }
9015
9016 switch (encoding)
9017 {
9018 case DW_ATE_address:
9019 /* Turn DW_ATE_address into a void * pointer. */
9020 code = TYPE_CODE_PTR;
9021 type_flags |= TYPE_FLAG_UNSIGNED;
9022 target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
9023 break;
9024 case DW_ATE_boolean:
9025 code = TYPE_CODE_BOOL;
9026 type_flags |= TYPE_FLAG_UNSIGNED;
9027 break;
9028 case DW_ATE_complex_float:
9029 code = TYPE_CODE_COMPLEX;
9030 target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile);
9031 break;
9032 case DW_ATE_decimal_float:
9033 code = TYPE_CODE_DECFLOAT;
9034 break;
9035 case DW_ATE_float:
9036 code = TYPE_CODE_FLT;
9037 break;
9038 case DW_ATE_signed:
9039 break;
9040 case DW_ATE_unsigned:
9041 type_flags |= TYPE_FLAG_UNSIGNED;
9042 if (cu->language == language_fortran
9043 && name
9044 && strncmp (name, "character(", sizeof ("character(") - 1) == 0)
9045 code = TYPE_CODE_CHAR;
9046 break;
9047 case DW_ATE_signed_char:
9048 if (cu->language == language_ada || cu->language == language_m2
9049 || cu->language == language_pascal
9050 || cu->language == language_fortran)
9051 code = TYPE_CODE_CHAR;
9052 break;
9053 case DW_ATE_unsigned_char:
9054 if (cu->language == language_ada || cu->language == language_m2
9055 || cu->language == language_pascal
9056 || cu->language == language_fortran)
9057 code = TYPE_CODE_CHAR;
9058 type_flags |= TYPE_FLAG_UNSIGNED;
9059 break;
9060 case DW_ATE_UTF:
9061 /* We just treat this as an integer and then recognize the
9062 type by name elsewhere. */
9063 break;
9064
9065 default:
9066 complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"),
9067 dwarf_type_encoding_name (encoding));
9068 break;
9069 }
9070
9071 type = init_type (code, size, type_flags, NULL, objfile);
9072 TYPE_NAME (type) = name;
9073 TYPE_TARGET_TYPE (type) = target_type;
9074
9075 if (name && strcmp (name, "char") == 0)
9076 TYPE_NOSIGN (type) = 1;
9077
9078 return set_die_type (die, type, cu);
9079 }
9080
9081 /* Read the given DW_AT_subrange DIE. */
9082
9083 static struct type *
9084 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
9085 {
9086 struct type *base_type;
9087 struct type *range_type;
9088 struct attribute *attr;
9089 LONGEST low = 0;
9090 LONGEST high = -1;
9091 char *name;
9092 LONGEST negative_mask;
9093
9094 base_type = die_type (die, cu);
9095 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
9096 check_typedef (base_type);
9097
9098 /* The die_type call above may have already set the type for this DIE. */
9099 range_type = get_die_type (die, cu);
9100 if (range_type)
9101 return range_type;
9102
9103 if (cu->language == language_fortran)
9104 {
9105 /* FORTRAN implies a lower bound of 1, if not given. */
9106 low = 1;
9107 }
9108
9109 /* FIXME: For variable sized arrays either of these could be
9110 a variable rather than a constant value. We'll allow it,
9111 but we don't know how to handle it. */
9112 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
9113 if (attr)
9114 low = dwarf2_get_attr_constant_value (attr, 0);
9115
9116 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
9117 if (attr)
9118 {
9119 if (attr_form_is_block (attr) || is_ref_attr (attr))
9120 {
9121 /* GCC encodes arrays with unspecified or dynamic length
9122 with a DW_FORM_block1 attribute or a reference attribute.
9123 FIXME: GDB does not yet know how to handle dynamic
9124 arrays properly, treat them as arrays with unspecified
9125 length for now.
9126
9127 FIXME: jimb/2003-09-22: GDB does not really know
9128 how to handle arrays of unspecified length
9129 either; we just represent them as zero-length
9130 arrays. Choose an appropriate upper bound given
9131 the lower bound we've computed above. */
9132 high = low - 1;
9133 }
9134 else
9135 high = dwarf2_get_attr_constant_value (attr, 1);
9136 }
9137 else
9138 {
9139 attr = dwarf2_attr (die, DW_AT_count, cu);
9140 if (attr)
9141 {
9142 int count = dwarf2_get_attr_constant_value (attr, 1);
9143 high = low + count - 1;
9144 }
9145 else
9146 {
9147 /* Unspecified array length. */
9148 high = low - 1;
9149 }
9150 }
9151
9152 /* Dwarf-2 specifications explicitly allows to create subrange types
9153 without specifying a base type.
9154 In that case, the base type must be set to the type of
9155 the lower bound, upper bound or count, in that order, if any of these
9156 three attributes references an object that has a type.
9157 If no base type is found, the Dwarf-2 specifications say that
9158 a signed integer type of size equal to the size of an address should
9159 be used.
9160 For the following C code: `extern char gdb_int [];'
9161 GCC produces an empty range DIE.
9162 FIXME: muller/2010-05-28: Possible references to object for low bound,
9163 high bound or count are not yet handled by this code. */
9164 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
9165 {
9166 struct objfile *objfile = cu->objfile;
9167 struct gdbarch *gdbarch = get_objfile_arch (objfile);
9168 int addr_size = gdbarch_addr_bit (gdbarch) /8;
9169 struct type *int_type = objfile_type (objfile)->builtin_int;
9170
9171 /* Test "int", "long int", and "long long int" objfile types,
9172 and select the first one having a size above or equal to the
9173 architecture address size. */
9174 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
9175 base_type = int_type;
9176 else
9177 {
9178 int_type = objfile_type (objfile)->builtin_long;
9179 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
9180 base_type = int_type;
9181 else
9182 {
9183 int_type = objfile_type (objfile)->builtin_long_long;
9184 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
9185 base_type = int_type;
9186 }
9187 }
9188 }
9189
9190 negative_mask =
9191 (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
9192 if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
9193 low |= negative_mask;
9194 if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
9195 high |= negative_mask;
9196
9197 range_type = create_range_type (NULL, base_type, low, high);
9198
9199 /* Mark arrays with dynamic length at least as an array of unspecified
9200 length. GDB could check the boundary but before it gets implemented at
9201 least allow accessing the array elements. */
9202 if (attr && attr_form_is_block (attr))
9203 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
9204
9205 /* Ada expects an empty array on no boundary attributes. */
9206 if (attr == NULL && cu->language != language_ada)
9207 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
9208
9209 name = dwarf2_name (die, cu);
9210 if (name)
9211 TYPE_NAME (range_type) = name;
9212
9213 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
9214 if (attr)
9215 TYPE_LENGTH (range_type) = DW_UNSND (attr);
9216
9217 set_die_type (die, range_type, cu);
9218
9219 /* set_die_type should be already done. */
9220 set_descriptive_type (range_type, die, cu);
9221
9222 return range_type;
9223 }
9224
9225 static struct type *
9226 read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
9227 {
9228 struct type *type;
9229
9230 /* For now, we only support the C meaning of an unspecified type: void. */
9231
9232 type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile);
9233 TYPE_NAME (type) = dwarf2_name (die, cu);
9234
9235 return set_die_type (die, type, cu);
9236 }
9237
9238 /* Trivial hash function for die_info: the hash value of a DIE
9239 is its offset in .debug_info for this objfile. */
9240
9241 static hashval_t
9242 die_hash (const void *item)
9243 {
9244 const struct die_info *die = item;
9245
9246 return die->offset.sect_off;
9247 }
9248
9249 /* Trivial comparison function for die_info structures: two DIEs
9250 are equal if they have the same offset. */
9251
9252 static int
9253 die_eq (const void *item_lhs, const void *item_rhs)
9254 {
9255 const struct die_info *die_lhs = item_lhs;
9256 const struct die_info *die_rhs = item_rhs;
9257
9258 return die_lhs->offset.sect_off == die_rhs->offset.sect_off;
9259 }
9260
9261 /* Read a whole compilation unit into a linked list of dies. */
9262
9263 static struct die_info *
9264 read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu)
9265 {
9266 struct die_reader_specs reader_specs;
9267 int read_abbrevs = 0;
9268 struct cleanup *back_to = NULL;
9269 struct die_info *die;
9270
9271 if (cu->dwarf2_abbrevs == NULL)
9272 {
9273 dwarf2_read_abbrevs (cu);
9274 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
9275 read_abbrevs = 1;
9276 }
9277
9278 gdb_assert (cu->die_hash == NULL);
9279 cu->die_hash
9280 = htab_create_alloc_ex (cu->header.length / 12,
9281 die_hash,
9282 die_eq,
9283 NULL,
9284 &cu->comp_unit_obstack,
9285 hashtab_obstack_allocate,
9286 dummy_obstack_deallocate);
9287
9288 init_cu_die_reader (&reader_specs, cu);
9289
9290 die = read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL);
9291
9292 if (read_abbrevs)
9293 do_cleanups (back_to);
9294
9295 return die;
9296 }
9297
9298 /* Main entry point for reading a DIE and all children.
9299 Read the DIE and dump it if requested. */
9300
9301 static struct die_info *
9302 read_die_and_children (const struct die_reader_specs *reader,
9303 gdb_byte *info_ptr,
9304 gdb_byte **new_info_ptr,
9305 struct die_info *parent)
9306 {
9307 struct die_info *result = read_die_and_children_1 (reader, info_ptr,
9308 new_info_ptr, parent);
9309
9310 if (dwarf2_die_debug)
9311 {
9312 fprintf_unfiltered (gdb_stdlog,
9313 "\nRead die from %s of %s:\n",
9314 (reader->cu->per_cu->debug_types_section
9315 ? ".debug_types"
9316 : ".debug_info"),
9317 reader->abfd->filename);
9318 dump_die (result, dwarf2_die_debug);
9319 }
9320
9321 return result;
9322 }
9323
9324 /* Read a single die and all its descendents. Set the die's sibling
9325 field to NULL; set other fields in the die correctly, and set all
9326 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
9327 location of the info_ptr after reading all of those dies. PARENT
9328 is the parent of the die in question. */
9329
9330 static struct die_info *
9331 read_die_and_children_1 (const struct die_reader_specs *reader,
9332 gdb_byte *info_ptr,
9333 gdb_byte **new_info_ptr,
9334 struct die_info *parent)
9335 {
9336 struct die_info *die;
9337 gdb_byte *cur_ptr;
9338 int has_children;
9339
9340 cur_ptr = read_full_die (reader, &die, info_ptr, &has_children);
9341 if (die == NULL)
9342 {
9343 *new_info_ptr = cur_ptr;
9344 return NULL;
9345 }
9346 store_in_ref_table (die, reader->cu);
9347
9348 if (has_children)
9349 die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die);
9350 else
9351 {
9352 die->child = NULL;
9353 *new_info_ptr = cur_ptr;
9354 }
9355
9356 die->sibling = NULL;
9357 die->parent = parent;
9358 return die;
9359 }
9360
9361 /* Read a die, all of its descendents, and all of its siblings; set
9362 all of the fields of all of the dies correctly. Arguments are as
9363 in read_die_and_children. */
9364
9365 static struct die_info *
9366 read_die_and_siblings (const struct die_reader_specs *reader,
9367 gdb_byte *info_ptr,
9368 gdb_byte **new_info_ptr,
9369 struct die_info *parent)
9370 {
9371 struct die_info *first_die, *last_sibling;
9372 gdb_byte *cur_ptr;
9373
9374 cur_ptr = info_ptr;
9375 first_die = last_sibling = NULL;
9376
9377 while (1)
9378 {
9379 struct die_info *die
9380 = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent);
9381
9382 if (die == NULL)
9383 {
9384 *new_info_ptr = cur_ptr;
9385 return first_die;
9386 }
9387
9388 if (!first_die)
9389 first_die = die;
9390 else
9391 last_sibling->sibling = die;
9392
9393 last_sibling = die;
9394 }
9395 }
9396
9397 /* Read the die from the .debug_info section buffer. Set DIEP to
9398 point to a newly allocated die with its information, except for its
9399 child, sibling, and parent fields. Set HAS_CHILDREN to tell
9400 whether the die has children or not. */
9401
9402 static gdb_byte *
9403 read_full_die (const struct die_reader_specs *reader,
9404 struct die_info **diep, gdb_byte *info_ptr,
9405 int *has_children)
9406 {
9407 unsigned int abbrev_number, bytes_read, i;
9408 sect_offset offset;
9409 struct abbrev_info *abbrev;
9410 struct die_info *die;
9411 struct dwarf2_cu *cu = reader->cu;
9412 bfd *abfd = reader->abfd;
9413
9414 offset.sect_off = info_ptr - reader->buffer;
9415 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
9416 info_ptr += bytes_read;
9417 if (!abbrev_number)
9418 {
9419 *diep = NULL;
9420 *has_children = 0;
9421 return info_ptr;
9422 }
9423
9424 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
9425 if (!abbrev)
9426 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
9427 abbrev_number,
9428 bfd_get_filename (abfd));
9429
9430 die = dwarf_alloc_die (cu, abbrev->num_attrs);
9431 die->offset = offset;
9432 die->tag = abbrev->tag;
9433 die->abbrev = abbrev_number;
9434
9435 die->num_attrs = abbrev->num_attrs;
9436
9437 for (i = 0; i < abbrev->num_attrs; ++i)
9438 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
9439 abfd, info_ptr, cu);
9440
9441 *diep = die;
9442 *has_children = abbrev->has_children;
9443 return info_ptr;
9444 }
9445
9446 /* In DWARF version 2, the description of the debugging information is
9447 stored in a separate .debug_abbrev section. Before we read any
9448 dies from a section we read in all abbreviations and install them
9449 in a hash table. This function also sets flags in CU describing
9450 the data found in the abbrev table. */
9451
9452 static void
9453 dwarf2_read_abbrevs (struct dwarf2_cu *cu)
9454 {
9455 bfd *abfd = cu->objfile->obfd;
9456 struct comp_unit_head *cu_header = &cu->header;
9457 gdb_byte *abbrev_ptr;
9458 struct abbrev_info *cur_abbrev;
9459 unsigned int abbrev_number, bytes_read, abbrev_name;
9460 unsigned int abbrev_form, hash_number;
9461 struct attr_abbrev *cur_attrs;
9462 unsigned int allocated_attrs;
9463
9464 /* Initialize dwarf2 abbrevs. */
9465 obstack_init (&cu->abbrev_obstack);
9466 cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack,
9467 (ABBREV_HASH_SIZE
9468 * sizeof (struct abbrev_info *)));
9469 memset (cu->dwarf2_abbrevs, 0,
9470 ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
9471
9472 dwarf2_read_section (dwarf2_per_objfile->objfile,
9473 &dwarf2_per_objfile->abbrev);
9474 abbrev_ptr = (dwarf2_per_objfile->abbrev.buffer
9475 + cu_header->abbrev_offset.sect_off);
9476 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9477 abbrev_ptr += bytes_read;
9478
9479 allocated_attrs = ATTR_ALLOC_CHUNK;
9480 cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
9481
9482 /* Loop until we reach an abbrev number of 0. */
9483 while (abbrev_number)
9484 {
9485 cur_abbrev = dwarf_alloc_abbrev (cu);
9486
9487 /* read in abbrev header */
9488 cur_abbrev->number = abbrev_number;
9489 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9490 abbrev_ptr += bytes_read;
9491 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
9492 abbrev_ptr += 1;
9493
9494 /* now read in declarations */
9495 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9496 abbrev_ptr += bytes_read;
9497 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9498 abbrev_ptr += bytes_read;
9499 while (abbrev_name)
9500 {
9501 if (cur_abbrev->num_attrs == allocated_attrs)
9502 {
9503 allocated_attrs += ATTR_ALLOC_CHUNK;
9504 cur_attrs
9505 = xrealloc (cur_attrs, (allocated_attrs
9506 * sizeof (struct attr_abbrev)));
9507 }
9508
9509 cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
9510 cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
9511 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9512 abbrev_ptr += bytes_read;
9513 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9514 abbrev_ptr += bytes_read;
9515 }
9516
9517 cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack,
9518 (cur_abbrev->num_attrs
9519 * sizeof (struct attr_abbrev)));
9520 memcpy (cur_abbrev->attrs, cur_attrs,
9521 cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
9522
9523 hash_number = abbrev_number % ABBREV_HASH_SIZE;
9524 cur_abbrev->next = cu->dwarf2_abbrevs[hash_number];
9525 cu->dwarf2_abbrevs[hash_number] = cur_abbrev;
9526
9527 /* Get next abbreviation.
9528 Under Irix6 the abbreviations for a compilation unit are not
9529 always properly terminated with an abbrev number of 0.
9530 Exit loop if we encounter an abbreviation which we have
9531 already read (which means we are about to read the abbreviations
9532 for the next compile unit) or if the end of the abbreviation
9533 table is reached. */
9534 if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer)
9535 >= dwarf2_per_objfile->abbrev.size)
9536 break;
9537 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9538 abbrev_ptr += bytes_read;
9539 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
9540 break;
9541 }
9542
9543 xfree (cur_attrs);
9544 }
9545
9546 /* Release the memory used by the abbrev table for a compilation unit. */
9547
9548 static void
9549 dwarf2_free_abbrev_table (void *ptr_to_cu)
9550 {
9551 struct dwarf2_cu *cu = ptr_to_cu;
9552
9553 obstack_free (&cu->abbrev_obstack, NULL);
9554 cu->dwarf2_abbrevs = NULL;
9555 }
9556
9557 /* Lookup an abbrev_info structure in the abbrev hash table. */
9558
9559 static struct abbrev_info *
9560 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
9561 {
9562 unsigned int hash_number;
9563 struct abbrev_info *abbrev;
9564
9565 hash_number = number % ABBREV_HASH_SIZE;
9566 abbrev = cu->dwarf2_abbrevs[hash_number];
9567
9568 while (abbrev)
9569 {
9570 if (abbrev->number == number)
9571 return abbrev;
9572 else
9573 abbrev = abbrev->next;
9574 }
9575 return NULL;
9576 }
9577
9578 /* Returns nonzero if TAG represents a type that we might generate a partial
9579 symbol for. */
9580
9581 static int
9582 is_type_tag_for_partial (int tag)
9583 {
9584 switch (tag)
9585 {
9586 #if 0
9587 /* Some types that would be reasonable to generate partial symbols for,
9588 that we don't at present. */
9589 case DW_TAG_array_type:
9590 case DW_TAG_file_type:
9591 case DW_TAG_ptr_to_member_type:
9592 case DW_TAG_set_type:
9593 case DW_TAG_string_type:
9594 case DW_TAG_subroutine_type:
9595 #endif
9596 case DW_TAG_base_type:
9597 case DW_TAG_class_type:
9598 case DW_TAG_interface_type:
9599 case DW_TAG_enumeration_type:
9600 case DW_TAG_structure_type:
9601 case DW_TAG_subrange_type:
9602 case DW_TAG_typedef:
9603 case DW_TAG_union_type:
9604 return 1;
9605 default:
9606 return 0;
9607 }
9608 }
9609
9610 /* Load all DIEs that are interesting for partial symbols into memory. */
9611
9612 static struct partial_die_info *
9613 load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
9614 int building_psymtab, struct dwarf2_cu *cu)
9615 {
9616 struct objfile *objfile = cu->objfile;
9617 struct partial_die_info *part_die;
9618 struct partial_die_info *parent_die, *last_die, *first_die = NULL;
9619 struct abbrev_info *abbrev;
9620 unsigned int bytes_read;
9621 unsigned int load_all = 0;
9622 int nesting_level = 1;
9623
9624 parent_die = NULL;
9625 last_die = NULL;
9626
9627 gdb_assert (cu->per_cu != NULL);
9628 if (cu->per_cu->load_all_dies)
9629 load_all = 1;
9630
9631 cu->partial_dies
9632 = htab_create_alloc_ex (cu->header.length / 12,
9633 partial_die_hash,
9634 partial_die_eq,
9635 NULL,
9636 &cu->comp_unit_obstack,
9637 hashtab_obstack_allocate,
9638 dummy_obstack_deallocate);
9639
9640 part_die = obstack_alloc (&cu->comp_unit_obstack,
9641 sizeof (struct partial_die_info));
9642
9643 while (1)
9644 {
9645 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
9646
9647 /* A NULL abbrev means the end of a series of children. */
9648 if (abbrev == NULL)
9649 {
9650 if (--nesting_level == 0)
9651 {
9652 /* PART_DIE was probably the last thing allocated on the
9653 comp_unit_obstack, so we could call obstack_free
9654 here. We don't do that because the waste is small,
9655 and will be cleaned up when we're done with this
9656 compilation unit. This way, we're also more robust
9657 against other users of the comp_unit_obstack. */
9658 return first_die;
9659 }
9660 info_ptr += bytes_read;
9661 last_die = parent_die;
9662 parent_die = parent_die->die_parent;
9663 continue;
9664 }
9665
9666 /* Check for template arguments. We never save these; if
9667 they're seen, we just mark the parent, and go on our way. */
9668 if (parent_die != NULL
9669 && cu->language == language_cplus
9670 && (abbrev->tag == DW_TAG_template_type_param
9671 || abbrev->tag == DW_TAG_template_value_param))
9672 {
9673 parent_die->has_template_arguments = 1;
9674
9675 if (!load_all)
9676 {
9677 /* We don't need a partial DIE for the template argument. */
9678 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev,
9679 cu);
9680 continue;
9681 }
9682 }
9683
9684 /* We only recurse into c++ subprograms looking for template arguments.
9685 Skip their other children. */
9686 if (!load_all
9687 && cu->language == language_cplus
9688 && parent_die != NULL
9689 && parent_die->tag == DW_TAG_subprogram)
9690 {
9691 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
9692 continue;
9693 }
9694
9695 /* Check whether this DIE is interesting enough to save. Normally
9696 we would not be interested in members here, but there may be
9697 later variables referencing them via DW_AT_specification (for
9698 static members). */
9699 if (!load_all
9700 && !is_type_tag_for_partial (abbrev->tag)
9701 && abbrev->tag != DW_TAG_constant
9702 && abbrev->tag != DW_TAG_enumerator
9703 && abbrev->tag != DW_TAG_subprogram
9704 && abbrev->tag != DW_TAG_lexical_block
9705 && abbrev->tag != DW_TAG_variable
9706 && abbrev->tag != DW_TAG_namespace
9707 && abbrev->tag != DW_TAG_module
9708 && abbrev->tag != DW_TAG_member)
9709 {
9710 /* Otherwise we skip to the next sibling, if any. */
9711 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
9712 continue;
9713 }
9714
9715 info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd,
9716 buffer, info_ptr, cu);
9717
9718 /* This two-pass algorithm for processing partial symbols has a
9719 high cost in cache pressure. Thus, handle some simple cases
9720 here which cover the majority of C partial symbols. DIEs
9721 which neither have specification tags in them, nor could have
9722 specification tags elsewhere pointing at them, can simply be
9723 processed and discarded.
9724
9725 This segment is also optional; scan_partial_symbols and
9726 add_partial_symbol will handle these DIEs if we chain
9727 them in normally. When compilers which do not emit large
9728 quantities of duplicate debug information are more common,
9729 this code can probably be removed. */
9730
9731 /* Any complete simple types at the top level (pretty much all
9732 of them, for a language without namespaces), can be processed
9733 directly. */
9734 if (parent_die == NULL
9735 && part_die->has_specification == 0
9736 && part_die->is_declaration == 0
9737 && ((part_die->tag == DW_TAG_typedef && !part_die->has_children)
9738 || part_die->tag == DW_TAG_base_type
9739 || part_die->tag == DW_TAG_subrange_type))
9740 {
9741 if (building_psymtab && part_die->name != NULL)
9742 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
9743 VAR_DOMAIN, LOC_TYPEDEF,
9744 &objfile->static_psymbols,
9745 0, (CORE_ADDR) 0, cu->language, objfile);
9746 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
9747 continue;
9748 }
9749
9750 /* The exception for DW_TAG_typedef with has_children above is
9751 a workaround of GCC PR debug/47510. In the case of this complaint
9752 type_name_no_tag_or_error will error on such types later.
9753
9754 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9755 it could not find the child DIEs referenced later, this is checked
9756 above. In correct DWARF DW_TAG_typedef should have no children. */
9757
9758 if (part_die->tag == DW_TAG_typedef && part_die->has_children)
9759 complaint (&symfile_complaints,
9760 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9761 "- DIE at 0x%x [in module %s]"),
9762 part_die->offset.sect_off, objfile->name);
9763
9764 /* If we're at the second level, and we're an enumerator, and
9765 our parent has no specification (meaning possibly lives in a
9766 namespace elsewhere), then we can add the partial symbol now
9767 instead of queueing it. */
9768 if (part_die->tag == DW_TAG_enumerator
9769 && parent_die != NULL
9770 && parent_die->die_parent == NULL
9771 && parent_die->tag == DW_TAG_enumeration_type
9772 && parent_die->has_specification == 0)
9773 {
9774 if (part_die->name == NULL)
9775 complaint (&symfile_complaints,
9776 _("malformed enumerator DIE ignored"));
9777 else if (building_psymtab)
9778 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
9779 VAR_DOMAIN, LOC_CONST,
9780 (cu->language == language_cplus
9781 || cu->language == language_java)
9782 ? &objfile->global_psymbols
9783 : &objfile->static_psymbols,
9784 0, (CORE_ADDR) 0, cu->language, objfile);
9785
9786 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
9787 continue;
9788 }
9789
9790 /* We'll save this DIE so link it in. */
9791 part_die->die_parent = parent_die;
9792 part_die->die_sibling = NULL;
9793 part_die->die_child = NULL;
9794
9795 if (last_die && last_die == parent_die)
9796 last_die->die_child = part_die;
9797 else if (last_die)
9798 last_die->die_sibling = part_die;
9799
9800 last_die = part_die;
9801
9802 if (first_die == NULL)
9803 first_die = part_die;
9804
9805 /* Maybe add the DIE to the hash table. Not all DIEs that we
9806 find interesting need to be in the hash table, because we
9807 also have the parent/sibling/child chains; only those that we
9808 might refer to by offset later during partial symbol reading.
9809
9810 For now this means things that might have be the target of a
9811 DW_AT_specification, DW_AT_abstract_origin, or
9812 DW_AT_extension. DW_AT_extension will refer only to
9813 namespaces; DW_AT_abstract_origin refers to functions (and
9814 many things under the function DIE, but we do not recurse
9815 into function DIEs during partial symbol reading) and
9816 possibly variables as well; DW_AT_specification refers to
9817 declarations. Declarations ought to have the DW_AT_declaration
9818 flag. It happens that GCC forgets to put it in sometimes, but
9819 only for functions, not for types.
9820
9821 Adding more things than necessary to the hash table is harmless
9822 except for the performance cost. Adding too few will result in
9823 wasted time in find_partial_die, when we reread the compilation
9824 unit with load_all_dies set. */
9825
9826 if (load_all
9827 || abbrev->tag == DW_TAG_constant
9828 || abbrev->tag == DW_TAG_subprogram
9829 || abbrev->tag == DW_TAG_variable
9830 || abbrev->tag == DW_TAG_namespace
9831 || part_die->is_declaration)
9832 {
9833 void **slot;
9834
9835 slot = htab_find_slot_with_hash (cu->partial_dies, part_die,
9836 part_die->offset.sect_off, INSERT);
9837 *slot = part_die;
9838 }
9839
9840 part_die = obstack_alloc (&cu->comp_unit_obstack,
9841 sizeof (struct partial_die_info));
9842
9843 /* For some DIEs we want to follow their children (if any). For C
9844 we have no reason to follow the children of structures; for other
9845 languages we have to, so that we can get at method physnames
9846 to infer fully qualified class names, for DW_AT_specification,
9847 and for C++ template arguments. For C++, we also look one level
9848 inside functions to find template arguments (if the name of the
9849 function does not already contain the template arguments).
9850
9851 For Ada, we need to scan the children of subprograms and lexical
9852 blocks as well because Ada allows the definition of nested
9853 entities that could be interesting for the debugger, such as
9854 nested subprograms for instance. */
9855 if (last_die->has_children
9856 && (load_all
9857 || last_die->tag == DW_TAG_namespace
9858 || last_die->tag == DW_TAG_module
9859 || last_die->tag == DW_TAG_enumeration_type
9860 || (cu->language == language_cplus
9861 && last_die->tag == DW_TAG_subprogram
9862 && (last_die->name == NULL
9863 || strchr (last_die->name, '<') == NULL))
9864 || (cu->language != language_c
9865 && (last_die->tag == DW_TAG_class_type
9866 || last_die->tag == DW_TAG_interface_type
9867 || last_die->tag == DW_TAG_structure_type
9868 || last_die->tag == DW_TAG_union_type))
9869 || (cu->language == language_ada
9870 && (last_die->tag == DW_TAG_subprogram
9871 || last_die->tag == DW_TAG_lexical_block))))
9872 {
9873 nesting_level++;
9874 parent_die = last_die;
9875 continue;
9876 }
9877
9878 /* Otherwise we skip to the next sibling, if any. */
9879 info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu);
9880
9881 /* Back to the top, do it again. */
9882 }
9883 }
9884
9885 /* Read a minimal amount of information into the minimal die structure. */
9886
9887 static gdb_byte *
9888 read_partial_die (struct partial_die_info *part_die,
9889 struct abbrev_info *abbrev,
9890 unsigned int abbrev_len, bfd *abfd,
9891 gdb_byte *buffer, gdb_byte *info_ptr,
9892 struct dwarf2_cu *cu)
9893 {
9894 struct objfile *objfile = cu->objfile;
9895 unsigned int i;
9896 struct attribute attr;
9897 int has_low_pc_attr = 0;
9898 int has_high_pc_attr = 0;
9899
9900 memset (part_die, 0, sizeof (struct partial_die_info));
9901
9902 part_die->offset.sect_off = info_ptr - buffer;
9903
9904 info_ptr += abbrev_len;
9905
9906 if (abbrev == NULL)
9907 return info_ptr;
9908
9909 part_die->tag = abbrev->tag;
9910 part_die->has_children = abbrev->has_children;
9911
9912 for (i = 0; i < abbrev->num_attrs; ++i)
9913 {
9914 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
9915
9916 /* Store the data if it is of an attribute we want to keep in a
9917 partial symbol table. */
9918 switch (attr.name)
9919 {
9920 case DW_AT_name:
9921 switch (part_die->tag)
9922 {
9923 case DW_TAG_compile_unit:
9924 case DW_TAG_type_unit:
9925 /* Compilation units have a DW_AT_name that is a filename, not
9926 a source language identifier. */
9927 case DW_TAG_enumeration_type:
9928 case DW_TAG_enumerator:
9929 /* These tags always have simple identifiers already; no need
9930 to canonicalize them. */
9931 part_die->name = DW_STRING (&attr);
9932 break;
9933 default:
9934 part_die->name
9935 = dwarf2_canonicalize_name (DW_STRING (&attr), cu,
9936 &objfile->objfile_obstack);
9937 break;
9938 }
9939 break;
9940 case DW_AT_linkage_name:
9941 case DW_AT_MIPS_linkage_name:
9942 /* Note that both forms of linkage name might appear. We
9943 assume they will be the same, and we only store the last
9944 one we see. */
9945 if (cu->language == language_ada)
9946 part_die->name = DW_STRING (&attr);
9947 part_die->linkage_name = DW_STRING (&attr);
9948 break;
9949 case DW_AT_low_pc:
9950 has_low_pc_attr = 1;
9951 part_die->lowpc = DW_ADDR (&attr);
9952 break;
9953 case DW_AT_high_pc:
9954 has_high_pc_attr = 1;
9955 part_die->highpc = DW_ADDR (&attr);
9956 break;
9957 case DW_AT_location:
9958 /* Support the .debug_loc offsets. */
9959 if (attr_form_is_block (&attr))
9960 {
9961 part_die->locdesc = DW_BLOCK (&attr);
9962 }
9963 else if (attr_form_is_section_offset (&attr))
9964 {
9965 dwarf2_complex_location_expr_complaint ();
9966 }
9967 else
9968 {
9969 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9970 "partial symbol information");
9971 }
9972 break;
9973 case DW_AT_external:
9974 part_die->is_external = DW_UNSND (&attr);
9975 break;
9976 case DW_AT_declaration:
9977 part_die->is_declaration = DW_UNSND (&attr);
9978 break;
9979 case DW_AT_type:
9980 part_die->has_type = 1;
9981 break;
9982 case DW_AT_abstract_origin:
9983 case DW_AT_specification:
9984 case DW_AT_extension:
9985 part_die->has_specification = 1;
9986 part_die->spec_offset = dwarf2_get_ref_die_offset (&attr);
9987 break;
9988 case DW_AT_sibling:
9989 /* Ignore absolute siblings, they might point outside of
9990 the current compile unit. */
9991 if (attr.form == DW_FORM_ref_addr)
9992 complaint (&symfile_complaints,
9993 _("ignoring absolute DW_AT_sibling"));
9994 else
9995 part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr).sect_off;
9996 break;
9997 case DW_AT_byte_size:
9998 part_die->has_byte_size = 1;
9999 break;
10000 case DW_AT_calling_convention:
10001 /* DWARF doesn't provide a way to identify a program's source-level
10002 entry point. DW_AT_calling_convention attributes are only meant
10003 to describe functions' calling conventions.
10004
10005 However, because it's a necessary piece of information in
10006 Fortran, and because DW_CC_program is the only piece of debugging
10007 information whose definition refers to a 'main program' at all,
10008 several compilers have begun marking Fortran main programs with
10009 DW_CC_program --- even when those functions use the standard
10010 calling conventions.
10011
10012 So until DWARF specifies a way to provide this information and
10013 compilers pick up the new representation, we'll support this
10014 practice. */
10015 if (DW_UNSND (&attr) == DW_CC_program
10016 && cu->language == language_fortran)
10017 {
10018 set_main_name (part_die->name);
10019
10020 /* As this DIE has a static linkage the name would be difficult
10021 to look up later. */
10022 language_of_main = language_fortran;
10023 }
10024 break;
10025 case DW_AT_inline:
10026 if (DW_UNSND (&attr) == DW_INL_inlined
10027 || DW_UNSND (&attr) == DW_INL_declared_inlined)
10028 part_die->may_be_inlined = 1;
10029 break;
10030 default:
10031 break;
10032 }
10033 }
10034
10035 if (has_low_pc_attr && has_high_pc_attr)
10036 {
10037 /* When using the GNU linker, .gnu.linkonce. sections are used to
10038 eliminate duplicate copies of functions and vtables and such.
10039 The linker will arbitrarily choose one and discard the others.
10040 The AT_*_pc values for such functions refer to local labels in
10041 these sections. If the section from that file was discarded, the
10042 labels are not in the output, so the relocs get a value of 0.
10043 If this is a discarded function, mark the pc bounds as invalid,
10044 so that GDB will ignore it. */
10045 if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero)
10046 {
10047 struct gdbarch *gdbarch = get_objfile_arch (objfile);
10048
10049 complaint (&symfile_complaints,
10050 _("DW_AT_low_pc %s is zero "
10051 "for DIE at 0x%x [in module %s]"),
10052 paddress (gdbarch, part_die->lowpc),
10053 part_die->offset.sect_off, objfile->name);
10054 }
10055 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
10056 else if (part_die->lowpc >= part_die->highpc)
10057 {
10058 struct gdbarch *gdbarch = get_objfile_arch (objfile);
10059
10060 complaint (&symfile_complaints,
10061 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
10062 "for DIE at 0x%x [in module %s]"),
10063 paddress (gdbarch, part_die->lowpc),
10064 paddress (gdbarch, part_die->highpc),
10065 part_die->offset.sect_off, objfile->name);
10066 }
10067 else
10068 part_die->has_pc_info = 1;
10069 }
10070
10071 return info_ptr;
10072 }
10073
10074 /* Find a cached partial DIE at OFFSET in CU. */
10075
10076 static struct partial_die_info *
10077 find_partial_die_in_comp_unit (sect_offset offset, struct dwarf2_cu *cu)
10078 {
10079 struct partial_die_info *lookup_die = NULL;
10080 struct partial_die_info part_die;
10081
10082 part_die.offset = offset;
10083 lookup_die = htab_find_with_hash (cu->partial_dies, &part_die,
10084 offset.sect_off);
10085
10086 return lookup_die;
10087 }
10088
10089 /* Find a partial DIE at OFFSET, which may or may not be in CU,
10090 except in the case of .debug_types DIEs which do not reference
10091 outside their CU (they do however referencing other types via
10092 DW_FORM_ref_sig8). */
10093
10094 static struct partial_die_info *
10095 find_partial_die (sect_offset offset, struct dwarf2_cu *cu)
10096 {
10097 struct objfile *objfile = cu->objfile;
10098 struct dwarf2_per_cu_data *per_cu = NULL;
10099 struct partial_die_info *pd = NULL;
10100
10101 if (offset_in_cu_p (&cu->header, offset))
10102 {
10103 pd = find_partial_die_in_comp_unit (offset, cu);
10104 if (pd != NULL)
10105 return pd;
10106 /* We missed recording what we needed.
10107 Load all dies and try again. */
10108 per_cu = cu->per_cu;
10109 }
10110 else
10111 {
10112 /* TUs don't reference other CUs/TUs (except via type signatures). */
10113 if (cu->per_cu->debug_types_section)
10114 {
10115 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
10116 " external reference to offset 0x%lx [in module %s].\n"),
10117 (long) cu->header.offset.sect_off, (long) offset.sect_off,
10118 bfd_get_filename (objfile->obfd));
10119 }
10120 per_cu = dwarf2_find_containing_comp_unit (offset, objfile);
10121
10122 if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL)
10123 load_partial_comp_unit (per_cu);
10124
10125 per_cu->cu->last_used = 0;
10126 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
10127 }
10128
10129 if (pd == NULL && per_cu->load_all_dies == 0)
10130 {
10131 struct cleanup *back_to;
10132 struct partial_die_info comp_unit_die;
10133 struct abbrev_info *abbrev;
10134 unsigned int bytes_read;
10135 char *info_ptr;
10136 struct dwarf2_section_info *sec;
10137
10138 per_cu->load_all_dies = 1;
10139
10140 if (per_cu->debug_types_section)
10141 sec = per_cu->debug_types_section;
10142 else
10143 sec = &dwarf2_per_objfile->info;
10144
10145 /* Re-read the DIEs, this time reading all of them.
10146 NOTE: We don't discard the previous set of DIEs.
10147 This doesn't happen very often so it's (hopefully) not a problem. */
10148 back_to = make_cleanup (null_cleanup, 0);
10149 if (per_cu->cu->dwarf2_abbrevs == NULL)
10150 {
10151 dwarf2_read_abbrevs (per_cu->cu);
10152 make_cleanup (dwarf2_free_abbrev_table, per_cu->cu);
10153 }
10154 info_ptr = (sec->buffer
10155 + per_cu->cu->header.offset.sect_off
10156 + per_cu->cu->header.first_die_offset.cu_off);
10157 abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu);
10158 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
10159 objfile->obfd, sec->buffer, info_ptr,
10160 per_cu->cu);
10161 if (comp_unit_die.has_children)
10162 load_partial_dies (objfile->obfd, sec->buffer, info_ptr, 0,
10163 per_cu->cu);
10164 do_cleanups (back_to);
10165
10166 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
10167 }
10168
10169 if (pd == NULL)
10170 internal_error (__FILE__, __LINE__,
10171 _("could not find partial DIE 0x%x "
10172 "in cache [from module %s]\n"),
10173 offset.sect_off, bfd_get_filename (objfile->obfd));
10174 return pd;
10175 }
10176
10177 /* See if we can figure out if the class lives in a namespace. We do
10178 this by looking for a member function; its demangled name will
10179 contain namespace info, if there is any. */
10180
10181 static void
10182 guess_partial_die_structure_name (struct partial_die_info *struct_pdi,
10183 struct dwarf2_cu *cu)
10184 {
10185 /* NOTE: carlton/2003-10-07: Getting the info this way changes
10186 what template types look like, because the demangler
10187 frequently doesn't give the same name as the debug info. We
10188 could fix this by only using the demangled name to get the
10189 prefix (but see comment in read_structure_type). */
10190
10191 struct partial_die_info *real_pdi;
10192 struct partial_die_info *child_pdi;
10193
10194 /* If this DIE (this DIE's specification, if any) has a parent, then
10195 we should not do this. We'll prepend the parent's fully qualified
10196 name when we create the partial symbol. */
10197
10198 real_pdi = struct_pdi;
10199 while (real_pdi->has_specification)
10200 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
10201
10202 if (real_pdi->die_parent != NULL)
10203 return;
10204
10205 for (child_pdi = struct_pdi->die_child;
10206 child_pdi != NULL;
10207 child_pdi = child_pdi->die_sibling)
10208 {
10209 if (child_pdi->tag == DW_TAG_subprogram
10210 && child_pdi->linkage_name != NULL)
10211 {
10212 char *actual_class_name
10213 = language_class_name_from_physname (cu->language_defn,
10214 child_pdi->linkage_name);
10215 if (actual_class_name != NULL)
10216 {
10217 struct_pdi->name
10218 = obsavestring (actual_class_name,
10219 strlen (actual_class_name),
10220 &cu->objfile->objfile_obstack);
10221 xfree (actual_class_name);
10222 }
10223 break;
10224 }
10225 }
10226 }
10227
10228 /* Adjust PART_DIE before generating a symbol for it. This function
10229 may set the is_external flag or change the DIE's name. */
10230
10231 static void
10232 fixup_partial_die (struct partial_die_info *part_die,
10233 struct dwarf2_cu *cu)
10234 {
10235 /* Once we've fixed up a die, there's no point in doing so again.
10236 This also avoids a memory leak if we were to call
10237 guess_partial_die_structure_name multiple times. */
10238 if (part_die->fixup_called)
10239 return;
10240
10241 /* If we found a reference attribute and the DIE has no name, try
10242 to find a name in the referred to DIE. */
10243
10244 if (part_die->name == NULL && part_die->has_specification)
10245 {
10246 struct partial_die_info *spec_die;
10247
10248 spec_die = find_partial_die (part_die->spec_offset, cu);
10249
10250 fixup_partial_die (spec_die, cu);
10251
10252 if (spec_die->name)
10253 {
10254 part_die->name = spec_die->name;
10255
10256 /* Copy DW_AT_external attribute if it is set. */
10257 if (spec_die->is_external)
10258 part_die->is_external = spec_die->is_external;
10259 }
10260 }
10261
10262 /* Set default names for some unnamed DIEs. */
10263
10264 if (part_die->name == NULL && part_die->tag == DW_TAG_namespace)
10265 part_die->name = CP_ANONYMOUS_NAMESPACE_STR;
10266
10267 /* If there is no parent die to provide a namespace, and there are
10268 children, see if we can determine the namespace from their linkage
10269 name. */
10270 if (cu->language == language_cplus
10271 && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)
10272 && part_die->die_parent == NULL
10273 && part_die->has_children
10274 && (part_die->tag == DW_TAG_class_type
10275 || part_die->tag == DW_TAG_structure_type
10276 || part_die->tag == DW_TAG_union_type))
10277 guess_partial_die_structure_name (part_die, cu);
10278
10279 /* GCC might emit a nameless struct or union that has a linkage
10280 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
10281 if (part_die->name == NULL
10282 && (part_die->tag == DW_TAG_class_type
10283 || part_die->tag == DW_TAG_interface_type
10284 || part_die->tag == DW_TAG_structure_type
10285 || part_die->tag == DW_TAG_union_type)
10286 && part_die->linkage_name != NULL)
10287 {
10288 char *demangled;
10289
10290 demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES);
10291 if (demangled)
10292 {
10293 const char *base;
10294
10295 /* Strip any leading namespaces/classes, keep only the base name.
10296 DW_AT_name for named DIEs does not contain the prefixes. */
10297 base = strrchr (demangled, ':');
10298 if (base && base > demangled && base[-1] == ':')
10299 base++;
10300 else
10301 base = demangled;
10302
10303 part_die->name = obsavestring (base, strlen (base),
10304 &cu->objfile->objfile_obstack);
10305 xfree (demangled);
10306 }
10307 }
10308
10309 part_die->fixup_called = 1;
10310 }
10311
10312 /* Read an attribute value described by an attribute form. */
10313
10314 static gdb_byte *
10315 read_attribute_value (struct attribute *attr, unsigned form,
10316 bfd *abfd, gdb_byte *info_ptr,
10317 struct dwarf2_cu *cu)
10318 {
10319 struct comp_unit_head *cu_header = &cu->header;
10320 unsigned int bytes_read;
10321 struct dwarf_block *blk;
10322
10323 attr->form = form;
10324 switch (form)
10325 {
10326 case DW_FORM_ref_addr:
10327 if (cu->header.version == 2)
10328 DW_UNSND (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
10329 else
10330 DW_UNSND (attr) = read_offset (abfd, info_ptr,
10331 &cu->header, &bytes_read);
10332 info_ptr += bytes_read;
10333 break;
10334 case DW_FORM_addr:
10335 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
10336 info_ptr += bytes_read;
10337 break;
10338 case DW_FORM_block2:
10339 blk = dwarf_alloc_block (cu);
10340 blk->size = read_2_bytes (abfd, info_ptr);
10341 info_ptr += 2;
10342 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
10343 info_ptr += blk->size;
10344 DW_BLOCK (attr) = blk;
10345 break;
10346 case DW_FORM_block4:
10347 blk = dwarf_alloc_block (cu);
10348 blk->size = read_4_bytes (abfd, info_ptr);
10349 info_ptr += 4;
10350 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
10351 info_ptr += blk->size;
10352 DW_BLOCK (attr) = blk;
10353 break;
10354 case DW_FORM_data2:
10355 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
10356 info_ptr += 2;
10357 break;
10358 case DW_FORM_data4:
10359 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
10360 info_ptr += 4;
10361 break;
10362 case DW_FORM_data8:
10363 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
10364 info_ptr += 8;
10365 break;
10366 case DW_FORM_sec_offset:
10367 DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
10368 info_ptr += bytes_read;
10369 break;
10370 case DW_FORM_string:
10371 DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read);
10372 DW_STRING_IS_CANONICAL (attr) = 0;
10373 info_ptr += bytes_read;
10374 break;
10375 case DW_FORM_strp:
10376 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
10377 &bytes_read);
10378 DW_STRING_IS_CANONICAL (attr) = 0;
10379 info_ptr += bytes_read;
10380 break;
10381 case DW_FORM_exprloc:
10382 case DW_FORM_block:
10383 blk = dwarf_alloc_block (cu);
10384 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
10385 info_ptr += bytes_read;
10386 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
10387 info_ptr += blk->size;
10388 DW_BLOCK (attr) = blk;
10389 break;
10390 case DW_FORM_block1:
10391 blk = dwarf_alloc_block (cu);
10392 blk->size = read_1_byte (abfd, info_ptr);
10393 info_ptr += 1;
10394 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
10395 info_ptr += blk->size;
10396 DW_BLOCK (attr) = blk;
10397 break;
10398 case DW_FORM_data1:
10399 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
10400 info_ptr += 1;
10401 break;
10402 case DW_FORM_flag:
10403 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
10404 info_ptr += 1;
10405 break;
10406 case DW_FORM_flag_present:
10407 DW_UNSND (attr) = 1;
10408 break;
10409 case DW_FORM_sdata:
10410 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
10411 info_ptr += bytes_read;
10412 break;
10413 case DW_FORM_udata:
10414 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
10415 info_ptr += bytes_read;
10416 break;
10417 case DW_FORM_ref1:
10418 DW_UNSND (attr) = (cu->header.offset.sect_off
10419 + read_1_byte (abfd, info_ptr));
10420 info_ptr += 1;
10421 break;
10422 case DW_FORM_ref2:
10423 DW_UNSND (attr) = (cu->header.offset.sect_off
10424 + read_2_bytes (abfd, info_ptr));
10425 info_ptr += 2;
10426 break;
10427 case DW_FORM_ref4:
10428 DW_UNSND (attr) = (cu->header.offset.sect_off
10429 + read_4_bytes (abfd, info_ptr));
10430 info_ptr += 4;
10431 break;
10432 case DW_FORM_ref8:
10433 DW_UNSND (attr) = (cu->header.offset.sect_off
10434 + read_8_bytes (abfd, info_ptr));
10435 info_ptr += 8;
10436 break;
10437 case DW_FORM_ref_sig8:
10438 /* Convert the signature to something we can record in DW_UNSND
10439 for later lookup.
10440 NOTE: This is NULL if the type wasn't found. */
10441 DW_SIGNATURED_TYPE (attr) =
10442 lookup_signatured_type (read_8_bytes (abfd, info_ptr));
10443 info_ptr += 8;
10444 break;
10445 case DW_FORM_ref_udata:
10446 DW_UNSND (attr) = (cu->header.offset.sect_off
10447 + read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
10448 info_ptr += bytes_read;
10449 break;
10450 case DW_FORM_indirect:
10451 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
10452 info_ptr += bytes_read;
10453 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
10454 break;
10455 default:
10456 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
10457 dwarf_form_name (form),
10458 bfd_get_filename (abfd));
10459 }
10460
10461 /* We have seen instances where the compiler tried to emit a byte
10462 size attribute of -1 which ended up being encoded as an unsigned
10463 0xffffffff. Although 0xffffffff is technically a valid size value,
10464 an object of this size seems pretty unlikely so we can relatively
10465 safely treat these cases as if the size attribute was invalid and
10466 treat them as zero by default. */
10467 if (attr->name == DW_AT_byte_size
10468 && form == DW_FORM_data4
10469 && DW_UNSND (attr) >= 0xffffffff)
10470 {
10471 complaint
10472 (&symfile_complaints,
10473 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
10474 hex_string (DW_UNSND (attr)));
10475 DW_UNSND (attr) = 0;
10476 }
10477
10478 return info_ptr;
10479 }
10480
10481 /* Read an attribute described by an abbreviated attribute. */
10482
10483 static gdb_byte *
10484 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
10485 bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu)
10486 {
10487 attr->name = abbrev->name;
10488 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
10489 }
10490
10491 /* Read dwarf information from a buffer. */
10492
10493 static unsigned int
10494 read_1_byte (bfd *abfd, gdb_byte *buf)
10495 {
10496 return bfd_get_8 (abfd, buf);
10497 }
10498
10499 static int
10500 read_1_signed_byte (bfd *abfd, gdb_byte *buf)
10501 {
10502 return bfd_get_signed_8 (abfd, buf);
10503 }
10504
10505 static unsigned int
10506 read_2_bytes (bfd *abfd, gdb_byte *buf)
10507 {
10508 return bfd_get_16 (abfd, buf);
10509 }
10510
10511 static int
10512 read_2_signed_bytes (bfd *abfd, gdb_byte *buf)
10513 {
10514 return bfd_get_signed_16 (abfd, buf);
10515 }
10516
10517 static unsigned int
10518 read_4_bytes (bfd *abfd, gdb_byte *buf)
10519 {
10520 return bfd_get_32 (abfd, buf);
10521 }
10522
10523 static int
10524 read_4_signed_bytes (bfd *abfd, gdb_byte *buf)
10525 {
10526 return bfd_get_signed_32 (abfd, buf);
10527 }
10528
10529 static ULONGEST
10530 read_8_bytes (bfd *abfd, gdb_byte *buf)
10531 {
10532 return bfd_get_64 (abfd, buf);
10533 }
10534
10535 static CORE_ADDR
10536 read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu,
10537 unsigned int *bytes_read)
10538 {
10539 struct comp_unit_head *cu_header = &cu->header;
10540 CORE_ADDR retval = 0;
10541
10542 if (cu_header->signed_addr_p)
10543 {
10544 switch (cu_header->addr_size)
10545 {
10546 case 2:
10547 retval = bfd_get_signed_16 (abfd, buf);
10548 break;
10549 case 4:
10550 retval = bfd_get_signed_32 (abfd, buf);
10551 break;
10552 case 8:
10553 retval = bfd_get_signed_64 (abfd, buf);
10554 break;
10555 default:
10556 internal_error (__FILE__, __LINE__,
10557 _("read_address: bad switch, signed [in module %s]"),
10558 bfd_get_filename (abfd));
10559 }
10560 }
10561 else
10562 {
10563 switch (cu_header->addr_size)
10564 {
10565 case 2:
10566 retval = bfd_get_16 (abfd, buf);
10567 break;
10568 case 4:
10569 retval = bfd_get_32 (abfd, buf);
10570 break;
10571 case 8:
10572 retval = bfd_get_64 (abfd, buf);
10573 break;
10574 default:
10575 internal_error (__FILE__, __LINE__,
10576 _("read_address: bad switch, "
10577 "unsigned [in module %s]"),
10578 bfd_get_filename (abfd));
10579 }
10580 }
10581
10582 *bytes_read = cu_header->addr_size;
10583 return retval;
10584 }
10585
10586 /* Read the initial length from a section. The (draft) DWARF 3
10587 specification allows the initial length to take up either 4 bytes
10588 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
10589 bytes describe the length and all offsets will be 8 bytes in length
10590 instead of 4.
10591
10592 An older, non-standard 64-bit format is also handled by this
10593 function. The older format in question stores the initial length
10594 as an 8-byte quantity without an escape value. Lengths greater
10595 than 2^32 aren't very common which means that the initial 4 bytes
10596 is almost always zero. Since a length value of zero doesn't make
10597 sense for the 32-bit format, this initial zero can be considered to
10598 be an escape value which indicates the presence of the older 64-bit
10599 format. As written, the code can't detect (old format) lengths
10600 greater than 4GB. If it becomes necessary to handle lengths
10601 somewhat larger than 4GB, we could allow other small values (such
10602 as the non-sensical values of 1, 2, and 3) to also be used as
10603 escape values indicating the presence of the old format.
10604
10605 The value returned via bytes_read should be used to increment the
10606 relevant pointer after calling read_initial_length().
10607
10608 [ Note: read_initial_length() and read_offset() are based on the
10609 document entitled "DWARF Debugging Information Format", revision
10610 3, draft 8, dated November 19, 2001. This document was obtained
10611 from:
10612
10613 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
10614
10615 This document is only a draft and is subject to change. (So beware.)
10616
10617 Details regarding the older, non-standard 64-bit format were
10618 determined empirically by examining 64-bit ELF files produced by
10619 the SGI toolchain on an IRIX 6.5 machine.
10620
10621 - Kevin, July 16, 2002
10622 ] */
10623
10624 static LONGEST
10625 read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read)
10626 {
10627 LONGEST length = bfd_get_32 (abfd, buf);
10628
10629 if (length == 0xffffffff)
10630 {
10631 length = bfd_get_64 (abfd, buf + 4);
10632 *bytes_read = 12;
10633 }
10634 else if (length == 0)
10635 {
10636 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
10637 length = bfd_get_64 (abfd, buf);
10638 *bytes_read = 8;
10639 }
10640 else
10641 {
10642 *bytes_read = 4;
10643 }
10644
10645 return length;
10646 }
10647
10648 /* Cover function for read_initial_length.
10649 Returns the length of the object at BUF, and stores the size of the
10650 initial length in *BYTES_READ and stores the size that offsets will be in
10651 *OFFSET_SIZE.
10652 If the initial length size is not equivalent to that specified in
10653 CU_HEADER then issue a complaint.
10654 This is useful when reading non-comp-unit headers. */
10655
10656 static LONGEST
10657 read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf,
10658 const struct comp_unit_head *cu_header,
10659 unsigned int *bytes_read,
10660 unsigned int *offset_size)
10661 {
10662 LONGEST length = read_initial_length (abfd, buf, bytes_read);
10663
10664 gdb_assert (cu_header->initial_length_size == 4
10665 || cu_header->initial_length_size == 8
10666 || cu_header->initial_length_size == 12);
10667
10668 if (cu_header->initial_length_size != *bytes_read)
10669 complaint (&symfile_complaints,
10670 _("intermixed 32-bit and 64-bit DWARF sections"));
10671
10672 *offset_size = (*bytes_read == 4) ? 4 : 8;
10673 return length;
10674 }
10675
10676 /* Read an offset from the data stream. The size of the offset is
10677 given by cu_header->offset_size. */
10678
10679 static LONGEST
10680 read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header,
10681 unsigned int *bytes_read)
10682 {
10683 LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size);
10684
10685 *bytes_read = cu_header->offset_size;
10686 return offset;
10687 }
10688
10689 /* Read an offset from the data stream. */
10690
10691 static LONGEST
10692 read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size)
10693 {
10694 LONGEST retval = 0;
10695
10696 switch (offset_size)
10697 {
10698 case 4:
10699 retval = bfd_get_32 (abfd, buf);
10700 break;
10701 case 8:
10702 retval = bfd_get_64 (abfd, buf);
10703 break;
10704 default:
10705 internal_error (__FILE__, __LINE__,
10706 _("read_offset_1: bad switch [in module %s]"),
10707 bfd_get_filename (abfd));
10708 }
10709
10710 return retval;
10711 }
10712
10713 static gdb_byte *
10714 read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size)
10715 {
10716 /* If the size of a host char is 8 bits, we can return a pointer
10717 to the buffer, otherwise we have to copy the data to a buffer
10718 allocated on the temporary obstack. */
10719 gdb_assert (HOST_CHAR_BIT == 8);
10720 return buf;
10721 }
10722
10723 static char *
10724 read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
10725 {
10726 /* If the size of a host char is 8 bits, we can return a pointer
10727 to the string, otherwise we have to copy the string to a buffer
10728 allocated on the temporary obstack. */
10729 gdb_assert (HOST_CHAR_BIT == 8);
10730 if (*buf == '\0')
10731 {
10732 *bytes_read_ptr = 1;
10733 return NULL;
10734 }
10735 *bytes_read_ptr = strlen ((char *) buf) + 1;
10736 return (char *) buf;
10737 }
10738
10739 static char *
10740 read_indirect_string_at_offset (bfd *abfd, LONGEST str_offset)
10741 {
10742 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str);
10743 if (dwarf2_per_objfile->str.buffer == NULL)
10744 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10745 bfd_get_filename (abfd));
10746 if (str_offset >= dwarf2_per_objfile->str.size)
10747 error (_("DW_FORM_strp pointing outside of "
10748 ".debug_str section [in module %s]"),
10749 bfd_get_filename (abfd));
10750 gdb_assert (HOST_CHAR_BIT == 8);
10751 if (dwarf2_per_objfile->str.buffer[str_offset] == '\0')
10752 return NULL;
10753 return (char *) (dwarf2_per_objfile->str.buffer + str_offset);
10754 }
10755
10756 static char *
10757 read_indirect_string (bfd *abfd, gdb_byte *buf,
10758 const struct comp_unit_head *cu_header,
10759 unsigned int *bytes_read_ptr)
10760 {
10761 LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr);
10762
10763 return read_indirect_string_at_offset (abfd, str_offset);
10764 }
10765
10766 static ULONGEST
10767 read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
10768 {
10769 ULONGEST result;
10770 unsigned int num_read;
10771 int i, shift;
10772 unsigned char byte;
10773
10774 result = 0;
10775 shift = 0;
10776 num_read = 0;
10777 i = 0;
10778 while (1)
10779 {
10780 byte = bfd_get_8 (abfd, buf);
10781 buf++;
10782 num_read++;
10783 result |= ((ULONGEST) (byte & 127) << shift);
10784 if ((byte & 128) == 0)
10785 {
10786 break;
10787 }
10788 shift += 7;
10789 }
10790 *bytes_read_ptr = num_read;
10791 return result;
10792 }
10793
10794 static LONGEST
10795 read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
10796 {
10797 LONGEST result;
10798 int i, shift, num_read;
10799 unsigned char byte;
10800
10801 result = 0;
10802 shift = 0;
10803 num_read = 0;
10804 i = 0;
10805 while (1)
10806 {
10807 byte = bfd_get_8 (abfd, buf);
10808 buf++;
10809 num_read++;
10810 result |= ((LONGEST) (byte & 127) << shift);
10811 shift += 7;
10812 if ((byte & 128) == 0)
10813 {
10814 break;
10815 }
10816 }
10817 if ((shift < 8 * sizeof (result)) && (byte & 0x40))
10818 result |= -(((LONGEST) 1) << shift);
10819 *bytes_read_ptr = num_read;
10820 return result;
10821 }
10822
10823 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10824
10825 static gdb_byte *
10826 skip_leb128 (bfd *abfd, gdb_byte *buf)
10827 {
10828 int byte;
10829
10830 while (1)
10831 {
10832 byte = bfd_get_8 (abfd, buf);
10833 buf++;
10834 if ((byte & 128) == 0)
10835 return buf;
10836 }
10837 }
10838
10839 static void
10840 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
10841 {
10842 switch (lang)
10843 {
10844 case DW_LANG_C89:
10845 case DW_LANG_C99:
10846 case DW_LANG_C:
10847 cu->language = language_c;
10848 break;
10849 case DW_LANG_C_plus_plus:
10850 cu->language = language_cplus;
10851 break;
10852 case DW_LANG_D:
10853 cu->language = language_d;
10854 break;
10855 case DW_LANG_Fortran77:
10856 case DW_LANG_Fortran90:
10857 case DW_LANG_Fortran95:
10858 cu->language = language_fortran;
10859 break;
10860 case DW_LANG_Go:
10861 cu->language = language_go;
10862 break;
10863 case DW_LANG_Mips_Assembler:
10864 cu->language = language_asm;
10865 break;
10866 case DW_LANG_Java:
10867 cu->language = language_java;
10868 break;
10869 case DW_LANG_Ada83:
10870 case DW_LANG_Ada95:
10871 cu->language = language_ada;
10872 break;
10873 case DW_LANG_Modula2:
10874 cu->language = language_m2;
10875 break;
10876 case DW_LANG_Pascal83:
10877 cu->language = language_pascal;
10878 break;
10879 case DW_LANG_ObjC:
10880 cu->language = language_objc;
10881 break;
10882 case DW_LANG_Cobol74:
10883 case DW_LANG_Cobol85:
10884 default:
10885 cu->language = language_minimal;
10886 break;
10887 }
10888 cu->language_defn = language_def (cu->language);
10889 }
10890
10891 /* Return the named attribute or NULL if not there. */
10892
10893 static struct attribute *
10894 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
10895 {
10896 for (;;)
10897 {
10898 unsigned int i;
10899 struct attribute *spec = NULL;
10900
10901 for (i = 0; i < die->num_attrs; ++i)
10902 {
10903 if (die->attrs[i].name == name)
10904 return &die->attrs[i];
10905 if (die->attrs[i].name == DW_AT_specification
10906 || die->attrs[i].name == DW_AT_abstract_origin)
10907 spec = &die->attrs[i];
10908 }
10909
10910 if (!spec)
10911 break;
10912
10913 die = follow_die_ref (die, spec, &cu);
10914 }
10915
10916 return NULL;
10917 }
10918
10919 /* Return the named attribute or NULL if not there,
10920 but do not follow DW_AT_specification, etc.
10921 This is for use in contexts where we're reading .debug_types dies.
10922 Following DW_AT_specification, DW_AT_abstract_origin will take us
10923 back up the chain, and we want to go down. */
10924
10925 static struct attribute *
10926 dwarf2_attr_no_follow (struct die_info *die, unsigned int name,
10927 struct dwarf2_cu *cu)
10928 {
10929 unsigned int i;
10930
10931 for (i = 0; i < die->num_attrs; ++i)
10932 if (die->attrs[i].name == name)
10933 return &die->attrs[i];
10934
10935 return NULL;
10936 }
10937
10938 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10939 and holds a non-zero value. This function should only be used for
10940 DW_FORM_flag or DW_FORM_flag_present attributes. */
10941
10942 static int
10943 dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
10944 {
10945 struct attribute *attr = dwarf2_attr (die, name, cu);
10946
10947 return (attr && DW_UNSND (attr));
10948 }
10949
10950 static int
10951 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
10952 {
10953 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10954 which value is non-zero. However, we have to be careful with
10955 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10956 (via dwarf2_flag_true_p) follows this attribute. So we may
10957 end up accidently finding a declaration attribute that belongs
10958 to a different DIE referenced by the specification attribute,
10959 even though the given DIE does not have a declaration attribute. */
10960 return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
10961 && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
10962 }
10963
10964 /* Return the die giving the specification for DIE, if there is
10965 one. *SPEC_CU is the CU containing DIE on input, and the CU
10966 containing the return value on output. If there is no
10967 specification, but there is an abstract origin, that is
10968 returned. */
10969
10970 static struct die_info *
10971 die_specification (struct die_info *die, struct dwarf2_cu **spec_cu)
10972 {
10973 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification,
10974 *spec_cu);
10975
10976 if (spec_attr == NULL)
10977 spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu);
10978
10979 if (spec_attr == NULL)
10980 return NULL;
10981 else
10982 return follow_die_ref (die, spec_attr, spec_cu);
10983 }
10984
10985 /* Free the line_header structure *LH, and any arrays and strings it
10986 refers to.
10987 NOTE: This is also used as a "cleanup" function. */
10988
10989 static void
10990 free_line_header (struct line_header *lh)
10991 {
10992 if (lh->standard_opcode_lengths)
10993 xfree (lh->standard_opcode_lengths);
10994
10995 /* Remember that all the lh->file_names[i].name pointers are
10996 pointers into debug_line_buffer, and don't need to be freed. */
10997 if (lh->file_names)
10998 xfree (lh->file_names);
10999
11000 /* Similarly for the include directory names. */
11001 if (lh->include_dirs)
11002 xfree (lh->include_dirs);
11003
11004 xfree (lh);
11005 }
11006
11007 /* Add an entry to LH's include directory table. */
11008
11009 static void
11010 add_include_dir (struct line_header *lh, char *include_dir)
11011 {
11012 /* Grow the array if necessary. */
11013 if (lh->include_dirs_size == 0)
11014 {
11015 lh->include_dirs_size = 1; /* for testing */
11016 lh->include_dirs = xmalloc (lh->include_dirs_size
11017 * sizeof (*lh->include_dirs));
11018 }
11019 else if (lh->num_include_dirs >= lh->include_dirs_size)
11020 {
11021 lh->include_dirs_size *= 2;
11022 lh->include_dirs = xrealloc (lh->include_dirs,
11023 (lh->include_dirs_size
11024 * sizeof (*lh->include_dirs)));
11025 }
11026
11027 lh->include_dirs[lh->num_include_dirs++] = include_dir;
11028 }
11029
11030 /* Add an entry to LH's file name table. */
11031
11032 static void
11033 add_file_name (struct line_header *lh,
11034 char *name,
11035 unsigned int dir_index,
11036 unsigned int mod_time,
11037 unsigned int length)
11038 {
11039 struct file_entry *fe;
11040
11041 /* Grow the array if necessary. */
11042 if (lh->file_names_size == 0)
11043 {
11044 lh->file_names_size = 1; /* for testing */
11045 lh->file_names = xmalloc (lh->file_names_size
11046 * sizeof (*lh->file_names));
11047 }
11048 else if (lh->num_file_names >= lh->file_names_size)
11049 {
11050 lh->file_names_size *= 2;
11051 lh->file_names = xrealloc (lh->file_names,
11052 (lh->file_names_size
11053 * sizeof (*lh->file_names)));
11054 }
11055
11056 fe = &lh->file_names[lh->num_file_names++];
11057 fe->name = name;
11058 fe->dir_index = dir_index;
11059 fe->mod_time = mod_time;
11060 fe->length = length;
11061 fe->included_p = 0;
11062 fe->symtab = NULL;
11063 }
11064
11065 /* Read the statement program header starting at OFFSET in
11066 .debug_line, according to the endianness of ABFD. Return a pointer
11067 to a struct line_header, allocated using xmalloc.
11068
11069 NOTE: the strings in the include directory and file name tables of
11070 the returned object point into debug_line_buffer, and must not be
11071 freed. */
11072
11073 static struct line_header *
11074 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
11075 struct dwarf2_cu *cu)
11076 {
11077 struct cleanup *back_to;
11078 struct line_header *lh;
11079 gdb_byte *line_ptr;
11080 unsigned int bytes_read, offset_size;
11081 int i;
11082 char *cur_dir, *cur_file;
11083
11084 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line);
11085 if (dwarf2_per_objfile->line.buffer == NULL)
11086 {
11087 complaint (&symfile_complaints, _("missing .debug_line section"));
11088 return 0;
11089 }
11090
11091 /* Make sure that at least there's room for the total_length field.
11092 That could be 12 bytes long, but we're just going to fudge that. */
11093 if (offset + 4 >= dwarf2_per_objfile->line.size)
11094 {
11095 dwarf2_statement_list_fits_in_line_number_section_complaint ();
11096 return 0;
11097 }
11098
11099 lh = xmalloc (sizeof (*lh));
11100 memset (lh, 0, sizeof (*lh));
11101 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
11102 (void *) lh);
11103
11104 line_ptr = dwarf2_per_objfile->line.buffer + offset;
11105
11106 /* Read in the header. */
11107 lh->total_length =
11108 read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header,
11109 &bytes_read, &offset_size);
11110 line_ptr += bytes_read;
11111 if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer
11112 + dwarf2_per_objfile->line.size))
11113 {
11114 dwarf2_statement_list_fits_in_line_number_section_complaint ();
11115 return 0;
11116 }
11117 lh->statement_program_end = line_ptr + lh->total_length;
11118 lh->version = read_2_bytes (abfd, line_ptr);
11119 line_ptr += 2;
11120 lh->header_length = read_offset_1 (abfd, line_ptr, offset_size);
11121 line_ptr += offset_size;
11122 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
11123 line_ptr += 1;
11124 if (lh->version >= 4)
11125 {
11126 lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr);
11127 line_ptr += 1;
11128 }
11129 else
11130 lh->maximum_ops_per_instruction = 1;
11131
11132 if (lh->maximum_ops_per_instruction == 0)
11133 {
11134 lh->maximum_ops_per_instruction = 1;
11135 complaint (&symfile_complaints,
11136 _("invalid maximum_ops_per_instruction "
11137 "in `.debug_line' section"));
11138 }
11139
11140 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
11141 line_ptr += 1;
11142 lh->line_base = read_1_signed_byte (abfd, line_ptr);
11143 line_ptr += 1;
11144 lh->line_range = read_1_byte (abfd, line_ptr);
11145 line_ptr += 1;
11146 lh->opcode_base = read_1_byte (abfd, line_ptr);
11147 line_ptr += 1;
11148 lh->standard_opcode_lengths
11149 = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0]));
11150
11151 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
11152 for (i = 1; i < lh->opcode_base; ++i)
11153 {
11154 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
11155 line_ptr += 1;
11156 }
11157
11158 /* Read directory table. */
11159 while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
11160 {
11161 line_ptr += bytes_read;
11162 add_include_dir (lh, cur_dir);
11163 }
11164 line_ptr += bytes_read;
11165
11166 /* Read file name table. */
11167 while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
11168 {
11169 unsigned int dir_index, mod_time, length;
11170
11171 line_ptr += bytes_read;
11172 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11173 line_ptr += bytes_read;
11174 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11175 line_ptr += bytes_read;
11176 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11177 line_ptr += bytes_read;
11178
11179 add_file_name (lh, cur_file, dir_index, mod_time, length);
11180 }
11181 line_ptr += bytes_read;
11182 lh->statement_program_start = line_ptr;
11183
11184 if (line_ptr > (dwarf2_per_objfile->line.buffer
11185 + dwarf2_per_objfile->line.size))
11186 complaint (&symfile_complaints,
11187 _("line number info header doesn't "
11188 "fit in `.debug_line' section"));
11189
11190 discard_cleanups (back_to);
11191 return lh;
11192 }
11193
11194 /* Subroutine of dwarf_decode_lines to simplify it.
11195 Return the file name of the psymtab for included file FILE_INDEX
11196 in line header LH of PST.
11197 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11198 If space for the result is malloc'd, it will be freed by a cleanup.
11199 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
11200
11201 static char *
11202 psymtab_include_file_name (const struct line_header *lh, int file_index,
11203 const struct partial_symtab *pst,
11204 const char *comp_dir)
11205 {
11206 const struct file_entry fe = lh->file_names [file_index];
11207 char *include_name = fe.name;
11208 char *include_name_to_compare = include_name;
11209 char *dir_name = NULL;
11210 const char *pst_filename;
11211 char *copied_name = NULL;
11212 int file_is_pst;
11213
11214 if (fe.dir_index)
11215 dir_name = lh->include_dirs[fe.dir_index - 1];
11216
11217 if (!IS_ABSOLUTE_PATH (include_name)
11218 && (dir_name != NULL || comp_dir != NULL))
11219 {
11220 /* Avoid creating a duplicate psymtab for PST.
11221 We do this by comparing INCLUDE_NAME and PST_FILENAME.
11222 Before we do the comparison, however, we need to account
11223 for DIR_NAME and COMP_DIR.
11224 First prepend dir_name (if non-NULL). If we still don't
11225 have an absolute path prepend comp_dir (if non-NULL).
11226 However, the directory we record in the include-file's
11227 psymtab does not contain COMP_DIR (to match the
11228 corresponding symtab(s)).
11229
11230 Example:
11231
11232 bash$ cd /tmp
11233 bash$ gcc -g ./hello.c
11234 include_name = "hello.c"
11235 dir_name = "."
11236 DW_AT_comp_dir = comp_dir = "/tmp"
11237 DW_AT_name = "./hello.c" */
11238
11239 if (dir_name != NULL)
11240 {
11241 include_name = concat (dir_name, SLASH_STRING,
11242 include_name, (char *)NULL);
11243 include_name_to_compare = include_name;
11244 make_cleanup (xfree, include_name);
11245 }
11246 if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL)
11247 {
11248 include_name_to_compare = concat (comp_dir, SLASH_STRING,
11249 include_name, (char *)NULL);
11250 }
11251 }
11252
11253 pst_filename = pst->filename;
11254 if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL)
11255 {
11256 copied_name = concat (pst->dirname, SLASH_STRING,
11257 pst_filename, (char *)NULL);
11258 pst_filename = copied_name;
11259 }
11260
11261 file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0;
11262
11263 if (include_name_to_compare != include_name)
11264 xfree (include_name_to_compare);
11265 if (copied_name != NULL)
11266 xfree (copied_name);
11267
11268 if (file_is_pst)
11269 return NULL;
11270 return include_name;
11271 }
11272
11273 /* Ignore this record_line request. */
11274
11275 static void
11276 noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc)
11277 {
11278 return;
11279 }
11280
11281 /* Subroutine of dwarf_decode_lines to simplify it.
11282 Process the line number information in LH. */
11283
11284 static void
11285 dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
11286 struct dwarf2_cu *cu, struct partial_symtab *pst)
11287 {
11288 gdb_byte *line_ptr, *extended_end;
11289 gdb_byte *line_end;
11290 unsigned int bytes_read, extended_len;
11291 unsigned char op_code, extended_op, adj_opcode;
11292 CORE_ADDR baseaddr;
11293 struct objfile *objfile = cu->objfile;
11294 bfd *abfd = objfile->obfd;
11295 struct gdbarch *gdbarch = get_objfile_arch (objfile);
11296 const int decode_for_pst_p = (pst != NULL);
11297 struct subfile *last_subfile = NULL;
11298 void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc)
11299 = record_line;
11300
11301 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
11302
11303 line_ptr = lh->statement_program_start;
11304 line_end = lh->statement_program_end;
11305
11306 /* Read the statement sequences until there's nothing left. */
11307 while (line_ptr < line_end)
11308 {
11309 /* state machine registers */
11310 CORE_ADDR address = 0;
11311 unsigned int file = 1;
11312 unsigned int line = 1;
11313 unsigned int column = 0;
11314 int is_stmt = lh->default_is_stmt;
11315 int basic_block = 0;
11316 int end_sequence = 0;
11317 CORE_ADDR addr;
11318 unsigned char op_index = 0;
11319
11320 if (!decode_for_pst_p && lh->num_file_names >= file)
11321 {
11322 /* Start a subfile for the current file of the state machine. */
11323 /* lh->include_dirs and lh->file_names are 0-based, but the
11324 directory and file name numbers in the statement program
11325 are 1-based. */
11326 struct file_entry *fe = &lh->file_names[file - 1];
11327 char *dir = NULL;
11328
11329 if (fe->dir_index)
11330 dir = lh->include_dirs[fe->dir_index - 1];
11331
11332 dwarf2_start_subfile (fe->name, dir, comp_dir);
11333 }
11334
11335 /* Decode the table. */
11336 while (!end_sequence)
11337 {
11338 op_code = read_1_byte (abfd, line_ptr);
11339 line_ptr += 1;
11340 if (line_ptr > line_end)
11341 {
11342 dwarf2_debug_line_missing_end_sequence_complaint ();
11343 break;
11344 }
11345
11346 if (op_code >= lh->opcode_base)
11347 {
11348 /* Special operand. */
11349 adj_opcode = op_code - lh->opcode_base;
11350 address += (((op_index + (adj_opcode / lh->line_range))
11351 / lh->maximum_ops_per_instruction)
11352 * lh->minimum_instruction_length);
11353 op_index = ((op_index + (adj_opcode / lh->line_range))
11354 % lh->maximum_ops_per_instruction);
11355 line += lh->line_base + (adj_opcode % lh->line_range);
11356 if (lh->num_file_names < file || file == 0)
11357 dwarf2_debug_line_missing_file_complaint ();
11358 /* For now we ignore lines not starting on an
11359 instruction boundary. */
11360 else if (op_index == 0)
11361 {
11362 lh->file_names[file - 1].included_p = 1;
11363 if (!decode_for_pst_p && is_stmt)
11364 {
11365 if (last_subfile != current_subfile)
11366 {
11367 addr = gdbarch_addr_bits_remove (gdbarch, address);
11368 if (last_subfile)
11369 (*p_record_line) (last_subfile, 0, addr);
11370 last_subfile = current_subfile;
11371 }
11372 /* Append row to matrix using current values. */
11373 addr = gdbarch_addr_bits_remove (gdbarch, address);
11374 (*p_record_line) (current_subfile, line, addr);
11375 }
11376 }
11377 basic_block = 0;
11378 }
11379 else switch (op_code)
11380 {
11381 case DW_LNS_extended_op:
11382 extended_len = read_unsigned_leb128 (abfd, line_ptr,
11383 &bytes_read);
11384 line_ptr += bytes_read;
11385 extended_end = line_ptr + extended_len;
11386 extended_op = read_1_byte (abfd, line_ptr);
11387 line_ptr += 1;
11388 switch (extended_op)
11389 {
11390 case DW_LNE_end_sequence:
11391 p_record_line = record_line;
11392 end_sequence = 1;
11393 break;
11394 case DW_LNE_set_address:
11395 address = read_address (abfd, line_ptr, cu, &bytes_read);
11396
11397 if (address == 0 && !dwarf2_per_objfile->has_section_at_zero)
11398 {
11399 /* This line table is for a function which has been
11400 GCd by the linker. Ignore it. PR gdb/12528 */
11401
11402 long line_offset
11403 = line_ptr - dwarf2_per_objfile->line.buffer;
11404
11405 complaint (&symfile_complaints,
11406 _(".debug_line address at offset 0x%lx is 0 "
11407 "[in module %s]"),
11408 line_offset, objfile->name);
11409 p_record_line = noop_record_line;
11410 }
11411
11412 op_index = 0;
11413 line_ptr += bytes_read;
11414 address += baseaddr;
11415 break;
11416 case DW_LNE_define_file:
11417 {
11418 char *cur_file;
11419 unsigned int dir_index, mod_time, length;
11420
11421 cur_file = read_direct_string (abfd, line_ptr,
11422 &bytes_read);
11423 line_ptr += bytes_read;
11424 dir_index =
11425 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11426 line_ptr += bytes_read;
11427 mod_time =
11428 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11429 line_ptr += bytes_read;
11430 length =
11431 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11432 line_ptr += bytes_read;
11433 add_file_name (lh, cur_file, dir_index, mod_time, length);
11434 }
11435 break;
11436 case DW_LNE_set_discriminator:
11437 /* The discriminator is not interesting to the debugger;
11438 just ignore it. */
11439 line_ptr = extended_end;
11440 break;
11441 default:
11442 complaint (&symfile_complaints,
11443 _("mangled .debug_line section"));
11444 return;
11445 }
11446 /* Make sure that we parsed the extended op correctly. If e.g.
11447 we expected a different address size than the producer used,
11448 we may have read the wrong number of bytes. */
11449 if (line_ptr != extended_end)
11450 {
11451 complaint (&symfile_complaints,
11452 _("mangled .debug_line section"));
11453 return;
11454 }
11455 break;
11456 case DW_LNS_copy:
11457 if (lh->num_file_names < file || file == 0)
11458 dwarf2_debug_line_missing_file_complaint ();
11459 else
11460 {
11461 lh->file_names[file - 1].included_p = 1;
11462 if (!decode_for_pst_p && is_stmt)
11463 {
11464 if (last_subfile != current_subfile)
11465 {
11466 addr = gdbarch_addr_bits_remove (gdbarch, address);
11467 if (last_subfile)
11468 (*p_record_line) (last_subfile, 0, addr);
11469 last_subfile = current_subfile;
11470 }
11471 addr = gdbarch_addr_bits_remove (gdbarch, address);
11472 (*p_record_line) (current_subfile, line, addr);
11473 }
11474 }
11475 basic_block = 0;
11476 break;
11477 case DW_LNS_advance_pc:
11478 {
11479 CORE_ADDR adjust
11480 = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11481
11482 address += (((op_index + adjust)
11483 / lh->maximum_ops_per_instruction)
11484 * lh->minimum_instruction_length);
11485 op_index = ((op_index + adjust)
11486 % lh->maximum_ops_per_instruction);
11487 line_ptr += bytes_read;
11488 }
11489 break;
11490 case DW_LNS_advance_line:
11491 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
11492 line_ptr += bytes_read;
11493 break;
11494 case DW_LNS_set_file:
11495 {
11496 /* The arrays lh->include_dirs and lh->file_names are
11497 0-based, but the directory and file name numbers in
11498 the statement program are 1-based. */
11499 struct file_entry *fe;
11500 char *dir = NULL;
11501
11502 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11503 line_ptr += bytes_read;
11504 if (lh->num_file_names < file || file == 0)
11505 dwarf2_debug_line_missing_file_complaint ();
11506 else
11507 {
11508 fe = &lh->file_names[file - 1];
11509 if (fe->dir_index)
11510 dir = lh->include_dirs[fe->dir_index - 1];
11511 if (!decode_for_pst_p)
11512 {
11513 last_subfile = current_subfile;
11514 dwarf2_start_subfile (fe->name, dir, comp_dir);
11515 }
11516 }
11517 }
11518 break;
11519 case DW_LNS_set_column:
11520 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11521 line_ptr += bytes_read;
11522 break;
11523 case DW_LNS_negate_stmt:
11524 is_stmt = (!is_stmt);
11525 break;
11526 case DW_LNS_set_basic_block:
11527 basic_block = 1;
11528 break;
11529 /* Add to the address register of the state machine the
11530 address increment value corresponding to special opcode
11531 255. I.e., this value is scaled by the minimum
11532 instruction length since special opcode 255 would have
11533 scaled the increment. */
11534 case DW_LNS_const_add_pc:
11535 {
11536 CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range;
11537
11538 address += (((op_index + adjust)
11539 / lh->maximum_ops_per_instruction)
11540 * lh->minimum_instruction_length);
11541 op_index = ((op_index + adjust)
11542 % lh->maximum_ops_per_instruction);
11543 }
11544 break;
11545 case DW_LNS_fixed_advance_pc:
11546 address += read_2_bytes (abfd, line_ptr);
11547 op_index = 0;
11548 line_ptr += 2;
11549 break;
11550 default:
11551 {
11552 /* Unknown standard opcode, ignore it. */
11553 int i;
11554
11555 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
11556 {
11557 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11558 line_ptr += bytes_read;
11559 }
11560 }
11561 }
11562 }
11563 if (lh->num_file_names < file || file == 0)
11564 dwarf2_debug_line_missing_file_complaint ();
11565 else
11566 {
11567 lh->file_names[file - 1].included_p = 1;
11568 if (!decode_for_pst_p)
11569 {
11570 addr = gdbarch_addr_bits_remove (gdbarch, address);
11571 (*p_record_line) (current_subfile, 0, addr);
11572 }
11573 }
11574 }
11575 }
11576
11577 /* Decode the Line Number Program (LNP) for the given line_header
11578 structure and CU. The actual information extracted and the type
11579 of structures created from the LNP depends on the value of PST.
11580
11581 1. If PST is NULL, then this procedure uses the data from the program
11582 to create all necessary symbol tables, and their linetables.
11583
11584 2. If PST is not NULL, this procedure reads the program to determine
11585 the list of files included by the unit represented by PST, and
11586 builds all the associated partial symbol tables.
11587
11588 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11589 It is used for relative paths in the line table.
11590 NOTE: When processing partial symtabs (pst != NULL),
11591 comp_dir == pst->dirname.
11592
11593 NOTE: It is important that psymtabs have the same file name (via strcmp)
11594 as the corresponding symtab. Since COMP_DIR is not used in the name of the
11595 symtab we don't use it in the name of the psymtabs we create.
11596 E.g. expand_line_sal requires this when finding psymtabs to expand.
11597 A good testcase for this is mb-inline.exp. */
11598
11599 static void
11600 dwarf_decode_lines (struct line_header *lh, const char *comp_dir,
11601 struct dwarf2_cu *cu, struct partial_symtab *pst,
11602 int want_line_info)
11603 {
11604 struct objfile *objfile = cu->objfile;
11605 const int decode_for_pst_p = (pst != NULL);
11606 struct subfile *first_subfile = current_subfile;
11607
11608 if (want_line_info)
11609 dwarf_decode_lines_1 (lh, comp_dir, cu, pst);
11610
11611 if (decode_for_pst_p)
11612 {
11613 int file_index;
11614
11615 /* Now that we're done scanning the Line Header Program, we can
11616 create the psymtab of each included file. */
11617 for (file_index = 0; file_index < lh->num_file_names; file_index++)
11618 if (lh->file_names[file_index].included_p == 1)
11619 {
11620 char *include_name =
11621 psymtab_include_file_name (lh, file_index, pst, comp_dir);
11622 if (include_name != NULL)
11623 dwarf2_create_include_psymtab (include_name, pst, objfile);
11624 }
11625 }
11626 else
11627 {
11628 /* Make sure a symtab is created for every file, even files
11629 which contain only variables (i.e. no code with associated
11630 line numbers). */
11631 int i;
11632
11633 for (i = 0; i < lh->num_file_names; i++)
11634 {
11635 char *dir = NULL;
11636 struct file_entry *fe;
11637
11638 fe = &lh->file_names[i];
11639 if (fe->dir_index)
11640 dir = lh->include_dirs[fe->dir_index - 1];
11641 dwarf2_start_subfile (fe->name, dir, comp_dir);
11642
11643 /* Skip the main file; we don't need it, and it must be
11644 allocated last, so that it will show up before the
11645 non-primary symtabs in the objfile's symtab list. */
11646 if (current_subfile == first_subfile)
11647 continue;
11648
11649 if (current_subfile->symtab == NULL)
11650 current_subfile->symtab = allocate_symtab (current_subfile->name,
11651 objfile);
11652 fe->symtab = current_subfile->symtab;
11653 }
11654 }
11655 }
11656
11657 /* Start a subfile for DWARF. FILENAME is the name of the file and
11658 DIRNAME the name of the source directory which contains FILENAME
11659 or NULL if not known. COMP_DIR is the compilation directory for the
11660 linetable's compilation unit or NULL if not known.
11661 This routine tries to keep line numbers from identical absolute and
11662 relative file names in a common subfile.
11663
11664 Using the `list' example from the GDB testsuite, which resides in
11665 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
11666 of /srcdir/list0.c yields the following debugging information for list0.c:
11667
11668 DW_AT_name: /srcdir/list0.c
11669 DW_AT_comp_dir: /compdir
11670 files.files[0].name: list0.h
11671 files.files[0].dir: /srcdir
11672 files.files[1].name: list0.c
11673 files.files[1].dir: /srcdir
11674
11675 The line number information for list0.c has to end up in a single
11676 subfile, so that `break /srcdir/list0.c:1' works as expected.
11677 start_subfile will ensure that this happens provided that we pass the
11678 concatenation of files.files[1].dir and files.files[1].name as the
11679 subfile's name. */
11680
11681 static void
11682 dwarf2_start_subfile (char *filename, const char *dirname,
11683 const char *comp_dir)
11684 {
11685 char *fullname;
11686
11687 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
11688 `start_symtab' will always pass the contents of DW_AT_comp_dir as
11689 second argument to start_subfile. To be consistent, we do the
11690 same here. In order not to lose the line information directory,
11691 we concatenate it to the filename when it makes sense.
11692 Note that the Dwarf3 standard says (speaking of filenames in line
11693 information): ``The directory index is ignored for file names
11694 that represent full path names''. Thus ignoring dirname in the
11695 `else' branch below isn't an issue. */
11696
11697 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
11698 fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL);
11699 else
11700 fullname = filename;
11701
11702 start_subfile (fullname, comp_dir);
11703
11704 if (fullname != filename)
11705 xfree (fullname);
11706 }
11707
11708 static void
11709 var_decode_location (struct attribute *attr, struct symbol *sym,
11710 struct dwarf2_cu *cu)
11711 {
11712 struct objfile *objfile = cu->objfile;
11713 struct comp_unit_head *cu_header = &cu->header;
11714
11715 /* NOTE drow/2003-01-30: There used to be a comment and some special
11716 code here to turn a symbol with DW_AT_external and a
11717 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11718 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11719 with some versions of binutils) where shared libraries could have
11720 relocations against symbols in their debug information - the
11721 minimal symbol would have the right address, but the debug info
11722 would not. It's no longer necessary, because we will explicitly
11723 apply relocations when we read in the debug information now. */
11724
11725 /* A DW_AT_location attribute with no contents indicates that a
11726 variable has been optimized away. */
11727 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
11728 {
11729 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
11730 return;
11731 }
11732
11733 /* Handle one degenerate form of location expression specially, to
11734 preserve GDB's previous behavior when section offsets are
11735 specified. If this is just a DW_OP_addr then mark this symbol
11736 as LOC_STATIC. */
11737
11738 if (attr_form_is_block (attr)
11739 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
11740 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
11741 {
11742 unsigned int dummy;
11743
11744 SYMBOL_VALUE_ADDRESS (sym) =
11745 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
11746 SYMBOL_CLASS (sym) = LOC_STATIC;
11747 fixup_symbol_section (sym, objfile);
11748 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
11749 SYMBOL_SECTION (sym));
11750 return;
11751 }
11752
11753 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11754 expression evaluator, and use LOC_COMPUTED only when necessary
11755 (i.e. when the value of a register or memory location is
11756 referenced, or a thread-local block, etc.). Then again, it might
11757 not be worthwhile. I'm assuming that it isn't unless performance
11758 or memory numbers show me otherwise. */
11759
11760 dwarf2_symbol_mark_computed (attr, sym, cu);
11761 SYMBOL_CLASS (sym) = LOC_COMPUTED;
11762
11763 if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs)
11764 cu->has_loclist = 1;
11765 }
11766
11767 /* Given a pointer to a DWARF information entry, figure out if we need
11768 to make a symbol table entry for it, and if so, create a new entry
11769 and return a pointer to it.
11770 If TYPE is NULL, determine symbol type from the die, otherwise
11771 used the passed type.
11772 If SPACE is not NULL, use it to hold the new symbol. If it is
11773 NULL, allocate a new symbol on the objfile's obstack. */
11774
11775 static struct symbol *
11776 new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
11777 struct symbol *space)
11778 {
11779 struct objfile *objfile = cu->objfile;
11780 struct symbol *sym = NULL;
11781 char *name;
11782 struct attribute *attr = NULL;
11783 struct attribute *attr2 = NULL;
11784 CORE_ADDR baseaddr;
11785 struct pending **list_to_add = NULL;
11786
11787 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
11788
11789 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
11790
11791 name = dwarf2_name (die, cu);
11792 if (name)
11793 {
11794 const char *linkagename;
11795 int suppress_add = 0;
11796
11797 if (space)
11798 sym = space;
11799 else
11800 sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol);
11801 OBJSTAT (objfile, n_syms++);
11802
11803 /* Cache this symbol's name and the name's demangled form (if any). */
11804 SYMBOL_SET_LANGUAGE (sym, cu->language);
11805 linkagename = dwarf2_physname (name, die, cu);
11806 SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile);
11807
11808 /* Fortran does not have mangling standard and the mangling does differ
11809 between gfortran, iFort etc. */
11810 if (cu->language == language_fortran
11811 && symbol_get_demangled_name (&(sym->ginfo)) == NULL)
11812 symbol_set_demangled_name (&(sym->ginfo),
11813 (char *) dwarf2_full_name (name, die, cu),
11814 NULL);
11815
11816 /* Default assumptions.
11817 Use the passed type or decode it from the die. */
11818 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11819 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
11820 if (type != NULL)
11821 SYMBOL_TYPE (sym) = type;
11822 else
11823 SYMBOL_TYPE (sym) = die_type (die, cu);
11824 attr = dwarf2_attr (die,
11825 inlined_func ? DW_AT_call_line : DW_AT_decl_line,
11826 cu);
11827 if (attr)
11828 {
11829 SYMBOL_LINE (sym) = DW_UNSND (attr);
11830 }
11831
11832 attr = dwarf2_attr (die,
11833 inlined_func ? DW_AT_call_file : DW_AT_decl_file,
11834 cu);
11835 if (attr)
11836 {
11837 int file_index = DW_UNSND (attr);
11838
11839 if (cu->line_header == NULL
11840 || file_index > cu->line_header->num_file_names)
11841 complaint (&symfile_complaints,
11842 _("file index out of range"));
11843 else if (file_index > 0)
11844 {
11845 struct file_entry *fe;
11846
11847 fe = &cu->line_header->file_names[file_index - 1];
11848 SYMBOL_SYMTAB (sym) = fe->symtab;
11849 }
11850 }
11851
11852 switch (die->tag)
11853 {
11854 case DW_TAG_label:
11855 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
11856 if (attr)
11857 {
11858 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
11859 }
11860 SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr;
11861 SYMBOL_DOMAIN (sym) = LABEL_DOMAIN;
11862 SYMBOL_CLASS (sym) = LOC_LABEL;
11863 add_symbol_to_list (sym, cu->list_in_scope);
11864 break;
11865 case DW_TAG_subprogram:
11866 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11867 finish_block. */
11868 SYMBOL_CLASS (sym) = LOC_BLOCK;
11869 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11870 if ((attr2 && (DW_UNSND (attr2) != 0))
11871 || cu->language == language_ada)
11872 {
11873 /* Subprograms marked external are stored as a global symbol.
11874 Ada subprograms, whether marked external or not, are always
11875 stored as a global symbol, because we want to be able to
11876 access them globally. For instance, we want to be able
11877 to break on a nested subprogram without having to
11878 specify the context. */
11879 list_to_add = &global_symbols;
11880 }
11881 else
11882 {
11883 list_to_add = cu->list_in_scope;
11884 }
11885 break;
11886 case DW_TAG_inlined_subroutine:
11887 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11888 finish_block. */
11889 SYMBOL_CLASS (sym) = LOC_BLOCK;
11890 SYMBOL_INLINED (sym) = 1;
11891 list_to_add = cu->list_in_scope;
11892 break;
11893 case DW_TAG_template_value_param:
11894 suppress_add = 1;
11895 /* Fall through. */
11896 case DW_TAG_constant:
11897 case DW_TAG_variable:
11898 case DW_TAG_member:
11899 /* Compilation with minimal debug info may result in
11900 variables with missing type entries. Change the
11901 misleading `void' type to something sensible. */
11902 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
11903 SYMBOL_TYPE (sym)
11904 = objfile_type (objfile)->nodebug_data_symbol;
11905
11906 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11907 /* In the case of DW_TAG_member, we should only be called for
11908 static const members. */
11909 if (die->tag == DW_TAG_member)
11910 {
11911 /* dwarf2_add_field uses die_is_declaration,
11912 so we do the same. */
11913 gdb_assert (die_is_declaration (die, cu));
11914 gdb_assert (attr);
11915 }
11916 if (attr)
11917 {
11918 dwarf2_const_value (attr, sym, cu);
11919 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11920 if (!suppress_add)
11921 {
11922 if (attr2 && (DW_UNSND (attr2) != 0))
11923 list_to_add = &global_symbols;
11924 else
11925 list_to_add = cu->list_in_scope;
11926 }
11927 break;
11928 }
11929 attr = dwarf2_attr (die, DW_AT_location, cu);
11930 if (attr)
11931 {
11932 var_decode_location (attr, sym, cu);
11933 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11934 if (SYMBOL_CLASS (sym) == LOC_STATIC
11935 && SYMBOL_VALUE_ADDRESS (sym) == 0
11936 && !dwarf2_per_objfile->has_section_at_zero)
11937 {
11938 /* When a static variable is eliminated by the linker,
11939 the corresponding debug information is not stripped
11940 out, but the variable address is set to null;
11941 do not add such variables into symbol table. */
11942 }
11943 else if (attr2 && (DW_UNSND (attr2) != 0))
11944 {
11945 /* Workaround gfortran PR debug/40040 - it uses
11946 DW_AT_location for variables in -fPIC libraries which may
11947 get overriden by other libraries/executable and get
11948 a different address. Resolve it by the minimal symbol
11949 which may come from inferior's executable using copy
11950 relocation. Make this workaround only for gfortran as for
11951 other compilers GDB cannot guess the minimal symbol
11952 Fortran mangling kind. */
11953 if (cu->language == language_fortran && die->parent
11954 && die->parent->tag == DW_TAG_module
11955 && cu->producer
11956 && strncmp (cu->producer, "GNU Fortran ", 12) == 0)
11957 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
11958
11959 /* A variable with DW_AT_external is never static,
11960 but it may be block-scoped. */
11961 list_to_add = (cu->list_in_scope == &file_symbols
11962 ? &global_symbols : cu->list_in_scope);
11963 }
11964 else
11965 list_to_add = cu->list_in_scope;
11966 }
11967 else
11968 {
11969 /* We do not know the address of this symbol.
11970 If it is an external symbol and we have type information
11971 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11972 The address of the variable will then be determined from
11973 the minimal symbol table whenever the variable is
11974 referenced. */
11975 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11976 if (attr2 && (DW_UNSND (attr2) != 0)
11977 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
11978 {
11979 /* A variable with DW_AT_external is never static, but it
11980 may be block-scoped. */
11981 list_to_add = (cu->list_in_scope == &file_symbols
11982 ? &global_symbols : cu->list_in_scope);
11983
11984 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
11985 }
11986 else if (!die_is_declaration (die, cu))
11987 {
11988 /* Use the default LOC_OPTIMIZED_OUT class. */
11989 gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT);
11990 if (!suppress_add)
11991 list_to_add = cu->list_in_scope;
11992 }
11993 }
11994 break;
11995 case DW_TAG_formal_parameter:
11996 /* If we are inside a function, mark this as an argument. If
11997 not, we might be looking at an argument to an inlined function
11998 when we do not have enough information to show inlined frames;
11999 pretend it's a local variable in that case so that the user can
12000 still see it. */
12001 if (context_stack_depth > 0
12002 && context_stack[context_stack_depth - 1].name != NULL)
12003 SYMBOL_IS_ARGUMENT (sym) = 1;
12004 attr = dwarf2_attr (die, DW_AT_location, cu);
12005 if (attr)
12006 {
12007 var_decode_location (attr, sym, cu);
12008 }
12009 attr = dwarf2_attr (die, DW_AT_const_value, cu);
12010 if (attr)
12011 {
12012 dwarf2_const_value (attr, sym, cu);
12013 }
12014
12015 list_to_add = cu->list_in_scope;
12016 break;
12017 case DW_TAG_unspecified_parameters:
12018 /* From varargs functions; gdb doesn't seem to have any
12019 interest in this information, so just ignore it for now.
12020 (FIXME?) */
12021 break;
12022 case DW_TAG_template_type_param:
12023 suppress_add = 1;
12024 /* Fall through. */
12025 case DW_TAG_class_type:
12026 case DW_TAG_interface_type:
12027 case DW_TAG_structure_type:
12028 case DW_TAG_union_type:
12029 case DW_TAG_set_type:
12030 case DW_TAG_enumeration_type:
12031 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
12032 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
12033
12034 {
12035 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
12036 really ever be static objects: otherwise, if you try
12037 to, say, break of a class's method and you're in a file
12038 which doesn't mention that class, it won't work unless
12039 the check for all static symbols in lookup_symbol_aux
12040 saves you. See the OtherFileClass tests in
12041 gdb.c++/namespace.exp. */
12042
12043 if (!suppress_add)
12044 {
12045 list_to_add = (cu->list_in_scope == &file_symbols
12046 && (cu->language == language_cplus
12047 || cu->language == language_java)
12048 ? &global_symbols : cu->list_in_scope);
12049
12050 /* The semantics of C++ state that "struct foo {
12051 ... }" also defines a typedef for "foo". A Java
12052 class declaration also defines a typedef for the
12053 class. */
12054 if (cu->language == language_cplus
12055 || cu->language == language_java
12056 || cu->language == language_ada)
12057 {
12058 /* The symbol's name is already allocated along
12059 with this objfile, so we don't need to
12060 duplicate it for the type. */
12061 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
12062 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym);
12063 }
12064 }
12065 }
12066 break;
12067 case DW_TAG_typedef:
12068 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
12069 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
12070 list_to_add = cu->list_in_scope;
12071 break;
12072 case DW_TAG_base_type:
12073 case DW_TAG_subrange_type:
12074 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
12075 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
12076 list_to_add = cu->list_in_scope;
12077 break;
12078 case DW_TAG_enumerator:
12079 attr = dwarf2_attr (die, DW_AT_const_value, cu);
12080 if (attr)
12081 {
12082 dwarf2_const_value (attr, sym, cu);
12083 }
12084 {
12085 /* NOTE: carlton/2003-11-10: See comment above in the
12086 DW_TAG_class_type, etc. block. */
12087
12088 list_to_add = (cu->list_in_scope == &file_symbols
12089 && (cu->language == language_cplus
12090 || cu->language == language_java)
12091 ? &global_symbols : cu->list_in_scope);
12092 }
12093 break;
12094 case DW_TAG_namespace:
12095 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
12096 list_to_add = &global_symbols;
12097 break;
12098 default:
12099 /* Not a tag we recognize. Hopefully we aren't processing
12100 trash data, but since we must specifically ignore things
12101 we don't recognize, there is nothing else we should do at
12102 this point. */
12103 complaint (&symfile_complaints, _("unsupported tag: '%s'"),
12104 dwarf_tag_name (die->tag));
12105 break;
12106 }
12107
12108 if (suppress_add)
12109 {
12110 sym->hash_next = objfile->template_symbols;
12111 objfile->template_symbols = sym;
12112 list_to_add = NULL;
12113 }
12114
12115 if (list_to_add != NULL)
12116 add_symbol_to_list (sym, list_to_add);
12117
12118 /* For the benefit of old versions of GCC, check for anonymous
12119 namespaces based on the demangled name. */
12120 if (!processing_has_namespace_info
12121 && cu->language == language_cplus)
12122 cp_scan_for_anonymous_namespaces (sym, objfile);
12123 }
12124 return (sym);
12125 }
12126
12127 /* A wrapper for new_symbol_full that always allocates a new symbol. */
12128
12129 static struct symbol *
12130 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
12131 {
12132 return new_symbol_full (die, type, cu, NULL);
12133 }
12134
12135 /* Given an attr with a DW_FORM_dataN value in host byte order,
12136 zero-extend it as appropriate for the symbol's type. The DWARF
12137 standard (v4) is not entirely clear about the meaning of using
12138 DW_FORM_dataN for a constant with a signed type, where the type is
12139 wider than the data. The conclusion of a discussion on the DWARF
12140 list was that this is unspecified. We choose to always zero-extend
12141 because that is the interpretation long in use by GCC. */
12142
12143 static gdb_byte *
12144 dwarf2_const_value_data (struct attribute *attr, struct type *type,
12145 const char *name, struct obstack *obstack,
12146 struct dwarf2_cu *cu, LONGEST *value, int bits)
12147 {
12148 struct objfile *objfile = cu->objfile;
12149 enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ?
12150 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
12151 LONGEST l = DW_UNSND (attr);
12152
12153 if (bits < sizeof (*value) * 8)
12154 {
12155 l &= ((LONGEST) 1 << bits) - 1;
12156 *value = l;
12157 }
12158 else if (bits == sizeof (*value) * 8)
12159 *value = l;
12160 else
12161 {
12162 gdb_byte *bytes = obstack_alloc (obstack, bits / 8);
12163 store_unsigned_integer (bytes, bits / 8, byte_order, l);
12164 return bytes;
12165 }
12166
12167 return NULL;
12168 }
12169
12170 /* Read a constant value from an attribute. Either set *VALUE, or if
12171 the value does not fit in *VALUE, set *BYTES - either already
12172 allocated on the objfile obstack, or newly allocated on OBSTACK,
12173 or, set *BATON, if we translated the constant to a location
12174 expression. */
12175
12176 static void
12177 dwarf2_const_value_attr (struct attribute *attr, struct type *type,
12178 const char *name, struct obstack *obstack,
12179 struct dwarf2_cu *cu,
12180 LONGEST *value, gdb_byte **bytes,
12181 struct dwarf2_locexpr_baton **baton)
12182 {
12183 struct objfile *objfile = cu->objfile;
12184 struct comp_unit_head *cu_header = &cu->header;
12185 struct dwarf_block *blk;
12186 enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ?
12187 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE);
12188
12189 *value = 0;
12190 *bytes = NULL;
12191 *baton = NULL;
12192
12193 switch (attr->form)
12194 {
12195 case DW_FORM_addr:
12196 {
12197 gdb_byte *data;
12198
12199 if (TYPE_LENGTH (type) != cu_header->addr_size)
12200 dwarf2_const_value_length_mismatch_complaint (name,
12201 cu_header->addr_size,
12202 TYPE_LENGTH (type));
12203 /* Symbols of this form are reasonably rare, so we just
12204 piggyback on the existing location code rather than writing
12205 a new implementation of symbol_computed_ops. */
12206 *baton = obstack_alloc (&objfile->objfile_obstack,
12207 sizeof (struct dwarf2_locexpr_baton));
12208 (*baton)->per_cu = cu->per_cu;
12209 gdb_assert ((*baton)->per_cu);
12210
12211 (*baton)->size = 2 + cu_header->addr_size;
12212 data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size);
12213 (*baton)->data = data;
12214
12215 data[0] = DW_OP_addr;
12216 store_unsigned_integer (&data[1], cu_header->addr_size,
12217 byte_order, DW_ADDR (attr));
12218 data[cu_header->addr_size + 1] = DW_OP_stack_value;
12219 }
12220 break;
12221 case DW_FORM_string:
12222 case DW_FORM_strp:
12223 /* DW_STRING is already allocated on the objfile obstack, point
12224 directly to it. */
12225 *bytes = (gdb_byte *) DW_STRING (attr);
12226 break;
12227 case DW_FORM_block1:
12228 case DW_FORM_block2:
12229 case DW_FORM_block4:
12230 case DW_FORM_block:
12231 case DW_FORM_exprloc:
12232 blk = DW_BLOCK (attr);
12233 if (TYPE_LENGTH (type) != blk->size)
12234 dwarf2_const_value_length_mismatch_complaint (name, blk->size,
12235 TYPE_LENGTH (type));
12236 *bytes = blk->data;
12237 break;
12238
12239 /* The DW_AT_const_value attributes are supposed to carry the
12240 symbol's value "represented as it would be on the target
12241 architecture." By the time we get here, it's already been
12242 converted to host endianness, so we just need to sign- or
12243 zero-extend it as appropriate. */
12244 case DW_FORM_data1:
12245 *bytes = dwarf2_const_value_data (attr, type, name,
12246 obstack, cu, value, 8);
12247 break;
12248 case DW_FORM_data2:
12249 *bytes = dwarf2_const_value_data (attr, type, name,
12250 obstack, cu, value, 16);
12251 break;
12252 case DW_FORM_data4:
12253 *bytes = dwarf2_const_value_data (attr, type, name,
12254 obstack, cu, value, 32);
12255 break;
12256 case DW_FORM_data8:
12257 *bytes = dwarf2_const_value_data (attr, type, name,
12258 obstack, cu, value, 64);
12259 break;
12260
12261 case DW_FORM_sdata:
12262 *value = DW_SND (attr);
12263 break;
12264
12265 case DW_FORM_udata:
12266 *value = DW_UNSND (attr);
12267 break;
12268
12269 default:
12270 complaint (&symfile_complaints,
12271 _("unsupported const value attribute form: '%s'"),
12272 dwarf_form_name (attr->form));
12273 *value = 0;
12274 break;
12275 }
12276 }
12277
12278
12279 /* Copy constant value from an attribute to a symbol. */
12280
12281 static void
12282 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
12283 struct dwarf2_cu *cu)
12284 {
12285 struct objfile *objfile = cu->objfile;
12286 struct comp_unit_head *cu_header = &cu->header;
12287 LONGEST value;
12288 gdb_byte *bytes;
12289 struct dwarf2_locexpr_baton *baton;
12290
12291 dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym),
12292 SYMBOL_PRINT_NAME (sym),
12293 &objfile->objfile_obstack, cu,
12294 &value, &bytes, &baton);
12295
12296 if (baton != NULL)
12297 {
12298 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
12299 SYMBOL_LOCATION_BATON (sym) = baton;
12300 SYMBOL_CLASS (sym) = LOC_COMPUTED;
12301 }
12302 else if (bytes != NULL)
12303 {
12304 SYMBOL_VALUE_BYTES (sym) = bytes;
12305 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
12306 }
12307 else
12308 {
12309 SYMBOL_VALUE (sym) = value;
12310 SYMBOL_CLASS (sym) = LOC_CONST;
12311 }
12312 }
12313
12314 /* Return the type of the die in question using its DW_AT_type attribute. */
12315
12316 static struct type *
12317 die_type (struct die_info *die, struct dwarf2_cu *cu)
12318 {
12319 struct attribute *type_attr;
12320
12321 type_attr = dwarf2_attr (die, DW_AT_type, cu);
12322 if (!type_attr)
12323 {
12324 /* A missing DW_AT_type represents a void type. */
12325 return objfile_type (cu->objfile)->builtin_void;
12326 }
12327
12328 return lookup_die_type (die, type_attr, cu);
12329 }
12330
12331 /* True iff CU's producer generates GNAT Ada auxiliary information
12332 that allows to find parallel types through that information instead
12333 of having to do expensive parallel lookups by type name. */
12334
12335 static int
12336 need_gnat_info (struct dwarf2_cu *cu)
12337 {
12338 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
12339 of GNAT produces this auxiliary information, without any indication
12340 that it is produced. Part of enhancing the FSF version of GNAT
12341 to produce that information will be to put in place an indicator
12342 that we can use in order to determine whether the descriptive type
12343 info is available or not. One suggestion that has been made is
12344 to use a new attribute, attached to the CU die. For now, assume
12345 that the descriptive type info is not available. */
12346 return 0;
12347 }
12348
12349 /* Return the auxiliary type of the die in question using its
12350 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
12351 attribute is not present. */
12352
12353 static struct type *
12354 die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu)
12355 {
12356 struct attribute *type_attr;
12357
12358 type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu);
12359 if (!type_attr)
12360 return NULL;
12361
12362 return lookup_die_type (die, type_attr, cu);
12363 }
12364
12365 /* If DIE has a descriptive_type attribute, then set the TYPE's
12366 descriptive type accordingly. */
12367
12368 static void
12369 set_descriptive_type (struct type *type, struct die_info *die,
12370 struct dwarf2_cu *cu)
12371 {
12372 struct type *descriptive_type = die_descriptive_type (die, cu);
12373
12374 if (descriptive_type)
12375 {
12376 ALLOCATE_GNAT_AUX_TYPE (type);
12377 TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type;
12378 }
12379 }
12380
12381 /* Return the containing type of the die in question using its
12382 DW_AT_containing_type attribute. */
12383
12384 static struct type *
12385 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
12386 {
12387 struct attribute *type_attr;
12388
12389 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
12390 if (!type_attr)
12391 error (_("Dwarf Error: Problem turning containing type into gdb type "
12392 "[in module %s]"), cu->objfile->name);
12393
12394 return lookup_die_type (die, type_attr, cu);
12395 }
12396
12397 /* Look up the type of DIE in CU using its type attribute ATTR.
12398 If there is no type substitute an error marker. */
12399
12400 static struct type *
12401 lookup_die_type (struct die_info *die, struct attribute *attr,
12402 struct dwarf2_cu *cu)
12403 {
12404 struct objfile *objfile = cu->objfile;
12405 struct type *this_type;
12406
12407 /* First see if we have it cached. */
12408
12409 if (is_ref_attr (attr))
12410 {
12411 sect_offset offset = dwarf2_get_ref_die_offset (attr);
12412
12413 this_type = get_die_type_at_offset (offset, cu->per_cu);
12414 }
12415 else if (attr->form == DW_FORM_ref_sig8)
12416 {
12417 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
12418 struct dwarf2_cu *sig_cu;
12419 sect_offset offset;
12420
12421 /* sig_type will be NULL if the signatured type is missing from
12422 the debug info. */
12423 if (sig_type == NULL)
12424 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12425 "at 0x%x [in module %s]"),
12426 die->offset.sect_off, objfile->name);
12427
12428 gdb_assert (sig_type->per_cu.debug_types_section);
12429 offset.sect_off = (sig_type->per_cu.offset.sect_off
12430 + sig_type->type_offset.cu_off);
12431 this_type = get_die_type_at_offset (offset, &sig_type->per_cu);
12432 }
12433 else
12434 {
12435 dump_die_for_error (die);
12436 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
12437 dwarf_attr_name (attr->name), objfile->name);
12438 }
12439
12440 /* If not cached we need to read it in. */
12441
12442 if (this_type == NULL)
12443 {
12444 struct die_info *type_die;
12445 struct dwarf2_cu *type_cu = cu;
12446
12447 type_die = follow_die_ref_or_sig (die, attr, &type_cu);
12448 /* If the type is cached, we should have found it above. */
12449 gdb_assert (get_die_type (type_die, type_cu) == NULL);
12450 this_type = read_type_die_1 (type_die, type_cu);
12451 }
12452
12453 /* If we still don't have a type use an error marker. */
12454
12455 if (this_type == NULL)
12456 {
12457 char *message, *saved;
12458
12459 /* read_type_die already issued a complaint. */
12460 message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
12461 objfile->name,
12462 cu->header.offset.sect_off,
12463 die->offset.sect_off);
12464 saved = obstack_copy0 (&objfile->objfile_obstack,
12465 message, strlen (message));
12466 xfree (message);
12467
12468 this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, objfile);
12469 }
12470
12471 return this_type;
12472 }
12473
12474 /* Return the type in DIE, CU.
12475 Returns NULL for invalid types.
12476
12477 This first does a lookup in the appropriate type_hash table,
12478 and only reads the die in if necessary.
12479
12480 NOTE: This can be called when reading in partial or full symbols. */
12481
12482 static struct type *
12483 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
12484 {
12485 struct type *this_type;
12486
12487 this_type = get_die_type (die, cu);
12488 if (this_type)
12489 return this_type;
12490
12491 return read_type_die_1 (die, cu);
12492 }
12493
12494 /* Read the type in DIE, CU.
12495 Returns NULL for invalid types. */
12496
12497 static struct type *
12498 read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu)
12499 {
12500 struct type *this_type = NULL;
12501
12502 switch (die->tag)
12503 {
12504 case DW_TAG_class_type:
12505 case DW_TAG_interface_type:
12506 case DW_TAG_structure_type:
12507 case DW_TAG_union_type:
12508 this_type = read_structure_type (die, cu);
12509 break;
12510 case DW_TAG_enumeration_type:
12511 this_type = read_enumeration_type (die, cu);
12512 break;
12513 case DW_TAG_subprogram:
12514 case DW_TAG_subroutine_type:
12515 case DW_TAG_inlined_subroutine:
12516 this_type = read_subroutine_type (die, cu);
12517 break;
12518 case DW_TAG_array_type:
12519 this_type = read_array_type (die, cu);
12520 break;
12521 case DW_TAG_set_type:
12522 this_type = read_set_type (die, cu);
12523 break;
12524 case DW_TAG_pointer_type:
12525 this_type = read_tag_pointer_type (die, cu);
12526 break;
12527 case DW_TAG_ptr_to_member_type:
12528 this_type = read_tag_ptr_to_member_type (die, cu);
12529 break;
12530 case DW_TAG_reference_type:
12531 this_type = read_tag_reference_type (die, cu);
12532 break;
12533 case DW_TAG_const_type:
12534 this_type = read_tag_const_type (die, cu);
12535 break;
12536 case DW_TAG_volatile_type:
12537 this_type = read_tag_volatile_type (die, cu);
12538 break;
12539 case DW_TAG_string_type:
12540 this_type = read_tag_string_type (die, cu);
12541 break;
12542 case DW_TAG_typedef:
12543 this_type = read_typedef (die, cu);
12544 break;
12545 case DW_TAG_subrange_type:
12546 this_type = read_subrange_type (die, cu);
12547 break;
12548 case DW_TAG_base_type:
12549 this_type = read_base_type (die, cu);
12550 break;
12551 case DW_TAG_unspecified_type:
12552 this_type = read_unspecified_type (die, cu);
12553 break;
12554 case DW_TAG_namespace:
12555 this_type = read_namespace_type (die, cu);
12556 break;
12557 case DW_TAG_module:
12558 this_type = read_module_type (die, cu);
12559 break;
12560 default:
12561 complaint (&symfile_complaints,
12562 _("unexpected tag in read_type_die: '%s'"),
12563 dwarf_tag_name (die->tag));
12564 break;
12565 }
12566
12567 return this_type;
12568 }
12569
12570 /* See if we can figure out if the class lives in a namespace. We do
12571 this by looking for a member function; its demangled name will
12572 contain namespace info, if there is any.
12573 Return the computed name or NULL.
12574 Space for the result is allocated on the objfile's obstack.
12575 This is the full-die version of guess_partial_die_structure_name.
12576 In this case we know DIE has no useful parent. */
12577
12578 static char *
12579 guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu)
12580 {
12581 struct die_info *spec_die;
12582 struct dwarf2_cu *spec_cu;
12583 struct die_info *child;
12584
12585 spec_cu = cu;
12586 spec_die = die_specification (die, &spec_cu);
12587 if (spec_die != NULL)
12588 {
12589 die = spec_die;
12590 cu = spec_cu;
12591 }
12592
12593 for (child = die->child;
12594 child != NULL;
12595 child = child->sibling)
12596 {
12597 if (child->tag == DW_TAG_subprogram)
12598 {
12599 struct attribute *attr;
12600
12601 attr = dwarf2_attr (child, DW_AT_linkage_name, cu);
12602 if (attr == NULL)
12603 attr = dwarf2_attr (child, DW_AT_MIPS_linkage_name, cu);
12604 if (attr != NULL)
12605 {
12606 char *actual_name
12607 = language_class_name_from_physname (cu->language_defn,
12608 DW_STRING (attr));
12609 char *name = NULL;
12610
12611 if (actual_name != NULL)
12612 {
12613 char *die_name = dwarf2_name (die, cu);
12614
12615 if (die_name != NULL
12616 && strcmp (die_name, actual_name) != 0)
12617 {
12618 /* Strip off the class name from the full name.
12619 We want the prefix. */
12620 int die_name_len = strlen (die_name);
12621 int actual_name_len = strlen (actual_name);
12622
12623 /* Test for '::' as a sanity check. */
12624 if (actual_name_len > die_name_len + 2
12625 && actual_name[actual_name_len
12626 - die_name_len - 1] == ':')
12627 name =
12628 obsavestring (actual_name,
12629 actual_name_len - die_name_len - 2,
12630 &cu->objfile->objfile_obstack);
12631 }
12632 }
12633 xfree (actual_name);
12634 return name;
12635 }
12636 }
12637 }
12638
12639 return NULL;
12640 }
12641
12642 /* GCC might emit a nameless typedef that has a linkage name. Determine the
12643 prefix part in such case. See
12644 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12645
12646 static char *
12647 anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu)
12648 {
12649 struct attribute *attr;
12650 char *base;
12651
12652 if (die->tag != DW_TAG_class_type && die->tag != DW_TAG_interface_type
12653 && die->tag != DW_TAG_structure_type && die->tag != DW_TAG_union_type)
12654 return NULL;
12655
12656 attr = dwarf2_attr (die, DW_AT_name, cu);
12657 if (attr != NULL && DW_STRING (attr) != NULL)
12658 return NULL;
12659
12660 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
12661 if (attr == NULL)
12662 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
12663 if (attr == NULL || DW_STRING (attr) == NULL)
12664 return NULL;
12665
12666 /* dwarf2_name had to be already called. */
12667 gdb_assert (DW_STRING_IS_CANONICAL (attr));
12668
12669 /* Strip the base name, keep any leading namespaces/classes. */
12670 base = strrchr (DW_STRING (attr), ':');
12671 if (base == NULL || base == DW_STRING (attr) || base[-1] != ':')
12672 return "";
12673
12674 return obsavestring (DW_STRING (attr), &base[-1] - DW_STRING (attr),
12675 &cu->objfile->objfile_obstack);
12676 }
12677
12678 /* Return the name of the namespace/class that DIE is defined within,
12679 or "" if we can't tell. The caller should not xfree the result.
12680
12681 For example, if we're within the method foo() in the following
12682 code:
12683
12684 namespace N {
12685 class C {
12686 void foo () {
12687 }
12688 };
12689 }
12690
12691 then determine_prefix on foo's die will return "N::C". */
12692
12693 static const char *
12694 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
12695 {
12696 struct die_info *parent, *spec_die;
12697 struct dwarf2_cu *spec_cu;
12698 struct type *parent_type;
12699 char *retval;
12700
12701 if (cu->language != language_cplus && cu->language != language_java
12702 && cu->language != language_fortran)
12703 return "";
12704
12705 retval = anonymous_struct_prefix (die, cu);
12706 if (retval)
12707 return retval;
12708
12709 /* We have to be careful in the presence of DW_AT_specification.
12710 For example, with GCC 3.4, given the code
12711
12712 namespace N {
12713 void foo() {
12714 // Definition of N::foo.
12715 }
12716 }
12717
12718 then we'll have a tree of DIEs like this:
12719
12720 1: DW_TAG_compile_unit
12721 2: DW_TAG_namespace // N
12722 3: DW_TAG_subprogram // declaration of N::foo
12723 4: DW_TAG_subprogram // definition of N::foo
12724 DW_AT_specification // refers to die #3
12725
12726 Thus, when processing die #4, we have to pretend that we're in
12727 the context of its DW_AT_specification, namely the contex of die
12728 #3. */
12729 spec_cu = cu;
12730 spec_die = die_specification (die, &spec_cu);
12731 if (spec_die == NULL)
12732 parent = die->parent;
12733 else
12734 {
12735 parent = spec_die->parent;
12736 cu = spec_cu;
12737 }
12738
12739 if (parent == NULL)
12740 return "";
12741 else if (parent->building_fullname)
12742 {
12743 const char *name;
12744 const char *parent_name;
12745
12746 /* It has been seen on RealView 2.2 built binaries,
12747 DW_TAG_template_type_param types actually _defined_ as
12748 children of the parent class:
12749
12750 enum E {};
12751 template class <class Enum> Class{};
12752 Class<enum E> class_e;
12753
12754 1: DW_TAG_class_type (Class)
12755 2: DW_TAG_enumeration_type (E)
12756 3: DW_TAG_enumerator (enum1:0)
12757 3: DW_TAG_enumerator (enum2:1)
12758 ...
12759 2: DW_TAG_template_type_param
12760 DW_AT_type DW_FORM_ref_udata (E)
12761
12762 Besides being broken debug info, it can put GDB into an
12763 infinite loop. Consider:
12764
12765 When we're building the full name for Class<E>, we'll start
12766 at Class, and go look over its template type parameters,
12767 finding E. We'll then try to build the full name of E, and
12768 reach here. We're now trying to build the full name of E,
12769 and look over the parent DIE for containing scope. In the
12770 broken case, if we followed the parent DIE of E, we'd again
12771 find Class, and once again go look at its template type
12772 arguments, etc., etc. Simply don't consider such parent die
12773 as source-level parent of this die (it can't be, the language
12774 doesn't allow it), and break the loop here. */
12775 name = dwarf2_name (die, cu);
12776 parent_name = dwarf2_name (parent, cu);
12777 complaint (&symfile_complaints,
12778 _("template param type '%s' defined within parent '%s'"),
12779 name ? name : "<unknown>",
12780 parent_name ? parent_name : "<unknown>");
12781 return "";
12782 }
12783 else
12784 switch (parent->tag)
12785 {
12786 case DW_TAG_namespace:
12787 parent_type = read_type_die (parent, cu);
12788 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12789 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12790 Work around this problem here. */
12791 if (cu->language == language_cplus
12792 && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0)
12793 return "";
12794 /* We give a name to even anonymous namespaces. */
12795 return TYPE_TAG_NAME (parent_type);
12796 case DW_TAG_class_type:
12797 case DW_TAG_interface_type:
12798 case DW_TAG_structure_type:
12799 case DW_TAG_union_type:
12800 case DW_TAG_module:
12801 parent_type = read_type_die (parent, cu);
12802 if (TYPE_TAG_NAME (parent_type) != NULL)
12803 return TYPE_TAG_NAME (parent_type);
12804 else
12805 /* An anonymous structure is only allowed non-static data
12806 members; no typedefs, no member functions, et cetera.
12807 So it does not need a prefix. */
12808 return "";
12809 case DW_TAG_compile_unit:
12810 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12811 if (cu->language == language_cplus
12812 && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)
12813 && die->child != NULL
12814 && (die->tag == DW_TAG_class_type
12815 || die->tag == DW_TAG_structure_type
12816 || die->tag == DW_TAG_union_type))
12817 {
12818 char *name = guess_full_die_structure_name (die, cu);
12819 if (name != NULL)
12820 return name;
12821 }
12822 return "";
12823 default:
12824 return determine_prefix (parent, cu);
12825 }
12826 }
12827
12828 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12829 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12830 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12831 an obconcat, otherwise allocate storage for the result. The CU argument is
12832 used to determine the language and hence, the appropriate separator. */
12833
12834 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12835
12836 static char *
12837 typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
12838 int physname, struct dwarf2_cu *cu)
12839 {
12840 const char *lead = "";
12841 const char *sep;
12842
12843 if (suffix == NULL || suffix[0] == '\0'
12844 || prefix == NULL || prefix[0] == '\0')
12845 sep = "";
12846 else if (cu->language == language_java)
12847 sep = ".";
12848 else if (cu->language == language_fortran && physname)
12849 {
12850 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12851 DW_AT_MIPS_linkage_name is preferred and used instead. */
12852
12853 lead = "__";
12854 sep = "_MOD_";
12855 }
12856 else
12857 sep = "::";
12858
12859 if (prefix == NULL)
12860 prefix = "";
12861 if (suffix == NULL)
12862 suffix = "";
12863
12864 if (obs == NULL)
12865 {
12866 char *retval
12867 = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
12868
12869 strcpy (retval, lead);
12870 strcat (retval, prefix);
12871 strcat (retval, sep);
12872 strcat (retval, suffix);
12873 return retval;
12874 }
12875 else
12876 {
12877 /* We have an obstack. */
12878 return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL);
12879 }
12880 }
12881
12882 /* Return sibling of die, NULL if no sibling. */
12883
12884 static struct die_info *
12885 sibling_die (struct die_info *die)
12886 {
12887 return die->sibling;
12888 }
12889
12890 /* Get name of a die, return NULL if not found. */
12891
12892 static char *
12893 dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu,
12894 struct obstack *obstack)
12895 {
12896 if (name && cu->language == language_cplus)
12897 {
12898 char *canon_name = cp_canonicalize_string (name);
12899
12900 if (canon_name != NULL)
12901 {
12902 if (strcmp (canon_name, name) != 0)
12903 name = obsavestring (canon_name, strlen (canon_name),
12904 obstack);
12905 xfree (canon_name);
12906 }
12907 }
12908
12909 return name;
12910 }
12911
12912 /* Get name of a die, return NULL if not found. */
12913
12914 static char *
12915 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
12916 {
12917 struct attribute *attr;
12918
12919 attr = dwarf2_attr (die, DW_AT_name, cu);
12920 if ((!attr || !DW_STRING (attr))
12921 && die->tag != DW_TAG_class_type
12922 && die->tag != DW_TAG_interface_type
12923 && die->tag != DW_TAG_structure_type
12924 && die->tag != DW_TAG_union_type)
12925 return NULL;
12926
12927 switch (die->tag)
12928 {
12929 case DW_TAG_compile_unit:
12930 /* Compilation units have a DW_AT_name that is a filename, not
12931 a source language identifier. */
12932 case DW_TAG_enumeration_type:
12933 case DW_TAG_enumerator:
12934 /* These tags always have simple identifiers already; no need
12935 to canonicalize them. */
12936 return DW_STRING (attr);
12937
12938 case DW_TAG_subprogram:
12939 /* Java constructors will all be named "<init>", so return
12940 the class name when we see this special case. */
12941 if (cu->language == language_java
12942 && DW_STRING (attr) != NULL
12943 && strcmp (DW_STRING (attr), "<init>") == 0)
12944 {
12945 struct dwarf2_cu *spec_cu = cu;
12946 struct die_info *spec_die;
12947
12948 /* GCJ will output '<init>' for Java constructor names.
12949 For this special case, return the name of the parent class. */
12950
12951 /* GCJ may output suprogram DIEs with AT_specification set.
12952 If so, use the name of the specified DIE. */
12953 spec_die = die_specification (die, &spec_cu);
12954 if (spec_die != NULL)
12955 return dwarf2_name (spec_die, spec_cu);
12956
12957 do
12958 {
12959 die = die->parent;
12960 if (die->tag == DW_TAG_class_type)
12961 return dwarf2_name (die, cu);
12962 }
12963 while (die->tag != DW_TAG_compile_unit);
12964 }
12965 break;
12966
12967 case DW_TAG_class_type:
12968 case DW_TAG_interface_type:
12969 case DW_TAG_structure_type:
12970 case DW_TAG_union_type:
12971 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12972 structures or unions. These were of the form "._%d" in GCC 4.1,
12973 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12974 and GCC 4.4. We work around this problem by ignoring these. */
12975 if (attr && DW_STRING (attr)
12976 && (strncmp (DW_STRING (attr), "._", 2) == 0
12977 || strncmp (DW_STRING (attr), "<anonymous", 10) == 0))
12978 return NULL;
12979
12980 /* GCC might emit a nameless typedef that has a linkage name. See
12981 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12982 if (!attr || DW_STRING (attr) == NULL)
12983 {
12984 char *demangled = NULL;
12985
12986 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
12987 if (attr == NULL)
12988 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
12989
12990 if (attr == NULL || DW_STRING (attr) == NULL)
12991 return NULL;
12992
12993 /* Avoid demangling DW_STRING (attr) the second time on a second
12994 call for the same DIE. */
12995 if (!DW_STRING_IS_CANONICAL (attr))
12996 demangled = cplus_demangle (DW_STRING (attr), DMGL_TYPES);
12997
12998 if (demangled)
12999 {
13000 char *base;
13001
13002 /* FIXME: we already did this for the partial symbol... */
13003 DW_STRING (attr) = obsavestring (demangled, strlen (demangled),
13004 &cu->objfile->objfile_obstack);
13005 DW_STRING_IS_CANONICAL (attr) = 1;
13006 xfree (demangled);
13007
13008 /* Strip any leading namespaces/classes, keep only the base name.
13009 DW_AT_name for named DIEs does not contain the prefixes. */
13010 base = strrchr (DW_STRING (attr), ':');
13011 if (base && base > DW_STRING (attr) && base[-1] == ':')
13012 return &base[1];
13013 else
13014 return DW_STRING (attr);
13015 }
13016 }
13017 break;
13018
13019 default:
13020 break;
13021 }
13022
13023 if (!DW_STRING_IS_CANONICAL (attr))
13024 {
13025 DW_STRING (attr)
13026 = dwarf2_canonicalize_name (DW_STRING (attr), cu,
13027 &cu->objfile->objfile_obstack);
13028 DW_STRING_IS_CANONICAL (attr) = 1;
13029 }
13030 return DW_STRING (attr);
13031 }
13032
13033 /* Return the die that this die in an extension of, or NULL if there
13034 is none. *EXT_CU is the CU containing DIE on input, and the CU
13035 containing the return value on output. */
13036
13037 static struct die_info *
13038 dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu)
13039 {
13040 struct attribute *attr;
13041
13042 attr = dwarf2_attr (die, DW_AT_extension, *ext_cu);
13043 if (attr == NULL)
13044 return NULL;
13045
13046 return follow_die_ref (die, attr, ext_cu);
13047 }
13048
13049 /* Convert a DIE tag into its string name. */
13050
13051 static char *
13052 dwarf_tag_name (unsigned tag)
13053 {
13054 switch (tag)
13055 {
13056 case DW_TAG_padding:
13057 return "DW_TAG_padding";
13058 case DW_TAG_array_type:
13059 return "DW_TAG_array_type";
13060 case DW_TAG_class_type:
13061 return "DW_TAG_class_type";
13062 case DW_TAG_entry_point:
13063 return "DW_TAG_entry_point";
13064 case DW_TAG_enumeration_type:
13065 return "DW_TAG_enumeration_type";
13066 case DW_TAG_formal_parameter:
13067 return "DW_TAG_formal_parameter";
13068 case DW_TAG_imported_declaration:
13069 return "DW_TAG_imported_declaration";
13070 case DW_TAG_label:
13071 return "DW_TAG_label";
13072 case DW_TAG_lexical_block:
13073 return "DW_TAG_lexical_block";
13074 case DW_TAG_member:
13075 return "DW_TAG_member";
13076 case DW_TAG_pointer_type:
13077 return "DW_TAG_pointer_type";
13078 case DW_TAG_reference_type:
13079 return "DW_TAG_reference_type";
13080 case DW_TAG_compile_unit:
13081 return "DW_TAG_compile_unit";
13082 case DW_TAG_string_type:
13083 return "DW_TAG_string_type";
13084 case DW_TAG_structure_type:
13085 return "DW_TAG_structure_type";
13086 case DW_TAG_subroutine_type:
13087 return "DW_TAG_subroutine_type";
13088 case DW_TAG_typedef:
13089 return "DW_TAG_typedef";
13090 case DW_TAG_union_type:
13091 return "DW_TAG_union_type";
13092 case DW_TAG_unspecified_parameters:
13093 return "DW_TAG_unspecified_parameters";
13094 case DW_TAG_variant:
13095 return "DW_TAG_variant";
13096 case DW_TAG_common_block:
13097 return "DW_TAG_common_block";
13098 case DW_TAG_common_inclusion:
13099 return "DW_TAG_common_inclusion";
13100 case DW_TAG_inheritance:
13101 return "DW_TAG_inheritance";
13102 case DW_TAG_inlined_subroutine:
13103 return "DW_TAG_inlined_subroutine";
13104 case DW_TAG_module:
13105 return "DW_TAG_module";
13106 case DW_TAG_ptr_to_member_type:
13107 return "DW_TAG_ptr_to_member_type";
13108 case DW_TAG_set_type:
13109 return "DW_TAG_set_type";
13110 case DW_TAG_subrange_type:
13111 return "DW_TAG_subrange_type";
13112 case DW_TAG_with_stmt:
13113 return "DW_TAG_with_stmt";
13114 case DW_TAG_access_declaration:
13115 return "DW_TAG_access_declaration";
13116 case DW_TAG_base_type:
13117 return "DW_TAG_base_type";
13118 case DW_TAG_catch_block:
13119 return "DW_TAG_catch_block";
13120 case DW_TAG_const_type:
13121 return "DW_TAG_const_type";
13122 case DW_TAG_constant:
13123 return "DW_TAG_constant";
13124 case DW_TAG_enumerator:
13125 return "DW_TAG_enumerator";
13126 case DW_TAG_file_type:
13127 return "DW_TAG_file_type";
13128 case DW_TAG_friend:
13129 return "DW_TAG_friend";
13130 case DW_TAG_namelist:
13131 return "DW_TAG_namelist";
13132 case DW_TAG_namelist_item:
13133 return "DW_TAG_namelist_item";
13134 case DW_TAG_packed_type:
13135 return "DW_TAG_packed_type";
13136 case DW_TAG_subprogram:
13137 return "DW_TAG_subprogram";
13138 case DW_TAG_template_type_param:
13139 return "DW_TAG_template_type_param";
13140 case DW_TAG_template_value_param:
13141 return "DW_TAG_template_value_param";
13142 case DW_TAG_thrown_type:
13143 return "DW_TAG_thrown_type";
13144 case DW_TAG_try_block:
13145 return "DW_TAG_try_block";
13146 case DW_TAG_variant_part:
13147 return "DW_TAG_variant_part";
13148 case DW_TAG_variable:
13149 return "DW_TAG_variable";
13150 case DW_TAG_volatile_type:
13151 return "DW_TAG_volatile_type";
13152 case DW_TAG_dwarf_procedure:
13153 return "DW_TAG_dwarf_procedure";
13154 case DW_TAG_restrict_type:
13155 return "DW_TAG_restrict_type";
13156 case DW_TAG_interface_type:
13157 return "DW_TAG_interface_type";
13158 case DW_TAG_namespace:
13159 return "DW_TAG_namespace";
13160 case DW_TAG_imported_module:
13161 return "DW_TAG_imported_module";
13162 case DW_TAG_unspecified_type:
13163 return "DW_TAG_unspecified_type";
13164 case DW_TAG_partial_unit:
13165 return "DW_TAG_partial_unit";
13166 case DW_TAG_imported_unit:
13167 return "DW_TAG_imported_unit";
13168 case DW_TAG_condition:
13169 return "DW_TAG_condition";
13170 case DW_TAG_shared_type:
13171 return "DW_TAG_shared_type";
13172 case DW_TAG_type_unit:
13173 return "DW_TAG_type_unit";
13174 case DW_TAG_MIPS_loop:
13175 return "DW_TAG_MIPS_loop";
13176 case DW_TAG_HP_array_descriptor:
13177 return "DW_TAG_HP_array_descriptor";
13178 case DW_TAG_format_label:
13179 return "DW_TAG_format_label";
13180 case DW_TAG_function_template:
13181 return "DW_TAG_function_template";
13182 case DW_TAG_class_template:
13183 return "DW_TAG_class_template";
13184 case DW_TAG_GNU_BINCL:
13185 return "DW_TAG_GNU_BINCL";
13186 case DW_TAG_GNU_EINCL:
13187 return "DW_TAG_GNU_EINCL";
13188 case DW_TAG_upc_shared_type:
13189 return "DW_TAG_upc_shared_type";
13190 case DW_TAG_upc_strict_type:
13191 return "DW_TAG_upc_strict_type";
13192 case DW_TAG_upc_relaxed_type:
13193 return "DW_TAG_upc_relaxed_type";
13194 case DW_TAG_PGI_kanji_type:
13195 return "DW_TAG_PGI_kanji_type";
13196 case DW_TAG_PGI_interface_block:
13197 return "DW_TAG_PGI_interface_block";
13198 case DW_TAG_GNU_call_site:
13199 return "DW_TAG_GNU_call_site";
13200 default:
13201 return "DW_TAG_<unknown>";
13202 }
13203 }
13204
13205 /* Convert a DWARF attribute code into its string name. */
13206
13207 static char *
13208 dwarf_attr_name (unsigned attr)
13209 {
13210 switch (attr)
13211 {
13212 case DW_AT_sibling:
13213 return "DW_AT_sibling";
13214 case DW_AT_location:
13215 return "DW_AT_location";
13216 case DW_AT_name:
13217 return "DW_AT_name";
13218 case DW_AT_ordering:
13219 return "DW_AT_ordering";
13220 case DW_AT_subscr_data:
13221 return "DW_AT_subscr_data";
13222 case DW_AT_byte_size:
13223 return "DW_AT_byte_size";
13224 case DW_AT_bit_offset:
13225 return "DW_AT_bit_offset";
13226 case DW_AT_bit_size:
13227 return "DW_AT_bit_size";
13228 case DW_AT_element_list:
13229 return "DW_AT_element_list";
13230 case DW_AT_stmt_list:
13231 return "DW_AT_stmt_list";
13232 case DW_AT_low_pc:
13233 return "DW_AT_low_pc";
13234 case DW_AT_high_pc:
13235 return "DW_AT_high_pc";
13236 case DW_AT_language:
13237 return "DW_AT_language";
13238 case DW_AT_member:
13239 return "DW_AT_member";
13240 case DW_AT_discr:
13241 return "DW_AT_discr";
13242 case DW_AT_discr_value:
13243 return "DW_AT_discr_value";
13244 case DW_AT_visibility:
13245 return "DW_AT_visibility";
13246 case DW_AT_import:
13247 return "DW_AT_import";
13248 case DW_AT_string_length:
13249 return "DW_AT_string_length";
13250 case DW_AT_common_reference:
13251 return "DW_AT_common_reference";
13252 case DW_AT_comp_dir:
13253 return "DW_AT_comp_dir";
13254 case DW_AT_const_value:
13255 return "DW_AT_const_value";
13256 case DW_AT_containing_type:
13257 return "DW_AT_containing_type";
13258 case DW_AT_default_value:
13259 return "DW_AT_default_value";
13260 case DW_AT_inline:
13261 return "DW_AT_inline";
13262 case DW_AT_is_optional:
13263 return "DW_AT_is_optional";
13264 case DW_AT_lower_bound:
13265 return "DW_AT_lower_bound";
13266 case DW_AT_producer:
13267 return "DW_AT_producer";
13268 case DW_AT_prototyped:
13269 return "DW_AT_prototyped";
13270 case DW_AT_return_addr:
13271 return "DW_AT_return_addr";
13272 case DW_AT_start_scope:
13273 return "DW_AT_start_scope";
13274 case DW_AT_bit_stride:
13275 return "DW_AT_bit_stride";
13276 case DW_AT_upper_bound:
13277 return "DW_AT_upper_bound";
13278 case DW_AT_abstract_origin:
13279 return "DW_AT_abstract_origin";
13280 case DW_AT_accessibility:
13281 return "DW_AT_accessibility";
13282 case DW_AT_address_class:
13283 return "DW_AT_address_class";
13284 case DW_AT_artificial:
13285 return "DW_AT_artificial";
13286 case DW_AT_base_types:
13287 return "DW_AT_base_types";
13288 case DW_AT_calling_convention:
13289 return "DW_AT_calling_convention";
13290 case DW_AT_count:
13291 return "DW_AT_count";
13292 case DW_AT_data_member_location:
13293 return "DW_AT_data_member_location";
13294 case DW_AT_decl_column:
13295 return "DW_AT_decl_column";
13296 case DW_AT_decl_file:
13297 return "DW_AT_decl_file";
13298 case DW_AT_decl_line:
13299 return "DW_AT_decl_line";
13300 case DW_AT_declaration:
13301 return "DW_AT_declaration";
13302 case DW_AT_discr_list:
13303 return "DW_AT_discr_list";
13304 case DW_AT_encoding:
13305 return "DW_AT_encoding";
13306 case DW_AT_external:
13307 return "DW_AT_external";
13308 case DW_AT_frame_base:
13309 return "DW_AT_frame_base";
13310 case DW_AT_friend:
13311 return "DW_AT_friend";
13312 case DW_AT_identifier_case:
13313 return "DW_AT_identifier_case";
13314 case DW_AT_macro_info:
13315 return "DW_AT_macro_info";
13316 case DW_AT_namelist_items:
13317 return "DW_AT_namelist_items";
13318 case DW_AT_priority:
13319 return "DW_AT_priority";
13320 case DW_AT_segment:
13321 return "DW_AT_segment";
13322 case DW_AT_specification:
13323 return "DW_AT_specification";
13324 case DW_AT_static_link:
13325 return "DW_AT_static_link";
13326 case DW_AT_type:
13327 return "DW_AT_type";
13328 case DW_AT_use_location:
13329 return "DW_AT_use_location";
13330 case DW_AT_variable_parameter:
13331 return "DW_AT_variable_parameter";
13332 case DW_AT_virtuality:
13333 return "DW_AT_virtuality";
13334 case DW_AT_vtable_elem_location:
13335 return "DW_AT_vtable_elem_location";
13336 /* DWARF 3 values. */
13337 case DW_AT_allocated:
13338 return "DW_AT_allocated";
13339 case DW_AT_associated:
13340 return "DW_AT_associated";
13341 case DW_AT_data_location:
13342 return "DW_AT_data_location";
13343 case DW_AT_byte_stride:
13344 return "DW_AT_byte_stride";
13345 case DW_AT_entry_pc:
13346 return "DW_AT_entry_pc";
13347 case DW_AT_use_UTF8:
13348 return "DW_AT_use_UTF8";
13349 case DW_AT_extension:
13350 return "DW_AT_extension";
13351 case DW_AT_ranges:
13352 return "DW_AT_ranges";
13353 case DW_AT_trampoline:
13354 return "DW_AT_trampoline";
13355 case DW_AT_call_column:
13356 return "DW_AT_call_column";
13357 case DW_AT_call_file:
13358 return "DW_AT_call_file";
13359 case DW_AT_call_line:
13360 return "DW_AT_call_line";
13361 case DW_AT_description:
13362 return "DW_AT_description";
13363 case DW_AT_binary_scale:
13364 return "DW_AT_binary_scale";
13365 case DW_AT_decimal_scale:
13366 return "DW_AT_decimal_scale";
13367 case DW_AT_small:
13368 return "DW_AT_small";
13369 case DW_AT_decimal_sign:
13370 return "DW_AT_decimal_sign";
13371 case DW_AT_digit_count:
13372 return "DW_AT_digit_count";
13373 case DW_AT_picture_string:
13374 return "DW_AT_picture_string";
13375 case DW_AT_mutable:
13376 return "DW_AT_mutable";
13377 case DW_AT_threads_scaled:
13378 return "DW_AT_threads_scaled";
13379 case DW_AT_explicit:
13380 return "DW_AT_explicit";
13381 case DW_AT_object_pointer:
13382 return "DW_AT_object_pointer";
13383 case DW_AT_endianity:
13384 return "DW_AT_endianity";
13385 case DW_AT_elemental:
13386 return "DW_AT_elemental";
13387 case DW_AT_pure:
13388 return "DW_AT_pure";
13389 case DW_AT_recursive:
13390 return "DW_AT_recursive";
13391 /* DWARF 4 values. */
13392 case DW_AT_signature:
13393 return "DW_AT_signature";
13394 case DW_AT_linkage_name:
13395 return "DW_AT_linkage_name";
13396 /* SGI/MIPS extensions. */
13397 #ifdef MIPS /* collides with DW_AT_HP_block_index */
13398 case DW_AT_MIPS_fde:
13399 return "DW_AT_MIPS_fde";
13400 #endif
13401 case DW_AT_MIPS_loop_begin:
13402 return "DW_AT_MIPS_loop_begin";
13403 case DW_AT_MIPS_tail_loop_begin:
13404 return "DW_AT_MIPS_tail_loop_begin";
13405 case DW_AT_MIPS_epilog_begin:
13406 return "DW_AT_MIPS_epilog_begin";
13407 case DW_AT_MIPS_loop_unroll_factor:
13408 return "DW_AT_MIPS_loop_unroll_factor";
13409 case DW_AT_MIPS_software_pipeline_depth:
13410 return "DW_AT_MIPS_software_pipeline_depth";
13411 case DW_AT_MIPS_linkage_name:
13412 return "DW_AT_MIPS_linkage_name";
13413 case DW_AT_MIPS_stride:
13414 return "DW_AT_MIPS_stride";
13415 case DW_AT_MIPS_abstract_name:
13416 return "DW_AT_MIPS_abstract_name";
13417 case DW_AT_MIPS_clone_origin:
13418 return "DW_AT_MIPS_clone_origin";
13419 case DW_AT_MIPS_has_inlines:
13420 return "DW_AT_MIPS_has_inlines";
13421 /* HP extensions. */
13422 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
13423 case DW_AT_HP_block_index:
13424 return "DW_AT_HP_block_index";
13425 #endif
13426 case DW_AT_HP_unmodifiable:
13427 return "DW_AT_HP_unmodifiable";
13428 case DW_AT_HP_actuals_stmt_list:
13429 return "DW_AT_HP_actuals_stmt_list";
13430 case DW_AT_HP_proc_per_section:
13431 return "DW_AT_HP_proc_per_section";
13432 case DW_AT_HP_raw_data_ptr:
13433 return "DW_AT_HP_raw_data_ptr";
13434 case DW_AT_HP_pass_by_reference:
13435 return "DW_AT_HP_pass_by_reference";
13436 case DW_AT_HP_opt_level:
13437 return "DW_AT_HP_opt_level";
13438 case DW_AT_HP_prof_version_id:
13439 return "DW_AT_HP_prof_version_id";
13440 case DW_AT_HP_opt_flags:
13441 return "DW_AT_HP_opt_flags";
13442 case DW_AT_HP_cold_region_low_pc:
13443 return "DW_AT_HP_cold_region_low_pc";
13444 case DW_AT_HP_cold_region_high_pc:
13445 return "DW_AT_HP_cold_region_high_pc";
13446 case DW_AT_HP_all_variables_modifiable:
13447 return "DW_AT_HP_all_variables_modifiable";
13448 case DW_AT_HP_linkage_name:
13449 return "DW_AT_HP_linkage_name";
13450 case DW_AT_HP_prof_flags:
13451 return "DW_AT_HP_prof_flags";
13452 /* GNU extensions. */
13453 case DW_AT_sf_names:
13454 return "DW_AT_sf_names";
13455 case DW_AT_src_info:
13456 return "DW_AT_src_info";
13457 case DW_AT_mac_info:
13458 return "DW_AT_mac_info";
13459 case DW_AT_src_coords:
13460 return "DW_AT_src_coords";
13461 case DW_AT_body_begin:
13462 return "DW_AT_body_begin";
13463 case DW_AT_body_end:
13464 return "DW_AT_body_end";
13465 case DW_AT_GNU_vector:
13466 return "DW_AT_GNU_vector";
13467 case DW_AT_GNU_odr_signature:
13468 return "DW_AT_GNU_odr_signature";
13469 /* VMS extensions. */
13470 case DW_AT_VMS_rtnbeg_pd_address:
13471 return "DW_AT_VMS_rtnbeg_pd_address";
13472 /* UPC extension. */
13473 case DW_AT_upc_threads_scaled:
13474 return "DW_AT_upc_threads_scaled";
13475 /* PGI (STMicroelectronics) extensions. */
13476 case DW_AT_PGI_lbase:
13477 return "DW_AT_PGI_lbase";
13478 case DW_AT_PGI_soffset:
13479 return "DW_AT_PGI_soffset";
13480 case DW_AT_PGI_lstride:
13481 return "DW_AT_PGI_lstride";
13482 default:
13483 return "DW_AT_<unknown>";
13484 }
13485 }
13486
13487 /* Convert a DWARF value form code into its string name. */
13488
13489 static char *
13490 dwarf_form_name (unsigned form)
13491 {
13492 switch (form)
13493 {
13494 case DW_FORM_addr:
13495 return "DW_FORM_addr";
13496 case DW_FORM_block2:
13497 return "DW_FORM_block2";
13498 case DW_FORM_block4:
13499 return "DW_FORM_block4";
13500 case DW_FORM_data2:
13501 return "DW_FORM_data2";
13502 case DW_FORM_data4:
13503 return "DW_FORM_data4";
13504 case DW_FORM_data8:
13505 return "DW_FORM_data8";
13506 case DW_FORM_string:
13507 return "DW_FORM_string";
13508 case DW_FORM_block:
13509 return "DW_FORM_block";
13510 case DW_FORM_block1:
13511 return "DW_FORM_block1";
13512 case DW_FORM_data1:
13513 return "DW_FORM_data1";
13514 case DW_FORM_flag:
13515 return "DW_FORM_flag";
13516 case DW_FORM_sdata:
13517 return "DW_FORM_sdata";
13518 case DW_FORM_strp:
13519 return "DW_FORM_strp";
13520 case DW_FORM_udata:
13521 return "DW_FORM_udata";
13522 case DW_FORM_ref_addr:
13523 return "DW_FORM_ref_addr";
13524 case DW_FORM_ref1:
13525 return "DW_FORM_ref1";
13526 case DW_FORM_ref2:
13527 return "DW_FORM_ref2";
13528 case DW_FORM_ref4:
13529 return "DW_FORM_ref4";
13530 case DW_FORM_ref8:
13531 return "DW_FORM_ref8";
13532 case DW_FORM_ref_udata:
13533 return "DW_FORM_ref_udata";
13534 case DW_FORM_indirect:
13535 return "DW_FORM_indirect";
13536 case DW_FORM_sec_offset:
13537 return "DW_FORM_sec_offset";
13538 case DW_FORM_exprloc:
13539 return "DW_FORM_exprloc";
13540 case DW_FORM_flag_present:
13541 return "DW_FORM_flag_present";
13542 case DW_FORM_ref_sig8:
13543 return "DW_FORM_ref_sig8";
13544 default:
13545 return "DW_FORM_<unknown>";
13546 }
13547 }
13548
13549 /* Convert a DWARF stack opcode into its string name. */
13550
13551 const char *
13552 dwarf_stack_op_name (unsigned op)
13553 {
13554 switch (op)
13555 {
13556 case DW_OP_addr:
13557 return "DW_OP_addr";
13558 case DW_OP_deref:
13559 return "DW_OP_deref";
13560 case DW_OP_const1u:
13561 return "DW_OP_const1u";
13562 case DW_OP_const1s:
13563 return "DW_OP_const1s";
13564 case DW_OP_const2u:
13565 return "DW_OP_const2u";
13566 case DW_OP_const2s:
13567 return "DW_OP_const2s";
13568 case DW_OP_const4u:
13569 return "DW_OP_const4u";
13570 case DW_OP_const4s:
13571 return "DW_OP_const4s";
13572 case DW_OP_const8u:
13573 return "DW_OP_const8u";
13574 case DW_OP_const8s:
13575 return "DW_OP_const8s";
13576 case DW_OP_constu:
13577 return "DW_OP_constu";
13578 case DW_OP_consts:
13579 return "DW_OP_consts";
13580 case DW_OP_dup:
13581 return "DW_OP_dup";
13582 case DW_OP_drop:
13583 return "DW_OP_drop";
13584 case DW_OP_over:
13585 return "DW_OP_over";
13586 case DW_OP_pick:
13587 return "DW_OP_pick";
13588 case DW_OP_swap:
13589 return "DW_OP_swap";
13590 case DW_OP_rot:
13591 return "DW_OP_rot";
13592 case DW_OP_xderef:
13593 return "DW_OP_xderef";
13594 case DW_OP_abs:
13595 return "DW_OP_abs";
13596 case DW_OP_and:
13597 return "DW_OP_and";
13598 case DW_OP_div:
13599 return "DW_OP_div";
13600 case DW_OP_minus:
13601 return "DW_OP_minus";
13602 case DW_OP_mod:
13603 return "DW_OP_mod";
13604 case DW_OP_mul:
13605 return "DW_OP_mul";
13606 case DW_OP_neg:
13607 return "DW_OP_neg";
13608 case DW_OP_not:
13609 return "DW_OP_not";
13610 case DW_OP_or:
13611 return "DW_OP_or";
13612 case DW_OP_plus:
13613 return "DW_OP_plus";
13614 case DW_OP_plus_uconst:
13615 return "DW_OP_plus_uconst";
13616 case DW_OP_shl:
13617 return "DW_OP_shl";
13618 case DW_OP_shr:
13619 return "DW_OP_shr";
13620 case DW_OP_shra:
13621 return "DW_OP_shra";
13622 case DW_OP_xor:
13623 return "DW_OP_xor";
13624 case DW_OP_bra:
13625 return "DW_OP_bra";
13626 case DW_OP_eq:
13627 return "DW_OP_eq";
13628 case DW_OP_ge:
13629 return "DW_OP_ge";
13630 case DW_OP_gt:
13631 return "DW_OP_gt";
13632 case DW_OP_le:
13633 return "DW_OP_le";
13634 case DW_OP_lt:
13635 return "DW_OP_lt";
13636 case DW_OP_ne:
13637 return "DW_OP_ne";
13638 case DW_OP_skip:
13639 return "DW_OP_skip";
13640 case DW_OP_lit0:
13641 return "DW_OP_lit0";
13642 case DW_OP_lit1:
13643 return "DW_OP_lit1";
13644 case DW_OP_lit2:
13645 return "DW_OP_lit2";
13646 case DW_OP_lit3:
13647 return "DW_OP_lit3";
13648 case DW_OP_lit4:
13649 return "DW_OP_lit4";
13650 case DW_OP_lit5:
13651 return "DW_OP_lit5";
13652 case DW_OP_lit6:
13653 return "DW_OP_lit6";
13654 case DW_OP_lit7:
13655 return "DW_OP_lit7";
13656 case DW_OP_lit8:
13657 return "DW_OP_lit8";
13658 case DW_OP_lit9:
13659 return "DW_OP_lit9";
13660 case DW_OP_lit10:
13661 return "DW_OP_lit10";
13662 case DW_OP_lit11:
13663 return "DW_OP_lit11";
13664 case DW_OP_lit12:
13665 return "DW_OP_lit12";
13666 case DW_OP_lit13:
13667 return "DW_OP_lit13";
13668 case DW_OP_lit14:
13669 return "DW_OP_lit14";
13670 case DW_OP_lit15:
13671 return "DW_OP_lit15";
13672 case DW_OP_lit16:
13673 return "DW_OP_lit16";
13674 case DW_OP_lit17:
13675 return "DW_OP_lit17";
13676 case DW_OP_lit18:
13677 return "DW_OP_lit18";
13678 case DW_OP_lit19:
13679 return "DW_OP_lit19";
13680 case DW_OP_lit20:
13681 return "DW_OP_lit20";
13682 case DW_OP_lit21:
13683 return "DW_OP_lit21";
13684 case DW_OP_lit22:
13685 return "DW_OP_lit22";
13686 case DW_OP_lit23:
13687 return "DW_OP_lit23";
13688 case DW_OP_lit24:
13689 return "DW_OP_lit24";
13690 case DW_OP_lit25:
13691 return "DW_OP_lit25";
13692 case DW_OP_lit26:
13693 return "DW_OP_lit26";
13694 case DW_OP_lit27:
13695 return "DW_OP_lit27";
13696 case DW_OP_lit28:
13697 return "DW_OP_lit28";
13698 case DW_OP_lit29:
13699 return "DW_OP_lit29";
13700 case DW_OP_lit30:
13701 return "DW_OP_lit30";
13702 case DW_OP_lit31:
13703 return "DW_OP_lit31";
13704 case DW_OP_reg0:
13705 return "DW_OP_reg0";
13706 case DW_OP_reg1:
13707 return "DW_OP_reg1";
13708 case DW_OP_reg2:
13709 return "DW_OP_reg2";
13710 case DW_OP_reg3:
13711 return "DW_OP_reg3";
13712 case DW_OP_reg4:
13713 return "DW_OP_reg4";
13714 case DW_OP_reg5:
13715 return "DW_OP_reg5";
13716 case DW_OP_reg6:
13717 return "DW_OP_reg6";
13718 case DW_OP_reg7:
13719 return "DW_OP_reg7";
13720 case DW_OP_reg8:
13721 return "DW_OP_reg8";
13722 case DW_OP_reg9:
13723 return "DW_OP_reg9";
13724 case DW_OP_reg10:
13725 return "DW_OP_reg10";
13726 case DW_OP_reg11:
13727 return "DW_OP_reg11";
13728 case DW_OP_reg12:
13729 return "DW_OP_reg12";
13730 case DW_OP_reg13:
13731 return "DW_OP_reg13";
13732 case DW_OP_reg14:
13733 return "DW_OP_reg14";
13734 case DW_OP_reg15:
13735 return "DW_OP_reg15";
13736 case DW_OP_reg16:
13737 return "DW_OP_reg16";
13738 case DW_OP_reg17:
13739 return "DW_OP_reg17";
13740 case DW_OP_reg18:
13741 return "DW_OP_reg18";
13742 case DW_OP_reg19:
13743 return "DW_OP_reg19";
13744 case DW_OP_reg20:
13745 return "DW_OP_reg20";
13746 case DW_OP_reg21:
13747 return "DW_OP_reg21";
13748 case DW_OP_reg22:
13749 return "DW_OP_reg22";
13750 case DW_OP_reg23:
13751 return "DW_OP_reg23";
13752 case DW_OP_reg24:
13753 return "DW_OP_reg24";
13754 case DW_OP_reg25:
13755 return "DW_OP_reg25";
13756 case DW_OP_reg26:
13757 return "DW_OP_reg26";
13758 case DW_OP_reg27:
13759 return "DW_OP_reg27";
13760 case DW_OP_reg28:
13761 return "DW_OP_reg28";
13762 case DW_OP_reg29:
13763 return "DW_OP_reg29";
13764 case DW_OP_reg30:
13765 return "DW_OP_reg30";
13766 case DW_OP_reg31:
13767 return "DW_OP_reg31";
13768 case DW_OP_breg0:
13769 return "DW_OP_breg0";
13770 case DW_OP_breg1:
13771 return "DW_OP_breg1";
13772 case DW_OP_breg2:
13773 return "DW_OP_breg2";
13774 case DW_OP_breg3:
13775 return "DW_OP_breg3";
13776 case DW_OP_breg4:
13777 return "DW_OP_breg4";
13778 case DW_OP_breg5:
13779 return "DW_OP_breg5";
13780 case DW_OP_breg6:
13781 return "DW_OP_breg6";
13782 case DW_OP_breg7:
13783 return "DW_OP_breg7";
13784 case DW_OP_breg8:
13785 return "DW_OP_breg8";
13786 case DW_OP_breg9:
13787 return "DW_OP_breg9";
13788 case DW_OP_breg10:
13789 return "DW_OP_breg10";
13790 case DW_OP_breg11:
13791 return "DW_OP_breg11";
13792 case DW_OP_breg12:
13793 return "DW_OP_breg12";
13794 case DW_OP_breg13:
13795 return "DW_OP_breg13";
13796 case DW_OP_breg14:
13797 return "DW_OP_breg14";
13798 case DW_OP_breg15:
13799 return "DW_OP_breg15";
13800 case DW_OP_breg16:
13801 return "DW_OP_breg16";
13802 case DW_OP_breg17:
13803 return "DW_OP_breg17";
13804 case DW_OP_breg18:
13805 return "DW_OP_breg18";
13806 case DW_OP_breg19:
13807 return "DW_OP_breg19";
13808 case DW_OP_breg20:
13809 return "DW_OP_breg20";
13810 case DW_OP_breg21:
13811 return "DW_OP_breg21";
13812 case DW_OP_breg22:
13813 return "DW_OP_breg22";
13814 case DW_OP_breg23:
13815 return "DW_OP_breg23";
13816 case DW_OP_breg24:
13817 return "DW_OP_breg24";
13818 case DW_OP_breg25:
13819 return "DW_OP_breg25";
13820 case DW_OP_breg26:
13821 return "DW_OP_breg26";
13822 case DW_OP_breg27:
13823 return "DW_OP_breg27";
13824 case DW_OP_breg28:
13825 return "DW_OP_breg28";
13826 case DW_OP_breg29:
13827 return "DW_OP_breg29";
13828 case DW_OP_breg30:
13829 return "DW_OP_breg30";
13830 case DW_OP_breg31:
13831 return "DW_OP_breg31";
13832 case DW_OP_regx:
13833 return "DW_OP_regx";
13834 case DW_OP_fbreg:
13835 return "DW_OP_fbreg";
13836 case DW_OP_bregx:
13837 return "DW_OP_bregx";
13838 case DW_OP_piece:
13839 return "DW_OP_piece";
13840 case DW_OP_deref_size:
13841 return "DW_OP_deref_size";
13842 case DW_OP_xderef_size:
13843 return "DW_OP_xderef_size";
13844 case DW_OP_nop:
13845 return "DW_OP_nop";
13846 /* DWARF 3 extensions. */
13847 case DW_OP_push_object_address:
13848 return "DW_OP_push_object_address";
13849 case DW_OP_call2:
13850 return "DW_OP_call2";
13851 case DW_OP_call4:
13852 return "DW_OP_call4";
13853 case DW_OP_call_ref:
13854 return "DW_OP_call_ref";
13855 case DW_OP_form_tls_address:
13856 return "DW_OP_form_tls_address";
13857 case DW_OP_call_frame_cfa:
13858 return "DW_OP_call_frame_cfa";
13859 case DW_OP_bit_piece:
13860 return "DW_OP_bit_piece";
13861 /* DWARF 4 extensions. */
13862 case DW_OP_implicit_value:
13863 return "DW_OP_implicit_value";
13864 case DW_OP_stack_value:
13865 return "DW_OP_stack_value";
13866 /* GNU extensions. */
13867 case DW_OP_GNU_push_tls_address:
13868 return "DW_OP_GNU_push_tls_address";
13869 case DW_OP_GNU_uninit:
13870 return "DW_OP_GNU_uninit";
13871 case DW_OP_GNU_encoded_addr:
13872 return "DW_OP_GNU_encoded_addr";
13873 case DW_OP_GNU_implicit_pointer:
13874 return "DW_OP_GNU_implicit_pointer";
13875 case DW_OP_GNU_entry_value:
13876 return "DW_OP_GNU_entry_value";
13877 case DW_OP_GNU_const_type:
13878 return "DW_OP_GNU_const_type";
13879 case DW_OP_GNU_regval_type:
13880 return "DW_OP_GNU_regval_type";
13881 case DW_OP_GNU_deref_type:
13882 return "DW_OP_GNU_deref_type";
13883 case DW_OP_GNU_convert:
13884 return "DW_OP_GNU_convert";
13885 case DW_OP_GNU_reinterpret:
13886 return "DW_OP_GNU_reinterpret";
13887 case DW_OP_GNU_parameter_ref:
13888 return "DW_OP_GNU_parameter_ref";
13889 default:
13890 return NULL;
13891 }
13892 }
13893
13894 static char *
13895 dwarf_bool_name (unsigned mybool)
13896 {
13897 if (mybool)
13898 return "TRUE";
13899 else
13900 return "FALSE";
13901 }
13902
13903 /* Convert a DWARF type code into its string name. */
13904
13905 static char *
13906 dwarf_type_encoding_name (unsigned enc)
13907 {
13908 switch (enc)
13909 {
13910 case DW_ATE_void:
13911 return "DW_ATE_void";
13912 case DW_ATE_address:
13913 return "DW_ATE_address";
13914 case DW_ATE_boolean:
13915 return "DW_ATE_boolean";
13916 case DW_ATE_complex_float:
13917 return "DW_ATE_complex_float";
13918 case DW_ATE_float:
13919 return "DW_ATE_float";
13920 case DW_ATE_signed:
13921 return "DW_ATE_signed";
13922 case DW_ATE_signed_char:
13923 return "DW_ATE_signed_char";
13924 case DW_ATE_unsigned:
13925 return "DW_ATE_unsigned";
13926 case DW_ATE_unsigned_char:
13927 return "DW_ATE_unsigned_char";
13928 /* DWARF 3. */
13929 case DW_ATE_imaginary_float:
13930 return "DW_ATE_imaginary_float";
13931 case DW_ATE_packed_decimal:
13932 return "DW_ATE_packed_decimal";
13933 case DW_ATE_numeric_string:
13934 return "DW_ATE_numeric_string";
13935 case DW_ATE_edited:
13936 return "DW_ATE_edited";
13937 case DW_ATE_signed_fixed:
13938 return "DW_ATE_signed_fixed";
13939 case DW_ATE_unsigned_fixed:
13940 return "DW_ATE_unsigned_fixed";
13941 case DW_ATE_decimal_float:
13942 return "DW_ATE_decimal_float";
13943 /* DWARF 4. */
13944 case DW_ATE_UTF:
13945 return "DW_ATE_UTF";
13946 /* HP extensions. */
13947 case DW_ATE_HP_float80:
13948 return "DW_ATE_HP_float80";
13949 case DW_ATE_HP_complex_float80:
13950 return "DW_ATE_HP_complex_float80";
13951 case DW_ATE_HP_float128:
13952 return "DW_ATE_HP_float128";
13953 case DW_ATE_HP_complex_float128:
13954 return "DW_ATE_HP_complex_float128";
13955 case DW_ATE_HP_floathpintel:
13956 return "DW_ATE_HP_floathpintel";
13957 case DW_ATE_HP_imaginary_float80:
13958 return "DW_ATE_HP_imaginary_float80";
13959 case DW_ATE_HP_imaginary_float128:
13960 return "DW_ATE_HP_imaginary_float128";
13961 default:
13962 return "DW_ATE_<unknown>";
13963 }
13964 }
13965
13966 /* Convert a DWARF call frame info operation to its string name. */
13967
13968 #if 0
13969 static char *
13970 dwarf_cfi_name (unsigned cfi_opc)
13971 {
13972 switch (cfi_opc)
13973 {
13974 case DW_CFA_advance_loc:
13975 return "DW_CFA_advance_loc";
13976 case DW_CFA_offset:
13977 return "DW_CFA_offset";
13978 case DW_CFA_restore:
13979 return "DW_CFA_restore";
13980 case DW_CFA_nop:
13981 return "DW_CFA_nop";
13982 case DW_CFA_set_loc:
13983 return "DW_CFA_set_loc";
13984 case DW_CFA_advance_loc1:
13985 return "DW_CFA_advance_loc1";
13986 case DW_CFA_advance_loc2:
13987 return "DW_CFA_advance_loc2";
13988 case DW_CFA_advance_loc4:
13989 return "DW_CFA_advance_loc4";
13990 case DW_CFA_offset_extended:
13991 return "DW_CFA_offset_extended";
13992 case DW_CFA_restore_extended:
13993 return "DW_CFA_restore_extended";
13994 case DW_CFA_undefined:
13995 return "DW_CFA_undefined";
13996 case DW_CFA_same_value:
13997 return "DW_CFA_same_value";
13998 case DW_CFA_register:
13999 return "DW_CFA_register";
14000 case DW_CFA_remember_state:
14001 return "DW_CFA_remember_state";
14002 case DW_CFA_restore_state:
14003 return "DW_CFA_restore_state";
14004 case DW_CFA_def_cfa:
14005 return "DW_CFA_def_cfa";
14006 case DW_CFA_def_cfa_register:
14007 return "DW_CFA_def_cfa_register";
14008 case DW_CFA_def_cfa_offset:
14009 return "DW_CFA_def_cfa_offset";
14010 /* DWARF 3. */
14011 case DW_CFA_def_cfa_expression:
14012 return "DW_CFA_def_cfa_expression";
14013 case DW_CFA_expression:
14014 return "DW_CFA_expression";
14015 case DW_CFA_offset_extended_sf:
14016 return "DW_CFA_offset_extended_sf";
14017 case DW_CFA_def_cfa_sf:
14018 return "DW_CFA_def_cfa_sf";
14019 case DW_CFA_def_cfa_offset_sf:
14020 return "DW_CFA_def_cfa_offset_sf";
14021 case DW_CFA_val_offset:
14022 return "DW_CFA_val_offset";
14023 case DW_CFA_val_offset_sf:
14024 return "DW_CFA_val_offset_sf";
14025 case DW_CFA_val_expression:
14026 return "DW_CFA_val_expression";
14027 /* SGI/MIPS specific. */
14028 case DW_CFA_MIPS_advance_loc8:
14029 return "DW_CFA_MIPS_advance_loc8";
14030 /* GNU extensions. */
14031 case DW_CFA_GNU_window_save:
14032 return "DW_CFA_GNU_window_save";
14033 case DW_CFA_GNU_args_size:
14034 return "DW_CFA_GNU_args_size";
14035 case DW_CFA_GNU_negative_offset_extended:
14036 return "DW_CFA_GNU_negative_offset_extended";
14037 default:
14038 return "DW_CFA_<unknown>";
14039 }
14040 }
14041 #endif
14042
14043 static void
14044 dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
14045 {
14046 unsigned int i;
14047
14048 print_spaces (indent, f);
14049 fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n",
14050 dwarf_tag_name (die->tag), die->abbrev, die->offset.sect_off);
14051
14052 if (die->parent != NULL)
14053 {
14054 print_spaces (indent, f);
14055 fprintf_unfiltered (f, " parent at offset: 0x%x\n",
14056 die->parent->offset.sect_off);
14057 }
14058
14059 print_spaces (indent, f);
14060 fprintf_unfiltered (f, " has children: %s\n",
14061 dwarf_bool_name (die->child != NULL));
14062
14063 print_spaces (indent, f);
14064 fprintf_unfiltered (f, " attributes:\n");
14065
14066 for (i = 0; i < die->num_attrs; ++i)
14067 {
14068 print_spaces (indent, f);
14069 fprintf_unfiltered (f, " %s (%s) ",
14070 dwarf_attr_name (die->attrs[i].name),
14071 dwarf_form_name (die->attrs[i].form));
14072
14073 switch (die->attrs[i].form)
14074 {
14075 case DW_FORM_addr:
14076 fprintf_unfiltered (f, "address: ");
14077 fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f);
14078 break;
14079 case DW_FORM_block2:
14080 case DW_FORM_block4:
14081 case DW_FORM_block:
14082 case DW_FORM_block1:
14083 fprintf_unfiltered (f, "block: size %d",
14084 DW_BLOCK (&die->attrs[i])->size);
14085 break;
14086 case DW_FORM_exprloc:
14087 fprintf_unfiltered (f, "expression: size %u",
14088 DW_BLOCK (&die->attrs[i])->size);
14089 break;
14090 case DW_FORM_ref_addr:
14091 fprintf_unfiltered (f, "ref address: ");
14092 fputs_filtered (hex_string (DW_UNSND (&die->attrs[i])), f);
14093 break;
14094 case DW_FORM_ref1:
14095 case DW_FORM_ref2:
14096 case DW_FORM_ref4:
14097 case DW_FORM_ref8:
14098 case DW_FORM_ref_udata:
14099 fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)",
14100 (long) (DW_UNSND (&die->attrs[i])));
14101 break;
14102 case DW_FORM_data1:
14103 case DW_FORM_data2:
14104 case DW_FORM_data4:
14105 case DW_FORM_data8:
14106 case DW_FORM_udata:
14107 case DW_FORM_sdata:
14108 fprintf_unfiltered (f, "constant: %s",
14109 pulongest (DW_UNSND (&die->attrs[i])));
14110 break;
14111 case DW_FORM_sec_offset:
14112 fprintf_unfiltered (f, "section offset: %s",
14113 pulongest (DW_UNSND (&die->attrs[i])));
14114 break;
14115 case DW_FORM_ref_sig8:
14116 if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL)
14117 fprintf_unfiltered (f, "signatured type, offset: 0x%x",
14118 DW_SIGNATURED_TYPE (&die->attrs[i])->per_cu.offset.sect_off);
14119 else
14120 fprintf_unfiltered (f, "signatured type, offset: unknown");
14121 break;
14122 case DW_FORM_string:
14123 case DW_FORM_strp:
14124 fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)",
14125 DW_STRING (&die->attrs[i])
14126 ? DW_STRING (&die->attrs[i]) : "",
14127 DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not");
14128 break;
14129 case DW_FORM_flag:
14130 if (DW_UNSND (&die->attrs[i]))
14131 fprintf_unfiltered (f, "flag: TRUE");
14132 else
14133 fprintf_unfiltered (f, "flag: FALSE");
14134 break;
14135 case DW_FORM_flag_present:
14136 fprintf_unfiltered (f, "flag: TRUE");
14137 break;
14138 case DW_FORM_indirect:
14139 /* The reader will have reduced the indirect form to
14140 the "base form" so this form should not occur. */
14141 fprintf_unfiltered (f,
14142 "unexpected attribute form: DW_FORM_indirect");
14143 break;
14144 default:
14145 fprintf_unfiltered (f, "unsupported attribute form: %d.",
14146 die->attrs[i].form);
14147 break;
14148 }
14149 fprintf_unfiltered (f, "\n");
14150 }
14151 }
14152
14153 static void
14154 dump_die_for_error (struct die_info *die)
14155 {
14156 dump_die_shallow (gdb_stderr, 0, die);
14157 }
14158
14159 static void
14160 dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die)
14161 {
14162 int indent = level * 4;
14163
14164 gdb_assert (die != NULL);
14165
14166 if (level >= max_level)
14167 return;
14168
14169 dump_die_shallow (f, indent, die);
14170
14171 if (die->child != NULL)
14172 {
14173 print_spaces (indent, f);
14174 fprintf_unfiltered (f, " Children:");
14175 if (level + 1 < max_level)
14176 {
14177 fprintf_unfiltered (f, "\n");
14178 dump_die_1 (f, level + 1, max_level, die->child);
14179 }
14180 else
14181 {
14182 fprintf_unfiltered (f,
14183 " [not printed, max nesting level reached]\n");
14184 }
14185 }
14186
14187 if (die->sibling != NULL && level > 0)
14188 {
14189 dump_die_1 (f, level, max_level, die->sibling);
14190 }
14191 }
14192
14193 /* This is called from the pdie macro in gdbinit.in.
14194 It's not static so gcc will keep a copy callable from gdb. */
14195
14196 void
14197 dump_die (struct die_info *die, int max_level)
14198 {
14199 dump_die_1 (gdb_stdlog, 0, max_level, die);
14200 }
14201
14202 static void
14203 store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu)
14204 {
14205 void **slot;
14206
14207 slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset.sect_off,
14208 INSERT);
14209
14210 *slot = die;
14211 }
14212
14213 /* DW_ADDR is always stored already as sect_offset; despite for the forms
14214 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
14215
14216 static int
14217 is_ref_attr (struct attribute *attr)
14218 {
14219 switch (attr->form)
14220 {
14221 case DW_FORM_ref_addr:
14222 case DW_FORM_ref1:
14223 case DW_FORM_ref2:
14224 case DW_FORM_ref4:
14225 case DW_FORM_ref8:
14226 case DW_FORM_ref_udata:
14227 return 1;
14228 default:
14229 return 0;
14230 }
14231 }
14232
14233 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
14234 required kind. */
14235
14236 static sect_offset
14237 dwarf2_get_ref_die_offset (struct attribute *attr)
14238 {
14239 sect_offset retval = { DW_UNSND (attr) };
14240
14241 if (is_ref_attr (attr))
14242 return retval;
14243
14244 retval.sect_off = 0;
14245 complaint (&symfile_complaints,
14246 _("unsupported die ref attribute form: '%s'"),
14247 dwarf_form_name (attr->form));
14248 return retval;
14249 }
14250
14251 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
14252 * the value held by the attribute is not constant. */
14253
14254 static LONGEST
14255 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
14256 {
14257 if (attr->form == DW_FORM_sdata)
14258 return DW_SND (attr);
14259 else if (attr->form == DW_FORM_udata
14260 || attr->form == DW_FORM_data1
14261 || attr->form == DW_FORM_data2
14262 || attr->form == DW_FORM_data4
14263 || attr->form == DW_FORM_data8)
14264 return DW_UNSND (attr);
14265 else
14266 {
14267 complaint (&symfile_complaints,
14268 _("Attribute value is not a constant (%s)"),
14269 dwarf_form_name (attr->form));
14270 return default_value;
14271 }
14272 }
14273
14274 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
14275 unit and add it to our queue.
14276 The result is non-zero if PER_CU was queued, otherwise the result is zero
14277 meaning either PER_CU is already queued or it is already loaded. */
14278
14279 static int
14280 maybe_queue_comp_unit (struct dwarf2_cu *this_cu,
14281 struct dwarf2_per_cu_data *per_cu)
14282 {
14283 /* We may arrive here during partial symbol reading, if we need full
14284 DIEs to process an unusual case (e.g. template arguments). Do
14285 not queue PER_CU, just tell our caller to load its DIEs. */
14286 if (dwarf2_per_objfile->reading_partial_symbols)
14287 {
14288 if (per_cu->cu == NULL || per_cu->cu->dies == NULL)
14289 return 1;
14290 return 0;
14291 }
14292
14293 /* Mark the dependence relation so that we don't flush PER_CU
14294 too early. */
14295 dwarf2_add_dependence (this_cu, per_cu);
14296
14297 /* If it's already on the queue, we have nothing to do. */
14298 if (per_cu->queued)
14299 return 0;
14300
14301 /* If the compilation unit is already loaded, just mark it as
14302 used. */
14303 if (per_cu->cu != NULL)
14304 {
14305 per_cu->cu->last_used = 0;
14306 return 0;
14307 }
14308
14309 /* Add it to the queue. */
14310 queue_comp_unit (per_cu);
14311
14312 return 1;
14313 }
14314
14315 /* Follow reference or signature attribute ATTR of SRC_DIE.
14316 On entry *REF_CU is the CU of SRC_DIE.
14317 On exit *REF_CU is the CU of the result. */
14318
14319 static struct die_info *
14320 follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr,
14321 struct dwarf2_cu **ref_cu)
14322 {
14323 struct die_info *die;
14324
14325 if (is_ref_attr (attr))
14326 die = follow_die_ref (src_die, attr, ref_cu);
14327 else if (attr->form == DW_FORM_ref_sig8)
14328 die = follow_die_sig (src_die, attr, ref_cu);
14329 else
14330 {
14331 dump_die_for_error (src_die);
14332 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
14333 (*ref_cu)->objfile->name);
14334 }
14335
14336 return die;
14337 }
14338
14339 /* Follow reference OFFSET.
14340 On entry *REF_CU is the CU of the source die referencing OFFSET.
14341 On exit *REF_CU is the CU of the result.
14342 Returns NULL if OFFSET is invalid. */
14343
14344 static struct die_info *
14345 follow_die_offset (sect_offset offset, struct dwarf2_cu **ref_cu)
14346 {
14347 struct die_info temp_die;
14348 struct dwarf2_cu *target_cu, *cu = *ref_cu;
14349
14350 gdb_assert (cu->per_cu != NULL);
14351
14352 target_cu = cu;
14353
14354 if (cu->per_cu->debug_types_section)
14355 {
14356 /* .debug_types CUs cannot reference anything outside their CU.
14357 If they need to, they have to reference a signatured type via
14358 DW_FORM_ref_sig8. */
14359 if (! offset_in_cu_p (&cu->header, offset))
14360 return NULL;
14361 }
14362 else if (! offset_in_cu_p (&cu->header, offset))
14363 {
14364 struct dwarf2_per_cu_data *per_cu;
14365
14366 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
14367
14368 /* If necessary, add it to the queue and load its DIEs. */
14369 if (maybe_queue_comp_unit (cu, per_cu))
14370 load_full_comp_unit (per_cu);
14371
14372 target_cu = per_cu->cu;
14373 }
14374 else if (cu->dies == NULL)
14375 {
14376 /* We're loading full DIEs during partial symbol reading. */
14377 gdb_assert (dwarf2_per_objfile->reading_partial_symbols);
14378 load_full_comp_unit (cu->per_cu);
14379 }
14380
14381 *ref_cu = target_cu;
14382 temp_die.offset = offset;
14383 return htab_find_with_hash (target_cu->die_hash, &temp_die, offset.sect_off);
14384 }
14385
14386 /* Follow reference attribute ATTR of SRC_DIE.
14387 On entry *REF_CU is the CU of SRC_DIE.
14388 On exit *REF_CU is the CU of the result. */
14389
14390 static struct die_info *
14391 follow_die_ref (struct die_info *src_die, struct attribute *attr,
14392 struct dwarf2_cu **ref_cu)
14393 {
14394 sect_offset offset = dwarf2_get_ref_die_offset (attr);
14395 struct dwarf2_cu *cu = *ref_cu;
14396 struct die_info *die;
14397
14398 die = follow_die_offset (offset, ref_cu);
14399 if (!die)
14400 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
14401 "at 0x%x [in module %s]"),
14402 offset.sect_off, src_die->offset.sect_off, cu->objfile->name);
14403
14404 return die;
14405 }
14406
14407 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
14408 Returned value is intended for DW_OP_call*. Returned
14409 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
14410
14411 struct dwarf2_locexpr_baton
14412 dwarf2_fetch_die_location_block (cu_offset offset_in_cu,
14413 struct dwarf2_per_cu_data *per_cu,
14414 CORE_ADDR (*get_frame_pc) (void *baton),
14415 void *baton)
14416 {
14417 sect_offset offset = { per_cu->offset.sect_off + offset_in_cu.cu_off };
14418 struct dwarf2_cu *cu;
14419 struct die_info *die;
14420 struct attribute *attr;
14421 struct dwarf2_locexpr_baton retval;
14422
14423 dw2_setup (per_cu->objfile);
14424
14425 if (per_cu->cu == NULL)
14426 load_cu (per_cu);
14427 cu = per_cu->cu;
14428
14429 die = follow_die_offset (offset, &cu);
14430 if (!die)
14431 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
14432 offset.sect_off, per_cu->objfile->name);
14433
14434 attr = dwarf2_attr (die, DW_AT_location, cu);
14435 if (!attr)
14436 {
14437 /* DWARF: "If there is no such attribute, then there is no effect.".
14438 DATA is ignored if SIZE is 0. */
14439
14440 retval.data = NULL;
14441 retval.size = 0;
14442 }
14443 else if (attr_form_is_section_offset (attr))
14444 {
14445 struct dwarf2_loclist_baton loclist_baton;
14446 CORE_ADDR pc = (*get_frame_pc) (baton);
14447 size_t size;
14448
14449 fill_in_loclist_baton (cu, &loclist_baton, attr);
14450
14451 retval.data = dwarf2_find_location_expression (&loclist_baton,
14452 &size, pc);
14453 retval.size = size;
14454 }
14455 else
14456 {
14457 if (!attr_form_is_block (attr))
14458 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
14459 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
14460 offset.sect_off, per_cu->objfile->name);
14461
14462 retval.data = DW_BLOCK (attr)->data;
14463 retval.size = DW_BLOCK (attr)->size;
14464 }
14465 retval.per_cu = cu->per_cu;
14466
14467 age_cached_comp_units ();
14468
14469 return retval;
14470 }
14471
14472 /* Return the type of the DIE at DIE_OFFSET in the CU named by
14473 PER_CU. */
14474
14475 struct type *
14476 dwarf2_get_die_type (cu_offset die_offset,
14477 struct dwarf2_per_cu_data *per_cu)
14478 {
14479 sect_offset die_offset_sect;
14480
14481 dw2_setup (per_cu->objfile);
14482
14483 die_offset_sect.sect_off = per_cu->offset.sect_off + die_offset.cu_off;
14484 return get_die_type_at_offset (die_offset_sect, per_cu);
14485 }
14486
14487 /* Follow the signature attribute ATTR in SRC_DIE.
14488 On entry *REF_CU is the CU of SRC_DIE.
14489 On exit *REF_CU is the CU of the result. */
14490
14491 static struct die_info *
14492 follow_die_sig (struct die_info *src_die, struct attribute *attr,
14493 struct dwarf2_cu **ref_cu)
14494 {
14495 struct objfile *objfile = (*ref_cu)->objfile;
14496 struct die_info temp_die;
14497 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
14498 struct dwarf2_cu *sig_cu;
14499 struct die_info *die;
14500
14501 /* sig_type will be NULL if the signatured type is missing from
14502 the debug info. */
14503 if (sig_type == NULL)
14504 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14505 "at 0x%x [in module %s]"),
14506 src_die->offset.sect_off, objfile->name);
14507
14508 /* If necessary, add it to the queue and load its DIEs. */
14509
14510 if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu))
14511 read_signatured_type (sig_type);
14512
14513 gdb_assert (sig_type->per_cu.cu != NULL);
14514
14515 sig_cu = sig_type->per_cu.cu;
14516 temp_die.offset.sect_off = (sig_type->per_cu.offset.sect_off
14517 + sig_type->type_offset.cu_off);
14518 die = htab_find_with_hash (sig_cu->die_hash, &temp_die,
14519 temp_die.offset.sect_off);
14520 if (die)
14521 {
14522 *ref_cu = sig_cu;
14523 return die;
14524 }
14525
14526 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
14527 "from DIE at 0x%x [in module %s]"),
14528 temp_die.offset.sect_off, src_die->offset.sect_off, objfile->name);
14529 }
14530
14531 /* Given an offset of a signatured type, return its signatured_type. */
14532
14533 static struct signatured_type *
14534 lookup_signatured_type_at_offset (struct objfile *objfile,
14535 struct dwarf2_section_info *section,
14536 sect_offset offset)
14537 {
14538 gdb_byte *info_ptr = section->buffer + offset.sect_off;
14539 unsigned int length, initial_length_size;
14540 unsigned int sig_offset;
14541 struct signatured_type find_entry, *sig_type;
14542
14543 length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size);
14544 sig_offset = (initial_length_size
14545 + 2 /*version*/
14546 + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/
14547 + 1 /*address_size*/);
14548 find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset);
14549 sig_type = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
14550
14551 /* This is only used to lookup previously recorded types.
14552 If we didn't find it, it's our bug. */
14553 gdb_assert (sig_type != NULL);
14554 gdb_assert (offset.sect_off == sig_type->per_cu.offset.sect_off);
14555
14556 return sig_type;
14557 }
14558
14559 /* Load the DIEs associated with type unit PER_CU into memory. */
14560
14561 static void
14562 load_full_type_unit (struct dwarf2_per_cu_data *per_cu)
14563 {
14564 struct objfile *objfile = per_cu->objfile;
14565 struct dwarf2_section_info *sect = per_cu->debug_types_section;
14566 sect_offset offset = per_cu->offset;
14567 struct signatured_type *sig_type;
14568
14569 dwarf2_read_section (objfile, sect);
14570
14571 /* We have the section offset, but we need the signature to do the
14572 hash table lookup. */
14573 /* FIXME: This is sorta unnecessary, read_signatured_type only uses
14574 the signature to assert we found the right one.
14575 Ok, but it's a lot of work. We should simplify things so any needed
14576 assert doesn't require all this clumsiness. */
14577 sig_type = lookup_signatured_type_at_offset (objfile, sect, offset);
14578
14579 gdb_assert (sig_type->per_cu.cu == NULL);
14580
14581 read_signatured_type (sig_type);
14582
14583 gdb_assert (sig_type->per_cu.cu != NULL);
14584 }
14585
14586 /* Read in a signatured type and build its CU and DIEs. */
14587
14588 static void
14589 read_signatured_type (struct signatured_type *sig_type)
14590 {
14591 struct objfile *objfile = sig_type->per_cu.objfile;
14592 gdb_byte *types_ptr;
14593 struct die_reader_specs reader_specs;
14594 struct dwarf2_cu *cu;
14595 ULONGEST signature;
14596 struct cleanup *back_to, *free_cu_cleanup;
14597 struct dwarf2_section_info *section = sig_type->per_cu.debug_types_section;
14598
14599 dwarf2_read_section (objfile, section);
14600 types_ptr = section->buffer + sig_type->per_cu.offset.sect_off;
14601
14602 gdb_assert (sig_type->per_cu.cu == NULL);
14603
14604 cu = xmalloc (sizeof (*cu));
14605 init_one_comp_unit (cu, &sig_type->per_cu);
14606
14607 /* If an error occurs while loading, release our storage. */
14608 free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu);
14609
14610 types_ptr = read_and_check_type_unit_head (&cu->header, section, types_ptr,
14611 &signature, NULL);
14612 gdb_assert (signature == sig_type->signature);
14613
14614 cu->die_hash
14615 = htab_create_alloc_ex (cu->header.length / 12,
14616 die_hash,
14617 die_eq,
14618 NULL,
14619 &cu->comp_unit_obstack,
14620 hashtab_obstack_allocate,
14621 dummy_obstack_deallocate);
14622
14623 dwarf2_read_abbrevs (cu);
14624 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
14625
14626 init_cu_die_reader (&reader_specs, cu);
14627
14628 cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr,
14629 NULL /*parent*/);
14630
14631 /* We try not to read any attributes in this function, because not
14632 all CUs needed for references have been loaded yet, and symbol
14633 table processing isn't initialized. But we have to set the CU language,
14634 or we won't be able to build types correctly. */
14635 prepare_one_comp_unit (cu, cu->dies);
14636
14637 do_cleanups (back_to);
14638
14639 /* We've successfully allocated this compilation unit. Let our caller
14640 clean it up when finished with it. */
14641 discard_cleanups (free_cu_cleanup);
14642
14643 /* Link this TU into read_in_chain. */
14644 sig_type->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
14645 dwarf2_per_objfile->read_in_chain = &sig_type->per_cu;
14646 }
14647
14648 /* Decode simple location descriptions.
14649 Given a pointer to a dwarf block that defines a location, compute
14650 the location and return the value.
14651
14652 NOTE drow/2003-11-18: This function is called in two situations
14653 now: for the address of static or global variables (partial symbols
14654 only) and for offsets into structures which are expected to be
14655 (more or less) constant. The partial symbol case should go away,
14656 and only the constant case should remain. That will let this
14657 function complain more accurately. A few special modes are allowed
14658 without complaint for global variables (for instance, global
14659 register values and thread-local values).
14660
14661 A location description containing no operations indicates that the
14662 object is optimized out. The return value is 0 for that case.
14663 FIXME drow/2003-11-16: No callers check for this case any more; soon all
14664 callers will only want a very basic result and this can become a
14665 complaint.
14666
14667 Note that stack[0] is unused except as a default error return. */
14668
14669 static CORE_ADDR
14670 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
14671 {
14672 struct objfile *objfile = cu->objfile;
14673 int i;
14674 int size = blk->size;
14675 gdb_byte *data = blk->data;
14676 CORE_ADDR stack[64];
14677 int stacki;
14678 unsigned int bytes_read, unsnd;
14679 gdb_byte op;
14680
14681 i = 0;
14682 stacki = 0;
14683 stack[stacki] = 0;
14684 stack[++stacki] = 0;
14685
14686 while (i < size)
14687 {
14688 op = data[i++];
14689 switch (op)
14690 {
14691 case DW_OP_lit0:
14692 case DW_OP_lit1:
14693 case DW_OP_lit2:
14694 case DW_OP_lit3:
14695 case DW_OP_lit4:
14696 case DW_OP_lit5:
14697 case DW_OP_lit6:
14698 case DW_OP_lit7:
14699 case DW_OP_lit8:
14700 case DW_OP_lit9:
14701 case DW_OP_lit10:
14702 case DW_OP_lit11:
14703 case DW_OP_lit12:
14704 case DW_OP_lit13:
14705 case DW_OP_lit14:
14706 case DW_OP_lit15:
14707 case DW_OP_lit16:
14708 case DW_OP_lit17:
14709 case DW_OP_lit18:
14710 case DW_OP_lit19:
14711 case DW_OP_lit20:
14712 case DW_OP_lit21:
14713 case DW_OP_lit22:
14714 case DW_OP_lit23:
14715 case DW_OP_lit24:
14716 case DW_OP_lit25:
14717 case DW_OP_lit26:
14718 case DW_OP_lit27:
14719 case DW_OP_lit28:
14720 case DW_OP_lit29:
14721 case DW_OP_lit30:
14722 case DW_OP_lit31:
14723 stack[++stacki] = op - DW_OP_lit0;
14724 break;
14725
14726 case DW_OP_reg0:
14727 case DW_OP_reg1:
14728 case DW_OP_reg2:
14729 case DW_OP_reg3:
14730 case DW_OP_reg4:
14731 case DW_OP_reg5:
14732 case DW_OP_reg6:
14733 case DW_OP_reg7:
14734 case DW_OP_reg8:
14735 case DW_OP_reg9:
14736 case DW_OP_reg10:
14737 case DW_OP_reg11:
14738 case DW_OP_reg12:
14739 case DW_OP_reg13:
14740 case DW_OP_reg14:
14741 case DW_OP_reg15:
14742 case DW_OP_reg16:
14743 case DW_OP_reg17:
14744 case DW_OP_reg18:
14745 case DW_OP_reg19:
14746 case DW_OP_reg20:
14747 case DW_OP_reg21:
14748 case DW_OP_reg22:
14749 case DW_OP_reg23:
14750 case DW_OP_reg24:
14751 case DW_OP_reg25:
14752 case DW_OP_reg26:
14753 case DW_OP_reg27:
14754 case DW_OP_reg28:
14755 case DW_OP_reg29:
14756 case DW_OP_reg30:
14757 case DW_OP_reg31:
14758 stack[++stacki] = op - DW_OP_reg0;
14759 if (i < size)
14760 dwarf2_complex_location_expr_complaint ();
14761 break;
14762
14763 case DW_OP_regx:
14764 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
14765 i += bytes_read;
14766 stack[++stacki] = unsnd;
14767 if (i < size)
14768 dwarf2_complex_location_expr_complaint ();
14769 break;
14770
14771 case DW_OP_addr:
14772 stack[++stacki] = read_address (objfile->obfd, &data[i],
14773 cu, &bytes_read);
14774 i += bytes_read;
14775 break;
14776
14777 case DW_OP_const1u:
14778 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
14779 i += 1;
14780 break;
14781
14782 case DW_OP_const1s:
14783 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
14784 i += 1;
14785 break;
14786
14787 case DW_OP_const2u:
14788 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
14789 i += 2;
14790 break;
14791
14792 case DW_OP_const2s:
14793 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
14794 i += 2;
14795 break;
14796
14797 case DW_OP_const4u:
14798 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
14799 i += 4;
14800 break;
14801
14802 case DW_OP_const4s:
14803 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
14804 i += 4;
14805 break;
14806
14807 case DW_OP_const8u:
14808 stack[++stacki] = read_8_bytes (objfile->obfd, &data[i]);
14809 i += 8;
14810 break;
14811
14812 case DW_OP_constu:
14813 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
14814 &bytes_read);
14815 i += bytes_read;
14816 break;
14817
14818 case DW_OP_consts:
14819 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
14820 i += bytes_read;
14821 break;
14822
14823 case DW_OP_dup:
14824 stack[stacki + 1] = stack[stacki];
14825 stacki++;
14826 break;
14827
14828 case DW_OP_plus:
14829 stack[stacki - 1] += stack[stacki];
14830 stacki--;
14831 break;
14832
14833 case DW_OP_plus_uconst:
14834 stack[stacki] += read_unsigned_leb128 (NULL, (data + i),
14835 &bytes_read);
14836 i += bytes_read;
14837 break;
14838
14839 case DW_OP_minus:
14840 stack[stacki - 1] -= stack[stacki];
14841 stacki--;
14842 break;
14843
14844 case DW_OP_deref:
14845 /* If we're not the last op, then we definitely can't encode
14846 this using GDB's address_class enum. This is valid for partial
14847 global symbols, although the variable's address will be bogus
14848 in the psymtab. */
14849 if (i < size)
14850 dwarf2_complex_location_expr_complaint ();
14851 break;
14852
14853 case DW_OP_GNU_push_tls_address:
14854 /* The top of the stack has the offset from the beginning
14855 of the thread control block at which the variable is located. */
14856 /* Nothing should follow this operator, so the top of stack would
14857 be returned. */
14858 /* This is valid for partial global symbols, but the variable's
14859 address will be bogus in the psymtab. Make it always at least
14860 non-zero to not look as a variable garbage collected by linker
14861 which have DW_OP_addr 0. */
14862 if (i < size)
14863 dwarf2_complex_location_expr_complaint ();
14864 stack[stacki]++;
14865 break;
14866
14867 case DW_OP_GNU_uninit:
14868 break;
14869
14870 default:
14871 {
14872 const char *name = dwarf_stack_op_name (op);
14873
14874 if (name)
14875 complaint (&symfile_complaints, _("unsupported stack op: '%s'"),
14876 name);
14877 else
14878 complaint (&symfile_complaints, _("unsupported stack op: '%02x'"),
14879 op);
14880 }
14881
14882 return (stack[stacki]);
14883 }
14884
14885 /* Enforce maximum stack depth of SIZE-1 to avoid writing
14886 outside of the allocated space. Also enforce minimum>0. */
14887 if (stacki >= ARRAY_SIZE (stack) - 1)
14888 {
14889 complaint (&symfile_complaints,
14890 _("location description stack overflow"));
14891 return 0;
14892 }
14893
14894 if (stacki <= 0)
14895 {
14896 complaint (&symfile_complaints,
14897 _("location description stack underflow"));
14898 return 0;
14899 }
14900 }
14901 return (stack[stacki]);
14902 }
14903
14904 /* memory allocation interface */
14905
14906 static struct dwarf_block *
14907 dwarf_alloc_block (struct dwarf2_cu *cu)
14908 {
14909 struct dwarf_block *blk;
14910
14911 blk = (struct dwarf_block *)
14912 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block));
14913 return (blk);
14914 }
14915
14916 static struct abbrev_info *
14917 dwarf_alloc_abbrev (struct dwarf2_cu *cu)
14918 {
14919 struct abbrev_info *abbrev;
14920
14921 abbrev = (struct abbrev_info *)
14922 obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info));
14923 memset (abbrev, 0, sizeof (struct abbrev_info));
14924 return (abbrev);
14925 }
14926
14927 static struct die_info *
14928 dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs)
14929 {
14930 struct die_info *die;
14931 size_t size = sizeof (struct die_info);
14932
14933 if (num_attrs > 1)
14934 size += (num_attrs - 1) * sizeof (struct attribute);
14935
14936 die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size);
14937 memset (die, 0, sizeof (struct die_info));
14938 return (die);
14939 }
14940
14941 \f
14942 /* Macro support. */
14943
14944 /* Return the full name of file number I in *LH's file name table.
14945 Use COMP_DIR as the name of the current directory of the
14946 compilation. The result is allocated using xmalloc; the caller is
14947 responsible for freeing it. */
14948 static char *
14949 file_full_name (int file, struct line_header *lh, const char *comp_dir)
14950 {
14951 /* Is the file number a valid index into the line header's file name
14952 table? Remember that file numbers start with one, not zero. */
14953 if (1 <= file && file <= lh->num_file_names)
14954 {
14955 struct file_entry *fe = &lh->file_names[file - 1];
14956
14957 if (IS_ABSOLUTE_PATH (fe->name))
14958 return xstrdup (fe->name);
14959 else
14960 {
14961 const char *dir;
14962 int dir_len;
14963 char *full_name;
14964
14965 if (fe->dir_index)
14966 dir = lh->include_dirs[fe->dir_index - 1];
14967 else
14968 dir = comp_dir;
14969
14970 if (dir)
14971 {
14972 dir_len = strlen (dir);
14973 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
14974 strcpy (full_name, dir);
14975 full_name[dir_len] = '/';
14976 strcpy (full_name + dir_len + 1, fe->name);
14977 return full_name;
14978 }
14979 else
14980 return xstrdup (fe->name);
14981 }
14982 }
14983 else
14984 {
14985 /* The compiler produced a bogus file number. We can at least
14986 record the macro definitions made in the file, even if we
14987 won't be able to find the file by name. */
14988 char fake_name[80];
14989
14990 sprintf (fake_name, "<bad macro file number %d>", file);
14991
14992 complaint (&symfile_complaints,
14993 _("bad file number in macro information (%d)"),
14994 file);
14995
14996 return xstrdup (fake_name);
14997 }
14998 }
14999
15000
15001 static struct macro_source_file *
15002 macro_start_file (int file, int line,
15003 struct macro_source_file *current_file,
15004 const char *comp_dir,
15005 struct line_header *lh, struct objfile *objfile)
15006 {
15007 /* The full name of this source file. */
15008 char *full_name = file_full_name (file, lh, comp_dir);
15009
15010 /* We don't create a macro table for this compilation unit
15011 at all until we actually get a filename. */
15012 if (! pending_macros)
15013 pending_macros = new_macro_table (&objfile->objfile_obstack,
15014 objfile->macro_cache);
15015
15016 if (! current_file)
15017 /* If we have no current file, then this must be the start_file
15018 directive for the compilation unit's main source file. */
15019 current_file = macro_set_main (pending_macros, full_name);
15020 else
15021 current_file = macro_include (current_file, line, full_name);
15022
15023 xfree (full_name);
15024
15025 return current_file;
15026 }
15027
15028
15029 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
15030 followed by a null byte. */
15031 static char *
15032 copy_string (const char *buf, int len)
15033 {
15034 char *s = xmalloc (len + 1);
15035
15036 memcpy (s, buf, len);
15037 s[len] = '\0';
15038 return s;
15039 }
15040
15041
15042 static const char *
15043 consume_improper_spaces (const char *p, const char *body)
15044 {
15045 if (*p == ' ')
15046 {
15047 complaint (&symfile_complaints,
15048 _("macro definition contains spaces "
15049 "in formal argument list:\n`%s'"),
15050 body);
15051
15052 while (*p == ' ')
15053 p++;
15054 }
15055
15056 return p;
15057 }
15058
15059
15060 static void
15061 parse_macro_definition (struct macro_source_file *file, int line,
15062 const char *body)
15063 {
15064 const char *p;
15065
15066 /* The body string takes one of two forms. For object-like macro
15067 definitions, it should be:
15068
15069 <macro name> " " <definition>
15070
15071 For function-like macro definitions, it should be:
15072
15073 <macro name> "() " <definition>
15074 or
15075 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
15076
15077 Spaces may appear only where explicitly indicated, and in the
15078 <definition>.
15079
15080 The Dwarf 2 spec says that an object-like macro's name is always
15081 followed by a space, but versions of GCC around March 2002 omit
15082 the space when the macro's definition is the empty string.
15083
15084 The Dwarf 2 spec says that there should be no spaces between the
15085 formal arguments in a function-like macro's formal argument list,
15086 but versions of GCC around March 2002 include spaces after the
15087 commas. */
15088
15089
15090 /* Find the extent of the macro name. The macro name is terminated
15091 by either a space or null character (for an object-like macro) or
15092 an opening paren (for a function-like macro). */
15093 for (p = body; *p; p++)
15094 if (*p == ' ' || *p == '(')
15095 break;
15096
15097 if (*p == ' ' || *p == '\0')
15098 {
15099 /* It's an object-like macro. */
15100 int name_len = p - body;
15101 char *name = copy_string (body, name_len);
15102 const char *replacement;
15103
15104 if (*p == ' ')
15105 replacement = body + name_len + 1;
15106 else
15107 {
15108 dwarf2_macro_malformed_definition_complaint (body);
15109 replacement = body + name_len;
15110 }
15111
15112 macro_define_object (file, line, name, replacement);
15113
15114 xfree (name);
15115 }
15116 else if (*p == '(')
15117 {
15118 /* It's a function-like macro. */
15119 char *name = copy_string (body, p - body);
15120 int argc = 0;
15121 int argv_size = 1;
15122 char **argv = xmalloc (argv_size * sizeof (*argv));
15123
15124 p++;
15125
15126 p = consume_improper_spaces (p, body);
15127
15128 /* Parse the formal argument list. */
15129 while (*p && *p != ')')
15130 {
15131 /* Find the extent of the current argument name. */
15132 const char *arg_start = p;
15133
15134 while (*p && *p != ',' && *p != ')' && *p != ' ')
15135 p++;
15136
15137 if (! *p || p == arg_start)
15138 dwarf2_macro_malformed_definition_complaint (body);
15139 else
15140 {
15141 /* Make sure argv has room for the new argument. */
15142 if (argc >= argv_size)
15143 {
15144 argv_size *= 2;
15145 argv = xrealloc (argv, argv_size * sizeof (*argv));
15146 }
15147
15148 argv[argc++] = copy_string (arg_start, p - arg_start);
15149 }
15150
15151 p = consume_improper_spaces (p, body);
15152
15153 /* Consume the comma, if present. */
15154 if (*p == ',')
15155 {
15156 p++;
15157
15158 p = consume_improper_spaces (p, body);
15159 }
15160 }
15161
15162 if (*p == ')')
15163 {
15164 p++;
15165
15166 if (*p == ' ')
15167 /* Perfectly formed definition, no complaints. */
15168 macro_define_function (file, line, name,
15169 argc, (const char **) argv,
15170 p + 1);
15171 else if (*p == '\0')
15172 {
15173 /* Complain, but do define it. */
15174 dwarf2_macro_malformed_definition_complaint (body);
15175 macro_define_function (file, line, name,
15176 argc, (const char **) argv,
15177 p);
15178 }
15179 else
15180 /* Just complain. */
15181 dwarf2_macro_malformed_definition_complaint (body);
15182 }
15183 else
15184 /* Just complain. */
15185 dwarf2_macro_malformed_definition_complaint (body);
15186
15187 xfree (name);
15188 {
15189 int i;
15190
15191 for (i = 0; i < argc; i++)
15192 xfree (argv[i]);
15193 }
15194 xfree (argv);
15195 }
15196 else
15197 dwarf2_macro_malformed_definition_complaint (body);
15198 }
15199
15200 /* Skip some bytes from BYTES according to the form given in FORM.
15201 Returns the new pointer. */
15202
15203 static gdb_byte *
15204 skip_form_bytes (bfd *abfd, gdb_byte *bytes,
15205 enum dwarf_form form,
15206 unsigned int offset_size,
15207 struct dwarf2_section_info *section)
15208 {
15209 unsigned int bytes_read;
15210
15211 switch (form)
15212 {
15213 case DW_FORM_data1:
15214 case DW_FORM_flag:
15215 ++bytes;
15216 break;
15217
15218 case DW_FORM_data2:
15219 bytes += 2;
15220 break;
15221
15222 case DW_FORM_data4:
15223 bytes += 4;
15224 break;
15225
15226 case DW_FORM_data8:
15227 bytes += 8;
15228 break;
15229
15230 case DW_FORM_string:
15231 read_direct_string (abfd, bytes, &bytes_read);
15232 bytes += bytes_read;
15233 break;
15234
15235 case DW_FORM_sec_offset:
15236 case DW_FORM_strp:
15237 bytes += offset_size;
15238 break;
15239
15240 case DW_FORM_block:
15241 bytes += read_unsigned_leb128 (abfd, bytes, &bytes_read);
15242 bytes += bytes_read;
15243 break;
15244
15245 case DW_FORM_block1:
15246 bytes += 1 + read_1_byte (abfd, bytes);
15247 break;
15248 case DW_FORM_block2:
15249 bytes += 2 + read_2_bytes (abfd, bytes);
15250 break;
15251 case DW_FORM_block4:
15252 bytes += 4 + read_4_bytes (abfd, bytes);
15253 break;
15254
15255 case DW_FORM_sdata:
15256 case DW_FORM_udata:
15257 bytes = skip_leb128 (abfd, bytes);
15258 break;
15259
15260 default:
15261 {
15262 complain:
15263 complaint (&symfile_complaints,
15264 _("invalid form 0x%x in `%s'"),
15265 form,
15266 section->asection->name);
15267 return NULL;
15268 }
15269 }
15270
15271 return bytes;
15272 }
15273
15274 /* A helper for dwarf_decode_macros that handles skipping an unknown
15275 opcode. Returns an updated pointer to the macro data buffer; or,
15276 on error, issues a complaint and returns NULL. */
15277
15278 static gdb_byte *
15279 skip_unknown_opcode (unsigned int opcode,
15280 gdb_byte **opcode_definitions,
15281 gdb_byte *mac_ptr,
15282 bfd *abfd,
15283 unsigned int offset_size,
15284 struct dwarf2_section_info *section)
15285 {
15286 unsigned int bytes_read, i;
15287 unsigned long arg;
15288 gdb_byte *defn;
15289
15290 if (opcode_definitions[opcode] == NULL)
15291 {
15292 complaint (&symfile_complaints,
15293 _("unrecognized DW_MACFINO opcode 0x%x"),
15294 opcode);
15295 return NULL;
15296 }
15297
15298 defn = opcode_definitions[opcode];
15299 arg = read_unsigned_leb128 (abfd, defn, &bytes_read);
15300 defn += bytes_read;
15301
15302 for (i = 0; i < arg; ++i)
15303 {
15304 mac_ptr = skip_form_bytes (abfd, mac_ptr, defn[i], offset_size, section);
15305 if (mac_ptr == NULL)
15306 {
15307 /* skip_form_bytes already issued the complaint. */
15308 return NULL;
15309 }
15310 }
15311
15312 return mac_ptr;
15313 }
15314
15315 /* A helper function which parses the header of a macro section.
15316 If the macro section is the extended (for now called "GNU") type,
15317 then this updates *OFFSET_SIZE. Returns a pointer to just after
15318 the header, or issues a complaint and returns NULL on error. */
15319
15320 static gdb_byte *
15321 dwarf_parse_macro_header (gdb_byte **opcode_definitions,
15322 bfd *abfd,
15323 gdb_byte *mac_ptr,
15324 unsigned int *offset_size,
15325 int section_is_gnu)
15326 {
15327 memset (opcode_definitions, 0, 256 * sizeof (gdb_byte *));
15328
15329 if (section_is_gnu)
15330 {
15331 unsigned int version, flags;
15332
15333 version = read_2_bytes (abfd, mac_ptr);
15334 if (version != 4)
15335 {
15336 complaint (&symfile_complaints,
15337 _("unrecognized version `%d' in .debug_macro section"),
15338 version);
15339 return NULL;
15340 }
15341 mac_ptr += 2;
15342
15343 flags = read_1_byte (abfd, mac_ptr);
15344 ++mac_ptr;
15345 *offset_size = (flags & 1) ? 8 : 4;
15346
15347 if ((flags & 2) != 0)
15348 /* We don't need the line table offset. */
15349 mac_ptr += *offset_size;
15350
15351 /* Vendor opcode descriptions. */
15352 if ((flags & 4) != 0)
15353 {
15354 unsigned int i, count;
15355
15356 count = read_1_byte (abfd, mac_ptr);
15357 ++mac_ptr;
15358 for (i = 0; i < count; ++i)
15359 {
15360 unsigned int opcode, bytes_read;
15361 unsigned long arg;
15362
15363 opcode = read_1_byte (abfd, mac_ptr);
15364 ++mac_ptr;
15365 opcode_definitions[opcode] = mac_ptr;
15366 arg = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15367 mac_ptr += bytes_read;
15368 mac_ptr += arg;
15369 }
15370 }
15371 }
15372
15373 return mac_ptr;
15374 }
15375
15376 /* A helper for dwarf_decode_macros that handles the GNU extensions,
15377 including DW_MACRO_GNU_transparent_include. */
15378
15379 static void
15380 dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end,
15381 struct macro_source_file *current_file,
15382 struct line_header *lh, char *comp_dir,
15383 struct dwarf2_section_info *section,
15384 int section_is_gnu,
15385 unsigned int offset_size,
15386 struct objfile *objfile,
15387 htab_t include_hash)
15388 {
15389 enum dwarf_macro_record_type macinfo_type;
15390 int at_commandline;
15391 gdb_byte *opcode_definitions[256];
15392
15393 mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr,
15394 &offset_size, section_is_gnu);
15395 if (mac_ptr == NULL)
15396 {
15397 /* We already issued a complaint. */
15398 return;
15399 }
15400
15401 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
15402 GDB is still reading the definitions from command line. First
15403 DW_MACINFO_start_file will need to be ignored as it was already executed
15404 to create CURRENT_FILE for the main source holding also the command line
15405 definitions. On first met DW_MACINFO_start_file this flag is reset to
15406 normally execute all the remaining DW_MACINFO_start_file macinfos. */
15407
15408 at_commandline = 1;
15409
15410 do
15411 {
15412 /* Do we at least have room for a macinfo type byte? */
15413 if (mac_ptr >= mac_end)
15414 {
15415 dwarf2_macros_too_long_complaint (section);
15416 break;
15417 }
15418
15419 macinfo_type = read_1_byte (abfd, mac_ptr);
15420 mac_ptr++;
15421
15422 /* Note that we rely on the fact that the corresponding GNU and
15423 DWARF constants are the same. */
15424 switch (macinfo_type)
15425 {
15426 /* A zero macinfo type indicates the end of the macro
15427 information. */
15428 case 0:
15429 break;
15430
15431 case DW_MACRO_GNU_define:
15432 case DW_MACRO_GNU_undef:
15433 case DW_MACRO_GNU_define_indirect:
15434 case DW_MACRO_GNU_undef_indirect:
15435 {
15436 unsigned int bytes_read;
15437 int line;
15438 char *body;
15439 int is_define;
15440
15441 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15442 mac_ptr += bytes_read;
15443
15444 if (macinfo_type == DW_MACRO_GNU_define
15445 || macinfo_type == DW_MACRO_GNU_undef)
15446 {
15447 body = read_direct_string (abfd, mac_ptr, &bytes_read);
15448 mac_ptr += bytes_read;
15449 }
15450 else
15451 {
15452 LONGEST str_offset;
15453
15454 str_offset = read_offset_1 (abfd, mac_ptr, offset_size);
15455 mac_ptr += offset_size;
15456
15457 body = read_indirect_string_at_offset (abfd, str_offset);
15458 }
15459
15460 is_define = (macinfo_type == DW_MACRO_GNU_define
15461 || macinfo_type == DW_MACRO_GNU_define_indirect);
15462 if (! current_file)
15463 {
15464 /* DWARF violation as no main source is present. */
15465 complaint (&symfile_complaints,
15466 _("debug info with no main source gives macro %s "
15467 "on line %d: %s"),
15468 is_define ? _("definition") : _("undefinition"),
15469 line, body);
15470 break;
15471 }
15472 if ((line == 0 && !at_commandline)
15473 || (line != 0 && at_commandline))
15474 complaint (&symfile_complaints,
15475 _("debug info gives %s macro %s with %s line %d: %s"),
15476 at_commandline ? _("command-line") : _("in-file"),
15477 is_define ? _("definition") : _("undefinition"),
15478 line == 0 ? _("zero") : _("non-zero"), line, body);
15479
15480 if (is_define)
15481 parse_macro_definition (current_file, line, body);
15482 else
15483 {
15484 gdb_assert (macinfo_type == DW_MACRO_GNU_undef
15485 || macinfo_type == DW_MACRO_GNU_undef_indirect);
15486 macro_undef (current_file, line, body);
15487 }
15488 }
15489 break;
15490
15491 case DW_MACRO_GNU_start_file:
15492 {
15493 unsigned int bytes_read;
15494 int line, file;
15495
15496 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15497 mac_ptr += bytes_read;
15498 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15499 mac_ptr += bytes_read;
15500
15501 if ((line == 0 && !at_commandline)
15502 || (line != 0 && at_commandline))
15503 complaint (&symfile_complaints,
15504 _("debug info gives source %d included "
15505 "from %s at %s line %d"),
15506 file, at_commandline ? _("command-line") : _("file"),
15507 line == 0 ? _("zero") : _("non-zero"), line);
15508
15509 if (at_commandline)
15510 {
15511 /* This DW_MACRO_GNU_start_file was executed in the
15512 pass one. */
15513 at_commandline = 0;
15514 }
15515 else
15516 current_file = macro_start_file (file, line,
15517 current_file, comp_dir,
15518 lh, objfile);
15519 }
15520 break;
15521
15522 case DW_MACRO_GNU_end_file:
15523 if (! current_file)
15524 complaint (&symfile_complaints,
15525 _("macro debug info has an unmatched "
15526 "`close_file' directive"));
15527 else
15528 {
15529 current_file = current_file->included_by;
15530 if (! current_file)
15531 {
15532 enum dwarf_macro_record_type next_type;
15533
15534 /* GCC circa March 2002 doesn't produce the zero
15535 type byte marking the end of the compilation
15536 unit. Complain if it's not there, but exit no
15537 matter what. */
15538
15539 /* Do we at least have room for a macinfo type byte? */
15540 if (mac_ptr >= mac_end)
15541 {
15542 dwarf2_macros_too_long_complaint (section);
15543 return;
15544 }
15545
15546 /* We don't increment mac_ptr here, so this is just
15547 a look-ahead. */
15548 next_type = read_1_byte (abfd, mac_ptr);
15549 if (next_type != 0)
15550 complaint (&symfile_complaints,
15551 _("no terminating 0-type entry for "
15552 "macros in `.debug_macinfo' section"));
15553
15554 return;
15555 }
15556 }
15557 break;
15558
15559 case DW_MACRO_GNU_transparent_include:
15560 {
15561 LONGEST offset;
15562 void **slot;
15563
15564 offset = read_offset_1 (abfd, mac_ptr, offset_size);
15565 mac_ptr += offset_size;
15566
15567 slot = htab_find_slot (include_hash, mac_ptr, INSERT);
15568 if (*slot != NULL)
15569 {
15570 /* This has actually happened; see
15571 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
15572 complaint (&symfile_complaints,
15573 _("recursive DW_MACRO_GNU_transparent_include in "
15574 ".debug_macro section"));
15575 }
15576 else
15577 {
15578 *slot = mac_ptr;
15579
15580 dwarf_decode_macro_bytes (abfd,
15581 section->buffer + offset,
15582 mac_end, current_file,
15583 lh, comp_dir,
15584 section, section_is_gnu,
15585 offset_size, objfile, include_hash);
15586
15587 htab_remove_elt (include_hash, mac_ptr);
15588 }
15589 }
15590 break;
15591
15592 case DW_MACINFO_vendor_ext:
15593 if (!section_is_gnu)
15594 {
15595 unsigned int bytes_read;
15596 int constant;
15597
15598 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15599 mac_ptr += bytes_read;
15600 read_direct_string (abfd, mac_ptr, &bytes_read);
15601 mac_ptr += bytes_read;
15602
15603 /* We don't recognize any vendor extensions. */
15604 break;
15605 }
15606 /* FALLTHROUGH */
15607
15608 default:
15609 mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions,
15610 mac_ptr, abfd, offset_size,
15611 section);
15612 if (mac_ptr == NULL)
15613 return;
15614 break;
15615 }
15616 } while (macinfo_type != 0);
15617 }
15618
15619 static void
15620 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
15621 char *comp_dir, bfd *abfd,
15622 struct dwarf2_cu *cu,
15623 struct dwarf2_section_info *section,
15624 int section_is_gnu)
15625 {
15626 struct objfile *objfile = dwarf2_per_objfile->objfile;
15627 gdb_byte *mac_ptr, *mac_end;
15628 struct macro_source_file *current_file = 0;
15629 enum dwarf_macro_record_type macinfo_type;
15630 unsigned int offset_size = cu->header.offset_size;
15631 gdb_byte *opcode_definitions[256];
15632 struct cleanup *cleanup;
15633 htab_t include_hash;
15634 void **slot;
15635
15636 dwarf2_read_section (objfile, section);
15637 if (section->buffer == NULL)
15638 {
15639 complaint (&symfile_complaints, _("missing %s section"),
15640 section->asection->name);
15641 return;
15642 }
15643
15644 /* First pass: Find the name of the base filename.
15645 This filename is needed in order to process all macros whose definition
15646 (or undefinition) comes from the command line. These macros are defined
15647 before the first DW_MACINFO_start_file entry, and yet still need to be
15648 associated to the base file.
15649
15650 To determine the base file name, we scan the macro definitions until we
15651 reach the first DW_MACINFO_start_file entry. We then initialize
15652 CURRENT_FILE accordingly so that any macro definition found before the
15653 first DW_MACINFO_start_file can still be associated to the base file. */
15654
15655 mac_ptr = section->buffer + offset;
15656 mac_end = section->buffer + section->size;
15657
15658 mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr,
15659 &offset_size, section_is_gnu);
15660 if (mac_ptr == NULL)
15661 {
15662 /* We already issued a complaint. */
15663 return;
15664 }
15665
15666 do
15667 {
15668 /* Do we at least have room for a macinfo type byte? */
15669 if (mac_ptr >= mac_end)
15670 {
15671 /* Complaint is printed during the second pass as GDB will probably
15672 stop the first pass earlier upon finding
15673 DW_MACINFO_start_file. */
15674 break;
15675 }
15676
15677 macinfo_type = read_1_byte (abfd, mac_ptr);
15678 mac_ptr++;
15679
15680 /* Note that we rely on the fact that the corresponding GNU and
15681 DWARF constants are the same. */
15682 switch (macinfo_type)
15683 {
15684 /* A zero macinfo type indicates the end of the macro
15685 information. */
15686 case 0:
15687 break;
15688
15689 case DW_MACRO_GNU_define:
15690 case DW_MACRO_GNU_undef:
15691 /* Only skip the data by MAC_PTR. */
15692 {
15693 unsigned int bytes_read;
15694
15695 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15696 mac_ptr += bytes_read;
15697 read_direct_string (abfd, mac_ptr, &bytes_read);
15698 mac_ptr += bytes_read;
15699 }
15700 break;
15701
15702 case DW_MACRO_GNU_start_file:
15703 {
15704 unsigned int bytes_read;
15705 int line, file;
15706
15707 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15708 mac_ptr += bytes_read;
15709 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15710 mac_ptr += bytes_read;
15711
15712 current_file = macro_start_file (file, line, current_file,
15713 comp_dir, lh, objfile);
15714 }
15715 break;
15716
15717 case DW_MACRO_GNU_end_file:
15718 /* No data to skip by MAC_PTR. */
15719 break;
15720
15721 case DW_MACRO_GNU_define_indirect:
15722 case DW_MACRO_GNU_undef_indirect:
15723 {
15724 unsigned int bytes_read;
15725
15726 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15727 mac_ptr += bytes_read;
15728 mac_ptr += offset_size;
15729 }
15730 break;
15731
15732 case DW_MACRO_GNU_transparent_include:
15733 /* Note that, according to the spec, a transparent include
15734 chain cannot call DW_MACRO_GNU_start_file. So, we can just
15735 skip this opcode. */
15736 mac_ptr += offset_size;
15737 break;
15738
15739 case DW_MACINFO_vendor_ext:
15740 /* Only skip the data by MAC_PTR. */
15741 if (!section_is_gnu)
15742 {
15743 unsigned int bytes_read;
15744
15745 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15746 mac_ptr += bytes_read;
15747 read_direct_string (abfd, mac_ptr, &bytes_read);
15748 mac_ptr += bytes_read;
15749 }
15750 /* FALLTHROUGH */
15751
15752 default:
15753 mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions,
15754 mac_ptr, abfd, offset_size,
15755 section);
15756 if (mac_ptr == NULL)
15757 return;
15758 break;
15759 }
15760 } while (macinfo_type != 0 && current_file == NULL);
15761
15762 /* Second pass: Process all entries.
15763
15764 Use the AT_COMMAND_LINE flag to determine whether we are still processing
15765 command-line macro definitions/undefinitions. This flag is unset when we
15766 reach the first DW_MACINFO_start_file entry. */
15767
15768 include_hash = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer,
15769 NULL, xcalloc, xfree);
15770 cleanup = make_cleanup_htab_delete (include_hash);
15771 mac_ptr = section->buffer + offset;
15772 slot = htab_find_slot (include_hash, mac_ptr, INSERT);
15773 *slot = mac_ptr;
15774 dwarf_decode_macro_bytes (abfd, mac_ptr, mac_end,
15775 current_file, lh, comp_dir, section, section_is_gnu,
15776 offset_size, objfile, include_hash);
15777 do_cleanups (cleanup);
15778 }
15779
15780 /* Check if the attribute's form is a DW_FORM_block*
15781 if so return true else false. */
15782
15783 static int
15784 attr_form_is_block (struct attribute *attr)
15785 {
15786 return (attr == NULL ? 0 :
15787 attr->form == DW_FORM_block1
15788 || attr->form == DW_FORM_block2
15789 || attr->form == DW_FORM_block4
15790 || attr->form == DW_FORM_block
15791 || attr->form == DW_FORM_exprloc);
15792 }
15793
15794 /* Return non-zero if ATTR's value is a section offset --- classes
15795 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
15796 You may use DW_UNSND (attr) to retrieve such offsets.
15797
15798 Section 7.5.4, "Attribute Encodings", explains that no attribute
15799 may have a value that belongs to more than one of these classes; it
15800 would be ambiguous if we did, because we use the same forms for all
15801 of them. */
15802
15803 static int
15804 attr_form_is_section_offset (struct attribute *attr)
15805 {
15806 return (attr->form == DW_FORM_data4
15807 || attr->form == DW_FORM_data8
15808 || attr->form == DW_FORM_sec_offset);
15809 }
15810
15811
15812 /* Return non-zero if ATTR's value falls in the 'constant' class, or
15813 zero otherwise. When this function returns true, you can apply
15814 dwarf2_get_attr_constant_value to it.
15815
15816 However, note that for some attributes you must check
15817 attr_form_is_section_offset before using this test. DW_FORM_data4
15818 and DW_FORM_data8 are members of both the constant class, and of
15819 the classes that contain offsets into other debug sections
15820 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
15821 that, if an attribute's can be either a constant or one of the
15822 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
15823 taken as section offsets, not constants. */
15824
15825 static int
15826 attr_form_is_constant (struct attribute *attr)
15827 {
15828 switch (attr->form)
15829 {
15830 case DW_FORM_sdata:
15831 case DW_FORM_udata:
15832 case DW_FORM_data1:
15833 case DW_FORM_data2:
15834 case DW_FORM_data4:
15835 case DW_FORM_data8:
15836 return 1;
15837 default:
15838 return 0;
15839 }
15840 }
15841
15842 /* A helper function that fills in a dwarf2_loclist_baton. */
15843
15844 static void
15845 fill_in_loclist_baton (struct dwarf2_cu *cu,
15846 struct dwarf2_loclist_baton *baton,
15847 struct attribute *attr)
15848 {
15849 dwarf2_read_section (dwarf2_per_objfile->objfile,
15850 &dwarf2_per_objfile->loc);
15851
15852 baton->per_cu = cu->per_cu;
15853 gdb_assert (baton->per_cu);
15854 /* We don't know how long the location list is, but make sure we
15855 don't run off the edge of the section. */
15856 baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr);
15857 baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr);
15858 baton->base_address = cu->base_address;
15859 }
15860
15861 static void
15862 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
15863 struct dwarf2_cu *cu)
15864 {
15865 struct objfile *objfile = dwarf2_per_objfile->objfile;
15866
15867 if (attr_form_is_section_offset (attr)
15868 /* ".debug_loc" may not exist at all, or the offset may be outside
15869 the section. If so, fall through to the complaint in the
15870 other branch. */
15871 && DW_UNSND (attr) < dwarf2_section_size (objfile,
15872 &dwarf2_per_objfile->loc))
15873 {
15874 struct dwarf2_loclist_baton *baton;
15875
15876 baton = obstack_alloc (&objfile->objfile_obstack,
15877 sizeof (struct dwarf2_loclist_baton));
15878
15879 fill_in_loclist_baton (cu, baton, attr);
15880
15881 if (cu->base_known == 0)
15882 complaint (&symfile_complaints,
15883 _("Location list used without "
15884 "specifying the CU base address."));
15885
15886 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs;
15887 SYMBOL_LOCATION_BATON (sym) = baton;
15888 }
15889 else
15890 {
15891 struct dwarf2_locexpr_baton *baton;
15892
15893 baton = obstack_alloc (&objfile->objfile_obstack,
15894 sizeof (struct dwarf2_locexpr_baton));
15895 baton->per_cu = cu->per_cu;
15896 gdb_assert (baton->per_cu);
15897
15898 if (attr_form_is_block (attr))
15899 {
15900 /* Note that we're just copying the block's data pointer
15901 here, not the actual data. We're still pointing into the
15902 info_buffer for SYM's objfile; right now we never release
15903 that buffer, but when we do clean up properly this may
15904 need to change. */
15905 baton->size = DW_BLOCK (attr)->size;
15906 baton->data = DW_BLOCK (attr)->data;
15907 }
15908 else
15909 {
15910 dwarf2_invalid_attrib_class_complaint ("location description",
15911 SYMBOL_NATURAL_NAME (sym));
15912 baton->size = 0;
15913 }
15914
15915 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
15916 SYMBOL_LOCATION_BATON (sym) = baton;
15917 }
15918 }
15919
15920 /* Return the OBJFILE associated with the compilation unit CU. If CU
15921 came from a separate debuginfo file, then the master objfile is
15922 returned. */
15923
15924 struct objfile *
15925 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
15926 {
15927 struct objfile *objfile = per_cu->objfile;
15928
15929 /* Return the master objfile, so that we can report and look up the
15930 correct file containing this variable. */
15931 if (objfile->separate_debug_objfile_backlink)
15932 objfile = objfile->separate_debug_objfile_backlink;
15933
15934 return objfile;
15935 }
15936
15937 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
15938 (CU_HEADERP is unused in such case) or prepare a temporary copy at
15939 CU_HEADERP first. */
15940
15941 static const struct comp_unit_head *
15942 per_cu_header_read_in (struct comp_unit_head *cu_headerp,
15943 struct dwarf2_per_cu_data *per_cu)
15944 {
15945 struct objfile *objfile;
15946 struct dwarf2_per_objfile *per_objfile;
15947 gdb_byte *info_ptr;
15948
15949 if (per_cu->cu)
15950 return &per_cu->cu->header;
15951
15952 objfile = per_cu->objfile;
15953 per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
15954 info_ptr = per_objfile->info.buffer + per_cu->offset.sect_off;
15955
15956 memset (cu_headerp, 0, sizeof (*cu_headerp));
15957 read_comp_unit_head (cu_headerp, info_ptr, objfile->obfd);
15958
15959 return cu_headerp;
15960 }
15961
15962 /* Return the address size given in the compilation unit header for CU. */
15963
15964 int
15965 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
15966 {
15967 struct comp_unit_head cu_header_local;
15968 const struct comp_unit_head *cu_headerp;
15969
15970 cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
15971
15972 return cu_headerp->addr_size;
15973 }
15974
15975 /* Return the offset size given in the compilation unit header for CU. */
15976
15977 int
15978 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
15979 {
15980 struct comp_unit_head cu_header_local;
15981 const struct comp_unit_head *cu_headerp;
15982
15983 cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
15984
15985 return cu_headerp->offset_size;
15986 }
15987
15988 /* See its dwarf2loc.h declaration. */
15989
15990 int
15991 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *per_cu)
15992 {
15993 struct comp_unit_head cu_header_local;
15994 const struct comp_unit_head *cu_headerp;
15995
15996 cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
15997
15998 if (cu_headerp->version == 2)
15999 return cu_headerp->addr_size;
16000 else
16001 return cu_headerp->offset_size;
16002 }
16003
16004 /* Return the text offset of the CU. The returned offset comes from
16005 this CU's objfile. If this objfile came from a separate debuginfo
16006 file, then the offset may be different from the corresponding
16007 offset in the parent objfile. */
16008
16009 CORE_ADDR
16010 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu)
16011 {
16012 struct objfile *objfile = per_cu->objfile;
16013
16014 return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
16015 }
16016
16017 /* Locate the .debug_info compilation unit from CU's objfile which contains
16018 the DIE at OFFSET. Raises an error on failure. */
16019
16020 static struct dwarf2_per_cu_data *
16021 dwarf2_find_containing_comp_unit (sect_offset offset,
16022 struct objfile *objfile)
16023 {
16024 struct dwarf2_per_cu_data *this_cu;
16025 int low, high;
16026
16027 low = 0;
16028 high = dwarf2_per_objfile->n_comp_units - 1;
16029 while (high > low)
16030 {
16031 int mid = low + (high - low) / 2;
16032
16033 if (dwarf2_per_objfile->all_comp_units[mid]->offset.sect_off
16034 >= offset.sect_off)
16035 high = mid;
16036 else
16037 low = mid + 1;
16038 }
16039 gdb_assert (low == high);
16040 if (dwarf2_per_objfile->all_comp_units[low]->offset.sect_off
16041 > offset.sect_off)
16042 {
16043 if (low == 0)
16044 error (_("Dwarf Error: could not find partial DIE containing "
16045 "offset 0x%lx [in module %s]"),
16046 (long) offset.sect_off, bfd_get_filename (objfile->obfd));
16047
16048 gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset.sect_off
16049 <= offset.sect_off);
16050 return dwarf2_per_objfile->all_comp_units[low-1];
16051 }
16052 else
16053 {
16054 this_cu = dwarf2_per_objfile->all_comp_units[low];
16055 if (low == dwarf2_per_objfile->n_comp_units - 1
16056 && offset.sect_off >= this_cu->offset.sect_off + this_cu->length)
16057 error (_("invalid dwarf2 offset %u"), offset.sect_off);
16058 gdb_assert (offset.sect_off < this_cu->offset.sect_off + this_cu->length);
16059 return this_cu;
16060 }
16061 }
16062
16063 /* Initialize dwarf2_cu CU, owned by PER_CU. */
16064
16065 static void
16066 init_one_comp_unit (struct dwarf2_cu *cu, struct dwarf2_per_cu_data *per_cu)
16067 {
16068 memset (cu, 0, sizeof (*cu));
16069 per_cu->cu = cu;
16070 cu->per_cu = per_cu;
16071 cu->objfile = per_cu->objfile;
16072 obstack_init (&cu->comp_unit_obstack);
16073 }
16074
16075 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
16076
16077 static void
16078 prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die)
16079 {
16080 struct attribute *attr;
16081
16082 /* Set the language we're debugging. */
16083 attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu);
16084 if (attr)
16085 set_cu_language (DW_UNSND (attr), cu);
16086 else
16087 {
16088 cu->language = language_minimal;
16089 cu->language_defn = language_def (cu->language);
16090 }
16091 }
16092
16093 /* Release one cached compilation unit, CU. We unlink it from the tree
16094 of compilation units, but we don't remove it from the read_in_chain;
16095 the caller is responsible for that.
16096 NOTE: DATA is a void * because this function is also used as a
16097 cleanup routine. */
16098
16099 static void
16100 free_heap_comp_unit (void *data)
16101 {
16102 struct dwarf2_cu *cu = data;
16103
16104 gdb_assert (cu->per_cu != NULL);
16105 cu->per_cu->cu = NULL;
16106 cu->per_cu = NULL;
16107
16108 obstack_free (&cu->comp_unit_obstack, NULL);
16109
16110 xfree (cu);
16111 }
16112
16113 /* This cleanup function is passed the address of a dwarf2_cu on the stack
16114 when we're finished with it. We can't free the pointer itself, but be
16115 sure to unlink it from the cache. Also release any associated storage
16116 and perform cache maintenance.
16117
16118 Only used during partial symbol parsing. */
16119
16120 static void
16121 free_stack_comp_unit (void *data)
16122 {
16123 struct dwarf2_cu *cu = data;
16124
16125 gdb_assert (cu->per_cu != NULL);
16126 cu->per_cu->cu = NULL;
16127 cu->per_cu = NULL;
16128
16129 obstack_free (&cu->comp_unit_obstack, NULL);
16130 cu->partial_dies = NULL;
16131
16132 /* The previous code only did this if per_cu != NULL.
16133 But that would always succeed, so now we just unconditionally do
16134 the aging. This seems like the wrong place to do such aging,
16135 but cleaning that up is left for later. */
16136 age_cached_comp_units ();
16137 }
16138
16139 /* Free all cached compilation units. */
16140
16141 static void
16142 free_cached_comp_units (void *data)
16143 {
16144 struct dwarf2_per_cu_data *per_cu, **last_chain;
16145
16146 per_cu = dwarf2_per_objfile->read_in_chain;
16147 last_chain = &dwarf2_per_objfile->read_in_chain;
16148 while (per_cu != NULL)
16149 {
16150 struct dwarf2_per_cu_data *next_cu;
16151
16152 next_cu = per_cu->cu->read_in_chain;
16153
16154 free_heap_comp_unit (per_cu->cu);
16155 *last_chain = next_cu;
16156
16157 per_cu = next_cu;
16158 }
16159 }
16160
16161 /* Increase the age counter on each cached compilation unit, and free
16162 any that are too old. */
16163
16164 static void
16165 age_cached_comp_units (void)
16166 {
16167 struct dwarf2_per_cu_data *per_cu, **last_chain;
16168
16169 dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain);
16170 per_cu = dwarf2_per_objfile->read_in_chain;
16171 while (per_cu != NULL)
16172 {
16173 per_cu->cu->last_used ++;
16174 if (per_cu->cu->last_used <= dwarf2_max_cache_age)
16175 dwarf2_mark (per_cu->cu);
16176 per_cu = per_cu->cu->read_in_chain;
16177 }
16178
16179 per_cu = dwarf2_per_objfile->read_in_chain;
16180 last_chain = &dwarf2_per_objfile->read_in_chain;
16181 while (per_cu != NULL)
16182 {
16183 struct dwarf2_per_cu_data *next_cu;
16184
16185 next_cu = per_cu->cu->read_in_chain;
16186
16187 if (!per_cu->cu->mark)
16188 {
16189 free_heap_comp_unit (per_cu->cu);
16190 *last_chain = next_cu;
16191 }
16192 else
16193 last_chain = &per_cu->cu->read_in_chain;
16194
16195 per_cu = next_cu;
16196 }
16197 }
16198
16199 /* Remove a single compilation unit from the cache. */
16200
16201 static void
16202 free_one_cached_comp_unit (void *target_cu)
16203 {
16204 struct dwarf2_per_cu_data *per_cu, **last_chain;
16205
16206 per_cu = dwarf2_per_objfile->read_in_chain;
16207 last_chain = &dwarf2_per_objfile->read_in_chain;
16208 while (per_cu != NULL)
16209 {
16210 struct dwarf2_per_cu_data *next_cu;
16211
16212 next_cu = per_cu->cu->read_in_chain;
16213
16214 if (per_cu->cu == target_cu)
16215 {
16216 free_heap_comp_unit (per_cu->cu);
16217 *last_chain = next_cu;
16218 break;
16219 }
16220 else
16221 last_chain = &per_cu->cu->read_in_chain;
16222
16223 per_cu = next_cu;
16224 }
16225 }
16226
16227 /* Release all extra memory associated with OBJFILE. */
16228
16229 void
16230 dwarf2_free_objfile (struct objfile *objfile)
16231 {
16232 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
16233
16234 if (dwarf2_per_objfile == NULL)
16235 return;
16236
16237 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
16238 free_cached_comp_units (NULL);
16239
16240 if (dwarf2_per_objfile->quick_file_names_table)
16241 htab_delete (dwarf2_per_objfile->quick_file_names_table);
16242
16243 /* Everything else should be on the objfile obstack. */
16244 }
16245
16246 /* A pair of DIE offset and GDB type pointer. We store these
16247 in a hash table separate from the DIEs, and preserve them
16248 when the DIEs are flushed out of cache. */
16249
16250 struct dwarf2_offset_and_type
16251 {
16252 sect_offset offset;
16253 struct type *type;
16254 };
16255
16256 /* Hash function for a dwarf2_offset_and_type. */
16257
16258 static hashval_t
16259 offset_and_type_hash (const void *item)
16260 {
16261 const struct dwarf2_offset_and_type *ofs = item;
16262
16263 return ofs->offset.sect_off;
16264 }
16265
16266 /* Equality function for a dwarf2_offset_and_type. */
16267
16268 static int
16269 offset_and_type_eq (const void *item_lhs, const void *item_rhs)
16270 {
16271 const struct dwarf2_offset_and_type *ofs_lhs = item_lhs;
16272 const struct dwarf2_offset_and_type *ofs_rhs = item_rhs;
16273
16274 return ofs_lhs->offset.sect_off == ofs_rhs->offset.sect_off;
16275 }
16276
16277 /* Set the type associated with DIE to TYPE. Save it in CU's hash
16278 table if necessary. For convenience, return TYPE.
16279
16280 The DIEs reading must have careful ordering to:
16281 * Not cause infite loops trying to read in DIEs as a prerequisite for
16282 reading current DIE.
16283 * Not trying to dereference contents of still incompletely read in types
16284 while reading in other DIEs.
16285 * Enable referencing still incompletely read in types just by a pointer to
16286 the type without accessing its fields.
16287
16288 Therefore caller should follow these rules:
16289 * Try to fetch any prerequisite types we may need to build this DIE type
16290 before building the type and calling set_die_type.
16291 * After building type call set_die_type for current DIE as soon as
16292 possible before fetching more types to complete the current type.
16293 * Make the type as complete as possible before fetching more types. */
16294
16295 static struct type *
16296 set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
16297 {
16298 struct dwarf2_offset_and_type **slot, ofs;
16299 struct objfile *objfile = cu->objfile;
16300 htab_t *type_hash_ptr;
16301
16302 /* For Ada types, make sure that the gnat-specific data is always
16303 initialized (if not already set). There are a few types where
16304 we should not be doing so, because the type-specific area is
16305 already used to hold some other piece of info (eg: TYPE_CODE_FLT
16306 where the type-specific area is used to store the floatformat).
16307 But this is not a problem, because the gnat-specific information
16308 is actually not needed for these types. */
16309 if (need_gnat_info (cu)
16310 && TYPE_CODE (type) != TYPE_CODE_FUNC
16311 && TYPE_CODE (type) != TYPE_CODE_FLT
16312 && !HAVE_GNAT_AUX_INFO (type))
16313 INIT_GNAT_SPECIFIC (type);
16314
16315 if (cu->per_cu->debug_types_section)
16316 type_hash_ptr = &dwarf2_per_objfile->debug_types_type_hash;
16317 else
16318 type_hash_ptr = &dwarf2_per_objfile->debug_info_type_hash;
16319
16320 if (*type_hash_ptr == NULL)
16321 {
16322 *type_hash_ptr
16323 = htab_create_alloc_ex (127,
16324 offset_and_type_hash,
16325 offset_and_type_eq,
16326 NULL,
16327 &objfile->objfile_obstack,
16328 hashtab_obstack_allocate,
16329 dummy_obstack_deallocate);
16330 }
16331
16332 ofs.offset = die->offset;
16333 ofs.type = type;
16334 slot = (struct dwarf2_offset_and_type **)
16335 htab_find_slot_with_hash (*type_hash_ptr, &ofs, ofs.offset.sect_off,
16336 INSERT);
16337 if (*slot)
16338 complaint (&symfile_complaints,
16339 _("A problem internal to GDB: DIE 0x%x has type already set"),
16340 die->offset.sect_off);
16341 *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot));
16342 **slot = ofs;
16343 return type;
16344 }
16345
16346 /* Look up the type for the die at OFFSET in the appropriate type_hash
16347 table, or return NULL if the die does not have a saved type. */
16348
16349 static struct type *
16350 get_die_type_at_offset (sect_offset offset,
16351 struct dwarf2_per_cu_data *per_cu)
16352 {
16353 struct dwarf2_offset_and_type *slot, ofs;
16354 htab_t type_hash;
16355
16356 if (per_cu->debug_types_section)
16357 type_hash = dwarf2_per_objfile->debug_types_type_hash;
16358 else
16359 type_hash = dwarf2_per_objfile->debug_info_type_hash;
16360 if (type_hash == NULL)
16361 return NULL;
16362
16363 ofs.offset = offset;
16364 slot = htab_find_with_hash (type_hash, &ofs, ofs.offset.sect_off);
16365 if (slot)
16366 return slot->type;
16367 else
16368 return NULL;
16369 }
16370
16371 /* Look up the type for DIE in the appropriate type_hash table,
16372 or return NULL if DIE does not have a saved type. */
16373
16374 static struct type *
16375 get_die_type (struct die_info *die, struct dwarf2_cu *cu)
16376 {
16377 return get_die_type_at_offset (die->offset, cu->per_cu);
16378 }
16379
16380 /* Add a dependence relationship from CU to REF_PER_CU. */
16381
16382 static void
16383 dwarf2_add_dependence (struct dwarf2_cu *cu,
16384 struct dwarf2_per_cu_data *ref_per_cu)
16385 {
16386 void **slot;
16387
16388 if (cu->dependencies == NULL)
16389 cu->dependencies
16390 = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer,
16391 NULL, &cu->comp_unit_obstack,
16392 hashtab_obstack_allocate,
16393 dummy_obstack_deallocate);
16394
16395 slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT);
16396 if (*slot == NULL)
16397 *slot = ref_per_cu;
16398 }
16399
16400 /* Subroutine of dwarf2_mark to pass to htab_traverse.
16401 Set the mark field in every compilation unit in the
16402 cache that we must keep because we are keeping CU. */
16403
16404 static int
16405 dwarf2_mark_helper (void **slot, void *data)
16406 {
16407 struct dwarf2_per_cu_data *per_cu;
16408
16409 per_cu = (struct dwarf2_per_cu_data *) *slot;
16410
16411 /* cu->dependencies references may not yet have been ever read if QUIT aborts
16412 reading of the chain. As such dependencies remain valid it is not much
16413 useful to track and undo them during QUIT cleanups. */
16414 if (per_cu->cu == NULL)
16415 return 1;
16416
16417 if (per_cu->cu->mark)
16418 return 1;
16419 per_cu->cu->mark = 1;
16420
16421 if (per_cu->cu->dependencies != NULL)
16422 htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL);
16423
16424 return 1;
16425 }
16426
16427 /* Set the mark field in CU and in every other compilation unit in the
16428 cache that we must keep because we are keeping CU. */
16429
16430 static void
16431 dwarf2_mark (struct dwarf2_cu *cu)
16432 {
16433 if (cu->mark)
16434 return;
16435 cu->mark = 1;
16436 if (cu->dependencies != NULL)
16437 htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL);
16438 }
16439
16440 static void
16441 dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu)
16442 {
16443 while (per_cu)
16444 {
16445 per_cu->cu->mark = 0;
16446 per_cu = per_cu->cu->read_in_chain;
16447 }
16448 }
16449
16450 /* Trivial hash function for partial_die_info: the hash value of a DIE
16451 is its offset in .debug_info for this objfile. */
16452
16453 static hashval_t
16454 partial_die_hash (const void *item)
16455 {
16456 const struct partial_die_info *part_die = item;
16457
16458 return part_die->offset.sect_off;
16459 }
16460
16461 /* Trivial comparison function for partial_die_info structures: two DIEs
16462 are equal if they have the same offset. */
16463
16464 static int
16465 partial_die_eq (const void *item_lhs, const void *item_rhs)
16466 {
16467 const struct partial_die_info *part_die_lhs = item_lhs;
16468 const struct partial_die_info *part_die_rhs = item_rhs;
16469
16470 return part_die_lhs->offset.sect_off == part_die_rhs->offset.sect_off;
16471 }
16472
16473 static struct cmd_list_element *set_dwarf2_cmdlist;
16474 static struct cmd_list_element *show_dwarf2_cmdlist;
16475
16476 static void
16477 set_dwarf2_cmd (char *args, int from_tty)
16478 {
16479 help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout);
16480 }
16481
16482 static void
16483 show_dwarf2_cmd (char *args, int from_tty)
16484 {
16485 cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
16486 }
16487
16488 /* If section described by INFO was mmapped, munmap it now. */
16489
16490 static void
16491 munmap_section_buffer (struct dwarf2_section_info *info)
16492 {
16493 if (info->map_addr != NULL)
16494 {
16495 #ifdef HAVE_MMAP
16496 int res;
16497
16498 res = munmap (info->map_addr, info->map_len);
16499 gdb_assert (res == 0);
16500 #else
16501 /* Without HAVE_MMAP, we should never be here to begin with. */
16502 gdb_assert_not_reached ("no mmap support");
16503 #endif
16504 }
16505 }
16506
16507 /* munmap debug sections for OBJFILE, if necessary. */
16508
16509 static void
16510 dwarf2_per_objfile_free (struct objfile *objfile, void *d)
16511 {
16512 struct dwarf2_per_objfile *data = d;
16513 int ix;
16514 struct dwarf2_section_info *section;
16515
16516 /* This is sorted according to the order they're defined in to make it easier
16517 to keep in sync. */
16518 munmap_section_buffer (&data->info);
16519 munmap_section_buffer (&data->abbrev);
16520 munmap_section_buffer (&data->line);
16521 munmap_section_buffer (&data->loc);
16522 munmap_section_buffer (&data->macinfo);
16523 munmap_section_buffer (&data->macro);
16524 munmap_section_buffer (&data->str);
16525 munmap_section_buffer (&data->ranges);
16526 munmap_section_buffer (&data->frame);
16527 munmap_section_buffer (&data->eh_frame);
16528 munmap_section_buffer (&data->gdb_index);
16529
16530 for (ix = 0;
16531 VEC_iterate (dwarf2_section_info_def, data->types, ix, section);
16532 ++ix)
16533 munmap_section_buffer (section);
16534
16535 VEC_free (dwarf2_section_info_def, data->types);
16536 }
16537
16538 \f
16539 /* The "save gdb-index" command. */
16540
16541 /* The contents of the hash table we create when building the string
16542 table. */
16543 struct strtab_entry
16544 {
16545 offset_type offset;
16546 const char *str;
16547 };
16548
16549 /* Hash function for a strtab_entry.
16550
16551 Function is used only during write_hash_table so no index format backward
16552 compatibility is needed. */
16553
16554 static hashval_t
16555 hash_strtab_entry (const void *e)
16556 {
16557 const struct strtab_entry *entry = e;
16558 return mapped_index_string_hash (INT_MAX, entry->str);
16559 }
16560
16561 /* Equality function for a strtab_entry. */
16562
16563 static int
16564 eq_strtab_entry (const void *a, const void *b)
16565 {
16566 const struct strtab_entry *ea = a;
16567 const struct strtab_entry *eb = b;
16568 return !strcmp (ea->str, eb->str);
16569 }
16570
16571 /* Create a strtab_entry hash table. */
16572
16573 static htab_t
16574 create_strtab (void)
16575 {
16576 return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry,
16577 xfree, xcalloc, xfree);
16578 }
16579
16580 /* Add a string to the constant pool. Return the string's offset in
16581 host order. */
16582
16583 static offset_type
16584 add_string (htab_t table, struct obstack *cpool, const char *str)
16585 {
16586 void **slot;
16587 struct strtab_entry entry;
16588 struct strtab_entry *result;
16589
16590 entry.str = str;
16591 slot = htab_find_slot (table, &entry, INSERT);
16592 if (*slot)
16593 result = *slot;
16594 else
16595 {
16596 result = XNEW (struct strtab_entry);
16597 result->offset = obstack_object_size (cpool);
16598 result->str = str;
16599 obstack_grow_str0 (cpool, str);
16600 *slot = result;
16601 }
16602 return result->offset;
16603 }
16604
16605 /* An entry in the symbol table. */
16606 struct symtab_index_entry
16607 {
16608 /* The name of the symbol. */
16609 const char *name;
16610 /* The offset of the name in the constant pool. */
16611 offset_type index_offset;
16612 /* A sorted vector of the indices of all the CUs that hold an object
16613 of this name. */
16614 VEC (offset_type) *cu_indices;
16615 };
16616
16617 /* The symbol table. This is a power-of-2-sized hash table. */
16618 struct mapped_symtab
16619 {
16620 offset_type n_elements;
16621 offset_type size;
16622 struct symtab_index_entry **data;
16623 };
16624
16625 /* Hash function for a symtab_index_entry. */
16626
16627 static hashval_t
16628 hash_symtab_entry (const void *e)
16629 {
16630 const struct symtab_index_entry *entry = e;
16631 return iterative_hash (VEC_address (offset_type, entry->cu_indices),
16632 sizeof (offset_type) * VEC_length (offset_type,
16633 entry->cu_indices),
16634 0);
16635 }
16636
16637 /* Equality function for a symtab_index_entry. */
16638
16639 static int
16640 eq_symtab_entry (const void *a, const void *b)
16641 {
16642 const struct symtab_index_entry *ea = a;
16643 const struct symtab_index_entry *eb = b;
16644 int len = VEC_length (offset_type, ea->cu_indices);
16645 if (len != VEC_length (offset_type, eb->cu_indices))
16646 return 0;
16647 return !memcmp (VEC_address (offset_type, ea->cu_indices),
16648 VEC_address (offset_type, eb->cu_indices),
16649 sizeof (offset_type) * len);
16650 }
16651
16652 /* Destroy a symtab_index_entry. */
16653
16654 static void
16655 delete_symtab_entry (void *p)
16656 {
16657 struct symtab_index_entry *entry = p;
16658 VEC_free (offset_type, entry->cu_indices);
16659 xfree (entry);
16660 }
16661
16662 /* Create a hash table holding symtab_index_entry objects. */
16663
16664 static htab_t
16665 create_symbol_hash_table (void)
16666 {
16667 return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry,
16668 delete_symtab_entry, xcalloc, xfree);
16669 }
16670
16671 /* Create a new mapped symtab object. */
16672
16673 static struct mapped_symtab *
16674 create_mapped_symtab (void)
16675 {
16676 struct mapped_symtab *symtab = XNEW (struct mapped_symtab);
16677 symtab->n_elements = 0;
16678 symtab->size = 1024;
16679 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
16680 return symtab;
16681 }
16682
16683 /* Destroy a mapped_symtab. */
16684
16685 static void
16686 cleanup_mapped_symtab (void *p)
16687 {
16688 struct mapped_symtab *symtab = p;
16689 /* The contents of the array are freed when the other hash table is
16690 destroyed. */
16691 xfree (symtab->data);
16692 xfree (symtab);
16693 }
16694
16695 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
16696 the slot.
16697
16698 Function is used only during write_hash_table so no index format backward
16699 compatibility is needed. */
16700
16701 static struct symtab_index_entry **
16702 find_slot (struct mapped_symtab *symtab, const char *name)
16703 {
16704 offset_type index, step, hash = mapped_index_string_hash (INT_MAX, name);
16705
16706 index = hash & (symtab->size - 1);
16707 step = ((hash * 17) & (symtab->size - 1)) | 1;
16708
16709 for (;;)
16710 {
16711 if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name))
16712 return &symtab->data[index];
16713 index = (index + step) & (symtab->size - 1);
16714 }
16715 }
16716
16717 /* Expand SYMTAB's hash table. */
16718
16719 static void
16720 hash_expand (struct mapped_symtab *symtab)
16721 {
16722 offset_type old_size = symtab->size;
16723 offset_type i;
16724 struct symtab_index_entry **old_entries = symtab->data;
16725
16726 symtab->size *= 2;
16727 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
16728
16729 for (i = 0; i < old_size; ++i)
16730 {
16731 if (old_entries[i])
16732 {
16733 struct symtab_index_entry **slot = find_slot (symtab,
16734 old_entries[i]->name);
16735 *slot = old_entries[i];
16736 }
16737 }
16738
16739 xfree (old_entries);
16740 }
16741
16742 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
16743 is the index of the CU in which the symbol appears. */
16744
16745 static void
16746 add_index_entry (struct mapped_symtab *symtab, const char *name,
16747 offset_type cu_index)
16748 {
16749 struct symtab_index_entry **slot;
16750
16751 ++symtab->n_elements;
16752 if (4 * symtab->n_elements / 3 >= symtab->size)
16753 hash_expand (symtab);
16754
16755 slot = find_slot (symtab, name);
16756 if (!*slot)
16757 {
16758 *slot = XNEW (struct symtab_index_entry);
16759 (*slot)->name = name;
16760 (*slot)->cu_indices = NULL;
16761 }
16762 /* Don't push an index twice. Due to how we add entries we only
16763 have to check the last one. */
16764 if (VEC_empty (offset_type, (*slot)->cu_indices)
16765 || VEC_last (offset_type, (*slot)->cu_indices) != cu_index)
16766 VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index);
16767 }
16768
16769 /* Add a vector of indices to the constant pool. */
16770
16771 static offset_type
16772 add_indices_to_cpool (htab_t symbol_hash_table, struct obstack *cpool,
16773 struct symtab_index_entry *entry)
16774 {
16775 void **slot;
16776
16777 slot = htab_find_slot (symbol_hash_table, entry, INSERT);
16778 if (!*slot)
16779 {
16780 offset_type len = VEC_length (offset_type, entry->cu_indices);
16781 offset_type val = MAYBE_SWAP (len);
16782 offset_type iter;
16783 int i;
16784
16785 *slot = entry;
16786 entry->index_offset = obstack_object_size (cpool);
16787
16788 obstack_grow (cpool, &val, sizeof (val));
16789 for (i = 0;
16790 VEC_iterate (offset_type, entry->cu_indices, i, iter);
16791 ++i)
16792 {
16793 val = MAYBE_SWAP (iter);
16794 obstack_grow (cpool, &val, sizeof (val));
16795 }
16796 }
16797 else
16798 {
16799 struct symtab_index_entry *old_entry = *slot;
16800 entry->index_offset = old_entry->index_offset;
16801 entry = old_entry;
16802 }
16803 return entry->index_offset;
16804 }
16805
16806 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
16807 constant pool entries going into the obstack CPOOL. */
16808
16809 static void
16810 write_hash_table (struct mapped_symtab *symtab,
16811 struct obstack *output, struct obstack *cpool)
16812 {
16813 offset_type i;
16814 htab_t symbol_hash_table;
16815 htab_t str_table;
16816
16817 symbol_hash_table = create_symbol_hash_table ();
16818 str_table = create_strtab ();
16819
16820 /* We add all the index vectors to the constant pool first, to
16821 ensure alignment is ok. */
16822 for (i = 0; i < symtab->size; ++i)
16823 {
16824 if (symtab->data[i])
16825 add_indices_to_cpool (symbol_hash_table, cpool, symtab->data[i]);
16826 }
16827
16828 /* Now write out the hash table. */
16829 for (i = 0; i < symtab->size; ++i)
16830 {
16831 offset_type str_off, vec_off;
16832
16833 if (symtab->data[i])
16834 {
16835 str_off = add_string (str_table, cpool, symtab->data[i]->name);
16836 vec_off = symtab->data[i]->index_offset;
16837 }
16838 else
16839 {
16840 /* While 0 is a valid constant pool index, it is not valid
16841 to have 0 for both offsets. */
16842 str_off = 0;
16843 vec_off = 0;
16844 }
16845
16846 str_off = MAYBE_SWAP (str_off);
16847 vec_off = MAYBE_SWAP (vec_off);
16848
16849 obstack_grow (output, &str_off, sizeof (str_off));
16850 obstack_grow (output, &vec_off, sizeof (vec_off));
16851 }
16852
16853 htab_delete (str_table);
16854 htab_delete (symbol_hash_table);
16855 }
16856
16857 /* Struct to map psymtab to CU index in the index file. */
16858 struct psymtab_cu_index_map
16859 {
16860 struct partial_symtab *psymtab;
16861 unsigned int cu_index;
16862 };
16863
16864 static hashval_t
16865 hash_psymtab_cu_index (const void *item)
16866 {
16867 const struct psymtab_cu_index_map *map = item;
16868
16869 return htab_hash_pointer (map->psymtab);
16870 }
16871
16872 static int
16873 eq_psymtab_cu_index (const void *item_lhs, const void *item_rhs)
16874 {
16875 const struct psymtab_cu_index_map *lhs = item_lhs;
16876 const struct psymtab_cu_index_map *rhs = item_rhs;
16877
16878 return lhs->psymtab == rhs->psymtab;
16879 }
16880
16881 /* Helper struct for building the address table. */
16882 struct addrmap_index_data
16883 {
16884 struct objfile *objfile;
16885 struct obstack *addr_obstack;
16886 htab_t cu_index_htab;
16887
16888 /* Non-zero if the previous_* fields are valid.
16889 We can't write an entry until we see the next entry (since it is only then
16890 that we know the end of the entry). */
16891 int previous_valid;
16892 /* Index of the CU in the table of all CUs in the index file. */
16893 unsigned int previous_cu_index;
16894 /* Start address of the CU. */
16895 CORE_ADDR previous_cu_start;
16896 };
16897
16898 /* Write an address entry to OBSTACK. */
16899
16900 static void
16901 add_address_entry (struct objfile *objfile, struct obstack *obstack,
16902 CORE_ADDR start, CORE_ADDR end, unsigned int cu_index)
16903 {
16904 offset_type cu_index_to_write;
16905 char addr[8];
16906 CORE_ADDR baseaddr;
16907
16908 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
16909
16910 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, start - baseaddr);
16911 obstack_grow (obstack, addr, 8);
16912 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, end - baseaddr);
16913 obstack_grow (obstack, addr, 8);
16914 cu_index_to_write = MAYBE_SWAP (cu_index);
16915 obstack_grow (obstack, &cu_index_to_write, sizeof (offset_type));
16916 }
16917
16918 /* Worker function for traversing an addrmap to build the address table. */
16919
16920 static int
16921 add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj)
16922 {
16923 struct addrmap_index_data *data = datap;
16924 struct partial_symtab *pst = obj;
16925 offset_type cu_index;
16926 void **slot;
16927
16928 if (data->previous_valid)
16929 add_address_entry (data->objfile, data->addr_obstack,
16930 data->previous_cu_start, start_addr,
16931 data->previous_cu_index);
16932
16933 data->previous_cu_start = start_addr;
16934 if (pst != NULL)
16935 {
16936 struct psymtab_cu_index_map find_map, *map;
16937 find_map.psymtab = pst;
16938 map = htab_find (data->cu_index_htab, &find_map);
16939 gdb_assert (map != NULL);
16940 data->previous_cu_index = map->cu_index;
16941 data->previous_valid = 1;
16942 }
16943 else
16944 data->previous_valid = 0;
16945
16946 return 0;
16947 }
16948
16949 /* Write OBJFILE's address map to OBSTACK.
16950 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
16951 in the index file. */
16952
16953 static void
16954 write_address_map (struct objfile *objfile, struct obstack *obstack,
16955 htab_t cu_index_htab)
16956 {
16957 struct addrmap_index_data addrmap_index_data;
16958
16959 /* When writing the address table, we have to cope with the fact that
16960 the addrmap iterator only provides the start of a region; we have to
16961 wait until the next invocation to get the start of the next region. */
16962
16963 addrmap_index_data.objfile = objfile;
16964 addrmap_index_data.addr_obstack = obstack;
16965 addrmap_index_data.cu_index_htab = cu_index_htab;
16966 addrmap_index_data.previous_valid = 0;
16967
16968 addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker,
16969 &addrmap_index_data);
16970
16971 /* It's highly unlikely the last entry (end address = 0xff...ff)
16972 is valid, but we should still handle it.
16973 The end address is recorded as the start of the next region, but that
16974 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
16975 anyway. */
16976 if (addrmap_index_data.previous_valid)
16977 add_address_entry (objfile, obstack,
16978 addrmap_index_data.previous_cu_start, (CORE_ADDR) -1,
16979 addrmap_index_data.previous_cu_index);
16980 }
16981
16982 /* Add a list of partial symbols to SYMTAB. */
16983
16984 static void
16985 write_psymbols (struct mapped_symtab *symtab,
16986 htab_t psyms_seen,
16987 struct partial_symbol **psymp,
16988 int count,
16989 offset_type cu_index,
16990 int is_static)
16991 {
16992 for (; count-- > 0; ++psymp)
16993 {
16994 void **slot, *lookup;
16995
16996 if (SYMBOL_LANGUAGE (*psymp) == language_ada)
16997 error (_("Ada is not currently supported by the index"));
16998
16999 /* We only want to add a given psymbol once. However, we also
17000 want to account for whether it is global or static. So, we
17001 may add it twice, using slightly different values. */
17002 if (is_static)
17003 {
17004 uintptr_t val = 1 | (uintptr_t) *psymp;
17005
17006 lookup = (void *) val;
17007 }
17008 else
17009 lookup = *psymp;
17010
17011 /* Only add a given psymbol once. */
17012 slot = htab_find_slot (psyms_seen, lookup, INSERT);
17013 if (!*slot)
17014 {
17015 *slot = lookup;
17016 add_index_entry (symtab, SYMBOL_SEARCH_NAME (*psymp), cu_index);
17017 }
17018 }
17019 }
17020
17021 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
17022 exception if there is an error. */
17023
17024 static void
17025 write_obstack (FILE *file, struct obstack *obstack)
17026 {
17027 if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack),
17028 file)
17029 != obstack_object_size (obstack))
17030 error (_("couldn't data write to file"));
17031 }
17032
17033 /* Unlink a file if the argument is not NULL. */
17034
17035 static void
17036 unlink_if_set (void *p)
17037 {
17038 char **filename = p;
17039 if (*filename)
17040 unlink (*filename);
17041 }
17042
17043 /* A helper struct used when iterating over debug_types. */
17044 struct signatured_type_index_data
17045 {
17046 struct objfile *objfile;
17047 struct mapped_symtab *symtab;
17048 struct obstack *types_list;
17049 htab_t psyms_seen;
17050 int cu_index;
17051 };
17052
17053 /* A helper function that writes a single signatured_type to an
17054 obstack. */
17055
17056 static int
17057 write_one_signatured_type (void **slot, void *d)
17058 {
17059 struct signatured_type_index_data *info = d;
17060 struct signatured_type *entry = (struct signatured_type *) *slot;
17061 struct dwarf2_per_cu_data *per_cu = &entry->per_cu;
17062 struct partial_symtab *psymtab = per_cu->v.psymtab;
17063 gdb_byte val[8];
17064
17065 write_psymbols (info->symtab,
17066 info->psyms_seen,
17067 info->objfile->global_psymbols.list
17068 + psymtab->globals_offset,
17069 psymtab->n_global_syms, info->cu_index,
17070 0);
17071 write_psymbols (info->symtab,
17072 info->psyms_seen,
17073 info->objfile->static_psymbols.list
17074 + psymtab->statics_offset,
17075 psymtab->n_static_syms, info->cu_index,
17076 1);
17077
17078 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE,
17079 entry->per_cu.offset.sect_off);
17080 obstack_grow (info->types_list, val, 8);
17081 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->type_offset.cu_off);
17082 obstack_grow (info->types_list, val, 8);
17083 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature);
17084 obstack_grow (info->types_list, val, 8);
17085
17086 ++info->cu_index;
17087
17088 return 1;
17089 }
17090
17091 /* Create an index file for OBJFILE in the directory DIR. */
17092
17093 static void
17094 write_psymtabs_to_index (struct objfile *objfile, const char *dir)
17095 {
17096 struct cleanup *cleanup;
17097 char *filename, *cleanup_filename;
17098 struct obstack contents, addr_obstack, constant_pool, symtab_obstack;
17099 struct obstack cu_list, types_cu_list;
17100 int i;
17101 FILE *out_file;
17102 struct mapped_symtab *symtab;
17103 offset_type val, size_of_contents, total_len;
17104 struct stat st;
17105 char buf[8];
17106 htab_t psyms_seen;
17107 htab_t cu_index_htab;
17108 struct psymtab_cu_index_map *psymtab_cu_index_map;
17109
17110 if (!objfile->psymtabs || !objfile->psymtabs_addrmap)
17111 return;
17112
17113 if (dwarf2_per_objfile->using_index)
17114 error (_("Cannot use an index to create the index"));
17115
17116 if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) > 1)
17117 error (_("Cannot make an index when the file has multiple .debug_types sections"));
17118
17119 if (stat (objfile->name, &st) < 0)
17120 perror_with_name (objfile->name);
17121
17122 filename = concat (dir, SLASH_STRING, lbasename (objfile->name),
17123 INDEX_SUFFIX, (char *) NULL);
17124 cleanup = make_cleanup (xfree, filename);
17125
17126 out_file = fopen (filename, "wb");
17127 if (!out_file)
17128 error (_("Can't open `%s' for writing"), filename);
17129
17130 cleanup_filename = filename;
17131 make_cleanup (unlink_if_set, &cleanup_filename);
17132
17133 symtab = create_mapped_symtab ();
17134 make_cleanup (cleanup_mapped_symtab, symtab);
17135
17136 obstack_init (&addr_obstack);
17137 make_cleanup_obstack_free (&addr_obstack);
17138
17139 obstack_init (&cu_list);
17140 make_cleanup_obstack_free (&cu_list);
17141
17142 obstack_init (&types_cu_list);
17143 make_cleanup_obstack_free (&types_cu_list);
17144
17145 psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer,
17146 NULL, xcalloc, xfree);
17147 make_cleanup_htab_delete (psyms_seen);
17148
17149 /* While we're scanning CU's create a table that maps a psymtab pointer
17150 (which is what addrmap records) to its index (which is what is recorded
17151 in the index file). This will later be needed to write the address
17152 table. */
17153 cu_index_htab = htab_create_alloc (100,
17154 hash_psymtab_cu_index,
17155 eq_psymtab_cu_index,
17156 NULL, xcalloc, xfree);
17157 make_cleanup_htab_delete (cu_index_htab);
17158 psymtab_cu_index_map = (struct psymtab_cu_index_map *)
17159 xmalloc (sizeof (struct psymtab_cu_index_map)
17160 * dwarf2_per_objfile->n_comp_units);
17161 make_cleanup (xfree, psymtab_cu_index_map);
17162
17163 /* The CU list is already sorted, so we don't need to do additional
17164 work here. Also, the debug_types entries do not appear in
17165 all_comp_units, but only in their own hash table. */
17166 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
17167 {
17168 struct dwarf2_per_cu_data *per_cu
17169 = dwarf2_per_objfile->all_comp_units[i];
17170 struct partial_symtab *psymtab = per_cu->v.psymtab;
17171 gdb_byte val[8];
17172 struct psymtab_cu_index_map *map;
17173 void **slot;
17174
17175 write_psymbols (symtab,
17176 psyms_seen,
17177 objfile->global_psymbols.list + psymtab->globals_offset,
17178 psymtab->n_global_syms, i,
17179 0);
17180 write_psymbols (symtab,
17181 psyms_seen,
17182 objfile->static_psymbols.list + psymtab->statics_offset,
17183 psymtab->n_static_syms, i,
17184 1);
17185
17186 map = &psymtab_cu_index_map[i];
17187 map->psymtab = psymtab;
17188 map->cu_index = i;
17189 slot = htab_find_slot (cu_index_htab, map, INSERT);
17190 gdb_assert (slot != NULL);
17191 gdb_assert (*slot == NULL);
17192 *slot = map;
17193
17194 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE,
17195 per_cu->offset.sect_off);
17196 obstack_grow (&cu_list, val, 8);
17197 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length);
17198 obstack_grow (&cu_list, val, 8);
17199 }
17200
17201 /* Dump the address map. */
17202 write_address_map (objfile, &addr_obstack, cu_index_htab);
17203
17204 /* Write out the .debug_type entries, if any. */
17205 if (dwarf2_per_objfile->signatured_types)
17206 {
17207 struct signatured_type_index_data sig_data;
17208
17209 sig_data.objfile = objfile;
17210 sig_data.symtab = symtab;
17211 sig_data.types_list = &types_cu_list;
17212 sig_data.psyms_seen = psyms_seen;
17213 sig_data.cu_index = dwarf2_per_objfile->n_comp_units;
17214 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
17215 write_one_signatured_type, &sig_data);
17216 }
17217
17218 obstack_init (&constant_pool);
17219 make_cleanup_obstack_free (&constant_pool);
17220 obstack_init (&symtab_obstack);
17221 make_cleanup_obstack_free (&symtab_obstack);
17222 write_hash_table (symtab, &symtab_obstack, &constant_pool);
17223
17224 obstack_init (&contents);
17225 make_cleanup_obstack_free (&contents);
17226 size_of_contents = 6 * sizeof (offset_type);
17227 total_len = size_of_contents;
17228
17229 /* The version number. */
17230 val = MAYBE_SWAP (6);
17231 obstack_grow (&contents, &val, sizeof (val));
17232
17233 /* The offset of the CU list from the start of the file. */
17234 val = MAYBE_SWAP (total_len);
17235 obstack_grow (&contents, &val, sizeof (val));
17236 total_len += obstack_object_size (&cu_list);
17237
17238 /* The offset of the types CU list from the start of the file. */
17239 val = MAYBE_SWAP (total_len);
17240 obstack_grow (&contents, &val, sizeof (val));
17241 total_len += obstack_object_size (&types_cu_list);
17242
17243 /* The offset of the address table from the start of the file. */
17244 val = MAYBE_SWAP (total_len);
17245 obstack_grow (&contents, &val, sizeof (val));
17246 total_len += obstack_object_size (&addr_obstack);
17247
17248 /* The offset of the symbol table from the start of the file. */
17249 val = MAYBE_SWAP (total_len);
17250 obstack_grow (&contents, &val, sizeof (val));
17251 total_len += obstack_object_size (&symtab_obstack);
17252
17253 /* The offset of the constant pool from the start of the file. */
17254 val = MAYBE_SWAP (total_len);
17255 obstack_grow (&contents, &val, sizeof (val));
17256 total_len += obstack_object_size (&constant_pool);
17257
17258 gdb_assert (obstack_object_size (&contents) == size_of_contents);
17259
17260 write_obstack (out_file, &contents);
17261 write_obstack (out_file, &cu_list);
17262 write_obstack (out_file, &types_cu_list);
17263 write_obstack (out_file, &addr_obstack);
17264 write_obstack (out_file, &symtab_obstack);
17265 write_obstack (out_file, &constant_pool);
17266
17267 fclose (out_file);
17268
17269 /* We want to keep the file, so we set cleanup_filename to NULL
17270 here. See unlink_if_set. */
17271 cleanup_filename = NULL;
17272
17273 do_cleanups (cleanup);
17274 }
17275
17276 /* Implementation of the `save gdb-index' command.
17277
17278 Note that the file format used by this command is documented in the
17279 GDB manual. Any changes here must be documented there. */
17280
17281 static void
17282 save_gdb_index_command (char *arg, int from_tty)
17283 {
17284 struct objfile *objfile;
17285
17286 if (!arg || !*arg)
17287 error (_("usage: save gdb-index DIRECTORY"));
17288
17289 ALL_OBJFILES (objfile)
17290 {
17291 struct stat st;
17292
17293 /* If the objfile does not correspond to an actual file, skip it. */
17294 if (stat (objfile->name, &st) < 0)
17295 continue;
17296
17297 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
17298 if (dwarf2_per_objfile)
17299 {
17300 volatile struct gdb_exception except;
17301
17302 TRY_CATCH (except, RETURN_MASK_ERROR)
17303 {
17304 write_psymtabs_to_index (objfile, arg);
17305 }
17306 if (except.reason < 0)
17307 exception_fprintf (gdb_stderr, except,
17308 _("Error while writing index for `%s': "),
17309 objfile->name);
17310 }
17311 }
17312 }
17313
17314 \f
17315
17316 int dwarf2_always_disassemble;
17317
17318 static void
17319 show_dwarf2_always_disassemble (struct ui_file *file, int from_tty,
17320 struct cmd_list_element *c, const char *value)
17321 {
17322 fprintf_filtered (file,
17323 _("Whether to always disassemble "
17324 "DWARF expressions is %s.\n"),
17325 value);
17326 }
17327
17328 static void
17329 show_check_physname (struct ui_file *file, int from_tty,
17330 struct cmd_list_element *c, const char *value)
17331 {
17332 fprintf_filtered (file,
17333 _("Whether to check \"physname\" is %s.\n"),
17334 value);
17335 }
17336
17337 void _initialize_dwarf2_read (void);
17338
17339 void
17340 _initialize_dwarf2_read (void)
17341 {
17342 struct cmd_list_element *c;
17343
17344 dwarf2_objfile_data_key
17345 = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free);
17346
17347 add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\
17348 Set DWARF 2 specific variables.\n\
17349 Configure DWARF 2 variables such as the cache size"),
17350 &set_dwarf2_cmdlist, "maintenance set dwarf2 ",
17351 0/*allow-unknown*/, &maintenance_set_cmdlist);
17352
17353 add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\
17354 Show DWARF 2 specific variables\n\
17355 Show DWARF 2 variables such as the cache size"),
17356 &show_dwarf2_cmdlist, "maintenance show dwarf2 ",
17357 0/*allow-unknown*/, &maintenance_show_cmdlist);
17358
17359 add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
17360 &dwarf2_max_cache_age, _("\
17361 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
17362 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
17363 A higher limit means that cached compilation units will be stored\n\
17364 in memory longer, and more total memory will be used. Zero disables\n\
17365 caching, which can slow down startup."),
17366 NULL,
17367 show_dwarf2_max_cache_age,
17368 &set_dwarf2_cmdlist,
17369 &show_dwarf2_cmdlist);
17370
17371 add_setshow_boolean_cmd ("always-disassemble", class_obscure,
17372 &dwarf2_always_disassemble, _("\
17373 Set whether `info address' always disassembles DWARF expressions."), _("\
17374 Show whether `info address' always disassembles DWARF expressions."), _("\
17375 When enabled, DWARF expressions are always printed in an assembly-like\n\
17376 syntax. When disabled, expressions will be printed in a more\n\
17377 conversational style, when possible."),
17378 NULL,
17379 show_dwarf2_always_disassemble,
17380 &set_dwarf2_cmdlist,
17381 &show_dwarf2_cmdlist);
17382
17383 add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\
17384 Set debugging of the dwarf2 DIE reader."), _("\
17385 Show debugging of the dwarf2 DIE reader."), _("\
17386 When enabled (non-zero), DIEs are dumped after they are read in.\n\
17387 The value is the maximum depth to print."),
17388 NULL,
17389 NULL,
17390 &setdebuglist, &showdebuglist);
17391
17392 add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\
17393 Set cross-checking of \"physname\" code against demangler."), _("\
17394 Show cross-checking of \"physname\" code against demangler."), _("\
17395 When enabled, GDB's internal \"physname\" code is checked against\n\
17396 the demangler."),
17397 NULL, show_check_physname,
17398 &setdebuglist, &showdebuglist);
17399
17400 c = add_cmd ("gdb-index", class_files, save_gdb_index_command,
17401 _("\
17402 Save a gdb-index file.\n\
17403 Usage: save gdb-index DIRECTORY"),
17404 &save_cmdlist);
17405 set_cmd_completer (c, filename_completer);
17406 }
This page took 0.433068 seconds and 4 git commands to generate.