gdb
[deliverable/binutils-gdb.git] / gdb / dwarf2read.c
1 /* DWARF 2 debugging format support for GDB.
2
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009, 2010
5 Free Software Foundation, Inc.
6
7 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
8 Inc. with support from Florida State University (under contract
9 with the Ada Joint Program Office), and Silicon Graphics, Inc.
10 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
11 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 support.
13
14 This file is part of GDB.
15
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
20
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28
29 #include "defs.h"
30 #include "bfd.h"
31 #include "symtab.h"
32 #include "gdbtypes.h"
33 #include "objfiles.h"
34 #include "dwarf2.h"
35 #include "buildsym.h"
36 #include "demangle.h"
37 #include "expression.h"
38 #include "filenames.h" /* for DOSish file names */
39 #include "macrotab.h"
40 #include "language.h"
41 #include "complaints.h"
42 #include "bcache.h"
43 #include "dwarf2expr.h"
44 #include "dwarf2loc.h"
45 #include "cp-support.h"
46 #include "hashtab.h"
47 #include "command.h"
48 #include "gdbcmd.h"
49 #include "block.h"
50 #include "addrmap.h"
51 #include "typeprint.h"
52 #include "jv-lang.h"
53 #include "psympriv.h"
54 #include "exceptions.h"
55 #include "gdb_stat.h"
56 #include "completer.h"
57 #include "vec.h"
58 #include "c-lang.h"
59 #include "valprint.h"
60
61 #include <fcntl.h>
62 #include "gdb_string.h"
63 #include "gdb_assert.h"
64 #include <sys/types.h>
65 #ifdef HAVE_ZLIB_H
66 #include <zlib.h>
67 #endif
68 #ifdef HAVE_MMAP
69 #include <sys/mman.h>
70 #ifndef MAP_FAILED
71 #define MAP_FAILED ((void *) -1)
72 #endif
73 #endif
74
75 typedef struct symbol *symbolp;
76 DEF_VEC_P (symbolp);
77
78 #if 0
79 /* .debug_info header for a compilation unit
80 Because of alignment constraints, this structure has padding and cannot
81 be mapped directly onto the beginning of the .debug_info section. */
82 typedef struct comp_unit_header
83 {
84 unsigned int length; /* length of the .debug_info
85 contribution */
86 unsigned short version; /* version number -- 2 for DWARF
87 version 2 */
88 unsigned int abbrev_offset; /* offset into .debug_abbrev section */
89 unsigned char addr_size; /* byte size of an address -- 4 */
90 }
91 _COMP_UNIT_HEADER;
92 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
93 #endif
94
95 /* .debug_line statement program prologue
96 Because of alignment constraints, this structure has padding and cannot
97 be mapped directly onto the beginning of the .debug_info section. */
98 typedef struct statement_prologue
99 {
100 unsigned int total_length; /* byte length of the statement
101 information */
102 unsigned short version; /* version number -- 2 for DWARF
103 version 2 */
104 unsigned int prologue_length; /* # bytes between prologue &
105 stmt program */
106 unsigned char minimum_instruction_length; /* byte size of
107 smallest instr */
108 unsigned char default_is_stmt; /* initial value of is_stmt
109 register */
110 char line_base;
111 unsigned char line_range;
112 unsigned char opcode_base; /* number assigned to first special
113 opcode */
114 unsigned char *standard_opcode_lengths;
115 }
116 _STATEMENT_PROLOGUE;
117
118 /* When non-zero, dump DIEs after they are read in. */
119 static int dwarf2_die_debug = 0;
120
121 static int pagesize;
122
123 /* When set, the file that we're processing is known to have debugging
124 info for C++ namespaces. GCC 3.3.x did not produce this information,
125 but later versions do. */
126
127 static int processing_has_namespace_info;
128
129 static const struct objfile_data *dwarf2_objfile_data_key;
130
131 struct dwarf2_section_info
132 {
133 asection *asection;
134 gdb_byte *buffer;
135 bfd_size_type size;
136 int was_mmapped;
137 /* True if we have tried to read this section. */
138 int readin;
139 };
140
141 /* All offsets in the index are of this type. It must be
142 architecture-independent. */
143 typedef uint32_t offset_type;
144
145 DEF_VEC_I (offset_type);
146
147 /* A description of the mapped index. The file format is described in
148 a comment by the code that writes the index. */
149 struct mapped_index
150 {
151 /* The total length of the buffer. */
152 off_t total_size;
153 /* A pointer to the address table data. */
154 const gdb_byte *address_table;
155 /* Size of the address table data in bytes. */
156 offset_type address_table_size;
157 /* The hash table. */
158 const offset_type *index_table;
159 /* Size in slots, each slot is 2 offset_types. */
160 offset_type index_table_slots;
161 /* A pointer to the constant pool. */
162 const char *constant_pool;
163 };
164
165 struct dwarf2_per_objfile
166 {
167 struct dwarf2_section_info info;
168 struct dwarf2_section_info abbrev;
169 struct dwarf2_section_info line;
170 struct dwarf2_section_info loc;
171 struct dwarf2_section_info macinfo;
172 struct dwarf2_section_info str;
173 struct dwarf2_section_info ranges;
174 struct dwarf2_section_info types;
175 struct dwarf2_section_info frame;
176 struct dwarf2_section_info eh_frame;
177 struct dwarf2_section_info gdb_index;
178
179 /* Back link. */
180 struct objfile *objfile;
181
182 /* A list of all the compilation units. This is used to locate
183 the target compilation unit of a particular reference. */
184 struct dwarf2_per_cu_data **all_comp_units;
185
186 /* The number of compilation units in ALL_COMP_UNITS. */
187 int n_comp_units;
188
189 /* The number of .debug_types-related CUs. */
190 int n_type_comp_units;
191
192 /* The .debug_types-related CUs. */
193 struct dwarf2_per_cu_data **type_comp_units;
194
195 /* A chain of compilation units that are currently read in, so that
196 they can be freed later. */
197 struct dwarf2_per_cu_data *read_in_chain;
198
199 /* A table mapping .debug_types signatures to its signatured_type entry.
200 This is NULL if the .debug_types section hasn't been read in yet. */
201 htab_t signatured_types;
202
203 /* A flag indicating wether this objfile has a section loaded at a
204 VMA of 0. */
205 int has_section_at_zero;
206
207 /* True if we are using the mapped index. */
208 unsigned char using_index;
209
210 /* The mapped index. */
211 struct mapped_index *index_table;
212
213 /* Set during partial symbol reading, to prevent queueing of full
214 symbols. */
215 int reading_partial_symbols;
216
217 /* Table mapping type .debug_info DIE offsets to types.
218 This is NULL if not allocated yet.
219 It (currently) makes sense to allocate debug_types_type_hash lazily.
220 To keep things simple we allocate both lazily. */
221 htab_t debug_info_type_hash;
222
223 /* Table mapping type .debug_types DIE offsets to types.
224 This is NULL if not allocated yet. */
225 htab_t debug_types_type_hash;
226 };
227
228 static struct dwarf2_per_objfile *dwarf2_per_objfile;
229
230 /* names of the debugging sections */
231
232 /* Note that if the debugging section has been compressed, it might
233 have a name like .zdebug_info. */
234
235 #define INFO_SECTION "debug_info"
236 #define ABBREV_SECTION "debug_abbrev"
237 #define LINE_SECTION "debug_line"
238 #define LOC_SECTION "debug_loc"
239 #define MACINFO_SECTION "debug_macinfo"
240 #define STR_SECTION "debug_str"
241 #define RANGES_SECTION "debug_ranges"
242 #define TYPES_SECTION "debug_types"
243 #define FRAME_SECTION "debug_frame"
244 #define EH_FRAME_SECTION "eh_frame"
245 #define GDB_INDEX_SECTION "gdb_index"
246
247 /* local data types */
248
249 /* We hold several abbreviation tables in memory at the same time. */
250 #ifndef ABBREV_HASH_SIZE
251 #define ABBREV_HASH_SIZE 121
252 #endif
253
254 /* The data in a compilation unit header, after target2host
255 translation, looks like this. */
256 struct comp_unit_head
257 {
258 unsigned int length;
259 short version;
260 unsigned char addr_size;
261 unsigned char signed_addr_p;
262 unsigned int abbrev_offset;
263
264 /* Size of file offsets; either 4 or 8. */
265 unsigned int offset_size;
266
267 /* Size of the length field; either 4 or 12. */
268 unsigned int initial_length_size;
269
270 /* Offset to the first byte of this compilation unit header in the
271 .debug_info section, for resolving relative reference dies. */
272 unsigned int offset;
273
274 /* Offset to first die in this cu from the start of the cu.
275 This will be the first byte following the compilation unit header. */
276 unsigned int first_die_offset;
277 };
278
279 /* Type used for delaying computation of method physnames.
280 See comments for compute_delayed_physnames. */
281 struct delayed_method_info
282 {
283 /* The type to which the method is attached, i.e., its parent class. */
284 struct type *type;
285
286 /* The index of the method in the type's function fieldlists. */
287 int fnfield_index;
288
289 /* The index of the method in the fieldlist. */
290 int index;
291
292 /* The name of the DIE. */
293 const char *name;
294
295 /* The DIE associated with this method. */
296 struct die_info *die;
297 };
298
299 typedef struct delayed_method_info delayed_method_info;
300 DEF_VEC_O (delayed_method_info);
301
302 /* Internal state when decoding a particular compilation unit. */
303 struct dwarf2_cu
304 {
305 /* The objfile containing this compilation unit. */
306 struct objfile *objfile;
307
308 /* The header of the compilation unit. */
309 struct comp_unit_head header;
310
311 /* Base address of this compilation unit. */
312 CORE_ADDR base_address;
313
314 /* Non-zero if base_address has been set. */
315 int base_known;
316
317 struct function_range *first_fn, *last_fn, *cached_fn;
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 htab_t partial_dies;
344
345 /* Storage for things with the same lifetime as this read-in compilation
346 unit, including partial DIEs. */
347 struct obstack comp_unit_obstack;
348
349 /* When multiple dwarf2_cu structures are living in memory, this field
350 chains them all together, so that they can be released efficiently.
351 We will probably also want a generation counter so that most-recently-used
352 compilation units are cached... */
353 struct dwarf2_per_cu_data *read_in_chain;
354
355 /* Backchain to our per_cu entry if the tree has been built. */
356 struct dwarf2_per_cu_data *per_cu;
357
358 /* How many compilation units ago was this CU last referenced? */
359 int last_used;
360
361 /* A hash table of die offsets for following references. */
362 htab_t die_hash;
363
364 /* Full DIEs if read in. */
365 struct die_info *dies;
366
367 /* A set of pointers to dwarf2_per_cu_data objects for compilation
368 units referenced by this one. Only set during full symbol processing;
369 partial symbol tables do not have dependencies. */
370 htab_t dependencies;
371
372 /* Header data from the line table, during full symbol processing. */
373 struct line_header *line_header;
374
375 /* A list of methods which need to have physnames computed
376 after all type information has been read. */
377 VEC (delayed_method_info) *method_list;
378
379 /* Mark used when releasing cached dies. */
380 unsigned int mark : 1;
381
382 /* This flag will be set if this compilation unit might include
383 inter-compilation-unit references. */
384 unsigned int has_form_ref_addr : 1;
385
386 /* This flag will be set if this compilation unit includes any
387 DW_TAG_namespace DIEs. If we know that there are explicit
388 DIEs for namespaces, we don't need to try to infer them
389 from mangled names. */
390 unsigned int has_namespace_info : 1;
391 };
392
393 /* When using the index (and thus not using psymtabs), each CU has an
394 object of this type. This is used to hold information needed by
395 the various "quick" methods. */
396 struct dwarf2_per_cu_quick_data
397 {
398 /* The line table. This can be NULL if there was no line table. */
399 struct line_header *lines;
400
401 /* The file names from the line table. */
402 const char **file_names;
403 /* The file names from the line table after being run through
404 gdb_realpath. */
405 const char **full_names;
406
407 /* The corresponding symbol table. This is NULL if symbols for this
408 CU have not yet been read. */
409 struct symtab *symtab;
410
411 /* A temporary mark bit used when iterating over all CUs in
412 expand_symtabs_matching. */
413 unsigned int mark : 1;
414
415 /* True if we've tried to read the line table. */
416 unsigned int read_lines : 1;
417 };
418
419 /* Persistent data held for a compilation unit, even when not
420 processing it. We put a pointer to this structure in the
421 read_symtab_private field of the psymtab. If we encounter
422 inter-compilation-unit references, we also maintain a sorted
423 list of all compilation units. */
424
425 struct dwarf2_per_cu_data
426 {
427 /* The start offset and length of this compilation unit. 2**29-1
428 bytes should suffice to store the length of any compilation unit
429 - if it doesn't, GDB will fall over anyway.
430 NOTE: Unlike comp_unit_head.length, this length includes
431 initial_length_size. */
432 unsigned int offset;
433 unsigned int length : 29;
434
435 /* Flag indicating this compilation unit will be read in before
436 any of the current compilation units are processed. */
437 unsigned int queued : 1;
438
439 /* This flag will be set if we need to load absolutely all DIEs
440 for this compilation unit, instead of just the ones we think
441 are interesting. It gets set if we look for a DIE in the
442 hash table and don't find it. */
443 unsigned int load_all_dies : 1;
444
445 /* Non-zero if this CU is from .debug_types.
446 Otherwise it's from .debug_info. */
447 unsigned int from_debug_types : 1;
448
449 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
450 of the CU cache it gets reset to NULL again. */
451 struct dwarf2_cu *cu;
452
453 /* The corresponding objfile. */
454 struct objfile *objfile;
455
456 /* When using partial symbol tables, the 'psymtab' field is active.
457 Otherwise the 'quick' field is active. */
458 union
459 {
460 /* The partial symbol table associated with this compilation unit,
461 or NULL for partial units (which do not have an associated
462 symtab). */
463 struct partial_symtab *psymtab;
464
465 /* Data needed by the "quick" functions. */
466 struct dwarf2_per_cu_quick_data *quick;
467 } v;
468 };
469
470 /* Entry in the signatured_types hash table. */
471
472 struct signatured_type
473 {
474 ULONGEST signature;
475
476 /* Offset in .debug_types of the TU (type_unit) for this type. */
477 unsigned int offset;
478
479 /* Offset in .debug_types of the type defined by this TU. */
480 unsigned int type_offset;
481
482 /* The CU(/TU) of this type. */
483 struct dwarf2_per_cu_data per_cu;
484 };
485
486 /* Struct used to pass misc. parameters to read_die_and_children, et. al.
487 which are used for both .debug_info and .debug_types dies.
488 All parameters here are unchanging for the life of the call.
489 This struct exists to abstract away the constant parameters of
490 die reading. */
491
492 struct die_reader_specs
493 {
494 /* The bfd of this objfile. */
495 bfd* abfd;
496
497 /* The CU of the DIE we are parsing. */
498 struct dwarf2_cu *cu;
499
500 /* Pointer to start of section buffer.
501 This is either the start of .debug_info or .debug_types. */
502 const gdb_byte *buffer;
503 };
504
505 /* The line number information for a compilation unit (found in the
506 .debug_line section) begins with a "statement program header",
507 which contains the following information. */
508 struct line_header
509 {
510 unsigned int total_length;
511 unsigned short version;
512 unsigned int header_length;
513 unsigned char minimum_instruction_length;
514 unsigned char maximum_ops_per_instruction;
515 unsigned char default_is_stmt;
516 int line_base;
517 unsigned char line_range;
518 unsigned char opcode_base;
519
520 /* standard_opcode_lengths[i] is the number of operands for the
521 standard opcode whose value is i. This means that
522 standard_opcode_lengths[0] is unused, and the last meaningful
523 element is standard_opcode_lengths[opcode_base - 1]. */
524 unsigned char *standard_opcode_lengths;
525
526 /* The include_directories table. NOTE! These strings are not
527 allocated with xmalloc; instead, they are pointers into
528 debug_line_buffer. If you try to free them, `free' will get
529 indigestion. */
530 unsigned int num_include_dirs, include_dirs_size;
531 char **include_dirs;
532
533 /* The file_names table. NOTE! These strings are not allocated
534 with xmalloc; instead, they are pointers into debug_line_buffer.
535 Don't try to free them directly. */
536 unsigned int num_file_names, file_names_size;
537 struct file_entry
538 {
539 char *name;
540 unsigned int dir_index;
541 unsigned int mod_time;
542 unsigned int length;
543 int included_p; /* Non-zero if referenced by the Line Number Program. */
544 struct symtab *symtab; /* The associated symbol table, if any. */
545 } *file_names;
546
547 /* The start and end of the statement program following this
548 header. These point into dwarf2_per_objfile->line_buffer. */
549 gdb_byte *statement_program_start, *statement_program_end;
550 };
551
552 /* When we construct a partial symbol table entry we only
553 need this much information. */
554 struct partial_die_info
555 {
556 /* Offset of this DIE. */
557 unsigned int offset;
558
559 /* DWARF-2 tag for this DIE. */
560 ENUM_BITFIELD(dwarf_tag) tag : 16;
561
562 /* Assorted flags describing the data found in this DIE. */
563 unsigned int has_children : 1;
564 unsigned int is_external : 1;
565 unsigned int is_declaration : 1;
566 unsigned int has_type : 1;
567 unsigned int has_specification : 1;
568 unsigned int has_pc_info : 1;
569
570 /* Flag set if the SCOPE field of this structure has been
571 computed. */
572 unsigned int scope_set : 1;
573
574 /* Flag set if the DIE has a byte_size attribute. */
575 unsigned int has_byte_size : 1;
576
577 /* Flag set if any of the DIE's children are template arguments. */
578 unsigned int has_template_arguments : 1;
579
580 /* The name of this DIE. Normally the value of DW_AT_name, but
581 sometimes a default name for unnamed DIEs. */
582 char *name;
583
584 /* The scope to prepend to our children. This is generally
585 allocated on the comp_unit_obstack, so will disappear
586 when this compilation unit leaves the cache. */
587 char *scope;
588
589 /* The location description associated with this DIE, if any. */
590 struct dwarf_block *locdesc;
591
592 /* If HAS_PC_INFO, the PC range associated with this DIE. */
593 CORE_ADDR lowpc;
594 CORE_ADDR highpc;
595
596 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
597 DW_AT_sibling, if any. */
598 gdb_byte *sibling;
599
600 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
601 DW_AT_specification (or DW_AT_abstract_origin or
602 DW_AT_extension). */
603 unsigned int spec_offset;
604
605 /* Pointers to this DIE's parent, first child, and next sibling,
606 if any. */
607 struct partial_die_info *die_parent, *die_child, *die_sibling;
608 };
609
610 /* This data structure holds the information of an abbrev. */
611 struct abbrev_info
612 {
613 unsigned int number; /* number identifying abbrev */
614 enum dwarf_tag tag; /* dwarf tag */
615 unsigned short has_children; /* boolean */
616 unsigned short num_attrs; /* number of attributes */
617 struct attr_abbrev *attrs; /* an array of attribute descriptions */
618 struct abbrev_info *next; /* next in chain */
619 };
620
621 struct attr_abbrev
622 {
623 ENUM_BITFIELD(dwarf_attribute) name : 16;
624 ENUM_BITFIELD(dwarf_form) form : 16;
625 };
626
627 /* Attributes have a name and a value */
628 struct attribute
629 {
630 ENUM_BITFIELD(dwarf_attribute) name : 16;
631 ENUM_BITFIELD(dwarf_form) form : 15;
632
633 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
634 field should be in u.str (existing only for DW_STRING) but it is kept
635 here for better struct attribute alignment. */
636 unsigned int string_is_canonical : 1;
637
638 union
639 {
640 char *str;
641 struct dwarf_block *blk;
642 ULONGEST unsnd;
643 LONGEST snd;
644 CORE_ADDR addr;
645 struct signatured_type *signatured_type;
646 }
647 u;
648 };
649
650 /* This data structure holds a complete die structure. */
651 struct die_info
652 {
653 /* DWARF-2 tag for this DIE. */
654 ENUM_BITFIELD(dwarf_tag) tag : 16;
655
656 /* Number of attributes */
657 unsigned char num_attrs;
658
659 /* True if we're presently building the full type name for the
660 type derived from this DIE. */
661 unsigned char building_fullname : 1;
662
663 /* Abbrev number */
664 unsigned int abbrev;
665
666 /* Offset in .debug_info or .debug_types section. */
667 unsigned int offset;
668
669 /* The dies in a compilation unit form an n-ary tree. PARENT
670 points to this die's parent; CHILD points to the first child of
671 this node; and all the children of a given node are chained
672 together via their SIBLING fields, terminated by a die whose
673 tag is zero. */
674 struct die_info *child; /* Its first child, if any. */
675 struct die_info *sibling; /* Its next sibling, if any. */
676 struct die_info *parent; /* Its parent, if any. */
677
678 /* An array of attributes, with NUM_ATTRS elements. There may be
679 zero, but it's not common and zero-sized arrays are not
680 sufficiently portable C. */
681 struct attribute attrs[1];
682 };
683
684 struct function_range
685 {
686 const char *name;
687 CORE_ADDR lowpc, highpc;
688 int seen_line;
689 struct function_range *next;
690 };
691
692 /* Get at parts of an attribute structure */
693
694 #define DW_STRING(attr) ((attr)->u.str)
695 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
696 #define DW_UNSND(attr) ((attr)->u.unsnd)
697 #define DW_BLOCK(attr) ((attr)->u.blk)
698 #define DW_SND(attr) ((attr)->u.snd)
699 #define DW_ADDR(attr) ((attr)->u.addr)
700 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
701
702 /* Blocks are a bunch of untyped bytes. */
703 struct dwarf_block
704 {
705 unsigned int size;
706 gdb_byte *data;
707 };
708
709 #ifndef ATTR_ALLOC_CHUNK
710 #define ATTR_ALLOC_CHUNK 4
711 #endif
712
713 /* Allocate fields for structs, unions and enums in this size. */
714 #ifndef DW_FIELD_ALLOC_CHUNK
715 #define DW_FIELD_ALLOC_CHUNK 4
716 #endif
717
718 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
719 but this would require a corresponding change in unpack_field_as_long
720 and friends. */
721 static int bits_per_byte = 8;
722
723 /* The routines that read and process dies for a C struct or C++ class
724 pass lists of data member fields and lists of member function fields
725 in an instance of a field_info structure, as defined below. */
726 struct field_info
727 {
728 /* List of data member and baseclasses fields. */
729 struct nextfield
730 {
731 struct nextfield *next;
732 int accessibility;
733 int virtuality;
734 struct field field;
735 }
736 *fields, *baseclasses;
737
738 /* Number of fields (including baseclasses). */
739 int nfields;
740
741 /* Number of baseclasses. */
742 int nbaseclasses;
743
744 /* Set if the accesibility of one of the fields is not public. */
745 int non_public_fields;
746
747 /* Member function fields array, entries are allocated in the order they
748 are encountered in the object file. */
749 struct nextfnfield
750 {
751 struct nextfnfield *next;
752 struct fn_field fnfield;
753 }
754 *fnfields;
755
756 /* Member function fieldlist array, contains name of possibly overloaded
757 member function, number of overloaded member functions and a pointer
758 to the head of the member function field chain. */
759 struct fnfieldlist
760 {
761 char *name;
762 int length;
763 struct nextfnfield *head;
764 }
765 *fnfieldlists;
766
767 /* Number of entries in the fnfieldlists array. */
768 int nfnfields;
769
770 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
771 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
772 struct typedef_field_list
773 {
774 struct typedef_field field;
775 struct typedef_field_list *next;
776 }
777 *typedef_field_list;
778 unsigned typedef_field_list_count;
779 };
780
781 /* One item on the queue of compilation units to read in full symbols
782 for. */
783 struct dwarf2_queue_item
784 {
785 struct dwarf2_per_cu_data *per_cu;
786 struct dwarf2_queue_item *next;
787 };
788
789 /* The current queue. */
790 static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail;
791
792 /* Loaded secondary compilation units are kept in memory until they
793 have not been referenced for the processing of this many
794 compilation units. Set this to zero to disable caching. Cache
795 sizes of up to at least twenty will improve startup time for
796 typical inter-CU-reference binaries, at an obvious memory cost. */
797 static int dwarf2_max_cache_age = 5;
798 static void
799 show_dwarf2_max_cache_age (struct ui_file *file, int from_tty,
800 struct cmd_list_element *c, const char *value)
801 {
802 fprintf_filtered (file, _("\
803 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
804 value);
805 }
806
807
808 /* Various complaints about symbol reading that don't abort the process */
809
810 static void
811 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
812 {
813 complaint (&symfile_complaints,
814 _("statement list doesn't fit in .debug_line section"));
815 }
816
817 static void
818 dwarf2_debug_line_missing_file_complaint (void)
819 {
820 complaint (&symfile_complaints,
821 _(".debug_line section has line data without a file"));
822 }
823
824 static void
825 dwarf2_debug_line_missing_end_sequence_complaint (void)
826 {
827 complaint (&symfile_complaints,
828 _(".debug_line section has line program sequence without an end"));
829 }
830
831 static void
832 dwarf2_complex_location_expr_complaint (void)
833 {
834 complaint (&symfile_complaints, _("location expression too complex"));
835 }
836
837 static void
838 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
839 int arg3)
840 {
841 complaint (&symfile_complaints,
842 _("const value length mismatch for '%s', got %d, expected %d"), arg1,
843 arg2, arg3);
844 }
845
846 static void
847 dwarf2_macros_too_long_complaint (void)
848 {
849 complaint (&symfile_complaints,
850 _("macro info runs off end of `.debug_macinfo' section"));
851 }
852
853 static void
854 dwarf2_macro_malformed_definition_complaint (const char *arg1)
855 {
856 complaint (&symfile_complaints,
857 _("macro debug info contains a malformed macro definition:\n`%s'"),
858 arg1);
859 }
860
861 static void
862 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
863 {
864 complaint (&symfile_complaints,
865 _("invalid attribute class or form for '%s' in '%s'"), arg1, arg2);
866 }
867
868 /* local function prototypes */
869
870 static void dwarf2_locate_sections (bfd *, asection *, void *);
871
872 static void dwarf2_create_include_psymtab (char *, struct partial_symtab *,
873 struct objfile *);
874
875 static void dwarf2_build_psymtabs_hard (struct objfile *);
876
877 static void scan_partial_symbols (struct partial_die_info *,
878 CORE_ADDR *, CORE_ADDR *,
879 int, struct dwarf2_cu *);
880
881 static void add_partial_symbol (struct partial_die_info *,
882 struct dwarf2_cu *);
883
884 static void add_partial_namespace (struct partial_die_info *pdi,
885 CORE_ADDR *lowpc, CORE_ADDR *highpc,
886 int need_pc, struct dwarf2_cu *cu);
887
888 static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
889 CORE_ADDR *highpc, int need_pc,
890 struct dwarf2_cu *cu);
891
892 static void add_partial_enumeration (struct partial_die_info *enum_pdi,
893 struct dwarf2_cu *cu);
894
895 static void add_partial_subprogram (struct partial_die_info *pdi,
896 CORE_ADDR *lowpc, CORE_ADDR *highpc,
897 int need_pc, struct dwarf2_cu *cu);
898
899 static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi,
900 gdb_byte *buffer, gdb_byte *info_ptr,
901 bfd *abfd, struct dwarf2_cu *cu);
902
903 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
904
905 static void psymtab_to_symtab_1 (struct partial_symtab *);
906
907 static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
908
909 static void dwarf2_free_abbrev_table (void *);
910
911 static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *,
912 struct dwarf2_cu *);
913
914 static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int,
915 struct dwarf2_cu *);
916
917 static struct partial_die_info *load_partial_dies (bfd *,
918 gdb_byte *, gdb_byte *,
919 int, struct dwarf2_cu *);
920
921 static gdb_byte *read_partial_die (struct partial_die_info *,
922 struct abbrev_info *abbrev,
923 unsigned int, bfd *,
924 gdb_byte *, gdb_byte *,
925 struct dwarf2_cu *);
926
927 static struct partial_die_info *find_partial_die (unsigned int,
928 struct dwarf2_cu *);
929
930 static void fixup_partial_die (struct partial_die_info *,
931 struct dwarf2_cu *);
932
933 static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *,
934 bfd *, gdb_byte *, struct dwarf2_cu *);
935
936 static gdb_byte *read_attribute_value (struct attribute *, unsigned,
937 bfd *, gdb_byte *, struct dwarf2_cu *);
938
939 static unsigned int read_1_byte (bfd *, gdb_byte *);
940
941 static int read_1_signed_byte (bfd *, gdb_byte *);
942
943 static unsigned int read_2_bytes (bfd *, gdb_byte *);
944
945 static unsigned int read_4_bytes (bfd *, gdb_byte *);
946
947 static ULONGEST read_8_bytes (bfd *, gdb_byte *);
948
949 static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *,
950 unsigned int *);
951
952 static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *);
953
954 static LONGEST read_checked_initial_length_and_offset
955 (bfd *, gdb_byte *, const struct comp_unit_head *,
956 unsigned int *, unsigned int *);
957
958 static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *,
959 unsigned int *);
960
961 static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int);
962
963 static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int);
964
965 static char *read_direct_string (bfd *, gdb_byte *, unsigned int *);
966
967 static char *read_indirect_string (bfd *, gdb_byte *,
968 const struct comp_unit_head *,
969 unsigned int *);
970
971 static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *);
972
973 static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *);
974
975 static gdb_byte *skip_leb128 (bfd *, gdb_byte *);
976
977 static void set_cu_language (unsigned int, struct dwarf2_cu *);
978
979 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
980 struct dwarf2_cu *);
981
982 static struct attribute *dwarf2_attr_no_follow (struct die_info *,
983 unsigned int,
984 struct dwarf2_cu *);
985
986 static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
987 struct dwarf2_cu *cu);
988
989 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
990
991 static struct die_info *die_specification (struct die_info *die,
992 struct dwarf2_cu **);
993
994 static void free_line_header (struct line_header *lh);
995
996 static void add_file_name (struct line_header *, char *, unsigned int,
997 unsigned int, unsigned int);
998
999 static struct line_header *(dwarf_decode_line_header
1000 (unsigned int offset,
1001 bfd *abfd, struct dwarf2_cu *cu));
1002
1003 static void dwarf_decode_lines (struct line_header *, char *, bfd *,
1004 struct dwarf2_cu *, struct partial_symtab *);
1005
1006 static void dwarf2_start_subfile (char *, char *, char *);
1007
1008 static struct symbol *new_symbol (struct die_info *, struct type *,
1009 struct dwarf2_cu *);
1010
1011 static struct symbol *new_symbol_full (struct die_info *, struct type *,
1012 struct dwarf2_cu *, struct symbol *);
1013
1014 static void dwarf2_const_value (struct attribute *, struct symbol *,
1015 struct dwarf2_cu *);
1016
1017 static void dwarf2_const_value_attr (struct attribute *attr,
1018 struct type *type,
1019 const char *name,
1020 struct obstack *obstack,
1021 struct dwarf2_cu *cu, long *value,
1022 gdb_byte **bytes,
1023 struct dwarf2_locexpr_baton **baton);
1024
1025 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
1026
1027 static int need_gnat_info (struct dwarf2_cu *);
1028
1029 static struct type *die_descriptive_type (struct die_info *, struct dwarf2_cu *);
1030
1031 static void set_descriptive_type (struct type *, struct die_info *,
1032 struct dwarf2_cu *);
1033
1034 static struct type *die_containing_type (struct die_info *,
1035 struct dwarf2_cu *);
1036
1037 static struct type *lookup_die_type (struct die_info *, struct attribute *,
1038 struct dwarf2_cu *);
1039
1040 static struct type *read_type_die (struct die_info *, struct dwarf2_cu *);
1041
1042 static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *);
1043
1044 static char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
1045
1046 static char *typename_concat (struct obstack *obs, const char *prefix,
1047 const char *suffix, int physname,
1048 struct dwarf2_cu *cu);
1049
1050 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
1051
1052 static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *);
1053
1054 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
1055
1056 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
1057
1058 static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *,
1059 struct dwarf2_cu *, struct partial_symtab *);
1060
1061 static int dwarf2_get_pc_bounds (struct die_info *,
1062 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *,
1063 struct partial_symtab *);
1064
1065 static void get_scope_pc_bounds (struct die_info *,
1066 CORE_ADDR *, CORE_ADDR *,
1067 struct dwarf2_cu *);
1068
1069 static void dwarf2_record_block_ranges (struct die_info *, struct block *,
1070 CORE_ADDR, struct dwarf2_cu *);
1071
1072 static void dwarf2_add_field (struct field_info *, struct die_info *,
1073 struct dwarf2_cu *);
1074
1075 static void dwarf2_attach_fields_to_type (struct field_info *,
1076 struct type *, struct dwarf2_cu *);
1077
1078 static void dwarf2_add_member_fn (struct field_info *,
1079 struct die_info *, struct type *,
1080 struct dwarf2_cu *);
1081
1082 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
1083 struct type *, struct dwarf2_cu *);
1084
1085 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
1086
1087 static void read_common_block (struct die_info *, struct dwarf2_cu *);
1088
1089 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
1090
1091 static void read_module (struct die_info *die, struct dwarf2_cu *cu);
1092
1093 static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
1094
1095 static struct type *read_module_type (struct die_info *die,
1096 struct dwarf2_cu *cu);
1097
1098 static const char *namespace_name (struct die_info *die,
1099 int *is_anonymous, struct dwarf2_cu *);
1100
1101 static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
1102
1103 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
1104
1105 static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
1106 struct dwarf2_cu *);
1107
1108 static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *);
1109
1110 static struct die_info *read_die_and_children_1 (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_children (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 struct die_info *read_die_and_siblings (const struct die_reader_specs *reader,
1121 gdb_byte *info_ptr,
1122 gdb_byte **new_info_ptr,
1123 struct die_info *parent);
1124
1125 static gdb_byte *read_full_die (const struct die_reader_specs *reader,
1126 struct die_info **, gdb_byte *,
1127 int *);
1128
1129 static void process_die (struct die_info *, struct dwarf2_cu *);
1130
1131 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *,
1132 struct obstack *);
1133
1134 static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
1135
1136 static const char *dwarf2_full_name (char *name,
1137 struct die_info *die,
1138 struct dwarf2_cu *cu);
1139
1140 static struct die_info *dwarf2_extension (struct die_info *die,
1141 struct dwarf2_cu **);
1142
1143 static char *dwarf_tag_name (unsigned int);
1144
1145 static char *dwarf_attr_name (unsigned int);
1146
1147 static char *dwarf_form_name (unsigned int);
1148
1149 static char *dwarf_bool_name (unsigned int);
1150
1151 static char *dwarf_type_encoding_name (unsigned int);
1152
1153 #if 0
1154 static char *dwarf_cfi_name (unsigned int);
1155 #endif
1156
1157 static struct die_info *sibling_die (struct die_info *);
1158
1159 static void dump_die_shallow (struct ui_file *, int indent, struct die_info *);
1160
1161 static void dump_die_for_error (struct die_info *);
1162
1163 static void dump_die_1 (struct ui_file *, int level, int max_level,
1164 struct die_info *);
1165
1166 /*static*/ void dump_die (struct die_info *, int max_level);
1167
1168 static void store_in_ref_table (struct die_info *,
1169 struct dwarf2_cu *);
1170
1171 static int is_ref_attr (struct attribute *);
1172
1173 static unsigned int dwarf2_get_ref_die_offset (struct attribute *);
1174
1175 static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int);
1176
1177 static struct die_info *follow_die_ref_or_sig (struct die_info *,
1178 struct attribute *,
1179 struct dwarf2_cu **);
1180
1181 static struct die_info *follow_die_ref (struct die_info *,
1182 struct attribute *,
1183 struct dwarf2_cu **);
1184
1185 static struct die_info *follow_die_sig (struct die_info *,
1186 struct attribute *,
1187 struct dwarf2_cu **);
1188
1189 static void read_signatured_type_at_offset (struct objfile *objfile,
1190 unsigned int offset);
1191
1192 static void read_signatured_type (struct objfile *,
1193 struct signatured_type *type_sig);
1194
1195 /* memory allocation interface */
1196
1197 static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
1198
1199 static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *);
1200
1201 static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int);
1202
1203 static void initialize_cu_func_list (struct dwarf2_cu *);
1204
1205 static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR,
1206 struct dwarf2_cu *);
1207
1208 static void dwarf_decode_macros (struct line_header *, unsigned int,
1209 char *, bfd *, struct dwarf2_cu *);
1210
1211 static int attr_form_is_block (struct attribute *);
1212
1213 static int attr_form_is_section_offset (struct attribute *);
1214
1215 static int attr_form_is_constant (struct attribute *);
1216
1217 static void dwarf2_symbol_mark_computed (struct attribute *attr,
1218 struct symbol *sym,
1219 struct dwarf2_cu *cu);
1220
1221 static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
1222 struct abbrev_info *abbrev,
1223 struct dwarf2_cu *cu);
1224
1225 static void free_stack_comp_unit (void *);
1226
1227 static hashval_t partial_die_hash (const void *item);
1228
1229 static int partial_die_eq (const void *item_lhs, const void *item_rhs);
1230
1231 static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit
1232 (unsigned int offset, struct objfile *objfile);
1233
1234 static struct dwarf2_per_cu_data *dwarf2_find_comp_unit
1235 (unsigned int offset, struct objfile *objfile);
1236
1237 static struct dwarf2_cu *alloc_one_comp_unit (struct objfile *objfile);
1238
1239 static void free_one_comp_unit (void *);
1240
1241 static void free_cached_comp_units (void *);
1242
1243 static void age_cached_comp_units (void);
1244
1245 static void free_one_cached_comp_unit (void *);
1246
1247 static struct type *set_die_type (struct die_info *, struct type *,
1248 struct dwarf2_cu *);
1249
1250 static void create_all_comp_units (struct objfile *);
1251
1252 static int create_debug_types_hash_table (struct objfile *objfile);
1253
1254 static void load_full_comp_unit (struct dwarf2_per_cu_data *,
1255 struct objfile *);
1256
1257 static void process_full_comp_unit (struct dwarf2_per_cu_data *);
1258
1259 static void dwarf2_add_dependence (struct dwarf2_cu *,
1260 struct dwarf2_per_cu_data *);
1261
1262 static void dwarf2_mark (struct dwarf2_cu *);
1263
1264 static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
1265
1266 static struct type *get_die_type_at_offset (unsigned int,
1267 struct dwarf2_per_cu_data *per_cu);
1268
1269 static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
1270
1271 static void dwarf2_release_queue (void *dummy);
1272
1273 static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu,
1274 struct objfile *objfile);
1275
1276 static void process_queue (struct objfile *objfile);
1277
1278 static void find_file_and_directory (struct die_info *die,
1279 struct dwarf2_cu *cu,
1280 char **name, char **comp_dir);
1281
1282 static char *file_full_name (int file, struct line_header *lh,
1283 const char *comp_dir);
1284
1285 static gdb_byte *partial_read_comp_unit_head (struct comp_unit_head *header,
1286 gdb_byte *info_ptr,
1287 gdb_byte *buffer,
1288 unsigned int buffer_size,
1289 bfd *abfd);
1290
1291 static void init_cu_die_reader (struct die_reader_specs *reader,
1292 struct dwarf2_cu *cu);
1293
1294 static htab_t allocate_signatured_type_table (struct objfile *objfile);
1295
1296 #if WORDS_BIGENDIAN
1297
1298 /* Convert VALUE between big- and little-endian. */
1299 static offset_type
1300 byte_swap (offset_type value)
1301 {
1302 offset_type result;
1303
1304 result = (value & 0xff) << 24;
1305 result |= (value & 0xff00) << 8;
1306 result |= (value & 0xff0000) >> 8;
1307 result |= (value & 0xff000000) >> 24;
1308 return result;
1309 }
1310
1311 #define MAYBE_SWAP(V) byte_swap (V)
1312
1313 #else
1314 #define MAYBE_SWAP(V) (V)
1315 #endif /* WORDS_BIGENDIAN */
1316
1317 /* The suffix for an index file. */
1318 #define INDEX_SUFFIX ".gdb-index"
1319
1320 static const char *dwarf2_physname (char *name, struct die_info *die,
1321 struct dwarf2_cu *cu);
1322
1323 /* Try to locate the sections we need for DWARF 2 debugging
1324 information and return true if we have enough to do something. */
1325
1326 int
1327 dwarf2_has_info (struct objfile *objfile)
1328 {
1329 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
1330 if (!dwarf2_per_objfile)
1331 {
1332 /* Initialize per-objfile state. */
1333 struct dwarf2_per_objfile *data
1334 = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
1335
1336 memset (data, 0, sizeof (*data));
1337 set_objfile_data (objfile, dwarf2_objfile_data_key, data);
1338 dwarf2_per_objfile = data;
1339
1340 bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL);
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 can either look for ".<name>", or for
1348 * ".z<name>", which indicates a compressed section. */
1349
1350 static int
1351 section_is_p (const char *section_name, const char *name)
1352 {
1353 return (section_name[0] == '.'
1354 && (strcmp (section_name + 1, name) == 0
1355 || (section_name[1] == 'z'
1356 && strcmp (section_name + 2, name) == 0)));
1357 }
1358
1359 /* This function is mapped across the sections and remembers the
1360 offset and size of each of the debugging sections we are interested
1361 in. */
1362
1363 static void
1364 dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr)
1365 {
1366 if (section_is_p (sectp->name, INFO_SECTION))
1367 {
1368 dwarf2_per_objfile->info.asection = sectp;
1369 dwarf2_per_objfile->info.size = bfd_get_section_size (sectp);
1370 }
1371 else if (section_is_p (sectp->name, ABBREV_SECTION))
1372 {
1373 dwarf2_per_objfile->abbrev.asection = sectp;
1374 dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp);
1375 }
1376 else if (section_is_p (sectp->name, LINE_SECTION))
1377 {
1378 dwarf2_per_objfile->line.asection = sectp;
1379 dwarf2_per_objfile->line.size = bfd_get_section_size (sectp);
1380 }
1381 else if (section_is_p (sectp->name, LOC_SECTION))
1382 {
1383 dwarf2_per_objfile->loc.asection = sectp;
1384 dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp);
1385 }
1386 else if (section_is_p (sectp->name, MACINFO_SECTION))
1387 {
1388 dwarf2_per_objfile->macinfo.asection = sectp;
1389 dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp);
1390 }
1391 else if (section_is_p (sectp->name, STR_SECTION))
1392 {
1393 dwarf2_per_objfile->str.asection = sectp;
1394 dwarf2_per_objfile->str.size = bfd_get_section_size (sectp);
1395 }
1396 else if (section_is_p (sectp->name, FRAME_SECTION))
1397 {
1398 dwarf2_per_objfile->frame.asection = sectp;
1399 dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp);
1400 }
1401 else if (section_is_p (sectp->name, EH_FRAME_SECTION))
1402 {
1403 flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
1404
1405 if (aflag & SEC_HAS_CONTENTS)
1406 {
1407 dwarf2_per_objfile->eh_frame.asection = sectp;
1408 dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp);
1409 }
1410 }
1411 else if (section_is_p (sectp->name, RANGES_SECTION))
1412 {
1413 dwarf2_per_objfile->ranges.asection = sectp;
1414 dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp);
1415 }
1416 else if (section_is_p (sectp->name, TYPES_SECTION))
1417 {
1418 dwarf2_per_objfile->types.asection = sectp;
1419 dwarf2_per_objfile->types.size = bfd_get_section_size (sectp);
1420 }
1421 else if (section_is_p (sectp->name, GDB_INDEX_SECTION))
1422 {
1423 dwarf2_per_objfile->gdb_index.asection = sectp;
1424 dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp);
1425 }
1426
1427 if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD)
1428 && bfd_section_vma (abfd, sectp) == 0)
1429 dwarf2_per_objfile->has_section_at_zero = 1;
1430 }
1431
1432 /* Decompress a section that was compressed using zlib. Store the
1433 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1434
1435 static void
1436 zlib_decompress_section (struct objfile *objfile, asection *sectp,
1437 gdb_byte **outbuf, bfd_size_type *outsize)
1438 {
1439 bfd *abfd = objfile->obfd;
1440 #ifndef HAVE_ZLIB_H
1441 error (_("Support for zlib-compressed DWARF data (from '%s') "
1442 "is disabled in this copy of GDB"),
1443 bfd_get_filename (abfd));
1444 #else
1445 bfd_size_type compressed_size = bfd_get_section_size (sectp);
1446 gdb_byte *compressed_buffer = xmalloc (compressed_size);
1447 struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer);
1448 bfd_size_type uncompressed_size;
1449 gdb_byte *uncompressed_buffer;
1450 z_stream strm;
1451 int rc;
1452 int header_size = 12;
1453
1454 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1455 || bfd_bread (compressed_buffer, compressed_size, abfd) != compressed_size)
1456 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1457 bfd_get_filename (abfd));
1458
1459 /* Read the zlib header. In this case, it should be "ZLIB" followed
1460 by the uncompressed section size, 8 bytes in big-endian order. */
1461 if (compressed_size < header_size
1462 || strncmp (compressed_buffer, "ZLIB", 4) != 0)
1463 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1464 bfd_get_filename (abfd));
1465 uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
1466 uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
1467 uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
1468 uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8;
1469 uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8;
1470 uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8;
1471 uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8;
1472 uncompressed_size += compressed_buffer[11];
1473
1474 /* It is possible the section consists of several compressed
1475 buffers concatenated together, so we uncompress in a loop. */
1476 strm.zalloc = NULL;
1477 strm.zfree = NULL;
1478 strm.opaque = NULL;
1479 strm.avail_in = compressed_size - header_size;
1480 strm.next_in = (Bytef*) compressed_buffer + header_size;
1481 strm.avail_out = uncompressed_size;
1482 uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack,
1483 uncompressed_size);
1484 rc = inflateInit (&strm);
1485 while (strm.avail_in > 0)
1486 {
1487 if (rc != Z_OK)
1488 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1489 bfd_get_filename (abfd), rc);
1490 strm.next_out = ((Bytef*) uncompressed_buffer
1491 + (uncompressed_size - strm.avail_out));
1492 rc = inflate (&strm, Z_FINISH);
1493 if (rc != Z_STREAM_END)
1494 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1495 bfd_get_filename (abfd), rc);
1496 rc = inflateReset (&strm);
1497 }
1498 rc = inflateEnd (&strm);
1499 if (rc != Z_OK
1500 || strm.avail_out != 0)
1501 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1502 bfd_get_filename (abfd), rc);
1503
1504 do_cleanups (cleanup);
1505 *outbuf = uncompressed_buffer;
1506 *outsize = uncompressed_size;
1507 #endif
1508 }
1509
1510 /* Read the contents of the section SECTP from object file specified by
1511 OBJFILE, store info about the section into INFO.
1512 If the section is compressed, uncompress it before returning. */
1513
1514 static void
1515 dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
1516 {
1517 bfd *abfd = objfile->obfd;
1518 asection *sectp = info->asection;
1519 gdb_byte *buf, *retbuf;
1520 unsigned char header[4];
1521
1522 if (info->readin)
1523 return;
1524 info->buffer = NULL;
1525 info->was_mmapped = 0;
1526 info->readin = 1;
1527
1528 if (info->asection == NULL || info->size == 0)
1529 return;
1530
1531 /* Check if the file has a 4-byte header indicating compression. */
1532 if (info->size > sizeof (header)
1533 && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0
1534 && bfd_bread (header, sizeof (header), abfd) == sizeof (header))
1535 {
1536 /* Upon decompression, update the buffer and its size. */
1537 if (strncmp (header, "ZLIB", sizeof (header)) == 0)
1538 {
1539 zlib_decompress_section (objfile, sectp, &info->buffer,
1540 &info->size);
1541 return;
1542 }
1543 }
1544
1545 #ifdef HAVE_MMAP
1546 if (pagesize == 0)
1547 pagesize = getpagesize ();
1548
1549 /* Only try to mmap sections which are large enough: we don't want to
1550 waste space due to fragmentation. Also, only try mmap for sections
1551 without relocations. */
1552
1553 if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0)
1554 {
1555 off_t pg_offset = sectp->filepos & ~(pagesize - 1);
1556 size_t map_length = info->size + sectp->filepos - pg_offset;
1557 caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ,
1558 MAP_PRIVATE, pg_offset);
1559
1560 if (retbuf != MAP_FAILED)
1561 {
1562 info->was_mmapped = 1;
1563 info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ;
1564 #if HAVE_POSIX_MADVISE
1565 posix_madvise (retbuf, map_length, POSIX_MADV_WILLNEED);
1566 #endif
1567 return;
1568 }
1569 }
1570 #endif
1571
1572 /* If we get here, we are a normal, not-compressed section. */
1573 info->buffer = buf
1574 = obstack_alloc (&objfile->objfile_obstack, info->size);
1575
1576 /* When debugging .o files, we may need to apply relocations; see
1577 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1578 We never compress sections in .o files, so we only need to
1579 try this when the section is not compressed. */
1580 retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
1581 if (retbuf != NULL)
1582 {
1583 info->buffer = retbuf;
1584 return;
1585 }
1586
1587 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1588 || bfd_bread (buf, info->size, abfd) != info->size)
1589 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1590 bfd_get_filename (abfd));
1591 }
1592
1593 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1594 SECTION_NAME. */
1595
1596 void
1597 dwarf2_get_section_info (struct objfile *objfile, const char *section_name,
1598 asection **sectp, gdb_byte **bufp,
1599 bfd_size_type *sizep)
1600 {
1601 struct dwarf2_per_objfile *data
1602 = objfile_data (objfile, dwarf2_objfile_data_key);
1603 struct dwarf2_section_info *info;
1604
1605 /* We may see an objfile without any DWARF, in which case we just
1606 return nothing. */
1607 if (data == NULL)
1608 {
1609 *sectp = NULL;
1610 *bufp = NULL;
1611 *sizep = 0;
1612 return;
1613 }
1614 if (section_is_p (section_name, EH_FRAME_SECTION))
1615 info = &data->eh_frame;
1616 else if (section_is_p (section_name, FRAME_SECTION))
1617 info = &data->frame;
1618 else
1619 gdb_assert_not_reached ("unexpected section");
1620
1621 if (info->asection != NULL && info->size != 0 && info->buffer == NULL)
1622 /* We haven't read this section in yet. Do it now. */
1623 dwarf2_read_section (objfile, info);
1624
1625 *sectp = info->asection;
1626 *bufp = info->buffer;
1627 *sizep = info->size;
1628 }
1629
1630 \f
1631
1632 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1633 this CU came. */
1634 static void
1635 dw2_do_instantiate_symtab (struct objfile *objfile,
1636 struct dwarf2_per_cu_data *per_cu)
1637 {
1638 struct cleanup *back_to;
1639
1640 back_to = make_cleanup (dwarf2_release_queue, NULL);
1641
1642 queue_comp_unit (per_cu, objfile);
1643
1644 if (per_cu->from_debug_types)
1645 read_signatured_type_at_offset (objfile, per_cu->offset);
1646 else
1647 load_full_comp_unit (per_cu, objfile);
1648
1649 process_queue (objfile);
1650
1651 /* Age the cache, releasing compilation units that have not
1652 been used recently. */
1653 age_cached_comp_units ();
1654
1655 do_cleanups (back_to);
1656 }
1657
1658 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1659 the objfile from which this CU came. Returns the resulting symbol
1660 table. */
1661 static struct symtab *
1662 dw2_instantiate_symtab (struct objfile *objfile,
1663 struct dwarf2_per_cu_data *per_cu)
1664 {
1665 if (!per_cu->v.quick->symtab)
1666 {
1667 struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL);
1668 increment_reading_symtab ();
1669 dw2_do_instantiate_symtab (objfile, per_cu);
1670 do_cleanups (back_to);
1671 }
1672 return per_cu->v.quick->symtab;
1673 }
1674
1675 /* Return the CU given its index. */
1676 static struct dwarf2_per_cu_data *
1677 dw2_get_cu (int index)
1678 {
1679 if (index >= dwarf2_per_objfile->n_comp_units)
1680 {
1681 index -= dwarf2_per_objfile->n_comp_units;
1682 return dwarf2_per_objfile->type_comp_units[index];
1683 }
1684 return dwarf2_per_objfile->all_comp_units[index];
1685 }
1686
1687 /* A helper function that knows how to read a 64-bit value in a way
1688 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1689 otherwise. */
1690 static int
1691 extract_cu_value (const char *bytes, ULONGEST *result)
1692 {
1693 if (sizeof (ULONGEST) < 8)
1694 {
1695 int i;
1696
1697 /* Ignore the upper 4 bytes if they are all zero. */
1698 for (i = 0; i < 4; ++i)
1699 if (bytes[i + 4] != 0)
1700 return 0;
1701
1702 *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE);
1703 }
1704 else
1705 *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE);
1706 return 1;
1707 }
1708
1709 /* Read the CU list from the mapped index, and use it to create all
1710 the CU objects for this objfile. Return 0 if something went wrong,
1711 1 if everything went ok. */
1712 static int
1713 create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list,
1714 offset_type cu_list_elements)
1715 {
1716 offset_type i;
1717
1718 dwarf2_per_objfile->n_comp_units = cu_list_elements / 2;
1719 dwarf2_per_objfile->all_comp_units
1720 = obstack_alloc (&objfile->objfile_obstack,
1721 dwarf2_per_objfile->n_comp_units
1722 * sizeof (struct dwarf2_per_cu_data *));
1723
1724 for (i = 0; i < cu_list_elements; i += 2)
1725 {
1726 struct dwarf2_per_cu_data *the_cu;
1727 ULONGEST offset, length;
1728
1729 if (!extract_cu_value (cu_list, &offset)
1730 || !extract_cu_value (cu_list + 8, &length))
1731 return 0;
1732 cu_list += 2 * 8;
1733
1734 the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1735 struct dwarf2_per_cu_data);
1736 the_cu->offset = offset;
1737 the_cu->length = length;
1738 the_cu->objfile = objfile;
1739 the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1740 struct dwarf2_per_cu_quick_data);
1741 dwarf2_per_objfile->all_comp_units[i / 2] = the_cu;
1742 }
1743
1744 return 1;
1745 }
1746
1747 /* Create the signatured type hash table from the index. */
1748
1749 static int
1750 create_signatured_type_table_from_index (struct objfile *objfile,
1751 const gdb_byte *bytes,
1752 offset_type elements)
1753 {
1754 offset_type i;
1755 htab_t sig_types_hash;
1756
1757 dwarf2_per_objfile->n_type_comp_units = elements / 3;
1758 dwarf2_per_objfile->type_comp_units
1759 = obstack_alloc (&objfile->objfile_obstack,
1760 dwarf2_per_objfile->n_type_comp_units
1761 * sizeof (struct dwarf2_per_cu_data *));
1762
1763 sig_types_hash = allocate_signatured_type_table (objfile);
1764
1765 for (i = 0; i < elements; i += 3)
1766 {
1767 struct signatured_type *type_sig;
1768 ULONGEST offset, type_offset, signature;
1769 void **slot;
1770
1771 if (!extract_cu_value (bytes, &offset)
1772 || !extract_cu_value (bytes + 8, &type_offset))
1773 return 0;
1774 signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE);
1775 bytes += 3 * 8;
1776
1777 type_sig = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1778 struct signatured_type);
1779 type_sig->signature = signature;
1780 type_sig->offset = offset;
1781 type_sig->type_offset = type_offset;
1782 type_sig->per_cu.from_debug_types = 1;
1783 type_sig->per_cu.offset = offset;
1784 type_sig->per_cu.objfile = objfile;
1785 type_sig->per_cu.v.quick
1786 = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1787 struct dwarf2_per_cu_quick_data);
1788
1789 slot = htab_find_slot (sig_types_hash, type_sig, INSERT);
1790 *slot = type_sig;
1791
1792 dwarf2_per_objfile->type_comp_units[i / 3] = &type_sig->per_cu;
1793 }
1794
1795 dwarf2_per_objfile->signatured_types = sig_types_hash;
1796
1797 return 1;
1798 }
1799
1800 /* Read the address map data from the mapped index, and use it to
1801 populate the objfile's psymtabs_addrmap. */
1802 static void
1803 create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index)
1804 {
1805 const gdb_byte *iter, *end;
1806 struct obstack temp_obstack;
1807 struct addrmap *mutable_map;
1808 struct cleanup *cleanup;
1809 CORE_ADDR baseaddr;
1810
1811 obstack_init (&temp_obstack);
1812 cleanup = make_cleanup_obstack_free (&temp_obstack);
1813 mutable_map = addrmap_create_mutable (&temp_obstack);
1814
1815 iter = index->address_table;
1816 end = iter + index->address_table_size;
1817
1818 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1819
1820 while (iter < end)
1821 {
1822 ULONGEST hi, lo, cu_index;
1823 lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
1824 iter += 8;
1825 hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
1826 iter += 8;
1827 cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE);
1828 iter += 4;
1829
1830 addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1,
1831 dw2_get_cu (cu_index));
1832 }
1833
1834 objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map,
1835 &objfile->objfile_obstack);
1836 do_cleanups (cleanup);
1837 }
1838
1839 /* The hash function for strings in the mapped index. This is the
1840 same as the hashtab.c hash function, but we keep a separate copy to
1841 maintain control over the implementation. This is necessary
1842 because the hash function is tied to the format of the mapped index
1843 file. */
1844 static hashval_t
1845 mapped_index_string_hash (const void *p)
1846 {
1847 const unsigned char *str = (const unsigned char *) p;
1848 hashval_t r = 0;
1849 unsigned char c;
1850
1851 while ((c = *str++) != 0)
1852 r = r * 67 + c - 113;
1853
1854 return r;
1855 }
1856
1857 /* Find a slot in the mapped index INDEX for the object named NAME.
1858 If NAME is found, set *VEC_OUT to point to the CU vector in the
1859 constant pool and return 1. If NAME cannot be found, return 0. */
1860 static int
1861 find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
1862 offset_type **vec_out)
1863 {
1864 offset_type hash = mapped_index_string_hash (name);
1865 offset_type slot, step;
1866
1867 slot = hash & (index->index_table_slots - 1);
1868 step = ((hash * 17) & (index->index_table_slots - 1)) | 1;
1869
1870 for (;;)
1871 {
1872 /* Convert a slot number to an offset into the table. */
1873 offset_type i = 2 * slot;
1874 const char *str;
1875 if (index->index_table[i] == 0 && index->index_table[i + 1] == 0)
1876 return 0;
1877
1878 str = index->constant_pool + MAYBE_SWAP (index->index_table[i]);
1879 if (!strcmp (name, str))
1880 {
1881 *vec_out = (offset_type *) (index->constant_pool
1882 + MAYBE_SWAP (index->index_table[i + 1]));
1883 return 1;
1884 }
1885
1886 slot = (slot + step) & (index->index_table_slots - 1);
1887 }
1888 }
1889
1890 /* Read the index file. If everything went ok, initialize the "quick"
1891 elements of all the CUs and return 1. Otherwise, return 0. */
1892 static int
1893 dwarf2_read_index (struct objfile *objfile)
1894 {
1895 char *addr;
1896 struct mapped_index *map;
1897 offset_type *metadata;
1898 const gdb_byte *cu_list;
1899 const gdb_byte *types_list = NULL;
1900 offset_type version, cu_list_elements;
1901 offset_type types_list_elements = 0;
1902 int i;
1903
1904 if (dwarf2_per_objfile->gdb_index.asection == NULL
1905 || dwarf2_per_objfile->gdb_index.size == 0)
1906 return 0;
1907 dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index);
1908
1909 addr = dwarf2_per_objfile->gdb_index.buffer;
1910 /* Version check. */
1911 version = MAYBE_SWAP (*(offset_type *) addr);
1912 if (version == 1)
1913 {
1914 /* Index version 1 neglected to account for .debug_types. So,
1915 if we see .debug_types, we cannot use this index. */
1916 if (dwarf2_per_objfile->types.asection != NULL
1917 && dwarf2_per_objfile->types.size != 0)
1918 return 0;
1919 }
1920 else if (version != 2)
1921 return 0;
1922
1923 map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index);
1924 map->total_size = dwarf2_per_objfile->gdb_index.size;
1925
1926 metadata = (offset_type *) (addr + sizeof (offset_type));
1927
1928 i = 0;
1929 cu_list = addr + MAYBE_SWAP (metadata[i]);
1930 cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i]))
1931 / 8);
1932 ++i;
1933
1934 if (version == 2)
1935 {
1936 types_list = addr + MAYBE_SWAP (metadata[i]);
1937 types_list_elements = ((MAYBE_SWAP (metadata[i + 1])
1938 - MAYBE_SWAP (metadata[i]))
1939 / 8);
1940 ++i;
1941 }
1942
1943 map->address_table = addr + MAYBE_SWAP (metadata[i]);
1944 map->address_table_size = (MAYBE_SWAP (metadata[i + 1])
1945 - MAYBE_SWAP (metadata[i]));
1946 ++i;
1947
1948 map->index_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i]));
1949 map->index_table_slots = ((MAYBE_SWAP (metadata[i + 1])
1950 - MAYBE_SWAP (metadata[i]))
1951 / (2 * sizeof (offset_type)));
1952 ++i;
1953
1954 map->constant_pool = addr + MAYBE_SWAP (metadata[i]);
1955
1956 if (!create_cus_from_index (objfile, cu_list, cu_list_elements))
1957 return 0;
1958
1959 if (version == 2
1960 && types_list_elements
1961 && !create_signatured_type_table_from_index (objfile, types_list,
1962 types_list_elements))
1963 return 0;
1964
1965 create_addrmap_from_index (objfile, map);
1966
1967 dwarf2_per_objfile->index_table = map;
1968 dwarf2_per_objfile->using_index = 1;
1969
1970 return 1;
1971 }
1972
1973 /* A helper for the "quick" functions which sets the global
1974 dwarf2_per_objfile according to OBJFILE. */
1975 static void
1976 dw2_setup (struct objfile *objfile)
1977 {
1978 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
1979 gdb_assert (dwarf2_per_objfile);
1980 }
1981
1982 /* A helper for the "quick" functions which attempts to read the line
1983 table for THIS_CU. */
1984 static void
1985 dw2_require_line_header (struct objfile *objfile,
1986 struct dwarf2_per_cu_data *this_cu)
1987 {
1988 bfd *abfd = objfile->obfd;
1989 struct line_header *lh = NULL;
1990 struct attribute *attr;
1991 struct cleanup *cleanups;
1992 struct die_info *comp_unit_die;
1993 struct dwarf2_section_info* sec;
1994 gdb_byte *beg_of_comp_unit, *info_ptr, *buffer;
1995 int has_children, i;
1996 struct dwarf2_cu cu;
1997 unsigned int bytes_read, buffer_size;
1998 struct die_reader_specs reader_specs;
1999 char *name, *comp_dir;
2000
2001 if (this_cu->v.quick->read_lines)
2002 return;
2003 this_cu->v.quick->read_lines = 1;
2004
2005 memset (&cu, 0, sizeof (cu));
2006 cu.objfile = objfile;
2007 obstack_init (&cu.comp_unit_obstack);
2008
2009 cleanups = make_cleanup (free_stack_comp_unit, &cu);
2010
2011 if (this_cu->from_debug_types)
2012 sec = &dwarf2_per_objfile->types;
2013 else
2014 sec = &dwarf2_per_objfile->info;
2015 dwarf2_read_section (objfile, sec);
2016 buffer_size = sec->size;
2017 buffer = sec->buffer;
2018 info_ptr = buffer + this_cu->offset;
2019 beg_of_comp_unit = info_ptr;
2020
2021 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
2022 buffer, buffer_size,
2023 abfd);
2024
2025 /* Complete the cu_header. */
2026 cu.header.offset = beg_of_comp_unit - buffer;
2027 cu.header.first_die_offset = info_ptr - beg_of_comp_unit;
2028
2029 this_cu->cu = &cu;
2030 cu.per_cu = this_cu;
2031
2032 dwarf2_read_abbrevs (abfd, &cu);
2033 make_cleanup (dwarf2_free_abbrev_table, &cu);
2034
2035 if (this_cu->from_debug_types)
2036 info_ptr += 8 /*signature*/ + cu.header.offset_size;
2037 init_cu_die_reader (&reader_specs, &cu);
2038 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
2039 &has_children);
2040
2041 attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu);
2042 if (attr)
2043 {
2044 unsigned int line_offset = DW_UNSND (attr);
2045 lh = dwarf_decode_line_header (line_offset, abfd, &cu);
2046 }
2047 if (lh == NULL)
2048 {
2049 do_cleanups (cleanups);
2050 return;
2051 }
2052
2053 find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir);
2054
2055 this_cu->v.quick->lines = lh;
2056
2057 this_cu->v.quick->file_names
2058 = obstack_alloc (&objfile->objfile_obstack,
2059 lh->num_file_names * sizeof (char *));
2060 for (i = 0; i < lh->num_file_names; ++i)
2061 this_cu->v.quick->file_names[i] = file_full_name (i + 1, lh, comp_dir);
2062
2063 do_cleanups (cleanups);
2064 }
2065
2066 /* A helper for the "quick" functions which computes and caches the
2067 real path for a given file name from the line table.
2068 dw2_require_line_header must have been called before this is
2069 invoked. */
2070 static const char *
2071 dw2_require_full_path (struct objfile *objfile,
2072 struct dwarf2_per_cu_data *per_cu,
2073 int index)
2074 {
2075 if (!per_cu->v.quick->full_names)
2076 per_cu->v.quick->full_names
2077 = OBSTACK_CALLOC (&objfile->objfile_obstack,
2078 per_cu->v.quick->lines->num_file_names,
2079 sizeof (char *));
2080
2081 if (!per_cu->v.quick->full_names[index])
2082 per_cu->v.quick->full_names[index]
2083 = gdb_realpath (per_cu->v.quick->file_names[index]);
2084
2085 return per_cu->v.quick->full_names[index];
2086 }
2087
2088 static struct symtab *
2089 dw2_find_last_source_symtab (struct objfile *objfile)
2090 {
2091 int index;
2092 dw2_setup (objfile);
2093 index = dwarf2_per_objfile->n_comp_units - 1;
2094 return dw2_instantiate_symtab (objfile, dw2_get_cu (index));
2095 }
2096
2097 static void
2098 dw2_forget_cached_source_info (struct objfile *objfile)
2099 {
2100 int i;
2101
2102 dw2_setup (objfile);
2103 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2104 + dwarf2_per_objfile->n_type_comp_units); ++i)
2105 {
2106 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2107
2108 if (per_cu->v.quick->full_names)
2109 {
2110 int j;
2111
2112 for (j = 0; j < per_cu->v.quick->lines->num_file_names; ++j)
2113 xfree ((void *) per_cu->v.quick->full_names[j]);
2114 }
2115 }
2116 }
2117
2118 static int
2119 dw2_lookup_symtab (struct objfile *objfile, const char *name,
2120 const char *full_path, const char *real_path,
2121 struct symtab **result)
2122 {
2123 int i;
2124 int check_basename = lbasename (name) == name;
2125 struct dwarf2_per_cu_data *base_cu = NULL;
2126
2127 dw2_setup (objfile);
2128 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2129 + dwarf2_per_objfile->n_type_comp_units); ++i)
2130 {
2131 int j;
2132 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2133
2134 if (per_cu->v.quick->symtab)
2135 continue;
2136
2137 dw2_require_line_header (objfile, per_cu);
2138 if (!per_cu->v.quick->lines)
2139 continue;
2140
2141 for (j = 0; j < per_cu->v.quick->lines->num_file_names; ++j)
2142 {
2143 const char *this_name = per_cu->v.quick->file_names[j];
2144
2145 if (FILENAME_CMP (name, this_name) == 0)
2146 {
2147 *result = dw2_instantiate_symtab (objfile, per_cu);
2148 return 1;
2149 }
2150
2151 if (check_basename && ! base_cu
2152 && FILENAME_CMP (lbasename (this_name), name) == 0)
2153 base_cu = per_cu;
2154
2155 if (full_path != NULL)
2156 {
2157 const char *this_full_name = dw2_require_full_path (objfile,
2158 per_cu, j);
2159
2160 if (this_full_name
2161 && FILENAME_CMP (full_path, this_full_name) == 0)
2162 {
2163 *result = dw2_instantiate_symtab (objfile, per_cu);
2164 return 1;
2165 }
2166 }
2167
2168 if (real_path != NULL)
2169 {
2170 const char *this_full_name = dw2_require_full_path (objfile,
2171 per_cu, j);
2172
2173 if (this_full_name != NULL)
2174 {
2175 char *rp = gdb_realpath (this_full_name);
2176 if (rp != NULL && FILENAME_CMP (real_path, rp) == 0)
2177 {
2178 xfree (rp);
2179 *result = dw2_instantiate_symtab (objfile, per_cu);
2180 return 1;
2181 }
2182 xfree (rp);
2183 }
2184 }
2185 }
2186 }
2187
2188 if (base_cu)
2189 {
2190 *result = dw2_instantiate_symtab (objfile, base_cu);
2191 return 1;
2192 }
2193
2194 return 0;
2195 }
2196
2197 static struct symtab *
2198 dw2_lookup_symbol (struct objfile *objfile, int block_index,
2199 const char *name, domain_enum domain)
2200 {
2201 /* We do all the work in the pre_expand_symtabs_matching hook
2202 instead. */
2203 return NULL;
2204 }
2205
2206 /* A helper function that expands all symtabs that hold an object
2207 named NAME. */
2208 static void
2209 dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name)
2210 {
2211 dw2_setup (objfile);
2212
2213 if (dwarf2_per_objfile->index_table)
2214 {
2215 offset_type *vec;
2216
2217 if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
2218 name, &vec))
2219 {
2220 offset_type i, len = MAYBE_SWAP (*vec);
2221 for (i = 0; i < len; ++i)
2222 {
2223 offset_type cu_index = MAYBE_SWAP (vec[i + 1]);
2224 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index);
2225
2226 dw2_instantiate_symtab (objfile, per_cu);
2227 }
2228 }
2229 }
2230 }
2231
2232 static void
2233 dw2_pre_expand_symtabs_matching (struct objfile *objfile,
2234 int kind, const char *name,
2235 domain_enum domain)
2236 {
2237 dw2_do_expand_symtabs_matching (objfile, name);
2238 }
2239
2240 static void
2241 dw2_print_stats (struct objfile *objfile)
2242 {
2243 int i, count;
2244
2245 dw2_setup (objfile);
2246 count = 0;
2247 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2248 + dwarf2_per_objfile->n_type_comp_units); ++i)
2249 {
2250 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2251
2252 if (!per_cu->v.quick->symtab)
2253 ++count;
2254 }
2255 printf_filtered (_(" Number of unread CUs: %d\n"), count);
2256 }
2257
2258 static void
2259 dw2_dump (struct objfile *objfile)
2260 {
2261 /* Nothing worth printing. */
2262 }
2263
2264 static void
2265 dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets,
2266 struct section_offsets *delta)
2267 {
2268 /* There's nothing to relocate here. */
2269 }
2270
2271 static void
2272 dw2_expand_symtabs_for_function (struct objfile *objfile,
2273 const char *func_name)
2274 {
2275 dw2_do_expand_symtabs_matching (objfile, func_name);
2276 }
2277
2278 static void
2279 dw2_expand_all_symtabs (struct objfile *objfile)
2280 {
2281 int i;
2282
2283 dw2_setup (objfile);
2284
2285 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2286 + dwarf2_per_objfile->n_type_comp_units); ++i)
2287 {
2288 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2289
2290 dw2_instantiate_symtab (objfile, per_cu);
2291 }
2292 }
2293
2294 static void
2295 dw2_expand_symtabs_with_filename (struct objfile *objfile,
2296 const char *filename)
2297 {
2298 int i;
2299
2300 dw2_setup (objfile);
2301 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2302 + dwarf2_per_objfile->n_type_comp_units); ++i)
2303 {
2304 int j;
2305 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2306
2307 if (per_cu->v.quick->symtab)
2308 continue;
2309
2310 dw2_require_line_header (objfile, per_cu);
2311 if (!per_cu->v.quick->lines)
2312 continue;
2313
2314 for (j = 0; j < per_cu->v.quick->lines->num_file_names; ++j)
2315 {
2316 const char *this_name = per_cu->v.quick->file_names[j];
2317 if (strcmp (this_name, filename) == 0)
2318 {
2319 dw2_instantiate_symtab (objfile, per_cu);
2320 break;
2321 }
2322 }
2323 }
2324 }
2325
2326 static const char *
2327 dw2_find_symbol_file (struct objfile *objfile, const char *name)
2328 {
2329 struct dwarf2_per_cu_data *per_cu;
2330 offset_type *vec;
2331
2332 dw2_setup (objfile);
2333
2334 if (!dwarf2_per_objfile->index_table)
2335 return NULL;
2336
2337 if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
2338 name, &vec))
2339 return NULL;
2340
2341 /* Note that this just looks at the very first one named NAME -- but
2342 actually we are looking for a function. find_main_filename
2343 should be rewritten so that it doesn't require a custom hook. It
2344 could just use the ordinary symbol tables. */
2345 /* vec[0] is the length, which must always be >0. */
2346 per_cu = dw2_get_cu (MAYBE_SWAP (vec[1]));
2347
2348 dw2_require_line_header (objfile, per_cu);
2349 if (!per_cu->v.quick->lines)
2350 return NULL;
2351
2352 return per_cu->v.quick->file_names[per_cu->v.quick->lines->num_file_names - 1];
2353 }
2354
2355 static void
2356 dw2_map_ada_symtabs (struct objfile *objfile,
2357 int (*wild_match) (const char *, int, const char *),
2358 int (*is_name_suffix) (const char *),
2359 void (*callback) (struct objfile *,
2360 struct symtab *, void *),
2361 const char *name, int global,
2362 domain_enum namespace, int wild,
2363 void *data)
2364 {
2365 /* For now, we don't support Ada, so this function can't be
2366 reached. */
2367 internal_error (__FILE__, __LINE__,
2368 _("map_ada_symtabs called via index method"));
2369 }
2370
2371 static void
2372 dw2_expand_symtabs_matching (struct objfile *objfile,
2373 int (*file_matcher) (const char *, void *),
2374 int (*name_matcher) (const char *, void *),
2375 domain_enum kind,
2376 void *data)
2377 {
2378 int i;
2379 offset_type iter;
2380
2381 dw2_setup (objfile);
2382 if (!dwarf2_per_objfile->index_table)
2383 return;
2384
2385 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2386 + dwarf2_per_objfile->n_type_comp_units); ++i)
2387 {
2388 int j;
2389 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2390
2391 per_cu->v.quick->mark = 0;
2392 if (per_cu->v.quick->symtab)
2393 continue;
2394
2395 dw2_require_line_header (objfile, per_cu);
2396 if (!per_cu->v.quick->lines)
2397 continue;
2398
2399 for (j = 0; j < per_cu->v.quick->lines->num_file_names; ++j)
2400 {
2401 if (file_matcher (per_cu->v.quick->file_names[j], data))
2402 {
2403 per_cu->v.quick->mark = 1;
2404 break;
2405 }
2406 }
2407 }
2408
2409 for (iter = 0;
2410 iter < dwarf2_per_objfile->index_table->index_table_slots;
2411 ++iter)
2412 {
2413 offset_type idx = 2 * iter;
2414 const char *name;
2415 offset_type *vec, vec_len, vec_idx;
2416
2417 if (dwarf2_per_objfile->index_table->index_table[idx] == 0
2418 && dwarf2_per_objfile->index_table->index_table[idx + 1] == 0)
2419 continue;
2420
2421 name = (dwarf2_per_objfile->index_table->constant_pool
2422 + dwarf2_per_objfile->index_table->index_table[idx]);
2423
2424 if (! (*name_matcher) (name, data))
2425 continue;
2426
2427 /* The name was matched, now expand corresponding CUs that were
2428 marked. */
2429 vec = (offset_type *) (dwarf2_per_objfile->index_table->constant_pool
2430 + dwarf2_per_objfile->index_table->index_table[idx + 1]);
2431 vec_len = MAYBE_SWAP (vec[0]);
2432 for (vec_idx = 0; vec_idx < vec_len; ++vec_idx)
2433 {
2434 struct dwarf2_per_cu_data *per_cu;
2435
2436 per_cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1]));
2437 if (per_cu->v.quick->mark)
2438 dw2_instantiate_symtab (objfile, per_cu);
2439 }
2440 }
2441 }
2442
2443 static struct symtab *
2444 dw2_find_pc_sect_symtab (struct objfile *objfile,
2445 struct minimal_symbol *msymbol,
2446 CORE_ADDR pc,
2447 struct obj_section *section,
2448 int warn_if_readin)
2449 {
2450 struct dwarf2_per_cu_data *data;
2451
2452 dw2_setup (objfile);
2453
2454 if (!objfile->psymtabs_addrmap)
2455 return NULL;
2456
2457 data = addrmap_find (objfile->psymtabs_addrmap, pc);
2458 if (!data)
2459 return NULL;
2460
2461 if (warn_if_readin && data->v.quick->symtab)
2462 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2463 paddress (get_objfile_arch (objfile), pc));
2464
2465 return dw2_instantiate_symtab (objfile, data);
2466 }
2467
2468 static void
2469 dw2_map_symbol_names (struct objfile *objfile,
2470 void (*fun) (const char *, void *),
2471 void *data)
2472 {
2473 offset_type iter;
2474 dw2_setup (objfile);
2475
2476 if (!dwarf2_per_objfile->index_table)
2477 return;
2478
2479 for (iter = 0;
2480 iter < dwarf2_per_objfile->index_table->index_table_slots;
2481 ++iter)
2482 {
2483 offset_type idx = 2 * iter;
2484 const char *name;
2485 offset_type *vec, vec_len, vec_idx;
2486
2487 if (dwarf2_per_objfile->index_table->index_table[idx] == 0
2488 && dwarf2_per_objfile->index_table->index_table[idx + 1] == 0)
2489 continue;
2490
2491 name = (dwarf2_per_objfile->index_table->constant_pool
2492 + dwarf2_per_objfile->index_table->index_table[idx]);
2493
2494 (*fun) (name, data);
2495 }
2496 }
2497
2498 static void
2499 dw2_map_symbol_filenames (struct objfile *objfile,
2500 void (*fun) (const char *, const char *, void *),
2501 void *data)
2502 {
2503 int i;
2504
2505 dw2_setup (objfile);
2506 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2507 + dwarf2_per_objfile->n_type_comp_units); ++i)
2508 {
2509 int j;
2510 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2511
2512 if (per_cu->v.quick->symtab)
2513 continue;
2514
2515 dw2_require_line_header (objfile, per_cu);
2516 if (!per_cu->v.quick->lines)
2517 continue;
2518
2519 for (j = 0; j < per_cu->v.quick->lines->num_file_names; ++j)
2520 {
2521 const char *this_full_name = dw2_require_full_path (objfile, per_cu,
2522 j);
2523 (*fun) (per_cu->v.quick->file_names[j], this_full_name, data);
2524 }
2525 }
2526 }
2527
2528 static int
2529 dw2_has_symbols (struct objfile *objfile)
2530 {
2531 return 1;
2532 }
2533
2534 const struct quick_symbol_functions dwarf2_gdb_index_functions =
2535 {
2536 dw2_has_symbols,
2537 dw2_find_last_source_symtab,
2538 dw2_forget_cached_source_info,
2539 dw2_lookup_symtab,
2540 dw2_lookup_symbol,
2541 dw2_pre_expand_symtabs_matching,
2542 dw2_print_stats,
2543 dw2_dump,
2544 dw2_relocate,
2545 dw2_expand_symtabs_for_function,
2546 dw2_expand_all_symtabs,
2547 dw2_expand_symtabs_with_filename,
2548 dw2_find_symbol_file,
2549 dw2_map_ada_symtabs,
2550 dw2_expand_symtabs_matching,
2551 dw2_find_pc_sect_symtab,
2552 dw2_map_symbol_names,
2553 dw2_map_symbol_filenames
2554 };
2555
2556 /* Initialize for reading DWARF for this objfile. Return 0 if this
2557 file will use psymtabs, or 1 if using the GNU index. */
2558
2559 int
2560 dwarf2_initialize_objfile (struct objfile *objfile)
2561 {
2562 /* If we're about to read full symbols, don't bother with the
2563 indices. In this case we also don't care if some other debug
2564 format is making psymtabs, because they are all about to be
2565 expanded anyway. */
2566 if ((objfile->flags & OBJF_READNOW))
2567 {
2568 int i;
2569
2570 dwarf2_per_objfile->using_index = 1;
2571 create_all_comp_units (objfile);
2572 create_debug_types_hash_table (objfile);
2573
2574 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2575 + dwarf2_per_objfile->n_type_comp_units); ++i)
2576 {
2577 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2578
2579 per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2580 struct dwarf2_per_cu_quick_data);
2581 }
2582
2583 /* Return 1 so that gdb sees the "quick" functions. However,
2584 these functions will be no-ops because we will have expanded
2585 all symtabs. */
2586 return 1;
2587 }
2588
2589 if (dwarf2_read_index (objfile))
2590 return 1;
2591
2592 dwarf2_build_psymtabs (objfile);
2593 return 0;
2594 }
2595
2596 \f
2597
2598 /* Build a partial symbol table. */
2599
2600 void
2601 dwarf2_build_psymtabs (struct objfile *objfile)
2602 {
2603 if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0)
2604 {
2605 init_psymbol_list (objfile, 1024);
2606 }
2607
2608 dwarf2_build_psymtabs_hard (objfile);
2609 }
2610
2611 /* Return TRUE if OFFSET is within CU_HEADER. */
2612
2613 static inline int
2614 offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset)
2615 {
2616 unsigned int bottom = cu_header->offset;
2617 unsigned int top = (cu_header->offset
2618 + cu_header->length
2619 + cu_header->initial_length_size);
2620
2621 return (offset >= bottom && offset < top);
2622 }
2623
2624 /* Read in the comp unit header information from the debug_info at info_ptr.
2625 NOTE: This leaves members offset, first_die_offset to be filled in
2626 by the caller. */
2627
2628 static gdb_byte *
2629 read_comp_unit_head (struct comp_unit_head *cu_header,
2630 gdb_byte *info_ptr, bfd *abfd)
2631 {
2632 int signed_addr;
2633 unsigned int bytes_read;
2634
2635 cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read);
2636 cu_header->initial_length_size = bytes_read;
2637 cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
2638 info_ptr += bytes_read;
2639 cu_header->version = read_2_bytes (abfd, info_ptr);
2640 info_ptr += 2;
2641 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
2642 &bytes_read);
2643 info_ptr += bytes_read;
2644 cu_header->addr_size = read_1_byte (abfd, info_ptr);
2645 info_ptr += 1;
2646 signed_addr = bfd_get_sign_extend_vma (abfd);
2647 if (signed_addr < 0)
2648 internal_error (__FILE__, __LINE__,
2649 _("read_comp_unit_head: dwarf from non elf file"));
2650 cu_header->signed_addr_p = signed_addr;
2651
2652 return info_ptr;
2653 }
2654
2655 static gdb_byte *
2656 partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr,
2657 gdb_byte *buffer, unsigned int buffer_size,
2658 bfd *abfd)
2659 {
2660 gdb_byte *beg_of_comp_unit = info_ptr;
2661
2662 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
2663
2664 if (header->version != 2 && header->version != 3 && header->version != 4)
2665 error (_("Dwarf Error: wrong version in compilation unit header "
2666 "(is %d, should be 2, 3, or 4) [in module %s]"), header->version,
2667 bfd_get_filename (abfd));
2668
2669 if (header->abbrev_offset >= dwarf2_per_objfile->abbrev.size)
2670 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2671 "(offset 0x%lx + 6) [in module %s]"),
2672 (long) header->abbrev_offset,
2673 (long) (beg_of_comp_unit - buffer),
2674 bfd_get_filename (abfd));
2675
2676 if (beg_of_comp_unit + header->length + header->initial_length_size
2677 > buffer + buffer_size)
2678 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2679 "(offset 0x%lx + 0) [in module %s]"),
2680 (long) header->length,
2681 (long) (beg_of_comp_unit - buffer),
2682 bfd_get_filename (abfd));
2683
2684 return info_ptr;
2685 }
2686
2687 /* Read in the types comp unit header information from .debug_types entry at
2688 types_ptr. The result is a pointer to one past the end of the header. */
2689
2690 static gdb_byte *
2691 read_type_comp_unit_head (struct comp_unit_head *cu_header,
2692 ULONGEST *signature,
2693 gdb_byte *types_ptr, bfd *abfd)
2694 {
2695 gdb_byte *initial_types_ptr = types_ptr;
2696
2697 dwarf2_read_section (dwarf2_per_objfile->objfile,
2698 &dwarf2_per_objfile->types);
2699 cu_header->offset = types_ptr - dwarf2_per_objfile->types.buffer;
2700
2701 types_ptr = read_comp_unit_head (cu_header, types_ptr, abfd);
2702
2703 *signature = read_8_bytes (abfd, types_ptr);
2704 types_ptr += 8;
2705 types_ptr += cu_header->offset_size;
2706 cu_header->first_die_offset = types_ptr - initial_types_ptr;
2707
2708 return types_ptr;
2709 }
2710
2711 /* Allocate a new partial symtab for file named NAME and mark this new
2712 partial symtab as being an include of PST. */
2713
2714 static void
2715 dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst,
2716 struct objfile *objfile)
2717 {
2718 struct partial_symtab *subpst = allocate_psymtab (name, objfile);
2719
2720 subpst->section_offsets = pst->section_offsets;
2721 subpst->textlow = 0;
2722 subpst->texthigh = 0;
2723
2724 subpst->dependencies = (struct partial_symtab **)
2725 obstack_alloc (&objfile->objfile_obstack,
2726 sizeof (struct partial_symtab *));
2727 subpst->dependencies[0] = pst;
2728 subpst->number_of_dependencies = 1;
2729
2730 subpst->globals_offset = 0;
2731 subpst->n_global_syms = 0;
2732 subpst->statics_offset = 0;
2733 subpst->n_static_syms = 0;
2734 subpst->symtab = NULL;
2735 subpst->read_symtab = pst->read_symtab;
2736 subpst->readin = 0;
2737
2738 /* No private part is necessary for include psymtabs. This property
2739 can be used to differentiate between such include psymtabs and
2740 the regular ones. */
2741 subpst->read_symtab_private = NULL;
2742 }
2743
2744 /* Read the Line Number Program data and extract the list of files
2745 included by the source file represented by PST. Build an include
2746 partial symtab for each of these included files. */
2747
2748 static void
2749 dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
2750 struct die_info *die,
2751 struct partial_symtab *pst)
2752 {
2753 struct objfile *objfile = cu->objfile;
2754 bfd *abfd = objfile->obfd;
2755 struct line_header *lh = NULL;
2756 struct attribute *attr;
2757
2758 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
2759 if (attr)
2760 {
2761 unsigned int line_offset = DW_UNSND (attr);
2762
2763 lh = dwarf_decode_line_header (line_offset, abfd, cu);
2764 }
2765 if (lh == NULL)
2766 return; /* No linetable, so no includes. */
2767
2768 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
2769 dwarf_decode_lines (lh, pst->dirname, abfd, cu, pst);
2770
2771 free_line_header (lh);
2772 }
2773
2774 static hashval_t
2775 hash_type_signature (const void *item)
2776 {
2777 const struct signatured_type *type_sig = item;
2778
2779 /* This drops the top 32 bits of the signature, but is ok for a hash. */
2780 return type_sig->signature;
2781 }
2782
2783 static int
2784 eq_type_signature (const void *item_lhs, const void *item_rhs)
2785 {
2786 const struct signatured_type *lhs = item_lhs;
2787 const struct signatured_type *rhs = item_rhs;
2788
2789 return lhs->signature == rhs->signature;
2790 }
2791
2792 /* Allocate a hash table for signatured types. */
2793
2794 static htab_t
2795 allocate_signatured_type_table (struct objfile *objfile)
2796 {
2797 return htab_create_alloc_ex (41,
2798 hash_type_signature,
2799 eq_type_signature,
2800 NULL,
2801 &objfile->objfile_obstack,
2802 hashtab_obstack_allocate,
2803 dummy_obstack_deallocate);
2804 }
2805
2806 /* A helper function to add a signatured type CU to a list. */
2807
2808 static int
2809 add_signatured_type_cu_to_list (void **slot, void *datum)
2810 {
2811 struct signatured_type *sigt = *slot;
2812 struct dwarf2_per_cu_data ***datap = datum;
2813
2814 **datap = &sigt->per_cu;
2815 ++*datap;
2816
2817 return 1;
2818 }
2819
2820 /* Create the hash table of all entries in the .debug_types section.
2821 The result is zero if there is an error (e.g. missing .debug_types section),
2822 otherwise non-zero. */
2823
2824 static int
2825 create_debug_types_hash_table (struct objfile *objfile)
2826 {
2827 gdb_byte *info_ptr;
2828 htab_t types_htab;
2829 struct dwarf2_per_cu_data **iter;
2830
2831 dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
2832 info_ptr = dwarf2_per_objfile->types.buffer;
2833
2834 if (info_ptr == NULL)
2835 {
2836 dwarf2_per_objfile->signatured_types = NULL;
2837 return 0;
2838 }
2839
2840 types_htab = allocate_signatured_type_table (objfile);
2841
2842 if (dwarf2_die_debug)
2843 fprintf_unfiltered (gdb_stdlog, "Signatured types:\n");
2844
2845 while (info_ptr < dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size)
2846 {
2847 unsigned int offset;
2848 unsigned int offset_size;
2849 unsigned int type_offset;
2850 unsigned int length, initial_length_size;
2851 unsigned short version;
2852 ULONGEST signature;
2853 struct signatured_type *type_sig;
2854 void **slot;
2855 gdb_byte *ptr = info_ptr;
2856
2857 offset = ptr - dwarf2_per_objfile->types.buffer;
2858
2859 /* We need to read the type's signature in order to build the hash
2860 table, but we don't need to read anything else just yet. */
2861
2862 /* Sanity check to ensure entire cu is present. */
2863 length = read_initial_length (objfile->obfd, ptr, &initial_length_size);
2864 if (ptr + length + initial_length_size
2865 > dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size)
2866 {
2867 complaint (&symfile_complaints,
2868 _("debug type entry runs off end of `.debug_types' section, ignored"));
2869 break;
2870 }
2871
2872 offset_size = initial_length_size == 4 ? 4 : 8;
2873 ptr += initial_length_size;
2874 version = bfd_get_16 (objfile->obfd, ptr);
2875 ptr += 2;
2876 ptr += offset_size; /* abbrev offset */
2877 ptr += 1; /* address size */
2878 signature = bfd_get_64 (objfile->obfd, ptr);
2879 ptr += 8;
2880 type_offset = read_offset_1 (objfile->obfd, ptr, offset_size);
2881
2882 type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig));
2883 memset (type_sig, 0, sizeof (*type_sig));
2884 type_sig->signature = signature;
2885 type_sig->offset = offset;
2886 type_sig->type_offset = type_offset;
2887 type_sig->per_cu.objfile = objfile;
2888 type_sig->per_cu.from_debug_types = 1;
2889
2890 slot = htab_find_slot (types_htab, type_sig, INSERT);
2891 gdb_assert (slot != NULL);
2892 *slot = type_sig;
2893
2894 if (dwarf2_die_debug)
2895 fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n",
2896 offset, phex (signature, sizeof (signature)));
2897
2898 info_ptr = info_ptr + initial_length_size + length;
2899 }
2900
2901 dwarf2_per_objfile->signatured_types = types_htab;
2902
2903 dwarf2_per_objfile->n_type_comp_units = htab_elements (types_htab);
2904 dwarf2_per_objfile->type_comp_units
2905 = obstack_alloc (&objfile->objfile_obstack,
2906 dwarf2_per_objfile->n_type_comp_units
2907 * sizeof (struct dwarf2_per_cu_data *));
2908 iter = &dwarf2_per_objfile->type_comp_units[0];
2909 htab_traverse_noresize (types_htab, add_signatured_type_cu_to_list, &iter);
2910 gdb_assert (iter - &dwarf2_per_objfile->type_comp_units[0]
2911 == dwarf2_per_objfile->n_type_comp_units);
2912
2913 return 1;
2914 }
2915
2916 /* Lookup a signature based type.
2917 Returns NULL if SIG is not present in the table. */
2918
2919 static struct signatured_type *
2920 lookup_signatured_type (struct objfile *objfile, ULONGEST sig)
2921 {
2922 struct signatured_type find_entry, *entry;
2923
2924 if (dwarf2_per_objfile->signatured_types == NULL)
2925 {
2926 complaint (&symfile_complaints,
2927 _("missing `.debug_types' section for DW_FORM_sig8 die"));
2928 return 0;
2929 }
2930
2931 find_entry.signature = sig;
2932 entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
2933 return entry;
2934 }
2935
2936 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
2937
2938 static void
2939 init_cu_die_reader (struct die_reader_specs *reader,
2940 struct dwarf2_cu *cu)
2941 {
2942 reader->abfd = cu->objfile->obfd;
2943 reader->cu = cu;
2944 if (cu->per_cu->from_debug_types)
2945 {
2946 gdb_assert (dwarf2_per_objfile->types.readin);
2947 reader->buffer = dwarf2_per_objfile->types.buffer;
2948 }
2949 else
2950 {
2951 gdb_assert (dwarf2_per_objfile->info.readin);
2952 reader->buffer = dwarf2_per_objfile->info.buffer;
2953 }
2954 }
2955
2956 /* Find the base address of the compilation unit for range lists and
2957 location lists. It will normally be specified by DW_AT_low_pc.
2958 In DWARF-3 draft 4, the base address could be overridden by
2959 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2960 compilation units with discontinuous ranges. */
2961
2962 static void
2963 dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
2964 {
2965 struct attribute *attr;
2966
2967 cu->base_known = 0;
2968 cu->base_address = 0;
2969
2970 attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
2971 if (attr)
2972 {
2973 cu->base_address = DW_ADDR (attr);
2974 cu->base_known = 1;
2975 }
2976 else
2977 {
2978 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
2979 if (attr)
2980 {
2981 cu->base_address = DW_ADDR (attr);
2982 cu->base_known = 1;
2983 }
2984 }
2985 }
2986
2987 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
2988 to combine the common parts.
2989 Process a compilation unit for a psymtab.
2990 BUFFER is a pointer to the beginning of the dwarf section buffer,
2991 either .debug_info or debug_types.
2992 INFO_PTR is a pointer to the start of the CU.
2993 Returns a pointer to the next CU. */
2994
2995 static gdb_byte *
2996 process_psymtab_comp_unit (struct objfile *objfile,
2997 struct dwarf2_per_cu_data *this_cu,
2998 gdb_byte *buffer, gdb_byte *info_ptr,
2999 unsigned int buffer_size)
3000 {
3001 bfd *abfd = objfile->obfd;
3002 gdb_byte *beg_of_comp_unit = info_ptr;
3003 struct die_info *comp_unit_die;
3004 struct partial_symtab *pst;
3005 CORE_ADDR baseaddr;
3006 struct cleanup *back_to_inner;
3007 struct dwarf2_cu cu;
3008 int has_children, has_pc_info;
3009 struct attribute *attr;
3010 CORE_ADDR best_lowpc = 0, best_highpc = 0;
3011 struct die_reader_specs reader_specs;
3012
3013 memset (&cu, 0, sizeof (cu));
3014 cu.objfile = objfile;
3015 obstack_init (&cu.comp_unit_obstack);
3016
3017 back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
3018
3019 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
3020 buffer, buffer_size,
3021 abfd);
3022
3023 /* Complete the cu_header. */
3024 cu.header.offset = beg_of_comp_unit - buffer;
3025 cu.header.first_die_offset = info_ptr - beg_of_comp_unit;
3026
3027 cu.list_in_scope = &file_symbols;
3028
3029 /* If this compilation unit was already read in, free the
3030 cached copy in order to read it in again. This is
3031 necessary because we skipped some symbols when we first
3032 read in the compilation unit (see load_partial_dies).
3033 This problem could be avoided, but the benefit is
3034 unclear. */
3035 if (this_cu->cu != NULL)
3036 free_one_cached_comp_unit (this_cu->cu);
3037
3038 /* Note that this is a pointer to our stack frame, being
3039 added to a global data structure. It will be cleaned up
3040 in free_stack_comp_unit when we finish with this
3041 compilation unit. */
3042 this_cu->cu = &cu;
3043 cu.per_cu = this_cu;
3044
3045 /* Read the abbrevs for this compilation unit into a table. */
3046 dwarf2_read_abbrevs (abfd, &cu);
3047 make_cleanup (dwarf2_free_abbrev_table, &cu);
3048
3049 /* Read the compilation unit die. */
3050 if (this_cu->from_debug_types)
3051 info_ptr += 8 /*signature*/ + cu.header.offset_size;
3052 init_cu_die_reader (&reader_specs, &cu);
3053 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
3054 &has_children);
3055
3056 if (this_cu->from_debug_types)
3057 {
3058 /* offset,length haven't been set yet for type units. */
3059 this_cu->offset = cu.header.offset;
3060 this_cu->length = cu.header.length + cu.header.initial_length_size;
3061 }
3062 else if (comp_unit_die->tag == DW_TAG_partial_unit)
3063 {
3064 info_ptr = (beg_of_comp_unit + cu.header.length
3065 + cu.header.initial_length_size);
3066 do_cleanups (back_to_inner);
3067 return info_ptr;
3068 }
3069
3070 /* Set the language we're debugging. */
3071 attr = dwarf2_attr (comp_unit_die, DW_AT_language, &cu);
3072 if (attr)
3073 set_cu_language (DW_UNSND (attr), &cu);
3074 else
3075 set_cu_language (language_minimal, &cu);
3076
3077 /* Allocate a new partial symbol table structure. */
3078 attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu);
3079 pst = start_psymtab_common (objfile, objfile->section_offsets,
3080 (attr != NULL) ? DW_STRING (attr) : "",
3081 /* TEXTLOW and TEXTHIGH are set below. */
3082 0,
3083 objfile->global_psymbols.next,
3084 objfile->static_psymbols.next);
3085
3086 attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu);
3087 if (attr != NULL)
3088 pst->dirname = DW_STRING (attr);
3089
3090 pst->read_symtab_private = this_cu;
3091
3092 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3093
3094 /* Store the function that reads in the rest of the symbol table */
3095 pst->read_symtab = dwarf2_psymtab_to_symtab;
3096
3097 this_cu->v.psymtab = pst;
3098
3099 dwarf2_find_base_address (comp_unit_die, &cu);
3100
3101 /* Possibly set the default values of LOWPC and HIGHPC from
3102 `DW_AT_ranges'. */
3103 has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc,
3104 &best_highpc, &cu, pst);
3105 if (has_pc_info == 1 && best_lowpc < best_highpc)
3106 /* Store the contiguous range if it is not empty; it can be empty for
3107 CUs with no code. */
3108 addrmap_set_empty (objfile->psymtabs_addrmap,
3109 best_lowpc + baseaddr,
3110 best_highpc + baseaddr - 1, pst);
3111
3112 /* Check if comp unit has_children.
3113 If so, read the rest of the partial symbols from this comp unit.
3114 If not, there's no more debug_info for this comp unit. */
3115 if (has_children)
3116 {
3117 struct partial_die_info *first_die;
3118 CORE_ADDR lowpc, highpc;
3119
3120 lowpc = ((CORE_ADDR) -1);
3121 highpc = ((CORE_ADDR) 0);
3122
3123 first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu);
3124
3125 scan_partial_symbols (first_die, &lowpc, &highpc,
3126 ! has_pc_info, &cu);
3127
3128 /* If we didn't find a lowpc, set it to highpc to avoid
3129 complaints from `maint check'. */
3130 if (lowpc == ((CORE_ADDR) -1))
3131 lowpc = highpc;
3132
3133 /* If the compilation unit didn't have an explicit address range,
3134 then use the information extracted from its child dies. */
3135 if (! has_pc_info)
3136 {
3137 best_lowpc = lowpc;
3138 best_highpc = highpc;
3139 }
3140 }
3141 pst->textlow = best_lowpc + baseaddr;
3142 pst->texthigh = best_highpc + baseaddr;
3143
3144 pst->n_global_syms = objfile->global_psymbols.next -
3145 (objfile->global_psymbols.list + pst->globals_offset);
3146 pst->n_static_syms = objfile->static_psymbols.next -
3147 (objfile->static_psymbols.list + pst->statics_offset);
3148 sort_pst_symbols (pst);
3149
3150 info_ptr = (beg_of_comp_unit + cu.header.length
3151 + cu.header.initial_length_size);
3152
3153 if (this_cu->from_debug_types)
3154 {
3155 /* It's not clear we want to do anything with stmt lists here.
3156 Waiting to see what gcc ultimately does. */
3157 }
3158 else
3159 {
3160 /* Get the list of files included in the current compilation unit,
3161 and build a psymtab for each of them. */
3162 dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst);
3163 }
3164
3165 do_cleanups (back_to_inner);
3166
3167 return info_ptr;
3168 }
3169
3170 /* Traversal function for htab_traverse_noresize.
3171 Process one .debug_types comp-unit. */
3172
3173 static int
3174 process_type_comp_unit (void **slot, void *info)
3175 {
3176 struct signatured_type *entry = (struct signatured_type *) *slot;
3177 struct objfile *objfile = (struct objfile *) info;
3178 struct dwarf2_per_cu_data *this_cu;
3179
3180 this_cu = &entry->per_cu;
3181
3182 gdb_assert (dwarf2_per_objfile->types.readin);
3183 process_psymtab_comp_unit (objfile, this_cu,
3184 dwarf2_per_objfile->types.buffer,
3185 dwarf2_per_objfile->types.buffer + entry->offset,
3186 dwarf2_per_objfile->types.size);
3187
3188 return 1;
3189 }
3190
3191 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3192 Build partial symbol tables for the .debug_types comp-units. */
3193
3194 static void
3195 build_type_psymtabs (struct objfile *objfile)
3196 {
3197 if (! create_debug_types_hash_table (objfile))
3198 return;
3199
3200 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
3201 process_type_comp_unit, objfile);
3202 }
3203
3204 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3205
3206 static void
3207 psymtabs_addrmap_cleanup (void *o)
3208 {
3209 struct objfile *objfile = o;
3210
3211 objfile->psymtabs_addrmap = NULL;
3212 }
3213
3214 /* Build the partial symbol table by doing a quick pass through the
3215 .debug_info and .debug_abbrev sections. */
3216
3217 static void
3218 dwarf2_build_psymtabs_hard (struct objfile *objfile)
3219 {
3220 gdb_byte *info_ptr;
3221 struct cleanup *back_to, *addrmap_cleanup;
3222 struct obstack temp_obstack;
3223
3224 dwarf2_per_objfile->reading_partial_symbols = 1;
3225
3226 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3227 info_ptr = dwarf2_per_objfile->info.buffer;
3228
3229 /* Any cached compilation units will be linked by the per-objfile
3230 read_in_chain. Make sure to free them when we're done. */
3231 back_to = make_cleanup (free_cached_comp_units, NULL);
3232
3233 build_type_psymtabs (objfile);
3234
3235 create_all_comp_units (objfile);
3236
3237 /* Create a temporary address map on a temporary obstack. We later
3238 copy this to the final obstack. */
3239 obstack_init (&temp_obstack);
3240 make_cleanup_obstack_free (&temp_obstack);
3241 objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack);
3242 addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile);
3243
3244 /* Since the objects we're extracting from .debug_info vary in
3245 length, only the individual functions to extract them (like
3246 read_comp_unit_head and load_partial_die) can really know whether
3247 the buffer is large enough to hold another complete object.
3248
3249 At the moment, they don't actually check that. If .debug_info
3250 holds just one extra byte after the last compilation unit's dies,
3251 then read_comp_unit_head will happily read off the end of the
3252 buffer. read_partial_die is similarly casual. Those functions
3253 should be fixed.
3254
3255 For this loop condition, simply checking whether there's any data
3256 left at all should be sufficient. */
3257
3258 while (info_ptr < (dwarf2_per_objfile->info.buffer
3259 + dwarf2_per_objfile->info.size))
3260 {
3261 struct dwarf2_per_cu_data *this_cu;
3262
3263 this_cu = dwarf2_find_comp_unit (info_ptr - dwarf2_per_objfile->info.buffer,
3264 objfile);
3265
3266 info_ptr = process_psymtab_comp_unit (objfile, this_cu,
3267 dwarf2_per_objfile->info.buffer,
3268 info_ptr,
3269 dwarf2_per_objfile->info.size);
3270 }
3271
3272 objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap,
3273 &objfile->objfile_obstack);
3274 discard_cleanups (addrmap_cleanup);
3275
3276 do_cleanups (back_to);
3277 }
3278
3279 /* Load the partial DIEs for a secondary CU into memory. */
3280
3281 static void
3282 load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu,
3283 struct objfile *objfile)
3284 {
3285 bfd *abfd = objfile->obfd;
3286 gdb_byte *info_ptr, *beg_of_comp_unit;
3287 struct die_info *comp_unit_die;
3288 struct dwarf2_cu *cu;
3289 struct cleanup *free_abbrevs_cleanup, *free_cu_cleanup = NULL;
3290 struct attribute *attr;
3291 int has_children;
3292 struct die_reader_specs reader_specs;
3293 int read_cu = 0;
3294
3295 gdb_assert (! this_cu->from_debug_types);
3296
3297 gdb_assert (dwarf2_per_objfile->info.readin);
3298 info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset;
3299 beg_of_comp_unit = info_ptr;
3300
3301 if (this_cu->cu == NULL)
3302 {
3303 cu = alloc_one_comp_unit (objfile);
3304
3305 read_cu = 1;
3306
3307 /* If an error occurs while loading, release our storage. */
3308 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
3309
3310 info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr,
3311 dwarf2_per_objfile->info.buffer,
3312 dwarf2_per_objfile->info.size,
3313 abfd);
3314
3315 /* Complete the cu_header. */
3316 cu->header.offset = this_cu->offset;
3317 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
3318
3319 /* Link this compilation unit into the compilation unit tree. */
3320 this_cu->cu = cu;
3321 cu->per_cu = this_cu;
3322
3323 /* Link this CU into read_in_chain. */
3324 this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
3325 dwarf2_per_objfile->read_in_chain = this_cu;
3326 }
3327 else
3328 {
3329 cu = this_cu->cu;
3330 info_ptr += cu->header.first_die_offset;
3331 }
3332
3333 /* Read the abbrevs for this compilation unit into a table. */
3334 gdb_assert (cu->dwarf2_abbrevs == NULL);
3335 dwarf2_read_abbrevs (abfd, cu);
3336 free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu);
3337
3338 /* Read the compilation unit die. */
3339 init_cu_die_reader (&reader_specs, cu);
3340 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
3341 &has_children);
3342
3343 /* Set the language we're debugging. */
3344 attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu);
3345 if (attr)
3346 set_cu_language (DW_UNSND (attr), cu);
3347 else
3348 set_cu_language (language_minimal, cu);
3349
3350 /* Check if comp unit has_children.
3351 If so, read the rest of the partial symbols from this comp unit.
3352 If not, there's no more debug_info for this comp unit. */
3353 if (has_children)
3354 load_partial_dies (abfd, dwarf2_per_objfile->info.buffer, info_ptr, 0, cu);
3355
3356 do_cleanups (free_abbrevs_cleanup);
3357
3358 if (read_cu)
3359 {
3360 /* We've successfully allocated this compilation unit. Let our
3361 caller clean it up when finished with it. */
3362 discard_cleanups (free_cu_cleanup);
3363 }
3364 }
3365
3366 /* Create a list of all compilation units in OBJFILE. We do this only
3367 if an inter-comp-unit reference is found; presumably if there is one,
3368 there will be many, and one will occur early in the .debug_info section.
3369 So there's no point in building this list incrementally. */
3370
3371 static void
3372 create_all_comp_units (struct objfile *objfile)
3373 {
3374 int n_allocated;
3375 int n_comp_units;
3376 struct dwarf2_per_cu_data **all_comp_units;
3377 gdb_byte *info_ptr;
3378
3379 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3380 info_ptr = dwarf2_per_objfile->info.buffer;
3381
3382 n_comp_units = 0;
3383 n_allocated = 10;
3384 all_comp_units = xmalloc (n_allocated
3385 * sizeof (struct dwarf2_per_cu_data *));
3386
3387 while (info_ptr < dwarf2_per_objfile->info.buffer + dwarf2_per_objfile->info.size)
3388 {
3389 unsigned int length, initial_length_size;
3390 struct dwarf2_per_cu_data *this_cu;
3391 unsigned int offset;
3392
3393 offset = info_ptr - dwarf2_per_objfile->info.buffer;
3394
3395 /* Read just enough information to find out where the next
3396 compilation unit is. */
3397 length = read_initial_length (objfile->obfd, info_ptr,
3398 &initial_length_size);
3399
3400 /* Save the compilation unit for later lookup. */
3401 this_cu = obstack_alloc (&objfile->objfile_obstack,
3402 sizeof (struct dwarf2_per_cu_data));
3403 memset (this_cu, 0, sizeof (*this_cu));
3404 this_cu->offset = offset;
3405 this_cu->length = length + initial_length_size;
3406 this_cu->objfile = objfile;
3407
3408 if (n_comp_units == n_allocated)
3409 {
3410 n_allocated *= 2;
3411 all_comp_units = xrealloc (all_comp_units,
3412 n_allocated
3413 * sizeof (struct dwarf2_per_cu_data *));
3414 }
3415 all_comp_units[n_comp_units++] = this_cu;
3416
3417 info_ptr = info_ptr + this_cu->length;
3418 }
3419
3420 dwarf2_per_objfile->all_comp_units
3421 = obstack_alloc (&objfile->objfile_obstack,
3422 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
3423 memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units,
3424 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
3425 xfree (all_comp_units);
3426 dwarf2_per_objfile->n_comp_units = n_comp_units;
3427 }
3428
3429 /* Process all loaded DIEs for compilation unit CU, starting at
3430 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3431 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3432 DW_AT_ranges). If NEED_PC is set, then this function will set
3433 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3434 and record the covered ranges in the addrmap. */
3435
3436 static void
3437 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
3438 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
3439 {
3440 struct partial_die_info *pdi;
3441
3442 /* Now, march along the PDI's, descending into ones which have
3443 interesting children but skipping the children of the other ones,
3444 until we reach the end of the compilation unit. */
3445
3446 pdi = first_die;
3447
3448 while (pdi != NULL)
3449 {
3450 fixup_partial_die (pdi, cu);
3451
3452 /* Anonymous namespaces or modules have no name but have interesting
3453 children, so we need to look at them. Ditto for anonymous
3454 enums. */
3455
3456 if (pdi->name != NULL || pdi->tag == DW_TAG_namespace
3457 || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type)
3458 {
3459 switch (pdi->tag)
3460 {
3461 case DW_TAG_subprogram:
3462 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
3463 break;
3464 case DW_TAG_variable:
3465 case DW_TAG_typedef:
3466 case DW_TAG_union_type:
3467 if (!pdi->is_declaration)
3468 {
3469 add_partial_symbol (pdi, cu);
3470 }
3471 break;
3472 case DW_TAG_class_type:
3473 case DW_TAG_interface_type:
3474 case DW_TAG_structure_type:
3475 if (!pdi->is_declaration)
3476 {
3477 add_partial_symbol (pdi, cu);
3478 }
3479 break;
3480 case DW_TAG_enumeration_type:
3481 if (!pdi->is_declaration)
3482 add_partial_enumeration (pdi, cu);
3483 break;
3484 case DW_TAG_base_type:
3485 case DW_TAG_subrange_type:
3486 /* File scope base type definitions are added to the partial
3487 symbol table. */
3488 add_partial_symbol (pdi, cu);
3489 break;
3490 case DW_TAG_namespace:
3491 add_partial_namespace (pdi, lowpc, highpc, need_pc, cu);
3492 break;
3493 case DW_TAG_module:
3494 add_partial_module (pdi, lowpc, highpc, need_pc, cu);
3495 break;
3496 default:
3497 break;
3498 }
3499 }
3500
3501 /* If the die has a sibling, skip to the sibling. */
3502
3503 pdi = pdi->die_sibling;
3504 }
3505 }
3506
3507 /* Functions used to compute the fully scoped name of a partial DIE.
3508
3509 Normally, this is simple. For C++, the parent DIE's fully scoped
3510 name is concatenated with "::" and the partial DIE's name. For
3511 Java, the same thing occurs except that "." is used instead of "::".
3512 Enumerators are an exception; they use the scope of their parent
3513 enumeration type, i.e. the name of the enumeration type is not
3514 prepended to the enumerator.
3515
3516 There are two complexities. One is DW_AT_specification; in this
3517 case "parent" means the parent of the target of the specification,
3518 instead of the direct parent of the DIE. The other is compilers
3519 which do not emit DW_TAG_namespace; in this case we try to guess
3520 the fully qualified name of structure types from their members'
3521 linkage names. This must be done using the DIE's children rather
3522 than the children of any DW_AT_specification target. We only need
3523 to do this for structures at the top level, i.e. if the target of
3524 any DW_AT_specification (if any; otherwise the DIE itself) does not
3525 have a parent. */
3526
3527 /* Compute the scope prefix associated with PDI's parent, in
3528 compilation unit CU. The result will be allocated on CU's
3529 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3530 field. NULL is returned if no prefix is necessary. */
3531 static char *
3532 partial_die_parent_scope (struct partial_die_info *pdi,
3533 struct dwarf2_cu *cu)
3534 {
3535 char *grandparent_scope;
3536 struct partial_die_info *parent, *real_pdi;
3537
3538 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3539 then this means the parent of the specification DIE. */
3540
3541 real_pdi = pdi;
3542 while (real_pdi->has_specification)
3543 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
3544
3545 parent = real_pdi->die_parent;
3546 if (parent == NULL)
3547 return NULL;
3548
3549 if (parent->scope_set)
3550 return parent->scope;
3551
3552 fixup_partial_die (parent, cu);
3553
3554 grandparent_scope = partial_die_parent_scope (parent, cu);
3555
3556 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3557 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3558 Work around this problem here. */
3559 if (cu->language == language_cplus
3560 && parent->tag == DW_TAG_namespace
3561 && strcmp (parent->name, "::") == 0
3562 && grandparent_scope == NULL)
3563 {
3564 parent->scope = NULL;
3565 parent->scope_set = 1;
3566 return NULL;
3567 }
3568
3569 if (parent->tag == DW_TAG_namespace
3570 || parent->tag == DW_TAG_module
3571 || parent->tag == DW_TAG_structure_type
3572 || parent->tag == DW_TAG_class_type
3573 || parent->tag == DW_TAG_interface_type
3574 || parent->tag == DW_TAG_union_type
3575 || parent->tag == DW_TAG_enumeration_type)
3576 {
3577 if (grandparent_scope == NULL)
3578 parent->scope = parent->name;
3579 else
3580 parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope,
3581 parent->name, 0, cu);
3582 }
3583 else if (parent->tag == DW_TAG_enumerator)
3584 /* Enumerators should not get the name of the enumeration as a prefix. */
3585 parent->scope = grandparent_scope;
3586 else
3587 {
3588 /* FIXME drow/2004-04-01: What should we be doing with
3589 function-local names? For partial symbols, we should probably be
3590 ignoring them. */
3591 complaint (&symfile_complaints,
3592 _("unhandled containing DIE tag %d for DIE at %d"),
3593 parent->tag, pdi->offset);
3594 parent->scope = grandparent_scope;
3595 }
3596
3597 parent->scope_set = 1;
3598 return parent->scope;
3599 }
3600
3601 /* Return the fully scoped name associated with PDI, from compilation unit
3602 CU. The result will be allocated with malloc. */
3603 static char *
3604 partial_die_full_name (struct partial_die_info *pdi,
3605 struct dwarf2_cu *cu)
3606 {
3607 char *parent_scope;
3608
3609 /* If this is a template instantiation, we can not work out the
3610 template arguments from partial DIEs. So, unfortunately, we have
3611 to go through the full DIEs. At least any work we do building
3612 types here will be reused if full symbols are loaded later. */
3613 if (pdi->has_template_arguments)
3614 {
3615 fixup_partial_die (pdi, cu);
3616
3617 if (pdi->name != NULL && strchr (pdi->name, '<') == NULL)
3618 {
3619 struct die_info *die;
3620 struct attribute attr;
3621 struct dwarf2_cu *ref_cu = cu;
3622
3623 attr.name = 0;
3624 attr.form = DW_FORM_ref_addr;
3625 attr.u.addr = pdi->offset;
3626 die = follow_die_ref (NULL, &attr, &ref_cu);
3627
3628 return xstrdup (dwarf2_full_name (NULL, die, ref_cu));
3629 }
3630 }
3631
3632 parent_scope = partial_die_parent_scope (pdi, cu);
3633 if (parent_scope == NULL)
3634 return NULL;
3635 else
3636 return typename_concat (NULL, parent_scope, pdi->name, 0, cu);
3637 }
3638
3639 static void
3640 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
3641 {
3642 struct objfile *objfile = cu->objfile;
3643 CORE_ADDR addr = 0;
3644 char *actual_name = NULL;
3645 const struct partial_symbol *psym = NULL;
3646 CORE_ADDR baseaddr;
3647 int built_actual_name = 0;
3648
3649 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3650
3651 actual_name = partial_die_full_name (pdi, cu);
3652 if (actual_name)
3653 built_actual_name = 1;
3654
3655 if (actual_name == NULL)
3656 actual_name = pdi->name;
3657
3658 switch (pdi->tag)
3659 {
3660 case DW_TAG_subprogram:
3661 if (pdi->is_external || cu->language == language_ada)
3662 {
3663 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3664 of the global scope. But in Ada, we want to be able to access
3665 nested procedures globally. So all Ada subprograms are stored
3666 in the global scope. */
3667 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3668 mst_text, objfile); */
3669 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
3670 built_actual_name,
3671 VAR_DOMAIN, LOC_BLOCK,
3672 &objfile->global_psymbols,
3673 0, pdi->lowpc + baseaddr,
3674 cu->language, objfile);
3675 }
3676 else
3677 {
3678 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3679 mst_file_text, objfile); */
3680 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
3681 built_actual_name,
3682 VAR_DOMAIN, LOC_BLOCK,
3683 &objfile->static_psymbols,
3684 0, pdi->lowpc + baseaddr,
3685 cu->language, objfile);
3686 }
3687 break;
3688 case DW_TAG_variable:
3689 if (pdi->locdesc)
3690 addr = decode_locdesc (pdi->locdesc, cu);
3691
3692 if (pdi->locdesc
3693 && addr == 0
3694 && !dwarf2_per_objfile->has_section_at_zero)
3695 {
3696 /* A global or static variable may also have been stripped
3697 out by the linker if unused, in which case its address
3698 will be nullified; do not add such variables into partial
3699 symbol table then. */
3700 }
3701 else if (pdi->is_external)
3702 {
3703 /* Global Variable.
3704 Don't enter into the minimal symbol tables as there is
3705 a minimal symbol table entry from the ELF symbols already.
3706 Enter into partial symbol table if it has a location
3707 descriptor or a type.
3708 If the location descriptor is missing, new_symbol will create
3709 a LOC_UNRESOLVED symbol, the address of the variable will then
3710 be determined from the minimal symbol table whenever the variable
3711 is referenced.
3712 The address for the partial symbol table entry is not
3713 used by GDB, but it comes in handy for debugging partial symbol
3714 table building. */
3715
3716 if (pdi->locdesc || pdi->has_type)
3717 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
3718 built_actual_name,
3719 VAR_DOMAIN, LOC_STATIC,
3720 &objfile->global_psymbols,
3721 0, addr + baseaddr,
3722 cu->language, objfile);
3723 }
3724 else
3725 {
3726 /* Static Variable. Skip symbols without location descriptors. */
3727 if (pdi->locdesc == NULL)
3728 {
3729 if (built_actual_name)
3730 xfree (actual_name);
3731 return;
3732 }
3733 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
3734 mst_file_data, objfile); */
3735 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
3736 built_actual_name,
3737 VAR_DOMAIN, LOC_STATIC,
3738 &objfile->static_psymbols,
3739 0, addr + baseaddr,
3740 cu->language, objfile);
3741 }
3742 break;
3743 case DW_TAG_typedef:
3744 case DW_TAG_base_type:
3745 case DW_TAG_subrange_type:
3746 add_psymbol_to_list (actual_name, strlen (actual_name),
3747 built_actual_name,
3748 VAR_DOMAIN, LOC_TYPEDEF,
3749 &objfile->static_psymbols,
3750 0, (CORE_ADDR) 0, cu->language, objfile);
3751 break;
3752 case DW_TAG_namespace:
3753 add_psymbol_to_list (actual_name, strlen (actual_name),
3754 built_actual_name,
3755 VAR_DOMAIN, LOC_TYPEDEF,
3756 &objfile->global_psymbols,
3757 0, (CORE_ADDR) 0, cu->language, objfile);
3758 break;
3759 case DW_TAG_class_type:
3760 case DW_TAG_interface_type:
3761 case DW_TAG_structure_type:
3762 case DW_TAG_union_type:
3763 case DW_TAG_enumeration_type:
3764 /* Skip external references. The DWARF standard says in the section
3765 about "Structure, Union, and Class Type Entries": "An incomplete
3766 structure, union or class type is represented by a structure,
3767 union or class entry that does not have a byte size attribute
3768 and that has a DW_AT_declaration attribute." */
3769 if (!pdi->has_byte_size && pdi->is_declaration)
3770 {
3771 if (built_actual_name)
3772 xfree (actual_name);
3773 return;
3774 }
3775
3776 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
3777 static vs. global. */
3778 add_psymbol_to_list (actual_name, strlen (actual_name),
3779 built_actual_name,
3780 STRUCT_DOMAIN, LOC_TYPEDEF,
3781 (cu->language == language_cplus
3782 || cu->language == language_java)
3783 ? &objfile->global_psymbols
3784 : &objfile->static_psymbols,
3785 0, (CORE_ADDR) 0, cu->language, objfile);
3786
3787 break;
3788 case DW_TAG_enumerator:
3789 add_psymbol_to_list (actual_name, strlen (actual_name),
3790 built_actual_name,
3791 VAR_DOMAIN, LOC_CONST,
3792 (cu->language == language_cplus
3793 || cu->language == language_java)
3794 ? &objfile->global_psymbols
3795 : &objfile->static_psymbols,
3796 0, (CORE_ADDR) 0, cu->language, objfile);
3797 break;
3798 default:
3799 break;
3800 }
3801
3802 if (built_actual_name)
3803 xfree (actual_name);
3804 }
3805
3806 /* Read a partial die corresponding to a namespace; also, add a symbol
3807 corresponding to that namespace to the symbol table. NAMESPACE is
3808 the name of the enclosing namespace. */
3809
3810 static void
3811 add_partial_namespace (struct partial_die_info *pdi,
3812 CORE_ADDR *lowpc, CORE_ADDR *highpc,
3813 int need_pc, struct dwarf2_cu *cu)
3814 {
3815 /* Add a symbol for the namespace. */
3816
3817 add_partial_symbol (pdi, cu);
3818
3819 /* Now scan partial symbols in that namespace. */
3820
3821 if (pdi->has_children)
3822 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
3823 }
3824
3825 /* Read a partial die corresponding to a Fortran module. */
3826
3827 static void
3828 add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
3829 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
3830 {
3831 /* Now scan partial symbols in that module. */
3832
3833 if (pdi->has_children)
3834 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
3835 }
3836
3837 /* Read a partial die corresponding to a subprogram and create a partial
3838 symbol for that subprogram. When the CU language allows it, this
3839 routine also defines a partial symbol for each nested subprogram
3840 that this subprogram contains.
3841
3842 DIE my also be a lexical block, in which case we simply search
3843 recursively for suprograms defined inside that lexical block.
3844 Again, this is only performed when the CU language allows this
3845 type of definitions. */
3846
3847 static void
3848 add_partial_subprogram (struct partial_die_info *pdi,
3849 CORE_ADDR *lowpc, CORE_ADDR *highpc,
3850 int need_pc, struct dwarf2_cu *cu)
3851 {
3852 if (pdi->tag == DW_TAG_subprogram)
3853 {
3854 if (pdi->has_pc_info)
3855 {
3856 if (pdi->lowpc < *lowpc)
3857 *lowpc = pdi->lowpc;
3858 if (pdi->highpc > *highpc)
3859 *highpc = pdi->highpc;
3860 if (need_pc)
3861 {
3862 CORE_ADDR baseaddr;
3863 struct objfile *objfile = cu->objfile;
3864
3865 baseaddr = ANOFFSET (objfile->section_offsets,
3866 SECT_OFF_TEXT (objfile));
3867 addrmap_set_empty (objfile->psymtabs_addrmap,
3868 pdi->lowpc + baseaddr,
3869 pdi->highpc - 1 + baseaddr,
3870 cu->per_cu->v.psymtab);
3871 }
3872 if (!pdi->is_declaration)
3873 /* Ignore subprogram DIEs that do not have a name, they are
3874 illegal. Do not emit a complaint at this point, we will
3875 do so when we convert this psymtab into a symtab. */
3876 if (pdi->name)
3877 add_partial_symbol (pdi, cu);
3878 }
3879 }
3880
3881 if (! pdi->has_children)
3882 return;
3883
3884 if (cu->language == language_ada)
3885 {
3886 pdi = pdi->die_child;
3887 while (pdi != NULL)
3888 {
3889 fixup_partial_die (pdi, cu);
3890 if (pdi->tag == DW_TAG_subprogram
3891 || pdi->tag == DW_TAG_lexical_block)
3892 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
3893 pdi = pdi->die_sibling;
3894 }
3895 }
3896 }
3897
3898 /* See if we can figure out if the class lives in a namespace. We do
3899 this by looking for a member function; its demangled name will
3900 contain namespace info, if there is any. */
3901
3902 static void
3903 guess_structure_name (struct partial_die_info *struct_pdi,
3904 struct dwarf2_cu *cu)
3905 {
3906 if ((cu->language == language_cplus
3907 || cu->language == language_java)
3908 && cu->has_namespace_info == 0
3909 && struct_pdi->has_children)
3910 {
3911 /* NOTE: carlton/2003-10-07: Getting the info this way changes
3912 what template types look like, because the demangler
3913 frequently doesn't give the same name as the debug info. We
3914 could fix this by only using the demangled name to get the
3915 prefix (but see comment in read_structure_type). */
3916
3917 struct partial_die_info *real_pdi;
3918
3919 /* If this DIE (this DIE's specification, if any) has a parent, then
3920 we should not do this. We'll prepend the parent's fully qualified
3921 name when we create the partial symbol. */
3922
3923 real_pdi = struct_pdi;
3924 while (real_pdi->has_specification)
3925 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
3926
3927 if (real_pdi->die_parent != NULL)
3928 return;
3929 }
3930 }
3931
3932 /* Read a partial die corresponding to an enumeration type. */
3933
3934 static void
3935 add_partial_enumeration (struct partial_die_info *enum_pdi,
3936 struct dwarf2_cu *cu)
3937 {
3938 struct partial_die_info *pdi;
3939
3940 if (enum_pdi->name != NULL)
3941 add_partial_symbol (enum_pdi, cu);
3942
3943 pdi = enum_pdi->die_child;
3944 while (pdi)
3945 {
3946 if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL)
3947 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
3948 else
3949 add_partial_symbol (pdi, cu);
3950 pdi = pdi->die_sibling;
3951 }
3952 }
3953
3954 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
3955 Return the corresponding abbrev, or NULL if the number is zero (indicating
3956 an empty DIE). In either case *BYTES_READ will be set to the length of
3957 the initial number. */
3958
3959 static struct abbrev_info *
3960 peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read,
3961 struct dwarf2_cu *cu)
3962 {
3963 bfd *abfd = cu->objfile->obfd;
3964 unsigned int abbrev_number;
3965 struct abbrev_info *abbrev;
3966
3967 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
3968
3969 if (abbrev_number == 0)
3970 return NULL;
3971
3972 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
3973 if (!abbrev)
3974 {
3975 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number,
3976 bfd_get_filename (abfd));
3977 }
3978
3979 return abbrev;
3980 }
3981
3982 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
3983 Returns a pointer to the end of a series of DIEs, terminated by an empty
3984 DIE. Any children of the skipped DIEs will also be skipped. */
3985
3986 static gdb_byte *
3987 skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu)
3988 {
3989 struct abbrev_info *abbrev;
3990 unsigned int bytes_read;
3991
3992 while (1)
3993 {
3994 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
3995 if (abbrev == NULL)
3996 return info_ptr + bytes_read;
3997 else
3998 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
3999 }
4000 }
4001
4002 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4003 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4004 abbrev corresponding to that skipped uleb128 should be passed in
4005 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4006 children. */
4007
4008 static gdb_byte *
4009 skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
4010 struct abbrev_info *abbrev, struct dwarf2_cu *cu)
4011 {
4012 unsigned int bytes_read;
4013 struct attribute attr;
4014 bfd *abfd = cu->objfile->obfd;
4015 unsigned int form, i;
4016
4017 for (i = 0; i < abbrev->num_attrs; i++)
4018 {
4019 /* The only abbrev we care about is DW_AT_sibling. */
4020 if (abbrev->attrs[i].name == DW_AT_sibling)
4021 {
4022 read_attribute (&attr, &abbrev->attrs[i],
4023 abfd, info_ptr, cu);
4024 if (attr.form == DW_FORM_ref_addr)
4025 complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling"));
4026 else
4027 return buffer + dwarf2_get_ref_die_offset (&attr);
4028 }
4029
4030 /* If it isn't DW_AT_sibling, skip this attribute. */
4031 form = abbrev->attrs[i].form;
4032 skip_attribute:
4033 switch (form)
4034 {
4035 case DW_FORM_ref_addr:
4036 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4037 and later it is offset sized. */
4038 if (cu->header.version == 2)
4039 info_ptr += cu->header.addr_size;
4040 else
4041 info_ptr += cu->header.offset_size;
4042 break;
4043 case DW_FORM_addr:
4044 info_ptr += cu->header.addr_size;
4045 break;
4046 case DW_FORM_data1:
4047 case DW_FORM_ref1:
4048 case DW_FORM_flag:
4049 info_ptr += 1;
4050 break;
4051 case DW_FORM_flag_present:
4052 break;
4053 case DW_FORM_data2:
4054 case DW_FORM_ref2:
4055 info_ptr += 2;
4056 break;
4057 case DW_FORM_data4:
4058 case DW_FORM_ref4:
4059 info_ptr += 4;
4060 break;
4061 case DW_FORM_data8:
4062 case DW_FORM_ref8:
4063 case DW_FORM_sig8:
4064 info_ptr += 8;
4065 break;
4066 case DW_FORM_string:
4067 read_direct_string (abfd, info_ptr, &bytes_read);
4068 info_ptr += bytes_read;
4069 break;
4070 case DW_FORM_sec_offset:
4071 case DW_FORM_strp:
4072 info_ptr += cu->header.offset_size;
4073 break;
4074 case DW_FORM_exprloc:
4075 case DW_FORM_block:
4076 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4077 info_ptr += bytes_read;
4078 break;
4079 case DW_FORM_block1:
4080 info_ptr += 1 + read_1_byte (abfd, info_ptr);
4081 break;
4082 case DW_FORM_block2:
4083 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
4084 break;
4085 case DW_FORM_block4:
4086 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
4087 break;
4088 case DW_FORM_sdata:
4089 case DW_FORM_udata:
4090 case DW_FORM_ref_udata:
4091 info_ptr = skip_leb128 (abfd, info_ptr);
4092 break;
4093 case DW_FORM_indirect:
4094 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4095 info_ptr += bytes_read;
4096 /* We need to continue parsing from here, so just go back to
4097 the top. */
4098 goto skip_attribute;
4099
4100 default:
4101 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
4102 dwarf_form_name (form),
4103 bfd_get_filename (abfd));
4104 }
4105 }
4106
4107 if (abbrev->has_children)
4108 return skip_children (buffer, info_ptr, cu);
4109 else
4110 return info_ptr;
4111 }
4112
4113 /* Locate ORIG_PDI's sibling.
4114 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4115 in BUFFER. */
4116
4117 static gdb_byte *
4118 locate_pdi_sibling (struct partial_die_info *orig_pdi,
4119 gdb_byte *buffer, gdb_byte *info_ptr,
4120 bfd *abfd, struct dwarf2_cu *cu)
4121 {
4122 /* Do we know the sibling already? */
4123
4124 if (orig_pdi->sibling)
4125 return orig_pdi->sibling;
4126
4127 /* Are there any children to deal with? */
4128
4129 if (!orig_pdi->has_children)
4130 return info_ptr;
4131
4132 /* Skip the children the long way. */
4133
4134 return skip_children (buffer, info_ptr, cu);
4135 }
4136
4137 /* Expand this partial symbol table into a full symbol table. */
4138
4139 static void
4140 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
4141 {
4142 if (pst != NULL)
4143 {
4144 if (pst->readin)
4145 {
4146 warning (_("bug: psymtab for %s is already read in."), pst->filename);
4147 }
4148 else
4149 {
4150 if (info_verbose)
4151 {
4152 printf_filtered (_("Reading in symbols for %s..."), pst->filename);
4153 gdb_flush (gdb_stdout);
4154 }
4155
4156 /* Restore our global data. */
4157 dwarf2_per_objfile = objfile_data (pst->objfile,
4158 dwarf2_objfile_data_key);
4159
4160 /* If this psymtab is constructed from a debug-only objfile, the
4161 has_section_at_zero flag will not necessarily be correct. We
4162 can get the correct value for this flag by looking at the data
4163 associated with the (presumably stripped) associated objfile. */
4164 if (pst->objfile->separate_debug_objfile_backlink)
4165 {
4166 struct dwarf2_per_objfile *dpo_backlink
4167 = objfile_data (pst->objfile->separate_debug_objfile_backlink,
4168 dwarf2_objfile_data_key);
4169
4170 dwarf2_per_objfile->has_section_at_zero
4171 = dpo_backlink->has_section_at_zero;
4172 }
4173
4174 dwarf2_per_objfile->reading_partial_symbols = 0;
4175
4176 psymtab_to_symtab_1 (pst);
4177
4178 /* Finish up the debug error message. */
4179 if (info_verbose)
4180 printf_filtered (_("done.\n"));
4181 }
4182 }
4183 }
4184
4185 /* Add PER_CU to the queue. */
4186
4187 static void
4188 queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
4189 {
4190 struct dwarf2_queue_item *item;
4191
4192 per_cu->queued = 1;
4193 item = xmalloc (sizeof (*item));
4194 item->per_cu = per_cu;
4195 item->next = NULL;
4196
4197 if (dwarf2_queue == NULL)
4198 dwarf2_queue = item;
4199 else
4200 dwarf2_queue_tail->next = item;
4201
4202 dwarf2_queue_tail = item;
4203 }
4204
4205 /* Process the queue. */
4206
4207 static void
4208 process_queue (struct objfile *objfile)
4209 {
4210 struct dwarf2_queue_item *item, *next_item;
4211
4212 /* The queue starts out with one item, but following a DIE reference
4213 may load a new CU, adding it to the end of the queue. */
4214 for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
4215 {
4216 if (dwarf2_per_objfile->using_index
4217 ? !item->per_cu->v.quick->symtab
4218 : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin))
4219 process_full_comp_unit (item->per_cu);
4220
4221 item->per_cu->queued = 0;
4222 next_item = item->next;
4223 xfree (item);
4224 }
4225
4226 dwarf2_queue_tail = NULL;
4227 }
4228
4229 /* Free all allocated queue entries. This function only releases anything if
4230 an error was thrown; if the queue was processed then it would have been
4231 freed as we went along. */
4232
4233 static void
4234 dwarf2_release_queue (void *dummy)
4235 {
4236 struct dwarf2_queue_item *item, *last;
4237
4238 item = dwarf2_queue;
4239 while (item)
4240 {
4241 /* Anything still marked queued is likely to be in an
4242 inconsistent state, so discard it. */
4243 if (item->per_cu->queued)
4244 {
4245 if (item->per_cu->cu != NULL)
4246 free_one_cached_comp_unit (item->per_cu->cu);
4247 item->per_cu->queued = 0;
4248 }
4249
4250 last = item;
4251 item = item->next;
4252 xfree (last);
4253 }
4254
4255 dwarf2_queue = dwarf2_queue_tail = NULL;
4256 }
4257
4258 /* Read in full symbols for PST, and anything it depends on. */
4259
4260 static void
4261 psymtab_to_symtab_1 (struct partial_symtab *pst)
4262 {
4263 struct dwarf2_per_cu_data *per_cu;
4264 struct cleanup *back_to;
4265 int i;
4266
4267 for (i = 0; i < pst->number_of_dependencies; i++)
4268 if (!pst->dependencies[i]->readin)
4269 {
4270 /* Inform about additional files that need to be read in. */
4271 if (info_verbose)
4272 {
4273 /* FIXME: i18n: Need to make this a single string. */
4274 fputs_filtered (" ", gdb_stdout);
4275 wrap_here ("");
4276 fputs_filtered ("and ", gdb_stdout);
4277 wrap_here ("");
4278 printf_filtered ("%s...", pst->dependencies[i]->filename);
4279 wrap_here (""); /* Flush output */
4280 gdb_flush (gdb_stdout);
4281 }
4282 psymtab_to_symtab_1 (pst->dependencies[i]);
4283 }
4284
4285 per_cu = pst->read_symtab_private;
4286
4287 if (per_cu == NULL)
4288 {
4289 /* It's an include file, no symbols to read for it.
4290 Everything is in the parent symtab. */
4291 pst->readin = 1;
4292 return;
4293 }
4294
4295 dw2_do_instantiate_symtab (pst->objfile, per_cu);
4296 }
4297
4298 /* Load the DIEs associated with PER_CU into memory. */
4299
4300 static void
4301 load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
4302 {
4303 bfd *abfd = objfile->obfd;
4304 struct dwarf2_cu *cu;
4305 unsigned int offset;
4306 gdb_byte *info_ptr, *beg_of_comp_unit;
4307 struct cleanup *free_abbrevs_cleanup = NULL, *free_cu_cleanup = NULL;
4308 struct attribute *attr;
4309 int read_cu = 0;
4310
4311 gdb_assert (! per_cu->from_debug_types);
4312
4313 /* Set local variables from the partial symbol table info. */
4314 offset = per_cu->offset;
4315
4316 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
4317 info_ptr = dwarf2_per_objfile->info.buffer + offset;
4318 beg_of_comp_unit = info_ptr;
4319
4320 if (per_cu->cu == NULL)
4321 {
4322 cu = alloc_one_comp_unit (objfile);
4323
4324 read_cu = 1;
4325
4326 /* If an error occurs while loading, release our storage. */
4327 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
4328
4329 /* Read in the comp_unit header. */
4330 info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd);
4331
4332 /* Complete the cu_header. */
4333 cu->header.offset = offset;
4334 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
4335
4336 /* Read the abbrevs for this compilation unit. */
4337 dwarf2_read_abbrevs (abfd, cu);
4338 free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu);
4339
4340 /* Link this compilation unit into the compilation unit tree. */
4341 per_cu->cu = cu;
4342 cu->per_cu = per_cu;
4343
4344 /* Link this CU into read_in_chain. */
4345 per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
4346 dwarf2_per_objfile->read_in_chain = per_cu;
4347 }
4348 else
4349 {
4350 cu = per_cu->cu;
4351 info_ptr += cu->header.first_die_offset;
4352 }
4353
4354 cu->dies = read_comp_unit (info_ptr, cu);
4355
4356 /* We try not to read any attributes in this function, because not
4357 all objfiles needed for references have been loaded yet, and symbol
4358 table processing isn't initialized. But we have to set the CU language,
4359 or we won't be able to build types correctly. */
4360 attr = dwarf2_attr (cu->dies, DW_AT_language, cu);
4361 if (attr)
4362 set_cu_language (DW_UNSND (attr), cu);
4363 else
4364 set_cu_language (language_minimal, cu);
4365
4366 /* Similarly, if we do not read the producer, we can not apply
4367 producer-specific interpretation. */
4368 attr = dwarf2_attr (cu->dies, DW_AT_producer, cu);
4369 if (attr)
4370 cu->producer = DW_STRING (attr);
4371
4372 if (read_cu)
4373 {
4374 do_cleanups (free_abbrevs_cleanup);
4375
4376 /* We've successfully allocated this compilation unit. Let our
4377 caller clean it up when finished with it. */
4378 discard_cleanups (free_cu_cleanup);
4379 }
4380 }
4381
4382 /* Add a DIE to the delayed physname list. */
4383
4384 static void
4385 add_to_method_list (struct type *type, int fnfield_index, int index,
4386 const char *name, struct die_info *die,
4387 struct dwarf2_cu *cu)
4388 {
4389 struct delayed_method_info mi;
4390 mi.type = type;
4391 mi.fnfield_index = fnfield_index;
4392 mi.index = index;
4393 mi.name = name;
4394 mi.die = die;
4395 VEC_safe_push (delayed_method_info, cu->method_list, &mi);
4396 }
4397
4398 /* A cleanup for freeing the delayed method list. */
4399
4400 static void
4401 free_delayed_list (void *ptr)
4402 {
4403 struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr;
4404 if (cu->method_list != NULL)
4405 {
4406 VEC_free (delayed_method_info, cu->method_list);
4407 cu->method_list = NULL;
4408 }
4409 }
4410
4411 /* Compute the physnames of any methods on the CU's method list.
4412
4413 The computation of method physnames is delayed in order to avoid the
4414 (bad) condition that one of the method's formal parameters is of an as yet
4415 incomplete type. */
4416
4417 static void
4418 compute_delayed_physnames (struct dwarf2_cu *cu)
4419 {
4420 int i;
4421 struct delayed_method_info *mi;
4422 for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i)
4423 {
4424 char *physname;
4425 struct fn_fieldlist *fn_flp
4426 = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index);
4427 physname = (char *) dwarf2_physname ((char *) mi->name, mi->die, cu);
4428 fn_flp->fn_fields[mi->index].physname = physname ? physname : "";
4429 }
4430 }
4431
4432 /* Generate full symbol information for PST and CU, whose DIEs have
4433 already been loaded into memory. */
4434
4435 static void
4436 process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
4437 {
4438 struct dwarf2_cu *cu = per_cu->cu;
4439 struct objfile *objfile = per_cu->objfile;
4440 CORE_ADDR lowpc, highpc;
4441 struct symtab *symtab;
4442 struct cleanup *back_to, *delayed_list_cleanup;
4443 CORE_ADDR baseaddr;
4444
4445 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4446
4447 buildsym_init ();
4448 back_to = make_cleanup (really_free_pendings, NULL);
4449 delayed_list_cleanup = make_cleanup (free_delayed_list, cu);
4450
4451 cu->list_in_scope = &file_symbols;
4452
4453 dwarf2_find_base_address (cu->dies, cu);
4454
4455 /* Do line number decoding in read_file_scope () */
4456 process_die (cu->dies, cu);
4457
4458 /* Now that we have processed all the DIEs in the CU, all the types
4459 should be complete, and it should now be safe to compute all of the
4460 physnames. */
4461 compute_delayed_physnames (cu);
4462 do_cleanups (delayed_list_cleanup);
4463
4464 /* Some compilers don't define a DW_AT_high_pc attribute for the
4465 compilation unit. If the DW_AT_high_pc is missing, synthesize
4466 it, by scanning the DIE's below the compilation unit. */
4467 get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
4468
4469 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
4470
4471 /* Set symtab language to language from DW_AT_language.
4472 If the compilation is from a C file generated by language preprocessors,
4473 do not set the language if it was already deduced by start_subfile. */
4474 if (symtab != NULL
4475 && !(cu->language == language_c && symtab->language != language_c))
4476 {
4477 symtab->language = cu->language;
4478 }
4479
4480 if (dwarf2_per_objfile->using_index)
4481 per_cu->v.quick->symtab = symtab;
4482 else
4483 {
4484 struct partial_symtab *pst = per_cu->v.psymtab;
4485 pst->symtab = symtab;
4486 pst->readin = 1;
4487 }
4488
4489 do_cleanups (back_to);
4490 }
4491
4492 /* Process a die and its children. */
4493
4494 static void
4495 process_die (struct die_info *die, struct dwarf2_cu *cu)
4496 {
4497 switch (die->tag)
4498 {
4499 case DW_TAG_padding:
4500 break;
4501 case DW_TAG_compile_unit:
4502 read_file_scope (die, cu);
4503 break;
4504 case DW_TAG_type_unit:
4505 read_type_unit_scope (die, cu);
4506 break;
4507 case DW_TAG_subprogram:
4508 case DW_TAG_inlined_subroutine:
4509 read_func_scope (die, cu);
4510 break;
4511 case DW_TAG_lexical_block:
4512 case DW_TAG_try_block:
4513 case DW_TAG_catch_block:
4514 read_lexical_block_scope (die, cu);
4515 break;
4516 case DW_TAG_class_type:
4517 case DW_TAG_interface_type:
4518 case DW_TAG_structure_type:
4519 case DW_TAG_union_type:
4520 process_structure_scope (die, cu);
4521 break;
4522 case DW_TAG_enumeration_type:
4523 process_enumeration_scope (die, cu);
4524 break;
4525
4526 /* These dies have a type, but processing them does not create
4527 a symbol or recurse to process the children. Therefore we can
4528 read them on-demand through read_type_die. */
4529 case DW_TAG_subroutine_type:
4530 case DW_TAG_set_type:
4531 case DW_TAG_array_type:
4532 case DW_TAG_pointer_type:
4533 case DW_TAG_ptr_to_member_type:
4534 case DW_TAG_reference_type:
4535 case DW_TAG_string_type:
4536 break;
4537
4538 case DW_TAG_base_type:
4539 case DW_TAG_subrange_type:
4540 case DW_TAG_typedef:
4541 /* Add a typedef symbol for the type definition, if it has a
4542 DW_AT_name. */
4543 new_symbol (die, read_type_die (die, cu), cu);
4544 break;
4545 case DW_TAG_common_block:
4546 read_common_block (die, cu);
4547 break;
4548 case DW_TAG_common_inclusion:
4549 break;
4550 case DW_TAG_namespace:
4551 processing_has_namespace_info = 1;
4552 read_namespace (die, cu);
4553 break;
4554 case DW_TAG_module:
4555 processing_has_namespace_info = 1;
4556 read_module (die, cu);
4557 break;
4558 case DW_TAG_imported_declaration:
4559 case DW_TAG_imported_module:
4560 processing_has_namespace_info = 1;
4561 if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
4562 || cu->language != language_fortran))
4563 complaint (&symfile_complaints, _("Tag '%s' has unexpected children"),
4564 dwarf_tag_name (die->tag));
4565 read_import_statement (die, cu);
4566 break;
4567 default:
4568 new_symbol (die, NULL, cu);
4569 break;
4570 }
4571 }
4572
4573 /* A helper function for dwarf2_compute_name which determines whether DIE
4574 needs to have the name of the scope prepended to the name listed in the
4575 die. */
4576
4577 static int
4578 die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
4579 {
4580 struct attribute *attr;
4581
4582 switch (die->tag)
4583 {
4584 case DW_TAG_namespace:
4585 case DW_TAG_typedef:
4586 case DW_TAG_class_type:
4587 case DW_TAG_interface_type:
4588 case DW_TAG_structure_type:
4589 case DW_TAG_union_type:
4590 case DW_TAG_enumeration_type:
4591 case DW_TAG_enumerator:
4592 case DW_TAG_subprogram:
4593 case DW_TAG_member:
4594 return 1;
4595
4596 case DW_TAG_variable:
4597 /* We only need to prefix "globally" visible variables. These include
4598 any variable marked with DW_AT_external or any variable that
4599 lives in a namespace. [Variables in anonymous namespaces
4600 require prefixing, but they are not DW_AT_external.] */
4601
4602 if (dwarf2_attr (die, DW_AT_specification, cu))
4603 {
4604 struct dwarf2_cu *spec_cu = cu;
4605
4606 return die_needs_namespace (die_specification (die, &spec_cu),
4607 spec_cu);
4608 }
4609
4610 attr = dwarf2_attr (die, DW_AT_external, cu);
4611 if (attr == NULL && die->parent->tag != DW_TAG_namespace
4612 && die->parent->tag != DW_TAG_module)
4613 return 0;
4614 /* A variable in a lexical block of some kind does not need a
4615 namespace, even though in C++ such variables may be external
4616 and have a mangled name. */
4617 if (die->parent->tag == DW_TAG_lexical_block
4618 || die->parent->tag == DW_TAG_try_block
4619 || die->parent->tag == DW_TAG_catch_block
4620 || die->parent->tag == DW_TAG_subprogram)
4621 return 0;
4622 return 1;
4623
4624 default:
4625 return 0;
4626 }
4627 }
4628
4629 /* Retrieve the last character from a mem_file. */
4630
4631 static void
4632 do_ui_file_peek_last (void *object, const char *buffer, long length)
4633 {
4634 char *last_char_p = (char *) object;
4635
4636 if (length > 0)
4637 *last_char_p = buffer[length - 1];
4638 }
4639
4640 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4641 compute the physname for the object, which include a method's
4642 formal parameters (C++/Java) and return type (Java).
4643
4644 For Ada, return the DIE's linkage name rather than the fully qualified
4645 name. PHYSNAME is ignored..
4646
4647 The result is allocated on the objfile_obstack and canonicalized. */
4648
4649 static const char *
4650 dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
4651 int physname)
4652 {
4653 if (name == NULL)
4654 name = dwarf2_name (die, cu);
4655
4656 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4657 compute it by typename_concat inside GDB. */
4658 if (cu->language == language_ada
4659 || (cu->language == language_fortran && physname))
4660 {
4661 /* For Ada unit, we prefer the linkage name over the name, as
4662 the former contains the exported name, which the user expects
4663 to be able to reference. Ideally, we want the user to be able
4664 to reference this entity using either natural or linkage name,
4665 but we haven't started looking at this enhancement yet. */
4666 struct attribute *attr;
4667
4668 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
4669 if (attr == NULL)
4670 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
4671 if (attr && DW_STRING (attr))
4672 return DW_STRING (attr);
4673 }
4674
4675 /* These are the only languages we know how to qualify names in. */
4676 if (name != NULL
4677 && (cu->language == language_cplus || cu->language == language_java
4678 || cu->language == language_fortran))
4679 {
4680 if (die_needs_namespace (die, cu))
4681 {
4682 long length;
4683 char *prefix;
4684 struct ui_file *buf;
4685
4686 prefix = determine_prefix (die, cu);
4687 buf = mem_fileopen ();
4688 if (*prefix != '\0')
4689 {
4690 char *prefixed_name = typename_concat (NULL, prefix, name,
4691 physname, cu);
4692
4693 fputs_unfiltered (prefixed_name, buf);
4694 xfree (prefixed_name);
4695 }
4696 else
4697 fputs_unfiltered (name ? name : "", buf);
4698
4699 /* Template parameters may be specified in the DIE's DW_AT_name, or
4700 as children with DW_TAG_template_type_param or
4701 DW_TAG_value_type_param. If the latter, add them to the name
4702 here. If the name already has template parameters, then
4703 skip this step; some versions of GCC emit both, and
4704 it is more efficient to use the pre-computed name.
4705
4706 Something to keep in mind about this process: it is very
4707 unlikely, or in some cases downright impossible, to produce
4708 something that will match the mangled name of a function.
4709 If the definition of the function has the same debug info,
4710 we should be able to match up with it anyway. But fallbacks
4711 using the minimal symbol, for instance to find a method
4712 implemented in a stripped copy of libstdc++, will not work.
4713 If we do not have debug info for the definition, we will have to
4714 match them up some other way.
4715
4716 When we do name matching there is a related problem with function
4717 templates; two instantiated function templates are allowed to
4718 differ only by their return types, which we do not add here. */
4719
4720 if (cu->language == language_cplus && strchr (name, '<') == NULL)
4721 {
4722 struct attribute *attr;
4723 struct die_info *child;
4724 int first = 1;
4725
4726 die->building_fullname = 1;
4727
4728 for (child = die->child; child != NULL; child = child->sibling)
4729 {
4730 struct type *type;
4731 long value;
4732 gdb_byte *bytes;
4733 struct dwarf2_locexpr_baton *baton;
4734 struct value *v;
4735
4736 if (child->tag != DW_TAG_template_type_param
4737 && child->tag != DW_TAG_template_value_param)
4738 continue;
4739
4740 if (first)
4741 {
4742 fputs_unfiltered ("<", buf);
4743 first = 0;
4744 }
4745 else
4746 fputs_unfiltered (", ", buf);
4747
4748 attr = dwarf2_attr (child, DW_AT_type, cu);
4749 if (attr == NULL)
4750 {
4751 complaint (&symfile_complaints,
4752 _("template parameter missing DW_AT_type"));
4753 fputs_unfiltered ("UNKNOWN_TYPE", buf);
4754 continue;
4755 }
4756 type = die_type (child, cu);
4757
4758 if (child->tag == DW_TAG_template_type_param)
4759 {
4760 c_print_type (type, "", buf, -1, 0);
4761 continue;
4762 }
4763
4764 attr = dwarf2_attr (child, DW_AT_const_value, cu);
4765 if (attr == NULL)
4766 {
4767 complaint (&symfile_complaints,
4768 _("template parameter missing DW_AT_const_value"));
4769 fputs_unfiltered ("UNKNOWN_VALUE", buf);
4770 continue;
4771 }
4772
4773 dwarf2_const_value_attr (attr, type, name,
4774 &cu->comp_unit_obstack, cu,
4775 &value, &bytes, &baton);
4776
4777 if (TYPE_NOSIGN (type))
4778 /* GDB prints characters as NUMBER 'CHAR'. If that's
4779 changed, this can use value_print instead. */
4780 c_printchar (value, type, buf);
4781 else
4782 {
4783 struct value_print_options opts;
4784
4785 if (baton != NULL)
4786 v = dwarf2_evaluate_loc_desc (type, NULL,
4787 baton->data,
4788 baton->size,
4789 baton->per_cu);
4790 else if (bytes != NULL)
4791 {
4792 v = allocate_value (type);
4793 memcpy (value_contents_writeable (v), bytes,
4794 TYPE_LENGTH (type));
4795 }
4796 else
4797 v = value_from_longest (type, value);
4798
4799 /* Specify decimal so that we do not depend on the radix. */
4800 get_formatted_print_options (&opts, 'd');
4801 opts.raw = 1;
4802 value_print (v, buf, &opts);
4803 release_value (v);
4804 value_free (v);
4805 }
4806 }
4807
4808 die->building_fullname = 0;
4809
4810 if (!first)
4811 {
4812 /* Close the argument list, with a space if necessary
4813 (nested templates). */
4814 char last_char = '\0';
4815 ui_file_put (buf, do_ui_file_peek_last, &last_char);
4816 if (last_char == '>')
4817 fputs_unfiltered (" >", buf);
4818 else
4819 fputs_unfiltered (">", buf);
4820 }
4821 }
4822
4823 /* For Java and C++ methods, append formal parameter type
4824 information, if PHYSNAME. */
4825
4826 if (physname && die->tag == DW_TAG_subprogram
4827 && (cu->language == language_cplus
4828 || cu->language == language_java))
4829 {
4830 struct type *type = read_type_die (die, cu);
4831
4832 c_type_print_args (type, buf, 0, cu->language);
4833
4834 if (cu->language == language_java)
4835 {
4836 /* For java, we must append the return type to method
4837 names. */
4838 if (die->tag == DW_TAG_subprogram)
4839 java_print_type (TYPE_TARGET_TYPE (type), "", buf,
4840 0, 0);
4841 }
4842 else if (cu->language == language_cplus)
4843 {
4844 if (TYPE_NFIELDS (type) > 0
4845 && TYPE_FIELD_ARTIFICIAL (type, 0)
4846 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0))))
4847 fputs_unfiltered (" const", buf);
4848 }
4849 }
4850
4851 name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack,
4852 &length);
4853 ui_file_delete (buf);
4854
4855 if (cu->language == language_cplus)
4856 {
4857 char *cname
4858 = dwarf2_canonicalize_name (name, cu,
4859 &cu->objfile->objfile_obstack);
4860
4861 if (cname != NULL)
4862 name = cname;
4863 }
4864 }
4865 }
4866
4867 return name;
4868 }
4869
4870 /* Return the fully qualified name of DIE, based on its DW_AT_name.
4871 If scope qualifiers are appropriate they will be added. The result
4872 will be allocated on the objfile_obstack, or NULL if the DIE does
4873 not have a name. NAME may either be from a previous call to
4874 dwarf2_name or NULL.
4875
4876 The output string will be canonicalized (if C++/Java). */
4877
4878 static const char *
4879 dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu)
4880 {
4881 return dwarf2_compute_name (name, die, cu, 0);
4882 }
4883
4884 /* Construct a physname for the given DIE in CU. NAME may either be
4885 from a previous call to dwarf2_name or NULL. The result will be
4886 allocated on the objfile_objstack or NULL if the DIE does not have a
4887 name.
4888
4889 The output string will be canonicalized (if C++/Java). */
4890
4891 static const char *
4892 dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu)
4893 {
4894 return dwarf2_compute_name (name, die, cu, 1);
4895 }
4896
4897 /* Read the import statement specified by the given die and record it. */
4898
4899 static void
4900 read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
4901 {
4902 struct attribute *import_attr;
4903 struct die_info *imported_die;
4904 struct dwarf2_cu *imported_cu;
4905 const char *imported_name;
4906 const char *imported_name_prefix;
4907 const char *canonical_name;
4908 const char *import_alias;
4909 const char *imported_declaration = NULL;
4910 const char *import_prefix;
4911
4912 char *temp;
4913
4914 import_attr = dwarf2_attr (die, DW_AT_import, cu);
4915 if (import_attr == NULL)
4916 {
4917 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
4918 dwarf_tag_name (die->tag));
4919 return;
4920 }
4921
4922 imported_cu = cu;
4923 imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu);
4924 imported_name = dwarf2_name (imported_die, imported_cu);
4925 if (imported_name == NULL)
4926 {
4927 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
4928
4929 The import in the following code:
4930 namespace A
4931 {
4932 typedef int B;
4933 }
4934
4935 int main ()
4936 {
4937 using A::B;
4938 B b;
4939 return b;
4940 }
4941
4942 ...
4943 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
4944 <52> DW_AT_decl_file : 1
4945 <53> DW_AT_decl_line : 6
4946 <54> DW_AT_import : <0x75>
4947 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
4948 <59> DW_AT_name : B
4949 <5b> DW_AT_decl_file : 1
4950 <5c> DW_AT_decl_line : 2
4951 <5d> DW_AT_type : <0x6e>
4952 ...
4953 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
4954 <76> DW_AT_byte_size : 4
4955 <77> DW_AT_encoding : 5 (signed)
4956
4957 imports the wrong die ( 0x75 instead of 0x58 ).
4958 This case will be ignored until the gcc bug is fixed. */
4959 return;
4960 }
4961
4962 /* Figure out the local name after import. */
4963 import_alias = dwarf2_name (die, cu);
4964
4965 /* Figure out where the statement is being imported to. */
4966 import_prefix = determine_prefix (die, cu);
4967
4968 /* Figure out what the scope of the imported die is and prepend it
4969 to the name of the imported die. */
4970 imported_name_prefix = determine_prefix (imported_die, imported_cu);
4971
4972 if (imported_die->tag != DW_TAG_namespace
4973 && imported_die->tag != DW_TAG_module)
4974 {
4975 imported_declaration = imported_name;
4976 canonical_name = imported_name_prefix;
4977 }
4978 else if (strlen (imported_name_prefix) > 0)
4979 {
4980 temp = alloca (strlen (imported_name_prefix)
4981 + 2 + strlen (imported_name) + 1);
4982 strcpy (temp, imported_name_prefix);
4983 strcat (temp, "::");
4984 strcat (temp, imported_name);
4985 canonical_name = temp;
4986 }
4987 else
4988 canonical_name = imported_name;
4989
4990 cp_add_using_directive (import_prefix,
4991 canonical_name,
4992 import_alias,
4993 imported_declaration,
4994 &cu->objfile->objfile_obstack);
4995 }
4996
4997 static void
4998 initialize_cu_func_list (struct dwarf2_cu *cu)
4999 {
5000 cu->first_fn = cu->last_fn = cu->cached_fn = NULL;
5001 }
5002
5003 static void
5004 free_cu_line_header (void *arg)
5005 {
5006 struct dwarf2_cu *cu = arg;
5007
5008 free_line_header (cu->line_header);
5009 cu->line_header = NULL;
5010 }
5011
5012 static void
5013 find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu,
5014 char **name, char **comp_dir)
5015 {
5016 struct attribute *attr;
5017
5018 *name = NULL;
5019 *comp_dir = NULL;
5020
5021 /* Find the filename. Do not use dwarf2_name here, since the filename
5022 is not a source language identifier. */
5023 attr = dwarf2_attr (die, DW_AT_name, cu);
5024 if (attr)
5025 {
5026 *name = DW_STRING (attr);
5027 }
5028
5029 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
5030 if (attr)
5031 *comp_dir = DW_STRING (attr);
5032 else if (*name != NULL && IS_ABSOLUTE_PATH (*name))
5033 {
5034 *comp_dir = ldirname (*name);
5035 if (*comp_dir != NULL)
5036 make_cleanup (xfree, *comp_dir);
5037 }
5038 if (*comp_dir != NULL)
5039 {
5040 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5041 directory, get rid of it. */
5042 char *cp = strchr (*comp_dir, ':');
5043
5044 if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/')
5045 *comp_dir = cp + 1;
5046 }
5047
5048 if (*name == NULL)
5049 *name = "<unknown>";
5050 }
5051
5052 static void
5053 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
5054 {
5055 struct objfile *objfile = cu->objfile;
5056 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
5057 CORE_ADDR lowpc = ((CORE_ADDR) -1);
5058 CORE_ADDR highpc = ((CORE_ADDR) 0);
5059 struct attribute *attr;
5060 char *name = NULL;
5061 char *comp_dir = NULL;
5062 struct die_info *child_die;
5063 bfd *abfd = objfile->obfd;
5064 struct line_header *line_header = 0;
5065 CORE_ADDR baseaddr;
5066
5067 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5068
5069 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
5070
5071 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5072 from finish_block. */
5073 if (lowpc == ((CORE_ADDR) -1))
5074 lowpc = highpc;
5075 lowpc += baseaddr;
5076 highpc += baseaddr;
5077
5078 find_file_and_directory (die, cu, &name, &comp_dir);
5079
5080 attr = dwarf2_attr (die, DW_AT_language, cu);
5081 if (attr)
5082 {
5083 set_cu_language (DW_UNSND (attr), cu);
5084 }
5085
5086 attr = dwarf2_attr (die, DW_AT_producer, cu);
5087 if (attr)
5088 cu->producer = DW_STRING (attr);
5089
5090 /* We assume that we're processing GCC output. */
5091 processing_gcc_compilation = 2;
5092
5093 processing_has_namespace_info = 0;
5094
5095 start_symtab (name, comp_dir, lowpc);
5096 record_debugformat ("DWARF 2");
5097 record_producer (cu->producer);
5098
5099 initialize_cu_func_list (cu);
5100
5101 /* Decode line number information if present. We do this before
5102 processing child DIEs, so that the line header table is available
5103 for DW_AT_decl_file. */
5104 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
5105 if (attr)
5106 {
5107 unsigned int line_offset = DW_UNSND (attr);
5108 line_header = dwarf_decode_line_header (line_offset, abfd, cu);
5109 if (line_header)
5110 {
5111 cu->line_header = line_header;
5112 make_cleanup (free_cu_line_header, cu);
5113 dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL);
5114 }
5115 }
5116
5117 /* Process all dies in compilation unit. */
5118 if (die->child != NULL)
5119 {
5120 child_die = die->child;
5121 while (child_die && child_die->tag)
5122 {
5123 process_die (child_die, cu);
5124 child_die = sibling_die (child_die);
5125 }
5126 }
5127
5128 /* Decode macro information, if present. Dwarf 2 macro information
5129 refers to information in the line number info statement program
5130 header, so we can only read it if we've read the header
5131 successfully. */
5132 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
5133 if (attr && line_header)
5134 {
5135 unsigned int macro_offset = DW_UNSND (attr);
5136
5137 dwarf_decode_macros (line_header, macro_offset,
5138 comp_dir, abfd, cu);
5139 }
5140 do_cleanups (back_to);
5141 }
5142
5143 /* For TUs we want to skip the first top level sibling if it's not the
5144 actual type being defined by this TU. In this case the first top
5145 level sibling is there to provide context only. */
5146
5147 static void
5148 read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
5149 {
5150 struct objfile *objfile = cu->objfile;
5151 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
5152 CORE_ADDR lowpc;
5153 struct attribute *attr;
5154 char *name = NULL;
5155 char *comp_dir = NULL;
5156 struct die_info *child_die;
5157 bfd *abfd = objfile->obfd;
5158
5159 /* start_symtab needs a low pc, but we don't really have one.
5160 Do what read_file_scope would do in the absence of such info. */
5161 lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5162
5163 /* Find the filename. Do not use dwarf2_name here, since the filename
5164 is not a source language identifier. */
5165 attr = dwarf2_attr (die, DW_AT_name, cu);
5166 if (attr)
5167 name = DW_STRING (attr);
5168
5169 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
5170 if (attr)
5171 comp_dir = DW_STRING (attr);
5172 else if (name != NULL && IS_ABSOLUTE_PATH (name))
5173 {
5174 comp_dir = ldirname (name);
5175 if (comp_dir != NULL)
5176 make_cleanup (xfree, comp_dir);
5177 }
5178
5179 if (name == NULL)
5180 name = "<unknown>";
5181
5182 attr = dwarf2_attr (die, DW_AT_language, cu);
5183 if (attr)
5184 set_cu_language (DW_UNSND (attr), cu);
5185
5186 /* This isn't technically needed today. It is done for symmetry
5187 with read_file_scope. */
5188 attr = dwarf2_attr (die, DW_AT_producer, cu);
5189 if (attr)
5190 cu->producer = DW_STRING (attr);
5191
5192 /* We assume that we're processing GCC output. */
5193 processing_gcc_compilation = 2;
5194
5195 processing_has_namespace_info = 0;
5196
5197 start_symtab (name, comp_dir, lowpc);
5198 record_debugformat ("DWARF 2");
5199 record_producer (cu->producer);
5200
5201 /* Process the dies in the type unit. */
5202 if (die->child == NULL)
5203 {
5204 dump_die_for_error (die);
5205 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5206 bfd_get_filename (abfd));
5207 }
5208
5209 child_die = die->child;
5210
5211 while (child_die && child_die->tag)
5212 {
5213 process_die (child_die, cu);
5214
5215 child_die = sibling_die (child_die);
5216 }
5217
5218 do_cleanups (back_to);
5219 }
5220
5221 static void
5222 add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc,
5223 struct dwarf2_cu *cu)
5224 {
5225 struct function_range *thisfn;
5226
5227 thisfn = (struct function_range *)
5228 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range));
5229 thisfn->name = name;
5230 thisfn->lowpc = lowpc;
5231 thisfn->highpc = highpc;
5232 thisfn->seen_line = 0;
5233 thisfn->next = NULL;
5234
5235 if (cu->last_fn == NULL)
5236 cu->first_fn = thisfn;
5237 else
5238 cu->last_fn->next = thisfn;
5239
5240 cu->last_fn = thisfn;
5241 }
5242
5243 /* qsort helper for inherit_abstract_dies. */
5244
5245 static int
5246 unsigned_int_compar (const void *ap, const void *bp)
5247 {
5248 unsigned int a = *(unsigned int *) ap;
5249 unsigned int b = *(unsigned int *) bp;
5250
5251 return (a > b) - (b > a);
5252 }
5253
5254 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5255 Inherit only the children of the DW_AT_abstract_origin DIE not being already
5256 referenced by DW_AT_abstract_origin from the children of the current DIE. */
5257
5258 static void
5259 inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
5260 {
5261 struct die_info *child_die;
5262 unsigned die_children_count;
5263 /* CU offsets which were referenced by children of the current DIE. */
5264 unsigned *offsets;
5265 unsigned *offsets_end, *offsetp;
5266 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5267 struct die_info *origin_die;
5268 /* Iterator of the ORIGIN_DIE children. */
5269 struct die_info *origin_child_die;
5270 struct cleanup *cleanups;
5271 struct attribute *attr;
5272 struct dwarf2_cu *origin_cu;
5273 struct pending **origin_previous_list_in_scope;
5274
5275 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
5276 if (!attr)
5277 return;
5278
5279 /* Note that following die references may follow to a die in a
5280 different cu. */
5281
5282 origin_cu = cu;
5283 origin_die = follow_die_ref (die, attr, &origin_cu);
5284
5285 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5286 symbols in. */
5287 origin_previous_list_in_scope = origin_cu->list_in_scope;
5288 origin_cu->list_in_scope = cu->list_in_scope;
5289
5290 if (die->tag != origin_die->tag
5291 && !(die->tag == DW_TAG_inlined_subroutine
5292 && origin_die->tag == DW_TAG_subprogram))
5293 complaint (&symfile_complaints,
5294 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5295 die->offset, origin_die->offset);
5296
5297 child_die = die->child;
5298 die_children_count = 0;
5299 while (child_die && child_die->tag)
5300 {
5301 child_die = sibling_die (child_die);
5302 die_children_count++;
5303 }
5304 offsets = xmalloc (sizeof (*offsets) * die_children_count);
5305 cleanups = make_cleanup (xfree, offsets);
5306
5307 offsets_end = offsets;
5308 child_die = die->child;
5309 while (child_die && child_die->tag)
5310 {
5311 /* For each CHILD_DIE, find the corresponding child of
5312 ORIGIN_DIE. If there is more than one layer of
5313 DW_AT_abstract_origin, follow them all; there shouldn't be,
5314 but GCC versions at least through 4.4 generate this (GCC PR
5315 40573). */
5316 struct die_info *child_origin_die = child_die;
5317 struct dwarf2_cu *child_origin_cu = cu;
5318
5319 while (1)
5320 {
5321 attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin,
5322 child_origin_cu);
5323 if (attr == NULL)
5324 break;
5325 child_origin_die = follow_die_ref (child_origin_die, attr,
5326 &child_origin_cu);
5327 }
5328
5329 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5330 counterpart may exist. */
5331 if (child_origin_die != child_die)
5332 {
5333 if (child_die->tag != child_origin_die->tag
5334 && !(child_die->tag == DW_TAG_inlined_subroutine
5335 && child_origin_die->tag == DW_TAG_subprogram))
5336 complaint (&symfile_complaints,
5337 _("Child DIE 0x%x and its abstract origin 0x%x have "
5338 "different tags"), child_die->offset,
5339 child_origin_die->offset);
5340 if (child_origin_die->parent != origin_die)
5341 complaint (&symfile_complaints,
5342 _("Child DIE 0x%x and its abstract origin 0x%x have "
5343 "different parents"), child_die->offset,
5344 child_origin_die->offset);
5345 else
5346 *offsets_end++ = child_origin_die->offset;
5347 }
5348 child_die = sibling_die (child_die);
5349 }
5350 qsort (offsets, offsets_end - offsets, sizeof (*offsets),
5351 unsigned_int_compar);
5352 for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++)
5353 if (offsetp[-1] == *offsetp)
5354 complaint (&symfile_complaints, _("Multiple children of DIE 0x%x refer "
5355 "to DIE 0x%x as their abstract origin"),
5356 die->offset, *offsetp);
5357
5358 offsetp = offsets;
5359 origin_child_die = origin_die->child;
5360 while (origin_child_die && origin_child_die->tag)
5361 {
5362 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5363 while (offsetp < offsets_end && *offsetp < origin_child_die->offset)
5364 offsetp++;
5365 if (offsetp >= offsets_end || *offsetp > origin_child_die->offset)
5366 {
5367 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5368 process_die (origin_child_die, origin_cu);
5369 }
5370 origin_child_die = sibling_die (origin_child_die);
5371 }
5372 origin_cu->list_in_scope = origin_previous_list_in_scope;
5373
5374 do_cleanups (cleanups);
5375 }
5376
5377 static void
5378 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
5379 {
5380 struct objfile *objfile = cu->objfile;
5381 struct context_stack *new;
5382 CORE_ADDR lowpc;
5383 CORE_ADDR highpc;
5384 struct die_info *child_die;
5385 struct attribute *attr, *call_line, *call_file;
5386 char *name;
5387 CORE_ADDR baseaddr;
5388 struct block *block;
5389 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
5390 VEC (symbolp) *template_args = NULL;
5391 struct template_symbol *templ_func = NULL;
5392
5393 if (inlined_func)
5394 {
5395 /* If we do not have call site information, we can't show the
5396 caller of this inlined function. That's too confusing, so
5397 only use the scope for local variables. */
5398 call_line = dwarf2_attr (die, DW_AT_call_line, cu);
5399 call_file = dwarf2_attr (die, DW_AT_call_file, cu);
5400 if (call_line == NULL || call_file == NULL)
5401 {
5402 read_lexical_block_scope (die, cu);
5403 return;
5404 }
5405 }
5406
5407 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5408
5409 name = dwarf2_name (die, cu);
5410
5411 /* Ignore functions with missing or empty names. These are actually
5412 illegal according to the DWARF standard. */
5413 if (name == NULL)
5414 {
5415 complaint (&symfile_complaints,
5416 _("missing name for subprogram DIE at %d"), die->offset);
5417 return;
5418 }
5419
5420 /* Ignore functions with missing or invalid low and high pc attributes. */
5421 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
5422 {
5423 attr = dwarf2_attr (die, DW_AT_external, cu);
5424 if (!attr || !DW_UNSND (attr))
5425 complaint (&symfile_complaints,
5426 _("cannot get low and high bounds for subprogram DIE at %d"),
5427 die->offset);
5428 return;
5429 }
5430
5431 lowpc += baseaddr;
5432 highpc += baseaddr;
5433
5434 /* Record the function range for dwarf_decode_lines. */
5435 add_to_cu_func_list (name, lowpc, highpc, cu);
5436
5437 /* If we have any template arguments, then we must allocate a
5438 different sort of symbol. */
5439 for (child_die = die->child; child_die; child_die = sibling_die (child_die))
5440 {
5441 if (child_die->tag == DW_TAG_template_type_param
5442 || child_die->tag == DW_TAG_template_value_param)
5443 {
5444 templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack,
5445 struct template_symbol);
5446 templ_func->base.is_cplus_template_function = 1;
5447 break;
5448 }
5449 }
5450
5451 new = push_context (0, lowpc);
5452 new->name = new_symbol_full (die, read_type_die (die, cu), cu,
5453 (struct symbol *) templ_func);
5454
5455 /* If there is a location expression for DW_AT_frame_base, record
5456 it. */
5457 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
5458 if (attr)
5459 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5460 expression is being recorded directly in the function's symbol
5461 and not in a separate frame-base object. I guess this hack is
5462 to avoid adding some sort of frame-base adjunct/annex to the
5463 function's symbol :-(. The problem with doing this is that it
5464 results in a function symbol with a location expression that
5465 has nothing to do with the location of the function, ouch! The
5466 relationship should be: a function's symbol has-a frame base; a
5467 frame-base has-a location expression. */
5468 dwarf2_symbol_mark_computed (attr, new->name, cu);
5469
5470 cu->list_in_scope = &local_symbols;
5471
5472 if (die->child != NULL)
5473 {
5474 child_die = die->child;
5475 while (child_die && child_die->tag)
5476 {
5477 if (child_die->tag == DW_TAG_template_type_param
5478 || child_die->tag == DW_TAG_template_value_param)
5479 {
5480 struct symbol *arg = new_symbol (child_die, NULL, cu);
5481
5482 VEC_safe_push (symbolp, template_args, arg);
5483 }
5484 else
5485 process_die (child_die, cu);
5486 child_die = sibling_die (child_die);
5487 }
5488 }
5489
5490 inherit_abstract_dies (die, cu);
5491
5492 /* If we have a DW_AT_specification, we might need to import using
5493 directives from the context of the specification DIE. See the
5494 comment in determine_prefix. */
5495 if (cu->language == language_cplus
5496 && dwarf2_attr (die, DW_AT_specification, cu))
5497 {
5498 struct dwarf2_cu *spec_cu = cu;
5499 struct die_info *spec_die = die_specification (die, &spec_cu);
5500
5501 while (spec_die)
5502 {
5503 child_die = spec_die->child;
5504 while (child_die && child_die->tag)
5505 {
5506 if (child_die->tag == DW_TAG_imported_module)
5507 process_die (child_die, spec_cu);
5508 child_die = sibling_die (child_die);
5509 }
5510
5511 /* In some cases, GCC generates specification DIEs that
5512 themselves contain DW_AT_specification attributes. */
5513 spec_die = die_specification (spec_die, &spec_cu);
5514 }
5515 }
5516
5517 new = pop_context ();
5518 /* Make a block for the local symbols within. */
5519 block = finish_block (new->name, &local_symbols, new->old_blocks,
5520 lowpc, highpc, objfile);
5521
5522 /* For C++, set the block's scope. */
5523 if (cu->language == language_cplus || cu->language == language_fortran)
5524 cp_set_block_scope (new->name, block, &objfile->objfile_obstack,
5525 determine_prefix (die, cu),
5526 processing_has_namespace_info);
5527
5528 /* If we have address ranges, record them. */
5529 dwarf2_record_block_ranges (die, block, baseaddr, cu);
5530
5531 /* Attach template arguments to function. */
5532 if (! VEC_empty (symbolp, template_args))
5533 {
5534 gdb_assert (templ_func != NULL);
5535
5536 templ_func->n_template_arguments = VEC_length (symbolp, template_args);
5537 templ_func->template_arguments
5538 = obstack_alloc (&objfile->objfile_obstack,
5539 (templ_func->n_template_arguments
5540 * sizeof (struct symbol *)));
5541 memcpy (templ_func->template_arguments,
5542 VEC_address (symbolp, template_args),
5543 (templ_func->n_template_arguments * sizeof (struct symbol *)));
5544 VEC_free (symbolp, template_args);
5545 }
5546
5547 /* In C++, we can have functions nested inside functions (e.g., when
5548 a function declares a class that has methods). This means that
5549 when we finish processing a function scope, we may need to go
5550 back to building a containing block's symbol lists. */
5551 local_symbols = new->locals;
5552 param_symbols = new->params;
5553 using_directives = new->using_directives;
5554
5555 /* If we've finished processing a top-level function, subsequent
5556 symbols go in the file symbol list. */
5557 if (outermost_context_p ())
5558 cu->list_in_scope = &file_symbols;
5559 }
5560
5561 /* Process all the DIES contained within a lexical block scope. Start
5562 a new scope, process the dies, and then close the scope. */
5563
5564 static void
5565 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
5566 {
5567 struct objfile *objfile = cu->objfile;
5568 struct context_stack *new;
5569 CORE_ADDR lowpc, highpc;
5570 struct die_info *child_die;
5571 CORE_ADDR baseaddr;
5572
5573 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5574
5575 /* Ignore blocks with missing or invalid low and high pc attributes. */
5576 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
5577 as multiple lexical blocks? Handling children in a sane way would
5578 be nasty. Might be easier to properly extend generic blocks to
5579 describe ranges. */
5580 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
5581 return;
5582 lowpc += baseaddr;
5583 highpc += baseaddr;
5584
5585 push_context (0, lowpc);
5586 if (die->child != NULL)
5587 {
5588 child_die = die->child;
5589 while (child_die && child_die->tag)
5590 {
5591 process_die (child_die, cu);
5592 child_die = sibling_die (child_die);
5593 }
5594 }
5595 new = pop_context ();
5596
5597 if (local_symbols != NULL || using_directives != NULL)
5598 {
5599 struct block *block
5600 = finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
5601 highpc, objfile);
5602
5603 /* Note that recording ranges after traversing children, as we
5604 do here, means that recording a parent's ranges entails
5605 walking across all its children's ranges as they appear in
5606 the address map, which is quadratic behavior.
5607
5608 It would be nicer to record the parent's ranges before
5609 traversing its children, simply overriding whatever you find
5610 there. But since we don't even decide whether to create a
5611 block until after we've traversed its children, that's hard
5612 to do. */
5613 dwarf2_record_block_ranges (die, block, baseaddr, cu);
5614 }
5615 local_symbols = new->locals;
5616 using_directives = new->using_directives;
5617 }
5618
5619 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
5620 Return 1 if the attributes are present and valid, otherwise, return 0.
5621 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
5622
5623 static int
5624 dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
5625 CORE_ADDR *high_return, struct dwarf2_cu *cu,
5626 struct partial_symtab *ranges_pst)
5627 {
5628 struct objfile *objfile = cu->objfile;
5629 struct comp_unit_head *cu_header = &cu->header;
5630 bfd *obfd = objfile->obfd;
5631 unsigned int addr_size = cu_header->addr_size;
5632 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
5633 /* Base address selection entry. */
5634 CORE_ADDR base;
5635 int found_base;
5636 unsigned int dummy;
5637 gdb_byte *buffer;
5638 CORE_ADDR marker;
5639 int low_set;
5640 CORE_ADDR low = 0;
5641 CORE_ADDR high = 0;
5642 CORE_ADDR baseaddr;
5643
5644 found_base = cu->base_known;
5645 base = cu->base_address;
5646
5647 dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges);
5648 if (offset >= dwarf2_per_objfile->ranges.size)
5649 {
5650 complaint (&symfile_complaints,
5651 _("Offset %d out of bounds for DW_AT_ranges attribute"),
5652 offset);
5653 return 0;
5654 }
5655 buffer = dwarf2_per_objfile->ranges.buffer + offset;
5656
5657 /* Read in the largest possible address. */
5658 marker = read_address (obfd, buffer, cu, &dummy);
5659 if ((marker & mask) == mask)
5660 {
5661 /* If we found the largest possible address, then
5662 read the base address. */
5663 base = read_address (obfd, buffer + addr_size, cu, &dummy);
5664 buffer += 2 * addr_size;
5665 offset += 2 * addr_size;
5666 found_base = 1;
5667 }
5668
5669 low_set = 0;
5670
5671 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5672
5673 while (1)
5674 {
5675 CORE_ADDR range_beginning, range_end;
5676
5677 range_beginning = read_address (obfd, buffer, cu, &dummy);
5678 buffer += addr_size;
5679 range_end = read_address (obfd, buffer, cu, &dummy);
5680 buffer += addr_size;
5681 offset += 2 * addr_size;
5682
5683 /* An end of list marker is a pair of zero addresses. */
5684 if (range_beginning == 0 && range_end == 0)
5685 /* Found the end of list entry. */
5686 break;
5687
5688 /* Each base address selection entry is a pair of 2 values.
5689 The first is the largest possible address, the second is
5690 the base address. Check for a base address here. */
5691 if ((range_beginning & mask) == mask)
5692 {
5693 /* If we found the largest possible address, then
5694 read the base address. */
5695 base = read_address (obfd, buffer + addr_size, cu, &dummy);
5696 found_base = 1;
5697 continue;
5698 }
5699
5700 if (!found_base)
5701 {
5702 /* We have no valid base address for the ranges
5703 data. */
5704 complaint (&symfile_complaints,
5705 _("Invalid .debug_ranges data (no base address)"));
5706 return 0;
5707 }
5708
5709 range_beginning += base;
5710 range_end += base;
5711
5712 if (ranges_pst != NULL && range_beginning < range_end)
5713 addrmap_set_empty (objfile->psymtabs_addrmap,
5714 range_beginning + baseaddr, range_end - 1 + baseaddr,
5715 ranges_pst);
5716
5717 /* FIXME: This is recording everything as a low-high
5718 segment of consecutive addresses. We should have a
5719 data structure for discontiguous block ranges
5720 instead. */
5721 if (! low_set)
5722 {
5723 low = range_beginning;
5724 high = range_end;
5725 low_set = 1;
5726 }
5727 else
5728 {
5729 if (range_beginning < low)
5730 low = range_beginning;
5731 if (range_end > high)
5732 high = range_end;
5733 }
5734 }
5735
5736 if (! low_set)
5737 /* If the first entry is an end-of-list marker, the range
5738 describes an empty scope, i.e. no instructions. */
5739 return 0;
5740
5741 if (low_return)
5742 *low_return = low;
5743 if (high_return)
5744 *high_return = high;
5745 return 1;
5746 }
5747
5748 /* Get low and high pc attributes from a die. Return 1 if the attributes
5749 are present and valid, otherwise, return 0. Return -1 if the range is
5750 discontinuous, i.e. derived from DW_AT_ranges information. */
5751 static int
5752 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
5753 CORE_ADDR *highpc, struct dwarf2_cu *cu,
5754 struct partial_symtab *pst)
5755 {
5756 struct attribute *attr;
5757 CORE_ADDR low = 0;
5758 CORE_ADDR high = 0;
5759 int ret = 0;
5760
5761 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
5762 if (attr)
5763 {
5764 high = DW_ADDR (attr);
5765 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
5766 if (attr)
5767 low = DW_ADDR (attr);
5768 else
5769 /* Found high w/o low attribute. */
5770 return 0;
5771
5772 /* Found consecutive range of addresses. */
5773 ret = 1;
5774 }
5775 else
5776 {
5777 attr = dwarf2_attr (die, DW_AT_ranges, cu);
5778 if (attr != NULL)
5779 {
5780 /* Value of the DW_AT_ranges attribute is the offset in the
5781 .debug_ranges section. */
5782 if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst))
5783 return 0;
5784 /* Found discontinuous range of addresses. */
5785 ret = -1;
5786 }
5787 }
5788
5789 if (high < low)
5790 return 0;
5791
5792 /* When using the GNU linker, .gnu.linkonce. sections are used to
5793 eliminate duplicate copies of functions and vtables and such.
5794 The linker will arbitrarily choose one and discard the others.
5795 The AT_*_pc values for such functions refer to local labels in
5796 these sections. If the section from that file was discarded, the
5797 labels are not in the output, so the relocs get a value of 0.
5798 If this is a discarded function, mark the pc bounds as invalid,
5799 so that GDB will ignore it. */
5800 if (low == 0 && !dwarf2_per_objfile->has_section_at_zero)
5801 return 0;
5802
5803 *lowpc = low;
5804 *highpc = high;
5805 return ret;
5806 }
5807
5808 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
5809 its low and high PC addresses. Do nothing if these addresses could not
5810 be determined. Otherwise, set LOWPC to the low address if it is smaller,
5811 and HIGHPC to the high address if greater than HIGHPC. */
5812
5813 static void
5814 dwarf2_get_subprogram_pc_bounds (struct die_info *die,
5815 CORE_ADDR *lowpc, CORE_ADDR *highpc,
5816 struct dwarf2_cu *cu)
5817 {
5818 CORE_ADDR low, high;
5819 struct die_info *child = die->child;
5820
5821 if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL))
5822 {
5823 *lowpc = min (*lowpc, low);
5824 *highpc = max (*highpc, high);
5825 }
5826
5827 /* If the language does not allow nested subprograms (either inside
5828 subprograms or lexical blocks), we're done. */
5829 if (cu->language != language_ada)
5830 return;
5831
5832 /* Check all the children of the given DIE. If it contains nested
5833 subprograms, then check their pc bounds. Likewise, we need to
5834 check lexical blocks as well, as they may also contain subprogram
5835 definitions. */
5836 while (child && child->tag)
5837 {
5838 if (child->tag == DW_TAG_subprogram
5839 || child->tag == DW_TAG_lexical_block)
5840 dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu);
5841 child = sibling_die (child);
5842 }
5843 }
5844
5845 /* Get the low and high pc's represented by the scope DIE, and store
5846 them in *LOWPC and *HIGHPC. If the correct values can't be
5847 determined, set *LOWPC to -1 and *HIGHPC to 0. */
5848
5849 static void
5850 get_scope_pc_bounds (struct die_info *die,
5851 CORE_ADDR *lowpc, CORE_ADDR *highpc,
5852 struct dwarf2_cu *cu)
5853 {
5854 CORE_ADDR best_low = (CORE_ADDR) -1;
5855 CORE_ADDR best_high = (CORE_ADDR) 0;
5856 CORE_ADDR current_low, current_high;
5857
5858 if (dwarf2_get_pc_bounds (die, &current_low, &current_high, cu, NULL))
5859 {
5860 best_low = current_low;
5861 best_high = current_high;
5862 }
5863 else
5864 {
5865 struct die_info *child = die->child;
5866
5867 while (child && child->tag)
5868 {
5869 switch (child->tag) {
5870 case DW_TAG_subprogram:
5871 dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu);
5872 break;
5873 case DW_TAG_namespace:
5874 case DW_TAG_module:
5875 /* FIXME: carlton/2004-01-16: Should we do this for
5876 DW_TAG_class_type/DW_TAG_structure_type, too? I think
5877 that current GCC's always emit the DIEs corresponding
5878 to definitions of methods of classes as children of a
5879 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
5880 the DIEs giving the declarations, which could be
5881 anywhere). But I don't see any reason why the
5882 standards says that they have to be there. */
5883 get_scope_pc_bounds (child, &current_low, &current_high, cu);
5884
5885 if (current_low != ((CORE_ADDR) -1))
5886 {
5887 best_low = min (best_low, current_low);
5888 best_high = max (best_high, current_high);
5889 }
5890 break;
5891 default:
5892 /* Ignore. */
5893 break;
5894 }
5895
5896 child = sibling_die (child);
5897 }
5898 }
5899
5900 *lowpc = best_low;
5901 *highpc = best_high;
5902 }
5903
5904 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
5905 in DIE. */
5906 static void
5907 dwarf2_record_block_ranges (struct die_info *die, struct block *block,
5908 CORE_ADDR baseaddr, struct dwarf2_cu *cu)
5909 {
5910 struct attribute *attr;
5911
5912 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
5913 if (attr)
5914 {
5915 CORE_ADDR high = DW_ADDR (attr);
5916
5917 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
5918 if (attr)
5919 {
5920 CORE_ADDR low = DW_ADDR (attr);
5921
5922 record_block_range (block, baseaddr + low, baseaddr + high - 1);
5923 }
5924 }
5925
5926 attr = dwarf2_attr (die, DW_AT_ranges, cu);
5927 if (attr)
5928 {
5929 bfd *obfd = cu->objfile->obfd;
5930
5931 /* The value of the DW_AT_ranges attribute is the offset of the
5932 address range list in the .debug_ranges section. */
5933 unsigned long offset = DW_UNSND (attr);
5934 gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset;
5935
5936 /* For some target architectures, but not others, the
5937 read_address function sign-extends the addresses it returns.
5938 To recognize base address selection entries, we need a
5939 mask. */
5940 unsigned int addr_size = cu->header.addr_size;
5941 CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
5942
5943 /* The base address, to which the next pair is relative. Note
5944 that this 'base' is a DWARF concept: most entries in a range
5945 list are relative, to reduce the number of relocs against the
5946 debugging information. This is separate from this function's
5947 'baseaddr' argument, which GDB uses to relocate debugging
5948 information from a shared library based on the address at
5949 which the library was loaded. */
5950 CORE_ADDR base = cu->base_address;
5951 int base_known = cu->base_known;
5952
5953 gdb_assert (dwarf2_per_objfile->ranges.readin);
5954 if (offset >= dwarf2_per_objfile->ranges.size)
5955 {
5956 complaint (&symfile_complaints,
5957 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
5958 offset);
5959 return;
5960 }
5961
5962 for (;;)
5963 {
5964 unsigned int bytes_read;
5965 CORE_ADDR start, end;
5966
5967 start = read_address (obfd, buffer, cu, &bytes_read);
5968 buffer += bytes_read;
5969 end = read_address (obfd, buffer, cu, &bytes_read);
5970 buffer += bytes_read;
5971
5972 /* Did we find the end of the range list? */
5973 if (start == 0 && end == 0)
5974 break;
5975
5976 /* Did we find a base address selection entry? */
5977 else if ((start & base_select_mask) == base_select_mask)
5978 {
5979 base = end;
5980 base_known = 1;
5981 }
5982
5983 /* We found an ordinary address range. */
5984 else
5985 {
5986 if (!base_known)
5987 {
5988 complaint (&symfile_complaints,
5989 _("Invalid .debug_ranges data (no base address)"));
5990 return;
5991 }
5992
5993 record_block_range (block,
5994 baseaddr + base + start,
5995 baseaddr + base + end - 1);
5996 }
5997 }
5998 }
5999 }
6000
6001 /* Add an aggregate field to the field list. */
6002
6003 static void
6004 dwarf2_add_field (struct field_info *fip, struct die_info *die,
6005 struct dwarf2_cu *cu)
6006 {
6007 struct objfile *objfile = cu->objfile;
6008 struct gdbarch *gdbarch = get_objfile_arch (objfile);
6009 struct nextfield *new_field;
6010 struct attribute *attr;
6011 struct field *fp;
6012 char *fieldname = "";
6013
6014 /* Allocate a new field list entry and link it in. */
6015 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
6016 make_cleanup (xfree, new_field);
6017 memset (new_field, 0, sizeof (struct nextfield));
6018
6019 if (die->tag == DW_TAG_inheritance)
6020 {
6021 new_field->next = fip->baseclasses;
6022 fip->baseclasses = new_field;
6023 }
6024 else
6025 {
6026 new_field->next = fip->fields;
6027 fip->fields = new_field;
6028 }
6029 fip->nfields++;
6030
6031 /* Handle accessibility and virtuality of field.
6032 The default accessibility for members is public, the default
6033 accessibility for inheritance is private. */
6034 if (die->tag != DW_TAG_inheritance)
6035 new_field->accessibility = DW_ACCESS_public;
6036 else
6037 new_field->accessibility = DW_ACCESS_private;
6038 new_field->virtuality = DW_VIRTUALITY_none;
6039
6040 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
6041 if (attr)
6042 new_field->accessibility = DW_UNSND (attr);
6043 if (new_field->accessibility != DW_ACCESS_public)
6044 fip->non_public_fields = 1;
6045 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
6046 if (attr)
6047 new_field->virtuality = DW_UNSND (attr);
6048
6049 fp = &new_field->field;
6050
6051 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
6052 {
6053 /* Data member other than a C++ static data member. */
6054
6055 /* Get type of field. */
6056 fp->type = die_type (die, cu);
6057
6058 SET_FIELD_BITPOS (*fp, 0);
6059
6060 /* Get bit size of field (zero if none). */
6061 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
6062 if (attr)
6063 {
6064 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
6065 }
6066 else
6067 {
6068 FIELD_BITSIZE (*fp) = 0;
6069 }
6070
6071 /* Get bit offset of field. */
6072 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
6073 if (attr)
6074 {
6075 int byte_offset = 0;
6076
6077 if (attr_form_is_section_offset (attr))
6078 dwarf2_complex_location_expr_complaint ();
6079 else if (attr_form_is_constant (attr))
6080 byte_offset = dwarf2_get_attr_constant_value (attr, 0);
6081 else if (attr_form_is_block (attr))
6082 byte_offset = decode_locdesc (DW_BLOCK (attr), cu);
6083 else
6084 dwarf2_complex_location_expr_complaint ();
6085
6086 SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte);
6087 }
6088 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
6089 if (attr)
6090 {
6091 if (gdbarch_bits_big_endian (gdbarch))
6092 {
6093 /* For big endian bits, the DW_AT_bit_offset gives the
6094 additional bit offset from the MSB of the containing
6095 anonymous object to the MSB of the field. We don't
6096 have to do anything special since we don't need to
6097 know the size of the anonymous object. */
6098 FIELD_BITPOS (*fp) += DW_UNSND (attr);
6099 }
6100 else
6101 {
6102 /* For little endian bits, compute the bit offset to the
6103 MSB of the anonymous object, subtract off the number of
6104 bits from the MSB of the field to the MSB of the
6105 object, and then subtract off the number of bits of
6106 the field itself. The result is the bit offset of
6107 the LSB of the field. */
6108 int anonymous_size;
6109 int bit_offset = DW_UNSND (attr);
6110
6111 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
6112 if (attr)
6113 {
6114 /* The size of the anonymous object containing
6115 the bit field is explicit, so use the
6116 indicated size (in bytes). */
6117 anonymous_size = DW_UNSND (attr);
6118 }
6119 else
6120 {
6121 /* The size of the anonymous object containing
6122 the bit field must be inferred from the type
6123 attribute of the data member containing the
6124 bit field. */
6125 anonymous_size = TYPE_LENGTH (fp->type);
6126 }
6127 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
6128 - bit_offset - FIELD_BITSIZE (*fp);
6129 }
6130 }
6131
6132 /* Get name of field. */
6133 fieldname = dwarf2_name (die, cu);
6134 if (fieldname == NULL)
6135 fieldname = "";
6136
6137 /* The name is already allocated along with this objfile, so we don't
6138 need to duplicate it for the type. */
6139 fp->name = fieldname;
6140
6141 /* Change accessibility for artificial fields (e.g. virtual table
6142 pointer or virtual base class pointer) to private. */
6143 if (dwarf2_attr (die, DW_AT_artificial, cu))
6144 {
6145 FIELD_ARTIFICIAL (*fp) = 1;
6146 new_field->accessibility = DW_ACCESS_private;
6147 fip->non_public_fields = 1;
6148 }
6149 }
6150 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
6151 {
6152 /* C++ static member. */
6153
6154 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6155 is a declaration, but all versions of G++ as of this writing
6156 (so through at least 3.2.1) incorrectly generate
6157 DW_TAG_variable tags. */
6158
6159 char *physname;
6160
6161 /* Get name of field. */
6162 fieldname = dwarf2_name (die, cu);
6163 if (fieldname == NULL)
6164 return;
6165
6166 attr = dwarf2_attr (die, DW_AT_const_value, cu);
6167 if (attr
6168 /* Only create a symbol if this is an external value.
6169 new_symbol checks this and puts the value in the global symbol
6170 table, which we want. If it is not external, new_symbol
6171 will try to put the value in cu->list_in_scope which is wrong. */
6172 && dwarf2_flag_true_p (die, DW_AT_external, cu))
6173 {
6174 /* A static const member, not much different than an enum as far as
6175 we're concerned, except that we can support more types. */
6176 new_symbol (die, NULL, cu);
6177 }
6178
6179 /* Get physical name. */
6180 physname = (char *) dwarf2_physname (fieldname, die, cu);
6181
6182 /* The name is already allocated along with this objfile, so we don't
6183 need to duplicate it for the type. */
6184 SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
6185 FIELD_TYPE (*fp) = die_type (die, cu);
6186 FIELD_NAME (*fp) = fieldname;
6187 }
6188 else if (die->tag == DW_TAG_inheritance)
6189 {
6190 /* C++ base class field. */
6191 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
6192 if (attr)
6193 {
6194 int byte_offset = 0;
6195
6196 if (attr_form_is_section_offset (attr))
6197 dwarf2_complex_location_expr_complaint ();
6198 else if (attr_form_is_constant (attr))
6199 byte_offset = dwarf2_get_attr_constant_value (attr, 0);
6200 else if (attr_form_is_block (attr))
6201 byte_offset = decode_locdesc (DW_BLOCK (attr), cu);
6202 else
6203 dwarf2_complex_location_expr_complaint ();
6204
6205 SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte);
6206 }
6207 FIELD_BITSIZE (*fp) = 0;
6208 FIELD_TYPE (*fp) = die_type (die, cu);
6209 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
6210 fip->nbaseclasses++;
6211 }
6212 }
6213
6214 /* Add a typedef defined in the scope of the FIP's class. */
6215
6216 static void
6217 dwarf2_add_typedef (struct field_info *fip, struct die_info *die,
6218 struct dwarf2_cu *cu)
6219 {
6220 struct objfile *objfile = cu->objfile;
6221 struct gdbarch *gdbarch = get_objfile_arch (objfile);
6222 struct typedef_field_list *new_field;
6223 struct attribute *attr;
6224 struct typedef_field *fp;
6225 char *fieldname = "";
6226
6227 /* Allocate a new field list entry and link it in. */
6228 new_field = xzalloc (sizeof (*new_field));
6229 make_cleanup (xfree, new_field);
6230
6231 gdb_assert (die->tag == DW_TAG_typedef);
6232
6233 fp = &new_field->field;
6234
6235 /* Get name of field. */
6236 fp->name = dwarf2_name (die, cu);
6237 if (fp->name == NULL)
6238 return;
6239
6240 fp->type = read_type_die (die, cu);
6241
6242 new_field->next = fip->typedef_field_list;
6243 fip->typedef_field_list = new_field;
6244 fip->typedef_field_list_count++;
6245 }
6246
6247 /* Create the vector of fields, and attach it to the type. */
6248
6249 static void
6250 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
6251 struct dwarf2_cu *cu)
6252 {
6253 int nfields = fip->nfields;
6254
6255 /* Record the field count, allocate space for the array of fields,
6256 and create blank accessibility bitfields if necessary. */
6257 TYPE_NFIELDS (type) = nfields;
6258 TYPE_FIELDS (type) = (struct field *)
6259 TYPE_ALLOC (type, sizeof (struct field) * nfields);
6260 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
6261
6262 if (fip->non_public_fields && cu->language != language_ada)
6263 {
6264 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6265
6266 TYPE_FIELD_PRIVATE_BITS (type) =
6267 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
6268 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
6269
6270 TYPE_FIELD_PROTECTED_BITS (type) =
6271 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
6272 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
6273
6274 /* We don't set TYPE_FIELD_IGNORE_BITS here. The DWARF reader
6275 never sets any bits in that array, so leaving it NULL lets us
6276 save a little memory. */
6277 }
6278
6279 /* If the type has baseclasses, allocate and clear a bit vector for
6280 TYPE_FIELD_VIRTUAL_BITS. */
6281 if (fip->nbaseclasses && cu->language != language_ada)
6282 {
6283 int num_bytes = B_BYTES (fip->nbaseclasses);
6284 unsigned char *pointer;
6285
6286 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6287 pointer = TYPE_ALLOC (type, num_bytes);
6288 TYPE_FIELD_VIRTUAL_BITS (type) = pointer;
6289 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
6290 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
6291 }
6292
6293 /* Copy the saved-up fields into the field vector. Start from the head
6294 of the list, adding to the tail of the field array, so that they end
6295 up in the same order in the array in which they were added to the list. */
6296 while (nfields-- > 0)
6297 {
6298 struct nextfield *fieldp;
6299
6300 if (fip->fields)
6301 {
6302 fieldp = fip->fields;
6303 fip->fields = fieldp->next;
6304 }
6305 else
6306 {
6307 fieldp = fip->baseclasses;
6308 fip->baseclasses = fieldp->next;
6309 }
6310
6311 TYPE_FIELD (type, nfields) = fieldp->field;
6312 switch (fieldp->accessibility)
6313 {
6314 case DW_ACCESS_private:
6315 if (cu->language != language_ada)
6316 SET_TYPE_FIELD_PRIVATE (type, nfields);
6317 break;
6318
6319 case DW_ACCESS_protected:
6320 if (cu->language != language_ada)
6321 SET_TYPE_FIELD_PROTECTED (type, nfields);
6322 break;
6323
6324 case DW_ACCESS_public:
6325 break;
6326
6327 default:
6328 /* Unknown accessibility. Complain and treat it as public. */
6329 {
6330 complaint (&symfile_complaints, _("unsupported accessibility %d"),
6331 fieldp->accessibility);
6332 }
6333 break;
6334 }
6335 if (nfields < fip->nbaseclasses)
6336 {
6337 switch (fieldp->virtuality)
6338 {
6339 case DW_VIRTUALITY_virtual:
6340 case DW_VIRTUALITY_pure_virtual:
6341 if (cu->language == language_ada)
6342 error ("unexpected virtuality in component of Ada type");
6343 SET_TYPE_FIELD_VIRTUAL (type, nfields);
6344 break;
6345 }
6346 }
6347 }
6348 }
6349
6350 /* Add a member function to the proper fieldlist. */
6351
6352 static void
6353 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
6354 struct type *type, struct dwarf2_cu *cu)
6355 {
6356 struct objfile *objfile = cu->objfile;
6357 struct attribute *attr;
6358 struct fnfieldlist *flp;
6359 int i;
6360 struct fn_field *fnp;
6361 char *fieldname;
6362 struct nextfnfield *new_fnfield;
6363 struct type *this_type;
6364
6365 if (cu->language == language_ada)
6366 error ("unexpected member function in Ada type");
6367
6368 /* Get name of member function. */
6369 fieldname = dwarf2_name (die, cu);
6370 if (fieldname == NULL)
6371 return;
6372
6373 /* Look up member function name in fieldlist. */
6374 for (i = 0; i < fip->nfnfields; i++)
6375 {
6376 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
6377 break;
6378 }
6379
6380 /* Create new list element if necessary. */
6381 if (i < fip->nfnfields)
6382 flp = &fip->fnfieldlists[i];
6383 else
6384 {
6385 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
6386 {
6387 fip->fnfieldlists = (struct fnfieldlist *)
6388 xrealloc (fip->fnfieldlists,
6389 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
6390 * sizeof (struct fnfieldlist));
6391 if (fip->nfnfields == 0)
6392 make_cleanup (free_current_contents, &fip->fnfieldlists);
6393 }
6394 flp = &fip->fnfieldlists[fip->nfnfields];
6395 flp->name = fieldname;
6396 flp->length = 0;
6397 flp->head = NULL;
6398 i = fip->nfnfields++;
6399 }
6400
6401 /* Create a new member function field and chain it to the field list
6402 entry. */
6403 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
6404 make_cleanup (xfree, new_fnfield);
6405 memset (new_fnfield, 0, sizeof (struct nextfnfield));
6406 new_fnfield->next = flp->head;
6407 flp->head = new_fnfield;
6408 flp->length++;
6409
6410 /* Fill in the member function field info. */
6411 fnp = &new_fnfield->fnfield;
6412
6413 /* Delay processing of the physname until later. */
6414 if (cu->language == language_cplus || cu->language == language_java)
6415 {
6416 add_to_method_list (type, i, flp->length - 1, fieldname,
6417 die, cu);
6418 }
6419 else
6420 {
6421 char *physname = (char *) dwarf2_physname (fieldname, die, cu);
6422 fnp->physname = physname ? physname : "";
6423 }
6424
6425 fnp->type = alloc_type (objfile);
6426 this_type = read_type_die (die, cu);
6427 if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC)
6428 {
6429 int nparams = TYPE_NFIELDS (this_type);
6430
6431 /* TYPE is the domain of this method, and THIS_TYPE is the type
6432 of the method itself (TYPE_CODE_METHOD). */
6433 smash_to_method_type (fnp->type, type,
6434 TYPE_TARGET_TYPE (this_type),
6435 TYPE_FIELDS (this_type),
6436 TYPE_NFIELDS (this_type),
6437 TYPE_VARARGS (this_type));
6438
6439 /* Handle static member functions.
6440 Dwarf2 has no clean way to discern C++ static and non-static
6441 member functions. G++ helps GDB by marking the first
6442 parameter for non-static member functions (which is the
6443 this pointer) as artificial. We obtain this information
6444 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
6445 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0)
6446 fnp->voffset = VOFFSET_STATIC;
6447 }
6448 else
6449 complaint (&symfile_complaints, _("member function type missing for '%s'"),
6450 dwarf2_full_name (fieldname, die, cu));
6451
6452 /* Get fcontext from DW_AT_containing_type if present. */
6453 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
6454 fnp->fcontext = die_containing_type (die, cu);
6455
6456 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
6457 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
6458
6459 /* Get accessibility. */
6460 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
6461 if (attr)
6462 {
6463 switch (DW_UNSND (attr))
6464 {
6465 case DW_ACCESS_private:
6466 fnp->is_private = 1;
6467 break;
6468 case DW_ACCESS_protected:
6469 fnp->is_protected = 1;
6470 break;
6471 }
6472 }
6473
6474 /* Check for artificial methods. */
6475 attr = dwarf2_attr (die, DW_AT_artificial, cu);
6476 if (attr && DW_UNSND (attr) != 0)
6477 fnp->is_artificial = 1;
6478
6479 /* Get index in virtual function table if it is a virtual member
6480 function. For older versions of GCC, this is an offset in the
6481 appropriate virtual table, as specified by DW_AT_containing_type.
6482 For everyone else, it is an expression to be evaluated relative
6483 to the object address. */
6484
6485 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
6486 if (attr)
6487 {
6488 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0)
6489 {
6490 if (DW_BLOCK (attr)->data[0] == DW_OP_constu)
6491 {
6492 /* Old-style GCC. */
6493 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
6494 }
6495 else if (DW_BLOCK (attr)->data[0] == DW_OP_deref
6496 || (DW_BLOCK (attr)->size > 1
6497 && DW_BLOCK (attr)->data[0] == DW_OP_deref_size
6498 && DW_BLOCK (attr)->data[1] == cu->header.addr_size))
6499 {
6500 struct dwarf_block blk;
6501 int offset;
6502
6503 offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref
6504 ? 1 : 2);
6505 blk.size = DW_BLOCK (attr)->size - offset;
6506 blk.data = DW_BLOCK (attr)->data + offset;
6507 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu);
6508 if ((fnp->voffset % cu->header.addr_size) != 0)
6509 dwarf2_complex_location_expr_complaint ();
6510 else
6511 fnp->voffset /= cu->header.addr_size;
6512 fnp->voffset += 2;
6513 }
6514 else
6515 dwarf2_complex_location_expr_complaint ();
6516
6517 if (!fnp->fcontext)
6518 fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0));
6519 }
6520 else if (attr_form_is_section_offset (attr))
6521 {
6522 dwarf2_complex_location_expr_complaint ();
6523 }
6524 else
6525 {
6526 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
6527 fieldname);
6528 }
6529 }
6530 else
6531 {
6532 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
6533 if (attr && DW_UNSND (attr))
6534 {
6535 /* GCC does this, as of 2008-08-25; PR debug/37237. */
6536 complaint (&symfile_complaints,
6537 _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
6538 fieldname, die->offset);
6539 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6540 TYPE_CPLUS_DYNAMIC (type) = 1;
6541 }
6542 }
6543 }
6544
6545 /* Create the vector of member function fields, and attach it to the type. */
6546
6547 static void
6548 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
6549 struct dwarf2_cu *cu)
6550 {
6551 struct fnfieldlist *flp;
6552 int total_length = 0;
6553 int i;
6554
6555 if (cu->language == language_ada)
6556 error ("unexpected member functions in Ada type");
6557
6558 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6559 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
6560 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
6561
6562 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
6563 {
6564 struct nextfnfield *nfp = flp->head;
6565 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
6566 int k;
6567
6568 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
6569 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
6570 fn_flp->fn_fields = (struct fn_field *)
6571 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
6572 for (k = flp->length; (k--, nfp); nfp = nfp->next)
6573 fn_flp->fn_fields[k] = nfp->fnfield;
6574
6575 total_length += flp->length;
6576 }
6577
6578 TYPE_NFN_FIELDS (type) = fip->nfnfields;
6579 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
6580 }
6581
6582 /* Returns non-zero if NAME is the name of a vtable member in CU's
6583 language, zero otherwise. */
6584 static int
6585 is_vtable_name (const char *name, struct dwarf2_cu *cu)
6586 {
6587 static const char vptr[] = "_vptr";
6588 static const char vtable[] = "vtable";
6589
6590 /* Look for the C++ and Java forms of the vtable. */
6591 if ((cu->language == language_java
6592 && strncmp (name, vtable, sizeof (vtable) - 1) == 0)
6593 || (strncmp (name, vptr, sizeof (vptr) - 1) == 0
6594 && is_cplus_marker (name[sizeof (vptr) - 1])))
6595 return 1;
6596
6597 return 0;
6598 }
6599
6600 /* GCC outputs unnamed structures that are really pointers to member
6601 functions, with the ABI-specified layout. If TYPE describes
6602 such a structure, smash it into a member function type.
6603
6604 GCC shouldn't do this; it should just output pointer to member DIEs.
6605 This is GCC PR debug/28767. */
6606
6607 static void
6608 quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
6609 {
6610 struct type *pfn_type, *domain_type, *new_type;
6611
6612 /* Check for a structure with no name and two children. */
6613 if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2)
6614 return;
6615
6616 /* Check for __pfn and __delta members. */
6617 if (TYPE_FIELD_NAME (type, 0) == NULL
6618 || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0
6619 || TYPE_FIELD_NAME (type, 1) == NULL
6620 || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0)
6621 return;
6622
6623 /* Find the type of the method. */
6624 pfn_type = TYPE_FIELD_TYPE (type, 0);
6625 if (pfn_type == NULL
6626 || TYPE_CODE (pfn_type) != TYPE_CODE_PTR
6627 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC)
6628 return;
6629
6630 /* Look for the "this" argument. */
6631 pfn_type = TYPE_TARGET_TYPE (pfn_type);
6632 if (TYPE_NFIELDS (pfn_type) == 0
6633 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
6634 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR)
6635 return;
6636
6637 domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
6638 new_type = alloc_type (objfile);
6639 smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type),
6640 TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type),
6641 TYPE_VARARGS (pfn_type));
6642 smash_to_methodptr_type (type, new_type);
6643 }
6644
6645 /* Called when we find the DIE that starts a structure or union scope
6646 (definition) to process all dies that define the members of the
6647 structure or union.
6648
6649 NOTE: we need to call struct_type regardless of whether or not the
6650 DIE has an at_name attribute, since it might be an anonymous
6651 structure or union. This gets the type entered into our set of
6652 user defined types.
6653
6654 However, if the structure is incomplete (an opaque struct/union)
6655 then suppress creating a symbol table entry for it since gdb only
6656 wants to find the one with the complete definition. Note that if
6657 it is complete, we just call new_symbol, which does it's own
6658 checking about whether the struct/union is anonymous or not (and
6659 suppresses creating a symbol table entry itself). */
6660
6661 static struct type *
6662 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
6663 {
6664 struct objfile *objfile = cu->objfile;
6665 struct type *type;
6666 struct attribute *attr;
6667 char *name;
6668 struct cleanup *back_to;
6669
6670 /* If the definition of this type lives in .debug_types, read that type.
6671 Don't follow DW_AT_specification though, that will take us back up
6672 the chain and we want to go down. */
6673 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
6674 if (attr)
6675 {
6676 struct dwarf2_cu *type_cu = cu;
6677 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
6678
6679 /* We could just recurse on read_structure_type, but we need to call
6680 get_die_type to ensure only one type for this DIE is created.
6681 This is important, for example, because for c++ classes we need
6682 TYPE_NAME set which is only done by new_symbol. Blech. */
6683 type = read_type_die (type_die, type_cu);
6684
6685 /* TYPE_CU may not be the same as CU.
6686 Ensure TYPE is recorded in CU's type_hash table. */
6687 return set_die_type (die, type, cu);
6688 }
6689
6690 back_to = make_cleanup (null_cleanup, 0);
6691
6692 type = alloc_type (objfile);
6693 INIT_CPLUS_SPECIFIC (type);
6694
6695 name = dwarf2_name (die, cu);
6696 if (name != NULL)
6697 {
6698 if (cu->language == language_cplus
6699 || cu->language == language_java)
6700 {
6701 char *full_name = (char *) dwarf2_full_name (name, die, cu);
6702
6703 /* dwarf2_full_name might have already finished building the DIE's
6704 type. If so, there is no need to continue. */
6705 if (get_die_type (die, cu) != NULL)
6706 return get_die_type (die, cu);
6707
6708 TYPE_TAG_NAME (type) = full_name;
6709 if (die->tag == DW_TAG_structure_type
6710 || die->tag == DW_TAG_class_type)
6711 TYPE_NAME (type) = TYPE_TAG_NAME (type);
6712 }
6713 else
6714 {
6715 /* The name is already allocated along with this objfile, so
6716 we don't need to duplicate it for the type. */
6717 TYPE_TAG_NAME (type) = (char *) name;
6718 if (die->tag == DW_TAG_class_type)
6719 TYPE_NAME (type) = TYPE_TAG_NAME (type);
6720 }
6721 }
6722
6723 if (die->tag == DW_TAG_structure_type)
6724 {
6725 TYPE_CODE (type) = TYPE_CODE_STRUCT;
6726 }
6727 else if (die->tag == DW_TAG_union_type)
6728 {
6729 TYPE_CODE (type) = TYPE_CODE_UNION;
6730 }
6731 else
6732 {
6733 TYPE_CODE (type) = TYPE_CODE_CLASS;
6734 }
6735
6736 if (cu->language == language_cplus && die->tag == DW_TAG_class_type)
6737 TYPE_DECLARED_CLASS (type) = 1;
6738
6739 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
6740 if (attr)
6741 {
6742 TYPE_LENGTH (type) = DW_UNSND (attr);
6743 }
6744 else
6745 {
6746 TYPE_LENGTH (type) = 0;
6747 }
6748
6749 TYPE_STUB_SUPPORTED (type) = 1;
6750 if (die_is_declaration (die, cu))
6751 TYPE_STUB (type) = 1;
6752 else if (attr == NULL && die->child == NULL
6753 && producer_is_realview (cu->producer))
6754 /* RealView does not output the required DW_AT_declaration
6755 on incomplete types. */
6756 TYPE_STUB (type) = 1;
6757
6758 /* We need to add the type field to the die immediately so we don't
6759 infinitely recurse when dealing with pointers to the structure
6760 type within the structure itself. */
6761 set_die_type (die, type, cu);
6762
6763 /* set_die_type should be already done. */
6764 set_descriptive_type (type, die, cu);
6765
6766 if (die->child != NULL && ! die_is_declaration (die, cu))
6767 {
6768 struct field_info fi;
6769 struct die_info *child_die;
6770 VEC (symbolp) *template_args = NULL;
6771
6772 memset (&fi, 0, sizeof (struct field_info));
6773
6774 child_die = die->child;
6775
6776 while (child_die && child_die->tag)
6777 {
6778 if (child_die->tag == DW_TAG_member
6779 || child_die->tag == DW_TAG_variable)
6780 {
6781 /* NOTE: carlton/2002-11-05: A C++ static data member
6782 should be a DW_TAG_member that is a declaration, but
6783 all versions of G++ as of this writing (so through at
6784 least 3.2.1) incorrectly generate DW_TAG_variable
6785 tags for them instead. */
6786 dwarf2_add_field (&fi, child_die, cu);
6787 }
6788 else if (child_die->tag == DW_TAG_subprogram)
6789 {
6790 /* C++ member function. */
6791 dwarf2_add_member_fn (&fi, child_die, type, cu);
6792 }
6793 else if (child_die->tag == DW_TAG_inheritance)
6794 {
6795 /* C++ base class field. */
6796 dwarf2_add_field (&fi, child_die, cu);
6797 }
6798 else if (child_die->tag == DW_TAG_typedef)
6799 dwarf2_add_typedef (&fi, child_die, cu);
6800 else if (child_die->tag == DW_TAG_template_type_param
6801 || child_die->tag == DW_TAG_template_value_param)
6802 {
6803 struct symbol *arg = new_symbol (child_die, NULL, cu);
6804
6805 VEC_safe_push (symbolp, template_args, arg);
6806 }
6807
6808 child_die = sibling_die (child_die);
6809 }
6810
6811 /* Attach template arguments to type. */
6812 if (! VEC_empty (symbolp, template_args))
6813 {
6814 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6815 TYPE_N_TEMPLATE_ARGUMENTS (type)
6816 = VEC_length (symbolp, template_args);
6817 TYPE_TEMPLATE_ARGUMENTS (type)
6818 = obstack_alloc (&objfile->objfile_obstack,
6819 (TYPE_N_TEMPLATE_ARGUMENTS (type)
6820 * sizeof (struct symbol *)));
6821 memcpy (TYPE_TEMPLATE_ARGUMENTS (type),
6822 VEC_address (symbolp, template_args),
6823 (TYPE_N_TEMPLATE_ARGUMENTS (type)
6824 * sizeof (struct symbol *)));
6825 VEC_free (symbolp, template_args);
6826 }
6827
6828 /* Attach fields and member functions to the type. */
6829 if (fi.nfields)
6830 dwarf2_attach_fields_to_type (&fi, type, cu);
6831 if (fi.nfnfields)
6832 {
6833 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
6834
6835 /* Get the type which refers to the base class (possibly this
6836 class itself) which contains the vtable pointer for the current
6837 class from the DW_AT_containing_type attribute. This use of
6838 DW_AT_containing_type is a GNU extension. */
6839
6840 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
6841 {
6842 struct type *t = die_containing_type (die, cu);
6843
6844 TYPE_VPTR_BASETYPE (type) = t;
6845 if (type == t)
6846 {
6847 int i;
6848
6849 /* Our own class provides vtbl ptr. */
6850 for (i = TYPE_NFIELDS (t) - 1;
6851 i >= TYPE_N_BASECLASSES (t);
6852 --i)
6853 {
6854 char *fieldname = TYPE_FIELD_NAME (t, i);
6855
6856 if (is_vtable_name (fieldname, cu))
6857 {
6858 TYPE_VPTR_FIELDNO (type) = i;
6859 break;
6860 }
6861 }
6862
6863 /* Complain if virtual function table field not found. */
6864 if (i < TYPE_N_BASECLASSES (t))
6865 complaint (&symfile_complaints,
6866 _("virtual function table pointer not found when defining class '%s'"),
6867 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
6868 "");
6869 }
6870 else
6871 {
6872 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
6873 }
6874 }
6875 else if (cu->producer
6876 && strncmp (cu->producer,
6877 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
6878 {
6879 /* The IBM XLC compiler does not provide direct indication
6880 of the containing type, but the vtable pointer is
6881 always named __vfp. */
6882
6883 int i;
6884
6885 for (i = TYPE_NFIELDS (type) - 1;
6886 i >= TYPE_N_BASECLASSES (type);
6887 --i)
6888 {
6889 if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0)
6890 {
6891 TYPE_VPTR_FIELDNO (type) = i;
6892 TYPE_VPTR_BASETYPE (type) = type;
6893 break;
6894 }
6895 }
6896 }
6897 }
6898
6899 /* Copy fi.typedef_field_list linked list elements content into the
6900 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
6901 if (fi.typedef_field_list)
6902 {
6903 int i = fi.typedef_field_list_count;
6904
6905 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6906 TYPE_TYPEDEF_FIELD_ARRAY (type)
6907 = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i);
6908 TYPE_TYPEDEF_FIELD_COUNT (type) = i;
6909
6910 /* Reverse the list order to keep the debug info elements order. */
6911 while (--i >= 0)
6912 {
6913 struct typedef_field *dest, *src;
6914
6915 dest = &TYPE_TYPEDEF_FIELD (type, i);
6916 src = &fi.typedef_field_list->field;
6917 fi.typedef_field_list = fi.typedef_field_list->next;
6918 *dest = *src;
6919 }
6920 }
6921 }
6922
6923 quirk_gcc_member_function_pointer (type, cu->objfile);
6924
6925 do_cleanups (back_to);
6926 return type;
6927 }
6928
6929 static void
6930 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
6931 {
6932 struct die_info *child_die = die->child;
6933 struct type *this_type;
6934
6935 this_type = get_die_type (die, cu);
6936 if (this_type == NULL)
6937 this_type = read_structure_type (die, cu);
6938
6939 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
6940 snapshots) has been known to create a die giving a declaration
6941 for a class that has, as a child, a die giving a definition for a
6942 nested class. So we have to process our children even if the
6943 current die is a declaration. Normally, of course, a declaration
6944 won't have any children at all. */
6945
6946 while (child_die != NULL && child_die->tag)
6947 {
6948 if (child_die->tag == DW_TAG_member
6949 || child_die->tag == DW_TAG_variable
6950 || child_die->tag == DW_TAG_inheritance
6951 || child_die->tag == DW_TAG_template_value_param
6952 || child_die->tag == DW_TAG_template_type_param)
6953 {
6954 /* Do nothing. */
6955 }
6956 else
6957 process_die (child_die, cu);
6958
6959 child_die = sibling_die (child_die);
6960 }
6961
6962 /* Do not consider external references. According to the DWARF standard,
6963 these DIEs are identified by the fact that they have no byte_size
6964 attribute, and a declaration attribute. */
6965 if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL
6966 || !die_is_declaration (die, cu))
6967 new_symbol (die, this_type, cu);
6968 }
6969
6970 /* Given a DW_AT_enumeration_type die, set its type. We do not
6971 complete the type's fields yet, or create any symbols. */
6972
6973 static struct type *
6974 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
6975 {
6976 struct objfile *objfile = cu->objfile;
6977 struct type *type;
6978 struct attribute *attr;
6979 const char *name;
6980
6981 /* If the definition of this type lives in .debug_types, read that type.
6982 Don't follow DW_AT_specification though, that will take us back up
6983 the chain and we want to go down. */
6984 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
6985 if (attr)
6986 {
6987 struct dwarf2_cu *type_cu = cu;
6988 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
6989
6990 type = read_type_die (type_die, type_cu);
6991
6992 /* TYPE_CU may not be the same as CU.
6993 Ensure TYPE is recorded in CU's type_hash table. */
6994 return set_die_type (die, type, cu);
6995 }
6996
6997 type = alloc_type (objfile);
6998
6999 TYPE_CODE (type) = TYPE_CODE_ENUM;
7000 name = dwarf2_full_name (NULL, die, cu);
7001 if (name != NULL)
7002 TYPE_TAG_NAME (type) = (char *) name;
7003
7004 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7005 if (attr)
7006 {
7007 TYPE_LENGTH (type) = DW_UNSND (attr);
7008 }
7009 else
7010 {
7011 TYPE_LENGTH (type) = 0;
7012 }
7013
7014 /* The enumeration DIE can be incomplete. In Ada, any type can be
7015 declared as private in the package spec, and then defined only
7016 inside the package body. Such types are known as Taft Amendment
7017 Types. When another package uses such a type, an incomplete DIE
7018 may be generated by the compiler. */
7019 if (die_is_declaration (die, cu))
7020 TYPE_STUB (type) = 1;
7021
7022 return set_die_type (die, type, cu);
7023 }
7024
7025 /* Given a pointer to a die which begins an enumeration, process all
7026 the dies that define the members of the enumeration, and create the
7027 symbol for the enumeration type.
7028
7029 NOTE: We reverse the order of the element list. */
7030
7031 static void
7032 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
7033 {
7034 struct type *this_type;
7035
7036 this_type = get_die_type (die, cu);
7037 if (this_type == NULL)
7038 this_type = read_enumeration_type (die, cu);
7039
7040 if (die->child != NULL)
7041 {
7042 struct die_info *child_die;
7043 struct symbol *sym;
7044 struct field *fields = NULL;
7045 int num_fields = 0;
7046 int unsigned_enum = 1;
7047 char *name;
7048
7049 child_die = die->child;
7050 while (child_die && child_die->tag)
7051 {
7052 if (child_die->tag != DW_TAG_enumerator)
7053 {
7054 process_die (child_die, cu);
7055 }
7056 else
7057 {
7058 name = dwarf2_name (child_die, cu);
7059 if (name)
7060 {
7061 sym = new_symbol (child_die, this_type, cu);
7062 if (SYMBOL_VALUE (sym) < 0)
7063 unsigned_enum = 0;
7064
7065 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
7066 {
7067 fields = (struct field *)
7068 xrealloc (fields,
7069 (num_fields + DW_FIELD_ALLOC_CHUNK)
7070 * sizeof (struct field));
7071 }
7072
7073 FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym);
7074 FIELD_TYPE (fields[num_fields]) = NULL;
7075 SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym));
7076 FIELD_BITSIZE (fields[num_fields]) = 0;
7077
7078 num_fields++;
7079 }
7080 }
7081
7082 child_die = sibling_die (child_die);
7083 }
7084
7085 if (num_fields)
7086 {
7087 TYPE_NFIELDS (this_type) = num_fields;
7088 TYPE_FIELDS (this_type) = (struct field *)
7089 TYPE_ALLOC (this_type, sizeof (struct field) * num_fields);
7090 memcpy (TYPE_FIELDS (this_type), fields,
7091 sizeof (struct field) * num_fields);
7092 xfree (fields);
7093 }
7094 if (unsigned_enum)
7095 TYPE_UNSIGNED (this_type) = 1;
7096 }
7097
7098 new_symbol (die, this_type, cu);
7099 }
7100
7101 /* Extract all information from a DW_TAG_array_type DIE and put it in
7102 the DIE's type field. For now, this only handles one dimensional
7103 arrays. */
7104
7105 static struct type *
7106 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
7107 {
7108 struct objfile *objfile = cu->objfile;
7109 struct die_info *child_die;
7110 struct type *type;
7111 struct type *element_type, *range_type, *index_type;
7112 struct type **range_types = NULL;
7113 struct attribute *attr;
7114 int ndim = 0;
7115 struct cleanup *back_to;
7116 char *name;
7117
7118 element_type = die_type (die, cu);
7119
7120 /* The die_type call above may have already set the type for this DIE. */
7121 type = get_die_type (die, cu);
7122 if (type)
7123 return type;
7124
7125 /* Irix 6.2 native cc creates array types without children for
7126 arrays with unspecified length. */
7127 if (die->child == NULL)
7128 {
7129 index_type = objfile_type (objfile)->builtin_int;
7130 range_type = create_range_type (NULL, index_type, 0, -1);
7131 type = create_array_type (NULL, element_type, range_type);
7132 return set_die_type (die, type, cu);
7133 }
7134
7135 back_to = make_cleanup (null_cleanup, NULL);
7136 child_die = die->child;
7137 while (child_die && child_die->tag)
7138 {
7139 if (child_die->tag == DW_TAG_subrange_type)
7140 {
7141 struct type *child_type = read_type_die (child_die, cu);
7142
7143 if (child_type != NULL)
7144 {
7145 /* The range type was succesfully read. Save it for
7146 the array type creation. */
7147 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
7148 {
7149 range_types = (struct type **)
7150 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
7151 * sizeof (struct type *));
7152 if (ndim == 0)
7153 make_cleanup (free_current_contents, &range_types);
7154 }
7155 range_types[ndim++] = child_type;
7156 }
7157 }
7158 child_die = sibling_die (child_die);
7159 }
7160
7161 /* Dwarf2 dimensions are output from left to right, create the
7162 necessary array types in backwards order. */
7163
7164 type = element_type;
7165
7166 if (read_array_order (die, cu) == DW_ORD_col_major)
7167 {
7168 int i = 0;
7169
7170 while (i < ndim)
7171 type = create_array_type (NULL, type, range_types[i++]);
7172 }
7173 else
7174 {
7175 while (ndim-- > 0)
7176 type = create_array_type (NULL, type, range_types[ndim]);
7177 }
7178
7179 /* Understand Dwarf2 support for vector types (like they occur on
7180 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7181 array type. This is not part of the Dwarf2/3 standard yet, but a
7182 custom vendor extension. The main difference between a regular
7183 array and the vector variant is that vectors are passed by value
7184 to functions. */
7185 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
7186 if (attr)
7187 make_vector_type (type);
7188
7189 name = dwarf2_name (die, cu);
7190 if (name)
7191 TYPE_NAME (type) = name;
7192
7193 /* Install the type in the die. */
7194 set_die_type (die, type, cu);
7195
7196 /* set_die_type should be already done. */
7197 set_descriptive_type (type, die, cu);
7198
7199 do_cleanups (back_to);
7200
7201 return type;
7202 }
7203
7204 static enum dwarf_array_dim_ordering
7205 read_array_order (struct die_info *die, struct dwarf2_cu *cu)
7206 {
7207 struct attribute *attr;
7208
7209 attr = dwarf2_attr (die, DW_AT_ordering, cu);
7210
7211 if (attr) return DW_SND (attr);
7212
7213 /*
7214 GNU F77 is a special case, as at 08/2004 array type info is the
7215 opposite order to the dwarf2 specification, but data is still
7216 laid out as per normal fortran.
7217
7218 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7219 version checking.
7220 */
7221
7222 if (cu->language == language_fortran
7223 && cu->producer && strstr (cu->producer, "GNU F77"))
7224 {
7225 return DW_ORD_row_major;
7226 }
7227
7228 switch (cu->language_defn->la_array_ordering)
7229 {
7230 case array_column_major:
7231 return DW_ORD_col_major;
7232 case array_row_major:
7233 default:
7234 return DW_ORD_row_major;
7235 };
7236 }
7237
7238 /* Extract all information from a DW_TAG_set_type DIE and put it in
7239 the DIE's type field. */
7240
7241 static struct type *
7242 read_set_type (struct die_info *die, struct dwarf2_cu *cu)
7243 {
7244 struct type *domain_type, *set_type;
7245 struct attribute *attr;
7246
7247 domain_type = die_type (die, cu);
7248
7249 /* The die_type call above may have already set the type for this DIE. */
7250 set_type = get_die_type (die, cu);
7251 if (set_type)
7252 return set_type;
7253
7254 set_type = create_set_type (NULL, domain_type);
7255
7256 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7257 if (attr)
7258 TYPE_LENGTH (set_type) = DW_UNSND (attr);
7259
7260 return set_die_type (die, set_type, cu);
7261 }
7262
7263 /* First cut: install each common block member as a global variable. */
7264
7265 static void
7266 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
7267 {
7268 struct die_info *child_die;
7269 struct attribute *attr;
7270 struct symbol *sym;
7271 CORE_ADDR base = (CORE_ADDR) 0;
7272
7273 attr = dwarf2_attr (die, DW_AT_location, cu);
7274 if (attr)
7275 {
7276 /* Support the .debug_loc offsets */
7277 if (attr_form_is_block (attr))
7278 {
7279 base = decode_locdesc (DW_BLOCK (attr), cu);
7280 }
7281 else if (attr_form_is_section_offset (attr))
7282 {
7283 dwarf2_complex_location_expr_complaint ();
7284 }
7285 else
7286 {
7287 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7288 "common block member");
7289 }
7290 }
7291 if (die->child != NULL)
7292 {
7293 child_die = die->child;
7294 while (child_die && child_die->tag)
7295 {
7296 sym = new_symbol (child_die, NULL, cu);
7297 attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu);
7298 if (attr)
7299 {
7300 CORE_ADDR byte_offset = 0;
7301
7302 if (attr_form_is_section_offset (attr))
7303 dwarf2_complex_location_expr_complaint ();
7304 else if (attr_form_is_constant (attr))
7305 byte_offset = dwarf2_get_attr_constant_value (attr, 0);
7306 else if (attr_form_is_block (attr))
7307 byte_offset = decode_locdesc (DW_BLOCK (attr), cu);
7308 else
7309 dwarf2_complex_location_expr_complaint ();
7310
7311 SYMBOL_VALUE_ADDRESS (sym) = base + byte_offset;
7312 add_symbol_to_list (sym, &global_symbols);
7313 }
7314 child_die = sibling_die (child_die);
7315 }
7316 }
7317 }
7318
7319 /* Create a type for a C++ namespace. */
7320
7321 static struct type *
7322 read_namespace_type (struct die_info *die, struct dwarf2_cu *cu)
7323 {
7324 struct objfile *objfile = cu->objfile;
7325 const char *previous_prefix, *name;
7326 int is_anonymous;
7327 struct type *type;
7328
7329 /* For extensions, reuse the type of the original namespace. */
7330 if (dwarf2_attr (die, DW_AT_extension, cu) != NULL)
7331 {
7332 struct die_info *ext_die;
7333 struct dwarf2_cu *ext_cu = cu;
7334
7335 ext_die = dwarf2_extension (die, &ext_cu);
7336 type = read_type_die (ext_die, ext_cu);
7337
7338 /* EXT_CU may not be the same as CU.
7339 Ensure TYPE is recorded in CU's type_hash table. */
7340 return set_die_type (die, type, cu);
7341 }
7342
7343 name = namespace_name (die, &is_anonymous, cu);
7344
7345 /* Now build the name of the current namespace. */
7346
7347 previous_prefix = determine_prefix (die, cu);
7348 if (previous_prefix[0] != '\0')
7349 name = typename_concat (&objfile->objfile_obstack,
7350 previous_prefix, name, 0, cu);
7351
7352 /* Create the type. */
7353 type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL,
7354 objfile);
7355 TYPE_NAME (type) = (char *) name;
7356 TYPE_TAG_NAME (type) = TYPE_NAME (type);
7357
7358 return set_die_type (die, type, cu);
7359 }
7360
7361 /* Read a C++ namespace. */
7362
7363 static void
7364 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
7365 {
7366 struct objfile *objfile = cu->objfile;
7367 const char *name;
7368 int is_anonymous;
7369
7370 /* Add a symbol associated to this if we haven't seen the namespace
7371 before. Also, add a using directive if it's an anonymous
7372 namespace. */
7373
7374 if (dwarf2_attr (die, DW_AT_extension, cu) == NULL)
7375 {
7376 struct type *type;
7377
7378 type = read_type_die (die, cu);
7379 new_symbol (die, type, cu);
7380
7381 name = namespace_name (die, &is_anonymous, cu);
7382 if (is_anonymous)
7383 {
7384 const char *previous_prefix = determine_prefix (die, cu);
7385
7386 cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL,
7387 NULL, &objfile->objfile_obstack);
7388 }
7389 }
7390
7391 if (die->child != NULL)
7392 {
7393 struct die_info *child_die = die->child;
7394
7395 while (child_die && child_die->tag)
7396 {
7397 process_die (child_die, cu);
7398 child_die = sibling_die (child_die);
7399 }
7400 }
7401 }
7402
7403 /* Read a Fortran module as type. This DIE can be only a declaration used for
7404 imported module. Still we need that type as local Fortran "use ... only"
7405 declaration imports depend on the created type in determine_prefix. */
7406
7407 static struct type *
7408 read_module_type (struct die_info *die, struct dwarf2_cu *cu)
7409 {
7410 struct objfile *objfile = cu->objfile;
7411 char *module_name;
7412 struct type *type;
7413
7414 module_name = dwarf2_name (die, cu);
7415 if (!module_name)
7416 complaint (&symfile_complaints, _("DW_TAG_module has no name, offset 0x%x"),
7417 die->offset);
7418 type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile);
7419
7420 /* determine_prefix uses TYPE_TAG_NAME. */
7421 TYPE_TAG_NAME (type) = TYPE_NAME (type);
7422
7423 return set_die_type (die, type, cu);
7424 }
7425
7426 /* Read a Fortran module. */
7427
7428 static void
7429 read_module (struct die_info *die, struct dwarf2_cu *cu)
7430 {
7431 struct die_info *child_die = die->child;
7432
7433 while (child_die && child_die->tag)
7434 {
7435 process_die (child_die, cu);
7436 child_die = sibling_die (child_die);
7437 }
7438 }
7439
7440 /* Return the name of the namespace represented by DIE. Set
7441 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
7442 namespace. */
7443
7444 static const char *
7445 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
7446 {
7447 struct die_info *current_die;
7448 const char *name = NULL;
7449
7450 /* Loop through the extensions until we find a name. */
7451
7452 for (current_die = die;
7453 current_die != NULL;
7454 current_die = dwarf2_extension (die, &cu))
7455 {
7456 name = dwarf2_name (current_die, cu);
7457 if (name != NULL)
7458 break;
7459 }
7460
7461 /* Is it an anonymous namespace? */
7462
7463 *is_anonymous = (name == NULL);
7464 if (*is_anonymous)
7465 name = "(anonymous namespace)";
7466
7467 return name;
7468 }
7469
7470 /* Extract all information from a DW_TAG_pointer_type DIE and add to
7471 the user defined type vector. */
7472
7473 static struct type *
7474 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
7475 {
7476 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
7477 struct comp_unit_head *cu_header = &cu->header;
7478 struct type *type;
7479 struct attribute *attr_byte_size;
7480 struct attribute *attr_address_class;
7481 int byte_size, addr_class;
7482 struct type *target_type;
7483
7484 target_type = die_type (die, cu);
7485
7486 /* The die_type call above may have already set the type for this DIE. */
7487 type = get_die_type (die, cu);
7488 if (type)
7489 return type;
7490
7491 type = lookup_pointer_type (target_type);
7492
7493 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
7494 if (attr_byte_size)
7495 byte_size = DW_UNSND (attr_byte_size);
7496 else
7497 byte_size = cu_header->addr_size;
7498
7499 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
7500 if (attr_address_class)
7501 addr_class = DW_UNSND (attr_address_class);
7502 else
7503 addr_class = DW_ADDR_none;
7504
7505 /* If the pointer size or address class is different than the
7506 default, create a type variant marked as such and set the
7507 length accordingly. */
7508 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
7509 {
7510 if (gdbarch_address_class_type_flags_p (gdbarch))
7511 {
7512 int type_flags;
7513
7514 type_flags = gdbarch_address_class_type_flags
7515 (gdbarch, byte_size, addr_class);
7516 gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
7517 == 0);
7518 type = make_type_with_address_space (type, type_flags);
7519 }
7520 else if (TYPE_LENGTH (type) != byte_size)
7521 {
7522 complaint (&symfile_complaints, _("invalid pointer size %d"), byte_size);
7523 }
7524 else
7525 {
7526 /* Should we also complain about unhandled address classes? */
7527 }
7528 }
7529
7530 TYPE_LENGTH (type) = byte_size;
7531 return set_die_type (die, type, cu);
7532 }
7533
7534 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
7535 the user defined type vector. */
7536
7537 static struct type *
7538 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
7539 {
7540 struct type *type;
7541 struct type *to_type;
7542 struct type *domain;
7543
7544 to_type = die_type (die, cu);
7545 domain = die_containing_type (die, cu);
7546
7547 /* The calls above may have already set the type for this DIE. */
7548 type = get_die_type (die, cu);
7549 if (type)
7550 return type;
7551
7552 if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD)
7553 type = lookup_methodptr_type (to_type);
7554 else
7555 type = lookup_memberptr_type (to_type, domain);
7556
7557 return set_die_type (die, type, cu);
7558 }
7559
7560 /* Extract all information from a DW_TAG_reference_type DIE and add to
7561 the user defined type vector. */
7562
7563 static struct type *
7564 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
7565 {
7566 struct comp_unit_head *cu_header = &cu->header;
7567 struct type *type, *target_type;
7568 struct attribute *attr;
7569
7570 target_type = die_type (die, cu);
7571
7572 /* The die_type call above may have already set the type for this DIE. */
7573 type = get_die_type (die, cu);
7574 if (type)
7575 return type;
7576
7577 type = lookup_reference_type (target_type);
7578 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7579 if (attr)
7580 {
7581 TYPE_LENGTH (type) = DW_UNSND (attr);
7582 }
7583 else
7584 {
7585 TYPE_LENGTH (type) = cu_header->addr_size;
7586 }
7587 return set_die_type (die, type, cu);
7588 }
7589
7590 static struct type *
7591 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
7592 {
7593 struct type *base_type, *cv_type;
7594
7595 base_type = die_type (die, cu);
7596
7597 /* The die_type call above may have already set the type for this DIE. */
7598 cv_type = get_die_type (die, cu);
7599 if (cv_type)
7600 return cv_type;
7601
7602 cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
7603 return set_die_type (die, cv_type, cu);
7604 }
7605
7606 static struct type *
7607 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
7608 {
7609 struct type *base_type, *cv_type;
7610
7611 base_type = die_type (die, cu);
7612
7613 /* The die_type call above may have already set the type for this DIE. */
7614 cv_type = get_die_type (die, cu);
7615 if (cv_type)
7616 return cv_type;
7617
7618 cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
7619 return set_die_type (die, cv_type, cu);
7620 }
7621
7622 /* Extract all information from a DW_TAG_string_type DIE and add to
7623 the user defined type vector. It isn't really a user defined type,
7624 but it behaves like one, with other DIE's using an AT_user_def_type
7625 attribute to reference it. */
7626
7627 static struct type *
7628 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
7629 {
7630 struct objfile *objfile = cu->objfile;
7631 struct gdbarch *gdbarch = get_objfile_arch (objfile);
7632 struct type *type, *range_type, *index_type, *char_type;
7633 struct attribute *attr;
7634 unsigned int length;
7635
7636 attr = dwarf2_attr (die, DW_AT_string_length, cu);
7637 if (attr)
7638 {
7639 length = DW_UNSND (attr);
7640 }
7641 else
7642 {
7643 /* check for the DW_AT_byte_size attribute */
7644 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7645 if (attr)
7646 {
7647 length = DW_UNSND (attr);
7648 }
7649 else
7650 {
7651 length = 1;
7652 }
7653 }
7654
7655 index_type = objfile_type (objfile)->builtin_int;
7656 range_type = create_range_type (NULL, index_type, 1, length);
7657 char_type = language_string_char_type (cu->language_defn, gdbarch);
7658 type = create_string_type (NULL, char_type, range_type);
7659
7660 return set_die_type (die, type, cu);
7661 }
7662
7663 /* Handle DIES due to C code like:
7664
7665 struct foo
7666 {
7667 int (*funcp)(int a, long l);
7668 int b;
7669 };
7670
7671 ('funcp' generates a DW_TAG_subroutine_type DIE)
7672 */
7673
7674 static struct type *
7675 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
7676 {
7677 struct type *type; /* Type that this function returns */
7678 struct type *ftype; /* Function that returns above type */
7679 struct attribute *attr;
7680
7681 type = die_type (die, cu);
7682
7683 /* The die_type call above may have already set the type for this DIE. */
7684 ftype = get_die_type (die, cu);
7685 if (ftype)
7686 return ftype;
7687
7688 ftype = lookup_function_type (type);
7689
7690 /* All functions in C++, Pascal and Java have prototypes. */
7691 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
7692 if ((attr && (DW_UNSND (attr) != 0))
7693 || cu->language == language_cplus
7694 || cu->language == language_java
7695 || cu->language == language_pascal)
7696 TYPE_PROTOTYPED (ftype) = 1;
7697 else if (producer_is_realview (cu->producer))
7698 /* RealView does not emit DW_AT_prototyped. We can not
7699 distinguish prototyped and unprototyped functions; default to
7700 prototyped, since that is more common in modern code (and
7701 RealView warns about unprototyped functions). */
7702 TYPE_PROTOTYPED (ftype) = 1;
7703
7704 /* Store the calling convention in the type if it's available in
7705 the subroutine die. Otherwise set the calling convention to
7706 the default value DW_CC_normal. */
7707 attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
7708 TYPE_CALLING_CONVENTION (ftype) = attr ? DW_UNSND (attr) : DW_CC_normal;
7709
7710 /* We need to add the subroutine type to the die immediately so
7711 we don't infinitely recurse when dealing with parameters
7712 declared as the same subroutine type. */
7713 set_die_type (die, ftype, cu);
7714
7715 if (die->child != NULL)
7716 {
7717 struct type *void_type = objfile_type (cu->objfile)->builtin_void;
7718 struct die_info *child_die;
7719 int nparams, iparams;
7720
7721 /* Count the number of parameters.
7722 FIXME: GDB currently ignores vararg functions, but knows about
7723 vararg member functions. */
7724 nparams = 0;
7725 child_die = die->child;
7726 while (child_die && child_die->tag)
7727 {
7728 if (child_die->tag == DW_TAG_formal_parameter)
7729 nparams++;
7730 else if (child_die->tag == DW_TAG_unspecified_parameters)
7731 TYPE_VARARGS (ftype) = 1;
7732 child_die = sibling_die (child_die);
7733 }
7734
7735 /* Allocate storage for parameters and fill them in. */
7736 TYPE_NFIELDS (ftype) = nparams;
7737 TYPE_FIELDS (ftype) = (struct field *)
7738 TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
7739
7740 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
7741 even if we error out during the parameters reading below. */
7742 for (iparams = 0; iparams < nparams; iparams++)
7743 TYPE_FIELD_TYPE (ftype, iparams) = void_type;
7744
7745 iparams = 0;
7746 child_die = die->child;
7747 while (child_die && child_die->tag)
7748 {
7749 if (child_die->tag == DW_TAG_formal_parameter)
7750 {
7751 struct type *arg_type;
7752
7753 /* DWARF version 2 has no clean way to discern C++
7754 static and non-static member functions. G++ helps
7755 GDB by marking the first parameter for non-static
7756 member functions (which is the this pointer) as
7757 artificial. We pass this information to
7758 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
7759
7760 DWARF version 3 added DW_AT_object_pointer, which GCC
7761 4.5 does not yet generate. */
7762 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
7763 if (attr)
7764 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
7765 else
7766 {
7767 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
7768
7769 /* GCC/43521: In java, the formal parameter
7770 "this" is sometimes not marked with DW_AT_artificial. */
7771 if (cu->language == language_java)
7772 {
7773 const char *name = dwarf2_name (child_die, cu);
7774
7775 if (name && !strcmp (name, "this"))
7776 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1;
7777 }
7778 }
7779 arg_type = die_type (child_die, cu);
7780
7781 /* RealView does not mark THIS as const, which the testsuite
7782 expects. GCC marks THIS as const in method definitions,
7783 but not in the class specifications (GCC PR 43053). */
7784 if (cu->language == language_cplus && !TYPE_CONST (arg_type)
7785 && TYPE_FIELD_ARTIFICIAL (ftype, iparams))
7786 {
7787 int is_this = 0;
7788 struct dwarf2_cu *arg_cu = cu;
7789 const char *name = dwarf2_name (child_die, cu);
7790
7791 attr = dwarf2_attr (die, DW_AT_object_pointer, cu);
7792 if (attr)
7793 {
7794 /* If the compiler emits this, use it. */
7795 if (follow_die_ref (die, attr, &arg_cu) == child_die)
7796 is_this = 1;
7797 }
7798 else if (name && strcmp (name, "this") == 0)
7799 /* Function definitions will have the argument names. */
7800 is_this = 1;
7801 else if (name == NULL && iparams == 0)
7802 /* Declarations may not have the names, so like
7803 elsewhere in GDB, assume an artificial first
7804 argument is "this". */
7805 is_this = 1;
7806
7807 if (is_this)
7808 arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type),
7809 arg_type, 0);
7810 }
7811
7812 TYPE_FIELD_TYPE (ftype, iparams) = arg_type;
7813 iparams++;
7814 }
7815 child_die = sibling_die (child_die);
7816 }
7817 }
7818
7819 return ftype;
7820 }
7821
7822 static struct type *
7823 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
7824 {
7825 struct objfile *objfile = cu->objfile;
7826 const char *name = NULL;
7827 struct type *this_type;
7828
7829 name = dwarf2_full_name (NULL, die, cu);
7830 this_type = init_type (TYPE_CODE_TYPEDEF, 0,
7831 TYPE_FLAG_TARGET_STUB, NULL, objfile);
7832 TYPE_NAME (this_type) = (char *) name;
7833 set_die_type (die, this_type, cu);
7834 TYPE_TARGET_TYPE (this_type) = die_type (die, cu);
7835 return this_type;
7836 }
7837
7838 /* Find a representation of a given base type and install
7839 it in the TYPE field of the die. */
7840
7841 static struct type *
7842 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
7843 {
7844 struct objfile *objfile = cu->objfile;
7845 struct type *type;
7846 struct attribute *attr;
7847 int encoding = 0, size = 0;
7848 char *name;
7849 enum type_code code = TYPE_CODE_INT;
7850 int type_flags = 0;
7851 struct type *target_type = NULL;
7852
7853 attr = dwarf2_attr (die, DW_AT_encoding, cu);
7854 if (attr)
7855 {
7856 encoding = DW_UNSND (attr);
7857 }
7858 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7859 if (attr)
7860 {
7861 size = DW_UNSND (attr);
7862 }
7863 name = dwarf2_name (die, cu);
7864 if (!name)
7865 {
7866 complaint (&symfile_complaints,
7867 _("DW_AT_name missing from DW_TAG_base_type"));
7868 }
7869
7870 switch (encoding)
7871 {
7872 case DW_ATE_address:
7873 /* Turn DW_ATE_address into a void * pointer. */
7874 code = TYPE_CODE_PTR;
7875 type_flags |= TYPE_FLAG_UNSIGNED;
7876 target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
7877 break;
7878 case DW_ATE_boolean:
7879 code = TYPE_CODE_BOOL;
7880 type_flags |= TYPE_FLAG_UNSIGNED;
7881 break;
7882 case DW_ATE_complex_float:
7883 code = TYPE_CODE_COMPLEX;
7884 target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile);
7885 break;
7886 case DW_ATE_decimal_float:
7887 code = TYPE_CODE_DECFLOAT;
7888 break;
7889 case DW_ATE_float:
7890 code = TYPE_CODE_FLT;
7891 break;
7892 case DW_ATE_signed:
7893 break;
7894 case DW_ATE_unsigned:
7895 type_flags |= TYPE_FLAG_UNSIGNED;
7896 break;
7897 case DW_ATE_signed_char:
7898 if (cu->language == language_ada || cu->language == language_m2
7899 || cu->language == language_pascal)
7900 code = TYPE_CODE_CHAR;
7901 break;
7902 case DW_ATE_unsigned_char:
7903 if (cu->language == language_ada || cu->language == language_m2
7904 || cu->language == language_pascal)
7905 code = TYPE_CODE_CHAR;
7906 type_flags |= TYPE_FLAG_UNSIGNED;
7907 break;
7908 case DW_ATE_UTF:
7909 /* We just treat this as an integer and then recognize the
7910 type by name elsewhere. */
7911 break;
7912
7913 default:
7914 complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"),
7915 dwarf_type_encoding_name (encoding));
7916 break;
7917 }
7918
7919 type = init_type (code, size, type_flags, NULL, objfile);
7920 TYPE_NAME (type) = name;
7921 TYPE_TARGET_TYPE (type) = target_type;
7922
7923 if (name && strcmp (name, "char") == 0)
7924 TYPE_NOSIGN (type) = 1;
7925
7926 return set_die_type (die, type, cu);
7927 }
7928
7929 /* Read the given DW_AT_subrange DIE. */
7930
7931 static struct type *
7932 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
7933 {
7934 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
7935 struct type *base_type;
7936 struct type *range_type;
7937 struct attribute *attr;
7938 LONGEST low = 0;
7939 LONGEST high = -1;
7940 char *name;
7941 LONGEST negative_mask;
7942
7943 base_type = die_type (die, cu);
7944 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
7945 check_typedef (base_type);
7946
7947 /* The die_type call above may have already set the type for this DIE. */
7948 range_type = get_die_type (die, cu);
7949 if (range_type)
7950 return range_type;
7951
7952 if (cu->language == language_fortran)
7953 {
7954 /* FORTRAN implies a lower bound of 1, if not given. */
7955 low = 1;
7956 }
7957
7958 /* FIXME: For variable sized arrays either of these could be
7959 a variable rather than a constant value. We'll allow it,
7960 but we don't know how to handle it. */
7961 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
7962 if (attr)
7963 low = dwarf2_get_attr_constant_value (attr, 0);
7964
7965 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
7966 if (attr)
7967 {
7968 if (attr->form == DW_FORM_block1 || is_ref_attr (attr))
7969 {
7970 /* GCC encodes arrays with unspecified or dynamic length
7971 with a DW_FORM_block1 attribute or a reference attribute.
7972 FIXME: GDB does not yet know how to handle dynamic
7973 arrays properly, treat them as arrays with unspecified
7974 length for now.
7975
7976 FIXME: jimb/2003-09-22: GDB does not really know
7977 how to handle arrays of unspecified length
7978 either; we just represent them as zero-length
7979 arrays. Choose an appropriate upper bound given
7980 the lower bound we've computed above. */
7981 high = low - 1;
7982 }
7983 else
7984 high = dwarf2_get_attr_constant_value (attr, 1);
7985 }
7986 else
7987 {
7988 attr = dwarf2_attr (die, DW_AT_count, cu);
7989 if (attr)
7990 {
7991 int count = dwarf2_get_attr_constant_value (attr, 1);
7992 high = low + count - 1;
7993 }
7994 }
7995
7996 /* Dwarf-2 specifications explicitly allows to create subrange types
7997 without specifying a base type.
7998 In that case, the base type must be set to the type of
7999 the lower bound, upper bound or count, in that order, if any of these
8000 three attributes references an object that has a type.
8001 If no base type is found, the Dwarf-2 specifications say that
8002 a signed integer type of size equal to the size of an address should
8003 be used.
8004 For the following C code: `extern char gdb_int [];'
8005 GCC produces an empty range DIE.
8006 FIXME: muller/2010-05-28: Possible references to object for low bound,
8007 high bound or count are not yet handled by this code.
8008 */
8009 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
8010 {
8011 struct objfile *objfile = cu->objfile;
8012 struct gdbarch *gdbarch = get_objfile_arch (objfile);
8013 int addr_size = gdbarch_addr_bit (gdbarch) /8;
8014 struct type *int_type = objfile_type (objfile)->builtin_int;
8015
8016 /* Test "int", "long int", and "long long int" objfile types,
8017 and select the first one having a size above or equal to the
8018 architecture address size. */
8019 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
8020 base_type = int_type;
8021 else
8022 {
8023 int_type = objfile_type (objfile)->builtin_long;
8024 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
8025 base_type = int_type;
8026 else
8027 {
8028 int_type = objfile_type (objfile)->builtin_long_long;
8029 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
8030 base_type = int_type;
8031 }
8032 }
8033 }
8034
8035 negative_mask =
8036 (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
8037 if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
8038 low |= negative_mask;
8039 if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
8040 high |= negative_mask;
8041
8042 range_type = create_range_type (NULL, base_type, low, high);
8043
8044 /* Mark arrays with dynamic length at least as an array of unspecified
8045 length. GDB could check the boundary but before it gets implemented at
8046 least allow accessing the array elements. */
8047 if (attr && attr->form == DW_FORM_block1)
8048 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
8049
8050 name = dwarf2_name (die, cu);
8051 if (name)
8052 TYPE_NAME (range_type) = name;
8053
8054 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8055 if (attr)
8056 TYPE_LENGTH (range_type) = DW_UNSND (attr);
8057
8058 set_die_type (die, range_type, cu);
8059
8060 /* set_die_type should be already done. */
8061 set_descriptive_type (range_type, die, cu);
8062
8063 return range_type;
8064 }
8065
8066 static struct type *
8067 read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
8068 {
8069 struct type *type;
8070
8071 /* For now, we only support the C meaning of an unspecified type: void. */
8072
8073 type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile);
8074 TYPE_NAME (type) = dwarf2_name (die, cu);
8075
8076 return set_die_type (die, type, cu);
8077 }
8078
8079 /* Trivial hash function for die_info: the hash value of a DIE
8080 is its offset in .debug_info for this objfile. */
8081
8082 static hashval_t
8083 die_hash (const void *item)
8084 {
8085 const struct die_info *die = item;
8086
8087 return die->offset;
8088 }
8089
8090 /* Trivial comparison function for die_info structures: two DIEs
8091 are equal if they have the same offset. */
8092
8093 static int
8094 die_eq (const void *item_lhs, const void *item_rhs)
8095 {
8096 const struct die_info *die_lhs = item_lhs;
8097 const struct die_info *die_rhs = item_rhs;
8098
8099 return die_lhs->offset == die_rhs->offset;
8100 }
8101
8102 /* Read a whole compilation unit into a linked list of dies. */
8103
8104 static struct die_info *
8105 read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu)
8106 {
8107 struct die_reader_specs reader_specs;
8108 int read_abbrevs = 0;
8109 struct cleanup *back_to = NULL;
8110 struct die_info *die;
8111
8112 if (cu->dwarf2_abbrevs == NULL)
8113 {
8114 dwarf2_read_abbrevs (cu->objfile->obfd, cu);
8115 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
8116 read_abbrevs = 1;
8117 }
8118
8119 gdb_assert (cu->die_hash == NULL);
8120 cu->die_hash
8121 = htab_create_alloc_ex (cu->header.length / 12,
8122 die_hash,
8123 die_eq,
8124 NULL,
8125 &cu->comp_unit_obstack,
8126 hashtab_obstack_allocate,
8127 dummy_obstack_deallocate);
8128
8129 init_cu_die_reader (&reader_specs, cu);
8130
8131 die = read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL);
8132
8133 if (read_abbrevs)
8134 do_cleanups (back_to);
8135
8136 return die;
8137 }
8138
8139 /* Main entry point for reading a DIE and all children.
8140 Read the DIE and dump it if requested. */
8141
8142 static struct die_info *
8143 read_die_and_children (const struct die_reader_specs *reader,
8144 gdb_byte *info_ptr,
8145 gdb_byte **new_info_ptr,
8146 struct die_info *parent)
8147 {
8148 struct die_info *result = read_die_and_children_1 (reader, info_ptr,
8149 new_info_ptr, parent);
8150
8151 if (dwarf2_die_debug)
8152 {
8153 fprintf_unfiltered (gdb_stdlog,
8154 "\nRead die from %s of %s:\n",
8155 reader->buffer == dwarf2_per_objfile->info.buffer
8156 ? ".debug_info"
8157 : reader->buffer == dwarf2_per_objfile->types.buffer
8158 ? ".debug_types"
8159 : "unknown section",
8160 reader->abfd->filename);
8161 dump_die (result, dwarf2_die_debug);
8162 }
8163
8164 return result;
8165 }
8166
8167 /* Read a single die and all its descendents. Set the die's sibling
8168 field to NULL; set other fields in the die correctly, and set all
8169 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8170 location of the info_ptr after reading all of those dies. PARENT
8171 is the parent of the die in question. */
8172
8173 static struct die_info *
8174 read_die_and_children_1 (const struct die_reader_specs *reader,
8175 gdb_byte *info_ptr,
8176 gdb_byte **new_info_ptr,
8177 struct die_info *parent)
8178 {
8179 struct die_info *die;
8180 gdb_byte *cur_ptr;
8181 int has_children;
8182
8183 cur_ptr = read_full_die (reader, &die, info_ptr, &has_children);
8184 if (die == NULL)
8185 {
8186 *new_info_ptr = cur_ptr;
8187 return NULL;
8188 }
8189 store_in_ref_table (die, reader->cu);
8190
8191 if (has_children)
8192 die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die);
8193 else
8194 {
8195 die->child = NULL;
8196 *new_info_ptr = cur_ptr;
8197 }
8198
8199 die->sibling = NULL;
8200 die->parent = parent;
8201 return die;
8202 }
8203
8204 /* Read a die, all of its descendents, and all of its siblings; set
8205 all of the fields of all of the dies correctly. Arguments are as
8206 in read_die_and_children. */
8207
8208 static struct die_info *
8209 read_die_and_siblings (const struct die_reader_specs *reader,
8210 gdb_byte *info_ptr,
8211 gdb_byte **new_info_ptr,
8212 struct die_info *parent)
8213 {
8214 struct die_info *first_die, *last_sibling;
8215 gdb_byte *cur_ptr;
8216
8217 cur_ptr = info_ptr;
8218 first_die = last_sibling = NULL;
8219
8220 while (1)
8221 {
8222 struct die_info *die
8223 = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent);
8224
8225 if (die == NULL)
8226 {
8227 *new_info_ptr = cur_ptr;
8228 return first_die;
8229 }
8230
8231 if (!first_die)
8232 first_die = die;
8233 else
8234 last_sibling->sibling = die;
8235
8236 last_sibling = die;
8237 }
8238 }
8239
8240 /* Read the die from the .debug_info section buffer. Set DIEP to
8241 point to a newly allocated die with its information, except for its
8242 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8243 whether the die has children or not. */
8244
8245 static gdb_byte *
8246 read_full_die (const struct die_reader_specs *reader,
8247 struct die_info **diep, gdb_byte *info_ptr,
8248 int *has_children)
8249 {
8250 unsigned int abbrev_number, bytes_read, i, offset;
8251 struct abbrev_info *abbrev;
8252 struct die_info *die;
8253 struct dwarf2_cu *cu = reader->cu;
8254 bfd *abfd = reader->abfd;
8255
8256 offset = info_ptr - reader->buffer;
8257 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
8258 info_ptr += bytes_read;
8259 if (!abbrev_number)
8260 {
8261 *diep = NULL;
8262 *has_children = 0;
8263 return info_ptr;
8264 }
8265
8266 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
8267 if (!abbrev)
8268 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8269 abbrev_number,
8270 bfd_get_filename (abfd));
8271
8272 die = dwarf_alloc_die (cu, abbrev->num_attrs);
8273 die->offset = offset;
8274 die->tag = abbrev->tag;
8275 die->abbrev = abbrev_number;
8276
8277 die->num_attrs = abbrev->num_attrs;
8278
8279 for (i = 0; i < abbrev->num_attrs; ++i)
8280 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
8281 abfd, info_ptr, cu);
8282
8283 *diep = die;
8284 *has_children = abbrev->has_children;
8285 return info_ptr;
8286 }
8287
8288 /* In DWARF version 2, the description of the debugging information is
8289 stored in a separate .debug_abbrev section. Before we read any
8290 dies from a section we read in all abbreviations and install them
8291 in a hash table. This function also sets flags in CU describing
8292 the data found in the abbrev table. */
8293
8294 static void
8295 dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
8296 {
8297 struct comp_unit_head *cu_header = &cu->header;
8298 gdb_byte *abbrev_ptr;
8299 struct abbrev_info *cur_abbrev;
8300 unsigned int abbrev_number, bytes_read, abbrev_name;
8301 unsigned int abbrev_form, hash_number;
8302 struct attr_abbrev *cur_attrs;
8303 unsigned int allocated_attrs;
8304
8305 /* Initialize dwarf2 abbrevs */
8306 obstack_init (&cu->abbrev_obstack);
8307 cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack,
8308 (ABBREV_HASH_SIZE
8309 * sizeof (struct abbrev_info *)));
8310 memset (cu->dwarf2_abbrevs, 0,
8311 ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
8312
8313 dwarf2_read_section (dwarf2_per_objfile->objfile,
8314 &dwarf2_per_objfile->abbrev);
8315 abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset;
8316 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8317 abbrev_ptr += bytes_read;
8318
8319 allocated_attrs = ATTR_ALLOC_CHUNK;
8320 cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
8321
8322 /* loop until we reach an abbrev number of 0 */
8323 while (abbrev_number)
8324 {
8325 cur_abbrev = dwarf_alloc_abbrev (cu);
8326
8327 /* read in abbrev header */
8328 cur_abbrev->number = abbrev_number;
8329 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8330 abbrev_ptr += bytes_read;
8331 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
8332 abbrev_ptr += 1;
8333
8334 if (cur_abbrev->tag == DW_TAG_namespace)
8335 cu->has_namespace_info = 1;
8336
8337 /* now read in declarations */
8338 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8339 abbrev_ptr += bytes_read;
8340 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8341 abbrev_ptr += bytes_read;
8342 while (abbrev_name)
8343 {
8344 if (cur_abbrev->num_attrs == allocated_attrs)
8345 {
8346 allocated_attrs += ATTR_ALLOC_CHUNK;
8347 cur_attrs
8348 = xrealloc (cur_attrs, (allocated_attrs
8349 * sizeof (struct attr_abbrev)));
8350 }
8351
8352 /* Record whether this compilation unit might have
8353 inter-compilation-unit references. If we don't know what form
8354 this attribute will have, then it might potentially be a
8355 DW_FORM_ref_addr, so we conservatively expect inter-CU
8356 references. */
8357
8358 if (abbrev_form == DW_FORM_ref_addr
8359 || abbrev_form == DW_FORM_indirect)
8360 cu->has_form_ref_addr = 1;
8361
8362 cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
8363 cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
8364 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8365 abbrev_ptr += bytes_read;
8366 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8367 abbrev_ptr += bytes_read;
8368 }
8369
8370 cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack,
8371 (cur_abbrev->num_attrs
8372 * sizeof (struct attr_abbrev)));
8373 memcpy (cur_abbrev->attrs, cur_attrs,
8374 cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
8375
8376 hash_number = abbrev_number % ABBREV_HASH_SIZE;
8377 cur_abbrev->next = cu->dwarf2_abbrevs[hash_number];
8378 cu->dwarf2_abbrevs[hash_number] = cur_abbrev;
8379
8380 /* Get next abbreviation.
8381 Under Irix6 the abbreviations for a compilation unit are not
8382 always properly terminated with an abbrev number of 0.
8383 Exit loop if we encounter an abbreviation which we have
8384 already read (which means we are about to read the abbreviations
8385 for the next compile unit) or if the end of the abbreviation
8386 table is reached. */
8387 if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer)
8388 >= dwarf2_per_objfile->abbrev.size)
8389 break;
8390 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8391 abbrev_ptr += bytes_read;
8392 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
8393 break;
8394 }
8395
8396 xfree (cur_attrs);
8397 }
8398
8399 /* Release the memory used by the abbrev table for a compilation unit. */
8400
8401 static void
8402 dwarf2_free_abbrev_table (void *ptr_to_cu)
8403 {
8404 struct dwarf2_cu *cu = ptr_to_cu;
8405
8406 obstack_free (&cu->abbrev_obstack, NULL);
8407 cu->dwarf2_abbrevs = NULL;
8408 }
8409
8410 /* Lookup an abbrev_info structure in the abbrev hash table. */
8411
8412 static struct abbrev_info *
8413 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
8414 {
8415 unsigned int hash_number;
8416 struct abbrev_info *abbrev;
8417
8418 hash_number = number % ABBREV_HASH_SIZE;
8419 abbrev = cu->dwarf2_abbrevs[hash_number];
8420
8421 while (abbrev)
8422 {
8423 if (abbrev->number == number)
8424 return abbrev;
8425 else
8426 abbrev = abbrev->next;
8427 }
8428 return NULL;
8429 }
8430
8431 /* Returns nonzero if TAG represents a type that we might generate a partial
8432 symbol for. */
8433
8434 static int
8435 is_type_tag_for_partial (int tag)
8436 {
8437 switch (tag)
8438 {
8439 #if 0
8440 /* Some types that would be reasonable to generate partial symbols for,
8441 that we don't at present. */
8442 case DW_TAG_array_type:
8443 case DW_TAG_file_type:
8444 case DW_TAG_ptr_to_member_type:
8445 case DW_TAG_set_type:
8446 case DW_TAG_string_type:
8447 case DW_TAG_subroutine_type:
8448 #endif
8449 case DW_TAG_base_type:
8450 case DW_TAG_class_type:
8451 case DW_TAG_interface_type:
8452 case DW_TAG_enumeration_type:
8453 case DW_TAG_structure_type:
8454 case DW_TAG_subrange_type:
8455 case DW_TAG_typedef:
8456 case DW_TAG_union_type:
8457 return 1;
8458 default:
8459 return 0;
8460 }
8461 }
8462
8463 /* Load all DIEs that are interesting for partial symbols into memory. */
8464
8465 static struct partial_die_info *
8466 load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
8467 int building_psymtab, struct dwarf2_cu *cu)
8468 {
8469 struct partial_die_info *part_die;
8470 struct partial_die_info *parent_die, *last_die, *first_die = NULL;
8471 struct abbrev_info *abbrev;
8472 unsigned int bytes_read;
8473 unsigned int load_all = 0;
8474
8475 int nesting_level = 1;
8476
8477 parent_die = NULL;
8478 last_die = NULL;
8479
8480 if (cu->per_cu && cu->per_cu->load_all_dies)
8481 load_all = 1;
8482
8483 cu->partial_dies
8484 = htab_create_alloc_ex (cu->header.length / 12,
8485 partial_die_hash,
8486 partial_die_eq,
8487 NULL,
8488 &cu->comp_unit_obstack,
8489 hashtab_obstack_allocate,
8490 dummy_obstack_deallocate);
8491
8492 part_die = obstack_alloc (&cu->comp_unit_obstack,
8493 sizeof (struct partial_die_info));
8494
8495 while (1)
8496 {
8497 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
8498
8499 /* A NULL abbrev means the end of a series of children. */
8500 if (abbrev == NULL)
8501 {
8502 if (--nesting_level == 0)
8503 {
8504 /* PART_DIE was probably the last thing allocated on the
8505 comp_unit_obstack, so we could call obstack_free
8506 here. We don't do that because the waste is small,
8507 and will be cleaned up when we're done with this
8508 compilation unit. This way, we're also more robust
8509 against other users of the comp_unit_obstack. */
8510 return first_die;
8511 }
8512 info_ptr += bytes_read;
8513 last_die = parent_die;
8514 parent_die = parent_die->die_parent;
8515 continue;
8516 }
8517
8518 /* Check for template arguments. We never save these; if
8519 they're seen, we just mark the parent, and go on our way. */
8520 if (parent_die != NULL
8521 && cu->language == language_cplus
8522 && (abbrev->tag == DW_TAG_template_type_param
8523 || abbrev->tag == DW_TAG_template_value_param))
8524 {
8525 parent_die->has_template_arguments = 1;
8526
8527 if (!load_all)
8528 {
8529 /* We don't need a partial DIE for the template argument. */
8530 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev,
8531 cu);
8532 continue;
8533 }
8534 }
8535
8536 /* We only recurse into subprograms looking for template arguments.
8537 Skip their other children. */
8538 if (!load_all
8539 && cu->language == language_cplus
8540 && parent_die != NULL
8541 && parent_die->tag == DW_TAG_subprogram)
8542 {
8543 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
8544 continue;
8545 }
8546
8547 /* Check whether this DIE is interesting enough to save. Normally
8548 we would not be interested in members here, but there may be
8549 later variables referencing them via DW_AT_specification (for
8550 static members). */
8551 if (!load_all
8552 && !is_type_tag_for_partial (abbrev->tag)
8553 && abbrev->tag != DW_TAG_enumerator
8554 && abbrev->tag != DW_TAG_subprogram
8555 && abbrev->tag != DW_TAG_lexical_block
8556 && abbrev->tag != DW_TAG_variable
8557 && abbrev->tag != DW_TAG_namespace
8558 && abbrev->tag != DW_TAG_module
8559 && abbrev->tag != DW_TAG_member)
8560 {
8561 /* Otherwise we skip to the next sibling, if any. */
8562 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
8563 continue;
8564 }
8565
8566 info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd,
8567 buffer, info_ptr, cu);
8568
8569 /* This two-pass algorithm for processing partial symbols has a
8570 high cost in cache pressure. Thus, handle some simple cases
8571 here which cover the majority of C partial symbols. DIEs
8572 which neither have specification tags in them, nor could have
8573 specification tags elsewhere pointing at them, can simply be
8574 processed and discarded.
8575
8576 This segment is also optional; scan_partial_symbols and
8577 add_partial_symbol will handle these DIEs if we chain
8578 them in normally. When compilers which do not emit large
8579 quantities of duplicate debug information are more common,
8580 this code can probably be removed. */
8581
8582 /* Any complete simple types at the top level (pretty much all
8583 of them, for a language without namespaces), can be processed
8584 directly. */
8585 if (parent_die == NULL
8586 && part_die->has_specification == 0
8587 && part_die->is_declaration == 0
8588 && (part_die->tag == DW_TAG_typedef
8589 || part_die->tag == DW_TAG_base_type
8590 || part_die->tag == DW_TAG_subrange_type))
8591 {
8592 if (building_psymtab && part_die->name != NULL)
8593 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
8594 VAR_DOMAIN, LOC_TYPEDEF,
8595 &cu->objfile->static_psymbols,
8596 0, (CORE_ADDR) 0, cu->language, cu->objfile);
8597 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
8598 continue;
8599 }
8600
8601 /* If we're at the second level, and we're an enumerator, and
8602 our parent has no specification (meaning possibly lives in a
8603 namespace elsewhere), then we can add the partial symbol now
8604 instead of queueing it. */
8605 if (part_die->tag == DW_TAG_enumerator
8606 && parent_die != NULL
8607 && parent_die->die_parent == NULL
8608 && parent_die->tag == DW_TAG_enumeration_type
8609 && parent_die->has_specification == 0)
8610 {
8611 if (part_die->name == NULL)
8612 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
8613 else if (building_psymtab)
8614 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
8615 VAR_DOMAIN, LOC_CONST,
8616 (cu->language == language_cplus
8617 || cu->language == language_java)
8618 ? &cu->objfile->global_psymbols
8619 : &cu->objfile->static_psymbols,
8620 0, (CORE_ADDR) 0, cu->language, cu->objfile);
8621
8622 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
8623 continue;
8624 }
8625
8626 /* We'll save this DIE so link it in. */
8627 part_die->die_parent = parent_die;
8628 part_die->die_sibling = NULL;
8629 part_die->die_child = NULL;
8630
8631 if (last_die && last_die == parent_die)
8632 last_die->die_child = part_die;
8633 else if (last_die)
8634 last_die->die_sibling = part_die;
8635
8636 last_die = part_die;
8637
8638 if (first_die == NULL)
8639 first_die = part_die;
8640
8641 /* Maybe add the DIE to the hash table. Not all DIEs that we
8642 find interesting need to be in the hash table, because we
8643 also have the parent/sibling/child chains; only those that we
8644 might refer to by offset later during partial symbol reading.
8645
8646 For now this means things that might have be the target of a
8647 DW_AT_specification, DW_AT_abstract_origin, or
8648 DW_AT_extension. DW_AT_extension will refer only to
8649 namespaces; DW_AT_abstract_origin refers to functions (and
8650 many things under the function DIE, but we do not recurse
8651 into function DIEs during partial symbol reading) and
8652 possibly variables as well; DW_AT_specification refers to
8653 declarations. Declarations ought to have the DW_AT_declaration
8654 flag. It happens that GCC forgets to put it in sometimes, but
8655 only for functions, not for types.
8656
8657 Adding more things than necessary to the hash table is harmless
8658 except for the performance cost. Adding too few will result in
8659 wasted time in find_partial_die, when we reread the compilation
8660 unit with load_all_dies set. */
8661
8662 if (load_all
8663 || abbrev->tag == DW_TAG_subprogram
8664 || abbrev->tag == DW_TAG_variable
8665 || abbrev->tag == DW_TAG_namespace
8666 || part_die->is_declaration)
8667 {
8668 void **slot;
8669
8670 slot = htab_find_slot_with_hash (cu->partial_dies, part_die,
8671 part_die->offset, INSERT);
8672 *slot = part_die;
8673 }
8674
8675 part_die = obstack_alloc (&cu->comp_unit_obstack,
8676 sizeof (struct partial_die_info));
8677
8678 /* For some DIEs we want to follow their children (if any). For C
8679 we have no reason to follow the children of structures; for other
8680 languages we have to, so that we can get at method physnames
8681 to infer fully qualified class names, for DW_AT_specification,
8682 and for C++ template arguments. For C++, we also look one level
8683 inside functions to find template arguments (if the name of the
8684 function does not already contain the template arguments).
8685
8686 For Ada, we need to scan the children of subprograms and lexical
8687 blocks as well because Ada allows the definition of nested
8688 entities that could be interesting for the debugger, such as
8689 nested subprograms for instance. */
8690 if (last_die->has_children
8691 && (load_all
8692 || last_die->tag == DW_TAG_namespace
8693 || last_die->tag == DW_TAG_module
8694 || last_die->tag == DW_TAG_enumeration_type
8695 || (cu->language == language_cplus
8696 && last_die->tag == DW_TAG_subprogram
8697 && (last_die->name == NULL
8698 || strchr (last_die->name, '<') == NULL))
8699 || (cu->language != language_c
8700 && (last_die->tag == DW_TAG_class_type
8701 || last_die->tag == DW_TAG_interface_type
8702 || last_die->tag == DW_TAG_structure_type
8703 || last_die->tag == DW_TAG_union_type))
8704 || (cu->language == language_ada
8705 && (last_die->tag == DW_TAG_subprogram
8706 || last_die->tag == DW_TAG_lexical_block))))
8707 {
8708 nesting_level++;
8709 parent_die = last_die;
8710 continue;
8711 }
8712
8713 /* Otherwise we skip to the next sibling, if any. */
8714 info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu);
8715
8716 /* Back to the top, do it again. */
8717 }
8718 }
8719
8720 /* Read a minimal amount of information into the minimal die structure. */
8721
8722 static gdb_byte *
8723 read_partial_die (struct partial_die_info *part_die,
8724 struct abbrev_info *abbrev,
8725 unsigned int abbrev_len, bfd *abfd,
8726 gdb_byte *buffer, gdb_byte *info_ptr,
8727 struct dwarf2_cu *cu)
8728 {
8729 unsigned int i;
8730 struct attribute attr;
8731 int has_low_pc_attr = 0;
8732 int has_high_pc_attr = 0;
8733
8734 memset (part_die, 0, sizeof (struct partial_die_info));
8735
8736 part_die->offset = info_ptr - buffer;
8737
8738 info_ptr += abbrev_len;
8739
8740 if (abbrev == NULL)
8741 return info_ptr;
8742
8743 part_die->tag = abbrev->tag;
8744 part_die->has_children = abbrev->has_children;
8745
8746 for (i = 0; i < abbrev->num_attrs; ++i)
8747 {
8748 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
8749
8750 /* Store the data if it is of an attribute we want to keep in a
8751 partial symbol table. */
8752 switch (attr.name)
8753 {
8754 case DW_AT_name:
8755 switch (part_die->tag)
8756 {
8757 case DW_TAG_compile_unit:
8758 case DW_TAG_type_unit:
8759 /* Compilation units have a DW_AT_name that is a filename, not
8760 a source language identifier. */
8761 case DW_TAG_enumeration_type:
8762 case DW_TAG_enumerator:
8763 /* These tags always have simple identifiers already; no need
8764 to canonicalize them. */
8765 part_die->name = DW_STRING (&attr);
8766 break;
8767 default:
8768 part_die->name
8769 = dwarf2_canonicalize_name (DW_STRING (&attr), cu,
8770 &cu->objfile->objfile_obstack);
8771 break;
8772 }
8773 break;
8774 case DW_AT_linkage_name:
8775 case DW_AT_MIPS_linkage_name:
8776 /* Note that both forms of linkage name might appear. We
8777 assume they will be the same, and we only store the last
8778 one we see. */
8779 if (cu->language == language_ada)
8780 part_die->name = DW_STRING (&attr);
8781 break;
8782 case DW_AT_low_pc:
8783 has_low_pc_attr = 1;
8784 part_die->lowpc = DW_ADDR (&attr);
8785 break;
8786 case DW_AT_high_pc:
8787 has_high_pc_attr = 1;
8788 part_die->highpc = DW_ADDR (&attr);
8789 break;
8790 case DW_AT_location:
8791 /* Support the .debug_loc offsets */
8792 if (attr_form_is_block (&attr))
8793 {
8794 part_die->locdesc = DW_BLOCK (&attr);
8795 }
8796 else if (attr_form_is_section_offset (&attr))
8797 {
8798 dwarf2_complex_location_expr_complaint ();
8799 }
8800 else
8801 {
8802 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8803 "partial symbol information");
8804 }
8805 break;
8806 case DW_AT_external:
8807 part_die->is_external = DW_UNSND (&attr);
8808 break;
8809 case DW_AT_declaration:
8810 part_die->is_declaration = DW_UNSND (&attr);
8811 break;
8812 case DW_AT_type:
8813 part_die->has_type = 1;
8814 break;
8815 case DW_AT_abstract_origin:
8816 case DW_AT_specification:
8817 case DW_AT_extension:
8818 part_die->has_specification = 1;
8819 part_die->spec_offset = dwarf2_get_ref_die_offset (&attr);
8820 break;
8821 case DW_AT_sibling:
8822 /* Ignore absolute siblings, they might point outside of
8823 the current compile unit. */
8824 if (attr.form == DW_FORM_ref_addr)
8825 complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling"));
8826 else
8827 part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr);
8828 break;
8829 case DW_AT_byte_size:
8830 part_die->has_byte_size = 1;
8831 break;
8832 case DW_AT_calling_convention:
8833 /* DWARF doesn't provide a way to identify a program's source-level
8834 entry point. DW_AT_calling_convention attributes are only meant
8835 to describe functions' calling conventions.
8836
8837 However, because it's a necessary piece of information in
8838 Fortran, and because DW_CC_program is the only piece of debugging
8839 information whose definition refers to a 'main program' at all,
8840 several compilers have begun marking Fortran main programs with
8841 DW_CC_program --- even when those functions use the standard
8842 calling conventions.
8843
8844 So until DWARF specifies a way to provide this information and
8845 compilers pick up the new representation, we'll support this
8846 practice. */
8847 if (DW_UNSND (&attr) == DW_CC_program
8848 && cu->language == language_fortran)
8849 set_main_name (part_die->name);
8850 break;
8851 default:
8852 break;
8853 }
8854 }
8855
8856 /* When using the GNU linker, .gnu.linkonce. sections are used to
8857 eliminate duplicate copies of functions and vtables and such.
8858 The linker will arbitrarily choose one and discard the others.
8859 The AT_*_pc values for such functions refer to local labels in
8860 these sections. If the section from that file was discarded, the
8861 labels are not in the output, so the relocs get a value of 0.
8862 If this is a discarded function, mark the pc bounds as invalid,
8863 so that GDB will ignore it. */
8864 if (has_low_pc_attr && has_high_pc_attr
8865 && part_die->lowpc < part_die->highpc
8866 && (part_die->lowpc != 0
8867 || dwarf2_per_objfile->has_section_at_zero))
8868 part_die->has_pc_info = 1;
8869
8870 return info_ptr;
8871 }
8872
8873 /* Find a cached partial DIE at OFFSET in CU. */
8874
8875 static struct partial_die_info *
8876 find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu)
8877 {
8878 struct partial_die_info *lookup_die = NULL;
8879 struct partial_die_info part_die;
8880
8881 part_die.offset = offset;
8882 lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset);
8883
8884 return lookup_die;
8885 }
8886
8887 /* Find a partial DIE at OFFSET, which may or may not be in CU,
8888 except in the case of .debug_types DIEs which do not reference
8889 outside their CU (they do however referencing other types via
8890 DW_FORM_sig8). */
8891
8892 static struct partial_die_info *
8893 find_partial_die (unsigned int offset, struct dwarf2_cu *cu)
8894 {
8895 struct dwarf2_per_cu_data *per_cu = NULL;
8896 struct partial_die_info *pd = NULL;
8897
8898 if (cu->per_cu->from_debug_types)
8899 {
8900 pd = find_partial_die_in_comp_unit (offset, cu);
8901 if (pd != NULL)
8902 return pd;
8903 goto not_found;
8904 }
8905
8906 if (offset_in_cu_p (&cu->header, offset))
8907 {
8908 pd = find_partial_die_in_comp_unit (offset, cu);
8909 if (pd != NULL)
8910 return pd;
8911 }
8912
8913 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
8914
8915 if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL)
8916 load_partial_comp_unit (per_cu, cu->objfile);
8917
8918 per_cu->cu->last_used = 0;
8919 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
8920
8921 if (pd == NULL && per_cu->load_all_dies == 0)
8922 {
8923 struct cleanup *back_to;
8924 struct partial_die_info comp_unit_die;
8925 struct abbrev_info *abbrev;
8926 unsigned int bytes_read;
8927 char *info_ptr;
8928
8929 per_cu->load_all_dies = 1;
8930
8931 /* Re-read the DIEs. */
8932 back_to = make_cleanup (null_cleanup, 0);
8933 if (per_cu->cu->dwarf2_abbrevs == NULL)
8934 {
8935 dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu);
8936 make_cleanup (dwarf2_free_abbrev_table, per_cu->cu);
8937 }
8938 info_ptr = (dwarf2_per_objfile->info.buffer
8939 + per_cu->cu->header.offset
8940 + per_cu->cu->header.first_die_offset);
8941 abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu);
8942 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
8943 per_cu->cu->objfile->obfd,
8944 dwarf2_per_objfile->info.buffer, info_ptr,
8945 per_cu->cu);
8946 if (comp_unit_die.has_children)
8947 load_partial_dies (per_cu->cu->objfile->obfd,
8948 dwarf2_per_objfile->info.buffer, info_ptr,
8949 0, per_cu->cu);
8950 do_cleanups (back_to);
8951
8952 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
8953 }
8954
8955 not_found:
8956
8957 if (pd == NULL)
8958 internal_error (__FILE__, __LINE__,
8959 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
8960 offset, bfd_get_filename (cu->objfile->obfd));
8961 return pd;
8962 }
8963
8964 /* Adjust PART_DIE before generating a symbol for it. This function
8965 may set the is_external flag or change the DIE's name. */
8966
8967 static void
8968 fixup_partial_die (struct partial_die_info *part_die,
8969 struct dwarf2_cu *cu)
8970 {
8971 /* If we found a reference attribute and the DIE has no name, try
8972 to find a name in the referred to DIE. */
8973
8974 if (part_die->name == NULL && part_die->has_specification)
8975 {
8976 struct partial_die_info *spec_die;
8977
8978 spec_die = find_partial_die (part_die->spec_offset, cu);
8979
8980 fixup_partial_die (spec_die, cu);
8981
8982 if (spec_die->name)
8983 {
8984 part_die->name = spec_die->name;
8985
8986 /* Copy DW_AT_external attribute if it is set. */
8987 if (spec_die->is_external)
8988 part_die->is_external = spec_die->is_external;
8989 }
8990 }
8991
8992 /* Set default names for some unnamed DIEs. */
8993 if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type
8994 || part_die->tag == DW_TAG_class_type))
8995 part_die->name = "(anonymous class)";
8996
8997 if (part_die->name == NULL && part_die->tag == DW_TAG_namespace)
8998 part_die->name = "(anonymous namespace)";
8999
9000 if (part_die->tag == DW_TAG_structure_type
9001 || part_die->tag == DW_TAG_class_type
9002 || part_die->tag == DW_TAG_union_type)
9003 guess_structure_name (part_die, cu);
9004 }
9005
9006 /* Read an attribute value described by an attribute form. */
9007
9008 static gdb_byte *
9009 read_attribute_value (struct attribute *attr, unsigned form,
9010 bfd *abfd, gdb_byte *info_ptr,
9011 struct dwarf2_cu *cu)
9012 {
9013 struct comp_unit_head *cu_header = &cu->header;
9014 unsigned int bytes_read;
9015 struct dwarf_block *blk;
9016
9017 attr->form = form;
9018 switch (form)
9019 {
9020 case DW_FORM_ref_addr:
9021 if (cu->header.version == 2)
9022 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
9023 else
9024 DW_ADDR (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
9025 info_ptr += bytes_read;
9026 break;
9027 case DW_FORM_addr:
9028 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
9029 info_ptr += bytes_read;
9030 break;
9031 case DW_FORM_block2:
9032 blk = dwarf_alloc_block (cu);
9033 blk->size = read_2_bytes (abfd, info_ptr);
9034 info_ptr += 2;
9035 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
9036 info_ptr += blk->size;
9037 DW_BLOCK (attr) = blk;
9038 break;
9039 case DW_FORM_block4:
9040 blk = dwarf_alloc_block (cu);
9041 blk->size = read_4_bytes (abfd, info_ptr);
9042 info_ptr += 4;
9043 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
9044 info_ptr += blk->size;
9045 DW_BLOCK (attr) = blk;
9046 break;
9047 case DW_FORM_data2:
9048 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
9049 info_ptr += 2;
9050 break;
9051 case DW_FORM_data4:
9052 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
9053 info_ptr += 4;
9054 break;
9055 case DW_FORM_data8:
9056 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
9057 info_ptr += 8;
9058 break;
9059 case DW_FORM_sec_offset:
9060 DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
9061 info_ptr += bytes_read;
9062 break;
9063 case DW_FORM_string:
9064 DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read);
9065 DW_STRING_IS_CANONICAL (attr) = 0;
9066 info_ptr += bytes_read;
9067 break;
9068 case DW_FORM_strp:
9069 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
9070 &bytes_read);
9071 DW_STRING_IS_CANONICAL (attr) = 0;
9072 info_ptr += bytes_read;
9073 break;
9074 case DW_FORM_exprloc:
9075 case DW_FORM_block:
9076 blk = dwarf_alloc_block (cu);
9077 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
9078 info_ptr += bytes_read;
9079 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
9080 info_ptr += blk->size;
9081 DW_BLOCK (attr) = blk;
9082 break;
9083 case DW_FORM_block1:
9084 blk = dwarf_alloc_block (cu);
9085 blk->size = read_1_byte (abfd, info_ptr);
9086 info_ptr += 1;
9087 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
9088 info_ptr += blk->size;
9089 DW_BLOCK (attr) = blk;
9090 break;
9091 case DW_FORM_data1:
9092 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
9093 info_ptr += 1;
9094 break;
9095 case DW_FORM_flag:
9096 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
9097 info_ptr += 1;
9098 break;
9099 case DW_FORM_flag_present:
9100 DW_UNSND (attr) = 1;
9101 break;
9102 case DW_FORM_sdata:
9103 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
9104 info_ptr += bytes_read;
9105 break;
9106 case DW_FORM_udata:
9107 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
9108 info_ptr += bytes_read;
9109 break;
9110 case DW_FORM_ref1:
9111 DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr);
9112 info_ptr += 1;
9113 break;
9114 case DW_FORM_ref2:
9115 DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr);
9116 info_ptr += 2;
9117 break;
9118 case DW_FORM_ref4:
9119 DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr);
9120 info_ptr += 4;
9121 break;
9122 case DW_FORM_ref8:
9123 DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr);
9124 info_ptr += 8;
9125 break;
9126 case DW_FORM_sig8:
9127 /* Convert the signature to something we can record in DW_UNSND
9128 for later lookup.
9129 NOTE: This is NULL if the type wasn't found. */
9130 DW_SIGNATURED_TYPE (attr) =
9131 lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr));
9132 info_ptr += 8;
9133 break;
9134 case DW_FORM_ref_udata:
9135 DW_ADDR (attr) = (cu->header.offset
9136 + read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
9137 info_ptr += bytes_read;
9138 break;
9139 case DW_FORM_indirect:
9140 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
9141 info_ptr += bytes_read;
9142 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
9143 break;
9144 default:
9145 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
9146 dwarf_form_name (form),
9147 bfd_get_filename (abfd));
9148 }
9149
9150 /* We have seen instances where the compiler tried to emit a byte
9151 size attribute of -1 which ended up being encoded as an unsigned
9152 0xffffffff. Although 0xffffffff is technically a valid size value,
9153 an object of this size seems pretty unlikely so we can relatively
9154 safely treat these cases as if the size attribute was invalid and
9155 treat them as zero by default. */
9156 if (attr->name == DW_AT_byte_size
9157 && form == DW_FORM_data4
9158 && DW_UNSND (attr) >= 0xffffffff)
9159 {
9160 complaint
9161 (&symfile_complaints,
9162 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
9163 hex_string (DW_UNSND (attr)));
9164 DW_UNSND (attr) = 0;
9165 }
9166
9167 return info_ptr;
9168 }
9169
9170 /* Read an attribute described by an abbreviated attribute. */
9171
9172 static gdb_byte *
9173 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
9174 bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu)
9175 {
9176 attr->name = abbrev->name;
9177 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
9178 }
9179
9180 /* read dwarf information from a buffer */
9181
9182 static unsigned int
9183 read_1_byte (bfd *abfd, gdb_byte *buf)
9184 {
9185 return bfd_get_8 (abfd, buf);
9186 }
9187
9188 static int
9189 read_1_signed_byte (bfd *abfd, gdb_byte *buf)
9190 {
9191 return bfd_get_signed_8 (abfd, buf);
9192 }
9193
9194 static unsigned int
9195 read_2_bytes (bfd *abfd, gdb_byte *buf)
9196 {
9197 return bfd_get_16 (abfd, buf);
9198 }
9199
9200 static int
9201 read_2_signed_bytes (bfd *abfd, gdb_byte *buf)
9202 {
9203 return bfd_get_signed_16 (abfd, buf);
9204 }
9205
9206 static unsigned int
9207 read_4_bytes (bfd *abfd, gdb_byte *buf)
9208 {
9209 return bfd_get_32 (abfd, buf);
9210 }
9211
9212 static int
9213 read_4_signed_bytes (bfd *abfd, gdb_byte *buf)
9214 {
9215 return bfd_get_signed_32 (abfd, buf);
9216 }
9217
9218 static ULONGEST
9219 read_8_bytes (bfd *abfd, gdb_byte *buf)
9220 {
9221 return bfd_get_64 (abfd, buf);
9222 }
9223
9224 static CORE_ADDR
9225 read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu,
9226 unsigned int *bytes_read)
9227 {
9228 struct comp_unit_head *cu_header = &cu->header;
9229 CORE_ADDR retval = 0;
9230
9231 if (cu_header->signed_addr_p)
9232 {
9233 switch (cu_header->addr_size)
9234 {
9235 case 2:
9236 retval = bfd_get_signed_16 (abfd, buf);
9237 break;
9238 case 4:
9239 retval = bfd_get_signed_32 (abfd, buf);
9240 break;
9241 case 8:
9242 retval = bfd_get_signed_64 (abfd, buf);
9243 break;
9244 default:
9245 internal_error (__FILE__, __LINE__,
9246 _("read_address: bad switch, signed [in module %s]"),
9247 bfd_get_filename (abfd));
9248 }
9249 }
9250 else
9251 {
9252 switch (cu_header->addr_size)
9253 {
9254 case 2:
9255 retval = bfd_get_16 (abfd, buf);
9256 break;
9257 case 4:
9258 retval = bfd_get_32 (abfd, buf);
9259 break;
9260 case 8:
9261 retval = bfd_get_64 (abfd, buf);
9262 break;
9263 default:
9264 internal_error (__FILE__, __LINE__,
9265 _("read_address: bad switch, unsigned [in module %s]"),
9266 bfd_get_filename (abfd));
9267 }
9268 }
9269
9270 *bytes_read = cu_header->addr_size;
9271 return retval;
9272 }
9273
9274 /* Read the initial length from a section. The (draft) DWARF 3
9275 specification allows the initial length to take up either 4 bytes
9276 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
9277 bytes describe the length and all offsets will be 8 bytes in length
9278 instead of 4.
9279
9280 An older, non-standard 64-bit format is also handled by this
9281 function. The older format in question stores the initial length
9282 as an 8-byte quantity without an escape value. Lengths greater
9283 than 2^32 aren't very common which means that the initial 4 bytes
9284 is almost always zero. Since a length value of zero doesn't make
9285 sense for the 32-bit format, this initial zero can be considered to
9286 be an escape value which indicates the presence of the older 64-bit
9287 format. As written, the code can't detect (old format) lengths
9288 greater than 4GB. If it becomes necessary to handle lengths
9289 somewhat larger than 4GB, we could allow other small values (such
9290 as the non-sensical values of 1, 2, and 3) to also be used as
9291 escape values indicating the presence of the old format.
9292
9293 The value returned via bytes_read should be used to increment the
9294 relevant pointer after calling read_initial_length().
9295
9296 [ Note: read_initial_length() and read_offset() are based on the
9297 document entitled "DWARF Debugging Information Format", revision
9298 3, draft 8, dated November 19, 2001. This document was obtained
9299 from:
9300
9301 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
9302
9303 This document is only a draft and is subject to change. (So beware.)
9304
9305 Details regarding the older, non-standard 64-bit format were
9306 determined empirically by examining 64-bit ELF files produced by
9307 the SGI toolchain on an IRIX 6.5 machine.
9308
9309 - Kevin, July 16, 2002
9310 ] */
9311
9312 static LONGEST
9313 read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read)
9314 {
9315 LONGEST length = bfd_get_32 (abfd, buf);
9316
9317 if (length == 0xffffffff)
9318 {
9319 length = bfd_get_64 (abfd, buf + 4);
9320 *bytes_read = 12;
9321 }
9322 else if (length == 0)
9323 {
9324 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
9325 length = bfd_get_64 (abfd, buf);
9326 *bytes_read = 8;
9327 }
9328 else
9329 {
9330 *bytes_read = 4;
9331 }
9332
9333 return length;
9334 }
9335
9336 /* Cover function for read_initial_length.
9337 Returns the length of the object at BUF, and stores the size of the
9338 initial length in *BYTES_READ and stores the size that offsets will be in
9339 *OFFSET_SIZE.
9340 If the initial length size is not equivalent to that specified in
9341 CU_HEADER then issue a complaint.
9342 This is useful when reading non-comp-unit headers. */
9343
9344 static LONGEST
9345 read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf,
9346 const struct comp_unit_head *cu_header,
9347 unsigned int *bytes_read,
9348 unsigned int *offset_size)
9349 {
9350 LONGEST length = read_initial_length (abfd, buf, bytes_read);
9351
9352 gdb_assert (cu_header->initial_length_size == 4
9353 || cu_header->initial_length_size == 8
9354 || cu_header->initial_length_size == 12);
9355
9356 if (cu_header->initial_length_size != *bytes_read)
9357 complaint (&symfile_complaints,
9358 _("intermixed 32-bit and 64-bit DWARF sections"));
9359
9360 *offset_size = (*bytes_read == 4) ? 4 : 8;
9361 return length;
9362 }
9363
9364 /* Read an offset from the data stream. The size of the offset is
9365 given by cu_header->offset_size. */
9366
9367 static LONGEST
9368 read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header,
9369 unsigned int *bytes_read)
9370 {
9371 LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size);
9372
9373 *bytes_read = cu_header->offset_size;
9374 return offset;
9375 }
9376
9377 /* Read an offset from the data stream. */
9378
9379 static LONGEST
9380 read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size)
9381 {
9382 LONGEST retval = 0;
9383
9384 switch (offset_size)
9385 {
9386 case 4:
9387 retval = bfd_get_32 (abfd, buf);
9388 break;
9389 case 8:
9390 retval = bfd_get_64 (abfd, buf);
9391 break;
9392 default:
9393 internal_error (__FILE__, __LINE__,
9394 _("read_offset_1: bad switch [in module %s]"),
9395 bfd_get_filename (abfd));
9396 }
9397
9398 return retval;
9399 }
9400
9401 static gdb_byte *
9402 read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size)
9403 {
9404 /* If the size of a host char is 8 bits, we can return a pointer
9405 to the buffer, otherwise we have to copy the data to a buffer
9406 allocated on the temporary obstack. */
9407 gdb_assert (HOST_CHAR_BIT == 8);
9408 return buf;
9409 }
9410
9411 static char *
9412 read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
9413 {
9414 /* If the size of a host char is 8 bits, we can return a pointer
9415 to the string, otherwise we have to copy the string to a buffer
9416 allocated on the temporary obstack. */
9417 gdb_assert (HOST_CHAR_BIT == 8);
9418 if (*buf == '\0')
9419 {
9420 *bytes_read_ptr = 1;
9421 return NULL;
9422 }
9423 *bytes_read_ptr = strlen ((char *) buf) + 1;
9424 return (char *) buf;
9425 }
9426
9427 static char *
9428 read_indirect_string (bfd *abfd, gdb_byte *buf,
9429 const struct comp_unit_head *cu_header,
9430 unsigned int *bytes_read_ptr)
9431 {
9432 LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr);
9433
9434 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str);
9435 if (dwarf2_per_objfile->str.buffer == NULL)
9436 {
9437 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
9438 bfd_get_filename (abfd));
9439 return NULL;
9440 }
9441 if (str_offset >= dwarf2_per_objfile->str.size)
9442 {
9443 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
9444 bfd_get_filename (abfd));
9445 return NULL;
9446 }
9447 gdb_assert (HOST_CHAR_BIT == 8);
9448 if (dwarf2_per_objfile->str.buffer[str_offset] == '\0')
9449 return NULL;
9450 return (char *) (dwarf2_per_objfile->str.buffer + str_offset);
9451 }
9452
9453 static unsigned long
9454 read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
9455 {
9456 unsigned long result;
9457 unsigned int num_read;
9458 int i, shift;
9459 unsigned char byte;
9460
9461 result = 0;
9462 shift = 0;
9463 num_read = 0;
9464 i = 0;
9465 while (1)
9466 {
9467 byte = bfd_get_8 (abfd, buf);
9468 buf++;
9469 num_read++;
9470 result |= ((unsigned long)(byte & 127) << shift);
9471 if ((byte & 128) == 0)
9472 {
9473 break;
9474 }
9475 shift += 7;
9476 }
9477 *bytes_read_ptr = num_read;
9478 return result;
9479 }
9480
9481 static long
9482 read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
9483 {
9484 long result;
9485 int i, shift, num_read;
9486 unsigned char byte;
9487
9488 result = 0;
9489 shift = 0;
9490 num_read = 0;
9491 i = 0;
9492 while (1)
9493 {
9494 byte = bfd_get_8 (abfd, buf);
9495 buf++;
9496 num_read++;
9497 result |= ((long)(byte & 127) << shift);
9498 shift += 7;
9499 if ((byte & 128) == 0)
9500 {
9501 break;
9502 }
9503 }
9504 if ((shift < 8 * sizeof (result)) && (byte & 0x40))
9505 result |= -(((long)1) << shift);
9506 *bytes_read_ptr = num_read;
9507 return result;
9508 }
9509
9510 /* Return a pointer to just past the end of an LEB128 number in BUF. */
9511
9512 static gdb_byte *
9513 skip_leb128 (bfd *abfd, gdb_byte *buf)
9514 {
9515 int byte;
9516
9517 while (1)
9518 {
9519 byte = bfd_get_8 (abfd, buf);
9520 buf++;
9521 if ((byte & 128) == 0)
9522 return buf;
9523 }
9524 }
9525
9526 static void
9527 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
9528 {
9529 switch (lang)
9530 {
9531 case DW_LANG_C89:
9532 case DW_LANG_C99:
9533 case DW_LANG_C:
9534 cu->language = language_c;
9535 break;
9536 case DW_LANG_C_plus_plus:
9537 cu->language = language_cplus;
9538 break;
9539 case DW_LANG_D:
9540 cu->language = language_d;
9541 break;
9542 case DW_LANG_Fortran77:
9543 case DW_LANG_Fortran90:
9544 case DW_LANG_Fortran95:
9545 cu->language = language_fortran;
9546 break;
9547 case DW_LANG_Mips_Assembler:
9548 cu->language = language_asm;
9549 break;
9550 case DW_LANG_Java:
9551 cu->language = language_java;
9552 break;
9553 case DW_LANG_Ada83:
9554 case DW_LANG_Ada95:
9555 cu->language = language_ada;
9556 break;
9557 case DW_LANG_Modula2:
9558 cu->language = language_m2;
9559 break;
9560 case DW_LANG_Pascal83:
9561 cu->language = language_pascal;
9562 break;
9563 case DW_LANG_ObjC:
9564 cu->language = language_objc;
9565 break;
9566 case DW_LANG_Cobol74:
9567 case DW_LANG_Cobol85:
9568 default:
9569 cu->language = language_minimal;
9570 break;
9571 }
9572 cu->language_defn = language_def (cu->language);
9573 }
9574
9575 /* Return the named attribute or NULL if not there. */
9576
9577 static struct attribute *
9578 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
9579 {
9580 unsigned int i;
9581 struct attribute *spec = NULL;
9582
9583 for (i = 0; i < die->num_attrs; ++i)
9584 {
9585 if (die->attrs[i].name == name)
9586 return &die->attrs[i];
9587 if (die->attrs[i].name == DW_AT_specification
9588 || die->attrs[i].name == DW_AT_abstract_origin)
9589 spec = &die->attrs[i];
9590 }
9591
9592 if (spec)
9593 {
9594 die = follow_die_ref (die, spec, &cu);
9595 return dwarf2_attr (die, name, cu);
9596 }
9597
9598 return NULL;
9599 }
9600
9601 /* Return the named attribute or NULL if not there,
9602 but do not follow DW_AT_specification, etc.
9603 This is for use in contexts where we're reading .debug_types dies.
9604 Following DW_AT_specification, DW_AT_abstract_origin will take us
9605 back up the chain, and we want to go down. */
9606
9607 static struct attribute *
9608 dwarf2_attr_no_follow (struct die_info *die, unsigned int name,
9609 struct dwarf2_cu *cu)
9610 {
9611 unsigned int i;
9612
9613 for (i = 0; i < die->num_attrs; ++i)
9614 if (die->attrs[i].name == name)
9615 return &die->attrs[i];
9616
9617 return NULL;
9618 }
9619
9620 /* Return non-zero iff the attribute NAME is defined for the given DIE,
9621 and holds a non-zero value. This function should only be used for
9622 DW_FORM_flag or DW_FORM_flag_present attributes. */
9623
9624 static int
9625 dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
9626 {
9627 struct attribute *attr = dwarf2_attr (die, name, cu);
9628
9629 return (attr && DW_UNSND (attr));
9630 }
9631
9632 static int
9633 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
9634 {
9635 /* A DIE is a declaration if it has a DW_AT_declaration attribute
9636 which value is non-zero. However, we have to be careful with
9637 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
9638 (via dwarf2_flag_true_p) follows this attribute. So we may
9639 end up accidently finding a declaration attribute that belongs
9640 to a different DIE referenced by the specification attribute,
9641 even though the given DIE does not have a declaration attribute. */
9642 return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
9643 && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
9644 }
9645
9646 /* Return the die giving the specification for DIE, if there is
9647 one. *SPEC_CU is the CU containing DIE on input, and the CU
9648 containing the return value on output. If there is no
9649 specification, but there is an abstract origin, that is
9650 returned. */
9651
9652 static struct die_info *
9653 die_specification (struct die_info *die, struct dwarf2_cu **spec_cu)
9654 {
9655 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification,
9656 *spec_cu);
9657
9658 if (spec_attr == NULL)
9659 spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu);
9660
9661 if (spec_attr == NULL)
9662 return NULL;
9663 else
9664 return follow_die_ref (die, spec_attr, spec_cu);
9665 }
9666
9667 /* Free the line_header structure *LH, and any arrays and strings it
9668 refers to. */
9669 static void
9670 free_line_header (struct line_header *lh)
9671 {
9672 if (lh->standard_opcode_lengths)
9673 xfree (lh->standard_opcode_lengths);
9674
9675 /* Remember that all the lh->file_names[i].name pointers are
9676 pointers into debug_line_buffer, and don't need to be freed. */
9677 if (lh->file_names)
9678 xfree (lh->file_names);
9679
9680 /* Similarly for the include directory names. */
9681 if (lh->include_dirs)
9682 xfree (lh->include_dirs);
9683
9684 xfree (lh);
9685 }
9686
9687
9688 /* Add an entry to LH's include directory table. */
9689 static void
9690 add_include_dir (struct line_header *lh, char *include_dir)
9691 {
9692 /* Grow the array if necessary. */
9693 if (lh->include_dirs_size == 0)
9694 {
9695 lh->include_dirs_size = 1; /* for testing */
9696 lh->include_dirs = xmalloc (lh->include_dirs_size
9697 * sizeof (*lh->include_dirs));
9698 }
9699 else if (lh->num_include_dirs >= lh->include_dirs_size)
9700 {
9701 lh->include_dirs_size *= 2;
9702 lh->include_dirs = xrealloc (lh->include_dirs,
9703 (lh->include_dirs_size
9704 * sizeof (*lh->include_dirs)));
9705 }
9706
9707 lh->include_dirs[lh->num_include_dirs++] = include_dir;
9708 }
9709
9710
9711 /* Add an entry to LH's file name table. */
9712 static void
9713 add_file_name (struct line_header *lh,
9714 char *name,
9715 unsigned int dir_index,
9716 unsigned int mod_time,
9717 unsigned int length)
9718 {
9719 struct file_entry *fe;
9720
9721 /* Grow the array if necessary. */
9722 if (lh->file_names_size == 0)
9723 {
9724 lh->file_names_size = 1; /* for testing */
9725 lh->file_names = xmalloc (lh->file_names_size
9726 * sizeof (*lh->file_names));
9727 }
9728 else if (lh->num_file_names >= lh->file_names_size)
9729 {
9730 lh->file_names_size *= 2;
9731 lh->file_names = xrealloc (lh->file_names,
9732 (lh->file_names_size
9733 * sizeof (*lh->file_names)));
9734 }
9735
9736 fe = &lh->file_names[lh->num_file_names++];
9737 fe->name = name;
9738 fe->dir_index = dir_index;
9739 fe->mod_time = mod_time;
9740 fe->length = length;
9741 fe->included_p = 0;
9742 fe->symtab = NULL;
9743 }
9744
9745
9746 /* Read the statement program header starting at OFFSET in
9747 .debug_line, according to the endianness of ABFD. Return a pointer
9748 to a struct line_header, allocated using xmalloc.
9749
9750 NOTE: the strings in the include directory and file name tables of
9751 the returned object point into debug_line_buffer, and must not be
9752 freed. */
9753 static struct line_header *
9754 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
9755 struct dwarf2_cu *cu)
9756 {
9757 struct cleanup *back_to;
9758 struct line_header *lh;
9759 gdb_byte *line_ptr;
9760 unsigned int bytes_read, offset_size;
9761 int i;
9762 char *cur_dir, *cur_file;
9763
9764 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line);
9765 if (dwarf2_per_objfile->line.buffer == NULL)
9766 {
9767 complaint (&symfile_complaints, _("missing .debug_line section"));
9768 return 0;
9769 }
9770
9771 /* Make sure that at least there's room for the total_length field.
9772 That could be 12 bytes long, but we're just going to fudge that. */
9773 if (offset + 4 >= dwarf2_per_objfile->line.size)
9774 {
9775 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9776 return 0;
9777 }
9778
9779 lh = xmalloc (sizeof (*lh));
9780 memset (lh, 0, sizeof (*lh));
9781 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
9782 (void *) lh);
9783
9784 line_ptr = dwarf2_per_objfile->line.buffer + offset;
9785
9786 /* Read in the header. */
9787 lh->total_length =
9788 read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header,
9789 &bytes_read, &offset_size);
9790 line_ptr += bytes_read;
9791 if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer
9792 + dwarf2_per_objfile->line.size))
9793 {
9794 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9795 return 0;
9796 }
9797 lh->statement_program_end = line_ptr + lh->total_length;
9798 lh->version = read_2_bytes (abfd, line_ptr);
9799 line_ptr += 2;
9800 lh->header_length = read_offset_1 (abfd, line_ptr, offset_size);
9801 line_ptr += offset_size;
9802 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
9803 line_ptr += 1;
9804 if (lh->version >= 4)
9805 {
9806 lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr);
9807 line_ptr += 1;
9808 }
9809 else
9810 lh->maximum_ops_per_instruction = 1;
9811
9812 if (lh->maximum_ops_per_instruction == 0)
9813 {
9814 lh->maximum_ops_per_instruction = 1;
9815 complaint (&symfile_complaints,
9816 _("invalid maximum_ops_per_instruction in `.debug_line' section"));
9817 }
9818
9819 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
9820 line_ptr += 1;
9821 lh->line_base = read_1_signed_byte (abfd, line_ptr);
9822 line_ptr += 1;
9823 lh->line_range = read_1_byte (abfd, line_ptr);
9824 line_ptr += 1;
9825 lh->opcode_base = read_1_byte (abfd, line_ptr);
9826 line_ptr += 1;
9827 lh->standard_opcode_lengths
9828 = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0]));
9829
9830 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
9831 for (i = 1; i < lh->opcode_base; ++i)
9832 {
9833 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
9834 line_ptr += 1;
9835 }
9836
9837 /* Read directory table. */
9838 while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
9839 {
9840 line_ptr += bytes_read;
9841 add_include_dir (lh, cur_dir);
9842 }
9843 line_ptr += bytes_read;
9844
9845 /* Read file name table. */
9846 while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
9847 {
9848 unsigned int dir_index, mod_time, length;
9849
9850 line_ptr += bytes_read;
9851 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
9852 line_ptr += bytes_read;
9853 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
9854 line_ptr += bytes_read;
9855 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
9856 line_ptr += bytes_read;
9857
9858 add_file_name (lh, cur_file, dir_index, mod_time, length);
9859 }
9860 line_ptr += bytes_read;
9861 lh->statement_program_start = line_ptr;
9862
9863 if (line_ptr > (dwarf2_per_objfile->line.buffer
9864 + dwarf2_per_objfile->line.size))
9865 complaint (&symfile_complaints,
9866 _("line number info header doesn't fit in `.debug_line' section"));
9867
9868 discard_cleanups (back_to);
9869 return lh;
9870 }
9871
9872 /* This function exists to work around a bug in certain compilers
9873 (particularly GCC 2.95), in which the first line number marker of a
9874 function does not show up until after the prologue, right before
9875 the second line number marker. This function shifts ADDRESS down
9876 to the beginning of the function if necessary, and is called on
9877 addresses passed to record_line. */
9878
9879 static CORE_ADDR
9880 check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu)
9881 {
9882 struct function_range *fn;
9883
9884 /* Find the function_range containing address. */
9885 if (!cu->first_fn)
9886 return address;
9887
9888 if (!cu->cached_fn)
9889 cu->cached_fn = cu->first_fn;
9890
9891 fn = cu->cached_fn;
9892 while (fn)
9893 if (fn->lowpc <= address && fn->highpc > address)
9894 goto found;
9895 else
9896 fn = fn->next;
9897
9898 fn = cu->first_fn;
9899 while (fn && fn != cu->cached_fn)
9900 if (fn->lowpc <= address && fn->highpc > address)
9901 goto found;
9902 else
9903 fn = fn->next;
9904
9905 return address;
9906
9907 found:
9908 if (fn->seen_line)
9909 return address;
9910 if (address != fn->lowpc)
9911 complaint (&symfile_complaints,
9912 _("misplaced first line number at 0x%lx for '%s'"),
9913 (unsigned long) address, fn->name);
9914 fn->seen_line = 1;
9915 return fn->lowpc;
9916 }
9917
9918 /* Subroutine of dwarf_decode_lines to simplify it.
9919 Return the file name of the psymtab for included file FILE_INDEX
9920 in line header LH of PST.
9921 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
9922 If space for the result is malloc'd, it will be freed by a cleanup.
9923 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
9924
9925 static char *
9926 psymtab_include_file_name (const struct line_header *lh, int file_index,
9927 const struct partial_symtab *pst,
9928 const char *comp_dir)
9929 {
9930 const struct file_entry fe = lh->file_names [file_index];
9931 char *include_name = fe.name;
9932 char *include_name_to_compare = include_name;
9933 char *dir_name = NULL;
9934 char *pst_filename;
9935 int file_is_pst;
9936
9937 if (fe.dir_index)
9938 dir_name = lh->include_dirs[fe.dir_index - 1];
9939
9940 if (!IS_ABSOLUTE_PATH (include_name)
9941 && (dir_name != NULL || comp_dir != NULL))
9942 {
9943 /* Avoid creating a duplicate psymtab for PST.
9944 We do this by comparing INCLUDE_NAME and PST_FILENAME.
9945 Before we do the comparison, however, we need to account
9946 for DIR_NAME and COMP_DIR.
9947 First prepend dir_name (if non-NULL). If we still don't
9948 have an absolute path prepend comp_dir (if non-NULL).
9949 However, the directory we record in the include-file's
9950 psymtab does not contain COMP_DIR (to match the
9951 corresponding symtab(s)).
9952
9953 Example:
9954
9955 bash$ cd /tmp
9956 bash$ gcc -g ./hello.c
9957 include_name = "hello.c"
9958 dir_name = "."
9959 DW_AT_comp_dir = comp_dir = "/tmp"
9960 DW_AT_name = "./hello.c" */
9961
9962 if (dir_name != NULL)
9963 {
9964 include_name = concat (dir_name, SLASH_STRING,
9965 include_name, (char *)NULL);
9966 include_name_to_compare = include_name;
9967 make_cleanup (xfree, include_name);
9968 }
9969 if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL)
9970 {
9971 include_name_to_compare = concat (comp_dir, SLASH_STRING,
9972 include_name, (char *)NULL);
9973 }
9974 }
9975
9976 pst_filename = pst->filename;
9977 if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL)
9978 {
9979 pst_filename = concat (pst->dirname, SLASH_STRING,
9980 pst_filename, (char *)NULL);
9981 }
9982
9983 file_is_pst = strcmp (include_name_to_compare, pst_filename) == 0;
9984
9985 if (include_name_to_compare != include_name)
9986 xfree (include_name_to_compare);
9987 if (pst_filename != pst->filename)
9988 xfree (pst_filename);
9989
9990 if (file_is_pst)
9991 return NULL;
9992 return include_name;
9993 }
9994
9995 /* Decode the Line Number Program (LNP) for the given line_header
9996 structure and CU. The actual information extracted and the type
9997 of structures created from the LNP depends on the value of PST.
9998
9999 1. If PST is NULL, then this procedure uses the data from the program
10000 to create all necessary symbol tables, and their linetables.
10001
10002 2. If PST is not NULL, this procedure reads the program to determine
10003 the list of files included by the unit represented by PST, and
10004 builds all the associated partial symbol tables.
10005
10006 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10007 It is used for relative paths in the line table.
10008 NOTE: When processing partial symtabs (pst != NULL),
10009 comp_dir == pst->dirname.
10010
10011 NOTE: It is important that psymtabs have the same file name (via strcmp)
10012 as the corresponding symtab. Since COMP_DIR is not used in the name of the
10013 symtab we don't use it in the name of the psymtabs we create.
10014 E.g. expand_line_sal requires this when finding psymtabs to expand.
10015 A good testcase for this is mb-inline.exp. */
10016
10017 static void
10018 dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
10019 struct dwarf2_cu *cu, struct partial_symtab *pst)
10020 {
10021 gdb_byte *line_ptr, *extended_end;
10022 gdb_byte *line_end;
10023 unsigned int bytes_read, extended_len;
10024 unsigned char op_code, extended_op, adj_opcode;
10025 CORE_ADDR baseaddr;
10026 struct objfile *objfile = cu->objfile;
10027 struct gdbarch *gdbarch = get_objfile_arch (objfile);
10028 const int decode_for_pst_p = (pst != NULL);
10029 struct subfile *last_subfile = NULL, *first_subfile = current_subfile;
10030
10031 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
10032
10033 line_ptr = lh->statement_program_start;
10034 line_end = lh->statement_program_end;
10035
10036 /* Read the statement sequences until there's nothing left. */
10037 while (line_ptr < line_end)
10038 {
10039 /* state machine registers */
10040 CORE_ADDR address = 0;
10041 unsigned int file = 1;
10042 unsigned int line = 1;
10043 unsigned int column = 0;
10044 int is_stmt = lh->default_is_stmt;
10045 int basic_block = 0;
10046 int end_sequence = 0;
10047 CORE_ADDR addr;
10048 unsigned char op_index = 0;
10049
10050 if (!decode_for_pst_p && lh->num_file_names >= file)
10051 {
10052 /* Start a subfile for the current file of the state machine. */
10053 /* lh->include_dirs and lh->file_names are 0-based, but the
10054 directory and file name numbers in the statement program
10055 are 1-based. */
10056 struct file_entry *fe = &lh->file_names[file - 1];
10057 char *dir = NULL;
10058
10059 if (fe->dir_index)
10060 dir = lh->include_dirs[fe->dir_index - 1];
10061
10062 dwarf2_start_subfile (fe->name, dir, comp_dir);
10063 }
10064
10065 /* Decode the table. */
10066 while (!end_sequence)
10067 {
10068 op_code = read_1_byte (abfd, line_ptr);
10069 line_ptr += 1;
10070 if (line_ptr > line_end)
10071 {
10072 dwarf2_debug_line_missing_end_sequence_complaint ();
10073 break;
10074 }
10075
10076 if (op_code >= lh->opcode_base)
10077 {
10078 /* Special operand. */
10079 adj_opcode = op_code - lh->opcode_base;
10080 address += (((op_index + (adj_opcode / lh->line_range))
10081 / lh->maximum_ops_per_instruction)
10082 * lh->minimum_instruction_length);
10083 op_index = ((op_index + (adj_opcode / lh->line_range))
10084 % lh->maximum_ops_per_instruction);
10085 line += lh->line_base + (adj_opcode % lh->line_range);
10086 if (lh->num_file_names < file || file == 0)
10087 dwarf2_debug_line_missing_file_complaint ();
10088 /* For now we ignore lines not starting on an
10089 instruction boundary. */
10090 else if (op_index == 0)
10091 {
10092 lh->file_names[file - 1].included_p = 1;
10093 if (!decode_for_pst_p && is_stmt)
10094 {
10095 if (last_subfile != current_subfile)
10096 {
10097 addr = gdbarch_addr_bits_remove (gdbarch, address);
10098 if (last_subfile)
10099 record_line (last_subfile, 0, addr);
10100 last_subfile = current_subfile;
10101 }
10102 /* Append row to matrix using current values. */
10103 addr = check_cu_functions (address, cu);
10104 addr = gdbarch_addr_bits_remove (gdbarch, addr);
10105 record_line (current_subfile, line, addr);
10106 }
10107 }
10108 basic_block = 0;
10109 }
10110 else switch (op_code)
10111 {
10112 case DW_LNS_extended_op:
10113 extended_len = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10114 line_ptr += bytes_read;
10115 extended_end = line_ptr + extended_len;
10116 extended_op = read_1_byte (abfd, line_ptr);
10117 line_ptr += 1;
10118 switch (extended_op)
10119 {
10120 case DW_LNE_end_sequence:
10121 end_sequence = 1;
10122 break;
10123 case DW_LNE_set_address:
10124 address = read_address (abfd, line_ptr, cu, &bytes_read);
10125 op_index = 0;
10126 line_ptr += bytes_read;
10127 address += baseaddr;
10128 break;
10129 case DW_LNE_define_file:
10130 {
10131 char *cur_file;
10132 unsigned int dir_index, mod_time, length;
10133
10134 cur_file = read_direct_string (abfd, line_ptr, &bytes_read);
10135 line_ptr += bytes_read;
10136 dir_index =
10137 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10138 line_ptr += bytes_read;
10139 mod_time =
10140 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10141 line_ptr += bytes_read;
10142 length =
10143 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10144 line_ptr += bytes_read;
10145 add_file_name (lh, cur_file, dir_index, mod_time, length);
10146 }
10147 break;
10148 case DW_LNE_set_discriminator:
10149 /* The discriminator is not interesting to the debugger;
10150 just ignore it. */
10151 line_ptr = extended_end;
10152 break;
10153 default:
10154 complaint (&symfile_complaints,
10155 _("mangled .debug_line section"));
10156 return;
10157 }
10158 /* Make sure that we parsed the extended op correctly. If e.g.
10159 we expected a different address size than the producer used,
10160 we may have read the wrong number of bytes. */
10161 if (line_ptr != extended_end)
10162 {
10163 complaint (&symfile_complaints,
10164 _("mangled .debug_line section"));
10165 return;
10166 }
10167 break;
10168 case DW_LNS_copy:
10169 if (lh->num_file_names < file || file == 0)
10170 dwarf2_debug_line_missing_file_complaint ();
10171 else
10172 {
10173 lh->file_names[file - 1].included_p = 1;
10174 if (!decode_for_pst_p && is_stmt)
10175 {
10176 if (last_subfile != current_subfile)
10177 {
10178 addr = gdbarch_addr_bits_remove (gdbarch, address);
10179 if (last_subfile)
10180 record_line (last_subfile, 0, addr);
10181 last_subfile = current_subfile;
10182 }
10183 addr = check_cu_functions (address, cu);
10184 addr = gdbarch_addr_bits_remove (gdbarch, addr);
10185 record_line (current_subfile, line, addr);
10186 }
10187 }
10188 basic_block = 0;
10189 break;
10190 case DW_LNS_advance_pc:
10191 {
10192 CORE_ADDR adjust
10193 = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10194
10195 address += (((op_index + adjust)
10196 / lh->maximum_ops_per_instruction)
10197 * lh->minimum_instruction_length);
10198 op_index = ((op_index + adjust)
10199 % lh->maximum_ops_per_instruction);
10200 line_ptr += bytes_read;
10201 }
10202 break;
10203 case DW_LNS_advance_line:
10204 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
10205 line_ptr += bytes_read;
10206 break;
10207 case DW_LNS_set_file:
10208 {
10209 /* The arrays lh->include_dirs and lh->file_names are
10210 0-based, but the directory and file name numbers in
10211 the statement program are 1-based. */
10212 struct file_entry *fe;
10213 char *dir = NULL;
10214
10215 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10216 line_ptr += bytes_read;
10217 if (lh->num_file_names < file || file == 0)
10218 dwarf2_debug_line_missing_file_complaint ();
10219 else
10220 {
10221 fe = &lh->file_names[file - 1];
10222 if (fe->dir_index)
10223 dir = lh->include_dirs[fe->dir_index - 1];
10224 if (!decode_for_pst_p)
10225 {
10226 last_subfile = current_subfile;
10227 dwarf2_start_subfile (fe->name, dir, comp_dir);
10228 }
10229 }
10230 }
10231 break;
10232 case DW_LNS_set_column:
10233 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10234 line_ptr += bytes_read;
10235 break;
10236 case DW_LNS_negate_stmt:
10237 is_stmt = (!is_stmt);
10238 break;
10239 case DW_LNS_set_basic_block:
10240 basic_block = 1;
10241 break;
10242 /* Add to the address register of the state machine the
10243 address increment value corresponding to special opcode
10244 255. I.e., this value is scaled by the minimum
10245 instruction length since special opcode 255 would have
10246 scaled the the increment. */
10247 case DW_LNS_const_add_pc:
10248 {
10249 CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range;
10250
10251 address += (((op_index + adjust)
10252 / lh->maximum_ops_per_instruction)
10253 * lh->minimum_instruction_length);
10254 op_index = ((op_index + adjust)
10255 % lh->maximum_ops_per_instruction);
10256 }
10257 break;
10258 case DW_LNS_fixed_advance_pc:
10259 address += read_2_bytes (abfd, line_ptr);
10260 op_index = 0;
10261 line_ptr += 2;
10262 break;
10263 default:
10264 {
10265 /* Unknown standard opcode, ignore it. */
10266 int i;
10267
10268 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
10269 {
10270 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10271 line_ptr += bytes_read;
10272 }
10273 }
10274 }
10275 }
10276 if (lh->num_file_names < file || file == 0)
10277 dwarf2_debug_line_missing_file_complaint ();
10278 else
10279 {
10280 lh->file_names[file - 1].included_p = 1;
10281 if (!decode_for_pst_p)
10282 {
10283 addr = gdbarch_addr_bits_remove (gdbarch, address);
10284 record_line (current_subfile, 0, addr);
10285 }
10286 }
10287 }
10288
10289 if (decode_for_pst_p)
10290 {
10291 int file_index;
10292
10293 /* Now that we're done scanning the Line Header Program, we can
10294 create the psymtab of each included file. */
10295 for (file_index = 0; file_index < lh->num_file_names; file_index++)
10296 if (lh->file_names[file_index].included_p == 1)
10297 {
10298 char *include_name =
10299 psymtab_include_file_name (lh, file_index, pst, comp_dir);
10300 if (include_name != NULL)
10301 dwarf2_create_include_psymtab (include_name, pst, objfile);
10302 }
10303 }
10304 else
10305 {
10306 /* Make sure a symtab is created for every file, even files
10307 which contain only variables (i.e. no code with associated
10308 line numbers). */
10309
10310 int i;
10311 struct file_entry *fe;
10312
10313 for (i = 0; i < lh->num_file_names; i++)
10314 {
10315 char *dir = NULL;
10316
10317 fe = &lh->file_names[i];
10318 if (fe->dir_index)
10319 dir = lh->include_dirs[fe->dir_index - 1];
10320 dwarf2_start_subfile (fe->name, dir, comp_dir);
10321
10322 /* Skip the main file; we don't need it, and it must be
10323 allocated last, so that it will show up before the
10324 non-primary symtabs in the objfile's symtab list. */
10325 if (current_subfile == first_subfile)
10326 continue;
10327
10328 if (current_subfile->symtab == NULL)
10329 current_subfile->symtab = allocate_symtab (current_subfile->name,
10330 cu->objfile);
10331 fe->symtab = current_subfile->symtab;
10332 }
10333 }
10334 }
10335
10336 /* Start a subfile for DWARF. FILENAME is the name of the file and
10337 DIRNAME the name of the source directory which contains FILENAME
10338 or NULL if not known. COMP_DIR is the compilation directory for the
10339 linetable's compilation unit or NULL if not known.
10340 This routine tries to keep line numbers from identical absolute and
10341 relative file names in a common subfile.
10342
10343 Using the `list' example from the GDB testsuite, which resides in
10344 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
10345 of /srcdir/list0.c yields the following debugging information for list0.c:
10346
10347 DW_AT_name: /srcdir/list0.c
10348 DW_AT_comp_dir: /compdir
10349 files.files[0].name: list0.h
10350 files.files[0].dir: /srcdir
10351 files.files[1].name: list0.c
10352 files.files[1].dir: /srcdir
10353
10354 The line number information for list0.c has to end up in a single
10355 subfile, so that `break /srcdir/list0.c:1' works as expected.
10356 start_subfile will ensure that this happens provided that we pass the
10357 concatenation of files.files[1].dir and files.files[1].name as the
10358 subfile's name. */
10359
10360 static void
10361 dwarf2_start_subfile (char *filename, char *dirname, char *comp_dir)
10362 {
10363 char *fullname;
10364
10365 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
10366 `start_symtab' will always pass the contents of DW_AT_comp_dir as
10367 second argument to start_subfile. To be consistent, we do the
10368 same here. In order not to lose the line information directory,
10369 we concatenate it to the filename when it makes sense.
10370 Note that the Dwarf3 standard says (speaking of filenames in line
10371 information): ``The directory index is ignored for file names
10372 that represent full path names''. Thus ignoring dirname in the
10373 `else' branch below isn't an issue. */
10374
10375 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
10376 fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL);
10377 else
10378 fullname = filename;
10379
10380 start_subfile (fullname, comp_dir);
10381
10382 if (fullname != filename)
10383 xfree (fullname);
10384 }
10385
10386 static void
10387 var_decode_location (struct attribute *attr, struct symbol *sym,
10388 struct dwarf2_cu *cu)
10389 {
10390 struct objfile *objfile = cu->objfile;
10391 struct comp_unit_head *cu_header = &cu->header;
10392
10393 /* NOTE drow/2003-01-30: There used to be a comment and some special
10394 code here to turn a symbol with DW_AT_external and a
10395 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
10396 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
10397 with some versions of binutils) where shared libraries could have
10398 relocations against symbols in their debug information - the
10399 minimal symbol would have the right address, but the debug info
10400 would not. It's no longer necessary, because we will explicitly
10401 apply relocations when we read in the debug information now. */
10402
10403 /* A DW_AT_location attribute with no contents indicates that a
10404 variable has been optimized away. */
10405 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
10406 {
10407 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
10408 return;
10409 }
10410
10411 /* Handle one degenerate form of location expression specially, to
10412 preserve GDB's previous behavior when section offsets are
10413 specified. If this is just a DW_OP_addr then mark this symbol
10414 as LOC_STATIC. */
10415
10416 if (attr_form_is_block (attr)
10417 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
10418 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
10419 {
10420 unsigned int dummy;
10421
10422 SYMBOL_VALUE_ADDRESS (sym) =
10423 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
10424 SYMBOL_CLASS (sym) = LOC_STATIC;
10425 fixup_symbol_section (sym, objfile);
10426 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
10427 SYMBOL_SECTION (sym));
10428 return;
10429 }
10430
10431 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
10432 expression evaluator, and use LOC_COMPUTED only when necessary
10433 (i.e. when the value of a register or memory location is
10434 referenced, or a thread-local block, etc.). Then again, it might
10435 not be worthwhile. I'm assuming that it isn't unless performance
10436 or memory numbers show me otherwise. */
10437
10438 dwarf2_symbol_mark_computed (attr, sym, cu);
10439 SYMBOL_CLASS (sym) = LOC_COMPUTED;
10440 }
10441
10442 /* Given a pointer to a DWARF information entry, figure out if we need
10443 to make a symbol table entry for it, and if so, create a new entry
10444 and return a pointer to it.
10445 If TYPE is NULL, determine symbol type from the die, otherwise
10446 used the passed type.
10447 If SPACE is not NULL, use it to hold the new symbol. If it is
10448 NULL, allocate a new symbol on the objfile's obstack. */
10449
10450 static struct symbol *
10451 new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
10452 struct symbol *space)
10453 {
10454 struct objfile *objfile = cu->objfile;
10455 struct symbol *sym = NULL;
10456 char *name;
10457 struct attribute *attr = NULL;
10458 struct attribute *attr2 = NULL;
10459 CORE_ADDR baseaddr;
10460 struct pending **list_to_add = NULL;
10461
10462 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
10463
10464 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
10465
10466 name = dwarf2_name (die, cu);
10467 if (name)
10468 {
10469 const char *linkagename;
10470 int suppress_add = 0;
10471
10472 if (space)
10473 sym = space;
10474 else
10475 sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol);
10476 OBJSTAT (objfile, n_syms++);
10477
10478 /* Cache this symbol's name and the name's demangled form (if any). */
10479 SYMBOL_SET_LANGUAGE (sym, cu->language);
10480 linkagename = dwarf2_physname (name, die, cu);
10481 SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile);
10482
10483 /* Fortran does not have mangling standard and the mangling does differ
10484 between gfortran, iFort etc. */
10485 if (cu->language == language_fortran
10486 && symbol_get_demangled_name (&(sym->ginfo)) == NULL)
10487 symbol_set_demangled_name (&(sym->ginfo),
10488 (char *) dwarf2_full_name (name, die, cu),
10489 NULL);
10490
10491 /* Default assumptions.
10492 Use the passed type or decode it from the die. */
10493 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
10494 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
10495 if (type != NULL)
10496 SYMBOL_TYPE (sym) = type;
10497 else
10498 SYMBOL_TYPE (sym) = die_type (die, cu);
10499 attr = dwarf2_attr (die,
10500 inlined_func ? DW_AT_call_line : DW_AT_decl_line,
10501 cu);
10502 if (attr)
10503 {
10504 SYMBOL_LINE (sym) = DW_UNSND (attr);
10505 }
10506
10507 attr = dwarf2_attr (die,
10508 inlined_func ? DW_AT_call_file : DW_AT_decl_file,
10509 cu);
10510 if (attr)
10511 {
10512 int file_index = DW_UNSND (attr);
10513
10514 if (cu->line_header == NULL
10515 || file_index > cu->line_header->num_file_names)
10516 complaint (&symfile_complaints,
10517 _("file index out of range"));
10518 else if (file_index > 0)
10519 {
10520 struct file_entry *fe;
10521
10522 fe = &cu->line_header->file_names[file_index - 1];
10523 SYMBOL_SYMTAB (sym) = fe->symtab;
10524 }
10525 }
10526
10527 switch (die->tag)
10528 {
10529 case DW_TAG_label:
10530 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
10531 if (attr)
10532 {
10533 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
10534 }
10535 SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr;
10536 SYMBOL_DOMAIN (sym) = LABEL_DOMAIN;
10537 SYMBOL_CLASS (sym) = LOC_LABEL;
10538 add_symbol_to_list (sym, cu->list_in_scope);
10539 break;
10540 case DW_TAG_subprogram:
10541 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
10542 finish_block. */
10543 SYMBOL_CLASS (sym) = LOC_BLOCK;
10544 attr2 = dwarf2_attr (die, DW_AT_external, cu);
10545 if ((attr2 && (DW_UNSND (attr2) != 0))
10546 || cu->language == language_ada)
10547 {
10548 /* Subprograms marked external are stored as a global symbol.
10549 Ada subprograms, whether marked external or not, are always
10550 stored as a global symbol, because we want to be able to
10551 access them globally. For instance, we want to be able
10552 to break on a nested subprogram without having to
10553 specify the context. */
10554 list_to_add = &global_symbols;
10555 }
10556 else
10557 {
10558 list_to_add = cu->list_in_scope;
10559 }
10560 break;
10561 case DW_TAG_inlined_subroutine:
10562 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
10563 finish_block. */
10564 SYMBOL_CLASS (sym) = LOC_BLOCK;
10565 SYMBOL_INLINED (sym) = 1;
10566 /* Do not add the symbol to any lists. It will be found via
10567 BLOCK_FUNCTION from the blockvector. */
10568 break;
10569 case DW_TAG_template_value_param:
10570 suppress_add = 1;
10571 /* Fall through. */
10572 case DW_TAG_variable:
10573 case DW_TAG_member:
10574 /* Compilation with minimal debug info may result in variables
10575 with missing type entries. Change the misleading `void' type
10576 to something sensible. */
10577 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
10578 SYMBOL_TYPE (sym)
10579 = objfile_type (objfile)->nodebug_data_symbol;
10580
10581 attr = dwarf2_attr (die, DW_AT_const_value, cu);
10582 /* In the case of DW_TAG_member, we should only be called for
10583 static const members. */
10584 if (die->tag == DW_TAG_member)
10585 {
10586 /* dwarf2_add_field uses die_is_declaration,
10587 so we do the same. */
10588 gdb_assert (die_is_declaration (die, cu));
10589 gdb_assert (attr);
10590 }
10591 if (attr)
10592 {
10593 dwarf2_const_value (attr, sym, cu);
10594 attr2 = dwarf2_attr (die, DW_AT_external, cu);
10595 if (!suppress_add)
10596 {
10597 if (attr2 && (DW_UNSND (attr2) != 0))
10598 list_to_add = &global_symbols;
10599 else
10600 list_to_add = cu->list_in_scope;
10601 }
10602 break;
10603 }
10604 attr = dwarf2_attr (die, DW_AT_location, cu);
10605 if (attr)
10606 {
10607 var_decode_location (attr, sym, cu);
10608 attr2 = dwarf2_attr (die, DW_AT_external, cu);
10609 if (SYMBOL_CLASS (sym) == LOC_STATIC
10610 && SYMBOL_VALUE_ADDRESS (sym) == 0
10611 && !dwarf2_per_objfile->has_section_at_zero)
10612 {
10613 /* When a static variable is eliminated by the linker,
10614 the corresponding debug information is not stripped
10615 out, but the variable address is set to null;
10616 do not add such variables into symbol table. */
10617 }
10618 else if (attr2 && (DW_UNSND (attr2) != 0))
10619 {
10620 /* Workaround gfortran PR debug/40040 - it uses
10621 DW_AT_location for variables in -fPIC libraries which may
10622 get overriden by other libraries/executable and get
10623 a different address. Resolve it by the minimal symbol
10624 which may come from inferior's executable using copy
10625 relocation. Make this workaround only for gfortran as for
10626 other compilers GDB cannot guess the minimal symbol
10627 Fortran mangling kind. */
10628 if (cu->language == language_fortran && die->parent
10629 && die->parent->tag == DW_TAG_module
10630 && cu->producer
10631 && strncmp (cu->producer, "GNU Fortran ", 12) == 0)
10632 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
10633
10634 /* A variable with DW_AT_external is never static,
10635 but it may be block-scoped. */
10636 list_to_add = (cu->list_in_scope == &file_symbols
10637 ? &global_symbols : cu->list_in_scope);
10638 }
10639 else
10640 list_to_add = cu->list_in_scope;
10641 }
10642 else
10643 {
10644 /* We do not know the address of this symbol.
10645 If it is an external symbol and we have type information
10646 for it, enter the symbol as a LOC_UNRESOLVED symbol.
10647 The address of the variable will then be determined from
10648 the minimal symbol table whenever the variable is
10649 referenced. */
10650 attr2 = dwarf2_attr (die, DW_AT_external, cu);
10651 if (attr2 && (DW_UNSND (attr2) != 0)
10652 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
10653 {
10654 /* A variable with DW_AT_external is never static, but it
10655 may be block-scoped. */
10656 list_to_add = (cu->list_in_scope == &file_symbols
10657 ? &global_symbols : cu->list_in_scope);
10658
10659 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
10660 }
10661 else if (!die_is_declaration (die, cu))
10662 {
10663 /* Use the default LOC_OPTIMIZED_OUT class. */
10664 gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT);
10665 if (!suppress_add)
10666 list_to_add = cu->list_in_scope;
10667 }
10668 }
10669 break;
10670 case DW_TAG_formal_parameter:
10671 /* If we are inside a function, mark this as an argument. If
10672 not, we might be looking at an argument to an inlined function
10673 when we do not have enough information to show inlined frames;
10674 pretend it's a local variable in that case so that the user can
10675 still see it. */
10676 if (context_stack_depth > 0
10677 && context_stack[context_stack_depth - 1].name != NULL)
10678 SYMBOL_IS_ARGUMENT (sym) = 1;
10679 attr = dwarf2_attr (die, DW_AT_location, cu);
10680 if (attr)
10681 {
10682 var_decode_location (attr, sym, cu);
10683 }
10684 attr = dwarf2_attr (die, DW_AT_const_value, cu);
10685 if (attr)
10686 {
10687 dwarf2_const_value (attr, sym, cu);
10688 }
10689 attr = dwarf2_attr (die, DW_AT_variable_parameter, cu);
10690 if (attr && DW_UNSND (attr))
10691 {
10692 struct type *ref_type;
10693
10694 ref_type = lookup_reference_type (SYMBOL_TYPE (sym));
10695 SYMBOL_TYPE (sym) = ref_type;
10696 }
10697
10698 list_to_add = cu->list_in_scope;
10699 break;
10700 case DW_TAG_unspecified_parameters:
10701 /* From varargs functions; gdb doesn't seem to have any
10702 interest in this information, so just ignore it for now.
10703 (FIXME?) */
10704 break;
10705 case DW_TAG_template_type_param:
10706 suppress_add = 1;
10707 /* Fall through. */
10708 case DW_TAG_class_type:
10709 case DW_TAG_interface_type:
10710 case DW_TAG_structure_type:
10711 case DW_TAG_union_type:
10712 case DW_TAG_set_type:
10713 case DW_TAG_enumeration_type:
10714 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
10715 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
10716
10717 {
10718 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
10719 really ever be static objects: otherwise, if you try
10720 to, say, break of a class's method and you're in a file
10721 which doesn't mention that class, it won't work unless
10722 the check for all static symbols in lookup_symbol_aux
10723 saves you. See the OtherFileClass tests in
10724 gdb.c++/namespace.exp. */
10725
10726 if (!suppress_add)
10727 {
10728 list_to_add = (cu->list_in_scope == &file_symbols
10729 && (cu->language == language_cplus
10730 || cu->language == language_java)
10731 ? &global_symbols : cu->list_in_scope);
10732 }
10733
10734 /* The semantics of C++ state that "struct foo { ... }" also
10735 defines a typedef for "foo". A Java class declaration also
10736 defines a typedef for the class. */
10737 if (cu->language == language_cplus
10738 || cu->language == language_java
10739 || cu->language == language_ada)
10740 {
10741 /* The symbol's name is already allocated along with
10742 this objfile, so we don't need to duplicate it for
10743 the type. */
10744 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
10745 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym);
10746 }
10747 }
10748 break;
10749 case DW_TAG_typedef:
10750 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
10751 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
10752 list_to_add = cu->list_in_scope;
10753 break;
10754 case DW_TAG_base_type:
10755 case DW_TAG_subrange_type:
10756 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
10757 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
10758 list_to_add = cu->list_in_scope;
10759 break;
10760 case DW_TAG_enumerator:
10761 attr = dwarf2_attr (die, DW_AT_const_value, cu);
10762 if (attr)
10763 {
10764 dwarf2_const_value (attr, sym, cu);
10765 }
10766 {
10767 /* NOTE: carlton/2003-11-10: See comment above in the
10768 DW_TAG_class_type, etc. block. */
10769
10770 list_to_add = (cu->list_in_scope == &file_symbols
10771 && (cu->language == language_cplus
10772 || cu->language == language_java)
10773 ? &global_symbols : cu->list_in_scope);
10774 }
10775 break;
10776 case DW_TAG_namespace:
10777 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
10778 list_to_add = &global_symbols;
10779 break;
10780 default:
10781 /* Not a tag we recognize. Hopefully we aren't processing
10782 trash data, but since we must specifically ignore things
10783 we don't recognize, there is nothing else we should do at
10784 this point. */
10785 complaint (&symfile_complaints, _("unsupported tag: '%s'"),
10786 dwarf_tag_name (die->tag));
10787 break;
10788 }
10789
10790 if (suppress_add)
10791 {
10792 sym->hash_next = objfile->template_symbols;
10793 objfile->template_symbols = sym;
10794 list_to_add = NULL;
10795 }
10796
10797 if (list_to_add != NULL)
10798 add_symbol_to_list (sym, list_to_add);
10799
10800 /* For the benefit of old versions of GCC, check for anonymous
10801 namespaces based on the demangled name. */
10802 if (!processing_has_namespace_info
10803 && cu->language == language_cplus)
10804 cp_scan_for_anonymous_namespaces (sym);
10805 }
10806 return (sym);
10807 }
10808
10809 /* A wrapper for new_symbol_full that always allocates a new symbol. */
10810
10811 static struct symbol *
10812 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
10813 {
10814 return new_symbol_full (die, type, cu, NULL);
10815 }
10816
10817 /* Given an attr with a DW_FORM_dataN value in host byte order,
10818 zero-extend it as appropriate for the symbol's type. The DWARF
10819 standard (v4) is not entirely clear about the meaning of using
10820 DW_FORM_dataN for a constant with a signed type, where the type is
10821 wider than the data. The conclusion of a discussion on the DWARF
10822 list was that this is unspecified. We choose to always zero-extend
10823 because that is the interpretation long in use by GCC. */
10824
10825 static gdb_byte *
10826 dwarf2_const_value_data (struct attribute *attr, struct type *type,
10827 const char *name, struct obstack *obstack,
10828 struct dwarf2_cu *cu, long *value, int bits)
10829 {
10830 struct objfile *objfile = cu->objfile;
10831 enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ?
10832 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
10833 LONGEST l = DW_UNSND (attr);
10834
10835 if (bits < sizeof (*value) * 8)
10836 {
10837 l &= ((LONGEST) 1 << bits) - 1;
10838 *value = l;
10839 }
10840 else if (bits == sizeof (*value) * 8)
10841 *value = l;
10842 else
10843 {
10844 gdb_byte *bytes = obstack_alloc (obstack, bits / 8);
10845 store_unsigned_integer (bytes, bits / 8, byte_order, l);
10846 return bytes;
10847 }
10848
10849 return NULL;
10850 }
10851
10852 /* Read a constant value from an attribute. Either set *VALUE, or if
10853 the value does not fit in *VALUE, set *BYTES - either already
10854 allocated on the objfile obstack, or newly allocated on OBSTACK,
10855 or, set *BATON, if we translated the constant to a location
10856 expression. */
10857
10858 static void
10859 dwarf2_const_value_attr (struct attribute *attr, struct type *type,
10860 const char *name, struct obstack *obstack,
10861 struct dwarf2_cu *cu,
10862 long *value, gdb_byte **bytes,
10863 struct dwarf2_locexpr_baton **baton)
10864 {
10865 struct objfile *objfile = cu->objfile;
10866 struct comp_unit_head *cu_header = &cu->header;
10867 struct dwarf_block *blk;
10868 enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ?
10869 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE);
10870
10871 *value = 0;
10872 *bytes = NULL;
10873 *baton = NULL;
10874
10875 switch (attr->form)
10876 {
10877 case DW_FORM_addr:
10878 {
10879 gdb_byte *data;
10880
10881 if (TYPE_LENGTH (type) != cu_header->addr_size)
10882 dwarf2_const_value_length_mismatch_complaint (name,
10883 cu_header->addr_size,
10884 TYPE_LENGTH (type));
10885 /* Symbols of this form are reasonably rare, so we just
10886 piggyback on the existing location code rather than writing
10887 a new implementation of symbol_computed_ops. */
10888 *baton = obstack_alloc (&objfile->objfile_obstack,
10889 sizeof (struct dwarf2_locexpr_baton));
10890 (*baton)->per_cu = cu->per_cu;
10891 gdb_assert ((*baton)->per_cu);
10892
10893 (*baton)->size = 2 + cu_header->addr_size;
10894 data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size);
10895 (*baton)->data = data;
10896
10897 data[0] = DW_OP_addr;
10898 store_unsigned_integer (&data[1], cu_header->addr_size,
10899 byte_order, DW_ADDR (attr));
10900 data[cu_header->addr_size + 1] = DW_OP_stack_value;
10901 }
10902 break;
10903 case DW_FORM_string:
10904 case DW_FORM_strp:
10905 /* DW_STRING is already allocated on the objfile obstack, point
10906 directly to it. */
10907 *bytes = (gdb_byte *) DW_STRING (attr);
10908 break;
10909 case DW_FORM_block1:
10910 case DW_FORM_block2:
10911 case DW_FORM_block4:
10912 case DW_FORM_block:
10913 case DW_FORM_exprloc:
10914 blk = DW_BLOCK (attr);
10915 if (TYPE_LENGTH (type) != blk->size)
10916 dwarf2_const_value_length_mismatch_complaint (name, blk->size,
10917 TYPE_LENGTH (type));
10918 *bytes = blk->data;
10919 break;
10920
10921 /* The DW_AT_const_value attributes are supposed to carry the
10922 symbol's value "represented as it would be on the target
10923 architecture." By the time we get here, it's already been
10924 converted to host endianness, so we just need to sign- or
10925 zero-extend it as appropriate. */
10926 case DW_FORM_data1:
10927 *bytes = dwarf2_const_value_data (attr, type, name, obstack, cu, value, 8);
10928 break;
10929 case DW_FORM_data2:
10930 *bytes = dwarf2_const_value_data (attr, type, name, obstack, cu, value, 16);
10931 break;
10932 case DW_FORM_data4:
10933 *bytes = dwarf2_const_value_data (attr, type, name, obstack, cu, value, 32);
10934 break;
10935 case DW_FORM_data8:
10936 *bytes = dwarf2_const_value_data (attr, type, name, obstack, cu, value, 64);
10937 break;
10938
10939 case DW_FORM_sdata:
10940 *value = DW_SND (attr);
10941 break;
10942
10943 case DW_FORM_udata:
10944 *value = DW_UNSND (attr);
10945 break;
10946
10947 default:
10948 complaint (&symfile_complaints,
10949 _("unsupported const value attribute form: '%s'"),
10950 dwarf_form_name (attr->form));
10951 *value = 0;
10952 break;
10953 }
10954 }
10955
10956
10957 /* Copy constant value from an attribute to a symbol. */
10958
10959 static void
10960 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
10961 struct dwarf2_cu *cu)
10962 {
10963 struct objfile *objfile = cu->objfile;
10964 struct comp_unit_head *cu_header = &cu->header;
10965 long value;
10966 gdb_byte *bytes;
10967 struct dwarf2_locexpr_baton *baton;
10968
10969 dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym),
10970 SYMBOL_PRINT_NAME (sym),
10971 &objfile->objfile_obstack, cu,
10972 &value, &bytes, &baton);
10973
10974 if (baton != NULL)
10975 {
10976 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
10977 SYMBOL_LOCATION_BATON (sym) = baton;
10978 SYMBOL_CLASS (sym) = LOC_COMPUTED;
10979 }
10980 else if (bytes != NULL)
10981 {
10982 SYMBOL_VALUE_BYTES (sym) = bytes;
10983 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
10984 }
10985 else
10986 {
10987 SYMBOL_VALUE (sym) = value;
10988 SYMBOL_CLASS (sym) = LOC_CONST;
10989 }
10990 }
10991
10992 /* Return the type of the die in question using its DW_AT_type attribute. */
10993
10994 static struct type *
10995 die_type (struct die_info *die, struct dwarf2_cu *cu)
10996 {
10997 struct attribute *type_attr;
10998
10999 type_attr = dwarf2_attr (die, DW_AT_type, cu);
11000 if (!type_attr)
11001 {
11002 /* A missing DW_AT_type represents a void type. */
11003 return objfile_type (cu->objfile)->builtin_void;
11004 }
11005
11006 return lookup_die_type (die, type_attr, cu);
11007 }
11008
11009 /* True iff CU's producer generates GNAT Ada auxiliary information
11010 that allows to find parallel types through that information instead
11011 of having to do expensive parallel lookups by type name. */
11012
11013 static int
11014 need_gnat_info (struct dwarf2_cu *cu)
11015 {
11016 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
11017 of GNAT produces this auxiliary information, without any indication
11018 that it is produced. Part of enhancing the FSF version of GNAT
11019 to produce that information will be to put in place an indicator
11020 that we can use in order to determine whether the descriptive type
11021 info is available or not. One suggestion that has been made is
11022 to use a new attribute, attached to the CU die. For now, assume
11023 that the descriptive type info is not available. */
11024 return 0;
11025 }
11026
11027 /* Return the auxiliary type of the die in question using its
11028 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
11029 attribute is not present. */
11030
11031 static struct type *
11032 die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu)
11033 {
11034 struct attribute *type_attr;
11035
11036 type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu);
11037 if (!type_attr)
11038 return NULL;
11039
11040 return lookup_die_type (die, type_attr, cu);
11041 }
11042
11043 /* If DIE has a descriptive_type attribute, then set the TYPE's
11044 descriptive type accordingly. */
11045
11046 static void
11047 set_descriptive_type (struct type *type, struct die_info *die,
11048 struct dwarf2_cu *cu)
11049 {
11050 struct type *descriptive_type = die_descriptive_type (die, cu);
11051
11052 if (descriptive_type)
11053 {
11054 ALLOCATE_GNAT_AUX_TYPE (type);
11055 TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type;
11056 }
11057 }
11058
11059 /* Return the containing type of the die in question using its
11060 DW_AT_containing_type attribute. */
11061
11062 static struct type *
11063 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
11064 {
11065 struct attribute *type_attr;
11066
11067 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
11068 if (!type_attr)
11069 error (_("Dwarf Error: Problem turning containing type into gdb type "
11070 "[in module %s]"), cu->objfile->name);
11071
11072 return lookup_die_type (die, type_attr, cu);
11073 }
11074
11075 /* Look up the type of DIE in CU using its type attribute ATTR.
11076 If there is no type substitute an error marker. */
11077
11078 static struct type *
11079 lookup_die_type (struct die_info *die, struct attribute *attr,
11080 struct dwarf2_cu *cu)
11081 {
11082 struct type *this_type;
11083
11084 /* First see if we have it cached. */
11085
11086 if (is_ref_attr (attr))
11087 {
11088 unsigned int offset = dwarf2_get_ref_die_offset (attr);
11089
11090 this_type = get_die_type_at_offset (offset, cu->per_cu);
11091 }
11092 else if (attr->form == DW_FORM_sig8)
11093 {
11094 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
11095 struct dwarf2_cu *sig_cu;
11096 unsigned int offset;
11097
11098 /* sig_type will be NULL if the signatured type is missing from
11099 the debug info. */
11100 if (sig_type == NULL)
11101 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
11102 "at 0x%x [in module %s]"),
11103 die->offset, cu->objfile->name);
11104
11105 gdb_assert (sig_type->per_cu.from_debug_types);
11106 offset = sig_type->offset + sig_type->type_offset;
11107 this_type = get_die_type_at_offset (offset, &sig_type->per_cu);
11108 }
11109 else
11110 {
11111 dump_die_for_error (die);
11112 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
11113 dwarf_attr_name (attr->name), cu->objfile->name);
11114 }
11115
11116 /* If not cached we need to read it in. */
11117
11118 if (this_type == NULL)
11119 {
11120 struct die_info *type_die;
11121 struct dwarf2_cu *type_cu = cu;
11122
11123 type_die = follow_die_ref_or_sig (die, attr, &type_cu);
11124 /* If the type is cached, we should have found it above. */
11125 gdb_assert (get_die_type (type_die, type_cu) == NULL);
11126 this_type = read_type_die_1 (type_die, type_cu);
11127 }
11128
11129 /* If we still don't have a type use an error marker. */
11130
11131 if (this_type == NULL)
11132 {
11133 char *message, *saved;
11134
11135 /* read_type_die already issued a complaint. */
11136 message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
11137 cu->objfile->name,
11138 cu->header.offset,
11139 die->offset);
11140 saved = obstack_copy0 (&cu->objfile->objfile_obstack,
11141 message, strlen (message));
11142 xfree (message);
11143
11144 this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, cu->objfile);
11145 }
11146
11147 return this_type;
11148 }
11149
11150 /* Return the type in DIE, CU.
11151 Returns NULL for invalid types.
11152
11153 This first does a lookup in the appropriate type_hash table,
11154 and only reads the die in if necessary.
11155
11156 NOTE: This can be called when reading in partial or full symbols. */
11157
11158 static struct type *
11159 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
11160 {
11161 struct type *this_type;
11162
11163 this_type = get_die_type (die, cu);
11164 if (this_type)
11165 return this_type;
11166
11167 return read_type_die_1 (die, cu);
11168 }
11169
11170 /* Read the type in DIE, CU.
11171 Returns NULL for invalid types. */
11172
11173 static struct type *
11174 read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu)
11175 {
11176 struct type *this_type = NULL;
11177
11178 switch (die->tag)
11179 {
11180 case DW_TAG_class_type:
11181 case DW_TAG_interface_type:
11182 case DW_TAG_structure_type:
11183 case DW_TAG_union_type:
11184 this_type = read_structure_type (die, cu);
11185 break;
11186 case DW_TAG_enumeration_type:
11187 this_type = read_enumeration_type (die, cu);
11188 break;
11189 case DW_TAG_subprogram:
11190 case DW_TAG_subroutine_type:
11191 case DW_TAG_inlined_subroutine:
11192 this_type = read_subroutine_type (die, cu);
11193 break;
11194 case DW_TAG_array_type:
11195 this_type = read_array_type (die, cu);
11196 break;
11197 case DW_TAG_set_type:
11198 this_type = read_set_type (die, cu);
11199 break;
11200 case DW_TAG_pointer_type:
11201 this_type = read_tag_pointer_type (die, cu);
11202 break;
11203 case DW_TAG_ptr_to_member_type:
11204 this_type = read_tag_ptr_to_member_type (die, cu);
11205 break;
11206 case DW_TAG_reference_type:
11207 this_type = read_tag_reference_type (die, cu);
11208 break;
11209 case DW_TAG_const_type:
11210 this_type = read_tag_const_type (die, cu);
11211 break;
11212 case DW_TAG_volatile_type:
11213 this_type = read_tag_volatile_type (die, cu);
11214 break;
11215 case DW_TAG_string_type:
11216 this_type = read_tag_string_type (die, cu);
11217 break;
11218 case DW_TAG_typedef:
11219 this_type = read_typedef (die, cu);
11220 break;
11221 case DW_TAG_subrange_type:
11222 this_type = read_subrange_type (die, cu);
11223 break;
11224 case DW_TAG_base_type:
11225 this_type = read_base_type (die, cu);
11226 break;
11227 case DW_TAG_unspecified_type:
11228 this_type = read_unspecified_type (die, cu);
11229 break;
11230 case DW_TAG_namespace:
11231 this_type = read_namespace_type (die, cu);
11232 break;
11233 case DW_TAG_module:
11234 this_type = read_module_type (die, cu);
11235 break;
11236 default:
11237 complaint (&symfile_complaints, _("unexpected tag in read_type_die: '%s'"),
11238 dwarf_tag_name (die->tag));
11239 break;
11240 }
11241
11242 return this_type;
11243 }
11244
11245 /* Return the name of the namespace/class that DIE is defined within,
11246 or "" if we can't tell. The caller should not xfree the result.
11247
11248 For example, if we're within the method foo() in the following
11249 code:
11250
11251 namespace N {
11252 class C {
11253 void foo () {
11254 }
11255 };
11256 }
11257
11258 then determine_prefix on foo's die will return "N::C". */
11259
11260 static char *
11261 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
11262 {
11263 struct die_info *parent, *spec_die;
11264 struct dwarf2_cu *spec_cu;
11265 struct type *parent_type;
11266
11267 if (cu->language != language_cplus && cu->language != language_java
11268 && cu->language != language_fortran)
11269 return "";
11270
11271 /* We have to be careful in the presence of DW_AT_specification.
11272 For example, with GCC 3.4, given the code
11273
11274 namespace N {
11275 void foo() {
11276 // Definition of N::foo.
11277 }
11278 }
11279
11280 then we'll have a tree of DIEs like this:
11281
11282 1: DW_TAG_compile_unit
11283 2: DW_TAG_namespace // N
11284 3: DW_TAG_subprogram // declaration of N::foo
11285 4: DW_TAG_subprogram // definition of N::foo
11286 DW_AT_specification // refers to die #3
11287
11288 Thus, when processing die #4, we have to pretend that we're in
11289 the context of its DW_AT_specification, namely the contex of die
11290 #3. */
11291 spec_cu = cu;
11292 spec_die = die_specification (die, &spec_cu);
11293 if (spec_die == NULL)
11294 parent = die->parent;
11295 else
11296 {
11297 parent = spec_die->parent;
11298 cu = spec_cu;
11299 }
11300
11301 if (parent == NULL)
11302 return "";
11303 else if (parent->building_fullname)
11304 {
11305 const char *name;
11306 const char *parent_name;
11307
11308 /* It has been seen on RealView 2.2 built binaries,
11309 DW_TAG_template_type_param types actually _defined_ as
11310 children of the parent class:
11311
11312 enum E {};
11313 template class <class Enum> Class{};
11314 Class<enum E> class_e;
11315
11316 1: DW_TAG_class_type (Class)
11317 2: DW_TAG_enumeration_type (E)
11318 3: DW_TAG_enumerator (enum1:0)
11319 3: DW_TAG_enumerator (enum2:1)
11320 ...
11321 2: DW_TAG_template_type_param
11322 DW_AT_type DW_FORM_ref_udata (E)
11323
11324 Besides being broken debug info, it can put GDB into an
11325 infinite loop. Consider:
11326
11327 When we're building the full name for Class<E>, we'll start
11328 at Class, and go look over its template type parameters,
11329 finding E. We'll then try to build the full name of E, and
11330 reach here. We're now trying to build the full name of E,
11331 and look over the parent DIE for containing scope. In the
11332 broken case, if we followed the parent DIE of E, we'd again
11333 find Class, and once again go look at its template type
11334 arguments, etc., etc. Simply don't consider such parent die
11335 as source-level parent of this die (it can't be, the language
11336 doesn't allow it), and break the loop here. */
11337 name = dwarf2_name (die, cu);
11338 parent_name = dwarf2_name (parent, cu);
11339 complaint (&symfile_complaints,
11340 _("template param type '%s' defined within parent '%s'"),
11341 name ? name : "<unknown>",
11342 parent_name ? parent_name : "<unknown>");
11343 return "";
11344 }
11345 else
11346 switch (parent->tag)
11347 {
11348 case DW_TAG_namespace:
11349 parent_type = read_type_die (parent, cu);
11350 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
11351 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
11352 Work around this problem here. */
11353 if (cu->language == language_cplus
11354 && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0)
11355 return "";
11356 /* We give a name to even anonymous namespaces. */
11357 return TYPE_TAG_NAME (parent_type);
11358 case DW_TAG_class_type:
11359 case DW_TAG_interface_type:
11360 case DW_TAG_structure_type:
11361 case DW_TAG_union_type:
11362 case DW_TAG_module:
11363 parent_type = read_type_die (parent, cu);
11364 if (TYPE_TAG_NAME (parent_type) != NULL)
11365 return TYPE_TAG_NAME (parent_type);
11366 else
11367 /* An anonymous structure is only allowed non-static data
11368 members; no typedefs, no member functions, et cetera.
11369 So it does not need a prefix. */
11370 return "";
11371 default:
11372 return determine_prefix (parent, cu);
11373 }
11374 }
11375
11376 /* Return a newly-allocated string formed by concatenating PREFIX and
11377 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
11378 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
11379 perform an obconcat, otherwise allocate storage for the result. The CU argument
11380 is used to determine the language and hence, the appropriate separator. */
11381
11382 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
11383
11384 static char *
11385 typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
11386 int physname, struct dwarf2_cu *cu)
11387 {
11388 const char *lead = "";
11389 const char *sep;
11390
11391 if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0')
11392 sep = "";
11393 else if (cu->language == language_java)
11394 sep = ".";
11395 else if (cu->language == language_fortran && physname)
11396 {
11397 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
11398 DW_AT_MIPS_linkage_name is preferred and used instead. */
11399
11400 lead = "__";
11401 sep = "_MOD_";
11402 }
11403 else
11404 sep = "::";
11405
11406 if (prefix == NULL)
11407 prefix = "";
11408 if (suffix == NULL)
11409 suffix = "";
11410
11411 if (obs == NULL)
11412 {
11413 char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
11414
11415 strcpy (retval, lead);
11416 strcat (retval, prefix);
11417 strcat (retval, sep);
11418 strcat (retval, suffix);
11419 return retval;
11420 }
11421 else
11422 {
11423 /* We have an obstack. */
11424 return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL);
11425 }
11426 }
11427
11428 /* Return sibling of die, NULL if no sibling. */
11429
11430 static struct die_info *
11431 sibling_die (struct die_info *die)
11432 {
11433 return die->sibling;
11434 }
11435
11436 /* Get name of a die, return NULL if not found. */
11437
11438 static char *
11439 dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu,
11440 struct obstack *obstack)
11441 {
11442 if (name && cu->language == language_cplus)
11443 {
11444 char *canon_name = cp_canonicalize_string (name);
11445
11446 if (canon_name != NULL)
11447 {
11448 if (strcmp (canon_name, name) != 0)
11449 name = obsavestring (canon_name, strlen (canon_name),
11450 obstack);
11451 xfree (canon_name);
11452 }
11453 }
11454
11455 return name;
11456 }
11457
11458 /* Get name of a die, return NULL if not found. */
11459
11460 static char *
11461 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
11462 {
11463 struct attribute *attr;
11464
11465 attr = dwarf2_attr (die, DW_AT_name, cu);
11466 if (!attr || !DW_STRING (attr))
11467 return NULL;
11468
11469 switch (die->tag)
11470 {
11471 case DW_TAG_compile_unit:
11472 /* Compilation units have a DW_AT_name that is a filename, not
11473 a source language identifier. */
11474 case DW_TAG_enumeration_type:
11475 case DW_TAG_enumerator:
11476 /* These tags always have simple identifiers already; no need
11477 to canonicalize them. */
11478 return DW_STRING (attr);
11479
11480 case DW_TAG_subprogram:
11481 /* Java constructors will all be named "<init>", so return
11482 the class name when we see this special case. */
11483 if (cu->language == language_java
11484 && DW_STRING (attr) != NULL
11485 && strcmp (DW_STRING (attr), "<init>") == 0)
11486 {
11487 struct dwarf2_cu *spec_cu = cu;
11488 struct die_info *spec_die;
11489
11490 /* GCJ will output '<init>' for Java constructor names.
11491 For this special case, return the name of the parent class. */
11492
11493 /* GCJ may output suprogram DIEs with AT_specification set.
11494 If so, use the name of the specified DIE. */
11495 spec_die = die_specification (die, &spec_cu);
11496 if (spec_die != NULL)
11497 return dwarf2_name (spec_die, spec_cu);
11498
11499 do
11500 {
11501 die = die->parent;
11502 if (die->tag == DW_TAG_class_type)
11503 return dwarf2_name (die, cu);
11504 }
11505 while (die->tag != DW_TAG_compile_unit);
11506 }
11507 break;
11508
11509 case DW_TAG_class_type:
11510 case DW_TAG_interface_type:
11511 case DW_TAG_structure_type:
11512 case DW_TAG_union_type:
11513 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
11514 structures or unions. These were of the form "._%d" in GCC 4.1,
11515 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
11516 and GCC 4.4. We work around this problem by ignoring these. */
11517 if (strncmp (DW_STRING (attr), "._", 2) == 0
11518 || strncmp (DW_STRING (attr), "<anonymous", 10) == 0)
11519 return NULL;
11520 break;
11521
11522 default:
11523 break;
11524 }
11525
11526 if (!DW_STRING_IS_CANONICAL (attr))
11527 {
11528 DW_STRING (attr)
11529 = dwarf2_canonicalize_name (DW_STRING (attr), cu,
11530 &cu->objfile->objfile_obstack);
11531 DW_STRING_IS_CANONICAL (attr) = 1;
11532 }
11533 return DW_STRING (attr);
11534 }
11535
11536 /* Return the die that this die in an extension of, or NULL if there
11537 is none. *EXT_CU is the CU containing DIE on input, and the CU
11538 containing the return value on output. */
11539
11540 static struct die_info *
11541 dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu)
11542 {
11543 struct attribute *attr;
11544
11545 attr = dwarf2_attr (die, DW_AT_extension, *ext_cu);
11546 if (attr == NULL)
11547 return NULL;
11548
11549 return follow_die_ref (die, attr, ext_cu);
11550 }
11551
11552 /* Convert a DIE tag into its string name. */
11553
11554 static char *
11555 dwarf_tag_name (unsigned tag)
11556 {
11557 switch (tag)
11558 {
11559 case DW_TAG_padding:
11560 return "DW_TAG_padding";
11561 case DW_TAG_array_type:
11562 return "DW_TAG_array_type";
11563 case DW_TAG_class_type:
11564 return "DW_TAG_class_type";
11565 case DW_TAG_entry_point:
11566 return "DW_TAG_entry_point";
11567 case DW_TAG_enumeration_type:
11568 return "DW_TAG_enumeration_type";
11569 case DW_TAG_formal_parameter:
11570 return "DW_TAG_formal_parameter";
11571 case DW_TAG_imported_declaration:
11572 return "DW_TAG_imported_declaration";
11573 case DW_TAG_label:
11574 return "DW_TAG_label";
11575 case DW_TAG_lexical_block:
11576 return "DW_TAG_lexical_block";
11577 case DW_TAG_member:
11578 return "DW_TAG_member";
11579 case DW_TAG_pointer_type:
11580 return "DW_TAG_pointer_type";
11581 case DW_TAG_reference_type:
11582 return "DW_TAG_reference_type";
11583 case DW_TAG_compile_unit:
11584 return "DW_TAG_compile_unit";
11585 case DW_TAG_string_type:
11586 return "DW_TAG_string_type";
11587 case DW_TAG_structure_type:
11588 return "DW_TAG_structure_type";
11589 case DW_TAG_subroutine_type:
11590 return "DW_TAG_subroutine_type";
11591 case DW_TAG_typedef:
11592 return "DW_TAG_typedef";
11593 case DW_TAG_union_type:
11594 return "DW_TAG_union_type";
11595 case DW_TAG_unspecified_parameters:
11596 return "DW_TAG_unspecified_parameters";
11597 case DW_TAG_variant:
11598 return "DW_TAG_variant";
11599 case DW_TAG_common_block:
11600 return "DW_TAG_common_block";
11601 case DW_TAG_common_inclusion:
11602 return "DW_TAG_common_inclusion";
11603 case DW_TAG_inheritance:
11604 return "DW_TAG_inheritance";
11605 case DW_TAG_inlined_subroutine:
11606 return "DW_TAG_inlined_subroutine";
11607 case DW_TAG_module:
11608 return "DW_TAG_module";
11609 case DW_TAG_ptr_to_member_type:
11610 return "DW_TAG_ptr_to_member_type";
11611 case DW_TAG_set_type:
11612 return "DW_TAG_set_type";
11613 case DW_TAG_subrange_type:
11614 return "DW_TAG_subrange_type";
11615 case DW_TAG_with_stmt:
11616 return "DW_TAG_with_stmt";
11617 case DW_TAG_access_declaration:
11618 return "DW_TAG_access_declaration";
11619 case DW_TAG_base_type:
11620 return "DW_TAG_base_type";
11621 case DW_TAG_catch_block:
11622 return "DW_TAG_catch_block";
11623 case DW_TAG_const_type:
11624 return "DW_TAG_const_type";
11625 case DW_TAG_constant:
11626 return "DW_TAG_constant";
11627 case DW_TAG_enumerator:
11628 return "DW_TAG_enumerator";
11629 case DW_TAG_file_type:
11630 return "DW_TAG_file_type";
11631 case DW_TAG_friend:
11632 return "DW_TAG_friend";
11633 case DW_TAG_namelist:
11634 return "DW_TAG_namelist";
11635 case DW_TAG_namelist_item:
11636 return "DW_TAG_namelist_item";
11637 case DW_TAG_packed_type:
11638 return "DW_TAG_packed_type";
11639 case DW_TAG_subprogram:
11640 return "DW_TAG_subprogram";
11641 case DW_TAG_template_type_param:
11642 return "DW_TAG_template_type_param";
11643 case DW_TAG_template_value_param:
11644 return "DW_TAG_template_value_param";
11645 case DW_TAG_thrown_type:
11646 return "DW_TAG_thrown_type";
11647 case DW_TAG_try_block:
11648 return "DW_TAG_try_block";
11649 case DW_TAG_variant_part:
11650 return "DW_TAG_variant_part";
11651 case DW_TAG_variable:
11652 return "DW_TAG_variable";
11653 case DW_TAG_volatile_type:
11654 return "DW_TAG_volatile_type";
11655 case DW_TAG_dwarf_procedure:
11656 return "DW_TAG_dwarf_procedure";
11657 case DW_TAG_restrict_type:
11658 return "DW_TAG_restrict_type";
11659 case DW_TAG_interface_type:
11660 return "DW_TAG_interface_type";
11661 case DW_TAG_namespace:
11662 return "DW_TAG_namespace";
11663 case DW_TAG_imported_module:
11664 return "DW_TAG_imported_module";
11665 case DW_TAG_unspecified_type:
11666 return "DW_TAG_unspecified_type";
11667 case DW_TAG_partial_unit:
11668 return "DW_TAG_partial_unit";
11669 case DW_TAG_imported_unit:
11670 return "DW_TAG_imported_unit";
11671 case DW_TAG_condition:
11672 return "DW_TAG_condition";
11673 case DW_TAG_shared_type:
11674 return "DW_TAG_shared_type";
11675 case DW_TAG_type_unit:
11676 return "DW_TAG_type_unit";
11677 case DW_TAG_MIPS_loop:
11678 return "DW_TAG_MIPS_loop";
11679 case DW_TAG_HP_array_descriptor:
11680 return "DW_TAG_HP_array_descriptor";
11681 case DW_TAG_format_label:
11682 return "DW_TAG_format_label";
11683 case DW_TAG_function_template:
11684 return "DW_TAG_function_template";
11685 case DW_TAG_class_template:
11686 return "DW_TAG_class_template";
11687 case DW_TAG_GNU_BINCL:
11688 return "DW_TAG_GNU_BINCL";
11689 case DW_TAG_GNU_EINCL:
11690 return "DW_TAG_GNU_EINCL";
11691 case DW_TAG_upc_shared_type:
11692 return "DW_TAG_upc_shared_type";
11693 case DW_TAG_upc_strict_type:
11694 return "DW_TAG_upc_strict_type";
11695 case DW_TAG_upc_relaxed_type:
11696 return "DW_TAG_upc_relaxed_type";
11697 case DW_TAG_PGI_kanji_type:
11698 return "DW_TAG_PGI_kanji_type";
11699 case DW_TAG_PGI_interface_block:
11700 return "DW_TAG_PGI_interface_block";
11701 default:
11702 return "DW_TAG_<unknown>";
11703 }
11704 }
11705
11706 /* Convert a DWARF attribute code into its string name. */
11707
11708 static char *
11709 dwarf_attr_name (unsigned attr)
11710 {
11711 switch (attr)
11712 {
11713 case DW_AT_sibling:
11714 return "DW_AT_sibling";
11715 case DW_AT_location:
11716 return "DW_AT_location";
11717 case DW_AT_name:
11718 return "DW_AT_name";
11719 case DW_AT_ordering:
11720 return "DW_AT_ordering";
11721 case DW_AT_subscr_data:
11722 return "DW_AT_subscr_data";
11723 case DW_AT_byte_size:
11724 return "DW_AT_byte_size";
11725 case DW_AT_bit_offset:
11726 return "DW_AT_bit_offset";
11727 case DW_AT_bit_size:
11728 return "DW_AT_bit_size";
11729 case DW_AT_element_list:
11730 return "DW_AT_element_list";
11731 case DW_AT_stmt_list:
11732 return "DW_AT_stmt_list";
11733 case DW_AT_low_pc:
11734 return "DW_AT_low_pc";
11735 case DW_AT_high_pc:
11736 return "DW_AT_high_pc";
11737 case DW_AT_language:
11738 return "DW_AT_language";
11739 case DW_AT_member:
11740 return "DW_AT_member";
11741 case DW_AT_discr:
11742 return "DW_AT_discr";
11743 case DW_AT_discr_value:
11744 return "DW_AT_discr_value";
11745 case DW_AT_visibility:
11746 return "DW_AT_visibility";
11747 case DW_AT_import:
11748 return "DW_AT_import";
11749 case DW_AT_string_length:
11750 return "DW_AT_string_length";
11751 case DW_AT_common_reference:
11752 return "DW_AT_common_reference";
11753 case DW_AT_comp_dir:
11754 return "DW_AT_comp_dir";
11755 case DW_AT_const_value:
11756 return "DW_AT_const_value";
11757 case DW_AT_containing_type:
11758 return "DW_AT_containing_type";
11759 case DW_AT_default_value:
11760 return "DW_AT_default_value";
11761 case DW_AT_inline:
11762 return "DW_AT_inline";
11763 case DW_AT_is_optional:
11764 return "DW_AT_is_optional";
11765 case DW_AT_lower_bound:
11766 return "DW_AT_lower_bound";
11767 case DW_AT_producer:
11768 return "DW_AT_producer";
11769 case DW_AT_prototyped:
11770 return "DW_AT_prototyped";
11771 case DW_AT_return_addr:
11772 return "DW_AT_return_addr";
11773 case DW_AT_start_scope:
11774 return "DW_AT_start_scope";
11775 case DW_AT_bit_stride:
11776 return "DW_AT_bit_stride";
11777 case DW_AT_upper_bound:
11778 return "DW_AT_upper_bound";
11779 case DW_AT_abstract_origin:
11780 return "DW_AT_abstract_origin";
11781 case DW_AT_accessibility:
11782 return "DW_AT_accessibility";
11783 case DW_AT_address_class:
11784 return "DW_AT_address_class";
11785 case DW_AT_artificial:
11786 return "DW_AT_artificial";
11787 case DW_AT_base_types:
11788 return "DW_AT_base_types";
11789 case DW_AT_calling_convention:
11790 return "DW_AT_calling_convention";
11791 case DW_AT_count:
11792 return "DW_AT_count";
11793 case DW_AT_data_member_location:
11794 return "DW_AT_data_member_location";
11795 case DW_AT_decl_column:
11796 return "DW_AT_decl_column";
11797 case DW_AT_decl_file:
11798 return "DW_AT_decl_file";
11799 case DW_AT_decl_line:
11800 return "DW_AT_decl_line";
11801 case DW_AT_declaration:
11802 return "DW_AT_declaration";
11803 case DW_AT_discr_list:
11804 return "DW_AT_discr_list";
11805 case DW_AT_encoding:
11806 return "DW_AT_encoding";
11807 case DW_AT_external:
11808 return "DW_AT_external";
11809 case DW_AT_frame_base:
11810 return "DW_AT_frame_base";
11811 case DW_AT_friend:
11812 return "DW_AT_friend";
11813 case DW_AT_identifier_case:
11814 return "DW_AT_identifier_case";
11815 case DW_AT_macro_info:
11816 return "DW_AT_macro_info";
11817 case DW_AT_namelist_items:
11818 return "DW_AT_namelist_items";
11819 case DW_AT_priority:
11820 return "DW_AT_priority";
11821 case DW_AT_segment:
11822 return "DW_AT_segment";
11823 case DW_AT_specification:
11824 return "DW_AT_specification";
11825 case DW_AT_static_link:
11826 return "DW_AT_static_link";
11827 case DW_AT_type:
11828 return "DW_AT_type";
11829 case DW_AT_use_location:
11830 return "DW_AT_use_location";
11831 case DW_AT_variable_parameter:
11832 return "DW_AT_variable_parameter";
11833 case DW_AT_virtuality:
11834 return "DW_AT_virtuality";
11835 case DW_AT_vtable_elem_location:
11836 return "DW_AT_vtable_elem_location";
11837 /* DWARF 3 values. */
11838 case DW_AT_allocated:
11839 return "DW_AT_allocated";
11840 case DW_AT_associated:
11841 return "DW_AT_associated";
11842 case DW_AT_data_location:
11843 return "DW_AT_data_location";
11844 case DW_AT_byte_stride:
11845 return "DW_AT_byte_stride";
11846 case DW_AT_entry_pc:
11847 return "DW_AT_entry_pc";
11848 case DW_AT_use_UTF8:
11849 return "DW_AT_use_UTF8";
11850 case DW_AT_extension:
11851 return "DW_AT_extension";
11852 case DW_AT_ranges:
11853 return "DW_AT_ranges";
11854 case DW_AT_trampoline:
11855 return "DW_AT_trampoline";
11856 case DW_AT_call_column:
11857 return "DW_AT_call_column";
11858 case DW_AT_call_file:
11859 return "DW_AT_call_file";
11860 case DW_AT_call_line:
11861 return "DW_AT_call_line";
11862 case DW_AT_description:
11863 return "DW_AT_description";
11864 case DW_AT_binary_scale:
11865 return "DW_AT_binary_scale";
11866 case DW_AT_decimal_scale:
11867 return "DW_AT_decimal_scale";
11868 case DW_AT_small:
11869 return "DW_AT_small";
11870 case DW_AT_decimal_sign:
11871 return "DW_AT_decimal_sign";
11872 case DW_AT_digit_count:
11873 return "DW_AT_digit_count";
11874 case DW_AT_picture_string:
11875 return "DW_AT_picture_string";
11876 case DW_AT_mutable:
11877 return "DW_AT_mutable";
11878 case DW_AT_threads_scaled:
11879 return "DW_AT_threads_scaled";
11880 case DW_AT_explicit:
11881 return "DW_AT_explicit";
11882 case DW_AT_object_pointer:
11883 return "DW_AT_object_pointer";
11884 case DW_AT_endianity:
11885 return "DW_AT_endianity";
11886 case DW_AT_elemental:
11887 return "DW_AT_elemental";
11888 case DW_AT_pure:
11889 return "DW_AT_pure";
11890 case DW_AT_recursive:
11891 return "DW_AT_recursive";
11892 /* DWARF 4 values. */
11893 case DW_AT_signature:
11894 return "DW_AT_signature";
11895 case DW_AT_linkage_name:
11896 return "DW_AT_linkage_name";
11897 /* SGI/MIPS extensions. */
11898 #ifdef MIPS /* collides with DW_AT_HP_block_index */
11899 case DW_AT_MIPS_fde:
11900 return "DW_AT_MIPS_fde";
11901 #endif
11902 case DW_AT_MIPS_loop_begin:
11903 return "DW_AT_MIPS_loop_begin";
11904 case DW_AT_MIPS_tail_loop_begin:
11905 return "DW_AT_MIPS_tail_loop_begin";
11906 case DW_AT_MIPS_epilog_begin:
11907 return "DW_AT_MIPS_epilog_begin";
11908 case DW_AT_MIPS_loop_unroll_factor:
11909 return "DW_AT_MIPS_loop_unroll_factor";
11910 case DW_AT_MIPS_software_pipeline_depth:
11911 return "DW_AT_MIPS_software_pipeline_depth";
11912 case DW_AT_MIPS_linkage_name:
11913 return "DW_AT_MIPS_linkage_name";
11914 case DW_AT_MIPS_stride:
11915 return "DW_AT_MIPS_stride";
11916 case DW_AT_MIPS_abstract_name:
11917 return "DW_AT_MIPS_abstract_name";
11918 case DW_AT_MIPS_clone_origin:
11919 return "DW_AT_MIPS_clone_origin";
11920 case DW_AT_MIPS_has_inlines:
11921 return "DW_AT_MIPS_has_inlines";
11922 /* HP extensions. */
11923 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
11924 case DW_AT_HP_block_index:
11925 return "DW_AT_HP_block_index";
11926 #endif
11927 case DW_AT_HP_unmodifiable:
11928 return "DW_AT_HP_unmodifiable";
11929 case DW_AT_HP_actuals_stmt_list:
11930 return "DW_AT_HP_actuals_stmt_list";
11931 case DW_AT_HP_proc_per_section:
11932 return "DW_AT_HP_proc_per_section";
11933 case DW_AT_HP_raw_data_ptr:
11934 return "DW_AT_HP_raw_data_ptr";
11935 case DW_AT_HP_pass_by_reference:
11936 return "DW_AT_HP_pass_by_reference";
11937 case DW_AT_HP_opt_level:
11938 return "DW_AT_HP_opt_level";
11939 case DW_AT_HP_prof_version_id:
11940 return "DW_AT_HP_prof_version_id";
11941 case DW_AT_HP_opt_flags:
11942 return "DW_AT_HP_opt_flags";
11943 case DW_AT_HP_cold_region_low_pc:
11944 return "DW_AT_HP_cold_region_low_pc";
11945 case DW_AT_HP_cold_region_high_pc:
11946 return "DW_AT_HP_cold_region_high_pc";
11947 case DW_AT_HP_all_variables_modifiable:
11948 return "DW_AT_HP_all_variables_modifiable";
11949 case DW_AT_HP_linkage_name:
11950 return "DW_AT_HP_linkage_name";
11951 case DW_AT_HP_prof_flags:
11952 return "DW_AT_HP_prof_flags";
11953 /* GNU extensions. */
11954 case DW_AT_sf_names:
11955 return "DW_AT_sf_names";
11956 case DW_AT_src_info:
11957 return "DW_AT_src_info";
11958 case DW_AT_mac_info:
11959 return "DW_AT_mac_info";
11960 case DW_AT_src_coords:
11961 return "DW_AT_src_coords";
11962 case DW_AT_body_begin:
11963 return "DW_AT_body_begin";
11964 case DW_AT_body_end:
11965 return "DW_AT_body_end";
11966 case DW_AT_GNU_vector:
11967 return "DW_AT_GNU_vector";
11968 case DW_AT_GNU_odr_signature:
11969 return "DW_AT_GNU_odr_signature";
11970 /* VMS extensions. */
11971 case DW_AT_VMS_rtnbeg_pd_address:
11972 return "DW_AT_VMS_rtnbeg_pd_address";
11973 /* UPC extension. */
11974 case DW_AT_upc_threads_scaled:
11975 return "DW_AT_upc_threads_scaled";
11976 /* PGI (STMicroelectronics) extensions. */
11977 case DW_AT_PGI_lbase:
11978 return "DW_AT_PGI_lbase";
11979 case DW_AT_PGI_soffset:
11980 return "DW_AT_PGI_soffset";
11981 case DW_AT_PGI_lstride:
11982 return "DW_AT_PGI_lstride";
11983 default:
11984 return "DW_AT_<unknown>";
11985 }
11986 }
11987
11988 /* Convert a DWARF value form code into its string name. */
11989
11990 static char *
11991 dwarf_form_name (unsigned form)
11992 {
11993 switch (form)
11994 {
11995 case DW_FORM_addr:
11996 return "DW_FORM_addr";
11997 case DW_FORM_block2:
11998 return "DW_FORM_block2";
11999 case DW_FORM_block4:
12000 return "DW_FORM_block4";
12001 case DW_FORM_data2:
12002 return "DW_FORM_data2";
12003 case DW_FORM_data4:
12004 return "DW_FORM_data4";
12005 case DW_FORM_data8:
12006 return "DW_FORM_data8";
12007 case DW_FORM_string:
12008 return "DW_FORM_string";
12009 case DW_FORM_block:
12010 return "DW_FORM_block";
12011 case DW_FORM_block1:
12012 return "DW_FORM_block1";
12013 case DW_FORM_data1:
12014 return "DW_FORM_data1";
12015 case DW_FORM_flag:
12016 return "DW_FORM_flag";
12017 case DW_FORM_sdata:
12018 return "DW_FORM_sdata";
12019 case DW_FORM_strp:
12020 return "DW_FORM_strp";
12021 case DW_FORM_udata:
12022 return "DW_FORM_udata";
12023 case DW_FORM_ref_addr:
12024 return "DW_FORM_ref_addr";
12025 case DW_FORM_ref1:
12026 return "DW_FORM_ref1";
12027 case DW_FORM_ref2:
12028 return "DW_FORM_ref2";
12029 case DW_FORM_ref4:
12030 return "DW_FORM_ref4";
12031 case DW_FORM_ref8:
12032 return "DW_FORM_ref8";
12033 case DW_FORM_ref_udata:
12034 return "DW_FORM_ref_udata";
12035 case DW_FORM_indirect:
12036 return "DW_FORM_indirect";
12037 case DW_FORM_sec_offset:
12038 return "DW_FORM_sec_offset";
12039 case DW_FORM_exprloc:
12040 return "DW_FORM_exprloc";
12041 case DW_FORM_flag_present:
12042 return "DW_FORM_flag_present";
12043 case DW_FORM_sig8:
12044 return "DW_FORM_sig8";
12045 default:
12046 return "DW_FORM_<unknown>";
12047 }
12048 }
12049
12050 /* Convert a DWARF stack opcode into its string name. */
12051
12052 const char *
12053 dwarf_stack_op_name (unsigned op, int def)
12054 {
12055 switch (op)
12056 {
12057 case DW_OP_addr:
12058 return "DW_OP_addr";
12059 case DW_OP_deref:
12060 return "DW_OP_deref";
12061 case DW_OP_const1u:
12062 return "DW_OP_const1u";
12063 case DW_OP_const1s:
12064 return "DW_OP_const1s";
12065 case DW_OP_const2u:
12066 return "DW_OP_const2u";
12067 case DW_OP_const2s:
12068 return "DW_OP_const2s";
12069 case DW_OP_const4u:
12070 return "DW_OP_const4u";
12071 case DW_OP_const4s:
12072 return "DW_OP_const4s";
12073 case DW_OP_const8u:
12074 return "DW_OP_const8u";
12075 case DW_OP_const8s:
12076 return "DW_OP_const8s";
12077 case DW_OP_constu:
12078 return "DW_OP_constu";
12079 case DW_OP_consts:
12080 return "DW_OP_consts";
12081 case DW_OP_dup:
12082 return "DW_OP_dup";
12083 case DW_OP_drop:
12084 return "DW_OP_drop";
12085 case DW_OP_over:
12086 return "DW_OP_over";
12087 case DW_OP_pick:
12088 return "DW_OP_pick";
12089 case DW_OP_swap:
12090 return "DW_OP_swap";
12091 case DW_OP_rot:
12092 return "DW_OP_rot";
12093 case DW_OP_xderef:
12094 return "DW_OP_xderef";
12095 case DW_OP_abs:
12096 return "DW_OP_abs";
12097 case DW_OP_and:
12098 return "DW_OP_and";
12099 case DW_OP_div:
12100 return "DW_OP_div";
12101 case DW_OP_minus:
12102 return "DW_OP_minus";
12103 case DW_OP_mod:
12104 return "DW_OP_mod";
12105 case DW_OP_mul:
12106 return "DW_OP_mul";
12107 case DW_OP_neg:
12108 return "DW_OP_neg";
12109 case DW_OP_not:
12110 return "DW_OP_not";
12111 case DW_OP_or:
12112 return "DW_OP_or";
12113 case DW_OP_plus:
12114 return "DW_OP_plus";
12115 case DW_OP_plus_uconst:
12116 return "DW_OP_plus_uconst";
12117 case DW_OP_shl:
12118 return "DW_OP_shl";
12119 case DW_OP_shr:
12120 return "DW_OP_shr";
12121 case DW_OP_shra:
12122 return "DW_OP_shra";
12123 case DW_OP_xor:
12124 return "DW_OP_xor";
12125 case DW_OP_bra:
12126 return "DW_OP_bra";
12127 case DW_OP_eq:
12128 return "DW_OP_eq";
12129 case DW_OP_ge:
12130 return "DW_OP_ge";
12131 case DW_OP_gt:
12132 return "DW_OP_gt";
12133 case DW_OP_le:
12134 return "DW_OP_le";
12135 case DW_OP_lt:
12136 return "DW_OP_lt";
12137 case DW_OP_ne:
12138 return "DW_OP_ne";
12139 case DW_OP_skip:
12140 return "DW_OP_skip";
12141 case DW_OP_lit0:
12142 return "DW_OP_lit0";
12143 case DW_OP_lit1:
12144 return "DW_OP_lit1";
12145 case DW_OP_lit2:
12146 return "DW_OP_lit2";
12147 case DW_OP_lit3:
12148 return "DW_OP_lit3";
12149 case DW_OP_lit4:
12150 return "DW_OP_lit4";
12151 case DW_OP_lit5:
12152 return "DW_OP_lit5";
12153 case DW_OP_lit6:
12154 return "DW_OP_lit6";
12155 case DW_OP_lit7:
12156 return "DW_OP_lit7";
12157 case DW_OP_lit8:
12158 return "DW_OP_lit8";
12159 case DW_OP_lit9:
12160 return "DW_OP_lit9";
12161 case DW_OP_lit10:
12162 return "DW_OP_lit10";
12163 case DW_OP_lit11:
12164 return "DW_OP_lit11";
12165 case DW_OP_lit12:
12166 return "DW_OP_lit12";
12167 case DW_OP_lit13:
12168 return "DW_OP_lit13";
12169 case DW_OP_lit14:
12170 return "DW_OP_lit14";
12171 case DW_OP_lit15:
12172 return "DW_OP_lit15";
12173 case DW_OP_lit16:
12174 return "DW_OP_lit16";
12175 case DW_OP_lit17:
12176 return "DW_OP_lit17";
12177 case DW_OP_lit18:
12178 return "DW_OP_lit18";
12179 case DW_OP_lit19:
12180 return "DW_OP_lit19";
12181 case DW_OP_lit20:
12182 return "DW_OP_lit20";
12183 case DW_OP_lit21:
12184 return "DW_OP_lit21";
12185 case DW_OP_lit22:
12186 return "DW_OP_lit22";
12187 case DW_OP_lit23:
12188 return "DW_OP_lit23";
12189 case DW_OP_lit24:
12190 return "DW_OP_lit24";
12191 case DW_OP_lit25:
12192 return "DW_OP_lit25";
12193 case DW_OP_lit26:
12194 return "DW_OP_lit26";
12195 case DW_OP_lit27:
12196 return "DW_OP_lit27";
12197 case DW_OP_lit28:
12198 return "DW_OP_lit28";
12199 case DW_OP_lit29:
12200 return "DW_OP_lit29";
12201 case DW_OP_lit30:
12202 return "DW_OP_lit30";
12203 case DW_OP_lit31:
12204 return "DW_OP_lit31";
12205 case DW_OP_reg0:
12206 return "DW_OP_reg0";
12207 case DW_OP_reg1:
12208 return "DW_OP_reg1";
12209 case DW_OP_reg2:
12210 return "DW_OP_reg2";
12211 case DW_OP_reg3:
12212 return "DW_OP_reg3";
12213 case DW_OP_reg4:
12214 return "DW_OP_reg4";
12215 case DW_OP_reg5:
12216 return "DW_OP_reg5";
12217 case DW_OP_reg6:
12218 return "DW_OP_reg6";
12219 case DW_OP_reg7:
12220 return "DW_OP_reg7";
12221 case DW_OP_reg8:
12222 return "DW_OP_reg8";
12223 case DW_OP_reg9:
12224 return "DW_OP_reg9";
12225 case DW_OP_reg10:
12226 return "DW_OP_reg10";
12227 case DW_OP_reg11:
12228 return "DW_OP_reg11";
12229 case DW_OP_reg12:
12230 return "DW_OP_reg12";
12231 case DW_OP_reg13:
12232 return "DW_OP_reg13";
12233 case DW_OP_reg14:
12234 return "DW_OP_reg14";
12235 case DW_OP_reg15:
12236 return "DW_OP_reg15";
12237 case DW_OP_reg16:
12238 return "DW_OP_reg16";
12239 case DW_OP_reg17:
12240 return "DW_OP_reg17";
12241 case DW_OP_reg18:
12242 return "DW_OP_reg18";
12243 case DW_OP_reg19:
12244 return "DW_OP_reg19";
12245 case DW_OP_reg20:
12246 return "DW_OP_reg20";
12247 case DW_OP_reg21:
12248 return "DW_OP_reg21";
12249 case DW_OP_reg22:
12250 return "DW_OP_reg22";
12251 case DW_OP_reg23:
12252 return "DW_OP_reg23";
12253 case DW_OP_reg24:
12254 return "DW_OP_reg24";
12255 case DW_OP_reg25:
12256 return "DW_OP_reg25";
12257 case DW_OP_reg26:
12258 return "DW_OP_reg26";
12259 case DW_OP_reg27:
12260 return "DW_OP_reg27";
12261 case DW_OP_reg28:
12262 return "DW_OP_reg28";
12263 case DW_OP_reg29:
12264 return "DW_OP_reg29";
12265 case DW_OP_reg30:
12266 return "DW_OP_reg30";
12267 case DW_OP_reg31:
12268 return "DW_OP_reg31";
12269 case DW_OP_breg0:
12270 return "DW_OP_breg0";
12271 case DW_OP_breg1:
12272 return "DW_OP_breg1";
12273 case DW_OP_breg2:
12274 return "DW_OP_breg2";
12275 case DW_OP_breg3:
12276 return "DW_OP_breg3";
12277 case DW_OP_breg4:
12278 return "DW_OP_breg4";
12279 case DW_OP_breg5:
12280 return "DW_OP_breg5";
12281 case DW_OP_breg6:
12282 return "DW_OP_breg6";
12283 case DW_OP_breg7:
12284 return "DW_OP_breg7";
12285 case DW_OP_breg8:
12286 return "DW_OP_breg8";
12287 case DW_OP_breg9:
12288 return "DW_OP_breg9";
12289 case DW_OP_breg10:
12290 return "DW_OP_breg10";
12291 case DW_OP_breg11:
12292 return "DW_OP_breg11";
12293 case DW_OP_breg12:
12294 return "DW_OP_breg12";
12295 case DW_OP_breg13:
12296 return "DW_OP_breg13";
12297 case DW_OP_breg14:
12298 return "DW_OP_breg14";
12299 case DW_OP_breg15:
12300 return "DW_OP_breg15";
12301 case DW_OP_breg16:
12302 return "DW_OP_breg16";
12303 case DW_OP_breg17:
12304 return "DW_OP_breg17";
12305 case DW_OP_breg18:
12306 return "DW_OP_breg18";
12307 case DW_OP_breg19:
12308 return "DW_OP_breg19";
12309 case DW_OP_breg20:
12310 return "DW_OP_breg20";
12311 case DW_OP_breg21:
12312 return "DW_OP_breg21";
12313 case DW_OP_breg22:
12314 return "DW_OP_breg22";
12315 case DW_OP_breg23:
12316 return "DW_OP_breg23";
12317 case DW_OP_breg24:
12318 return "DW_OP_breg24";
12319 case DW_OP_breg25:
12320 return "DW_OP_breg25";
12321 case DW_OP_breg26:
12322 return "DW_OP_breg26";
12323 case DW_OP_breg27:
12324 return "DW_OP_breg27";
12325 case DW_OP_breg28:
12326 return "DW_OP_breg28";
12327 case DW_OP_breg29:
12328 return "DW_OP_breg29";
12329 case DW_OP_breg30:
12330 return "DW_OP_breg30";
12331 case DW_OP_breg31:
12332 return "DW_OP_breg31";
12333 case DW_OP_regx:
12334 return "DW_OP_regx";
12335 case DW_OP_fbreg:
12336 return "DW_OP_fbreg";
12337 case DW_OP_bregx:
12338 return "DW_OP_bregx";
12339 case DW_OP_piece:
12340 return "DW_OP_piece";
12341 case DW_OP_deref_size:
12342 return "DW_OP_deref_size";
12343 case DW_OP_xderef_size:
12344 return "DW_OP_xderef_size";
12345 case DW_OP_nop:
12346 return "DW_OP_nop";
12347 /* DWARF 3 extensions. */
12348 case DW_OP_push_object_address:
12349 return "DW_OP_push_object_address";
12350 case DW_OP_call2:
12351 return "DW_OP_call2";
12352 case DW_OP_call4:
12353 return "DW_OP_call4";
12354 case DW_OP_call_ref:
12355 return "DW_OP_call_ref";
12356 case DW_OP_form_tls_address:
12357 return "DW_OP_form_tls_address";
12358 case DW_OP_call_frame_cfa:
12359 return "DW_OP_call_frame_cfa";
12360 case DW_OP_bit_piece:
12361 return "DW_OP_bit_piece";
12362 /* DWARF 4 extensions. */
12363 case DW_OP_implicit_value:
12364 return "DW_OP_implicit_value";
12365 case DW_OP_stack_value:
12366 return "DW_OP_stack_value";
12367 /* GNU extensions. */
12368 case DW_OP_GNU_push_tls_address:
12369 return "DW_OP_GNU_push_tls_address";
12370 case DW_OP_GNU_uninit:
12371 return "DW_OP_GNU_uninit";
12372 default:
12373 return def ? "OP_<unknown>" : NULL;
12374 }
12375 }
12376
12377 static char *
12378 dwarf_bool_name (unsigned mybool)
12379 {
12380 if (mybool)
12381 return "TRUE";
12382 else
12383 return "FALSE";
12384 }
12385
12386 /* Convert a DWARF type code into its string name. */
12387
12388 static char *
12389 dwarf_type_encoding_name (unsigned enc)
12390 {
12391 switch (enc)
12392 {
12393 case DW_ATE_void:
12394 return "DW_ATE_void";
12395 case DW_ATE_address:
12396 return "DW_ATE_address";
12397 case DW_ATE_boolean:
12398 return "DW_ATE_boolean";
12399 case DW_ATE_complex_float:
12400 return "DW_ATE_complex_float";
12401 case DW_ATE_float:
12402 return "DW_ATE_float";
12403 case DW_ATE_signed:
12404 return "DW_ATE_signed";
12405 case DW_ATE_signed_char:
12406 return "DW_ATE_signed_char";
12407 case DW_ATE_unsigned:
12408 return "DW_ATE_unsigned";
12409 case DW_ATE_unsigned_char:
12410 return "DW_ATE_unsigned_char";
12411 /* DWARF 3. */
12412 case DW_ATE_imaginary_float:
12413 return "DW_ATE_imaginary_float";
12414 case DW_ATE_packed_decimal:
12415 return "DW_ATE_packed_decimal";
12416 case DW_ATE_numeric_string:
12417 return "DW_ATE_numeric_string";
12418 case DW_ATE_edited:
12419 return "DW_ATE_edited";
12420 case DW_ATE_signed_fixed:
12421 return "DW_ATE_signed_fixed";
12422 case DW_ATE_unsigned_fixed:
12423 return "DW_ATE_unsigned_fixed";
12424 case DW_ATE_decimal_float:
12425 return "DW_ATE_decimal_float";
12426 /* DWARF 4. */
12427 case DW_ATE_UTF:
12428 return "DW_ATE_UTF";
12429 /* HP extensions. */
12430 case DW_ATE_HP_float80:
12431 return "DW_ATE_HP_float80";
12432 case DW_ATE_HP_complex_float80:
12433 return "DW_ATE_HP_complex_float80";
12434 case DW_ATE_HP_float128:
12435 return "DW_ATE_HP_float128";
12436 case DW_ATE_HP_complex_float128:
12437 return "DW_ATE_HP_complex_float128";
12438 case DW_ATE_HP_floathpintel:
12439 return "DW_ATE_HP_floathpintel";
12440 case DW_ATE_HP_imaginary_float80:
12441 return "DW_ATE_HP_imaginary_float80";
12442 case DW_ATE_HP_imaginary_float128:
12443 return "DW_ATE_HP_imaginary_float128";
12444 default:
12445 return "DW_ATE_<unknown>";
12446 }
12447 }
12448
12449 /* Convert a DWARF call frame info operation to its string name. */
12450
12451 #if 0
12452 static char *
12453 dwarf_cfi_name (unsigned cfi_opc)
12454 {
12455 switch (cfi_opc)
12456 {
12457 case DW_CFA_advance_loc:
12458 return "DW_CFA_advance_loc";
12459 case DW_CFA_offset:
12460 return "DW_CFA_offset";
12461 case DW_CFA_restore:
12462 return "DW_CFA_restore";
12463 case DW_CFA_nop:
12464 return "DW_CFA_nop";
12465 case DW_CFA_set_loc:
12466 return "DW_CFA_set_loc";
12467 case DW_CFA_advance_loc1:
12468 return "DW_CFA_advance_loc1";
12469 case DW_CFA_advance_loc2:
12470 return "DW_CFA_advance_loc2";
12471 case DW_CFA_advance_loc4:
12472 return "DW_CFA_advance_loc4";
12473 case DW_CFA_offset_extended:
12474 return "DW_CFA_offset_extended";
12475 case DW_CFA_restore_extended:
12476 return "DW_CFA_restore_extended";
12477 case DW_CFA_undefined:
12478 return "DW_CFA_undefined";
12479 case DW_CFA_same_value:
12480 return "DW_CFA_same_value";
12481 case DW_CFA_register:
12482 return "DW_CFA_register";
12483 case DW_CFA_remember_state:
12484 return "DW_CFA_remember_state";
12485 case DW_CFA_restore_state:
12486 return "DW_CFA_restore_state";
12487 case DW_CFA_def_cfa:
12488 return "DW_CFA_def_cfa";
12489 case DW_CFA_def_cfa_register:
12490 return "DW_CFA_def_cfa_register";
12491 case DW_CFA_def_cfa_offset:
12492 return "DW_CFA_def_cfa_offset";
12493 /* DWARF 3. */
12494 case DW_CFA_def_cfa_expression:
12495 return "DW_CFA_def_cfa_expression";
12496 case DW_CFA_expression:
12497 return "DW_CFA_expression";
12498 case DW_CFA_offset_extended_sf:
12499 return "DW_CFA_offset_extended_sf";
12500 case DW_CFA_def_cfa_sf:
12501 return "DW_CFA_def_cfa_sf";
12502 case DW_CFA_def_cfa_offset_sf:
12503 return "DW_CFA_def_cfa_offset_sf";
12504 case DW_CFA_val_offset:
12505 return "DW_CFA_val_offset";
12506 case DW_CFA_val_offset_sf:
12507 return "DW_CFA_val_offset_sf";
12508 case DW_CFA_val_expression:
12509 return "DW_CFA_val_expression";
12510 /* SGI/MIPS specific. */
12511 case DW_CFA_MIPS_advance_loc8:
12512 return "DW_CFA_MIPS_advance_loc8";
12513 /* GNU extensions. */
12514 case DW_CFA_GNU_window_save:
12515 return "DW_CFA_GNU_window_save";
12516 case DW_CFA_GNU_args_size:
12517 return "DW_CFA_GNU_args_size";
12518 case DW_CFA_GNU_negative_offset_extended:
12519 return "DW_CFA_GNU_negative_offset_extended";
12520 default:
12521 return "DW_CFA_<unknown>";
12522 }
12523 }
12524 #endif
12525
12526 static void
12527 dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
12528 {
12529 unsigned int i;
12530
12531 print_spaces (indent, f);
12532 fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n",
12533 dwarf_tag_name (die->tag), die->abbrev, die->offset);
12534
12535 if (die->parent != NULL)
12536 {
12537 print_spaces (indent, f);
12538 fprintf_unfiltered (f, " parent at offset: 0x%x\n",
12539 die->parent->offset);
12540 }
12541
12542 print_spaces (indent, f);
12543 fprintf_unfiltered (f, " has children: %s\n",
12544 dwarf_bool_name (die->child != NULL));
12545
12546 print_spaces (indent, f);
12547 fprintf_unfiltered (f, " attributes:\n");
12548
12549 for (i = 0; i < die->num_attrs; ++i)
12550 {
12551 print_spaces (indent, f);
12552 fprintf_unfiltered (f, " %s (%s) ",
12553 dwarf_attr_name (die->attrs[i].name),
12554 dwarf_form_name (die->attrs[i].form));
12555
12556 switch (die->attrs[i].form)
12557 {
12558 case DW_FORM_ref_addr:
12559 case DW_FORM_addr:
12560 fprintf_unfiltered (f, "address: ");
12561 fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f);
12562 break;
12563 case DW_FORM_block2:
12564 case DW_FORM_block4:
12565 case DW_FORM_block:
12566 case DW_FORM_block1:
12567 fprintf_unfiltered (f, "block: size %d", DW_BLOCK (&die->attrs[i])->size);
12568 break;
12569 case DW_FORM_exprloc:
12570 fprintf_unfiltered (f, "expression: size %u",
12571 DW_BLOCK (&die->attrs[i])->size);
12572 break;
12573 case DW_FORM_ref1:
12574 case DW_FORM_ref2:
12575 case DW_FORM_ref4:
12576 fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)",
12577 (long) (DW_ADDR (&die->attrs[i])));
12578 break;
12579 case DW_FORM_data1:
12580 case DW_FORM_data2:
12581 case DW_FORM_data4:
12582 case DW_FORM_data8:
12583 case DW_FORM_udata:
12584 case DW_FORM_sdata:
12585 fprintf_unfiltered (f, "constant: %s",
12586 pulongest (DW_UNSND (&die->attrs[i])));
12587 break;
12588 case DW_FORM_sec_offset:
12589 fprintf_unfiltered (f, "section offset: %s",
12590 pulongest (DW_UNSND (&die->attrs[i])));
12591 break;
12592 case DW_FORM_sig8:
12593 if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL)
12594 fprintf_unfiltered (f, "signatured type, offset: 0x%x",
12595 DW_SIGNATURED_TYPE (&die->attrs[i])->offset);
12596 else
12597 fprintf_unfiltered (f, "signatured type, offset: unknown");
12598 break;
12599 case DW_FORM_string:
12600 case DW_FORM_strp:
12601 fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)",
12602 DW_STRING (&die->attrs[i])
12603 ? DW_STRING (&die->attrs[i]) : "",
12604 DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not");
12605 break;
12606 case DW_FORM_flag:
12607 if (DW_UNSND (&die->attrs[i]))
12608 fprintf_unfiltered (f, "flag: TRUE");
12609 else
12610 fprintf_unfiltered (f, "flag: FALSE");
12611 break;
12612 case DW_FORM_flag_present:
12613 fprintf_unfiltered (f, "flag: TRUE");
12614 break;
12615 case DW_FORM_indirect:
12616 /* the reader will have reduced the indirect form to
12617 the "base form" so this form should not occur */
12618 fprintf_unfiltered (f, "unexpected attribute form: DW_FORM_indirect");
12619 break;
12620 default:
12621 fprintf_unfiltered (f, "unsupported attribute form: %d.",
12622 die->attrs[i].form);
12623 break;
12624 }
12625 fprintf_unfiltered (f, "\n");
12626 }
12627 }
12628
12629 static void
12630 dump_die_for_error (struct die_info *die)
12631 {
12632 dump_die_shallow (gdb_stderr, 0, die);
12633 }
12634
12635 static void
12636 dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die)
12637 {
12638 int indent = level * 4;
12639
12640 gdb_assert (die != NULL);
12641
12642 if (level >= max_level)
12643 return;
12644
12645 dump_die_shallow (f, indent, die);
12646
12647 if (die->child != NULL)
12648 {
12649 print_spaces (indent, f);
12650 fprintf_unfiltered (f, " Children:");
12651 if (level + 1 < max_level)
12652 {
12653 fprintf_unfiltered (f, "\n");
12654 dump_die_1 (f, level + 1, max_level, die->child);
12655 }
12656 else
12657 {
12658 fprintf_unfiltered (f, " [not printed, max nesting level reached]\n");
12659 }
12660 }
12661
12662 if (die->sibling != NULL && level > 0)
12663 {
12664 dump_die_1 (f, level, max_level, die->sibling);
12665 }
12666 }
12667
12668 /* This is called from the pdie macro in gdbinit.in.
12669 It's not static so gcc will keep a copy callable from gdb. */
12670
12671 void
12672 dump_die (struct die_info *die, int max_level)
12673 {
12674 dump_die_1 (gdb_stdlog, 0, max_level, die);
12675 }
12676
12677 static void
12678 store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu)
12679 {
12680 void **slot;
12681
12682 slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT);
12683
12684 *slot = die;
12685 }
12686
12687 static int
12688 is_ref_attr (struct attribute *attr)
12689 {
12690 switch (attr->form)
12691 {
12692 case DW_FORM_ref_addr:
12693 case DW_FORM_ref1:
12694 case DW_FORM_ref2:
12695 case DW_FORM_ref4:
12696 case DW_FORM_ref8:
12697 case DW_FORM_ref_udata:
12698 return 1;
12699 default:
12700 return 0;
12701 }
12702 }
12703
12704 static unsigned int
12705 dwarf2_get_ref_die_offset (struct attribute *attr)
12706 {
12707 if (is_ref_attr (attr))
12708 return DW_ADDR (attr);
12709
12710 complaint (&symfile_complaints,
12711 _("unsupported die ref attribute form: '%s'"),
12712 dwarf_form_name (attr->form));
12713 return 0;
12714 }
12715
12716 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
12717 * the value held by the attribute is not constant. */
12718
12719 static LONGEST
12720 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
12721 {
12722 if (attr->form == DW_FORM_sdata)
12723 return DW_SND (attr);
12724 else if (attr->form == DW_FORM_udata
12725 || attr->form == DW_FORM_data1
12726 || attr->form == DW_FORM_data2
12727 || attr->form == DW_FORM_data4
12728 || attr->form == DW_FORM_data8)
12729 return DW_UNSND (attr);
12730 else
12731 {
12732 complaint (&symfile_complaints, _("Attribute value is not a constant (%s)"),
12733 dwarf_form_name (attr->form));
12734 return default_value;
12735 }
12736 }
12737
12738 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
12739 unit and add it to our queue.
12740 The result is non-zero if PER_CU was queued, otherwise the result is zero
12741 meaning either PER_CU is already queued or it is already loaded. */
12742
12743 static int
12744 maybe_queue_comp_unit (struct dwarf2_cu *this_cu,
12745 struct dwarf2_per_cu_data *per_cu)
12746 {
12747 /* We may arrive here during partial symbol reading, if we need full
12748 DIEs to process an unusual case (e.g. template arguments). Do
12749 not queue PER_CU, just tell our caller to load its DIEs. */
12750 if (dwarf2_per_objfile->reading_partial_symbols)
12751 {
12752 if (per_cu->cu == NULL || per_cu->cu->dies == NULL)
12753 return 1;
12754 return 0;
12755 }
12756
12757 /* Mark the dependence relation so that we don't flush PER_CU
12758 too early. */
12759 dwarf2_add_dependence (this_cu, per_cu);
12760
12761 /* If it's already on the queue, we have nothing to do. */
12762 if (per_cu->queued)
12763 return 0;
12764
12765 /* If the compilation unit is already loaded, just mark it as
12766 used. */
12767 if (per_cu->cu != NULL)
12768 {
12769 per_cu->cu->last_used = 0;
12770 return 0;
12771 }
12772
12773 /* Add it to the queue. */
12774 queue_comp_unit (per_cu, this_cu->objfile);
12775
12776 return 1;
12777 }
12778
12779 /* Follow reference or signature attribute ATTR of SRC_DIE.
12780 On entry *REF_CU is the CU of SRC_DIE.
12781 On exit *REF_CU is the CU of the result. */
12782
12783 static struct die_info *
12784 follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr,
12785 struct dwarf2_cu **ref_cu)
12786 {
12787 struct die_info *die;
12788
12789 if (is_ref_attr (attr))
12790 die = follow_die_ref (src_die, attr, ref_cu);
12791 else if (attr->form == DW_FORM_sig8)
12792 die = follow_die_sig (src_die, attr, ref_cu);
12793 else
12794 {
12795 dump_die_for_error (src_die);
12796 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
12797 (*ref_cu)->objfile->name);
12798 }
12799
12800 return die;
12801 }
12802
12803 /* Follow reference OFFSET.
12804 On entry *REF_CU is the CU of the source die referencing OFFSET.
12805 On exit *REF_CU is the CU of the result.
12806 Returns NULL if OFFSET is invalid. */
12807
12808 static struct die_info *
12809 follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu)
12810 {
12811 struct die_info temp_die;
12812 struct dwarf2_cu *target_cu, *cu = *ref_cu;
12813
12814 gdb_assert (cu->per_cu != NULL);
12815
12816 target_cu = cu;
12817
12818 if (cu->per_cu->from_debug_types)
12819 {
12820 /* .debug_types CUs cannot reference anything outside their CU.
12821 If they need to, they have to reference a signatured type via
12822 DW_FORM_sig8. */
12823 if (! offset_in_cu_p (&cu->header, offset))
12824 return NULL;
12825 }
12826 else if (! offset_in_cu_p (&cu->header, offset))
12827 {
12828 struct dwarf2_per_cu_data *per_cu;
12829
12830 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
12831
12832 /* If necessary, add it to the queue and load its DIEs. */
12833 if (maybe_queue_comp_unit (cu, per_cu))
12834 load_full_comp_unit (per_cu, cu->objfile);
12835
12836 target_cu = per_cu->cu;
12837 }
12838 else if (cu->dies == NULL)
12839 {
12840 /* We're loading full DIEs during partial symbol reading. */
12841 gdb_assert (dwarf2_per_objfile->reading_partial_symbols);
12842 load_full_comp_unit (cu->per_cu, cu->objfile);
12843 }
12844
12845 *ref_cu = target_cu;
12846 temp_die.offset = offset;
12847 return htab_find_with_hash (target_cu->die_hash, &temp_die, offset);
12848 }
12849
12850 /* Follow reference attribute ATTR of SRC_DIE.
12851 On entry *REF_CU is the CU of SRC_DIE.
12852 On exit *REF_CU is the CU of the result. */
12853
12854 static struct die_info *
12855 follow_die_ref (struct die_info *src_die, struct attribute *attr,
12856 struct dwarf2_cu **ref_cu)
12857 {
12858 unsigned int offset = dwarf2_get_ref_die_offset (attr);
12859 struct dwarf2_cu *cu = *ref_cu;
12860 struct die_info *die;
12861
12862 die = follow_die_offset (offset, ref_cu);
12863 if (!die)
12864 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
12865 "at 0x%x [in module %s]"),
12866 offset, src_die->offset, cu->objfile->name);
12867
12868 return die;
12869 }
12870
12871 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
12872 value is intended for DW_OP_call*. */
12873
12874 struct dwarf2_locexpr_baton
12875 dwarf2_fetch_die_location_block (unsigned int offset,
12876 struct dwarf2_per_cu_data *per_cu)
12877 {
12878 struct dwarf2_cu *cu = per_cu->cu;
12879 struct die_info *die;
12880 struct attribute *attr;
12881 struct dwarf2_locexpr_baton retval;
12882
12883 die = follow_die_offset (offset, &cu);
12884 if (!die)
12885 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
12886 offset, per_cu->cu->objfile->name);
12887
12888 attr = dwarf2_attr (die, DW_AT_location, cu);
12889 if (!attr)
12890 {
12891 /* DWARF: "If there is no such attribute, then there is no effect.". */
12892
12893 retval.data = NULL;
12894 retval.size = 0;
12895 }
12896 else
12897 {
12898 if (!attr_form_is_block (attr))
12899 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
12900 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
12901 offset, per_cu->cu->objfile->name);
12902
12903 retval.data = DW_BLOCK (attr)->data;
12904 retval.size = DW_BLOCK (attr)->size;
12905 }
12906 retval.per_cu = cu->per_cu;
12907 return retval;
12908 }
12909
12910 /* Follow the signature attribute ATTR in SRC_DIE.
12911 On entry *REF_CU is the CU of SRC_DIE.
12912 On exit *REF_CU is the CU of the result. */
12913
12914 static struct die_info *
12915 follow_die_sig (struct die_info *src_die, struct attribute *attr,
12916 struct dwarf2_cu **ref_cu)
12917 {
12918 struct objfile *objfile = (*ref_cu)->objfile;
12919 struct die_info temp_die;
12920 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
12921 struct dwarf2_cu *sig_cu;
12922 struct die_info *die;
12923
12924 /* sig_type will be NULL if the signatured type is missing from
12925 the debug info. */
12926 if (sig_type == NULL)
12927 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12928 "at 0x%x [in module %s]"),
12929 src_die->offset, objfile->name);
12930
12931 /* If necessary, add it to the queue and load its DIEs. */
12932
12933 if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu))
12934 read_signatured_type (objfile, sig_type);
12935
12936 gdb_assert (sig_type->per_cu.cu != NULL);
12937
12938 sig_cu = sig_type->per_cu.cu;
12939 temp_die.offset = sig_cu->header.offset + sig_type->type_offset;
12940 die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset);
12941 if (die)
12942 {
12943 *ref_cu = sig_cu;
12944 return die;
12945 }
12946
12947 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
12948 "at 0x%x [in module %s]"),
12949 sig_type->type_offset, src_die->offset, objfile->name);
12950 }
12951
12952 /* Given an offset of a signatured type, return its signatured_type. */
12953
12954 static struct signatured_type *
12955 lookup_signatured_type_at_offset (struct objfile *objfile, unsigned int offset)
12956 {
12957 gdb_byte *info_ptr = dwarf2_per_objfile->types.buffer + offset;
12958 unsigned int length, initial_length_size;
12959 unsigned int sig_offset;
12960 struct signatured_type find_entry, *type_sig;
12961
12962 length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size);
12963 sig_offset = (initial_length_size
12964 + 2 /*version*/
12965 + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/
12966 + 1 /*address_size*/);
12967 find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset);
12968 type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
12969
12970 /* This is only used to lookup previously recorded types.
12971 If we didn't find it, it's our bug. */
12972 gdb_assert (type_sig != NULL);
12973 gdb_assert (offset == type_sig->offset);
12974
12975 return type_sig;
12976 }
12977
12978 /* Read in signatured type at OFFSET and build its CU and die(s). */
12979
12980 static void
12981 read_signatured_type_at_offset (struct objfile *objfile,
12982 unsigned int offset)
12983 {
12984 struct signatured_type *type_sig;
12985
12986 dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
12987
12988 /* We have the section offset, but we need the signature to do the
12989 hash table lookup. */
12990 type_sig = lookup_signatured_type_at_offset (objfile, offset);
12991
12992 gdb_assert (type_sig->per_cu.cu == NULL);
12993
12994 read_signatured_type (objfile, type_sig);
12995
12996 gdb_assert (type_sig->per_cu.cu != NULL);
12997 }
12998
12999 /* Read in a signatured type and build its CU and DIEs. */
13000
13001 static void
13002 read_signatured_type (struct objfile *objfile,
13003 struct signatured_type *type_sig)
13004 {
13005 gdb_byte *types_ptr;
13006 struct die_reader_specs reader_specs;
13007 struct dwarf2_cu *cu;
13008 ULONGEST signature;
13009 struct cleanup *back_to, *free_cu_cleanup;
13010 struct attribute *attr;
13011
13012 dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
13013 types_ptr = dwarf2_per_objfile->types.buffer + type_sig->offset;
13014
13015 gdb_assert (type_sig->per_cu.cu == NULL);
13016
13017 cu = xmalloc (sizeof (struct dwarf2_cu));
13018 memset (cu, 0, sizeof (struct dwarf2_cu));
13019 obstack_init (&cu->comp_unit_obstack);
13020 cu->objfile = objfile;
13021 type_sig->per_cu.cu = cu;
13022 cu->per_cu = &type_sig->per_cu;
13023
13024 /* If an error occurs while loading, release our storage. */
13025 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
13026
13027 types_ptr = read_type_comp_unit_head (&cu->header, &signature,
13028 types_ptr, objfile->obfd);
13029 gdb_assert (signature == type_sig->signature);
13030
13031 cu->die_hash
13032 = htab_create_alloc_ex (cu->header.length / 12,
13033 die_hash,
13034 die_eq,
13035 NULL,
13036 &cu->comp_unit_obstack,
13037 hashtab_obstack_allocate,
13038 dummy_obstack_deallocate);
13039
13040 dwarf2_read_abbrevs (cu->objfile->obfd, cu);
13041 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
13042
13043 init_cu_die_reader (&reader_specs, cu);
13044
13045 cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr,
13046 NULL /*parent*/);
13047
13048 /* We try not to read any attributes in this function, because not
13049 all objfiles needed for references have been loaded yet, and symbol
13050 table processing isn't initialized. But we have to set the CU language,
13051 or we won't be able to build types correctly. */
13052 attr = dwarf2_attr (cu->dies, DW_AT_language, cu);
13053 if (attr)
13054 set_cu_language (DW_UNSND (attr), cu);
13055 else
13056 set_cu_language (language_minimal, cu);
13057
13058 do_cleanups (back_to);
13059
13060 /* We've successfully allocated this compilation unit. Let our caller
13061 clean it up when finished with it. */
13062 discard_cleanups (free_cu_cleanup);
13063
13064 type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
13065 dwarf2_per_objfile->read_in_chain = &type_sig->per_cu;
13066 }
13067
13068 /* Decode simple location descriptions.
13069 Given a pointer to a dwarf block that defines a location, compute
13070 the location and return the value.
13071
13072 NOTE drow/2003-11-18: This function is called in two situations
13073 now: for the address of static or global variables (partial symbols
13074 only) and for offsets into structures which are expected to be
13075 (more or less) constant. The partial symbol case should go away,
13076 and only the constant case should remain. That will let this
13077 function complain more accurately. A few special modes are allowed
13078 without complaint for global variables (for instance, global
13079 register values and thread-local values).
13080
13081 A location description containing no operations indicates that the
13082 object is optimized out. The return value is 0 for that case.
13083 FIXME drow/2003-11-16: No callers check for this case any more; soon all
13084 callers will only want a very basic result and this can become a
13085 complaint.
13086
13087 Note that stack[0] is unused except as a default error return.
13088 Note that stack overflow is not yet handled. */
13089
13090 static CORE_ADDR
13091 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
13092 {
13093 struct objfile *objfile = cu->objfile;
13094 int i;
13095 int size = blk->size;
13096 gdb_byte *data = blk->data;
13097 CORE_ADDR stack[64];
13098 int stacki;
13099 unsigned int bytes_read, unsnd;
13100 gdb_byte op;
13101
13102 i = 0;
13103 stacki = 0;
13104 stack[stacki] = 0;
13105
13106 while (i < size)
13107 {
13108 op = data[i++];
13109 switch (op)
13110 {
13111 case DW_OP_lit0:
13112 case DW_OP_lit1:
13113 case DW_OP_lit2:
13114 case DW_OP_lit3:
13115 case DW_OP_lit4:
13116 case DW_OP_lit5:
13117 case DW_OP_lit6:
13118 case DW_OP_lit7:
13119 case DW_OP_lit8:
13120 case DW_OP_lit9:
13121 case DW_OP_lit10:
13122 case DW_OP_lit11:
13123 case DW_OP_lit12:
13124 case DW_OP_lit13:
13125 case DW_OP_lit14:
13126 case DW_OP_lit15:
13127 case DW_OP_lit16:
13128 case DW_OP_lit17:
13129 case DW_OP_lit18:
13130 case DW_OP_lit19:
13131 case DW_OP_lit20:
13132 case DW_OP_lit21:
13133 case DW_OP_lit22:
13134 case DW_OP_lit23:
13135 case DW_OP_lit24:
13136 case DW_OP_lit25:
13137 case DW_OP_lit26:
13138 case DW_OP_lit27:
13139 case DW_OP_lit28:
13140 case DW_OP_lit29:
13141 case DW_OP_lit30:
13142 case DW_OP_lit31:
13143 stack[++stacki] = op - DW_OP_lit0;
13144 break;
13145
13146 case DW_OP_reg0:
13147 case DW_OP_reg1:
13148 case DW_OP_reg2:
13149 case DW_OP_reg3:
13150 case DW_OP_reg4:
13151 case DW_OP_reg5:
13152 case DW_OP_reg6:
13153 case DW_OP_reg7:
13154 case DW_OP_reg8:
13155 case DW_OP_reg9:
13156 case DW_OP_reg10:
13157 case DW_OP_reg11:
13158 case DW_OP_reg12:
13159 case DW_OP_reg13:
13160 case DW_OP_reg14:
13161 case DW_OP_reg15:
13162 case DW_OP_reg16:
13163 case DW_OP_reg17:
13164 case DW_OP_reg18:
13165 case DW_OP_reg19:
13166 case DW_OP_reg20:
13167 case DW_OP_reg21:
13168 case DW_OP_reg22:
13169 case DW_OP_reg23:
13170 case DW_OP_reg24:
13171 case DW_OP_reg25:
13172 case DW_OP_reg26:
13173 case DW_OP_reg27:
13174 case DW_OP_reg28:
13175 case DW_OP_reg29:
13176 case DW_OP_reg30:
13177 case DW_OP_reg31:
13178 stack[++stacki] = op - DW_OP_reg0;
13179 if (i < size)
13180 dwarf2_complex_location_expr_complaint ();
13181 break;
13182
13183 case DW_OP_regx:
13184 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
13185 i += bytes_read;
13186 stack[++stacki] = unsnd;
13187 if (i < size)
13188 dwarf2_complex_location_expr_complaint ();
13189 break;
13190
13191 case DW_OP_addr:
13192 stack[++stacki] = read_address (objfile->obfd, &data[i],
13193 cu, &bytes_read);
13194 i += bytes_read;
13195 break;
13196
13197 case DW_OP_const1u:
13198 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
13199 i += 1;
13200 break;
13201
13202 case DW_OP_const1s:
13203 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
13204 i += 1;
13205 break;
13206
13207 case DW_OP_const2u:
13208 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
13209 i += 2;
13210 break;
13211
13212 case DW_OP_const2s:
13213 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
13214 i += 2;
13215 break;
13216
13217 case DW_OP_const4u:
13218 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
13219 i += 4;
13220 break;
13221
13222 case DW_OP_const4s:
13223 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
13224 i += 4;
13225 break;
13226
13227 case DW_OP_constu:
13228 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
13229 &bytes_read);
13230 i += bytes_read;
13231 break;
13232
13233 case DW_OP_consts:
13234 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
13235 i += bytes_read;
13236 break;
13237
13238 case DW_OP_dup:
13239 stack[stacki + 1] = stack[stacki];
13240 stacki++;
13241 break;
13242
13243 case DW_OP_plus:
13244 stack[stacki - 1] += stack[stacki];
13245 stacki--;
13246 break;
13247
13248 case DW_OP_plus_uconst:
13249 stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read);
13250 i += bytes_read;
13251 break;
13252
13253 case DW_OP_minus:
13254 stack[stacki - 1] -= stack[stacki];
13255 stacki--;
13256 break;
13257
13258 case DW_OP_deref:
13259 /* If we're not the last op, then we definitely can't encode
13260 this using GDB's address_class enum. This is valid for partial
13261 global symbols, although the variable's address will be bogus
13262 in the psymtab. */
13263 if (i < size)
13264 dwarf2_complex_location_expr_complaint ();
13265 break;
13266
13267 case DW_OP_GNU_push_tls_address:
13268 /* The top of the stack has the offset from the beginning
13269 of the thread control block at which the variable is located. */
13270 /* Nothing should follow this operator, so the top of stack would
13271 be returned. */
13272 /* This is valid for partial global symbols, but the variable's
13273 address will be bogus in the psymtab. */
13274 if (i < size)
13275 dwarf2_complex_location_expr_complaint ();
13276 break;
13277
13278 case DW_OP_GNU_uninit:
13279 break;
13280
13281 default:
13282 complaint (&symfile_complaints, _("unsupported stack op: '%s'"),
13283 dwarf_stack_op_name (op, 1));
13284 return (stack[stacki]);
13285 }
13286 }
13287 return (stack[stacki]);
13288 }
13289
13290 /* memory allocation interface */
13291
13292 static struct dwarf_block *
13293 dwarf_alloc_block (struct dwarf2_cu *cu)
13294 {
13295 struct dwarf_block *blk;
13296
13297 blk = (struct dwarf_block *)
13298 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block));
13299 return (blk);
13300 }
13301
13302 static struct abbrev_info *
13303 dwarf_alloc_abbrev (struct dwarf2_cu *cu)
13304 {
13305 struct abbrev_info *abbrev;
13306
13307 abbrev = (struct abbrev_info *)
13308 obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info));
13309 memset (abbrev, 0, sizeof (struct abbrev_info));
13310 return (abbrev);
13311 }
13312
13313 static struct die_info *
13314 dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs)
13315 {
13316 struct die_info *die;
13317 size_t size = sizeof (struct die_info);
13318
13319 if (num_attrs > 1)
13320 size += (num_attrs - 1) * sizeof (struct attribute);
13321
13322 die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size);
13323 memset (die, 0, sizeof (struct die_info));
13324 return (die);
13325 }
13326
13327 \f
13328 /* Macro support. */
13329
13330
13331 /* Return the full name of file number I in *LH's file name table.
13332 Use COMP_DIR as the name of the current directory of the
13333 compilation. The result is allocated using xmalloc; the caller is
13334 responsible for freeing it. */
13335 static char *
13336 file_full_name (int file, struct line_header *lh, const char *comp_dir)
13337 {
13338 /* Is the file number a valid index into the line header's file name
13339 table? Remember that file numbers start with one, not zero. */
13340 if (1 <= file && file <= lh->num_file_names)
13341 {
13342 struct file_entry *fe = &lh->file_names[file - 1];
13343
13344 if (IS_ABSOLUTE_PATH (fe->name))
13345 return xstrdup (fe->name);
13346 else
13347 {
13348 const char *dir;
13349 int dir_len;
13350 char *full_name;
13351
13352 if (fe->dir_index)
13353 dir = lh->include_dirs[fe->dir_index - 1];
13354 else
13355 dir = comp_dir;
13356
13357 if (dir)
13358 {
13359 dir_len = strlen (dir);
13360 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
13361 strcpy (full_name, dir);
13362 full_name[dir_len] = '/';
13363 strcpy (full_name + dir_len + 1, fe->name);
13364 return full_name;
13365 }
13366 else
13367 return xstrdup (fe->name);
13368 }
13369 }
13370 else
13371 {
13372 /* The compiler produced a bogus file number. We can at least
13373 record the macro definitions made in the file, even if we
13374 won't be able to find the file by name. */
13375 char fake_name[80];
13376
13377 sprintf (fake_name, "<bad macro file number %d>", file);
13378
13379 complaint (&symfile_complaints,
13380 _("bad file number in macro information (%d)"),
13381 file);
13382
13383 return xstrdup (fake_name);
13384 }
13385 }
13386
13387
13388 static struct macro_source_file *
13389 macro_start_file (int file, int line,
13390 struct macro_source_file *current_file,
13391 const char *comp_dir,
13392 struct line_header *lh, struct objfile *objfile)
13393 {
13394 /* The full name of this source file. */
13395 char *full_name = file_full_name (file, lh, comp_dir);
13396
13397 /* We don't create a macro table for this compilation unit
13398 at all until we actually get a filename. */
13399 if (! pending_macros)
13400 pending_macros = new_macro_table (&objfile->objfile_obstack,
13401 objfile->macro_cache);
13402
13403 if (! current_file)
13404 /* If we have no current file, then this must be the start_file
13405 directive for the compilation unit's main source file. */
13406 current_file = macro_set_main (pending_macros, full_name);
13407 else
13408 current_file = macro_include (current_file, line, full_name);
13409
13410 xfree (full_name);
13411
13412 return current_file;
13413 }
13414
13415
13416 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
13417 followed by a null byte. */
13418 static char *
13419 copy_string (const char *buf, int len)
13420 {
13421 char *s = xmalloc (len + 1);
13422
13423 memcpy (s, buf, len);
13424 s[len] = '\0';
13425 return s;
13426 }
13427
13428
13429 static const char *
13430 consume_improper_spaces (const char *p, const char *body)
13431 {
13432 if (*p == ' ')
13433 {
13434 complaint (&symfile_complaints,
13435 _("macro definition contains spaces in formal argument list:\n`%s'"),
13436 body);
13437
13438 while (*p == ' ')
13439 p++;
13440 }
13441
13442 return p;
13443 }
13444
13445
13446 static void
13447 parse_macro_definition (struct macro_source_file *file, int line,
13448 const char *body)
13449 {
13450 const char *p;
13451
13452 /* The body string takes one of two forms. For object-like macro
13453 definitions, it should be:
13454
13455 <macro name> " " <definition>
13456
13457 For function-like macro definitions, it should be:
13458
13459 <macro name> "() " <definition>
13460 or
13461 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
13462
13463 Spaces may appear only where explicitly indicated, and in the
13464 <definition>.
13465
13466 The Dwarf 2 spec says that an object-like macro's name is always
13467 followed by a space, but versions of GCC around March 2002 omit
13468 the space when the macro's definition is the empty string.
13469
13470 The Dwarf 2 spec says that there should be no spaces between the
13471 formal arguments in a function-like macro's formal argument list,
13472 but versions of GCC around March 2002 include spaces after the
13473 commas. */
13474
13475
13476 /* Find the extent of the macro name. The macro name is terminated
13477 by either a space or null character (for an object-like macro) or
13478 an opening paren (for a function-like macro). */
13479 for (p = body; *p; p++)
13480 if (*p == ' ' || *p == '(')
13481 break;
13482
13483 if (*p == ' ' || *p == '\0')
13484 {
13485 /* It's an object-like macro. */
13486 int name_len = p - body;
13487 char *name = copy_string (body, name_len);
13488 const char *replacement;
13489
13490 if (*p == ' ')
13491 replacement = body + name_len + 1;
13492 else
13493 {
13494 dwarf2_macro_malformed_definition_complaint (body);
13495 replacement = body + name_len;
13496 }
13497
13498 macro_define_object (file, line, name, replacement);
13499
13500 xfree (name);
13501 }
13502 else if (*p == '(')
13503 {
13504 /* It's a function-like macro. */
13505 char *name = copy_string (body, p - body);
13506 int argc = 0;
13507 int argv_size = 1;
13508 char **argv = xmalloc (argv_size * sizeof (*argv));
13509
13510 p++;
13511
13512 p = consume_improper_spaces (p, body);
13513
13514 /* Parse the formal argument list. */
13515 while (*p && *p != ')')
13516 {
13517 /* Find the extent of the current argument name. */
13518 const char *arg_start = p;
13519
13520 while (*p && *p != ',' && *p != ')' && *p != ' ')
13521 p++;
13522
13523 if (! *p || p == arg_start)
13524 dwarf2_macro_malformed_definition_complaint (body);
13525 else
13526 {
13527 /* Make sure argv has room for the new argument. */
13528 if (argc >= argv_size)
13529 {
13530 argv_size *= 2;
13531 argv = xrealloc (argv, argv_size * sizeof (*argv));
13532 }
13533
13534 argv[argc++] = copy_string (arg_start, p - arg_start);
13535 }
13536
13537 p = consume_improper_spaces (p, body);
13538
13539 /* Consume the comma, if present. */
13540 if (*p == ',')
13541 {
13542 p++;
13543
13544 p = consume_improper_spaces (p, body);
13545 }
13546 }
13547
13548 if (*p == ')')
13549 {
13550 p++;
13551
13552 if (*p == ' ')
13553 /* Perfectly formed definition, no complaints. */
13554 macro_define_function (file, line, name,
13555 argc, (const char **) argv,
13556 p + 1);
13557 else if (*p == '\0')
13558 {
13559 /* Complain, but do define it. */
13560 dwarf2_macro_malformed_definition_complaint (body);
13561 macro_define_function (file, line, name,
13562 argc, (const char **) argv,
13563 p);
13564 }
13565 else
13566 /* Just complain. */
13567 dwarf2_macro_malformed_definition_complaint (body);
13568 }
13569 else
13570 /* Just complain. */
13571 dwarf2_macro_malformed_definition_complaint (body);
13572
13573 xfree (name);
13574 {
13575 int i;
13576
13577 for (i = 0; i < argc; i++)
13578 xfree (argv[i]);
13579 }
13580 xfree (argv);
13581 }
13582 else
13583 dwarf2_macro_malformed_definition_complaint (body);
13584 }
13585
13586
13587 static void
13588 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
13589 char *comp_dir, bfd *abfd,
13590 struct dwarf2_cu *cu)
13591 {
13592 gdb_byte *mac_ptr, *mac_end;
13593 struct macro_source_file *current_file = 0;
13594 enum dwarf_macinfo_record_type macinfo_type;
13595 int at_commandline;
13596
13597 dwarf2_read_section (dwarf2_per_objfile->objfile,
13598 &dwarf2_per_objfile->macinfo);
13599 if (dwarf2_per_objfile->macinfo.buffer == NULL)
13600 {
13601 complaint (&symfile_complaints, _("missing .debug_macinfo section"));
13602 return;
13603 }
13604
13605 /* First pass: Find the name of the base filename.
13606 This filename is needed in order to process all macros whose definition
13607 (or undefinition) comes from the command line. These macros are defined
13608 before the first DW_MACINFO_start_file entry, and yet still need to be
13609 associated to the base file.
13610
13611 To determine the base file name, we scan the macro definitions until we
13612 reach the first DW_MACINFO_start_file entry. We then initialize
13613 CURRENT_FILE accordingly so that any macro definition found before the
13614 first DW_MACINFO_start_file can still be associated to the base file. */
13615
13616 mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
13617 mac_end = dwarf2_per_objfile->macinfo.buffer
13618 + dwarf2_per_objfile->macinfo.size;
13619
13620 do
13621 {
13622 /* Do we at least have room for a macinfo type byte? */
13623 if (mac_ptr >= mac_end)
13624 {
13625 /* Complaint is printed during the second pass as GDB will probably
13626 stop the first pass earlier upon finding DW_MACINFO_start_file. */
13627 break;
13628 }
13629
13630 macinfo_type = read_1_byte (abfd, mac_ptr);
13631 mac_ptr++;
13632
13633 switch (macinfo_type)
13634 {
13635 /* A zero macinfo type indicates the end of the macro
13636 information. */
13637 case 0:
13638 break;
13639
13640 case DW_MACINFO_define:
13641 case DW_MACINFO_undef:
13642 /* Only skip the data by MAC_PTR. */
13643 {
13644 unsigned int bytes_read;
13645
13646 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
13647 mac_ptr += bytes_read;
13648 read_direct_string (abfd, mac_ptr, &bytes_read);
13649 mac_ptr += bytes_read;
13650 }
13651 break;
13652
13653 case DW_MACINFO_start_file:
13654 {
13655 unsigned int bytes_read;
13656 int line, file;
13657
13658 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
13659 mac_ptr += bytes_read;
13660 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
13661 mac_ptr += bytes_read;
13662
13663 current_file = macro_start_file (file, line, current_file, comp_dir,
13664 lh, cu->objfile);
13665 }
13666 break;
13667
13668 case DW_MACINFO_end_file:
13669 /* No data to skip by MAC_PTR. */
13670 break;
13671
13672 case DW_MACINFO_vendor_ext:
13673 /* Only skip the data by MAC_PTR. */
13674 {
13675 unsigned int bytes_read;
13676
13677 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
13678 mac_ptr += bytes_read;
13679 read_direct_string (abfd, mac_ptr, &bytes_read);
13680 mac_ptr += bytes_read;
13681 }
13682 break;
13683
13684 default:
13685 break;
13686 }
13687 } while (macinfo_type != 0 && current_file == NULL);
13688
13689 /* Second pass: Process all entries.
13690
13691 Use the AT_COMMAND_LINE flag to determine whether we are still processing
13692 command-line macro definitions/undefinitions. This flag is unset when we
13693 reach the first DW_MACINFO_start_file entry. */
13694
13695 mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
13696
13697 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
13698 GDB is still reading the definitions from command line. First
13699 DW_MACINFO_start_file will need to be ignored as it was already executed
13700 to create CURRENT_FILE for the main source holding also the command line
13701 definitions. On first met DW_MACINFO_start_file this flag is reset to
13702 normally execute all the remaining DW_MACINFO_start_file macinfos. */
13703
13704 at_commandline = 1;
13705
13706 do
13707 {
13708 /* Do we at least have room for a macinfo type byte? */
13709 if (mac_ptr >= mac_end)
13710 {
13711 dwarf2_macros_too_long_complaint ();
13712 break;
13713 }
13714
13715 macinfo_type = read_1_byte (abfd, mac_ptr);
13716 mac_ptr++;
13717
13718 switch (macinfo_type)
13719 {
13720 /* A zero macinfo type indicates the end of the macro
13721 information. */
13722 case 0:
13723 break;
13724
13725 case DW_MACINFO_define:
13726 case DW_MACINFO_undef:
13727 {
13728 unsigned int bytes_read;
13729 int line;
13730 char *body;
13731
13732 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
13733 mac_ptr += bytes_read;
13734 body = read_direct_string (abfd, mac_ptr, &bytes_read);
13735 mac_ptr += bytes_read;
13736
13737 if (! current_file)
13738 {
13739 /* DWARF violation as no main source is present. */
13740 complaint (&symfile_complaints,
13741 _("debug info with no main source gives macro %s "
13742 "on line %d: %s"),
13743 macinfo_type == DW_MACINFO_define ?
13744 _("definition") :
13745 macinfo_type == DW_MACINFO_undef ?
13746 _("undefinition") :
13747 _("something-or-other"), line, body);
13748 break;
13749 }
13750 if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
13751 complaint (&symfile_complaints,
13752 _("debug info gives %s macro %s with %s line %d: %s"),
13753 at_commandline ? _("command-line") : _("in-file"),
13754 macinfo_type == DW_MACINFO_define ?
13755 _("definition") :
13756 macinfo_type == DW_MACINFO_undef ?
13757 _("undefinition") :
13758 _("something-or-other"),
13759 line == 0 ? _("zero") : _("non-zero"), line, body);
13760
13761 if (macinfo_type == DW_MACINFO_define)
13762 parse_macro_definition (current_file, line, body);
13763 else if (macinfo_type == DW_MACINFO_undef)
13764 macro_undef (current_file, line, body);
13765 }
13766 break;
13767
13768 case DW_MACINFO_start_file:
13769 {
13770 unsigned int bytes_read;
13771 int line, file;
13772
13773 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
13774 mac_ptr += bytes_read;
13775 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
13776 mac_ptr += bytes_read;
13777
13778 if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
13779 complaint (&symfile_complaints,
13780 _("debug info gives source %d included "
13781 "from %s at %s line %d"),
13782 file, at_commandline ? _("command-line") : _("file"),
13783 line == 0 ? _("zero") : _("non-zero"), line);
13784
13785 if (at_commandline)
13786 {
13787 /* This DW_MACINFO_start_file was executed in the pass one. */
13788 at_commandline = 0;
13789 }
13790 else
13791 current_file = macro_start_file (file, line,
13792 current_file, comp_dir,
13793 lh, cu->objfile);
13794 }
13795 break;
13796
13797 case DW_MACINFO_end_file:
13798 if (! current_file)
13799 complaint (&symfile_complaints,
13800 _("macro debug info has an unmatched `close_file' directive"));
13801 else
13802 {
13803 current_file = current_file->included_by;
13804 if (! current_file)
13805 {
13806 enum dwarf_macinfo_record_type next_type;
13807
13808 /* GCC circa March 2002 doesn't produce the zero
13809 type byte marking the end of the compilation
13810 unit. Complain if it's not there, but exit no
13811 matter what. */
13812
13813 /* Do we at least have room for a macinfo type byte? */
13814 if (mac_ptr >= mac_end)
13815 {
13816 dwarf2_macros_too_long_complaint ();
13817 return;
13818 }
13819
13820 /* We don't increment mac_ptr here, so this is just
13821 a look-ahead. */
13822 next_type = read_1_byte (abfd, mac_ptr);
13823 if (next_type != 0)
13824 complaint (&symfile_complaints,
13825 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
13826
13827 return;
13828 }
13829 }
13830 break;
13831
13832 case DW_MACINFO_vendor_ext:
13833 {
13834 unsigned int bytes_read;
13835 int constant;
13836 char *string;
13837
13838 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
13839 mac_ptr += bytes_read;
13840 string = read_direct_string (abfd, mac_ptr, &bytes_read);
13841 mac_ptr += bytes_read;
13842
13843 /* We don't recognize any vendor extensions. */
13844 }
13845 break;
13846 }
13847 } while (macinfo_type != 0);
13848 }
13849
13850 /* Check if the attribute's form is a DW_FORM_block*
13851 if so return true else false. */
13852 static int
13853 attr_form_is_block (struct attribute *attr)
13854 {
13855 return (attr == NULL ? 0 :
13856 attr->form == DW_FORM_block1
13857 || attr->form == DW_FORM_block2
13858 || attr->form == DW_FORM_block4
13859 || attr->form == DW_FORM_block
13860 || attr->form == DW_FORM_exprloc);
13861 }
13862
13863 /* Return non-zero if ATTR's value is a section offset --- classes
13864 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
13865 You may use DW_UNSND (attr) to retrieve such offsets.
13866
13867 Section 7.5.4, "Attribute Encodings", explains that no attribute
13868 may have a value that belongs to more than one of these classes; it
13869 would be ambiguous if we did, because we use the same forms for all
13870 of them. */
13871 static int
13872 attr_form_is_section_offset (struct attribute *attr)
13873 {
13874 return (attr->form == DW_FORM_data4
13875 || attr->form == DW_FORM_data8
13876 || attr->form == DW_FORM_sec_offset);
13877 }
13878
13879
13880 /* Return non-zero if ATTR's value falls in the 'constant' class, or
13881 zero otherwise. When this function returns true, you can apply
13882 dwarf2_get_attr_constant_value to it.
13883
13884 However, note that for some attributes you must check
13885 attr_form_is_section_offset before using this test. DW_FORM_data4
13886 and DW_FORM_data8 are members of both the constant class, and of
13887 the classes that contain offsets into other debug sections
13888 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
13889 that, if an attribute's can be either a constant or one of the
13890 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
13891 taken as section offsets, not constants. */
13892 static int
13893 attr_form_is_constant (struct attribute *attr)
13894 {
13895 switch (attr->form)
13896 {
13897 case DW_FORM_sdata:
13898 case DW_FORM_udata:
13899 case DW_FORM_data1:
13900 case DW_FORM_data2:
13901 case DW_FORM_data4:
13902 case DW_FORM_data8:
13903 return 1;
13904 default:
13905 return 0;
13906 }
13907 }
13908
13909 static void
13910 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
13911 struct dwarf2_cu *cu)
13912 {
13913 if (attr_form_is_section_offset (attr)
13914 /* ".debug_loc" may not exist at all, or the offset may be outside
13915 the section. If so, fall through to the complaint in the
13916 other branch. */
13917 && DW_UNSND (attr) < dwarf2_per_objfile->loc.size)
13918 {
13919 struct dwarf2_loclist_baton *baton;
13920
13921 baton = obstack_alloc (&cu->objfile->objfile_obstack,
13922 sizeof (struct dwarf2_loclist_baton));
13923 baton->per_cu = cu->per_cu;
13924 gdb_assert (baton->per_cu);
13925
13926 dwarf2_read_section (dwarf2_per_objfile->objfile,
13927 &dwarf2_per_objfile->loc);
13928
13929 /* We don't know how long the location list is, but make sure we
13930 don't run off the edge of the section. */
13931 baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr);
13932 baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr);
13933 baton->base_address = cu->base_address;
13934 if (cu->base_known == 0)
13935 complaint (&symfile_complaints,
13936 _("Location list used without specifying the CU base address."));
13937
13938 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs;
13939 SYMBOL_LOCATION_BATON (sym) = baton;
13940 }
13941 else
13942 {
13943 struct dwarf2_locexpr_baton *baton;
13944
13945 baton = obstack_alloc (&cu->objfile->objfile_obstack,
13946 sizeof (struct dwarf2_locexpr_baton));
13947 baton->per_cu = cu->per_cu;
13948 gdb_assert (baton->per_cu);
13949
13950 if (attr_form_is_block (attr))
13951 {
13952 /* Note that we're just copying the block's data pointer
13953 here, not the actual data. We're still pointing into the
13954 info_buffer for SYM's objfile; right now we never release
13955 that buffer, but when we do clean up properly this may
13956 need to change. */
13957 baton->size = DW_BLOCK (attr)->size;
13958 baton->data = DW_BLOCK (attr)->data;
13959 }
13960 else
13961 {
13962 dwarf2_invalid_attrib_class_complaint ("location description",
13963 SYMBOL_NATURAL_NAME (sym));
13964 baton->size = 0;
13965 baton->data = NULL;
13966 }
13967
13968 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
13969 SYMBOL_LOCATION_BATON (sym) = baton;
13970 }
13971 }
13972
13973 /* Return the OBJFILE associated with the compilation unit CU. If CU
13974 came from a separate debuginfo file, then the master objfile is
13975 returned. */
13976
13977 struct objfile *
13978 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
13979 {
13980 struct objfile *objfile = per_cu->objfile;
13981
13982 /* Return the master objfile, so that we can report and look up the
13983 correct file containing this variable. */
13984 if (objfile->separate_debug_objfile_backlink)
13985 objfile = objfile->separate_debug_objfile_backlink;
13986
13987 return objfile;
13988 }
13989
13990 /* Return the address size given in the compilation unit header for CU. */
13991
13992 CORE_ADDR
13993 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
13994 {
13995 if (per_cu->cu)
13996 return per_cu->cu->header.addr_size;
13997 else
13998 {
13999 /* If the CU is not currently read in, we re-read its header. */
14000 struct objfile *objfile = per_cu->objfile;
14001 struct dwarf2_per_objfile *per_objfile
14002 = objfile_data (objfile, dwarf2_objfile_data_key);
14003 gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
14004 struct comp_unit_head cu_header;
14005
14006 memset (&cu_header, 0, sizeof cu_header);
14007 read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
14008 return cu_header.addr_size;
14009 }
14010 }
14011
14012 /* Return the offset size given in the compilation unit header for CU. */
14013
14014 int
14015 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
14016 {
14017 if (per_cu->cu)
14018 return per_cu->cu->header.offset_size;
14019 else
14020 {
14021 /* If the CU is not currently read in, we re-read its header. */
14022 struct objfile *objfile = per_cu->objfile;
14023 struct dwarf2_per_objfile *per_objfile
14024 = objfile_data (objfile, dwarf2_objfile_data_key);
14025 gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
14026 struct comp_unit_head cu_header;
14027
14028 memset (&cu_header, 0, sizeof cu_header);
14029 read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
14030 return cu_header.offset_size;
14031 }
14032 }
14033
14034 /* Return the text offset of the CU. The returned offset comes from
14035 this CU's objfile. If this objfile came from a separate debuginfo
14036 file, then the offset may be different from the corresponding
14037 offset in the parent objfile. */
14038
14039 CORE_ADDR
14040 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu)
14041 {
14042 struct objfile *objfile = per_cu->objfile;
14043
14044 return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
14045 }
14046
14047 /* Locate the .debug_info compilation unit from CU's objfile which contains
14048 the DIE at OFFSET. Raises an error on failure. */
14049
14050 static struct dwarf2_per_cu_data *
14051 dwarf2_find_containing_comp_unit (unsigned int offset,
14052 struct objfile *objfile)
14053 {
14054 struct dwarf2_per_cu_data *this_cu;
14055 int low, high;
14056
14057 low = 0;
14058 high = dwarf2_per_objfile->n_comp_units - 1;
14059 while (high > low)
14060 {
14061 int mid = low + (high - low) / 2;
14062
14063 if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset)
14064 high = mid;
14065 else
14066 low = mid + 1;
14067 }
14068 gdb_assert (low == high);
14069 if (dwarf2_per_objfile->all_comp_units[low]->offset > offset)
14070 {
14071 if (low == 0)
14072 error (_("Dwarf Error: could not find partial DIE containing "
14073 "offset 0x%lx [in module %s]"),
14074 (long) offset, bfd_get_filename (objfile->obfd));
14075
14076 gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset);
14077 return dwarf2_per_objfile->all_comp_units[low-1];
14078 }
14079 else
14080 {
14081 this_cu = dwarf2_per_objfile->all_comp_units[low];
14082 if (low == dwarf2_per_objfile->n_comp_units - 1
14083 && offset >= this_cu->offset + this_cu->length)
14084 error (_("invalid dwarf2 offset %u"), offset);
14085 gdb_assert (offset < this_cu->offset + this_cu->length);
14086 return this_cu;
14087 }
14088 }
14089
14090 /* Locate the compilation unit from OBJFILE which is located at exactly
14091 OFFSET. Raises an error on failure. */
14092
14093 static struct dwarf2_per_cu_data *
14094 dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile)
14095 {
14096 struct dwarf2_per_cu_data *this_cu;
14097
14098 this_cu = dwarf2_find_containing_comp_unit (offset, objfile);
14099 if (this_cu->offset != offset)
14100 error (_("no compilation unit with offset %u."), offset);
14101 return this_cu;
14102 }
14103
14104 /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */
14105
14106 static struct dwarf2_cu *
14107 alloc_one_comp_unit (struct objfile *objfile)
14108 {
14109 struct dwarf2_cu *cu = xcalloc (1, sizeof (struct dwarf2_cu));
14110 cu->objfile = objfile;
14111 obstack_init (&cu->comp_unit_obstack);
14112 return cu;
14113 }
14114
14115 /* Release one cached compilation unit, CU. We unlink it from the tree
14116 of compilation units, but we don't remove it from the read_in_chain;
14117 the caller is responsible for that.
14118 NOTE: DATA is a void * because this function is also used as a
14119 cleanup routine. */
14120
14121 static void
14122 free_one_comp_unit (void *data)
14123 {
14124 struct dwarf2_cu *cu = data;
14125
14126 if (cu->per_cu != NULL)
14127 cu->per_cu->cu = NULL;
14128 cu->per_cu = NULL;
14129
14130 obstack_free (&cu->comp_unit_obstack, NULL);
14131
14132 xfree (cu);
14133 }
14134
14135 /* This cleanup function is passed the address of a dwarf2_cu on the stack
14136 when we're finished with it. We can't free the pointer itself, but be
14137 sure to unlink it from the cache. Also release any associated storage
14138 and perform cache maintenance.
14139
14140 Only used during partial symbol parsing. */
14141
14142 static void
14143 free_stack_comp_unit (void *data)
14144 {
14145 struct dwarf2_cu *cu = data;
14146
14147 obstack_free (&cu->comp_unit_obstack, NULL);
14148 cu->partial_dies = NULL;
14149
14150 if (cu->per_cu != NULL)
14151 {
14152 /* This compilation unit is on the stack in our caller, so we
14153 should not xfree it. Just unlink it. */
14154 cu->per_cu->cu = NULL;
14155 cu->per_cu = NULL;
14156
14157 /* If we had a per-cu pointer, then we may have other compilation
14158 units loaded, so age them now. */
14159 age_cached_comp_units ();
14160 }
14161 }
14162
14163 /* Free all cached compilation units. */
14164
14165 static void
14166 free_cached_comp_units (void *data)
14167 {
14168 struct dwarf2_per_cu_data *per_cu, **last_chain;
14169
14170 per_cu = dwarf2_per_objfile->read_in_chain;
14171 last_chain = &dwarf2_per_objfile->read_in_chain;
14172 while (per_cu != NULL)
14173 {
14174 struct dwarf2_per_cu_data *next_cu;
14175
14176 next_cu = per_cu->cu->read_in_chain;
14177
14178 free_one_comp_unit (per_cu->cu);
14179 *last_chain = next_cu;
14180
14181 per_cu = next_cu;
14182 }
14183 }
14184
14185 /* Increase the age counter on each cached compilation unit, and free
14186 any that are too old. */
14187
14188 static void
14189 age_cached_comp_units (void)
14190 {
14191 struct dwarf2_per_cu_data *per_cu, **last_chain;
14192
14193 dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain);
14194 per_cu = dwarf2_per_objfile->read_in_chain;
14195 while (per_cu != NULL)
14196 {
14197 per_cu->cu->last_used ++;
14198 if (per_cu->cu->last_used <= dwarf2_max_cache_age)
14199 dwarf2_mark (per_cu->cu);
14200 per_cu = per_cu->cu->read_in_chain;
14201 }
14202
14203 per_cu = dwarf2_per_objfile->read_in_chain;
14204 last_chain = &dwarf2_per_objfile->read_in_chain;
14205 while (per_cu != NULL)
14206 {
14207 struct dwarf2_per_cu_data *next_cu;
14208
14209 next_cu = per_cu->cu->read_in_chain;
14210
14211 if (!per_cu->cu->mark)
14212 {
14213 free_one_comp_unit (per_cu->cu);
14214 *last_chain = next_cu;
14215 }
14216 else
14217 last_chain = &per_cu->cu->read_in_chain;
14218
14219 per_cu = next_cu;
14220 }
14221 }
14222
14223 /* Remove a single compilation unit from the cache. */
14224
14225 static void
14226 free_one_cached_comp_unit (void *target_cu)
14227 {
14228 struct dwarf2_per_cu_data *per_cu, **last_chain;
14229
14230 per_cu = dwarf2_per_objfile->read_in_chain;
14231 last_chain = &dwarf2_per_objfile->read_in_chain;
14232 while (per_cu != NULL)
14233 {
14234 struct dwarf2_per_cu_data *next_cu;
14235
14236 next_cu = per_cu->cu->read_in_chain;
14237
14238 if (per_cu->cu == target_cu)
14239 {
14240 free_one_comp_unit (per_cu->cu);
14241 *last_chain = next_cu;
14242 break;
14243 }
14244 else
14245 last_chain = &per_cu->cu->read_in_chain;
14246
14247 per_cu = next_cu;
14248 }
14249 }
14250
14251 /* Release all extra memory associated with OBJFILE. */
14252
14253 void
14254 dwarf2_free_objfile (struct objfile *objfile)
14255 {
14256 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
14257
14258 if (dwarf2_per_objfile == NULL)
14259 return;
14260
14261 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
14262 free_cached_comp_units (NULL);
14263
14264 if (dwarf2_per_objfile->using_index)
14265 {
14266 int i;
14267
14268 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
14269 {
14270 int j;
14271 struct dwarf2_per_cu_data *per_cu =
14272 dwarf2_per_objfile->all_comp_units[i];
14273
14274 if (!per_cu->v.quick->lines)
14275 continue;
14276
14277 for (j = 0; j < per_cu->v.quick->lines->num_file_names; ++j)
14278 {
14279 if (per_cu->v.quick->file_names)
14280 xfree ((void *) per_cu->v.quick->file_names[j]);
14281 if (per_cu->v.quick->full_names)
14282 xfree ((void *) per_cu->v.quick->full_names[j]);
14283 }
14284
14285 free_line_header (per_cu->v.quick->lines);
14286 }
14287 }
14288
14289 /* Everything else should be on the objfile obstack. */
14290 }
14291
14292 /* A pair of DIE offset and GDB type pointer. We store these
14293 in a hash table separate from the DIEs, and preserve them
14294 when the DIEs are flushed out of cache. */
14295
14296 struct dwarf2_offset_and_type
14297 {
14298 unsigned int offset;
14299 struct type *type;
14300 };
14301
14302 /* Hash function for a dwarf2_offset_and_type. */
14303
14304 static hashval_t
14305 offset_and_type_hash (const void *item)
14306 {
14307 const struct dwarf2_offset_and_type *ofs = item;
14308
14309 return ofs->offset;
14310 }
14311
14312 /* Equality function for a dwarf2_offset_and_type. */
14313
14314 static int
14315 offset_and_type_eq (const void *item_lhs, const void *item_rhs)
14316 {
14317 const struct dwarf2_offset_and_type *ofs_lhs = item_lhs;
14318 const struct dwarf2_offset_and_type *ofs_rhs = item_rhs;
14319
14320 return ofs_lhs->offset == ofs_rhs->offset;
14321 }
14322
14323 /* Set the type associated with DIE to TYPE. Save it in CU's hash
14324 table if necessary. For convenience, return TYPE.
14325
14326 The DIEs reading must have careful ordering to:
14327 * Not cause infite loops trying to read in DIEs as a prerequisite for
14328 reading current DIE.
14329 * Not trying to dereference contents of still incompletely read in types
14330 while reading in other DIEs.
14331 * Enable referencing still incompletely read in types just by a pointer to
14332 the type without accessing its fields.
14333
14334 Therefore caller should follow these rules:
14335 * Try to fetch any prerequisite types we may need to build this DIE type
14336 before building the type and calling set_die_type.
14337 * After building type call set_die_type for current DIE as soon as
14338 possible before fetching more types to complete the current type.
14339 * Make the type as complete as possible before fetching more types. */
14340
14341 static struct type *
14342 set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
14343 {
14344 struct dwarf2_offset_and_type **slot, ofs;
14345 struct objfile *objfile = cu->objfile;
14346 htab_t *type_hash_ptr;
14347
14348 /* For Ada types, make sure that the gnat-specific data is always
14349 initialized (if not already set). There are a few types where
14350 we should not be doing so, because the type-specific area is
14351 already used to hold some other piece of info (eg: TYPE_CODE_FLT
14352 where the type-specific area is used to store the floatformat).
14353 But this is not a problem, because the gnat-specific information
14354 is actually not needed for these types. */
14355 if (need_gnat_info (cu)
14356 && TYPE_CODE (type) != TYPE_CODE_FUNC
14357 && TYPE_CODE (type) != TYPE_CODE_FLT
14358 && !HAVE_GNAT_AUX_INFO (type))
14359 INIT_GNAT_SPECIFIC (type);
14360
14361 if (cu->per_cu->from_debug_types)
14362 type_hash_ptr = &dwarf2_per_objfile->debug_types_type_hash;
14363 else
14364 type_hash_ptr = &dwarf2_per_objfile->debug_info_type_hash;
14365
14366 if (*type_hash_ptr == NULL)
14367 {
14368 *type_hash_ptr
14369 = htab_create_alloc_ex (127,
14370 offset_and_type_hash,
14371 offset_and_type_eq,
14372 NULL,
14373 &objfile->objfile_obstack,
14374 hashtab_obstack_allocate,
14375 dummy_obstack_deallocate);
14376 }
14377
14378 ofs.offset = die->offset;
14379 ofs.type = type;
14380 slot = (struct dwarf2_offset_and_type **)
14381 htab_find_slot_with_hash (*type_hash_ptr, &ofs, ofs.offset, INSERT);
14382 if (*slot)
14383 complaint (&symfile_complaints,
14384 _("A problem internal to GDB: DIE 0x%x has type already set"),
14385 die->offset);
14386 *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot));
14387 **slot = ofs;
14388 return type;
14389 }
14390
14391 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
14392 table, or return NULL if the die does not have a saved type. */
14393
14394 static struct type *
14395 get_die_type_at_offset (unsigned int offset,
14396 struct dwarf2_per_cu_data *per_cu)
14397 {
14398 struct dwarf2_offset_and_type *slot, ofs;
14399 htab_t type_hash;
14400
14401 if (per_cu->from_debug_types)
14402 type_hash = dwarf2_per_objfile->debug_types_type_hash;
14403 else
14404 type_hash = dwarf2_per_objfile->debug_info_type_hash;
14405 if (type_hash == NULL)
14406 return NULL;
14407
14408 ofs.offset = offset;
14409 slot = htab_find_with_hash (type_hash, &ofs, ofs.offset);
14410 if (slot)
14411 return slot->type;
14412 else
14413 return NULL;
14414 }
14415
14416 /* Look up the type for DIE in the appropriate type_hash table,
14417 or return NULL if DIE does not have a saved type. */
14418
14419 static struct type *
14420 get_die_type (struct die_info *die, struct dwarf2_cu *cu)
14421 {
14422 return get_die_type_at_offset (die->offset, cu->per_cu);
14423 }
14424
14425 /* Add a dependence relationship from CU to REF_PER_CU. */
14426
14427 static void
14428 dwarf2_add_dependence (struct dwarf2_cu *cu,
14429 struct dwarf2_per_cu_data *ref_per_cu)
14430 {
14431 void **slot;
14432
14433 if (cu->dependencies == NULL)
14434 cu->dependencies
14435 = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer,
14436 NULL, &cu->comp_unit_obstack,
14437 hashtab_obstack_allocate,
14438 dummy_obstack_deallocate);
14439
14440 slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT);
14441 if (*slot == NULL)
14442 *slot = ref_per_cu;
14443 }
14444
14445 /* Subroutine of dwarf2_mark to pass to htab_traverse.
14446 Set the mark field in every compilation unit in the
14447 cache that we must keep because we are keeping CU. */
14448
14449 static int
14450 dwarf2_mark_helper (void **slot, void *data)
14451 {
14452 struct dwarf2_per_cu_data *per_cu;
14453
14454 per_cu = (struct dwarf2_per_cu_data *) *slot;
14455 if (per_cu->cu->mark)
14456 return 1;
14457 per_cu->cu->mark = 1;
14458
14459 if (per_cu->cu->dependencies != NULL)
14460 htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL);
14461
14462 return 1;
14463 }
14464
14465 /* Set the mark field in CU and in every other compilation unit in the
14466 cache that we must keep because we are keeping CU. */
14467
14468 static void
14469 dwarf2_mark (struct dwarf2_cu *cu)
14470 {
14471 if (cu->mark)
14472 return;
14473 cu->mark = 1;
14474 if (cu->dependencies != NULL)
14475 htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL);
14476 }
14477
14478 static void
14479 dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu)
14480 {
14481 while (per_cu)
14482 {
14483 per_cu->cu->mark = 0;
14484 per_cu = per_cu->cu->read_in_chain;
14485 }
14486 }
14487
14488 /* Trivial hash function for partial_die_info: the hash value of a DIE
14489 is its offset in .debug_info for this objfile. */
14490
14491 static hashval_t
14492 partial_die_hash (const void *item)
14493 {
14494 const struct partial_die_info *part_die = item;
14495
14496 return part_die->offset;
14497 }
14498
14499 /* Trivial comparison function for partial_die_info structures: two DIEs
14500 are equal if they have the same offset. */
14501
14502 static int
14503 partial_die_eq (const void *item_lhs, const void *item_rhs)
14504 {
14505 const struct partial_die_info *part_die_lhs = item_lhs;
14506 const struct partial_die_info *part_die_rhs = item_rhs;
14507
14508 return part_die_lhs->offset == part_die_rhs->offset;
14509 }
14510
14511 static struct cmd_list_element *set_dwarf2_cmdlist;
14512 static struct cmd_list_element *show_dwarf2_cmdlist;
14513
14514 static void
14515 set_dwarf2_cmd (char *args, int from_tty)
14516 {
14517 help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout);
14518 }
14519
14520 static void
14521 show_dwarf2_cmd (char *args, int from_tty)
14522 {
14523 cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
14524 }
14525
14526 /* If section described by INFO was mmapped, munmap it now. */
14527
14528 static void
14529 munmap_section_buffer (struct dwarf2_section_info *info)
14530 {
14531 if (info->was_mmapped)
14532 {
14533 #ifdef HAVE_MMAP
14534 intptr_t begin = (intptr_t) info->buffer;
14535 intptr_t map_begin = begin & ~(pagesize - 1);
14536 size_t map_length = info->size + begin - map_begin;
14537
14538 gdb_assert (munmap ((void *) map_begin, map_length) == 0);
14539 #else
14540 /* Without HAVE_MMAP, we should never be here to begin with. */
14541 gdb_assert_not_reached ("no mmap support");
14542 #endif
14543 }
14544 }
14545
14546 /* munmap debug sections for OBJFILE, if necessary. */
14547
14548 static void
14549 dwarf2_per_objfile_free (struct objfile *objfile, void *d)
14550 {
14551 struct dwarf2_per_objfile *data = d;
14552
14553 /* This is sorted according to the order they're defined in to make it easier
14554 to keep in sync. */
14555 munmap_section_buffer (&data->info);
14556 munmap_section_buffer (&data->abbrev);
14557 munmap_section_buffer (&data->line);
14558 munmap_section_buffer (&data->loc);
14559 munmap_section_buffer (&data->macinfo);
14560 munmap_section_buffer (&data->str);
14561 munmap_section_buffer (&data->ranges);
14562 munmap_section_buffer (&data->types);
14563 munmap_section_buffer (&data->frame);
14564 munmap_section_buffer (&data->eh_frame);
14565 munmap_section_buffer (&data->gdb_index);
14566 }
14567
14568 \f
14569
14570 /* The contents of the hash table we create when building the string
14571 table. */
14572 struct strtab_entry
14573 {
14574 offset_type offset;
14575 const char *str;
14576 };
14577
14578 /* Hash function for a strtab_entry. */
14579 static hashval_t
14580 hash_strtab_entry (const void *e)
14581 {
14582 const struct strtab_entry *entry = e;
14583 return mapped_index_string_hash (entry->str);
14584 }
14585
14586 /* Equality function for a strtab_entry. */
14587 static int
14588 eq_strtab_entry (const void *a, const void *b)
14589 {
14590 const struct strtab_entry *ea = a;
14591 const struct strtab_entry *eb = b;
14592 return !strcmp (ea->str, eb->str);
14593 }
14594
14595 /* Create a strtab_entry hash table. */
14596 static htab_t
14597 create_strtab (void)
14598 {
14599 return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry,
14600 xfree, xcalloc, xfree);
14601 }
14602
14603 /* Add a string to the constant pool. Return the string's offset in
14604 host order. */
14605 static offset_type
14606 add_string (htab_t table, struct obstack *cpool, const char *str)
14607 {
14608 void **slot;
14609 struct strtab_entry entry;
14610 struct strtab_entry *result;
14611
14612 entry.str = str;
14613 slot = htab_find_slot (table, &entry, INSERT);
14614 if (*slot)
14615 result = *slot;
14616 else
14617 {
14618 result = XNEW (struct strtab_entry);
14619 result->offset = obstack_object_size (cpool);
14620 result->str = str;
14621 obstack_grow_str0 (cpool, str);
14622 *slot = result;
14623 }
14624 return result->offset;
14625 }
14626
14627 /* An entry in the symbol table. */
14628 struct symtab_index_entry
14629 {
14630 /* The name of the symbol. */
14631 const char *name;
14632 /* The offset of the name in the constant pool. */
14633 offset_type index_offset;
14634 /* A sorted vector of the indices of all the CUs that hold an object
14635 of this name. */
14636 VEC (offset_type) *cu_indices;
14637 };
14638
14639 /* The symbol table. This is a power-of-2-sized hash table. */
14640 struct mapped_symtab
14641 {
14642 offset_type n_elements;
14643 offset_type size;
14644 struct symtab_index_entry **data;
14645 };
14646
14647 /* Hash function for a symtab_index_entry. */
14648 static hashval_t
14649 hash_symtab_entry (const void *e)
14650 {
14651 const struct symtab_index_entry *entry = e;
14652 return iterative_hash (VEC_address (offset_type, entry->cu_indices),
14653 sizeof (offset_type) * VEC_length (offset_type,
14654 entry->cu_indices),
14655 0);
14656 }
14657
14658 /* Equality function for a symtab_index_entry. */
14659 static int
14660 eq_symtab_entry (const void *a, const void *b)
14661 {
14662 const struct symtab_index_entry *ea = a;
14663 const struct symtab_index_entry *eb = b;
14664 int len = VEC_length (offset_type, ea->cu_indices);
14665 if (len != VEC_length (offset_type, eb->cu_indices))
14666 return 0;
14667 return !memcmp (VEC_address (offset_type, ea->cu_indices),
14668 VEC_address (offset_type, eb->cu_indices),
14669 sizeof (offset_type) * len);
14670 }
14671
14672 /* Destroy a symtab_index_entry. */
14673 static void
14674 delete_symtab_entry (void *p)
14675 {
14676 struct symtab_index_entry *entry = p;
14677 VEC_free (offset_type, entry->cu_indices);
14678 xfree (entry);
14679 }
14680
14681 /* Create a hash table holding symtab_index_entry objects. */
14682 static htab_t
14683 create_index_table (void)
14684 {
14685 return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry,
14686 delete_symtab_entry, xcalloc, xfree);
14687 }
14688
14689 /* Create a new mapped symtab object. */
14690 static struct mapped_symtab *
14691 create_mapped_symtab (void)
14692 {
14693 struct mapped_symtab *symtab = XNEW (struct mapped_symtab);
14694 symtab->n_elements = 0;
14695 symtab->size = 1024;
14696 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
14697 return symtab;
14698 }
14699
14700 /* Destroy a mapped_symtab. */
14701 static void
14702 cleanup_mapped_symtab (void *p)
14703 {
14704 struct mapped_symtab *symtab = p;
14705 /* The contents of the array are freed when the other hash table is
14706 destroyed. */
14707 xfree (symtab->data);
14708 xfree (symtab);
14709 }
14710
14711 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
14712 the slot. */
14713 static struct symtab_index_entry **
14714 find_slot (struct mapped_symtab *symtab, const char *name)
14715 {
14716 offset_type index, step, hash = mapped_index_string_hash (name);
14717
14718 index = hash & (symtab->size - 1);
14719 step = ((hash * 17) & (symtab->size - 1)) | 1;
14720
14721 for (;;)
14722 {
14723 if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name))
14724 return &symtab->data[index];
14725 index = (index + step) & (symtab->size - 1);
14726 }
14727 }
14728
14729 /* Expand SYMTAB's hash table. */
14730 static void
14731 hash_expand (struct mapped_symtab *symtab)
14732 {
14733 offset_type old_size = symtab->size;
14734 offset_type i;
14735 struct symtab_index_entry **old_entries = symtab->data;
14736
14737 symtab->size *= 2;
14738 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
14739
14740 for (i = 0; i < old_size; ++i)
14741 {
14742 if (old_entries[i])
14743 {
14744 struct symtab_index_entry **slot = find_slot (symtab,
14745 old_entries[i]->name);
14746 *slot = old_entries[i];
14747 }
14748 }
14749
14750 xfree (old_entries);
14751 }
14752
14753 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
14754 is the index of the CU in which the symbol appears. */
14755 static void
14756 add_index_entry (struct mapped_symtab *symtab, const char *name,
14757 offset_type cu_index)
14758 {
14759 struct symtab_index_entry **slot;
14760
14761 ++symtab->n_elements;
14762 if (4 * symtab->n_elements / 3 >= symtab->size)
14763 hash_expand (symtab);
14764
14765 slot = find_slot (symtab, name);
14766 if (!*slot)
14767 {
14768 *slot = XNEW (struct symtab_index_entry);
14769 (*slot)->name = name;
14770 (*slot)->cu_indices = NULL;
14771 }
14772 /* Don't push an index twice. Due to how we add entries we only
14773 have to check the last one. */
14774 if (VEC_empty (offset_type, (*slot)->cu_indices)
14775 || VEC_length (offset_type, (*slot)->cu_indices) != cu_index)
14776 VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index);
14777 }
14778
14779 /* Add a vector of indices to the constant pool. */
14780 static offset_type
14781 add_indices_to_cpool (htab_t index_table, struct obstack *cpool,
14782 struct symtab_index_entry *entry)
14783 {
14784 void **slot;
14785
14786 slot = htab_find_slot (index_table, entry, INSERT);
14787 if (!*slot)
14788 {
14789 offset_type len = VEC_length (offset_type, entry->cu_indices);
14790 offset_type val = MAYBE_SWAP (len);
14791 offset_type iter;
14792 int i;
14793
14794 *slot = entry;
14795 entry->index_offset = obstack_object_size (cpool);
14796
14797 obstack_grow (cpool, &val, sizeof (val));
14798 for (i = 0;
14799 VEC_iterate (offset_type, entry->cu_indices, i, iter);
14800 ++i)
14801 {
14802 val = MAYBE_SWAP (iter);
14803 obstack_grow (cpool, &val, sizeof (val));
14804 }
14805 }
14806 else
14807 {
14808 struct symtab_index_entry *old_entry = *slot;
14809 entry->index_offset = old_entry->index_offset;
14810 entry = old_entry;
14811 }
14812 return entry->index_offset;
14813 }
14814
14815 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
14816 constant pool entries going into the obstack CPOOL. */
14817 static void
14818 write_hash_table (struct mapped_symtab *symtab,
14819 struct obstack *output, struct obstack *cpool)
14820 {
14821 offset_type i;
14822 htab_t index_table;
14823 htab_t str_table;
14824
14825 index_table = create_index_table ();
14826 str_table = create_strtab ();
14827 /* We add all the index vectors to the constant pool first, to
14828 ensure alignment is ok. */
14829 for (i = 0; i < symtab->size; ++i)
14830 {
14831 if (symtab->data[i])
14832 add_indices_to_cpool (index_table, cpool, symtab->data[i]);
14833 }
14834
14835 /* Now write out the hash table. */
14836 for (i = 0; i < symtab->size; ++i)
14837 {
14838 offset_type str_off, vec_off;
14839
14840 if (symtab->data[i])
14841 {
14842 str_off = add_string (str_table, cpool, symtab->data[i]->name);
14843 vec_off = symtab->data[i]->index_offset;
14844 }
14845 else
14846 {
14847 /* While 0 is a valid constant pool index, it is not valid
14848 to have 0 for both offsets. */
14849 str_off = 0;
14850 vec_off = 0;
14851 }
14852
14853 str_off = MAYBE_SWAP (str_off);
14854 vec_off = MAYBE_SWAP (vec_off);
14855
14856 obstack_grow (output, &str_off, sizeof (str_off));
14857 obstack_grow (output, &vec_off, sizeof (vec_off));
14858 }
14859
14860 htab_delete (str_table);
14861 htab_delete (index_table);
14862 }
14863
14864 /* Write an address entry to ADDR_OBSTACK. The addresses are taken
14865 from PST; CU_INDEX is the index of the CU in the vector of all
14866 CUs. */
14867 static void
14868 add_address_entry (struct objfile *objfile,
14869 struct obstack *addr_obstack, struct partial_symtab *pst,
14870 unsigned int cu_index)
14871 {
14872 offset_type offset;
14873 char addr[8];
14874 CORE_ADDR baseaddr;
14875
14876 /* Don't bother recording empty ranges. */
14877 if (pst->textlow == pst->texthigh)
14878 return;
14879
14880 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
14881
14882 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, pst->textlow - baseaddr);
14883 obstack_grow (addr_obstack, addr, 8);
14884 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, pst->texthigh - baseaddr);
14885 obstack_grow (addr_obstack, addr, 8);
14886 offset = MAYBE_SWAP (cu_index);
14887 obstack_grow (addr_obstack, &offset, sizeof (offset_type));
14888 }
14889
14890 /* Add a list of partial symbols to SYMTAB. */
14891 static void
14892 write_psymbols (struct mapped_symtab *symtab,
14893 struct partial_symbol **psymp,
14894 int count,
14895 offset_type cu_index)
14896 {
14897 for (; count-- > 0; ++psymp)
14898 {
14899 if (SYMBOL_LANGUAGE (*psymp) == language_ada)
14900 error (_("Ada is not currently supported by the index"));
14901 add_index_entry (symtab, SYMBOL_NATURAL_NAME (*psymp), cu_index);
14902 }
14903 }
14904
14905 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
14906 exception if there is an error. */
14907 static void
14908 write_obstack (FILE *file, struct obstack *obstack)
14909 {
14910 if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack),
14911 file)
14912 != obstack_object_size (obstack))
14913 error (_("couldn't data write to file"));
14914 }
14915
14916 /* Unlink a file if the argument is not NULL. */
14917 static void
14918 unlink_if_set (void *p)
14919 {
14920 char **filename = p;
14921 if (*filename)
14922 unlink (*filename);
14923 }
14924
14925 /* A helper struct used when iterating over debug_types. */
14926 struct signatured_type_index_data
14927 {
14928 struct objfile *objfile;
14929 struct mapped_symtab *symtab;
14930 struct obstack *types_list;
14931 int cu_index;
14932 };
14933
14934 /* A helper function that writes a single signatured_type to an
14935 obstack. */
14936 static int
14937 write_one_signatured_type (void **slot, void *d)
14938 {
14939 struct signatured_type_index_data *info = d;
14940 struct signatured_type *entry = (struct signatured_type *) *slot;
14941 struct dwarf2_per_cu_data *per_cu = &entry->per_cu;
14942 struct partial_symtab *psymtab = per_cu->v.psymtab;
14943 gdb_byte val[8];
14944
14945 write_psymbols (info->symtab,
14946 info->objfile->global_psymbols.list + psymtab->globals_offset,
14947 psymtab->n_global_syms, info->cu_index);
14948 write_psymbols (info->symtab,
14949 info->objfile->static_psymbols.list + psymtab->statics_offset,
14950 psymtab->n_static_syms, info->cu_index);
14951
14952 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->offset);
14953 obstack_grow (info->types_list, val, 8);
14954 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->type_offset);
14955 obstack_grow (info->types_list, val, 8);
14956 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature);
14957 obstack_grow (info->types_list, val, 8);
14958
14959 ++info->cu_index;
14960
14961 return 1;
14962 }
14963
14964 /* Create an index file for OBJFILE in the directory DIR. */
14965 static void
14966 write_psymtabs_to_index (struct objfile *objfile, const char *dir)
14967 {
14968 struct cleanup *cleanup;
14969 char *filename, *cleanup_filename;
14970 struct obstack contents, addr_obstack, constant_pool, symtab_obstack;
14971 struct obstack cu_list, types_cu_list;
14972 int i;
14973 FILE *out_file;
14974 struct mapped_symtab *symtab;
14975 offset_type val, size_of_contents, total_len;
14976 struct stat st;
14977 char buf[8];
14978
14979 if (!objfile->psymtabs)
14980 return;
14981 if (dwarf2_per_objfile->using_index)
14982 error (_("Cannot use an index to create the index"));
14983
14984 if (stat (objfile->name, &st) < 0)
14985 perror_with_name (_("Could not stat"));
14986
14987 filename = concat (dir, SLASH_STRING, lbasename (objfile->name),
14988 INDEX_SUFFIX, (char *) NULL);
14989 cleanup = make_cleanup (xfree, filename);
14990
14991 out_file = fopen (filename, "wb");
14992 if (!out_file)
14993 error (_("Can't open `%s' for writing"), filename);
14994
14995 cleanup_filename = filename;
14996 make_cleanup (unlink_if_set, &cleanup_filename);
14997
14998 symtab = create_mapped_symtab ();
14999 make_cleanup (cleanup_mapped_symtab, symtab);
15000
15001 obstack_init (&addr_obstack);
15002 make_cleanup_obstack_free (&addr_obstack);
15003
15004 obstack_init (&cu_list);
15005 make_cleanup_obstack_free (&cu_list);
15006
15007 obstack_init (&types_cu_list);
15008 make_cleanup_obstack_free (&types_cu_list);
15009
15010 /* The list is already sorted, so we don't need to do additional
15011 work here. Also, the debug_types entries do not appear in
15012 all_comp_units, but only in their own hash table. */
15013 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
15014 {
15015 struct dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->all_comp_units[i];
15016 struct partial_symtab *psymtab = per_cu->v.psymtab;
15017 gdb_byte val[8];
15018
15019 write_psymbols (symtab,
15020 objfile->global_psymbols.list + psymtab->globals_offset,
15021 psymtab->n_global_syms, i);
15022 write_psymbols (symtab,
15023 objfile->static_psymbols.list + psymtab->statics_offset,
15024 psymtab->n_static_syms, i);
15025
15026 add_address_entry (objfile, &addr_obstack, psymtab, i);
15027
15028 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->offset);
15029 obstack_grow (&cu_list, val, 8);
15030 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length);
15031 obstack_grow (&cu_list, val, 8);
15032 }
15033
15034 /* Write out the .debug_type entries, if any. */
15035 if (dwarf2_per_objfile->signatured_types)
15036 {
15037 struct signatured_type_index_data sig_data;
15038
15039 sig_data.objfile = objfile;
15040 sig_data.symtab = symtab;
15041 sig_data.types_list = &types_cu_list;
15042 sig_data.cu_index = dwarf2_per_objfile->n_comp_units;
15043 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
15044 write_one_signatured_type, &sig_data);
15045 }
15046
15047 obstack_init (&constant_pool);
15048 make_cleanup_obstack_free (&constant_pool);
15049 obstack_init (&symtab_obstack);
15050 make_cleanup_obstack_free (&symtab_obstack);
15051 write_hash_table (symtab, &symtab_obstack, &constant_pool);
15052
15053 obstack_init (&contents);
15054 make_cleanup_obstack_free (&contents);
15055 size_of_contents = 6 * sizeof (offset_type);
15056 total_len = size_of_contents;
15057
15058 /* The version number. */
15059 val = MAYBE_SWAP (2);
15060 obstack_grow (&contents, &val, sizeof (val));
15061
15062 /* The offset of the CU list from the start of the file. */
15063 val = MAYBE_SWAP (total_len);
15064 obstack_grow (&contents, &val, sizeof (val));
15065 total_len += obstack_object_size (&cu_list);
15066
15067 /* The offset of the types CU list from the start of the file. */
15068 val = MAYBE_SWAP (total_len);
15069 obstack_grow (&contents, &val, sizeof (val));
15070 total_len += obstack_object_size (&types_cu_list);
15071
15072 /* The offset of the address table from the start of the file. */
15073 val = MAYBE_SWAP (total_len);
15074 obstack_grow (&contents, &val, sizeof (val));
15075 total_len += obstack_object_size (&addr_obstack);
15076
15077 /* The offset of the symbol table from the start of the file. */
15078 val = MAYBE_SWAP (total_len);
15079 obstack_grow (&contents, &val, sizeof (val));
15080 total_len += obstack_object_size (&symtab_obstack);
15081
15082 /* The offset of the constant pool from the start of the file. */
15083 val = MAYBE_SWAP (total_len);
15084 obstack_grow (&contents, &val, sizeof (val));
15085 total_len += obstack_object_size (&constant_pool);
15086
15087 gdb_assert (obstack_object_size (&contents) == size_of_contents);
15088
15089 write_obstack (out_file, &contents);
15090 write_obstack (out_file, &cu_list);
15091 write_obstack (out_file, &types_cu_list);
15092 write_obstack (out_file, &addr_obstack);
15093 write_obstack (out_file, &symtab_obstack);
15094 write_obstack (out_file, &constant_pool);
15095
15096 fclose (out_file);
15097
15098 /* We want to keep the file, so we set cleanup_filename to NULL
15099 here. See unlink_if_set. */
15100 cleanup_filename = NULL;
15101
15102 do_cleanups (cleanup);
15103 }
15104
15105 /* The mapped index file format is designed to be directly mmap()able
15106 on any architecture. In most cases, a datum is represented using a
15107 little-endian 32-bit integer value, called an offset_type. Big
15108 endian machines must byte-swap the values before using them.
15109 Exceptions to this rule are noted. The data is laid out such that
15110 alignment is always respected.
15111
15112 A mapped index consists of several sections.
15113
15114 1. The file header. This is a sequence of values, of offset_type
15115 unless otherwise noted:
15116 [0] The version number. Currently 1 or 2. The differences are
15117 noted below. Version 1 did not account for .debug_types sections;
15118 the presence of a .debug_types section invalidates any version 1
15119 index that may exist.
15120 [1] The offset, from the start of the file, of the CU list.
15121 [1.5] In version 2, the offset, from the start of the file, of the
15122 types CU list. This offset does not appear in version 1. Note
15123 that this can be empty, in which case this offset will be equal to
15124 the next offset.
15125 [2] The offset, from the start of the file, of the address section.
15126 [3] The offset, from the start of the file, of the symbol table.
15127 [4] The offset, from the start of the file, of the constant pool.
15128
15129 2. The CU list. This is a sequence of pairs of 64-bit
15130 little-endian values, sorted by the CU offset. The first element
15131 in each pair is the offset of a CU in the .debug_info section. The
15132 second element in each pair is the length of that CU. References
15133 to a CU elsewhere in the map are done using a CU index, which is
15134 just the 0-based index into this table. Note that if there are
15135 type CUs, then conceptually CUs and type CUs form a single list for
15136 the purposes of CU indices.
15137
15138 2.5 The types CU list. This does not appear in a version 1 index.
15139 This is a sequence of triplets of 64-bit little-endian values. In
15140 a triplet, the first value is the CU offset, the second value is
15141 the type offset in the CU, and the third value is the type
15142 signature. The types CU list is not sorted.
15143
15144 3. The address section. The address section consists of a sequence
15145 of address entries. Each address entry has three elements.
15146 [0] The low address. This is a 64-bit little-endian value.
15147 [1] The high address. This is a 64-bit little-endian value.
15148 [2] The CU index. This is an offset_type value.
15149
15150 4. The symbol table. This is a hash table. The size of the hash
15151 table is always a power of 2. The initial hash and the step are
15152 currently defined by the `find_slot' function.
15153
15154 Each slot in the hash table consists of a pair of offset_type
15155 values. The first value is the offset of the symbol's name in the
15156 constant pool. The second value is the offset of the CU vector in
15157 the constant pool.
15158
15159 If both values are 0, then this slot in the hash table is empty.
15160 This is ok because while 0 is a valid constant pool index, it
15161 cannot be a valid index for both a string and a CU vector.
15162
15163 A string in the constant pool is stored as a \0-terminated string,
15164 as you'd expect.
15165
15166 A CU vector in the constant pool is a sequence of offset_type
15167 values. The first value is the number of CU indices in the vector.
15168 Each subsequent value is the index of a CU in the CU list. This
15169 element in the hash table is used to indicate which CUs define the
15170 symbol.
15171
15172 5. The constant pool. This is simply a bunch of bytes. It is
15173 organized so that alignment is correct: CU vectors are stored
15174 first, followed by strings. */
15175 static void
15176 save_gdb_index_command (char *arg, int from_tty)
15177 {
15178 struct objfile *objfile;
15179
15180 if (!arg || !*arg)
15181 error (_("usage: save gdb-index DIRECTORY"));
15182
15183 ALL_OBJFILES (objfile)
15184 {
15185 struct stat st;
15186
15187 /* If the objfile does not correspond to an actual file, skip it. */
15188 if (stat (objfile->name, &st) < 0)
15189 continue;
15190
15191 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
15192 if (dwarf2_per_objfile)
15193 {
15194 volatile struct gdb_exception except;
15195
15196 TRY_CATCH (except, RETURN_MASK_ERROR)
15197 {
15198 write_psymtabs_to_index (objfile, arg);
15199 }
15200 if (except.reason < 0)
15201 exception_fprintf (gdb_stderr, except,
15202 _("Error while writing index for `%s': "),
15203 objfile->name);
15204 }
15205 }
15206 }
15207
15208 \f
15209
15210 int dwarf2_always_disassemble;
15211
15212 static void
15213 show_dwarf2_always_disassemble (struct ui_file *file, int from_tty,
15214 struct cmd_list_element *c, const char *value)
15215 {
15216 fprintf_filtered (file, _("\
15217 Whether to always disassemble DWARF expressions is %s.\n"),
15218 value);
15219 }
15220
15221 void _initialize_dwarf2_read (void);
15222
15223 void
15224 _initialize_dwarf2_read (void)
15225 {
15226 struct cmd_list_element *c;
15227
15228 dwarf2_objfile_data_key
15229 = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free);
15230
15231 add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\
15232 Set DWARF 2 specific variables.\n\
15233 Configure DWARF 2 variables such as the cache size"),
15234 &set_dwarf2_cmdlist, "maintenance set dwarf2 ",
15235 0/*allow-unknown*/, &maintenance_set_cmdlist);
15236
15237 add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\
15238 Show DWARF 2 specific variables\n\
15239 Show DWARF 2 variables such as the cache size"),
15240 &show_dwarf2_cmdlist, "maintenance show dwarf2 ",
15241 0/*allow-unknown*/, &maintenance_show_cmdlist);
15242
15243 add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
15244 &dwarf2_max_cache_age, _("\
15245 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
15246 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
15247 A higher limit means that cached compilation units will be stored\n\
15248 in memory longer, and more total memory will be used. Zero disables\n\
15249 caching, which can slow down startup."),
15250 NULL,
15251 show_dwarf2_max_cache_age,
15252 &set_dwarf2_cmdlist,
15253 &show_dwarf2_cmdlist);
15254
15255 add_setshow_boolean_cmd ("always-disassemble", class_obscure,
15256 &dwarf2_always_disassemble, _("\
15257 Set whether `info address' always disassembles DWARF expressions."), _("\
15258 Show whether `info address' always disassembles DWARF expressions."), _("\
15259 When enabled, DWARF expressions are always printed in an assembly-like\n\
15260 syntax. When disabled, expressions will be printed in a more\n\
15261 conversational style, when possible."),
15262 NULL,
15263 show_dwarf2_always_disassemble,
15264 &set_dwarf2_cmdlist,
15265 &show_dwarf2_cmdlist);
15266
15267 add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\
15268 Set debugging of the dwarf2 DIE reader."), _("\
15269 Show debugging of the dwarf2 DIE reader."), _("\
15270 When enabled (non-zero), DIEs are dumped after they are read in.\n\
15271 The value is the maximum depth to print."),
15272 NULL,
15273 NULL,
15274 &setdebuglist, &showdebuglist);
15275
15276 c = add_cmd ("gdb-index", class_files, save_gdb_index_command,
15277 _("Save a .gdb-index file"),
15278 &save_cmdlist);
15279 set_cmd_completer (c, filename_completer);
15280 }
This page took 0.353422 seconds and 4 git commands to generate.