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