1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
7 Inc. with support from Florida State University (under contract
8 with the Ada Joint Program Office), and Silicon Graphics, Inc.
9 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
10 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
13 This file is part of GDB.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 3 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>. */
33 #include "elf/dwarf2.h"
36 #include "expression.h"
37 #include "filenames.h" /* for DOSish file names */
40 #include "complaints.h"
42 #include "dwarf2expr.h"
43 #include "dwarf2loc.h"
44 #include "cp-support.h"
51 #include "gdb_string.h"
52 #include "gdb_assert.h"
53 #include <sys/types.h>
58 /* A note on memory usage for this file.
60 At the present time, this code reads the debug info sections into
61 the objfile's objfile_obstack. A definite improvement for startup
62 time, on platforms which do not emit relocations for debug
63 sections, would be to use mmap instead. The object's complete
64 debug information is loaded into memory, partly to simplify
65 absolute DIE references.
67 Whether using obstacks or mmap, the sections should remain loaded
68 until the objfile is released, and pointers into the section data
69 can be used for any other data associated to the objfile (symbol
70 names, type names, location expressions to name a few). */
73 /* .debug_info header for a compilation unit
74 Because of alignment constraints, this structure has padding and cannot
75 be mapped directly onto the beginning of the .debug_info section. */
76 typedef struct comp_unit_header
78 unsigned int length
; /* length of the .debug_info
80 unsigned short version
; /* version number -- 2 for DWARF
82 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
83 unsigned char addr_size
; /* byte size of an address -- 4 */
86 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
89 /* .debug_pubnames header
90 Because of alignment constraints, this structure has padding and cannot
91 be mapped directly onto the beginning of the .debug_info section. */
92 typedef struct pubnames_header
94 unsigned int length
; /* length of the .debug_pubnames
96 unsigned char version
; /* version number -- 2 for DWARF
98 unsigned int info_offset
; /* offset into .debug_info section */
99 unsigned int info_size
; /* byte size of .debug_info section
103 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
105 /* .debug_pubnames header
106 Because of alignment constraints, this structure has padding and cannot
107 be mapped directly onto the beginning of the .debug_info section. */
108 typedef struct aranges_header
110 unsigned int length
; /* byte len of the .debug_aranges
112 unsigned short version
; /* version number -- 2 for DWARF
114 unsigned int info_offset
; /* offset into .debug_info section */
115 unsigned char addr_size
; /* byte size of an address */
116 unsigned char seg_size
; /* byte size of segment descriptor */
119 #define _ACTUAL_ARANGES_HEADER_SIZE 12
121 /* .debug_line statement program prologue
122 Because of alignment constraints, this structure has padding and cannot
123 be mapped directly onto the beginning of the .debug_info section. */
124 typedef struct statement_prologue
126 unsigned int total_length
; /* byte length of the statement
128 unsigned short version
; /* version number -- 2 for DWARF
130 unsigned int prologue_length
; /* # bytes between prologue &
132 unsigned char minimum_instruction_length
; /* byte size of
134 unsigned char default_is_stmt
; /* initial value of is_stmt
137 unsigned char line_range
;
138 unsigned char opcode_base
; /* number assigned to first special
140 unsigned char *standard_opcode_lengths
;
144 static const struct objfile_data
*dwarf2_objfile_data_key
;
146 struct dwarf2_per_objfile
148 /* Sizes of debugging sections. */
149 unsigned int info_size
;
150 unsigned int abbrev_size
;
151 unsigned int line_size
;
152 unsigned int pubnames_size
;
153 unsigned int aranges_size
;
154 unsigned int loc_size
;
155 unsigned int macinfo_size
;
156 unsigned int str_size
;
157 unsigned int ranges_size
;
158 unsigned int frame_size
;
159 unsigned int eh_frame_size
;
161 /* Loaded data from the sections. */
162 gdb_byte
*info_buffer
;
163 gdb_byte
*abbrev_buffer
;
164 gdb_byte
*line_buffer
;
165 gdb_byte
*str_buffer
;
166 gdb_byte
*macinfo_buffer
;
167 gdb_byte
*ranges_buffer
;
168 gdb_byte
*loc_buffer
;
170 /* A list of all the compilation units. This is used to locate
171 the target compilation unit of a particular reference. */
172 struct dwarf2_per_cu_data
**all_comp_units
;
174 /* The number of compilation units in ALL_COMP_UNITS. */
177 /* A chain of compilation units that are currently read in, so that
178 they can be freed later. */
179 struct dwarf2_per_cu_data
*read_in_chain
;
181 /* A flag indicating wether this objfile has a section loaded at a
183 int has_section_at_zero
;
186 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
188 static asection
*dwarf_info_section
;
189 static asection
*dwarf_abbrev_section
;
190 static asection
*dwarf_line_section
;
191 static asection
*dwarf_pubnames_section
;
192 static asection
*dwarf_aranges_section
;
193 static asection
*dwarf_loc_section
;
194 static asection
*dwarf_macinfo_section
;
195 static asection
*dwarf_str_section
;
196 static asection
*dwarf_ranges_section
;
197 asection
*dwarf_frame_section
;
198 asection
*dwarf_eh_frame_section
;
200 /* names of the debugging sections */
202 /* Note that if the debugging section has been compressed, it might
203 have a name like .zdebug_info. */
205 #define INFO_SECTION "debug_info"
206 #define ABBREV_SECTION "debug_abbrev"
207 #define LINE_SECTION "debug_line"
208 #define PUBNAMES_SECTION "debug_pubnames"
209 #define ARANGES_SECTION "debug_aranges"
210 #define LOC_SECTION "debug_loc"
211 #define MACINFO_SECTION "debug_macinfo"
212 #define STR_SECTION "debug_str"
213 #define RANGES_SECTION "debug_ranges"
214 #define FRAME_SECTION "debug_frame"
215 #define EH_FRAME_SECTION "eh_frame"
217 /* local data types */
219 /* We hold several abbreviation tables in memory at the same time. */
220 #ifndef ABBREV_HASH_SIZE
221 #define ABBREV_HASH_SIZE 121
224 /* The data in a compilation unit header, after target2host
225 translation, looks like this. */
226 struct comp_unit_head
228 unsigned long length
;
230 unsigned int abbrev_offset
;
231 unsigned char addr_size
;
232 unsigned char signed_addr_p
;
234 /* Size of file offsets; either 4 or 8. */
235 unsigned int offset_size
;
237 /* Size of the length field; either 4 or 12. */
238 unsigned int initial_length_size
;
240 /* Offset to the first byte of this compilation unit header in the
241 .debug_info section, for resolving relative reference dies. */
244 /* Pointer to this compilation unit header in the .debug_info
246 gdb_byte
*cu_head_ptr
;
248 /* Pointer to the first die of this compilation unit. This will be
249 the first byte following the compilation unit header. */
250 gdb_byte
*first_die_ptr
;
252 /* Pointer to the next compilation unit header in the program. */
253 struct comp_unit_head
*next
;
255 /* Base address of this compilation unit. */
256 CORE_ADDR base_address
;
258 /* Non-zero if base_address has been set. */
262 /* Internal state when decoding a particular compilation unit. */
265 /* The objfile containing this compilation unit. */
266 struct objfile
*objfile
;
268 /* The header of the compilation unit.
270 FIXME drow/2003-11-10: Some of the things from the comp_unit_head
271 should logically be moved to the dwarf2_cu structure. */
272 struct comp_unit_head header
;
274 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
276 /* The language we are debugging. */
277 enum language language
;
278 const struct language_defn
*language_defn
;
280 const char *producer
;
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.
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
;
293 /* DWARF abbreviation table associated with this compilation unit. */
294 struct abbrev_info
**dwarf2_abbrevs
;
296 /* Storage for the abbrev table. */
297 struct obstack abbrev_obstack
;
299 /* Hash table holding all the loaded partial DIEs. */
302 /* `.debug_ranges' offset for this `DW_TAG_compile_unit' DIE. */
303 unsigned long ranges_offset
;
305 /* Storage for things with the same lifetime as this read-in compilation
306 unit, including partial DIEs. */
307 struct obstack comp_unit_obstack
;
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
;
315 /* Backchain to our per_cu entry if the tree has been built. */
316 struct dwarf2_per_cu_data
*per_cu
;
318 /* Pointer to the die -> type map. Although it is stored
319 permanently in per_cu, we copy it here to avoid double
323 /* How many compilation units ago was this CU last referenced? */
326 /* A hash table of die offsets for following references. */
329 /* Full DIEs if read in. */
330 struct die_info
*dies
;
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. */
337 /* Header data from the line table, during full symbol processing. */
338 struct line_header
*line_header
;
340 /* Mark used when releasing cached dies. */
341 unsigned int mark
: 1;
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;
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;
353 /* Field `ranges_offset' is filled in; flag as the value may be zero. */
354 unsigned int has_ranges_offset
: 1;
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. */
363 struct dwarf2_per_cu_data
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 unsigned long offset
;
369 unsigned long length
: 30;
371 /* Flag indicating this compilation unit will be read in before
372 any of the current compilation units are processed. */
373 unsigned long queued
: 1;
375 /* This flag will be set if we need to load absolutely all DIEs
376 for this compilation unit, instead of just the ones we think
377 are interesting. It gets set if we look for a DIE in the
378 hash table and don't find it. */
379 unsigned int load_all_dies
: 1;
381 /* Set iff currently read in. */
382 struct dwarf2_cu
*cu
;
384 /* If full symbols for this CU have been read in, then this field
385 holds a map of DIE offsets to types. It isn't always possible
386 to reconstruct this information later, so we have to preserve
390 /* The partial symbol table associated with this compilation unit,
391 or NULL for partial units (which do not have an associated
393 struct partial_symtab
*psymtab
;
396 /* The line number information for a compilation unit (found in the
397 .debug_line section) begins with a "statement program header",
398 which contains the following information. */
401 unsigned int total_length
;
402 unsigned short version
;
403 unsigned int header_length
;
404 unsigned char minimum_instruction_length
;
405 unsigned char default_is_stmt
;
407 unsigned char line_range
;
408 unsigned char opcode_base
;
410 /* standard_opcode_lengths[i] is the number of operands for the
411 standard opcode whose value is i. This means that
412 standard_opcode_lengths[0] is unused, and the last meaningful
413 element is standard_opcode_lengths[opcode_base - 1]. */
414 unsigned char *standard_opcode_lengths
;
416 /* The include_directories table. NOTE! These strings are not
417 allocated with xmalloc; instead, they are pointers into
418 debug_line_buffer. If you try to free them, `free' will get
420 unsigned int num_include_dirs
, include_dirs_size
;
423 /* The file_names table. NOTE! These strings are not allocated
424 with xmalloc; instead, they are pointers into debug_line_buffer.
425 Don't try to free them directly. */
426 unsigned int num_file_names
, file_names_size
;
430 unsigned int dir_index
;
431 unsigned int mod_time
;
433 int included_p
; /* Non-zero if referenced by the Line Number Program. */
434 struct symtab
*symtab
; /* The associated symbol table, if any. */
437 /* The start and end of the statement program following this
438 header. These point into dwarf2_per_objfile->line_buffer. */
439 gdb_byte
*statement_program_start
, *statement_program_end
;
442 /* When we construct a partial symbol table entry we only
443 need this much information. */
444 struct partial_die_info
446 /* Offset of this DIE. */
449 /* DWARF-2 tag for this DIE. */
450 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
452 /* Language code associated with this DIE. This is only used
453 for the compilation unit DIE. */
454 unsigned int language
: 8;
456 /* Assorted flags describing the data found in this DIE. */
457 unsigned int has_children
: 1;
458 unsigned int is_external
: 1;
459 unsigned int is_declaration
: 1;
460 unsigned int has_type
: 1;
461 unsigned int has_specification
: 1;
462 unsigned int has_stmt_list
: 1;
463 unsigned int has_pc_info
: 1;
465 /* Flag set if the SCOPE field of this structure has been
467 unsigned int scope_set
: 1;
469 /* Flag set if the DIE has a byte_size attribute. */
470 unsigned int has_byte_size
: 1;
472 /* The name of this DIE. Normally the value of DW_AT_name, but
473 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
478 /* The scope to prepend to our children. This is generally
479 allocated on the comp_unit_obstack, so will disappear
480 when this compilation unit leaves the cache. */
483 /* The location description associated with this DIE, if any. */
484 struct dwarf_block
*locdesc
;
486 /* If HAS_PC_INFO, the PC range associated with this DIE. */
490 /* Pointer into the info_buffer pointing at the target of
491 DW_AT_sibling, if any. */
494 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
495 DW_AT_specification (or DW_AT_abstract_origin or
497 unsigned int spec_offset
;
499 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
500 unsigned int line_offset
;
502 /* Pointers to this DIE's parent, first child, and next sibling,
504 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
507 /* This data structure holds the information of an abbrev. */
510 unsigned int number
; /* number identifying abbrev */
511 enum dwarf_tag tag
; /* dwarf tag */
512 unsigned short has_children
; /* boolean */
513 unsigned short num_attrs
; /* number of attributes */
514 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
515 struct abbrev_info
*next
; /* next in chain */
520 enum dwarf_attribute name
;
521 enum dwarf_form form
;
524 /* Attributes have a name and a value */
527 enum dwarf_attribute name
;
528 enum dwarf_form form
;
532 struct dwarf_block
*blk
;
540 /* This data structure holds a complete die structure. */
543 enum dwarf_tag tag
; /* Tag indicating type of die */
544 unsigned int abbrev
; /* Abbrev number */
545 unsigned int offset
; /* Offset in .debug_info section */
546 unsigned int num_attrs
; /* Number of attributes */
548 /* The dies in a compilation unit form an n-ary tree. PARENT
549 points to this die's parent; CHILD points to the first child of
550 this node; and all the children of a given node are chained
551 together via their SIBLING fields, terminated by a die whose
553 struct die_info
*child
; /* Its first child, if any. */
554 struct die_info
*sibling
; /* Its next sibling, if any. */
555 struct die_info
*parent
; /* Its parent, if any. */
557 /* An array of attributes, with NUM_ATTRS elements. There may be
558 zero, but it's not common and zero-sized arrays are not
559 sufficiently portable C. */
560 struct attribute attrs
[1];
563 struct function_range
566 CORE_ADDR lowpc
, highpc
;
568 struct function_range
*next
;
571 /* Get at parts of an attribute structure */
573 #define DW_STRING(attr) ((attr)->u.str)
574 #define DW_UNSND(attr) ((attr)->u.unsnd)
575 #define DW_BLOCK(attr) ((attr)->u.blk)
576 #define DW_SND(attr) ((attr)->u.snd)
577 #define DW_ADDR(attr) ((attr)->u.addr)
579 /* Blocks are a bunch of untyped bytes. */
586 #ifndef ATTR_ALLOC_CHUNK
587 #define ATTR_ALLOC_CHUNK 4
590 /* Allocate fields for structs, unions and enums in this size. */
591 #ifndef DW_FIELD_ALLOC_CHUNK
592 #define DW_FIELD_ALLOC_CHUNK 4
595 /* A zeroed version of a partial die for initialization purposes. */
596 static struct partial_die_info zeroed_partial_die
;
598 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
599 but this would require a corresponding change in unpack_field_as_long
601 static int bits_per_byte
= 8;
603 /* The routines that read and process dies for a C struct or C++ class
604 pass lists of data member fields and lists of member function fields
605 in an instance of a field_info structure, as defined below. */
608 /* List of data member and baseclasses fields. */
611 struct nextfield
*next
;
618 /* Number of fields. */
621 /* Number of baseclasses. */
624 /* Set if the accesibility of one of the fields is not public. */
625 int non_public_fields
;
627 /* Member function fields array, entries are allocated in the order they
628 are encountered in the object file. */
631 struct nextfnfield
*next
;
632 struct fn_field fnfield
;
636 /* Member function fieldlist array, contains name of possibly overloaded
637 member function, number of overloaded member functions and a pointer
638 to the head of the member function field chain. */
643 struct nextfnfield
*head
;
647 /* Number of entries in the fnfieldlists array. */
651 /* One item on the queue of compilation units to read in full symbols
653 struct dwarf2_queue_item
655 struct dwarf2_per_cu_data
*per_cu
;
656 struct dwarf2_queue_item
*next
;
659 /* The current queue. */
660 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
662 /* Loaded secondary compilation units are kept in memory until they
663 have not been referenced for the processing of this many
664 compilation units. Set this to zero to disable caching. Cache
665 sizes of up to at least twenty will improve startup time for
666 typical inter-CU-reference binaries, at an obvious memory cost. */
667 static int dwarf2_max_cache_age
= 5;
669 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
670 struct cmd_list_element
*c
, const char *value
)
672 fprintf_filtered (file
, _("\
673 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
678 /* Various complaints about symbol reading that don't abort the process */
681 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
683 complaint (&symfile_complaints
,
684 _("statement list doesn't fit in .debug_line section"));
688 dwarf2_debug_line_missing_file_complaint (void)
690 complaint (&symfile_complaints
,
691 _(".debug_line section has line data without a file"));
695 dwarf2_complex_location_expr_complaint (void)
697 complaint (&symfile_complaints
, _("location expression too complex"));
701 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
704 complaint (&symfile_complaints
,
705 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
710 dwarf2_macros_too_long_complaint (void)
712 complaint (&symfile_complaints
,
713 _("macro info runs off end of `.debug_macinfo' section"));
717 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
719 complaint (&symfile_complaints
,
720 _("macro debug info contains a malformed macro definition:\n`%s'"),
725 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
727 complaint (&symfile_complaints
,
728 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
731 /* local function prototypes */
733 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
736 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
739 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
742 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
743 struct partial_die_info
*,
744 struct partial_symtab
*);
746 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
748 static void scan_partial_symbols (struct partial_die_info
*,
749 CORE_ADDR
*, CORE_ADDR
*,
752 static void add_partial_symbol (struct partial_die_info
*,
755 static int pdi_needs_namespace (enum dwarf_tag tag
);
757 static void add_partial_namespace (struct partial_die_info
*pdi
,
758 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
759 struct dwarf2_cu
*cu
);
761 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
762 struct dwarf2_cu
*cu
);
764 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
767 struct dwarf2_cu
*cu
);
769 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
771 static void psymtab_to_symtab_1 (struct partial_symtab
*);
773 gdb_byte
*dwarf2_read_section (struct objfile
*, asection
*);
775 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
777 static void dwarf2_free_abbrev_table (void *);
779 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
782 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
785 static struct partial_die_info
*load_partial_dies (bfd
*, gdb_byte
*, int,
788 static gdb_byte
*read_partial_die (struct partial_die_info
*,
789 struct abbrev_info
*abbrev
, unsigned int,
790 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
792 static struct partial_die_info
*find_partial_die (unsigned long,
795 static void fixup_partial_die (struct partial_die_info
*,
798 static gdb_byte
*read_full_die (struct die_info
**, bfd
*, gdb_byte
*,
799 struct dwarf2_cu
*, int *);
801 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
802 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
804 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
805 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
807 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
809 static int read_1_signed_byte (bfd
*, gdb_byte
*);
811 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
813 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
815 static unsigned long read_8_bytes (bfd
*, gdb_byte
*);
817 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
820 static LONGEST
read_initial_length (bfd
*, gdb_byte
*,
821 struct comp_unit_head
*, unsigned int *);
823 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
826 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
828 static char *read_string (bfd
*, gdb_byte
*, unsigned int *);
830 static char *read_indirect_string (bfd
*, gdb_byte
*,
831 const struct comp_unit_head
*,
834 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
836 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
838 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
840 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
842 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
845 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
846 struct dwarf2_cu
*cu
);
848 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
850 static struct die_info
*die_specification (struct die_info
*die
,
853 static void free_line_header (struct line_header
*lh
);
855 static void add_file_name (struct line_header
*, char *, unsigned int,
856 unsigned int, unsigned int);
858 static struct line_header
*(dwarf_decode_line_header
859 (unsigned int offset
,
860 bfd
*abfd
, struct dwarf2_cu
*cu
));
862 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
863 struct dwarf2_cu
*, struct partial_symtab
*);
865 static void dwarf2_start_subfile (char *, char *, char *);
867 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
870 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
873 static void dwarf2_const_value_data (struct attribute
*attr
,
877 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
879 static struct type
*die_containing_type (struct die_info
*,
882 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
884 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
886 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
888 static char *typename_concat (struct obstack
*,
893 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
895 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
897 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
899 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
900 struct dwarf2_cu
*, struct partial_symtab
*);
902 static int dwarf2_get_pc_bounds (struct die_info
*,
903 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
905 static void get_scope_pc_bounds (struct die_info
*,
906 CORE_ADDR
*, CORE_ADDR
*,
909 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
910 CORE_ADDR
, struct dwarf2_cu
*);
912 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
915 static void dwarf2_attach_fields_to_type (struct field_info
*,
916 struct type
*, struct dwarf2_cu
*);
918 static void dwarf2_add_member_fn (struct field_info
*,
919 struct die_info
*, struct type
*,
922 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
923 struct type
*, struct dwarf2_cu
*);
925 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
927 static char *determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
929 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
931 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
933 static const char *namespace_name (struct die_info
*die
,
934 int *is_anonymous
, struct dwarf2_cu
*);
936 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
938 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
940 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
943 static struct die_info
*read_comp_unit (gdb_byte
*, bfd
*, struct dwarf2_cu
*);
945 static struct die_info
*read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
947 gdb_byte
**new_info_ptr
,
948 struct die_info
*parent
);
950 static struct die_info
*read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
952 gdb_byte
**new_info_ptr
,
953 struct die_info
*parent
);
955 static void process_die (struct die_info
*, struct dwarf2_cu
*);
957 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
959 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
961 static struct die_info
*dwarf2_extension (struct die_info
*die
,
964 static char *dwarf_tag_name (unsigned int);
966 static char *dwarf_attr_name (unsigned int);
968 static char *dwarf_form_name (unsigned int);
970 static char *dwarf_stack_op_name (unsigned int);
972 static char *dwarf_bool_name (unsigned int);
974 static char *dwarf_type_encoding_name (unsigned int);
977 static char *dwarf_cfi_name (unsigned int);
980 static struct die_info
*sibling_die (struct die_info
*);
982 static void dump_die (struct die_info
*);
984 static void dump_die_list (struct die_info
*);
986 static void store_in_ref_table (struct die_info
*,
989 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*,
992 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
994 static struct die_info
*follow_die_ref (struct die_info
*,
998 /* memory allocation interface */
1000 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1002 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1004 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1006 static void initialize_cu_func_list (struct dwarf2_cu
*);
1008 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1009 struct dwarf2_cu
*);
1011 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1012 char *, bfd
*, struct dwarf2_cu
*);
1014 static int attr_form_is_block (struct attribute
*);
1016 static int attr_form_is_section_offset (struct attribute
*);
1018 static int attr_form_is_constant (struct attribute
*);
1020 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1022 struct dwarf2_cu
*cu
);
1024 static gdb_byte
*skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
1025 struct dwarf2_cu
*cu
);
1027 static void free_stack_comp_unit (void *);
1029 static hashval_t
partial_die_hash (const void *item
);
1031 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1033 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1034 (unsigned long offset
, struct objfile
*objfile
);
1036 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1037 (unsigned long offset
, struct objfile
*objfile
);
1039 static void free_one_comp_unit (void *);
1041 static void free_cached_comp_units (void *);
1043 static void age_cached_comp_units (void);
1045 static void free_one_cached_comp_unit (void *);
1047 static struct type
*set_die_type (struct die_info
*, struct type
*,
1048 struct dwarf2_cu
*);
1050 static void create_all_comp_units (struct objfile
*);
1052 static struct dwarf2_cu
*load_full_comp_unit (struct dwarf2_per_cu_data
*,
1055 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1057 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1058 struct dwarf2_per_cu_data
*);
1060 static void dwarf2_mark (struct dwarf2_cu
*);
1062 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1064 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1066 /* Try to locate the sections we need for DWARF 2 debugging
1067 information and return true if we have enough to do something. */
1070 dwarf2_has_info (struct objfile
*objfile
)
1072 struct dwarf2_per_objfile
*data
;
1074 /* Initialize per-objfile state. */
1075 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1076 memset (data
, 0, sizeof (*data
));
1077 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1078 dwarf2_per_objfile
= data
;
1080 dwarf_info_section
= 0;
1081 dwarf_abbrev_section
= 0;
1082 dwarf_line_section
= 0;
1083 dwarf_str_section
= 0;
1084 dwarf_macinfo_section
= 0;
1085 dwarf_frame_section
= 0;
1086 dwarf_eh_frame_section
= 0;
1087 dwarf_ranges_section
= 0;
1088 dwarf_loc_section
= 0;
1090 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1091 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
1094 /* When loading sections, we can either look for ".<name>", or for
1095 * ".z<name>", which indicates a compressed section. */
1098 section_is_p (asection
*sectp
, const char *name
)
1100 return ((sectp
->name
[0] == '.'
1101 && strcmp (sectp
->name
+ 1, name
) == 0)
1102 || (sectp
->name
[0] == '.' && sectp
->name
[1] == 'z'
1103 && strcmp (sectp
->name
+ 2, name
) == 0));
1106 /* This function is mapped across the sections and remembers the
1107 offset and size of each of the debugging sections we are interested
1111 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1113 if (section_is_p (sectp
, INFO_SECTION
))
1115 dwarf2_per_objfile
->info_size
= bfd_get_section_size (sectp
);
1116 dwarf_info_section
= sectp
;
1118 else if (section_is_p (sectp
, ABBREV_SECTION
))
1120 dwarf2_per_objfile
->abbrev_size
= bfd_get_section_size (sectp
);
1121 dwarf_abbrev_section
= sectp
;
1123 else if (section_is_p (sectp
, LINE_SECTION
))
1125 dwarf2_per_objfile
->line_size
= bfd_get_section_size (sectp
);
1126 dwarf_line_section
= sectp
;
1128 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1130 dwarf2_per_objfile
->pubnames_size
= bfd_get_section_size (sectp
);
1131 dwarf_pubnames_section
= sectp
;
1133 else if (section_is_p (sectp
, ARANGES_SECTION
))
1135 dwarf2_per_objfile
->aranges_size
= bfd_get_section_size (sectp
);
1136 dwarf_aranges_section
= sectp
;
1138 else if (section_is_p (sectp
, LOC_SECTION
))
1140 dwarf2_per_objfile
->loc_size
= bfd_get_section_size (sectp
);
1141 dwarf_loc_section
= sectp
;
1143 else if (section_is_p (sectp
, MACINFO_SECTION
))
1145 dwarf2_per_objfile
->macinfo_size
= bfd_get_section_size (sectp
);
1146 dwarf_macinfo_section
= sectp
;
1148 else if (section_is_p (sectp
, STR_SECTION
))
1150 dwarf2_per_objfile
->str_size
= bfd_get_section_size (sectp
);
1151 dwarf_str_section
= sectp
;
1153 else if (section_is_p (sectp
, FRAME_SECTION
))
1155 dwarf2_per_objfile
->frame_size
= bfd_get_section_size (sectp
);
1156 dwarf_frame_section
= sectp
;
1158 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1160 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1161 if (aflag
& SEC_HAS_CONTENTS
)
1163 dwarf2_per_objfile
->eh_frame_size
= bfd_get_section_size (sectp
);
1164 dwarf_eh_frame_section
= sectp
;
1167 else if (section_is_p (sectp
, RANGES_SECTION
))
1169 dwarf2_per_objfile
->ranges_size
= bfd_get_section_size (sectp
);
1170 dwarf_ranges_section
= sectp
;
1173 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1174 && bfd_section_vma (abfd
, sectp
) == 0)
1175 dwarf2_per_objfile
->has_section_at_zero
= 1;
1178 /* This function is called after decompressing a section, so
1179 dwarf2_per_objfile can record its new, uncompressed size. */
1182 dwarf2_resize_section (asection
*sectp
, bfd_size_type new_size
)
1184 if (section_is_p (sectp
, INFO_SECTION
))
1185 dwarf2_per_objfile
->info_size
= new_size
;
1186 else if (section_is_p (sectp
, ABBREV_SECTION
))
1187 dwarf2_per_objfile
->abbrev_size
= new_size
;
1188 else if (section_is_p (sectp
, LINE_SECTION
))
1189 dwarf2_per_objfile
->line_size
= new_size
;
1190 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1191 dwarf2_per_objfile
->pubnames_size
= new_size
;
1192 else if (section_is_p (sectp
, ARANGES_SECTION
))
1193 dwarf2_per_objfile
->aranges_size
= new_size
;
1194 else if (section_is_p (sectp
, LOC_SECTION
))
1195 dwarf2_per_objfile
->loc_size
= new_size
;
1196 else if (section_is_p (sectp
, MACINFO_SECTION
))
1197 dwarf2_per_objfile
->macinfo_size
= new_size
;
1198 else if (section_is_p (sectp
, STR_SECTION
))
1199 dwarf2_per_objfile
->str_size
= new_size
;
1200 else if (section_is_p (sectp
, FRAME_SECTION
))
1201 dwarf2_per_objfile
->frame_size
= new_size
;
1202 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1203 dwarf2_per_objfile
->eh_frame_size
= new_size
;
1204 else if (section_is_p (sectp
, RANGES_SECTION
))
1205 dwarf2_per_objfile
->ranges_size
= new_size
;
1207 internal_error (__FILE__
, __LINE__
,
1208 _("dwarf2_resize_section: missing section_is_p check: %s"),
1212 /* Build a partial symbol table. */
1215 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1217 /* We definitely need the .debug_info and .debug_abbrev sections */
1219 dwarf2_per_objfile
->info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1220 dwarf2_per_objfile
->abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1222 if (dwarf_line_section
)
1223 dwarf2_per_objfile
->line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1225 dwarf2_per_objfile
->line_buffer
= NULL
;
1227 if (dwarf_str_section
)
1228 dwarf2_per_objfile
->str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1230 dwarf2_per_objfile
->str_buffer
= NULL
;
1232 if (dwarf_macinfo_section
)
1233 dwarf2_per_objfile
->macinfo_buffer
= dwarf2_read_section (objfile
,
1234 dwarf_macinfo_section
);
1236 dwarf2_per_objfile
->macinfo_buffer
= NULL
;
1238 if (dwarf_ranges_section
)
1239 dwarf2_per_objfile
->ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1241 dwarf2_per_objfile
->ranges_buffer
= NULL
;
1243 if (dwarf_loc_section
)
1244 dwarf2_per_objfile
->loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1246 dwarf2_per_objfile
->loc_buffer
= NULL
;
1249 || (objfile
->global_psymbols
.size
== 0
1250 && objfile
->static_psymbols
.size
== 0))
1252 init_psymbol_list (objfile
, 1024);
1256 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1258 /* Things are significantly easier if we have .debug_aranges and
1259 .debug_pubnames sections */
1261 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1265 /* only test this case for now */
1267 /* In this case we have to work a bit harder */
1268 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1273 /* Build the partial symbol table from the information in the
1274 .debug_pubnames and .debug_aranges sections. */
1277 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1279 bfd
*abfd
= objfile
->obfd
;
1280 char *aranges_buffer
, *pubnames_buffer
;
1281 char *aranges_ptr
, *pubnames_ptr
;
1282 unsigned int entry_length
, version
, info_offset
, info_size
;
1284 pubnames_buffer
= dwarf2_read_section (objfile
,
1285 dwarf_pubnames_section
);
1286 pubnames_ptr
= pubnames_buffer
;
1287 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames_size
)
1289 struct comp_unit_head cu_header
;
1290 unsigned int bytes_read
;
1292 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1294 pubnames_ptr
+= bytes_read
;
1295 version
= read_1_byte (abfd
, pubnames_ptr
);
1297 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1299 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1303 aranges_buffer
= dwarf2_read_section (objfile
,
1304 dwarf_aranges_section
);
1309 /* Read in the comp unit header information from the debug_info at
1313 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1314 gdb_byte
*info_ptr
, bfd
*abfd
)
1317 unsigned int bytes_read
;
1318 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1320 info_ptr
+= bytes_read
;
1321 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1323 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1325 info_ptr
+= bytes_read
;
1326 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1328 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1329 if (signed_addr
< 0)
1330 internal_error (__FILE__
, __LINE__
,
1331 _("read_comp_unit_head: dwarf from non elf file"));
1332 cu_header
->signed_addr_p
= signed_addr
;
1337 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1340 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1342 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1344 if (header
->version
!= 2 && header
->version
!= 3)
1345 error (_("Dwarf Error: wrong version in compilation unit header "
1346 "(is %d, should be %d) [in module %s]"), header
->version
,
1347 2, bfd_get_filename (abfd
));
1349 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev_size
)
1350 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1351 "(offset 0x%lx + 6) [in module %s]"),
1352 (long) header
->abbrev_offset
,
1353 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1354 bfd_get_filename (abfd
));
1356 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1357 > dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1358 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1359 "(offset 0x%lx + 0) [in module %s]"),
1360 (long) header
->length
,
1361 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1362 bfd_get_filename (abfd
));
1367 /* Allocate a new partial symtab for file named NAME and mark this new
1368 partial symtab as being an include of PST. */
1371 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1372 struct objfile
*objfile
)
1374 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1376 subpst
->section_offsets
= pst
->section_offsets
;
1377 subpst
->textlow
= 0;
1378 subpst
->texthigh
= 0;
1380 subpst
->dependencies
= (struct partial_symtab
**)
1381 obstack_alloc (&objfile
->objfile_obstack
,
1382 sizeof (struct partial_symtab
*));
1383 subpst
->dependencies
[0] = pst
;
1384 subpst
->number_of_dependencies
= 1;
1386 subpst
->globals_offset
= 0;
1387 subpst
->n_global_syms
= 0;
1388 subpst
->statics_offset
= 0;
1389 subpst
->n_static_syms
= 0;
1390 subpst
->symtab
= NULL
;
1391 subpst
->read_symtab
= pst
->read_symtab
;
1394 /* No private part is necessary for include psymtabs. This property
1395 can be used to differentiate between such include psymtabs and
1396 the regular ones. */
1397 subpst
->read_symtab_private
= NULL
;
1400 /* Read the Line Number Program data and extract the list of files
1401 included by the source file represented by PST. Build an include
1402 partial symtab for each of these included files.
1404 This procedure assumes that there *is* a Line Number Program in
1405 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1406 before calling this procedure. */
1409 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1410 struct partial_die_info
*pdi
,
1411 struct partial_symtab
*pst
)
1413 struct objfile
*objfile
= cu
->objfile
;
1414 bfd
*abfd
= objfile
->obfd
;
1415 struct line_header
*lh
;
1417 lh
= dwarf_decode_line_header (pdi
->line_offset
, abfd
, cu
);
1419 return; /* No linetable, so no includes. */
1421 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1423 free_line_header (lh
);
1427 /* Build the partial symbol table by doing a quick pass through the
1428 .debug_info and .debug_abbrev sections. */
1431 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1433 /* Instead of reading this into a big buffer, we should probably use
1434 mmap() on architectures that support it. (FIXME) */
1435 bfd
*abfd
= objfile
->obfd
;
1437 gdb_byte
*beg_of_comp_unit
;
1438 struct partial_die_info comp_unit_die
;
1439 struct partial_symtab
*pst
;
1440 struct cleanup
*back_to
;
1441 CORE_ADDR lowpc
, highpc
, baseaddr
;
1443 info_ptr
= dwarf2_per_objfile
->info_buffer
;
1445 /* Any cached compilation units will be linked by the per-objfile
1446 read_in_chain. Make sure to free them when we're done. */
1447 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1449 create_all_comp_units (objfile
);
1451 objfile
->psymtabs_addrmap
= addrmap_create_mutable
1452 (&objfile
->objfile_obstack
);
1454 /* Since the objects we're extracting from .debug_info vary in
1455 length, only the individual functions to extract them (like
1456 read_comp_unit_head and load_partial_die) can really know whether
1457 the buffer is large enough to hold another complete object.
1459 At the moment, they don't actually check that. If .debug_info
1460 holds just one extra byte after the last compilation unit's dies,
1461 then read_comp_unit_head will happily read off the end of the
1462 buffer. read_partial_die is similarly casual. Those functions
1465 For this loop condition, simply checking whether there's any data
1466 left at all should be sufficient. */
1467 while (info_ptr
< (dwarf2_per_objfile
->info_buffer
1468 + dwarf2_per_objfile
->info_size
))
1470 struct cleanup
*back_to_inner
;
1471 struct dwarf2_cu cu
;
1472 struct abbrev_info
*abbrev
;
1473 unsigned int bytes_read
;
1474 struct dwarf2_per_cu_data
*this_cu
;
1476 beg_of_comp_unit
= info_ptr
;
1478 memset (&cu
, 0, sizeof (cu
));
1480 obstack_init (&cu
.comp_unit_obstack
);
1482 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1484 cu
.objfile
= objfile
;
1485 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1487 /* Complete the cu_header */
1488 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1489 cu
.header
.first_die_ptr
= info_ptr
;
1490 cu
.header
.cu_head_ptr
= beg_of_comp_unit
;
1492 cu
.list_in_scope
= &file_symbols
;
1494 /* Read the abbrevs for this compilation unit into a table */
1495 dwarf2_read_abbrevs (abfd
, &cu
);
1496 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1498 this_cu
= dwarf2_find_comp_unit (cu
.header
.offset
, objfile
);
1500 /* Read the compilation unit die */
1501 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, &cu
);
1502 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1503 abfd
, info_ptr
, &cu
);
1505 if (comp_unit_die
.tag
== DW_TAG_partial_unit
)
1507 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1508 + cu
.header
.initial_length_size
);
1509 do_cleanups (back_to_inner
);
1513 /* Set the language we're debugging */
1514 set_cu_language (comp_unit_die
.language
, &cu
);
1516 /* Allocate a new partial symbol table structure */
1517 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1518 comp_unit_die
.name
? comp_unit_die
.name
: "",
1519 /* TEXTLOW and TEXTHIGH are set below. */
1521 objfile
->global_psymbols
.next
,
1522 objfile
->static_psymbols
.next
);
1524 if (comp_unit_die
.dirname
)
1525 pst
->dirname
= xstrdup (comp_unit_die
.dirname
);
1527 pst
->read_symtab_private
= (char *) this_cu
;
1529 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1531 /* Store the function that reads in the rest of the symbol table */
1532 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1534 /* If this compilation unit was already read in, free the
1535 cached copy in order to read it in again. This is
1536 necessary because we skipped some symbols when we first
1537 read in the compilation unit (see load_partial_dies).
1538 This problem could be avoided, but the benefit is
1540 if (this_cu
->cu
!= NULL
)
1541 free_one_cached_comp_unit (this_cu
->cu
);
1543 cu
.per_cu
= this_cu
;
1545 /* Note that this is a pointer to our stack frame, being
1546 added to a global data structure. It will be cleaned up
1547 in free_stack_comp_unit when we finish with this
1548 compilation unit. */
1551 this_cu
->psymtab
= pst
;
1553 /* Possibly set the default values of LOWPC and HIGHPC from
1555 if (cu
.has_ranges_offset
)
1557 if (dwarf2_ranges_read (cu
.ranges_offset
, &comp_unit_die
.lowpc
,
1558 &comp_unit_die
.highpc
, &cu
, pst
))
1559 comp_unit_die
.has_pc_info
= 1;
1562 /* Check if comp unit has_children.
1563 If so, read the rest of the partial symbols from this comp unit.
1564 If not, there's no more debug_info for this comp unit. */
1565 if (comp_unit_die
.has_children
)
1567 struct partial_die_info
*first_die
;
1569 lowpc
= ((CORE_ADDR
) -1);
1570 highpc
= ((CORE_ADDR
) 0);
1572 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1574 scan_partial_symbols (first_die
, &lowpc
, &highpc
, &cu
);
1576 /* If we didn't find a lowpc, set it to highpc to avoid
1577 complaints from `maint check'. */
1578 if (lowpc
== ((CORE_ADDR
) -1))
1581 /* If the compilation unit didn't have an explicit address range,
1582 then use the information extracted from its child dies. */
1583 if (! comp_unit_die
.has_pc_info
)
1585 comp_unit_die
.lowpc
= lowpc
;
1586 comp_unit_die
.highpc
= highpc
;
1589 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1590 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1592 /* Store the contiguous range; `DW_AT_ranges' range is stored above. The
1593 range can be also empty for CUs with no code. */
1594 if (!cu
.has_ranges_offset
&& pst
->textlow
< pst
->texthigh
)
1595 addrmap_set_empty (objfile
->psymtabs_addrmap
, pst
->textlow
,
1596 pst
->texthigh
- 1, pst
);
1598 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1599 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1600 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1601 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1602 sort_pst_symbols (pst
);
1604 /* If there is already a psymtab or symtab for a file of this
1605 name, remove it. (If there is a symtab, more drastic things
1606 also happen.) This happens in VxWorks. */
1607 free_named_symtabs (pst
->filename
);
1609 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1610 + cu
.header
.initial_length_size
;
1612 if (comp_unit_die
.has_stmt_list
)
1614 /* Get the list of files included in the current compilation unit,
1615 and build a psymtab for each of them. */
1616 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1619 do_cleanups (back_to_inner
);
1622 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
1623 &objfile
->objfile_obstack
);
1625 do_cleanups (back_to
);
1628 /* Load the DIEs for a secondary CU into memory. */
1631 load_comp_unit (struct dwarf2_per_cu_data
*this_cu
, struct objfile
*objfile
)
1633 bfd
*abfd
= objfile
->obfd
;
1634 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
1635 struct partial_die_info comp_unit_die
;
1636 struct dwarf2_cu
*cu
;
1637 struct abbrev_info
*abbrev
;
1638 unsigned int bytes_read
;
1639 struct cleanup
*back_to
;
1641 info_ptr
= dwarf2_per_objfile
->info_buffer
+ this_cu
->offset
;
1642 beg_of_comp_unit
= info_ptr
;
1644 cu
= xmalloc (sizeof (struct dwarf2_cu
));
1645 memset (cu
, 0, sizeof (struct dwarf2_cu
));
1647 obstack_init (&cu
->comp_unit_obstack
);
1649 cu
->objfile
= objfile
;
1650 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
1652 /* Complete the cu_header. */
1653 cu
->header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1654 cu
->header
.first_die_ptr
= info_ptr
;
1655 cu
->header
.cu_head_ptr
= beg_of_comp_unit
;
1657 /* Read the abbrevs for this compilation unit into a table. */
1658 dwarf2_read_abbrevs (abfd
, cu
);
1659 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
1661 /* Read the compilation unit die. */
1662 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1663 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1664 abfd
, info_ptr
, cu
);
1666 /* Set the language we're debugging. */
1667 set_cu_language (comp_unit_die
.language
, cu
);
1669 /* Link this compilation unit into the compilation unit tree. */
1671 cu
->per_cu
= this_cu
;
1672 cu
->type_hash
= cu
->per_cu
->type_hash
;
1674 /* Check if comp unit has_children.
1675 If so, read the rest of the partial symbols from this comp unit.
1676 If not, there's no more debug_info for this comp unit. */
1677 if (comp_unit_die
.has_children
)
1678 load_partial_dies (abfd
, info_ptr
, 0, cu
);
1680 do_cleanups (back_to
);
1683 /* Create a list of all compilation units in OBJFILE. We do this only
1684 if an inter-comp-unit reference is found; presumably if there is one,
1685 there will be many, and one will occur early in the .debug_info section.
1686 So there's no point in building this list incrementally. */
1689 create_all_comp_units (struct objfile
*objfile
)
1693 struct dwarf2_per_cu_data
**all_comp_units
;
1694 gdb_byte
*info_ptr
= dwarf2_per_objfile
->info_buffer
;
1698 all_comp_units
= xmalloc (n_allocated
1699 * sizeof (struct dwarf2_per_cu_data
*));
1701 while (info_ptr
< dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1703 struct comp_unit_head cu_header
;
1704 gdb_byte
*beg_of_comp_unit
;
1705 struct dwarf2_per_cu_data
*this_cu
;
1706 unsigned long offset
;
1707 unsigned int bytes_read
;
1709 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
1711 /* Read just enough information to find out where the next
1712 compilation unit is. */
1713 cu_header
.initial_length_size
= 0;
1714 cu_header
.length
= read_initial_length (objfile
->obfd
, info_ptr
,
1715 &cu_header
, &bytes_read
);
1717 /* Save the compilation unit for later lookup. */
1718 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
1719 sizeof (struct dwarf2_per_cu_data
));
1720 memset (this_cu
, 0, sizeof (*this_cu
));
1721 this_cu
->offset
= offset
;
1722 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
1724 if (n_comp_units
== n_allocated
)
1727 all_comp_units
= xrealloc (all_comp_units
,
1729 * sizeof (struct dwarf2_per_cu_data
*));
1731 all_comp_units
[n_comp_units
++] = this_cu
;
1733 info_ptr
= info_ptr
+ this_cu
->length
;
1736 dwarf2_per_objfile
->all_comp_units
1737 = obstack_alloc (&objfile
->objfile_obstack
,
1738 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1739 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
1740 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1741 xfree (all_comp_units
);
1742 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
1745 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1746 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1750 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1751 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
1753 struct objfile
*objfile
= cu
->objfile
;
1754 bfd
*abfd
= objfile
->obfd
;
1755 struct partial_die_info
*pdi
;
1757 /* Now, march along the PDI's, descending into ones which have
1758 interesting children but skipping the children of the other ones,
1759 until we reach the end of the compilation unit. */
1765 fixup_partial_die (pdi
, cu
);
1767 /* Anonymous namespaces have no name but have interesting
1768 children, so we need to look at them. Ditto for anonymous
1771 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1772 || pdi
->tag
== DW_TAG_enumeration_type
)
1776 case DW_TAG_subprogram
:
1777 if (pdi
->has_pc_info
)
1779 if (pdi
->lowpc
< *lowpc
)
1781 *lowpc
= pdi
->lowpc
;
1783 if (pdi
->highpc
> *highpc
)
1785 *highpc
= pdi
->highpc
;
1787 if (!pdi
->is_declaration
)
1789 add_partial_symbol (pdi
, cu
);
1793 case DW_TAG_variable
:
1794 case DW_TAG_typedef
:
1795 case DW_TAG_union_type
:
1796 if (!pdi
->is_declaration
)
1798 add_partial_symbol (pdi
, cu
);
1801 case DW_TAG_class_type
:
1802 case DW_TAG_interface_type
:
1803 case DW_TAG_structure_type
:
1804 if (!pdi
->is_declaration
)
1806 add_partial_symbol (pdi
, cu
);
1809 case DW_TAG_enumeration_type
:
1810 if (!pdi
->is_declaration
)
1811 add_partial_enumeration (pdi
, cu
);
1813 case DW_TAG_base_type
:
1814 case DW_TAG_subrange_type
:
1815 /* File scope base type definitions are added to the partial
1817 add_partial_symbol (pdi
, cu
);
1819 case DW_TAG_namespace
:
1820 add_partial_namespace (pdi
, lowpc
, highpc
, cu
);
1827 /* If the die has a sibling, skip to the sibling. */
1829 pdi
= pdi
->die_sibling
;
1833 /* Functions used to compute the fully scoped name of a partial DIE.
1835 Normally, this is simple. For C++, the parent DIE's fully scoped
1836 name is concatenated with "::" and the partial DIE's name. For
1837 Java, the same thing occurs except that "." is used instead of "::".
1838 Enumerators are an exception; they use the scope of their parent
1839 enumeration type, i.e. the name of the enumeration type is not
1840 prepended to the enumerator.
1842 There are two complexities. One is DW_AT_specification; in this
1843 case "parent" means the parent of the target of the specification,
1844 instead of the direct parent of the DIE. The other is compilers
1845 which do not emit DW_TAG_namespace; in this case we try to guess
1846 the fully qualified name of structure types from their members'
1847 linkage names. This must be done using the DIE's children rather
1848 than the children of any DW_AT_specification target. We only need
1849 to do this for structures at the top level, i.e. if the target of
1850 any DW_AT_specification (if any; otherwise the DIE itself) does not
1853 /* Compute the scope prefix associated with PDI's parent, in
1854 compilation unit CU. The result will be allocated on CU's
1855 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1856 field. NULL is returned if no prefix is necessary. */
1858 partial_die_parent_scope (struct partial_die_info
*pdi
,
1859 struct dwarf2_cu
*cu
)
1861 char *grandparent_scope
;
1862 struct partial_die_info
*parent
, *real_pdi
;
1864 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1865 then this means the parent of the specification DIE. */
1868 while (real_pdi
->has_specification
)
1869 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
1871 parent
= real_pdi
->die_parent
;
1875 if (parent
->scope_set
)
1876 return parent
->scope
;
1878 fixup_partial_die (parent
, cu
);
1880 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
1882 if (parent
->tag
== DW_TAG_namespace
1883 || parent
->tag
== DW_TAG_structure_type
1884 || parent
->tag
== DW_TAG_class_type
1885 || parent
->tag
== DW_TAG_interface_type
1886 || parent
->tag
== DW_TAG_union_type
)
1888 if (grandparent_scope
== NULL
)
1889 parent
->scope
= parent
->name
;
1891 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
1894 else if (parent
->tag
== DW_TAG_enumeration_type
)
1895 /* Enumerators should not get the name of the enumeration as a prefix. */
1896 parent
->scope
= grandparent_scope
;
1899 /* FIXME drow/2004-04-01: What should we be doing with
1900 function-local names? For partial symbols, we should probably be
1902 complaint (&symfile_complaints
,
1903 _("unhandled containing DIE tag %d for DIE at %d"),
1904 parent
->tag
, pdi
->offset
);
1905 parent
->scope
= grandparent_scope
;
1908 parent
->scope_set
= 1;
1909 return parent
->scope
;
1912 /* Return the fully scoped name associated with PDI, from compilation unit
1913 CU. The result will be allocated with malloc. */
1915 partial_die_full_name (struct partial_die_info
*pdi
,
1916 struct dwarf2_cu
*cu
)
1920 parent_scope
= partial_die_parent_scope (pdi
, cu
);
1921 if (parent_scope
== NULL
)
1924 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
1928 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
1930 struct objfile
*objfile
= cu
->objfile
;
1932 char *actual_name
= NULL
;
1933 const char *my_prefix
;
1934 const struct partial_symbol
*psym
= NULL
;
1936 int built_actual_name
= 0;
1938 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1940 if (pdi_needs_namespace (pdi
->tag
))
1942 actual_name
= partial_die_full_name (pdi
, cu
);
1944 built_actual_name
= 1;
1947 if (actual_name
== NULL
)
1948 actual_name
= pdi
->name
;
1952 case DW_TAG_subprogram
:
1953 if (pdi
->is_external
|| cu
->language
== language_ada
)
1955 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
1956 of the global scope. But in Ada, we want to be able to access
1957 nested procedures globally. So all Ada subprograms are stored
1958 in the global scope. */
1959 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1960 mst_text, objfile); */
1961 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1962 VAR_DOMAIN
, LOC_BLOCK
,
1963 &objfile
->global_psymbols
,
1964 0, pdi
->lowpc
+ baseaddr
,
1965 cu
->language
, objfile
);
1969 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1970 mst_file_text, objfile); */
1971 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1972 VAR_DOMAIN
, LOC_BLOCK
,
1973 &objfile
->static_psymbols
,
1974 0, pdi
->lowpc
+ baseaddr
,
1975 cu
->language
, objfile
);
1978 case DW_TAG_variable
:
1979 if (pdi
->is_external
)
1982 Don't enter into the minimal symbol tables as there is
1983 a minimal symbol table entry from the ELF symbols already.
1984 Enter into partial symbol table if it has a location
1985 descriptor or a type.
1986 If the location descriptor is missing, new_symbol will create
1987 a LOC_UNRESOLVED symbol, the address of the variable will then
1988 be determined from the minimal symbol table whenever the variable
1990 The address for the partial symbol table entry is not
1991 used by GDB, but it comes in handy for debugging partial symbol
1995 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1996 if (pdi
->locdesc
|| pdi
->has_type
)
1997 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1998 VAR_DOMAIN
, LOC_STATIC
,
1999 &objfile
->global_psymbols
,
2001 cu
->language
, objfile
);
2005 /* Static Variable. Skip symbols without location descriptors. */
2006 if (pdi
->locdesc
== NULL
)
2008 if (built_actual_name
)
2009 xfree (actual_name
);
2012 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2013 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2014 mst_file_data, objfile); */
2015 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2016 VAR_DOMAIN
, LOC_STATIC
,
2017 &objfile
->static_psymbols
,
2019 cu
->language
, objfile
);
2022 case DW_TAG_typedef
:
2023 case DW_TAG_base_type
:
2024 case DW_TAG_subrange_type
:
2025 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2026 VAR_DOMAIN
, LOC_TYPEDEF
,
2027 &objfile
->static_psymbols
,
2028 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2030 case DW_TAG_namespace
:
2031 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2032 VAR_DOMAIN
, LOC_TYPEDEF
,
2033 &objfile
->global_psymbols
,
2034 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2036 case DW_TAG_class_type
:
2037 case DW_TAG_interface_type
:
2038 case DW_TAG_structure_type
:
2039 case DW_TAG_union_type
:
2040 case DW_TAG_enumeration_type
:
2041 /* Skip external references. The DWARF standard says in the section
2042 about "Structure, Union, and Class Type Entries": "An incomplete
2043 structure, union or class type is represented by a structure,
2044 union or class entry that does not have a byte size attribute
2045 and that has a DW_AT_declaration attribute." */
2046 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2048 if (built_actual_name
)
2049 xfree (actual_name
);
2053 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2054 static vs. global. */
2055 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2056 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2057 (cu
->language
== language_cplus
2058 || cu
->language
== language_java
)
2059 ? &objfile
->global_psymbols
2060 : &objfile
->static_psymbols
,
2061 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2064 case DW_TAG_enumerator
:
2065 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2066 VAR_DOMAIN
, LOC_CONST
,
2067 (cu
->language
== language_cplus
2068 || cu
->language
== language_java
)
2069 ? &objfile
->global_psymbols
2070 : &objfile
->static_psymbols
,
2071 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2077 /* Check to see if we should scan the name for possible namespace
2078 info. Only do this if this is C++, if we don't have namespace
2079 debugging info in the file, if the psym is of an appropriate type
2080 (otherwise we'll have psym == NULL), and if we actually had a
2081 mangled name to begin with. */
2083 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2084 cases which do not set PSYM above? */
2086 if (cu
->language
== language_cplus
2087 && cu
->has_namespace_info
== 0
2089 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
2090 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
2093 if (built_actual_name
)
2094 xfree (actual_name
);
2097 /* Determine whether a die of type TAG living in a C++ class or
2098 namespace needs to have the name of the scope prepended to the
2099 name listed in the die. */
2102 pdi_needs_namespace (enum dwarf_tag tag
)
2106 case DW_TAG_namespace
:
2107 case DW_TAG_typedef
:
2108 case DW_TAG_class_type
:
2109 case DW_TAG_interface_type
:
2110 case DW_TAG_structure_type
:
2111 case DW_TAG_union_type
:
2112 case DW_TAG_enumeration_type
:
2113 case DW_TAG_enumerator
:
2120 /* Read a partial die corresponding to a namespace; also, add a symbol
2121 corresponding to that namespace to the symbol table. NAMESPACE is
2122 the name of the enclosing namespace. */
2125 add_partial_namespace (struct partial_die_info
*pdi
,
2126 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2127 struct dwarf2_cu
*cu
)
2129 struct objfile
*objfile
= cu
->objfile
;
2131 /* Add a symbol for the namespace. */
2133 add_partial_symbol (pdi
, cu
);
2135 /* Now scan partial symbols in that namespace. */
2137 if (pdi
->has_children
)
2138 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, cu
);
2141 /* See if we can figure out if the class lives in a namespace. We do
2142 this by looking for a member function; its demangled name will
2143 contain namespace info, if there is any. */
2146 guess_structure_name (struct partial_die_info
*struct_pdi
,
2147 struct dwarf2_cu
*cu
)
2149 if ((cu
->language
== language_cplus
2150 || cu
->language
== language_java
)
2151 && cu
->has_namespace_info
== 0
2152 && struct_pdi
->has_children
)
2154 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2155 what template types look like, because the demangler
2156 frequently doesn't give the same name as the debug info. We
2157 could fix this by only using the demangled name to get the
2158 prefix (but see comment in read_structure_type). */
2160 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
2161 struct partial_die_info
*real_pdi
;
2163 /* If this DIE (this DIE's specification, if any) has a parent, then
2164 we should not do this. We'll prepend the parent's fully qualified
2165 name when we create the partial symbol. */
2167 real_pdi
= struct_pdi
;
2168 while (real_pdi
->has_specification
)
2169 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2171 if (real_pdi
->die_parent
!= NULL
)
2174 while (child_pdi
!= NULL
)
2176 if (child_pdi
->tag
== DW_TAG_subprogram
)
2178 char *actual_class_name
2179 = language_class_name_from_physname (cu
->language_defn
,
2181 if (actual_class_name
!= NULL
)
2184 = obsavestring (actual_class_name
,
2185 strlen (actual_class_name
),
2186 &cu
->comp_unit_obstack
);
2187 xfree (actual_class_name
);
2192 child_pdi
= child_pdi
->die_sibling
;
2197 /* Read a partial die corresponding to an enumeration type. */
2200 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2201 struct dwarf2_cu
*cu
)
2203 struct objfile
*objfile
= cu
->objfile
;
2204 bfd
*abfd
= objfile
->obfd
;
2205 struct partial_die_info
*pdi
;
2207 if (enum_pdi
->name
!= NULL
)
2208 add_partial_symbol (enum_pdi
, cu
);
2210 pdi
= enum_pdi
->die_child
;
2213 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2214 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2216 add_partial_symbol (pdi
, cu
);
2217 pdi
= pdi
->die_sibling
;
2221 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2222 Return the corresponding abbrev, or NULL if the number is zero (indicating
2223 an empty DIE). In either case *BYTES_READ will be set to the length of
2224 the initial number. */
2226 static struct abbrev_info
*
2227 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2228 struct dwarf2_cu
*cu
)
2230 bfd
*abfd
= cu
->objfile
->obfd
;
2231 unsigned int abbrev_number
;
2232 struct abbrev_info
*abbrev
;
2234 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2236 if (abbrev_number
== 0)
2239 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2242 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2243 bfd_get_filename (abfd
));
2249 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2250 pointer to the end of a series of DIEs, terminated by an empty
2251 DIE. Any children of the skipped DIEs will also be skipped. */
2254 skip_children (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2256 struct abbrev_info
*abbrev
;
2257 unsigned int bytes_read
;
2261 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2263 return info_ptr
+ bytes_read
;
2265 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
2269 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2270 should point just after the initial uleb128 of a DIE, and the
2271 abbrev corresponding to that skipped uleb128 should be passed in
2272 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2276 skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
2277 struct dwarf2_cu
*cu
)
2279 unsigned int bytes_read
;
2280 struct attribute attr
;
2281 bfd
*abfd
= cu
->objfile
->obfd
;
2282 unsigned int form
, i
;
2284 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2286 /* The only abbrev we care about is DW_AT_sibling. */
2287 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2289 read_attribute (&attr
, &abbrev
->attrs
[i
],
2290 abfd
, info_ptr
, cu
);
2291 if (attr
.form
== DW_FORM_ref_addr
)
2292 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2294 return dwarf2_per_objfile
->info_buffer
2295 + dwarf2_get_ref_die_offset (&attr
, cu
);
2298 /* If it isn't DW_AT_sibling, skip this attribute. */
2299 form
= abbrev
->attrs
[i
].form
;
2304 case DW_FORM_ref_addr
:
2305 info_ptr
+= cu
->header
.addr_size
;
2324 case DW_FORM_string
:
2325 read_string (abfd
, info_ptr
, &bytes_read
);
2326 info_ptr
+= bytes_read
;
2329 info_ptr
+= cu
->header
.offset_size
;
2332 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2333 info_ptr
+= bytes_read
;
2335 case DW_FORM_block1
:
2336 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2338 case DW_FORM_block2
:
2339 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2341 case DW_FORM_block4
:
2342 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2346 case DW_FORM_ref_udata
:
2347 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2349 case DW_FORM_indirect
:
2350 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2351 info_ptr
+= bytes_read
;
2352 /* We need to continue parsing from here, so just go back to
2354 goto skip_attribute
;
2357 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2358 dwarf_form_name (form
),
2359 bfd_get_filename (abfd
));
2363 if (abbrev
->has_children
)
2364 return skip_children (info_ptr
, cu
);
2369 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2370 the next DIE after ORIG_PDI. */
2373 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, gdb_byte
*info_ptr
,
2374 bfd
*abfd
, struct dwarf2_cu
*cu
)
2376 /* Do we know the sibling already? */
2378 if (orig_pdi
->sibling
)
2379 return orig_pdi
->sibling
;
2381 /* Are there any children to deal with? */
2383 if (!orig_pdi
->has_children
)
2386 /* Skip the children the long way. */
2388 return skip_children (info_ptr
, cu
);
2391 /* Expand this partial symbol table into a full symbol table. */
2394 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2396 /* FIXME: This is barely more than a stub. */
2401 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2407 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2408 gdb_flush (gdb_stdout
);
2411 /* Restore our global data. */
2412 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2413 dwarf2_objfile_data_key
);
2415 psymtab_to_symtab_1 (pst
);
2417 /* Finish up the debug error message. */
2419 printf_filtered (_("done.\n"));
2424 /* Add PER_CU to the queue. */
2427 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2429 struct dwarf2_queue_item
*item
;
2432 item
= xmalloc (sizeof (*item
));
2433 item
->per_cu
= per_cu
;
2436 if (dwarf2_queue
== NULL
)
2437 dwarf2_queue
= item
;
2439 dwarf2_queue_tail
->next
= item
;
2441 dwarf2_queue_tail
= item
;
2443 /* Either PER_CU is the CU we want to process, or we're following a reference
2444 pointing into PER_CU. Either way, we need its DIEs now. */
2445 load_full_comp_unit (item
->per_cu
, objfile
);
2446 item
->per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
2447 dwarf2_per_objfile
->read_in_chain
= item
->per_cu
;
2450 /* Process the queue. */
2453 process_queue (struct objfile
*objfile
)
2455 struct dwarf2_queue_item
*item
, *next_item
;
2457 /* The queue starts out with one item, but following a DIE reference
2458 may load a new CU, adding it to the end of the queue. */
2459 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2461 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2462 process_full_comp_unit (item
->per_cu
);
2464 item
->per_cu
->queued
= 0;
2465 next_item
= item
->next
;
2469 dwarf2_queue_tail
= NULL
;
2472 /* Free all allocated queue entries. This function only releases anything if
2473 an error was thrown; if the queue was processed then it would have been
2474 freed as we went along. */
2477 dwarf2_release_queue (void *dummy
)
2479 struct dwarf2_queue_item
*item
, *last
;
2481 item
= dwarf2_queue
;
2484 /* Anything still marked queued is likely to be in an
2485 inconsistent state, so discard it. */
2486 if (item
->per_cu
->queued
)
2488 if (item
->per_cu
->cu
!= NULL
)
2489 free_one_cached_comp_unit (item
->per_cu
->cu
);
2490 item
->per_cu
->queued
= 0;
2498 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2501 /* Read in full symbols for PST, and anything it depends on. */
2504 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2506 struct dwarf2_per_cu_data
*per_cu
;
2507 struct cleanup
*back_to
;
2510 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2511 if (!pst
->dependencies
[i
]->readin
)
2513 /* Inform about additional files that need to be read in. */
2516 /* FIXME: i18n: Need to make this a single string. */
2517 fputs_filtered (" ", gdb_stdout
);
2519 fputs_filtered ("and ", gdb_stdout
);
2521 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2522 wrap_here (""); /* Flush output */
2523 gdb_flush (gdb_stdout
);
2525 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2528 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
2532 /* It's an include file, no symbols to read for it.
2533 Everything is in the parent symtab. */
2538 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2540 queue_comp_unit (per_cu
, pst
->objfile
);
2542 process_queue (pst
->objfile
);
2544 /* Age the cache, releasing compilation units that have not
2545 been used recently. */
2546 age_cached_comp_units ();
2548 do_cleanups (back_to
);
2551 /* Load the DIEs associated with PST and PER_CU into memory. */
2553 static struct dwarf2_cu
*
2554 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2556 bfd
*abfd
= objfile
->obfd
;
2557 struct dwarf2_cu
*cu
;
2558 unsigned long offset
;
2560 struct cleanup
*back_to
, *free_cu_cleanup
;
2561 struct attribute
*attr
;
2564 /* Set local variables from the partial symbol table info. */
2565 offset
= per_cu
->offset
;
2567 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2569 cu
= xmalloc (sizeof (struct dwarf2_cu
));
2570 memset (cu
, 0, sizeof (struct dwarf2_cu
));
2572 /* If an error occurs while loading, release our storage. */
2573 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
2575 cu
->objfile
= objfile
;
2577 /* read in the comp_unit header */
2578 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
2580 /* Read the abbrevs for this compilation unit */
2581 dwarf2_read_abbrevs (abfd
, cu
);
2582 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2584 cu
->header
.offset
= offset
;
2586 cu
->per_cu
= per_cu
;
2588 cu
->type_hash
= per_cu
->type_hash
;
2590 /* We use this obstack for block values in dwarf_alloc_block. */
2591 obstack_init (&cu
->comp_unit_obstack
);
2593 cu
->dies
= read_comp_unit (info_ptr
, abfd
, cu
);
2595 /* We try not to read any attributes in this function, because not
2596 all objfiles needed for references have been loaded yet, and symbol
2597 table processing isn't initialized. But we have to set the CU language,
2598 or we won't be able to build types correctly. */
2599 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
2601 set_cu_language (DW_UNSND (attr
), cu
);
2603 set_cu_language (language_minimal
, cu
);
2605 do_cleanups (back_to
);
2607 /* We've successfully allocated this compilation unit. Let our caller
2608 clean it up when finished with it. */
2609 discard_cleanups (free_cu_cleanup
);
2614 /* Generate full symbol information for PST and CU, whose DIEs have
2615 already been loaded into memory. */
2618 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2620 struct partial_symtab
*pst
= per_cu
->psymtab
;
2621 struct dwarf2_cu
*cu
= per_cu
->cu
;
2622 struct objfile
*objfile
= pst
->objfile
;
2623 bfd
*abfd
= objfile
->obfd
;
2624 CORE_ADDR lowpc
, highpc
;
2625 struct symtab
*symtab
;
2626 struct cleanup
*back_to
;
2627 struct attribute
*attr
;
2630 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2632 /* We're in the global namespace. */
2633 processing_current_prefix
= "";
2636 back_to
= make_cleanup (really_free_pendings
, NULL
);
2638 cu
->list_in_scope
= &file_symbols
;
2640 /* Find the base address of the compilation unit for range lists and
2641 location lists. It will normally be specified by DW_AT_low_pc.
2642 In DWARF-3 draft 4, the base address could be overridden by
2643 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2644 compilation units with discontinuous ranges. */
2646 cu
->header
.base_known
= 0;
2647 cu
->header
.base_address
= 0;
2649 attr
= dwarf2_attr (cu
->dies
, DW_AT_entry_pc
, cu
);
2652 cu
->header
.base_address
= DW_ADDR (attr
);
2653 cu
->header
.base_known
= 1;
2657 attr
= dwarf2_attr (cu
->dies
, DW_AT_low_pc
, cu
);
2660 cu
->header
.base_address
= DW_ADDR (attr
);
2661 cu
->header
.base_known
= 1;
2665 /* Do line number decoding in read_file_scope () */
2666 process_die (cu
->dies
, cu
);
2668 /* Some compilers don't define a DW_AT_high_pc attribute for the
2669 compilation unit. If the DW_AT_high_pc is missing, synthesize
2670 it, by scanning the DIE's below the compilation unit. */
2671 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
2673 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2675 /* Set symtab language to language from DW_AT_language.
2676 If the compilation is from a C file generated by language preprocessors,
2677 do not set the language if it was already deduced by start_subfile. */
2679 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
2681 symtab
->language
= cu
->language
;
2683 pst
->symtab
= symtab
;
2686 do_cleanups (back_to
);
2689 /* Process a die and its children. */
2692 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2696 case DW_TAG_padding
:
2698 case DW_TAG_compile_unit
:
2699 read_file_scope (die
, cu
);
2701 case DW_TAG_subprogram
:
2702 read_func_scope (die
, cu
);
2704 case DW_TAG_inlined_subroutine
:
2705 /* FIXME: These are ignored for now.
2706 They could be used to set breakpoints on all inlined instances
2707 of a function and make GDB `next' properly over inlined functions. */
2709 case DW_TAG_lexical_block
:
2710 case DW_TAG_try_block
:
2711 case DW_TAG_catch_block
:
2712 read_lexical_block_scope (die
, cu
);
2714 case DW_TAG_class_type
:
2715 case DW_TAG_interface_type
:
2716 case DW_TAG_structure_type
:
2717 case DW_TAG_union_type
:
2718 process_structure_scope (die
, cu
);
2720 case DW_TAG_enumeration_type
:
2721 process_enumeration_scope (die
, cu
);
2724 /* These dies have a type, but processing them does not create
2725 a symbol or recurse to process the children. Therefore we can
2726 read them on-demand through read_type_die. */
2727 case DW_TAG_subroutine_type
:
2728 case DW_TAG_set_type
:
2729 case DW_TAG_array_type
:
2730 case DW_TAG_pointer_type
:
2731 case DW_TAG_ptr_to_member_type
:
2732 case DW_TAG_reference_type
:
2733 case DW_TAG_string_type
:
2736 case DW_TAG_base_type
:
2737 case DW_TAG_subrange_type
:
2738 /* Add a typedef symbol for the type definition, if it has a
2740 new_symbol (die
, read_type_die (die
, cu
), cu
);
2742 case DW_TAG_common_block
:
2743 read_common_block (die
, cu
);
2745 case DW_TAG_common_inclusion
:
2747 case DW_TAG_namespace
:
2748 processing_has_namespace_info
= 1;
2749 read_namespace (die
, cu
);
2751 case DW_TAG_imported_declaration
:
2752 case DW_TAG_imported_module
:
2753 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2754 information contained in these. DW_TAG_imported_declaration
2755 dies shouldn't have children; DW_TAG_imported_module dies
2756 shouldn't in the C++ case, but conceivably could in the
2757 Fortran case, so we'll have to replace this gdb_assert if
2758 Fortran compilers start generating that info. */
2759 processing_has_namespace_info
= 1;
2760 gdb_assert (die
->child
== NULL
);
2763 new_symbol (die
, NULL
, cu
);
2769 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2771 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2775 free_cu_line_header (void *arg
)
2777 struct dwarf2_cu
*cu
= arg
;
2779 free_line_header (cu
->line_header
);
2780 cu
->line_header
= NULL
;
2784 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2786 struct objfile
*objfile
= cu
->objfile
;
2787 struct comp_unit_head
*cu_header
= &cu
->header
;
2788 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2789 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2790 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2791 struct attribute
*attr
;
2793 char *comp_dir
= NULL
;
2794 struct die_info
*child_die
;
2795 bfd
*abfd
= objfile
->obfd
;
2796 struct line_header
*line_header
= 0;
2799 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2801 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2803 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2804 from finish_block. */
2805 if (lowpc
== ((CORE_ADDR
) -1))
2810 /* Find the filename. Do not use dwarf2_name here, since the filename
2811 is not a source language identifier. */
2812 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2815 name
= DW_STRING (attr
);
2818 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2820 comp_dir
= DW_STRING (attr
);
2821 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
2823 comp_dir
= ldirname (name
);
2824 if (comp_dir
!= NULL
)
2825 make_cleanup (xfree
, comp_dir
);
2827 if (comp_dir
!= NULL
)
2829 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2830 directory, get rid of it. */
2831 char *cp
= strchr (comp_dir
, ':');
2833 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2840 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2843 set_cu_language (DW_UNSND (attr
), cu
);
2846 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
2848 cu
->producer
= DW_STRING (attr
);
2850 /* We assume that we're processing GCC output. */
2851 processing_gcc_compilation
= 2;
2853 start_symtab (name
, comp_dir
, lowpc
);
2854 record_debugformat ("DWARF 2");
2855 record_producer (cu
->producer
);
2857 initialize_cu_func_list (cu
);
2859 /* Decode line number information if present. We do this before
2860 processing child DIEs, so that the line header table is available
2861 for DW_AT_decl_file. */
2862 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2865 unsigned int line_offset
= DW_UNSND (attr
);
2866 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2869 cu
->line_header
= line_header
;
2870 make_cleanup (free_cu_line_header
, cu
);
2871 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
2875 /* Process all dies in compilation unit. */
2876 if (die
->child
!= NULL
)
2878 child_die
= die
->child
;
2879 while (child_die
&& child_die
->tag
)
2881 process_die (child_die
, cu
);
2882 child_die
= sibling_die (child_die
);
2886 /* Decode macro information, if present. Dwarf 2 macro information
2887 refers to information in the line number info statement program
2888 header, so we can only read it if we've read the header
2890 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2891 if (attr
&& line_header
)
2893 unsigned int macro_offset
= DW_UNSND (attr
);
2894 dwarf_decode_macros (line_header
, macro_offset
,
2895 comp_dir
, abfd
, cu
);
2897 do_cleanups (back_to
);
2901 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2902 struct dwarf2_cu
*cu
)
2904 struct function_range
*thisfn
;
2906 thisfn
= (struct function_range
*)
2907 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
2908 thisfn
->name
= name
;
2909 thisfn
->lowpc
= lowpc
;
2910 thisfn
->highpc
= highpc
;
2911 thisfn
->seen_line
= 0;
2912 thisfn
->next
= NULL
;
2914 if (cu
->last_fn
== NULL
)
2915 cu
->first_fn
= thisfn
;
2917 cu
->last_fn
->next
= thisfn
;
2919 cu
->last_fn
= thisfn
;
2923 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2925 struct objfile
*objfile
= cu
->objfile
;
2926 struct context_stack
*new;
2929 struct die_info
*child_die
;
2930 struct attribute
*attr
;
2932 const char *previous_prefix
= processing_current_prefix
;
2933 struct cleanup
*back_to
= NULL
;
2935 struct block
*block
;
2937 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2939 name
= dwarf2_linkage_name (die
, cu
);
2941 /* Ignore functions with missing or empty names and functions with
2942 missing or invalid low and high pc attributes. */
2943 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2946 if (cu
->language
== language_cplus
2947 || cu
->language
== language_java
)
2949 struct die_info
*spec_die
= die_specification (die
, cu
);
2951 /* NOTE: carlton/2004-01-23: We have to be careful in the
2952 presence of DW_AT_specification. For example, with GCC 3.4,
2957 // Definition of N::foo.
2961 then we'll have a tree of DIEs like this:
2963 1: DW_TAG_compile_unit
2964 2: DW_TAG_namespace // N
2965 3: DW_TAG_subprogram // declaration of N::foo
2966 4: DW_TAG_subprogram // definition of N::foo
2967 DW_AT_specification // refers to die #3
2969 Thus, when processing die #4, we have to pretend that we're
2970 in the context of its DW_AT_specification, namely the contex
2973 if (spec_die
!= NULL
)
2975 char *specification_prefix
= determine_prefix (spec_die
, cu
);
2976 processing_current_prefix
= specification_prefix
;
2977 back_to
= make_cleanup (xfree
, specification_prefix
);
2984 /* Record the function range for dwarf_decode_lines. */
2985 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
2987 new = push_context (0, lowpc
);
2988 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
2990 /* If there is a location expression for DW_AT_frame_base, record
2992 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
2994 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
2995 expression is being recorded directly in the function's symbol
2996 and not in a separate frame-base object. I guess this hack is
2997 to avoid adding some sort of frame-base adjunct/annex to the
2998 function's symbol :-(. The problem with doing this is that it
2999 results in a function symbol with a location expression that
3000 has nothing to do with the location of the function, ouch! The
3001 relationship should be: a function's symbol has-a frame base; a
3002 frame-base has-a location expression. */
3003 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3005 cu
->list_in_scope
= &local_symbols
;
3007 if (die
->child
!= NULL
)
3009 child_die
= die
->child
;
3010 while (child_die
&& child_die
->tag
)
3012 process_die (child_die
, cu
);
3013 child_die
= sibling_die (child_die
);
3017 new = pop_context ();
3018 /* Make a block for the local symbols within. */
3019 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3020 lowpc
, highpc
, objfile
);
3022 /* If we have address ranges, record them. */
3023 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3025 /* In C++, we can have functions nested inside functions (e.g., when
3026 a function declares a class that has methods). This means that
3027 when we finish processing a function scope, we may need to go
3028 back to building a containing block's symbol lists. */
3029 local_symbols
= new->locals
;
3030 param_symbols
= new->params
;
3032 /* If we've finished processing a top-level function, subsequent
3033 symbols go in the file symbol list. */
3034 if (outermost_context_p ())
3035 cu
->list_in_scope
= &file_symbols
;
3037 processing_current_prefix
= previous_prefix
;
3038 if (back_to
!= NULL
)
3039 do_cleanups (back_to
);
3042 /* Process all the DIES contained within a lexical block scope. Start
3043 a new scope, process the dies, and then close the scope. */
3046 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3048 struct objfile
*objfile
= cu
->objfile
;
3049 struct context_stack
*new;
3050 CORE_ADDR lowpc
, highpc
;
3051 struct die_info
*child_die
;
3054 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3056 /* Ignore blocks with missing or invalid low and high pc attributes. */
3057 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3058 as multiple lexical blocks? Handling children in a sane way would
3059 be nasty. Might be easier to properly extend generic blocks to
3061 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3066 push_context (0, lowpc
);
3067 if (die
->child
!= NULL
)
3069 child_die
= die
->child
;
3070 while (child_die
&& child_die
->tag
)
3072 process_die (child_die
, cu
);
3073 child_die
= sibling_die (child_die
);
3076 new = pop_context ();
3078 if (local_symbols
!= NULL
)
3081 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3084 /* Note that recording ranges after traversing children, as we
3085 do here, means that recording a parent's ranges entails
3086 walking across all its children's ranges as they appear in
3087 the address map, which is quadratic behavior.
3089 It would be nicer to record the parent's ranges before
3090 traversing its children, simply overriding whatever you find
3091 there. But since we don't even decide whether to create a
3092 block until after we've traversed its children, that's hard
3094 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3096 local_symbols
= new->locals
;
3099 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3100 Return 1 if the attributes are present and valid, otherwise, return 0.
3101 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3104 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
3105 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
3106 struct partial_symtab
*ranges_pst
)
3108 struct objfile
*objfile
= cu
->objfile
;
3109 struct comp_unit_head
*cu_header
= &cu
->header
;
3110 bfd
*obfd
= objfile
->obfd
;
3111 unsigned int addr_size
= cu_header
->addr_size
;
3112 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3113 /* Base address selection entry. */
3124 found_base
= cu_header
->base_known
;
3125 base
= cu_header
->base_address
;
3127 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3129 complaint (&symfile_complaints
,
3130 _("Offset %d out of bounds for DW_AT_ranges attribute"),
3134 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3136 /* Read in the largest possible address. */
3137 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
3138 if ((marker
& mask
) == mask
)
3140 /* If we found the largest possible address, then
3141 read the base address. */
3142 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3143 buffer
+= 2 * addr_size
;
3144 offset
+= 2 * addr_size
;
3150 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3154 CORE_ADDR range_beginning
, range_end
;
3156 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
3157 buffer
+= addr_size
;
3158 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
3159 buffer
+= addr_size
;
3160 offset
+= 2 * addr_size
;
3162 /* An end of list marker is a pair of zero addresses. */
3163 if (range_beginning
== 0 && range_end
== 0)
3164 /* Found the end of list entry. */
3167 /* Each base address selection entry is a pair of 2 values.
3168 The first is the largest possible address, the second is
3169 the base address. Check for a base address here. */
3170 if ((range_beginning
& mask
) == mask
)
3172 /* If we found the largest possible address, then
3173 read the base address. */
3174 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3181 /* We have no valid base address for the ranges
3183 complaint (&symfile_complaints
,
3184 _("Invalid .debug_ranges data (no base address)"));
3188 range_beginning
+= base
;
3191 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
3192 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3193 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
3196 /* FIXME: This is recording everything as a low-high
3197 segment of consecutive addresses. We should have a
3198 data structure for discontiguous block ranges
3202 low
= range_beginning
;
3208 if (range_beginning
< low
)
3209 low
= range_beginning
;
3210 if (range_end
> high
)
3216 /* If the first entry is an end-of-list marker, the range
3217 describes an empty scope, i.e. no instructions. */
3223 *high_return
= high
;
3227 /* Get low and high pc attributes from a die. Return 1 if the attributes
3228 are present and valid, otherwise, return 0. Return -1 if the range is
3229 discontinuous, i.e. derived from DW_AT_ranges information. */
3231 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
3232 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
3234 struct attribute
*attr
;
3239 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3242 high
= DW_ADDR (attr
);
3243 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3245 low
= DW_ADDR (attr
);
3247 /* Found high w/o low attribute. */
3250 /* Found consecutive range of addresses. */
3255 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3258 /* Value of the DW_AT_ranges attribute is the offset in the
3259 .debug_ranges section. */
3260 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, NULL
))
3262 /* Found discontinuous range of addresses. */
3270 /* When using the GNU linker, .gnu.linkonce. sections are used to
3271 eliminate duplicate copies of functions and vtables and such.
3272 The linker will arbitrarily choose one and discard the others.
3273 The AT_*_pc values for such functions refer to local labels in
3274 these sections. If the section from that file was discarded, the
3275 labels are not in the output, so the relocs get a value of 0.
3276 If this is a discarded function, mark the pc bounds as invalid,
3277 so that GDB will ignore it. */
3278 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3286 /* Get the low and high pc's represented by the scope DIE, and store
3287 them in *LOWPC and *HIGHPC. If the correct values can't be
3288 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3291 get_scope_pc_bounds (struct die_info
*die
,
3292 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3293 struct dwarf2_cu
*cu
)
3295 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3296 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3297 CORE_ADDR current_low
, current_high
;
3299 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3301 best_low
= current_low
;
3302 best_high
= current_high
;
3306 struct die_info
*child
= die
->child
;
3308 while (child
&& child
->tag
)
3310 switch (child
->tag
) {
3311 case DW_TAG_subprogram
:
3312 if (dwarf2_get_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
))
3314 best_low
= min (best_low
, current_low
);
3315 best_high
= max (best_high
, current_high
);
3318 case DW_TAG_namespace
:
3319 /* FIXME: carlton/2004-01-16: Should we do this for
3320 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3321 that current GCC's always emit the DIEs corresponding
3322 to definitions of methods of classes as children of a
3323 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3324 the DIEs giving the declarations, which could be
3325 anywhere). But I don't see any reason why the
3326 standards says that they have to be there. */
3327 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3329 if (current_low
!= ((CORE_ADDR
) -1))
3331 best_low
= min (best_low
, current_low
);
3332 best_high
= max (best_high
, current_high
);
3340 child
= sibling_die (child
);
3345 *highpc
= best_high
;
3348 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
3351 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
3352 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
3354 struct attribute
*attr
;
3356 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3359 CORE_ADDR high
= DW_ADDR (attr
);
3360 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3363 CORE_ADDR low
= DW_ADDR (attr
);
3364 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
3368 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3371 bfd
*obfd
= cu
->objfile
->obfd
;
3373 /* The value of the DW_AT_ranges attribute is the offset of the
3374 address range list in the .debug_ranges section. */
3375 unsigned long offset
= DW_UNSND (attr
);
3376 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3378 /* For some target architectures, but not others, the
3379 read_address function sign-extends the addresses it returns.
3380 To recognize base address selection entries, we need a
3382 unsigned int addr_size
= cu
->header
.addr_size
;
3383 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3385 /* The base address, to which the next pair is relative. Note
3386 that this 'base' is a DWARF concept: most entries in a range
3387 list are relative, to reduce the number of relocs against the
3388 debugging information. This is separate from this function's
3389 'baseaddr' argument, which GDB uses to relocate debugging
3390 information from a shared library based on the address at
3391 which the library was loaded. */
3392 CORE_ADDR base
= cu
->header
.base_address
;
3393 int base_known
= cu
->header
.base_known
;
3395 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3397 complaint (&symfile_complaints
,
3398 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
3405 unsigned int bytes_read
;
3406 CORE_ADDR start
, end
;
3408 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3409 buffer
+= bytes_read
;
3410 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3411 buffer
+= bytes_read
;
3413 /* Did we find the end of the range list? */
3414 if (start
== 0 && end
== 0)
3417 /* Did we find a base address selection entry? */
3418 else if ((start
& base_select_mask
) == base_select_mask
)
3424 /* We found an ordinary address range. */
3429 complaint (&symfile_complaints
,
3430 _("Invalid .debug_ranges data (no base address)"));
3434 record_block_range (block
,
3435 baseaddr
+ base
+ start
,
3436 baseaddr
+ base
+ end
- 1);
3442 /* Add an aggregate field to the field list. */
3445 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3446 struct dwarf2_cu
*cu
)
3448 struct objfile
*objfile
= cu
->objfile
;
3449 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3450 struct nextfield
*new_field
;
3451 struct attribute
*attr
;
3453 char *fieldname
= "";
3455 /* Allocate a new field list entry and link it in. */
3456 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3457 make_cleanup (xfree
, new_field
);
3458 memset (new_field
, 0, sizeof (struct nextfield
));
3459 new_field
->next
= fip
->fields
;
3460 fip
->fields
= new_field
;
3463 /* Handle accessibility and virtuality of field.
3464 The default accessibility for members is public, the default
3465 accessibility for inheritance is private. */
3466 if (die
->tag
!= DW_TAG_inheritance
)
3467 new_field
->accessibility
= DW_ACCESS_public
;
3469 new_field
->accessibility
= DW_ACCESS_private
;
3470 new_field
->virtuality
= DW_VIRTUALITY_none
;
3472 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3474 new_field
->accessibility
= DW_UNSND (attr
);
3475 if (new_field
->accessibility
!= DW_ACCESS_public
)
3476 fip
->non_public_fields
= 1;
3477 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3479 new_field
->virtuality
= DW_UNSND (attr
);
3481 fp
= &new_field
->field
;
3483 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3485 /* Data member other than a C++ static data member. */
3487 /* Get type of field. */
3488 fp
->type
= die_type (die
, cu
);
3490 FIELD_STATIC_KIND (*fp
) = 0;
3492 /* Get bit size of field (zero if none). */
3493 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3496 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3500 FIELD_BITSIZE (*fp
) = 0;
3503 /* Get bit offset of field. */
3504 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3509 if (attr_form_is_section_offset (attr
))
3511 dwarf2_complex_location_expr_complaint ();
3514 else if (attr_form_is_constant (attr
))
3515 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
3517 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
3519 FIELD_BITPOS (*fp
) = byte_offset
* bits_per_byte
;
3522 FIELD_BITPOS (*fp
) = 0;
3523 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3526 if (gdbarch_bits_big_endian (gdbarch
))
3528 /* For big endian bits, the DW_AT_bit_offset gives the
3529 additional bit offset from the MSB of the containing
3530 anonymous object to the MSB of the field. We don't
3531 have to do anything special since we don't need to
3532 know the size of the anonymous object. */
3533 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3537 /* For little endian bits, compute the bit offset to the
3538 MSB of the anonymous object, subtract off the number of
3539 bits from the MSB of the field to the MSB of the
3540 object, and then subtract off the number of bits of
3541 the field itself. The result is the bit offset of
3542 the LSB of the field. */
3544 int bit_offset
= DW_UNSND (attr
);
3546 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3549 /* The size of the anonymous object containing
3550 the bit field is explicit, so use the
3551 indicated size (in bytes). */
3552 anonymous_size
= DW_UNSND (attr
);
3556 /* The size of the anonymous object containing
3557 the bit field must be inferred from the type
3558 attribute of the data member containing the
3560 anonymous_size
= TYPE_LENGTH (fp
->type
);
3562 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
3563 - bit_offset
- FIELD_BITSIZE (*fp
);
3567 /* Get name of field. */
3568 fieldname
= dwarf2_name (die
, cu
);
3569 if (fieldname
== NULL
)
3572 /* The name is already allocated along with this objfile, so we don't
3573 need to duplicate it for the type. */
3574 fp
->name
= fieldname
;
3576 /* Change accessibility for artificial fields (e.g. virtual table
3577 pointer or virtual base class pointer) to private. */
3578 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
3580 new_field
->accessibility
= DW_ACCESS_private
;
3581 fip
->non_public_fields
= 1;
3584 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
3586 /* C++ static member. */
3588 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3589 is a declaration, but all versions of G++ as of this writing
3590 (so through at least 3.2.1) incorrectly generate
3591 DW_TAG_variable tags. */
3595 /* Get name of field. */
3596 fieldname
= dwarf2_name (die
, cu
);
3597 if (fieldname
== NULL
)
3600 /* Get physical name. */
3601 physname
= dwarf2_linkage_name (die
, cu
);
3603 /* The name is already allocated along with this objfile, so we don't
3604 need to duplicate it for the type. */
3605 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
3606 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3607 FIELD_NAME (*fp
) = fieldname
;
3609 else if (die
->tag
== DW_TAG_inheritance
)
3611 /* C++ base class field. */
3612 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3614 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
3616 FIELD_BITSIZE (*fp
) = 0;
3617 FIELD_STATIC_KIND (*fp
) = 0;
3618 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3619 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
3620 fip
->nbaseclasses
++;
3624 /* Create the vector of fields, and attach it to the type. */
3627 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3628 struct dwarf2_cu
*cu
)
3630 int nfields
= fip
->nfields
;
3632 /* Record the field count, allocate space for the array of fields,
3633 and create blank accessibility bitfields if necessary. */
3634 TYPE_NFIELDS (type
) = nfields
;
3635 TYPE_FIELDS (type
) = (struct field
*)
3636 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3637 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3639 if (fip
->non_public_fields
)
3641 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3643 TYPE_FIELD_PRIVATE_BITS (type
) =
3644 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3645 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3647 TYPE_FIELD_PROTECTED_BITS (type
) =
3648 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3649 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3651 TYPE_FIELD_IGNORE_BITS (type
) =
3652 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3653 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3656 /* If the type has baseclasses, allocate and clear a bit vector for
3657 TYPE_FIELD_VIRTUAL_BITS. */
3658 if (fip
->nbaseclasses
)
3660 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3661 unsigned char *pointer
;
3663 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3664 pointer
= TYPE_ALLOC (type
, num_bytes
);
3665 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
3666 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3667 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3670 /* Copy the saved-up fields into the field vector. Start from the head
3671 of the list, adding to the tail of the field array, so that they end
3672 up in the same order in the array in which they were added to the list. */
3673 while (nfields
-- > 0)
3675 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3676 switch (fip
->fields
->accessibility
)
3678 case DW_ACCESS_private
:
3679 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3682 case DW_ACCESS_protected
:
3683 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3686 case DW_ACCESS_public
:
3690 /* Unknown accessibility. Complain and treat it as public. */
3692 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
3693 fip
->fields
->accessibility
);
3697 if (nfields
< fip
->nbaseclasses
)
3699 switch (fip
->fields
->virtuality
)
3701 case DW_VIRTUALITY_virtual
:
3702 case DW_VIRTUALITY_pure_virtual
:
3703 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3707 fip
->fields
= fip
->fields
->next
;
3711 /* Add a member function to the proper fieldlist. */
3714 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3715 struct type
*type
, struct dwarf2_cu
*cu
)
3717 struct objfile
*objfile
= cu
->objfile
;
3718 struct attribute
*attr
;
3719 struct fnfieldlist
*flp
;
3721 struct fn_field
*fnp
;
3724 struct nextfnfield
*new_fnfield
;
3725 struct type
*this_type
;
3727 /* Get name of member function. */
3728 fieldname
= dwarf2_name (die
, cu
);
3729 if (fieldname
== NULL
)
3732 /* Get the mangled name. */
3733 physname
= dwarf2_linkage_name (die
, cu
);
3735 /* Look up member function name in fieldlist. */
3736 for (i
= 0; i
< fip
->nfnfields
; i
++)
3738 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3742 /* Create new list element if necessary. */
3743 if (i
< fip
->nfnfields
)
3744 flp
= &fip
->fnfieldlists
[i
];
3747 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3749 fip
->fnfieldlists
= (struct fnfieldlist
*)
3750 xrealloc (fip
->fnfieldlists
,
3751 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3752 * sizeof (struct fnfieldlist
));
3753 if (fip
->nfnfields
== 0)
3754 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3756 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3757 flp
->name
= fieldname
;
3763 /* Create a new member function field and chain it to the field list
3765 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3766 make_cleanup (xfree
, new_fnfield
);
3767 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3768 new_fnfield
->next
= flp
->head
;
3769 flp
->head
= new_fnfield
;
3772 /* Fill in the member function field info. */
3773 fnp
= &new_fnfield
->fnfield
;
3774 /* The name is already allocated along with this objfile, so we don't
3775 need to duplicate it for the type. */
3776 fnp
->physname
= physname
? physname
: "";
3777 fnp
->type
= alloc_type (objfile
);
3778 this_type
= read_type_die (die
, cu
);
3779 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
3781 int nparams
= TYPE_NFIELDS (this_type
);
3783 /* TYPE is the domain of this method, and THIS_TYPE is the type
3784 of the method itself (TYPE_CODE_METHOD). */
3785 smash_to_method_type (fnp
->type
, type
,
3786 TYPE_TARGET_TYPE (this_type
),
3787 TYPE_FIELDS (this_type
),
3788 TYPE_NFIELDS (this_type
),
3789 TYPE_VARARGS (this_type
));
3791 /* Handle static member functions.
3792 Dwarf2 has no clean way to discern C++ static and non-static
3793 member functions. G++ helps GDB by marking the first
3794 parameter for non-static member functions (which is the
3795 this pointer) as artificial. We obtain this information
3796 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3797 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
3798 fnp
->voffset
= VOFFSET_STATIC
;
3801 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
3804 /* Get fcontext from DW_AT_containing_type if present. */
3805 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3806 fnp
->fcontext
= die_containing_type (die
, cu
);
3808 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3809 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3811 /* Get accessibility. */
3812 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3815 switch (DW_UNSND (attr
))
3817 case DW_ACCESS_private
:
3818 fnp
->is_private
= 1;
3820 case DW_ACCESS_protected
:
3821 fnp
->is_protected
= 1;
3826 /* Check for artificial methods. */
3827 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3828 if (attr
&& DW_UNSND (attr
) != 0)
3829 fnp
->is_artificial
= 1;
3831 /* Get index in virtual function table if it is a virtual member function. */
3832 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3835 /* Support the .debug_loc offsets */
3836 if (attr_form_is_block (attr
))
3838 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3840 else if (attr_form_is_section_offset (attr
))
3842 dwarf2_complex_location_expr_complaint ();
3846 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3852 /* Create the vector of member function fields, and attach it to the type. */
3855 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3856 struct dwarf2_cu
*cu
)
3858 struct fnfieldlist
*flp
;
3859 int total_length
= 0;
3862 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3863 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3864 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3866 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3868 struct nextfnfield
*nfp
= flp
->head
;
3869 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3872 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3873 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3874 fn_flp
->fn_fields
= (struct fn_field
*)
3875 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3876 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3877 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3879 total_length
+= flp
->length
;
3882 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3883 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3886 /* Returns non-zero if NAME is the name of a vtable member in CU's
3887 language, zero otherwise. */
3889 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
3891 static const char vptr
[] = "_vptr";
3892 static const char vtable
[] = "vtable";
3894 /* Look for the C++ and Java forms of the vtable. */
3895 if ((cu
->language
== language_java
3896 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
3897 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
3898 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
3904 /* GCC outputs unnamed structures that are really pointers to member
3905 functions, with the ABI-specified layout. If DIE (from CU) describes
3906 such a structure, set its type, and return nonzero. Otherwise return
3909 GCC shouldn't do this; it should just output pointer to member DIEs.
3910 This is GCC PR debug/28767. */
3912 static struct type
*
3913 quirk_gcc_member_function_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
)
3915 struct objfile
*objfile
= cu
->objfile
;
3917 struct die_info
*pfn_die
, *delta_die
;
3918 struct attribute
*pfn_name
, *delta_name
;
3919 struct type
*pfn_type
, *domain_type
;
3921 /* Check for a structure with no name and two children. */
3922 if (die
->tag
!= DW_TAG_structure_type
3923 || dwarf2_attr (die
, DW_AT_name
, cu
) != NULL
3924 || die
->child
== NULL
3925 || die
->child
->sibling
== NULL
3926 || (die
->child
->sibling
->sibling
!= NULL
3927 && die
->child
->sibling
->sibling
->tag
!= DW_TAG_padding
))
3930 /* Check for __pfn and __delta members. */
3931 pfn_die
= die
->child
;
3932 pfn_name
= dwarf2_attr (pfn_die
, DW_AT_name
, cu
);
3933 if (pfn_die
->tag
!= DW_TAG_member
3935 || DW_STRING (pfn_name
) == NULL
3936 || strcmp ("__pfn", DW_STRING (pfn_name
)) != 0)
3939 delta_die
= pfn_die
->sibling
;
3940 delta_name
= dwarf2_attr (delta_die
, DW_AT_name
, cu
);
3941 if (delta_die
->tag
!= DW_TAG_member
3942 || delta_name
== NULL
3943 || DW_STRING (delta_name
) == NULL
3944 || strcmp ("__delta", DW_STRING (delta_name
)) != 0)
3947 /* Find the type of the method. */
3948 pfn_type
= die_type (pfn_die
, cu
);
3949 if (pfn_type
== NULL
3950 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
3951 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
3954 /* Look for the "this" argument. */
3955 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
3956 if (TYPE_NFIELDS (pfn_type
) == 0
3957 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
3960 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
3961 type
= alloc_type (objfile
);
3962 smash_to_method_type (type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
3963 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
3964 TYPE_VARARGS (pfn_type
));
3965 type
= lookup_methodptr_type (type
);
3966 return set_die_type (die
, type
, cu
);
3969 /* Called when we find the DIE that starts a structure or union scope
3970 (definition) to process all dies that define the members of the
3973 NOTE: we need to call struct_type regardless of whether or not the
3974 DIE has an at_name attribute, since it might be an anonymous
3975 structure or union. This gets the type entered into our set of
3978 However, if the structure is incomplete (an opaque struct/union)
3979 then suppress creating a symbol table entry for it since gdb only
3980 wants to find the one with the complete definition. Note that if
3981 it is complete, we just call new_symbol, which does it's own
3982 checking about whether the struct/union is anonymous or not (and
3983 suppresses creating a symbol table entry itself). */
3985 static struct type
*
3986 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3988 struct objfile
*objfile
= cu
->objfile
;
3990 struct attribute
*attr
;
3991 const char *previous_prefix
= processing_current_prefix
;
3992 struct cleanup
*back_to
= NULL
;
3995 type
= quirk_gcc_member_function_pointer (die
, cu
);
3999 type
= alloc_type (objfile
);
4000 INIT_CPLUS_SPECIFIC (type
);
4001 name
= dwarf2_name (die
, cu
);
4004 if (cu
->language
== language_cplus
4005 || cu
->language
== language_java
)
4007 char *new_prefix
= determine_class_name (die
, cu
);
4008 TYPE_TAG_NAME (type
) = obsavestring (new_prefix
,
4009 strlen (new_prefix
),
4010 &objfile
->objfile_obstack
);
4011 back_to
= make_cleanup (xfree
, new_prefix
);
4012 processing_current_prefix
= new_prefix
;
4016 /* The name is already allocated along with this objfile, so
4017 we don't need to duplicate it for the type. */
4018 TYPE_TAG_NAME (type
) = name
;
4022 if (die
->tag
== DW_TAG_structure_type
)
4024 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
4026 else if (die
->tag
== DW_TAG_union_type
)
4028 TYPE_CODE (type
) = TYPE_CODE_UNION
;
4032 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
4034 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
4037 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4040 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4044 TYPE_LENGTH (type
) = 0;
4047 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB_SUPPORTED
;
4048 if (die_is_declaration (die
, cu
))
4049 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
4051 /* We need to add the type field to the die immediately so we don't
4052 infinitely recurse when dealing with pointers to the structure
4053 type within the structure itself. */
4054 set_die_type (die
, type
, cu
);
4056 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
4058 struct field_info fi
;
4059 struct die_info
*child_die
;
4060 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
4062 memset (&fi
, 0, sizeof (struct field_info
));
4064 child_die
= die
->child
;
4066 while (child_die
&& child_die
->tag
)
4068 if (child_die
->tag
== DW_TAG_member
4069 || child_die
->tag
== DW_TAG_variable
)
4071 /* NOTE: carlton/2002-11-05: A C++ static data member
4072 should be a DW_TAG_member that is a declaration, but
4073 all versions of G++ as of this writing (so through at
4074 least 3.2.1) incorrectly generate DW_TAG_variable
4075 tags for them instead. */
4076 dwarf2_add_field (&fi
, child_die
, cu
);
4078 else if (child_die
->tag
== DW_TAG_subprogram
)
4080 /* C++ member function. */
4081 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
4083 else if (child_die
->tag
== DW_TAG_inheritance
)
4085 /* C++ base class field. */
4086 dwarf2_add_field (&fi
, child_die
, cu
);
4088 child_die
= sibling_die (child_die
);
4091 /* Attach fields and member functions to the type. */
4093 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
4096 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
4098 /* Get the type which refers to the base class (possibly this
4099 class itself) which contains the vtable pointer for the current
4100 class from the DW_AT_containing_type attribute. */
4102 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4104 struct type
*t
= die_containing_type (die
, cu
);
4106 TYPE_VPTR_BASETYPE (type
) = t
;
4111 /* Our own class provides vtbl ptr. */
4112 for (i
= TYPE_NFIELDS (t
) - 1;
4113 i
>= TYPE_N_BASECLASSES (t
);
4116 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
4118 if (is_vtable_name (fieldname
, cu
))
4120 TYPE_VPTR_FIELDNO (type
) = i
;
4125 /* Complain if virtual function table field not found. */
4126 if (i
< TYPE_N_BASECLASSES (t
))
4127 complaint (&symfile_complaints
,
4128 _("virtual function table pointer not found when defining class '%s'"),
4129 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
4134 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
4137 else if (cu
->producer
4138 && strncmp (cu
->producer
,
4139 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
4141 /* The IBM XLC compiler does not provide direct indication
4142 of the containing type, but the vtable pointer is
4143 always named __vfp. */
4147 for (i
= TYPE_NFIELDS (type
) - 1;
4148 i
>= TYPE_N_BASECLASSES (type
);
4151 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
4153 TYPE_VPTR_FIELDNO (type
) = i
;
4154 TYPE_VPTR_BASETYPE (type
) = type
;
4161 do_cleanups (back_to
);
4164 processing_current_prefix
= previous_prefix
;
4165 if (back_to
!= NULL
)
4166 do_cleanups (back_to
);
4172 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4174 struct objfile
*objfile
= cu
->objfile
;
4175 const char *previous_prefix
= processing_current_prefix
;
4176 struct die_info
*child_die
= die
->child
;
4177 struct type
*this_type
;
4179 this_type
= get_die_type (die
, cu
);
4180 if (this_type
== NULL
)
4181 this_type
= read_structure_type (die
, cu
);
4182 if (TYPE_TAG_NAME (this_type
) != NULL
)
4183 processing_current_prefix
= TYPE_TAG_NAME (this_type
);
4185 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
4186 snapshots) has been known to create a die giving a declaration
4187 for a class that has, as a child, a die giving a definition for a
4188 nested class. So we have to process our children even if the
4189 current die is a declaration. Normally, of course, a declaration
4190 won't have any children at all. */
4192 while (child_die
!= NULL
&& child_die
->tag
)
4194 if (child_die
->tag
== DW_TAG_member
4195 || child_die
->tag
== DW_TAG_variable
4196 || child_die
->tag
== DW_TAG_inheritance
)
4201 process_die (child_die
, cu
);
4203 child_die
= sibling_die (child_die
);
4206 /* Do not consider external references. According to the DWARF standard,
4207 these DIEs are identified by the fact that they have no byte_size
4208 attribute, and a declaration attribute. */
4209 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
4210 || !die_is_declaration (die
, cu
))
4211 new_symbol (die
, this_type
, cu
);
4213 processing_current_prefix
= previous_prefix
;
4216 /* Given a DW_AT_enumeration_type die, set its type. We do not
4217 complete the type's fields yet, or create any symbols. */
4219 static struct type
*
4220 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4222 struct objfile
*objfile
= cu
->objfile
;
4224 struct attribute
*attr
;
4227 type
= alloc_type (objfile
);
4229 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4230 name
= dwarf2_name (die
, cu
);
4233 if (processing_has_namespace_info
)
4235 TYPE_TAG_NAME (type
) = typename_concat (&objfile
->objfile_obstack
,
4236 processing_current_prefix
,
4241 /* The name is already allocated along with this objfile, so
4242 we don't need to duplicate it for the type. */
4243 TYPE_TAG_NAME (type
) = name
;
4247 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4250 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4254 TYPE_LENGTH (type
) = 0;
4257 /* The enumeration DIE can be incomplete. In Ada, any type can be
4258 declared as private in the package spec, and then defined only
4259 inside the package body. Such types are known as Taft Amendment
4260 Types. When another package uses such a type, an incomplete DIE
4261 may be generated by the compiler. */
4262 if (die_is_declaration (die
, cu
))
4263 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
4265 return set_die_type (die
, type
, cu
);
4268 /* Determine the name of the type represented by DIE, which should be
4269 a named C++ or Java compound type. Return the name in question; the caller
4270 is responsible for xfree()'ing it. */
4273 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
4275 struct cleanup
*back_to
= NULL
;
4276 struct die_info
*spec_die
= die_specification (die
, cu
);
4277 char *new_prefix
= NULL
;
4279 /* If this is the definition of a class that is declared by another
4280 die, then processing_current_prefix may not be accurate; see
4281 read_func_scope for a similar example. */
4282 if (spec_die
!= NULL
)
4284 char *specification_prefix
= determine_prefix (spec_die
, cu
);
4285 processing_current_prefix
= specification_prefix
;
4286 back_to
= make_cleanup (xfree
, specification_prefix
);
4289 /* If we don't have namespace debug info, guess the name by trying
4290 to demangle the names of members, just like we did in
4291 guess_structure_name. */
4292 if (!processing_has_namespace_info
)
4294 struct die_info
*child
;
4296 for (child
= die
->child
;
4297 child
!= NULL
&& child
->tag
!= 0;
4298 child
= sibling_die (child
))
4300 if (child
->tag
== DW_TAG_subprogram
)
4303 = language_class_name_from_physname (cu
->language_defn
,
4307 if (new_prefix
!= NULL
)
4313 if (new_prefix
== NULL
)
4315 const char *name
= dwarf2_name (die
, cu
);
4316 new_prefix
= typename_concat (NULL
, processing_current_prefix
,
4317 name
? name
: "<<anonymous>>",
4321 if (back_to
!= NULL
)
4322 do_cleanups (back_to
);
4327 /* Given a pointer to a die which begins an enumeration, process all
4328 the dies that define the members of the enumeration, and create the
4329 symbol for the enumeration type.
4331 NOTE: We reverse the order of the element list. */
4334 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4336 struct objfile
*objfile
= cu
->objfile
;
4337 struct die_info
*child_die
;
4338 struct field
*fields
;
4341 int unsigned_enum
= 1;
4343 struct type
*this_type
;
4347 this_type
= get_die_type (die
, cu
);
4348 if (this_type
== NULL
)
4349 this_type
= read_enumeration_type (die
, cu
);
4350 if (die
->child
!= NULL
)
4352 child_die
= die
->child
;
4353 while (child_die
&& child_die
->tag
)
4355 if (child_die
->tag
!= DW_TAG_enumerator
)
4357 process_die (child_die
, cu
);
4361 name
= dwarf2_name (child_die
, cu
);
4364 sym
= new_symbol (child_die
, this_type
, cu
);
4365 if (SYMBOL_VALUE (sym
) < 0)
4368 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4370 fields
= (struct field
*)
4372 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
4373 * sizeof (struct field
));
4376 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
4377 FIELD_TYPE (fields
[num_fields
]) = NULL
;
4378 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
4379 FIELD_BITSIZE (fields
[num_fields
]) = 0;
4380 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
4386 child_die
= sibling_die (child_die
);
4391 TYPE_NFIELDS (this_type
) = num_fields
;
4392 TYPE_FIELDS (this_type
) = (struct field
*)
4393 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
4394 memcpy (TYPE_FIELDS (this_type
), fields
,
4395 sizeof (struct field
) * num_fields
);
4399 TYPE_FLAGS (this_type
) |= TYPE_FLAG_UNSIGNED
;
4402 new_symbol (die
, this_type
, cu
);
4405 /* Extract all information from a DW_TAG_array_type DIE and put it in
4406 the DIE's type field. For now, this only handles one dimensional
4409 static struct type
*
4410 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4412 struct objfile
*objfile
= cu
->objfile
;
4413 struct die_info
*child_die
;
4414 struct type
*type
= NULL
;
4415 struct type
*element_type
, *range_type
, *index_type
;
4416 struct type
**range_types
= NULL
;
4417 struct attribute
*attr
;
4419 struct cleanup
*back_to
;
4422 element_type
= die_type (die
, cu
);
4424 /* Irix 6.2 native cc creates array types without children for
4425 arrays with unspecified length. */
4426 if (die
->child
== NULL
)
4428 index_type
= builtin_type_int32
;
4429 range_type
= create_range_type (NULL
, index_type
, 0, -1);
4430 type
= create_array_type (NULL
, element_type
, range_type
);
4431 return set_die_type (die
, type
, cu
);
4434 back_to
= make_cleanup (null_cleanup
, NULL
);
4435 child_die
= die
->child
;
4436 while (child_die
&& child_die
->tag
)
4438 if (child_die
->tag
== DW_TAG_subrange_type
)
4440 struct type
*child_type
= read_type_die (child_die
, cu
);
4441 if (child_type
!= NULL
)
4443 /* The range type was succesfully read. Save it for
4444 the array type creation. */
4445 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
4447 range_types
= (struct type
**)
4448 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
4449 * sizeof (struct type
*));
4451 make_cleanup (free_current_contents
, &range_types
);
4453 range_types
[ndim
++] = child_type
;
4456 child_die
= sibling_die (child_die
);
4459 /* Dwarf2 dimensions are output from left to right, create the
4460 necessary array types in backwards order. */
4462 type
= element_type
;
4464 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
4468 type
= create_array_type (NULL
, type
, range_types
[i
++]);
4473 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
4476 /* Understand Dwarf2 support for vector types (like they occur on
4477 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4478 array type. This is not part of the Dwarf2/3 standard yet, but a
4479 custom vendor extension. The main difference between a regular
4480 array and the vector variant is that vectors are passed by value
4482 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4484 make_vector_type (type
);
4486 name
= dwarf2_name (die
, cu
);
4488 TYPE_NAME (type
) = name
;
4490 do_cleanups (back_to
);
4492 /* Install the type in the die. */
4493 return set_die_type (die
, type
, cu
);
4496 static enum dwarf_array_dim_ordering
4497 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4499 struct attribute
*attr
;
4501 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4503 if (attr
) return DW_SND (attr
);
4506 GNU F77 is a special case, as at 08/2004 array type info is the
4507 opposite order to the dwarf2 specification, but data is still
4508 laid out as per normal fortran.
4510 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4514 if (cu
->language
== language_fortran
&&
4515 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4517 return DW_ORD_row_major
;
4520 switch (cu
->language_defn
->la_array_ordering
)
4522 case array_column_major
:
4523 return DW_ORD_col_major
;
4524 case array_row_major
:
4526 return DW_ORD_row_major
;
4530 /* Extract all information from a DW_TAG_set_type DIE and put it in
4531 the DIE's type field. */
4533 static struct type
*
4534 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4536 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
4538 return set_die_type (die
, set_type
, cu
);
4541 /* First cut: install each common block member as a global variable. */
4544 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4546 struct die_info
*child_die
;
4547 struct attribute
*attr
;
4549 CORE_ADDR base
= (CORE_ADDR
) 0;
4551 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4554 /* Support the .debug_loc offsets */
4555 if (attr_form_is_block (attr
))
4557 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4559 else if (attr_form_is_section_offset (attr
))
4561 dwarf2_complex_location_expr_complaint ();
4565 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4566 "common block member");
4569 if (die
->child
!= NULL
)
4571 child_die
= die
->child
;
4572 while (child_die
&& child_die
->tag
)
4574 sym
= new_symbol (child_die
, NULL
, cu
);
4575 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4578 SYMBOL_VALUE_ADDRESS (sym
) =
4579 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4580 add_symbol_to_list (sym
, &global_symbols
);
4582 child_die
= sibling_die (child_die
);
4587 /* Read a C++ namespace. */
4590 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4592 struct objfile
*objfile
= cu
->objfile
;
4593 const char *previous_prefix
= processing_current_prefix
;
4596 struct die_info
*current_die
;
4597 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4599 name
= namespace_name (die
, &is_anonymous
, cu
);
4601 /* Now build the name of the current namespace. */
4603 if (previous_prefix
[0] == '\0')
4605 processing_current_prefix
= name
;
4609 char *temp_name
= typename_concat (NULL
, previous_prefix
, name
, cu
);
4610 make_cleanup (xfree
, temp_name
);
4611 processing_current_prefix
= temp_name
;
4614 /* Add a symbol associated to this if we haven't seen the namespace
4615 before. Also, add a using directive if it's an anonymous
4618 if (dwarf2_extension (die
, cu
) == NULL
)
4622 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
4623 this cast will hopefully become unnecessary. */
4624 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
4625 (char *) processing_current_prefix
,
4627 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4629 new_symbol (die
, type
, cu
);
4630 set_die_type (die
, type
, cu
);
4633 cp_add_using_directive (processing_current_prefix
,
4634 strlen (previous_prefix
),
4635 strlen (processing_current_prefix
));
4638 if (die
->child
!= NULL
)
4640 struct die_info
*child_die
= die
->child
;
4642 while (child_die
&& child_die
->tag
)
4644 process_die (child_die
, cu
);
4645 child_die
= sibling_die (child_die
);
4649 processing_current_prefix
= previous_prefix
;
4650 do_cleanups (back_to
);
4653 /* Return the name of the namespace represented by DIE. Set
4654 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4658 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
4660 struct die_info
*current_die
;
4661 const char *name
= NULL
;
4663 /* Loop through the extensions until we find a name. */
4665 for (current_die
= die
;
4666 current_die
!= NULL
;
4667 current_die
= dwarf2_extension (die
, cu
))
4669 name
= dwarf2_name (current_die
, cu
);
4674 /* Is it an anonymous namespace? */
4676 *is_anonymous
= (name
== NULL
);
4678 name
= "(anonymous namespace)";
4683 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4684 the user defined type vector. */
4686 static struct type
*
4687 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4689 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
4690 struct comp_unit_head
*cu_header
= &cu
->header
;
4692 struct attribute
*attr_byte_size
;
4693 struct attribute
*attr_address_class
;
4694 int byte_size
, addr_class
;
4696 type
= lookup_pointer_type (die_type (die
, cu
));
4698 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4700 byte_size
= DW_UNSND (attr_byte_size
);
4702 byte_size
= cu_header
->addr_size
;
4704 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
4705 if (attr_address_class
)
4706 addr_class
= DW_UNSND (attr_address_class
);
4708 addr_class
= DW_ADDR_none
;
4710 /* If the pointer size or address class is different than the
4711 default, create a type variant marked as such and set the
4712 length accordingly. */
4713 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
4715 if (gdbarch_address_class_type_flags_p (gdbarch
))
4719 type_flags
= gdbarch_address_class_type_flags
4720 (gdbarch
, byte_size
, addr_class
);
4721 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
4722 type
= make_type_with_address_space (type
, type_flags
);
4724 else if (TYPE_LENGTH (type
) != byte_size
)
4726 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
4729 /* Should we also complain about unhandled address classes? */
4733 TYPE_LENGTH (type
) = byte_size
;
4734 return set_die_type (die
, type
, cu
);
4737 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4738 the user defined type vector. */
4740 static struct type
*
4741 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4743 struct objfile
*objfile
= cu
->objfile
;
4745 struct type
*to_type
;
4746 struct type
*domain
;
4748 to_type
= die_type (die
, cu
);
4749 domain
= die_containing_type (die
, cu
);
4751 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
4752 type
= lookup_methodptr_type (to_type
);
4754 type
= lookup_memberptr_type (to_type
, domain
);
4756 return set_die_type (die
, type
, cu
);
4759 /* Extract all information from a DW_TAG_reference_type DIE and add to
4760 the user defined type vector. */
4762 static struct type
*
4763 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4765 struct comp_unit_head
*cu_header
= &cu
->header
;
4767 struct attribute
*attr
;
4769 type
= lookup_reference_type (die_type (die
, cu
));
4770 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4773 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4777 TYPE_LENGTH (type
) = cu_header
->addr_size
;
4779 return set_die_type (die
, type
, cu
);
4782 static struct type
*
4783 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4785 struct type
*base_type
, *cv_type
;
4787 base_type
= die_type (die
, cu
);
4788 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
4789 return set_die_type (die
, cv_type
, cu
);
4792 static struct type
*
4793 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4795 struct type
*base_type
, *cv_type
;
4797 base_type
= die_type (die
, cu
);
4798 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
4799 return set_die_type (die
, cv_type
, cu
);
4802 /* Extract all information from a DW_TAG_string_type DIE and add to
4803 the user defined type vector. It isn't really a user defined type,
4804 but it behaves like one, with other DIE's using an AT_user_def_type
4805 attribute to reference it. */
4807 static struct type
*
4808 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4810 struct objfile
*objfile
= cu
->objfile
;
4811 struct type
*type
, *range_type
, *index_type
, *char_type
;
4812 struct attribute
*attr
;
4813 unsigned int length
;
4815 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4818 length
= DW_UNSND (attr
);
4822 /* check for the DW_AT_byte_size attribute */
4823 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4826 length
= DW_UNSND (attr
);
4834 index_type
= builtin_type_int32
;
4835 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4836 type
= create_string_type (NULL
, range_type
);
4838 return set_die_type (die
, type
, cu
);
4841 /* Handle DIES due to C code like:
4845 int (*funcp)(int a, long l);
4849 ('funcp' generates a DW_TAG_subroutine_type DIE)
4852 static struct type
*
4853 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4855 struct type
*type
; /* Type that this function returns */
4856 struct type
*ftype
; /* Function that returns above type */
4857 struct attribute
*attr
;
4859 type
= die_type (die
, cu
);
4860 ftype
= make_function_type (type
, (struct type
**) 0);
4862 /* All functions in C++, Pascal and Java have prototypes. */
4863 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4864 if ((attr
&& (DW_UNSND (attr
) != 0))
4865 || cu
->language
== language_cplus
4866 || cu
->language
== language_java
4867 || cu
->language
== language_pascal
)
4868 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
4870 /* Store the calling convention in the type if it's available in
4871 the subroutine die. Otherwise set the calling convention to
4872 the default value DW_CC_normal. */
4873 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
4874 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
4876 if (die
->child
!= NULL
)
4878 struct die_info
*child_die
;
4882 /* Count the number of parameters.
4883 FIXME: GDB currently ignores vararg functions, but knows about
4884 vararg member functions. */
4885 child_die
= die
->child
;
4886 while (child_die
&& child_die
->tag
)
4888 if (child_die
->tag
== DW_TAG_formal_parameter
)
4890 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4891 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
4892 child_die
= sibling_die (child_die
);
4895 /* Allocate storage for parameters and fill them in. */
4896 TYPE_NFIELDS (ftype
) = nparams
;
4897 TYPE_FIELDS (ftype
) = (struct field
*)
4898 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
4900 child_die
= die
->child
;
4901 while (child_die
&& child_die
->tag
)
4903 if (child_die
->tag
== DW_TAG_formal_parameter
)
4905 /* Dwarf2 has no clean way to discern C++ static and non-static
4906 member functions. G++ helps GDB by marking the first
4907 parameter for non-static member functions (which is the
4908 this pointer) as artificial. We pass this information
4909 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4910 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
4912 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
4914 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
4915 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
4918 child_die
= sibling_die (child_die
);
4922 return set_die_type (die
, ftype
, cu
);
4925 static struct type
*
4926 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
4928 struct objfile
*objfile
= cu
->objfile
;
4929 struct attribute
*attr
;
4931 struct type
*this_type
;
4933 name
= dwarf2_name (die
, cu
);
4934 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
4935 TYPE_FLAG_TARGET_STUB
, name
, objfile
);
4936 set_die_type (die
, this_type
, cu
);
4937 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
4941 /* Find a representation of a given base type and install
4942 it in the TYPE field of the die. */
4944 static struct type
*
4945 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4947 struct objfile
*objfile
= cu
->objfile
;
4949 struct attribute
*attr
;
4950 int encoding
= 0, size
= 0;
4952 enum type_code code
= TYPE_CODE_INT
;
4954 struct type
*target_type
= NULL
;
4956 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
4959 encoding
= DW_UNSND (attr
);
4961 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4964 size
= DW_UNSND (attr
);
4966 name
= dwarf2_name (die
, cu
);
4969 complaint (&symfile_complaints
,
4970 _("DW_AT_name missing from DW_TAG_base_type"));
4975 case DW_ATE_address
:
4976 /* Turn DW_ATE_address into a void * pointer. */
4977 code
= TYPE_CODE_PTR
;
4978 type_flags
|= TYPE_FLAG_UNSIGNED
;
4979 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
4981 case DW_ATE_boolean
:
4982 code
= TYPE_CODE_BOOL
;
4983 type_flags
|= TYPE_FLAG_UNSIGNED
;
4985 case DW_ATE_complex_float
:
4986 code
= TYPE_CODE_COMPLEX
;
4987 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
4989 case DW_ATE_decimal_float
:
4990 code
= TYPE_CODE_DECFLOAT
;
4993 code
= TYPE_CODE_FLT
;
4997 case DW_ATE_unsigned
:
4998 type_flags
|= TYPE_FLAG_UNSIGNED
;
5000 case DW_ATE_signed_char
:
5001 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5002 code
= TYPE_CODE_CHAR
;
5004 case DW_ATE_unsigned_char
:
5005 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5006 code
= TYPE_CODE_CHAR
;
5007 type_flags
|= TYPE_FLAG_UNSIGNED
;
5010 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
5011 dwarf_type_encoding_name (encoding
));
5015 type
= init_type (code
, size
, type_flags
, name
, objfile
);
5016 TYPE_TARGET_TYPE (type
) = target_type
;
5018 return set_die_type (die
, type
, cu
);
5021 /* Read the given DW_AT_subrange DIE. */
5023 static struct type
*
5024 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5026 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5027 struct type
*base_type
;
5028 struct type
*range_type
;
5029 struct attribute
*attr
;
5034 base_type
= die_type (die
, cu
);
5035 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
5037 complaint (&symfile_complaints
,
5038 _("DW_AT_type missing from DW_TAG_subrange_type"));
5040 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
5041 0, NULL
, cu
->objfile
);
5044 if (cu
->language
== language_fortran
)
5046 /* FORTRAN implies a lower bound of 1, if not given. */
5050 /* FIXME: For variable sized arrays either of these could be
5051 a variable rather than a constant value. We'll allow it,
5052 but we don't know how to handle it. */
5053 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
5055 low
= dwarf2_get_attr_constant_value (attr
, 0);
5057 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
5060 if (attr
->form
== DW_FORM_block1
)
5062 /* GCC encodes arrays with unspecified or dynamic length
5063 with a DW_FORM_block1 attribute.
5064 FIXME: GDB does not yet know how to handle dynamic
5065 arrays properly, treat them as arrays with unspecified
5068 FIXME: jimb/2003-09-22: GDB does not really know
5069 how to handle arrays of unspecified length
5070 either; we just represent them as zero-length
5071 arrays. Choose an appropriate upper bound given
5072 the lower bound we've computed above. */
5076 high
= dwarf2_get_attr_constant_value (attr
, 1);
5079 range_type
= create_range_type (NULL
, base_type
, low
, high
);
5081 name
= dwarf2_name (die
, cu
);
5083 TYPE_NAME (range_type
) = name
;
5085 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5087 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
5089 return set_die_type (die
, range_type
, cu
);
5092 static struct type
*
5093 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5097 /* For now, we only support the C meaning of an unspecified type: void. */
5099 type
= init_type (TYPE_CODE_VOID
, 0, 0, dwarf2_name (die
, cu
),
5102 return set_die_type (die
, type
, cu
);
5105 /* Trivial hash function for die_info: the hash value of a DIE
5106 is its offset in .debug_info for this objfile. */
5109 die_hash (const void *item
)
5111 const struct die_info
*die
= item
;
5115 /* Trivial comparison function for die_info structures: two DIEs
5116 are equal if they have the same offset. */
5119 die_eq (const void *item_lhs
, const void *item_rhs
)
5121 const struct die_info
*die_lhs
= item_lhs
;
5122 const struct die_info
*die_rhs
= item_rhs
;
5123 return die_lhs
->offset
== die_rhs
->offset
;
5126 /* Read a whole compilation unit into a linked list of dies. */
5128 static struct die_info
*
5129 read_comp_unit (gdb_byte
*info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
5132 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5136 &cu
->comp_unit_obstack
,
5137 hashtab_obstack_allocate
,
5138 dummy_obstack_deallocate
);
5140 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
5143 /* Read a single die and all its descendents. Set the die's sibling
5144 field to NULL; set other fields in the die correctly, and set all
5145 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
5146 location of the info_ptr after reading all of those dies. PARENT
5147 is the parent of the die in question. */
5149 static struct die_info
*
5150 read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
5151 struct dwarf2_cu
*cu
,
5152 gdb_byte
**new_info_ptr
,
5153 struct die_info
*parent
)
5155 struct die_info
*die
;
5159 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
5162 *new_info_ptr
= cur_ptr
;
5165 store_in_ref_table (die
, cu
);
5169 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
5175 *new_info_ptr
= cur_ptr
;
5178 die
->sibling
= NULL
;
5179 die
->parent
= parent
;
5183 /* Read a die, all of its descendents, and all of its siblings; set
5184 all of the fields of all of the dies correctly. Arguments are as
5185 in read_die_and_children. */
5187 static struct die_info
*
5188 read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
5189 struct dwarf2_cu
*cu
,
5190 gdb_byte
**new_info_ptr
,
5191 struct die_info
*parent
)
5193 struct die_info
*first_die
, *last_sibling
;
5197 first_die
= last_sibling
= NULL
;
5201 struct die_info
*die
5202 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
5206 *new_info_ptr
= cur_ptr
;
5213 last_sibling
->sibling
= die
;
5219 /* Decompress a section that was compressed using zlib. Store the
5220 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
5223 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
5224 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
5226 bfd
*abfd
= objfile
->obfd
;
5228 error (_("Support for zlib-compressed DWARF data (from '%s') "
5229 "is disabled in this copy of GDB"),
5230 bfd_get_filename (abfd
));
5232 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
5233 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
5234 bfd_size_type uncompressed_size
;
5235 gdb_byte
*uncompressed_buffer
;
5238 int header_size
= 12;
5240 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5241 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
5242 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5243 bfd_get_filename (abfd
));
5245 /* Read the zlib header. In this case, it should be "ZLIB" followed
5246 by the uncompressed section size, 8 bytes in big-endian order. */
5247 if (compressed_size
< header_size
5248 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
5249 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
5250 bfd_get_filename (abfd
));
5251 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
5252 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
5253 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
5254 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
5255 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
5256 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
5257 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
5258 uncompressed_size
+= compressed_buffer
[11];
5260 /* It is possible the section consists of several compressed
5261 buffers concatenated together, so we uncompress in a loop. */
5265 strm
.avail_in
= compressed_size
- header_size
;
5266 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
5267 strm
.avail_out
= uncompressed_size
;
5268 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
5270 rc
= inflateInit (&strm
);
5271 while (strm
.avail_in
> 0)
5274 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
5275 bfd_get_filename (abfd
), rc
);
5276 strm
.next_out
= ((Bytef
*) uncompressed_buffer
5277 + (uncompressed_size
- strm
.avail_out
));
5278 rc
= inflate (&strm
, Z_FINISH
);
5279 if (rc
!= Z_STREAM_END
)
5280 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
5281 bfd_get_filename (abfd
), rc
);
5282 rc
= inflateReset (&strm
);
5284 rc
= inflateEnd (&strm
);
5286 || strm
.avail_out
!= 0)
5287 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
5288 bfd_get_filename (abfd
), rc
);
5290 xfree (compressed_buffer
);
5291 *outbuf
= uncompressed_buffer
;
5292 *outsize
= uncompressed_size
;
5297 /* Read the contents of the section at OFFSET and of size SIZE from the
5298 object file specified by OBJFILE into the objfile_obstack and return it.
5299 If the section is compressed, uncompress it before returning. */
5302 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
5304 bfd
*abfd
= objfile
->obfd
;
5305 gdb_byte
*buf
, *retbuf
;
5306 bfd_size_type size
= bfd_get_section_size (sectp
);
5307 unsigned char header
[4];
5312 /* Check if the file has a 4-byte header indicating compression. */
5313 if (size
> sizeof (header
)
5314 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
5315 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
5317 /* Upon decompression, update the buffer and its size. */
5318 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
5320 zlib_decompress_section (objfile
, sectp
, &buf
, &size
);
5321 dwarf2_resize_section (sectp
, size
);
5326 /* If we get here, we are a normal, not-compressed section. */
5327 buf
= obstack_alloc (&objfile
->objfile_obstack
, size
);
5328 /* When debugging .o files, we may need to apply relocations; see
5329 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
5330 We never compress sections in .o files, so we only need to
5331 try this when the section is not compressed. */
5332 retbuf
= symfile_relocate_debug_section (abfd
, sectp
, buf
);
5336 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5337 || bfd_bread (buf
, size
, abfd
) != size
)
5338 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5339 bfd_get_filename (abfd
));
5344 /* In DWARF version 2, the description of the debugging information is
5345 stored in a separate .debug_abbrev section. Before we read any
5346 dies from a section we read in all abbreviations and install them
5347 in a hash table. This function also sets flags in CU describing
5348 the data found in the abbrev table. */
5351 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
5353 struct comp_unit_head
*cu_header
= &cu
->header
;
5354 gdb_byte
*abbrev_ptr
;
5355 struct abbrev_info
*cur_abbrev
;
5356 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
5357 unsigned int abbrev_form
, hash_number
;
5358 struct attr_abbrev
*cur_attrs
;
5359 unsigned int allocated_attrs
;
5361 /* Initialize dwarf2 abbrevs */
5362 obstack_init (&cu
->abbrev_obstack
);
5363 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
5365 * sizeof (struct abbrev_info
*)));
5366 memset (cu
->dwarf2_abbrevs
, 0,
5367 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
5369 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
5370 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5371 abbrev_ptr
+= bytes_read
;
5373 allocated_attrs
= ATTR_ALLOC_CHUNK
;
5374 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
5376 /* loop until we reach an abbrev number of 0 */
5377 while (abbrev_number
)
5379 cur_abbrev
= dwarf_alloc_abbrev (cu
);
5381 /* read in abbrev header */
5382 cur_abbrev
->number
= abbrev_number
;
5383 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5384 abbrev_ptr
+= bytes_read
;
5385 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
5388 if (cur_abbrev
->tag
== DW_TAG_namespace
)
5389 cu
->has_namespace_info
= 1;
5391 /* now read in declarations */
5392 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5393 abbrev_ptr
+= bytes_read
;
5394 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5395 abbrev_ptr
+= bytes_read
;
5398 if (cur_abbrev
->num_attrs
== allocated_attrs
)
5400 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
5402 = xrealloc (cur_attrs
, (allocated_attrs
5403 * sizeof (struct attr_abbrev
)));
5406 /* Record whether this compilation unit might have
5407 inter-compilation-unit references. If we don't know what form
5408 this attribute will have, then it might potentially be a
5409 DW_FORM_ref_addr, so we conservatively expect inter-CU
5412 if (abbrev_form
== DW_FORM_ref_addr
5413 || abbrev_form
== DW_FORM_indirect
)
5414 cu
->has_form_ref_addr
= 1;
5416 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
5417 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
5418 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5419 abbrev_ptr
+= bytes_read
;
5420 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5421 abbrev_ptr
+= bytes_read
;
5424 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
5425 (cur_abbrev
->num_attrs
5426 * sizeof (struct attr_abbrev
)));
5427 memcpy (cur_abbrev
->attrs
, cur_attrs
,
5428 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
5430 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
5431 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
5432 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
5434 /* Get next abbreviation.
5435 Under Irix6 the abbreviations for a compilation unit are not
5436 always properly terminated with an abbrev number of 0.
5437 Exit loop if we encounter an abbreviation which we have
5438 already read (which means we are about to read the abbreviations
5439 for the next compile unit) or if the end of the abbreviation
5440 table is reached. */
5441 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
5442 >= dwarf2_per_objfile
->abbrev_size
)
5444 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5445 abbrev_ptr
+= bytes_read
;
5446 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
5453 /* Release the memory used by the abbrev table for a compilation unit. */
5456 dwarf2_free_abbrev_table (void *ptr_to_cu
)
5458 struct dwarf2_cu
*cu
= ptr_to_cu
;
5460 obstack_free (&cu
->abbrev_obstack
, NULL
);
5461 cu
->dwarf2_abbrevs
= NULL
;
5464 /* Lookup an abbrev_info structure in the abbrev hash table. */
5466 static struct abbrev_info
*
5467 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
5469 unsigned int hash_number
;
5470 struct abbrev_info
*abbrev
;
5472 hash_number
= number
% ABBREV_HASH_SIZE
;
5473 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
5477 if (abbrev
->number
== number
)
5480 abbrev
= abbrev
->next
;
5485 /* Returns nonzero if TAG represents a type that we might generate a partial
5489 is_type_tag_for_partial (int tag
)
5494 /* Some types that would be reasonable to generate partial symbols for,
5495 that we don't at present. */
5496 case DW_TAG_array_type
:
5497 case DW_TAG_file_type
:
5498 case DW_TAG_ptr_to_member_type
:
5499 case DW_TAG_set_type
:
5500 case DW_TAG_string_type
:
5501 case DW_TAG_subroutine_type
:
5503 case DW_TAG_base_type
:
5504 case DW_TAG_class_type
:
5505 case DW_TAG_interface_type
:
5506 case DW_TAG_enumeration_type
:
5507 case DW_TAG_structure_type
:
5508 case DW_TAG_subrange_type
:
5509 case DW_TAG_typedef
:
5510 case DW_TAG_union_type
:
5517 /* Load all DIEs that are interesting for partial symbols into memory. */
5519 static struct partial_die_info
*
5520 load_partial_dies (bfd
*abfd
, gdb_byte
*info_ptr
, int building_psymtab
,
5521 struct dwarf2_cu
*cu
)
5523 struct partial_die_info
*part_die
;
5524 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
5525 struct abbrev_info
*abbrev
;
5526 unsigned int bytes_read
;
5527 unsigned int load_all
= 0;
5529 int nesting_level
= 1;
5534 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
5538 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5542 &cu
->comp_unit_obstack
,
5543 hashtab_obstack_allocate
,
5544 dummy_obstack_deallocate
);
5546 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5547 sizeof (struct partial_die_info
));
5551 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5553 /* A NULL abbrev means the end of a series of children. */
5556 if (--nesting_level
== 0)
5558 /* PART_DIE was probably the last thing allocated on the
5559 comp_unit_obstack, so we could call obstack_free
5560 here. We don't do that because the waste is small,
5561 and will be cleaned up when we're done with this
5562 compilation unit. This way, we're also more robust
5563 against other users of the comp_unit_obstack. */
5566 info_ptr
+= bytes_read
;
5567 last_die
= parent_die
;
5568 parent_die
= parent_die
->die_parent
;
5572 /* Check whether this DIE is interesting enough to save. Normally
5573 we would not be interested in members here, but there may be
5574 later variables referencing them via DW_AT_specification (for
5577 && !is_type_tag_for_partial (abbrev
->tag
)
5578 && abbrev
->tag
!= DW_TAG_enumerator
5579 && abbrev
->tag
!= DW_TAG_subprogram
5580 && abbrev
->tag
!= DW_TAG_variable
5581 && abbrev
->tag
!= DW_TAG_namespace
5582 && abbrev
->tag
!= DW_TAG_member
)
5584 /* Otherwise we skip to the next sibling, if any. */
5585 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5589 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5590 abfd
, info_ptr
, cu
);
5592 /* This two-pass algorithm for processing partial symbols has a
5593 high cost in cache pressure. Thus, handle some simple cases
5594 here which cover the majority of C partial symbols. DIEs
5595 which neither have specification tags in them, nor could have
5596 specification tags elsewhere pointing at them, can simply be
5597 processed and discarded.
5599 This segment is also optional; scan_partial_symbols and
5600 add_partial_symbol will handle these DIEs if we chain
5601 them in normally. When compilers which do not emit large
5602 quantities of duplicate debug information are more common,
5603 this code can probably be removed. */
5605 /* Any complete simple types at the top level (pretty much all
5606 of them, for a language without namespaces), can be processed
5608 if (parent_die
== NULL
5609 && part_die
->has_specification
== 0
5610 && part_die
->is_declaration
== 0
5611 && (part_die
->tag
== DW_TAG_typedef
5612 || part_die
->tag
== DW_TAG_base_type
5613 || part_die
->tag
== DW_TAG_subrange_type
))
5615 if (building_psymtab
&& part_die
->name
!= NULL
)
5616 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5617 VAR_DOMAIN
, LOC_TYPEDEF
,
5618 &cu
->objfile
->static_psymbols
,
5619 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5620 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5624 /* If we're at the second level, and we're an enumerator, and
5625 our parent has no specification (meaning possibly lives in a
5626 namespace elsewhere), then we can add the partial symbol now
5627 instead of queueing it. */
5628 if (part_die
->tag
== DW_TAG_enumerator
5629 && parent_die
!= NULL
5630 && parent_die
->die_parent
== NULL
5631 && parent_die
->tag
== DW_TAG_enumeration_type
5632 && parent_die
->has_specification
== 0)
5634 if (part_die
->name
== NULL
)
5635 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5636 else if (building_psymtab
)
5637 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5638 VAR_DOMAIN
, LOC_CONST
,
5639 (cu
->language
== language_cplus
5640 || cu
->language
== language_java
)
5641 ? &cu
->objfile
->global_psymbols
5642 : &cu
->objfile
->static_psymbols
,
5643 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5645 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5649 /* We'll save this DIE so link it in. */
5650 part_die
->die_parent
= parent_die
;
5651 part_die
->die_sibling
= NULL
;
5652 part_die
->die_child
= NULL
;
5654 if (last_die
&& last_die
== parent_die
)
5655 last_die
->die_child
= part_die
;
5657 last_die
->die_sibling
= part_die
;
5659 last_die
= part_die
;
5661 if (first_die
== NULL
)
5662 first_die
= part_die
;
5664 /* Maybe add the DIE to the hash table. Not all DIEs that we
5665 find interesting need to be in the hash table, because we
5666 also have the parent/sibling/child chains; only those that we
5667 might refer to by offset later during partial symbol reading.
5669 For now this means things that might have be the target of a
5670 DW_AT_specification, DW_AT_abstract_origin, or
5671 DW_AT_extension. DW_AT_extension will refer only to
5672 namespaces; DW_AT_abstract_origin refers to functions (and
5673 many things under the function DIE, but we do not recurse
5674 into function DIEs during partial symbol reading) and
5675 possibly variables as well; DW_AT_specification refers to
5676 declarations. Declarations ought to have the DW_AT_declaration
5677 flag. It happens that GCC forgets to put it in sometimes, but
5678 only for functions, not for types.
5680 Adding more things than necessary to the hash table is harmless
5681 except for the performance cost. Adding too few will result in
5682 wasted time in find_partial_die, when we reread the compilation
5683 unit with load_all_dies set. */
5686 || abbrev
->tag
== DW_TAG_subprogram
5687 || abbrev
->tag
== DW_TAG_variable
5688 || abbrev
->tag
== DW_TAG_namespace
5689 || part_die
->is_declaration
)
5693 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
5694 part_die
->offset
, INSERT
);
5698 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5699 sizeof (struct partial_die_info
));
5701 /* For some DIEs we want to follow their children (if any). For C
5702 we have no reason to follow the children of structures; for other
5703 languages we have to, both so that we can get at method physnames
5704 to infer fully qualified class names, and for DW_AT_specification. */
5705 if (last_die
->has_children
5707 || last_die
->tag
== DW_TAG_namespace
5708 || last_die
->tag
== DW_TAG_enumeration_type
5709 || (cu
->language
!= language_c
5710 && (last_die
->tag
== DW_TAG_class_type
5711 || last_die
->tag
== DW_TAG_interface_type
5712 || last_die
->tag
== DW_TAG_structure_type
5713 || last_die
->tag
== DW_TAG_union_type
))))
5716 parent_die
= last_die
;
5720 /* Otherwise we skip to the next sibling, if any. */
5721 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
5723 /* Back to the top, do it again. */
5727 /* Read a minimal amount of information into the minimal die structure. */
5730 read_partial_die (struct partial_die_info
*part_die
,
5731 struct abbrev_info
*abbrev
,
5732 unsigned int abbrev_len
, bfd
*abfd
,
5733 gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
5735 unsigned int bytes_read
, i
;
5736 struct attribute attr
;
5737 int has_low_pc_attr
= 0;
5738 int has_high_pc_attr
= 0;
5739 CORE_ADDR base_address
= 0;
5743 base_address_low_pc
,
5744 /* Overrides BASE_ADDRESS_LOW_PC. */
5745 base_address_entry_pc
5747 base_address_type
= base_address_none
;
5749 memset (part_die
, 0, sizeof (struct partial_die_info
));
5751 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5753 info_ptr
+= abbrev_len
;
5758 part_die
->tag
= abbrev
->tag
;
5759 part_die
->has_children
= abbrev
->has_children
;
5761 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5763 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
5765 /* Store the data if it is of an attribute we want to keep in a
5766 partial symbol table. */
5771 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
5772 if (part_die
->name
== NULL
)
5773 part_die
->name
= DW_STRING (&attr
);
5775 case DW_AT_comp_dir
:
5776 if (part_die
->dirname
== NULL
)
5777 part_die
->dirname
= DW_STRING (&attr
);
5779 case DW_AT_MIPS_linkage_name
:
5780 part_die
->name
= DW_STRING (&attr
);
5783 has_low_pc_attr
= 1;
5784 part_die
->lowpc
= DW_ADDR (&attr
);
5785 if (part_die
->tag
== DW_TAG_compile_unit
5786 && base_address_type
< base_address_low_pc
)
5788 base_address
= DW_ADDR (&attr
);
5789 base_address_type
= base_address_low_pc
;
5793 has_high_pc_attr
= 1;
5794 part_die
->highpc
= DW_ADDR (&attr
);
5796 case DW_AT_entry_pc
:
5797 if (part_die
->tag
== DW_TAG_compile_unit
5798 && base_address_type
< base_address_entry_pc
)
5800 base_address
= DW_ADDR (&attr
);
5801 base_address_type
= base_address_entry_pc
;
5805 if (part_die
->tag
== DW_TAG_compile_unit
)
5807 cu
->ranges_offset
= DW_UNSND (&attr
);
5808 cu
->has_ranges_offset
= 1;
5811 case DW_AT_location
:
5812 /* Support the .debug_loc offsets */
5813 if (attr_form_is_block (&attr
))
5815 part_die
->locdesc
= DW_BLOCK (&attr
);
5817 else if (attr_form_is_section_offset (&attr
))
5819 dwarf2_complex_location_expr_complaint ();
5823 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5824 "partial symbol information");
5827 case DW_AT_language
:
5828 part_die
->language
= DW_UNSND (&attr
);
5830 case DW_AT_external
:
5831 part_die
->is_external
= DW_UNSND (&attr
);
5833 case DW_AT_declaration
:
5834 part_die
->is_declaration
= DW_UNSND (&attr
);
5837 part_die
->has_type
= 1;
5839 case DW_AT_abstract_origin
:
5840 case DW_AT_specification
:
5841 case DW_AT_extension
:
5842 part_die
->has_specification
= 1;
5843 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
, cu
);
5846 /* Ignore absolute siblings, they might point outside of
5847 the current compile unit. */
5848 if (attr
.form
== DW_FORM_ref_addr
)
5849 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
5851 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
5852 + dwarf2_get_ref_die_offset (&attr
, cu
);
5854 case DW_AT_stmt_list
:
5855 part_die
->has_stmt_list
= 1;
5856 part_die
->line_offset
= DW_UNSND (&attr
);
5858 case DW_AT_byte_size
:
5859 part_die
->has_byte_size
= 1;
5861 case DW_AT_calling_convention
:
5862 /* DWARF doesn't provide a way to identify a program's source-level
5863 entry point. DW_AT_calling_convention attributes are only meant
5864 to describe functions' calling conventions.
5866 However, because it's a necessary piece of information in
5867 Fortran, and because DW_CC_program is the only piece of debugging
5868 information whose definition refers to a 'main program' at all,
5869 several compilers have begun marking Fortran main programs with
5870 DW_CC_program --- even when those functions use the standard
5871 calling conventions.
5873 So until DWARF specifies a way to provide this information and
5874 compilers pick up the new representation, we'll support this
5876 if (DW_UNSND (&attr
) == DW_CC_program
5877 && cu
->language
== language_fortran
)
5878 set_main_name (part_die
->name
);
5885 /* When using the GNU linker, .gnu.linkonce. sections are used to
5886 eliminate duplicate copies of functions and vtables and such.
5887 The linker will arbitrarily choose one and discard the others.
5888 The AT_*_pc values for such functions refer to local labels in
5889 these sections. If the section from that file was discarded, the
5890 labels are not in the output, so the relocs get a value of 0.
5891 If this is a discarded function, mark the pc bounds as invalid,
5892 so that GDB will ignore it. */
5893 if (has_low_pc_attr
&& has_high_pc_attr
5894 && part_die
->lowpc
< part_die
->highpc
5895 && (part_die
->lowpc
!= 0
5896 || dwarf2_per_objfile
->has_section_at_zero
))
5897 part_die
->has_pc_info
= 1;
5899 if (base_address_type
!= base_address_none
&& !cu
->header
.base_known
)
5901 gdb_assert (part_die
->tag
== DW_TAG_compile_unit
);
5902 cu
->header
.base_known
= 1;
5903 cu
->header
.base_address
= base_address
;
5909 /* Find a cached partial DIE at OFFSET in CU. */
5911 static struct partial_die_info
*
5912 find_partial_die_in_comp_unit (unsigned long offset
, struct dwarf2_cu
*cu
)
5914 struct partial_die_info
*lookup_die
= NULL
;
5915 struct partial_die_info part_die
;
5917 part_die
.offset
= offset
;
5918 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
5923 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
5925 static struct partial_die_info
*
5926 find_partial_die (unsigned long offset
, struct dwarf2_cu
*cu
)
5928 struct dwarf2_per_cu_data
*per_cu
= NULL
;
5929 struct partial_die_info
*pd
= NULL
;
5931 if (offset
>= cu
->header
.offset
5932 && offset
< cu
->header
.offset
+ cu
->header
.length
)
5934 pd
= find_partial_die_in_comp_unit (offset
, cu
);
5939 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
5941 if (per_cu
->cu
== NULL
)
5943 load_comp_unit (per_cu
, cu
->objfile
);
5944 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5945 dwarf2_per_objfile
->read_in_chain
= per_cu
;
5948 per_cu
->cu
->last_used
= 0;
5949 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
5951 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
5953 struct cleanup
*back_to
;
5954 struct partial_die_info comp_unit_die
;
5955 struct abbrev_info
*abbrev
;
5956 unsigned int bytes_read
;
5959 per_cu
->load_all_dies
= 1;
5961 /* Re-read the DIEs. */
5962 back_to
= make_cleanup (null_cleanup
, 0);
5963 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
5965 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
5966 back_to
= make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
5968 info_ptr
= per_cu
->cu
->header
.first_die_ptr
;
5969 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
5970 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
5971 per_cu
->cu
->objfile
->obfd
, info_ptr
,
5973 if (comp_unit_die
.has_children
)
5974 load_partial_dies (per_cu
->cu
->objfile
->obfd
, info_ptr
, 0, per_cu
->cu
);
5975 do_cleanups (back_to
);
5977 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
5981 internal_error (__FILE__
, __LINE__
,
5982 _("could not find partial DIE 0x%lx in cache [from module %s]\n"),
5983 offset
, bfd_get_filename (cu
->objfile
->obfd
));
5987 /* Adjust PART_DIE before generating a symbol for it. This function
5988 may set the is_external flag or change the DIE's name. */
5991 fixup_partial_die (struct partial_die_info
*part_die
,
5992 struct dwarf2_cu
*cu
)
5994 /* If we found a reference attribute and the DIE has no name, try
5995 to find a name in the referred to DIE. */
5997 if (part_die
->name
== NULL
&& part_die
->has_specification
)
5999 struct partial_die_info
*spec_die
;
6001 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
6003 fixup_partial_die (spec_die
, cu
);
6007 part_die
->name
= spec_die
->name
;
6009 /* Copy DW_AT_external attribute if it is set. */
6010 if (spec_die
->is_external
)
6011 part_die
->is_external
= spec_die
->is_external
;
6015 /* Set default names for some unnamed DIEs. */
6016 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
6017 || part_die
->tag
== DW_TAG_class_type
))
6018 part_die
->name
= "(anonymous class)";
6020 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
6021 part_die
->name
= "(anonymous namespace)";
6023 if (part_die
->tag
== DW_TAG_structure_type
6024 || part_die
->tag
== DW_TAG_class_type
6025 || part_die
->tag
== DW_TAG_union_type
)
6026 guess_structure_name (part_die
, cu
);
6029 /* Read the die from the .debug_info section buffer. Set DIEP to
6030 point to a newly allocated die with its information, except for its
6031 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6032 whether the die has children or not. */
6035 read_full_die (struct die_info
**diep
, bfd
*abfd
, gdb_byte
*info_ptr
,
6036 struct dwarf2_cu
*cu
, int *has_children
)
6038 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6039 struct abbrev_info
*abbrev
;
6040 struct die_info
*die
;
6042 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
6043 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6044 info_ptr
+= bytes_read
;
6052 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6055 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6057 bfd_get_filename (abfd
));
6059 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
6060 die
->offset
= offset
;
6061 die
->tag
= abbrev
->tag
;
6062 die
->abbrev
= abbrev_number
;
6064 die
->num_attrs
= abbrev
->num_attrs
;
6066 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6067 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6068 abfd
, info_ptr
, cu
);
6071 *has_children
= abbrev
->has_children
;
6075 /* Read an attribute value described by an attribute form. */
6078 read_attribute_value (struct attribute
*attr
, unsigned form
,
6079 bfd
*abfd
, gdb_byte
*info_ptr
,
6080 struct dwarf2_cu
*cu
)
6082 struct comp_unit_head
*cu_header
= &cu
->header
;
6083 unsigned int bytes_read
;
6084 struct dwarf_block
*blk
;
6090 case DW_FORM_ref_addr
:
6091 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6092 info_ptr
+= bytes_read
;
6094 case DW_FORM_block2
:
6095 blk
= dwarf_alloc_block (cu
);
6096 blk
->size
= read_2_bytes (abfd
, info_ptr
);
6098 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6099 info_ptr
+= blk
->size
;
6100 DW_BLOCK (attr
) = blk
;
6102 case DW_FORM_block4
:
6103 blk
= dwarf_alloc_block (cu
);
6104 blk
->size
= read_4_bytes (abfd
, info_ptr
);
6106 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6107 info_ptr
+= blk
->size
;
6108 DW_BLOCK (attr
) = blk
;
6111 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
6115 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
6119 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
6122 case DW_FORM_string
:
6123 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
6124 info_ptr
+= bytes_read
;
6127 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
6129 info_ptr
+= bytes_read
;
6132 blk
= dwarf_alloc_block (cu
);
6133 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6134 info_ptr
+= bytes_read
;
6135 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6136 info_ptr
+= blk
->size
;
6137 DW_BLOCK (attr
) = blk
;
6139 case DW_FORM_block1
:
6140 blk
= dwarf_alloc_block (cu
);
6141 blk
->size
= read_1_byte (abfd
, info_ptr
);
6143 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6144 info_ptr
+= blk
->size
;
6145 DW_BLOCK (attr
) = blk
;
6148 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6152 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6156 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
6157 info_ptr
+= bytes_read
;
6160 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6161 info_ptr
+= bytes_read
;
6164 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
6168 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
6172 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
6176 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
6179 case DW_FORM_ref_udata
:
6180 DW_ADDR (attr
) = (cu
->header
.offset
6181 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
6182 info_ptr
+= bytes_read
;
6184 case DW_FORM_indirect
:
6185 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6186 info_ptr
+= bytes_read
;
6187 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
6190 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
6191 dwarf_form_name (form
),
6192 bfd_get_filename (abfd
));
6195 /* We have seen instances where the compiler tried to emit a byte
6196 size attribute of -1 which ended up being encoded as an unsigned
6197 0xffffffff. Although 0xffffffff is technically a valid size value,
6198 an object of this size seems pretty unlikely so we can relatively
6199 safely treat these cases as if the size attribute was invalid and
6200 treat them as zero by default. */
6201 if (attr
->name
== DW_AT_byte_size
6202 && form
== DW_FORM_data4
6203 && DW_UNSND (attr
) >= 0xffffffff)
6206 (&symfile_complaints
,
6207 _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"),
6209 DW_UNSND (attr
) = 0;
6215 /* Read an attribute described by an abbreviated attribute. */
6218 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
6219 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6221 attr
->name
= abbrev
->name
;
6222 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
6225 /* read dwarf information from a buffer */
6228 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
6230 return bfd_get_8 (abfd
, buf
);
6234 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
6236 return bfd_get_signed_8 (abfd
, buf
);
6240 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
6242 return bfd_get_16 (abfd
, buf
);
6246 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6248 return bfd_get_signed_16 (abfd
, buf
);
6252 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
6254 return bfd_get_32 (abfd
, buf
);
6258 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6260 return bfd_get_signed_32 (abfd
, buf
);
6263 static unsigned long
6264 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
6266 return bfd_get_64 (abfd
, buf
);
6270 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
6271 unsigned int *bytes_read
)
6273 struct comp_unit_head
*cu_header
= &cu
->header
;
6274 CORE_ADDR retval
= 0;
6276 if (cu_header
->signed_addr_p
)
6278 switch (cu_header
->addr_size
)
6281 retval
= bfd_get_signed_16 (abfd
, buf
);
6284 retval
= bfd_get_signed_32 (abfd
, buf
);
6287 retval
= bfd_get_signed_64 (abfd
, buf
);
6290 internal_error (__FILE__
, __LINE__
,
6291 _("read_address: bad switch, signed [in module %s]"),
6292 bfd_get_filename (abfd
));
6297 switch (cu_header
->addr_size
)
6300 retval
= bfd_get_16 (abfd
, buf
);
6303 retval
= bfd_get_32 (abfd
, buf
);
6306 retval
= bfd_get_64 (abfd
, buf
);
6309 internal_error (__FILE__
, __LINE__
,
6310 _("read_address: bad switch, unsigned [in module %s]"),
6311 bfd_get_filename (abfd
));
6315 *bytes_read
= cu_header
->addr_size
;
6319 /* Read the initial length from a section. The (draft) DWARF 3
6320 specification allows the initial length to take up either 4 bytes
6321 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
6322 bytes describe the length and all offsets will be 8 bytes in length
6325 An older, non-standard 64-bit format is also handled by this
6326 function. The older format in question stores the initial length
6327 as an 8-byte quantity without an escape value. Lengths greater
6328 than 2^32 aren't very common which means that the initial 4 bytes
6329 is almost always zero. Since a length value of zero doesn't make
6330 sense for the 32-bit format, this initial zero can be considered to
6331 be an escape value which indicates the presence of the older 64-bit
6332 format. As written, the code can't detect (old format) lengths
6333 greater than 4GB. If it becomes necessary to handle lengths
6334 somewhat larger than 4GB, we could allow other small values (such
6335 as the non-sensical values of 1, 2, and 3) to also be used as
6336 escape values indicating the presence of the old format.
6338 The value returned via bytes_read should be used to increment the
6339 relevant pointer after calling read_initial_length().
6341 As a side effect, this function sets the fields initial_length_size
6342 and offset_size in cu_header to the values appropriate for the
6343 length field. (The format of the initial length field determines
6344 the width of file offsets to be fetched later with read_offset().)
6346 [ Note: read_initial_length() and read_offset() are based on the
6347 document entitled "DWARF Debugging Information Format", revision
6348 3, draft 8, dated November 19, 2001. This document was obtained
6351 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
6353 This document is only a draft and is subject to change. (So beware.)
6355 Details regarding the older, non-standard 64-bit format were
6356 determined empirically by examining 64-bit ELF files produced by
6357 the SGI toolchain on an IRIX 6.5 machine.
6359 - Kevin, July 16, 2002
6363 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, struct comp_unit_head
*cu_header
,
6364 unsigned int *bytes_read
)
6366 LONGEST length
= bfd_get_32 (abfd
, buf
);
6368 if (length
== 0xffffffff)
6370 length
= bfd_get_64 (abfd
, buf
+ 4);
6373 else if (length
== 0)
6375 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
6376 length
= bfd_get_64 (abfd
, buf
);
6386 gdb_assert (cu_header
->initial_length_size
== 0
6387 || cu_header
->initial_length_size
== 4
6388 || cu_header
->initial_length_size
== 8
6389 || cu_header
->initial_length_size
== 12);
6391 if (cu_header
->initial_length_size
!= 0
6392 && cu_header
->initial_length_size
!= *bytes_read
)
6393 complaint (&symfile_complaints
,
6394 _("intermixed 32-bit and 64-bit DWARF sections"));
6396 cu_header
->initial_length_size
= *bytes_read
;
6397 cu_header
->offset_size
= (*bytes_read
== 4) ? 4 : 8;
6403 /* Read an offset from the data stream. The size of the offset is
6404 given by cu_header->offset_size. */
6407 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
6408 unsigned int *bytes_read
)
6412 switch (cu_header
->offset_size
)
6415 retval
= bfd_get_32 (abfd
, buf
);
6419 retval
= bfd_get_64 (abfd
, buf
);
6423 internal_error (__FILE__
, __LINE__
,
6424 _("read_offset: bad switch [in module %s]"),
6425 bfd_get_filename (abfd
));
6432 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
6434 /* If the size of a host char is 8 bits, we can return a pointer
6435 to the buffer, otherwise we have to copy the data to a buffer
6436 allocated on the temporary obstack. */
6437 gdb_assert (HOST_CHAR_BIT
== 8);
6442 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6444 /* If the size of a host char is 8 bits, we can return a pointer
6445 to the string, otherwise we have to copy the string to a buffer
6446 allocated on the temporary obstack. */
6447 gdb_assert (HOST_CHAR_BIT
== 8);
6450 *bytes_read_ptr
= 1;
6453 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
6454 return (char *) buf
;
6458 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
6459 const struct comp_unit_head
*cu_header
,
6460 unsigned int *bytes_read_ptr
)
6462 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
6465 if (dwarf2_per_objfile
->str_buffer
== NULL
)
6467 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
6468 bfd_get_filename (abfd
));
6471 if (str_offset
>= dwarf2_per_objfile
->str_size
)
6473 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
6474 bfd_get_filename (abfd
));
6477 gdb_assert (HOST_CHAR_BIT
== 8);
6478 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
6480 return (char *) (dwarf2_per_objfile
->str_buffer
+ str_offset
);
6483 static unsigned long
6484 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6486 unsigned long result
;
6487 unsigned int num_read
;
6497 byte
= bfd_get_8 (abfd
, buf
);
6500 result
|= ((unsigned long)(byte
& 127) << shift
);
6501 if ((byte
& 128) == 0)
6507 *bytes_read_ptr
= num_read
;
6512 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6515 int i
, shift
, num_read
;
6524 byte
= bfd_get_8 (abfd
, buf
);
6527 result
|= ((long)(byte
& 127) << shift
);
6529 if ((byte
& 128) == 0)
6534 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
6535 result
|= -(((long)1) << shift
);
6536 *bytes_read_ptr
= num_read
;
6540 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6543 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
6549 byte
= bfd_get_8 (abfd
, buf
);
6551 if ((byte
& 128) == 0)
6557 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
6563 cu
->language
= language_c
;
6565 case DW_LANG_C_plus_plus
:
6566 cu
->language
= language_cplus
;
6568 case DW_LANG_Fortran77
:
6569 case DW_LANG_Fortran90
:
6570 case DW_LANG_Fortran95
:
6571 cu
->language
= language_fortran
;
6573 case DW_LANG_Mips_Assembler
:
6574 cu
->language
= language_asm
;
6577 cu
->language
= language_java
;
6581 cu
->language
= language_ada
;
6583 case DW_LANG_Modula2
:
6584 cu
->language
= language_m2
;
6586 case DW_LANG_Pascal83
:
6587 cu
->language
= language_pascal
;
6590 cu
->language
= language_objc
;
6592 case DW_LANG_Cobol74
:
6593 case DW_LANG_Cobol85
:
6595 cu
->language
= language_minimal
;
6598 cu
->language_defn
= language_def (cu
->language
);
6601 /* Return the named attribute or NULL if not there. */
6603 static struct attribute
*
6604 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
6607 struct attribute
*spec
= NULL
;
6609 for (i
= 0; i
< die
->num_attrs
; ++i
)
6611 if (die
->attrs
[i
].name
== name
)
6612 return &die
->attrs
[i
];
6613 if (die
->attrs
[i
].name
== DW_AT_specification
6614 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
6615 spec
= &die
->attrs
[i
];
6619 return dwarf2_attr (follow_die_ref (die
, spec
, cu
), name
, cu
);
6624 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6625 and holds a non-zero value. This function should only be used for
6626 DW_FORM_flag attributes. */
6629 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
6631 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
6633 return (attr
&& DW_UNSND (attr
));
6637 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
6639 /* A DIE is a declaration if it has a DW_AT_declaration attribute
6640 which value is non-zero. However, we have to be careful with
6641 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
6642 (via dwarf2_flag_true_p) follows this attribute. So we may
6643 end up accidently finding a declaration attribute that belongs
6644 to a different DIE referenced by the specification attribute,
6645 even though the given DIE does not have a declaration attribute. */
6646 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
6647 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
6650 /* Return the die giving the specification for DIE, if there is
6653 static struct die_info
*
6654 die_specification (struct die_info
*die
, struct dwarf2_cu
*cu
)
6656 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
, cu
);
6658 if (spec_attr
== NULL
)
6661 return follow_die_ref (die
, spec_attr
, cu
);
6664 /* Free the line_header structure *LH, and any arrays and strings it
6667 free_line_header (struct line_header
*lh
)
6669 if (lh
->standard_opcode_lengths
)
6670 xfree (lh
->standard_opcode_lengths
);
6672 /* Remember that all the lh->file_names[i].name pointers are
6673 pointers into debug_line_buffer, and don't need to be freed. */
6675 xfree (lh
->file_names
);
6677 /* Similarly for the include directory names. */
6678 if (lh
->include_dirs
)
6679 xfree (lh
->include_dirs
);
6685 /* Add an entry to LH's include directory table. */
6687 add_include_dir (struct line_header
*lh
, char *include_dir
)
6689 /* Grow the array if necessary. */
6690 if (lh
->include_dirs_size
== 0)
6692 lh
->include_dirs_size
= 1; /* for testing */
6693 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
6694 * sizeof (*lh
->include_dirs
));
6696 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
6698 lh
->include_dirs_size
*= 2;
6699 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
6700 (lh
->include_dirs_size
6701 * sizeof (*lh
->include_dirs
)));
6704 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
6708 /* Add an entry to LH's file name table. */
6710 add_file_name (struct line_header
*lh
,
6712 unsigned int dir_index
,
6713 unsigned int mod_time
,
6714 unsigned int length
)
6716 struct file_entry
*fe
;
6718 /* Grow the array if necessary. */
6719 if (lh
->file_names_size
== 0)
6721 lh
->file_names_size
= 1; /* for testing */
6722 lh
->file_names
= xmalloc (lh
->file_names_size
6723 * sizeof (*lh
->file_names
));
6725 else if (lh
->num_file_names
>= lh
->file_names_size
)
6727 lh
->file_names_size
*= 2;
6728 lh
->file_names
= xrealloc (lh
->file_names
,
6729 (lh
->file_names_size
6730 * sizeof (*lh
->file_names
)));
6733 fe
= &lh
->file_names
[lh
->num_file_names
++];
6735 fe
->dir_index
= dir_index
;
6736 fe
->mod_time
= mod_time
;
6737 fe
->length
= length
;
6743 /* Read the statement program header starting at OFFSET in
6744 .debug_line, according to the endianness of ABFD. Return a pointer
6745 to a struct line_header, allocated using xmalloc.
6747 NOTE: the strings in the include directory and file name tables of
6748 the returned object point into debug_line_buffer, and must not be
6750 static struct line_header
*
6751 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
6752 struct dwarf2_cu
*cu
)
6754 struct cleanup
*back_to
;
6755 struct line_header
*lh
;
6757 unsigned int bytes_read
;
6759 char *cur_dir
, *cur_file
;
6761 if (dwarf2_per_objfile
->line_buffer
== NULL
)
6763 complaint (&symfile_complaints
, _("missing .debug_line section"));
6767 /* Make sure that at least there's room for the total_length field.
6768 That could be 12 bytes long, but we're just going to fudge that. */
6769 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
6771 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6775 lh
= xmalloc (sizeof (*lh
));
6776 memset (lh
, 0, sizeof (*lh
));
6777 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
6780 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
6782 /* Read in the header. */
6784 read_initial_length (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6785 line_ptr
+= bytes_read
;
6786 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
6787 + dwarf2_per_objfile
->line_size
))
6789 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6792 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
6793 lh
->version
= read_2_bytes (abfd
, line_ptr
);
6795 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6796 line_ptr
+= bytes_read
;
6797 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
6799 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
6801 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
6803 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
6805 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
6807 lh
->standard_opcode_lengths
6808 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
6810 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
6811 for (i
= 1; i
< lh
->opcode_base
; ++i
)
6813 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
6817 /* Read directory table. */
6818 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6820 line_ptr
+= bytes_read
;
6821 add_include_dir (lh
, cur_dir
);
6823 line_ptr
+= bytes_read
;
6825 /* Read file name table. */
6826 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6828 unsigned int dir_index
, mod_time
, length
;
6830 line_ptr
+= bytes_read
;
6831 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6832 line_ptr
+= bytes_read
;
6833 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6834 line_ptr
+= bytes_read
;
6835 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6836 line_ptr
+= bytes_read
;
6838 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6840 line_ptr
+= bytes_read
;
6841 lh
->statement_program_start
= line_ptr
;
6843 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
6844 + dwarf2_per_objfile
->line_size
))
6845 complaint (&symfile_complaints
,
6846 _("line number info header doesn't fit in `.debug_line' section"));
6848 discard_cleanups (back_to
);
6852 /* This function exists to work around a bug in certain compilers
6853 (particularly GCC 2.95), in which the first line number marker of a
6854 function does not show up until after the prologue, right before
6855 the second line number marker. This function shifts ADDRESS down
6856 to the beginning of the function if necessary, and is called on
6857 addresses passed to record_line. */
6860 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
6862 struct function_range
*fn
;
6864 /* Find the function_range containing address. */
6869 cu
->cached_fn
= cu
->first_fn
;
6873 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6879 while (fn
&& fn
!= cu
->cached_fn
)
6880 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6890 if (address
!= fn
->lowpc
)
6891 complaint (&symfile_complaints
,
6892 _("misplaced first line number at 0x%lx for '%s'"),
6893 (unsigned long) address
, fn
->name
);
6898 /* Decode the Line Number Program (LNP) for the given line_header
6899 structure and CU. The actual information extracted and the type
6900 of structures created from the LNP depends on the value of PST.
6902 1. If PST is NULL, then this procedure uses the data from the program
6903 to create all necessary symbol tables, and their linetables.
6904 The compilation directory of the file is passed in COMP_DIR,
6905 and must not be NULL.
6907 2. If PST is not NULL, this procedure reads the program to determine
6908 the list of files included by the unit represented by PST, and
6909 builds all the associated partial symbol tables. In this case,
6910 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
6911 is not used to compute the full name of the symtab, and therefore
6912 omitting it when building the partial symtab does not introduce
6913 the potential for inconsistency - a partial symtab and its associated
6914 symbtab having a different fullname -). */
6917 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
6918 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
6920 gdb_byte
*line_ptr
, *extended_end
;
6922 unsigned int bytes_read
, extended_len
;
6923 unsigned char op_code
, extended_op
, adj_opcode
;
6925 struct objfile
*objfile
= cu
->objfile
;
6926 const int decode_for_pst_p
= (pst
!= NULL
);
6927 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
6929 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6931 line_ptr
= lh
->statement_program_start
;
6932 line_end
= lh
->statement_program_end
;
6934 /* Read the statement sequences until there's nothing left. */
6935 while (line_ptr
< line_end
)
6937 /* state machine registers */
6938 CORE_ADDR address
= 0;
6939 unsigned int file
= 1;
6940 unsigned int line
= 1;
6941 unsigned int column
= 0;
6942 int is_stmt
= lh
->default_is_stmt
;
6943 int basic_block
= 0;
6944 int end_sequence
= 0;
6946 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
6948 /* Start a subfile for the current file of the state machine. */
6949 /* lh->include_dirs and lh->file_names are 0-based, but the
6950 directory and file name numbers in the statement program
6952 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
6956 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6958 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
6961 /* Decode the table. */
6962 while (!end_sequence
)
6964 op_code
= read_1_byte (abfd
, line_ptr
);
6967 if (op_code
>= lh
->opcode_base
)
6969 /* Special operand. */
6970 adj_opcode
= op_code
- lh
->opcode_base
;
6971 address
+= (adj_opcode
/ lh
->line_range
)
6972 * lh
->minimum_instruction_length
;
6973 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
6974 if (lh
->num_file_names
< file
)
6975 dwarf2_debug_line_missing_file_complaint ();
6978 lh
->file_names
[file
- 1].included_p
= 1;
6979 if (!decode_for_pst_p
)
6981 if (last_subfile
!= current_subfile
)
6984 record_line (last_subfile
, 0, address
);
6985 last_subfile
= current_subfile
;
6987 /* Append row to matrix using current values. */
6988 record_line (current_subfile
, line
,
6989 check_cu_functions (address
, cu
));
6994 else switch (op_code
)
6996 case DW_LNS_extended_op
:
6997 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6998 line_ptr
+= bytes_read
;
6999 extended_end
= line_ptr
+ extended_len
;
7000 extended_op
= read_1_byte (abfd
, line_ptr
);
7002 switch (extended_op
)
7004 case DW_LNE_end_sequence
:
7007 if (lh
->num_file_names
< file
)
7008 dwarf2_debug_line_missing_file_complaint ();
7011 lh
->file_names
[file
- 1].included_p
= 1;
7012 if (!decode_for_pst_p
)
7013 record_line (current_subfile
, 0, address
);
7016 case DW_LNE_set_address
:
7017 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
7018 line_ptr
+= bytes_read
;
7019 address
+= baseaddr
;
7021 case DW_LNE_define_file
:
7024 unsigned int dir_index
, mod_time
, length
;
7026 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
7027 line_ptr
+= bytes_read
;
7029 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7030 line_ptr
+= bytes_read
;
7032 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7033 line_ptr
+= bytes_read
;
7035 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7036 line_ptr
+= bytes_read
;
7037 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7041 complaint (&symfile_complaints
,
7042 _("mangled .debug_line section"));
7045 /* Make sure that we parsed the extended op correctly. If e.g.
7046 we expected a different address size than the producer used,
7047 we may have read the wrong number of bytes. */
7048 if (line_ptr
!= extended_end
)
7050 complaint (&symfile_complaints
,
7051 _("mangled .debug_line section"));
7056 if (lh
->num_file_names
< file
)
7057 dwarf2_debug_line_missing_file_complaint ();
7060 lh
->file_names
[file
- 1].included_p
= 1;
7061 if (!decode_for_pst_p
)
7063 if (last_subfile
!= current_subfile
)
7066 record_line (last_subfile
, 0, address
);
7067 last_subfile
= current_subfile
;
7069 record_line (current_subfile
, line
,
7070 check_cu_functions (address
, cu
));
7075 case DW_LNS_advance_pc
:
7076 address
+= lh
->minimum_instruction_length
7077 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7078 line_ptr
+= bytes_read
;
7080 case DW_LNS_advance_line
:
7081 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
7082 line_ptr
+= bytes_read
;
7084 case DW_LNS_set_file
:
7086 /* The arrays lh->include_dirs and lh->file_names are
7087 0-based, but the directory and file name numbers in
7088 the statement program are 1-based. */
7089 struct file_entry
*fe
;
7092 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7093 line_ptr
+= bytes_read
;
7094 if (lh
->num_file_names
< file
)
7095 dwarf2_debug_line_missing_file_complaint ();
7098 fe
= &lh
->file_names
[file
- 1];
7100 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7101 if (!decode_for_pst_p
)
7103 last_subfile
= current_subfile
;
7104 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7109 case DW_LNS_set_column
:
7110 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7111 line_ptr
+= bytes_read
;
7113 case DW_LNS_negate_stmt
:
7114 is_stmt
= (!is_stmt
);
7116 case DW_LNS_set_basic_block
:
7119 /* Add to the address register of the state machine the
7120 address increment value corresponding to special opcode
7121 255. I.e., this value is scaled by the minimum
7122 instruction length since special opcode 255 would have
7123 scaled the the increment. */
7124 case DW_LNS_const_add_pc
:
7125 address
+= (lh
->minimum_instruction_length
7126 * ((255 - lh
->opcode_base
) / lh
->line_range
));
7128 case DW_LNS_fixed_advance_pc
:
7129 address
+= read_2_bytes (abfd
, line_ptr
);
7134 /* Unknown standard opcode, ignore it. */
7137 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
7139 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7140 line_ptr
+= bytes_read
;
7147 if (decode_for_pst_p
)
7151 /* Now that we're done scanning the Line Header Program, we can
7152 create the psymtab of each included file. */
7153 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
7154 if (lh
->file_names
[file_index
].included_p
== 1)
7156 const struct file_entry fe
= lh
->file_names
[file_index
];
7157 char *include_name
= fe
.name
;
7158 char *dir_name
= NULL
;
7159 char *pst_filename
= pst
->filename
;
7162 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
7164 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
7166 include_name
= concat (dir_name
, SLASH_STRING
,
7167 include_name
, (char *)NULL
);
7168 make_cleanup (xfree
, include_name
);
7171 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
7173 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
7174 pst_filename
, (char *)NULL
);
7175 make_cleanup (xfree
, pst_filename
);
7178 if (strcmp (include_name
, pst_filename
) != 0)
7179 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
7184 /* Make sure a symtab is created for every file, even files
7185 which contain only variables (i.e. no code with associated
7189 struct file_entry
*fe
;
7191 for (i
= 0; i
< lh
->num_file_names
; i
++)
7194 fe
= &lh
->file_names
[i
];
7196 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7197 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7199 /* Skip the main file; we don't need it, and it must be
7200 allocated last, so that it will show up before the
7201 non-primary symtabs in the objfile's symtab list. */
7202 if (current_subfile
== first_subfile
)
7205 if (current_subfile
->symtab
== NULL
)
7206 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7208 fe
->symtab
= current_subfile
->symtab
;
7213 /* Start a subfile for DWARF. FILENAME is the name of the file and
7214 DIRNAME the name of the source directory which contains FILENAME
7215 or NULL if not known. COMP_DIR is the compilation directory for the
7216 linetable's compilation unit or NULL if not known.
7217 This routine tries to keep line numbers from identical absolute and
7218 relative file names in a common subfile.
7220 Using the `list' example from the GDB testsuite, which resides in
7221 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
7222 of /srcdir/list0.c yields the following debugging information for list0.c:
7224 DW_AT_name: /srcdir/list0.c
7225 DW_AT_comp_dir: /compdir
7226 files.files[0].name: list0.h
7227 files.files[0].dir: /srcdir
7228 files.files[1].name: list0.c
7229 files.files[1].dir: /srcdir
7231 The line number information for list0.c has to end up in a single
7232 subfile, so that `break /srcdir/list0.c:1' works as expected.
7233 start_subfile will ensure that this happens provided that we pass the
7234 concatenation of files.files[1].dir and files.files[1].name as the
7238 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
7242 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
7243 `start_symtab' will always pass the contents of DW_AT_comp_dir as
7244 second argument to start_subfile. To be consistent, we do the
7245 same here. In order not to lose the line information directory,
7246 we concatenate it to the filename when it makes sense.
7247 Note that the Dwarf3 standard says (speaking of filenames in line
7248 information): ``The directory index is ignored for file names
7249 that represent full path names''. Thus ignoring dirname in the
7250 `else' branch below isn't an issue. */
7252 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
7253 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
7255 fullname
= filename
;
7257 start_subfile (fullname
, comp_dir
);
7259 if (fullname
!= filename
)
7264 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
7265 struct dwarf2_cu
*cu
)
7267 struct objfile
*objfile
= cu
->objfile
;
7268 struct comp_unit_head
*cu_header
= &cu
->header
;
7270 /* NOTE drow/2003-01-30: There used to be a comment and some special
7271 code here to turn a symbol with DW_AT_external and a
7272 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
7273 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
7274 with some versions of binutils) where shared libraries could have
7275 relocations against symbols in their debug information - the
7276 minimal symbol would have the right address, but the debug info
7277 would not. It's no longer necessary, because we will explicitly
7278 apply relocations when we read in the debug information now. */
7280 /* A DW_AT_location attribute with no contents indicates that a
7281 variable has been optimized away. */
7282 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
7284 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7288 /* Handle one degenerate form of location expression specially, to
7289 preserve GDB's previous behavior when section offsets are
7290 specified. If this is just a DW_OP_addr then mark this symbol
7293 if (attr_form_is_block (attr
)
7294 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
7295 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
7299 SYMBOL_VALUE_ADDRESS (sym
) =
7300 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
7301 SYMBOL_CLASS (sym
) = LOC_STATIC
;
7302 fixup_symbol_section (sym
, objfile
);
7303 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
7304 SYMBOL_SECTION (sym
));
7308 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
7309 expression evaluator, and use LOC_COMPUTED only when necessary
7310 (i.e. when the value of a register or memory location is
7311 referenced, or a thread-local block, etc.). Then again, it might
7312 not be worthwhile. I'm assuming that it isn't unless performance
7313 or memory numbers show me otherwise. */
7315 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
7316 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
7319 /* Given a pointer to a DWARF information entry, figure out if we need
7320 to make a symbol table entry for it, and if so, create a new entry
7321 and return a pointer to it.
7322 If TYPE is NULL, determine symbol type from the die, otherwise
7323 used the passed type. */
7325 static struct symbol
*
7326 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
7328 struct objfile
*objfile
= cu
->objfile
;
7329 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7330 struct symbol
*sym
= NULL
;
7332 struct attribute
*attr
= NULL
;
7333 struct attribute
*attr2
= NULL
;
7336 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7338 if (die
->tag
!= DW_TAG_namespace
)
7339 name
= dwarf2_linkage_name (die
, cu
);
7341 name
= TYPE_NAME (type
);
7345 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
7346 sizeof (struct symbol
));
7347 OBJSTAT (objfile
, n_syms
++);
7348 memset (sym
, 0, sizeof (struct symbol
));
7350 /* Cache this symbol's name and the name's demangled form (if any). */
7351 SYMBOL_LANGUAGE (sym
) = cu
->language
;
7352 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
7354 /* Default assumptions.
7355 Use the passed type or decode it from the die. */
7356 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7357 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7359 SYMBOL_TYPE (sym
) = type
;
7361 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
7362 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
7365 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
7368 attr
= dwarf2_attr (die
, DW_AT_decl_file
, cu
);
7371 int file_index
= DW_UNSND (attr
);
7372 if (cu
->line_header
== NULL
7373 || file_index
> cu
->line_header
->num_file_names
)
7374 complaint (&symfile_complaints
,
7375 _("file index out of range"));
7376 else if (file_index
> 0)
7378 struct file_entry
*fe
;
7379 fe
= &cu
->line_header
->file_names
[file_index
- 1];
7380 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
7387 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7390 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
7392 SYMBOL_CLASS (sym
) = LOC_LABEL
;
7394 case DW_TAG_subprogram
:
7395 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7397 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
7398 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7399 if ((attr2
&& (DW_UNSND (attr2
) != 0))
7400 || cu
->language
== language_ada
)
7402 /* Subprograms marked external are stored as a global symbol.
7403 Ada subprograms, whether marked external or not, are always
7404 stored as a global symbol, because we want to be able to
7405 access them globally. For instance, we want to be able
7406 to break on a nested subprogram without having to
7407 specify the context. */
7408 add_symbol_to_list (sym
, &global_symbols
);
7412 add_symbol_to_list (sym
, cu
->list_in_scope
);
7415 case DW_TAG_variable
:
7416 /* Compilation with minimal debug info may result in variables
7417 with missing type entries. Change the misleading `void' type
7418 to something sensible. */
7419 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
7421 = builtin_type (gdbarch
)->nodebug_data_symbol
;
7423 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7426 dwarf2_const_value (attr
, sym
, cu
);
7427 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7428 if (attr2
&& (DW_UNSND (attr2
) != 0))
7429 add_symbol_to_list (sym
, &global_symbols
);
7431 add_symbol_to_list (sym
, cu
->list_in_scope
);
7434 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7437 var_decode_location (attr
, sym
, cu
);
7438 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7439 if (attr2
&& (DW_UNSND (attr2
) != 0))
7440 add_symbol_to_list (sym
, &global_symbols
);
7442 add_symbol_to_list (sym
, cu
->list_in_scope
);
7446 /* We do not know the address of this symbol.
7447 If it is an external symbol and we have type information
7448 for it, enter the symbol as a LOC_UNRESOLVED symbol.
7449 The address of the variable will then be determined from
7450 the minimal symbol table whenever the variable is
7452 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7453 if (attr2
&& (DW_UNSND (attr2
) != 0)
7454 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
7456 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
7457 add_symbol_to_list (sym
, &global_symbols
);
7461 case DW_TAG_formal_parameter
:
7462 SYMBOL_IS_ARGUMENT (sym
) = 1;
7463 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7466 var_decode_location (attr
, sym
, cu
);
7468 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7471 dwarf2_const_value (attr
, sym
, cu
);
7473 add_symbol_to_list (sym
, cu
->list_in_scope
);
7475 case DW_TAG_unspecified_parameters
:
7476 /* From varargs functions; gdb doesn't seem to have any
7477 interest in this information, so just ignore it for now.
7480 case DW_TAG_class_type
:
7481 case DW_TAG_interface_type
:
7482 case DW_TAG_structure_type
:
7483 case DW_TAG_union_type
:
7484 case DW_TAG_set_type
:
7485 case DW_TAG_enumeration_type
:
7486 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7487 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7489 /* Make sure that the symbol includes appropriate enclosing
7490 classes/namespaces in its name. These are calculated in
7491 read_structure_type, and the correct name is saved in
7494 if (cu
->language
== language_cplus
7495 || cu
->language
== language_java
)
7497 struct type
*type
= SYMBOL_TYPE (sym
);
7499 if (TYPE_TAG_NAME (type
) != NULL
)
7501 /* FIXME: carlton/2003-11-10: Should this use
7502 SYMBOL_SET_NAMES instead? (The same problem also
7503 arises further down in this function.) */
7504 /* The type's name is already allocated along with
7505 this objfile, so we don't need to duplicate it
7507 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
7512 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
7513 really ever be static objects: otherwise, if you try
7514 to, say, break of a class's method and you're in a file
7515 which doesn't mention that class, it won't work unless
7516 the check for all static symbols in lookup_symbol_aux
7517 saves you. See the OtherFileClass tests in
7518 gdb.c++/namespace.exp. */
7520 struct pending
**list_to_add
;
7522 list_to_add
= (cu
->list_in_scope
== &file_symbols
7523 && (cu
->language
== language_cplus
7524 || cu
->language
== language_java
)
7525 ? &global_symbols
: cu
->list_in_scope
);
7527 add_symbol_to_list (sym
, list_to_add
);
7529 /* The semantics of C++ state that "struct foo { ... }" also
7530 defines a typedef for "foo". A Java class declaration also
7531 defines a typedef for the class. */
7532 if (cu
->language
== language_cplus
7533 || cu
->language
== language_java
7534 || cu
->language
== language_ada
)
7536 /* The symbol's name is already allocated along with
7537 this objfile, so we don't need to duplicate it for
7539 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
7540 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
7544 case DW_TAG_typedef
:
7545 if (processing_has_namespace_info
7546 && processing_current_prefix
[0] != '\0')
7548 SYMBOL_LINKAGE_NAME (sym
) = typename_concat (&objfile
->objfile_obstack
,
7549 processing_current_prefix
,
7552 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7553 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7554 add_symbol_to_list (sym
, cu
->list_in_scope
);
7556 case DW_TAG_base_type
:
7557 case DW_TAG_subrange_type
:
7558 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7559 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7560 add_symbol_to_list (sym
, cu
->list_in_scope
);
7562 case DW_TAG_enumerator
:
7563 if (processing_has_namespace_info
7564 && processing_current_prefix
[0] != '\0')
7566 SYMBOL_LINKAGE_NAME (sym
) = typename_concat (&objfile
->objfile_obstack
,
7567 processing_current_prefix
,
7570 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7573 dwarf2_const_value (attr
, sym
, cu
);
7576 /* NOTE: carlton/2003-11-10: See comment above in the
7577 DW_TAG_class_type, etc. block. */
7579 struct pending
**list_to_add
;
7581 list_to_add
= (cu
->list_in_scope
== &file_symbols
7582 && (cu
->language
== language_cplus
7583 || cu
->language
== language_java
)
7584 ? &global_symbols
: cu
->list_in_scope
);
7586 add_symbol_to_list (sym
, list_to_add
);
7589 case DW_TAG_namespace
:
7590 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7591 add_symbol_to_list (sym
, &global_symbols
);
7594 /* Not a tag we recognize. Hopefully we aren't processing
7595 trash data, but since we must specifically ignore things
7596 we don't recognize, there is nothing else we should do at
7598 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
7599 dwarf_tag_name (die
->tag
));
7606 /* Copy constant value from an attribute to a symbol. */
7609 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
7610 struct dwarf2_cu
*cu
)
7612 struct objfile
*objfile
= cu
->objfile
;
7613 struct comp_unit_head
*cu_header
= &cu
->header
;
7614 struct dwarf_block
*blk
;
7619 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
7620 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
7621 cu_header
->addr_size
,
7622 TYPE_LENGTH (SYMBOL_TYPE
7624 SYMBOL_VALUE_BYTES (sym
) =
7625 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
7626 /* NOTE: cagney/2003-05-09: In-lined store_address call with
7627 it's body - store_unsigned_integer. */
7628 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
7630 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7633 /* DW_STRING is already allocated on the obstack, point directly
7635 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
7636 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7638 case DW_FORM_block1
:
7639 case DW_FORM_block2
:
7640 case DW_FORM_block4
:
7642 blk
= DW_BLOCK (attr
);
7643 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
7644 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
7646 TYPE_LENGTH (SYMBOL_TYPE
7648 SYMBOL_VALUE_BYTES (sym
) =
7649 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
7650 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
7651 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7654 /* The DW_AT_const_value attributes are supposed to carry the
7655 symbol's value "represented as it would be on the target
7656 architecture." By the time we get here, it's already been
7657 converted to host endianness, so we just need to sign- or
7658 zero-extend it as appropriate. */
7660 dwarf2_const_value_data (attr
, sym
, 8);
7663 dwarf2_const_value_data (attr
, sym
, 16);
7666 dwarf2_const_value_data (attr
, sym
, 32);
7669 dwarf2_const_value_data (attr
, sym
, 64);
7673 SYMBOL_VALUE (sym
) = DW_SND (attr
);
7674 SYMBOL_CLASS (sym
) = LOC_CONST
;
7678 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
7679 SYMBOL_CLASS (sym
) = LOC_CONST
;
7683 complaint (&symfile_complaints
,
7684 _("unsupported const value attribute form: '%s'"),
7685 dwarf_form_name (attr
->form
));
7686 SYMBOL_VALUE (sym
) = 0;
7687 SYMBOL_CLASS (sym
) = LOC_CONST
;
7693 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
7694 or zero-extend it as appropriate for the symbol's type. */
7696 dwarf2_const_value_data (struct attribute
*attr
,
7700 LONGEST l
= DW_UNSND (attr
);
7702 if (bits
< sizeof (l
) * 8)
7704 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
7705 l
&= ((LONGEST
) 1 << bits
) - 1;
7707 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
7710 SYMBOL_VALUE (sym
) = l
;
7711 SYMBOL_CLASS (sym
) = LOC_CONST
;
7715 /* Return the type of the die in question using its DW_AT_type attribute. */
7717 static struct type
*
7718 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7720 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7722 struct attribute
*type_attr
;
7723 struct die_info
*type_die
;
7725 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
7728 /* A missing DW_AT_type represents a void type. */
7729 return builtin_type (gdbarch
)->builtin_void
;
7732 type_die
= follow_die_ref (die
, type_attr
, cu
);
7734 type
= tag_type_to_type (type_die
, cu
);
7737 dump_die (type_die
);
7738 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
7744 /* Return the containing type of the die in question using its
7745 DW_AT_containing_type attribute. */
7747 static struct type
*
7748 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7750 struct type
*type
= NULL
;
7751 struct attribute
*type_attr
;
7752 struct die_info
*type_die
= NULL
;
7754 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
7757 type_die
= follow_die_ref (die
, type_attr
, cu
);
7758 type
= tag_type_to_type (type_die
, cu
);
7763 dump_die (type_die
);
7764 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
7770 static struct type
*
7771 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7773 struct type
*this_type
;
7775 this_type
= read_type_die (die
, cu
);
7779 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
7785 static struct type
*
7786 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7789 const char *old_prefix
;
7790 struct cleanup
*back_to
;
7791 struct type
*this_type
;
7793 this_type
= get_die_type (die
, cu
);
7797 prefix
= determine_prefix (die
, cu
);
7798 old_prefix
= processing_current_prefix
;
7799 back_to
= make_cleanup (xfree
, prefix
);
7800 processing_current_prefix
= prefix
;
7804 case DW_TAG_class_type
:
7805 case DW_TAG_interface_type
:
7806 case DW_TAG_structure_type
:
7807 case DW_TAG_union_type
:
7808 this_type
= read_structure_type (die
, cu
);
7810 case DW_TAG_enumeration_type
:
7811 this_type
= read_enumeration_type (die
, cu
);
7813 case DW_TAG_subprogram
:
7814 case DW_TAG_subroutine_type
:
7815 this_type
= read_subroutine_type (die
, cu
);
7817 case DW_TAG_array_type
:
7818 this_type
= read_array_type (die
, cu
);
7820 case DW_TAG_set_type
:
7821 this_type
= read_set_type (die
, cu
);
7823 case DW_TAG_pointer_type
:
7824 this_type
= read_tag_pointer_type (die
, cu
);
7826 case DW_TAG_ptr_to_member_type
:
7827 this_type
= read_tag_ptr_to_member_type (die
, cu
);
7829 case DW_TAG_reference_type
:
7830 this_type
= read_tag_reference_type (die
, cu
);
7832 case DW_TAG_const_type
:
7833 this_type
= read_tag_const_type (die
, cu
);
7835 case DW_TAG_volatile_type
:
7836 this_type
= read_tag_volatile_type (die
, cu
);
7838 case DW_TAG_string_type
:
7839 this_type
= read_tag_string_type (die
, cu
);
7841 case DW_TAG_typedef
:
7842 this_type
= read_typedef (die
, cu
);
7844 case DW_TAG_subrange_type
:
7845 this_type
= read_subrange_type (die
, cu
);
7847 case DW_TAG_base_type
:
7848 this_type
= read_base_type (die
, cu
);
7850 case DW_TAG_unspecified_type
:
7851 this_type
= read_unspecified_type (die
, cu
);
7854 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
7855 dwarf_tag_name (die
->tag
));
7859 processing_current_prefix
= old_prefix
;
7860 do_cleanups (back_to
);
7864 /* Return the name of the namespace/class that DIE is defined within,
7865 or "" if we can't tell. The caller should xfree the result. */
7867 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
7868 therein) for an example of how to use this function to deal with
7869 DW_AT_specification. */
7872 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
7874 struct die_info
*parent
;
7876 if (cu
->language
!= language_cplus
7877 && cu
->language
!= language_java
)
7880 parent
= die
->parent
;
7884 return xstrdup ("");
7888 switch (parent
->tag
) {
7889 case DW_TAG_namespace
:
7891 /* FIXME: carlton/2004-03-05: Should I follow extension dies
7892 before doing this check? */
7893 struct type
*parent_type
= get_die_type (parent
, cu
);
7894 if (parent_type
!= NULL
&& TYPE_TAG_NAME (parent_type
) != NULL
)
7896 return xstrdup (TYPE_TAG_NAME (parent_type
));
7901 char *parent_prefix
= determine_prefix (parent
, cu
);
7902 char *retval
= typename_concat (NULL
, parent_prefix
,
7903 namespace_name (parent
, &dummy
,
7906 xfree (parent_prefix
);
7911 case DW_TAG_class_type
:
7912 case DW_TAG_interface_type
:
7913 case DW_TAG_structure_type
:
7915 struct type
*parent_type
= get_die_type (parent
, cu
);
7916 if (parent_type
!= NULL
&& TYPE_TAG_NAME (parent_type
) != NULL
)
7918 return xstrdup (TYPE_TAG_NAME (parent_type
));
7922 const char *old_prefix
= processing_current_prefix
;
7923 char *new_prefix
= determine_prefix (parent
, cu
);
7926 processing_current_prefix
= new_prefix
;
7927 retval
= determine_class_name (parent
, cu
);
7928 processing_current_prefix
= old_prefix
;
7935 return determine_prefix (parent
, cu
);
7940 /* Return a newly-allocated string formed by concatenating PREFIX and
7941 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
7942 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
7943 perform an obconcat, otherwise allocate storage for the result. The CU argument
7944 is used to determine the language and hence, the appropriate separator. */
7946 #define MAX_SEP_LEN 2 /* sizeof ("::") */
7949 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
7950 struct dwarf2_cu
*cu
)
7954 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
7956 else if (cu
->language
== language_java
)
7963 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
7968 strcpy (retval
, prefix
);
7969 strcat (retval
, sep
);
7972 strcat (retval
, suffix
);
7978 /* We have an obstack. */
7979 return obconcat (obs
, prefix
, sep
, suffix
);
7983 /* Return sibling of die, NULL if no sibling. */
7985 static struct die_info
*
7986 sibling_die (struct die_info
*die
)
7988 return die
->sibling
;
7991 /* Get linkage name of a die, return NULL if not found. */
7994 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
7996 struct attribute
*attr
;
7998 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7999 if (attr
&& DW_STRING (attr
))
8000 return DW_STRING (attr
);
8001 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8002 if (attr
&& DW_STRING (attr
))
8003 return DW_STRING (attr
);
8007 /* Get name of a die, return NULL if not found. */
8010 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8012 struct attribute
*attr
;
8014 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8015 if (attr
&& DW_STRING (attr
))
8016 return DW_STRING (attr
);
8020 /* Return the die that this die in an extension of, or NULL if there
8023 static struct die_info
*
8024 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
*cu
)
8026 struct attribute
*attr
;
8028 attr
= dwarf2_attr (die
, DW_AT_extension
, cu
);
8032 return follow_die_ref (die
, attr
, cu
);
8035 /* Convert a DIE tag into its string name. */
8038 dwarf_tag_name (unsigned tag
)
8042 case DW_TAG_padding
:
8043 return "DW_TAG_padding";
8044 case DW_TAG_array_type
:
8045 return "DW_TAG_array_type";
8046 case DW_TAG_class_type
:
8047 return "DW_TAG_class_type";
8048 case DW_TAG_entry_point
:
8049 return "DW_TAG_entry_point";
8050 case DW_TAG_enumeration_type
:
8051 return "DW_TAG_enumeration_type";
8052 case DW_TAG_formal_parameter
:
8053 return "DW_TAG_formal_parameter";
8054 case DW_TAG_imported_declaration
:
8055 return "DW_TAG_imported_declaration";
8057 return "DW_TAG_label";
8058 case DW_TAG_lexical_block
:
8059 return "DW_TAG_lexical_block";
8061 return "DW_TAG_member";
8062 case DW_TAG_pointer_type
:
8063 return "DW_TAG_pointer_type";
8064 case DW_TAG_reference_type
:
8065 return "DW_TAG_reference_type";
8066 case DW_TAG_compile_unit
:
8067 return "DW_TAG_compile_unit";
8068 case DW_TAG_string_type
:
8069 return "DW_TAG_string_type";
8070 case DW_TAG_structure_type
:
8071 return "DW_TAG_structure_type";
8072 case DW_TAG_subroutine_type
:
8073 return "DW_TAG_subroutine_type";
8074 case DW_TAG_typedef
:
8075 return "DW_TAG_typedef";
8076 case DW_TAG_union_type
:
8077 return "DW_TAG_union_type";
8078 case DW_TAG_unspecified_parameters
:
8079 return "DW_TAG_unspecified_parameters";
8080 case DW_TAG_variant
:
8081 return "DW_TAG_variant";
8082 case DW_TAG_common_block
:
8083 return "DW_TAG_common_block";
8084 case DW_TAG_common_inclusion
:
8085 return "DW_TAG_common_inclusion";
8086 case DW_TAG_inheritance
:
8087 return "DW_TAG_inheritance";
8088 case DW_TAG_inlined_subroutine
:
8089 return "DW_TAG_inlined_subroutine";
8091 return "DW_TAG_module";
8092 case DW_TAG_ptr_to_member_type
:
8093 return "DW_TAG_ptr_to_member_type";
8094 case DW_TAG_set_type
:
8095 return "DW_TAG_set_type";
8096 case DW_TAG_subrange_type
:
8097 return "DW_TAG_subrange_type";
8098 case DW_TAG_with_stmt
:
8099 return "DW_TAG_with_stmt";
8100 case DW_TAG_access_declaration
:
8101 return "DW_TAG_access_declaration";
8102 case DW_TAG_base_type
:
8103 return "DW_TAG_base_type";
8104 case DW_TAG_catch_block
:
8105 return "DW_TAG_catch_block";
8106 case DW_TAG_const_type
:
8107 return "DW_TAG_const_type";
8108 case DW_TAG_constant
:
8109 return "DW_TAG_constant";
8110 case DW_TAG_enumerator
:
8111 return "DW_TAG_enumerator";
8112 case DW_TAG_file_type
:
8113 return "DW_TAG_file_type";
8115 return "DW_TAG_friend";
8116 case DW_TAG_namelist
:
8117 return "DW_TAG_namelist";
8118 case DW_TAG_namelist_item
:
8119 return "DW_TAG_namelist_item";
8120 case DW_TAG_packed_type
:
8121 return "DW_TAG_packed_type";
8122 case DW_TAG_subprogram
:
8123 return "DW_TAG_subprogram";
8124 case DW_TAG_template_type_param
:
8125 return "DW_TAG_template_type_param";
8126 case DW_TAG_template_value_param
:
8127 return "DW_TAG_template_value_param";
8128 case DW_TAG_thrown_type
:
8129 return "DW_TAG_thrown_type";
8130 case DW_TAG_try_block
:
8131 return "DW_TAG_try_block";
8132 case DW_TAG_variant_part
:
8133 return "DW_TAG_variant_part";
8134 case DW_TAG_variable
:
8135 return "DW_TAG_variable";
8136 case DW_TAG_volatile_type
:
8137 return "DW_TAG_volatile_type";
8138 case DW_TAG_dwarf_procedure
:
8139 return "DW_TAG_dwarf_procedure";
8140 case DW_TAG_restrict_type
:
8141 return "DW_TAG_restrict_type";
8142 case DW_TAG_interface_type
:
8143 return "DW_TAG_interface_type";
8144 case DW_TAG_namespace
:
8145 return "DW_TAG_namespace";
8146 case DW_TAG_imported_module
:
8147 return "DW_TAG_imported_module";
8148 case DW_TAG_unspecified_type
:
8149 return "DW_TAG_unspecified_type";
8150 case DW_TAG_partial_unit
:
8151 return "DW_TAG_partial_unit";
8152 case DW_TAG_imported_unit
:
8153 return "DW_TAG_imported_unit";
8154 case DW_TAG_condition
:
8155 return "DW_TAG_condition";
8156 case DW_TAG_shared_type
:
8157 return "DW_TAG_shared_type";
8158 case DW_TAG_MIPS_loop
:
8159 return "DW_TAG_MIPS_loop";
8160 case DW_TAG_HP_array_descriptor
:
8161 return "DW_TAG_HP_array_descriptor";
8162 case DW_TAG_format_label
:
8163 return "DW_TAG_format_label";
8164 case DW_TAG_function_template
:
8165 return "DW_TAG_function_template";
8166 case DW_TAG_class_template
:
8167 return "DW_TAG_class_template";
8168 case DW_TAG_GNU_BINCL
:
8169 return "DW_TAG_GNU_BINCL";
8170 case DW_TAG_GNU_EINCL
:
8171 return "DW_TAG_GNU_EINCL";
8172 case DW_TAG_upc_shared_type
:
8173 return "DW_TAG_upc_shared_type";
8174 case DW_TAG_upc_strict_type
:
8175 return "DW_TAG_upc_strict_type";
8176 case DW_TAG_upc_relaxed_type
:
8177 return "DW_TAG_upc_relaxed_type";
8178 case DW_TAG_PGI_kanji_type
:
8179 return "DW_TAG_PGI_kanji_type";
8180 case DW_TAG_PGI_interface_block
:
8181 return "DW_TAG_PGI_interface_block";
8183 return "DW_TAG_<unknown>";
8187 /* Convert a DWARF attribute code into its string name. */
8190 dwarf_attr_name (unsigned attr
)
8195 return "DW_AT_sibling";
8196 case DW_AT_location
:
8197 return "DW_AT_location";
8199 return "DW_AT_name";
8200 case DW_AT_ordering
:
8201 return "DW_AT_ordering";
8202 case DW_AT_subscr_data
:
8203 return "DW_AT_subscr_data";
8204 case DW_AT_byte_size
:
8205 return "DW_AT_byte_size";
8206 case DW_AT_bit_offset
:
8207 return "DW_AT_bit_offset";
8208 case DW_AT_bit_size
:
8209 return "DW_AT_bit_size";
8210 case DW_AT_element_list
:
8211 return "DW_AT_element_list";
8212 case DW_AT_stmt_list
:
8213 return "DW_AT_stmt_list";
8215 return "DW_AT_low_pc";
8217 return "DW_AT_high_pc";
8218 case DW_AT_language
:
8219 return "DW_AT_language";
8221 return "DW_AT_member";
8223 return "DW_AT_discr";
8224 case DW_AT_discr_value
:
8225 return "DW_AT_discr_value";
8226 case DW_AT_visibility
:
8227 return "DW_AT_visibility";
8229 return "DW_AT_import";
8230 case DW_AT_string_length
:
8231 return "DW_AT_string_length";
8232 case DW_AT_common_reference
:
8233 return "DW_AT_common_reference";
8234 case DW_AT_comp_dir
:
8235 return "DW_AT_comp_dir";
8236 case DW_AT_const_value
:
8237 return "DW_AT_const_value";
8238 case DW_AT_containing_type
:
8239 return "DW_AT_containing_type";
8240 case DW_AT_default_value
:
8241 return "DW_AT_default_value";
8243 return "DW_AT_inline";
8244 case DW_AT_is_optional
:
8245 return "DW_AT_is_optional";
8246 case DW_AT_lower_bound
:
8247 return "DW_AT_lower_bound";
8248 case DW_AT_producer
:
8249 return "DW_AT_producer";
8250 case DW_AT_prototyped
:
8251 return "DW_AT_prototyped";
8252 case DW_AT_return_addr
:
8253 return "DW_AT_return_addr";
8254 case DW_AT_start_scope
:
8255 return "DW_AT_start_scope";
8256 case DW_AT_bit_stride
:
8257 return "DW_AT_bit_stride";
8258 case DW_AT_upper_bound
:
8259 return "DW_AT_upper_bound";
8260 case DW_AT_abstract_origin
:
8261 return "DW_AT_abstract_origin";
8262 case DW_AT_accessibility
:
8263 return "DW_AT_accessibility";
8264 case DW_AT_address_class
:
8265 return "DW_AT_address_class";
8266 case DW_AT_artificial
:
8267 return "DW_AT_artificial";
8268 case DW_AT_base_types
:
8269 return "DW_AT_base_types";
8270 case DW_AT_calling_convention
:
8271 return "DW_AT_calling_convention";
8273 return "DW_AT_count";
8274 case DW_AT_data_member_location
:
8275 return "DW_AT_data_member_location";
8276 case DW_AT_decl_column
:
8277 return "DW_AT_decl_column";
8278 case DW_AT_decl_file
:
8279 return "DW_AT_decl_file";
8280 case DW_AT_decl_line
:
8281 return "DW_AT_decl_line";
8282 case DW_AT_declaration
:
8283 return "DW_AT_declaration";
8284 case DW_AT_discr_list
:
8285 return "DW_AT_discr_list";
8286 case DW_AT_encoding
:
8287 return "DW_AT_encoding";
8288 case DW_AT_external
:
8289 return "DW_AT_external";
8290 case DW_AT_frame_base
:
8291 return "DW_AT_frame_base";
8293 return "DW_AT_friend";
8294 case DW_AT_identifier_case
:
8295 return "DW_AT_identifier_case";
8296 case DW_AT_macro_info
:
8297 return "DW_AT_macro_info";
8298 case DW_AT_namelist_items
:
8299 return "DW_AT_namelist_items";
8300 case DW_AT_priority
:
8301 return "DW_AT_priority";
8303 return "DW_AT_segment";
8304 case DW_AT_specification
:
8305 return "DW_AT_specification";
8306 case DW_AT_static_link
:
8307 return "DW_AT_static_link";
8309 return "DW_AT_type";
8310 case DW_AT_use_location
:
8311 return "DW_AT_use_location";
8312 case DW_AT_variable_parameter
:
8313 return "DW_AT_variable_parameter";
8314 case DW_AT_virtuality
:
8315 return "DW_AT_virtuality";
8316 case DW_AT_vtable_elem_location
:
8317 return "DW_AT_vtable_elem_location";
8318 /* DWARF 3 values. */
8319 case DW_AT_allocated
:
8320 return "DW_AT_allocated";
8321 case DW_AT_associated
:
8322 return "DW_AT_associated";
8323 case DW_AT_data_location
:
8324 return "DW_AT_data_location";
8325 case DW_AT_byte_stride
:
8326 return "DW_AT_byte_stride";
8327 case DW_AT_entry_pc
:
8328 return "DW_AT_entry_pc";
8329 case DW_AT_use_UTF8
:
8330 return "DW_AT_use_UTF8";
8331 case DW_AT_extension
:
8332 return "DW_AT_extension";
8334 return "DW_AT_ranges";
8335 case DW_AT_trampoline
:
8336 return "DW_AT_trampoline";
8337 case DW_AT_call_column
:
8338 return "DW_AT_call_column";
8339 case DW_AT_call_file
:
8340 return "DW_AT_call_file";
8341 case DW_AT_call_line
:
8342 return "DW_AT_call_line";
8343 case DW_AT_description
:
8344 return "DW_AT_description";
8345 case DW_AT_binary_scale
:
8346 return "DW_AT_binary_scale";
8347 case DW_AT_decimal_scale
:
8348 return "DW_AT_decimal_scale";
8350 return "DW_AT_small";
8351 case DW_AT_decimal_sign
:
8352 return "DW_AT_decimal_sign";
8353 case DW_AT_digit_count
:
8354 return "DW_AT_digit_count";
8355 case DW_AT_picture_string
:
8356 return "DW_AT_picture_string";
8358 return "DW_AT_mutable";
8359 case DW_AT_threads_scaled
:
8360 return "DW_AT_threads_scaled";
8361 case DW_AT_explicit
:
8362 return "DW_AT_explicit";
8363 case DW_AT_object_pointer
:
8364 return "DW_AT_object_pointer";
8365 case DW_AT_endianity
:
8366 return "DW_AT_endianity";
8367 case DW_AT_elemental
:
8368 return "DW_AT_elemental";
8370 return "DW_AT_pure";
8371 case DW_AT_recursive
:
8372 return "DW_AT_recursive";
8374 /* SGI/MIPS extensions. */
8375 case DW_AT_MIPS_fde
:
8376 return "DW_AT_MIPS_fde";
8377 case DW_AT_MIPS_loop_begin
:
8378 return "DW_AT_MIPS_loop_begin";
8379 case DW_AT_MIPS_tail_loop_begin
:
8380 return "DW_AT_MIPS_tail_loop_begin";
8381 case DW_AT_MIPS_epilog_begin
:
8382 return "DW_AT_MIPS_epilog_begin";
8383 case DW_AT_MIPS_loop_unroll_factor
:
8384 return "DW_AT_MIPS_loop_unroll_factor";
8385 case DW_AT_MIPS_software_pipeline_depth
:
8386 return "DW_AT_MIPS_software_pipeline_depth";
8387 case DW_AT_MIPS_linkage_name
:
8388 return "DW_AT_MIPS_linkage_name";
8389 case DW_AT_MIPS_stride
:
8390 return "DW_AT_MIPS_stride";
8391 case DW_AT_MIPS_abstract_name
:
8392 return "DW_AT_MIPS_abstract_name";
8393 case DW_AT_MIPS_clone_origin
:
8394 return "DW_AT_MIPS_clone_origin";
8395 case DW_AT_MIPS_has_inlines
:
8396 return "DW_AT_MIPS_has_inlines";
8398 /* HP extensions. */
8399 case DW_AT_HP_block_index
:
8400 return "DW_AT_HP_block_index";
8401 case DW_AT_HP_unmodifiable
:
8402 return "DW_AT_HP_unmodifiable";
8403 case DW_AT_HP_actuals_stmt_list
:
8404 return "DW_AT_HP_actuals_stmt_list";
8405 case DW_AT_HP_proc_per_section
:
8406 return "DW_AT_HP_proc_per_section";
8407 case DW_AT_HP_raw_data_ptr
:
8408 return "DW_AT_HP_raw_data_ptr";
8409 case DW_AT_HP_pass_by_reference
:
8410 return "DW_AT_HP_pass_by_reference";
8411 case DW_AT_HP_opt_level
:
8412 return "DW_AT_HP_opt_level";
8413 case DW_AT_HP_prof_version_id
:
8414 return "DW_AT_HP_prof_version_id";
8415 case DW_AT_HP_opt_flags
:
8416 return "DW_AT_HP_opt_flags";
8417 case DW_AT_HP_cold_region_low_pc
:
8418 return "DW_AT_HP_cold_region_low_pc";
8419 case DW_AT_HP_cold_region_high_pc
:
8420 return "DW_AT_HP_cold_region_high_pc";
8421 case DW_AT_HP_all_variables_modifiable
:
8422 return "DW_AT_HP_all_variables_modifiable";
8423 case DW_AT_HP_linkage_name
:
8424 return "DW_AT_HP_linkage_name";
8425 case DW_AT_HP_prof_flags
:
8426 return "DW_AT_HP_prof_flags";
8427 /* GNU extensions. */
8428 case DW_AT_sf_names
:
8429 return "DW_AT_sf_names";
8430 case DW_AT_src_info
:
8431 return "DW_AT_src_info";
8432 case DW_AT_mac_info
:
8433 return "DW_AT_mac_info";
8434 case DW_AT_src_coords
:
8435 return "DW_AT_src_coords";
8436 case DW_AT_body_begin
:
8437 return "DW_AT_body_begin";
8438 case DW_AT_body_end
:
8439 return "DW_AT_body_end";
8440 case DW_AT_GNU_vector
:
8441 return "DW_AT_GNU_vector";
8442 /* VMS extensions. */
8443 case DW_AT_VMS_rtnbeg_pd_address
:
8444 return "DW_AT_VMS_rtnbeg_pd_address";
8445 /* UPC extension. */
8446 case DW_AT_upc_threads_scaled
:
8447 return "DW_AT_upc_threads_scaled";
8448 /* PGI (STMicroelectronics) extensions. */
8449 case DW_AT_PGI_lbase
:
8450 return "DW_AT_PGI_lbase";
8451 case DW_AT_PGI_soffset
:
8452 return "DW_AT_PGI_soffset";
8453 case DW_AT_PGI_lstride
:
8454 return "DW_AT_PGI_lstride";
8456 return "DW_AT_<unknown>";
8460 /* Convert a DWARF value form code into its string name. */
8463 dwarf_form_name (unsigned form
)
8468 return "DW_FORM_addr";
8469 case DW_FORM_block2
:
8470 return "DW_FORM_block2";
8471 case DW_FORM_block4
:
8472 return "DW_FORM_block4";
8474 return "DW_FORM_data2";
8476 return "DW_FORM_data4";
8478 return "DW_FORM_data8";
8479 case DW_FORM_string
:
8480 return "DW_FORM_string";
8482 return "DW_FORM_block";
8483 case DW_FORM_block1
:
8484 return "DW_FORM_block1";
8486 return "DW_FORM_data1";
8488 return "DW_FORM_flag";
8490 return "DW_FORM_sdata";
8492 return "DW_FORM_strp";
8494 return "DW_FORM_udata";
8495 case DW_FORM_ref_addr
:
8496 return "DW_FORM_ref_addr";
8498 return "DW_FORM_ref1";
8500 return "DW_FORM_ref2";
8502 return "DW_FORM_ref4";
8504 return "DW_FORM_ref8";
8505 case DW_FORM_ref_udata
:
8506 return "DW_FORM_ref_udata";
8507 case DW_FORM_indirect
:
8508 return "DW_FORM_indirect";
8510 return "DW_FORM_<unknown>";
8514 /* Convert a DWARF stack opcode into its string name. */
8517 dwarf_stack_op_name (unsigned op
)
8522 return "DW_OP_addr";
8524 return "DW_OP_deref";
8526 return "DW_OP_const1u";
8528 return "DW_OP_const1s";
8530 return "DW_OP_const2u";
8532 return "DW_OP_const2s";
8534 return "DW_OP_const4u";
8536 return "DW_OP_const4s";
8538 return "DW_OP_const8u";
8540 return "DW_OP_const8s";
8542 return "DW_OP_constu";
8544 return "DW_OP_consts";
8548 return "DW_OP_drop";
8550 return "DW_OP_over";
8552 return "DW_OP_pick";
8554 return "DW_OP_swap";
8558 return "DW_OP_xderef";
8566 return "DW_OP_minus";
8578 return "DW_OP_plus";
8579 case DW_OP_plus_uconst
:
8580 return "DW_OP_plus_uconst";
8586 return "DW_OP_shra";
8604 return "DW_OP_skip";
8606 return "DW_OP_lit0";
8608 return "DW_OP_lit1";
8610 return "DW_OP_lit2";
8612 return "DW_OP_lit3";
8614 return "DW_OP_lit4";
8616 return "DW_OP_lit5";
8618 return "DW_OP_lit6";
8620 return "DW_OP_lit7";
8622 return "DW_OP_lit8";
8624 return "DW_OP_lit9";
8626 return "DW_OP_lit10";
8628 return "DW_OP_lit11";
8630 return "DW_OP_lit12";
8632 return "DW_OP_lit13";
8634 return "DW_OP_lit14";
8636 return "DW_OP_lit15";
8638 return "DW_OP_lit16";
8640 return "DW_OP_lit17";
8642 return "DW_OP_lit18";
8644 return "DW_OP_lit19";
8646 return "DW_OP_lit20";
8648 return "DW_OP_lit21";
8650 return "DW_OP_lit22";
8652 return "DW_OP_lit23";
8654 return "DW_OP_lit24";
8656 return "DW_OP_lit25";
8658 return "DW_OP_lit26";
8660 return "DW_OP_lit27";
8662 return "DW_OP_lit28";
8664 return "DW_OP_lit29";
8666 return "DW_OP_lit30";
8668 return "DW_OP_lit31";
8670 return "DW_OP_reg0";
8672 return "DW_OP_reg1";
8674 return "DW_OP_reg2";
8676 return "DW_OP_reg3";
8678 return "DW_OP_reg4";
8680 return "DW_OP_reg5";
8682 return "DW_OP_reg6";
8684 return "DW_OP_reg7";
8686 return "DW_OP_reg8";
8688 return "DW_OP_reg9";
8690 return "DW_OP_reg10";
8692 return "DW_OP_reg11";
8694 return "DW_OP_reg12";
8696 return "DW_OP_reg13";
8698 return "DW_OP_reg14";
8700 return "DW_OP_reg15";
8702 return "DW_OP_reg16";
8704 return "DW_OP_reg17";
8706 return "DW_OP_reg18";
8708 return "DW_OP_reg19";
8710 return "DW_OP_reg20";
8712 return "DW_OP_reg21";
8714 return "DW_OP_reg22";
8716 return "DW_OP_reg23";
8718 return "DW_OP_reg24";
8720 return "DW_OP_reg25";
8722 return "DW_OP_reg26";
8724 return "DW_OP_reg27";
8726 return "DW_OP_reg28";
8728 return "DW_OP_reg29";
8730 return "DW_OP_reg30";
8732 return "DW_OP_reg31";
8734 return "DW_OP_breg0";
8736 return "DW_OP_breg1";
8738 return "DW_OP_breg2";
8740 return "DW_OP_breg3";
8742 return "DW_OP_breg4";
8744 return "DW_OP_breg5";
8746 return "DW_OP_breg6";
8748 return "DW_OP_breg7";
8750 return "DW_OP_breg8";
8752 return "DW_OP_breg9";
8754 return "DW_OP_breg10";
8756 return "DW_OP_breg11";
8758 return "DW_OP_breg12";
8760 return "DW_OP_breg13";
8762 return "DW_OP_breg14";
8764 return "DW_OP_breg15";
8766 return "DW_OP_breg16";
8768 return "DW_OP_breg17";
8770 return "DW_OP_breg18";
8772 return "DW_OP_breg19";
8774 return "DW_OP_breg20";
8776 return "DW_OP_breg21";
8778 return "DW_OP_breg22";
8780 return "DW_OP_breg23";
8782 return "DW_OP_breg24";
8784 return "DW_OP_breg25";
8786 return "DW_OP_breg26";
8788 return "DW_OP_breg27";
8790 return "DW_OP_breg28";
8792 return "DW_OP_breg29";
8794 return "DW_OP_breg30";
8796 return "DW_OP_breg31";
8798 return "DW_OP_regx";
8800 return "DW_OP_fbreg";
8802 return "DW_OP_bregx";
8804 return "DW_OP_piece";
8805 case DW_OP_deref_size
:
8806 return "DW_OP_deref_size";
8807 case DW_OP_xderef_size
:
8808 return "DW_OP_xderef_size";
8811 /* DWARF 3 extensions. */
8812 case DW_OP_push_object_address
:
8813 return "DW_OP_push_object_address";
8815 return "DW_OP_call2";
8817 return "DW_OP_call4";
8818 case DW_OP_call_ref
:
8819 return "DW_OP_call_ref";
8820 /* GNU extensions. */
8821 case DW_OP_form_tls_address
:
8822 return "DW_OP_form_tls_address";
8823 case DW_OP_call_frame_cfa
:
8824 return "DW_OP_call_frame_cfa";
8825 case DW_OP_bit_piece
:
8826 return "DW_OP_bit_piece";
8827 case DW_OP_GNU_push_tls_address
:
8828 return "DW_OP_GNU_push_tls_address";
8829 case DW_OP_GNU_uninit
:
8830 return "DW_OP_GNU_uninit";
8831 /* HP extensions. */
8832 case DW_OP_HP_is_value
:
8833 return "DW_OP_HP_is_value";
8834 case DW_OP_HP_fltconst4
:
8835 return "DW_OP_HP_fltconst4";
8836 case DW_OP_HP_fltconst8
:
8837 return "DW_OP_HP_fltconst8";
8838 case DW_OP_HP_mod_range
:
8839 return "DW_OP_HP_mod_range";
8840 case DW_OP_HP_unmod_range
:
8841 return "DW_OP_HP_unmod_range";
8843 return "DW_OP_HP_tls";
8845 return "OP_<unknown>";
8850 dwarf_bool_name (unsigned mybool
)
8858 /* Convert a DWARF type code into its string name. */
8861 dwarf_type_encoding_name (unsigned enc
)
8866 return "DW_ATE_void";
8867 case DW_ATE_address
:
8868 return "DW_ATE_address";
8869 case DW_ATE_boolean
:
8870 return "DW_ATE_boolean";
8871 case DW_ATE_complex_float
:
8872 return "DW_ATE_complex_float";
8874 return "DW_ATE_float";
8876 return "DW_ATE_signed";
8877 case DW_ATE_signed_char
:
8878 return "DW_ATE_signed_char";
8879 case DW_ATE_unsigned
:
8880 return "DW_ATE_unsigned";
8881 case DW_ATE_unsigned_char
:
8882 return "DW_ATE_unsigned_char";
8884 case DW_ATE_imaginary_float
:
8885 return "DW_ATE_imaginary_float";
8886 case DW_ATE_packed_decimal
:
8887 return "DW_ATE_packed_decimal";
8888 case DW_ATE_numeric_string
:
8889 return "DW_ATE_numeric_string";
8891 return "DW_ATE_edited";
8892 case DW_ATE_signed_fixed
:
8893 return "DW_ATE_signed_fixed";
8894 case DW_ATE_unsigned_fixed
:
8895 return "DW_ATE_unsigned_fixed";
8896 case DW_ATE_decimal_float
:
8897 return "DW_ATE_decimal_float";
8898 /* HP extensions. */
8899 case DW_ATE_HP_float80
:
8900 return "DW_ATE_HP_float80";
8901 case DW_ATE_HP_complex_float80
:
8902 return "DW_ATE_HP_complex_float80";
8903 case DW_ATE_HP_float128
:
8904 return "DW_ATE_HP_float128";
8905 case DW_ATE_HP_complex_float128
:
8906 return "DW_ATE_HP_complex_float128";
8907 case DW_ATE_HP_floathpintel
:
8908 return "DW_ATE_HP_floathpintel";
8909 case DW_ATE_HP_imaginary_float80
:
8910 return "DW_ATE_HP_imaginary_float80";
8911 case DW_ATE_HP_imaginary_float128
:
8912 return "DW_ATE_HP_imaginary_float128";
8914 return "DW_ATE_<unknown>";
8918 /* Convert a DWARF call frame info operation to its string name. */
8922 dwarf_cfi_name (unsigned cfi_opc
)
8926 case DW_CFA_advance_loc
:
8927 return "DW_CFA_advance_loc";
8929 return "DW_CFA_offset";
8930 case DW_CFA_restore
:
8931 return "DW_CFA_restore";
8933 return "DW_CFA_nop";
8934 case DW_CFA_set_loc
:
8935 return "DW_CFA_set_loc";
8936 case DW_CFA_advance_loc1
:
8937 return "DW_CFA_advance_loc1";
8938 case DW_CFA_advance_loc2
:
8939 return "DW_CFA_advance_loc2";
8940 case DW_CFA_advance_loc4
:
8941 return "DW_CFA_advance_loc4";
8942 case DW_CFA_offset_extended
:
8943 return "DW_CFA_offset_extended";
8944 case DW_CFA_restore_extended
:
8945 return "DW_CFA_restore_extended";
8946 case DW_CFA_undefined
:
8947 return "DW_CFA_undefined";
8948 case DW_CFA_same_value
:
8949 return "DW_CFA_same_value";
8950 case DW_CFA_register
:
8951 return "DW_CFA_register";
8952 case DW_CFA_remember_state
:
8953 return "DW_CFA_remember_state";
8954 case DW_CFA_restore_state
:
8955 return "DW_CFA_restore_state";
8956 case DW_CFA_def_cfa
:
8957 return "DW_CFA_def_cfa";
8958 case DW_CFA_def_cfa_register
:
8959 return "DW_CFA_def_cfa_register";
8960 case DW_CFA_def_cfa_offset
:
8961 return "DW_CFA_def_cfa_offset";
8963 case DW_CFA_def_cfa_expression
:
8964 return "DW_CFA_def_cfa_expression";
8965 case DW_CFA_expression
:
8966 return "DW_CFA_expression";
8967 case DW_CFA_offset_extended_sf
:
8968 return "DW_CFA_offset_extended_sf";
8969 case DW_CFA_def_cfa_sf
:
8970 return "DW_CFA_def_cfa_sf";
8971 case DW_CFA_def_cfa_offset_sf
:
8972 return "DW_CFA_def_cfa_offset_sf";
8973 case DW_CFA_val_offset
:
8974 return "DW_CFA_val_offset";
8975 case DW_CFA_val_offset_sf
:
8976 return "DW_CFA_val_offset_sf";
8977 case DW_CFA_val_expression
:
8978 return "DW_CFA_val_expression";
8979 /* SGI/MIPS specific. */
8980 case DW_CFA_MIPS_advance_loc8
:
8981 return "DW_CFA_MIPS_advance_loc8";
8982 /* GNU extensions. */
8983 case DW_CFA_GNU_window_save
:
8984 return "DW_CFA_GNU_window_save";
8985 case DW_CFA_GNU_args_size
:
8986 return "DW_CFA_GNU_args_size";
8987 case DW_CFA_GNU_negative_offset_extended
:
8988 return "DW_CFA_GNU_negative_offset_extended";
8990 return "DW_CFA_<unknown>";
8996 dump_die (struct die_info
*die
)
9000 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
9001 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
9002 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
9003 dwarf_bool_name (die
->child
!= NULL
));
9005 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
9006 for (i
= 0; i
< die
->num_attrs
; ++i
)
9008 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
9009 dwarf_attr_name (die
->attrs
[i
].name
),
9010 dwarf_form_name (die
->attrs
[i
].form
));
9011 switch (die
->attrs
[i
].form
)
9013 case DW_FORM_ref_addr
:
9015 fprintf_unfiltered (gdb_stderr
, "address: ");
9016 fputs_filtered (paddress (DW_ADDR (&die
->attrs
[i
])), gdb_stderr
);
9018 case DW_FORM_block2
:
9019 case DW_FORM_block4
:
9021 case DW_FORM_block1
:
9022 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
9027 fprintf_unfiltered (gdb_stderr
, "constant ref: %ld (adjusted)",
9028 (long) (DW_ADDR (&die
->attrs
[i
])));
9036 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
9038 case DW_FORM_string
:
9040 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
9041 DW_STRING (&die
->attrs
[i
])
9042 ? DW_STRING (&die
->attrs
[i
]) : "");
9045 if (DW_UNSND (&die
->attrs
[i
]))
9046 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
9048 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
9050 case DW_FORM_indirect
:
9051 /* the reader will have reduced the indirect form to
9052 the "base form" so this form should not occur */
9053 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
9056 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
9057 die
->attrs
[i
].form
);
9059 fprintf_unfiltered (gdb_stderr
, "\n");
9064 dump_die_list (struct die_info
*die
)
9069 if (die
->child
!= NULL
)
9070 dump_die_list (die
->child
);
9071 if (die
->sibling
!= NULL
)
9072 dump_die_list (die
->sibling
);
9077 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
9081 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
9087 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
9089 unsigned int result
= 0;
9093 case DW_FORM_ref_addr
:
9098 case DW_FORM_ref_udata
:
9099 result
= DW_ADDR (attr
);
9102 complaint (&symfile_complaints
,
9103 _("unsupported die ref attribute form: '%s'"),
9104 dwarf_form_name (attr
->form
));
9109 /* Return the constant value held by the given attribute. Return -1
9110 if the value held by the attribute is not constant. */
9113 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
9115 if (attr
->form
== DW_FORM_sdata
)
9116 return DW_SND (attr
);
9117 else if (attr
->form
== DW_FORM_udata
9118 || attr
->form
== DW_FORM_data1
9119 || attr
->form
== DW_FORM_data2
9120 || attr
->form
== DW_FORM_data4
9121 || attr
->form
== DW_FORM_data8
)
9122 return DW_UNSND (attr
);
9125 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
9126 dwarf_form_name (attr
->form
));
9127 return default_value
;
9131 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
9132 unit and add it to our queue. */
9135 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
9136 struct dwarf2_per_cu_data
*per_cu
)
9138 /* Mark the dependence relation so that we don't flush PER_CU
9140 dwarf2_add_dependence (this_cu
, per_cu
);
9142 /* If it's already on the queue, we have nothing to do. */
9146 /* If the compilation unit is already loaded, just mark it as
9148 if (per_cu
->cu
!= NULL
)
9150 per_cu
->cu
->last_used
= 0;
9154 /* Add it to the queue. */
9155 queue_comp_unit (per_cu
, this_cu
->objfile
);
9158 static struct die_info
*
9159 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
9160 struct dwarf2_cu
*cu
)
9162 struct die_info
*die
;
9163 unsigned int offset
;
9164 struct die_info temp_die
;
9165 struct dwarf2_cu
*target_cu
;
9167 offset
= dwarf2_get_ref_die_offset (attr
, cu
);
9169 if (DW_ADDR (attr
) < cu
->header
.offset
9170 || DW_ADDR (attr
) >= cu
->header
.offset
+ cu
->header
.length
)
9172 struct dwarf2_per_cu_data
*per_cu
;
9173 per_cu
= dwarf2_find_containing_comp_unit (DW_ADDR (attr
),
9176 /* If necessary, add it to the queue and load its DIEs. */
9177 maybe_queue_comp_unit (cu
, per_cu
);
9179 target_cu
= per_cu
->cu
;
9184 temp_die
.offset
= offset
;
9185 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
9189 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
9190 "at 0x%lx [in module %s]"),
9191 (long) offset
, (long) src_die
->offset
, cu
->objfile
->name
);
9194 /* Decode simple location descriptions.
9195 Given a pointer to a dwarf block that defines a location, compute
9196 the location and return the value.
9198 NOTE drow/2003-11-18: This function is called in two situations
9199 now: for the address of static or global variables (partial symbols
9200 only) and for offsets into structures which are expected to be
9201 (more or less) constant. The partial symbol case should go away,
9202 and only the constant case should remain. That will let this
9203 function complain more accurately. A few special modes are allowed
9204 without complaint for global variables (for instance, global
9205 register values and thread-local values).
9207 A location description containing no operations indicates that the
9208 object is optimized out. The return value is 0 for that case.
9209 FIXME drow/2003-11-16: No callers check for this case any more; soon all
9210 callers will only want a very basic result and this can become a
9213 Note that stack[0] is unused except as a default error return.
9214 Note that stack overflow is not yet handled. */
9217 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
9219 struct objfile
*objfile
= cu
->objfile
;
9220 struct comp_unit_head
*cu_header
= &cu
->header
;
9222 int size
= blk
->size
;
9223 gdb_byte
*data
= blk
->data
;
9224 CORE_ADDR stack
[64];
9226 unsigned int bytes_read
, unsnd
;
9270 stack
[++stacki
] = op
- DW_OP_lit0
;
9305 stack
[++stacki
] = op
- DW_OP_reg0
;
9307 dwarf2_complex_location_expr_complaint ();
9311 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9313 stack
[++stacki
] = unsnd
;
9315 dwarf2_complex_location_expr_complaint ();
9319 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
9325 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
9330 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
9335 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
9340 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
9345 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
9350 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
9355 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
9361 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
9366 stack
[stacki
+ 1] = stack
[stacki
];
9371 stack
[stacki
- 1] += stack
[stacki
];
9375 case DW_OP_plus_uconst
:
9376 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9381 stack
[stacki
- 1] -= stack
[stacki
];
9386 /* If we're not the last op, then we definitely can't encode
9387 this using GDB's address_class enum. This is valid for partial
9388 global symbols, although the variable's address will be bogus
9391 dwarf2_complex_location_expr_complaint ();
9394 case DW_OP_GNU_push_tls_address
:
9395 /* The top of the stack has the offset from the beginning
9396 of the thread control block at which the variable is located. */
9397 /* Nothing should follow this operator, so the top of stack would
9399 /* This is valid for partial global symbols, but the variable's
9400 address will be bogus in the psymtab. */
9402 dwarf2_complex_location_expr_complaint ();
9405 case DW_OP_GNU_uninit
:
9409 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
9410 dwarf_stack_op_name (op
));
9411 return (stack
[stacki
]);
9414 return (stack
[stacki
]);
9417 /* memory allocation interface */
9419 static struct dwarf_block
*
9420 dwarf_alloc_block (struct dwarf2_cu
*cu
)
9422 struct dwarf_block
*blk
;
9424 blk
= (struct dwarf_block
*)
9425 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
9429 static struct abbrev_info
*
9430 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
9432 struct abbrev_info
*abbrev
;
9434 abbrev
= (struct abbrev_info
*)
9435 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
9436 memset (abbrev
, 0, sizeof (struct abbrev_info
));
9440 static struct die_info
*
9441 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
9443 struct die_info
*die
;
9444 size_t size
= sizeof (struct die_info
);
9447 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
9449 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
9450 memset (die
, 0, sizeof (struct die_info
));
9455 /* Macro support. */
9458 /* Return the full name of file number I in *LH's file name table.
9459 Use COMP_DIR as the name of the current directory of the
9460 compilation. The result is allocated using xmalloc; the caller is
9461 responsible for freeing it. */
9463 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
9465 /* Is the file number a valid index into the line header's file name
9466 table? Remember that file numbers start with one, not zero. */
9467 if (1 <= file
&& file
<= lh
->num_file_names
)
9469 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9471 if (IS_ABSOLUTE_PATH (fe
->name
))
9472 return xstrdup (fe
->name
);
9480 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9486 dir_len
= strlen (dir
);
9487 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
9488 strcpy (full_name
, dir
);
9489 full_name
[dir_len
] = '/';
9490 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
9494 return xstrdup (fe
->name
);
9499 /* The compiler produced a bogus file number. We can at least
9500 record the macro definitions made in the file, even if we
9501 won't be able to find the file by name. */
9503 sprintf (fake_name
, "<bad macro file number %d>", file
);
9505 complaint (&symfile_complaints
,
9506 _("bad file number in macro information (%d)"),
9509 return xstrdup (fake_name
);
9514 static struct macro_source_file
*
9515 macro_start_file (int file
, int line
,
9516 struct macro_source_file
*current_file
,
9517 const char *comp_dir
,
9518 struct line_header
*lh
, struct objfile
*objfile
)
9520 /* The full name of this source file. */
9521 char *full_name
= file_full_name (file
, lh
, comp_dir
);
9523 /* We don't create a macro table for this compilation unit
9524 at all until we actually get a filename. */
9525 if (! pending_macros
)
9526 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
9527 objfile
->macro_cache
);
9530 /* If we have no current file, then this must be the start_file
9531 directive for the compilation unit's main source file. */
9532 current_file
= macro_set_main (pending_macros
, full_name
);
9534 current_file
= macro_include (current_file
, line
, full_name
);
9538 return current_file
;
9542 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
9543 followed by a null byte. */
9545 copy_string (const char *buf
, int len
)
9547 char *s
= xmalloc (len
+ 1);
9548 memcpy (s
, buf
, len
);
9556 consume_improper_spaces (const char *p
, const char *body
)
9560 complaint (&symfile_complaints
,
9561 _("macro definition contains spaces in formal argument list:\n`%s'"),
9573 parse_macro_definition (struct macro_source_file
*file
, int line
,
9578 /* The body string takes one of two forms. For object-like macro
9579 definitions, it should be:
9581 <macro name> " " <definition>
9583 For function-like macro definitions, it should be:
9585 <macro name> "() " <definition>
9587 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
9589 Spaces may appear only where explicitly indicated, and in the
9592 The Dwarf 2 spec says that an object-like macro's name is always
9593 followed by a space, but versions of GCC around March 2002 omit
9594 the space when the macro's definition is the empty string.
9596 The Dwarf 2 spec says that there should be no spaces between the
9597 formal arguments in a function-like macro's formal argument list,
9598 but versions of GCC around March 2002 include spaces after the
9602 /* Find the extent of the macro name. The macro name is terminated
9603 by either a space or null character (for an object-like macro) or
9604 an opening paren (for a function-like macro). */
9605 for (p
= body
; *p
; p
++)
9606 if (*p
== ' ' || *p
== '(')
9609 if (*p
== ' ' || *p
== '\0')
9611 /* It's an object-like macro. */
9612 int name_len
= p
- body
;
9613 char *name
= copy_string (body
, name_len
);
9614 const char *replacement
;
9617 replacement
= body
+ name_len
+ 1;
9620 dwarf2_macro_malformed_definition_complaint (body
);
9621 replacement
= body
+ name_len
;
9624 macro_define_object (file
, line
, name
, replacement
);
9630 /* It's a function-like macro. */
9631 char *name
= copy_string (body
, p
- body
);
9634 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
9638 p
= consume_improper_spaces (p
, body
);
9640 /* Parse the formal argument list. */
9641 while (*p
&& *p
!= ')')
9643 /* Find the extent of the current argument name. */
9644 const char *arg_start
= p
;
9646 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
9649 if (! *p
|| p
== arg_start
)
9650 dwarf2_macro_malformed_definition_complaint (body
);
9653 /* Make sure argv has room for the new argument. */
9654 if (argc
>= argv_size
)
9657 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
9660 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
9663 p
= consume_improper_spaces (p
, body
);
9665 /* Consume the comma, if present. */
9670 p
= consume_improper_spaces (p
, body
);
9679 /* Perfectly formed definition, no complaints. */
9680 macro_define_function (file
, line
, name
,
9681 argc
, (const char **) argv
,
9683 else if (*p
== '\0')
9685 /* Complain, but do define it. */
9686 dwarf2_macro_malformed_definition_complaint (body
);
9687 macro_define_function (file
, line
, name
,
9688 argc
, (const char **) argv
,
9692 /* Just complain. */
9693 dwarf2_macro_malformed_definition_complaint (body
);
9696 /* Just complain. */
9697 dwarf2_macro_malformed_definition_complaint (body
);
9703 for (i
= 0; i
< argc
; i
++)
9709 dwarf2_macro_malformed_definition_complaint (body
);
9714 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
9715 char *comp_dir
, bfd
*abfd
,
9716 struct dwarf2_cu
*cu
)
9718 gdb_byte
*mac_ptr
, *mac_end
;
9719 struct macro_source_file
*current_file
= 0;
9721 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
9723 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
9727 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
9728 mac_end
= dwarf2_per_objfile
->macinfo_buffer
9729 + dwarf2_per_objfile
->macinfo_size
;
9733 enum dwarf_macinfo_record_type macinfo_type
;
9735 /* Do we at least have room for a macinfo type byte? */
9736 if (mac_ptr
>= mac_end
)
9738 dwarf2_macros_too_long_complaint ();
9742 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
9745 switch (macinfo_type
)
9747 /* A zero macinfo type indicates the end of the macro
9752 case DW_MACINFO_define
:
9753 case DW_MACINFO_undef
:
9755 unsigned int bytes_read
;
9759 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9760 mac_ptr
+= bytes_read
;
9761 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
9762 mac_ptr
+= bytes_read
;
9765 complaint (&symfile_complaints
,
9766 _("debug info gives macro %s outside of any file: %s"),
9768 DW_MACINFO_define
? "definition" : macinfo_type
==
9769 DW_MACINFO_undef
? "undefinition" :
9770 "something-or-other", body
);
9773 if (macinfo_type
== DW_MACINFO_define
)
9774 parse_macro_definition (current_file
, line
, body
);
9775 else if (macinfo_type
== DW_MACINFO_undef
)
9776 macro_undef (current_file
, line
, body
);
9781 case DW_MACINFO_start_file
:
9783 unsigned int bytes_read
;
9786 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9787 mac_ptr
+= bytes_read
;
9788 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9789 mac_ptr
+= bytes_read
;
9791 current_file
= macro_start_file (file
, line
,
9792 current_file
, comp_dir
,
9797 case DW_MACINFO_end_file
:
9799 complaint (&symfile_complaints
,
9800 _("macro debug info has an unmatched `close_file' directive"));
9803 current_file
= current_file
->included_by
;
9806 enum dwarf_macinfo_record_type next_type
;
9808 /* GCC circa March 2002 doesn't produce the zero
9809 type byte marking the end of the compilation
9810 unit. Complain if it's not there, but exit no
9813 /* Do we at least have room for a macinfo type byte? */
9814 if (mac_ptr
>= mac_end
)
9816 dwarf2_macros_too_long_complaint ();
9820 /* We don't increment mac_ptr here, so this is just
9822 next_type
= read_1_byte (abfd
, mac_ptr
);
9824 complaint (&symfile_complaints
,
9825 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
9832 case DW_MACINFO_vendor_ext
:
9834 unsigned int bytes_read
;
9838 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9839 mac_ptr
+= bytes_read
;
9840 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
9841 mac_ptr
+= bytes_read
;
9843 /* We don't recognize any vendor extensions. */
9850 /* Check if the attribute's form is a DW_FORM_block*
9851 if so return true else false. */
9853 attr_form_is_block (struct attribute
*attr
)
9855 return (attr
== NULL
? 0 :
9856 attr
->form
== DW_FORM_block1
9857 || attr
->form
== DW_FORM_block2
9858 || attr
->form
== DW_FORM_block4
9859 || attr
->form
== DW_FORM_block
);
9862 /* Return non-zero if ATTR's value is a section offset --- classes
9863 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
9864 You may use DW_UNSND (attr) to retrieve such offsets.
9866 Section 7.5.4, "Attribute Encodings", explains that no attribute
9867 may have a value that belongs to more than one of these classes; it
9868 would be ambiguous if we did, because we use the same forms for all
9871 attr_form_is_section_offset (struct attribute
*attr
)
9873 return (attr
->form
== DW_FORM_data4
9874 || attr
->form
== DW_FORM_data8
);
9878 /* Return non-zero if ATTR's value falls in the 'constant' class, or
9879 zero otherwise. When this function returns true, you can apply
9880 dwarf2_get_attr_constant_value to it.
9882 However, note that for some attributes you must check
9883 attr_form_is_section_offset before using this test. DW_FORM_data4
9884 and DW_FORM_data8 are members of both the constant class, and of
9885 the classes that contain offsets into other debug sections
9886 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
9887 that, if an attribute's can be either a constant or one of the
9888 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
9889 taken as section offsets, not constants. */
9891 attr_form_is_constant (struct attribute
*attr
)
9908 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
9909 struct dwarf2_cu
*cu
)
9911 if (attr_form_is_section_offset (attr
)
9912 /* ".debug_loc" may not exist at all, or the offset may be outside
9913 the section. If so, fall through to the complaint in the
9915 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc_size
)
9917 struct dwarf2_loclist_baton
*baton
;
9919 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9920 sizeof (struct dwarf2_loclist_baton
));
9921 baton
->per_cu
= cu
->per_cu
;
9922 gdb_assert (baton
->per_cu
);
9924 /* We don't know how long the location list is, but make sure we
9925 don't run off the edge of the section. */
9926 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
9927 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
9928 baton
->base_address
= cu
->header
.base_address
;
9929 if (cu
->header
.base_known
== 0)
9930 complaint (&symfile_complaints
,
9931 _("Location list used without specifying the CU base address."));
9933 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
9934 SYMBOL_LOCATION_BATON (sym
) = baton
;
9938 struct dwarf2_locexpr_baton
*baton
;
9940 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9941 sizeof (struct dwarf2_locexpr_baton
));
9942 baton
->per_cu
= cu
->per_cu
;
9943 gdb_assert (baton
->per_cu
);
9945 if (attr_form_is_block (attr
))
9947 /* Note that we're just copying the block's data pointer
9948 here, not the actual data. We're still pointing into the
9949 info_buffer for SYM's objfile; right now we never release
9950 that buffer, but when we do clean up properly this may
9952 baton
->size
= DW_BLOCK (attr
)->size
;
9953 baton
->data
= DW_BLOCK (attr
)->data
;
9957 dwarf2_invalid_attrib_class_complaint ("location description",
9958 SYMBOL_NATURAL_NAME (sym
));
9963 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
9964 SYMBOL_LOCATION_BATON (sym
) = baton
;
9968 /* Return the OBJFILE associated with the compilation unit CU. */
9971 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
9973 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
9975 /* Return the master objfile, so that we can report and look up the
9976 correct file containing this variable. */
9977 if (objfile
->separate_debug_objfile_backlink
)
9978 objfile
= objfile
->separate_debug_objfile_backlink
;
9983 /* Return the address size given in the compilation unit header for CU. */
9986 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
9989 return per_cu
->cu
->header
.addr_size
;
9992 /* If the CU is not currently read in, we re-read its header. */
9993 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
9994 struct dwarf2_per_objfile
*per_objfile
9995 = objfile_data (objfile
, dwarf2_objfile_data_key
);
9996 gdb_byte
*info_ptr
= per_objfile
->info_buffer
+ per_cu
->offset
;
9998 struct comp_unit_head cu_header
;
9999 memset (&cu_header
, 0, sizeof cu_header
);
10000 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
10001 return cu_header
.addr_size
;
10005 /* Locate the compilation unit from CU's objfile which contains the
10006 DIE at OFFSET. Raises an error on failure. */
10008 static struct dwarf2_per_cu_data
*
10009 dwarf2_find_containing_comp_unit (unsigned long offset
,
10010 struct objfile
*objfile
)
10012 struct dwarf2_per_cu_data
*this_cu
;
10016 high
= dwarf2_per_objfile
->n_comp_units
- 1;
10019 int mid
= low
+ (high
- low
) / 2;
10020 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
10025 gdb_assert (low
== high
);
10026 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
10029 error (_("Dwarf Error: could not find partial DIE containing "
10030 "offset 0x%lx [in module %s]"),
10031 (long) offset
, bfd_get_filename (objfile
->obfd
));
10033 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
10034 return dwarf2_per_objfile
->all_comp_units
[low
-1];
10038 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
10039 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
10040 && offset
>= this_cu
->offset
+ this_cu
->length
)
10041 error (_("invalid dwarf2 offset %ld"), offset
);
10042 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
10047 /* Locate the compilation unit from OBJFILE which is located at exactly
10048 OFFSET. Raises an error on failure. */
10050 static struct dwarf2_per_cu_data
*
10051 dwarf2_find_comp_unit (unsigned long offset
, struct objfile
*objfile
)
10053 struct dwarf2_per_cu_data
*this_cu
;
10054 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10055 if (this_cu
->offset
!= offset
)
10056 error (_("no compilation unit with offset %ld."), offset
);
10060 /* Release one cached compilation unit, CU. We unlink it from the tree
10061 of compilation units, but we don't remove it from the read_in_chain;
10062 the caller is responsible for that. */
10065 free_one_comp_unit (void *data
)
10067 struct dwarf2_cu
*cu
= data
;
10069 if (cu
->per_cu
!= NULL
)
10070 cu
->per_cu
->cu
= NULL
;
10073 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10078 /* This cleanup function is passed the address of a dwarf2_cu on the stack
10079 when we're finished with it. We can't free the pointer itself, but be
10080 sure to unlink it from the cache. Also release any associated storage
10081 and perform cache maintenance.
10083 Only used during partial symbol parsing. */
10086 free_stack_comp_unit (void *data
)
10088 struct dwarf2_cu
*cu
= data
;
10090 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10091 cu
->partial_dies
= NULL
;
10093 if (cu
->per_cu
!= NULL
)
10095 /* This compilation unit is on the stack in our caller, so we
10096 should not xfree it. Just unlink it. */
10097 cu
->per_cu
->cu
= NULL
;
10100 /* If we had a per-cu pointer, then we may have other compilation
10101 units loaded, so age them now. */
10102 age_cached_comp_units ();
10106 /* Free all cached compilation units. */
10109 free_cached_comp_units (void *data
)
10111 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10113 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10114 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10115 while (per_cu
!= NULL
)
10117 struct dwarf2_per_cu_data
*next_cu
;
10119 next_cu
= per_cu
->cu
->read_in_chain
;
10121 free_one_comp_unit (per_cu
->cu
);
10122 *last_chain
= next_cu
;
10128 /* Increase the age counter on each cached compilation unit, and free
10129 any that are too old. */
10132 age_cached_comp_units (void)
10134 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10136 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
10137 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10138 while (per_cu
!= NULL
)
10140 per_cu
->cu
->last_used
++;
10141 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
10142 dwarf2_mark (per_cu
->cu
);
10143 per_cu
= per_cu
->cu
->read_in_chain
;
10146 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10147 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10148 while (per_cu
!= NULL
)
10150 struct dwarf2_per_cu_data
*next_cu
;
10152 next_cu
= per_cu
->cu
->read_in_chain
;
10154 if (!per_cu
->cu
->mark
)
10156 free_one_comp_unit (per_cu
->cu
);
10157 *last_chain
= next_cu
;
10160 last_chain
= &per_cu
->cu
->read_in_chain
;
10166 /* Remove a single compilation unit from the cache. */
10169 free_one_cached_comp_unit (void *target_cu
)
10171 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10173 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10174 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10175 while (per_cu
!= NULL
)
10177 struct dwarf2_per_cu_data
*next_cu
;
10179 next_cu
= per_cu
->cu
->read_in_chain
;
10181 if (per_cu
->cu
== target_cu
)
10183 free_one_comp_unit (per_cu
->cu
);
10184 *last_chain
= next_cu
;
10188 last_chain
= &per_cu
->cu
->read_in_chain
;
10194 /* Release all extra memory associated with OBJFILE. */
10197 dwarf2_free_objfile (struct objfile
*objfile
)
10199 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
10201 if (dwarf2_per_objfile
== NULL
)
10204 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
10205 free_cached_comp_units (NULL
);
10207 /* Everything else should be on the objfile obstack. */
10210 /* A pair of DIE offset and GDB type pointer. We store these
10211 in a hash table separate from the DIEs, and preserve them
10212 when the DIEs are flushed out of cache. */
10214 struct dwarf2_offset_and_type
10216 unsigned int offset
;
10220 /* Hash function for a dwarf2_offset_and_type. */
10223 offset_and_type_hash (const void *item
)
10225 const struct dwarf2_offset_and_type
*ofs
= item
;
10226 return ofs
->offset
;
10229 /* Equality function for a dwarf2_offset_and_type. */
10232 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
10234 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
10235 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
10236 return ofs_lhs
->offset
== ofs_rhs
->offset
;
10239 /* Set the type associated with DIE to TYPE. Save it in CU's hash
10240 table if necessary. For convenience, return TYPE. */
10242 static struct type
*
10243 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10245 struct dwarf2_offset_and_type
**slot
, ofs
;
10247 if (cu
->type_hash
== NULL
)
10249 gdb_assert (cu
->per_cu
!= NULL
);
10250 cu
->per_cu
->type_hash
10251 = htab_create_alloc_ex (cu
->header
.length
/ 24,
10252 offset_and_type_hash
,
10253 offset_and_type_eq
,
10255 &cu
->objfile
->objfile_obstack
,
10256 hashtab_obstack_allocate
,
10257 dummy_obstack_deallocate
);
10258 cu
->type_hash
= cu
->per_cu
->type_hash
;
10261 ofs
.offset
= die
->offset
;
10263 slot
= (struct dwarf2_offset_and_type
**)
10264 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
10265 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
10270 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
10271 not have a saved type. */
10273 static struct type
*
10274 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10276 struct dwarf2_offset_and_type
*slot
, ofs
;
10277 htab_t type_hash
= cu
->type_hash
;
10279 if (type_hash
== NULL
)
10282 ofs
.offset
= die
->offset
;
10283 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
10290 /* Set the mark field in CU and in every other compilation unit in the
10291 cache that we must keep because we are keeping CU. */
10293 /* Add a dependence relationship from CU to REF_PER_CU. */
10296 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
10297 struct dwarf2_per_cu_data
*ref_per_cu
)
10301 if (cu
->dependencies
== NULL
)
10303 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
10304 NULL
, &cu
->comp_unit_obstack
,
10305 hashtab_obstack_allocate
,
10306 dummy_obstack_deallocate
);
10308 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
10310 *slot
= ref_per_cu
;
10313 /* Set the mark field in CU and in every other compilation unit in the
10314 cache that we must keep because we are keeping CU. */
10317 dwarf2_mark_helper (void **slot
, void *data
)
10319 struct dwarf2_per_cu_data
*per_cu
;
10321 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
10322 if (per_cu
->cu
->mark
)
10324 per_cu
->cu
->mark
= 1;
10326 if (per_cu
->cu
->dependencies
!= NULL
)
10327 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10333 dwarf2_mark (struct dwarf2_cu
*cu
)
10338 if (cu
->dependencies
!= NULL
)
10339 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10343 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
10347 per_cu
->cu
->mark
= 0;
10348 per_cu
= per_cu
->cu
->read_in_chain
;
10352 /* Trivial hash function for partial_die_info: the hash value of a DIE
10353 is its offset in .debug_info for this objfile. */
10356 partial_die_hash (const void *item
)
10358 const struct partial_die_info
*part_die
= item
;
10359 return part_die
->offset
;
10362 /* Trivial comparison function for partial_die_info structures: two DIEs
10363 are equal if they have the same offset. */
10366 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
10368 const struct partial_die_info
*part_die_lhs
= item_lhs
;
10369 const struct partial_die_info
*part_die_rhs
= item_rhs
;
10370 return part_die_lhs
->offset
== part_die_rhs
->offset
;
10373 static struct cmd_list_element
*set_dwarf2_cmdlist
;
10374 static struct cmd_list_element
*show_dwarf2_cmdlist
;
10377 set_dwarf2_cmd (char *args
, int from_tty
)
10379 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
10383 show_dwarf2_cmd (char *args
, int from_tty
)
10385 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
10388 void _initialize_dwarf2_read (void);
10391 _initialize_dwarf2_read (void)
10393 dwarf2_objfile_data_key
= register_objfile_data ();
10395 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
10396 Set DWARF 2 specific variables.\n\
10397 Configure DWARF 2 variables such as the cache size"),
10398 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
10399 0/*allow-unknown*/, &maintenance_set_cmdlist
);
10401 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
10402 Show DWARF 2 specific variables\n\
10403 Show DWARF 2 variables such as the cache size"),
10404 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
10405 0/*allow-unknown*/, &maintenance_show_cmdlist
);
10407 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
10408 &dwarf2_max_cache_age
, _("\
10409 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
10410 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
10411 A higher limit means that cached compilation units will be stored\n\
10412 in memory longer, and more total memory will be used. Zero disables\n\
10413 caching, which can slow down startup."),
10415 show_dwarf2_max_cache_age
,
10416 &set_dwarf2_cmdlist
,
10417 &show_dwarf2_cmdlist
);