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
= obsavestring (comp_unit_die
.dirname
,
1533 strlen (comp_unit_die
.dirname
),
1534 &objfile
->objfile_obstack
);
1536 pst
->read_symtab_private
= (char *) this_cu
;
1538 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1540 /* Store the function that reads in the rest of the symbol table */
1541 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1543 /* If this compilation unit was already read in, free the
1544 cached copy in order to read it in again. This is
1545 necessary because we skipped some symbols when we first
1546 read in the compilation unit (see load_partial_dies).
1547 This problem could be avoided, but the benefit is
1549 if (this_cu
->cu
!= NULL
)
1550 free_one_cached_comp_unit (this_cu
->cu
);
1552 cu
.per_cu
= this_cu
;
1554 /* Note that this is a pointer to our stack frame, being
1555 added to a global data structure. It will be cleaned up
1556 in free_stack_comp_unit when we finish with this
1557 compilation unit. */
1560 this_cu
->psymtab
= pst
;
1562 /* Possibly set the default values of LOWPC and HIGHPC from
1564 if (cu
.has_ranges_offset
)
1566 if (dwarf2_ranges_read (cu
.ranges_offset
, &comp_unit_die
.lowpc
,
1567 &comp_unit_die
.highpc
, &cu
, pst
))
1568 comp_unit_die
.has_pc_info
= 1;
1571 /* Check if comp unit has_children.
1572 If so, read the rest of the partial symbols from this comp unit.
1573 If not, there's no more debug_info for this comp unit. */
1574 if (comp_unit_die
.has_children
)
1576 struct partial_die_info
*first_die
;
1578 lowpc
= ((CORE_ADDR
) -1);
1579 highpc
= ((CORE_ADDR
) 0);
1581 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1583 scan_partial_symbols (first_die
, &lowpc
, &highpc
, &cu
);
1585 /* If we didn't find a lowpc, set it to highpc to avoid
1586 complaints from `maint check'. */
1587 if (lowpc
== ((CORE_ADDR
) -1))
1590 /* If the compilation unit didn't have an explicit address range,
1591 then use the information extracted from its child dies. */
1592 if (! comp_unit_die
.has_pc_info
)
1594 comp_unit_die
.lowpc
= lowpc
;
1595 comp_unit_die
.highpc
= highpc
;
1598 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1599 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1601 /* Store the contiguous range; `DW_AT_ranges' range is stored above. The
1602 range can be also empty for CUs with no code. */
1603 if (!cu
.has_ranges_offset
&& pst
->textlow
< pst
->texthigh
)
1604 addrmap_set_empty (objfile
->psymtabs_addrmap
, pst
->textlow
,
1605 pst
->texthigh
- 1, pst
);
1607 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1608 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1609 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1610 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1611 sort_pst_symbols (pst
);
1613 /* If there is already a psymtab or symtab for a file of this
1614 name, remove it. (If there is a symtab, more drastic things
1615 also happen.) This happens in VxWorks. */
1616 free_named_symtabs (pst
->filename
);
1618 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1619 + cu
.header
.initial_length_size
;
1621 if (comp_unit_die
.has_stmt_list
)
1623 /* Get the list of files included in the current compilation unit,
1624 and build a psymtab for each of them. */
1625 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1628 do_cleanups (back_to_inner
);
1631 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
1632 &objfile
->objfile_obstack
);
1634 do_cleanups (back_to
);
1637 /* Load the DIEs for a secondary CU into memory. */
1640 load_comp_unit (struct dwarf2_per_cu_data
*this_cu
, struct objfile
*objfile
)
1642 bfd
*abfd
= objfile
->obfd
;
1643 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
1644 struct partial_die_info comp_unit_die
;
1645 struct dwarf2_cu
*cu
;
1646 struct abbrev_info
*abbrev
;
1647 unsigned int bytes_read
;
1648 struct cleanup
*back_to
;
1650 info_ptr
= dwarf2_per_objfile
->info_buffer
+ this_cu
->offset
;
1651 beg_of_comp_unit
= info_ptr
;
1653 cu
= xmalloc (sizeof (struct dwarf2_cu
));
1654 memset (cu
, 0, sizeof (struct dwarf2_cu
));
1656 obstack_init (&cu
->comp_unit_obstack
);
1658 cu
->objfile
= objfile
;
1659 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
1661 /* Complete the cu_header. */
1662 cu
->header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1663 cu
->header
.first_die_ptr
= info_ptr
;
1664 cu
->header
.cu_head_ptr
= beg_of_comp_unit
;
1666 /* Read the abbrevs for this compilation unit into a table. */
1667 dwarf2_read_abbrevs (abfd
, cu
);
1668 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
1670 /* Read the compilation unit die. */
1671 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1672 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1673 abfd
, info_ptr
, cu
);
1675 /* Set the language we're debugging. */
1676 set_cu_language (comp_unit_die
.language
, cu
);
1678 /* Link this compilation unit into the compilation unit tree. */
1680 cu
->per_cu
= this_cu
;
1681 cu
->type_hash
= cu
->per_cu
->type_hash
;
1683 /* Check if comp unit has_children.
1684 If so, read the rest of the partial symbols from this comp unit.
1685 If not, there's no more debug_info for this comp unit. */
1686 if (comp_unit_die
.has_children
)
1687 load_partial_dies (abfd
, info_ptr
, 0, cu
);
1689 do_cleanups (back_to
);
1692 /* Create a list of all compilation units in OBJFILE. We do this only
1693 if an inter-comp-unit reference is found; presumably if there is one,
1694 there will be many, and one will occur early in the .debug_info section.
1695 So there's no point in building this list incrementally. */
1698 create_all_comp_units (struct objfile
*objfile
)
1702 struct dwarf2_per_cu_data
**all_comp_units
;
1703 gdb_byte
*info_ptr
= dwarf2_per_objfile
->info_buffer
;
1707 all_comp_units
= xmalloc (n_allocated
1708 * sizeof (struct dwarf2_per_cu_data
*));
1710 while (info_ptr
< dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1712 struct comp_unit_head cu_header
;
1713 gdb_byte
*beg_of_comp_unit
;
1714 struct dwarf2_per_cu_data
*this_cu
;
1715 unsigned long offset
;
1716 unsigned int bytes_read
;
1718 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
1720 /* Read just enough information to find out where the next
1721 compilation unit is. */
1722 cu_header
.initial_length_size
= 0;
1723 cu_header
.length
= read_initial_length (objfile
->obfd
, info_ptr
,
1724 &cu_header
, &bytes_read
);
1726 /* Save the compilation unit for later lookup. */
1727 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
1728 sizeof (struct dwarf2_per_cu_data
));
1729 memset (this_cu
, 0, sizeof (*this_cu
));
1730 this_cu
->offset
= offset
;
1731 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
1733 if (n_comp_units
== n_allocated
)
1736 all_comp_units
= xrealloc (all_comp_units
,
1738 * sizeof (struct dwarf2_per_cu_data
*));
1740 all_comp_units
[n_comp_units
++] = this_cu
;
1742 info_ptr
= info_ptr
+ this_cu
->length
;
1745 dwarf2_per_objfile
->all_comp_units
1746 = obstack_alloc (&objfile
->objfile_obstack
,
1747 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1748 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
1749 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1750 xfree (all_comp_units
);
1751 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
1754 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1755 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1759 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1760 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
1762 struct objfile
*objfile
= cu
->objfile
;
1763 bfd
*abfd
= objfile
->obfd
;
1764 struct partial_die_info
*pdi
;
1766 /* Now, march along the PDI's, descending into ones which have
1767 interesting children but skipping the children of the other ones,
1768 until we reach the end of the compilation unit. */
1774 fixup_partial_die (pdi
, cu
);
1776 /* Anonymous namespaces have no name but have interesting
1777 children, so we need to look at them. Ditto for anonymous
1780 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1781 || pdi
->tag
== DW_TAG_enumeration_type
)
1785 case DW_TAG_subprogram
:
1786 if (pdi
->has_pc_info
)
1788 if (pdi
->lowpc
< *lowpc
)
1790 *lowpc
= pdi
->lowpc
;
1792 if (pdi
->highpc
> *highpc
)
1794 *highpc
= pdi
->highpc
;
1796 if (!pdi
->is_declaration
)
1798 add_partial_symbol (pdi
, cu
);
1802 case DW_TAG_variable
:
1803 case DW_TAG_typedef
:
1804 case DW_TAG_union_type
:
1805 if (!pdi
->is_declaration
)
1807 add_partial_symbol (pdi
, cu
);
1810 case DW_TAG_class_type
:
1811 case DW_TAG_interface_type
:
1812 case DW_TAG_structure_type
:
1813 if (!pdi
->is_declaration
)
1815 add_partial_symbol (pdi
, cu
);
1818 case DW_TAG_enumeration_type
:
1819 if (!pdi
->is_declaration
)
1820 add_partial_enumeration (pdi
, cu
);
1822 case DW_TAG_base_type
:
1823 case DW_TAG_subrange_type
:
1824 /* File scope base type definitions are added to the partial
1826 add_partial_symbol (pdi
, cu
);
1828 case DW_TAG_namespace
:
1829 add_partial_namespace (pdi
, lowpc
, highpc
, cu
);
1836 /* If the die has a sibling, skip to the sibling. */
1838 pdi
= pdi
->die_sibling
;
1842 /* Functions used to compute the fully scoped name of a partial DIE.
1844 Normally, this is simple. For C++, the parent DIE's fully scoped
1845 name is concatenated with "::" and the partial DIE's name. For
1846 Java, the same thing occurs except that "." is used instead of "::".
1847 Enumerators are an exception; they use the scope of their parent
1848 enumeration type, i.e. the name of the enumeration type is not
1849 prepended to the enumerator.
1851 There are two complexities. One is DW_AT_specification; in this
1852 case "parent" means the parent of the target of the specification,
1853 instead of the direct parent of the DIE. The other is compilers
1854 which do not emit DW_TAG_namespace; in this case we try to guess
1855 the fully qualified name of structure types from their members'
1856 linkage names. This must be done using the DIE's children rather
1857 than the children of any DW_AT_specification target. We only need
1858 to do this for structures at the top level, i.e. if the target of
1859 any DW_AT_specification (if any; otherwise the DIE itself) does not
1862 /* Compute the scope prefix associated with PDI's parent, in
1863 compilation unit CU. The result will be allocated on CU's
1864 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1865 field. NULL is returned if no prefix is necessary. */
1867 partial_die_parent_scope (struct partial_die_info
*pdi
,
1868 struct dwarf2_cu
*cu
)
1870 char *grandparent_scope
;
1871 struct partial_die_info
*parent
, *real_pdi
;
1873 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1874 then this means the parent of the specification DIE. */
1877 while (real_pdi
->has_specification
)
1878 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
1880 parent
= real_pdi
->die_parent
;
1884 if (parent
->scope_set
)
1885 return parent
->scope
;
1887 fixup_partial_die (parent
, cu
);
1889 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
1891 if (parent
->tag
== DW_TAG_namespace
1892 || parent
->tag
== DW_TAG_structure_type
1893 || parent
->tag
== DW_TAG_class_type
1894 || parent
->tag
== DW_TAG_interface_type
1895 || parent
->tag
== DW_TAG_union_type
)
1897 if (grandparent_scope
== NULL
)
1898 parent
->scope
= parent
->name
;
1900 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
1903 else if (parent
->tag
== DW_TAG_enumeration_type
)
1904 /* Enumerators should not get the name of the enumeration as a prefix. */
1905 parent
->scope
= grandparent_scope
;
1908 /* FIXME drow/2004-04-01: What should we be doing with
1909 function-local names? For partial symbols, we should probably be
1911 complaint (&symfile_complaints
,
1912 _("unhandled containing DIE tag %d for DIE at %d"),
1913 parent
->tag
, pdi
->offset
);
1914 parent
->scope
= grandparent_scope
;
1917 parent
->scope_set
= 1;
1918 return parent
->scope
;
1921 /* Return the fully scoped name associated with PDI, from compilation unit
1922 CU. The result will be allocated with malloc. */
1924 partial_die_full_name (struct partial_die_info
*pdi
,
1925 struct dwarf2_cu
*cu
)
1929 parent_scope
= partial_die_parent_scope (pdi
, cu
);
1930 if (parent_scope
== NULL
)
1933 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
1937 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
1939 struct objfile
*objfile
= cu
->objfile
;
1941 char *actual_name
= NULL
;
1942 const char *my_prefix
;
1943 const struct partial_symbol
*psym
= NULL
;
1945 int built_actual_name
= 0;
1947 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1949 if (pdi_needs_namespace (pdi
->tag
))
1951 actual_name
= partial_die_full_name (pdi
, cu
);
1953 built_actual_name
= 1;
1956 if (actual_name
== NULL
)
1957 actual_name
= pdi
->name
;
1961 case DW_TAG_subprogram
:
1962 if (pdi
->is_external
|| cu
->language
== language_ada
)
1964 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
1965 of the global scope. But in Ada, we want to be able to access
1966 nested procedures globally. So all Ada subprograms are stored
1967 in the global scope. */
1968 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1969 mst_text, objfile); */
1970 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1971 VAR_DOMAIN
, LOC_BLOCK
,
1972 &objfile
->global_psymbols
,
1973 0, pdi
->lowpc
+ baseaddr
,
1974 cu
->language
, objfile
);
1978 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1979 mst_file_text, objfile); */
1980 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1981 VAR_DOMAIN
, LOC_BLOCK
,
1982 &objfile
->static_psymbols
,
1983 0, pdi
->lowpc
+ baseaddr
,
1984 cu
->language
, objfile
);
1987 case DW_TAG_variable
:
1988 if (pdi
->is_external
)
1991 Don't enter into the minimal symbol tables as there is
1992 a minimal symbol table entry from the ELF symbols already.
1993 Enter into partial symbol table if it has a location
1994 descriptor or a type.
1995 If the location descriptor is missing, new_symbol will create
1996 a LOC_UNRESOLVED symbol, the address of the variable will then
1997 be determined from the minimal symbol table whenever the variable
1999 The address for the partial symbol table entry is not
2000 used by GDB, but it comes in handy for debugging partial symbol
2004 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2005 if (pdi
->locdesc
|| pdi
->has_type
)
2006 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2007 VAR_DOMAIN
, LOC_STATIC
,
2008 &objfile
->global_psymbols
,
2010 cu
->language
, objfile
);
2014 /* Static Variable. Skip symbols without location descriptors. */
2015 if (pdi
->locdesc
== NULL
)
2017 if (built_actual_name
)
2018 xfree (actual_name
);
2021 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2022 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2023 mst_file_data, objfile); */
2024 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2025 VAR_DOMAIN
, LOC_STATIC
,
2026 &objfile
->static_psymbols
,
2028 cu
->language
, objfile
);
2031 case DW_TAG_typedef
:
2032 case DW_TAG_base_type
:
2033 case DW_TAG_subrange_type
:
2034 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2035 VAR_DOMAIN
, LOC_TYPEDEF
,
2036 &objfile
->static_psymbols
,
2037 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2039 case DW_TAG_namespace
:
2040 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2041 VAR_DOMAIN
, LOC_TYPEDEF
,
2042 &objfile
->global_psymbols
,
2043 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2045 case DW_TAG_class_type
:
2046 case DW_TAG_interface_type
:
2047 case DW_TAG_structure_type
:
2048 case DW_TAG_union_type
:
2049 case DW_TAG_enumeration_type
:
2050 /* Skip external references. The DWARF standard says in the section
2051 about "Structure, Union, and Class Type Entries": "An incomplete
2052 structure, union or class type is represented by a structure,
2053 union or class entry that does not have a byte size attribute
2054 and that has a DW_AT_declaration attribute." */
2055 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2057 if (built_actual_name
)
2058 xfree (actual_name
);
2062 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2063 static vs. global. */
2064 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2065 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2066 (cu
->language
== language_cplus
2067 || cu
->language
== language_java
)
2068 ? &objfile
->global_psymbols
2069 : &objfile
->static_psymbols
,
2070 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2073 case DW_TAG_enumerator
:
2074 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2075 VAR_DOMAIN
, LOC_CONST
,
2076 (cu
->language
== language_cplus
2077 || cu
->language
== language_java
)
2078 ? &objfile
->global_psymbols
2079 : &objfile
->static_psymbols
,
2080 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2086 /* Check to see if we should scan the name for possible namespace
2087 info. Only do this if this is C++, if we don't have namespace
2088 debugging info in the file, if the psym is of an appropriate type
2089 (otherwise we'll have psym == NULL), and if we actually had a
2090 mangled name to begin with. */
2092 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2093 cases which do not set PSYM above? */
2095 if (cu
->language
== language_cplus
2096 && cu
->has_namespace_info
== 0
2098 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
2099 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
2102 if (built_actual_name
)
2103 xfree (actual_name
);
2106 /* Determine whether a die of type TAG living in a C++ class or
2107 namespace needs to have the name of the scope prepended to the
2108 name listed in the die. */
2111 pdi_needs_namespace (enum dwarf_tag tag
)
2115 case DW_TAG_namespace
:
2116 case DW_TAG_typedef
:
2117 case DW_TAG_class_type
:
2118 case DW_TAG_interface_type
:
2119 case DW_TAG_structure_type
:
2120 case DW_TAG_union_type
:
2121 case DW_TAG_enumeration_type
:
2122 case DW_TAG_enumerator
:
2129 /* Read a partial die corresponding to a namespace; also, add a symbol
2130 corresponding to that namespace to the symbol table. NAMESPACE is
2131 the name of the enclosing namespace. */
2134 add_partial_namespace (struct partial_die_info
*pdi
,
2135 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2136 struct dwarf2_cu
*cu
)
2138 struct objfile
*objfile
= cu
->objfile
;
2140 /* Add a symbol for the namespace. */
2142 add_partial_symbol (pdi
, cu
);
2144 /* Now scan partial symbols in that namespace. */
2146 if (pdi
->has_children
)
2147 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, cu
);
2150 /* See if we can figure out if the class lives in a namespace. We do
2151 this by looking for a member function; its demangled name will
2152 contain namespace info, if there is any. */
2155 guess_structure_name (struct partial_die_info
*struct_pdi
,
2156 struct dwarf2_cu
*cu
)
2158 if ((cu
->language
== language_cplus
2159 || cu
->language
== language_java
)
2160 && cu
->has_namespace_info
== 0
2161 && struct_pdi
->has_children
)
2163 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2164 what template types look like, because the demangler
2165 frequently doesn't give the same name as the debug info. We
2166 could fix this by only using the demangled name to get the
2167 prefix (but see comment in read_structure_type). */
2169 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
2170 struct partial_die_info
*real_pdi
;
2172 /* If this DIE (this DIE's specification, if any) has a parent, then
2173 we should not do this. We'll prepend the parent's fully qualified
2174 name when we create the partial symbol. */
2176 real_pdi
= struct_pdi
;
2177 while (real_pdi
->has_specification
)
2178 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2180 if (real_pdi
->die_parent
!= NULL
)
2183 while (child_pdi
!= NULL
)
2185 if (child_pdi
->tag
== DW_TAG_subprogram
)
2187 char *actual_class_name
2188 = language_class_name_from_physname (cu
->language_defn
,
2190 if (actual_class_name
!= NULL
)
2193 = obsavestring (actual_class_name
,
2194 strlen (actual_class_name
),
2195 &cu
->comp_unit_obstack
);
2196 xfree (actual_class_name
);
2201 child_pdi
= child_pdi
->die_sibling
;
2206 /* Read a partial die corresponding to an enumeration type. */
2209 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2210 struct dwarf2_cu
*cu
)
2212 struct objfile
*objfile
= cu
->objfile
;
2213 bfd
*abfd
= objfile
->obfd
;
2214 struct partial_die_info
*pdi
;
2216 if (enum_pdi
->name
!= NULL
)
2217 add_partial_symbol (enum_pdi
, cu
);
2219 pdi
= enum_pdi
->die_child
;
2222 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2223 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2225 add_partial_symbol (pdi
, cu
);
2226 pdi
= pdi
->die_sibling
;
2230 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2231 Return the corresponding abbrev, or NULL if the number is zero (indicating
2232 an empty DIE). In either case *BYTES_READ will be set to the length of
2233 the initial number. */
2235 static struct abbrev_info
*
2236 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2237 struct dwarf2_cu
*cu
)
2239 bfd
*abfd
= cu
->objfile
->obfd
;
2240 unsigned int abbrev_number
;
2241 struct abbrev_info
*abbrev
;
2243 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2245 if (abbrev_number
== 0)
2248 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2251 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2252 bfd_get_filename (abfd
));
2258 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2259 pointer to the end of a series of DIEs, terminated by an empty
2260 DIE. Any children of the skipped DIEs will also be skipped. */
2263 skip_children (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2265 struct abbrev_info
*abbrev
;
2266 unsigned int bytes_read
;
2270 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2272 return info_ptr
+ bytes_read
;
2274 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
2278 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2279 should point just after the initial uleb128 of a DIE, and the
2280 abbrev corresponding to that skipped uleb128 should be passed in
2281 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2285 skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
2286 struct dwarf2_cu
*cu
)
2288 unsigned int bytes_read
;
2289 struct attribute attr
;
2290 bfd
*abfd
= cu
->objfile
->obfd
;
2291 unsigned int form
, i
;
2293 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2295 /* The only abbrev we care about is DW_AT_sibling. */
2296 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2298 read_attribute (&attr
, &abbrev
->attrs
[i
],
2299 abfd
, info_ptr
, cu
);
2300 if (attr
.form
== DW_FORM_ref_addr
)
2301 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2303 return dwarf2_per_objfile
->info_buffer
2304 + dwarf2_get_ref_die_offset (&attr
, cu
);
2307 /* If it isn't DW_AT_sibling, skip this attribute. */
2308 form
= abbrev
->attrs
[i
].form
;
2313 case DW_FORM_ref_addr
:
2314 info_ptr
+= cu
->header
.addr_size
;
2333 case DW_FORM_string
:
2334 read_string (abfd
, info_ptr
, &bytes_read
);
2335 info_ptr
+= bytes_read
;
2338 info_ptr
+= cu
->header
.offset_size
;
2341 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2342 info_ptr
+= bytes_read
;
2344 case DW_FORM_block1
:
2345 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2347 case DW_FORM_block2
:
2348 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2350 case DW_FORM_block4
:
2351 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2355 case DW_FORM_ref_udata
:
2356 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2358 case DW_FORM_indirect
:
2359 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2360 info_ptr
+= bytes_read
;
2361 /* We need to continue parsing from here, so just go back to
2363 goto skip_attribute
;
2366 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2367 dwarf_form_name (form
),
2368 bfd_get_filename (abfd
));
2372 if (abbrev
->has_children
)
2373 return skip_children (info_ptr
, cu
);
2378 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2379 the next DIE after ORIG_PDI. */
2382 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, gdb_byte
*info_ptr
,
2383 bfd
*abfd
, struct dwarf2_cu
*cu
)
2385 /* Do we know the sibling already? */
2387 if (orig_pdi
->sibling
)
2388 return orig_pdi
->sibling
;
2390 /* Are there any children to deal with? */
2392 if (!orig_pdi
->has_children
)
2395 /* Skip the children the long way. */
2397 return skip_children (info_ptr
, cu
);
2400 /* Expand this partial symbol table into a full symbol table. */
2403 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2405 /* FIXME: This is barely more than a stub. */
2410 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2416 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2417 gdb_flush (gdb_stdout
);
2420 /* Restore our global data. */
2421 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2422 dwarf2_objfile_data_key
);
2424 psymtab_to_symtab_1 (pst
);
2426 /* Finish up the debug error message. */
2428 printf_filtered (_("done.\n"));
2433 /* Add PER_CU to the queue. */
2436 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2438 struct dwarf2_queue_item
*item
;
2441 item
= xmalloc (sizeof (*item
));
2442 item
->per_cu
= per_cu
;
2445 if (dwarf2_queue
== NULL
)
2446 dwarf2_queue
= item
;
2448 dwarf2_queue_tail
->next
= item
;
2450 dwarf2_queue_tail
= item
;
2452 /* Either PER_CU is the CU we want to process, or we're following a reference
2453 pointing into PER_CU. Either way, we need its DIEs now. */
2454 load_full_comp_unit (item
->per_cu
, objfile
);
2455 item
->per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
2456 dwarf2_per_objfile
->read_in_chain
= item
->per_cu
;
2459 /* Process the queue. */
2462 process_queue (struct objfile
*objfile
)
2464 struct dwarf2_queue_item
*item
, *next_item
;
2466 /* The queue starts out with one item, but following a DIE reference
2467 may load a new CU, adding it to the end of the queue. */
2468 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2470 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2471 process_full_comp_unit (item
->per_cu
);
2473 item
->per_cu
->queued
= 0;
2474 next_item
= item
->next
;
2478 dwarf2_queue_tail
= NULL
;
2481 /* Free all allocated queue entries. This function only releases anything if
2482 an error was thrown; if the queue was processed then it would have been
2483 freed as we went along. */
2486 dwarf2_release_queue (void *dummy
)
2488 struct dwarf2_queue_item
*item
, *last
;
2490 item
= dwarf2_queue
;
2493 /* Anything still marked queued is likely to be in an
2494 inconsistent state, so discard it. */
2495 if (item
->per_cu
->queued
)
2497 if (item
->per_cu
->cu
!= NULL
)
2498 free_one_cached_comp_unit (item
->per_cu
->cu
);
2499 item
->per_cu
->queued
= 0;
2507 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2510 /* Read in full symbols for PST, and anything it depends on. */
2513 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2515 struct dwarf2_per_cu_data
*per_cu
;
2516 struct cleanup
*back_to
;
2519 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2520 if (!pst
->dependencies
[i
]->readin
)
2522 /* Inform about additional files that need to be read in. */
2525 /* FIXME: i18n: Need to make this a single string. */
2526 fputs_filtered (" ", gdb_stdout
);
2528 fputs_filtered ("and ", gdb_stdout
);
2530 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2531 wrap_here (""); /* Flush output */
2532 gdb_flush (gdb_stdout
);
2534 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2537 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
2541 /* It's an include file, no symbols to read for it.
2542 Everything is in the parent symtab. */
2547 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2549 queue_comp_unit (per_cu
, pst
->objfile
);
2551 process_queue (pst
->objfile
);
2553 /* Age the cache, releasing compilation units that have not
2554 been used recently. */
2555 age_cached_comp_units ();
2557 do_cleanups (back_to
);
2560 /* Load the DIEs associated with PST and PER_CU into memory. */
2562 static struct dwarf2_cu
*
2563 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2565 bfd
*abfd
= objfile
->obfd
;
2566 struct dwarf2_cu
*cu
;
2567 unsigned long offset
;
2569 struct cleanup
*back_to
, *free_cu_cleanup
;
2570 struct attribute
*attr
;
2573 /* Set local variables from the partial symbol table info. */
2574 offset
= per_cu
->offset
;
2576 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2578 cu
= xmalloc (sizeof (struct dwarf2_cu
));
2579 memset (cu
, 0, sizeof (struct dwarf2_cu
));
2581 /* If an error occurs while loading, release our storage. */
2582 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
2584 cu
->objfile
= objfile
;
2586 /* read in the comp_unit header */
2587 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
2589 /* Read the abbrevs for this compilation unit */
2590 dwarf2_read_abbrevs (abfd
, cu
);
2591 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2593 cu
->header
.offset
= offset
;
2595 cu
->per_cu
= per_cu
;
2597 cu
->type_hash
= per_cu
->type_hash
;
2599 /* We use this obstack for block values in dwarf_alloc_block. */
2600 obstack_init (&cu
->comp_unit_obstack
);
2602 cu
->dies
= read_comp_unit (info_ptr
, abfd
, cu
);
2604 /* We try not to read any attributes in this function, because not
2605 all objfiles needed for references have been loaded yet, and symbol
2606 table processing isn't initialized. But we have to set the CU language,
2607 or we won't be able to build types correctly. */
2608 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
2610 set_cu_language (DW_UNSND (attr
), cu
);
2612 set_cu_language (language_minimal
, cu
);
2614 do_cleanups (back_to
);
2616 /* We've successfully allocated this compilation unit. Let our caller
2617 clean it up when finished with it. */
2618 discard_cleanups (free_cu_cleanup
);
2623 /* Generate full symbol information for PST and CU, whose DIEs have
2624 already been loaded into memory. */
2627 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2629 struct partial_symtab
*pst
= per_cu
->psymtab
;
2630 struct dwarf2_cu
*cu
= per_cu
->cu
;
2631 struct objfile
*objfile
= pst
->objfile
;
2632 bfd
*abfd
= objfile
->obfd
;
2633 CORE_ADDR lowpc
, highpc
;
2634 struct symtab
*symtab
;
2635 struct cleanup
*back_to
;
2636 struct attribute
*attr
;
2639 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2642 back_to
= make_cleanup (really_free_pendings
, NULL
);
2644 cu
->list_in_scope
= &file_symbols
;
2646 /* Find the base address of the compilation unit for range lists and
2647 location lists. It will normally be specified by DW_AT_low_pc.
2648 In DWARF-3 draft 4, the base address could be overridden by
2649 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2650 compilation units with discontinuous ranges. */
2652 cu
->header
.base_known
= 0;
2653 cu
->header
.base_address
= 0;
2655 attr
= dwarf2_attr (cu
->dies
, DW_AT_entry_pc
, cu
);
2658 cu
->header
.base_address
= DW_ADDR (attr
);
2659 cu
->header
.base_known
= 1;
2663 attr
= dwarf2_attr (cu
->dies
, DW_AT_low_pc
, cu
);
2666 cu
->header
.base_address
= DW_ADDR (attr
);
2667 cu
->header
.base_known
= 1;
2671 /* Do line number decoding in read_file_scope () */
2672 process_die (cu
->dies
, cu
);
2674 /* Some compilers don't define a DW_AT_high_pc attribute for the
2675 compilation unit. If the DW_AT_high_pc is missing, synthesize
2676 it, by scanning the DIE's below the compilation unit. */
2677 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
2679 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2681 /* Set symtab language to language from DW_AT_language.
2682 If the compilation is from a C file generated by language preprocessors,
2683 do not set the language if it was already deduced by start_subfile. */
2685 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
2687 symtab
->language
= cu
->language
;
2689 pst
->symtab
= symtab
;
2692 do_cleanups (back_to
);
2695 /* Process a die and its children. */
2698 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2702 case DW_TAG_padding
:
2704 case DW_TAG_compile_unit
:
2705 read_file_scope (die
, cu
);
2707 case DW_TAG_subprogram
:
2708 read_func_scope (die
, cu
);
2710 case DW_TAG_inlined_subroutine
:
2711 /* FIXME: These are ignored for now.
2712 They could be used to set breakpoints on all inlined instances
2713 of a function and make GDB `next' properly over inlined functions. */
2715 case DW_TAG_lexical_block
:
2716 case DW_TAG_try_block
:
2717 case DW_TAG_catch_block
:
2718 read_lexical_block_scope (die
, cu
);
2720 case DW_TAG_class_type
:
2721 case DW_TAG_interface_type
:
2722 case DW_TAG_structure_type
:
2723 case DW_TAG_union_type
:
2724 process_structure_scope (die
, cu
);
2726 case DW_TAG_enumeration_type
:
2727 process_enumeration_scope (die
, cu
);
2730 /* These dies have a type, but processing them does not create
2731 a symbol or recurse to process the children. Therefore we can
2732 read them on-demand through read_type_die. */
2733 case DW_TAG_subroutine_type
:
2734 case DW_TAG_set_type
:
2735 case DW_TAG_array_type
:
2736 case DW_TAG_pointer_type
:
2737 case DW_TAG_ptr_to_member_type
:
2738 case DW_TAG_reference_type
:
2739 case DW_TAG_string_type
:
2742 case DW_TAG_base_type
:
2743 case DW_TAG_subrange_type
:
2744 /* Add a typedef symbol for the type definition, if it has a
2746 new_symbol (die
, read_type_die (die
, cu
), cu
);
2748 case DW_TAG_common_block
:
2749 read_common_block (die
, cu
);
2751 case DW_TAG_common_inclusion
:
2753 case DW_TAG_namespace
:
2754 processing_has_namespace_info
= 1;
2755 read_namespace (die
, cu
);
2757 case DW_TAG_imported_declaration
:
2758 case DW_TAG_imported_module
:
2759 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2760 information contained in these. DW_TAG_imported_declaration
2761 dies shouldn't have children; DW_TAG_imported_module dies
2762 shouldn't in the C++ case, but conceivably could in the
2764 processing_has_namespace_info
= 1;
2765 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
2766 dwarf_tag_name (die
->tag
));
2769 new_symbol (die
, NULL
, cu
);
2774 /* Return the fully qualified name of DIE, based on its DW_AT_name.
2775 If scope qualifiers are appropriate they will be added. The result
2776 will be allocated on the objfile_obstack, or NULL if the DIE does
2780 dwarf2_full_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
2782 struct attribute
*attr
;
2783 char *prefix
, *name
;
2784 struct ui_file
*buf
= NULL
;
2786 name
= dwarf2_name (die
, cu
);
2790 /* These are the only languages we know how to qualify names in. */
2791 if (cu
->language
!= language_cplus
2792 && cu
->language
!= language_java
)
2795 /* If no prefix is necessary for this type of DIE, return the
2796 unqualified name. The other three tags listed could be handled
2797 in pdi_needs_namespace, but that requires broader changes. */
2798 if (!pdi_needs_namespace (die
->tag
)
2799 && die
->tag
!= DW_TAG_subprogram
2800 && die
->tag
!= DW_TAG_variable
2801 && die
->tag
!= DW_TAG_member
)
2804 prefix
= determine_prefix (die
, cu
);
2805 if (*prefix
!= '\0')
2806 name
= typename_concat (&cu
->objfile
->objfile_obstack
, prefix
,
2813 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2815 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2819 free_cu_line_header (void *arg
)
2821 struct dwarf2_cu
*cu
= arg
;
2823 free_line_header (cu
->line_header
);
2824 cu
->line_header
= NULL
;
2828 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2830 struct objfile
*objfile
= cu
->objfile
;
2831 struct comp_unit_head
*cu_header
= &cu
->header
;
2832 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2833 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2834 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2835 struct attribute
*attr
;
2837 char *comp_dir
= NULL
;
2838 struct die_info
*child_die
;
2839 bfd
*abfd
= objfile
->obfd
;
2840 struct line_header
*line_header
= 0;
2843 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2845 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2847 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2848 from finish_block. */
2849 if (lowpc
== ((CORE_ADDR
) -1))
2854 /* Find the filename. Do not use dwarf2_name here, since the filename
2855 is not a source language identifier. */
2856 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2859 name
= DW_STRING (attr
);
2862 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2864 comp_dir
= DW_STRING (attr
);
2865 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
2867 comp_dir
= ldirname (name
);
2868 if (comp_dir
!= NULL
)
2869 make_cleanup (xfree
, comp_dir
);
2871 if (comp_dir
!= NULL
)
2873 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2874 directory, get rid of it. */
2875 char *cp
= strchr (comp_dir
, ':');
2877 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2884 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2887 set_cu_language (DW_UNSND (attr
), cu
);
2890 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
2892 cu
->producer
= DW_STRING (attr
);
2894 /* We assume that we're processing GCC output. */
2895 processing_gcc_compilation
= 2;
2897 processing_has_namespace_info
= 0;
2899 start_symtab (name
, comp_dir
, lowpc
);
2900 record_debugformat ("DWARF 2");
2901 record_producer (cu
->producer
);
2903 initialize_cu_func_list (cu
);
2905 /* Decode line number information if present. We do this before
2906 processing child DIEs, so that the line header table is available
2907 for DW_AT_decl_file. */
2908 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2911 unsigned int line_offset
= DW_UNSND (attr
);
2912 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2915 cu
->line_header
= line_header
;
2916 make_cleanup (free_cu_line_header
, cu
);
2917 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
2921 /* Process all dies in compilation unit. */
2922 if (die
->child
!= NULL
)
2924 child_die
= die
->child
;
2925 while (child_die
&& child_die
->tag
)
2927 process_die (child_die
, cu
);
2928 child_die
= sibling_die (child_die
);
2932 /* Decode macro information, if present. Dwarf 2 macro information
2933 refers to information in the line number info statement program
2934 header, so we can only read it if we've read the header
2936 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2937 if (attr
&& line_header
)
2939 unsigned int macro_offset
= DW_UNSND (attr
);
2940 dwarf_decode_macros (line_header
, macro_offset
,
2941 comp_dir
, abfd
, cu
);
2943 do_cleanups (back_to
);
2947 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2948 struct dwarf2_cu
*cu
)
2950 struct function_range
*thisfn
;
2952 thisfn
= (struct function_range
*)
2953 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
2954 thisfn
->name
= name
;
2955 thisfn
->lowpc
= lowpc
;
2956 thisfn
->highpc
= highpc
;
2957 thisfn
->seen_line
= 0;
2958 thisfn
->next
= NULL
;
2960 if (cu
->last_fn
== NULL
)
2961 cu
->first_fn
= thisfn
;
2963 cu
->last_fn
->next
= thisfn
;
2965 cu
->last_fn
= thisfn
;
2969 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2971 struct objfile
*objfile
= cu
->objfile
;
2972 struct context_stack
*new;
2975 struct die_info
*child_die
;
2976 struct attribute
*attr
;
2979 struct block
*block
;
2981 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2983 name
= dwarf2_linkage_name (die
, cu
);
2985 /* Ignore functions with missing or empty names and functions with
2986 missing or invalid low and high pc attributes. */
2987 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2993 /* Record the function range for dwarf_decode_lines. */
2994 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
2996 new = push_context (0, lowpc
);
2997 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
2999 /* If there is a location expression for DW_AT_frame_base, record
3001 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3003 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3004 expression is being recorded directly in the function's symbol
3005 and not in a separate frame-base object. I guess this hack is
3006 to avoid adding some sort of frame-base adjunct/annex to the
3007 function's symbol :-(. The problem with doing this is that it
3008 results in a function symbol with a location expression that
3009 has nothing to do with the location of the function, ouch! The
3010 relationship should be: a function's symbol has-a frame base; a
3011 frame-base has-a location expression. */
3012 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3014 cu
->list_in_scope
= &local_symbols
;
3016 if (die
->child
!= NULL
)
3018 child_die
= die
->child
;
3019 while (child_die
&& child_die
->tag
)
3021 process_die (child_die
, cu
);
3022 child_die
= sibling_die (child_die
);
3026 new = pop_context ();
3027 /* Make a block for the local symbols within. */
3028 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3029 lowpc
, highpc
, objfile
);
3031 /* For C++, set the block's scope. */
3032 if (cu
->language
== language_cplus
)
3033 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
3034 determine_prefix (die
, cu
),
3035 processing_has_namespace_info
);
3037 /* If we have address ranges, record them. */
3038 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3040 /* In C++, we can have functions nested inside functions (e.g., when
3041 a function declares a class that has methods). This means that
3042 when we finish processing a function scope, we may need to go
3043 back to building a containing block's symbol lists. */
3044 local_symbols
= new->locals
;
3045 param_symbols
= new->params
;
3047 /* If we've finished processing a top-level function, subsequent
3048 symbols go in the file symbol list. */
3049 if (outermost_context_p ())
3050 cu
->list_in_scope
= &file_symbols
;
3053 /* Process all the DIES contained within a lexical block scope. Start
3054 a new scope, process the dies, and then close the scope. */
3057 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3059 struct objfile
*objfile
= cu
->objfile
;
3060 struct context_stack
*new;
3061 CORE_ADDR lowpc
, highpc
;
3062 struct die_info
*child_die
;
3065 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3067 /* Ignore blocks with missing or invalid low and high pc attributes. */
3068 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3069 as multiple lexical blocks? Handling children in a sane way would
3070 be nasty. Might be easier to properly extend generic blocks to
3072 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3077 push_context (0, lowpc
);
3078 if (die
->child
!= NULL
)
3080 child_die
= die
->child
;
3081 while (child_die
&& child_die
->tag
)
3083 process_die (child_die
, cu
);
3084 child_die
= sibling_die (child_die
);
3087 new = pop_context ();
3089 if (local_symbols
!= NULL
)
3092 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3095 /* Note that recording ranges after traversing children, as we
3096 do here, means that recording a parent's ranges entails
3097 walking across all its children's ranges as they appear in
3098 the address map, which is quadratic behavior.
3100 It would be nicer to record the parent's ranges before
3101 traversing its children, simply overriding whatever you find
3102 there. But since we don't even decide whether to create a
3103 block until after we've traversed its children, that's hard
3105 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3107 local_symbols
= new->locals
;
3110 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3111 Return 1 if the attributes are present and valid, otherwise, return 0.
3112 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3115 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
3116 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
3117 struct partial_symtab
*ranges_pst
)
3119 struct objfile
*objfile
= cu
->objfile
;
3120 struct comp_unit_head
*cu_header
= &cu
->header
;
3121 bfd
*obfd
= objfile
->obfd
;
3122 unsigned int addr_size
= cu_header
->addr_size
;
3123 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3124 /* Base address selection entry. */
3135 found_base
= cu_header
->base_known
;
3136 base
= cu_header
->base_address
;
3138 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3140 complaint (&symfile_complaints
,
3141 _("Offset %d out of bounds for DW_AT_ranges attribute"),
3145 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3147 /* Read in the largest possible address. */
3148 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
3149 if ((marker
& mask
) == mask
)
3151 /* If we found the largest possible address, then
3152 read the base address. */
3153 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3154 buffer
+= 2 * addr_size
;
3155 offset
+= 2 * addr_size
;
3161 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3165 CORE_ADDR range_beginning
, range_end
;
3167 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
3168 buffer
+= addr_size
;
3169 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
3170 buffer
+= addr_size
;
3171 offset
+= 2 * addr_size
;
3173 /* An end of list marker is a pair of zero addresses. */
3174 if (range_beginning
== 0 && range_end
== 0)
3175 /* Found the end of list entry. */
3178 /* Each base address selection entry is a pair of 2 values.
3179 The first is the largest possible address, the second is
3180 the base address. Check for a base address here. */
3181 if ((range_beginning
& mask
) == mask
)
3183 /* If we found the largest possible address, then
3184 read the base address. */
3185 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3192 /* We have no valid base address for the ranges
3194 complaint (&symfile_complaints
,
3195 _("Invalid .debug_ranges data (no base address)"));
3199 range_beginning
+= base
;
3202 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
3203 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3204 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
3207 /* FIXME: This is recording everything as a low-high
3208 segment of consecutive addresses. We should have a
3209 data structure for discontiguous block ranges
3213 low
= range_beginning
;
3219 if (range_beginning
< low
)
3220 low
= range_beginning
;
3221 if (range_end
> high
)
3227 /* If the first entry is an end-of-list marker, the range
3228 describes an empty scope, i.e. no instructions. */
3234 *high_return
= high
;
3238 /* Get low and high pc attributes from a die. Return 1 if the attributes
3239 are present and valid, otherwise, return 0. Return -1 if the range is
3240 discontinuous, i.e. derived from DW_AT_ranges information. */
3242 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
3243 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
3245 struct attribute
*attr
;
3250 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3253 high
= DW_ADDR (attr
);
3254 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3256 low
= DW_ADDR (attr
);
3258 /* Found high w/o low attribute. */
3261 /* Found consecutive range of addresses. */
3266 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3269 /* Value of the DW_AT_ranges attribute is the offset in the
3270 .debug_ranges section. */
3271 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, NULL
))
3273 /* Found discontinuous range of addresses. */
3281 /* When using the GNU linker, .gnu.linkonce. sections are used to
3282 eliminate duplicate copies of functions and vtables and such.
3283 The linker will arbitrarily choose one and discard the others.
3284 The AT_*_pc values for such functions refer to local labels in
3285 these sections. If the section from that file was discarded, the
3286 labels are not in the output, so the relocs get a value of 0.
3287 If this is a discarded function, mark the pc bounds as invalid,
3288 so that GDB will ignore it. */
3289 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3297 /* Get the low and high pc's represented by the scope DIE, and store
3298 them in *LOWPC and *HIGHPC. If the correct values can't be
3299 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3302 get_scope_pc_bounds (struct die_info
*die
,
3303 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3304 struct dwarf2_cu
*cu
)
3306 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3307 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3308 CORE_ADDR current_low
, current_high
;
3310 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3312 best_low
= current_low
;
3313 best_high
= current_high
;
3317 struct die_info
*child
= die
->child
;
3319 while (child
&& child
->tag
)
3321 switch (child
->tag
) {
3322 case DW_TAG_subprogram
:
3323 if (dwarf2_get_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
))
3325 best_low
= min (best_low
, current_low
);
3326 best_high
= max (best_high
, current_high
);
3329 case DW_TAG_namespace
:
3330 /* FIXME: carlton/2004-01-16: Should we do this for
3331 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3332 that current GCC's always emit the DIEs corresponding
3333 to definitions of methods of classes as children of a
3334 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3335 the DIEs giving the declarations, which could be
3336 anywhere). But I don't see any reason why the
3337 standards says that they have to be there. */
3338 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3340 if (current_low
!= ((CORE_ADDR
) -1))
3342 best_low
= min (best_low
, current_low
);
3343 best_high
= max (best_high
, current_high
);
3351 child
= sibling_die (child
);
3356 *highpc
= best_high
;
3359 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
3362 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
3363 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
3365 struct attribute
*attr
;
3367 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3370 CORE_ADDR high
= DW_ADDR (attr
);
3371 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3374 CORE_ADDR low
= DW_ADDR (attr
);
3375 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
3379 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3382 bfd
*obfd
= cu
->objfile
->obfd
;
3384 /* The value of the DW_AT_ranges attribute is the offset of the
3385 address range list in the .debug_ranges section. */
3386 unsigned long offset
= DW_UNSND (attr
);
3387 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3389 /* For some target architectures, but not others, the
3390 read_address function sign-extends the addresses it returns.
3391 To recognize base address selection entries, we need a
3393 unsigned int addr_size
= cu
->header
.addr_size
;
3394 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3396 /* The base address, to which the next pair is relative. Note
3397 that this 'base' is a DWARF concept: most entries in a range
3398 list are relative, to reduce the number of relocs against the
3399 debugging information. This is separate from this function's
3400 'baseaddr' argument, which GDB uses to relocate debugging
3401 information from a shared library based on the address at
3402 which the library was loaded. */
3403 CORE_ADDR base
= cu
->header
.base_address
;
3404 int base_known
= cu
->header
.base_known
;
3406 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3408 complaint (&symfile_complaints
,
3409 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
3416 unsigned int bytes_read
;
3417 CORE_ADDR start
, end
;
3419 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3420 buffer
+= bytes_read
;
3421 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3422 buffer
+= bytes_read
;
3424 /* Did we find the end of the range list? */
3425 if (start
== 0 && end
== 0)
3428 /* Did we find a base address selection entry? */
3429 else if ((start
& base_select_mask
) == base_select_mask
)
3435 /* We found an ordinary address range. */
3440 complaint (&symfile_complaints
,
3441 _("Invalid .debug_ranges data (no base address)"));
3445 record_block_range (block
,
3446 baseaddr
+ base
+ start
,
3447 baseaddr
+ base
+ end
- 1);
3453 /* Add an aggregate field to the field list. */
3456 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3457 struct dwarf2_cu
*cu
)
3459 struct objfile
*objfile
= cu
->objfile
;
3460 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3461 struct nextfield
*new_field
;
3462 struct attribute
*attr
;
3464 char *fieldname
= "";
3466 /* Allocate a new field list entry and link it in. */
3467 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3468 make_cleanup (xfree
, new_field
);
3469 memset (new_field
, 0, sizeof (struct nextfield
));
3470 new_field
->next
= fip
->fields
;
3471 fip
->fields
= new_field
;
3474 /* Handle accessibility and virtuality of field.
3475 The default accessibility for members is public, the default
3476 accessibility for inheritance is private. */
3477 if (die
->tag
!= DW_TAG_inheritance
)
3478 new_field
->accessibility
= DW_ACCESS_public
;
3480 new_field
->accessibility
= DW_ACCESS_private
;
3481 new_field
->virtuality
= DW_VIRTUALITY_none
;
3483 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3485 new_field
->accessibility
= DW_UNSND (attr
);
3486 if (new_field
->accessibility
!= DW_ACCESS_public
)
3487 fip
->non_public_fields
= 1;
3488 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3490 new_field
->virtuality
= DW_UNSND (attr
);
3492 fp
= &new_field
->field
;
3494 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3496 /* Data member other than a C++ static data member. */
3498 /* Get type of field. */
3499 fp
->type
= die_type (die
, cu
);
3501 FIELD_STATIC_KIND (*fp
) = 0;
3503 /* Get bit size of field (zero if none). */
3504 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3507 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3511 FIELD_BITSIZE (*fp
) = 0;
3514 /* Get bit offset of field. */
3515 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3520 if (attr_form_is_section_offset (attr
))
3522 dwarf2_complex_location_expr_complaint ();
3525 else if (attr_form_is_constant (attr
))
3526 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
3528 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
3530 FIELD_BITPOS (*fp
) = byte_offset
* bits_per_byte
;
3533 FIELD_BITPOS (*fp
) = 0;
3534 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3537 if (gdbarch_bits_big_endian (gdbarch
))
3539 /* For big endian bits, the DW_AT_bit_offset gives the
3540 additional bit offset from the MSB of the containing
3541 anonymous object to the MSB of the field. We don't
3542 have to do anything special since we don't need to
3543 know the size of the anonymous object. */
3544 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3548 /* For little endian bits, compute the bit offset to the
3549 MSB of the anonymous object, subtract off the number of
3550 bits from the MSB of the field to the MSB of the
3551 object, and then subtract off the number of bits of
3552 the field itself. The result is the bit offset of
3553 the LSB of the field. */
3555 int bit_offset
= DW_UNSND (attr
);
3557 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3560 /* The size of the anonymous object containing
3561 the bit field is explicit, so use the
3562 indicated size (in bytes). */
3563 anonymous_size
= DW_UNSND (attr
);
3567 /* The size of the anonymous object containing
3568 the bit field must be inferred from the type
3569 attribute of the data member containing the
3571 anonymous_size
= TYPE_LENGTH (fp
->type
);
3573 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
3574 - bit_offset
- FIELD_BITSIZE (*fp
);
3578 /* Get name of field. */
3579 fieldname
= dwarf2_name (die
, cu
);
3580 if (fieldname
== NULL
)
3583 /* The name is already allocated along with this objfile, so we don't
3584 need to duplicate it for the type. */
3585 fp
->name
= fieldname
;
3587 /* Change accessibility for artificial fields (e.g. virtual table
3588 pointer or virtual base class pointer) to private. */
3589 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
3591 new_field
->accessibility
= DW_ACCESS_private
;
3592 fip
->non_public_fields
= 1;
3595 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
3597 /* C++ static member. */
3599 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3600 is a declaration, but all versions of G++ as of this writing
3601 (so through at least 3.2.1) incorrectly generate
3602 DW_TAG_variable tags. */
3606 /* Get name of field. */
3607 fieldname
= dwarf2_name (die
, cu
);
3608 if (fieldname
== NULL
)
3611 /* Get physical name. */
3612 physname
= dwarf2_linkage_name (die
, cu
);
3614 /* The name is already allocated along with this objfile, so we don't
3615 need to duplicate it for the type. */
3616 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
3617 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3618 FIELD_NAME (*fp
) = fieldname
;
3620 else if (die
->tag
== DW_TAG_inheritance
)
3622 /* C++ base class field. */
3623 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3625 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
3627 FIELD_BITSIZE (*fp
) = 0;
3628 FIELD_STATIC_KIND (*fp
) = 0;
3629 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3630 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
3631 fip
->nbaseclasses
++;
3635 /* Create the vector of fields, and attach it to the type. */
3638 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3639 struct dwarf2_cu
*cu
)
3641 int nfields
= fip
->nfields
;
3643 /* Record the field count, allocate space for the array of fields,
3644 and create blank accessibility bitfields if necessary. */
3645 TYPE_NFIELDS (type
) = nfields
;
3646 TYPE_FIELDS (type
) = (struct field
*)
3647 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3648 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3650 if (fip
->non_public_fields
)
3652 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3654 TYPE_FIELD_PRIVATE_BITS (type
) =
3655 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3656 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3658 TYPE_FIELD_PROTECTED_BITS (type
) =
3659 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3660 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3662 TYPE_FIELD_IGNORE_BITS (type
) =
3663 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3664 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3667 /* If the type has baseclasses, allocate and clear a bit vector for
3668 TYPE_FIELD_VIRTUAL_BITS. */
3669 if (fip
->nbaseclasses
)
3671 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3672 unsigned char *pointer
;
3674 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3675 pointer
= TYPE_ALLOC (type
, num_bytes
);
3676 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
3677 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3678 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3681 /* Copy the saved-up fields into the field vector. Start from the head
3682 of the list, adding to the tail of the field array, so that they end
3683 up in the same order in the array in which they were added to the list. */
3684 while (nfields
-- > 0)
3686 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3687 switch (fip
->fields
->accessibility
)
3689 case DW_ACCESS_private
:
3690 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3693 case DW_ACCESS_protected
:
3694 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3697 case DW_ACCESS_public
:
3701 /* Unknown accessibility. Complain and treat it as public. */
3703 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
3704 fip
->fields
->accessibility
);
3708 if (nfields
< fip
->nbaseclasses
)
3710 switch (fip
->fields
->virtuality
)
3712 case DW_VIRTUALITY_virtual
:
3713 case DW_VIRTUALITY_pure_virtual
:
3714 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3718 fip
->fields
= fip
->fields
->next
;
3722 /* Add a member function to the proper fieldlist. */
3725 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3726 struct type
*type
, struct dwarf2_cu
*cu
)
3728 struct objfile
*objfile
= cu
->objfile
;
3729 struct attribute
*attr
;
3730 struct fnfieldlist
*flp
;
3732 struct fn_field
*fnp
;
3735 struct nextfnfield
*new_fnfield
;
3736 struct type
*this_type
;
3738 /* Get name of member function. */
3739 fieldname
= dwarf2_name (die
, cu
);
3740 if (fieldname
== NULL
)
3743 /* Get the mangled name. */
3744 physname
= dwarf2_linkage_name (die
, cu
);
3746 /* Look up member function name in fieldlist. */
3747 for (i
= 0; i
< fip
->nfnfields
; i
++)
3749 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3753 /* Create new list element if necessary. */
3754 if (i
< fip
->nfnfields
)
3755 flp
= &fip
->fnfieldlists
[i
];
3758 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3760 fip
->fnfieldlists
= (struct fnfieldlist
*)
3761 xrealloc (fip
->fnfieldlists
,
3762 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3763 * sizeof (struct fnfieldlist
));
3764 if (fip
->nfnfields
== 0)
3765 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3767 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3768 flp
->name
= fieldname
;
3774 /* Create a new member function field and chain it to the field list
3776 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3777 make_cleanup (xfree
, new_fnfield
);
3778 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3779 new_fnfield
->next
= flp
->head
;
3780 flp
->head
= new_fnfield
;
3783 /* Fill in the member function field info. */
3784 fnp
= &new_fnfield
->fnfield
;
3785 /* The name is already allocated along with this objfile, so we don't
3786 need to duplicate it for the type. */
3787 fnp
->physname
= physname
? physname
: "";
3788 fnp
->type
= alloc_type (objfile
);
3789 this_type
= read_type_die (die
, cu
);
3790 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
3792 int nparams
= TYPE_NFIELDS (this_type
);
3794 /* TYPE is the domain of this method, and THIS_TYPE is the type
3795 of the method itself (TYPE_CODE_METHOD). */
3796 smash_to_method_type (fnp
->type
, type
,
3797 TYPE_TARGET_TYPE (this_type
),
3798 TYPE_FIELDS (this_type
),
3799 TYPE_NFIELDS (this_type
),
3800 TYPE_VARARGS (this_type
));
3802 /* Handle static member functions.
3803 Dwarf2 has no clean way to discern C++ static and non-static
3804 member functions. G++ helps GDB by marking the first
3805 parameter for non-static member functions (which is the
3806 this pointer) as artificial. We obtain this information
3807 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3808 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
3809 fnp
->voffset
= VOFFSET_STATIC
;
3812 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
3815 /* Get fcontext from DW_AT_containing_type if present. */
3816 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3817 fnp
->fcontext
= die_containing_type (die
, cu
);
3819 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3820 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3822 /* Get accessibility. */
3823 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3826 switch (DW_UNSND (attr
))
3828 case DW_ACCESS_private
:
3829 fnp
->is_private
= 1;
3831 case DW_ACCESS_protected
:
3832 fnp
->is_protected
= 1;
3837 /* Check for artificial methods. */
3838 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3839 if (attr
&& DW_UNSND (attr
) != 0)
3840 fnp
->is_artificial
= 1;
3842 /* Get index in virtual function table if it is a virtual member function. */
3843 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3846 /* Support the .debug_loc offsets */
3847 if (attr_form_is_block (attr
))
3849 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3851 else if (attr_form_is_section_offset (attr
))
3853 dwarf2_complex_location_expr_complaint ();
3857 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3863 /* Create the vector of member function fields, and attach it to the type. */
3866 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3867 struct dwarf2_cu
*cu
)
3869 struct fnfieldlist
*flp
;
3870 int total_length
= 0;
3873 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3874 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3875 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3877 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3879 struct nextfnfield
*nfp
= flp
->head
;
3880 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3883 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3884 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3885 fn_flp
->fn_fields
= (struct fn_field
*)
3886 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3887 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3888 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3890 total_length
+= flp
->length
;
3893 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3894 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3897 /* Returns non-zero if NAME is the name of a vtable member in CU's
3898 language, zero otherwise. */
3900 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
3902 static const char vptr
[] = "_vptr";
3903 static const char vtable
[] = "vtable";
3905 /* Look for the C++ and Java forms of the vtable. */
3906 if ((cu
->language
== language_java
3907 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
3908 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
3909 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
3915 /* GCC outputs unnamed structures that are really pointers to member
3916 functions, with the ABI-specified layout. If DIE (from CU) describes
3917 such a structure, set its type, and return nonzero. Otherwise return
3920 GCC shouldn't do this; it should just output pointer to member DIEs.
3921 This is GCC PR debug/28767. */
3923 static struct type
*
3924 quirk_gcc_member_function_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
)
3926 struct objfile
*objfile
= cu
->objfile
;
3928 struct die_info
*pfn_die
, *delta_die
;
3929 struct attribute
*pfn_name
, *delta_name
;
3930 struct type
*pfn_type
, *domain_type
;
3932 /* Check for a structure with no name and two children. */
3933 if (die
->tag
!= DW_TAG_structure_type
3934 || dwarf2_attr (die
, DW_AT_name
, cu
) != NULL
3935 || die
->child
== NULL
3936 || die
->child
->sibling
== NULL
3937 || (die
->child
->sibling
->sibling
!= NULL
3938 && die
->child
->sibling
->sibling
->tag
!= DW_TAG_padding
))
3941 /* Check for __pfn and __delta members. */
3942 pfn_die
= die
->child
;
3943 pfn_name
= dwarf2_attr (pfn_die
, DW_AT_name
, cu
);
3944 if (pfn_die
->tag
!= DW_TAG_member
3946 || DW_STRING (pfn_name
) == NULL
3947 || strcmp ("__pfn", DW_STRING (pfn_name
)) != 0)
3950 delta_die
= pfn_die
->sibling
;
3951 delta_name
= dwarf2_attr (delta_die
, DW_AT_name
, cu
);
3952 if (delta_die
->tag
!= DW_TAG_member
3953 || delta_name
== NULL
3954 || DW_STRING (delta_name
) == NULL
3955 || strcmp ("__delta", DW_STRING (delta_name
)) != 0)
3958 /* Find the type of the method. */
3959 pfn_type
= die_type (pfn_die
, cu
);
3960 if (pfn_type
== NULL
3961 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
3962 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
3965 /* Look for the "this" argument. */
3966 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
3967 if (TYPE_NFIELDS (pfn_type
) == 0
3968 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
3971 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
3972 type
= alloc_type (objfile
);
3973 smash_to_method_type (type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
3974 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
3975 TYPE_VARARGS (pfn_type
));
3976 type
= lookup_methodptr_type (type
);
3977 return set_die_type (die
, type
, cu
);
3980 /* Called when we find the DIE that starts a structure or union scope
3981 (definition) to process all dies that define the members of the
3984 NOTE: we need to call struct_type regardless of whether or not the
3985 DIE has an at_name attribute, since it might be an anonymous
3986 structure or union. This gets the type entered into our set of
3989 However, if the structure is incomplete (an opaque struct/union)
3990 then suppress creating a symbol table entry for it since gdb only
3991 wants to find the one with the complete definition. Note that if
3992 it is complete, we just call new_symbol, which does it's own
3993 checking about whether the struct/union is anonymous or not (and
3994 suppresses creating a symbol table entry itself). */
3996 static struct type
*
3997 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3999 struct objfile
*objfile
= cu
->objfile
;
4001 struct attribute
*attr
;
4003 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4005 type
= quirk_gcc_member_function_pointer (die
, cu
);
4009 type
= alloc_type (objfile
);
4010 INIT_CPLUS_SPECIFIC (type
);
4011 name
= dwarf2_name (die
, cu
);
4014 if (cu
->language
== language_cplus
4015 || cu
->language
== language_java
)
4017 const char *new_prefix
= determine_class_name (die
, cu
);
4018 TYPE_TAG_NAME (type
) = (char *) new_prefix
;
4022 /* The name is already allocated along with this objfile, so
4023 we don't need to duplicate it for the type. */
4024 TYPE_TAG_NAME (type
) = name
;
4028 if (die
->tag
== DW_TAG_structure_type
)
4030 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
4032 else if (die
->tag
== DW_TAG_union_type
)
4034 TYPE_CODE (type
) = TYPE_CODE_UNION
;
4038 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
4040 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
4043 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4046 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4050 TYPE_LENGTH (type
) = 0;
4053 TYPE_STUB_SUPPORTED (type
) = 1;
4054 if (die_is_declaration (die
, cu
))
4055 TYPE_STUB (type
) = 1;
4057 /* We need to add the type field to the die immediately so we don't
4058 infinitely recurse when dealing with pointers to the structure
4059 type within the structure itself. */
4060 set_die_type (die
, type
, cu
);
4062 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
4064 struct field_info fi
;
4065 struct die_info
*child_die
;
4067 memset (&fi
, 0, sizeof (struct field_info
));
4069 child_die
= die
->child
;
4071 while (child_die
&& child_die
->tag
)
4073 if (child_die
->tag
== DW_TAG_member
4074 || child_die
->tag
== DW_TAG_variable
)
4076 /* NOTE: carlton/2002-11-05: A C++ static data member
4077 should be a DW_TAG_member that is a declaration, but
4078 all versions of G++ as of this writing (so through at
4079 least 3.2.1) incorrectly generate DW_TAG_variable
4080 tags for them instead. */
4081 dwarf2_add_field (&fi
, child_die
, cu
);
4083 else if (child_die
->tag
== DW_TAG_subprogram
)
4085 /* C++ member function. */
4086 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
4088 else if (child_die
->tag
== DW_TAG_inheritance
)
4090 /* C++ base class field. */
4091 dwarf2_add_field (&fi
, child_die
, cu
);
4093 child_die
= sibling_die (child_die
);
4096 /* Attach fields and member functions to the type. */
4098 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
4101 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
4103 /* Get the type which refers to the base class (possibly this
4104 class itself) which contains the vtable pointer for the current
4105 class from the DW_AT_containing_type attribute. */
4107 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4109 struct type
*t
= die_containing_type (die
, cu
);
4111 TYPE_VPTR_BASETYPE (type
) = t
;
4116 /* Our own class provides vtbl ptr. */
4117 for (i
= TYPE_NFIELDS (t
) - 1;
4118 i
>= TYPE_N_BASECLASSES (t
);
4121 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
4123 if (is_vtable_name (fieldname
, cu
))
4125 TYPE_VPTR_FIELDNO (type
) = i
;
4130 /* Complain if virtual function table field not found. */
4131 if (i
< TYPE_N_BASECLASSES (t
))
4132 complaint (&symfile_complaints
,
4133 _("virtual function table pointer not found when defining class '%s'"),
4134 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
4139 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
4142 else if (cu
->producer
4143 && strncmp (cu
->producer
,
4144 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
4146 /* The IBM XLC compiler does not provide direct indication
4147 of the containing type, but the vtable pointer is
4148 always named __vfp. */
4152 for (i
= TYPE_NFIELDS (type
) - 1;
4153 i
>= TYPE_N_BASECLASSES (type
);
4156 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
4158 TYPE_VPTR_FIELDNO (type
) = i
;
4159 TYPE_VPTR_BASETYPE (type
) = type
;
4167 do_cleanups (back_to
);
4172 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4174 struct objfile
*objfile
= cu
->objfile
;
4175 struct die_info
*child_die
= die
->child
;
4176 struct type
*this_type
;
4178 this_type
= get_die_type (die
, cu
);
4179 if (this_type
== NULL
)
4180 this_type
= read_structure_type (die
, cu
);
4182 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
4183 snapshots) has been known to create a die giving a declaration
4184 for a class that has, as a child, a die giving a definition for a
4185 nested class. So we have to process our children even if the
4186 current die is a declaration. Normally, of course, a declaration
4187 won't have any children at all. */
4189 while (child_die
!= NULL
&& child_die
->tag
)
4191 if (child_die
->tag
== DW_TAG_member
4192 || child_die
->tag
== DW_TAG_variable
4193 || child_die
->tag
== DW_TAG_inheritance
)
4198 process_die (child_die
, cu
);
4200 child_die
= sibling_die (child_die
);
4203 /* Do not consider external references. According to the DWARF standard,
4204 these DIEs are identified by the fact that they have no byte_size
4205 attribute, and a declaration attribute. */
4206 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
4207 || !die_is_declaration (die
, cu
))
4208 new_symbol (die
, this_type
, cu
);
4211 /* Given a DW_AT_enumeration_type die, set its type. We do not
4212 complete the type's fields yet, or create any symbols. */
4214 static struct type
*
4215 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4217 struct objfile
*objfile
= cu
->objfile
;
4219 struct attribute
*attr
;
4222 type
= alloc_type (objfile
);
4224 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4225 name
= dwarf2_full_name (die
, cu
);
4227 TYPE_TAG_NAME (type
) = (char *) name
;
4229 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4232 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4236 TYPE_LENGTH (type
) = 0;
4239 /* The enumeration DIE can be incomplete. In Ada, any type can be
4240 declared as private in the package spec, and then defined only
4241 inside the package body. Such types are known as Taft Amendment
4242 Types. When another package uses such a type, an incomplete DIE
4243 may be generated by the compiler. */
4244 if (die_is_declaration (die
, cu
))
4245 TYPE_STUB (type
) = 1;
4247 return set_die_type (die
, type
, cu
);
4250 /* Determine the name of the type represented by DIE, which should be
4251 a named C++ or Java compound type. Return the name in question,
4252 allocated on the objfile obstack. */
4255 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
4257 const char *new_prefix
= NULL
;
4259 /* If we don't have namespace debug info, guess the name by trying
4260 to demangle the names of members, just like we did in
4261 guess_structure_name. */
4262 if (!processing_has_namespace_info
)
4264 struct die_info
*child
;
4266 for (child
= die
->child
;
4267 child
!= NULL
&& child
->tag
!= 0;
4268 child
= sibling_die (child
))
4270 if (child
->tag
== DW_TAG_subprogram
)
4273 = language_class_name_from_physname (cu
->language_defn
,
4277 if (phys_prefix
!= NULL
)
4280 = obsavestring (phys_prefix
, strlen (phys_prefix
),
4281 &cu
->objfile
->objfile_obstack
);
4282 xfree (phys_prefix
);
4289 if (new_prefix
== NULL
)
4290 new_prefix
= dwarf2_full_name (die
, cu
);
4295 /* Given a pointer to a die which begins an enumeration, process all
4296 the dies that define the members of the enumeration, and create the
4297 symbol for the enumeration type.
4299 NOTE: We reverse the order of the element list. */
4302 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4304 struct objfile
*objfile
= cu
->objfile
;
4305 struct die_info
*child_die
;
4306 struct field
*fields
;
4309 int unsigned_enum
= 1;
4311 struct type
*this_type
;
4315 this_type
= get_die_type (die
, cu
);
4316 if (this_type
== NULL
)
4317 this_type
= read_enumeration_type (die
, cu
);
4318 if (die
->child
!= NULL
)
4320 child_die
= die
->child
;
4321 while (child_die
&& child_die
->tag
)
4323 if (child_die
->tag
!= DW_TAG_enumerator
)
4325 process_die (child_die
, cu
);
4329 name
= dwarf2_name (child_die
, cu
);
4332 sym
= new_symbol (child_die
, this_type
, cu
);
4333 if (SYMBOL_VALUE (sym
) < 0)
4336 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4338 fields
= (struct field
*)
4340 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
4341 * sizeof (struct field
));
4344 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
4345 FIELD_TYPE (fields
[num_fields
]) = NULL
;
4346 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
4347 FIELD_BITSIZE (fields
[num_fields
]) = 0;
4348 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
4354 child_die
= sibling_die (child_die
);
4359 TYPE_NFIELDS (this_type
) = num_fields
;
4360 TYPE_FIELDS (this_type
) = (struct field
*)
4361 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
4362 memcpy (TYPE_FIELDS (this_type
), fields
,
4363 sizeof (struct field
) * num_fields
);
4367 TYPE_UNSIGNED (this_type
) = 1;
4370 new_symbol (die
, this_type
, cu
);
4373 /* Extract all information from a DW_TAG_array_type DIE and put it in
4374 the DIE's type field. For now, this only handles one dimensional
4377 static struct type
*
4378 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4380 struct objfile
*objfile
= cu
->objfile
;
4381 struct die_info
*child_die
;
4382 struct type
*type
= NULL
;
4383 struct type
*element_type
, *range_type
, *index_type
;
4384 struct type
**range_types
= NULL
;
4385 struct attribute
*attr
;
4387 struct cleanup
*back_to
;
4390 element_type
= die_type (die
, cu
);
4392 /* Irix 6.2 native cc creates array types without children for
4393 arrays with unspecified length. */
4394 if (die
->child
== NULL
)
4396 index_type
= builtin_type_int32
;
4397 range_type
= create_range_type (NULL
, index_type
, 0, -1);
4398 type
= create_array_type (NULL
, element_type
, range_type
);
4399 return set_die_type (die
, type
, cu
);
4402 back_to
= make_cleanup (null_cleanup
, NULL
);
4403 child_die
= die
->child
;
4404 while (child_die
&& child_die
->tag
)
4406 if (child_die
->tag
== DW_TAG_subrange_type
)
4408 struct type
*child_type
= read_type_die (child_die
, cu
);
4409 if (child_type
!= NULL
)
4411 /* The range type was succesfully read. Save it for
4412 the array type creation. */
4413 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
4415 range_types
= (struct type
**)
4416 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
4417 * sizeof (struct type
*));
4419 make_cleanup (free_current_contents
, &range_types
);
4421 range_types
[ndim
++] = child_type
;
4424 child_die
= sibling_die (child_die
);
4427 /* Dwarf2 dimensions are output from left to right, create the
4428 necessary array types in backwards order. */
4430 type
= element_type
;
4432 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
4436 type
= create_array_type (NULL
, type
, range_types
[i
++]);
4441 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
4444 /* Understand Dwarf2 support for vector types (like they occur on
4445 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4446 array type. This is not part of the Dwarf2/3 standard yet, but a
4447 custom vendor extension. The main difference between a regular
4448 array and the vector variant is that vectors are passed by value
4450 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4452 make_vector_type (type
);
4454 name
= dwarf2_name (die
, cu
);
4456 TYPE_NAME (type
) = name
;
4458 do_cleanups (back_to
);
4460 /* Install the type in the die. */
4461 return set_die_type (die
, type
, cu
);
4464 static enum dwarf_array_dim_ordering
4465 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4467 struct attribute
*attr
;
4469 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4471 if (attr
) return DW_SND (attr
);
4474 GNU F77 is a special case, as at 08/2004 array type info is the
4475 opposite order to the dwarf2 specification, but data is still
4476 laid out as per normal fortran.
4478 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4482 if (cu
->language
== language_fortran
&&
4483 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4485 return DW_ORD_row_major
;
4488 switch (cu
->language_defn
->la_array_ordering
)
4490 case array_column_major
:
4491 return DW_ORD_col_major
;
4492 case array_row_major
:
4494 return DW_ORD_row_major
;
4498 /* Extract all information from a DW_TAG_set_type DIE and put it in
4499 the DIE's type field. */
4501 static struct type
*
4502 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4504 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
4506 return set_die_type (die
, set_type
, cu
);
4509 /* First cut: install each common block member as a global variable. */
4512 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4514 struct die_info
*child_die
;
4515 struct attribute
*attr
;
4517 CORE_ADDR base
= (CORE_ADDR
) 0;
4519 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4522 /* Support the .debug_loc offsets */
4523 if (attr_form_is_block (attr
))
4525 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4527 else if (attr_form_is_section_offset (attr
))
4529 dwarf2_complex_location_expr_complaint ();
4533 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4534 "common block member");
4537 if (die
->child
!= NULL
)
4539 child_die
= die
->child
;
4540 while (child_die
&& child_die
->tag
)
4542 sym
= new_symbol (child_die
, NULL
, cu
);
4543 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4546 SYMBOL_VALUE_ADDRESS (sym
) =
4547 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4548 add_symbol_to_list (sym
, &global_symbols
);
4550 child_die
= sibling_die (child_die
);
4555 /* Create a type for a C++ namespace. */
4557 static struct type
*
4558 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4560 struct objfile
*objfile
= cu
->objfile
;
4561 const char *previous_prefix
, *name
;
4565 /* For extensions, reuse the type of the original namespace. */
4566 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
4568 struct die_info
*ext_die
;
4569 struct dwarf2_cu
*ext_cu
= cu
;
4570 ext_die
= dwarf2_extension (die
, &ext_cu
);
4571 type
= read_type_die (ext_die
, ext_cu
);
4572 return set_die_type (die
, type
, cu
);
4575 name
= namespace_name (die
, &is_anonymous
, cu
);
4577 /* Now build the name of the current namespace. */
4579 previous_prefix
= determine_prefix (die
, cu
);
4580 if (previous_prefix
[0] != '\0')
4581 name
= typename_concat (&objfile
->objfile_obstack
,
4582 previous_prefix
, name
, cu
);
4584 /* Create the type. */
4585 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
4587 TYPE_NAME (type
) = (char *) name
;
4588 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4590 set_die_type (die
, type
, cu
);
4595 /* Read a C++ namespace. */
4598 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4600 struct objfile
*objfile
= cu
->objfile
;
4604 /* Add a symbol associated to this if we haven't seen the namespace
4605 before. Also, add a using directive if it's an anonymous
4608 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
4612 type
= read_type_die (die
, cu
);
4613 new_symbol (die
, type
, cu
);
4615 name
= namespace_name (die
, &is_anonymous
, cu
);
4618 const char *previous_prefix
= determine_prefix (die
, cu
);
4619 cp_add_using_directive (TYPE_NAME (type
),
4620 strlen (previous_prefix
),
4621 strlen (TYPE_NAME (type
)));
4625 if (die
->child
!= NULL
)
4627 struct die_info
*child_die
= die
->child
;
4629 while (child_die
&& child_die
->tag
)
4631 process_die (child_die
, cu
);
4632 child_die
= sibling_die (child_die
);
4637 /* Return the name of the namespace represented by DIE. Set
4638 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4642 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
4644 struct die_info
*current_die
;
4645 const char *name
= NULL
;
4647 /* Loop through the extensions until we find a name. */
4649 for (current_die
= die
;
4650 current_die
!= NULL
;
4651 current_die
= dwarf2_extension (die
, &cu
))
4653 name
= dwarf2_name (current_die
, cu
);
4658 /* Is it an anonymous namespace? */
4660 *is_anonymous
= (name
== NULL
);
4662 name
= "(anonymous namespace)";
4667 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4668 the user defined type vector. */
4670 static struct type
*
4671 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4673 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
4674 struct comp_unit_head
*cu_header
= &cu
->header
;
4676 struct attribute
*attr_byte_size
;
4677 struct attribute
*attr_address_class
;
4678 int byte_size
, addr_class
;
4680 type
= lookup_pointer_type (die_type (die
, cu
));
4682 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4684 byte_size
= DW_UNSND (attr_byte_size
);
4686 byte_size
= cu_header
->addr_size
;
4688 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
4689 if (attr_address_class
)
4690 addr_class
= DW_UNSND (attr_address_class
);
4692 addr_class
= DW_ADDR_none
;
4694 /* If the pointer size or address class is different than the
4695 default, create a type variant marked as such and set the
4696 length accordingly. */
4697 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
4699 if (gdbarch_address_class_type_flags_p (gdbarch
))
4703 type_flags
= gdbarch_address_class_type_flags
4704 (gdbarch
, byte_size
, addr_class
);
4705 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
4707 type
= make_type_with_address_space (type
, type_flags
);
4709 else if (TYPE_LENGTH (type
) != byte_size
)
4711 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
4714 /* Should we also complain about unhandled address classes? */
4718 TYPE_LENGTH (type
) = byte_size
;
4719 return set_die_type (die
, type
, cu
);
4722 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4723 the user defined type vector. */
4725 static struct type
*
4726 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4728 struct objfile
*objfile
= cu
->objfile
;
4730 struct type
*to_type
;
4731 struct type
*domain
;
4733 to_type
= die_type (die
, cu
);
4734 domain
= die_containing_type (die
, cu
);
4736 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
4737 type
= lookup_methodptr_type (to_type
);
4739 type
= lookup_memberptr_type (to_type
, domain
);
4741 return set_die_type (die
, type
, cu
);
4744 /* Extract all information from a DW_TAG_reference_type DIE and add to
4745 the user defined type vector. */
4747 static struct type
*
4748 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4750 struct comp_unit_head
*cu_header
= &cu
->header
;
4752 struct attribute
*attr
;
4754 type
= lookup_reference_type (die_type (die
, cu
));
4755 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4758 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4762 TYPE_LENGTH (type
) = cu_header
->addr_size
;
4764 return set_die_type (die
, type
, cu
);
4767 static struct type
*
4768 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4770 struct type
*base_type
, *cv_type
;
4772 base_type
= die_type (die
, cu
);
4773 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
4774 return set_die_type (die
, cv_type
, cu
);
4777 static struct type
*
4778 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4780 struct type
*base_type
, *cv_type
;
4782 base_type
= die_type (die
, cu
);
4783 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
4784 return set_die_type (die
, cv_type
, cu
);
4787 /* Extract all information from a DW_TAG_string_type DIE and add to
4788 the user defined type vector. It isn't really a user defined type,
4789 but it behaves like one, with other DIE's using an AT_user_def_type
4790 attribute to reference it. */
4792 static struct type
*
4793 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4795 struct objfile
*objfile
= cu
->objfile
;
4796 struct type
*type
, *range_type
, *index_type
, *char_type
;
4797 struct attribute
*attr
;
4798 unsigned int length
;
4800 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4803 length
= DW_UNSND (attr
);
4807 /* check for the DW_AT_byte_size attribute */
4808 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4811 length
= DW_UNSND (attr
);
4819 index_type
= builtin_type_int32
;
4820 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4821 type
= create_string_type (NULL
, range_type
);
4823 return set_die_type (die
, type
, cu
);
4826 /* Handle DIES due to C code like:
4830 int (*funcp)(int a, long l);
4834 ('funcp' generates a DW_TAG_subroutine_type DIE)
4837 static struct type
*
4838 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4840 struct type
*type
; /* Type that this function returns */
4841 struct type
*ftype
; /* Function that returns above type */
4842 struct attribute
*attr
;
4844 type
= die_type (die
, cu
);
4845 ftype
= make_function_type (type
, (struct type
**) 0);
4847 /* All functions in C++, Pascal and Java have prototypes. */
4848 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4849 if ((attr
&& (DW_UNSND (attr
) != 0))
4850 || cu
->language
== language_cplus
4851 || cu
->language
== language_java
4852 || cu
->language
== language_pascal
)
4853 TYPE_PROTOTYPED (ftype
) = 1;
4855 /* Store the calling convention in the type if it's available in
4856 the subroutine die. Otherwise set the calling convention to
4857 the default value DW_CC_normal. */
4858 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
4859 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
4861 if (die
->child
!= NULL
)
4863 struct die_info
*child_die
;
4867 /* Count the number of parameters.
4868 FIXME: GDB currently ignores vararg functions, but knows about
4869 vararg member functions. */
4870 child_die
= die
->child
;
4871 while (child_die
&& child_die
->tag
)
4873 if (child_die
->tag
== DW_TAG_formal_parameter
)
4875 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4876 TYPE_VARARGS (ftype
) = 1;
4877 child_die
= sibling_die (child_die
);
4880 /* Allocate storage for parameters and fill them in. */
4881 TYPE_NFIELDS (ftype
) = nparams
;
4882 TYPE_FIELDS (ftype
) = (struct field
*)
4883 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
4885 child_die
= die
->child
;
4886 while (child_die
&& child_die
->tag
)
4888 if (child_die
->tag
== DW_TAG_formal_parameter
)
4890 /* Dwarf2 has no clean way to discern C++ static and non-static
4891 member functions. G++ helps GDB by marking the first
4892 parameter for non-static member functions (which is the
4893 this pointer) as artificial. We pass this information
4894 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4895 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
4897 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
4899 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
4900 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
4903 child_die
= sibling_die (child_die
);
4907 return set_die_type (die
, ftype
, cu
);
4910 static struct type
*
4911 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
4913 struct objfile
*objfile
= cu
->objfile
;
4914 struct attribute
*attr
;
4915 const char *name
= NULL
;
4916 struct type
*this_type
;
4918 name
= dwarf2_full_name (die
, cu
);
4919 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
4920 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
4921 TYPE_NAME (this_type
) = (char *) name
;
4922 set_die_type (die
, this_type
, cu
);
4923 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
4927 /* Find a representation of a given base type and install
4928 it in the TYPE field of the die. */
4930 static struct type
*
4931 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4933 struct objfile
*objfile
= cu
->objfile
;
4935 struct attribute
*attr
;
4936 int encoding
= 0, size
= 0;
4938 enum type_code code
= TYPE_CODE_INT
;
4940 struct type
*target_type
= NULL
;
4942 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
4945 encoding
= DW_UNSND (attr
);
4947 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4950 size
= DW_UNSND (attr
);
4952 name
= dwarf2_name (die
, cu
);
4955 complaint (&symfile_complaints
,
4956 _("DW_AT_name missing from DW_TAG_base_type"));
4961 case DW_ATE_address
:
4962 /* Turn DW_ATE_address into a void * pointer. */
4963 code
= TYPE_CODE_PTR
;
4964 type_flags
|= TYPE_FLAG_UNSIGNED
;
4965 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
4967 case DW_ATE_boolean
:
4968 code
= TYPE_CODE_BOOL
;
4969 type_flags
|= TYPE_FLAG_UNSIGNED
;
4971 case DW_ATE_complex_float
:
4972 code
= TYPE_CODE_COMPLEX
;
4973 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
4975 case DW_ATE_decimal_float
:
4976 code
= TYPE_CODE_DECFLOAT
;
4979 code
= TYPE_CODE_FLT
;
4983 case DW_ATE_unsigned
:
4984 type_flags
|= TYPE_FLAG_UNSIGNED
;
4986 case DW_ATE_signed_char
:
4987 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
4988 code
= TYPE_CODE_CHAR
;
4990 case DW_ATE_unsigned_char
:
4991 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
4992 code
= TYPE_CODE_CHAR
;
4993 type_flags
|= TYPE_FLAG_UNSIGNED
;
4996 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
4997 dwarf_type_encoding_name (encoding
));
5001 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
5002 TYPE_NAME (type
) = name
;
5003 TYPE_TARGET_TYPE (type
) = target_type
;
5005 if (name
&& strcmp (name
, "char") == 0)
5006 TYPE_NOSIGN (type
) = 1;
5008 return set_die_type (die
, type
, cu
);
5011 /* Read the given DW_AT_subrange DIE. */
5013 static struct type
*
5014 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5016 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5017 struct type
*base_type
;
5018 struct type
*range_type
;
5019 struct attribute
*attr
;
5024 base_type
= die_type (die
, cu
);
5025 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
5027 complaint (&symfile_complaints
,
5028 _("DW_AT_type missing from DW_TAG_subrange_type"));
5030 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
5031 0, NULL
, cu
->objfile
);
5034 if (cu
->language
== language_fortran
)
5036 /* FORTRAN implies a lower bound of 1, if not given. */
5040 /* FIXME: For variable sized arrays either of these could be
5041 a variable rather than a constant value. We'll allow it,
5042 but we don't know how to handle it. */
5043 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
5045 low
= dwarf2_get_attr_constant_value (attr
, 0);
5047 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
5050 if (attr
->form
== DW_FORM_block1
)
5052 /* GCC encodes arrays with unspecified or dynamic length
5053 with a DW_FORM_block1 attribute.
5054 FIXME: GDB does not yet know how to handle dynamic
5055 arrays properly, treat them as arrays with unspecified
5058 FIXME: jimb/2003-09-22: GDB does not really know
5059 how to handle arrays of unspecified length
5060 either; we just represent them as zero-length
5061 arrays. Choose an appropriate upper bound given
5062 the lower bound we've computed above. */
5066 high
= dwarf2_get_attr_constant_value (attr
, 1);
5069 range_type
= create_range_type (NULL
, base_type
, low
, high
);
5071 name
= dwarf2_name (die
, cu
);
5073 TYPE_NAME (range_type
) = name
;
5075 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5077 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
5079 return set_die_type (die
, range_type
, cu
);
5082 static struct type
*
5083 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5087 /* For now, we only support the C meaning of an unspecified type: void. */
5089 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
5090 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
5092 return set_die_type (die
, type
, cu
);
5095 /* Trivial hash function for die_info: the hash value of a DIE
5096 is its offset in .debug_info for this objfile. */
5099 die_hash (const void *item
)
5101 const struct die_info
*die
= item
;
5105 /* Trivial comparison function for die_info structures: two DIEs
5106 are equal if they have the same offset. */
5109 die_eq (const void *item_lhs
, const void *item_rhs
)
5111 const struct die_info
*die_lhs
= item_lhs
;
5112 const struct die_info
*die_rhs
= item_rhs
;
5113 return die_lhs
->offset
== die_rhs
->offset
;
5116 /* Read a whole compilation unit into a linked list of dies. */
5118 static struct die_info
*
5119 read_comp_unit (gdb_byte
*info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
5122 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5126 &cu
->comp_unit_obstack
,
5127 hashtab_obstack_allocate
,
5128 dummy_obstack_deallocate
);
5130 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
5133 /* Read a single die and all its descendents. Set the die's sibling
5134 field to NULL; set other fields in the die correctly, and set all
5135 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
5136 location of the info_ptr after reading all of those dies. PARENT
5137 is the parent of the die in question. */
5139 static struct die_info
*
5140 read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
5141 struct dwarf2_cu
*cu
,
5142 gdb_byte
**new_info_ptr
,
5143 struct die_info
*parent
)
5145 struct die_info
*die
;
5149 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
5152 *new_info_ptr
= cur_ptr
;
5155 store_in_ref_table (die
, cu
);
5159 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
5165 *new_info_ptr
= cur_ptr
;
5168 die
->sibling
= NULL
;
5169 die
->parent
= parent
;
5173 /* Read a die, all of its descendents, and all of its siblings; set
5174 all of the fields of all of the dies correctly. Arguments are as
5175 in read_die_and_children. */
5177 static struct die_info
*
5178 read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
5179 struct dwarf2_cu
*cu
,
5180 gdb_byte
**new_info_ptr
,
5181 struct die_info
*parent
)
5183 struct die_info
*first_die
, *last_sibling
;
5187 first_die
= last_sibling
= NULL
;
5191 struct die_info
*die
5192 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
5196 *new_info_ptr
= cur_ptr
;
5203 last_sibling
->sibling
= die
;
5209 /* Decompress a section that was compressed using zlib. Store the
5210 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
5213 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
5214 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
5216 bfd
*abfd
= objfile
->obfd
;
5218 error (_("Support for zlib-compressed DWARF data (from '%s') "
5219 "is disabled in this copy of GDB"),
5220 bfd_get_filename (abfd
));
5222 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
5223 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
5224 bfd_size_type uncompressed_size
;
5225 gdb_byte
*uncompressed_buffer
;
5228 int header_size
= 12;
5230 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5231 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
5232 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5233 bfd_get_filename (abfd
));
5235 /* Read the zlib header. In this case, it should be "ZLIB" followed
5236 by the uncompressed section size, 8 bytes in big-endian order. */
5237 if (compressed_size
< header_size
5238 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
5239 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
5240 bfd_get_filename (abfd
));
5241 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
5242 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
5243 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
5244 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
5245 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
5246 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
5247 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
5248 uncompressed_size
+= compressed_buffer
[11];
5250 /* It is possible the section consists of several compressed
5251 buffers concatenated together, so we uncompress in a loop. */
5255 strm
.avail_in
= compressed_size
- header_size
;
5256 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
5257 strm
.avail_out
= uncompressed_size
;
5258 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
5260 rc
= inflateInit (&strm
);
5261 while (strm
.avail_in
> 0)
5264 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
5265 bfd_get_filename (abfd
), rc
);
5266 strm
.next_out
= ((Bytef
*) uncompressed_buffer
5267 + (uncompressed_size
- strm
.avail_out
));
5268 rc
= inflate (&strm
, Z_FINISH
);
5269 if (rc
!= Z_STREAM_END
)
5270 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
5271 bfd_get_filename (abfd
), rc
);
5272 rc
= inflateReset (&strm
);
5274 rc
= inflateEnd (&strm
);
5276 || strm
.avail_out
!= 0)
5277 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
5278 bfd_get_filename (abfd
), rc
);
5280 xfree (compressed_buffer
);
5281 *outbuf
= uncompressed_buffer
;
5282 *outsize
= uncompressed_size
;
5287 /* Read the contents of the section at OFFSET and of size SIZE from the
5288 object file specified by OBJFILE into the objfile_obstack and return it.
5289 If the section is compressed, uncompress it before returning. */
5292 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
5294 bfd
*abfd
= objfile
->obfd
;
5295 gdb_byte
*buf
, *retbuf
;
5296 bfd_size_type size
= bfd_get_section_size (sectp
);
5297 unsigned char header
[4];
5302 /* Check if the file has a 4-byte header indicating compression. */
5303 if (size
> sizeof (header
)
5304 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
5305 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
5307 /* Upon decompression, update the buffer and its size. */
5308 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
5310 zlib_decompress_section (objfile
, sectp
, &buf
, &size
);
5311 dwarf2_resize_section (sectp
, size
);
5316 /* If we get here, we are a normal, not-compressed section. */
5317 buf
= obstack_alloc (&objfile
->objfile_obstack
, size
);
5318 /* When debugging .o files, we may need to apply relocations; see
5319 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
5320 We never compress sections in .o files, so we only need to
5321 try this when the section is not compressed. */
5322 retbuf
= symfile_relocate_debug_section (abfd
, sectp
, buf
);
5326 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5327 || bfd_bread (buf
, size
, abfd
) != size
)
5328 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5329 bfd_get_filename (abfd
));
5334 /* In DWARF version 2, the description of the debugging information is
5335 stored in a separate .debug_abbrev section. Before we read any
5336 dies from a section we read in all abbreviations and install them
5337 in a hash table. This function also sets flags in CU describing
5338 the data found in the abbrev table. */
5341 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
5343 struct comp_unit_head
*cu_header
= &cu
->header
;
5344 gdb_byte
*abbrev_ptr
;
5345 struct abbrev_info
*cur_abbrev
;
5346 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
5347 unsigned int abbrev_form
, hash_number
;
5348 struct attr_abbrev
*cur_attrs
;
5349 unsigned int allocated_attrs
;
5351 /* Initialize dwarf2 abbrevs */
5352 obstack_init (&cu
->abbrev_obstack
);
5353 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
5355 * sizeof (struct abbrev_info
*)));
5356 memset (cu
->dwarf2_abbrevs
, 0,
5357 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
5359 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
5360 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5361 abbrev_ptr
+= bytes_read
;
5363 allocated_attrs
= ATTR_ALLOC_CHUNK
;
5364 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
5366 /* loop until we reach an abbrev number of 0 */
5367 while (abbrev_number
)
5369 cur_abbrev
= dwarf_alloc_abbrev (cu
);
5371 /* read in abbrev header */
5372 cur_abbrev
->number
= abbrev_number
;
5373 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5374 abbrev_ptr
+= bytes_read
;
5375 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
5378 if (cur_abbrev
->tag
== DW_TAG_namespace
)
5379 cu
->has_namespace_info
= 1;
5381 /* now read in declarations */
5382 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5383 abbrev_ptr
+= bytes_read
;
5384 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5385 abbrev_ptr
+= bytes_read
;
5388 if (cur_abbrev
->num_attrs
== allocated_attrs
)
5390 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
5392 = xrealloc (cur_attrs
, (allocated_attrs
5393 * sizeof (struct attr_abbrev
)));
5396 /* Record whether this compilation unit might have
5397 inter-compilation-unit references. If we don't know what form
5398 this attribute will have, then it might potentially be a
5399 DW_FORM_ref_addr, so we conservatively expect inter-CU
5402 if (abbrev_form
== DW_FORM_ref_addr
5403 || abbrev_form
== DW_FORM_indirect
)
5404 cu
->has_form_ref_addr
= 1;
5406 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
5407 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
5408 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5409 abbrev_ptr
+= bytes_read
;
5410 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5411 abbrev_ptr
+= bytes_read
;
5414 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
5415 (cur_abbrev
->num_attrs
5416 * sizeof (struct attr_abbrev
)));
5417 memcpy (cur_abbrev
->attrs
, cur_attrs
,
5418 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
5420 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
5421 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
5422 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
5424 /* Get next abbreviation.
5425 Under Irix6 the abbreviations for a compilation unit are not
5426 always properly terminated with an abbrev number of 0.
5427 Exit loop if we encounter an abbreviation which we have
5428 already read (which means we are about to read the abbreviations
5429 for the next compile unit) or if the end of the abbreviation
5430 table is reached. */
5431 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
5432 >= dwarf2_per_objfile
->abbrev_size
)
5434 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5435 abbrev_ptr
+= bytes_read
;
5436 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
5443 /* Release the memory used by the abbrev table for a compilation unit. */
5446 dwarf2_free_abbrev_table (void *ptr_to_cu
)
5448 struct dwarf2_cu
*cu
= ptr_to_cu
;
5450 obstack_free (&cu
->abbrev_obstack
, NULL
);
5451 cu
->dwarf2_abbrevs
= NULL
;
5454 /* Lookup an abbrev_info structure in the abbrev hash table. */
5456 static struct abbrev_info
*
5457 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
5459 unsigned int hash_number
;
5460 struct abbrev_info
*abbrev
;
5462 hash_number
= number
% ABBREV_HASH_SIZE
;
5463 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
5467 if (abbrev
->number
== number
)
5470 abbrev
= abbrev
->next
;
5475 /* Returns nonzero if TAG represents a type that we might generate a partial
5479 is_type_tag_for_partial (int tag
)
5484 /* Some types that would be reasonable to generate partial symbols for,
5485 that we don't at present. */
5486 case DW_TAG_array_type
:
5487 case DW_TAG_file_type
:
5488 case DW_TAG_ptr_to_member_type
:
5489 case DW_TAG_set_type
:
5490 case DW_TAG_string_type
:
5491 case DW_TAG_subroutine_type
:
5493 case DW_TAG_base_type
:
5494 case DW_TAG_class_type
:
5495 case DW_TAG_interface_type
:
5496 case DW_TAG_enumeration_type
:
5497 case DW_TAG_structure_type
:
5498 case DW_TAG_subrange_type
:
5499 case DW_TAG_typedef
:
5500 case DW_TAG_union_type
:
5507 /* Load all DIEs that are interesting for partial symbols into memory. */
5509 static struct partial_die_info
*
5510 load_partial_dies (bfd
*abfd
, gdb_byte
*info_ptr
, int building_psymtab
,
5511 struct dwarf2_cu
*cu
)
5513 struct partial_die_info
*part_die
;
5514 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
5515 struct abbrev_info
*abbrev
;
5516 unsigned int bytes_read
;
5517 unsigned int load_all
= 0;
5519 int nesting_level
= 1;
5524 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
5528 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5532 &cu
->comp_unit_obstack
,
5533 hashtab_obstack_allocate
,
5534 dummy_obstack_deallocate
);
5536 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5537 sizeof (struct partial_die_info
));
5541 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5543 /* A NULL abbrev means the end of a series of children. */
5546 if (--nesting_level
== 0)
5548 /* PART_DIE was probably the last thing allocated on the
5549 comp_unit_obstack, so we could call obstack_free
5550 here. We don't do that because the waste is small,
5551 and will be cleaned up when we're done with this
5552 compilation unit. This way, we're also more robust
5553 against other users of the comp_unit_obstack. */
5556 info_ptr
+= bytes_read
;
5557 last_die
= parent_die
;
5558 parent_die
= parent_die
->die_parent
;
5562 /* Check whether this DIE is interesting enough to save. Normally
5563 we would not be interested in members here, but there may be
5564 later variables referencing them via DW_AT_specification (for
5567 && !is_type_tag_for_partial (abbrev
->tag
)
5568 && abbrev
->tag
!= DW_TAG_enumerator
5569 && abbrev
->tag
!= DW_TAG_subprogram
5570 && abbrev
->tag
!= DW_TAG_variable
5571 && abbrev
->tag
!= DW_TAG_namespace
5572 && abbrev
->tag
!= DW_TAG_member
)
5574 /* Otherwise we skip to the next sibling, if any. */
5575 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5579 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5580 abfd
, info_ptr
, cu
);
5582 /* This two-pass algorithm for processing partial symbols has a
5583 high cost in cache pressure. Thus, handle some simple cases
5584 here which cover the majority of C partial symbols. DIEs
5585 which neither have specification tags in them, nor could have
5586 specification tags elsewhere pointing at them, can simply be
5587 processed and discarded.
5589 This segment is also optional; scan_partial_symbols and
5590 add_partial_symbol will handle these DIEs if we chain
5591 them in normally. When compilers which do not emit large
5592 quantities of duplicate debug information are more common,
5593 this code can probably be removed. */
5595 /* Any complete simple types at the top level (pretty much all
5596 of them, for a language without namespaces), can be processed
5598 if (parent_die
== NULL
5599 && part_die
->has_specification
== 0
5600 && part_die
->is_declaration
== 0
5601 && (part_die
->tag
== DW_TAG_typedef
5602 || part_die
->tag
== DW_TAG_base_type
5603 || part_die
->tag
== DW_TAG_subrange_type
))
5605 if (building_psymtab
&& part_die
->name
!= NULL
)
5606 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5607 VAR_DOMAIN
, LOC_TYPEDEF
,
5608 &cu
->objfile
->static_psymbols
,
5609 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5610 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5614 /* If we're at the second level, and we're an enumerator, and
5615 our parent has no specification (meaning possibly lives in a
5616 namespace elsewhere), then we can add the partial symbol now
5617 instead of queueing it. */
5618 if (part_die
->tag
== DW_TAG_enumerator
5619 && parent_die
!= NULL
5620 && parent_die
->die_parent
== NULL
5621 && parent_die
->tag
== DW_TAG_enumeration_type
5622 && parent_die
->has_specification
== 0)
5624 if (part_die
->name
== NULL
)
5625 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5626 else if (building_psymtab
)
5627 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5628 VAR_DOMAIN
, LOC_CONST
,
5629 (cu
->language
== language_cplus
5630 || cu
->language
== language_java
)
5631 ? &cu
->objfile
->global_psymbols
5632 : &cu
->objfile
->static_psymbols
,
5633 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5635 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5639 /* We'll save this DIE so link it in. */
5640 part_die
->die_parent
= parent_die
;
5641 part_die
->die_sibling
= NULL
;
5642 part_die
->die_child
= NULL
;
5644 if (last_die
&& last_die
== parent_die
)
5645 last_die
->die_child
= part_die
;
5647 last_die
->die_sibling
= part_die
;
5649 last_die
= part_die
;
5651 if (first_die
== NULL
)
5652 first_die
= part_die
;
5654 /* Maybe add the DIE to the hash table. Not all DIEs that we
5655 find interesting need to be in the hash table, because we
5656 also have the parent/sibling/child chains; only those that we
5657 might refer to by offset later during partial symbol reading.
5659 For now this means things that might have be the target of a
5660 DW_AT_specification, DW_AT_abstract_origin, or
5661 DW_AT_extension. DW_AT_extension will refer only to
5662 namespaces; DW_AT_abstract_origin refers to functions (and
5663 many things under the function DIE, but we do not recurse
5664 into function DIEs during partial symbol reading) and
5665 possibly variables as well; DW_AT_specification refers to
5666 declarations. Declarations ought to have the DW_AT_declaration
5667 flag. It happens that GCC forgets to put it in sometimes, but
5668 only for functions, not for types.
5670 Adding more things than necessary to the hash table is harmless
5671 except for the performance cost. Adding too few will result in
5672 wasted time in find_partial_die, when we reread the compilation
5673 unit with load_all_dies set. */
5676 || abbrev
->tag
== DW_TAG_subprogram
5677 || abbrev
->tag
== DW_TAG_variable
5678 || abbrev
->tag
== DW_TAG_namespace
5679 || part_die
->is_declaration
)
5683 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
5684 part_die
->offset
, INSERT
);
5688 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5689 sizeof (struct partial_die_info
));
5691 /* For some DIEs we want to follow their children (if any). For C
5692 we have no reason to follow the children of structures; for other
5693 languages we have to, both so that we can get at method physnames
5694 to infer fully qualified class names, and for DW_AT_specification. */
5695 if (last_die
->has_children
5697 || last_die
->tag
== DW_TAG_namespace
5698 || last_die
->tag
== DW_TAG_enumeration_type
5699 || (cu
->language
!= language_c
5700 && (last_die
->tag
== DW_TAG_class_type
5701 || last_die
->tag
== DW_TAG_interface_type
5702 || last_die
->tag
== DW_TAG_structure_type
5703 || last_die
->tag
== DW_TAG_union_type
))))
5706 parent_die
= last_die
;
5710 /* Otherwise we skip to the next sibling, if any. */
5711 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
5713 /* Back to the top, do it again. */
5717 /* Read a minimal amount of information into the minimal die structure. */
5720 read_partial_die (struct partial_die_info
*part_die
,
5721 struct abbrev_info
*abbrev
,
5722 unsigned int abbrev_len
, bfd
*abfd
,
5723 gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
5725 unsigned int bytes_read
, i
;
5726 struct attribute attr
;
5727 int has_low_pc_attr
= 0;
5728 int has_high_pc_attr
= 0;
5729 CORE_ADDR base_address
= 0;
5733 base_address_low_pc
,
5734 /* Overrides BASE_ADDRESS_LOW_PC. */
5735 base_address_entry_pc
5737 base_address_type
= base_address_none
;
5739 memset (part_die
, 0, sizeof (struct partial_die_info
));
5741 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5743 info_ptr
+= abbrev_len
;
5748 part_die
->tag
= abbrev
->tag
;
5749 part_die
->has_children
= abbrev
->has_children
;
5751 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5753 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
5755 /* Store the data if it is of an attribute we want to keep in a
5756 partial symbol table. */
5761 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
5762 if (part_die
->name
== NULL
)
5763 part_die
->name
= DW_STRING (&attr
);
5765 case DW_AT_comp_dir
:
5766 if (part_die
->dirname
== NULL
)
5767 part_die
->dirname
= DW_STRING (&attr
);
5769 case DW_AT_MIPS_linkage_name
:
5770 part_die
->name
= DW_STRING (&attr
);
5773 has_low_pc_attr
= 1;
5774 part_die
->lowpc
= DW_ADDR (&attr
);
5775 if (part_die
->tag
== DW_TAG_compile_unit
5776 && base_address_type
< base_address_low_pc
)
5778 base_address
= DW_ADDR (&attr
);
5779 base_address_type
= base_address_low_pc
;
5783 has_high_pc_attr
= 1;
5784 part_die
->highpc
= DW_ADDR (&attr
);
5786 case DW_AT_entry_pc
:
5787 if (part_die
->tag
== DW_TAG_compile_unit
5788 && base_address_type
< base_address_entry_pc
)
5790 base_address
= DW_ADDR (&attr
);
5791 base_address_type
= base_address_entry_pc
;
5795 if (part_die
->tag
== DW_TAG_compile_unit
)
5797 cu
->ranges_offset
= DW_UNSND (&attr
);
5798 cu
->has_ranges_offset
= 1;
5801 case DW_AT_location
:
5802 /* Support the .debug_loc offsets */
5803 if (attr_form_is_block (&attr
))
5805 part_die
->locdesc
= DW_BLOCK (&attr
);
5807 else if (attr_form_is_section_offset (&attr
))
5809 dwarf2_complex_location_expr_complaint ();
5813 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5814 "partial symbol information");
5817 case DW_AT_language
:
5818 part_die
->language
= DW_UNSND (&attr
);
5820 case DW_AT_external
:
5821 part_die
->is_external
= DW_UNSND (&attr
);
5823 case DW_AT_declaration
:
5824 part_die
->is_declaration
= DW_UNSND (&attr
);
5827 part_die
->has_type
= 1;
5829 case DW_AT_abstract_origin
:
5830 case DW_AT_specification
:
5831 case DW_AT_extension
:
5832 part_die
->has_specification
= 1;
5833 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
, cu
);
5836 /* Ignore absolute siblings, they might point outside of
5837 the current compile unit. */
5838 if (attr
.form
== DW_FORM_ref_addr
)
5839 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
5841 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
5842 + dwarf2_get_ref_die_offset (&attr
, cu
);
5844 case DW_AT_stmt_list
:
5845 part_die
->has_stmt_list
= 1;
5846 part_die
->line_offset
= DW_UNSND (&attr
);
5848 case DW_AT_byte_size
:
5849 part_die
->has_byte_size
= 1;
5851 case DW_AT_calling_convention
:
5852 /* DWARF doesn't provide a way to identify a program's source-level
5853 entry point. DW_AT_calling_convention attributes are only meant
5854 to describe functions' calling conventions.
5856 However, because it's a necessary piece of information in
5857 Fortran, and because DW_CC_program is the only piece of debugging
5858 information whose definition refers to a 'main program' at all,
5859 several compilers have begun marking Fortran main programs with
5860 DW_CC_program --- even when those functions use the standard
5861 calling conventions.
5863 So until DWARF specifies a way to provide this information and
5864 compilers pick up the new representation, we'll support this
5866 if (DW_UNSND (&attr
) == DW_CC_program
5867 && cu
->language
== language_fortran
)
5868 set_main_name (part_die
->name
);
5875 /* When using the GNU linker, .gnu.linkonce. sections are used to
5876 eliminate duplicate copies of functions and vtables and such.
5877 The linker will arbitrarily choose one and discard the others.
5878 The AT_*_pc values for such functions refer to local labels in
5879 these sections. If the section from that file was discarded, the
5880 labels are not in the output, so the relocs get a value of 0.
5881 If this is a discarded function, mark the pc bounds as invalid,
5882 so that GDB will ignore it. */
5883 if (has_low_pc_attr
&& has_high_pc_attr
5884 && part_die
->lowpc
< part_die
->highpc
5885 && (part_die
->lowpc
!= 0
5886 || dwarf2_per_objfile
->has_section_at_zero
))
5887 part_die
->has_pc_info
= 1;
5889 if (base_address_type
!= base_address_none
&& !cu
->header
.base_known
)
5891 gdb_assert (part_die
->tag
== DW_TAG_compile_unit
);
5892 cu
->header
.base_known
= 1;
5893 cu
->header
.base_address
= base_address
;
5899 /* Find a cached partial DIE at OFFSET in CU. */
5901 static struct partial_die_info
*
5902 find_partial_die_in_comp_unit (unsigned long offset
, struct dwarf2_cu
*cu
)
5904 struct partial_die_info
*lookup_die
= NULL
;
5905 struct partial_die_info part_die
;
5907 part_die
.offset
= offset
;
5908 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
5913 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
5915 static struct partial_die_info
*
5916 find_partial_die (unsigned long offset
, struct dwarf2_cu
*cu
)
5918 struct dwarf2_per_cu_data
*per_cu
= NULL
;
5919 struct partial_die_info
*pd
= NULL
;
5921 if (offset
>= cu
->header
.offset
5922 && offset
< cu
->header
.offset
+ cu
->header
.length
)
5924 pd
= find_partial_die_in_comp_unit (offset
, cu
);
5929 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
5931 if (per_cu
->cu
== NULL
)
5933 load_comp_unit (per_cu
, cu
->objfile
);
5934 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5935 dwarf2_per_objfile
->read_in_chain
= per_cu
;
5938 per_cu
->cu
->last_used
= 0;
5939 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
5941 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
5943 struct cleanup
*back_to
;
5944 struct partial_die_info comp_unit_die
;
5945 struct abbrev_info
*abbrev
;
5946 unsigned int bytes_read
;
5949 per_cu
->load_all_dies
= 1;
5951 /* Re-read the DIEs. */
5952 back_to
= make_cleanup (null_cleanup
, 0);
5953 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
5955 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
5956 back_to
= make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
5958 info_ptr
= per_cu
->cu
->header
.first_die_ptr
;
5959 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
5960 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
5961 per_cu
->cu
->objfile
->obfd
, info_ptr
,
5963 if (comp_unit_die
.has_children
)
5964 load_partial_dies (per_cu
->cu
->objfile
->obfd
, info_ptr
, 0, per_cu
->cu
);
5965 do_cleanups (back_to
);
5967 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
5971 internal_error (__FILE__
, __LINE__
,
5972 _("could not find partial DIE 0x%lx in cache [from module %s]\n"),
5973 offset
, bfd_get_filename (cu
->objfile
->obfd
));
5977 /* Adjust PART_DIE before generating a symbol for it. This function
5978 may set the is_external flag or change the DIE's name. */
5981 fixup_partial_die (struct partial_die_info
*part_die
,
5982 struct dwarf2_cu
*cu
)
5984 /* If we found a reference attribute and the DIE has no name, try
5985 to find a name in the referred to DIE. */
5987 if (part_die
->name
== NULL
&& part_die
->has_specification
)
5989 struct partial_die_info
*spec_die
;
5991 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
5993 fixup_partial_die (spec_die
, cu
);
5997 part_die
->name
= spec_die
->name
;
5999 /* Copy DW_AT_external attribute if it is set. */
6000 if (spec_die
->is_external
)
6001 part_die
->is_external
= spec_die
->is_external
;
6005 /* Set default names for some unnamed DIEs. */
6006 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
6007 || part_die
->tag
== DW_TAG_class_type
))
6008 part_die
->name
= "(anonymous class)";
6010 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
6011 part_die
->name
= "(anonymous namespace)";
6013 if (part_die
->tag
== DW_TAG_structure_type
6014 || part_die
->tag
== DW_TAG_class_type
6015 || part_die
->tag
== DW_TAG_union_type
)
6016 guess_structure_name (part_die
, cu
);
6019 /* Read the die from the .debug_info section buffer. Set DIEP to
6020 point to a newly allocated die with its information, except for its
6021 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6022 whether the die has children or not. */
6025 read_full_die (struct die_info
**diep
, bfd
*abfd
, gdb_byte
*info_ptr
,
6026 struct dwarf2_cu
*cu
, int *has_children
)
6028 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6029 struct abbrev_info
*abbrev
;
6030 struct die_info
*die
;
6032 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
6033 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6034 info_ptr
+= bytes_read
;
6042 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6045 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6047 bfd_get_filename (abfd
));
6049 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
6050 die
->offset
= offset
;
6051 die
->tag
= abbrev
->tag
;
6052 die
->abbrev
= abbrev_number
;
6054 die
->num_attrs
= abbrev
->num_attrs
;
6056 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6057 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6058 abfd
, info_ptr
, cu
);
6061 *has_children
= abbrev
->has_children
;
6065 /* Read an attribute value described by an attribute form. */
6068 read_attribute_value (struct attribute
*attr
, unsigned form
,
6069 bfd
*abfd
, gdb_byte
*info_ptr
,
6070 struct dwarf2_cu
*cu
)
6072 struct comp_unit_head
*cu_header
= &cu
->header
;
6073 unsigned int bytes_read
;
6074 struct dwarf_block
*blk
;
6080 case DW_FORM_ref_addr
:
6081 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6082 info_ptr
+= bytes_read
;
6084 case DW_FORM_block2
:
6085 blk
= dwarf_alloc_block (cu
);
6086 blk
->size
= read_2_bytes (abfd
, info_ptr
);
6088 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6089 info_ptr
+= blk
->size
;
6090 DW_BLOCK (attr
) = blk
;
6092 case DW_FORM_block4
:
6093 blk
= dwarf_alloc_block (cu
);
6094 blk
->size
= read_4_bytes (abfd
, info_ptr
);
6096 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6097 info_ptr
+= blk
->size
;
6098 DW_BLOCK (attr
) = blk
;
6101 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
6105 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
6109 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
6112 case DW_FORM_string
:
6113 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
6114 info_ptr
+= bytes_read
;
6117 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
6119 info_ptr
+= bytes_read
;
6122 blk
= dwarf_alloc_block (cu
);
6123 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6124 info_ptr
+= bytes_read
;
6125 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6126 info_ptr
+= blk
->size
;
6127 DW_BLOCK (attr
) = blk
;
6129 case DW_FORM_block1
:
6130 blk
= dwarf_alloc_block (cu
);
6131 blk
->size
= read_1_byte (abfd
, info_ptr
);
6133 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6134 info_ptr
+= blk
->size
;
6135 DW_BLOCK (attr
) = blk
;
6138 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6142 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6146 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
6147 info_ptr
+= bytes_read
;
6150 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6151 info_ptr
+= bytes_read
;
6154 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
6158 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
6162 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
6166 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
6169 case DW_FORM_ref_udata
:
6170 DW_ADDR (attr
) = (cu
->header
.offset
6171 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
6172 info_ptr
+= bytes_read
;
6174 case DW_FORM_indirect
:
6175 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6176 info_ptr
+= bytes_read
;
6177 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
6180 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
6181 dwarf_form_name (form
),
6182 bfd_get_filename (abfd
));
6185 /* We have seen instances where the compiler tried to emit a byte
6186 size attribute of -1 which ended up being encoded as an unsigned
6187 0xffffffff. Although 0xffffffff is technically a valid size value,
6188 an object of this size seems pretty unlikely so we can relatively
6189 safely treat these cases as if the size attribute was invalid and
6190 treat them as zero by default. */
6191 if (attr
->name
== DW_AT_byte_size
6192 && form
== DW_FORM_data4
6193 && DW_UNSND (attr
) >= 0xffffffff)
6196 (&symfile_complaints
,
6197 _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"),
6199 DW_UNSND (attr
) = 0;
6205 /* Read an attribute described by an abbreviated attribute. */
6208 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
6209 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6211 attr
->name
= abbrev
->name
;
6212 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
6215 /* read dwarf information from a buffer */
6218 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
6220 return bfd_get_8 (abfd
, buf
);
6224 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
6226 return bfd_get_signed_8 (abfd
, buf
);
6230 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
6232 return bfd_get_16 (abfd
, buf
);
6236 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6238 return bfd_get_signed_16 (abfd
, buf
);
6242 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
6244 return bfd_get_32 (abfd
, buf
);
6248 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6250 return bfd_get_signed_32 (abfd
, buf
);
6253 static unsigned long
6254 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
6256 return bfd_get_64 (abfd
, buf
);
6260 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
6261 unsigned int *bytes_read
)
6263 struct comp_unit_head
*cu_header
= &cu
->header
;
6264 CORE_ADDR retval
= 0;
6266 if (cu_header
->signed_addr_p
)
6268 switch (cu_header
->addr_size
)
6271 retval
= bfd_get_signed_16 (abfd
, buf
);
6274 retval
= bfd_get_signed_32 (abfd
, buf
);
6277 retval
= bfd_get_signed_64 (abfd
, buf
);
6280 internal_error (__FILE__
, __LINE__
,
6281 _("read_address: bad switch, signed [in module %s]"),
6282 bfd_get_filename (abfd
));
6287 switch (cu_header
->addr_size
)
6290 retval
= bfd_get_16 (abfd
, buf
);
6293 retval
= bfd_get_32 (abfd
, buf
);
6296 retval
= bfd_get_64 (abfd
, buf
);
6299 internal_error (__FILE__
, __LINE__
,
6300 _("read_address: bad switch, unsigned [in module %s]"),
6301 bfd_get_filename (abfd
));
6305 *bytes_read
= cu_header
->addr_size
;
6309 /* Read the initial length from a section. The (draft) DWARF 3
6310 specification allows the initial length to take up either 4 bytes
6311 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
6312 bytes describe the length and all offsets will be 8 bytes in length
6315 An older, non-standard 64-bit format is also handled by this
6316 function. The older format in question stores the initial length
6317 as an 8-byte quantity without an escape value. Lengths greater
6318 than 2^32 aren't very common which means that the initial 4 bytes
6319 is almost always zero. Since a length value of zero doesn't make
6320 sense for the 32-bit format, this initial zero can be considered to
6321 be an escape value which indicates the presence of the older 64-bit
6322 format. As written, the code can't detect (old format) lengths
6323 greater than 4GB. If it becomes necessary to handle lengths
6324 somewhat larger than 4GB, we could allow other small values (such
6325 as the non-sensical values of 1, 2, and 3) to also be used as
6326 escape values indicating the presence of the old format.
6328 The value returned via bytes_read should be used to increment the
6329 relevant pointer after calling read_initial_length().
6331 As a side effect, this function sets the fields initial_length_size
6332 and offset_size in cu_header to the values appropriate for the
6333 length field. (The format of the initial length field determines
6334 the width of file offsets to be fetched later with read_offset().)
6336 [ Note: read_initial_length() and read_offset() are based on the
6337 document entitled "DWARF Debugging Information Format", revision
6338 3, draft 8, dated November 19, 2001. This document was obtained
6341 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
6343 This document is only a draft and is subject to change. (So beware.)
6345 Details regarding the older, non-standard 64-bit format were
6346 determined empirically by examining 64-bit ELF files produced by
6347 the SGI toolchain on an IRIX 6.5 machine.
6349 - Kevin, July 16, 2002
6353 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, struct comp_unit_head
*cu_header
,
6354 unsigned int *bytes_read
)
6356 LONGEST length
= bfd_get_32 (abfd
, buf
);
6358 if (length
== 0xffffffff)
6360 length
= bfd_get_64 (abfd
, buf
+ 4);
6363 else if (length
== 0)
6365 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
6366 length
= bfd_get_64 (abfd
, buf
);
6376 gdb_assert (cu_header
->initial_length_size
== 0
6377 || cu_header
->initial_length_size
== 4
6378 || cu_header
->initial_length_size
== 8
6379 || cu_header
->initial_length_size
== 12);
6381 if (cu_header
->initial_length_size
!= 0
6382 && cu_header
->initial_length_size
!= *bytes_read
)
6383 complaint (&symfile_complaints
,
6384 _("intermixed 32-bit and 64-bit DWARF sections"));
6386 cu_header
->initial_length_size
= *bytes_read
;
6387 cu_header
->offset_size
= (*bytes_read
== 4) ? 4 : 8;
6393 /* Read an offset from the data stream. The size of the offset is
6394 given by cu_header->offset_size. */
6397 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
6398 unsigned int *bytes_read
)
6402 switch (cu_header
->offset_size
)
6405 retval
= bfd_get_32 (abfd
, buf
);
6409 retval
= bfd_get_64 (abfd
, buf
);
6413 internal_error (__FILE__
, __LINE__
,
6414 _("read_offset: bad switch [in module %s]"),
6415 bfd_get_filename (abfd
));
6422 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
6424 /* If the size of a host char is 8 bits, we can return a pointer
6425 to the buffer, otherwise we have to copy the data to a buffer
6426 allocated on the temporary obstack. */
6427 gdb_assert (HOST_CHAR_BIT
== 8);
6432 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6434 /* If the size of a host char is 8 bits, we can return a pointer
6435 to the string, otherwise we have to copy the string to a buffer
6436 allocated on the temporary obstack. */
6437 gdb_assert (HOST_CHAR_BIT
== 8);
6440 *bytes_read_ptr
= 1;
6443 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
6444 return (char *) buf
;
6448 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
6449 const struct comp_unit_head
*cu_header
,
6450 unsigned int *bytes_read_ptr
)
6452 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
6455 if (dwarf2_per_objfile
->str_buffer
== NULL
)
6457 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
6458 bfd_get_filename (abfd
));
6461 if (str_offset
>= dwarf2_per_objfile
->str_size
)
6463 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
6464 bfd_get_filename (abfd
));
6467 gdb_assert (HOST_CHAR_BIT
== 8);
6468 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
6470 return (char *) (dwarf2_per_objfile
->str_buffer
+ str_offset
);
6473 static unsigned long
6474 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6476 unsigned long result
;
6477 unsigned int num_read
;
6487 byte
= bfd_get_8 (abfd
, buf
);
6490 result
|= ((unsigned long)(byte
& 127) << shift
);
6491 if ((byte
& 128) == 0)
6497 *bytes_read_ptr
= num_read
;
6502 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6505 int i
, shift
, num_read
;
6514 byte
= bfd_get_8 (abfd
, buf
);
6517 result
|= ((long)(byte
& 127) << shift
);
6519 if ((byte
& 128) == 0)
6524 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
6525 result
|= -(((long)1) << shift
);
6526 *bytes_read_ptr
= num_read
;
6530 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6533 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
6539 byte
= bfd_get_8 (abfd
, buf
);
6541 if ((byte
& 128) == 0)
6547 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
6553 cu
->language
= language_c
;
6555 case DW_LANG_C_plus_plus
:
6556 cu
->language
= language_cplus
;
6558 case DW_LANG_Fortran77
:
6559 case DW_LANG_Fortran90
:
6560 case DW_LANG_Fortran95
:
6561 cu
->language
= language_fortran
;
6563 case DW_LANG_Mips_Assembler
:
6564 cu
->language
= language_asm
;
6567 cu
->language
= language_java
;
6571 cu
->language
= language_ada
;
6573 case DW_LANG_Modula2
:
6574 cu
->language
= language_m2
;
6576 case DW_LANG_Pascal83
:
6577 cu
->language
= language_pascal
;
6580 cu
->language
= language_objc
;
6582 case DW_LANG_Cobol74
:
6583 case DW_LANG_Cobol85
:
6585 cu
->language
= language_minimal
;
6588 cu
->language_defn
= language_def (cu
->language
);
6591 /* Return the named attribute or NULL if not there. */
6593 static struct attribute
*
6594 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
6597 struct attribute
*spec
= NULL
;
6599 for (i
= 0; i
< die
->num_attrs
; ++i
)
6601 if (die
->attrs
[i
].name
== name
)
6602 return &die
->attrs
[i
];
6603 if (die
->attrs
[i
].name
== DW_AT_specification
6604 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
6605 spec
= &die
->attrs
[i
];
6610 die
= follow_die_ref (die
, spec
, &cu
);
6611 return dwarf2_attr (die
, name
, cu
);
6617 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6618 and holds a non-zero value. This function should only be used for
6619 DW_FORM_flag attributes. */
6622 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
6624 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
6626 return (attr
&& DW_UNSND (attr
));
6630 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
6632 /* A DIE is a declaration if it has a DW_AT_declaration attribute
6633 which value is non-zero. However, we have to be careful with
6634 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
6635 (via dwarf2_flag_true_p) follows this attribute. So we may
6636 end up accidently finding a declaration attribute that belongs
6637 to a different DIE referenced by the specification attribute,
6638 even though the given DIE does not have a declaration attribute. */
6639 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
6640 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
6643 /* Return the die giving the specification for DIE, if there is
6644 one. *SPEC_CU is the CU containing DIE on input, and the CU
6645 containing the return value on output. */
6647 static struct die_info
*
6648 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
6650 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
6653 if (spec_attr
== NULL
)
6656 return follow_die_ref (die
, spec_attr
, spec_cu
);
6659 /* Free the line_header structure *LH, and any arrays and strings it
6662 free_line_header (struct line_header
*lh
)
6664 if (lh
->standard_opcode_lengths
)
6665 xfree (lh
->standard_opcode_lengths
);
6667 /* Remember that all the lh->file_names[i].name pointers are
6668 pointers into debug_line_buffer, and don't need to be freed. */
6670 xfree (lh
->file_names
);
6672 /* Similarly for the include directory names. */
6673 if (lh
->include_dirs
)
6674 xfree (lh
->include_dirs
);
6680 /* Add an entry to LH's include directory table. */
6682 add_include_dir (struct line_header
*lh
, char *include_dir
)
6684 /* Grow the array if necessary. */
6685 if (lh
->include_dirs_size
== 0)
6687 lh
->include_dirs_size
= 1; /* for testing */
6688 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
6689 * sizeof (*lh
->include_dirs
));
6691 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
6693 lh
->include_dirs_size
*= 2;
6694 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
6695 (lh
->include_dirs_size
6696 * sizeof (*lh
->include_dirs
)));
6699 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
6703 /* Add an entry to LH's file name table. */
6705 add_file_name (struct line_header
*lh
,
6707 unsigned int dir_index
,
6708 unsigned int mod_time
,
6709 unsigned int length
)
6711 struct file_entry
*fe
;
6713 /* Grow the array if necessary. */
6714 if (lh
->file_names_size
== 0)
6716 lh
->file_names_size
= 1; /* for testing */
6717 lh
->file_names
= xmalloc (lh
->file_names_size
6718 * sizeof (*lh
->file_names
));
6720 else if (lh
->num_file_names
>= lh
->file_names_size
)
6722 lh
->file_names_size
*= 2;
6723 lh
->file_names
= xrealloc (lh
->file_names
,
6724 (lh
->file_names_size
6725 * sizeof (*lh
->file_names
)));
6728 fe
= &lh
->file_names
[lh
->num_file_names
++];
6730 fe
->dir_index
= dir_index
;
6731 fe
->mod_time
= mod_time
;
6732 fe
->length
= length
;
6738 /* Read the statement program header starting at OFFSET in
6739 .debug_line, according to the endianness of ABFD. Return a pointer
6740 to a struct line_header, allocated using xmalloc.
6742 NOTE: the strings in the include directory and file name tables of
6743 the returned object point into debug_line_buffer, and must not be
6745 static struct line_header
*
6746 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
6747 struct dwarf2_cu
*cu
)
6749 struct cleanup
*back_to
;
6750 struct line_header
*lh
;
6752 unsigned int bytes_read
;
6754 char *cur_dir
, *cur_file
;
6756 if (dwarf2_per_objfile
->line_buffer
== NULL
)
6758 complaint (&symfile_complaints
, _("missing .debug_line section"));
6762 /* Make sure that at least there's room for the total_length field.
6763 That could be 12 bytes long, but we're just going to fudge that. */
6764 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
6766 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6770 lh
= xmalloc (sizeof (*lh
));
6771 memset (lh
, 0, sizeof (*lh
));
6772 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
6775 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
6777 /* Read in the header. */
6779 read_initial_length (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6780 line_ptr
+= bytes_read
;
6781 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
6782 + dwarf2_per_objfile
->line_size
))
6784 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6787 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
6788 lh
->version
= read_2_bytes (abfd
, line_ptr
);
6790 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6791 line_ptr
+= bytes_read
;
6792 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
6794 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
6796 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
6798 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
6800 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
6802 lh
->standard_opcode_lengths
6803 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
6805 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
6806 for (i
= 1; i
< lh
->opcode_base
; ++i
)
6808 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
6812 /* Read directory table. */
6813 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6815 line_ptr
+= bytes_read
;
6816 add_include_dir (lh
, cur_dir
);
6818 line_ptr
+= bytes_read
;
6820 /* Read file name table. */
6821 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6823 unsigned int dir_index
, mod_time
, length
;
6825 line_ptr
+= bytes_read
;
6826 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6827 line_ptr
+= bytes_read
;
6828 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6829 line_ptr
+= bytes_read
;
6830 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6831 line_ptr
+= bytes_read
;
6833 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6835 line_ptr
+= bytes_read
;
6836 lh
->statement_program_start
= line_ptr
;
6838 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
6839 + dwarf2_per_objfile
->line_size
))
6840 complaint (&symfile_complaints
,
6841 _("line number info header doesn't fit in `.debug_line' section"));
6843 discard_cleanups (back_to
);
6847 /* This function exists to work around a bug in certain compilers
6848 (particularly GCC 2.95), in which the first line number marker of a
6849 function does not show up until after the prologue, right before
6850 the second line number marker. This function shifts ADDRESS down
6851 to the beginning of the function if necessary, and is called on
6852 addresses passed to record_line. */
6855 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
6857 struct function_range
*fn
;
6859 /* Find the function_range containing address. */
6864 cu
->cached_fn
= cu
->first_fn
;
6868 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6874 while (fn
&& fn
!= cu
->cached_fn
)
6875 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6885 if (address
!= fn
->lowpc
)
6886 complaint (&symfile_complaints
,
6887 _("misplaced first line number at 0x%lx for '%s'"),
6888 (unsigned long) address
, fn
->name
);
6893 /* Decode the Line Number Program (LNP) for the given line_header
6894 structure and CU. The actual information extracted and the type
6895 of structures created from the LNP depends on the value of PST.
6897 1. If PST is NULL, then this procedure uses the data from the program
6898 to create all necessary symbol tables, and their linetables.
6899 The compilation directory of the file is passed in COMP_DIR,
6900 and must not be NULL.
6902 2. If PST is not NULL, this procedure reads the program to determine
6903 the list of files included by the unit represented by PST, and
6904 builds all the associated partial symbol tables. In this case,
6905 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
6906 is not used to compute the full name of the symtab, and therefore
6907 omitting it when building the partial symtab does not introduce
6908 the potential for inconsistency - a partial symtab and its associated
6909 symbtab having a different fullname -). */
6912 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
6913 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
6915 gdb_byte
*line_ptr
, *extended_end
;
6917 unsigned int bytes_read
, extended_len
;
6918 unsigned char op_code
, extended_op
, adj_opcode
;
6920 struct objfile
*objfile
= cu
->objfile
;
6921 const int decode_for_pst_p
= (pst
!= NULL
);
6922 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
6924 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6926 line_ptr
= lh
->statement_program_start
;
6927 line_end
= lh
->statement_program_end
;
6929 /* Read the statement sequences until there's nothing left. */
6930 while (line_ptr
< line_end
)
6932 /* state machine registers */
6933 CORE_ADDR address
= 0;
6934 unsigned int file
= 1;
6935 unsigned int line
= 1;
6936 unsigned int column
= 0;
6937 int is_stmt
= lh
->default_is_stmt
;
6938 int basic_block
= 0;
6939 int end_sequence
= 0;
6941 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
6943 /* Start a subfile for the current file of the state machine. */
6944 /* lh->include_dirs and lh->file_names are 0-based, but the
6945 directory and file name numbers in the statement program
6947 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
6951 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6953 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
6956 /* Decode the table. */
6957 while (!end_sequence
)
6959 op_code
= read_1_byte (abfd
, line_ptr
);
6962 if (op_code
>= lh
->opcode_base
)
6964 /* Special operand. */
6965 adj_opcode
= op_code
- lh
->opcode_base
;
6966 address
+= (adj_opcode
/ lh
->line_range
)
6967 * lh
->minimum_instruction_length
;
6968 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
6969 if (lh
->num_file_names
< file
)
6970 dwarf2_debug_line_missing_file_complaint ();
6973 lh
->file_names
[file
- 1].included_p
= 1;
6974 if (!decode_for_pst_p
)
6976 if (last_subfile
!= current_subfile
)
6979 record_line (last_subfile
, 0, address
);
6980 last_subfile
= current_subfile
;
6982 /* Append row to matrix using current values. */
6983 record_line (current_subfile
, line
,
6984 check_cu_functions (address
, cu
));
6989 else switch (op_code
)
6991 case DW_LNS_extended_op
:
6992 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6993 line_ptr
+= bytes_read
;
6994 extended_end
= line_ptr
+ extended_len
;
6995 extended_op
= read_1_byte (abfd
, line_ptr
);
6997 switch (extended_op
)
6999 case DW_LNE_end_sequence
:
7002 if (lh
->num_file_names
< file
)
7003 dwarf2_debug_line_missing_file_complaint ();
7006 lh
->file_names
[file
- 1].included_p
= 1;
7007 if (!decode_for_pst_p
)
7008 record_line (current_subfile
, 0, address
);
7011 case DW_LNE_set_address
:
7012 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
7013 line_ptr
+= bytes_read
;
7014 address
+= baseaddr
;
7016 case DW_LNE_define_file
:
7019 unsigned int dir_index
, mod_time
, length
;
7021 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
7022 line_ptr
+= bytes_read
;
7024 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7025 line_ptr
+= bytes_read
;
7027 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7028 line_ptr
+= bytes_read
;
7030 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7031 line_ptr
+= bytes_read
;
7032 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7036 complaint (&symfile_complaints
,
7037 _("mangled .debug_line section"));
7040 /* Make sure that we parsed the extended op correctly. If e.g.
7041 we expected a different address size than the producer used,
7042 we may have read the wrong number of bytes. */
7043 if (line_ptr
!= extended_end
)
7045 complaint (&symfile_complaints
,
7046 _("mangled .debug_line section"));
7051 if (lh
->num_file_names
< file
)
7052 dwarf2_debug_line_missing_file_complaint ();
7055 lh
->file_names
[file
- 1].included_p
= 1;
7056 if (!decode_for_pst_p
)
7058 if (last_subfile
!= current_subfile
)
7061 record_line (last_subfile
, 0, address
);
7062 last_subfile
= current_subfile
;
7064 record_line (current_subfile
, line
,
7065 check_cu_functions (address
, cu
));
7070 case DW_LNS_advance_pc
:
7071 address
+= lh
->minimum_instruction_length
7072 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7073 line_ptr
+= bytes_read
;
7075 case DW_LNS_advance_line
:
7076 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
7077 line_ptr
+= bytes_read
;
7079 case DW_LNS_set_file
:
7081 /* The arrays lh->include_dirs and lh->file_names are
7082 0-based, but the directory and file name numbers in
7083 the statement program are 1-based. */
7084 struct file_entry
*fe
;
7087 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7088 line_ptr
+= bytes_read
;
7089 if (lh
->num_file_names
< file
)
7090 dwarf2_debug_line_missing_file_complaint ();
7093 fe
= &lh
->file_names
[file
- 1];
7095 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7096 if (!decode_for_pst_p
)
7098 last_subfile
= current_subfile
;
7099 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7104 case DW_LNS_set_column
:
7105 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7106 line_ptr
+= bytes_read
;
7108 case DW_LNS_negate_stmt
:
7109 is_stmt
= (!is_stmt
);
7111 case DW_LNS_set_basic_block
:
7114 /* Add to the address register of the state machine the
7115 address increment value corresponding to special opcode
7116 255. I.e., this value is scaled by the minimum
7117 instruction length since special opcode 255 would have
7118 scaled the the increment. */
7119 case DW_LNS_const_add_pc
:
7120 address
+= (lh
->minimum_instruction_length
7121 * ((255 - lh
->opcode_base
) / lh
->line_range
));
7123 case DW_LNS_fixed_advance_pc
:
7124 address
+= read_2_bytes (abfd
, line_ptr
);
7129 /* Unknown standard opcode, ignore it. */
7132 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
7134 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7135 line_ptr
+= bytes_read
;
7142 if (decode_for_pst_p
)
7146 /* Now that we're done scanning the Line Header Program, we can
7147 create the psymtab of each included file. */
7148 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
7149 if (lh
->file_names
[file_index
].included_p
== 1)
7151 const struct file_entry fe
= lh
->file_names
[file_index
];
7152 char *include_name
= fe
.name
;
7153 char *dir_name
= NULL
;
7154 char *pst_filename
= pst
->filename
;
7157 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
7159 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
7161 include_name
= concat (dir_name
, SLASH_STRING
,
7162 include_name
, (char *)NULL
);
7163 make_cleanup (xfree
, include_name
);
7166 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
7168 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
7169 pst_filename
, (char *)NULL
);
7170 make_cleanup (xfree
, pst_filename
);
7173 if (strcmp (include_name
, pst_filename
) != 0)
7174 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
7179 /* Make sure a symtab is created for every file, even files
7180 which contain only variables (i.e. no code with associated
7184 struct file_entry
*fe
;
7186 for (i
= 0; i
< lh
->num_file_names
; i
++)
7189 fe
= &lh
->file_names
[i
];
7191 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7192 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7194 /* Skip the main file; we don't need it, and it must be
7195 allocated last, so that it will show up before the
7196 non-primary symtabs in the objfile's symtab list. */
7197 if (current_subfile
== first_subfile
)
7200 if (current_subfile
->symtab
== NULL
)
7201 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7203 fe
->symtab
= current_subfile
->symtab
;
7208 /* Start a subfile for DWARF. FILENAME is the name of the file and
7209 DIRNAME the name of the source directory which contains FILENAME
7210 or NULL if not known. COMP_DIR is the compilation directory for the
7211 linetable's compilation unit or NULL if not known.
7212 This routine tries to keep line numbers from identical absolute and
7213 relative file names in a common subfile.
7215 Using the `list' example from the GDB testsuite, which resides in
7216 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
7217 of /srcdir/list0.c yields the following debugging information for list0.c:
7219 DW_AT_name: /srcdir/list0.c
7220 DW_AT_comp_dir: /compdir
7221 files.files[0].name: list0.h
7222 files.files[0].dir: /srcdir
7223 files.files[1].name: list0.c
7224 files.files[1].dir: /srcdir
7226 The line number information for list0.c has to end up in a single
7227 subfile, so that `break /srcdir/list0.c:1' works as expected.
7228 start_subfile will ensure that this happens provided that we pass the
7229 concatenation of files.files[1].dir and files.files[1].name as the
7233 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
7237 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
7238 `start_symtab' will always pass the contents of DW_AT_comp_dir as
7239 second argument to start_subfile. To be consistent, we do the
7240 same here. In order not to lose the line information directory,
7241 we concatenate it to the filename when it makes sense.
7242 Note that the Dwarf3 standard says (speaking of filenames in line
7243 information): ``The directory index is ignored for file names
7244 that represent full path names''. Thus ignoring dirname in the
7245 `else' branch below isn't an issue. */
7247 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
7248 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
7250 fullname
= filename
;
7252 start_subfile (fullname
, comp_dir
);
7254 if (fullname
!= filename
)
7259 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
7260 struct dwarf2_cu
*cu
)
7262 struct objfile
*objfile
= cu
->objfile
;
7263 struct comp_unit_head
*cu_header
= &cu
->header
;
7265 /* NOTE drow/2003-01-30: There used to be a comment and some special
7266 code here to turn a symbol with DW_AT_external and a
7267 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
7268 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
7269 with some versions of binutils) where shared libraries could have
7270 relocations against symbols in their debug information - the
7271 minimal symbol would have the right address, but the debug info
7272 would not. It's no longer necessary, because we will explicitly
7273 apply relocations when we read in the debug information now. */
7275 /* A DW_AT_location attribute with no contents indicates that a
7276 variable has been optimized away. */
7277 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
7279 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7283 /* Handle one degenerate form of location expression specially, to
7284 preserve GDB's previous behavior when section offsets are
7285 specified. If this is just a DW_OP_addr then mark this symbol
7288 if (attr_form_is_block (attr
)
7289 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
7290 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
7294 SYMBOL_VALUE_ADDRESS (sym
) =
7295 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
7296 SYMBOL_CLASS (sym
) = LOC_STATIC
;
7297 fixup_symbol_section (sym
, objfile
);
7298 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
7299 SYMBOL_SECTION (sym
));
7303 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
7304 expression evaluator, and use LOC_COMPUTED only when necessary
7305 (i.e. when the value of a register or memory location is
7306 referenced, or a thread-local block, etc.). Then again, it might
7307 not be worthwhile. I'm assuming that it isn't unless performance
7308 or memory numbers show me otherwise. */
7310 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
7311 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
7314 /* Given a pointer to a DWARF information entry, figure out if we need
7315 to make a symbol table entry for it, and if so, create a new entry
7316 and return a pointer to it.
7317 If TYPE is NULL, determine symbol type from the die, otherwise
7318 used the passed type. */
7320 static struct symbol
*
7321 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
7323 struct objfile
*objfile
= cu
->objfile
;
7324 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7325 struct symbol
*sym
= NULL
;
7327 struct attribute
*attr
= NULL
;
7328 struct attribute
*attr2
= NULL
;
7331 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7333 if (die
->tag
!= DW_TAG_namespace
)
7334 name
= dwarf2_linkage_name (die
, cu
);
7336 name
= TYPE_NAME (type
);
7340 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
7341 sizeof (struct symbol
));
7342 OBJSTAT (objfile
, n_syms
++);
7343 memset (sym
, 0, sizeof (struct symbol
));
7345 /* Cache this symbol's name and the name's demangled form (if any). */
7346 SYMBOL_LANGUAGE (sym
) = cu
->language
;
7347 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
7349 /* Default assumptions.
7350 Use the passed type or decode it from the die. */
7351 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7352 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7354 SYMBOL_TYPE (sym
) = type
;
7356 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
7357 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
7360 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
7363 attr
= dwarf2_attr (die
, DW_AT_decl_file
, cu
);
7366 int file_index
= DW_UNSND (attr
);
7367 if (cu
->line_header
== NULL
7368 || file_index
> cu
->line_header
->num_file_names
)
7369 complaint (&symfile_complaints
,
7370 _("file index out of range"));
7371 else if (file_index
> 0)
7373 struct file_entry
*fe
;
7374 fe
= &cu
->line_header
->file_names
[file_index
- 1];
7375 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
7382 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7385 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
7387 SYMBOL_CLASS (sym
) = LOC_LABEL
;
7389 case DW_TAG_subprogram
:
7390 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7392 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
7393 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7394 if ((attr2
&& (DW_UNSND (attr2
) != 0))
7395 || cu
->language
== language_ada
)
7397 /* Subprograms marked external are stored as a global symbol.
7398 Ada subprograms, whether marked external or not, are always
7399 stored as a global symbol, because we want to be able to
7400 access them globally. For instance, we want to be able
7401 to break on a nested subprogram without having to
7402 specify the context. */
7403 add_symbol_to_list (sym
, &global_symbols
);
7407 add_symbol_to_list (sym
, cu
->list_in_scope
);
7410 case DW_TAG_variable
:
7411 /* Compilation with minimal debug info may result in variables
7412 with missing type entries. Change the misleading `void' type
7413 to something sensible. */
7414 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
7416 = builtin_type (gdbarch
)->nodebug_data_symbol
;
7418 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7421 dwarf2_const_value (attr
, sym
, cu
);
7422 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7423 if (attr2
&& (DW_UNSND (attr2
) != 0))
7424 add_symbol_to_list (sym
, &global_symbols
);
7426 add_symbol_to_list (sym
, cu
->list_in_scope
);
7429 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7432 var_decode_location (attr
, sym
, cu
);
7433 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7434 if (attr2
&& (DW_UNSND (attr2
) != 0))
7435 add_symbol_to_list (sym
, &global_symbols
);
7437 add_symbol_to_list (sym
, cu
->list_in_scope
);
7441 /* We do not know the address of this symbol.
7442 If it is an external symbol and we have type information
7443 for it, enter the symbol as a LOC_UNRESOLVED symbol.
7444 The address of the variable will then be determined from
7445 the minimal symbol table whenever the variable is
7447 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7448 if (attr2
&& (DW_UNSND (attr2
) != 0)
7449 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
7451 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
7452 add_symbol_to_list (sym
, &global_symbols
);
7456 case DW_TAG_formal_parameter
:
7457 SYMBOL_IS_ARGUMENT (sym
) = 1;
7458 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7461 var_decode_location (attr
, sym
, cu
);
7463 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7466 dwarf2_const_value (attr
, sym
, cu
);
7468 add_symbol_to_list (sym
, cu
->list_in_scope
);
7470 case DW_TAG_unspecified_parameters
:
7471 /* From varargs functions; gdb doesn't seem to have any
7472 interest in this information, so just ignore it for now.
7475 case DW_TAG_class_type
:
7476 case DW_TAG_interface_type
:
7477 case DW_TAG_structure_type
:
7478 case DW_TAG_union_type
:
7479 case DW_TAG_set_type
:
7480 case DW_TAG_enumeration_type
:
7481 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7482 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7484 /* Make sure that the symbol includes appropriate enclosing
7485 classes/namespaces in its name. These are calculated in
7486 read_structure_type, and the correct name is saved in
7489 if (cu
->language
== language_cplus
7490 || cu
->language
== language_java
)
7492 struct type
*type
= SYMBOL_TYPE (sym
);
7494 if (TYPE_TAG_NAME (type
) != NULL
)
7496 /* FIXME: carlton/2003-11-10: Should this use
7497 SYMBOL_SET_NAMES instead? (The same problem also
7498 arises further down in this function.) */
7499 /* The type's name is already allocated along with
7500 this objfile, so we don't need to duplicate it
7502 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
7507 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
7508 really ever be static objects: otherwise, if you try
7509 to, say, break of a class's method and you're in a file
7510 which doesn't mention that class, it won't work unless
7511 the check for all static symbols in lookup_symbol_aux
7512 saves you. See the OtherFileClass tests in
7513 gdb.c++/namespace.exp. */
7515 struct pending
**list_to_add
;
7517 list_to_add
= (cu
->list_in_scope
== &file_symbols
7518 && (cu
->language
== language_cplus
7519 || cu
->language
== language_java
)
7520 ? &global_symbols
: cu
->list_in_scope
);
7522 add_symbol_to_list (sym
, list_to_add
);
7524 /* The semantics of C++ state that "struct foo { ... }" also
7525 defines a typedef for "foo". A Java class declaration also
7526 defines a typedef for the class. */
7527 if (cu
->language
== language_cplus
7528 || cu
->language
== language_java
7529 || cu
->language
== language_ada
)
7531 /* The symbol's name is already allocated along with
7532 this objfile, so we don't need to duplicate it for
7534 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
7535 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
7539 case DW_TAG_typedef
:
7540 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7541 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7542 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7543 add_symbol_to_list (sym
, cu
->list_in_scope
);
7545 case DW_TAG_base_type
:
7546 case DW_TAG_subrange_type
:
7547 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7548 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7549 add_symbol_to_list (sym
, cu
->list_in_scope
);
7551 case DW_TAG_enumerator
:
7552 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7553 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7556 dwarf2_const_value (attr
, sym
, cu
);
7559 /* NOTE: carlton/2003-11-10: See comment above in the
7560 DW_TAG_class_type, etc. block. */
7562 struct pending
**list_to_add
;
7564 list_to_add
= (cu
->list_in_scope
== &file_symbols
7565 && (cu
->language
== language_cplus
7566 || cu
->language
== language_java
)
7567 ? &global_symbols
: cu
->list_in_scope
);
7569 add_symbol_to_list (sym
, list_to_add
);
7572 case DW_TAG_namespace
:
7573 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7574 add_symbol_to_list (sym
, &global_symbols
);
7577 /* Not a tag we recognize. Hopefully we aren't processing
7578 trash data, but since we must specifically ignore things
7579 we don't recognize, there is nothing else we should do at
7581 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
7582 dwarf_tag_name (die
->tag
));
7586 /* For the benefit of old versions of GCC, check for anonymous
7587 namespaces based on the demangled name. */
7588 if (!processing_has_namespace_info
7589 && cu
->language
== language_cplus
7590 && dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
) != NULL
)
7591 cp_scan_for_anonymous_namespaces (sym
);
7596 /* Copy constant value from an attribute to a symbol. */
7599 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
7600 struct dwarf2_cu
*cu
)
7602 struct objfile
*objfile
= cu
->objfile
;
7603 struct comp_unit_head
*cu_header
= &cu
->header
;
7604 struct dwarf_block
*blk
;
7609 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
7610 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7611 cu_header
->addr_size
,
7612 TYPE_LENGTH (SYMBOL_TYPE
7614 SYMBOL_VALUE_BYTES (sym
) =
7615 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
7616 /* NOTE: cagney/2003-05-09: In-lined store_address call with
7617 it's body - store_unsigned_integer. */
7618 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
7620 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7623 /* DW_STRING is already allocated on the obstack, point directly
7625 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
7626 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7628 case DW_FORM_block1
:
7629 case DW_FORM_block2
:
7630 case DW_FORM_block4
:
7632 blk
= DW_BLOCK (attr
);
7633 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
7634 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7636 TYPE_LENGTH (SYMBOL_TYPE
7638 SYMBOL_VALUE_BYTES (sym
) =
7639 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
7640 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
7641 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7644 /* The DW_AT_const_value attributes are supposed to carry the
7645 symbol's value "represented as it would be on the target
7646 architecture." By the time we get here, it's already been
7647 converted to host endianness, so we just need to sign- or
7648 zero-extend it as appropriate. */
7650 dwarf2_const_value_data (attr
, sym
, 8);
7653 dwarf2_const_value_data (attr
, sym
, 16);
7656 dwarf2_const_value_data (attr
, sym
, 32);
7659 dwarf2_const_value_data (attr
, sym
, 64);
7663 SYMBOL_VALUE (sym
) = DW_SND (attr
);
7664 SYMBOL_CLASS (sym
) = LOC_CONST
;
7668 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
7669 SYMBOL_CLASS (sym
) = LOC_CONST
;
7673 complaint (&symfile_complaints
,
7674 _("unsupported const value attribute form: '%s'"),
7675 dwarf_form_name (attr
->form
));
7676 SYMBOL_VALUE (sym
) = 0;
7677 SYMBOL_CLASS (sym
) = LOC_CONST
;
7683 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
7684 or zero-extend it as appropriate for the symbol's type. */
7686 dwarf2_const_value_data (struct attribute
*attr
,
7690 LONGEST l
= DW_UNSND (attr
);
7692 if (bits
< sizeof (l
) * 8)
7694 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
7695 l
&= ((LONGEST
) 1 << bits
) - 1;
7697 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
7700 SYMBOL_VALUE (sym
) = l
;
7701 SYMBOL_CLASS (sym
) = LOC_CONST
;
7705 /* Return the type of the die in question using its DW_AT_type attribute. */
7707 static struct type
*
7708 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7710 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7712 struct attribute
*type_attr
;
7713 struct die_info
*type_die
;
7715 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
7718 /* A missing DW_AT_type represents a void type. */
7719 return builtin_type (gdbarch
)->builtin_void
;
7722 type_die
= follow_die_ref (die
, type_attr
, &cu
);
7724 type
= tag_type_to_type (type_die
, cu
);
7727 dump_die (type_die
);
7728 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
7734 /* Return the containing type of the die in question using its
7735 DW_AT_containing_type attribute. */
7737 static struct type
*
7738 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7740 struct type
*type
= NULL
;
7741 struct attribute
*type_attr
;
7742 struct die_info
*type_die
= NULL
;
7744 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
7747 type_die
= follow_die_ref (die
, type_attr
, &cu
);
7748 type
= tag_type_to_type (type_die
, cu
);
7753 dump_die (type_die
);
7754 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
7760 static struct type
*
7761 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7763 struct type
*this_type
;
7765 this_type
= read_type_die (die
, cu
);
7769 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
7775 static struct type
*
7776 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7778 struct type
*this_type
;
7780 this_type
= get_die_type (die
, cu
);
7786 case DW_TAG_class_type
:
7787 case DW_TAG_interface_type
:
7788 case DW_TAG_structure_type
:
7789 case DW_TAG_union_type
:
7790 this_type
= read_structure_type (die
, cu
);
7792 case DW_TAG_enumeration_type
:
7793 this_type
= read_enumeration_type (die
, cu
);
7795 case DW_TAG_subprogram
:
7796 case DW_TAG_subroutine_type
:
7797 this_type
= read_subroutine_type (die
, cu
);
7799 case DW_TAG_array_type
:
7800 this_type
= read_array_type (die
, cu
);
7802 case DW_TAG_set_type
:
7803 this_type
= read_set_type (die
, cu
);
7805 case DW_TAG_pointer_type
:
7806 this_type
= read_tag_pointer_type (die
, cu
);
7808 case DW_TAG_ptr_to_member_type
:
7809 this_type
= read_tag_ptr_to_member_type (die
, cu
);
7811 case DW_TAG_reference_type
:
7812 this_type
= read_tag_reference_type (die
, cu
);
7814 case DW_TAG_const_type
:
7815 this_type
= read_tag_const_type (die
, cu
);
7817 case DW_TAG_volatile_type
:
7818 this_type
= read_tag_volatile_type (die
, cu
);
7820 case DW_TAG_string_type
:
7821 this_type
= read_tag_string_type (die
, cu
);
7823 case DW_TAG_typedef
:
7824 this_type
= read_typedef (die
, cu
);
7826 case DW_TAG_subrange_type
:
7827 this_type
= read_subrange_type (die
, cu
);
7829 case DW_TAG_base_type
:
7830 this_type
= read_base_type (die
, cu
);
7832 case DW_TAG_unspecified_type
:
7833 this_type
= read_unspecified_type (die
, cu
);
7835 case DW_TAG_namespace
:
7836 this_type
= read_namespace_type (die
, cu
);
7839 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
7840 dwarf_tag_name (die
->tag
));
7847 /* Return the name of the namespace/class that DIE is defined within,
7848 or "" if we can't tell. The caller should not xfree the result.
7850 For example, if we're within the method foo() in the following
7860 then determine_prefix on foo's die will return "N::C". */
7863 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
7865 struct die_info
*parent
, *spec_die
;
7866 struct dwarf2_cu
*spec_cu
;
7867 struct type
*parent_type
;
7869 if (cu
->language
!= language_cplus
7870 && cu
->language
!= language_java
)
7873 /* We have to be careful in the presence of DW_AT_specification.
7874 For example, with GCC 3.4, given the code
7878 // Definition of N::foo.
7882 then we'll have a tree of DIEs like this:
7884 1: DW_TAG_compile_unit
7885 2: DW_TAG_namespace // N
7886 3: DW_TAG_subprogram // declaration of N::foo
7887 4: DW_TAG_subprogram // definition of N::foo
7888 DW_AT_specification // refers to die #3
7890 Thus, when processing die #4, we have to pretend that we're in
7891 the context of its DW_AT_specification, namely the contex of die
7894 spec_die
= die_specification (die
, &spec_cu
);
7895 if (spec_die
== NULL
)
7896 parent
= die
->parent
;
7899 parent
= spec_die
->parent
;
7906 switch (parent
->tag
)
7908 case DW_TAG_namespace
:
7909 parent_type
= read_type_die (parent
, cu
);
7910 /* We give a name to even anonymous namespaces. */
7911 return TYPE_TAG_NAME (parent_type
);
7912 case DW_TAG_class_type
:
7913 case DW_TAG_interface_type
:
7914 case DW_TAG_structure_type
:
7915 case DW_TAG_union_type
:
7916 parent_type
= read_type_die (parent
, cu
);
7917 if (TYPE_TAG_NAME (parent_type
) != NULL
)
7918 return TYPE_TAG_NAME (parent_type
);
7920 /* An anonymous structure is only allowed non-static data
7921 members; no typedefs, no member functions, et cetera.
7922 So it does not need a prefix. */
7925 return determine_prefix (parent
, cu
);
7929 /* Return a newly-allocated string formed by concatenating PREFIX and
7930 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
7931 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
7932 perform an obconcat, otherwise allocate storage for the result. The CU argument
7933 is used to determine the language and hence, the appropriate separator. */
7935 #define MAX_SEP_LEN 2 /* sizeof ("::") */
7938 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
7939 struct dwarf2_cu
*cu
)
7943 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
7945 else if (cu
->language
== language_java
)
7952 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
7957 strcpy (retval
, prefix
);
7958 strcat (retval
, sep
);
7961 strcat (retval
, suffix
);
7967 /* We have an obstack. */
7968 return obconcat (obs
, prefix
, sep
, suffix
);
7972 /* Return sibling of die, NULL if no sibling. */
7974 static struct die_info
*
7975 sibling_die (struct die_info
*die
)
7977 return die
->sibling
;
7980 /* Get linkage name of a die, return NULL if not found. */
7983 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
7985 struct attribute
*attr
;
7987 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7988 if (attr
&& DW_STRING (attr
))
7989 return DW_STRING (attr
);
7990 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7991 if (attr
&& DW_STRING (attr
))
7992 return DW_STRING (attr
);
7996 /* Get name of a die, return NULL if not found. */
7999 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8001 struct attribute
*attr
;
8003 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8004 if (attr
&& DW_STRING (attr
))
8005 return DW_STRING (attr
);
8009 /* Return the die that this die in an extension of, or NULL if there
8010 is none. *EXT_CU is the CU containing DIE on input, and the CU
8011 containing the return value on output. */
8013 static struct die_info
*
8014 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
8016 struct attribute
*attr
;
8018 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
8022 return follow_die_ref (die
, attr
, ext_cu
);
8025 /* Convert a DIE tag into its string name. */
8028 dwarf_tag_name (unsigned tag
)
8032 case DW_TAG_padding
:
8033 return "DW_TAG_padding";
8034 case DW_TAG_array_type
:
8035 return "DW_TAG_array_type";
8036 case DW_TAG_class_type
:
8037 return "DW_TAG_class_type";
8038 case DW_TAG_entry_point
:
8039 return "DW_TAG_entry_point";
8040 case DW_TAG_enumeration_type
:
8041 return "DW_TAG_enumeration_type";
8042 case DW_TAG_formal_parameter
:
8043 return "DW_TAG_formal_parameter";
8044 case DW_TAG_imported_declaration
:
8045 return "DW_TAG_imported_declaration";
8047 return "DW_TAG_label";
8048 case DW_TAG_lexical_block
:
8049 return "DW_TAG_lexical_block";
8051 return "DW_TAG_member";
8052 case DW_TAG_pointer_type
:
8053 return "DW_TAG_pointer_type";
8054 case DW_TAG_reference_type
:
8055 return "DW_TAG_reference_type";
8056 case DW_TAG_compile_unit
:
8057 return "DW_TAG_compile_unit";
8058 case DW_TAG_string_type
:
8059 return "DW_TAG_string_type";
8060 case DW_TAG_structure_type
:
8061 return "DW_TAG_structure_type";
8062 case DW_TAG_subroutine_type
:
8063 return "DW_TAG_subroutine_type";
8064 case DW_TAG_typedef
:
8065 return "DW_TAG_typedef";
8066 case DW_TAG_union_type
:
8067 return "DW_TAG_union_type";
8068 case DW_TAG_unspecified_parameters
:
8069 return "DW_TAG_unspecified_parameters";
8070 case DW_TAG_variant
:
8071 return "DW_TAG_variant";
8072 case DW_TAG_common_block
:
8073 return "DW_TAG_common_block";
8074 case DW_TAG_common_inclusion
:
8075 return "DW_TAG_common_inclusion";
8076 case DW_TAG_inheritance
:
8077 return "DW_TAG_inheritance";
8078 case DW_TAG_inlined_subroutine
:
8079 return "DW_TAG_inlined_subroutine";
8081 return "DW_TAG_module";
8082 case DW_TAG_ptr_to_member_type
:
8083 return "DW_TAG_ptr_to_member_type";
8084 case DW_TAG_set_type
:
8085 return "DW_TAG_set_type";
8086 case DW_TAG_subrange_type
:
8087 return "DW_TAG_subrange_type";
8088 case DW_TAG_with_stmt
:
8089 return "DW_TAG_with_stmt";
8090 case DW_TAG_access_declaration
:
8091 return "DW_TAG_access_declaration";
8092 case DW_TAG_base_type
:
8093 return "DW_TAG_base_type";
8094 case DW_TAG_catch_block
:
8095 return "DW_TAG_catch_block";
8096 case DW_TAG_const_type
:
8097 return "DW_TAG_const_type";
8098 case DW_TAG_constant
:
8099 return "DW_TAG_constant";
8100 case DW_TAG_enumerator
:
8101 return "DW_TAG_enumerator";
8102 case DW_TAG_file_type
:
8103 return "DW_TAG_file_type";
8105 return "DW_TAG_friend";
8106 case DW_TAG_namelist
:
8107 return "DW_TAG_namelist";
8108 case DW_TAG_namelist_item
:
8109 return "DW_TAG_namelist_item";
8110 case DW_TAG_packed_type
:
8111 return "DW_TAG_packed_type";
8112 case DW_TAG_subprogram
:
8113 return "DW_TAG_subprogram";
8114 case DW_TAG_template_type_param
:
8115 return "DW_TAG_template_type_param";
8116 case DW_TAG_template_value_param
:
8117 return "DW_TAG_template_value_param";
8118 case DW_TAG_thrown_type
:
8119 return "DW_TAG_thrown_type";
8120 case DW_TAG_try_block
:
8121 return "DW_TAG_try_block";
8122 case DW_TAG_variant_part
:
8123 return "DW_TAG_variant_part";
8124 case DW_TAG_variable
:
8125 return "DW_TAG_variable";
8126 case DW_TAG_volatile_type
:
8127 return "DW_TAG_volatile_type";
8128 case DW_TAG_dwarf_procedure
:
8129 return "DW_TAG_dwarf_procedure";
8130 case DW_TAG_restrict_type
:
8131 return "DW_TAG_restrict_type";
8132 case DW_TAG_interface_type
:
8133 return "DW_TAG_interface_type";
8134 case DW_TAG_namespace
:
8135 return "DW_TAG_namespace";
8136 case DW_TAG_imported_module
:
8137 return "DW_TAG_imported_module";
8138 case DW_TAG_unspecified_type
:
8139 return "DW_TAG_unspecified_type";
8140 case DW_TAG_partial_unit
:
8141 return "DW_TAG_partial_unit";
8142 case DW_TAG_imported_unit
:
8143 return "DW_TAG_imported_unit";
8144 case DW_TAG_condition
:
8145 return "DW_TAG_condition";
8146 case DW_TAG_shared_type
:
8147 return "DW_TAG_shared_type";
8148 case DW_TAG_MIPS_loop
:
8149 return "DW_TAG_MIPS_loop";
8150 case DW_TAG_HP_array_descriptor
:
8151 return "DW_TAG_HP_array_descriptor";
8152 case DW_TAG_format_label
:
8153 return "DW_TAG_format_label";
8154 case DW_TAG_function_template
:
8155 return "DW_TAG_function_template";
8156 case DW_TAG_class_template
:
8157 return "DW_TAG_class_template";
8158 case DW_TAG_GNU_BINCL
:
8159 return "DW_TAG_GNU_BINCL";
8160 case DW_TAG_GNU_EINCL
:
8161 return "DW_TAG_GNU_EINCL";
8162 case DW_TAG_upc_shared_type
:
8163 return "DW_TAG_upc_shared_type";
8164 case DW_TAG_upc_strict_type
:
8165 return "DW_TAG_upc_strict_type";
8166 case DW_TAG_upc_relaxed_type
:
8167 return "DW_TAG_upc_relaxed_type";
8168 case DW_TAG_PGI_kanji_type
:
8169 return "DW_TAG_PGI_kanji_type";
8170 case DW_TAG_PGI_interface_block
:
8171 return "DW_TAG_PGI_interface_block";
8173 return "DW_TAG_<unknown>";
8177 /* Convert a DWARF attribute code into its string name. */
8180 dwarf_attr_name (unsigned attr
)
8185 return "DW_AT_sibling";
8186 case DW_AT_location
:
8187 return "DW_AT_location";
8189 return "DW_AT_name";
8190 case DW_AT_ordering
:
8191 return "DW_AT_ordering";
8192 case DW_AT_subscr_data
:
8193 return "DW_AT_subscr_data";
8194 case DW_AT_byte_size
:
8195 return "DW_AT_byte_size";
8196 case DW_AT_bit_offset
:
8197 return "DW_AT_bit_offset";
8198 case DW_AT_bit_size
:
8199 return "DW_AT_bit_size";
8200 case DW_AT_element_list
:
8201 return "DW_AT_element_list";
8202 case DW_AT_stmt_list
:
8203 return "DW_AT_stmt_list";
8205 return "DW_AT_low_pc";
8207 return "DW_AT_high_pc";
8208 case DW_AT_language
:
8209 return "DW_AT_language";
8211 return "DW_AT_member";
8213 return "DW_AT_discr";
8214 case DW_AT_discr_value
:
8215 return "DW_AT_discr_value";
8216 case DW_AT_visibility
:
8217 return "DW_AT_visibility";
8219 return "DW_AT_import";
8220 case DW_AT_string_length
:
8221 return "DW_AT_string_length";
8222 case DW_AT_common_reference
:
8223 return "DW_AT_common_reference";
8224 case DW_AT_comp_dir
:
8225 return "DW_AT_comp_dir";
8226 case DW_AT_const_value
:
8227 return "DW_AT_const_value";
8228 case DW_AT_containing_type
:
8229 return "DW_AT_containing_type";
8230 case DW_AT_default_value
:
8231 return "DW_AT_default_value";
8233 return "DW_AT_inline";
8234 case DW_AT_is_optional
:
8235 return "DW_AT_is_optional";
8236 case DW_AT_lower_bound
:
8237 return "DW_AT_lower_bound";
8238 case DW_AT_producer
:
8239 return "DW_AT_producer";
8240 case DW_AT_prototyped
:
8241 return "DW_AT_prototyped";
8242 case DW_AT_return_addr
:
8243 return "DW_AT_return_addr";
8244 case DW_AT_start_scope
:
8245 return "DW_AT_start_scope";
8246 case DW_AT_bit_stride
:
8247 return "DW_AT_bit_stride";
8248 case DW_AT_upper_bound
:
8249 return "DW_AT_upper_bound";
8250 case DW_AT_abstract_origin
:
8251 return "DW_AT_abstract_origin";
8252 case DW_AT_accessibility
:
8253 return "DW_AT_accessibility";
8254 case DW_AT_address_class
:
8255 return "DW_AT_address_class";
8256 case DW_AT_artificial
:
8257 return "DW_AT_artificial";
8258 case DW_AT_base_types
:
8259 return "DW_AT_base_types";
8260 case DW_AT_calling_convention
:
8261 return "DW_AT_calling_convention";
8263 return "DW_AT_count";
8264 case DW_AT_data_member_location
:
8265 return "DW_AT_data_member_location";
8266 case DW_AT_decl_column
:
8267 return "DW_AT_decl_column";
8268 case DW_AT_decl_file
:
8269 return "DW_AT_decl_file";
8270 case DW_AT_decl_line
:
8271 return "DW_AT_decl_line";
8272 case DW_AT_declaration
:
8273 return "DW_AT_declaration";
8274 case DW_AT_discr_list
:
8275 return "DW_AT_discr_list";
8276 case DW_AT_encoding
:
8277 return "DW_AT_encoding";
8278 case DW_AT_external
:
8279 return "DW_AT_external";
8280 case DW_AT_frame_base
:
8281 return "DW_AT_frame_base";
8283 return "DW_AT_friend";
8284 case DW_AT_identifier_case
:
8285 return "DW_AT_identifier_case";
8286 case DW_AT_macro_info
:
8287 return "DW_AT_macro_info";
8288 case DW_AT_namelist_items
:
8289 return "DW_AT_namelist_items";
8290 case DW_AT_priority
:
8291 return "DW_AT_priority";
8293 return "DW_AT_segment";
8294 case DW_AT_specification
:
8295 return "DW_AT_specification";
8296 case DW_AT_static_link
:
8297 return "DW_AT_static_link";
8299 return "DW_AT_type";
8300 case DW_AT_use_location
:
8301 return "DW_AT_use_location";
8302 case DW_AT_variable_parameter
:
8303 return "DW_AT_variable_parameter";
8304 case DW_AT_virtuality
:
8305 return "DW_AT_virtuality";
8306 case DW_AT_vtable_elem_location
:
8307 return "DW_AT_vtable_elem_location";
8308 /* DWARF 3 values. */
8309 case DW_AT_allocated
:
8310 return "DW_AT_allocated";
8311 case DW_AT_associated
:
8312 return "DW_AT_associated";
8313 case DW_AT_data_location
:
8314 return "DW_AT_data_location";
8315 case DW_AT_byte_stride
:
8316 return "DW_AT_byte_stride";
8317 case DW_AT_entry_pc
:
8318 return "DW_AT_entry_pc";
8319 case DW_AT_use_UTF8
:
8320 return "DW_AT_use_UTF8";
8321 case DW_AT_extension
:
8322 return "DW_AT_extension";
8324 return "DW_AT_ranges";
8325 case DW_AT_trampoline
:
8326 return "DW_AT_trampoline";
8327 case DW_AT_call_column
:
8328 return "DW_AT_call_column";
8329 case DW_AT_call_file
:
8330 return "DW_AT_call_file";
8331 case DW_AT_call_line
:
8332 return "DW_AT_call_line";
8333 case DW_AT_description
:
8334 return "DW_AT_description";
8335 case DW_AT_binary_scale
:
8336 return "DW_AT_binary_scale";
8337 case DW_AT_decimal_scale
:
8338 return "DW_AT_decimal_scale";
8340 return "DW_AT_small";
8341 case DW_AT_decimal_sign
:
8342 return "DW_AT_decimal_sign";
8343 case DW_AT_digit_count
:
8344 return "DW_AT_digit_count";
8345 case DW_AT_picture_string
:
8346 return "DW_AT_picture_string";
8348 return "DW_AT_mutable";
8349 case DW_AT_threads_scaled
:
8350 return "DW_AT_threads_scaled";
8351 case DW_AT_explicit
:
8352 return "DW_AT_explicit";
8353 case DW_AT_object_pointer
:
8354 return "DW_AT_object_pointer";
8355 case DW_AT_endianity
:
8356 return "DW_AT_endianity";
8357 case DW_AT_elemental
:
8358 return "DW_AT_elemental";
8360 return "DW_AT_pure";
8361 case DW_AT_recursive
:
8362 return "DW_AT_recursive";
8364 /* SGI/MIPS extensions. */
8365 case DW_AT_MIPS_fde
:
8366 return "DW_AT_MIPS_fde";
8367 case DW_AT_MIPS_loop_begin
:
8368 return "DW_AT_MIPS_loop_begin";
8369 case DW_AT_MIPS_tail_loop_begin
:
8370 return "DW_AT_MIPS_tail_loop_begin";
8371 case DW_AT_MIPS_epilog_begin
:
8372 return "DW_AT_MIPS_epilog_begin";
8373 case DW_AT_MIPS_loop_unroll_factor
:
8374 return "DW_AT_MIPS_loop_unroll_factor";
8375 case DW_AT_MIPS_software_pipeline_depth
:
8376 return "DW_AT_MIPS_software_pipeline_depth";
8377 case DW_AT_MIPS_linkage_name
:
8378 return "DW_AT_MIPS_linkage_name";
8379 case DW_AT_MIPS_stride
:
8380 return "DW_AT_MIPS_stride";
8381 case DW_AT_MIPS_abstract_name
:
8382 return "DW_AT_MIPS_abstract_name";
8383 case DW_AT_MIPS_clone_origin
:
8384 return "DW_AT_MIPS_clone_origin";
8385 case DW_AT_MIPS_has_inlines
:
8386 return "DW_AT_MIPS_has_inlines";
8388 /* HP extensions. */
8389 case DW_AT_HP_block_index
:
8390 return "DW_AT_HP_block_index";
8391 case DW_AT_HP_unmodifiable
:
8392 return "DW_AT_HP_unmodifiable";
8393 case DW_AT_HP_actuals_stmt_list
:
8394 return "DW_AT_HP_actuals_stmt_list";
8395 case DW_AT_HP_proc_per_section
:
8396 return "DW_AT_HP_proc_per_section";
8397 case DW_AT_HP_raw_data_ptr
:
8398 return "DW_AT_HP_raw_data_ptr";
8399 case DW_AT_HP_pass_by_reference
:
8400 return "DW_AT_HP_pass_by_reference";
8401 case DW_AT_HP_opt_level
:
8402 return "DW_AT_HP_opt_level";
8403 case DW_AT_HP_prof_version_id
:
8404 return "DW_AT_HP_prof_version_id";
8405 case DW_AT_HP_opt_flags
:
8406 return "DW_AT_HP_opt_flags";
8407 case DW_AT_HP_cold_region_low_pc
:
8408 return "DW_AT_HP_cold_region_low_pc";
8409 case DW_AT_HP_cold_region_high_pc
:
8410 return "DW_AT_HP_cold_region_high_pc";
8411 case DW_AT_HP_all_variables_modifiable
:
8412 return "DW_AT_HP_all_variables_modifiable";
8413 case DW_AT_HP_linkage_name
:
8414 return "DW_AT_HP_linkage_name";
8415 case DW_AT_HP_prof_flags
:
8416 return "DW_AT_HP_prof_flags";
8417 /* GNU extensions. */
8418 case DW_AT_sf_names
:
8419 return "DW_AT_sf_names";
8420 case DW_AT_src_info
:
8421 return "DW_AT_src_info";
8422 case DW_AT_mac_info
:
8423 return "DW_AT_mac_info";
8424 case DW_AT_src_coords
:
8425 return "DW_AT_src_coords";
8426 case DW_AT_body_begin
:
8427 return "DW_AT_body_begin";
8428 case DW_AT_body_end
:
8429 return "DW_AT_body_end";
8430 case DW_AT_GNU_vector
:
8431 return "DW_AT_GNU_vector";
8432 /* VMS extensions. */
8433 case DW_AT_VMS_rtnbeg_pd_address
:
8434 return "DW_AT_VMS_rtnbeg_pd_address";
8435 /* UPC extension. */
8436 case DW_AT_upc_threads_scaled
:
8437 return "DW_AT_upc_threads_scaled";
8438 /* PGI (STMicroelectronics) extensions. */
8439 case DW_AT_PGI_lbase
:
8440 return "DW_AT_PGI_lbase";
8441 case DW_AT_PGI_soffset
:
8442 return "DW_AT_PGI_soffset";
8443 case DW_AT_PGI_lstride
:
8444 return "DW_AT_PGI_lstride";
8446 return "DW_AT_<unknown>";
8450 /* Convert a DWARF value form code into its string name. */
8453 dwarf_form_name (unsigned form
)
8458 return "DW_FORM_addr";
8459 case DW_FORM_block2
:
8460 return "DW_FORM_block2";
8461 case DW_FORM_block4
:
8462 return "DW_FORM_block4";
8464 return "DW_FORM_data2";
8466 return "DW_FORM_data4";
8468 return "DW_FORM_data8";
8469 case DW_FORM_string
:
8470 return "DW_FORM_string";
8472 return "DW_FORM_block";
8473 case DW_FORM_block1
:
8474 return "DW_FORM_block1";
8476 return "DW_FORM_data1";
8478 return "DW_FORM_flag";
8480 return "DW_FORM_sdata";
8482 return "DW_FORM_strp";
8484 return "DW_FORM_udata";
8485 case DW_FORM_ref_addr
:
8486 return "DW_FORM_ref_addr";
8488 return "DW_FORM_ref1";
8490 return "DW_FORM_ref2";
8492 return "DW_FORM_ref4";
8494 return "DW_FORM_ref8";
8495 case DW_FORM_ref_udata
:
8496 return "DW_FORM_ref_udata";
8497 case DW_FORM_indirect
:
8498 return "DW_FORM_indirect";
8500 return "DW_FORM_<unknown>";
8504 /* Convert a DWARF stack opcode into its string name. */
8507 dwarf_stack_op_name (unsigned op
)
8512 return "DW_OP_addr";
8514 return "DW_OP_deref";
8516 return "DW_OP_const1u";
8518 return "DW_OP_const1s";
8520 return "DW_OP_const2u";
8522 return "DW_OP_const2s";
8524 return "DW_OP_const4u";
8526 return "DW_OP_const4s";
8528 return "DW_OP_const8u";
8530 return "DW_OP_const8s";
8532 return "DW_OP_constu";
8534 return "DW_OP_consts";
8538 return "DW_OP_drop";
8540 return "DW_OP_over";
8542 return "DW_OP_pick";
8544 return "DW_OP_swap";
8548 return "DW_OP_xderef";
8556 return "DW_OP_minus";
8568 return "DW_OP_plus";
8569 case DW_OP_plus_uconst
:
8570 return "DW_OP_plus_uconst";
8576 return "DW_OP_shra";
8594 return "DW_OP_skip";
8596 return "DW_OP_lit0";
8598 return "DW_OP_lit1";
8600 return "DW_OP_lit2";
8602 return "DW_OP_lit3";
8604 return "DW_OP_lit4";
8606 return "DW_OP_lit5";
8608 return "DW_OP_lit6";
8610 return "DW_OP_lit7";
8612 return "DW_OP_lit8";
8614 return "DW_OP_lit9";
8616 return "DW_OP_lit10";
8618 return "DW_OP_lit11";
8620 return "DW_OP_lit12";
8622 return "DW_OP_lit13";
8624 return "DW_OP_lit14";
8626 return "DW_OP_lit15";
8628 return "DW_OP_lit16";
8630 return "DW_OP_lit17";
8632 return "DW_OP_lit18";
8634 return "DW_OP_lit19";
8636 return "DW_OP_lit20";
8638 return "DW_OP_lit21";
8640 return "DW_OP_lit22";
8642 return "DW_OP_lit23";
8644 return "DW_OP_lit24";
8646 return "DW_OP_lit25";
8648 return "DW_OP_lit26";
8650 return "DW_OP_lit27";
8652 return "DW_OP_lit28";
8654 return "DW_OP_lit29";
8656 return "DW_OP_lit30";
8658 return "DW_OP_lit31";
8660 return "DW_OP_reg0";
8662 return "DW_OP_reg1";
8664 return "DW_OP_reg2";
8666 return "DW_OP_reg3";
8668 return "DW_OP_reg4";
8670 return "DW_OP_reg5";
8672 return "DW_OP_reg6";
8674 return "DW_OP_reg7";
8676 return "DW_OP_reg8";
8678 return "DW_OP_reg9";
8680 return "DW_OP_reg10";
8682 return "DW_OP_reg11";
8684 return "DW_OP_reg12";
8686 return "DW_OP_reg13";
8688 return "DW_OP_reg14";
8690 return "DW_OP_reg15";
8692 return "DW_OP_reg16";
8694 return "DW_OP_reg17";
8696 return "DW_OP_reg18";
8698 return "DW_OP_reg19";
8700 return "DW_OP_reg20";
8702 return "DW_OP_reg21";
8704 return "DW_OP_reg22";
8706 return "DW_OP_reg23";
8708 return "DW_OP_reg24";
8710 return "DW_OP_reg25";
8712 return "DW_OP_reg26";
8714 return "DW_OP_reg27";
8716 return "DW_OP_reg28";
8718 return "DW_OP_reg29";
8720 return "DW_OP_reg30";
8722 return "DW_OP_reg31";
8724 return "DW_OP_breg0";
8726 return "DW_OP_breg1";
8728 return "DW_OP_breg2";
8730 return "DW_OP_breg3";
8732 return "DW_OP_breg4";
8734 return "DW_OP_breg5";
8736 return "DW_OP_breg6";
8738 return "DW_OP_breg7";
8740 return "DW_OP_breg8";
8742 return "DW_OP_breg9";
8744 return "DW_OP_breg10";
8746 return "DW_OP_breg11";
8748 return "DW_OP_breg12";
8750 return "DW_OP_breg13";
8752 return "DW_OP_breg14";
8754 return "DW_OP_breg15";
8756 return "DW_OP_breg16";
8758 return "DW_OP_breg17";
8760 return "DW_OP_breg18";
8762 return "DW_OP_breg19";
8764 return "DW_OP_breg20";
8766 return "DW_OP_breg21";
8768 return "DW_OP_breg22";
8770 return "DW_OP_breg23";
8772 return "DW_OP_breg24";
8774 return "DW_OP_breg25";
8776 return "DW_OP_breg26";
8778 return "DW_OP_breg27";
8780 return "DW_OP_breg28";
8782 return "DW_OP_breg29";
8784 return "DW_OP_breg30";
8786 return "DW_OP_breg31";
8788 return "DW_OP_regx";
8790 return "DW_OP_fbreg";
8792 return "DW_OP_bregx";
8794 return "DW_OP_piece";
8795 case DW_OP_deref_size
:
8796 return "DW_OP_deref_size";
8797 case DW_OP_xderef_size
:
8798 return "DW_OP_xderef_size";
8801 /* DWARF 3 extensions. */
8802 case DW_OP_push_object_address
:
8803 return "DW_OP_push_object_address";
8805 return "DW_OP_call2";
8807 return "DW_OP_call4";
8808 case DW_OP_call_ref
:
8809 return "DW_OP_call_ref";
8810 /* GNU extensions. */
8811 case DW_OP_form_tls_address
:
8812 return "DW_OP_form_tls_address";
8813 case DW_OP_call_frame_cfa
:
8814 return "DW_OP_call_frame_cfa";
8815 case DW_OP_bit_piece
:
8816 return "DW_OP_bit_piece";
8817 case DW_OP_GNU_push_tls_address
:
8818 return "DW_OP_GNU_push_tls_address";
8819 case DW_OP_GNU_uninit
:
8820 return "DW_OP_GNU_uninit";
8821 /* HP extensions. */
8822 case DW_OP_HP_is_value
:
8823 return "DW_OP_HP_is_value";
8824 case DW_OP_HP_fltconst4
:
8825 return "DW_OP_HP_fltconst4";
8826 case DW_OP_HP_fltconst8
:
8827 return "DW_OP_HP_fltconst8";
8828 case DW_OP_HP_mod_range
:
8829 return "DW_OP_HP_mod_range";
8830 case DW_OP_HP_unmod_range
:
8831 return "DW_OP_HP_unmod_range";
8833 return "DW_OP_HP_tls";
8835 return "OP_<unknown>";
8840 dwarf_bool_name (unsigned mybool
)
8848 /* Convert a DWARF type code into its string name. */
8851 dwarf_type_encoding_name (unsigned enc
)
8856 return "DW_ATE_void";
8857 case DW_ATE_address
:
8858 return "DW_ATE_address";
8859 case DW_ATE_boolean
:
8860 return "DW_ATE_boolean";
8861 case DW_ATE_complex_float
:
8862 return "DW_ATE_complex_float";
8864 return "DW_ATE_float";
8866 return "DW_ATE_signed";
8867 case DW_ATE_signed_char
:
8868 return "DW_ATE_signed_char";
8869 case DW_ATE_unsigned
:
8870 return "DW_ATE_unsigned";
8871 case DW_ATE_unsigned_char
:
8872 return "DW_ATE_unsigned_char";
8874 case DW_ATE_imaginary_float
:
8875 return "DW_ATE_imaginary_float";
8876 case DW_ATE_packed_decimal
:
8877 return "DW_ATE_packed_decimal";
8878 case DW_ATE_numeric_string
:
8879 return "DW_ATE_numeric_string";
8881 return "DW_ATE_edited";
8882 case DW_ATE_signed_fixed
:
8883 return "DW_ATE_signed_fixed";
8884 case DW_ATE_unsigned_fixed
:
8885 return "DW_ATE_unsigned_fixed";
8886 case DW_ATE_decimal_float
:
8887 return "DW_ATE_decimal_float";
8888 /* HP extensions. */
8889 case DW_ATE_HP_float80
:
8890 return "DW_ATE_HP_float80";
8891 case DW_ATE_HP_complex_float80
:
8892 return "DW_ATE_HP_complex_float80";
8893 case DW_ATE_HP_float128
:
8894 return "DW_ATE_HP_float128";
8895 case DW_ATE_HP_complex_float128
:
8896 return "DW_ATE_HP_complex_float128";
8897 case DW_ATE_HP_floathpintel
:
8898 return "DW_ATE_HP_floathpintel";
8899 case DW_ATE_HP_imaginary_float80
:
8900 return "DW_ATE_HP_imaginary_float80";
8901 case DW_ATE_HP_imaginary_float128
:
8902 return "DW_ATE_HP_imaginary_float128";
8904 return "DW_ATE_<unknown>";
8908 /* Convert a DWARF call frame info operation to its string name. */
8912 dwarf_cfi_name (unsigned cfi_opc
)
8916 case DW_CFA_advance_loc
:
8917 return "DW_CFA_advance_loc";
8919 return "DW_CFA_offset";
8920 case DW_CFA_restore
:
8921 return "DW_CFA_restore";
8923 return "DW_CFA_nop";
8924 case DW_CFA_set_loc
:
8925 return "DW_CFA_set_loc";
8926 case DW_CFA_advance_loc1
:
8927 return "DW_CFA_advance_loc1";
8928 case DW_CFA_advance_loc2
:
8929 return "DW_CFA_advance_loc2";
8930 case DW_CFA_advance_loc4
:
8931 return "DW_CFA_advance_loc4";
8932 case DW_CFA_offset_extended
:
8933 return "DW_CFA_offset_extended";
8934 case DW_CFA_restore_extended
:
8935 return "DW_CFA_restore_extended";
8936 case DW_CFA_undefined
:
8937 return "DW_CFA_undefined";
8938 case DW_CFA_same_value
:
8939 return "DW_CFA_same_value";
8940 case DW_CFA_register
:
8941 return "DW_CFA_register";
8942 case DW_CFA_remember_state
:
8943 return "DW_CFA_remember_state";
8944 case DW_CFA_restore_state
:
8945 return "DW_CFA_restore_state";
8946 case DW_CFA_def_cfa
:
8947 return "DW_CFA_def_cfa";
8948 case DW_CFA_def_cfa_register
:
8949 return "DW_CFA_def_cfa_register";
8950 case DW_CFA_def_cfa_offset
:
8951 return "DW_CFA_def_cfa_offset";
8953 case DW_CFA_def_cfa_expression
:
8954 return "DW_CFA_def_cfa_expression";
8955 case DW_CFA_expression
:
8956 return "DW_CFA_expression";
8957 case DW_CFA_offset_extended_sf
:
8958 return "DW_CFA_offset_extended_sf";
8959 case DW_CFA_def_cfa_sf
:
8960 return "DW_CFA_def_cfa_sf";
8961 case DW_CFA_def_cfa_offset_sf
:
8962 return "DW_CFA_def_cfa_offset_sf";
8963 case DW_CFA_val_offset
:
8964 return "DW_CFA_val_offset";
8965 case DW_CFA_val_offset_sf
:
8966 return "DW_CFA_val_offset_sf";
8967 case DW_CFA_val_expression
:
8968 return "DW_CFA_val_expression";
8969 /* SGI/MIPS specific. */
8970 case DW_CFA_MIPS_advance_loc8
:
8971 return "DW_CFA_MIPS_advance_loc8";
8972 /* GNU extensions. */
8973 case DW_CFA_GNU_window_save
:
8974 return "DW_CFA_GNU_window_save";
8975 case DW_CFA_GNU_args_size
:
8976 return "DW_CFA_GNU_args_size";
8977 case DW_CFA_GNU_negative_offset_extended
:
8978 return "DW_CFA_GNU_negative_offset_extended";
8980 return "DW_CFA_<unknown>";
8986 dump_die (struct die_info
*die
)
8990 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
8991 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
8992 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
8993 dwarf_bool_name (die
->child
!= NULL
));
8995 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
8996 for (i
= 0; i
< die
->num_attrs
; ++i
)
8998 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
8999 dwarf_attr_name (die
->attrs
[i
].name
),
9000 dwarf_form_name (die
->attrs
[i
].form
));
9001 switch (die
->attrs
[i
].form
)
9003 case DW_FORM_ref_addr
:
9005 fprintf_unfiltered (gdb_stderr
, "address: ");
9006 fputs_filtered (paddress (DW_ADDR (&die
->attrs
[i
])), gdb_stderr
);
9008 case DW_FORM_block2
:
9009 case DW_FORM_block4
:
9011 case DW_FORM_block1
:
9012 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
9017 fprintf_unfiltered (gdb_stderr
, "constant ref: %ld (adjusted)",
9018 (long) (DW_ADDR (&die
->attrs
[i
])));
9026 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
9028 case DW_FORM_string
:
9030 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
9031 DW_STRING (&die
->attrs
[i
])
9032 ? DW_STRING (&die
->attrs
[i
]) : "");
9035 if (DW_UNSND (&die
->attrs
[i
]))
9036 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
9038 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
9040 case DW_FORM_indirect
:
9041 /* the reader will have reduced the indirect form to
9042 the "base form" so this form should not occur */
9043 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
9046 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
9047 die
->attrs
[i
].form
);
9049 fprintf_unfiltered (gdb_stderr
, "\n");
9054 dump_die_list (struct die_info
*die
)
9059 if (die
->child
!= NULL
)
9060 dump_die_list (die
->child
);
9061 if (die
->sibling
!= NULL
)
9062 dump_die_list (die
->sibling
);
9067 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
9071 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
9077 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
9079 unsigned int result
= 0;
9083 case DW_FORM_ref_addr
:
9088 case DW_FORM_ref_udata
:
9089 result
= DW_ADDR (attr
);
9092 complaint (&symfile_complaints
,
9093 _("unsupported die ref attribute form: '%s'"),
9094 dwarf_form_name (attr
->form
));
9099 /* Return the constant value held by the given attribute. Return -1
9100 if the value held by the attribute is not constant. */
9103 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
9105 if (attr
->form
== DW_FORM_sdata
)
9106 return DW_SND (attr
);
9107 else if (attr
->form
== DW_FORM_udata
9108 || attr
->form
== DW_FORM_data1
9109 || attr
->form
== DW_FORM_data2
9110 || attr
->form
== DW_FORM_data4
9111 || attr
->form
== DW_FORM_data8
)
9112 return DW_UNSND (attr
);
9115 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
9116 dwarf_form_name (attr
->form
));
9117 return default_value
;
9121 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
9122 unit and add it to our queue. */
9125 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
9126 struct dwarf2_per_cu_data
*per_cu
)
9128 /* Mark the dependence relation so that we don't flush PER_CU
9130 dwarf2_add_dependence (this_cu
, per_cu
);
9132 /* If it's already on the queue, we have nothing to do. */
9136 /* If the compilation unit is already loaded, just mark it as
9138 if (per_cu
->cu
!= NULL
)
9140 per_cu
->cu
->last_used
= 0;
9144 /* Add it to the queue. */
9145 queue_comp_unit (per_cu
, this_cu
->objfile
);
9148 static struct die_info
*
9149 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
9150 struct dwarf2_cu
**ref_cu
)
9152 struct die_info
*die
;
9153 unsigned int offset
;
9154 struct die_info temp_die
;
9155 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
9157 offset
= dwarf2_get_ref_die_offset (attr
, cu
);
9159 if (DW_ADDR (attr
) < cu
->header
.offset
9160 || DW_ADDR (attr
) >= cu
->header
.offset
+ cu
->header
.length
)
9162 struct dwarf2_per_cu_data
*per_cu
;
9163 per_cu
= dwarf2_find_containing_comp_unit (DW_ADDR (attr
),
9166 /* If necessary, add it to the queue and load its DIEs. */
9167 maybe_queue_comp_unit (cu
, per_cu
);
9169 target_cu
= per_cu
->cu
;
9174 *ref_cu
= target_cu
;
9175 temp_die
.offset
= offset
;
9176 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
9180 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
9181 "at 0x%lx [in module %s]"),
9182 (long) offset
, (long) src_die
->offset
, cu
->objfile
->name
);
9185 /* Decode simple location descriptions.
9186 Given a pointer to a dwarf block that defines a location, compute
9187 the location and return the value.
9189 NOTE drow/2003-11-18: This function is called in two situations
9190 now: for the address of static or global variables (partial symbols
9191 only) and for offsets into structures which are expected to be
9192 (more or less) constant. The partial symbol case should go away,
9193 and only the constant case should remain. That will let this
9194 function complain more accurately. A few special modes are allowed
9195 without complaint for global variables (for instance, global
9196 register values and thread-local values).
9198 A location description containing no operations indicates that the
9199 object is optimized out. The return value is 0 for that case.
9200 FIXME drow/2003-11-16: No callers check for this case any more; soon all
9201 callers will only want a very basic result and this can become a
9204 Note that stack[0] is unused except as a default error return.
9205 Note that stack overflow is not yet handled. */
9208 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
9210 struct objfile
*objfile
= cu
->objfile
;
9211 struct comp_unit_head
*cu_header
= &cu
->header
;
9213 int size
= blk
->size
;
9214 gdb_byte
*data
= blk
->data
;
9215 CORE_ADDR stack
[64];
9217 unsigned int bytes_read
, unsnd
;
9261 stack
[++stacki
] = op
- DW_OP_lit0
;
9296 stack
[++stacki
] = op
- DW_OP_reg0
;
9298 dwarf2_complex_location_expr_complaint ();
9302 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9304 stack
[++stacki
] = unsnd
;
9306 dwarf2_complex_location_expr_complaint ();
9310 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
9316 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
9321 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
9326 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
9331 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
9336 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
9341 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
9346 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
9352 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
9357 stack
[stacki
+ 1] = stack
[stacki
];
9362 stack
[stacki
- 1] += stack
[stacki
];
9366 case DW_OP_plus_uconst
:
9367 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9372 stack
[stacki
- 1] -= stack
[stacki
];
9377 /* If we're not the last op, then we definitely can't encode
9378 this using GDB's address_class enum. This is valid for partial
9379 global symbols, although the variable's address will be bogus
9382 dwarf2_complex_location_expr_complaint ();
9385 case DW_OP_GNU_push_tls_address
:
9386 /* The top of the stack has the offset from the beginning
9387 of the thread control block at which the variable is located. */
9388 /* Nothing should follow this operator, so the top of stack would
9390 /* This is valid for partial global symbols, but the variable's
9391 address will be bogus in the psymtab. */
9393 dwarf2_complex_location_expr_complaint ();
9396 case DW_OP_GNU_uninit
:
9400 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
9401 dwarf_stack_op_name (op
));
9402 return (stack
[stacki
]);
9405 return (stack
[stacki
]);
9408 /* memory allocation interface */
9410 static struct dwarf_block
*
9411 dwarf_alloc_block (struct dwarf2_cu
*cu
)
9413 struct dwarf_block
*blk
;
9415 blk
= (struct dwarf_block
*)
9416 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
9420 static struct abbrev_info
*
9421 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
9423 struct abbrev_info
*abbrev
;
9425 abbrev
= (struct abbrev_info
*)
9426 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
9427 memset (abbrev
, 0, sizeof (struct abbrev_info
));
9431 static struct die_info
*
9432 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
9434 struct die_info
*die
;
9435 size_t size
= sizeof (struct die_info
);
9438 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
9440 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
9441 memset (die
, 0, sizeof (struct die_info
));
9446 /* Macro support. */
9449 /* Return the full name of file number I in *LH's file name table.
9450 Use COMP_DIR as the name of the current directory of the
9451 compilation. The result is allocated using xmalloc; the caller is
9452 responsible for freeing it. */
9454 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
9456 /* Is the file number a valid index into the line header's file name
9457 table? Remember that file numbers start with one, not zero. */
9458 if (1 <= file
&& file
<= lh
->num_file_names
)
9460 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9462 if (IS_ABSOLUTE_PATH (fe
->name
))
9463 return xstrdup (fe
->name
);
9471 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9477 dir_len
= strlen (dir
);
9478 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
9479 strcpy (full_name
, dir
);
9480 full_name
[dir_len
] = '/';
9481 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
9485 return xstrdup (fe
->name
);
9490 /* The compiler produced a bogus file number. We can at least
9491 record the macro definitions made in the file, even if we
9492 won't be able to find the file by name. */
9494 sprintf (fake_name
, "<bad macro file number %d>", file
);
9496 complaint (&symfile_complaints
,
9497 _("bad file number in macro information (%d)"),
9500 return xstrdup (fake_name
);
9505 static struct macro_source_file
*
9506 macro_start_file (int file
, int line
,
9507 struct macro_source_file
*current_file
,
9508 const char *comp_dir
,
9509 struct line_header
*lh
, struct objfile
*objfile
)
9511 /* The full name of this source file. */
9512 char *full_name
= file_full_name (file
, lh
, comp_dir
);
9514 /* We don't create a macro table for this compilation unit
9515 at all until we actually get a filename. */
9516 if (! pending_macros
)
9517 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
9518 objfile
->macro_cache
);
9521 /* If we have no current file, then this must be the start_file
9522 directive for the compilation unit's main source file. */
9523 current_file
= macro_set_main (pending_macros
, full_name
);
9525 current_file
= macro_include (current_file
, line
, full_name
);
9529 return current_file
;
9533 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
9534 followed by a null byte. */
9536 copy_string (const char *buf
, int len
)
9538 char *s
= xmalloc (len
+ 1);
9539 memcpy (s
, buf
, len
);
9547 consume_improper_spaces (const char *p
, const char *body
)
9551 complaint (&symfile_complaints
,
9552 _("macro definition contains spaces in formal argument list:\n`%s'"),
9564 parse_macro_definition (struct macro_source_file
*file
, int line
,
9569 /* The body string takes one of two forms. For object-like macro
9570 definitions, it should be:
9572 <macro name> " " <definition>
9574 For function-like macro definitions, it should be:
9576 <macro name> "() " <definition>
9578 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
9580 Spaces may appear only where explicitly indicated, and in the
9583 The Dwarf 2 spec says that an object-like macro's name is always
9584 followed by a space, but versions of GCC around March 2002 omit
9585 the space when the macro's definition is the empty string.
9587 The Dwarf 2 spec says that there should be no spaces between the
9588 formal arguments in a function-like macro's formal argument list,
9589 but versions of GCC around March 2002 include spaces after the
9593 /* Find the extent of the macro name. The macro name is terminated
9594 by either a space or null character (for an object-like macro) or
9595 an opening paren (for a function-like macro). */
9596 for (p
= body
; *p
; p
++)
9597 if (*p
== ' ' || *p
== '(')
9600 if (*p
== ' ' || *p
== '\0')
9602 /* It's an object-like macro. */
9603 int name_len
= p
- body
;
9604 char *name
= copy_string (body
, name_len
);
9605 const char *replacement
;
9608 replacement
= body
+ name_len
+ 1;
9611 dwarf2_macro_malformed_definition_complaint (body
);
9612 replacement
= body
+ name_len
;
9615 macro_define_object (file
, line
, name
, replacement
);
9621 /* It's a function-like macro. */
9622 char *name
= copy_string (body
, p
- body
);
9625 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
9629 p
= consume_improper_spaces (p
, body
);
9631 /* Parse the formal argument list. */
9632 while (*p
&& *p
!= ')')
9634 /* Find the extent of the current argument name. */
9635 const char *arg_start
= p
;
9637 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
9640 if (! *p
|| p
== arg_start
)
9641 dwarf2_macro_malformed_definition_complaint (body
);
9644 /* Make sure argv has room for the new argument. */
9645 if (argc
>= argv_size
)
9648 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
9651 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
9654 p
= consume_improper_spaces (p
, body
);
9656 /* Consume the comma, if present. */
9661 p
= consume_improper_spaces (p
, body
);
9670 /* Perfectly formed definition, no complaints. */
9671 macro_define_function (file
, line
, name
,
9672 argc
, (const char **) argv
,
9674 else if (*p
== '\0')
9676 /* Complain, but do define it. */
9677 dwarf2_macro_malformed_definition_complaint (body
);
9678 macro_define_function (file
, line
, name
,
9679 argc
, (const char **) argv
,
9683 /* Just complain. */
9684 dwarf2_macro_malformed_definition_complaint (body
);
9687 /* Just complain. */
9688 dwarf2_macro_malformed_definition_complaint (body
);
9694 for (i
= 0; i
< argc
; i
++)
9700 dwarf2_macro_malformed_definition_complaint (body
);
9705 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
9706 char *comp_dir
, bfd
*abfd
,
9707 struct dwarf2_cu
*cu
)
9709 gdb_byte
*mac_ptr
, *mac_end
;
9710 struct macro_source_file
*current_file
= 0;
9712 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
9714 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
9718 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
9719 mac_end
= dwarf2_per_objfile
->macinfo_buffer
9720 + dwarf2_per_objfile
->macinfo_size
;
9724 enum dwarf_macinfo_record_type macinfo_type
;
9726 /* Do we at least have room for a macinfo type byte? */
9727 if (mac_ptr
>= mac_end
)
9729 dwarf2_macros_too_long_complaint ();
9733 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
9736 switch (macinfo_type
)
9738 /* A zero macinfo type indicates the end of the macro
9743 case DW_MACINFO_define
:
9744 case DW_MACINFO_undef
:
9746 unsigned int bytes_read
;
9750 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9751 mac_ptr
+= bytes_read
;
9752 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
9753 mac_ptr
+= bytes_read
;
9756 complaint (&symfile_complaints
,
9757 _("debug info gives macro %s outside of any file: %s"),
9759 DW_MACINFO_define
? "definition" : macinfo_type
==
9760 DW_MACINFO_undef
? "undefinition" :
9761 "something-or-other", body
);
9764 if (macinfo_type
== DW_MACINFO_define
)
9765 parse_macro_definition (current_file
, line
, body
);
9766 else if (macinfo_type
== DW_MACINFO_undef
)
9767 macro_undef (current_file
, line
, body
);
9772 case DW_MACINFO_start_file
:
9774 unsigned int bytes_read
;
9777 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9778 mac_ptr
+= bytes_read
;
9779 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9780 mac_ptr
+= bytes_read
;
9782 current_file
= macro_start_file (file
, line
,
9783 current_file
, comp_dir
,
9788 case DW_MACINFO_end_file
:
9790 complaint (&symfile_complaints
,
9791 _("macro debug info has an unmatched `close_file' directive"));
9794 current_file
= current_file
->included_by
;
9797 enum dwarf_macinfo_record_type next_type
;
9799 /* GCC circa March 2002 doesn't produce the zero
9800 type byte marking the end of the compilation
9801 unit. Complain if it's not there, but exit no
9804 /* Do we at least have room for a macinfo type byte? */
9805 if (mac_ptr
>= mac_end
)
9807 dwarf2_macros_too_long_complaint ();
9811 /* We don't increment mac_ptr here, so this is just
9813 next_type
= read_1_byte (abfd
, mac_ptr
);
9815 complaint (&symfile_complaints
,
9816 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
9823 case DW_MACINFO_vendor_ext
:
9825 unsigned int bytes_read
;
9829 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9830 mac_ptr
+= bytes_read
;
9831 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
9832 mac_ptr
+= bytes_read
;
9834 /* We don't recognize any vendor extensions. */
9841 /* Check if the attribute's form is a DW_FORM_block*
9842 if so return true else false. */
9844 attr_form_is_block (struct attribute
*attr
)
9846 return (attr
== NULL
? 0 :
9847 attr
->form
== DW_FORM_block1
9848 || attr
->form
== DW_FORM_block2
9849 || attr
->form
== DW_FORM_block4
9850 || attr
->form
== DW_FORM_block
);
9853 /* Return non-zero if ATTR's value is a section offset --- classes
9854 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
9855 You may use DW_UNSND (attr) to retrieve such offsets.
9857 Section 7.5.4, "Attribute Encodings", explains that no attribute
9858 may have a value that belongs to more than one of these classes; it
9859 would be ambiguous if we did, because we use the same forms for all
9862 attr_form_is_section_offset (struct attribute
*attr
)
9864 return (attr
->form
== DW_FORM_data4
9865 || attr
->form
== DW_FORM_data8
);
9869 /* Return non-zero if ATTR's value falls in the 'constant' class, or
9870 zero otherwise. When this function returns true, you can apply
9871 dwarf2_get_attr_constant_value to it.
9873 However, note that for some attributes you must check
9874 attr_form_is_section_offset before using this test. DW_FORM_data4
9875 and DW_FORM_data8 are members of both the constant class, and of
9876 the classes that contain offsets into other debug sections
9877 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
9878 that, if an attribute's can be either a constant or one of the
9879 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
9880 taken as section offsets, not constants. */
9882 attr_form_is_constant (struct attribute
*attr
)
9899 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
9900 struct dwarf2_cu
*cu
)
9902 if (attr_form_is_section_offset (attr
)
9903 /* ".debug_loc" may not exist at all, or the offset may be outside
9904 the section. If so, fall through to the complaint in the
9906 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc_size
)
9908 struct dwarf2_loclist_baton
*baton
;
9910 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9911 sizeof (struct dwarf2_loclist_baton
));
9912 baton
->per_cu
= cu
->per_cu
;
9913 gdb_assert (baton
->per_cu
);
9915 /* We don't know how long the location list is, but make sure we
9916 don't run off the edge of the section. */
9917 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
9918 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
9919 baton
->base_address
= cu
->header
.base_address
;
9920 if (cu
->header
.base_known
== 0)
9921 complaint (&symfile_complaints
,
9922 _("Location list used without specifying the CU base address."));
9924 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
9925 SYMBOL_LOCATION_BATON (sym
) = baton
;
9929 struct dwarf2_locexpr_baton
*baton
;
9931 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9932 sizeof (struct dwarf2_locexpr_baton
));
9933 baton
->per_cu
= cu
->per_cu
;
9934 gdb_assert (baton
->per_cu
);
9936 if (attr_form_is_block (attr
))
9938 /* Note that we're just copying the block's data pointer
9939 here, not the actual data. We're still pointing into the
9940 info_buffer for SYM's objfile; right now we never release
9941 that buffer, but when we do clean up properly this may
9943 baton
->size
= DW_BLOCK (attr
)->size
;
9944 baton
->data
= DW_BLOCK (attr
)->data
;
9948 dwarf2_invalid_attrib_class_complaint ("location description",
9949 SYMBOL_NATURAL_NAME (sym
));
9954 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
9955 SYMBOL_LOCATION_BATON (sym
) = baton
;
9959 /* Return the OBJFILE associated with the compilation unit CU. */
9962 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
9964 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
9966 /* Return the master objfile, so that we can report and look up the
9967 correct file containing this variable. */
9968 if (objfile
->separate_debug_objfile_backlink
)
9969 objfile
= objfile
->separate_debug_objfile_backlink
;
9974 /* Return the address size given in the compilation unit header for CU. */
9977 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
9980 return per_cu
->cu
->header
.addr_size
;
9983 /* If the CU is not currently read in, we re-read its header. */
9984 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
9985 struct dwarf2_per_objfile
*per_objfile
9986 = objfile_data (objfile
, dwarf2_objfile_data_key
);
9987 gdb_byte
*info_ptr
= per_objfile
->info_buffer
+ per_cu
->offset
;
9989 struct comp_unit_head cu_header
;
9990 memset (&cu_header
, 0, sizeof cu_header
);
9991 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
9992 return cu_header
.addr_size
;
9996 /* Locate the compilation unit from CU's objfile which contains the
9997 DIE at OFFSET. Raises an error on failure. */
9999 static struct dwarf2_per_cu_data
*
10000 dwarf2_find_containing_comp_unit (unsigned long offset
,
10001 struct objfile
*objfile
)
10003 struct dwarf2_per_cu_data
*this_cu
;
10007 high
= dwarf2_per_objfile
->n_comp_units
- 1;
10010 int mid
= low
+ (high
- low
) / 2;
10011 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
10016 gdb_assert (low
== high
);
10017 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
10020 error (_("Dwarf Error: could not find partial DIE containing "
10021 "offset 0x%lx [in module %s]"),
10022 (long) offset
, bfd_get_filename (objfile
->obfd
));
10024 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
10025 return dwarf2_per_objfile
->all_comp_units
[low
-1];
10029 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
10030 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
10031 && offset
>= this_cu
->offset
+ this_cu
->length
)
10032 error (_("invalid dwarf2 offset %ld"), offset
);
10033 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
10038 /* Locate the compilation unit from OBJFILE which is located at exactly
10039 OFFSET. Raises an error on failure. */
10041 static struct dwarf2_per_cu_data
*
10042 dwarf2_find_comp_unit (unsigned long offset
, struct objfile
*objfile
)
10044 struct dwarf2_per_cu_data
*this_cu
;
10045 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10046 if (this_cu
->offset
!= offset
)
10047 error (_("no compilation unit with offset %ld."), offset
);
10051 /* Release one cached compilation unit, CU. We unlink it from the tree
10052 of compilation units, but we don't remove it from the read_in_chain;
10053 the caller is responsible for that. */
10056 free_one_comp_unit (void *data
)
10058 struct dwarf2_cu
*cu
= data
;
10060 if (cu
->per_cu
!= NULL
)
10061 cu
->per_cu
->cu
= NULL
;
10064 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10069 /* This cleanup function is passed the address of a dwarf2_cu on the stack
10070 when we're finished with it. We can't free the pointer itself, but be
10071 sure to unlink it from the cache. Also release any associated storage
10072 and perform cache maintenance.
10074 Only used during partial symbol parsing. */
10077 free_stack_comp_unit (void *data
)
10079 struct dwarf2_cu
*cu
= data
;
10081 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10082 cu
->partial_dies
= NULL
;
10084 if (cu
->per_cu
!= NULL
)
10086 /* This compilation unit is on the stack in our caller, so we
10087 should not xfree it. Just unlink it. */
10088 cu
->per_cu
->cu
= NULL
;
10091 /* If we had a per-cu pointer, then we may have other compilation
10092 units loaded, so age them now. */
10093 age_cached_comp_units ();
10097 /* Free all cached compilation units. */
10100 free_cached_comp_units (void *data
)
10102 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10104 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10105 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10106 while (per_cu
!= NULL
)
10108 struct dwarf2_per_cu_data
*next_cu
;
10110 next_cu
= per_cu
->cu
->read_in_chain
;
10112 free_one_comp_unit (per_cu
->cu
);
10113 *last_chain
= next_cu
;
10119 /* Increase the age counter on each cached compilation unit, and free
10120 any that are too old. */
10123 age_cached_comp_units (void)
10125 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10127 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
10128 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10129 while (per_cu
!= NULL
)
10131 per_cu
->cu
->last_used
++;
10132 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
10133 dwarf2_mark (per_cu
->cu
);
10134 per_cu
= per_cu
->cu
->read_in_chain
;
10137 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10138 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10139 while (per_cu
!= NULL
)
10141 struct dwarf2_per_cu_data
*next_cu
;
10143 next_cu
= per_cu
->cu
->read_in_chain
;
10145 if (!per_cu
->cu
->mark
)
10147 free_one_comp_unit (per_cu
->cu
);
10148 *last_chain
= next_cu
;
10151 last_chain
= &per_cu
->cu
->read_in_chain
;
10157 /* Remove a single compilation unit from the cache. */
10160 free_one_cached_comp_unit (void *target_cu
)
10162 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10164 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10165 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10166 while (per_cu
!= NULL
)
10168 struct dwarf2_per_cu_data
*next_cu
;
10170 next_cu
= per_cu
->cu
->read_in_chain
;
10172 if (per_cu
->cu
== target_cu
)
10174 free_one_comp_unit (per_cu
->cu
);
10175 *last_chain
= next_cu
;
10179 last_chain
= &per_cu
->cu
->read_in_chain
;
10185 /* Release all extra memory associated with OBJFILE. */
10188 dwarf2_free_objfile (struct objfile
*objfile
)
10190 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
10192 if (dwarf2_per_objfile
== NULL
)
10195 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
10196 free_cached_comp_units (NULL
);
10198 /* Everything else should be on the objfile obstack. */
10201 /* A pair of DIE offset and GDB type pointer. We store these
10202 in a hash table separate from the DIEs, and preserve them
10203 when the DIEs are flushed out of cache. */
10205 struct dwarf2_offset_and_type
10207 unsigned int offset
;
10211 /* Hash function for a dwarf2_offset_and_type. */
10214 offset_and_type_hash (const void *item
)
10216 const struct dwarf2_offset_and_type
*ofs
= item
;
10217 return ofs
->offset
;
10220 /* Equality function for a dwarf2_offset_and_type. */
10223 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
10225 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
10226 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
10227 return ofs_lhs
->offset
== ofs_rhs
->offset
;
10230 /* Set the type associated with DIE to TYPE. Save it in CU's hash
10231 table if necessary. For convenience, return TYPE. */
10233 static struct type
*
10234 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10236 struct dwarf2_offset_and_type
**slot
, ofs
;
10238 if (cu
->type_hash
== NULL
)
10240 gdb_assert (cu
->per_cu
!= NULL
);
10241 cu
->per_cu
->type_hash
10242 = htab_create_alloc_ex (cu
->header
.length
/ 24,
10243 offset_and_type_hash
,
10244 offset_and_type_eq
,
10246 &cu
->objfile
->objfile_obstack
,
10247 hashtab_obstack_allocate
,
10248 dummy_obstack_deallocate
);
10249 cu
->type_hash
= cu
->per_cu
->type_hash
;
10252 ofs
.offset
= die
->offset
;
10254 slot
= (struct dwarf2_offset_and_type
**)
10255 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
10256 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
10261 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
10262 not have a saved type. */
10264 static struct type
*
10265 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10267 struct dwarf2_offset_and_type
*slot
, ofs
;
10268 htab_t type_hash
= cu
->type_hash
;
10270 if (type_hash
== NULL
)
10273 ofs
.offset
= die
->offset
;
10274 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
10281 /* Set the mark field in CU and in every other compilation unit in the
10282 cache that we must keep because we are keeping CU. */
10284 /* Add a dependence relationship from CU to REF_PER_CU. */
10287 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
10288 struct dwarf2_per_cu_data
*ref_per_cu
)
10292 if (cu
->dependencies
== NULL
)
10294 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
10295 NULL
, &cu
->comp_unit_obstack
,
10296 hashtab_obstack_allocate
,
10297 dummy_obstack_deallocate
);
10299 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
10301 *slot
= ref_per_cu
;
10304 /* Set the mark field in CU and in every other compilation unit in the
10305 cache that we must keep because we are keeping CU. */
10308 dwarf2_mark_helper (void **slot
, void *data
)
10310 struct dwarf2_per_cu_data
*per_cu
;
10312 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
10313 if (per_cu
->cu
->mark
)
10315 per_cu
->cu
->mark
= 1;
10317 if (per_cu
->cu
->dependencies
!= NULL
)
10318 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10324 dwarf2_mark (struct dwarf2_cu
*cu
)
10329 if (cu
->dependencies
!= NULL
)
10330 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10334 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
10338 per_cu
->cu
->mark
= 0;
10339 per_cu
= per_cu
->cu
->read_in_chain
;
10343 /* Trivial hash function for partial_die_info: the hash value of a DIE
10344 is its offset in .debug_info for this objfile. */
10347 partial_die_hash (const void *item
)
10349 const struct partial_die_info
*part_die
= item
;
10350 return part_die
->offset
;
10353 /* Trivial comparison function for partial_die_info structures: two DIEs
10354 are equal if they have the same offset. */
10357 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
10359 const struct partial_die_info
*part_die_lhs
= item_lhs
;
10360 const struct partial_die_info
*part_die_rhs
= item_rhs
;
10361 return part_die_lhs
->offset
== part_die_rhs
->offset
;
10364 static struct cmd_list_element
*set_dwarf2_cmdlist
;
10365 static struct cmd_list_element
*show_dwarf2_cmdlist
;
10368 set_dwarf2_cmd (char *args
, int from_tty
)
10370 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
10374 show_dwarf2_cmd (char *args
, int from_tty
)
10376 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
10379 void _initialize_dwarf2_read (void);
10382 _initialize_dwarf2_read (void)
10384 dwarf2_objfile_data_key
= register_objfile_data ();
10386 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
10387 Set DWARF 2 specific variables.\n\
10388 Configure DWARF 2 variables such as the cache size"),
10389 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
10390 0/*allow-unknown*/, &maintenance_set_cmdlist
);
10392 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
10393 Show DWARF 2 specific variables\n\
10394 Show DWARF 2 variables such as the cache size"),
10395 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
10396 0/*allow-unknown*/, &maintenance_show_cmdlist
);
10398 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
10399 &dwarf2_max_cache_age
, _("\
10400 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
10401 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
10402 A higher limit means that cached compilation units will be stored\n\
10403 in memory longer, and more total memory will be used. Zero disables\n\
10404 caching, which can slow down startup."),
10406 show_dwarf2_max_cache_age
,
10407 &set_dwarf2_cmdlist
,
10408 &show_dwarf2_cmdlist
);