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