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