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 /* When set, the file that we're processing is known to have debugging
145 info for C++ namespaces. GCC 3.3.x did not produce this information,
146 but later versions do. */
148 static int processing_has_namespace_info
;
150 static const struct objfile_data
*dwarf2_objfile_data_key
;
152 struct dwarf2_per_objfile
154 /* Sizes of debugging sections. */
155 unsigned int info_size
;
156 unsigned int abbrev_size
;
157 unsigned int line_size
;
158 unsigned int pubnames_size
;
159 unsigned int aranges_size
;
160 unsigned int loc_size
;
161 unsigned int macinfo_size
;
162 unsigned int str_size
;
163 unsigned int ranges_size
;
164 unsigned int frame_size
;
165 unsigned int eh_frame_size
;
167 /* Loaded data from the sections. */
168 gdb_byte
*info_buffer
;
169 gdb_byte
*abbrev_buffer
;
170 gdb_byte
*line_buffer
;
171 gdb_byte
*str_buffer
;
172 gdb_byte
*macinfo_buffer
;
173 gdb_byte
*ranges_buffer
;
174 gdb_byte
*loc_buffer
;
176 /* A list of all the compilation units. This is used to locate
177 the target compilation unit of a particular reference. */
178 struct dwarf2_per_cu_data
**all_comp_units
;
180 /* The number of compilation units in ALL_COMP_UNITS. */
183 /* A chain of compilation units that are currently read in, so that
184 they can be freed later. */
185 struct dwarf2_per_cu_data
*read_in_chain
;
187 /* A flag indicating wether this objfile has a section loaded at a
189 int has_section_at_zero
;
192 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
194 static asection
*dwarf_info_section
;
195 static asection
*dwarf_abbrev_section
;
196 static asection
*dwarf_line_section
;
197 static asection
*dwarf_pubnames_section
;
198 static asection
*dwarf_aranges_section
;
199 static asection
*dwarf_loc_section
;
200 static asection
*dwarf_macinfo_section
;
201 static asection
*dwarf_str_section
;
202 static asection
*dwarf_ranges_section
;
203 asection
*dwarf_frame_section
;
204 asection
*dwarf_eh_frame_section
;
206 /* names of the debugging sections */
208 /* Note that if the debugging section has been compressed, it might
209 have a name like .zdebug_info. */
211 #define INFO_SECTION "debug_info"
212 #define ABBREV_SECTION "debug_abbrev"
213 #define LINE_SECTION "debug_line"
214 #define PUBNAMES_SECTION "debug_pubnames"
215 #define ARANGES_SECTION "debug_aranges"
216 #define LOC_SECTION "debug_loc"
217 #define MACINFO_SECTION "debug_macinfo"
218 #define STR_SECTION "debug_str"
219 #define RANGES_SECTION "debug_ranges"
220 #define FRAME_SECTION "debug_frame"
221 #define EH_FRAME_SECTION "eh_frame"
223 /* local data types */
225 /* We hold several abbreviation tables in memory at the same time. */
226 #ifndef ABBREV_HASH_SIZE
227 #define ABBREV_HASH_SIZE 121
230 /* The data in a compilation unit header, after target2host
231 translation, looks like this. */
232 struct comp_unit_head
234 unsigned long length
;
236 unsigned int abbrev_offset
;
237 unsigned char addr_size
;
238 unsigned char signed_addr_p
;
240 /* Size of file offsets; either 4 or 8. */
241 unsigned int offset_size
;
243 /* Size of the length field; either 4 or 12. */
244 unsigned int initial_length_size
;
246 /* Offset to the first byte of this compilation unit header in the
247 .debug_info section, for resolving relative reference dies. */
250 /* Pointer to this compilation unit header in the .debug_info
252 gdb_byte
*cu_head_ptr
;
254 /* Pointer to the first die of this compilation unit. This will be
255 the first byte following the compilation unit header. */
256 gdb_byte
*first_die_ptr
;
258 /* Pointer to the next compilation unit header in the program. */
259 struct comp_unit_head
*next
;
261 /* Base address of this compilation unit. */
262 CORE_ADDR base_address
;
264 /* Non-zero if base_address has been set. */
268 /* Internal state when decoding a particular compilation unit. */
271 /* The objfile containing this compilation unit. */
272 struct objfile
*objfile
;
274 /* The header of the compilation unit.
276 FIXME drow/2003-11-10: Some of the things from the comp_unit_head
277 should logically be moved to the dwarf2_cu structure. */
278 struct comp_unit_head header
;
280 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
282 /* The language we are debugging. */
283 enum language language
;
284 const struct language_defn
*language_defn
;
286 const char *producer
;
288 /* The generic symbol table building routines have separate lists for
289 file scope symbols and all all other scopes (local scopes). So
290 we need to select the right one to pass to add_symbol_to_list().
291 We do it by keeping a pointer to the correct list in list_in_scope.
293 FIXME: The original dwarf code just treated the file scope as the
294 first local scope, and all other local scopes as nested local
295 scopes, and worked fine. Check to see if we really need to
296 distinguish these in buildsym.c. */
297 struct pending
**list_in_scope
;
299 /* DWARF abbreviation table associated with this compilation unit. */
300 struct abbrev_info
**dwarf2_abbrevs
;
302 /* Storage for the abbrev table. */
303 struct obstack abbrev_obstack
;
305 /* Hash table holding all the loaded partial DIEs. */
308 /* `.debug_ranges' offset for this `DW_TAG_compile_unit' DIE. */
309 unsigned long ranges_offset
;
311 /* Storage for things with the same lifetime as this read-in compilation
312 unit, including partial DIEs. */
313 struct obstack comp_unit_obstack
;
315 /* When multiple dwarf2_cu structures are living in memory, this field
316 chains them all together, so that they can be released efficiently.
317 We will probably also want a generation counter so that most-recently-used
318 compilation units are cached... */
319 struct dwarf2_per_cu_data
*read_in_chain
;
321 /* Backchain to our per_cu entry if the tree has been built. */
322 struct dwarf2_per_cu_data
*per_cu
;
324 /* Pointer to the die -> type map. Although it is stored
325 permanently in per_cu, we copy it here to avoid double
329 /* How many compilation units ago was this CU last referenced? */
332 /* A hash table of die offsets for following references. */
335 /* Full DIEs if read in. */
336 struct die_info
*dies
;
338 /* A set of pointers to dwarf2_per_cu_data objects for compilation
339 units referenced by this one. Only set during full symbol processing;
340 partial symbol tables do not have dependencies. */
343 /* Header data from the line table, during full symbol processing. */
344 struct line_header
*line_header
;
346 /* Mark used when releasing cached dies. */
347 unsigned int mark
: 1;
349 /* This flag will be set if this compilation unit might include
350 inter-compilation-unit references. */
351 unsigned int has_form_ref_addr
: 1;
353 /* This flag will be set if this compilation unit includes any
354 DW_TAG_namespace DIEs. If we know that there are explicit
355 DIEs for namespaces, we don't need to try to infer them
356 from mangled names. */
357 unsigned int has_namespace_info
: 1;
359 /* Field `ranges_offset' is filled in; flag as the value may be zero. */
360 unsigned int has_ranges_offset
: 1;
363 /* Persistent data held for a compilation unit, even when not
364 processing it. We put a pointer to this structure in the
365 read_symtab_private field of the psymtab. If we encounter
366 inter-compilation-unit references, we also maintain a sorted
367 list of all compilation units. */
369 struct dwarf2_per_cu_data
371 /* The start offset and length of this compilation unit. 2**30-1
372 bytes should suffice to store the length of any compilation unit
373 - if it doesn't, GDB will fall over anyway. */
374 unsigned long offset
;
375 unsigned long length
: 30;
377 /* Flag indicating this compilation unit will be read in before
378 any of the current compilation units are processed. */
379 unsigned long queued
: 1;
381 /* This flag will be set if we need to load absolutely all DIEs
382 for this compilation unit, instead of just the ones we think
383 are interesting. It gets set if we look for a DIE in the
384 hash table and don't find it. */
385 unsigned int load_all_dies
: 1;
387 /* Set iff currently read in. */
388 struct dwarf2_cu
*cu
;
390 /* If full symbols for this CU have been read in, then this field
391 holds a map of DIE offsets to types. It isn't always possible
392 to reconstruct this information later, so we have to preserve
396 /* The partial symbol table associated with this compilation unit,
397 or NULL for partial units (which do not have an associated
399 struct partial_symtab
*psymtab
;
402 /* The line number information for a compilation unit (found in the
403 .debug_line section) begins with a "statement program header",
404 which contains the following information. */
407 unsigned int total_length
;
408 unsigned short version
;
409 unsigned int header_length
;
410 unsigned char minimum_instruction_length
;
411 unsigned char default_is_stmt
;
413 unsigned char line_range
;
414 unsigned char opcode_base
;
416 /* standard_opcode_lengths[i] is the number of operands for the
417 standard opcode whose value is i. This means that
418 standard_opcode_lengths[0] is unused, and the last meaningful
419 element is standard_opcode_lengths[opcode_base - 1]. */
420 unsigned char *standard_opcode_lengths
;
422 /* The include_directories table. NOTE! These strings are not
423 allocated with xmalloc; instead, they are pointers into
424 debug_line_buffer. If you try to free them, `free' will get
426 unsigned int num_include_dirs
, include_dirs_size
;
429 /* The file_names table. NOTE! These strings are not allocated
430 with xmalloc; instead, they are pointers into debug_line_buffer.
431 Don't try to free them directly. */
432 unsigned int num_file_names
, file_names_size
;
436 unsigned int dir_index
;
437 unsigned int mod_time
;
439 int included_p
; /* Non-zero if referenced by the Line Number Program. */
440 struct symtab
*symtab
; /* The associated symbol table, if any. */
443 /* The start and end of the statement program following this
444 header. These point into dwarf2_per_objfile->line_buffer. */
445 gdb_byte
*statement_program_start
, *statement_program_end
;
448 /* When we construct a partial symbol table entry we only
449 need this much information. */
450 struct partial_die_info
452 /* Offset of this DIE. */
455 /* DWARF-2 tag for this DIE. */
456 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
458 /* Language code associated with this DIE. This is only used
459 for the compilation unit DIE. */
460 unsigned int language
: 8;
462 /* Assorted flags describing the data found in this DIE. */
463 unsigned int has_children
: 1;
464 unsigned int is_external
: 1;
465 unsigned int is_declaration
: 1;
466 unsigned int has_type
: 1;
467 unsigned int has_specification
: 1;
468 unsigned int has_stmt_list
: 1;
469 unsigned int has_pc_info
: 1;
471 /* Flag set if the SCOPE field of this structure has been
473 unsigned int scope_set
: 1;
475 /* Flag set if the DIE has a byte_size attribute. */
476 unsigned int has_byte_size
: 1;
478 /* The name of this DIE. Normally the value of DW_AT_name, but
479 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
484 /* The scope to prepend to our children. This is generally
485 allocated on the comp_unit_obstack, so will disappear
486 when this compilation unit leaves the cache. */
489 /* The location description associated with this DIE, if any. */
490 struct dwarf_block
*locdesc
;
492 /* If HAS_PC_INFO, the PC range associated with this DIE. */
496 /* Pointer into the info_buffer pointing at the target of
497 DW_AT_sibling, if any. */
500 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
501 DW_AT_specification (or DW_AT_abstract_origin or
503 unsigned int spec_offset
;
505 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
506 unsigned int line_offset
;
508 /* Pointers to this DIE's parent, first child, and next sibling,
510 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
513 /* This data structure holds the information of an abbrev. */
516 unsigned int number
; /* number identifying abbrev */
517 enum dwarf_tag tag
; /* dwarf tag */
518 unsigned short has_children
; /* boolean */
519 unsigned short num_attrs
; /* number of attributes */
520 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
521 struct abbrev_info
*next
; /* next in chain */
526 enum dwarf_attribute name
;
527 enum dwarf_form form
;
530 /* Attributes have a name and a value */
533 enum dwarf_attribute name
;
534 enum dwarf_form form
;
538 struct dwarf_block
*blk
;
546 /* This data structure holds a complete die structure. */
549 enum dwarf_tag tag
; /* Tag indicating type of die */
550 unsigned int abbrev
; /* Abbrev number */
551 unsigned int offset
; /* Offset in .debug_info section */
552 unsigned int num_attrs
; /* Number of attributes */
554 /* The dies in a compilation unit form an n-ary tree. PARENT
555 points to this die's parent; CHILD points to the first child of
556 this node; and all the children of a given node are chained
557 together via their SIBLING fields, terminated by a die whose
559 struct die_info
*child
; /* Its first child, if any. */
560 struct die_info
*sibling
; /* Its next sibling, if any. */
561 struct die_info
*parent
; /* Its parent, if any. */
563 /* An array of attributes, with NUM_ATTRS elements. There may be
564 zero, but it's not common and zero-sized arrays are not
565 sufficiently portable C. */
566 struct attribute attrs
[1];
569 struct function_range
572 CORE_ADDR lowpc
, highpc
;
574 struct function_range
*next
;
577 /* Get at parts of an attribute structure */
579 #define DW_STRING(attr) ((attr)->u.str)
580 #define DW_UNSND(attr) ((attr)->u.unsnd)
581 #define DW_BLOCK(attr) ((attr)->u.blk)
582 #define DW_SND(attr) ((attr)->u.snd)
583 #define DW_ADDR(attr) ((attr)->u.addr)
585 /* Blocks are a bunch of untyped bytes. */
592 #ifndef ATTR_ALLOC_CHUNK
593 #define ATTR_ALLOC_CHUNK 4
596 /* Allocate fields for structs, unions and enums in this size. */
597 #ifndef DW_FIELD_ALLOC_CHUNK
598 #define DW_FIELD_ALLOC_CHUNK 4
601 /* A zeroed version of a partial die for initialization purposes. */
602 static struct partial_die_info zeroed_partial_die
;
604 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
605 but this would require a corresponding change in unpack_field_as_long
607 static int bits_per_byte
= 8;
609 /* The routines that read and process dies for a C struct or C++ class
610 pass lists of data member fields and lists of member function fields
611 in an instance of a field_info structure, as defined below. */
614 /* List of data member and baseclasses fields. */
617 struct nextfield
*next
;
624 /* Number of fields. */
627 /* Number of baseclasses. */
630 /* Set if the accesibility of one of the fields is not public. */
631 int non_public_fields
;
633 /* Member function fields array, entries are allocated in the order they
634 are encountered in the object file. */
637 struct nextfnfield
*next
;
638 struct fn_field fnfield
;
642 /* Member function fieldlist array, contains name of possibly overloaded
643 member function, number of overloaded member functions and a pointer
644 to the head of the member function field chain. */
649 struct nextfnfield
*head
;
653 /* Number of entries in the fnfieldlists array. */
657 /* One item on the queue of compilation units to read in full symbols
659 struct dwarf2_queue_item
661 struct dwarf2_per_cu_data
*per_cu
;
662 struct dwarf2_queue_item
*next
;
665 /* The current queue. */
666 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
668 /* Loaded secondary compilation units are kept in memory until they
669 have not been referenced for the processing of this many
670 compilation units. Set this to zero to disable caching. Cache
671 sizes of up to at least twenty will improve startup time for
672 typical inter-CU-reference binaries, at an obvious memory cost. */
673 static int dwarf2_max_cache_age
= 5;
675 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
676 struct cmd_list_element
*c
, const char *value
)
678 fprintf_filtered (file
, _("\
679 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
684 /* Various complaints about symbol reading that don't abort the process */
687 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
689 complaint (&symfile_complaints
,
690 _("statement list doesn't fit in .debug_line section"));
694 dwarf2_debug_line_missing_file_complaint (void)
696 complaint (&symfile_complaints
,
697 _(".debug_line section has line data without a file"));
701 dwarf2_complex_location_expr_complaint (void)
703 complaint (&symfile_complaints
, _("location expression too complex"));
707 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
710 complaint (&symfile_complaints
,
711 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
716 dwarf2_macros_too_long_complaint (void)
718 complaint (&symfile_complaints
,
719 _("macro info runs off end of `.debug_macinfo' section"));
723 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
725 complaint (&symfile_complaints
,
726 _("macro debug info contains a malformed macro definition:\n`%s'"),
731 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
733 complaint (&symfile_complaints
,
734 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
737 /* local function prototypes */
739 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
742 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
745 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
748 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
749 struct partial_die_info
*,
750 struct partial_symtab
*);
752 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
754 static void scan_partial_symbols (struct partial_die_info
*,
755 CORE_ADDR
*, CORE_ADDR
*,
758 static void add_partial_symbol (struct partial_die_info
*,
761 static int pdi_needs_namespace (enum dwarf_tag tag
);
763 static void add_partial_namespace (struct partial_die_info
*pdi
,
764 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
765 struct dwarf2_cu
*cu
);
767 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
768 struct dwarf2_cu
*cu
);
770 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
773 struct dwarf2_cu
*cu
);
775 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
777 static void psymtab_to_symtab_1 (struct partial_symtab
*);
779 gdb_byte
*dwarf2_read_section (struct objfile
*, asection
*);
781 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
783 static void dwarf2_free_abbrev_table (void *);
785 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
788 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
791 static struct partial_die_info
*load_partial_dies (bfd
*, gdb_byte
*, int,
794 static gdb_byte
*read_partial_die (struct partial_die_info
*,
795 struct abbrev_info
*abbrev
, unsigned int,
796 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
798 static struct partial_die_info
*find_partial_die (unsigned long,
801 static void fixup_partial_die (struct partial_die_info
*,
804 static gdb_byte
*read_full_die (struct die_info
**, bfd
*, gdb_byte
*,
805 struct dwarf2_cu
*, int *);
807 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
808 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
810 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
811 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
813 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
815 static int read_1_signed_byte (bfd
*, gdb_byte
*);
817 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
819 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
821 static unsigned long read_8_bytes (bfd
*, gdb_byte
*);
823 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
826 static LONGEST
read_initial_length (bfd
*, gdb_byte
*,
827 struct comp_unit_head
*, unsigned int *);
829 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
832 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
834 static char *read_string (bfd
*, gdb_byte
*, unsigned int *);
836 static char *read_indirect_string (bfd
*, gdb_byte
*,
837 const struct comp_unit_head
*,
840 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
842 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
844 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
846 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
848 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
851 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
852 struct dwarf2_cu
*cu
);
854 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
856 static struct die_info
*die_specification (struct die_info
*die
,
857 struct dwarf2_cu
**);
859 static void free_line_header (struct line_header
*lh
);
861 static void add_file_name (struct line_header
*, char *, unsigned int,
862 unsigned int, unsigned int);
864 static struct line_header
*(dwarf_decode_line_header
865 (unsigned int offset
,
866 bfd
*abfd
, struct dwarf2_cu
*cu
));
868 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
869 struct dwarf2_cu
*, struct partial_symtab
*);
871 static void dwarf2_start_subfile (char *, char *, char *);
873 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
876 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
879 static void dwarf2_const_value_data (struct attribute
*attr
,
883 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
885 static struct type
*die_containing_type (struct die_info
*,
888 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
890 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
892 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
894 static char *typename_concat (struct obstack
*,
899 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
901 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
903 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
905 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
906 struct dwarf2_cu
*, struct partial_symtab
*);
908 static int dwarf2_get_pc_bounds (struct die_info
*,
909 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
911 static void get_scope_pc_bounds (struct die_info
*,
912 CORE_ADDR
*, CORE_ADDR
*,
915 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
916 CORE_ADDR
, struct dwarf2_cu
*);
918 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
921 static void dwarf2_attach_fields_to_type (struct field_info
*,
922 struct type
*, struct dwarf2_cu
*);
924 static void dwarf2_add_member_fn (struct field_info
*,
925 struct die_info
*, struct type
*,
928 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
929 struct type
*, struct dwarf2_cu
*);
931 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
933 static const char *determine_class_name (struct die_info
*die
,
934 struct dwarf2_cu
*cu
);
936 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
938 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
940 static const char *namespace_name (struct die_info
*die
,
941 int *is_anonymous
, struct dwarf2_cu
*);
943 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
945 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
947 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
950 static struct die_info
*read_comp_unit (gdb_byte
*, bfd
*, struct dwarf2_cu
*);
952 static struct die_info
*read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
954 gdb_byte
**new_info_ptr
,
955 struct die_info
*parent
);
957 static struct die_info
*read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
959 gdb_byte
**new_info_ptr
,
960 struct die_info
*parent
);
962 static void process_die (struct die_info
*, struct dwarf2_cu
*);
964 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
966 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
968 static struct die_info
*dwarf2_extension (struct die_info
*die
,
969 struct dwarf2_cu
**);
971 static char *dwarf_tag_name (unsigned int);
973 static char *dwarf_attr_name (unsigned int);
975 static char *dwarf_form_name (unsigned int);
977 static char *dwarf_stack_op_name (unsigned int);
979 static char *dwarf_bool_name (unsigned int);
981 static char *dwarf_type_encoding_name (unsigned int);
984 static char *dwarf_cfi_name (unsigned int);
987 static struct die_info
*sibling_die (struct die_info
*);
989 static void dump_die (struct die_info
*);
991 static void dump_die_list (struct die_info
*);
993 static void store_in_ref_table (struct die_info
*,
996 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*,
999 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
1001 static struct die_info
*follow_die_ref (struct die_info
*,
1003 struct dwarf2_cu
**);
1005 /* memory allocation interface */
1007 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1009 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1011 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1013 static void initialize_cu_func_list (struct dwarf2_cu
*);
1015 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1016 struct dwarf2_cu
*);
1018 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1019 char *, bfd
*, struct dwarf2_cu
*);
1021 static int attr_form_is_block (struct attribute
*);
1023 static int attr_form_is_section_offset (struct attribute
*);
1025 static int attr_form_is_constant (struct attribute
*);
1027 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1029 struct dwarf2_cu
*cu
);
1031 static gdb_byte
*skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
1032 struct dwarf2_cu
*cu
);
1034 static void free_stack_comp_unit (void *);
1036 static hashval_t
partial_die_hash (const void *item
);
1038 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1040 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1041 (unsigned long offset
, struct objfile
*objfile
);
1043 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1044 (unsigned long offset
, struct objfile
*objfile
);
1046 static void free_one_comp_unit (void *);
1048 static void free_cached_comp_units (void *);
1050 static void age_cached_comp_units (void);
1052 static void free_one_cached_comp_unit (void *);
1054 static struct type
*set_die_type (struct die_info
*, struct type
*,
1055 struct dwarf2_cu
*);
1057 static void create_all_comp_units (struct objfile
*);
1059 static struct dwarf2_cu
*load_full_comp_unit (struct dwarf2_per_cu_data
*,
1062 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1064 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1065 struct dwarf2_per_cu_data
*);
1067 static void dwarf2_mark (struct dwarf2_cu
*);
1069 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1071 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1073 /* Try to locate the sections we need for DWARF 2 debugging
1074 information and return true if we have enough to do something. */
1077 dwarf2_has_info (struct objfile
*objfile
)
1079 struct dwarf2_per_objfile
*data
;
1081 /* Initialize per-objfile state. */
1082 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1083 memset (data
, 0, sizeof (*data
));
1084 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1085 dwarf2_per_objfile
= data
;
1087 dwarf_info_section
= 0;
1088 dwarf_abbrev_section
= 0;
1089 dwarf_line_section
= 0;
1090 dwarf_str_section
= 0;
1091 dwarf_macinfo_section
= 0;
1092 dwarf_frame_section
= 0;
1093 dwarf_eh_frame_section
= 0;
1094 dwarf_ranges_section
= 0;
1095 dwarf_loc_section
= 0;
1097 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1098 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
1101 /* When loading sections, we can either look for ".<name>", or for
1102 * ".z<name>", which indicates a compressed section. */
1105 section_is_p (asection
*sectp
, const char *name
)
1107 return ((sectp
->name
[0] == '.'
1108 && strcmp (sectp
->name
+ 1, name
) == 0)
1109 || (sectp
->name
[0] == '.' && sectp
->name
[1] == 'z'
1110 && strcmp (sectp
->name
+ 2, name
) == 0));
1113 /* This function is mapped across the sections and remembers the
1114 offset and size of each of the debugging sections we are interested
1118 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1120 if (section_is_p (sectp
, INFO_SECTION
))
1122 dwarf2_per_objfile
->info_size
= bfd_get_section_size (sectp
);
1123 dwarf_info_section
= sectp
;
1125 else if (section_is_p (sectp
, ABBREV_SECTION
))
1127 dwarf2_per_objfile
->abbrev_size
= bfd_get_section_size (sectp
);
1128 dwarf_abbrev_section
= sectp
;
1130 else if (section_is_p (sectp
, LINE_SECTION
))
1132 dwarf2_per_objfile
->line_size
= bfd_get_section_size (sectp
);
1133 dwarf_line_section
= sectp
;
1135 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1137 dwarf2_per_objfile
->pubnames_size
= bfd_get_section_size (sectp
);
1138 dwarf_pubnames_section
= sectp
;
1140 else if (section_is_p (sectp
, ARANGES_SECTION
))
1142 dwarf2_per_objfile
->aranges_size
= bfd_get_section_size (sectp
);
1143 dwarf_aranges_section
= sectp
;
1145 else if (section_is_p (sectp
, LOC_SECTION
))
1147 dwarf2_per_objfile
->loc_size
= bfd_get_section_size (sectp
);
1148 dwarf_loc_section
= sectp
;
1150 else if (section_is_p (sectp
, MACINFO_SECTION
))
1152 dwarf2_per_objfile
->macinfo_size
= bfd_get_section_size (sectp
);
1153 dwarf_macinfo_section
= sectp
;
1155 else if (section_is_p (sectp
, STR_SECTION
))
1157 dwarf2_per_objfile
->str_size
= bfd_get_section_size (sectp
);
1158 dwarf_str_section
= sectp
;
1160 else if (section_is_p (sectp
, FRAME_SECTION
))
1162 dwarf2_per_objfile
->frame_size
= bfd_get_section_size (sectp
);
1163 dwarf_frame_section
= sectp
;
1165 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1167 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1168 if (aflag
& SEC_HAS_CONTENTS
)
1170 dwarf2_per_objfile
->eh_frame_size
= bfd_get_section_size (sectp
);
1171 dwarf_eh_frame_section
= sectp
;
1174 else if (section_is_p (sectp
, RANGES_SECTION
))
1176 dwarf2_per_objfile
->ranges_size
= bfd_get_section_size (sectp
);
1177 dwarf_ranges_section
= sectp
;
1180 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1181 && bfd_section_vma (abfd
, sectp
) == 0)
1182 dwarf2_per_objfile
->has_section_at_zero
= 1;
1185 /* This function is called after decompressing a section, so
1186 dwarf2_per_objfile can record its new, uncompressed size. */
1189 dwarf2_resize_section (asection
*sectp
, bfd_size_type new_size
)
1191 if (section_is_p (sectp
, INFO_SECTION
))
1192 dwarf2_per_objfile
->info_size
= new_size
;
1193 else if (section_is_p (sectp
, ABBREV_SECTION
))
1194 dwarf2_per_objfile
->abbrev_size
= new_size
;
1195 else if (section_is_p (sectp
, LINE_SECTION
))
1196 dwarf2_per_objfile
->line_size
= new_size
;
1197 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1198 dwarf2_per_objfile
->pubnames_size
= new_size
;
1199 else if (section_is_p (sectp
, ARANGES_SECTION
))
1200 dwarf2_per_objfile
->aranges_size
= new_size
;
1201 else if (section_is_p (sectp
, LOC_SECTION
))
1202 dwarf2_per_objfile
->loc_size
= new_size
;
1203 else if (section_is_p (sectp
, MACINFO_SECTION
))
1204 dwarf2_per_objfile
->macinfo_size
= new_size
;
1205 else if (section_is_p (sectp
, STR_SECTION
))
1206 dwarf2_per_objfile
->str_size
= new_size
;
1207 else if (section_is_p (sectp
, FRAME_SECTION
))
1208 dwarf2_per_objfile
->frame_size
= new_size
;
1209 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1210 dwarf2_per_objfile
->eh_frame_size
= new_size
;
1211 else if (section_is_p (sectp
, RANGES_SECTION
))
1212 dwarf2_per_objfile
->ranges_size
= new_size
;
1214 internal_error (__FILE__
, __LINE__
,
1215 _("dwarf2_resize_section: missing section_is_p check: %s"),
1219 /* Build a partial symbol table. */
1222 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1224 /* We definitely need the .debug_info and .debug_abbrev sections */
1226 dwarf2_per_objfile
->info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1227 dwarf2_per_objfile
->abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1229 if (dwarf_line_section
)
1230 dwarf2_per_objfile
->line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1232 dwarf2_per_objfile
->line_buffer
= NULL
;
1234 if (dwarf_str_section
)
1235 dwarf2_per_objfile
->str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1237 dwarf2_per_objfile
->str_buffer
= NULL
;
1239 if (dwarf_macinfo_section
)
1240 dwarf2_per_objfile
->macinfo_buffer
= dwarf2_read_section (objfile
,
1241 dwarf_macinfo_section
);
1243 dwarf2_per_objfile
->macinfo_buffer
= NULL
;
1245 if (dwarf_ranges_section
)
1246 dwarf2_per_objfile
->ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1248 dwarf2_per_objfile
->ranges_buffer
= NULL
;
1250 if (dwarf_loc_section
)
1251 dwarf2_per_objfile
->loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1253 dwarf2_per_objfile
->loc_buffer
= NULL
;
1256 || (objfile
->global_psymbols
.size
== 0
1257 && objfile
->static_psymbols
.size
== 0))
1259 init_psymbol_list (objfile
, 1024);
1263 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1265 /* Things are significantly easier if we have .debug_aranges and
1266 .debug_pubnames sections */
1268 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1272 /* only test this case for now */
1274 /* In this case we have to work a bit harder */
1275 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1280 /* Build the partial symbol table from the information in the
1281 .debug_pubnames and .debug_aranges sections. */
1284 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1286 bfd
*abfd
= objfile
->obfd
;
1287 char *aranges_buffer
, *pubnames_buffer
;
1288 char *aranges_ptr
, *pubnames_ptr
;
1289 unsigned int entry_length
, version
, info_offset
, info_size
;
1291 pubnames_buffer
= dwarf2_read_section (objfile
,
1292 dwarf_pubnames_section
);
1293 pubnames_ptr
= pubnames_buffer
;
1294 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames_size
)
1296 struct comp_unit_head cu_header
;
1297 unsigned int bytes_read
;
1299 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1301 pubnames_ptr
+= bytes_read
;
1302 version
= read_1_byte (abfd
, pubnames_ptr
);
1304 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1306 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1310 aranges_buffer
= dwarf2_read_section (objfile
,
1311 dwarf_aranges_section
);
1316 /* Read in the comp unit header information from the debug_info at
1320 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1321 gdb_byte
*info_ptr
, bfd
*abfd
)
1324 unsigned int bytes_read
;
1325 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1327 info_ptr
+= bytes_read
;
1328 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1330 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1332 info_ptr
+= bytes_read
;
1333 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1335 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1336 if (signed_addr
< 0)
1337 internal_error (__FILE__
, __LINE__
,
1338 _("read_comp_unit_head: dwarf from non elf file"));
1339 cu_header
->signed_addr_p
= signed_addr
;
1344 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1347 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1349 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1351 if (header
->version
!= 2 && header
->version
!= 3)
1352 error (_("Dwarf Error: wrong version in compilation unit header "
1353 "(is %d, should be %d) [in module %s]"), header
->version
,
1354 2, bfd_get_filename (abfd
));
1356 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev_size
)
1357 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1358 "(offset 0x%lx + 6) [in module %s]"),
1359 (long) header
->abbrev_offset
,
1360 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1361 bfd_get_filename (abfd
));
1363 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1364 > dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1365 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1366 "(offset 0x%lx + 0) [in module %s]"),
1367 (long) header
->length
,
1368 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1369 bfd_get_filename (abfd
));
1374 /* Allocate a new partial symtab for file named NAME and mark this new
1375 partial symtab as being an include of PST. */
1378 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1379 struct objfile
*objfile
)
1381 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1383 subpst
->section_offsets
= pst
->section_offsets
;
1384 subpst
->textlow
= 0;
1385 subpst
->texthigh
= 0;
1387 subpst
->dependencies
= (struct partial_symtab
**)
1388 obstack_alloc (&objfile
->objfile_obstack
,
1389 sizeof (struct partial_symtab
*));
1390 subpst
->dependencies
[0] = pst
;
1391 subpst
->number_of_dependencies
= 1;
1393 subpst
->globals_offset
= 0;
1394 subpst
->n_global_syms
= 0;
1395 subpst
->statics_offset
= 0;
1396 subpst
->n_static_syms
= 0;
1397 subpst
->symtab
= NULL
;
1398 subpst
->read_symtab
= pst
->read_symtab
;
1401 /* No private part is necessary for include psymtabs. This property
1402 can be used to differentiate between such include psymtabs and
1403 the regular ones. */
1404 subpst
->read_symtab_private
= NULL
;
1407 /* Read the Line Number Program data and extract the list of files
1408 included by the source file represented by PST. Build an include
1409 partial symtab for each of these included files.
1411 This procedure assumes that there *is* a Line Number Program in
1412 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1413 before calling this procedure. */
1416 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1417 struct partial_die_info
*pdi
,
1418 struct partial_symtab
*pst
)
1420 struct objfile
*objfile
= cu
->objfile
;
1421 bfd
*abfd
= objfile
->obfd
;
1422 struct line_header
*lh
;
1424 lh
= dwarf_decode_line_header (pdi
->line_offset
, abfd
, cu
);
1426 return; /* No linetable, so no includes. */
1428 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1430 free_line_header (lh
);
1434 /* Build the partial symbol table by doing a quick pass through the
1435 .debug_info and .debug_abbrev sections. */
1438 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1440 /* Instead of reading this into a big buffer, we should probably use
1441 mmap() on architectures that support it. (FIXME) */
1442 bfd
*abfd
= objfile
->obfd
;
1444 gdb_byte
*beg_of_comp_unit
;
1445 struct partial_die_info comp_unit_die
;
1446 struct partial_symtab
*pst
;
1447 struct cleanup
*back_to
;
1448 CORE_ADDR lowpc
, highpc
, baseaddr
;
1450 info_ptr
= dwarf2_per_objfile
->info_buffer
;
1452 /* Any cached compilation units will be linked by the per-objfile
1453 read_in_chain. Make sure to free them when we're done. */
1454 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1456 create_all_comp_units (objfile
);
1458 objfile
->psymtabs_addrmap
= addrmap_create_mutable
1459 (&objfile
->objfile_obstack
);
1461 /* Since the objects we're extracting from .debug_info vary in
1462 length, only the individual functions to extract them (like
1463 read_comp_unit_head and load_partial_die) can really know whether
1464 the buffer is large enough to hold another complete object.
1466 At the moment, they don't actually check that. If .debug_info
1467 holds just one extra byte after the last compilation unit's dies,
1468 then read_comp_unit_head will happily read off the end of the
1469 buffer. read_partial_die is similarly casual. Those functions
1472 For this loop condition, simply checking whether there's any data
1473 left at all should be sufficient. */
1474 while (info_ptr
< (dwarf2_per_objfile
->info_buffer
1475 + dwarf2_per_objfile
->info_size
))
1477 struct cleanup
*back_to_inner
;
1478 struct dwarf2_cu cu
;
1479 struct abbrev_info
*abbrev
;
1480 unsigned int bytes_read
;
1481 struct dwarf2_per_cu_data
*this_cu
;
1483 beg_of_comp_unit
= info_ptr
;
1485 memset (&cu
, 0, sizeof (cu
));
1487 obstack_init (&cu
.comp_unit_obstack
);
1489 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1491 cu
.objfile
= objfile
;
1492 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1494 /* Complete the cu_header */
1495 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1496 cu
.header
.first_die_ptr
= info_ptr
;
1497 cu
.header
.cu_head_ptr
= beg_of_comp_unit
;
1499 cu
.list_in_scope
= &file_symbols
;
1501 /* Read the abbrevs for this compilation unit into a table */
1502 dwarf2_read_abbrevs (abfd
, &cu
);
1503 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1505 this_cu
= dwarf2_find_comp_unit (cu
.header
.offset
, objfile
);
1507 /* Read the compilation unit die */
1508 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, &cu
);
1509 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1510 abfd
, info_ptr
, &cu
);
1512 if (comp_unit_die
.tag
== DW_TAG_partial_unit
)
1514 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1515 + cu
.header
.initial_length_size
);
1516 do_cleanups (back_to_inner
);
1520 /* Set the language we're debugging */
1521 set_cu_language (comp_unit_die
.language
, &cu
);
1523 /* Allocate a new partial symbol table structure */
1524 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1525 comp_unit_die
.name
? comp_unit_die
.name
: "",
1526 /* TEXTLOW and TEXTHIGH are set below. */
1528 objfile
->global_psymbols
.next
,
1529 objfile
->static_psymbols
.next
);
1531 if (comp_unit_die
.dirname
)
1532 pst
->dirname
= xstrdup (comp_unit_die
.dirname
);
1534 pst
->read_symtab_private
= (char *) this_cu
;
1536 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1538 /* Store the function that reads in the rest of the symbol table */
1539 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1541 /* If this compilation unit was already read in, free the
1542 cached copy in order to read it in again. This is
1543 necessary because we skipped some symbols when we first
1544 read in the compilation unit (see load_partial_dies).
1545 This problem could be avoided, but the benefit is
1547 if (this_cu
->cu
!= NULL
)
1548 free_one_cached_comp_unit (this_cu
->cu
);
1550 cu
.per_cu
= this_cu
;
1552 /* Note that this is a pointer to our stack frame, being
1553 added to a global data structure. It will be cleaned up
1554 in free_stack_comp_unit when we finish with this
1555 compilation unit. */
1558 this_cu
->psymtab
= pst
;
1560 /* Possibly set the default values of LOWPC and HIGHPC from
1562 if (cu
.has_ranges_offset
)
1564 if (dwarf2_ranges_read (cu
.ranges_offset
, &comp_unit_die
.lowpc
,
1565 &comp_unit_die
.highpc
, &cu
, pst
))
1566 comp_unit_die
.has_pc_info
= 1;
1569 /* Check if comp unit has_children.
1570 If so, read the rest of the partial symbols from this comp unit.
1571 If not, there's no more debug_info for this comp unit. */
1572 if (comp_unit_die
.has_children
)
1574 struct partial_die_info
*first_die
;
1576 lowpc
= ((CORE_ADDR
) -1);
1577 highpc
= ((CORE_ADDR
) 0);
1579 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1581 scan_partial_symbols (first_die
, &lowpc
, &highpc
, &cu
);
1583 /* If we didn't find a lowpc, set it to highpc to avoid
1584 complaints from `maint check'. */
1585 if (lowpc
== ((CORE_ADDR
) -1))
1588 /* If the compilation unit didn't have an explicit address range,
1589 then use the information extracted from its child dies. */
1590 if (! comp_unit_die
.has_pc_info
)
1592 comp_unit_die
.lowpc
= lowpc
;
1593 comp_unit_die
.highpc
= highpc
;
1596 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1597 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1599 /* Store the contiguous range; `DW_AT_ranges' range is stored above. The
1600 range can be also empty for CUs with no code. */
1601 if (!cu
.has_ranges_offset
&& pst
->textlow
< pst
->texthigh
)
1602 addrmap_set_empty (objfile
->psymtabs_addrmap
, pst
->textlow
,
1603 pst
->texthigh
- 1, pst
);
1605 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1606 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1607 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1608 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1609 sort_pst_symbols (pst
);
1611 /* If there is already a psymtab or symtab for a file of this
1612 name, remove it. (If there is a symtab, more drastic things
1613 also happen.) This happens in VxWorks. */
1614 free_named_symtabs (pst
->filename
);
1616 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1617 + cu
.header
.initial_length_size
;
1619 if (comp_unit_die
.has_stmt_list
)
1621 /* Get the list of files included in the current compilation unit,
1622 and build a psymtab for each of them. */
1623 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1626 do_cleanups (back_to_inner
);
1629 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
1630 &objfile
->objfile_obstack
);
1632 do_cleanups (back_to
);
1635 /* Load the DIEs for a secondary CU into memory. */
1638 load_comp_unit (struct dwarf2_per_cu_data
*this_cu
, struct objfile
*objfile
)
1640 bfd
*abfd
= objfile
->obfd
;
1641 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
1642 struct partial_die_info comp_unit_die
;
1643 struct dwarf2_cu
*cu
;
1644 struct abbrev_info
*abbrev
;
1645 unsigned int bytes_read
;
1646 struct cleanup
*back_to
;
1648 info_ptr
= dwarf2_per_objfile
->info_buffer
+ this_cu
->offset
;
1649 beg_of_comp_unit
= info_ptr
;
1651 cu
= xmalloc (sizeof (struct dwarf2_cu
));
1652 memset (cu
, 0, sizeof (struct dwarf2_cu
));
1654 obstack_init (&cu
->comp_unit_obstack
);
1656 cu
->objfile
= objfile
;
1657 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
1659 /* Complete the cu_header. */
1660 cu
->header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1661 cu
->header
.first_die_ptr
= info_ptr
;
1662 cu
->header
.cu_head_ptr
= beg_of_comp_unit
;
1664 /* Read the abbrevs for this compilation unit into a table. */
1665 dwarf2_read_abbrevs (abfd
, cu
);
1666 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
1668 /* Read the compilation unit die. */
1669 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1670 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1671 abfd
, info_ptr
, cu
);
1673 /* Set the language we're debugging. */
1674 set_cu_language (comp_unit_die
.language
, cu
);
1676 /* Link this compilation unit into the compilation unit tree. */
1678 cu
->per_cu
= this_cu
;
1679 cu
->type_hash
= cu
->per_cu
->type_hash
;
1681 /* Check if comp unit has_children.
1682 If so, read the rest of the partial symbols from this comp unit.
1683 If not, there's no more debug_info for this comp unit. */
1684 if (comp_unit_die
.has_children
)
1685 load_partial_dies (abfd
, info_ptr
, 0, cu
);
1687 do_cleanups (back_to
);
1690 /* Create a list of all compilation units in OBJFILE. We do this only
1691 if an inter-comp-unit reference is found; presumably if there is one,
1692 there will be many, and one will occur early in the .debug_info section.
1693 So there's no point in building this list incrementally. */
1696 create_all_comp_units (struct objfile
*objfile
)
1700 struct dwarf2_per_cu_data
**all_comp_units
;
1701 gdb_byte
*info_ptr
= dwarf2_per_objfile
->info_buffer
;
1705 all_comp_units
= xmalloc (n_allocated
1706 * sizeof (struct dwarf2_per_cu_data
*));
1708 while (info_ptr
< dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1710 struct comp_unit_head cu_header
;
1711 gdb_byte
*beg_of_comp_unit
;
1712 struct dwarf2_per_cu_data
*this_cu
;
1713 unsigned long offset
;
1714 unsigned int bytes_read
;
1716 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
1718 /* Read just enough information to find out where the next
1719 compilation unit is. */
1720 cu_header
.initial_length_size
= 0;
1721 cu_header
.length
= read_initial_length (objfile
->obfd
, info_ptr
,
1722 &cu_header
, &bytes_read
);
1724 /* Save the compilation unit for later lookup. */
1725 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
1726 sizeof (struct dwarf2_per_cu_data
));
1727 memset (this_cu
, 0, sizeof (*this_cu
));
1728 this_cu
->offset
= offset
;
1729 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
1731 if (n_comp_units
== n_allocated
)
1734 all_comp_units
= xrealloc (all_comp_units
,
1736 * sizeof (struct dwarf2_per_cu_data
*));
1738 all_comp_units
[n_comp_units
++] = this_cu
;
1740 info_ptr
= info_ptr
+ this_cu
->length
;
1743 dwarf2_per_objfile
->all_comp_units
1744 = obstack_alloc (&objfile
->objfile_obstack
,
1745 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1746 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
1747 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1748 xfree (all_comp_units
);
1749 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
1752 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1753 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1757 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1758 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
1760 struct objfile
*objfile
= cu
->objfile
;
1761 bfd
*abfd
= objfile
->obfd
;
1762 struct partial_die_info
*pdi
;
1764 /* Now, march along the PDI's, descending into ones which have
1765 interesting children but skipping the children of the other ones,
1766 until we reach the end of the compilation unit. */
1772 fixup_partial_die (pdi
, cu
);
1774 /* Anonymous namespaces have no name but have interesting
1775 children, so we need to look at them. Ditto for anonymous
1778 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1779 || pdi
->tag
== DW_TAG_enumeration_type
)
1783 case DW_TAG_subprogram
:
1784 if (pdi
->has_pc_info
)
1786 if (pdi
->lowpc
< *lowpc
)
1788 *lowpc
= pdi
->lowpc
;
1790 if (pdi
->highpc
> *highpc
)
1792 *highpc
= pdi
->highpc
;
1794 if (!pdi
->is_declaration
)
1796 add_partial_symbol (pdi
, cu
);
1800 case DW_TAG_variable
:
1801 case DW_TAG_typedef
:
1802 case DW_TAG_union_type
:
1803 if (!pdi
->is_declaration
)
1805 add_partial_symbol (pdi
, cu
);
1808 case DW_TAG_class_type
:
1809 case DW_TAG_interface_type
:
1810 case DW_TAG_structure_type
:
1811 if (!pdi
->is_declaration
)
1813 add_partial_symbol (pdi
, cu
);
1816 case DW_TAG_enumeration_type
:
1817 if (!pdi
->is_declaration
)
1818 add_partial_enumeration (pdi
, cu
);
1820 case DW_TAG_base_type
:
1821 case DW_TAG_subrange_type
:
1822 /* File scope base type definitions are added to the partial
1824 add_partial_symbol (pdi
, cu
);
1826 case DW_TAG_namespace
:
1827 add_partial_namespace (pdi
, lowpc
, highpc
, cu
);
1834 /* If the die has a sibling, skip to the sibling. */
1836 pdi
= pdi
->die_sibling
;
1840 /* Functions used to compute the fully scoped name of a partial DIE.
1842 Normally, this is simple. For C++, the parent DIE's fully scoped
1843 name is concatenated with "::" and the partial DIE's name. For
1844 Java, the same thing occurs except that "." is used instead of "::".
1845 Enumerators are an exception; they use the scope of their parent
1846 enumeration type, i.e. the name of the enumeration type is not
1847 prepended to the enumerator.
1849 There are two complexities. One is DW_AT_specification; in this
1850 case "parent" means the parent of the target of the specification,
1851 instead of the direct parent of the DIE. The other is compilers
1852 which do not emit DW_TAG_namespace; in this case we try to guess
1853 the fully qualified name of structure types from their members'
1854 linkage names. This must be done using the DIE's children rather
1855 than the children of any DW_AT_specification target. We only need
1856 to do this for structures at the top level, i.e. if the target of
1857 any DW_AT_specification (if any; otherwise the DIE itself) does not
1860 /* Compute the scope prefix associated with PDI's parent, in
1861 compilation unit CU. The result will be allocated on CU's
1862 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1863 field. NULL is returned if no prefix is necessary. */
1865 partial_die_parent_scope (struct partial_die_info
*pdi
,
1866 struct dwarf2_cu
*cu
)
1868 char *grandparent_scope
;
1869 struct partial_die_info
*parent
, *real_pdi
;
1871 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1872 then this means the parent of the specification DIE. */
1875 while (real_pdi
->has_specification
)
1876 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
1878 parent
= real_pdi
->die_parent
;
1882 if (parent
->scope_set
)
1883 return parent
->scope
;
1885 fixup_partial_die (parent
, cu
);
1887 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
1889 if (parent
->tag
== DW_TAG_namespace
1890 || parent
->tag
== DW_TAG_structure_type
1891 || parent
->tag
== DW_TAG_class_type
1892 || parent
->tag
== DW_TAG_interface_type
1893 || parent
->tag
== DW_TAG_union_type
)
1895 if (grandparent_scope
== NULL
)
1896 parent
->scope
= parent
->name
;
1898 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
1901 else if (parent
->tag
== DW_TAG_enumeration_type
)
1902 /* Enumerators should not get the name of the enumeration as a prefix. */
1903 parent
->scope
= grandparent_scope
;
1906 /* FIXME drow/2004-04-01: What should we be doing with
1907 function-local names? For partial symbols, we should probably be
1909 complaint (&symfile_complaints
,
1910 _("unhandled containing DIE tag %d for DIE at %d"),
1911 parent
->tag
, pdi
->offset
);
1912 parent
->scope
= grandparent_scope
;
1915 parent
->scope_set
= 1;
1916 return parent
->scope
;
1919 /* Return the fully scoped name associated with PDI, from compilation unit
1920 CU. The result will be allocated with malloc. */
1922 partial_die_full_name (struct partial_die_info
*pdi
,
1923 struct dwarf2_cu
*cu
)
1927 parent_scope
= partial_die_parent_scope (pdi
, cu
);
1928 if (parent_scope
== NULL
)
1931 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
1935 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
1937 struct objfile
*objfile
= cu
->objfile
;
1939 char *actual_name
= NULL
;
1940 const char *my_prefix
;
1941 const struct partial_symbol
*psym
= NULL
;
1943 int built_actual_name
= 0;
1945 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1947 if (pdi_needs_namespace (pdi
->tag
))
1949 actual_name
= partial_die_full_name (pdi
, cu
);
1951 built_actual_name
= 1;
1954 if (actual_name
== NULL
)
1955 actual_name
= pdi
->name
;
1959 case DW_TAG_subprogram
:
1960 if (pdi
->is_external
|| cu
->language
== language_ada
)
1962 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
1963 of the global scope. But in Ada, we want to be able to access
1964 nested procedures globally. So all Ada subprograms are stored
1965 in the global scope. */
1966 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1967 mst_text, objfile); */
1968 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1969 VAR_DOMAIN
, LOC_BLOCK
,
1970 &objfile
->global_psymbols
,
1971 0, pdi
->lowpc
+ baseaddr
,
1972 cu
->language
, objfile
);
1976 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1977 mst_file_text, objfile); */
1978 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1979 VAR_DOMAIN
, LOC_BLOCK
,
1980 &objfile
->static_psymbols
,
1981 0, pdi
->lowpc
+ baseaddr
,
1982 cu
->language
, objfile
);
1985 case DW_TAG_variable
:
1986 if (pdi
->is_external
)
1989 Don't enter into the minimal symbol tables as there is
1990 a minimal symbol table entry from the ELF symbols already.
1991 Enter into partial symbol table if it has a location
1992 descriptor or a type.
1993 If the location descriptor is missing, new_symbol will create
1994 a LOC_UNRESOLVED symbol, the address of the variable will then
1995 be determined from the minimal symbol table whenever the variable
1997 The address for the partial symbol table entry is not
1998 used by GDB, but it comes in handy for debugging partial symbol
2002 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2003 if (pdi
->locdesc
|| pdi
->has_type
)
2004 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2005 VAR_DOMAIN
, LOC_STATIC
,
2006 &objfile
->global_psymbols
,
2008 cu
->language
, objfile
);
2012 /* Static Variable. Skip symbols without location descriptors. */
2013 if (pdi
->locdesc
== NULL
)
2015 if (built_actual_name
)
2016 xfree (actual_name
);
2019 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2020 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2021 mst_file_data, objfile); */
2022 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2023 VAR_DOMAIN
, LOC_STATIC
,
2024 &objfile
->static_psymbols
,
2026 cu
->language
, objfile
);
2029 case DW_TAG_typedef
:
2030 case DW_TAG_base_type
:
2031 case DW_TAG_subrange_type
:
2032 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2033 VAR_DOMAIN
, LOC_TYPEDEF
,
2034 &objfile
->static_psymbols
,
2035 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2037 case DW_TAG_namespace
:
2038 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2039 VAR_DOMAIN
, LOC_TYPEDEF
,
2040 &objfile
->global_psymbols
,
2041 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2043 case DW_TAG_class_type
:
2044 case DW_TAG_interface_type
:
2045 case DW_TAG_structure_type
:
2046 case DW_TAG_union_type
:
2047 case DW_TAG_enumeration_type
:
2048 /* Skip external references. The DWARF standard says in the section
2049 about "Structure, Union, and Class Type Entries": "An incomplete
2050 structure, union or class type is represented by a structure,
2051 union or class entry that does not have a byte size attribute
2052 and that has a DW_AT_declaration attribute." */
2053 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2055 if (built_actual_name
)
2056 xfree (actual_name
);
2060 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2061 static vs. global. */
2062 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2063 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2064 (cu
->language
== language_cplus
2065 || cu
->language
== language_java
)
2066 ? &objfile
->global_psymbols
2067 : &objfile
->static_psymbols
,
2068 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2071 case DW_TAG_enumerator
:
2072 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2073 VAR_DOMAIN
, LOC_CONST
,
2074 (cu
->language
== language_cplus
2075 || cu
->language
== language_java
)
2076 ? &objfile
->global_psymbols
2077 : &objfile
->static_psymbols
,
2078 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2084 /* Check to see if we should scan the name for possible namespace
2085 info. Only do this if this is C++, if we don't have namespace
2086 debugging info in the file, if the psym is of an appropriate type
2087 (otherwise we'll have psym == NULL), and if we actually had a
2088 mangled name to begin with. */
2090 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2091 cases which do not set PSYM above? */
2093 if (cu
->language
== language_cplus
2094 && cu
->has_namespace_info
== 0
2096 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
2097 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
2100 if (built_actual_name
)
2101 xfree (actual_name
);
2104 /* Determine whether a die of type TAG living in a C++ class or
2105 namespace needs to have the name of the scope prepended to the
2106 name listed in the die. */
2109 pdi_needs_namespace (enum dwarf_tag tag
)
2113 case DW_TAG_namespace
:
2114 case DW_TAG_typedef
:
2115 case DW_TAG_class_type
:
2116 case DW_TAG_interface_type
:
2117 case DW_TAG_structure_type
:
2118 case DW_TAG_union_type
:
2119 case DW_TAG_enumeration_type
:
2120 case DW_TAG_enumerator
:
2127 /* Read a partial die corresponding to a namespace; also, add a symbol
2128 corresponding to that namespace to the symbol table. NAMESPACE is
2129 the name of the enclosing namespace. */
2132 add_partial_namespace (struct partial_die_info
*pdi
,
2133 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2134 struct dwarf2_cu
*cu
)
2136 struct objfile
*objfile
= cu
->objfile
;
2138 /* Add a symbol for the namespace. */
2140 add_partial_symbol (pdi
, cu
);
2142 /* Now scan partial symbols in that namespace. */
2144 if (pdi
->has_children
)
2145 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, cu
);
2148 /* See if we can figure out if the class lives in a namespace. We do
2149 this by looking for a member function; its demangled name will
2150 contain namespace info, if there is any. */
2153 guess_structure_name (struct partial_die_info
*struct_pdi
,
2154 struct dwarf2_cu
*cu
)
2156 if ((cu
->language
== language_cplus
2157 || cu
->language
== language_java
)
2158 && cu
->has_namespace_info
== 0
2159 && struct_pdi
->has_children
)
2161 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2162 what template types look like, because the demangler
2163 frequently doesn't give the same name as the debug info. We
2164 could fix this by only using the demangled name to get the
2165 prefix (but see comment in read_structure_type). */
2167 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
2168 struct partial_die_info
*real_pdi
;
2170 /* If this DIE (this DIE's specification, if any) has a parent, then
2171 we should not do this. We'll prepend the parent's fully qualified
2172 name when we create the partial symbol. */
2174 real_pdi
= struct_pdi
;
2175 while (real_pdi
->has_specification
)
2176 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2178 if (real_pdi
->die_parent
!= NULL
)
2181 while (child_pdi
!= NULL
)
2183 if (child_pdi
->tag
== DW_TAG_subprogram
)
2185 char *actual_class_name
2186 = language_class_name_from_physname (cu
->language_defn
,
2188 if (actual_class_name
!= NULL
)
2191 = obsavestring (actual_class_name
,
2192 strlen (actual_class_name
),
2193 &cu
->comp_unit_obstack
);
2194 xfree (actual_class_name
);
2199 child_pdi
= child_pdi
->die_sibling
;
2204 /* Read a partial die corresponding to an enumeration type. */
2207 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2208 struct dwarf2_cu
*cu
)
2210 struct objfile
*objfile
= cu
->objfile
;
2211 bfd
*abfd
= objfile
->obfd
;
2212 struct partial_die_info
*pdi
;
2214 if (enum_pdi
->name
!= NULL
)
2215 add_partial_symbol (enum_pdi
, cu
);
2217 pdi
= enum_pdi
->die_child
;
2220 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2221 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2223 add_partial_symbol (pdi
, cu
);
2224 pdi
= pdi
->die_sibling
;
2228 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2229 Return the corresponding abbrev, or NULL if the number is zero (indicating
2230 an empty DIE). In either case *BYTES_READ will be set to the length of
2231 the initial number. */
2233 static struct abbrev_info
*
2234 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2235 struct dwarf2_cu
*cu
)
2237 bfd
*abfd
= cu
->objfile
->obfd
;
2238 unsigned int abbrev_number
;
2239 struct abbrev_info
*abbrev
;
2241 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2243 if (abbrev_number
== 0)
2246 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2249 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2250 bfd_get_filename (abfd
));
2256 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2257 pointer to the end of a series of DIEs, terminated by an empty
2258 DIE. Any children of the skipped DIEs will also be skipped. */
2261 skip_children (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2263 struct abbrev_info
*abbrev
;
2264 unsigned int bytes_read
;
2268 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2270 return info_ptr
+ bytes_read
;
2272 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
2276 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2277 should point just after the initial uleb128 of a DIE, and the
2278 abbrev corresponding to that skipped uleb128 should be passed in
2279 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2283 skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
2284 struct dwarf2_cu
*cu
)
2286 unsigned int bytes_read
;
2287 struct attribute attr
;
2288 bfd
*abfd
= cu
->objfile
->obfd
;
2289 unsigned int form
, i
;
2291 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2293 /* The only abbrev we care about is DW_AT_sibling. */
2294 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2296 read_attribute (&attr
, &abbrev
->attrs
[i
],
2297 abfd
, info_ptr
, cu
);
2298 if (attr
.form
== DW_FORM_ref_addr
)
2299 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2301 return dwarf2_per_objfile
->info_buffer
2302 + dwarf2_get_ref_die_offset (&attr
, cu
);
2305 /* If it isn't DW_AT_sibling, skip this attribute. */
2306 form
= abbrev
->attrs
[i
].form
;
2311 case DW_FORM_ref_addr
:
2312 info_ptr
+= cu
->header
.addr_size
;
2331 case DW_FORM_string
:
2332 read_string (abfd
, info_ptr
, &bytes_read
);
2333 info_ptr
+= bytes_read
;
2336 info_ptr
+= cu
->header
.offset_size
;
2339 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2340 info_ptr
+= bytes_read
;
2342 case DW_FORM_block1
:
2343 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2345 case DW_FORM_block2
:
2346 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2348 case DW_FORM_block4
:
2349 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2353 case DW_FORM_ref_udata
:
2354 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2356 case DW_FORM_indirect
:
2357 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2358 info_ptr
+= bytes_read
;
2359 /* We need to continue parsing from here, so just go back to
2361 goto skip_attribute
;
2364 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2365 dwarf_form_name (form
),
2366 bfd_get_filename (abfd
));
2370 if (abbrev
->has_children
)
2371 return skip_children (info_ptr
, cu
);
2376 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2377 the next DIE after ORIG_PDI. */
2380 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, gdb_byte
*info_ptr
,
2381 bfd
*abfd
, struct dwarf2_cu
*cu
)
2383 /* Do we know the sibling already? */
2385 if (orig_pdi
->sibling
)
2386 return orig_pdi
->sibling
;
2388 /* Are there any children to deal with? */
2390 if (!orig_pdi
->has_children
)
2393 /* Skip the children the long way. */
2395 return skip_children (info_ptr
, cu
);
2398 /* Expand this partial symbol table into a full symbol table. */
2401 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2403 /* FIXME: This is barely more than a stub. */
2408 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2414 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2415 gdb_flush (gdb_stdout
);
2418 /* Restore our global data. */
2419 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2420 dwarf2_objfile_data_key
);
2422 psymtab_to_symtab_1 (pst
);
2424 /* Finish up the debug error message. */
2426 printf_filtered (_("done.\n"));
2431 /* Add PER_CU to the queue. */
2434 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2436 struct dwarf2_queue_item
*item
;
2439 item
= xmalloc (sizeof (*item
));
2440 item
->per_cu
= per_cu
;
2443 if (dwarf2_queue
== NULL
)
2444 dwarf2_queue
= item
;
2446 dwarf2_queue_tail
->next
= item
;
2448 dwarf2_queue_tail
= item
;
2450 /* Either PER_CU is the CU we want to process, or we're following a reference
2451 pointing into PER_CU. Either way, we need its DIEs now. */
2452 load_full_comp_unit (item
->per_cu
, objfile
);
2453 item
->per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
2454 dwarf2_per_objfile
->read_in_chain
= item
->per_cu
;
2457 /* Process the queue. */
2460 process_queue (struct objfile
*objfile
)
2462 struct dwarf2_queue_item
*item
, *next_item
;
2464 /* The queue starts out with one item, but following a DIE reference
2465 may load a new CU, adding it to the end of the queue. */
2466 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2468 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2469 process_full_comp_unit (item
->per_cu
);
2471 item
->per_cu
->queued
= 0;
2472 next_item
= item
->next
;
2476 dwarf2_queue_tail
= NULL
;
2479 /* Free all allocated queue entries. This function only releases anything if
2480 an error was thrown; if the queue was processed then it would have been
2481 freed as we went along. */
2484 dwarf2_release_queue (void *dummy
)
2486 struct dwarf2_queue_item
*item
, *last
;
2488 item
= dwarf2_queue
;
2491 /* Anything still marked queued is likely to be in an
2492 inconsistent state, so discard it. */
2493 if (item
->per_cu
->queued
)
2495 if (item
->per_cu
->cu
!= NULL
)
2496 free_one_cached_comp_unit (item
->per_cu
->cu
);
2497 item
->per_cu
->queued
= 0;
2505 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2508 /* Read in full symbols for PST, and anything it depends on. */
2511 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2513 struct dwarf2_per_cu_data
*per_cu
;
2514 struct cleanup
*back_to
;
2517 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2518 if (!pst
->dependencies
[i
]->readin
)
2520 /* Inform about additional files that need to be read in. */
2523 /* FIXME: i18n: Need to make this a single string. */
2524 fputs_filtered (" ", gdb_stdout
);
2526 fputs_filtered ("and ", gdb_stdout
);
2528 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2529 wrap_here (""); /* Flush output */
2530 gdb_flush (gdb_stdout
);
2532 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2535 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
2539 /* It's an include file, no symbols to read for it.
2540 Everything is in the parent symtab. */
2545 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2547 queue_comp_unit (per_cu
, pst
->objfile
);
2549 process_queue (pst
->objfile
);
2551 /* Age the cache, releasing compilation units that have not
2552 been used recently. */
2553 age_cached_comp_units ();
2555 do_cleanups (back_to
);
2558 /* Load the DIEs associated with PST and PER_CU into memory. */
2560 static struct dwarf2_cu
*
2561 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2563 bfd
*abfd
= objfile
->obfd
;
2564 struct dwarf2_cu
*cu
;
2565 unsigned long offset
;
2567 struct cleanup
*back_to
, *free_cu_cleanup
;
2568 struct attribute
*attr
;
2571 /* Set local variables from the partial symbol table info. */
2572 offset
= per_cu
->offset
;
2574 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2576 cu
= xmalloc (sizeof (struct dwarf2_cu
));
2577 memset (cu
, 0, sizeof (struct dwarf2_cu
));
2579 /* If an error occurs while loading, release our storage. */
2580 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
2582 cu
->objfile
= objfile
;
2584 /* read in the comp_unit header */
2585 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
2587 /* Read the abbrevs for this compilation unit */
2588 dwarf2_read_abbrevs (abfd
, cu
);
2589 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2591 cu
->header
.offset
= offset
;
2593 cu
->per_cu
= per_cu
;
2595 cu
->type_hash
= per_cu
->type_hash
;
2597 /* We use this obstack for block values in dwarf_alloc_block. */
2598 obstack_init (&cu
->comp_unit_obstack
);
2600 cu
->dies
= read_comp_unit (info_ptr
, abfd
, cu
);
2602 /* We try not to read any attributes in this function, because not
2603 all objfiles needed for references have been loaded yet, and symbol
2604 table processing isn't initialized. But we have to set the CU language,
2605 or we won't be able to build types correctly. */
2606 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
2608 set_cu_language (DW_UNSND (attr
), cu
);
2610 set_cu_language (language_minimal
, cu
);
2612 do_cleanups (back_to
);
2614 /* We've successfully allocated this compilation unit. Let our caller
2615 clean it up when finished with it. */
2616 discard_cleanups (free_cu_cleanup
);
2621 /* Generate full symbol information for PST and CU, whose DIEs have
2622 already been loaded into memory. */
2625 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2627 struct partial_symtab
*pst
= per_cu
->psymtab
;
2628 struct dwarf2_cu
*cu
= per_cu
->cu
;
2629 struct objfile
*objfile
= pst
->objfile
;
2630 bfd
*abfd
= objfile
->obfd
;
2631 CORE_ADDR lowpc
, highpc
;
2632 struct symtab
*symtab
;
2633 struct cleanup
*back_to
;
2634 struct attribute
*attr
;
2637 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2640 back_to
= make_cleanup (really_free_pendings
, NULL
);
2642 cu
->list_in_scope
= &file_symbols
;
2644 /* Find the base address of the compilation unit for range lists and
2645 location lists. It will normally be specified by DW_AT_low_pc.
2646 In DWARF-3 draft 4, the base address could be overridden by
2647 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2648 compilation units with discontinuous ranges. */
2650 cu
->header
.base_known
= 0;
2651 cu
->header
.base_address
= 0;
2653 attr
= dwarf2_attr (cu
->dies
, DW_AT_entry_pc
, cu
);
2656 cu
->header
.base_address
= DW_ADDR (attr
);
2657 cu
->header
.base_known
= 1;
2661 attr
= dwarf2_attr (cu
->dies
, DW_AT_low_pc
, cu
);
2664 cu
->header
.base_address
= DW_ADDR (attr
);
2665 cu
->header
.base_known
= 1;
2669 /* Do line number decoding in read_file_scope () */
2670 process_die (cu
->dies
, cu
);
2672 /* Some compilers don't define a DW_AT_high_pc attribute for the
2673 compilation unit. If the DW_AT_high_pc is missing, synthesize
2674 it, by scanning the DIE's below the compilation unit. */
2675 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
2677 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2679 /* Set symtab language to language from DW_AT_language.
2680 If the compilation is from a C file generated by language preprocessors,
2681 do not set the language if it was already deduced by start_subfile. */
2683 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
2685 symtab
->language
= cu
->language
;
2687 pst
->symtab
= symtab
;
2690 do_cleanups (back_to
);
2693 /* Process a die and its children. */
2696 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2700 case DW_TAG_padding
:
2702 case DW_TAG_compile_unit
:
2703 read_file_scope (die
, cu
);
2705 case DW_TAG_subprogram
:
2706 read_func_scope (die
, cu
);
2708 case DW_TAG_inlined_subroutine
:
2709 /* FIXME: These are ignored for now.
2710 They could be used to set breakpoints on all inlined instances
2711 of a function and make GDB `next' properly over inlined functions. */
2713 case DW_TAG_lexical_block
:
2714 case DW_TAG_try_block
:
2715 case DW_TAG_catch_block
:
2716 read_lexical_block_scope (die
, cu
);
2718 case DW_TAG_class_type
:
2719 case DW_TAG_interface_type
:
2720 case DW_TAG_structure_type
:
2721 case DW_TAG_union_type
:
2722 process_structure_scope (die
, cu
);
2724 case DW_TAG_enumeration_type
:
2725 process_enumeration_scope (die
, cu
);
2728 /* These dies have a type, but processing them does not create
2729 a symbol or recurse to process the children. Therefore we can
2730 read them on-demand through read_type_die. */
2731 case DW_TAG_subroutine_type
:
2732 case DW_TAG_set_type
:
2733 case DW_TAG_array_type
:
2734 case DW_TAG_pointer_type
:
2735 case DW_TAG_ptr_to_member_type
:
2736 case DW_TAG_reference_type
:
2737 case DW_TAG_string_type
:
2740 case DW_TAG_base_type
:
2741 case DW_TAG_subrange_type
:
2742 /* Add a typedef symbol for the type definition, if it has a
2744 new_symbol (die
, read_type_die (die
, cu
), cu
);
2746 case DW_TAG_common_block
:
2747 read_common_block (die
, cu
);
2749 case DW_TAG_common_inclusion
:
2751 case DW_TAG_namespace
:
2752 processing_has_namespace_info
= 1;
2753 read_namespace (die
, cu
);
2755 case DW_TAG_imported_declaration
:
2756 case DW_TAG_imported_module
:
2757 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2758 information contained in these. DW_TAG_imported_declaration
2759 dies shouldn't have children; DW_TAG_imported_module dies
2760 shouldn't in the C++ case, but conceivably could in the
2761 Fortran case, so we'll have to replace this gdb_assert if
2762 Fortran compilers start generating that info. */
2763 processing_has_namespace_info
= 1;
2764 gdb_assert (die
->child
== NULL
);
2767 new_symbol (die
, NULL
, cu
);
2772 /* Return the fully qualified name of DIE, based on its DW_AT_name.
2773 If scope qualifiers are appropriate they will be added. The result
2774 will be allocated on the objfile_obstack, or NULL if the DIE does
2778 dwarf2_full_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
2780 struct attribute
*attr
;
2781 char *prefix
, *name
;
2782 struct ui_file
*buf
= NULL
;
2784 name
= dwarf2_name (die
, cu
);
2788 /* These are the only languages we know how to qualify names in. */
2789 if (cu
->language
!= language_cplus
2790 && cu
->language
!= language_java
)
2793 /* If no prefix is necessary for this type of DIE, return the
2794 unqualified name. The other three tags listed could be handled
2795 in pdi_needs_namespace, but that requires broader changes. */
2796 if (!pdi_needs_namespace (die
->tag
)
2797 && die
->tag
!= DW_TAG_subprogram
2798 && die
->tag
!= DW_TAG_variable
2799 && die
->tag
!= DW_TAG_member
)
2802 prefix
= determine_prefix (die
, cu
);
2803 if (*prefix
!= '\0')
2804 name
= typename_concat (&cu
->objfile
->objfile_obstack
, prefix
,
2811 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2813 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2817 free_cu_line_header (void *arg
)
2819 struct dwarf2_cu
*cu
= arg
;
2821 free_line_header (cu
->line_header
);
2822 cu
->line_header
= NULL
;
2826 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2828 struct objfile
*objfile
= cu
->objfile
;
2829 struct comp_unit_head
*cu_header
= &cu
->header
;
2830 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2831 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2832 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2833 struct attribute
*attr
;
2835 char *comp_dir
= NULL
;
2836 struct die_info
*child_die
;
2837 bfd
*abfd
= objfile
->obfd
;
2838 struct line_header
*line_header
= 0;
2841 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2843 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2845 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2846 from finish_block. */
2847 if (lowpc
== ((CORE_ADDR
) -1))
2852 /* Find the filename. Do not use dwarf2_name here, since the filename
2853 is not a source language identifier. */
2854 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2857 name
= DW_STRING (attr
);
2860 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2862 comp_dir
= DW_STRING (attr
);
2863 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
2865 comp_dir
= ldirname (name
);
2866 if (comp_dir
!= NULL
)
2867 make_cleanup (xfree
, comp_dir
);
2869 if (comp_dir
!= NULL
)
2871 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2872 directory, get rid of it. */
2873 char *cp
= strchr (comp_dir
, ':');
2875 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2882 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2885 set_cu_language (DW_UNSND (attr
), cu
);
2888 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
2890 cu
->producer
= DW_STRING (attr
);
2892 /* We assume that we're processing GCC output. */
2893 processing_gcc_compilation
= 2;
2895 processing_has_namespace_info
= 0;
2897 start_symtab (name
, comp_dir
, lowpc
);
2898 record_debugformat ("DWARF 2");
2899 record_producer (cu
->producer
);
2901 initialize_cu_func_list (cu
);
2903 /* Decode line number information if present. We do this before
2904 processing child DIEs, so that the line header table is available
2905 for DW_AT_decl_file. */
2906 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2909 unsigned int line_offset
= DW_UNSND (attr
);
2910 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2913 cu
->line_header
= line_header
;
2914 make_cleanup (free_cu_line_header
, cu
);
2915 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
2919 /* Process all dies in compilation unit. */
2920 if (die
->child
!= NULL
)
2922 child_die
= die
->child
;
2923 while (child_die
&& child_die
->tag
)
2925 process_die (child_die
, cu
);
2926 child_die
= sibling_die (child_die
);
2930 /* Decode macro information, if present. Dwarf 2 macro information
2931 refers to information in the line number info statement program
2932 header, so we can only read it if we've read the header
2934 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2935 if (attr
&& line_header
)
2937 unsigned int macro_offset
= DW_UNSND (attr
);
2938 dwarf_decode_macros (line_header
, macro_offset
,
2939 comp_dir
, abfd
, cu
);
2941 do_cleanups (back_to
);
2945 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2946 struct dwarf2_cu
*cu
)
2948 struct function_range
*thisfn
;
2950 thisfn
= (struct function_range
*)
2951 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
2952 thisfn
->name
= name
;
2953 thisfn
->lowpc
= lowpc
;
2954 thisfn
->highpc
= highpc
;
2955 thisfn
->seen_line
= 0;
2956 thisfn
->next
= NULL
;
2958 if (cu
->last_fn
== NULL
)
2959 cu
->first_fn
= thisfn
;
2961 cu
->last_fn
->next
= thisfn
;
2963 cu
->last_fn
= thisfn
;
2967 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2969 struct objfile
*objfile
= cu
->objfile
;
2970 struct context_stack
*new;
2973 struct die_info
*child_die
;
2974 struct attribute
*attr
;
2977 struct block
*block
;
2979 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2981 name
= dwarf2_linkage_name (die
, cu
);
2983 /* Ignore functions with missing or empty names and functions with
2984 missing or invalid low and high pc attributes. */
2985 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2991 /* Record the function range for dwarf_decode_lines. */
2992 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
2994 new = push_context (0, lowpc
);
2995 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
2997 /* If there is a location expression for DW_AT_frame_base, record
2999 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3001 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3002 expression is being recorded directly in the function's symbol
3003 and not in a separate frame-base object. I guess this hack is
3004 to avoid adding some sort of frame-base adjunct/annex to the
3005 function's symbol :-(. The problem with doing this is that it
3006 results in a function symbol with a location expression that
3007 has nothing to do with the location of the function, ouch! The
3008 relationship should be: a function's symbol has-a frame base; a
3009 frame-base has-a location expression. */
3010 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3012 cu
->list_in_scope
= &local_symbols
;
3014 if (die
->child
!= NULL
)
3016 child_die
= die
->child
;
3017 while (child_die
&& child_die
->tag
)
3019 process_die (child_die
, cu
);
3020 child_die
= sibling_die (child_die
);
3024 new = pop_context ();
3025 /* Make a block for the local symbols within. */
3026 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3027 lowpc
, highpc
, objfile
);
3029 /* For C++, set the block's scope. */
3030 if (cu
->language
== language_cplus
)
3031 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
3032 determine_prefix (die
, cu
),
3033 processing_has_namespace_info
);
3035 /* If we have address ranges, record them. */
3036 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3038 /* In C++, we can have functions nested inside functions (e.g., when
3039 a function declares a class that has methods). This means that
3040 when we finish processing a function scope, we may need to go
3041 back to building a containing block's symbol lists. */
3042 local_symbols
= new->locals
;
3043 param_symbols
= new->params
;
3045 /* If we've finished processing a top-level function, subsequent
3046 symbols go in the file symbol list. */
3047 if (outermost_context_p ())
3048 cu
->list_in_scope
= &file_symbols
;
3051 /* Process all the DIES contained within a lexical block scope. Start
3052 a new scope, process the dies, and then close the scope. */
3055 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3057 struct objfile
*objfile
= cu
->objfile
;
3058 struct context_stack
*new;
3059 CORE_ADDR lowpc
, highpc
;
3060 struct die_info
*child_die
;
3063 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3065 /* Ignore blocks with missing or invalid low and high pc attributes. */
3066 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3067 as multiple lexical blocks? Handling children in a sane way would
3068 be nasty. Might be easier to properly extend generic blocks to
3070 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3075 push_context (0, lowpc
);
3076 if (die
->child
!= NULL
)
3078 child_die
= die
->child
;
3079 while (child_die
&& child_die
->tag
)
3081 process_die (child_die
, cu
);
3082 child_die
= sibling_die (child_die
);
3085 new = pop_context ();
3087 if (local_symbols
!= NULL
)
3090 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3093 /* Note that recording ranges after traversing children, as we
3094 do here, means that recording a parent's ranges entails
3095 walking across all its children's ranges as they appear in
3096 the address map, which is quadratic behavior.
3098 It would be nicer to record the parent's ranges before
3099 traversing its children, simply overriding whatever you find
3100 there. But since we don't even decide whether to create a
3101 block until after we've traversed its children, that's hard
3103 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3105 local_symbols
= new->locals
;
3108 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3109 Return 1 if the attributes are present and valid, otherwise, return 0.
3110 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3113 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
3114 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
3115 struct partial_symtab
*ranges_pst
)
3117 struct objfile
*objfile
= cu
->objfile
;
3118 struct comp_unit_head
*cu_header
= &cu
->header
;
3119 bfd
*obfd
= objfile
->obfd
;
3120 unsigned int addr_size
= cu_header
->addr_size
;
3121 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3122 /* Base address selection entry. */
3133 found_base
= cu_header
->base_known
;
3134 base
= cu_header
->base_address
;
3136 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3138 complaint (&symfile_complaints
,
3139 _("Offset %d out of bounds for DW_AT_ranges attribute"),
3143 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3145 /* Read in the largest possible address. */
3146 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
3147 if ((marker
& mask
) == mask
)
3149 /* If we found the largest possible address, then
3150 read the base address. */
3151 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3152 buffer
+= 2 * addr_size
;
3153 offset
+= 2 * addr_size
;
3159 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3163 CORE_ADDR range_beginning
, range_end
;
3165 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
3166 buffer
+= addr_size
;
3167 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
3168 buffer
+= addr_size
;
3169 offset
+= 2 * addr_size
;
3171 /* An end of list marker is a pair of zero addresses. */
3172 if (range_beginning
== 0 && range_end
== 0)
3173 /* Found the end of list entry. */
3176 /* Each base address selection entry is a pair of 2 values.
3177 The first is the largest possible address, the second is
3178 the base address. Check for a base address here. */
3179 if ((range_beginning
& mask
) == mask
)
3181 /* If we found the largest possible address, then
3182 read the base address. */
3183 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3190 /* We have no valid base address for the ranges
3192 complaint (&symfile_complaints
,
3193 _("Invalid .debug_ranges data (no base address)"));
3197 range_beginning
+= base
;
3200 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
3201 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3202 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
3205 /* FIXME: This is recording everything as a low-high
3206 segment of consecutive addresses. We should have a
3207 data structure for discontiguous block ranges
3211 low
= range_beginning
;
3217 if (range_beginning
< low
)
3218 low
= range_beginning
;
3219 if (range_end
> high
)
3225 /* If the first entry is an end-of-list marker, the range
3226 describes an empty scope, i.e. no instructions. */
3232 *high_return
= high
;
3236 /* Get low and high pc attributes from a die. Return 1 if the attributes
3237 are present and valid, otherwise, return 0. Return -1 if the range is
3238 discontinuous, i.e. derived from DW_AT_ranges information. */
3240 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
3241 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
3243 struct attribute
*attr
;
3248 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3251 high
= DW_ADDR (attr
);
3252 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3254 low
= DW_ADDR (attr
);
3256 /* Found high w/o low attribute. */
3259 /* Found consecutive range of addresses. */
3264 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3267 /* Value of the DW_AT_ranges attribute is the offset in the
3268 .debug_ranges section. */
3269 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, NULL
))
3271 /* Found discontinuous range of addresses. */
3279 /* When using the GNU linker, .gnu.linkonce. sections are used to
3280 eliminate duplicate copies of functions and vtables and such.
3281 The linker will arbitrarily choose one and discard the others.
3282 The AT_*_pc values for such functions refer to local labels in
3283 these sections. If the section from that file was discarded, the
3284 labels are not in the output, so the relocs get a value of 0.
3285 If this is a discarded function, mark the pc bounds as invalid,
3286 so that GDB will ignore it. */
3287 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3295 /* Get the low and high pc's represented by the scope DIE, and store
3296 them in *LOWPC and *HIGHPC. If the correct values can't be
3297 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3300 get_scope_pc_bounds (struct die_info
*die
,
3301 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3302 struct dwarf2_cu
*cu
)
3304 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3305 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3306 CORE_ADDR current_low
, current_high
;
3308 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3310 best_low
= current_low
;
3311 best_high
= current_high
;
3315 struct die_info
*child
= die
->child
;
3317 while (child
&& child
->tag
)
3319 switch (child
->tag
) {
3320 case DW_TAG_subprogram
:
3321 if (dwarf2_get_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
))
3323 best_low
= min (best_low
, current_low
);
3324 best_high
= max (best_high
, current_high
);
3327 case DW_TAG_namespace
:
3328 /* FIXME: carlton/2004-01-16: Should we do this for
3329 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3330 that current GCC's always emit the DIEs corresponding
3331 to definitions of methods of classes as children of a
3332 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3333 the DIEs giving the declarations, which could be
3334 anywhere). But I don't see any reason why the
3335 standards says that they have to be there. */
3336 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3338 if (current_low
!= ((CORE_ADDR
) -1))
3340 best_low
= min (best_low
, current_low
);
3341 best_high
= max (best_high
, current_high
);
3349 child
= sibling_die (child
);
3354 *highpc
= best_high
;
3357 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
3360 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
3361 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
3363 struct attribute
*attr
;
3365 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3368 CORE_ADDR high
= DW_ADDR (attr
);
3369 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3372 CORE_ADDR low
= DW_ADDR (attr
);
3373 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
3377 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3380 bfd
*obfd
= cu
->objfile
->obfd
;
3382 /* The value of the DW_AT_ranges attribute is the offset of the
3383 address range list in the .debug_ranges section. */
3384 unsigned long offset
= DW_UNSND (attr
);
3385 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3387 /* For some target architectures, but not others, the
3388 read_address function sign-extends the addresses it returns.
3389 To recognize base address selection entries, we need a
3391 unsigned int addr_size
= cu
->header
.addr_size
;
3392 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3394 /* The base address, to which the next pair is relative. Note
3395 that this 'base' is a DWARF concept: most entries in a range
3396 list are relative, to reduce the number of relocs against the
3397 debugging information. This is separate from this function's
3398 'baseaddr' argument, which GDB uses to relocate debugging
3399 information from a shared library based on the address at
3400 which the library was loaded. */
3401 CORE_ADDR base
= cu
->header
.base_address
;
3402 int base_known
= cu
->header
.base_known
;
3404 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3406 complaint (&symfile_complaints
,
3407 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
3414 unsigned int bytes_read
;
3415 CORE_ADDR start
, end
;
3417 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3418 buffer
+= bytes_read
;
3419 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3420 buffer
+= bytes_read
;
3422 /* Did we find the end of the range list? */
3423 if (start
== 0 && end
== 0)
3426 /* Did we find a base address selection entry? */
3427 else if ((start
& base_select_mask
) == base_select_mask
)
3433 /* We found an ordinary address range. */
3438 complaint (&symfile_complaints
,
3439 _("Invalid .debug_ranges data (no base address)"));
3443 record_block_range (block
,
3444 baseaddr
+ base
+ start
,
3445 baseaddr
+ base
+ end
- 1);
3451 /* Add an aggregate field to the field list. */
3454 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3455 struct dwarf2_cu
*cu
)
3457 struct objfile
*objfile
= cu
->objfile
;
3458 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3459 struct nextfield
*new_field
;
3460 struct attribute
*attr
;
3462 char *fieldname
= "";
3464 /* Allocate a new field list entry and link it in. */
3465 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3466 make_cleanup (xfree
, new_field
);
3467 memset (new_field
, 0, sizeof (struct nextfield
));
3468 new_field
->next
= fip
->fields
;
3469 fip
->fields
= new_field
;
3472 /* Handle accessibility and virtuality of field.
3473 The default accessibility for members is public, the default
3474 accessibility for inheritance is private. */
3475 if (die
->tag
!= DW_TAG_inheritance
)
3476 new_field
->accessibility
= DW_ACCESS_public
;
3478 new_field
->accessibility
= DW_ACCESS_private
;
3479 new_field
->virtuality
= DW_VIRTUALITY_none
;
3481 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3483 new_field
->accessibility
= DW_UNSND (attr
);
3484 if (new_field
->accessibility
!= DW_ACCESS_public
)
3485 fip
->non_public_fields
= 1;
3486 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3488 new_field
->virtuality
= DW_UNSND (attr
);
3490 fp
= &new_field
->field
;
3492 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3494 /* Data member other than a C++ static data member. */
3496 /* Get type of field. */
3497 fp
->type
= die_type (die
, cu
);
3499 FIELD_STATIC_KIND (*fp
) = 0;
3501 /* Get bit size of field (zero if none). */
3502 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3505 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3509 FIELD_BITSIZE (*fp
) = 0;
3512 /* Get bit offset of field. */
3513 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3518 if (attr_form_is_section_offset (attr
))
3520 dwarf2_complex_location_expr_complaint ();
3523 else if (attr_form_is_constant (attr
))
3524 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
3526 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
3528 FIELD_BITPOS (*fp
) = byte_offset
* bits_per_byte
;
3531 FIELD_BITPOS (*fp
) = 0;
3532 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3535 if (gdbarch_bits_big_endian (gdbarch
))
3537 /* For big endian bits, the DW_AT_bit_offset gives the
3538 additional bit offset from the MSB of the containing
3539 anonymous object to the MSB of the field. We don't
3540 have to do anything special since we don't need to
3541 know the size of the anonymous object. */
3542 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3546 /* For little endian bits, compute the bit offset to the
3547 MSB of the anonymous object, subtract off the number of
3548 bits from the MSB of the field to the MSB of the
3549 object, and then subtract off the number of bits of
3550 the field itself. The result is the bit offset of
3551 the LSB of the field. */
3553 int bit_offset
= DW_UNSND (attr
);
3555 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3558 /* The size of the anonymous object containing
3559 the bit field is explicit, so use the
3560 indicated size (in bytes). */
3561 anonymous_size
= DW_UNSND (attr
);
3565 /* The size of the anonymous object containing
3566 the bit field must be inferred from the type
3567 attribute of the data member containing the
3569 anonymous_size
= TYPE_LENGTH (fp
->type
);
3571 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
3572 - bit_offset
- FIELD_BITSIZE (*fp
);
3576 /* Get name of field. */
3577 fieldname
= dwarf2_name (die
, cu
);
3578 if (fieldname
== NULL
)
3581 /* The name is already allocated along with this objfile, so we don't
3582 need to duplicate it for the type. */
3583 fp
->name
= fieldname
;
3585 /* Change accessibility for artificial fields (e.g. virtual table
3586 pointer or virtual base class pointer) to private. */
3587 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
3589 new_field
->accessibility
= DW_ACCESS_private
;
3590 fip
->non_public_fields
= 1;
3593 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
3595 /* C++ static member. */
3597 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3598 is a declaration, but all versions of G++ as of this writing
3599 (so through at least 3.2.1) incorrectly generate
3600 DW_TAG_variable tags. */
3604 /* Get name of field. */
3605 fieldname
= dwarf2_name (die
, cu
);
3606 if (fieldname
== NULL
)
3609 /* Get physical name. */
3610 physname
= dwarf2_linkage_name (die
, cu
);
3612 /* The name is already allocated along with this objfile, so we don't
3613 need to duplicate it for the type. */
3614 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
3615 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3616 FIELD_NAME (*fp
) = fieldname
;
3618 else if (die
->tag
== DW_TAG_inheritance
)
3620 /* C++ base class field. */
3621 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3623 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
3625 FIELD_BITSIZE (*fp
) = 0;
3626 FIELD_STATIC_KIND (*fp
) = 0;
3627 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3628 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
3629 fip
->nbaseclasses
++;
3633 /* Create the vector of fields, and attach it to the type. */
3636 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3637 struct dwarf2_cu
*cu
)
3639 int nfields
= fip
->nfields
;
3641 /* Record the field count, allocate space for the array of fields,
3642 and create blank accessibility bitfields if necessary. */
3643 TYPE_NFIELDS (type
) = nfields
;
3644 TYPE_FIELDS (type
) = (struct field
*)
3645 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3646 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3648 if (fip
->non_public_fields
)
3650 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3652 TYPE_FIELD_PRIVATE_BITS (type
) =
3653 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3654 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3656 TYPE_FIELD_PROTECTED_BITS (type
) =
3657 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3658 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3660 TYPE_FIELD_IGNORE_BITS (type
) =
3661 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3662 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3665 /* If the type has baseclasses, allocate and clear a bit vector for
3666 TYPE_FIELD_VIRTUAL_BITS. */
3667 if (fip
->nbaseclasses
)
3669 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3670 unsigned char *pointer
;
3672 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3673 pointer
= TYPE_ALLOC (type
, num_bytes
);
3674 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
3675 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3676 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3679 /* Copy the saved-up fields into the field vector. Start from the head
3680 of the list, adding to the tail of the field array, so that they end
3681 up in the same order in the array in which they were added to the list. */
3682 while (nfields
-- > 0)
3684 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3685 switch (fip
->fields
->accessibility
)
3687 case DW_ACCESS_private
:
3688 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3691 case DW_ACCESS_protected
:
3692 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3695 case DW_ACCESS_public
:
3699 /* Unknown accessibility. Complain and treat it as public. */
3701 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
3702 fip
->fields
->accessibility
);
3706 if (nfields
< fip
->nbaseclasses
)
3708 switch (fip
->fields
->virtuality
)
3710 case DW_VIRTUALITY_virtual
:
3711 case DW_VIRTUALITY_pure_virtual
:
3712 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3716 fip
->fields
= fip
->fields
->next
;
3720 /* Add a member function to the proper fieldlist. */
3723 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3724 struct type
*type
, struct dwarf2_cu
*cu
)
3726 struct objfile
*objfile
= cu
->objfile
;
3727 struct attribute
*attr
;
3728 struct fnfieldlist
*flp
;
3730 struct fn_field
*fnp
;
3733 struct nextfnfield
*new_fnfield
;
3734 struct type
*this_type
;
3736 /* Get name of member function. */
3737 fieldname
= dwarf2_name (die
, cu
);
3738 if (fieldname
== NULL
)
3741 /* Get the mangled name. */
3742 physname
= dwarf2_linkage_name (die
, cu
);
3744 /* Look up member function name in fieldlist. */
3745 for (i
= 0; i
< fip
->nfnfields
; i
++)
3747 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3751 /* Create new list element if necessary. */
3752 if (i
< fip
->nfnfields
)
3753 flp
= &fip
->fnfieldlists
[i
];
3756 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3758 fip
->fnfieldlists
= (struct fnfieldlist
*)
3759 xrealloc (fip
->fnfieldlists
,
3760 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3761 * sizeof (struct fnfieldlist
));
3762 if (fip
->nfnfields
== 0)
3763 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3765 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3766 flp
->name
= fieldname
;
3772 /* Create a new member function field and chain it to the field list
3774 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3775 make_cleanup (xfree
, new_fnfield
);
3776 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3777 new_fnfield
->next
= flp
->head
;
3778 flp
->head
= new_fnfield
;
3781 /* Fill in the member function field info. */
3782 fnp
= &new_fnfield
->fnfield
;
3783 /* The name is already allocated along with this objfile, so we don't
3784 need to duplicate it for the type. */
3785 fnp
->physname
= physname
? physname
: "";
3786 fnp
->type
= alloc_type (objfile
);
3787 this_type
= read_type_die (die
, cu
);
3788 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
3790 int nparams
= TYPE_NFIELDS (this_type
);
3792 /* TYPE is the domain of this method, and THIS_TYPE is the type
3793 of the method itself (TYPE_CODE_METHOD). */
3794 smash_to_method_type (fnp
->type
, type
,
3795 TYPE_TARGET_TYPE (this_type
),
3796 TYPE_FIELDS (this_type
),
3797 TYPE_NFIELDS (this_type
),
3798 TYPE_VARARGS (this_type
));
3800 /* Handle static member functions.
3801 Dwarf2 has no clean way to discern C++ static and non-static
3802 member functions. G++ helps GDB by marking the first
3803 parameter for non-static member functions (which is the
3804 this pointer) as artificial. We obtain this information
3805 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3806 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
3807 fnp
->voffset
= VOFFSET_STATIC
;
3810 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
3813 /* Get fcontext from DW_AT_containing_type if present. */
3814 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3815 fnp
->fcontext
= die_containing_type (die
, cu
);
3817 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3818 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3820 /* Get accessibility. */
3821 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3824 switch (DW_UNSND (attr
))
3826 case DW_ACCESS_private
:
3827 fnp
->is_private
= 1;
3829 case DW_ACCESS_protected
:
3830 fnp
->is_protected
= 1;
3835 /* Check for artificial methods. */
3836 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3837 if (attr
&& DW_UNSND (attr
) != 0)
3838 fnp
->is_artificial
= 1;
3840 /* Get index in virtual function table if it is a virtual member function. */
3841 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3844 /* Support the .debug_loc offsets */
3845 if (attr_form_is_block (attr
))
3847 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3849 else if (attr_form_is_section_offset (attr
))
3851 dwarf2_complex_location_expr_complaint ();
3855 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3861 /* Create the vector of member function fields, and attach it to the type. */
3864 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3865 struct dwarf2_cu
*cu
)
3867 struct fnfieldlist
*flp
;
3868 int total_length
= 0;
3871 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3872 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3873 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3875 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3877 struct nextfnfield
*nfp
= flp
->head
;
3878 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3881 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3882 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3883 fn_flp
->fn_fields
= (struct fn_field
*)
3884 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3885 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3886 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3888 total_length
+= flp
->length
;
3891 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3892 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3895 /* Returns non-zero if NAME is the name of a vtable member in CU's
3896 language, zero otherwise. */
3898 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
3900 static const char vptr
[] = "_vptr";
3901 static const char vtable
[] = "vtable";
3903 /* Look for the C++ and Java forms of the vtable. */
3904 if ((cu
->language
== language_java
3905 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
3906 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
3907 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
3913 /* GCC outputs unnamed structures that are really pointers to member
3914 functions, with the ABI-specified layout. If DIE (from CU) describes
3915 such a structure, set its type, and return nonzero. Otherwise return
3918 GCC shouldn't do this; it should just output pointer to member DIEs.
3919 This is GCC PR debug/28767. */
3921 static struct type
*
3922 quirk_gcc_member_function_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
)
3924 struct objfile
*objfile
= cu
->objfile
;
3926 struct die_info
*pfn_die
, *delta_die
;
3927 struct attribute
*pfn_name
, *delta_name
;
3928 struct type
*pfn_type
, *domain_type
;
3930 /* Check for a structure with no name and two children. */
3931 if (die
->tag
!= DW_TAG_structure_type
3932 || dwarf2_attr (die
, DW_AT_name
, cu
) != NULL
3933 || die
->child
== NULL
3934 || die
->child
->sibling
== NULL
3935 || (die
->child
->sibling
->sibling
!= NULL
3936 && die
->child
->sibling
->sibling
->tag
!= DW_TAG_padding
))
3939 /* Check for __pfn and __delta members. */
3940 pfn_die
= die
->child
;
3941 pfn_name
= dwarf2_attr (pfn_die
, DW_AT_name
, cu
);
3942 if (pfn_die
->tag
!= DW_TAG_member
3944 || DW_STRING (pfn_name
) == NULL
3945 || strcmp ("__pfn", DW_STRING (pfn_name
)) != 0)
3948 delta_die
= pfn_die
->sibling
;
3949 delta_name
= dwarf2_attr (delta_die
, DW_AT_name
, cu
);
3950 if (delta_die
->tag
!= DW_TAG_member
3951 || delta_name
== NULL
3952 || DW_STRING (delta_name
) == NULL
3953 || strcmp ("__delta", DW_STRING (delta_name
)) != 0)
3956 /* Find the type of the method. */
3957 pfn_type
= die_type (pfn_die
, cu
);
3958 if (pfn_type
== NULL
3959 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
3960 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
3963 /* Look for the "this" argument. */
3964 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
3965 if (TYPE_NFIELDS (pfn_type
) == 0
3966 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
3969 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
3970 type
= alloc_type (objfile
);
3971 smash_to_method_type (type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
3972 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
3973 TYPE_VARARGS (pfn_type
));
3974 type
= lookup_methodptr_type (type
);
3975 return set_die_type (die
, type
, cu
);
3978 /* Called when we find the DIE that starts a structure or union scope
3979 (definition) to process all dies that define the members of the
3982 NOTE: we need to call struct_type regardless of whether or not the
3983 DIE has an at_name attribute, since it might be an anonymous
3984 structure or union. This gets the type entered into our set of
3987 However, if the structure is incomplete (an opaque struct/union)
3988 then suppress creating a symbol table entry for it since gdb only
3989 wants to find the one with the complete definition. Note that if
3990 it is complete, we just call new_symbol, which does it's own
3991 checking about whether the struct/union is anonymous or not (and
3992 suppresses creating a symbol table entry itself). */
3994 static struct type
*
3995 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3997 struct objfile
*objfile
= cu
->objfile
;
3999 struct attribute
*attr
;
4001 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4003 type
= quirk_gcc_member_function_pointer (die
, cu
);
4007 type
= alloc_type (objfile
);
4008 INIT_CPLUS_SPECIFIC (type
);
4009 name
= dwarf2_name (die
, cu
);
4012 if (cu
->language
== language_cplus
4013 || cu
->language
== language_java
)
4015 const char *new_prefix
= determine_class_name (die
, cu
);
4016 TYPE_TAG_NAME (type
) = (char *) new_prefix
;
4020 /* The name is already allocated along with this objfile, so
4021 we don't need to duplicate it for the type. */
4022 TYPE_TAG_NAME (type
) = name
;
4026 if (die
->tag
== DW_TAG_structure_type
)
4028 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
4030 else if (die
->tag
== DW_TAG_union_type
)
4032 TYPE_CODE (type
) = TYPE_CODE_UNION
;
4036 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
4038 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
4041 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4044 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4048 TYPE_LENGTH (type
) = 0;
4051 TYPE_STUB_SUPPORTED (type
) = 1;
4052 if (die_is_declaration (die
, cu
))
4053 TYPE_STUB (type
) = 1;
4055 /* We need to add the type field to the die immediately so we don't
4056 infinitely recurse when dealing with pointers to the structure
4057 type within the structure itself. */
4058 set_die_type (die
, type
, cu
);
4060 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
4062 struct field_info fi
;
4063 struct die_info
*child_die
;
4065 memset (&fi
, 0, sizeof (struct field_info
));
4067 child_die
= die
->child
;
4069 while (child_die
&& child_die
->tag
)
4071 if (child_die
->tag
== DW_TAG_member
4072 || child_die
->tag
== DW_TAG_variable
)
4074 /* NOTE: carlton/2002-11-05: A C++ static data member
4075 should be a DW_TAG_member that is a declaration, but
4076 all versions of G++ as of this writing (so through at
4077 least 3.2.1) incorrectly generate DW_TAG_variable
4078 tags for them instead. */
4079 dwarf2_add_field (&fi
, child_die
, cu
);
4081 else if (child_die
->tag
== DW_TAG_subprogram
)
4083 /* C++ member function. */
4084 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
4086 else if (child_die
->tag
== DW_TAG_inheritance
)
4088 /* C++ base class field. */
4089 dwarf2_add_field (&fi
, child_die
, cu
);
4091 child_die
= sibling_die (child_die
);
4094 /* Attach fields and member functions to the type. */
4096 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
4099 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
4101 /* Get the type which refers to the base class (possibly this
4102 class itself) which contains the vtable pointer for the current
4103 class from the DW_AT_containing_type attribute. */
4105 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4107 struct type
*t
= die_containing_type (die
, cu
);
4109 TYPE_VPTR_BASETYPE (type
) = t
;
4114 /* Our own class provides vtbl ptr. */
4115 for (i
= TYPE_NFIELDS (t
) - 1;
4116 i
>= TYPE_N_BASECLASSES (t
);
4119 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
4121 if (is_vtable_name (fieldname
, cu
))
4123 TYPE_VPTR_FIELDNO (type
) = i
;
4128 /* Complain if virtual function table field not found. */
4129 if (i
< TYPE_N_BASECLASSES (t
))
4130 complaint (&symfile_complaints
,
4131 _("virtual function table pointer not found when defining class '%s'"),
4132 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
4137 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
4140 else if (cu
->producer
4141 && strncmp (cu
->producer
,
4142 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
4144 /* The IBM XLC compiler does not provide direct indication
4145 of the containing type, but the vtable pointer is
4146 always named __vfp. */
4150 for (i
= TYPE_NFIELDS (type
) - 1;
4151 i
>= TYPE_N_BASECLASSES (type
);
4154 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
4156 TYPE_VPTR_FIELDNO (type
) = i
;
4157 TYPE_VPTR_BASETYPE (type
) = type
;
4165 do_cleanups (back_to
);
4170 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4172 struct objfile
*objfile
= cu
->objfile
;
4173 struct die_info
*child_die
= die
->child
;
4174 struct type
*this_type
;
4176 this_type
= get_die_type (die
, cu
);
4177 if (this_type
== NULL
)
4178 this_type
= read_structure_type (die
, cu
);
4180 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
4181 snapshots) has been known to create a die giving a declaration
4182 for a class that has, as a child, a die giving a definition for a
4183 nested class. So we have to process our children even if the
4184 current die is a declaration. Normally, of course, a declaration
4185 won't have any children at all. */
4187 while (child_die
!= NULL
&& child_die
->tag
)
4189 if (child_die
->tag
== DW_TAG_member
4190 || child_die
->tag
== DW_TAG_variable
4191 || child_die
->tag
== DW_TAG_inheritance
)
4196 process_die (child_die
, cu
);
4198 child_die
= sibling_die (child_die
);
4201 /* Do not consider external references. According to the DWARF standard,
4202 these DIEs are identified by the fact that they have no byte_size
4203 attribute, and a declaration attribute. */
4204 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
4205 || !die_is_declaration (die
, cu
))
4206 new_symbol (die
, this_type
, cu
);
4209 /* Given a DW_AT_enumeration_type die, set its type. We do not
4210 complete the type's fields yet, or create any symbols. */
4212 static struct type
*
4213 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4215 struct objfile
*objfile
= cu
->objfile
;
4217 struct attribute
*attr
;
4220 type
= alloc_type (objfile
);
4222 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4223 name
= dwarf2_full_name (die
, cu
);
4225 TYPE_TAG_NAME (type
) = (char *) name
;
4227 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4230 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4234 TYPE_LENGTH (type
) = 0;
4237 /* The enumeration DIE can be incomplete. In Ada, any type can be
4238 declared as private in the package spec, and then defined only
4239 inside the package body. Such types are known as Taft Amendment
4240 Types. When another package uses such a type, an incomplete DIE
4241 may be generated by the compiler. */
4242 if (die_is_declaration (die
, cu
))
4243 TYPE_STUB (type
) = 1;
4245 return set_die_type (die
, type
, cu
);
4248 /* Determine the name of the type represented by DIE, which should be
4249 a named C++ or Java compound type. Return the name in question,
4250 allocated on the objfile obstack. */
4253 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
4255 const char *new_prefix
= NULL
;
4257 /* If we don't have namespace debug info, guess the name by trying
4258 to demangle the names of members, just like we did in
4259 guess_structure_name. */
4260 if (!processing_has_namespace_info
)
4262 struct die_info
*child
;
4264 for (child
= die
->child
;
4265 child
!= NULL
&& child
->tag
!= 0;
4266 child
= sibling_die (child
))
4268 if (child
->tag
== DW_TAG_subprogram
)
4271 = language_class_name_from_physname (cu
->language_defn
,
4275 if (phys_prefix
!= NULL
)
4278 = obsavestring (phys_prefix
, strlen (phys_prefix
),
4279 &cu
->objfile
->objfile_obstack
);
4280 xfree (phys_prefix
);
4287 if (new_prefix
== NULL
)
4288 new_prefix
= dwarf2_full_name (die
, cu
);
4293 /* Given a pointer to a die which begins an enumeration, process all
4294 the dies that define the members of the enumeration, and create the
4295 symbol for the enumeration type.
4297 NOTE: We reverse the order of the element list. */
4300 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4302 struct objfile
*objfile
= cu
->objfile
;
4303 struct die_info
*child_die
;
4304 struct field
*fields
;
4307 int unsigned_enum
= 1;
4309 struct type
*this_type
;
4313 this_type
= get_die_type (die
, cu
);
4314 if (this_type
== NULL
)
4315 this_type
= read_enumeration_type (die
, cu
);
4316 if (die
->child
!= NULL
)
4318 child_die
= die
->child
;
4319 while (child_die
&& child_die
->tag
)
4321 if (child_die
->tag
!= DW_TAG_enumerator
)
4323 process_die (child_die
, cu
);
4327 name
= dwarf2_name (child_die
, cu
);
4330 sym
= new_symbol (child_die
, this_type
, cu
);
4331 if (SYMBOL_VALUE (sym
) < 0)
4334 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4336 fields
= (struct field
*)
4338 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
4339 * sizeof (struct field
));
4342 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
4343 FIELD_TYPE (fields
[num_fields
]) = NULL
;
4344 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
4345 FIELD_BITSIZE (fields
[num_fields
]) = 0;
4346 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
4352 child_die
= sibling_die (child_die
);
4357 TYPE_NFIELDS (this_type
) = num_fields
;
4358 TYPE_FIELDS (this_type
) = (struct field
*)
4359 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
4360 memcpy (TYPE_FIELDS (this_type
), fields
,
4361 sizeof (struct field
) * num_fields
);
4365 TYPE_UNSIGNED (this_type
) = 1;
4368 new_symbol (die
, this_type
, cu
);
4371 /* Extract all information from a DW_TAG_array_type DIE and put it in
4372 the DIE's type field. For now, this only handles one dimensional
4375 static struct type
*
4376 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4378 struct objfile
*objfile
= cu
->objfile
;
4379 struct die_info
*child_die
;
4380 struct type
*type
= NULL
;
4381 struct type
*element_type
, *range_type
, *index_type
;
4382 struct type
**range_types
= NULL
;
4383 struct attribute
*attr
;
4385 struct cleanup
*back_to
;
4388 element_type
= die_type (die
, cu
);
4390 /* Irix 6.2 native cc creates array types without children for
4391 arrays with unspecified length. */
4392 if (die
->child
== NULL
)
4394 index_type
= builtin_type_int32
;
4395 range_type
= create_range_type (NULL
, index_type
, 0, -1);
4396 type
= create_array_type (NULL
, element_type
, range_type
);
4397 return set_die_type (die
, type
, cu
);
4400 back_to
= make_cleanup (null_cleanup
, NULL
);
4401 child_die
= die
->child
;
4402 while (child_die
&& child_die
->tag
)
4404 if (child_die
->tag
== DW_TAG_subrange_type
)
4406 struct type
*child_type
= read_type_die (child_die
, cu
);
4407 if (child_type
!= NULL
)
4409 /* The range type was succesfully read. Save it for
4410 the array type creation. */
4411 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
4413 range_types
= (struct type
**)
4414 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
4415 * sizeof (struct type
*));
4417 make_cleanup (free_current_contents
, &range_types
);
4419 range_types
[ndim
++] = child_type
;
4422 child_die
= sibling_die (child_die
);
4425 /* Dwarf2 dimensions are output from left to right, create the
4426 necessary array types in backwards order. */
4428 type
= element_type
;
4430 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
4434 type
= create_array_type (NULL
, type
, range_types
[i
++]);
4439 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
4442 /* Understand Dwarf2 support for vector types (like they occur on
4443 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4444 array type. This is not part of the Dwarf2/3 standard yet, but a
4445 custom vendor extension. The main difference between a regular
4446 array and the vector variant is that vectors are passed by value
4448 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4450 make_vector_type (type
);
4452 name
= dwarf2_name (die
, cu
);
4454 TYPE_NAME (type
) = name
;
4456 do_cleanups (back_to
);
4458 /* Install the type in the die. */
4459 return set_die_type (die
, type
, cu
);
4462 static enum dwarf_array_dim_ordering
4463 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4465 struct attribute
*attr
;
4467 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4469 if (attr
) return DW_SND (attr
);
4472 GNU F77 is a special case, as at 08/2004 array type info is the
4473 opposite order to the dwarf2 specification, but data is still
4474 laid out as per normal fortran.
4476 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4480 if (cu
->language
== language_fortran
&&
4481 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4483 return DW_ORD_row_major
;
4486 switch (cu
->language_defn
->la_array_ordering
)
4488 case array_column_major
:
4489 return DW_ORD_col_major
;
4490 case array_row_major
:
4492 return DW_ORD_row_major
;
4496 /* Extract all information from a DW_TAG_set_type DIE and put it in
4497 the DIE's type field. */
4499 static struct type
*
4500 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4502 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
4504 return set_die_type (die
, set_type
, cu
);
4507 /* First cut: install each common block member as a global variable. */
4510 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4512 struct die_info
*child_die
;
4513 struct attribute
*attr
;
4515 CORE_ADDR base
= (CORE_ADDR
) 0;
4517 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4520 /* Support the .debug_loc offsets */
4521 if (attr_form_is_block (attr
))
4523 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4525 else if (attr_form_is_section_offset (attr
))
4527 dwarf2_complex_location_expr_complaint ();
4531 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4532 "common block member");
4535 if (die
->child
!= NULL
)
4537 child_die
= die
->child
;
4538 while (child_die
&& child_die
->tag
)
4540 sym
= new_symbol (child_die
, NULL
, cu
);
4541 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4544 SYMBOL_VALUE_ADDRESS (sym
) =
4545 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4546 add_symbol_to_list (sym
, &global_symbols
);
4548 child_die
= sibling_die (child_die
);
4553 /* Create a type for a C++ namespace. */
4555 static struct type
*
4556 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4558 struct objfile
*objfile
= cu
->objfile
;
4559 const char *previous_prefix
, *name
;
4563 /* For extensions, reuse the type of the original namespace. */
4564 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
4566 struct die_info
*ext_die
;
4567 struct dwarf2_cu
*ext_cu
= cu
;
4568 ext_die
= dwarf2_extension (die
, &ext_cu
);
4569 type
= read_type_die (ext_die
, ext_cu
);
4570 return set_die_type (die
, type
, cu
);
4573 name
= namespace_name (die
, &is_anonymous
, cu
);
4575 /* Now build the name of the current namespace. */
4577 previous_prefix
= determine_prefix (die
, cu
);
4578 if (previous_prefix
[0] != '\0')
4579 name
= typename_concat (&objfile
->objfile_obstack
,
4580 previous_prefix
, name
, cu
);
4582 /* Create the type. */
4583 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
4585 TYPE_NAME (type
) = (char *) name
;
4586 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4588 set_die_type (die
, type
, cu
);
4593 /* Read a C++ namespace. */
4596 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4598 struct objfile
*objfile
= cu
->objfile
;
4602 /* Add a symbol associated to this if we haven't seen the namespace
4603 before. Also, add a using directive if it's an anonymous
4606 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
4610 type
= read_type_die (die
, cu
);
4611 new_symbol (die
, type
, cu
);
4613 name
= namespace_name (die
, &is_anonymous
, cu
);
4616 const char *previous_prefix
= determine_prefix (die
, cu
);
4617 cp_add_using_directive (TYPE_NAME (type
),
4618 strlen (previous_prefix
),
4619 strlen (TYPE_NAME (type
)));
4623 if (die
->child
!= NULL
)
4625 struct die_info
*child_die
= die
->child
;
4627 while (child_die
&& child_die
->tag
)
4629 process_die (child_die
, cu
);
4630 child_die
= sibling_die (child_die
);
4635 /* Return the name of the namespace represented by DIE. Set
4636 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4640 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
4642 struct die_info
*current_die
;
4643 const char *name
= NULL
;
4645 /* Loop through the extensions until we find a name. */
4647 for (current_die
= die
;
4648 current_die
!= NULL
;
4649 current_die
= dwarf2_extension (die
, &cu
))
4651 name
= dwarf2_name (current_die
, cu
);
4656 /* Is it an anonymous namespace? */
4658 *is_anonymous
= (name
== NULL
);
4660 name
= "(anonymous namespace)";
4665 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4666 the user defined type vector. */
4668 static struct type
*
4669 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4671 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
4672 struct comp_unit_head
*cu_header
= &cu
->header
;
4674 struct attribute
*attr_byte_size
;
4675 struct attribute
*attr_address_class
;
4676 int byte_size
, addr_class
;
4678 type
= lookup_pointer_type (die_type (die
, cu
));
4680 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4682 byte_size
= DW_UNSND (attr_byte_size
);
4684 byte_size
= cu_header
->addr_size
;
4686 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
4687 if (attr_address_class
)
4688 addr_class
= DW_UNSND (attr_address_class
);
4690 addr_class
= DW_ADDR_none
;
4692 /* If the pointer size or address class is different than the
4693 default, create a type variant marked as such and set the
4694 length accordingly. */
4695 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
4697 if (gdbarch_address_class_type_flags_p (gdbarch
))
4701 type_flags
= gdbarch_address_class_type_flags
4702 (gdbarch
, byte_size
, addr_class
);
4703 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
4705 type
= make_type_with_address_space (type
, type_flags
);
4707 else if (TYPE_LENGTH (type
) != byte_size
)
4709 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
4712 /* Should we also complain about unhandled address classes? */
4716 TYPE_LENGTH (type
) = byte_size
;
4717 return set_die_type (die
, type
, cu
);
4720 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4721 the user defined type vector. */
4723 static struct type
*
4724 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4726 struct objfile
*objfile
= cu
->objfile
;
4728 struct type
*to_type
;
4729 struct type
*domain
;
4731 to_type
= die_type (die
, cu
);
4732 domain
= die_containing_type (die
, cu
);
4734 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
4735 type
= lookup_methodptr_type (to_type
);
4737 type
= lookup_memberptr_type (to_type
, domain
);
4739 return set_die_type (die
, type
, cu
);
4742 /* Extract all information from a DW_TAG_reference_type DIE and add to
4743 the user defined type vector. */
4745 static struct type
*
4746 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4748 struct comp_unit_head
*cu_header
= &cu
->header
;
4750 struct attribute
*attr
;
4752 type
= lookup_reference_type (die_type (die
, cu
));
4753 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4756 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4760 TYPE_LENGTH (type
) = cu_header
->addr_size
;
4762 return set_die_type (die
, type
, cu
);
4765 static struct type
*
4766 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4768 struct type
*base_type
, *cv_type
;
4770 base_type
= die_type (die
, cu
);
4771 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
4772 return set_die_type (die
, cv_type
, cu
);
4775 static struct type
*
4776 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4778 struct type
*base_type
, *cv_type
;
4780 base_type
= die_type (die
, cu
);
4781 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
4782 return set_die_type (die
, cv_type
, cu
);
4785 /* Extract all information from a DW_TAG_string_type DIE and add to
4786 the user defined type vector. It isn't really a user defined type,
4787 but it behaves like one, with other DIE's using an AT_user_def_type
4788 attribute to reference it. */
4790 static struct type
*
4791 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4793 struct objfile
*objfile
= cu
->objfile
;
4794 struct type
*type
, *range_type
, *index_type
, *char_type
;
4795 struct attribute
*attr
;
4796 unsigned int length
;
4798 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4801 length
= DW_UNSND (attr
);
4805 /* check for the DW_AT_byte_size attribute */
4806 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4809 length
= DW_UNSND (attr
);
4817 index_type
= builtin_type_int32
;
4818 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4819 type
= create_string_type (NULL
, range_type
);
4821 return set_die_type (die
, type
, cu
);
4824 /* Handle DIES due to C code like:
4828 int (*funcp)(int a, long l);
4832 ('funcp' generates a DW_TAG_subroutine_type DIE)
4835 static struct type
*
4836 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4838 struct type
*type
; /* Type that this function returns */
4839 struct type
*ftype
; /* Function that returns above type */
4840 struct attribute
*attr
;
4842 type
= die_type (die
, cu
);
4843 ftype
= make_function_type (type
, (struct type
**) 0);
4845 /* All functions in C++, Pascal and Java have prototypes. */
4846 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4847 if ((attr
&& (DW_UNSND (attr
) != 0))
4848 || cu
->language
== language_cplus
4849 || cu
->language
== language_java
4850 || cu
->language
== language_pascal
)
4851 TYPE_PROTOTYPED (ftype
) = 1;
4853 /* Store the calling convention in the type if it's available in
4854 the subroutine die. Otherwise set the calling convention to
4855 the default value DW_CC_normal. */
4856 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
4857 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
4859 if (die
->child
!= NULL
)
4861 struct die_info
*child_die
;
4865 /* Count the number of parameters.
4866 FIXME: GDB currently ignores vararg functions, but knows about
4867 vararg member functions. */
4868 child_die
= die
->child
;
4869 while (child_die
&& child_die
->tag
)
4871 if (child_die
->tag
== DW_TAG_formal_parameter
)
4873 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4874 TYPE_VARARGS (ftype
) = 1;
4875 child_die
= sibling_die (child_die
);
4878 /* Allocate storage for parameters and fill them in. */
4879 TYPE_NFIELDS (ftype
) = nparams
;
4880 TYPE_FIELDS (ftype
) = (struct field
*)
4881 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
4883 child_die
= die
->child
;
4884 while (child_die
&& child_die
->tag
)
4886 if (child_die
->tag
== DW_TAG_formal_parameter
)
4888 /* Dwarf2 has no clean way to discern C++ static and non-static
4889 member functions. G++ helps GDB by marking the first
4890 parameter for non-static member functions (which is the
4891 this pointer) as artificial. We pass this information
4892 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4893 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
4895 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
4897 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
4898 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
4901 child_die
= sibling_die (child_die
);
4905 return set_die_type (die
, ftype
, cu
);
4908 static struct type
*
4909 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
4911 struct objfile
*objfile
= cu
->objfile
;
4912 struct attribute
*attr
;
4913 const char *name
= NULL
;
4914 struct type
*this_type
;
4916 name
= dwarf2_full_name (die
, cu
);
4917 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
4918 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
4919 TYPE_NAME (this_type
) = (char *) name
;
4920 set_die_type (die
, this_type
, cu
);
4921 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
4925 /* Find a representation of a given base type and install
4926 it in the TYPE field of the die. */
4928 static struct type
*
4929 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4931 struct objfile
*objfile
= cu
->objfile
;
4933 struct attribute
*attr
;
4934 int encoding
= 0, size
= 0;
4936 enum type_code code
= TYPE_CODE_INT
;
4938 struct type
*target_type
= NULL
;
4940 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
4943 encoding
= DW_UNSND (attr
);
4945 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4948 size
= DW_UNSND (attr
);
4950 name
= dwarf2_name (die
, cu
);
4953 complaint (&symfile_complaints
,
4954 _("DW_AT_name missing from DW_TAG_base_type"));
4959 case DW_ATE_address
:
4960 /* Turn DW_ATE_address into a void * pointer. */
4961 code
= TYPE_CODE_PTR
;
4962 type_flags
|= TYPE_FLAG_UNSIGNED
;
4963 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
4965 case DW_ATE_boolean
:
4966 code
= TYPE_CODE_BOOL
;
4967 type_flags
|= TYPE_FLAG_UNSIGNED
;
4969 case DW_ATE_complex_float
:
4970 code
= TYPE_CODE_COMPLEX
;
4971 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
4973 case DW_ATE_decimal_float
:
4974 code
= TYPE_CODE_DECFLOAT
;
4977 code
= TYPE_CODE_FLT
;
4981 case DW_ATE_unsigned
:
4982 type_flags
|= TYPE_FLAG_UNSIGNED
;
4984 case DW_ATE_signed_char
:
4985 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
4986 code
= TYPE_CODE_CHAR
;
4988 case DW_ATE_unsigned_char
:
4989 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
4990 code
= TYPE_CODE_CHAR
;
4991 type_flags
|= TYPE_FLAG_UNSIGNED
;
4994 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
4995 dwarf_type_encoding_name (encoding
));
4999 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
5000 TYPE_NAME (type
) = name
;
5001 TYPE_TARGET_TYPE (type
) = target_type
;
5003 if (name
&& strcmp (name
, "char") == 0)
5004 TYPE_NOSIGN (type
) = 1;
5006 return set_die_type (die
, type
, cu
);
5009 /* Read the given DW_AT_subrange DIE. */
5011 static struct type
*
5012 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5014 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5015 struct type
*base_type
;
5016 struct type
*range_type
;
5017 struct attribute
*attr
;
5022 base_type
= die_type (die
, cu
);
5023 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
5025 complaint (&symfile_complaints
,
5026 _("DW_AT_type missing from DW_TAG_subrange_type"));
5028 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
5029 0, NULL
, cu
->objfile
);
5032 if (cu
->language
== language_fortran
)
5034 /* FORTRAN implies a lower bound of 1, if not given. */
5038 /* FIXME: For variable sized arrays either of these could be
5039 a variable rather than a constant value. We'll allow it,
5040 but we don't know how to handle it. */
5041 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
5043 low
= dwarf2_get_attr_constant_value (attr
, 0);
5045 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
5048 if (attr
->form
== DW_FORM_block1
)
5050 /* GCC encodes arrays with unspecified or dynamic length
5051 with a DW_FORM_block1 attribute.
5052 FIXME: GDB does not yet know how to handle dynamic
5053 arrays properly, treat them as arrays with unspecified
5056 FIXME: jimb/2003-09-22: GDB does not really know
5057 how to handle arrays of unspecified length
5058 either; we just represent them as zero-length
5059 arrays. Choose an appropriate upper bound given
5060 the lower bound we've computed above. */
5064 high
= dwarf2_get_attr_constant_value (attr
, 1);
5067 range_type
= create_range_type (NULL
, base_type
, low
, high
);
5069 name
= dwarf2_name (die
, cu
);
5071 TYPE_NAME (range_type
) = name
;
5073 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5075 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
5077 return set_die_type (die
, range_type
, cu
);
5080 static struct type
*
5081 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5085 /* For now, we only support the C meaning of an unspecified type: void. */
5087 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
5088 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
5090 return set_die_type (die
, type
, cu
);
5093 /* Trivial hash function for die_info: the hash value of a DIE
5094 is its offset in .debug_info for this objfile. */
5097 die_hash (const void *item
)
5099 const struct die_info
*die
= item
;
5103 /* Trivial comparison function for die_info structures: two DIEs
5104 are equal if they have the same offset. */
5107 die_eq (const void *item_lhs
, const void *item_rhs
)
5109 const struct die_info
*die_lhs
= item_lhs
;
5110 const struct die_info
*die_rhs
= item_rhs
;
5111 return die_lhs
->offset
== die_rhs
->offset
;
5114 /* Read a whole compilation unit into a linked list of dies. */
5116 static struct die_info
*
5117 read_comp_unit (gdb_byte
*info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
5120 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5124 &cu
->comp_unit_obstack
,
5125 hashtab_obstack_allocate
,
5126 dummy_obstack_deallocate
);
5128 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
5131 /* Read a single die and all its descendents. Set the die's sibling
5132 field to NULL; set other fields in the die correctly, and set all
5133 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
5134 location of the info_ptr after reading all of those dies. PARENT
5135 is the parent of the die in question. */
5137 static struct die_info
*
5138 read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
5139 struct dwarf2_cu
*cu
,
5140 gdb_byte
**new_info_ptr
,
5141 struct die_info
*parent
)
5143 struct die_info
*die
;
5147 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
5150 *new_info_ptr
= cur_ptr
;
5153 store_in_ref_table (die
, cu
);
5157 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
5163 *new_info_ptr
= cur_ptr
;
5166 die
->sibling
= NULL
;
5167 die
->parent
= parent
;
5171 /* Read a die, all of its descendents, and all of its siblings; set
5172 all of the fields of all of the dies correctly. Arguments are as
5173 in read_die_and_children. */
5175 static struct die_info
*
5176 read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
5177 struct dwarf2_cu
*cu
,
5178 gdb_byte
**new_info_ptr
,
5179 struct die_info
*parent
)
5181 struct die_info
*first_die
, *last_sibling
;
5185 first_die
= last_sibling
= NULL
;
5189 struct die_info
*die
5190 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
5194 *new_info_ptr
= cur_ptr
;
5201 last_sibling
->sibling
= die
;
5207 /* Decompress a section that was compressed using zlib. Store the
5208 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
5211 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
5212 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
5214 bfd
*abfd
= objfile
->obfd
;
5216 error (_("Support for zlib-compressed DWARF data (from '%s') "
5217 "is disabled in this copy of GDB"),
5218 bfd_get_filename (abfd
));
5220 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
5221 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
5222 bfd_size_type uncompressed_size
;
5223 gdb_byte
*uncompressed_buffer
;
5226 int header_size
= 12;
5228 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5229 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
5230 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5231 bfd_get_filename (abfd
));
5233 /* Read the zlib header. In this case, it should be "ZLIB" followed
5234 by the uncompressed section size, 8 bytes in big-endian order. */
5235 if (compressed_size
< header_size
5236 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
5237 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
5238 bfd_get_filename (abfd
));
5239 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
5240 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
5241 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
5242 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
5243 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
5244 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
5245 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
5246 uncompressed_size
+= compressed_buffer
[11];
5248 /* It is possible the section consists of several compressed
5249 buffers concatenated together, so we uncompress in a loop. */
5253 strm
.avail_in
= compressed_size
- header_size
;
5254 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
5255 strm
.avail_out
= uncompressed_size
;
5256 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
5258 rc
= inflateInit (&strm
);
5259 while (strm
.avail_in
> 0)
5262 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
5263 bfd_get_filename (abfd
), rc
);
5264 strm
.next_out
= ((Bytef
*) uncompressed_buffer
5265 + (uncompressed_size
- strm
.avail_out
));
5266 rc
= inflate (&strm
, Z_FINISH
);
5267 if (rc
!= Z_STREAM_END
)
5268 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
5269 bfd_get_filename (abfd
), rc
);
5270 rc
= inflateReset (&strm
);
5272 rc
= inflateEnd (&strm
);
5274 || strm
.avail_out
!= 0)
5275 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
5276 bfd_get_filename (abfd
), rc
);
5278 xfree (compressed_buffer
);
5279 *outbuf
= uncompressed_buffer
;
5280 *outsize
= uncompressed_size
;
5285 /* Read the contents of the section at OFFSET and of size SIZE from the
5286 object file specified by OBJFILE into the objfile_obstack and return it.
5287 If the section is compressed, uncompress it before returning. */
5290 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
5292 bfd
*abfd
= objfile
->obfd
;
5293 gdb_byte
*buf
, *retbuf
;
5294 bfd_size_type size
= bfd_get_section_size (sectp
);
5295 unsigned char header
[4];
5300 /* Check if the file has a 4-byte header indicating compression. */
5301 if (size
> sizeof (header
)
5302 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
5303 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
5305 /* Upon decompression, update the buffer and its size. */
5306 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
5308 zlib_decompress_section (objfile
, sectp
, &buf
, &size
);
5309 dwarf2_resize_section (sectp
, size
);
5314 /* If we get here, we are a normal, not-compressed section. */
5315 buf
= obstack_alloc (&objfile
->objfile_obstack
, size
);
5316 /* When debugging .o files, we may need to apply relocations; see
5317 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
5318 We never compress sections in .o files, so we only need to
5319 try this when the section is not compressed. */
5320 retbuf
= symfile_relocate_debug_section (abfd
, sectp
, buf
);
5324 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5325 || bfd_bread (buf
, size
, abfd
) != size
)
5326 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5327 bfd_get_filename (abfd
));
5332 /* In DWARF version 2, the description of the debugging information is
5333 stored in a separate .debug_abbrev section. Before we read any
5334 dies from a section we read in all abbreviations and install them
5335 in a hash table. This function also sets flags in CU describing
5336 the data found in the abbrev table. */
5339 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
5341 struct comp_unit_head
*cu_header
= &cu
->header
;
5342 gdb_byte
*abbrev_ptr
;
5343 struct abbrev_info
*cur_abbrev
;
5344 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
5345 unsigned int abbrev_form
, hash_number
;
5346 struct attr_abbrev
*cur_attrs
;
5347 unsigned int allocated_attrs
;
5349 /* Initialize dwarf2 abbrevs */
5350 obstack_init (&cu
->abbrev_obstack
);
5351 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
5353 * sizeof (struct abbrev_info
*)));
5354 memset (cu
->dwarf2_abbrevs
, 0,
5355 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
5357 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
5358 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5359 abbrev_ptr
+= bytes_read
;
5361 allocated_attrs
= ATTR_ALLOC_CHUNK
;
5362 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
5364 /* loop until we reach an abbrev number of 0 */
5365 while (abbrev_number
)
5367 cur_abbrev
= dwarf_alloc_abbrev (cu
);
5369 /* read in abbrev header */
5370 cur_abbrev
->number
= abbrev_number
;
5371 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5372 abbrev_ptr
+= bytes_read
;
5373 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
5376 if (cur_abbrev
->tag
== DW_TAG_namespace
)
5377 cu
->has_namespace_info
= 1;
5379 /* now read in declarations */
5380 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5381 abbrev_ptr
+= bytes_read
;
5382 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5383 abbrev_ptr
+= bytes_read
;
5386 if (cur_abbrev
->num_attrs
== allocated_attrs
)
5388 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
5390 = xrealloc (cur_attrs
, (allocated_attrs
5391 * sizeof (struct attr_abbrev
)));
5394 /* Record whether this compilation unit might have
5395 inter-compilation-unit references. If we don't know what form
5396 this attribute will have, then it might potentially be a
5397 DW_FORM_ref_addr, so we conservatively expect inter-CU
5400 if (abbrev_form
== DW_FORM_ref_addr
5401 || abbrev_form
== DW_FORM_indirect
)
5402 cu
->has_form_ref_addr
= 1;
5404 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
5405 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
5406 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5407 abbrev_ptr
+= bytes_read
;
5408 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5409 abbrev_ptr
+= bytes_read
;
5412 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
5413 (cur_abbrev
->num_attrs
5414 * sizeof (struct attr_abbrev
)));
5415 memcpy (cur_abbrev
->attrs
, cur_attrs
,
5416 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
5418 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
5419 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
5420 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
5422 /* Get next abbreviation.
5423 Under Irix6 the abbreviations for a compilation unit are not
5424 always properly terminated with an abbrev number of 0.
5425 Exit loop if we encounter an abbreviation which we have
5426 already read (which means we are about to read the abbreviations
5427 for the next compile unit) or if the end of the abbreviation
5428 table is reached. */
5429 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
5430 >= dwarf2_per_objfile
->abbrev_size
)
5432 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5433 abbrev_ptr
+= bytes_read
;
5434 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
5441 /* Release the memory used by the abbrev table for a compilation unit. */
5444 dwarf2_free_abbrev_table (void *ptr_to_cu
)
5446 struct dwarf2_cu
*cu
= ptr_to_cu
;
5448 obstack_free (&cu
->abbrev_obstack
, NULL
);
5449 cu
->dwarf2_abbrevs
= NULL
;
5452 /* Lookup an abbrev_info structure in the abbrev hash table. */
5454 static struct abbrev_info
*
5455 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
5457 unsigned int hash_number
;
5458 struct abbrev_info
*abbrev
;
5460 hash_number
= number
% ABBREV_HASH_SIZE
;
5461 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
5465 if (abbrev
->number
== number
)
5468 abbrev
= abbrev
->next
;
5473 /* Returns nonzero if TAG represents a type that we might generate a partial
5477 is_type_tag_for_partial (int tag
)
5482 /* Some types that would be reasonable to generate partial symbols for,
5483 that we don't at present. */
5484 case DW_TAG_array_type
:
5485 case DW_TAG_file_type
:
5486 case DW_TAG_ptr_to_member_type
:
5487 case DW_TAG_set_type
:
5488 case DW_TAG_string_type
:
5489 case DW_TAG_subroutine_type
:
5491 case DW_TAG_base_type
:
5492 case DW_TAG_class_type
:
5493 case DW_TAG_interface_type
:
5494 case DW_TAG_enumeration_type
:
5495 case DW_TAG_structure_type
:
5496 case DW_TAG_subrange_type
:
5497 case DW_TAG_typedef
:
5498 case DW_TAG_union_type
:
5505 /* Load all DIEs that are interesting for partial symbols into memory. */
5507 static struct partial_die_info
*
5508 load_partial_dies (bfd
*abfd
, gdb_byte
*info_ptr
, int building_psymtab
,
5509 struct dwarf2_cu
*cu
)
5511 struct partial_die_info
*part_die
;
5512 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
5513 struct abbrev_info
*abbrev
;
5514 unsigned int bytes_read
;
5515 unsigned int load_all
= 0;
5517 int nesting_level
= 1;
5522 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
5526 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5530 &cu
->comp_unit_obstack
,
5531 hashtab_obstack_allocate
,
5532 dummy_obstack_deallocate
);
5534 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5535 sizeof (struct partial_die_info
));
5539 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5541 /* A NULL abbrev means the end of a series of children. */
5544 if (--nesting_level
== 0)
5546 /* PART_DIE was probably the last thing allocated on the
5547 comp_unit_obstack, so we could call obstack_free
5548 here. We don't do that because the waste is small,
5549 and will be cleaned up when we're done with this
5550 compilation unit. This way, we're also more robust
5551 against other users of the comp_unit_obstack. */
5554 info_ptr
+= bytes_read
;
5555 last_die
= parent_die
;
5556 parent_die
= parent_die
->die_parent
;
5560 /* Check whether this DIE is interesting enough to save. Normally
5561 we would not be interested in members here, but there may be
5562 later variables referencing them via DW_AT_specification (for
5565 && !is_type_tag_for_partial (abbrev
->tag
)
5566 && abbrev
->tag
!= DW_TAG_enumerator
5567 && abbrev
->tag
!= DW_TAG_subprogram
5568 && abbrev
->tag
!= DW_TAG_variable
5569 && abbrev
->tag
!= DW_TAG_namespace
5570 && abbrev
->tag
!= DW_TAG_member
)
5572 /* Otherwise we skip to the next sibling, if any. */
5573 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5577 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5578 abfd
, info_ptr
, cu
);
5580 /* This two-pass algorithm for processing partial symbols has a
5581 high cost in cache pressure. Thus, handle some simple cases
5582 here which cover the majority of C partial symbols. DIEs
5583 which neither have specification tags in them, nor could have
5584 specification tags elsewhere pointing at them, can simply be
5585 processed and discarded.
5587 This segment is also optional; scan_partial_symbols and
5588 add_partial_symbol will handle these DIEs if we chain
5589 them in normally. When compilers which do not emit large
5590 quantities of duplicate debug information are more common,
5591 this code can probably be removed. */
5593 /* Any complete simple types at the top level (pretty much all
5594 of them, for a language without namespaces), can be processed
5596 if (parent_die
== NULL
5597 && part_die
->has_specification
== 0
5598 && part_die
->is_declaration
== 0
5599 && (part_die
->tag
== DW_TAG_typedef
5600 || part_die
->tag
== DW_TAG_base_type
5601 || part_die
->tag
== DW_TAG_subrange_type
))
5603 if (building_psymtab
&& part_die
->name
!= NULL
)
5604 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5605 VAR_DOMAIN
, LOC_TYPEDEF
,
5606 &cu
->objfile
->static_psymbols
,
5607 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5608 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5612 /* If we're at the second level, and we're an enumerator, and
5613 our parent has no specification (meaning possibly lives in a
5614 namespace elsewhere), then we can add the partial symbol now
5615 instead of queueing it. */
5616 if (part_die
->tag
== DW_TAG_enumerator
5617 && parent_die
!= NULL
5618 && parent_die
->die_parent
== NULL
5619 && parent_die
->tag
== DW_TAG_enumeration_type
5620 && parent_die
->has_specification
== 0)
5622 if (part_die
->name
== NULL
)
5623 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5624 else if (building_psymtab
)
5625 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5626 VAR_DOMAIN
, LOC_CONST
,
5627 (cu
->language
== language_cplus
5628 || cu
->language
== language_java
)
5629 ? &cu
->objfile
->global_psymbols
5630 : &cu
->objfile
->static_psymbols
,
5631 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5633 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5637 /* We'll save this DIE so link it in. */
5638 part_die
->die_parent
= parent_die
;
5639 part_die
->die_sibling
= NULL
;
5640 part_die
->die_child
= NULL
;
5642 if (last_die
&& last_die
== parent_die
)
5643 last_die
->die_child
= part_die
;
5645 last_die
->die_sibling
= part_die
;
5647 last_die
= part_die
;
5649 if (first_die
== NULL
)
5650 first_die
= part_die
;
5652 /* Maybe add the DIE to the hash table. Not all DIEs that we
5653 find interesting need to be in the hash table, because we
5654 also have the parent/sibling/child chains; only those that we
5655 might refer to by offset later during partial symbol reading.
5657 For now this means things that might have be the target of a
5658 DW_AT_specification, DW_AT_abstract_origin, or
5659 DW_AT_extension. DW_AT_extension will refer only to
5660 namespaces; DW_AT_abstract_origin refers to functions (and
5661 many things under the function DIE, but we do not recurse
5662 into function DIEs during partial symbol reading) and
5663 possibly variables as well; DW_AT_specification refers to
5664 declarations. Declarations ought to have the DW_AT_declaration
5665 flag. It happens that GCC forgets to put it in sometimes, but
5666 only for functions, not for types.
5668 Adding more things than necessary to the hash table is harmless
5669 except for the performance cost. Adding too few will result in
5670 wasted time in find_partial_die, when we reread the compilation
5671 unit with load_all_dies set. */
5674 || abbrev
->tag
== DW_TAG_subprogram
5675 || abbrev
->tag
== DW_TAG_variable
5676 || abbrev
->tag
== DW_TAG_namespace
5677 || part_die
->is_declaration
)
5681 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
5682 part_die
->offset
, INSERT
);
5686 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5687 sizeof (struct partial_die_info
));
5689 /* For some DIEs we want to follow their children (if any). For C
5690 we have no reason to follow the children of structures; for other
5691 languages we have to, both so that we can get at method physnames
5692 to infer fully qualified class names, and for DW_AT_specification. */
5693 if (last_die
->has_children
5695 || last_die
->tag
== DW_TAG_namespace
5696 || last_die
->tag
== DW_TAG_enumeration_type
5697 || (cu
->language
!= language_c
5698 && (last_die
->tag
== DW_TAG_class_type
5699 || last_die
->tag
== DW_TAG_interface_type
5700 || last_die
->tag
== DW_TAG_structure_type
5701 || last_die
->tag
== DW_TAG_union_type
))))
5704 parent_die
= last_die
;
5708 /* Otherwise we skip to the next sibling, if any. */
5709 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
5711 /* Back to the top, do it again. */
5715 /* Read a minimal amount of information into the minimal die structure. */
5718 read_partial_die (struct partial_die_info
*part_die
,
5719 struct abbrev_info
*abbrev
,
5720 unsigned int abbrev_len
, bfd
*abfd
,
5721 gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
5723 unsigned int bytes_read
, i
;
5724 struct attribute attr
;
5725 int has_low_pc_attr
= 0;
5726 int has_high_pc_attr
= 0;
5727 CORE_ADDR base_address
= 0;
5731 base_address_low_pc
,
5732 /* Overrides BASE_ADDRESS_LOW_PC. */
5733 base_address_entry_pc
5735 base_address_type
= base_address_none
;
5737 memset (part_die
, 0, sizeof (struct partial_die_info
));
5739 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5741 info_ptr
+= abbrev_len
;
5746 part_die
->tag
= abbrev
->tag
;
5747 part_die
->has_children
= abbrev
->has_children
;
5749 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5751 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
5753 /* Store the data if it is of an attribute we want to keep in a
5754 partial symbol table. */
5759 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
5760 if (part_die
->name
== NULL
)
5761 part_die
->name
= DW_STRING (&attr
);
5763 case DW_AT_comp_dir
:
5764 if (part_die
->dirname
== NULL
)
5765 part_die
->dirname
= DW_STRING (&attr
);
5767 case DW_AT_MIPS_linkage_name
:
5768 part_die
->name
= DW_STRING (&attr
);
5771 has_low_pc_attr
= 1;
5772 part_die
->lowpc
= DW_ADDR (&attr
);
5773 if (part_die
->tag
== DW_TAG_compile_unit
5774 && base_address_type
< base_address_low_pc
)
5776 base_address
= DW_ADDR (&attr
);
5777 base_address_type
= base_address_low_pc
;
5781 has_high_pc_attr
= 1;
5782 part_die
->highpc
= DW_ADDR (&attr
);
5784 case DW_AT_entry_pc
:
5785 if (part_die
->tag
== DW_TAG_compile_unit
5786 && base_address_type
< base_address_entry_pc
)
5788 base_address
= DW_ADDR (&attr
);
5789 base_address_type
= base_address_entry_pc
;
5793 if (part_die
->tag
== DW_TAG_compile_unit
)
5795 cu
->ranges_offset
= DW_UNSND (&attr
);
5796 cu
->has_ranges_offset
= 1;
5799 case DW_AT_location
:
5800 /* Support the .debug_loc offsets */
5801 if (attr_form_is_block (&attr
))
5803 part_die
->locdesc
= DW_BLOCK (&attr
);
5805 else if (attr_form_is_section_offset (&attr
))
5807 dwarf2_complex_location_expr_complaint ();
5811 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5812 "partial symbol information");
5815 case DW_AT_language
:
5816 part_die
->language
= DW_UNSND (&attr
);
5818 case DW_AT_external
:
5819 part_die
->is_external
= DW_UNSND (&attr
);
5821 case DW_AT_declaration
:
5822 part_die
->is_declaration
= DW_UNSND (&attr
);
5825 part_die
->has_type
= 1;
5827 case DW_AT_abstract_origin
:
5828 case DW_AT_specification
:
5829 case DW_AT_extension
:
5830 part_die
->has_specification
= 1;
5831 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
, cu
);
5834 /* Ignore absolute siblings, they might point outside of
5835 the current compile unit. */
5836 if (attr
.form
== DW_FORM_ref_addr
)
5837 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
5839 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
5840 + dwarf2_get_ref_die_offset (&attr
, cu
);
5842 case DW_AT_stmt_list
:
5843 part_die
->has_stmt_list
= 1;
5844 part_die
->line_offset
= DW_UNSND (&attr
);
5846 case DW_AT_byte_size
:
5847 part_die
->has_byte_size
= 1;
5849 case DW_AT_calling_convention
:
5850 /* DWARF doesn't provide a way to identify a program's source-level
5851 entry point. DW_AT_calling_convention attributes are only meant
5852 to describe functions' calling conventions.
5854 However, because it's a necessary piece of information in
5855 Fortran, and because DW_CC_program is the only piece of debugging
5856 information whose definition refers to a 'main program' at all,
5857 several compilers have begun marking Fortran main programs with
5858 DW_CC_program --- even when those functions use the standard
5859 calling conventions.
5861 So until DWARF specifies a way to provide this information and
5862 compilers pick up the new representation, we'll support this
5864 if (DW_UNSND (&attr
) == DW_CC_program
5865 && cu
->language
== language_fortran
)
5866 set_main_name (part_die
->name
);
5873 /* When using the GNU linker, .gnu.linkonce. sections are used to
5874 eliminate duplicate copies of functions and vtables and such.
5875 The linker will arbitrarily choose one and discard the others.
5876 The AT_*_pc values for such functions refer to local labels in
5877 these sections. If the section from that file was discarded, the
5878 labels are not in the output, so the relocs get a value of 0.
5879 If this is a discarded function, mark the pc bounds as invalid,
5880 so that GDB will ignore it. */
5881 if (has_low_pc_attr
&& has_high_pc_attr
5882 && part_die
->lowpc
< part_die
->highpc
5883 && (part_die
->lowpc
!= 0
5884 || dwarf2_per_objfile
->has_section_at_zero
))
5885 part_die
->has_pc_info
= 1;
5887 if (base_address_type
!= base_address_none
&& !cu
->header
.base_known
)
5889 gdb_assert (part_die
->tag
== DW_TAG_compile_unit
);
5890 cu
->header
.base_known
= 1;
5891 cu
->header
.base_address
= base_address
;
5897 /* Find a cached partial DIE at OFFSET in CU. */
5899 static struct partial_die_info
*
5900 find_partial_die_in_comp_unit (unsigned long offset
, struct dwarf2_cu
*cu
)
5902 struct partial_die_info
*lookup_die
= NULL
;
5903 struct partial_die_info part_die
;
5905 part_die
.offset
= offset
;
5906 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
5911 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
5913 static struct partial_die_info
*
5914 find_partial_die (unsigned long offset
, struct dwarf2_cu
*cu
)
5916 struct dwarf2_per_cu_data
*per_cu
= NULL
;
5917 struct partial_die_info
*pd
= NULL
;
5919 if (offset
>= cu
->header
.offset
5920 && offset
< cu
->header
.offset
+ cu
->header
.length
)
5922 pd
= find_partial_die_in_comp_unit (offset
, cu
);
5927 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
5929 if (per_cu
->cu
== NULL
)
5931 load_comp_unit (per_cu
, cu
->objfile
);
5932 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5933 dwarf2_per_objfile
->read_in_chain
= per_cu
;
5936 per_cu
->cu
->last_used
= 0;
5937 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
5939 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
5941 struct cleanup
*back_to
;
5942 struct partial_die_info comp_unit_die
;
5943 struct abbrev_info
*abbrev
;
5944 unsigned int bytes_read
;
5947 per_cu
->load_all_dies
= 1;
5949 /* Re-read the DIEs. */
5950 back_to
= make_cleanup (null_cleanup
, 0);
5951 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
5953 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
5954 back_to
= make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
5956 info_ptr
= per_cu
->cu
->header
.first_die_ptr
;
5957 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
5958 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
5959 per_cu
->cu
->objfile
->obfd
, info_ptr
,
5961 if (comp_unit_die
.has_children
)
5962 load_partial_dies (per_cu
->cu
->objfile
->obfd
, info_ptr
, 0, per_cu
->cu
);
5963 do_cleanups (back_to
);
5965 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
5969 internal_error (__FILE__
, __LINE__
,
5970 _("could not find partial DIE 0x%lx in cache [from module %s]\n"),
5971 offset
, bfd_get_filename (cu
->objfile
->obfd
));
5975 /* Adjust PART_DIE before generating a symbol for it. This function
5976 may set the is_external flag or change the DIE's name. */
5979 fixup_partial_die (struct partial_die_info
*part_die
,
5980 struct dwarf2_cu
*cu
)
5982 /* If we found a reference attribute and the DIE has no name, try
5983 to find a name in the referred to DIE. */
5985 if (part_die
->name
== NULL
&& part_die
->has_specification
)
5987 struct partial_die_info
*spec_die
;
5989 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
5991 fixup_partial_die (spec_die
, cu
);
5995 part_die
->name
= spec_die
->name
;
5997 /* Copy DW_AT_external attribute if it is set. */
5998 if (spec_die
->is_external
)
5999 part_die
->is_external
= spec_die
->is_external
;
6003 /* Set default names for some unnamed DIEs. */
6004 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
6005 || part_die
->tag
== DW_TAG_class_type
))
6006 part_die
->name
= "(anonymous class)";
6008 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
6009 part_die
->name
= "(anonymous namespace)";
6011 if (part_die
->tag
== DW_TAG_structure_type
6012 || part_die
->tag
== DW_TAG_class_type
6013 || part_die
->tag
== DW_TAG_union_type
)
6014 guess_structure_name (part_die
, cu
);
6017 /* Read the die from the .debug_info section buffer. Set DIEP to
6018 point to a newly allocated die with its information, except for its
6019 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6020 whether the die has children or not. */
6023 read_full_die (struct die_info
**diep
, bfd
*abfd
, gdb_byte
*info_ptr
,
6024 struct dwarf2_cu
*cu
, int *has_children
)
6026 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6027 struct abbrev_info
*abbrev
;
6028 struct die_info
*die
;
6030 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
6031 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6032 info_ptr
+= bytes_read
;
6040 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6043 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6045 bfd_get_filename (abfd
));
6047 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
6048 die
->offset
= offset
;
6049 die
->tag
= abbrev
->tag
;
6050 die
->abbrev
= abbrev_number
;
6052 die
->num_attrs
= abbrev
->num_attrs
;
6054 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6055 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6056 abfd
, info_ptr
, cu
);
6059 *has_children
= abbrev
->has_children
;
6063 /* Read an attribute value described by an attribute form. */
6066 read_attribute_value (struct attribute
*attr
, unsigned form
,
6067 bfd
*abfd
, gdb_byte
*info_ptr
,
6068 struct dwarf2_cu
*cu
)
6070 struct comp_unit_head
*cu_header
= &cu
->header
;
6071 unsigned int bytes_read
;
6072 struct dwarf_block
*blk
;
6078 case DW_FORM_ref_addr
:
6079 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6080 info_ptr
+= bytes_read
;
6082 case DW_FORM_block2
:
6083 blk
= dwarf_alloc_block (cu
);
6084 blk
->size
= read_2_bytes (abfd
, info_ptr
);
6086 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6087 info_ptr
+= blk
->size
;
6088 DW_BLOCK (attr
) = blk
;
6090 case DW_FORM_block4
:
6091 blk
= dwarf_alloc_block (cu
);
6092 blk
->size
= read_4_bytes (abfd
, info_ptr
);
6094 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6095 info_ptr
+= blk
->size
;
6096 DW_BLOCK (attr
) = blk
;
6099 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
6103 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
6107 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
6110 case DW_FORM_string
:
6111 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
6112 info_ptr
+= bytes_read
;
6115 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
6117 info_ptr
+= bytes_read
;
6120 blk
= dwarf_alloc_block (cu
);
6121 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6122 info_ptr
+= bytes_read
;
6123 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6124 info_ptr
+= blk
->size
;
6125 DW_BLOCK (attr
) = blk
;
6127 case DW_FORM_block1
:
6128 blk
= dwarf_alloc_block (cu
);
6129 blk
->size
= read_1_byte (abfd
, info_ptr
);
6131 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6132 info_ptr
+= blk
->size
;
6133 DW_BLOCK (attr
) = blk
;
6136 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6140 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6144 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
6145 info_ptr
+= bytes_read
;
6148 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6149 info_ptr
+= bytes_read
;
6152 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
6156 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
6160 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
6164 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
6167 case DW_FORM_ref_udata
:
6168 DW_ADDR (attr
) = (cu
->header
.offset
6169 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
6170 info_ptr
+= bytes_read
;
6172 case DW_FORM_indirect
:
6173 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6174 info_ptr
+= bytes_read
;
6175 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
6178 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
6179 dwarf_form_name (form
),
6180 bfd_get_filename (abfd
));
6183 /* We have seen instances where the compiler tried to emit a byte
6184 size attribute of -1 which ended up being encoded as an unsigned
6185 0xffffffff. Although 0xffffffff is technically a valid size value,
6186 an object of this size seems pretty unlikely so we can relatively
6187 safely treat these cases as if the size attribute was invalid and
6188 treat them as zero by default. */
6189 if (attr
->name
== DW_AT_byte_size
6190 && form
== DW_FORM_data4
6191 && DW_UNSND (attr
) >= 0xffffffff)
6194 (&symfile_complaints
,
6195 _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"),
6197 DW_UNSND (attr
) = 0;
6203 /* Read an attribute described by an abbreviated attribute. */
6206 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
6207 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6209 attr
->name
= abbrev
->name
;
6210 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
6213 /* read dwarf information from a buffer */
6216 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
6218 return bfd_get_8 (abfd
, buf
);
6222 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
6224 return bfd_get_signed_8 (abfd
, buf
);
6228 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
6230 return bfd_get_16 (abfd
, buf
);
6234 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6236 return bfd_get_signed_16 (abfd
, buf
);
6240 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
6242 return bfd_get_32 (abfd
, buf
);
6246 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6248 return bfd_get_signed_32 (abfd
, buf
);
6251 static unsigned long
6252 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
6254 return bfd_get_64 (abfd
, buf
);
6258 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
6259 unsigned int *bytes_read
)
6261 struct comp_unit_head
*cu_header
= &cu
->header
;
6262 CORE_ADDR retval
= 0;
6264 if (cu_header
->signed_addr_p
)
6266 switch (cu_header
->addr_size
)
6269 retval
= bfd_get_signed_16 (abfd
, buf
);
6272 retval
= bfd_get_signed_32 (abfd
, buf
);
6275 retval
= bfd_get_signed_64 (abfd
, buf
);
6278 internal_error (__FILE__
, __LINE__
,
6279 _("read_address: bad switch, signed [in module %s]"),
6280 bfd_get_filename (abfd
));
6285 switch (cu_header
->addr_size
)
6288 retval
= bfd_get_16 (abfd
, buf
);
6291 retval
= bfd_get_32 (abfd
, buf
);
6294 retval
= bfd_get_64 (abfd
, buf
);
6297 internal_error (__FILE__
, __LINE__
,
6298 _("read_address: bad switch, unsigned [in module %s]"),
6299 bfd_get_filename (abfd
));
6303 *bytes_read
= cu_header
->addr_size
;
6307 /* Read the initial length from a section. The (draft) DWARF 3
6308 specification allows the initial length to take up either 4 bytes
6309 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
6310 bytes describe the length and all offsets will be 8 bytes in length
6313 An older, non-standard 64-bit format is also handled by this
6314 function. The older format in question stores the initial length
6315 as an 8-byte quantity without an escape value. Lengths greater
6316 than 2^32 aren't very common which means that the initial 4 bytes
6317 is almost always zero. Since a length value of zero doesn't make
6318 sense for the 32-bit format, this initial zero can be considered to
6319 be an escape value which indicates the presence of the older 64-bit
6320 format. As written, the code can't detect (old format) lengths
6321 greater than 4GB. If it becomes necessary to handle lengths
6322 somewhat larger than 4GB, we could allow other small values (such
6323 as the non-sensical values of 1, 2, and 3) to also be used as
6324 escape values indicating the presence of the old format.
6326 The value returned via bytes_read should be used to increment the
6327 relevant pointer after calling read_initial_length().
6329 As a side effect, this function sets the fields initial_length_size
6330 and offset_size in cu_header to the values appropriate for the
6331 length field. (The format of the initial length field determines
6332 the width of file offsets to be fetched later with read_offset().)
6334 [ Note: read_initial_length() and read_offset() are based on the
6335 document entitled "DWARF Debugging Information Format", revision
6336 3, draft 8, dated November 19, 2001. This document was obtained
6339 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
6341 This document is only a draft and is subject to change. (So beware.)
6343 Details regarding the older, non-standard 64-bit format were
6344 determined empirically by examining 64-bit ELF files produced by
6345 the SGI toolchain on an IRIX 6.5 machine.
6347 - Kevin, July 16, 2002
6351 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, struct comp_unit_head
*cu_header
,
6352 unsigned int *bytes_read
)
6354 LONGEST length
= bfd_get_32 (abfd
, buf
);
6356 if (length
== 0xffffffff)
6358 length
= bfd_get_64 (abfd
, buf
+ 4);
6361 else if (length
== 0)
6363 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
6364 length
= bfd_get_64 (abfd
, buf
);
6374 gdb_assert (cu_header
->initial_length_size
== 0
6375 || cu_header
->initial_length_size
== 4
6376 || cu_header
->initial_length_size
== 8
6377 || cu_header
->initial_length_size
== 12);
6379 if (cu_header
->initial_length_size
!= 0
6380 && cu_header
->initial_length_size
!= *bytes_read
)
6381 complaint (&symfile_complaints
,
6382 _("intermixed 32-bit and 64-bit DWARF sections"));
6384 cu_header
->initial_length_size
= *bytes_read
;
6385 cu_header
->offset_size
= (*bytes_read
== 4) ? 4 : 8;
6391 /* Read an offset from the data stream. The size of the offset is
6392 given by cu_header->offset_size. */
6395 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
6396 unsigned int *bytes_read
)
6400 switch (cu_header
->offset_size
)
6403 retval
= bfd_get_32 (abfd
, buf
);
6407 retval
= bfd_get_64 (abfd
, buf
);
6411 internal_error (__FILE__
, __LINE__
,
6412 _("read_offset: bad switch [in module %s]"),
6413 bfd_get_filename (abfd
));
6420 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
6422 /* If the size of a host char is 8 bits, we can return a pointer
6423 to the buffer, otherwise we have to copy the data to a buffer
6424 allocated on the temporary obstack. */
6425 gdb_assert (HOST_CHAR_BIT
== 8);
6430 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6432 /* If the size of a host char is 8 bits, we can return a pointer
6433 to the string, otherwise we have to copy the string to a buffer
6434 allocated on the temporary obstack. */
6435 gdb_assert (HOST_CHAR_BIT
== 8);
6438 *bytes_read_ptr
= 1;
6441 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
6442 return (char *) buf
;
6446 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
6447 const struct comp_unit_head
*cu_header
,
6448 unsigned int *bytes_read_ptr
)
6450 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
6453 if (dwarf2_per_objfile
->str_buffer
== NULL
)
6455 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
6456 bfd_get_filename (abfd
));
6459 if (str_offset
>= dwarf2_per_objfile
->str_size
)
6461 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
6462 bfd_get_filename (abfd
));
6465 gdb_assert (HOST_CHAR_BIT
== 8);
6466 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
6468 return (char *) (dwarf2_per_objfile
->str_buffer
+ str_offset
);
6471 static unsigned long
6472 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6474 unsigned long result
;
6475 unsigned int num_read
;
6485 byte
= bfd_get_8 (abfd
, buf
);
6488 result
|= ((unsigned long)(byte
& 127) << shift
);
6489 if ((byte
& 128) == 0)
6495 *bytes_read_ptr
= num_read
;
6500 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6503 int i
, shift
, num_read
;
6512 byte
= bfd_get_8 (abfd
, buf
);
6515 result
|= ((long)(byte
& 127) << shift
);
6517 if ((byte
& 128) == 0)
6522 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
6523 result
|= -(((long)1) << shift
);
6524 *bytes_read_ptr
= num_read
;
6528 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6531 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
6537 byte
= bfd_get_8 (abfd
, buf
);
6539 if ((byte
& 128) == 0)
6545 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
6551 cu
->language
= language_c
;
6553 case DW_LANG_C_plus_plus
:
6554 cu
->language
= language_cplus
;
6556 case DW_LANG_Fortran77
:
6557 case DW_LANG_Fortran90
:
6558 case DW_LANG_Fortran95
:
6559 cu
->language
= language_fortran
;
6561 case DW_LANG_Mips_Assembler
:
6562 cu
->language
= language_asm
;
6565 cu
->language
= language_java
;
6569 cu
->language
= language_ada
;
6571 case DW_LANG_Modula2
:
6572 cu
->language
= language_m2
;
6574 case DW_LANG_Pascal83
:
6575 cu
->language
= language_pascal
;
6578 cu
->language
= language_objc
;
6580 case DW_LANG_Cobol74
:
6581 case DW_LANG_Cobol85
:
6583 cu
->language
= language_minimal
;
6586 cu
->language_defn
= language_def (cu
->language
);
6589 /* Return the named attribute or NULL if not there. */
6591 static struct attribute
*
6592 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
6595 struct attribute
*spec
= NULL
;
6597 for (i
= 0; i
< die
->num_attrs
; ++i
)
6599 if (die
->attrs
[i
].name
== name
)
6600 return &die
->attrs
[i
];
6601 if (die
->attrs
[i
].name
== DW_AT_specification
6602 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
6603 spec
= &die
->attrs
[i
];
6608 die
= follow_die_ref (die
, spec
, &cu
);
6609 return dwarf2_attr (die
, name
, cu
);
6615 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6616 and holds a non-zero value. This function should only be used for
6617 DW_FORM_flag attributes. */
6620 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
6622 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
6624 return (attr
&& DW_UNSND (attr
));
6628 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
6630 /* A DIE is a declaration if it has a DW_AT_declaration attribute
6631 which value is non-zero. However, we have to be careful with
6632 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
6633 (via dwarf2_flag_true_p) follows this attribute. So we may
6634 end up accidently finding a declaration attribute that belongs
6635 to a different DIE referenced by the specification attribute,
6636 even though the given DIE does not have a declaration attribute. */
6637 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
6638 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
6641 /* Return the die giving the specification for DIE, if there is
6642 one. *SPEC_CU is the CU containing DIE on input, and the CU
6643 containing the return value on output. */
6645 static struct die_info
*
6646 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
6648 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
6651 if (spec_attr
== NULL
)
6654 return follow_die_ref (die
, spec_attr
, spec_cu
);
6657 /* Free the line_header structure *LH, and any arrays and strings it
6660 free_line_header (struct line_header
*lh
)
6662 if (lh
->standard_opcode_lengths
)
6663 xfree (lh
->standard_opcode_lengths
);
6665 /* Remember that all the lh->file_names[i].name pointers are
6666 pointers into debug_line_buffer, and don't need to be freed. */
6668 xfree (lh
->file_names
);
6670 /* Similarly for the include directory names. */
6671 if (lh
->include_dirs
)
6672 xfree (lh
->include_dirs
);
6678 /* Add an entry to LH's include directory table. */
6680 add_include_dir (struct line_header
*lh
, char *include_dir
)
6682 /* Grow the array if necessary. */
6683 if (lh
->include_dirs_size
== 0)
6685 lh
->include_dirs_size
= 1; /* for testing */
6686 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
6687 * sizeof (*lh
->include_dirs
));
6689 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
6691 lh
->include_dirs_size
*= 2;
6692 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
6693 (lh
->include_dirs_size
6694 * sizeof (*lh
->include_dirs
)));
6697 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
6701 /* Add an entry to LH's file name table. */
6703 add_file_name (struct line_header
*lh
,
6705 unsigned int dir_index
,
6706 unsigned int mod_time
,
6707 unsigned int length
)
6709 struct file_entry
*fe
;
6711 /* Grow the array if necessary. */
6712 if (lh
->file_names_size
== 0)
6714 lh
->file_names_size
= 1; /* for testing */
6715 lh
->file_names
= xmalloc (lh
->file_names_size
6716 * sizeof (*lh
->file_names
));
6718 else if (lh
->num_file_names
>= lh
->file_names_size
)
6720 lh
->file_names_size
*= 2;
6721 lh
->file_names
= xrealloc (lh
->file_names
,
6722 (lh
->file_names_size
6723 * sizeof (*lh
->file_names
)));
6726 fe
= &lh
->file_names
[lh
->num_file_names
++];
6728 fe
->dir_index
= dir_index
;
6729 fe
->mod_time
= mod_time
;
6730 fe
->length
= length
;
6736 /* Read the statement program header starting at OFFSET in
6737 .debug_line, according to the endianness of ABFD. Return a pointer
6738 to a struct line_header, allocated using xmalloc.
6740 NOTE: the strings in the include directory and file name tables of
6741 the returned object point into debug_line_buffer, and must not be
6743 static struct line_header
*
6744 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
6745 struct dwarf2_cu
*cu
)
6747 struct cleanup
*back_to
;
6748 struct line_header
*lh
;
6750 unsigned int bytes_read
;
6752 char *cur_dir
, *cur_file
;
6754 if (dwarf2_per_objfile
->line_buffer
== NULL
)
6756 complaint (&symfile_complaints
, _("missing .debug_line section"));
6760 /* Make sure that at least there's room for the total_length field.
6761 That could be 12 bytes long, but we're just going to fudge that. */
6762 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
6764 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6768 lh
= xmalloc (sizeof (*lh
));
6769 memset (lh
, 0, sizeof (*lh
));
6770 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
6773 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
6775 /* Read in the header. */
6777 read_initial_length (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6778 line_ptr
+= bytes_read
;
6779 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
6780 + dwarf2_per_objfile
->line_size
))
6782 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6785 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
6786 lh
->version
= read_2_bytes (abfd
, line_ptr
);
6788 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6789 line_ptr
+= bytes_read
;
6790 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
6792 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
6794 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
6796 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
6798 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
6800 lh
->standard_opcode_lengths
6801 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
6803 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
6804 for (i
= 1; i
< lh
->opcode_base
; ++i
)
6806 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
6810 /* Read directory table. */
6811 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6813 line_ptr
+= bytes_read
;
6814 add_include_dir (lh
, cur_dir
);
6816 line_ptr
+= bytes_read
;
6818 /* Read file name table. */
6819 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6821 unsigned int dir_index
, mod_time
, length
;
6823 line_ptr
+= bytes_read
;
6824 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6825 line_ptr
+= bytes_read
;
6826 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6827 line_ptr
+= bytes_read
;
6828 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6829 line_ptr
+= bytes_read
;
6831 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6833 line_ptr
+= bytes_read
;
6834 lh
->statement_program_start
= line_ptr
;
6836 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
6837 + dwarf2_per_objfile
->line_size
))
6838 complaint (&symfile_complaints
,
6839 _("line number info header doesn't fit in `.debug_line' section"));
6841 discard_cleanups (back_to
);
6845 /* This function exists to work around a bug in certain compilers
6846 (particularly GCC 2.95), in which the first line number marker of a
6847 function does not show up until after the prologue, right before
6848 the second line number marker. This function shifts ADDRESS down
6849 to the beginning of the function if necessary, and is called on
6850 addresses passed to record_line. */
6853 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
6855 struct function_range
*fn
;
6857 /* Find the function_range containing address. */
6862 cu
->cached_fn
= cu
->first_fn
;
6866 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6872 while (fn
&& fn
!= cu
->cached_fn
)
6873 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6883 if (address
!= fn
->lowpc
)
6884 complaint (&symfile_complaints
,
6885 _("misplaced first line number at 0x%lx for '%s'"),
6886 (unsigned long) address
, fn
->name
);
6891 /* Decode the Line Number Program (LNP) for the given line_header
6892 structure and CU. The actual information extracted and the type
6893 of structures created from the LNP depends on the value of PST.
6895 1. If PST is NULL, then this procedure uses the data from the program
6896 to create all necessary symbol tables, and their linetables.
6897 The compilation directory of the file is passed in COMP_DIR,
6898 and must not be NULL.
6900 2. If PST is not NULL, this procedure reads the program to determine
6901 the list of files included by the unit represented by PST, and
6902 builds all the associated partial symbol tables. In this case,
6903 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
6904 is not used to compute the full name of the symtab, and therefore
6905 omitting it when building the partial symtab does not introduce
6906 the potential for inconsistency - a partial symtab and its associated
6907 symbtab having a different fullname -). */
6910 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
6911 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
6913 gdb_byte
*line_ptr
, *extended_end
;
6915 unsigned int bytes_read
, extended_len
;
6916 unsigned char op_code
, extended_op
, adj_opcode
;
6918 struct objfile
*objfile
= cu
->objfile
;
6919 const int decode_for_pst_p
= (pst
!= NULL
);
6920 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
6922 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6924 line_ptr
= lh
->statement_program_start
;
6925 line_end
= lh
->statement_program_end
;
6927 /* Read the statement sequences until there's nothing left. */
6928 while (line_ptr
< line_end
)
6930 /* state machine registers */
6931 CORE_ADDR address
= 0;
6932 unsigned int file
= 1;
6933 unsigned int line
= 1;
6934 unsigned int column
= 0;
6935 int is_stmt
= lh
->default_is_stmt
;
6936 int basic_block
= 0;
6937 int end_sequence
= 0;
6939 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
6941 /* Start a subfile for the current file of the state machine. */
6942 /* lh->include_dirs and lh->file_names are 0-based, but the
6943 directory and file name numbers in the statement program
6945 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
6949 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6951 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
6954 /* Decode the table. */
6955 while (!end_sequence
)
6957 op_code
= read_1_byte (abfd
, line_ptr
);
6960 if (op_code
>= lh
->opcode_base
)
6962 /* Special operand. */
6963 adj_opcode
= op_code
- lh
->opcode_base
;
6964 address
+= (adj_opcode
/ lh
->line_range
)
6965 * lh
->minimum_instruction_length
;
6966 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
6967 if (lh
->num_file_names
< file
)
6968 dwarf2_debug_line_missing_file_complaint ();
6971 lh
->file_names
[file
- 1].included_p
= 1;
6972 if (!decode_for_pst_p
)
6974 if (last_subfile
!= current_subfile
)
6977 record_line (last_subfile
, 0, address
);
6978 last_subfile
= current_subfile
;
6980 /* Append row to matrix using current values. */
6981 record_line (current_subfile
, line
,
6982 check_cu_functions (address
, cu
));
6987 else switch (op_code
)
6989 case DW_LNS_extended_op
:
6990 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6991 line_ptr
+= bytes_read
;
6992 extended_end
= line_ptr
+ extended_len
;
6993 extended_op
= read_1_byte (abfd
, line_ptr
);
6995 switch (extended_op
)
6997 case DW_LNE_end_sequence
:
7000 if (lh
->num_file_names
< file
)
7001 dwarf2_debug_line_missing_file_complaint ();
7004 lh
->file_names
[file
- 1].included_p
= 1;
7005 if (!decode_for_pst_p
)
7006 record_line (current_subfile
, 0, address
);
7009 case DW_LNE_set_address
:
7010 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
7011 line_ptr
+= bytes_read
;
7012 address
+= baseaddr
;
7014 case DW_LNE_define_file
:
7017 unsigned int dir_index
, mod_time
, length
;
7019 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
7020 line_ptr
+= bytes_read
;
7022 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7023 line_ptr
+= bytes_read
;
7025 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7026 line_ptr
+= bytes_read
;
7028 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7029 line_ptr
+= bytes_read
;
7030 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7034 complaint (&symfile_complaints
,
7035 _("mangled .debug_line section"));
7038 /* Make sure that we parsed the extended op correctly. If e.g.
7039 we expected a different address size than the producer used,
7040 we may have read the wrong number of bytes. */
7041 if (line_ptr
!= extended_end
)
7043 complaint (&symfile_complaints
,
7044 _("mangled .debug_line section"));
7049 if (lh
->num_file_names
< file
)
7050 dwarf2_debug_line_missing_file_complaint ();
7053 lh
->file_names
[file
- 1].included_p
= 1;
7054 if (!decode_for_pst_p
)
7056 if (last_subfile
!= current_subfile
)
7059 record_line (last_subfile
, 0, address
);
7060 last_subfile
= current_subfile
;
7062 record_line (current_subfile
, line
,
7063 check_cu_functions (address
, cu
));
7068 case DW_LNS_advance_pc
:
7069 address
+= lh
->minimum_instruction_length
7070 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7071 line_ptr
+= bytes_read
;
7073 case DW_LNS_advance_line
:
7074 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
7075 line_ptr
+= bytes_read
;
7077 case DW_LNS_set_file
:
7079 /* The arrays lh->include_dirs and lh->file_names are
7080 0-based, but the directory and file name numbers in
7081 the statement program are 1-based. */
7082 struct file_entry
*fe
;
7085 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7086 line_ptr
+= bytes_read
;
7087 if (lh
->num_file_names
< file
)
7088 dwarf2_debug_line_missing_file_complaint ();
7091 fe
= &lh
->file_names
[file
- 1];
7093 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7094 if (!decode_for_pst_p
)
7096 last_subfile
= current_subfile
;
7097 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7102 case DW_LNS_set_column
:
7103 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7104 line_ptr
+= bytes_read
;
7106 case DW_LNS_negate_stmt
:
7107 is_stmt
= (!is_stmt
);
7109 case DW_LNS_set_basic_block
:
7112 /* Add to the address register of the state machine the
7113 address increment value corresponding to special opcode
7114 255. I.e., this value is scaled by the minimum
7115 instruction length since special opcode 255 would have
7116 scaled the the increment. */
7117 case DW_LNS_const_add_pc
:
7118 address
+= (lh
->minimum_instruction_length
7119 * ((255 - lh
->opcode_base
) / lh
->line_range
));
7121 case DW_LNS_fixed_advance_pc
:
7122 address
+= read_2_bytes (abfd
, line_ptr
);
7127 /* Unknown standard opcode, ignore it. */
7130 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
7132 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7133 line_ptr
+= bytes_read
;
7140 if (decode_for_pst_p
)
7144 /* Now that we're done scanning the Line Header Program, we can
7145 create the psymtab of each included file. */
7146 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
7147 if (lh
->file_names
[file_index
].included_p
== 1)
7149 const struct file_entry fe
= lh
->file_names
[file_index
];
7150 char *include_name
= fe
.name
;
7151 char *dir_name
= NULL
;
7152 char *pst_filename
= pst
->filename
;
7155 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
7157 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
7159 include_name
= concat (dir_name
, SLASH_STRING
,
7160 include_name
, (char *)NULL
);
7161 make_cleanup (xfree
, include_name
);
7164 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
7166 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
7167 pst_filename
, (char *)NULL
);
7168 make_cleanup (xfree
, pst_filename
);
7171 if (strcmp (include_name
, pst_filename
) != 0)
7172 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
7177 /* Make sure a symtab is created for every file, even files
7178 which contain only variables (i.e. no code with associated
7182 struct file_entry
*fe
;
7184 for (i
= 0; i
< lh
->num_file_names
; i
++)
7187 fe
= &lh
->file_names
[i
];
7189 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7190 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7192 /* Skip the main file; we don't need it, and it must be
7193 allocated last, so that it will show up before the
7194 non-primary symtabs in the objfile's symtab list. */
7195 if (current_subfile
== first_subfile
)
7198 if (current_subfile
->symtab
== NULL
)
7199 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7201 fe
->symtab
= current_subfile
->symtab
;
7206 /* Start a subfile for DWARF. FILENAME is the name of the file and
7207 DIRNAME the name of the source directory which contains FILENAME
7208 or NULL if not known. COMP_DIR is the compilation directory for the
7209 linetable's compilation unit or NULL if not known.
7210 This routine tries to keep line numbers from identical absolute and
7211 relative file names in a common subfile.
7213 Using the `list' example from the GDB testsuite, which resides in
7214 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
7215 of /srcdir/list0.c yields the following debugging information for list0.c:
7217 DW_AT_name: /srcdir/list0.c
7218 DW_AT_comp_dir: /compdir
7219 files.files[0].name: list0.h
7220 files.files[0].dir: /srcdir
7221 files.files[1].name: list0.c
7222 files.files[1].dir: /srcdir
7224 The line number information for list0.c has to end up in a single
7225 subfile, so that `break /srcdir/list0.c:1' works as expected.
7226 start_subfile will ensure that this happens provided that we pass the
7227 concatenation of files.files[1].dir and files.files[1].name as the
7231 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
7235 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
7236 `start_symtab' will always pass the contents of DW_AT_comp_dir as
7237 second argument to start_subfile. To be consistent, we do the
7238 same here. In order not to lose the line information directory,
7239 we concatenate it to the filename when it makes sense.
7240 Note that the Dwarf3 standard says (speaking of filenames in line
7241 information): ``The directory index is ignored for file names
7242 that represent full path names''. Thus ignoring dirname in the
7243 `else' branch below isn't an issue. */
7245 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
7246 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
7248 fullname
= filename
;
7250 start_subfile (fullname
, comp_dir
);
7252 if (fullname
!= filename
)
7257 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
7258 struct dwarf2_cu
*cu
)
7260 struct objfile
*objfile
= cu
->objfile
;
7261 struct comp_unit_head
*cu_header
= &cu
->header
;
7263 /* NOTE drow/2003-01-30: There used to be a comment and some special
7264 code here to turn a symbol with DW_AT_external and a
7265 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
7266 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
7267 with some versions of binutils) where shared libraries could have
7268 relocations against symbols in their debug information - the
7269 minimal symbol would have the right address, but the debug info
7270 would not. It's no longer necessary, because we will explicitly
7271 apply relocations when we read in the debug information now. */
7273 /* A DW_AT_location attribute with no contents indicates that a
7274 variable has been optimized away. */
7275 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
7277 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7281 /* Handle one degenerate form of location expression specially, to
7282 preserve GDB's previous behavior when section offsets are
7283 specified. If this is just a DW_OP_addr then mark this symbol
7286 if (attr_form_is_block (attr
)
7287 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
7288 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
7292 SYMBOL_VALUE_ADDRESS (sym
) =
7293 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
7294 SYMBOL_CLASS (sym
) = LOC_STATIC
;
7295 fixup_symbol_section (sym
, objfile
);
7296 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
7297 SYMBOL_SECTION (sym
));
7301 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
7302 expression evaluator, and use LOC_COMPUTED only when necessary
7303 (i.e. when the value of a register or memory location is
7304 referenced, or a thread-local block, etc.). Then again, it might
7305 not be worthwhile. I'm assuming that it isn't unless performance
7306 or memory numbers show me otherwise. */
7308 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
7309 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
7312 /* Given a pointer to a DWARF information entry, figure out if we need
7313 to make a symbol table entry for it, and if so, create a new entry
7314 and return a pointer to it.
7315 If TYPE is NULL, determine symbol type from the die, otherwise
7316 used the passed type. */
7318 static struct symbol
*
7319 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
7321 struct objfile
*objfile
= cu
->objfile
;
7322 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7323 struct symbol
*sym
= NULL
;
7325 struct attribute
*attr
= NULL
;
7326 struct attribute
*attr2
= NULL
;
7329 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7331 if (die
->tag
!= DW_TAG_namespace
)
7332 name
= dwarf2_linkage_name (die
, cu
);
7334 name
= TYPE_NAME (type
);
7338 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
7339 sizeof (struct symbol
));
7340 OBJSTAT (objfile
, n_syms
++);
7341 memset (sym
, 0, sizeof (struct symbol
));
7343 /* Cache this symbol's name and the name's demangled form (if any). */
7344 SYMBOL_LANGUAGE (sym
) = cu
->language
;
7345 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
7347 /* Default assumptions.
7348 Use the passed type or decode it from the die. */
7349 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7350 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7352 SYMBOL_TYPE (sym
) = type
;
7354 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
7355 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
7358 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
7361 attr
= dwarf2_attr (die
, DW_AT_decl_file
, cu
);
7364 int file_index
= DW_UNSND (attr
);
7365 if (cu
->line_header
== NULL
7366 || file_index
> cu
->line_header
->num_file_names
)
7367 complaint (&symfile_complaints
,
7368 _("file index out of range"));
7369 else if (file_index
> 0)
7371 struct file_entry
*fe
;
7372 fe
= &cu
->line_header
->file_names
[file_index
- 1];
7373 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
7380 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7383 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
7385 SYMBOL_CLASS (sym
) = LOC_LABEL
;
7387 case DW_TAG_subprogram
:
7388 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7390 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
7391 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7392 if ((attr2
&& (DW_UNSND (attr2
) != 0))
7393 || cu
->language
== language_ada
)
7395 /* Subprograms marked external are stored as a global symbol.
7396 Ada subprograms, whether marked external or not, are always
7397 stored as a global symbol, because we want to be able to
7398 access them globally. For instance, we want to be able
7399 to break on a nested subprogram without having to
7400 specify the context. */
7401 add_symbol_to_list (sym
, &global_symbols
);
7405 add_symbol_to_list (sym
, cu
->list_in_scope
);
7408 case DW_TAG_variable
:
7409 /* Compilation with minimal debug info may result in variables
7410 with missing type entries. Change the misleading `void' type
7411 to something sensible. */
7412 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
7414 = builtin_type (gdbarch
)->nodebug_data_symbol
;
7416 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7419 dwarf2_const_value (attr
, sym
, cu
);
7420 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7421 if (attr2
&& (DW_UNSND (attr2
) != 0))
7422 add_symbol_to_list (sym
, &global_symbols
);
7424 add_symbol_to_list (sym
, cu
->list_in_scope
);
7427 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7430 var_decode_location (attr
, sym
, cu
);
7431 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7432 if (attr2
&& (DW_UNSND (attr2
) != 0))
7433 add_symbol_to_list (sym
, &global_symbols
);
7435 add_symbol_to_list (sym
, cu
->list_in_scope
);
7439 /* We do not know the address of this symbol.
7440 If it is an external symbol and we have type information
7441 for it, enter the symbol as a LOC_UNRESOLVED symbol.
7442 The address of the variable will then be determined from
7443 the minimal symbol table whenever the variable is
7445 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7446 if (attr2
&& (DW_UNSND (attr2
) != 0)
7447 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
7449 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
7450 add_symbol_to_list (sym
, &global_symbols
);
7454 case DW_TAG_formal_parameter
:
7455 SYMBOL_IS_ARGUMENT (sym
) = 1;
7456 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7459 var_decode_location (attr
, sym
, cu
);
7461 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7464 dwarf2_const_value (attr
, sym
, cu
);
7466 add_symbol_to_list (sym
, cu
->list_in_scope
);
7468 case DW_TAG_unspecified_parameters
:
7469 /* From varargs functions; gdb doesn't seem to have any
7470 interest in this information, so just ignore it for now.
7473 case DW_TAG_class_type
:
7474 case DW_TAG_interface_type
:
7475 case DW_TAG_structure_type
:
7476 case DW_TAG_union_type
:
7477 case DW_TAG_set_type
:
7478 case DW_TAG_enumeration_type
:
7479 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7480 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7482 /* Make sure that the symbol includes appropriate enclosing
7483 classes/namespaces in its name. These are calculated in
7484 read_structure_type, and the correct name is saved in
7487 if (cu
->language
== language_cplus
7488 || cu
->language
== language_java
)
7490 struct type
*type
= SYMBOL_TYPE (sym
);
7492 if (TYPE_TAG_NAME (type
) != NULL
)
7494 /* FIXME: carlton/2003-11-10: Should this use
7495 SYMBOL_SET_NAMES instead? (The same problem also
7496 arises further down in this function.) */
7497 /* The type's name is already allocated along with
7498 this objfile, so we don't need to duplicate it
7500 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
7505 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
7506 really ever be static objects: otherwise, if you try
7507 to, say, break of a class's method and you're in a file
7508 which doesn't mention that class, it won't work unless
7509 the check for all static symbols in lookup_symbol_aux
7510 saves you. See the OtherFileClass tests in
7511 gdb.c++/namespace.exp. */
7513 struct pending
**list_to_add
;
7515 list_to_add
= (cu
->list_in_scope
== &file_symbols
7516 && (cu
->language
== language_cplus
7517 || cu
->language
== language_java
)
7518 ? &global_symbols
: cu
->list_in_scope
);
7520 add_symbol_to_list (sym
, list_to_add
);
7522 /* The semantics of C++ state that "struct foo { ... }" also
7523 defines a typedef for "foo". A Java class declaration also
7524 defines a typedef for the class. */
7525 if (cu
->language
== language_cplus
7526 || cu
->language
== language_java
7527 || cu
->language
== language_ada
)
7529 /* The symbol's name is already allocated along with
7530 this objfile, so we don't need to duplicate it for
7532 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
7533 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
7537 case DW_TAG_typedef
:
7538 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7539 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7540 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7541 add_symbol_to_list (sym
, cu
->list_in_scope
);
7543 case DW_TAG_base_type
:
7544 case DW_TAG_subrange_type
:
7545 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7546 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7547 add_symbol_to_list (sym
, cu
->list_in_scope
);
7549 case DW_TAG_enumerator
:
7550 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7551 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7554 dwarf2_const_value (attr
, sym
, cu
);
7557 /* NOTE: carlton/2003-11-10: See comment above in the
7558 DW_TAG_class_type, etc. block. */
7560 struct pending
**list_to_add
;
7562 list_to_add
= (cu
->list_in_scope
== &file_symbols
7563 && (cu
->language
== language_cplus
7564 || cu
->language
== language_java
)
7565 ? &global_symbols
: cu
->list_in_scope
);
7567 add_symbol_to_list (sym
, list_to_add
);
7570 case DW_TAG_namespace
:
7571 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7572 add_symbol_to_list (sym
, &global_symbols
);
7575 /* Not a tag we recognize. Hopefully we aren't processing
7576 trash data, but since we must specifically ignore things
7577 we don't recognize, there is nothing else we should do at
7579 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
7580 dwarf_tag_name (die
->tag
));
7584 /* For the benefit of old versions of GCC, check for anonymous
7585 namespaces based on the demangled name. */
7586 if (!processing_has_namespace_info
7587 && cu
->language
== language_cplus
7588 && dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
) != NULL
)
7589 cp_scan_for_anonymous_namespaces (sym
);
7594 /* Copy constant value from an attribute to a symbol. */
7597 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
7598 struct dwarf2_cu
*cu
)
7600 struct objfile
*objfile
= cu
->objfile
;
7601 struct comp_unit_head
*cu_header
= &cu
->header
;
7602 struct dwarf_block
*blk
;
7607 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
7608 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7609 cu_header
->addr_size
,
7610 TYPE_LENGTH (SYMBOL_TYPE
7612 SYMBOL_VALUE_BYTES (sym
) =
7613 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
7614 /* NOTE: cagney/2003-05-09: In-lined store_address call with
7615 it's body - store_unsigned_integer. */
7616 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
7618 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7621 /* DW_STRING is already allocated on the obstack, point directly
7623 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
7624 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7626 case DW_FORM_block1
:
7627 case DW_FORM_block2
:
7628 case DW_FORM_block4
:
7630 blk
= DW_BLOCK (attr
);
7631 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
7632 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7634 TYPE_LENGTH (SYMBOL_TYPE
7636 SYMBOL_VALUE_BYTES (sym
) =
7637 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
7638 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
7639 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7642 /* The DW_AT_const_value attributes are supposed to carry the
7643 symbol's value "represented as it would be on the target
7644 architecture." By the time we get here, it's already been
7645 converted to host endianness, so we just need to sign- or
7646 zero-extend it as appropriate. */
7648 dwarf2_const_value_data (attr
, sym
, 8);
7651 dwarf2_const_value_data (attr
, sym
, 16);
7654 dwarf2_const_value_data (attr
, sym
, 32);
7657 dwarf2_const_value_data (attr
, sym
, 64);
7661 SYMBOL_VALUE (sym
) = DW_SND (attr
);
7662 SYMBOL_CLASS (sym
) = LOC_CONST
;
7666 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
7667 SYMBOL_CLASS (sym
) = LOC_CONST
;
7671 complaint (&symfile_complaints
,
7672 _("unsupported const value attribute form: '%s'"),
7673 dwarf_form_name (attr
->form
));
7674 SYMBOL_VALUE (sym
) = 0;
7675 SYMBOL_CLASS (sym
) = LOC_CONST
;
7681 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
7682 or zero-extend it as appropriate for the symbol's type. */
7684 dwarf2_const_value_data (struct attribute
*attr
,
7688 LONGEST l
= DW_UNSND (attr
);
7690 if (bits
< sizeof (l
) * 8)
7692 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
7693 l
&= ((LONGEST
) 1 << bits
) - 1;
7695 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
7698 SYMBOL_VALUE (sym
) = l
;
7699 SYMBOL_CLASS (sym
) = LOC_CONST
;
7703 /* Return the type of the die in question using its DW_AT_type attribute. */
7705 static struct type
*
7706 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7708 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7710 struct attribute
*type_attr
;
7711 struct die_info
*type_die
;
7713 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
7716 /* A missing DW_AT_type represents a void type. */
7717 return builtin_type (gdbarch
)->builtin_void
;
7720 type_die
= follow_die_ref (die
, type_attr
, &cu
);
7722 type
= tag_type_to_type (type_die
, cu
);
7725 dump_die (type_die
);
7726 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
7732 /* Return the containing type of the die in question using its
7733 DW_AT_containing_type attribute. */
7735 static struct type
*
7736 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7738 struct type
*type
= NULL
;
7739 struct attribute
*type_attr
;
7740 struct die_info
*type_die
= NULL
;
7742 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
7745 type_die
= follow_die_ref (die
, type_attr
, &cu
);
7746 type
= tag_type_to_type (type_die
, cu
);
7751 dump_die (type_die
);
7752 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
7758 static struct type
*
7759 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7761 struct type
*this_type
;
7763 this_type
= read_type_die (die
, cu
);
7767 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
7773 static struct type
*
7774 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7776 struct type
*this_type
;
7778 this_type
= get_die_type (die
, cu
);
7784 case DW_TAG_class_type
:
7785 case DW_TAG_interface_type
:
7786 case DW_TAG_structure_type
:
7787 case DW_TAG_union_type
:
7788 this_type
= read_structure_type (die
, cu
);
7790 case DW_TAG_enumeration_type
:
7791 this_type
= read_enumeration_type (die
, cu
);
7793 case DW_TAG_subprogram
:
7794 case DW_TAG_subroutine_type
:
7795 this_type
= read_subroutine_type (die
, cu
);
7797 case DW_TAG_array_type
:
7798 this_type
= read_array_type (die
, cu
);
7800 case DW_TAG_set_type
:
7801 this_type
= read_set_type (die
, cu
);
7803 case DW_TAG_pointer_type
:
7804 this_type
= read_tag_pointer_type (die
, cu
);
7806 case DW_TAG_ptr_to_member_type
:
7807 this_type
= read_tag_ptr_to_member_type (die
, cu
);
7809 case DW_TAG_reference_type
:
7810 this_type
= read_tag_reference_type (die
, cu
);
7812 case DW_TAG_const_type
:
7813 this_type
= read_tag_const_type (die
, cu
);
7815 case DW_TAG_volatile_type
:
7816 this_type
= read_tag_volatile_type (die
, cu
);
7818 case DW_TAG_string_type
:
7819 this_type
= read_tag_string_type (die
, cu
);
7821 case DW_TAG_typedef
:
7822 this_type
= read_typedef (die
, cu
);
7824 case DW_TAG_subrange_type
:
7825 this_type
= read_subrange_type (die
, cu
);
7827 case DW_TAG_base_type
:
7828 this_type
= read_base_type (die
, cu
);
7830 case DW_TAG_unspecified_type
:
7831 this_type
= read_unspecified_type (die
, cu
);
7833 case DW_TAG_namespace
:
7834 this_type
= read_namespace_type (die
, cu
);
7837 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
7838 dwarf_tag_name (die
->tag
));
7845 /* Return the name of the namespace/class that DIE is defined within,
7846 or "" if we can't tell. The caller should not xfree the result.
7848 For example, if we're within the method foo() in the following
7858 then determine_prefix on foo's die will return "N::C". */
7861 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
7863 struct die_info
*parent
, *spec_die
;
7864 struct dwarf2_cu
*spec_cu
;
7865 struct type
*parent_type
;
7867 if (cu
->language
!= language_cplus
7868 && cu
->language
!= language_java
)
7871 /* We have to be careful in the presence of DW_AT_specification.
7872 For example, with GCC 3.4, given the code
7876 // Definition of N::foo.
7880 then we'll have a tree of DIEs like this:
7882 1: DW_TAG_compile_unit
7883 2: DW_TAG_namespace // N
7884 3: DW_TAG_subprogram // declaration of N::foo
7885 4: DW_TAG_subprogram // definition of N::foo
7886 DW_AT_specification // refers to die #3
7888 Thus, when processing die #4, we have to pretend that we're in
7889 the context of its DW_AT_specification, namely the contex of die
7892 spec_die
= die_specification (die
, &spec_cu
);
7893 if (spec_die
== NULL
)
7894 parent
= die
->parent
;
7897 parent
= spec_die
->parent
;
7904 switch (parent
->tag
)
7906 case DW_TAG_namespace
:
7907 parent_type
= read_type_die (parent
, cu
);
7908 /* We give a name to even anonymous namespaces. */
7909 return TYPE_TAG_NAME (parent_type
);
7910 case DW_TAG_class_type
:
7911 case DW_TAG_interface_type
:
7912 case DW_TAG_structure_type
:
7913 case DW_TAG_union_type
:
7914 parent_type
= read_type_die (parent
, cu
);
7915 if (TYPE_TAG_NAME (parent_type
) != NULL
)
7916 return TYPE_TAG_NAME (parent_type
);
7918 /* An anonymous structure is only allowed non-static data
7919 members; no typedefs, no member functions, et cetera.
7920 So it does not need a prefix. */
7923 return determine_prefix (parent
, cu
);
7927 /* Return a newly-allocated string formed by concatenating PREFIX and
7928 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
7929 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
7930 perform an obconcat, otherwise allocate storage for the result. The CU argument
7931 is used to determine the language and hence, the appropriate separator. */
7933 #define MAX_SEP_LEN 2 /* sizeof ("::") */
7936 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
7937 struct dwarf2_cu
*cu
)
7941 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
7943 else if (cu
->language
== language_java
)
7950 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
7955 strcpy (retval
, prefix
);
7956 strcat (retval
, sep
);
7959 strcat (retval
, suffix
);
7965 /* We have an obstack. */
7966 return obconcat (obs
, prefix
, sep
, suffix
);
7970 /* Return sibling of die, NULL if no sibling. */
7972 static struct die_info
*
7973 sibling_die (struct die_info
*die
)
7975 return die
->sibling
;
7978 /* Get linkage name of a die, return NULL if not found. */
7981 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
7983 struct attribute
*attr
;
7985 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7986 if (attr
&& DW_STRING (attr
))
7987 return DW_STRING (attr
);
7988 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7989 if (attr
&& DW_STRING (attr
))
7990 return DW_STRING (attr
);
7994 /* Get name of a die, return NULL if not found. */
7997 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
7999 struct attribute
*attr
;
8001 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8002 if (attr
&& DW_STRING (attr
))
8003 return DW_STRING (attr
);
8007 /* Return the die that this die in an extension of, or NULL if there
8008 is none. *EXT_CU is the CU containing DIE on input, and the CU
8009 containing the return value on output. */
8011 static struct die_info
*
8012 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
8014 struct attribute
*attr
;
8016 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
8020 return follow_die_ref (die
, attr
, ext_cu
);
8023 /* Convert a DIE tag into its string name. */
8026 dwarf_tag_name (unsigned tag
)
8030 case DW_TAG_padding
:
8031 return "DW_TAG_padding";
8032 case DW_TAG_array_type
:
8033 return "DW_TAG_array_type";
8034 case DW_TAG_class_type
:
8035 return "DW_TAG_class_type";
8036 case DW_TAG_entry_point
:
8037 return "DW_TAG_entry_point";
8038 case DW_TAG_enumeration_type
:
8039 return "DW_TAG_enumeration_type";
8040 case DW_TAG_formal_parameter
:
8041 return "DW_TAG_formal_parameter";
8042 case DW_TAG_imported_declaration
:
8043 return "DW_TAG_imported_declaration";
8045 return "DW_TAG_label";
8046 case DW_TAG_lexical_block
:
8047 return "DW_TAG_lexical_block";
8049 return "DW_TAG_member";
8050 case DW_TAG_pointer_type
:
8051 return "DW_TAG_pointer_type";
8052 case DW_TAG_reference_type
:
8053 return "DW_TAG_reference_type";
8054 case DW_TAG_compile_unit
:
8055 return "DW_TAG_compile_unit";
8056 case DW_TAG_string_type
:
8057 return "DW_TAG_string_type";
8058 case DW_TAG_structure_type
:
8059 return "DW_TAG_structure_type";
8060 case DW_TAG_subroutine_type
:
8061 return "DW_TAG_subroutine_type";
8062 case DW_TAG_typedef
:
8063 return "DW_TAG_typedef";
8064 case DW_TAG_union_type
:
8065 return "DW_TAG_union_type";
8066 case DW_TAG_unspecified_parameters
:
8067 return "DW_TAG_unspecified_parameters";
8068 case DW_TAG_variant
:
8069 return "DW_TAG_variant";
8070 case DW_TAG_common_block
:
8071 return "DW_TAG_common_block";
8072 case DW_TAG_common_inclusion
:
8073 return "DW_TAG_common_inclusion";
8074 case DW_TAG_inheritance
:
8075 return "DW_TAG_inheritance";
8076 case DW_TAG_inlined_subroutine
:
8077 return "DW_TAG_inlined_subroutine";
8079 return "DW_TAG_module";
8080 case DW_TAG_ptr_to_member_type
:
8081 return "DW_TAG_ptr_to_member_type";
8082 case DW_TAG_set_type
:
8083 return "DW_TAG_set_type";
8084 case DW_TAG_subrange_type
:
8085 return "DW_TAG_subrange_type";
8086 case DW_TAG_with_stmt
:
8087 return "DW_TAG_with_stmt";
8088 case DW_TAG_access_declaration
:
8089 return "DW_TAG_access_declaration";
8090 case DW_TAG_base_type
:
8091 return "DW_TAG_base_type";
8092 case DW_TAG_catch_block
:
8093 return "DW_TAG_catch_block";
8094 case DW_TAG_const_type
:
8095 return "DW_TAG_const_type";
8096 case DW_TAG_constant
:
8097 return "DW_TAG_constant";
8098 case DW_TAG_enumerator
:
8099 return "DW_TAG_enumerator";
8100 case DW_TAG_file_type
:
8101 return "DW_TAG_file_type";
8103 return "DW_TAG_friend";
8104 case DW_TAG_namelist
:
8105 return "DW_TAG_namelist";
8106 case DW_TAG_namelist_item
:
8107 return "DW_TAG_namelist_item";
8108 case DW_TAG_packed_type
:
8109 return "DW_TAG_packed_type";
8110 case DW_TAG_subprogram
:
8111 return "DW_TAG_subprogram";
8112 case DW_TAG_template_type_param
:
8113 return "DW_TAG_template_type_param";
8114 case DW_TAG_template_value_param
:
8115 return "DW_TAG_template_value_param";
8116 case DW_TAG_thrown_type
:
8117 return "DW_TAG_thrown_type";
8118 case DW_TAG_try_block
:
8119 return "DW_TAG_try_block";
8120 case DW_TAG_variant_part
:
8121 return "DW_TAG_variant_part";
8122 case DW_TAG_variable
:
8123 return "DW_TAG_variable";
8124 case DW_TAG_volatile_type
:
8125 return "DW_TAG_volatile_type";
8126 case DW_TAG_dwarf_procedure
:
8127 return "DW_TAG_dwarf_procedure";
8128 case DW_TAG_restrict_type
:
8129 return "DW_TAG_restrict_type";
8130 case DW_TAG_interface_type
:
8131 return "DW_TAG_interface_type";
8132 case DW_TAG_namespace
:
8133 return "DW_TAG_namespace";
8134 case DW_TAG_imported_module
:
8135 return "DW_TAG_imported_module";
8136 case DW_TAG_unspecified_type
:
8137 return "DW_TAG_unspecified_type";
8138 case DW_TAG_partial_unit
:
8139 return "DW_TAG_partial_unit";
8140 case DW_TAG_imported_unit
:
8141 return "DW_TAG_imported_unit";
8142 case DW_TAG_condition
:
8143 return "DW_TAG_condition";
8144 case DW_TAG_shared_type
:
8145 return "DW_TAG_shared_type";
8146 case DW_TAG_MIPS_loop
:
8147 return "DW_TAG_MIPS_loop";
8148 case DW_TAG_HP_array_descriptor
:
8149 return "DW_TAG_HP_array_descriptor";
8150 case DW_TAG_format_label
:
8151 return "DW_TAG_format_label";
8152 case DW_TAG_function_template
:
8153 return "DW_TAG_function_template";
8154 case DW_TAG_class_template
:
8155 return "DW_TAG_class_template";
8156 case DW_TAG_GNU_BINCL
:
8157 return "DW_TAG_GNU_BINCL";
8158 case DW_TAG_GNU_EINCL
:
8159 return "DW_TAG_GNU_EINCL";
8160 case DW_TAG_upc_shared_type
:
8161 return "DW_TAG_upc_shared_type";
8162 case DW_TAG_upc_strict_type
:
8163 return "DW_TAG_upc_strict_type";
8164 case DW_TAG_upc_relaxed_type
:
8165 return "DW_TAG_upc_relaxed_type";
8166 case DW_TAG_PGI_kanji_type
:
8167 return "DW_TAG_PGI_kanji_type";
8168 case DW_TAG_PGI_interface_block
:
8169 return "DW_TAG_PGI_interface_block";
8171 return "DW_TAG_<unknown>";
8175 /* Convert a DWARF attribute code into its string name. */
8178 dwarf_attr_name (unsigned attr
)
8183 return "DW_AT_sibling";
8184 case DW_AT_location
:
8185 return "DW_AT_location";
8187 return "DW_AT_name";
8188 case DW_AT_ordering
:
8189 return "DW_AT_ordering";
8190 case DW_AT_subscr_data
:
8191 return "DW_AT_subscr_data";
8192 case DW_AT_byte_size
:
8193 return "DW_AT_byte_size";
8194 case DW_AT_bit_offset
:
8195 return "DW_AT_bit_offset";
8196 case DW_AT_bit_size
:
8197 return "DW_AT_bit_size";
8198 case DW_AT_element_list
:
8199 return "DW_AT_element_list";
8200 case DW_AT_stmt_list
:
8201 return "DW_AT_stmt_list";
8203 return "DW_AT_low_pc";
8205 return "DW_AT_high_pc";
8206 case DW_AT_language
:
8207 return "DW_AT_language";
8209 return "DW_AT_member";
8211 return "DW_AT_discr";
8212 case DW_AT_discr_value
:
8213 return "DW_AT_discr_value";
8214 case DW_AT_visibility
:
8215 return "DW_AT_visibility";
8217 return "DW_AT_import";
8218 case DW_AT_string_length
:
8219 return "DW_AT_string_length";
8220 case DW_AT_common_reference
:
8221 return "DW_AT_common_reference";
8222 case DW_AT_comp_dir
:
8223 return "DW_AT_comp_dir";
8224 case DW_AT_const_value
:
8225 return "DW_AT_const_value";
8226 case DW_AT_containing_type
:
8227 return "DW_AT_containing_type";
8228 case DW_AT_default_value
:
8229 return "DW_AT_default_value";
8231 return "DW_AT_inline";
8232 case DW_AT_is_optional
:
8233 return "DW_AT_is_optional";
8234 case DW_AT_lower_bound
:
8235 return "DW_AT_lower_bound";
8236 case DW_AT_producer
:
8237 return "DW_AT_producer";
8238 case DW_AT_prototyped
:
8239 return "DW_AT_prototyped";
8240 case DW_AT_return_addr
:
8241 return "DW_AT_return_addr";
8242 case DW_AT_start_scope
:
8243 return "DW_AT_start_scope";
8244 case DW_AT_bit_stride
:
8245 return "DW_AT_bit_stride";
8246 case DW_AT_upper_bound
:
8247 return "DW_AT_upper_bound";
8248 case DW_AT_abstract_origin
:
8249 return "DW_AT_abstract_origin";
8250 case DW_AT_accessibility
:
8251 return "DW_AT_accessibility";
8252 case DW_AT_address_class
:
8253 return "DW_AT_address_class";
8254 case DW_AT_artificial
:
8255 return "DW_AT_artificial";
8256 case DW_AT_base_types
:
8257 return "DW_AT_base_types";
8258 case DW_AT_calling_convention
:
8259 return "DW_AT_calling_convention";
8261 return "DW_AT_count";
8262 case DW_AT_data_member_location
:
8263 return "DW_AT_data_member_location";
8264 case DW_AT_decl_column
:
8265 return "DW_AT_decl_column";
8266 case DW_AT_decl_file
:
8267 return "DW_AT_decl_file";
8268 case DW_AT_decl_line
:
8269 return "DW_AT_decl_line";
8270 case DW_AT_declaration
:
8271 return "DW_AT_declaration";
8272 case DW_AT_discr_list
:
8273 return "DW_AT_discr_list";
8274 case DW_AT_encoding
:
8275 return "DW_AT_encoding";
8276 case DW_AT_external
:
8277 return "DW_AT_external";
8278 case DW_AT_frame_base
:
8279 return "DW_AT_frame_base";
8281 return "DW_AT_friend";
8282 case DW_AT_identifier_case
:
8283 return "DW_AT_identifier_case";
8284 case DW_AT_macro_info
:
8285 return "DW_AT_macro_info";
8286 case DW_AT_namelist_items
:
8287 return "DW_AT_namelist_items";
8288 case DW_AT_priority
:
8289 return "DW_AT_priority";
8291 return "DW_AT_segment";
8292 case DW_AT_specification
:
8293 return "DW_AT_specification";
8294 case DW_AT_static_link
:
8295 return "DW_AT_static_link";
8297 return "DW_AT_type";
8298 case DW_AT_use_location
:
8299 return "DW_AT_use_location";
8300 case DW_AT_variable_parameter
:
8301 return "DW_AT_variable_parameter";
8302 case DW_AT_virtuality
:
8303 return "DW_AT_virtuality";
8304 case DW_AT_vtable_elem_location
:
8305 return "DW_AT_vtable_elem_location";
8306 /* DWARF 3 values. */
8307 case DW_AT_allocated
:
8308 return "DW_AT_allocated";
8309 case DW_AT_associated
:
8310 return "DW_AT_associated";
8311 case DW_AT_data_location
:
8312 return "DW_AT_data_location";
8313 case DW_AT_byte_stride
:
8314 return "DW_AT_byte_stride";
8315 case DW_AT_entry_pc
:
8316 return "DW_AT_entry_pc";
8317 case DW_AT_use_UTF8
:
8318 return "DW_AT_use_UTF8";
8319 case DW_AT_extension
:
8320 return "DW_AT_extension";
8322 return "DW_AT_ranges";
8323 case DW_AT_trampoline
:
8324 return "DW_AT_trampoline";
8325 case DW_AT_call_column
:
8326 return "DW_AT_call_column";
8327 case DW_AT_call_file
:
8328 return "DW_AT_call_file";
8329 case DW_AT_call_line
:
8330 return "DW_AT_call_line";
8331 case DW_AT_description
:
8332 return "DW_AT_description";
8333 case DW_AT_binary_scale
:
8334 return "DW_AT_binary_scale";
8335 case DW_AT_decimal_scale
:
8336 return "DW_AT_decimal_scale";
8338 return "DW_AT_small";
8339 case DW_AT_decimal_sign
:
8340 return "DW_AT_decimal_sign";
8341 case DW_AT_digit_count
:
8342 return "DW_AT_digit_count";
8343 case DW_AT_picture_string
:
8344 return "DW_AT_picture_string";
8346 return "DW_AT_mutable";
8347 case DW_AT_threads_scaled
:
8348 return "DW_AT_threads_scaled";
8349 case DW_AT_explicit
:
8350 return "DW_AT_explicit";
8351 case DW_AT_object_pointer
:
8352 return "DW_AT_object_pointer";
8353 case DW_AT_endianity
:
8354 return "DW_AT_endianity";
8355 case DW_AT_elemental
:
8356 return "DW_AT_elemental";
8358 return "DW_AT_pure";
8359 case DW_AT_recursive
:
8360 return "DW_AT_recursive";
8362 /* SGI/MIPS extensions. */
8363 case DW_AT_MIPS_fde
:
8364 return "DW_AT_MIPS_fde";
8365 case DW_AT_MIPS_loop_begin
:
8366 return "DW_AT_MIPS_loop_begin";
8367 case DW_AT_MIPS_tail_loop_begin
:
8368 return "DW_AT_MIPS_tail_loop_begin";
8369 case DW_AT_MIPS_epilog_begin
:
8370 return "DW_AT_MIPS_epilog_begin";
8371 case DW_AT_MIPS_loop_unroll_factor
:
8372 return "DW_AT_MIPS_loop_unroll_factor";
8373 case DW_AT_MIPS_software_pipeline_depth
:
8374 return "DW_AT_MIPS_software_pipeline_depth";
8375 case DW_AT_MIPS_linkage_name
:
8376 return "DW_AT_MIPS_linkage_name";
8377 case DW_AT_MIPS_stride
:
8378 return "DW_AT_MIPS_stride";
8379 case DW_AT_MIPS_abstract_name
:
8380 return "DW_AT_MIPS_abstract_name";
8381 case DW_AT_MIPS_clone_origin
:
8382 return "DW_AT_MIPS_clone_origin";
8383 case DW_AT_MIPS_has_inlines
:
8384 return "DW_AT_MIPS_has_inlines";
8386 /* HP extensions. */
8387 case DW_AT_HP_block_index
:
8388 return "DW_AT_HP_block_index";
8389 case DW_AT_HP_unmodifiable
:
8390 return "DW_AT_HP_unmodifiable";
8391 case DW_AT_HP_actuals_stmt_list
:
8392 return "DW_AT_HP_actuals_stmt_list";
8393 case DW_AT_HP_proc_per_section
:
8394 return "DW_AT_HP_proc_per_section";
8395 case DW_AT_HP_raw_data_ptr
:
8396 return "DW_AT_HP_raw_data_ptr";
8397 case DW_AT_HP_pass_by_reference
:
8398 return "DW_AT_HP_pass_by_reference";
8399 case DW_AT_HP_opt_level
:
8400 return "DW_AT_HP_opt_level";
8401 case DW_AT_HP_prof_version_id
:
8402 return "DW_AT_HP_prof_version_id";
8403 case DW_AT_HP_opt_flags
:
8404 return "DW_AT_HP_opt_flags";
8405 case DW_AT_HP_cold_region_low_pc
:
8406 return "DW_AT_HP_cold_region_low_pc";
8407 case DW_AT_HP_cold_region_high_pc
:
8408 return "DW_AT_HP_cold_region_high_pc";
8409 case DW_AT_HP_all_variables_modifiable
:
8410 return "DW_AT_HP_all_variables_modifiable";
8411 case DW_AT_HP_linkage_name
:
8412 return "DW_AT_HP_linkage_name";
8413 case DW_AT_HP_prof_flags
:
8414 return "DW_AT_HP_prof_flags";
8415 /* GNU extensions. */
8416 case DW_AT_sf_names
:
8417 return "DW_AT_sf_names";
8418 case DW_AT_src_info
:
8419 return "DW_AT_src_info";
8420 case DW_AT_mac_info
:
8421 return "DW_AT_mac_info";
8422 case DW_AT_src_coords
:
8423 return "DW_AT_src_coords";
8424 case DW_AT_body_begin
:
8425 return "DW_AT_body_begin";
8426 case DW_AT_body_end
:
8427 return "DW_AT_body_end";
8428 case DW_AT_GNU_vector
:
8429 return "DW_AT_GNU_vector";
8430 /* VMS extensions. */
8431 case DW_AT_VMS_rtnbeg_pd_address
:
8432 return "DW_AT_VMS_rtnbeg_pd_address";
8433 /* UPC extension. */
8434 case DW_AT_upc_threads_scaled
:
8435 return "DW_AT_upc_threads_scaled";
8436 /* PGI (STMicroelectronics) extensions. */
8437 case DW_AT_PGI_lbase
:
8438 return "DW_AT_PGI_lbase";
8439 case DW_AT_PGI_soffset
:
8440 return "DW_AT_PGI_soffset";
8441 case DW_AT_PGI_lstride
:
8442 return "DW_AT_PGI_lstride";
8444 return "DW_AT_<unknown>";
8448 /* Convert a DWARF value form code into its string name. */
8451 dwarf_form_name (unsigned form
)
8456 return "DW_FORM_addr";
8457 case DW_FORM_block2
:
8458 return "DW_FORM_block2";
8459 case DW_FORM_block4
:
8460 return "DW_FORM_block4";
8462 return "DW_FORM_data2";
8464 return "DW_FORM_data4";
8466 return "DW_FORM_data8";
8467 case DW_FORM_string
:
8468 return "DW_FORM_string";
8470 return "DW_FORM_block";
8471 case DW_FORM_block1
:
8472 return "DW_FORM_block1";
8474 return "DW_FORM_data1";
8476 return "DW_FORM_flag";
8478 return "DW_FORM_sdata";
8480 return "DW_FORM_strp";
8482 return "DW_FORM_udata";
8483 case DW_FORM_ref_addr
:
8484 return "DW_FORM_ref_addr";
8486 return "DW_FORM_ref1";
8488 return "DW_FORM_ref2";
8490 return "DW_FORM_ref4";
8492 return "DW_FORM_ref8";
8493 case DW_FORM_ref_udata
:
8494 return "DW_FORM_ref_udata";
8495 case DW_FORM_indirect
:
8496 return "DW_FORM_indirect";
8498 return "DW_FORM_<unknown>";
8502 /* Convert a DWARF stack opcode into its string name. */
8505 dwarf_stack_op_name (unsigned op
)
8510 return "DW_OP_addr";
8512 return "DW_OP_deref";
8514 return "DW_OP_const1u";
8516 return "DW_OP_const1s";
8518 return "DW_OP_const2u";
8520 return "DW_OP_const2s";
8522 return "DW_OP_const4u";
8524 return "DW_OP_const4s";
8526 return "DW_OP_const8u";
8528 return "DW_OP_const8s";
8530 return "DW_OP_constu";
8532 return "DW_OP_consts";
8536 return "DW_OP_drop";
8538 return "DW_OP_over";
8540 return "DW_OP_pick";
8542 return "DW_OP_swap";
8546 return "DW_OP_xderef";
8554 return "DW_OP_minus";
8566 return "DW_OP_plus";
8567 case DW_OP_plus_uconst
:
8568 return "DW_OP_plus_uconst";
8574 return "DW_OP_shra";
8592 return "DW_OP_skip";
8594 return "DW_OP_lit0";
8596 return "DW_OP_lit1";
8598 return "DW_OP_lit2";
8600 return "DW_OP_lit3";
8602 return "DW_OP_lit4";
8604 return "DW_OP_lit5";
8606 return "DW_OP_lit6";
8608 return "DW_OP_lit7";
8610 return "DW_OP_lit8";
8612 return "DW_OP_lit9";
8614 return "DW_OP_lit10";
8616 return "DW_OP_lit11";
8618 return "DW_OP_lit12";
8620 return "DW_OP_lit13";
8622 return "DW_OP_lit14";
8624 return "DW_OP_lit15";
8626 return "DW_OP_lit16";
8628 return "DW_OP_lit17";
8630 return "DW_OP_lit18";
8632 return "DW_OP_lit19";
8634 return "DW_OP_lit20";
8636 return "DW_OP_lit21";
8638 return "DW_OP_lit22";
8640 return "DW_OP_lit23";
8642 return "DW_OP_lit24";
8644 return "DW_OP_lit25";
8646 return "DW_OP_lit26";
8648 return "DW_OP_lit27";
8650 return "DW_OP_lit28";
8652 return "DW_OP_lit29";
8654 return "DW_OP_lit30";
8656 return "DW_OP_lit31";
8658 return "DW_OP_reg0";
8660 return "DW_OP_reg1";
8662 return "DW_OP_reg2";
8664 return "DW_OP_reg3";
8666 return "DW_OP_reg4";
8668 return "DW_OP_reg5";
8670 return "DW_OP_reg6";
8672 return "DW_OP_reg7";
8674 return "DW_OP_reg8";
8676 return "DW_OP_reg9";
8678 return "DW_OP_reg10";
8680 return "DW_OP_reg11";
8682 return "DW_OP_reg12";
8684 return "DW_OP_reg13";
8686 return "DW_OP_reg14";
8688 return "DW_OP_reg15";
8690 return "DW_OP_reg16";
8692 return "DW_OP_reg17";
8694 return "DW_OP_reg18";
8696 return "DW_OP_reg19";
8698 return "DW_OP_reg20";
8700 return "DW_OP_reg21";
8702 return "DW_OP_reg22";
8704 return "DW_OP_reg23";
8706 return "DW_OP_reg24";
8708 return "DW_OP_reg25";
8710 return "DW_OP_reg26";
8712 return "DW_OP_reg27";
8714 return "DW_OP_reg28";
8716 return "DW_OP_reg29";
8718 return "DW_OP_reg30";
8720 return "DW_OP_reg31";
8722 return "DW_OP_breg0";
8724 return "DW_OP_breg1";
8726 return "DW_OP_breg2";
8728 return "DW_OP_breg3";
8730 return "DW_OP_breg4";
8732 return "DW_OP_breg5";
8734 return "DW_OP_breg6";
8736 return "DW_OP_breg7";
8738 return "DW_OP_breg8";
8740 return "DW_OP_breg9";
8742 return "DW_OP_breg10";
8744 return "DW_OP_breg11";
8746 return "DW_OP_breg12";
8748 return "DW_OP_breg13";
8750 return "DW_OP_breg14";
8752 return "DW_OP_breg15";
8754 return "DW_OP_breg16";
8756 return "DW_OP_breg17";
8758 return "DW_OP_breg18";
8760 return "DW_OP_breg19";
8762 return "DW_OP_breg20";
8764 return "DW_OP_breg21";
8766 return "DW_OP_breg22";
8768 return "DW_OP_breg23";
8770 return "DW_OP_breg24";
8772 return "DW_OP_breg25";
8774 return "DW_OP_breg26";
8776 return "DW_OP_breg27";
8778 return "DW_OP_breg28";
8780 return "DW_OP_breg29";
8782 return "DW_OP_breg30";
8784 return "DW_OP_breg31";
8786 return "DW_OP_regx";
8788 return "DW_OP_fbreg";
8790 return "DW_OP_bregx";
8792 return "DW_OP_piece";
8793 case DW_OP_deref_size
:
8794 return "DW_OP_deref_size";
8795 case DW_OP_xderef_size
:
8796 return "DW_OP_xderef_size";
8799 /* DWARF 3 extensions. */
8800 case DW_OP_push_object_address
:
8801 return "DW_OP_push_object_address";
8803 return "DW_OP_call2";
8805 return "DW_OP_call4";
8806 case DW_OP_call_ref
:
8807 return "DW_OP_call_ref";
8808 /* GNU extensions. */
8809 case DW_OP_form_tls_address
:
8810 return "DW_OP_form_tls_address";
8811 case DW_OP_call_frame_cfa
:
8812 return "DW_OP_call_frame_cfa";
8813 case DW_OP_bit_piece
:
8814 return "DW_OP_bit_piece";
8815 case DW_OP_GNU_push_tls_address
:
8816 return "DW_OP_GNU_push_tls_address";
8817 case DW_OP_GNU_uninit
:
8818 return "DW_OP_GNU_uninit";
8819 /* HP extensions. */
8820 case DW_OP_HP_is_value
:
8821 return "DW_OP_HP_is_value";
8822 case DW_OP_HP_fltconst4
:
8823 return "DW_OP_HP_fltconst4";
8824 case DW_OP_HP_fltconst8
:
8825 return "DW_OP_HP_fltconst8";
8826 case DW_OP_HP_mod_range
:
8827 return "DW_OP_HP_mod_range";
8828 case DW_OP_HP_unmod_range
:
8829 return "DW_OP_HP_unmod_range";
8831 return "DW_OP_HP_tls";
8833 return "OP_<unknown>";
8838 dwarf_bool_name (unsigned mybool
)
8846 /* Convert a DWARF type code into its string name. */
8849 dwarf_type_encoding_name (unsigned enc
)
8854 return "DW_ATE_void";
8855 case DW_ATE_address
:
8856 return "DW_ATE_address";
8857 case DW_ATE_boolean
:
8858 return "DW_ATE_boolean";
8859 case DW_ATE_complex_float
:
8860 return "DW_ATE_complex_float";
8862 return "DW_ATE_float";
8864 return "DW_ATE_signed";
8865 case DW_ATE_signed_char
:
8866 return "DW_ATE_signed_char";
8867 case DW_ATE_unsigned
:
8868 return "DW_ATE_unsigned";
8869 case DW_ATE_unsigned_char
:
8870 return "DW_ATE_unsigned_char";
8872 case DW_ATE_imaginary_float
:
8873 return "DW_ATE_imaginary_float";
8874 case DW_ATE_packed_decimal
:
8875 return "DW_ATE_packed_decimal";
8876 case DW_ATE_numeric_string
:
8877 return "DW_ATE_numeric_string";
8879 return "DW_ATE_edited";
8880 case DW_ATE_signed_fixed
:
8881 return "DW_ATE_signed_fixed";
8882 case DW_ATE_unsigned_fixed
:
8883 return "DW_ATE_unsigned_fixed";
8884 case DW_ATE_decimal_float
:
8885 return "DW_ATE_decimal_float";
8886 /* HP extensions. */
8887 case DW_ATE_HP_float80
:
8888 return "DW_ATE_HP_float80";
8889 case DW_ATE_HP_complex_float80
:
8890 return "DW_ATE_HP_complex_float80";
8891 case DW_ATE_HP_float128
:
8892 return "DW_ATE_HP_float128";
8893 case DW_ATE_HP_complex_float128
:
8894 return "DW_ATE_HP_complex_float128";
8895 case DW_ATE_HP_floathpintel
:
8896 return "DW_ATE_HP_floathpintel";
8897 case DW_ATE_HP_imaginary_float80
:
8898 return "DW_ATE_HP_imaginary_float80";
8899 case DW_ATE_HP_imaginary_float128
:
8900 return "DW_ATE_HP_imaginary_float128";
8902 return "DW_ATE_<unknown>";
8906 /* Convert a DWARF call frame info operation to its string name. */
8910 dwarf_cfi_name (unsigned cfi_opc
)
8914 case DW_CFA_advance_loc
:
8915 return "DW_CFA_advance_loc";
8917 return "DW_CFA_offset";
8918 case DW_CFA_restore
:
8919 return "DW_CFA_restore";
8921 return "DW_CFA_nop";
8922 case DW_CFA_set_loc
:
8923 return "DW_CFA_set_loc";
8924 case DW_CFA_advance_loc1
:
8925 return "DW_CFA_advance_loc1";
8926 case DW_CFA_advance_loc2
:
8927 return "DW_CFA_advance_loc2";
8928 case DW_CFA_advance_loc4
:
8929 return "DW_CFA_advance_loc4";
8930 case DW_CFA_offset_extended
:
8931 return "DW_CFA_offset_extended";
8932 case DW_CFA_restore_extended
:
8933 return "DW_CFA_restore_extended";
8934 case DW_CFA_undefined
:
8935 return "DW_CFA_undefined";
8936 case DW_CFA_same_value
:
8937 return "DW_CFA_same_value";
8938 case DW_CFA_register
:
8939 return "DW_CFA_register";
8940 case DW_CFA_remember_state
:
8941 return "DW_CFA_remember_state";
8942 case DW_CFA_restore_state
:
8943 return "DW_CFA_restore_state";
8944 case DW_CFA_def_cfa
:
8945 return "DW_CFA_def_cfa";
8946 case DW_CFA_def_cfa_register
:
8947 return "DW_CFA_def_cfa_register";
8948 case DW_CFA_def_cfa_offset
:
8949 return "DW_CFA_def_cfa_offset";
8951 case DW_CFA_def_cfa_expression
:
8952 return "DW_CFA_def_cfa_expression";
8953 case DW_CFA_expression
:
8954 return "DW_CFA_expression";
8955 case DW_CFA_offset_extended_sf
:
8956 return "DW_CFA_offset_extended_sf";
8957 case DW_CFA_def_cfa_sf
:
8958 return "DW_CFA_def_cfa_sf";
8959 case DW_CFA_def_cfa_offset_sf
:
8960 return "DW_CFA_def_cfa_offset_sf";
8961 case DW_CFA_val_offset
:
8962 return "DW_CFA_val_offset";
8963 case DW_CFA_val_offset_sf
:
8964 return "DW_CFA_val_offset_sf";
8965 case DW_CFA_val_expression
:
8966 return "DW_CFA_val_expression";
8967 /* SGI/MIPS specific. */
8968 case DW_CFA_MIPS_advance_loc8
:
8969 return "DW_CFA_MIPS_advance_loc8";
8970 /* GNU extensions. */
8971 case DW_CFA_GNU_window_save
:
8972 return "DW_CFA_GNU_window_save";
8973 case DW_CFA_GNU_args_size
:
8974 return "DW_CFA_GNU_args_size";
8975 case DW_CFA_GNU_negative_offset_extended
:
8976 return "DW_CFA_GNU_negative_offset_extended";
8978 return "DW_CFA_<unknown>";
8984 dump_die (struct die_info
*die
)
8988 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
8989 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
8990 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
8991 dwarf_bool_name (die
->child
!= NULL
));
8993 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
8994 for (i
= 0; i
< die
->num_attrs
; ++i
)
8996 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
8997 dwarf_attr_name (die
->attrs
[i
].name
),
8998 dwarf_form_name (die
->attrs
[i
].form
));
8999 switch (die
->attrs
[i
].form
)
9001 case DW_FORM_ref_addr
:
9003 fprintf_unfiltered (gdb_stderr
, "address: ");
9004 fputs_filtered (paddress (DW_ADDR (&die
->attrs
[i
])), gdb_stderr
);
9006 case DW_FORM_block2
:
9007 case DW_FORM_block4
:
9009 case DW_FORM_block1
:
9010 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
9015 fprintf_unfiltered (gdb_stderr
, "constant ref: %ld (adjusted)",
9016 (long) (DW_ADDR (&die
->attrs
[i
])));
9024 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
9026 case DW_FORM_string
:
9028 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
9029 DW_STRING (&die
->attrs
[i
])
9030 ? DW_STRING (&die
->attrs
[i
]) : "");
9033 if (DW_UNSND (&die
->attrs
[i
]))
9034 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
9036 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
9038 case DW_FORM_indirect
:
9039 /* the reader will have reduced the indirect form to
9040 the "base form" so this form should not occur */
9041 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
9044 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
9045 die
->attrs
[i
].form
);
9047 fprintf_unfiltered (gdb_stderr
, "\n");
9052 dump_die_list (struct die_info
*die
)
9057 if (die
->child
!= NULL
)
9058 dump_die_list (die
->child
);
9059 if (die
->sibling
!= NULL
)
9060 dump_die_list (die
->sibling
);
9065 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
9069 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
9075 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
9077 unsigned int result
= 0;
9081 case DW_FORM_ref_addr
:
9086 case DW_FORM_ref_udata
:
9087 result
= DW_ADDR (attr
);
9090 complaint (&symfile_complaints
,
9091 _("unsupported die ref attribute form: '%s'"),
9092 dwarf_form_name (attr
->form
));
9097 /* Return the constant value held by the given attribute. Return -1
9098 if the value held by the attribute is not constant. */
9101 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
9103 if (attr
->form
== DW_FORM_sdata
)
9104 return DW_SND (attr
);
9105 else if (attr
->form
== DW_FORM_udata
9106 || attr
->form
== DW_FORM_data1
9107 || attr
->form
== DW_FORM_data2
9108 || attr
->form
== DW_FORM_data4
9109 || attr
->form
== DW_FORM_data8
)
9110 return DW_UNSND (attr
);
9113 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
9114 dwarf_form_name (attr
->form
));
9115 return default_value
;
9119 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
9120 unit and add it to our queue. */
9123 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
9124 struct dwarf2_per_cu_data
*per_cu
)
9126 /* Mark the dependence relation so that we don't flush PER_CU
9128 dwarf2_add_dependence (this_cu
, per_cu
);
9130 /* If it's already on the queue, we have nothing to do. */
9134 /* If the compilation unit is already loaded, just mark it as
9136 if (per_cu
->cu
!= NULL
)
9138 per_cu
->cu
->last_used
= 0;
9142 /* Add it to the queue. */
9143 queue_comp_unit (per_cu
, this_cu
->objfile
);
9146 static struct die_info
*
9147 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
9148 struct dwarf2_cu
**ref_cu
)
9150 struct die_info
*die
;
9151 unsigned int offset
;
9152 struct die_info temp_die
;
9153 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
9155 offset
= dwarf2_get_ref_die_offset (attr
, cu
);
9157 if (DW_ADDR (attr
) < cu
->header
.offset
9158 || DW_ADDR (attr
) >= cu
->header
.offset
+ cu
->header
.length
)
9160 struct dwarf2_per_cu_data
*per_cu
;
9161 per_cu
= dwarf2_find_containing_comp_unit (DW_ADDR (attr
),
9164 /* If necessary, add it to the queue and load its DIEs. */
9165 maybe_queue_comp_unit (cu
, per_cu
);
9167 target_cu
= per_cu
->cu
;
9172 *ref_cu
= target_cu
;
9173 temp_die
.offset
= offset
;
9174 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
9178 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
9179 "at 0x%lx [in module %s]"),
9180 (long) offset
, (long) src_die
->offset
, cu
->objfile
->name
);
9183 /* Decode simple location descriptions.
9184 Given a pointer to a dwarf block that defines a location, compute
9185 the location and return the value.
9187 NOTE drow/2003-11-18: This function is called in two situations
9188 now: for the address of static or global variables (partial symbols
9189 only) and for offsets into structures which are expected to be
9190 (more or less) constant. The partial symbol case should go away,
9191 and only the constant case should remain. That will let this
9192 function complain more accurately. A few special modes are allowed
9193 without complaint for global variables (for instance, global
9194 register values and thread-local values).
9196 A location description containing no operations indicates that the
9197 object is optimized out. The return value is 0 for that case.
9198 FIXME drow/2003-11-16: No callers check for this case any more; soon all
9199 callers will only want a very basic result and this can become a
9202 Note that stack[0] is unused except as a default error return.
9203 Note that stack overflow is not yet handled. */
9206 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
9208 struct objfile
*objfile
= cu
->objfile
;
9209 struct comp_unit_head
*cu_header
= &cu
->header
;
9211 int size
= blk
->size
;
9212 gdb_byte
*data
= blk
->data
;
9213 CORE_ADDR stack
[64];
9215 unsigned int bytes_read
, unsnd
;
9259 stack
[++stacki
] = op
- DW_OP_lit0
;
9294 stack
[++stacki
] = op
- DW_OP_reg0
;
9296 dwarf2_complex_location_expr_complaint ();
9300 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9302 stack
[++stacki
] = unsnd
;
9304 dwarf2_complex_location_expr_complaint ();
9308 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
9314 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
9319 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
9324 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
9329 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
9334 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
9339 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
9344 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
9350 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
9355 stack
[stacki
+ 1] = stack
[stacki
];
9360 stack
[stacki
- 1] += stack
[stacki
];
9364 case DW_OP_plus_uconst
:
9365 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9370 stack
[stacki
- 1] -= stack
[stacki
];
9375 /* If we're not the last op, then we definitely can't encode
9376 this using GDB's address_class enum. This is valid for partial
9377 global symbols, although the variable's address will be bogus
9380 dwarf2_complex_location_expr_complaint ();
9383 case DW_OP_GNU_push_tls_address
:
9384 /* The top of the stack has the offset from the beginning
9385 of the thread control block at which the variable is located. */
9386 /* Nothing should follow this operator, so the top of stack would
9388 /* This is valid for partial global symbols, but the variable's
9389 address will be bogus in the psymtab. */
9391 dwarf2_complex_location_expr_complaint ();
9394 case DW_OP_GNU_uninit
:
9398 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
9399 dwarf_stack_op_name (op
));
9400 return (stack
[stacki
]);
9403 return (stack
[stacki
]);
9406 /* memory allocation interface */
9408 static struct dwarf_block
*
9409 dwarf_alloc_block (struct dwarf2_cu
*cu
)
9411 struct dwarf_block
*blk
;
9413 blk
= (struct dwarf_block
*)
9414 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
9418 static struct abbrev_info
*
9419 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
9421 struct abbrev_info
*abbrev
;
9423 abbrev
= (struct abbrev_info
*)
9424 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
9425 memset (abbrev
, 0, sizeof (struct abbrev_info
));
9429 static struct die_info
*
9430 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
9432 struct die_info
*die
;
9433 size_t size
= sizeof (struct die_info
);
9436 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
9438 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
9439 memset (die
, 0, sizeof (struct die_info
));
9444 /* Macro support. */
9447 /* Return the full name of file number I in *LH's file name table.
9448 Use COMP_DIR as the name of the current directory of the
9449 compilation. The result is allocated using xmalloc; the caller is
9450 responsible for freeing it. */
9452 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
9454 /* Is the file number a valid index into the line header's file name
9455 table? Remember that file numbers start with one, not zero. */
9456 if (1 <= file
&& file
<= lh
->num_file_names
)
9458 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9460 if (IS_ABSOLUTE_PATH (fe
->name
))
9461 return xstrdup (fe
->name
);
9469 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9475 dir_len
= strlen (dir
);
9476 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
9477 strcpy (full_name
, dir
);
9478 full_name
[dir_len
] = '/';
9479 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
9483 return xstrdup (fe
->name
);
9488 /* The compiler produced a bogus file number. We can at least
9489 record the macro definitions made in the file, even if we
9490 won't be able to find the file by name. */
9492 sprintf (fake_name
, "<bad macro file number %d>", file
);
9494 complaint (&symfile_complaints
,
9495 _("bad file number in macro information (%d)"),
9498 return xstrdup (fake_name
);
9503 static struct macro_source_file
*
9504 macro_start_file (int file
, int line
,
9505 struct macro_source_file
*current_file
,
9506 const char *comp_dir
,
9507 struct line_header
*lh
, struct objfile
*objfile
)
9509 /* The full name of this source file. */
9510 char *full_name
= file_full_name (file
, lh
, comp_dir
);
9512 /* We don't create a macro table for this compilation unit
9513 at all until we actually get a filename. */
9514 if (! pending_macros
)
9515 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
9516 objfile
->macro_cache
);
9519 /* If we have no current file, then this must be the start_file
9520 directive for the compilation unit's main source file. */
9521 current_file
= macro_set_main (pending_macros
, full_name
);
9523 current_file
= macro_include (current_file
, line
, full_name
);
9527 return current_file
;
9531 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
9532 followed by a null byte. */
9534 copy_string (const char *buf
, int len
)
9536 char *s
= xmalloc (len
+ 1);
9537 memcpy (s
, buf
, len
);
9545 consume_improper_spaces (const char *p
, const char *body
)
9549 complaint (&symfile_complaints
,
9550 _("macro definition contains spaces in formal argument list:\n`%s'"),
9562 parse_macro_definition (struct macro_source_file
*file
, int line
,
9567 /* The body string takes one of two forms. For object-like macro
9568 definitions, it should be:
9570 <macro name> " " <definition>
9572 For function-like macro definitions, it should be:
9574 <macro name> "() " <definition>
9576 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
9578 Spaces may appear only where explicitly indicated, and in the
9581 The Dwarf 2 spec says that an object-like macro's name is always
9582 followed by a space, but versions of GCC around March 2002 omit
9583 the space when the macro's definition is the empty string.
9585 The Dwarf 2 spec says that there should be no spaces between the
9586 formal arguments in a function-like macro's formal argument list,
9587 but versions of GCC around March 2002 include spaces after the
9591 /* Find the extent of the macro name. The macro name is terminated
9592 by either a space or null character (for an object-like macro) or
9593 an opening paren (for a function-like macro). */
9594 for (p
= body
; *p
; p
++)
9595 if (*p
== ' ' || *p
== '(')
9598 if (*p
== ' ' || *p
== '\0')
9600 /* It's an object-like macro. */
9601 int name_len
= p
- body
;
9602 char *name
= copy_string (body
, name_len
);
9603 const char *replacement
;
9606 replacement
= body
+ name_len
+ 1;
9609 dwarf2_macro_malformed_definition_complaint (body
);
9610 replacement
= body
+ name_len
;
9613 macro_define_object (file
, line
, name
, replacement
);
9619 /* It's a function-like macro. */
9620 char *name
= copy_string (body
, p
- body
);
9623 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
9627 p
= consume_improper_spaces (p
, body
);
9629 /* Parse the formal argument list. */
9630 while (*p
&& *p
!= ')')
9632 /* Find the extent of the current argument name. */
9633 const char *arg_start
= p
;
9635 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
9638 if (! *p
|| p
== arg_start
)
9639 dwarf2_macro_malformed_definition_complaint (body
);
9642 /* Make sure argv has room for the new argument. */
9643 if (argc
>= argv_size
)
9646 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
9649 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
9652 p
= consume_improper_spaces (p
, body
);
9654 /* Consume the comma, if present. */
9659 p
= consume_improper_spaces (p
, body
);
9668 /* Perfectly formed definition, no complaints. */
9669 macro_define_function (file
, line
, name
,
9670 argc
, (const char **) argv
,
9672 else if (*p
== '\0')
9674 /* Complain, but do define it. */
9675 dwarf2_macro_malformed_definition_complaint (body
);
9676 macro_define_function (file
, line
, name
,
9677 argc
, (const char **) argv
,
9681 /* Just complain. */
9682 dwarf2_macro_malformed_definition_complaint (body
);
9685 /* Just complain. */
9686 dwarf2_macro_malformed_definition_complaint (body
);
9692 for (i
= 0; i
< argc
; i
++)
9698 dwarf2_macro_malformed_definition_complaint (body
);
9703 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
9704 char *comp_dir
, bfd
*abfd
,
9705 struct dwarf2_cu
*cu
)
9707 gdb_byte
*mac_ptr
, *mac_end
;
9708 struct macro_source_file
*current_file
= 0;
9710 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
9712 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
9716 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
9717 mac_end
= dwarf2_per_objfile
->macinfo_buffer
9718 + dwarf2_per_objfile
->macinfo_size
;
9722 enum dwarf_macinfo_record_type macinfo_type
;
9724 /* Do we at least have room for a macinfo type byte? */
9725 if (mac_ptr
>= mac_end
)
9727 dwarf2_macros_too_long_complaint ();
9731 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
9734 switch (macinfo_type
)
9736 /* A zero macinfo type indicates the end of the macro
9741 case DW_MACINFO_define
:
9742 case DW_MACINFO_undef
:
9744 unsigned int bytes_read
;
9748 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9749 mac_ptr
+= bytes_read
;
9750 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
9751 mac_ptr
+= bytes_read
;
9754 complaint (&symfile_complaints
,
9755 _("debug info gives macro %s outside of any file: %s"),
9757 DW_MACINFO_define
? "definition" : macinfo_type
==
9758 DW_MACINFO_undef
? "undefinition" :
9759 "something-or-other", body
);
9762 if (macinfo_type
== DW_MACINFO_define
)
9763 parse_macro_definition (current_file
, line
, body
);
9764 else if (macinfo_type
== DW_MACINFO_undef
)
9765 macro_undef (current_file
, line
, body
);
9770 case DW_MACINFO_start_file
:
9772 unsigned int bytes_read
;
9775 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9776 mac_ptr
+= bytes_read
;
9777 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9778 mac_ptr
+= bytes_read
;
9780 current_file
= macro_start_file (file
, line
,
9781 current_file
, comp_dir
,
9786 case DW_MACINFO_end_file
:
9788 complaint (&symfile_complaints
,
9789 _("macro debug info has an unmatched `close_file' directive"));
9792 current_file
= current_file
->included_by
;
9795 enum dwarf_macinfo_record_type next_type
;
9797 /* GCC circa March 2002 doesn't produce the zero
9798 type byte marking the end of the compilation
9799 unit. Complain if it's not there, but exit no
9802 /* Do we at least have room for a macinfo type byte? */
9803 if (mac_ptr
>= mac_end
)
9805 dwarf2_macros_too_long_complaint ();
9809 /* We don't increment mac_ptr here, so this is just
9811 next_type
= read_1_byte (abfd
, mac_ptr
);
9813 complaint (&symfile_complaints
,
9814 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
9821 case DW_MACINFO_vendor_ext
:
9823 unsigned int bytes_read
;
9827 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9828 mac_ptr
+= bytes_read
;
9829 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
9830 mac_ptr
+= bytes_read
;
9832 /* We don't recognize any vendor extensions. */
9839 /* Check if the attribute's form is a DW_FORM_block*
9840 if so return true else false. */
9842 attr_form_is_block (struct attribute
*attr
)
9844 return (attr
== NULL
? 0 :
9845 attr
->form
== DW_FORM_block1
9846 || attr
->form
== DW_FORM_block2
9847 || attr
->form
== DW_FORM_block4
9848 || attr
->form
== DW_FORM_block
);
9851 /* Return non-zero if ATTR's value is a section offset --- classes
9852 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
9853 You may use DW_UNSND (attr) to retrieve such offsets.
9855 Section 7.5.4, "Attribute Encodings", explains that no attribute
9856 may have a value that belongs to more than one of these classes; it
9857 would be ambiguous if we did, because we use the same forms for all
9860 attr_form_is_section_offset (struct attribute
*attr
)
9862 return (attr
->form
== DW_FORM_data4
9863 || attr
->form
== DW_FORM_data8
);
9867 /* Return non-zero if ATTR's value falls in the 'constant' class, or
9868 zero otherwise. When this function returns true, you can apply
9869 dwarf2_get_attr_constant_value to it.
9871 However, note that for some attributes you must check
9872 attr_form_is_section_offset before using this test. DW_FORM_data4
9873 and DW_FORM_data8 are members of both the constant class, and of
9874 the classes that contain offsets into other debug sections
9875 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
9876 that, if an attribute's can be either a constant or one of the
9877 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
9878 taken as section offsets, not constants. */
9880 attr_form_is_constant (struct attribute
*attr
)
9897 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
9898 struct dwarf2_cu
*cu
)
9900 if (attr_form_is_section_offset (attr
)
9901 /* ".debug_loc" may not exist at all, or the offset may be outside
9902 the section. If so, fall through to the complaint in the
9904 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc_size
)
9906 struct dwarf2_loclist_baton
*baton
;
9908 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9909 sizeof (struct dwarf2_loclist_baton
));
9910 baton
->per_cu
= cu
->per_cu
;
9911 gdb_assert (baton
->per_cu
);
9913 /* We don't know how long the location list is, but make sure we
9914 don't run off the edge of the section. */
9915 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
9916 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
9917 baton
->base_address
= cu
->header
.base_address
;
9918 if (cu
->header
.base_known
== 0)
9919 complaint (&symfile_complaints
,
9920 _("Location list used without specifying the CU base address."));
9922 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
9923 SYMBOL_LOCATION_BATON (sym
) = baton
;
9927 struct dwarf2_locexpr_baton
*baton
;
9929 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9930 sizeof (struct dwarf2_locexpr_baton
));
9931 baton
->per_cu
= cu
->per_cu
;
9932 gdb_assert (baton
->per_cu
);
9934 if (attr_form_is_block (attr
))
9936 /* Note that we're just copying the block's data pointer
9937 here, not the actual data. We're still pointing into the
9938 info_buffer for SYM's objfile; right now we never release
9939 that buffer, but when we do clean up properly this may
9941 baton
->size
= DW_BLOCK (attr
)->size
;
9942 baton
->data
= DW_BLOCK (attr
)->data
;
9946 dwarf2_invalid_attrib_class_complaint ("location description",
9947 SYMBOL_NATURAL_NAME (sym
));
9952 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
9953 SYMBOL_LOCATION_BATON (sym
) = baton
;
9957 /* Return the OBJFILE associated with the compilation unit CU. */
9960 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
9962 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
9964 /* Return the master objfile, so that we can report and look up the
9965 correct file containing this variable. */
9966 if (objfile
->separate_debug_objfile_backlink
)
9967 objfile
= objfile
->separate_debug_objfile_backlink
;
9972 /* Return the address size given in the compilation unit header for CU. */
9975 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
9978 return per_cu
->cu
->header
.addr_size
;
9981 /* If the CU is not currently read in, we re-read its header. */
9982 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
9983 struct dwarf2_per_objfile
*per_objfile
9984 = objfile_data (objfile
, dwarf2_objfile_data_key
);
9985 gdb_byte
*info_ptr
= per_objfile
->info_buffer
+ per_cu
->offset
;
9987 struct comp_unit_head cu_header
;
9988 memset (&cu_header
, 0, sizeof cu_header
);
9989 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
9990 return cu_header
.addr_size
;
9994 /* Locate the compilation unit from CU's objfile which contains the
9995 DIE at OFFSET. Raises an error on failure. */
9997 static struct dwarf2_per_cu_data
*
9998 dwarf2_find_containing_comp_unit (unsigned long offset
,
9999 struct objfile
*objfile
)
10001 struct dwarf2_per_cu_data
*this_cu
;
10005 high
= dwarf2_per_objfile
->n_comp_units
- 1;
10008 int mid
= low
+ (high
- low
) / 2;
10009 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
10014 gdb_assert (low
== high
);
10015 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
10018 error (_("Dwarf Error: could not find partial DIE containing "
10019 "offset 0x%lx [in module %s]"),
10020 (long) offset
, bfd_get_filename (objfile
->obfd
));
10022 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
10023 return dwarf2_per_objfile
->all_comp_units
[low
-1];
10027 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
10028 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
10029 && offset
>= this_cu
->offset
+ this_cu
->length
)
10030 error (_("invalid dwarf2 offset %ld"), offset
);
10031 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
10036 /* Locate the compilation unit from OBJFILE which is located at exactly
10037 OFFSET. Raises an error on failure. */
10039 static struct dwarf2_per_cu_data
*
10040 dwarf2_find_comp_unit (unsigned long offset
, struct objfile
*objfile
)
10042 struct dwarf2_per_cu_data
*this_cu
;
10043 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10044 if (this_cu
->offset
!= offset
)
10045 error (_("no compilation unit with offset %ld."), offset
);
10049 /* Release one cached compilation unit, CU. We unlink it from the tree
10050 of compilation units, but we don't remove it from the read_in_chain;
10051 the caller is responsible for that. */
10054 free_one_comp_unit (void *data
)
10056 struct dwarf2_cu
*cu
= data
;
10058 if (cu
->per_cu
!= NULL
)
10059 cu
->per_cu
->cu
= NULL
;
10062 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10067 /* This cleanup function is passed the address of a dwarf2_cu on the stack
10068 when we're finished with it. We can't free the pointer itself, but be
10069 sure to unlink it from the cache. Also release any associated storage
10070 and perform cache maintenance.
10072 Only used during partial symbol parsing. */
10075 free_stack_comp_unit (void *data
)
10077 struct dwarf2_cu
*cu
= data
;
10079 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10080 cu
->partial_dies
= NULL
;
10082 if (cu
->per_cu
!= NULL
)
10084 /* This compilation unit is on the stack in our caller, so we
10085 should not xfree it. Just unlink it. */
10086 cu
->per_cu
->cu
= NULL
;
10089 /* If we had a per-cu pointer, then we may have other compilation
10090 units loaded, so age them now. */
10091 age_cached_comp_units ();
10095 /* Free all cached compilation units. */
10098 free_cached_comp_units (void *data
)
10100 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10102 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10103 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10104 while (per_cu
!= NULL
)
10106 struct dwarf2_per_cu_data
*next_cu
;
10108 next_cu
= per_cu
->cu
->read_in_chain
;
10110 free_one_comp_unit (per_cu
->cu
);
10111 *last_chain
= next_cu
;
10117 /* Increase the age counter on each cached compilation unit, and free
10118 any that are too old. */
10121 age_cached_comp_units (void)
10123 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10125 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
10126 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10127 while (per_cu
!= NULL
)
10129 per_cu
->cu
->last_used
++;
10130 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
10131 dwarf2_mark (per_cu
->cu
);
10132 per_cu
= per_cu
->cu
->read_in_chain
;
10135 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10136 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10137 while (per_cu
!= NULL
)
10139 struct dwarf2_per_cu_data
*next_cu
;
10141 next_cu
= per_cu
->cu
->read_in_chain
;
10143 if (!per_cu
->cu
->mark
)
10145 free_one_comp_unit (per_cu
->cu
);
10146 *last_chain
= next_cu
;
10149 last_chain
= &per_cu
->cu
->read_in_chain
;
10155 /* Remove a single compilation unit from the cache. */
10158 free_one_cached_comp_unit (void *target_cu
)
10160 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10162 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10163 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10164 while (per_cu
!= NULL
)
10166 struct dwarf2_per_cu_data
*next_cu
;
10168 next_cu
= per_cu
->cu
->read_in_chain
;
10170 if (per_cu
->cu
== target_cu
)
10172 free_one_comp_unit (per_cu
->cu
);
10173 *last_chain
= next_cu
;
10177 last_chain
= &per_cu
->cu
->read_in_chain
;
10183 /* Release all extra memory associated with OBJFILE. */
10186 dwarf2_free_objfile (struct objfile
*objfile
)
10188 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
10190 if (dwarf2_per_objfile
== NULL
)
10193 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
10194 free_cached_comp_units (NULL
);
10196 /* Everything else should be on the objfile obstack. */
10199 /* A pair of DIE offset and GDB type pointer. We store these
10200 in a hash table separate from the DIEs, and preserve them
10201 when the DIEs are flushed out of cache. */
10203 struct dwarf2_offset_and_type
10205 unsigned int offset
;
10209 /* Hash function for a dwarf2_offset_and_type. */
10212 offset_and_type_hash (const void *item
)
10214 const struct dwarf2_offset_and_type
*ofs
= item
;
10215 return ofs
->offset
;
10218 /* Equality function for a dwarf2_offset_and_type. */
10221 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
10223 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
10224 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
10225 return ofs_lhs
->offset
== ofs_rhs
->offset
;
10228 /* Set the type associated with DIE to TYPE. Save it in CU's hash
10229 table if necessary. For convenience, return TYPE. */
10231 static struct type
*
10232 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10234 struct dwarf2_offset_and_type
**slot
, ofs
;
10236 if (cu
->type_hash
== NULL
)
10238 gdb_assert (cu
->per_cu
!= NULL
);
10239 cu
->per_cu
->type_hash
10240 = htab_create_alloc_ex (cu
->header
.length
/ 24,
10241 offset_and_type_hash
,
10242 offset_and_type_eq
,
10244 &cu
->objfile
->objfile_obstack
,
10245 hashtab_obstack_allocate
,
10246 dummy_obstack_deallocate
);
10247 cu
->type_hash
= cu
->per_cu
->type_hash
;
10250 ofs
.offset
= die
->offset
;
10252 slot
= (struct dwarf2_offset_and_type
**)
10253 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
10254 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
10259 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
10260 not have a saved type. */
10262 static struct type
*
10263 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10265 struct dwarf2_offset_and_type
*slot
, ofs
;
10266 htab_t type_hash
= cu
->type_hash
;
10268 if (type_hash
== NULL
)
10271 ofs
.offset
= die
->offset
;
10272 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
10279 /* Set the mark field in CU and in every other compilation unit in the
10280 cache that we must keep because we are keeping CU. */
10282 /* Add a dependence relationship from CU to REF_PER_CU. */
10285 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
10286 struct dwarf2_per_cu_data
*ref_per_cu
)
10290 if (cu
->dependencies
== NULL
)
10292 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
10293 NULL
, &cu
->comp_unit_obstack
,
10294 hashtab_obstack_allocate
,
10295 dummy_obstack_deallocate
);
10297 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
10299 *slot
= ref_per_cu
;
10302 /* Set the mark field in CU and in every other compilation unit in the
10303 cache that we must keep because we are keeping CU. */
10306 dwarf2_mark_helper (void **slot
, void *data
)
10308 struct dwarf2_per_cu_data
*per_cu
;
10310 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
10311 if (per_cu
->cu
->mark
)
10313 per_cu
->cu
->mark
= 1;
10315 if (per_cu
->cu
->dependencies
!= NULL
)
10316 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10322 dwarf2_mark (struct dwarf2_cu
*cu
)
10327 if (cu
->dependencies
!= NULL
)
10328 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10332 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
10336 per_cu
->cu
->mark
= 0;
10337 per_cu
= per_cu
->cu
->read_in_chain
;
10341 /* Trivial hash function for partial_die_info: the hash value of a DIE
10342 is its offset in .debug_info for this objfile. */
10345 partial_die_hash (const void *item
)
10347 const struct partial_die_info
*part_die
= item
;
10348 return part_die
->offset
;
10351 /* Trivial comparison function for partial_die_info structures: two DIEs
10352 are equal if they have the same offset. */
10355 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
10357 const struct partial_die_info
*part_die_lhs
= item_lhs
;
10358 const struct partial_die_info
*part_die_rhs
= item_rhs
;
10359 return part_die_lhs
->offset
== part_die_rhs
->offset
;
10362 static struct cmd_list_element
*set_dwarf2_cmdlist
;
10363 static struct cmd_list_element
*show_dwarf2_cmdlist
;
10366 set_dwarf2_cmd (char *args
, int from_tty
)
10368 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
10372 show_dwarf2_cmd (char *args
, int from_tty
)
10374 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
10377 void _initialize_dwarf2_read (void);
10380 _initialize_dwarf2_read (void)
10382 dwarf2_objfile_data_key
= register_objfile_data ();
10384 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
10385 Set DWARF 2 specific variables.\n\
10386 Configure DWARF 2 variables such as the cache size"),
10387 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
10388 0/*allow-unknown*/, &maintenance_set_cmdlist
);
10390 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
10391 Show DWARF 2 specific variables\n\
10392 Show DWARF 2 variables such as the cache size"),
10393 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
10394 0/*allow-unknown*/, &maintenance_show_cmdlist
);
10396 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
10397 &dwarf2_max_cache_age
, _("\
10398 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
10399 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
10400 A higher limit means that cached compilation units will be stored\n\
10401 in memory longer, and more total memory will be used. Zero disables\n\
10402 caching, which can slow down startup."),
10404 show_dwarf2_max_cache_age
,
10405 &set_dwarf2_cmdlist
,
10406 &show_dwarf2_cmdlist
);