1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
7 Inc. with support from Florida State University (under contract
8 with the Ada Joint Program Office), and Silicon Graphics, Inc.
9 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
10 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
13 This file is part of GDB.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 3 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>. */
33 #include "elf/dwarf2.h"
36 #include "expression.h"
37 #include "filenames.h" /* for DOSish file names */
40 #include "complaints.h"
42 #include "dwarf2expr.h"
43 #include "dwarf2loc.h"
44 #include "cp-support.h"
51 #include "gdb_string.h"
52 #include "gdb_assert.h"
53 #include <sys/types.h>
58 /* A note on memory usage for this file.
60 At the present time, this code reads the debug info sections into
61 the objfile's objfile_obstack. A definite improvement for startup
62 time, on platforms which do not emit relocations for debug
63 sections, would be to use mmap instead. The object's complete
64 debug information is loaded into memory, partly to simplify
65 absolute DIE references.
67 Whether using obstacks or mmap, the sections should remain loaded
68 until the objfile is released, and pointers into the section data
69 can be used for any other data associated to the objfile (symbol
70 names, type names, location expressions to name a few). */
73 /* .debug_info header for a compilation unit
74 Because of alignment constraints, this structure has padding and cannot
75 be mapped directly onto the beginning of the .debug_info section. */
76 typedef struct comp_unit_header
78 unsigned int length
; /* length of the .debug_info
80 unsigned short version
; /* version number -- 2 for DWARF
82 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
83 unsigned char addr_size
; /* byte size of an address -- 4 */
86 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
89 /* .debug_pubnames header
90 Because of alignment constraints, this structure has padding and cannot
91 be mapped directly onto the beginning of the .debug_info section. */
92 typedef struct pubnames_header
94 unsigned int length
; /* length of the .debug_pubnames
96 unsigned char version
; /* version number -- 2 for DWARF
98 unsigned int info_offset
; /* offset into .debug_info section */
99 unsigned int info_size
; /* byte size of .debug_info section
103 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
105 /* .debug_pubnames header
106 Because of alignment constraints, this structure has padding and cannot
107 be mapped directly onto the beginning of the .debug_info section. */
108 typedef struct aranges_header
110 unsigned int length
; /* byte len of the .debug_aranges
112 unsigned short version
; /* version number -- 2 for DWARF
114 unsigned int info_offset
; /* offset into .debug_info section */
115 unsigned char addr_size
; /* byte size of an address */
116 unsigned char seg_size
; /* byte size of segment descriptor */
119 #define _ACTUAL_ARANGES_HEADER_SIZE 12
121 /* .debug_line statement program prologue
122 Because of alignment constraints, this structure has padding and cannot
123 be mapped directly onto the beginning of the .debug_info section. */
124 typedef struct statement_prologue
126 unsigned int total_length
; /* byte length of the statement
128 unsigned short version
; /* version number -- 2 for DWARF
130 unsigned int prologue_length
; /* # bytes between prologue &
132 unsigned char minimum_instruction_length
; /* byte size of
134 unsigned char default_is_stmt
; /* initial value of is_stmt
137 unsigned char line_range
;
138 unsigned char opcode_base
; /* number assigned to first special
140 unsigned char *standard_opcode_lengths
;
144 /* When set, the file that we're processing is known to have debugging
145 info for C++ namespaces. GCC 3.3.x did not produce this information,
146 but later versions do. */
148 static int processing_has_namespace_info
;
150 static const struct objfile_data
*dwarf2_objfile_data_key
;
152 struct dwarf2_per_objfile
154 /* Sizes of debugging sections. */
155 unsigned int info_size
;
156 unsigned int abbrev_size
;
157 unsigned int line_size
;
158 unsigned int pubnames_size
;
159 unsigned int aranges_size
;
160 unsigned int loc_size
;
161 unsigned int macinfo_size
;
162 unsigned int str_size
;
163 unsigned int ranges_size
;
164 unsigned int frame_size
;
165 unsigned int eh_frame_size
;
167 /* Loaded data from the sections. */
168 gdb_byte
*info_buffer
;
169 gdb_byte
*abbrev_buffer
;
170 gdb_byte
*line_buffer
;
171 gdb_byte
*str_buffer
;
172 gdb_byte
*macinfo_buffer
;
173 gdb_byte
*ranges_buffer
;
174 gdb_byte
*loc_buffer
;
176 /* A list of all the compilation units. This is used to locate
177 the target compilation unit of a particular reference. */
178 struct dwarf2_per_cu_data
**all_comp_units
;
180 /* The number of compilation units in ALL_COMP_UNITS. */
183 /* A chain of compilation units that are currently read in, so that
184 they can be freed later. */
185 struct dwarf2_per_cu_data
*read_in_chain
;
187 /* A flag indicating wether this objfile has a section loaded at a
189 int has_section_at_zero
;
192 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
194 static asection
*dwarf_info_section
;
195 static asection
*dwarf_abbrev_section
;
196 static asection
*dwarf_line_section
;
197 static asection
*dwarf_pubnames_section
;
198 static asection
*dwarf_aranges_section
;
199 static asection
*dwarf_loc_section
;
200 static asection
*dwarf_macinfo_section
;
201 static asection
*dwarf_str_section
;
202 static asection
*dwarf_ranges_section
;
203 asection
*dwarf_frame_section
;
204 asection
*dwarf_eh_frame_section
;
206 /* names of the debugging sections */
208 /* Note that if the debugging section has been compressed, it might
209 have a name like .zdebug_info. */
211 #define INFO_SECTION "debug_info"
212 #define ABBREV_SECTION "debug_abbrev"
213 #define LINE_SECTION "debug_line"
214 #define PUBNAMES_SECTION "debug_pubnames"
215 #define ARANGES_SECTION "debug_aranges"
216 #define LOC_SECTION "debug_loc"
217 #define MACINFO_SECTION "debug_macinfo"
218 #define STR_SECTION "debug_str"
219 #define RANGES_SECTION "debug_ranges"
220 #define FRAME_SECTION "debug_frame"
221 #define EH_FRAME_SECTION "eh_frame"
223 /* local data types */
225 /* We hold several abbreviation tables in memory at the same time. */
226 #ifndef ABBREV_HASH_SIZE
227 #define ABBREV_HASH_SIZE 121
230 /* The data in a compilation unit header, after target2host
231 translation, looks like this. */
232 struct comp_unit_head
234 unsigned long length
;
236 unsigned int abbrev_offset
;
237 unsigned char addr_size
;
238 unsigned char signed_addr_p
;
240 /* Size of file offsets; either 4 or 8. */
241 unsigned int offset_size
;
243 /* Size of the length field; either 4 or 12. */
244 unsigned int initial_length_size
;
246 /* Offset to the first byte of this compilation unit header in the
247 .debug_info section, for resolving relative reference dies. */
250 /* Pointer to this compilation unit header in the .debug_info
252 gdb_byte
*cu_head_ptr
;
254 /* Pointer to the first die of this compilation unit. This will be
255 the first byte following the compilation unit header. */
256 gdb_byte
*first_die_ptr
;
258 /* Pointer to the next compilation unit header in the program. */
259 struct comp_unit_head
*next
;
261 /* Base address of this compilation unit. */
262 CORE_ADDR base_address
;
264 /* Non-zero if base_address has been set. */
268 /* Internal state when decoding a particular compilation unit. */
271 /* The objfile containing this compilation unit. */
272 struct objfile
*objfile
;
274 /* The header of the compilation unit.
276 FIXME drow/2003-11-10: Some of the things from the comp_unit_head
277 should logically be moved to the dwarf2_cu structure. */
278 struct comp_unit_head header
;
280 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
282 /* The language we are debugging. */
283 enum language language
;
284 const struct language_defn
*language_defn
;
286 const char *producer
;
288 /* The generic symbol table building routines have separate lists for
289 file scope symbols and all all other scopes (local scopes). So
290 we need to select the right one to pass to add_symbol_to_list().
291 We do it by keeping a pointer to the correct list in list_in_scope.
293 FIXME: The original dwarf code just treated the file scope as the
294 first local scope, and all other local scopes as nested local
295 scopes, and worked fine. Check to see if we really need to
296 distinguish these in buildsym.c. */
297 struct pending
**list_in_scope
;
299 /* DWARF abbreviation table associated with this compilation unit. */
300 struct abbrev_info
**dwarf2_abbrevs
;
302 /* Storage for the abbrev table. */
303 struct obstack abbrev_obstack
;
305 /* Hash table holding all the loaded partial DIEs. */
308 /* `.debug_ranges' offset for this `DW_TAG_compile_unit' DIE. */
309 unsigned long ranges_offset
;
311 /* Storage for things with the same lifetime as this read-in compilation
312 unit, including partial DIEs. */
313 struct obstack comp_unit_obstack
;
315 /* When multiple dwarf2_cu structures are living in memory, this field
316 chains them all together, so that they can be released efficiently.
317 We will probably also want a generation counter so that most-recently-used
318 compilation units are cached... */
319 struct dwarf2_per_cu_data
*read_in_chain
;
321 /* Backchain to our per_cu entry if the tree has been built. */
322 struct dwarf2_per_cu_data
*per_cu
;
324 /* Pointer to the die -> type map. Although it is stored
325 permanently in per_cu, we copy it here to avoid double
329 /* How many compilation units ago was this CU last referenced? */
332 /* A hash table of die offsets for following references. */
335 /* Full DIEs if read in. */
336 struct die_info
*dies
;
338 /* A set of pointers to dwarf2_per_cu_data objects for compilation
339 units referenced by this one. Only set during full symbol processing;
340 partial symbol tables do not have dependencies. */
343 /* Header data from the line table, during full symbol processing. */
344 struct line_header
*line_header
;
346 /* Mark used when releasing cached dies. */
347 unsigned int mark
: 1;
349 /* This flag will be set if this compilation unit might include
350 inter-compilation-unit references. */
351 unsigned int has_form_ref_addr
: 1;
353 /* This flag will be set if this compilation unit includes any
354 DW_TAG_namespace DIEs. If we know that there are explicit
355 DIEs for namespaces, we don't need to try to infer them
356 from mangled names. */
357 unsigned int has_namespace_info
: 1;
359 /* Field `ranges_offset' is filled in; flag as the value may be zero. */
360 unsigned int has_ranges_offset
: 1;
363 /* Persistent data held for a compilation unit, even when not
364 processing it. We put a pointer to this structure in the
365 read_symtab_private field of the psymtab. If we encounter
366 inter-compilation-unit references, we also maintain a sorted
367 list of all compilation units. */
369 struct dwarf2_per_cu_data
371 /* The start offset and length of this compilation unit. 2**30-1
372 bytes should suffice to store the length of any compilation unit
373 - if it doesn't, GDB will fall over anyway. */
374 unsigned long offset
;
375 unsigned long length
: 30;
377 /* Flag indicating this compilation unit will be read in before
378 any of the current compilation units are processed. */
379 unsigned long queued
: 1;
381 /* This flag will be set if we need to load absolutely all DIEs
382 for this compilation unit, instead of just the ones we think
383 are interesting. It gets set if we look for a DIE in the
384 hash table and don't find it. */
385 unsigned int load_all_dies
: 1;
387 /* Set iff currently read in. */
388 struct dwarf2_cu
*cu
;
390 /* If full symbols for this CU have been read in, then this field
391 holds a map of DIE offsets to types. It isn't always possible
392 to reconstruct this information later, so we have to preserve
396 /* The partial symbol table associated with this compilation unit,
397 or NULL for partial units (which do not have an associated
399 struct partial_symtab
*psymtab
;
402 /* The line number information for a compilation unit (found in the
403 .debug_line section) begins with a "statement program header",
404 which contains the following information. */
407 unsigned int total_length
;
408 unsigned short version
;
409 unsigned int header_length
;
410 unsigned char minimum_instruction_length
;
411 unsigned char default_is_stmt
;
413 unsigned char line_range
;
414 unsigned char opcode_base
;
416 /* standard_opcode_lengths[i] is the number of operands for the
417 standard opcode whose value is i. This means that
418 standard_opcode_lengths[0] is unused, and the last meaningful
419 element is standard_opcode_lengths[opcode_base - 1]. */
420 unsigned char *standard_opcode_lengths
;
422 /* The include_directories table. NOTE! These strings are not
423 allocated with xmalloc; instead, they are pointers into
424 debug_line_buffer. If you try to free them, `free' will get
426 unsigned int num_include_dirs
, include_dirs_size
;
429 /* The file_names table. NOTE! These strings are not allocated
430 with xmalloc; instead, they are pointers into debug_line_buffer.
431 Don't try to free them directly. */
432 unsigned int num_file_names
, file_names_size
;
436 unsigned int dir_index
;
437 unsigned int mod_time
;
439 int included_p
; /* Non-zero if referenced by the Line Number Program. */
440 struct symtab
*symtab
; /* The associated symbol table, if any. */
443 /* The start and end of the statement program following this
444 header. These point into dwarf2_per_objfile->line_buffer. */
445 gdb_byte
*statement_program_start
, *statement_program_end
;
448 /* When we construct a partial symbol table entry we only
449 need this much information. */
450 struct partial_die_info
452 /* Offset of this DIE. */
455 /* DWARF-2 tag for this DIE. */
456 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
458 /* Language code associated with this DIE. This is only used
459 for the compilation unit DIE. */
460 unsigned int language
: 8;
462 /* Assorted flags describing the data found in this DIE. */
463 unsigned int has_children
: 1;
464 unsigned int is_external
: 1;
465 unsigned int is_declaration
: 1;
466 unsigned int has_type
: 1;
467 unsigned int has_specification
: 1;
468 unsigned int has_stmt_list
: 1;
469 unsigned int has_pc_info
: 1;
471 /* Flag set if the SCOPE field of this structure has been
473 unsigned int scope_set
: 1;
475 /* Flag set if the DIE has a byte_size attribute. */
476 unsigned int has_byte_size
: 1;
478 /* The name of this DIE. Normally the value of DW_AT_name, but
479 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
484 /* The scope to prepend to our children. This is generally
485 allocated on the comp_unit_obstack, so will disappear
486 when this compilation unit leaves the cache. */
489 /* The location description associated with this DIE, if any. */
490 struct dwarf_block
*locdesc
;
492 /* If HAS_PC_INFO, the PC range associated with this DIE. */
496 /* Pointer into the info_buffer pointing at the target of
497 DW_AT_sibling, if any. */
500 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
501 DW_AT_specification (or DW_AT_abstract_origin or
503 unsigned int spec_offset
;
505 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
506 unsigned int line_offset
;
508 /* Pointers to this DIE's parent, first child, and next sibling,
510 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
513 /* This data structure holds the information of an abbrev. */
516 unsigned int number
; /* number identifying abbrev */
517 enum dwarf_tag tag
; /* dwarf tag */
518 unsigned short has_children
; /* boolean */
519 unsigned short num_attrs
; /* number of attributes */
520 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
521 struct abbrev_info
*next
; /* next in chain */
526 enum dwarf_attribute name
;
527 enum dwarf_form form
;
530 /* Attributes have a name and a value */
533 enum dwarf_attribute name
;
534 enum dwarf_form form
;
538 struct dwarf_block
*blk
;
546 /* This data structure holds a complete die structure. */
549 enum dwarf_tag tag
; /* Tag indicating type of die */
550 unsigned int abbrev
; /* Abbrev number */
551 unsigned int offset
; /* Offset in .debug_info section */
552 unsigned int num_attrs
; /* Number of attributes */
554 /* The dies in a compilation unit form an n-ary tree. PARENT
555 points to this die's parent; CHILD points to the first child of
556 this node; and all the children of a given node are chained
557 together via their SIBLING fields, terminated by a die whose
559 struct die_info
*child
; /* Its first child, if any. */
560 struct die_info
*sibling
; /* Its next sibling, if any. */
561 struct die_info
*parent
; /* Its parent, if any. */
563 /* An array of attributes, with NUM_ATTRS elements. There may be
564 zero, but it's not common and zero-sized arrays are not
565 sufficiently portable C. */
566 struct attribute attrs
[1];
569 struct function_range
572 CORE_ADDR lowpc
, highpc
;
574 struct function_range
*next
;
577 /* Get at parts of an attribute structure */
579 #define DW_STRING(attr) ((attr)->u.str)
580 #define DW_UNSND(attr) ((attr)->u.unsnd)
581 #define DW_BLOCK(attr) ((attr)->u.blk)
582 #define DW_SND(attr) ((attr)->u.snd)
583 #define DW_ADDR(attr) ((attr)->u.addr)
585 /* Blocks are a bunch of untyped bytes. */
592 #ifndef ATTR_ALLOC_CHUNK
593 #define ATTR_ALLOC_CHUNK 4
596 /* Allocate fields for structs, unions and enums in this size. */
597 #ifndef DW_FIELD_ALLOC_CHUNK
598 #define DW_FIELD_ALLOC_CHUNK 4
601 /* A zeroed version of a partial die for initialization purposes. */
602 static struct partial_die_info zeroed_partial_die
;
604 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
605 but this would require a corresponding change in unpack_field_as_long
607 static int bits_per_byte
= 8;
609 /* The routines that read and process dies for a C struct or C++ class
610 pass lists of data member fields and lists of member function fields
611 in an instance of a field_info structure, as defined below. */
614 /* List of data member and baseclasses fields. */
617 struct nextfield
*next
;
624 /* Number of fields. */
627 /* Number of baseclasses. */
630 /* Set if the accesibility of one of the fields is not public. */
631 int non_public_fields
;
633 /* Member function fields array, entries are allocated in the order they
634 are encountered in the object file. */
637 struct nextfnfield
*next
;
638 struct fn_field fnfield
;
642 /* Member function fieldlist array, contains name of possibly overloaded
643 member function, number of overloaded member functions and a pointer
644 to the head of the member function field chain. */
649 struct nextfnfield
*head
;
653 /* Number of entries in the fnfieldlists array. */
657 /* One item on the queue of compilation units to read in full symbols
659 struct dwarf2_queue_item
661 struct dwarf2_per_cu_data
*per_cu
;
662 struct dwarf2_queue_item
*next
;
665 /* The current queue. */
666 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
668 /* Loaded secondary compilation units are kept in memory until they
669 have not been referenced for the processing of this many
670 compilation units. Set this to zero to disable caching. Cache
671 sizes of up to at least twenty will improve startup time for
672 typical inter-CU-reference binaries, at an obvious memory cost. */
673 static int dwarf2_max_cache_age
= 5;
675 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
676 struct cmd_list_element
*c
, const char *value
)
678 fprintf_filtered (file
, _("\
679 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
684 /* Various complaints about symbol reading that don't abort the process */
687 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
689 complaint (&symfile_complaints
,
690 _("statement list doesn't fit in .debug_line section"));
694 dwarf2_debug_line_missing_file_complaint (void)
696 complaint (&symfile_complaints
,
697 _(".debug_line section has line data without a file"));
701 dwarf2_complex_location_expr_complaint (void)
703 complaint (&symfile_complaints
, _("location expression too complex"));
707 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
710 complaint (&symfile_complaints
,
711 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
716 dwarf2_macros_too_long_complaint (void)
718 complaint (&symfile_complaints
,
719 _("macro info runs off end of `.debug_macinfo' section"));
723 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
725 complaint (&symfile_complaints
,
726 _("macro debug info contains a malformed macro definition:\n`%s'"),
731 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
733 complaint (&symfile_complaints
,
734 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
737 /* local function prototypes */
739 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
742 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
745 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
748 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
749 struct partial_die_info
*,
750 struct partial_symtab
*);
752 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
754 static void scan_partial_symbols (struct partial_die_info
*,
755 CORE_ADDR
*, CORE_ADDR
*,
758 static void add_partial_symbol (struct partial_die_info
*,
761 static int pdi_needs_namespace (enum dwarf_tag tag
);
763 static void add_partial_namespace (struct partial_die_info
*pdi
,
764 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
765 struct dwarf2_cu
*cu
);
767 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
768 struct dwarf2_cu
*cu
);
770 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
773 struct dwarf2_cu
*cu
);
775 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
777 static void psymtab_to_symtab_1 (struct partial_symtab
*);
779 gdb_byte
*dwarf2_read_section (struct objfile
*, asection
*);
781 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
783 static void dwarf2_free_abbrev_table (void *);
785 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
788 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
791 static struct partial_die_info
*load_partial_dies (bfd
*, gdb_byte
*, int,
794 static gdb_byte
*read_partial_die (struct partial_die_info
*,
795 struct abbrev_info
*abbrev
, unsigned int,
796 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
798 static struct partial_die_info
*find_partial_die (unsigned long,
801 static void fixup_partial_die (struct partial_die_info
*,
804 static gdb_byte
*read_full_die (struct die_info
**, bfd
*, gdb_byte
*,
805 struct dwarf2_cu
*, int *);
807 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
808 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
810 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
811 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
813 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
815 static int read_1_signed_byte (bfd
*, gdb_byte
*);
817 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
819 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
821 static unsigned long read_8_bytes (bfd
*, gdb_byte
*);
823 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
826 static LONGEST
read_initial_length (bfd
*, gdb_byte
*,
827 struct comp_unit_head
*, unsigned int *);
829 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
832 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
834 static char *read_string (bfd
*, gdb_byte
*, unsigned int *);
836 static char *read_indirect_string (bfd
*, gdb_byte
*,
837 const struct comp_unit_head
*,
840 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
842 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
844 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
846 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
848 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
851 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
852 struct dwarf2_cu
*cu
);
854 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
856 static struct die_info
*die_specification (struct die_info
*die
,
857 struct dwarf2_cu
**);
859 static void free_line_header (struct line_header
*lh
);
861 static void add_file_name (struct line_header
*, char *, unsigned int,
862 unsigned int, unsigned int);
864 static struct line_header
*(dwarf_decode_line_header
865 (unsigned int offset
,
866 bfd
*abfd
, struct dwarf2_cu
*cu
));
868 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
869 struct dwarf2_cu
*, struct partial_symtab
*);
871 static void dwarf2_start_subfile (char *, char *, char *);
873 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
876 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
879 static void dwarf2_const_value_data (struct attribute
*attr
,
883 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
885 static struct type
*die_containing_type (struct die_info
*,
888 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
890 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
892 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
894 static char *typename_concat (struct obstack
*,
899 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
901 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
903 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
905 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
906 struct dwarf2_cu
*, struct partial_symtab
*);
908 static int dwarf2_get_pc_bounds (struct die_info
*,
909 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
911 static void get_scope_pc_bounds (struct die_info
*,
912 CORE_ADDR
*, CORE_ADDR
*,
915 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
916 CORE_ADDR
, struct dwarf2_cu
*);
918 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
921 static void dwarf2_attach_fields_to_type (struct field_info
*,
922 struct type
*, struct dwarf2_cu
*);
924 static void dwarf2_add_member_fn (struct field_info
*,
925 struct die_info
*, struct type
*,
928 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
929 struct type
*, struct dwarf2_cu
*);
931 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
933 static const char *determine_class_name (struct die_info
*die
,
934 struct dwarf2_cu
*cu
);
936 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
938 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
940 static const char *namespace_name (struct die_info
*die
,
941 int *is_anonymous
, struct dwarf2_cu
*);
943 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
945 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
947 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
950 static struct die_info
*read_comp_unit (gdb_byte
*, bfd
*, struct dwarf2_cu
*);
952 static struct die_info
*read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
954 gdb_byte
**new_info_ptr
,
955 struct die_info
*parent
);
957 static struct die_info
*read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
959 gdb_byte
**new_info_ptr
,
960 struct die_info
*parent
);
962 static void process_die (struct die_info
*, struct dwarf2_cu
*);
964 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
966 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
968 static struct die_info
*dwarf2_extension (struct die_info
*die
,
969 struct dwarf2_cu
**);
971 static char *dwarf_tag_name (unsigned int);
973 static char *dwarf_attr_name (unsigned int);
975 static char *dwarf_form_name (unsigned int);
977 static char *dwarf_stack_op_name (unsigned int);
979 static char *dwarf_bool_name (unsigned int);
981 static char *dwarf_type_encoding_name (unsigned int);
984 static char *dwarf_cfi_name (unsigned int);
987 static struct die_info
*sibling_die (struct die_info
*);
989 static void dump_die (struct die_info
*);
991 static void dump_die_list (struct die_info
*);
993 static void store_in_ref_table (struct die_info
*,
996 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*,
999 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
1001 static struct die_info
*follow_die_ref (struct die_info
*,
1003 struct dwarf2_cu
**);
1005 /* memory allocation interface */
1007 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1009 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1011 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1013 static void initialize_cu_func_list (struct dwarf2_cu
*);
1015 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1016 struct dwarf2_cu
*);
1018 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1019 char *, bfd
*, struct dwarf2_cu
*);
1021 static int attr_form_is_block (struct attribute
*);
1023 static int attr_form_is_section_offset (struct attribute
*);
1025 static int attr_form_is_constant (struct attribute
*);
1027 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1029 struct dwarf2_cu
*cu
);
1031 static gdb_byte
*skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
1032 struct dwarf2_cu
*cu
);
1034 static void free_stack_comp_unit (void *);
1036 static hashval_t
partial_die_hash (const void *item
);
1038 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1040 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1041 (unsigned long offset
, struct objfile
*objfile
);
1043 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1044 (unsigned long offset
, struct objfile
*objfile
);
1046 static void free_one_comp_unit (void *);
1048 static void free_cached_comp_units (void *);
1050 static void age_cached_comp_units (void);
1052 static void free_one_cached_comp_unit (void *);
1054 static struct type
*set_die_type (struct die_info
*, struct type
*,
1055 struct dwarf2_cu
*);
1057 static void create_all_comp_units (struct objfile
*);
1059 static struct dwarf2_cu
*load_full_comp_unit (struct dwarf2_per_cu_data
*,
1062 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1064 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1065 struct dwarf2_per_cu_data
*);
1067 static void dwarf2_mark (struct dwarf2_cu
*);
1069 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1071 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1073 /* Try to locate the sections we need for DWARF 2 debugging
1074 information and return true if we have enough to do something. */
1077 dwarf2_has_info (struct objfile
*objfile
)
1079 struct dwarf2_per_objfile
*data
;
1081 /* Initialize per-objfile state. */
1082 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1083 memset (data
, 0, sizeof (*data
));
1084 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1085 dwarf2_per_objfile
= data
;
1087 dwarf_info_section
= 0;
1088 dwarf_abbrev_section
= 0;
1089 dwarf_line_section
= 0;
1090 dwarf_str_section
= 0;
1091 dwarf_macinfo_section
= 0;
1092 dwarf_frame_section
= 0;
1093 dwarf_eh_frame_section
= 0;
1094 dwarf_ranges_section
= 0;
1095 dwarf_loc_section
= 0;
1097 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1098 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
1101 /* When loading sections, we can either look for ".<name>", or for
1102 * ".z<name>", which indicates a compressed section. */
1105 section_is_p (asection
*sectp
, const char *name
)
1107 return ((sectp
->name
[0] == '.'
1108 && strcmp (sectp
->name
+ 1, name
) == 0)
1109 || (sectp
->name
[0] == '.' && sectp
->name
[1] == 'z'
1110 && strcmp (sectp
->name
+ 2, name
) == 0));
1113 /* This function is mapped across the sections and remembers the
1114 offset and size of each of the debugging sections we are interested
1118 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1120 if (section_is_p (sectp
, INFO_SECTION
))
1122 dwarf2_per_objfile
->info_size
= bfd_get_section_size (sectp
);
1123 dwarf_info_section
= sectp
;
1125 else if (section_is_p (sectp
, ABBREV_SECTION
))
1127 dwarf2_per_objfile
->abbrev_size
= bfd_get_section_size (sectp
);
1128 dwarf_abbrev_section
= sectp
;
1130 else if (section_is_p (sectp
, LINE_SECTION
))
1132 dwarf2_per_objfile
->line_size
= bfd_get_section_size (sectp
);
1133 dwarf_line_section
= sectp
;
1135 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1137 dwarf2_per_objfile
->pubnames_size
= bfd_get_section_size (sectp
);
1138 dwarf_pubnames_section
= sectp
;
1140 else if (section_is_p (sectp
, ARANGES_SECTION
))
1142 dwarf2_per_objfile
->aranges_size
= bfd_get_section_size (sectp
);
1143 dwarf_aranges_section
= sectp
;
1145 else if (section_is_p (sectp
, LOC_SECTION
))
1147 dwarf2_per_objfile
->loc_size
= bfd_get_section_size (sectp
);
1148 dwarf_loc_section
= sectp
;
1150 else if (section_is_p (sectp
, MACINFO_SECTION
))
1152 dwarf2_per_objfile
->macinfo_size
= bfd_get_section_size (sectp
);
1153 dwarf_macinfo_section
= sectp
;
1155 else if (section_is_p (sectp
, STR_SECTION
))
1157 dwarf2_per_objfile
->str_size
= bfd_get_section_size (sectp
);
1158 dwarf_str_section
= sectp
;
1160 else if (section_is_p (sectp
, FRAME_SECTION
))
1162 dwarf2_per_objfile
->frame_size
= bfd_get_section_size (sectp
);
1163 dwarf_frame_section
= sectp
;
1165 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1167 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1168 if (aflag
& SEC_HAS_CONTENTS
)
1170 dwarf2_per_objfile
->eh_frame_size
= bfd_get_section_size (sectp
);
1171 dwarf_eh_frame_section
= sectp
;
1174 else if (section_is_p (sectp
, RANGES_SECTION
))
1176 dwarf2_per_objfile
->ranges_size
= bfd_get_section_size (sectp
);
1177 dwarf_ranges_section
= sectp
;
1180 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1181 && bfd_section_vma (abfd
, sectp
) == 0)
1182 dwarf2_per_objfile
->has_section_at_zero
= 1;
1185 /* This function is called after decompressing a section, so
1186 dwarf2_per_objfile can record its new, uncompressed size. */
1189 dwarf2_resize_section (asection
*sectp
, bfd_size_type new_size
)
1191 if (section_is_p (sectp
, INFO_SECTION
))
1192 dwarf2_per_objfile
->info_size
= new_size
;
1193 else if (section_is_p (sectp
, ABBREV_SECTION
))
1194 dwarf2_per_objfile
->abbrev_size
= new_size
;
1195 else if (section_is_p (sectp
, LINE_SECTION
))
1196 dwarf2_per_objfile
->line_size
= new_size
;
1197 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1198 dwarf2_per_objfile
->pubnames_size
= new_size
;
1199 else if (section_is_p (sectp
, ARANGES_SECTION
))
1200 dwarf2_per_objfile
->aranges_size
= new_size
;
1201 else if (section_is_p (sectp
, LOC_SECTION
))
1202 dwarf2_per_objfile
->loc_size
= new_size
;
1203 else if (section_is_p (sectp
, MACINFO_SECTION
))
1204 dwarf2_per_objfile
->macinfo_size
= new_size
;
1205 else if (section_is_p (sectp
, STR_SECTION
))
1206 dwarf2_per_objfile
->str_size
= new_size
;
1207 else if (section_is_p (sectp
, FRAME_SECTION
))
1208 dwarf2_per_objfile
->frame_size
= new_size
;
1209 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1210 dwarf2_per_objfile
->eh_frame_size
= new_size
;
1211 else if (section_is_p (sectp
, RANGES_SECTION
))
1212 dwarf2_per_objfile
->ranges_size
= new_size
;
1214 internal_error (__FILE__
, __LINE__
,
1215 _("dwarf2_resize_section: missing section_is_p check: %s"),
1219 /* Build a partial symbol table. */
1222 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1224 /* We definitely need the .debug_info and .debug_abbrev sections */
1226 dwarf2_per_objfile
->info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1227 dwarf2_per_objfile
->abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1229 if (dwarf_line_section
)
1230 dwarf2_per_objfile
->line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1232 dwarf2_per_objfile
->line_buffer
= NULL
;
1234 if (dwarf_str_section
)
1235 dwarf2_per_objfile
->str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1237 dwarf2_per_objfile
->str_buffer
= NULL
;
1239 if (dwarf_macinfo_section
)
1240 dwarf2_per_objfile
->macinfo_buffer
= dwarf2_read_section (objfile
,
1241 dwarf_macinfo_section
);
1243 dwarf2_per_objfile
->macinfo_buffer
= NULL
;
1245 if (dwarf_ranges_section
)
1246 dwarf2_per_objfile
->ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1248 dwarf2_per_objfile
->ranges_buffer
= NULL
;
1250 if (dwarf_loc_section
)
1251 dwarf2_per_objfile
->loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1253 dwarf2_per_objfile
->loc_buffer
= NULL
;
1256 || (objfile
->global_psymbols
.size
== 0
1257 && objfile
->static_psymbols
.size
== 0))
1259 init_psymbol_list (objfile
, 1024);
1263 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1265 /* Things are significantly easier if we have .debug_aranges and
1266 .debug_pubnames sections */
1268 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1272 /* only test this case for now */
1274 /* In this case we have to work a bit harder */
1275 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1280 /* Build the partial symbol table from the information in the
1281 .debug_pubnames and .debug_aranges sections. */
1284 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1286 bfd
*abfd
= objfile
->obfd
;
1287 char *aranges_buffer
, *pubnames_buffer
;
1288 char *aranges_ptr
, *pubnames_ptr
;
1289 unsigned int entry_length
, version
, info_offset
, info_size
;
1291 pubnames_buffer
= dwarf2_read_section (objfile
,
1292 dwarf_pubnames_section
);
1293 pubnames_ptr
= pubnames_buffer
;
1294 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames_size
)
1296 struct comp_unit_head cu_header
;
1297 unsigned int bytes_read
;
1299 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1301 pubnames_ptr
+= bytes_read
;
1302 version
= read_1_byte (abfd
, pubnames_ptr
);
1304 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1306 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1310 aranges_buffer
= dwarf2_read_section (objfile
,
1311 dwarf_aranges_section
);
1316 /* Read in the comp unit header information from the debug_info at
1320 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1321 gdb_byte
*info_ptr
, bfd
*abfd
)
1324 unsigned int bytes_read
;
1325 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1327 info_ptr
+= bytes_read
;
1328 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1330 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1332 info_ptr
+= bytes_read
;
1333 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1335 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1336 if (signed_addr
< 0)
1337 internal_error (__FILE__
, __LINE__
,
1338 _("read_comp_unit_head: dwarf from non elf file"));
1339 cu_header
->signed_addr_p
= signed_addr
;
1344 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1347 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1349 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1351 if (header
->version
!= 2 && header
->version
!= 3)
1352 error (_("Dwarf Error: wrong version in compilation unit header "
1353 "(is %d, should be %d) [in module %s]"), header
->version
,
1354 2, bfd_get_filename (abfd
));
1356 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev_size
)
1357 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1358 "(offset 0x%lx + 6) [in module %s]"),
1359 (long) header
->abbrev_offset
,
1360 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1361 bfd_get_filename (abfd
));
1363 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1364 > dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1365 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1366 "(offset 0x%lx + 0) [in module %s]"),
1367 (long) header
->length
,
1368 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1369 bfd_get_filename (abfd
));
1374 /* Allocate a new partial symtab for file named NAME and mark this new
1375 partial symtab as being an include of PST. */
1378 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1379 struct objfile
*objfile
)
1381 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1383 subpst
->section_offsets
= pst
->section_offsets
;
1384 subpst
->textlow
= 0;
1385 subpst
->texthigh
= 0;
1387 subpst
->dependencies
= (struct partial_symtab
**)
1388 obstack_alloc (&objfile
->objfile_obstack
,
1389 sizeof (struct partial_symtab
*));
1390 subpst
->dependencies
[0] = pst
;
1391 subpst
->number_of_dependencies
= 1;
1393 subpst
->globals_offset
= 0;
1394 subpst
->n_global_syms
= 0;
1395 subpst
->statics_offset
= 0;
1396 subpst
->n_static_syms
= 0;
1397 subpst
->symtab
= NULL
;
1398 subpst
->read_symtab
= pst
->read_symtab
;
1401 /* No private part is necessary for include psymtabs. This property
1402 can be used to differentiate between such include psymtabs and
1403 the regular ones. */
1404 subpst
->read_symtab_private
= NULL
;
1407 /* Read the Line Number Program data and extract the list of files
1408 included by the source file represented by PST. Build an include
1409 partial symtab for each of these included files.
1411 This procedure assumes that there *is* a Line Number Program in
1412 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1413 before calling this procedure. */
1416 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1417 struct partial_die_info
*pdi
,
1418 struct partial_symtab
*pst
)
1420 struct objfile
*objfile
= cu
->objfile
;
1421 bfd
*abfd
= objfile
->obfd
;
1422 struct line_header
*lh
;
1424 lh
= dwarf_decode_line_header (pdi
->line_offset
, abfd
, cu
);
1426 return; /* No linetable, so no includes. */
1428 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1430 free_line_header (lh
);
1434 /* Build the partial symbol table by doing a quick pass through the
1435 .debug_info and .debug_abbrev sections. */
1438 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1440 /* Instead of reading this into a big buffer, we should probably use
1441 mmap() on architectures that support it. (FIXME) */
1442 bfd
*abfd
= objfile
->obfd
;
1444 gdb_byte
*beg_of_comp_unit
;
1445 struct partial_die_info comp_unit_die
;
1446 struct partial_symtab
*pst
;
1447 struct cleanup
*back_to
;
1448 CORE_ADDR lowpc
, highpc
, baseaddr
;
1450 info_ptr
= dwarf2_per_objfile
->info_buffer
;
1452 /* Any cached compilation units will be linked by the per-objfile
1453 read_in_chain. Make sure to free them when we're done. */
1454 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1456 create_all_comp_units (objfile
);
1458 objfile
->psymtabs_addrmap
= addrmap_create_mutable
1459 (&objfile
->objfile_obstack
);
1461 /* Since the objects we're extracting from .debug_info vary in
1462 length, only the individual functions to extract them (like
1463 read_comp_unit_head and load_partial_die) can really know whether
1464 the buffer is large enough to hold another complete object.
1466 At the moment, they don't actually check that. If .debug_info
1467 holds just one extra byte after the last compilation unit's dies,
1468 then read_comp_unit_head will happily read off the end of the
1469 buffer. read_partial_die is similarly casual. Those functions
1472 For this loop condition, simply checking whether there's any data
1473 left at all should be sufficient. */
1474 while (info_ptr
< (dwarf2_per_objfile
->info_buffer
1475 + dwarf2_per_objfile
->info_size
))
1477 struct cleanup
*back_to_inner
;
1478 struct dwarf2_cu cu
;
1479 struct abbrev_info
*abbrev
;
1480 unsigned int bytes_read
;
1481 struct dwarf2_per_cu_data
*this_cu
;
1483 beg_of_comp_unit
= info_ptr
;
1485 memset (&cu
, 0, sizeof (cu
));
1487 obstack_init (&cu
.comp_unit_obstack
);
1489 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1491 cu
.objfile
= objfile
;
1492 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1494 /* Complete the cu_header */
1495 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1496 cu
.header
.first_die_ptr
= info_ptr
;
1497 cu
.header
.cu_head_ptr
= beg_of_comp_unit
;
1499 cu
.list_in_scope
= &file_symbols
;
1501 /* Read the abbrevs for this compilation unit into a table */
1502 dwarf2_read_abbrevs (abfd
, &cu
);
1503 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1505 this_cu
= dwarf2_find_comp_unit (cu
.header
.offset
, objfile
);
1507 /* Read the compilation unit die */
1508 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, &cu
);
1509 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1510 abfd
, info_ptr
, &cu
);
1512 if (comp_unit_die
.tag
== DW_TAG_partial_unit
)
1514 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1515 + cu
.header
.initial_length_size
);
1516 do_cleanups (back_to_inner
);
1520 /* Set the language we're debugging */
1521 set_cu_language (comp_unit_die
.language
, &cu
);
1523 /* Allocate a new partial symbol table structure */
1524 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1525 comp_unit_die
.name
? comp_unit_die
.name
: "",
1526 /* TEXTLOW and TEXTHIGH are set below. */
1528 objfile
->global_psymbols
.next
,
1529 objfile
->static_psymbols
.next
);
1531 if (comp_unit_die
.dirname
)
1532 pst
->dirname
= xstrdup (comp_unit_die
.dirname
);
1534 pst
->read_symtab_private
= (char *) this_cu
;
1536 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1538 /* Store the function that reads in the rest of the symbol table */
1539 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1541 /* If this compilation unit was already read in, free the
1542 cached copy in order to read it in again. This is
1543 necessary because we skipped some symbols when we first
1544 read in the compilation unit (see load_partial_dies).
1545 This problem could be avoided, but the benefit is
1547 if (this_cu
->cu
!= NULL
)
1548 free_one_cached_comp_unit (this_cu
->cu
);
1550 cu
.per_cu
= this_cu
;
1552 /* Note that this is a pointer to our stack frame, being
1553 added to a global data structure. It will be cleaned up
1554 in free_stack_comp_unit when we finish with this
1555 compilation unit. */
1558 this_cu
->psymtab
= pst
;
1560 /* Possibly set the default values of LOWPC and HIGHPC from
1562 if (cu
.has_ranges_offset
)
1564 if (dwarf2_ranges_read (cu
.ranges_offset
, &comp_unit_die
.lowpc
,
1565 &comp_unit_die
.highpc
, &cu
, pst
))
1566 comp_unit_die
.has_pc_info
= 1;
1569 /* Check if comp unit has_children.
1570 If so, read the rest of the partial symbols from this comp unit.
1571 If not, there's no more debug_info for this comp unit. */
1572 if (comp_unit_die
.has_children
)
1574 struct partial_die_info
*first_die
;
1576 lowpc
= ((CORE_ADDR
) -1);
1577 highpc
= ((CORE_ADDR
) 0);
1579 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1581 scan_partial_symbols (first_die
, &lowpc
, &highpc
, &cu
);
1583 /* If we didn't find a lowpc, set it to highpc to avoid
1584 complaints from `maint check'. */
1585 if (lowpc
== ((CORE_ADDR
) -1))
1588 /* If the compilation unit didn't have an explicit address range,
1589 then use the information extracted from its child dies. */
1590 if (! comp_unit_die
.has_pc_info
)
1592 comp_unit_die
.lowpc
= lowpc
;
1593 comp_unit_die
.highpc
= highpc
;
1596 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1597 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1599 /* Store the contiguous range; `DW_AT_ranges' range is stored above. The
1600 range can be also empty for CUs with no code. */
1601 if (!cu
.has_ranges_offset
&& pst
->textlow
< pst
->texthigh
)
1602 addrmap_set_empty (objfile
->psymtabs_addrmap
, pst
->textlow
,
1603 pst
->texthigh
- 1, pst
);
1605 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1606 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1607 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1608 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1609 sort_pst_symbols (pst
);
1611 /* If there is already a psymtab or symtab for a file of this
1612 name, remove it. (If there is a symtab, more drastic things
1613 also happen.) This happens in VxWorks. */
1614 free_named_symtabs (pst
->filename
);
1616 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1617 + cu
.header
.initial_length_size
;
1619 if (comp_unit_die
.has_stmt_list
)
1621 /* Get the list of files included in the current compilation unit,
1622 and build a psymtab for each of them. */
1623 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1626 do_cleanups (back_to_inner
);
1629 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
1630 &objfile
->objfile_obstack
);
1632 do_cleanups (back_to
);
1635 /* Load the DIEs for a secondary CU into memory. */
1638 load_comp_unit (struct dwarf2_per_cu_data
*this_cu
, struct objfile
*objfile
)
1640 bfd
*abfd
= objfile
->obfd
;
1641 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
1642 struct partial_die_info comp_unit_die
;
1643 struct dwarf2_cu
*cu
;
1644 struct abbrev_info
*abbrev
;
1645 unsigned int bytes_read
;
1646 struct cleanup
*back_to
;
1648 info_ptr
= dwarf2_per_objfile
->info_buffer
+ this_cu
->offset
;
1649 beg_of_comp_unit
= info_ptr
;
1651 cu
= xmalloc (sizeof (struct dwarf2_cu
));
1652 memset (cu
, 0, sizeof (struct dwarf2_cu
));
1654 obstack_init (&cu
->comp_unit_obstack
);
1656 cu
->objfile
= objfile
;
1657 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
1659 /* Complete the cu_header. */
1660 cu
->header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1661 cu
->header
.first_die_ptr
= info_ptr
;
1662 cu
->header
.cu_head_ptr
= beg_of_comp_unit
;
1664 /* Read the abbrevs for this compilation unit into a table. */
1665 dwarf2_read_abbrevs (abfd
, cu
);
1666 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
1668 /* Read the compilation unit die. */
1669 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1670 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1671 abfd
, info_ptr
, cu
);
1673 /* Set the language we're debugging. */
1674 set_cu_language (comp_unit_die
.language
, cu
);
1676 /* Link this compilation unit into the compilation unit tree. */
1678 cu
->per_cu
= this_cu
;
1679 cu
->type_hash
= cu
->per_cu
->type_hash
;
1681 /* Check if comp unit has_children.
1682 If so, read the rest of the partial symbols from this comp unit.
1683 If not, there's no more debug_info for this comp unit. */
1684 if (comp_unit_die
.has_children
)
1685 load_partial_dies (abfd
, info_ptr
, 0, cu
);
1687 do_cleanups (back_to
);
1690 /* Create a list of all compilation units in OBJFILE. We do this only
1691 if an inter-comp-unit reference is found; presumably if there is one,
1692 there will be many, and one will occur early in the .debug_info section.
1693 So there's no point in building this list incrementally. */
1696 create_all_comp_units (struct objfile
*objfile
)
1700 struct dwarf2_per_cu_data
**all_comp_units
;
1701 gdb_byte
*info_ptr
= dwarf2_per_objfile
->info_buffer
;
1705 all_comp_units
= xmalloc (n_allocated
1706 * sizeof (struct dwarf2_per_cu_data
*));
1708 while (info_ptr
< dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1710 struct comp_unit_head cu_header
;
1711 gdb_byte
*beg_of_comp_unit
;
1712 struct dwarf2_per_cu_data
*this_cu
;
1713 unsigned long offset
;
1714 unsigned int bytes_read
;
1716 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
1718 /* Read just enough information to find out where the next
1719 compilation unit is. */
1720 cu_header
.initial_length_size
= 0;
1721 cu_header
.length
= read_initial_length (objfile
->obfd
, info_ptr
,
1722 &cu_header
, &bytes_read
);
1724 /* Save the compilation unit for later lookup. */
1725 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
1726 sizeof (struct dwarf2_per_cu_data
));
1727 memset (this_cu
, 0, sizeof (*this_cu
));
1728 this_cu
->offset
= offset
;
1729 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
1731 if (n_comp_units
== n_allocated
)
1734 all_comp_units
= xrealloc (all_comp_units
,
1736 * sizeof (struct dwarf2_per_cu_data
*));
1738 all_comp_units
[n_comp_units
++] = this_cu
;
1740 info_ptr
= info_ptr
+ this_cu
->length
;
1743 dwarf2_per_objfile
->all_comp_units
1744 = obstack_alloc (&objfile
->objfile_obstack
,
1745 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1746 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
1747 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1748 xfree (all_comp_units
);
1749 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
1752 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1753 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1757 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1758 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
1760 struct objfile
*objfile
= cu
->objfile
;
1761 bfd
*abfd
= objfile
->obfd
;
1762 struct partial_die_info
*pdi
;
1764 /* Now, march along the PDI's, descending into ones which have
1765 interesting children but skipping the children of the other ones,
1766 until we reach the end of the compilation unit. */
1772 fixup_partial_die (pdi
, cu
);
1774 /* Anonymous namespaces have no name but have interesting
1775 children, so we need to look at them. Ditto for anonymous
1778 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1779 || pdi
->tag
== DW_TAG_enumeration_type
)
1783 case DW_TAG_subprogram
:
1784 if (pdi
->has_pc_info
)
1786 if (pdi
->lowpc
< *lowpc
)
1788 *lowpc
= pdi
->lowpc
;
1790 if (pdi
->highpc
> *highpc
)
1792 *highpc
= pdi
->highpc
;
1794 if (!pdi
->is_declaration
)
1796 add_partial_symbol (pdi
, cu
);
1800 case DW_TAG_variable
:
1801 case DW_TAG_typedef
:
1802 case DW_TAG_union_type
:
1803 if (!pdi
->is_declaration
)
1805 add_partial_symbol (pdi
, cu
);
1808 case DW_TAG_class_type
:
1809 case DW_TAG_interface_type
:
1810 case DW_TAG_structure_type
:
1811 if (!pdi
->is_declaration
)
1813 add_partial_symbol (pdi
, cu
);
1816 case DW_TAG_enumeration_type
:
1817 if (!pdi
->is_declaration
)
1818 add_partial_enumeration (pdi
, cu
);
1820 case DW_TAG_base_type
:
1821 case DW_TAG_subrange_type
:
1822 /* File scope base type definitions are added to the partial
1824 add_partial_symbol (pdi
, cu
);
1826 case DW_TAG_namespace
:
1827 add_partial_namespace (pdi
, lowpc
, highpc
, cu
);
1834 /* If the die has a sibling, skip to the sibling. */
1836 pdi
= pdi
->die_sibling
;
1840 /* Functions used to compute the fully scoped name of a partial DIE.
1842 Normally, this is simple. For C++, the parent DIE's fully scoped
1843 name is concatenated with "::" and the partial DIE's name. For
1844 Java, the same thing occurs except that "." is used instead of "::".
1845 Enumerators are an exception; they use the scope of their parent
1846 enumeration type, i.e. the name of the enumeration type is not
1847 prepended to the enumerator.
1849 There are two complexities. One is DW_AT_specification; in this
1850 case "parent" means the parent of the target of the specification,
1851 instead of the direct parent of the DIE. The other is compilers
1852 which do not emit DW_TAG_namespace; in this case we try to guess
1853 the fully qualified name of structure types from their members'
1854 linkage names. This must be done using the DIE's children rather
1855 than the children of any DW_AT_specification target. We only need
1856 to do this for structures at the top level, i.e. if the target of
1857 any DW_AT_specification (if any; otherwise the DIE itself) does not
1860 /* Compute the scope prefix associated with PDI's parent, in
1861 compilation unit CU. The result will be allocated on CU's
1862 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1863 field. NULL is returned if no prefix is necessary. */
1865 partial_die_parent_scope (struct partial_die_info
*pdi
,
1866 struct dwarf2_cu
*cu
)
1868 char *grandparent_scope
;
1869 struct partial_die_info
*parent
, *real_pdi
;
1871 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1872 then this means the parent of the specification DIE. */
1875 while (real_pdi
->has_specification
)
1876 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
1878 parent
= real_pdi
->die_parent
;
1882 if (parent
->scope_set
)
1883 return parent
->scope
;
1885 fixup_partial_die (parent
, cu
);
1887 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
1889 if (parent
->tag
== DW_TAG_namespace
1890 || parent
->tag
== DW_TAG_structure_type
1891 || parent
->tag
== DW_TAG_class_type
1892 || parent
->tag
== DW_TAG_interface_type
1893 || parent
->tag
== DW_TAG_union_type
)
1895 if (grandparent_scope
== NULL
)
1896 parent
->scope
= parent
->name
;
1898 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
1901 else if (parent
->tag
== DW_TAG_enumeration_type
)
1902 /* Enumerators should not get the name of the enumeration as a prefix. */
1903 parent
->scope
= grandparent_scope
;
1906 /* FIXME drow/2004-04-01: What should we be doing with
1907 function-local names? For partial symbols, we should probably be
1909 complaint (&symfile_complaints
,
1910 _("unhandled containing DIE tag %d for DIE at %d"),
1911 parent
->tag
, pdi
->offset
);
1912 parent
->scope
= grandparent_scope
;
1915 parent
->scope_set
= 1;
1916 return parent
->scope
;
1919 /* Return the fully scoped name associated with PDI, from compilation unit
1920 CU. The result will be allocated with malloc. */
1922 partial_die_full_name (struct partial_die_info
*pdi
,
1923 struct dwarf2_cu
*cu
)
1927 parent_scope
= partial_die_parent_scope (pdi
, cu
);
1928 if (parent_scope
== NULL
)
1931 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
1935 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
1937 struct objfile
*objfile
= cu
->objfile
;
1939 char *actual_name
= NULL
;
1940 const char *my_prefix
;
1941 const struct partial_symbol
*psym
= NULL
;
1943 int built_actual_name
= 0;
1945 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1947 if (pdi_needs_namespace (pdi
->tag
))
1949 actual_name
= partial_die_full_name (pdi
, cu
);
1951 built_actual_name
= 1;
1954 if (actual_name
== NULL
)
1955 actual_name
= pdi
->name
;
1959 case DW_TAG_subprogram
:
1960 if (pdi
->is_external
|| cu
->language
== language_ada
)
1962 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
1963 of the global scope. But in Ada, we want to be able to access
1964 nested procedures globally. So all Ada subprograms are stored
1965 in the global scope. */
1966 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1967 mst_text, objfile); */
1968 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1969 VAR_DOMAIN
, LOC_BLOCK
,
1970 &objfile
->global_psymbols
,
1971 0, pdi
->lowpc
+ baseaddr
,
1972 cu
->language
, objfile
);
1976 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1977 mst_file_text, objfile); */
1978 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1979 VAR_DOMAIN
, LOC_BLOCK
,
1980 &objfile
->static_psymbols
,
1981 0, pdi
->lowpc
+ baseaddr
,
1982 cu
->language
, objfile
);
1985 case DW_TAG_variable
:
1986 if (pdi
->is_external
)
1989 Don't enter into the minimal symbol tables as there is
1990 a minimal symbol table entry from the ELF symbols already.
1991 Enter into partial symbol table if it has a location
1992 descriptor or a type.
1993 If the location descriptor is missing, new_symbol will create
1994 a LOC_UNRESOLVED symbol, the address of the variable will then
1995 be determined from the minimal symbol table whenever the variable
1997 The address for the partial symbol table entry is not
1998 used by GDB, but it comes in handy for debugging partial symbol
2002 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2003 if (pdi
->locdesc
|| pdi
->has_type
)
2004 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2005 VAR_DOMAIN
, LOC_STATIC
,
2006 &objfile
->global_psymbols
,
2008 cu
->language
, objfile
);
2012 /* Static Variable. Skip symbols without location descriptors. */
2013 if (pdi
->locdesc
== NULL
)
2015 if (built_actual_name
)
2016 xfree (actual_name
);
2019 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2020 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2021 mst_file_data, objfile); */
2022 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2023 VAR_DOMAIN
, LOC_STATIC
,
2024 &objfile
->static_psymbols
,
2026 cu
->language
, objfile
);
2029 case DW_TAG_typedef
:
2030 case DW_TAG_base_type
:
2031 case DW_TAG_subrange_type
:
2032 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2033 VAR_DOMAIN
, LOC_TYPEDEF
,
2034 &objfile
->static_psymbols
,
2035 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2037 case DW_TAG_namespace
:
2038 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2039 VAR_DOMAIN
, LOC_TYPEDEF
,
2040 &objfile
->global_psymbols
,
2041 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2043 case DW_TAG_class_type
:
2044 case DW_TAG_interface_type
:
2045 case DW_TAG_structure_type
:
2046 case DW_TAG_union_type
:
2047 case DW_TAG_enumeration_type
:
2048 /* Skip external references. The DWARF standard says in the section
2049 about "Structure, Union, and Class Type Entries": "An incomplete
2050 structure, union or class type is represented by a structure,
2051 union or class entry that does not have a byte size attribute
2052 and that has a DW_AT_declaration attribute." */
2053 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2055 if (built_actual_name
)
2056 xfree (actual_name
);
2060 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2061 static vs. global. */
2062 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2063 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2064 (cu
->language
== language_cplus
2065 || cu
->language
== language_java
)
2066 ? &objfile
->global_psymbols
2067 : &objfile
->static_psymbols
,
2068 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2071 case DW_TAG_enumerator
:
2072 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2073 VAR_DOMAIN
, LOC_CONST
,
2074 (cu
->language
== language_cplus
2075 || cu
->language
== language_java
)
2076 ? &objfile
->global_psymbols
2077 : &objfile
->static_psymbols
,
2078 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2084 /* Check to see if we should scan the name for possible namespace
2085 info. Only do this if this is C++, if we don't have namespace
2086 debugging info in the file, if the psym is of an appropriate type
2087 (otherwise we'll have psym == NULL), and if we actually had a
2088 mangled name to begin with. */
2090 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2091 cases which do not set PSYM above? */
2093 if (cu
->language
== language_cplus
2094 && cu
->has_namespace_info
== 0
2096 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
2097 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
2100 if (built_actual_name
)
2101 xfree (actual_name
);
2104 /* Determine whether a die of type TAG living in a C++ class or
2105 namespace needs to have the name of the scope prepended to the
2106 name listed in the die. */
2109 pdi_needs_namespace (enum dwarf_tag tag
)
2113 case DW_TAG_namespace
:
2114 case DW_TAG_typedef
:
2115 case DW_TAG_class_type
:
2116 case DW_TAG_interface_type
:
2117 case DW_TAG_structure_type
:
2118 case DW_TAG_union_type
:
2119 case DW_TAG_enumeration_type
:
2120 case DW_TAG_enumerator
:
2127 /* Read a partial die corresponding to a namespace; also, add a symbol
2128 corresponding to that namespace to the symbol table. NAMESPACE is
2129 the name of the enclosing namespace. */
2132 add_partial_namespace (struct partial_die_info
*pdi
,
2133 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2134 struct dwarf2_cu
*cu
)
2136 struct objfile
*objfile
= cu
->objfile
;
2138 /* Add a symbol for the namespace. */
2140 add_partial_symbol (pdi
, cu
);
2142 /* Now scan partial symbols in that namespace. */
2144 if (pdi
->has_children
)
2145 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, cu
);
2148 /* See if we can figure out if the class lives in a namespace. We do
2149 this by looking for a member function; its demangled name will
2150 contain namespace info, if there is any. */
2153 guess_structure_name (struct partial_die_info
*struct_pdi
,
2154 struct dwarf2_cu
*cu
)
2156 if ((cu
->language
== language_cplus
2157 || cu
->language
== language_java
)
2158 && cu
->has_namespace_info
== 0
2159 && struct_pdi
->has_children
)
2161 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2162 what template types look like, because the demangler
2163 frequently doesn't give the same name as the debug info. We
2164 could fix this by only using the demangled name to get the
2165 prefix (but see comment in read_structure_type). */
2167 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
2168 struct partial_die_info
*real_pdi
;
2170 /* If this DIE (this DIE's specification, if any) has a parent, then
2171 we should not do this. We'll prepend the parent's fully qualified
2172 name when we create the partial symbol. */
2174 real_pdi
= struct_pdi
;
2175 while (real_pdi
->has_specification
)
2176 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2178 if (real_pdi
->die_parent
!= NULL
)
2181 while (child_pdi
!= NULL
)
2183 if (child_pdi
->tag
== DW_TAG_subprogram
)
2185 char *actual_class_name
2186 = language_class_name_from_physname (cu
->language_defn
,
2188 if (actual_class_name
!= NULL
)
2191 = obsavestring (actual_class_name
,
2192 strlen (actual_class_name
),
2193 &cu
->comp_unit_obstack
);
2194 xfree (actual_class_name
);
2199 child_pdi
= child_pdi
->die_sibling
;
2204 /* Read a partial die corresponding to an enumeration type. */
2207 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2208 struct dwarf2_cu
*cu
)
2210 struct objfile
*objfile
= cu
->objfile
;
2211 bfd
*abfd
= objfile
->obfd
;
2212 struct partial_die_info
*pdi
;
2214 if (enum_pdi
->name
!= NULL
)
2215 add_partial_symbol (enum_pdi
, cu
);
2217 pdi
= enum_pdi
->die_child
;
2220 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2221 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2223 add_partial_symbol (pdi
, cu
);
2224 pdi
= pdi
->die_sibling
;
2228 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2229 Return the corresponding abbrev, or NULL if the number is zero (indicating
2230 an empty DIE). In either case *BYTES_READ will be set to the length of
2231 the initial number. */
2233 static struct abbrev_info
*
2234 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2235 struct dwarf2_cu
*cu
)
2237 bfd
*abfd
= cu
->objfile
->obfd
;
2238 unsigned int abbrev_number
;
2239 struct abbrev_info
*abbrev
;
2241 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2243 if (abbrev_number
== 0)
2246 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2249 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2250 bfd_get_filename (abfd
));
2256 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2257 pointer to the end of a series of DIEs, terminated by an empty
2258 DIE. Any children of the skipped DIEs will also be skipped. */
2261 skip_children (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2263 struct abbrev_info
*abbrev
;
2264 unsigned int bytes_read
;
2268 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2270 return info_ptr
+ bytes_read
;
2272 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
2276 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2277 should point just after the initial uleb128 of a DIE, and the
2278 abbrev corresponding to that skipped uleb128 should be passed in
2279 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2283 skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
2284 struct dwarf2_cu
*cu
)
2286 unsigned int bytes_read
;
2287 struct attribute attr
;
2288 bfd
*abfd
= cu
->objfile
->obfd
;
2289 unsigned int form
, i
;
2291 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2293 /* The only abbrev we care about is DW_AT_sibling. */
2294 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2296 read_attribute (&attr
, &abbrev
->attrs
[i
],
2297 abfd
, info_ptr
, cu
);
2298 if (attr
.form
== DW_FORM_ref_addr
)
2299 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2301 return dwarf2_per_objfile
->info_buffer
2302 + dwarf2_get_ref_die_offset (&attr
, cu
);
2305 /* If it isn't DW_AT_sibling, skip this attribute. */
2306 form
= abbrev
->attrs
[i
].form
;
2311 case DW_FORM_ref_addr
:
2312 info_ptr
+= cu
->header
.addr_size
;
2331 case DW_FORM_string
:
2332 read_string (abfd
, info_ptr
, &bytes_read
);
2333 info_ptr
+= bytes_read
;
2336 info_ptr
+= cu
->header
.offset_size
;
2339 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2340 info_ptr
+= bytes_read
;
2342 case DW_FORM_block1
:
2343 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2345 case DW_FORM_block2
:
2346 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2348 case DW_FORM_block4
:
2349 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2353 case DW_FORM_ref_udata
:
2354 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2356 case DW_FORM_indirect
:
2357 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2358 info_ptr
+= bytes_read
;
2359 /* We need to continue parsing from here, so just go back to
2361 goto skip_attribute
;
2364 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2365 dwarf_form_name (form
),
2366 bfd_get_filename (abfd
));
2370 if (abbrev
->has_children
)
2371 return skip_children (info_ptr
, cu
);
2376 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2377 the next DIE after ORIG_PDI. */
2380 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, gdb_byte
*info_ptr
,
2381 bfd
*abfd
, struct dwarf2_cu
*cu
)
2383 /* Do we know the sibling already? */
2385 if (orig_pdi
->sibling
)
2386 return orig_pdi
->sibling
;
2388 /* Are there any children to deal with? */
2390 if (!orig_pdi
->has_children
)
2393 /* Skip the children the long way. */
2395 return skip_children (info_ptr
, cu
);
2398 /* Expand this partial symbol table into a full symbol table. */
2401 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2403 /* FIXME: This is barely more than a stub. */
2408 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2414 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2415 gdb_flush (gdb_stdout
);
2418 /* Restore our global data. */
2419 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2420 dwarf2_objfile_data_key
);
2422 psymtab_to_symtab_1 (pst
);
2424 /* Finish up the debug error message. */
2426 printf_filtered (_("done.\n"));
2431 /* Add PER_CU to the queue. */
2434 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2436 struct dwarf2_queue_item
*item
;
2439 item
= xmalloc (sizeof (*item
));
2440 item
->per_cu
= per_cu
;
2443 if (dwarf2_queue
== NULL
)
2444 dwarf2_queue
= item
;
2446 dwarf2_queue_tail
->next
= item
;
2448 dwarf2_queue_tail
= item
;
2450 /* Either PER_CU is the CU we want to process, or we're following a reference
2451 pointing into PER_CU. Either way, we need its DIEs now. */
2452 load_full_comp_unit (item
->per_cu
, objfile
);
2453 item
->per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
2454 dwarf2_per_objfile
->read_in_chain
= item
->per_cu
;
2457 /* Process the queue. */
2460 process_queue (struct objfile
*objfile
)
2462 struct dwarf2_queue_item
*item
, *next_item
;
2464 /* The queue starts out with one item, but following a DIE reference
2465 may load a new CU, adding it to the end of the queue. */
2466 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2468 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2469 process_full_comp_unit (item
->per_cu
);
2471 item
->per_cu
->queued
= 0;
2472 next_item
= item
->next
;
2476 dwarf2_queue_tail
= NULL
;
2479 /* Free all allocated queue entries. This function only releases anything if
2480 an error was thrown; if the queue was processed then it would have been
2481 freed as we went along. */
2484 dwarf2_release_queue (void *dummy
)
2486 struct dwarf2_queue_item
*item
, *last
;
2488 item
= dwarf2_queue
;
2491 /* Anything still marked queued is likely to be in an
2492 inconsistent state, so discard it. */
2493 if (item
->per_cu
->queued
)
2495 if (item
->per_cu
->cu
!= NULL
)
2496 free_one_cached_comp_unit (item
->per_cu
->cu
);
2497 item
->per_cu
->queued
= 0;
2505 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2508 /* Read in full symbols for PST, and anything it depends on. */
2511 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2513 struct dwarf2_per_cu_data
*per_cu
;
2514 struct cleanup
*back_to
;
2517 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2518 if (!pst
->dependencies
[i
]->readin
)
2520 /* Inform about additional files that need to be read in. */
2523 /* FIXME: i18n: Need to make this a single string. */
2524 fputs_filtered (" ", gdb_stdout
);
2526 fputs_filtered ("and ", gdb_stdout
);
2528 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2529 wrap_here (""); /* Flush output */
2530 gdb_flush (gdb_stdout
);
2532 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2535 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
2539 /* It's an include file, no symbols to read for it.
2540 Everything is in the parent symtab. */
2545 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2547 queue_comp_unit (per_cu
, pst
->objfile
);
2549 process_queue (pst
->objfile
);
2551 /* Age the cache, releasing compilation units that have not
2552 been used recently. */
2553 age_cached_comp_units ();
2555 do_cleanups (back_to
);
2558 /* Load the DIEs associated with PST and PER_CU into memory. */
2560 static struct dwarf2_cu
*
2561 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2563 bfd
*abfd
= objfile
->obfd
;
2564 struct dwarf2_cu
*cu
;
2565 unsigned long offset
;
2567 struct cleanup
*back_to
, *free_cu_cleanup
;
2568 struct attribute
*attr
;
2571 /* Set local variables from the partial symbol table info. */
2572 offset
= per_cu
->offset
;
2574 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2576 cu
= xmalloc (sizeof (struct dwarf2_cu
));
2577 memset (cu
, 0, sizeof (struct dwarf2_cu
));
2579 /* If an error occurs while loading, release our storage. */
2580 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
2582 cu
->objfile
= objfile
;
2584 /* read in the comp_unit header */
2585 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
2587 /* Read the abbrevs for this compilation unit */
2588 dwarf2_read_abbrevs (abfd
, cu
);
2589 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2591 cu
->header
.offset
= offset
;
2593 cu
->per_cu
= per_cu
;
2595 cu
->type_hash
= per_cu
->type_hash
;
2597 /* We use this obstack for block values in dwarf_alloc_block. */
2598 obstack_init (&cu
->comp_unit_obstack
);
2600 cu
->dies
= read_comp_unit (info_ptr
, abfd
, cu
);
2602 /* We try not to read any attributes in this function, because not
2603 all objfiles needed for references have been loaded yet, and symbol
2604 table processing isn't initialized. But we have to set the CU language,
2605 or we won't be able to build types correctly. */
2606 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
2608 set_cu_language (DW_UNSND (attr
), cu
);
2610 set_cu_language (language_minimal
, cu
);
2612 do_cleanups (back_to
);
2614 /* We've successfully allocated this compilation unit. Let our caller
2615 clean it up when finished with it. */
2616 discard_cleanups (free_cu_cleanup
);
2621 /* Generate full symbol information for PST and CU, whose DIEs have
2622 already been loaded into memory. */
2625 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2627 struct partial_symtab
*pst
= per_cu
->psymtab
;
2628 struct dwarf2_cu
*cu
= per_cu
->cu
;
2629 struct objfile
*objfile
= pst
->objfile
;
2630 bfd
*abfd
= objfile
->obfd
;
2631 CORE_ADDR lowpc
, highpc
;
2632 struct symtab
*symtab
;
2633 struct cleanup
*back_to
;
2634 struct attribute
*attr
;
2637 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2640 back_to
= make_cleanup (really_free_pendings
, NULL
);
2642 cu
->list_in_scope
= &file_symbols
;
2644 /* Find the base address of the compilation unit for range lists and
2645 location lists. It will normally be specified by DW_AT_low_pc.
2646 In DWARF-3 draft 4, the base address could be overridden by
2647 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2648 compilation units with discontinuous ranges. */
2650 cu
->header
.base_known
= 0;
2651 cu
->header
.base_address
= 0;
2653 attr
= dwarf2_attr (cu
->dies
, DW_AT_entry_pc
, cu
);
2656 cu
->header
.base_address
= DW_ADDR (attr
);
2657 cu
->header
.base_known
= 1;
2661 attr
= dwarf2_attr (cu
->dies
, DW_AT_low_pc
, cu
);
2664 cu
->header
.base_address
= DW_ADDR (attr
);
2665 cu
->header
.base_known
= 1;
2669 /* Do line number decoding in read_file_scope () */
2670 process_die (cu
->dies
, cu
);
2672 /* Some compilers don't define a DW_AT_high_pc attribute for the
2673 compilation unit. If the DW_AT_high_pc is missing, synthesize
2674 it, by scanning the DIE's below the compilation unit. */
2675 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
2677 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2679 /* Set symtab language to language from DW_AT_language.
2680 If the compilation is from a C file generated by language preprocessors,
2681 do not set the language if it was already deduced by start_subfile. */
2683 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
2685 symtab
->language
= cu
->language
;
2687 pst
->symtab
= symtab
;
2690 do_cleanups (back_to
);
2693 /* Process a die and its children. */
2696 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2700 case DW_TAG_padding
:
2702 case DW_TAG_compile_unit
:
2703 read_file_scope (die
, cu
);
2705 case DW_TAG_subprogram
:
2706 read_func_scope (die
, cu
);
2708 case DW_TAG_inlined_subroutine
:
2709 /* FIXME: These are ignored for now.
2710 They could be used to set breakpoints on all inlined instances
2711 of a function and make GDB `next' properly over inlined functions. */
2713 case DW_TAG_lexical_block
:
2714 case DW_TAG_try_block
:
2715 case DW_TAG_catch_block
:
2716 read_lexical_block_scope (die
, cu
);
2718 case DW_TAG_class_type
:
2719 case DW_TAG_interface_type
:
2720 case DW_TAG_structure_type
:
2721 case DW_TAG_union_type
:
2722 process_structure_scope (die
, cu
);
2724 case DW_TAG_enumeration_type
:
2725 process_enumeration_scope (die
, cu
);
2728 /* These dies have a type, but processing them does not create
2729 a symbol or recurse to process the children. Therefore we can
2730 read them on-demand through read_type_die. */
2731 case DW_TAG_subroutine_type
:
2732 case DW_TAG_set_type
:
2733 case DW_TAG_array_type
:
2734 case DW_TAG_pointer_type
:
2735 case DW_TAG_ptr_to_member_type
:
2736 case DW_TAG_reference_type
:
2737 case DW_TAG_string_type
:
2740 case DW_TAG_base_type
:
2741 case DW_TAG_subrange_type
:
2742 /* Add a typedef symbol for the type definition, if it has a
2744 new_symbol (die
, read_type_die (die
, cu
), cu
);
2746 case DW_TAG_common_block
:
2747 read_common_block (die
, cu
);
2749 case DW_TAG_common_inclusion
:
2751 case DW_TAG_namespace
:
2752 processing_has_namespace_info
= 1;
2753 read_namespace (die
, cu
);
2755 case DW_TAG_imported_declaration
:
2756 case DW_TAG_imported_module
:
2757 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2758 information contained in these. DW_TAG_imported_declaration
2759 dies shouldn't have children; DW_TAG_imported_module dies
2760 shouldn't in the C++ case, but conceivably could in the
2761 Fortran case, so we'll have to replace this gdb_assert if
2762 Fortran compilers start generating that info. */
2763 processing_has_namespace_info
= 1;
2764 gdb_assert (die
->child
== NULL
);
2767 new_symbol (die
, NULL
, cu
);
2772 /* Return the fully qualified name of DIE, based on its DW_AT_name.
2773 If scope qualifiers are appropriate they will be added. The result
2774 will be allocated on the objfile_obstack, or NULL if the DIE does
2778 dwarf2_full_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
2780 struct attribute
*attr
;
2781 char *prefix
, *name
;
2782 struct ui_file
*buf
= NULL
;
2784 name
= dwarf2_name (die
, cu
);
2788 /* These are the only languages we know how to qualify names in. */
2789 if (cu
->language
!= language_cplus
2790 && cu
->language
!= language_java
)
2793 /* If no prefix is necessary for this type of DIE, return the
2794 unqualified name. The other three tags listed could be handled
2795 in pdi_needs_namespace, but that requires broader changes. */
2796 if (!pdi_needs_namespace (die
->tag
)
2797 && die
->tag
!= DW_TAG_subprogram
2798 && die
->tag
!= DW_TAG_variable
2799 && die
->tag
!= DW_TAG_member
)
2802 prefix
= determine_prefix (die
, cu
);
2803 if (*prefix
!= '\0')
2804 name
= typename_concat (&cu
->objfile
->objfile_obstack
, prefix
,
2811 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2813 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2817 free_cu_line_header (void *arg
)
2819 struct dwarf2_cu
*cu
= arg
;
2821 free_line_header (cu
->line_header
);
2822 cu
->line_header
= NULL
;
2826 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2828 struct objfile
*objfile
= cu
->objfile
;
2829 struct comp_unit_head
*cu_header
= &cu
->header
;
2830 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2831 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2832 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2833 struct attribute
*attr
;
2835 char *comp_dir
= NULL
;
2836 struct die_info
*child_die
;
2837 bfd
*abfd
= objfile
->obfd
;
2838 struct line_header
*line_header
= 0;
2841 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2843 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2845 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2846 from finish_block. */
2847 if (lowpc
== ((CORE_ADDR
) -1))
2852 /* Find the filename. Do not use dwarf2_name here, since the filename
2853 is not a source language identifier. */
2854 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2857 name
= DW_STRING (attr
);
2860 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2862 comp_dir
= DW_STRING (attr
);
2863 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
2865 comp_dir
= ldirname (name
);
2866 if (comp_dir
!= NULL
)
2867 make_cleanup (xfree
, comp_dir
);
2869 if (comp_dir
!= NULL
)
2871 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2872 directory, get rid of it. */
2873 char *cp
= strchr (comp_dir
, ':');
2875 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2882 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2885 set_cu_language (DW_UNSND (attr
), cu
);
2888 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
2890 cu
->producer
= DW_STRING (attr
);
2892 /* We assume that we're processing GCC output. */
2893 processing_gcc_compilation
= 2;
2895 processing_has_namespace_info
= 0;
2897 start_symtab (name
, comp_dir
, lowpc
);
2898 record_debugformat ("DWARF 2");
2899 record_producer (cu
->producer
);
2901 initialize_cu_func_list (cu
);
2903 /* Decode line number information if present. We do this before
2904 processing child DIEs, so that the line header table is available
2905 for DW_AT_decl_file. */
2906 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2909 unsigned int line_offset
= DW_UNSND (attr
);
2910 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2913 cu
->line_header
= line_header
;
2914 make_cleanup (free_cu_line_header
, cu
);
2915 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
2919 /* Process all dies in compilation unit. */
2920 if (die
->child
!= NULL
)
2922 child_die
= die
->child
;
2923 while (child_die
&& child_die
->tag
)
2925 process_die (child_die
, cu
);
2926 child_die
= sibling_die (child_die
);
2930 /* Decode macro information, if present. Dwarf 2 macro information
2931 refers to information in the line number info statement program
2932 header, so we can only read it if we've read the header
2934 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2935 if (attr
&& line_header
)
2937 unsigned int macro_offset
= DW_UNSND (attr
);
2938 dwarf_decode_macros (line_header
, macro_offset
,
2939 comp_dir
, abfd
, cu
);
2941 do_cleanups (back_to
);
2945 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2946 struct dwarf2_cu
*cu
)
2948 struct function_range
*thisfn
;
2950 thisfn
= (struct function_range
*)
2951 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
2952 thisfn
->name
= name
;
2953 thisfn
->lowpc
= lowpc
;
2954 thisfn
->highpc
= highpc
;
2955 thisfn
->seen_line
= 0;
2956 thisfn
->next
= NULL
;
2958 if (cu
->last_fn
== NULL
)
2959 cu
->first_fn
= thisfn
;
2961 cu
->last_fn
->next
= thisfn
;
2963 cu
->last_fn
= thisfn
;
2967 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2969 struct objfile
*objfile
= cu
->objfile
;
2970 struct context_stack
*new;
2973 struct die_info
*child_die
;
2974 struct attribute
*attr
;
2977 struct block
*block
;
2979 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2981 name
= dwarf2_linkage_name (die
, cu
);
2983 /* Ignore functions with missing or empty names and functions with
2984 missing or invalid low and high pc attributes. */
2985 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2991 /* Record the function range for dwarf_decode_lines. */
2992 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
2994 new = push_context (0, lowpc
);
2995 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
2997 /* If there is a location expression for DW_AT_frame_base, record
2999 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3001 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3002 expression is being recorded directly in the function's symbol
3003 and not in a separate frame-base object. I guess this hack is
3004 to avoid adding some sort of frame-base adjunct/annex to the
3005 function's symbol :-(. The problem with doing this is that it
3006 results in a function symbol with a location expression that
3007 has nothing to do with the location of the function, ouch! The
3008 relationship should be: a function's symbol has-a frame base; a
3009 frame-base has-a location expression. */
3010 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3012 cu
->list_in_scope
= &local_symbols
;
3014 if (die
->child
!= NULL
)
3016 child_die
= die
->child
;
3017 while (child_die
&& child_die
->tag
)
3019 process_die (child_die
, cu
);
3020 child_die
= sibling_die (child_die
);
3024 new = pop_context ();
3025 /* Make a block for the local symbols within. */
3026 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3027 lowpc
, highpc
, objfile
);
3029 /* For C++, set the block's scope. */
3030 if (cu
->language
== language_cplus
)
3031 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
3032 determine_prefix (die
, cu
),
3033 processing_has_namespace_info
);
3035 /* If we have address ranges, record them. */
3036 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3038 /* In C++, we can have functions nested inside functions (e.g., when
3039 a function declares a class that has methods). This means that
3040 when we finish processing a function scope, we may need to go
3041 back to building a containing block's symbol lists. */
3042 local_symbols
= new->locals
;
3043 param_symbols
= new->params
;
3045 /* If we've finished processing a top-level function, subsequent
3046 symbols go in the file symbol list. */
3047 if (outermost_context_p ())
3048 cu
->list_in_scope
= &file_symbols
;
3051 /* Process all the DIES contained within a lexical block scope. Start
3052 a new scope, process the dies, and then close the scope. */
3055 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3057 struct objfile
*objfile
= cu
->objfile
;
3058 struct context_stack
*new;
3059 CORE_ADDR lowpc
, highpc
;
3060 struct die_info
*child_die
;
3063 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3065 /* Ignore blocks with missing or invalid low and high pc attributes. */
3066 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3067 as multiple lexical blocks? Handling children in a sane way would
3068 be nasty. Might be easier to properly extend generic blocks to
3070 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3075 push_context (0, lowpc
);
3076 if (die
->child
!= NULL
)
3078 child_die
= die
->child
;
3079 while (child_die
&& child_die
->tag
)
3081 process_die (child_die
, cu
);
3082 child_die
= sibling_die (child_die
);
3085 new = pop_context ();
3087 if (local_symbols
!= NULL
)
3090 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3093 /* Note that recording ranges after traversing children, as we
3094 do here, means that recording a parent's ranges entails
3095 walking across all its children's ranges as they appear in
3096 the address map, which is quadratic behavior.
3098 It would be nicer to record the parent's ranges before
3099 traversing its children, simply overriding whatever you find
3100 there. But since we don't even decide whether to create a
3101 block until after we've traversed its children, that's hard
3103 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3105 local_symbols
= new->locals
;
3108 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3109 Return 1 if the attributes are present and valid, otherwise, return 0.
3110 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3113 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
3114 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
3115 struct partial_symtab
*ranges_pst
)
3117 struct objfile
*objfile
= cu
->objfile
;
3118 struct comp_unit_head
*cu_header
= &cu
->header
;
3119 bfd
*obfd
= objfile
->obfd
;
3120 unsigned int addr_size
= cu_header
->addr_size
;
3121 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3122 /* Base address selection entry. */
3133 found_base
= cu_header
->base_known
;
3134 base
= cu_header
->base_address
;
3136 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3138 complaint (&symfile_complaints
,
3139 _("Offset %d out of bounds for DW_AT_ranges attribute"),
3143 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3145 /* Read in the largest possible address. */
3146 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
3147 if ((marker
& mask
) == mask
)
3149 /* If we found the largest possible address, then
3150 read the base address. */
3151 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3152 buffer
+= 2 * addr_size
;
3153 offset
+= 2 * addr_size
;
3159 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3163 CORE_ADDR range_beginning
, range_end
;
3165 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
3166 buffer
+= addr_size
;
3167 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
3168 buffer
+= addr_size
;
3169 offset
+= 2 * addr_size
;
3171 /* An end of list marker is a pair of zero addresses. */
3172 if (range_beginning
== 0 && range_end
== 0)
3173 /* Found the end of list entry. */
3176 /* Each base address selection entry is a pair of 2 values.
3177 The first is the largest possible address, the second is
3178 the base address. Check for a base address here. */
3179 if ((range_beginning
& mask
) == mask
)
3181 /* If we found the largest possible address, then
3182 read the base address. */
3183 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3190 /* We have no valid base address for the ranges
3192 complaint (&symfile_complaints
,
3193 _("Invalid .debug_ranges data (no base address)"));
3197 range_beginning
+= base
;
3200 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
3201 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3202 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
3205 /* FIXME: This is recording everything as a low-high
3206 segment of consecutive addresses. We should have a
3207 data structure for discontiguous block ranges
3211 low
= range_beginning
;
3217 if (range_beginning
< low
)
3218 low
= range_beginning
;
3219 if (range_end
> high
)
3225 /* If the first entry is an end-of-list marker, the range
3226 describes an empty scope, i.e. no instructions. */
3232 *high_return
= high
;
3236 /* Get low and high pc attributes from a die. Return 1 if the attributes
3237 are present and valid, otherwise, return 0. Return -1 if the range is
3238 discontinuous, i.e. derived from DW_AT_ranges information. */
3240 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
3241 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
3243 struct attribute
*attr
;
3248 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3251 high
= DW_ADDR (attr
);
3252 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3254 low
= DW_ADDR (attr
);
3256 /* Found high w/o low attribute. */
3259 /* Found consecutive range of addresses. */
3264 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3267 /* Value of the DW_AT_ranges attribute is the offset in the
3268 .debug_ranges section. */
3269 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, NULL
))
3271 /* Found discontinuous range of addresses. */
3279 /* When using the GNU linker, .gnu.linkonce. sections are used to
3280 eliminate duplicate copies of functions and vtables and such.
3281 The linker will arbitrarily choose one and discard the others.
3282 The AT_*_pc values for such functions refer to local labels in
3283 these sections. If the section from that file was discarded, the
3284 labels are not in the output, so the relocs get a value of 0.
3285 If this is a discarded function, mark the pc bounds as invalid,
3286 so that GDB will ignore it. */
3287 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3295 /* Get the low and high pc's represented by the scope DIE, and store
3296 them in *LOWPC and *HIGHPC. If the correct values can't be
3297 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3300 get_scope_pc_bounds (struct die_info
*die
,
3301 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3302 struct dwarf2_cu
*cu
)
3304 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3305 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3306 CORE_ADDR current_low
, current_high
;
3308 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3310 best_low
= current_low
;
3311 best_high
= current_high
;
3315 struct die_info
*child
= die
->child
;
3317 while (child
&& child
->tag
)
3319 switch (child
->tag
) {
3320 case DW_TAG_subprogram
:
3321 if (dwarf2_get_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
))
3323 best_low
= min (best_low
, current_low
);
3324 best_high
= max (best_high
, current_high
);
3327 case DW_TAG_namespace
:
3328 /* FIXME: carlton/2004-01-16: Should we do this for
3329 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3330 that current GCC's always emit the DIEs corresponding
3331 to definitions of methods of classes as children of a
3332 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3333 the DIEs giving the declarations, which could be
3334 anywhere). But I don't see any reason why the
3335 standards says that they have to be there. */
3336 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3338 if (current_low
!= ((CORE_ADDR
) -1))
3340 best_low
= min (best_low
, current_low
);
3341 best_high
= max (best_high
, current_high
);
3349 child
= sibling_die (child
);
3354 *highpc
= best_high
;
3357 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
3360 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
3361 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
3363 struct attribute
*attr
;
3365 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3368 CORE_ADDR high
= DW_ADDR (attr
);
3369 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3372 CORE_ADDR low
= DW_ADDR (attr
);
3373 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
3377 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3380 bfd
*obfd
= cu
->objfile
->obfd
;
3382 /* The value of the DW_AT_ranges attribute is the offset of the
3383 address range list in the .debug_ranges section. */
3384 unsigned long offset
= DW_UNSND (attr
);
3385 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3387 /* For some target architectures, but not others, the
3388 read_address function sign-extends the addresses it returns.
3389 To recognize base address selection entries, we need a
3391 unsigned int addr_size
= cu
->header
.addr_size
;
3392 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3394 /* The base address, to which the next pair is relative. Note
3395 that this 'base' is a DWARF concept: most entries in a range
3396 list are relative, to reduce the number of relocs against the
3397 debugging information. This is separate from this function's
3398 'baseaddr' argument, which GDB uses to relocate debugging
3399 information from a shared library based on the address at
3400 which the library was loaded. */
3401 CORE_ADDR base
= cu
->header
.base_address
;
3402 int base_known
= cu
->header
.base_known
;
3404 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3406 complaint (&symfile_complaints
,
3407 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
3414 unsigned int bytes_read
;
3415 CORE_ADDR start
, end
;
3417 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3418 buffer
+= bytes_read
;
3419 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3420 buffer
+= bytes_read
;
3422 /* Did we find the end of the range list? */
3423 if (start
== 0 && end
== 0)
3426 /* Did we find a base address selection entry? */
3427 else if ((start
& base_select_mask
) == base_select_mask
)
3433 /* We found an ordinary address range. */
3438 complaint (&symfile_complaints
,
3439 _("Invalid .debug_ranges data (no base address)"));
3443 record_block_range (block
,
3444 baseaddr
+ base
+ start
,
3445 baseaddr
+ base
+ end
- 1);
3451 /* Add an aggregate field to the field list. */
3454 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3455 struct dwarf2_cu
*cu
)
3457 struct objfile
*objfile
= cu
->objfile
;
3458 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3459 struct nextfield
*new_field
;
3460 struct attribute
*attr
;
3462 char *fieldname
= "";
3464 /* Allocate a new field list entry and link it in. */
3465 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3466 make_cleanup (xfree
, new_field
);
3467 memset (new_field
, 0, sizeof (struct nextfield
));
3468 new_field
->next
= fip
->fields
;
3469 fip
->fields
= new_field
;
3472 /* Handle accessibility and virtuality of field.
3473 The default accessibility for members is public, the default
3474 accessibility for inheritance is private. */
3475 if (die
->tag
!= DW_TAG_inheritance
)
3476 new_field
->accessibility
= DW_ACCESS_public
;
3478 new_field
->accessibility
= DW_ACCESS_private
;
3479 new_field
->virtuality
= DW_VIRTUALITY_none
;
3481 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3483 new_field
->accessibility
= DW_UNSND (attr
);
3484 if (new_field
->accessibility
!= DW_ACCESS_public
)
3485 fip
->non_public_fields
= 1;
3486 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3488 new_field
->virtuality
= DW_UNSND (attr
);
3490 fp
= &new_field
->field
;
3492 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3494 /* Data member other than a C++ static data member. */
3496 /* Get type of field. */
3497 fp
->type
= die_type (die
, cu
);
3499 FIELD_STATIC_KIND (*fp
) = 0;
3501 /* Get bit size of field (zero if none). */
3502 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3505 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3509 FIELD_BITSIZE (*fp
) = 0;
3512 /* Get bit offset of field. */
3513 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3518 if (attr_form_is_section_offset (attr
))
3520 dwarf2_complex_location_expr_complaint ();
3523 else if (attr_form_is_constant (attr
))
3524 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
3526 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
3528 FIELD_BITPOS (*fp
) = byte_offset
* bits_per_byte
;
3531 FIELD_BITPOS (*fp
) = 0;
3532 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3535 if (gdbarch_bits_big_endian (gdbarch
))
3537 /* For big endian bits, the DW_AT_bit_offset gives the
3538 additional bit offset from the MSB of the containing
3539 anonymous object to the MSB of the field. We don't
3540 have to do anything special since we don't need to
3541 know the size of the anonymous object. */
3542 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3546 /* For little endian bits, compute the bit offset to the
3547 MSB of the anonymous object, subtract off the number of
3548 bits from the MSB of the field to the MSB of the
3549 object, and then subtract off the number of bits of
3550 the field itself. The result is the bit offset of
3551 the LSB of the field. */
3553 int bit_offset
= DW_UNSND (attr
);
3555 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3558 /* The size of the anonymous object containing
3559 the bit field is explicit, so use the
3560 indicated size (in bytes). */
3561 anonymous_size
= DW_UNSND (attr
);
3565 /* The size of the anonymous object containing
3566 the bit field must be inferred from the type
3567 attribute of the data member containing the
3569 anonymous_size
= TYPE_LENGTH (fp
->type
);
3571 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
3572 - bit_offset
- FIELD_BITSIZE (*fp
);
3576 /* Get name of field. */
3577 fieldname
= dwarf2_name (die
, cu
);
3578 if (fieldname
== NULL
)
3581 /* The name is already allocated along with this objfile, so we don't
3582 need to duplicate it for the type. */
3583 fp
->name
= fieldname
;
3585 /* Change accessibility for artificial fields (e.g. virtual table
3586 pointer or virtual base class pointer) to private. */
3587 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
3589 new_field
->accessibility
= DW_ACCESS_private
;
3590 fip
->non_public_fields
= 1;
3593 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
3595 /* C++ static member. */
3597 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3598 is a declaration, but all versions of G++ as of this writing
3599 (so through at least 3.2.1) incorrectly generate
3600 DW_TAG_variable tags. */
3604 /* Get name of field. */
3605 fieldname
= dwarf2_name (die
, cu
);
3606 if (fieldname
== NULL
)
3609 /* Get physical name. */
3610 physname
= dwarf2_linkage_name (die
, cu
);
3612 /* The name is already allocated along with this objfile, so we don't
3613 need to duplicate it for the type. */
3614 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
3615 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3616 FIELD_NAME (*fp
) = fieldname
;
3618 else if (die
->tag
== DW_TAG_inheritance
)
3620 /* C++ base class field. */
3621 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3623 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
3625 FIELD_BITSIZE (*fp
) = 0;
3626 FIELD_STATIC_KIND (*fp
) = 0;
3627 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3628 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
3629 fip
->nbaseclasses
++;
3633 /* Create the vector of fields, and attach it to the type. */
3636 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3637 struct dwarf2_cu
*cu
)
3639 int nfields
= fip
->nfields
;
3641 /* Record the field count, allocate space for the array of fields,
3642 and create blank accessibility bitfields if necessary. */
3643 TYPE_NFIELDS (type
) = nfields
;
3644 TYPE_FIELDS (type
) = (struct field
*)
3645 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3646 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3648 if (fip
->non_public_fields
)
3650 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3652 TYPE_FIELD_PRIVATE_BITS (type
) =
3653 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3654 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3656 TYPE_FIELD_PROTECTED_BITS (type
) =
3657 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3658 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3660 TYPE_FIELD_IGNORE_BITS (type
) =
3661 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3662 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3665 /* If the type has baseclasses, allocate and clear a bit vector for
3666 TYPE_FIELD_VIRTUAL_BITS. */
3667 if (fip
->nbaseclasses
)
3669 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3670 unsigned char *pointer
;
3672 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3673 pointer
= TYPE_ALLOC (type
, num_bytes
);
3674 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
3675 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3676 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3679 /* Copy the saved-up fields into the field vector. Start from the head
3680 of the list, adding to the tail of the field array, so that they end
3681 up in the same order in the array in which they were added to the list. */
3682 while (nfields
-- > 0)
3684 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3685 switch (fip
->fields
->accessibility
)
3687 case DW_ACCESS_private
:
3688 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3691 case DW_ACCESS_protected
:
3692 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3695 case DW_ACCESS_public
:
3699 /* Unknown accessibility. Complain and treat it as public. */
3701 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
3702 fip
->fields
->accessibility
);
3706 if (nfields
< fip
->nbaseclasses
)
3708 switch (fip
->fields
->virtuality
)
3710 case DW_VIRTUALITY_virtual
:
3711 case DW_VIRTUALITY_pure_virtual
:
3712 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3716 fip
->fields
= fip
->fields
->next
;
3720 /* Add a member function to the proper fieldlist. */
3723 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3724 struct type
*type
, struct dwarf2_cu
*cu
)
3726 struct objfile
*objfile
= cu
->objfile
;
3727 struct attribute
*attr
;
3728 struct fnfieldlist
*flp
;
3730 struct fn_field
*fnp
;
3733 struct nextfnfield
*new_fnfield
;
3734 struct type
*this_type
;
3736 /* Get name of member function. */
3737 fieldname
= dwarf2_name (die
, cu
);
3738 if (fieldname
== NULL
)
3741 /* Get the mangled name. */
3742 physname
= dwarf2_linkage_name (die
, cu
);
3744 /* Look up member function name in fieldlist. */
3745 for (i
= 0; i
< fip
->nfnfields
; i
++)
3747 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3751 /* Create new list element if necessary. */
3752 if (i
< fip
->nfnfields
)
3753 flp
= &fip
->fnfieldlists
[i
];
3756 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3758 fip
->fnfieldlists
= (struct fnfieldlist
*)
3759 xrealloc (fip
->fnfieldlists
,
3760 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3761 * sizeof (struct fnfieldlist
));
3762 if (fip
->nfnfields
== 0)
3763 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3765 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3766 flp
->name
= fieldname
;
3772 /* Create a new member function field and chain it to the field list
3774 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3775 make_cleanup (xfree
, new_fnfield
);
3776 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3777 new_fnfield
->next
= flp
->head
;
3778 flp
->head
= new_fnfield
;
3781 /* Fill in the member function field info. */
3782 fnp
= &new_fnfield
->fnfield
;
3783 /* The name is already allocated along with this objfile, so we don't
3784 need to duplicate it for the type. */
3785 fnp
->physname
= physname
? physname
: "";
3786 fnp
->type
= alloc_type (objfile
);
3787 this_type
= read_type_die (die
, cu
);
3788 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
3790 int nparams
= TYPE_NFIELDS (this_type
);
3792 /* TYPE is the domain of this method, and THIS_TYPE is the type
3793 of the method itself (TYPE_CODE_METHOD). */
3794 smash_to_method_type (fnp
->type
, type
,
3795 TYPE_TARGET_TYPE (this_type
),
3796 TYPE_FIELDS (this_type
),
3797 TYPE_NFIELDS (this_type
),
3798 TYPE_VARARGS (this_type
));
3800 /* Handle static member functions.
3801 Dwarf2 has no clean way to discern C++ static and non-static
3802 member functions. G++ helps GDB by marking the first
3803 parameter for non-static member functions (which is the
3804 this pointer) as artificial. We obtain this information
3805 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3806 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
3807 fnp
->voffset
= VOFFSET_STATIC
;
3810 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
3813 /* Get fcontext from DW_AT_containing_type if present. */
3814 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3815 fnp
->fcontext
= die_containing_type (die
, cu
);
3817 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3818 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3820 /* Get accessibility. */
3821 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3824 switch (DW_UNSND (attr
))
3826 case DW_ACCESS_private
:
3827 fnp
->is_private
= 1;
3829 case DW_ACCESS_protected
:
3830 fnp
->is_protected
= 1;
3835 /* Check for artificial methods. */
3836 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3837 if (attr
&& DW_UNSND (attr
) != 0)
3838 fnp
->is_artificial
= 1;
3840 /* Get index in virtual function table if it is a virtual member function. */
3841 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3844 /* Support the .debug_loc offsets */
3845 if (attr_form_is_block (attr
))
3847 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3849 else if (attr_form_is_section_offset (attr
))
3851 dwarf2_complex_location_expr_complaint ();
3855 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3861 /* Create the vector of member function fields, and attach it to the type. */
3864 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3865 struct dwarf2_cu
*cu
)
3867 struct fnfieldlist
*flp
;
3868 int total_length
= 0;
3871 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3872 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3873 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3875 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3877 struct nextfnfield
*nfp
= flp
->head
;
3878 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3881 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3882 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3883 fn_flp
->fn_fields
= (struct fn_field
*)
3884 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3885 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3886 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3888 total_length
+= flp
->length
;
3891 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3892 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3895 /* Returns non-zero if NAME is the name of a vtable member in CU's
3896 language, zero otherwise. */
3898 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
3900 static const char vptr
[] = "_vptr";
3901 static const char vtable
[] = "vtable";
3903 /* Look for the C++ and Java forms of the vtable. */
3904 if ((cu
->language
== language_java
3905 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
3906 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
3907 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
3913 /* GCC outputs unnamed structures that are really pointers to member
3914 functions, with the ABI-specified layout. If DIE (from CU) describes
3915 such a structure, set its type, and return nonzero. Otherwise return
3918 GCC shouldn't do this; it should just output pointer to member DIEs.
3919 This is GCC PR debug/28767. */
3921 static struct type
*
3922 quirk_gcc_member_function_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
)
3924 struct objfile
*objfile
= cu
->objfile
;
3926 struct die_info
*pfn_die
, *delta_die
;
3927 struct attribute
*pfn_name
, *delta_name
;
3928 struct type
*pfn_type
, *domain_type
;
3930 /* Check for a structure with no name and two children. */
3931 if (die
->tag
!= DW_TAG_structure_type
3932 || dwarf2_attr (die
, DW_AT_name
, cu
) != NULL
3933 || die
->child
== NULL
3934 || die
->child
->sibling
== NULL
3935 || (die
->child
->sibling
->sibling
!= NULL
3936 && die
->child
->sibling
->sibling
->tag
!= DW_TAG_padding
))
3939 /* Check for __pfn and __delta members. */
3940 pfn_die
= die
->child
;
3941 pfn_name
= dwarf2_attr (pfn_die
, DW_AT_name
, cu
);
3942 if (pfn_die
->tag
!= DW_TAG_member
3944 || DW_STRING (pfn_name
) == NULL
3945 || strcmp ("__pfn", DW_STRING (pfn_name
)) != 0)
3948 delta_die
= pfn_die
->sibling
;
3949 delta_name
= dwarf2_attr (delta_die
, DW_AT_name
, cu
);
3950 if (delta_die
->tag
!= DW_TAG_member
3951 || delta_name
== NULL
3952 || DW_STRING (delta_name
) == NULL
3953 || strcmp ("__delta", DW_STRING (delta_name
)) != 0)
3956 /* Find the type of the method. */
3957 pfn_type
= die_type (pfn_die
, cu
);
3958 if (pfn_type
== NULL
3959 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
3960 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
3963 /* Look for the "this" argument. */
3964 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
3965 if (TYPE_NFIELDS (pfn_type
) == 0
3966 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
3969 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
3970 type
= alloc_type (objfile
);
3971 smash_to_method_type (type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
3972 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
3973 TYPE_VARARGS (pfn_type
));
3974 type
= lookup_methodptr_type (type
);
3975 return set_die_type (die
, type
, cu
);
3978 /* Called when we find the DIE that starts a structure or union scope
3979 (definition) to process all dies that define the members of the
3982 NOTE: we need to call struct_type regardless of whether or not the
3983 DIE has an at_name attribute, since it might be an anonymous
3984 structure or union. This gets the type entered into our set of
3987 However, if the structure is incomplete (an opaque struct/union)
3988 then suppress creating a symbol table entry for it since gdb only
3989 wants to find the one with the complete definition. Note that if
3990 it is complete, we just call new_symbol, which does it's own
3991 checking about whether the struct/union is anonymous or not (and
3992 suppresses creating a symbol table entry itself). */
3994 static struct type
*
3995 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3997 struct objfile
*objfile
= cu
->objfile
;
3999 struct attribute
*attr
;
4001 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4003 type
= quirk_gcc_member_function_pointer (die
, cu
);
4007 type
= alloc_type (objfile
);
4008 INIT_CPLUS_SPECIFIC (type
);
4009 name
= dwarf2_name (die
, cu
);
4012 if (cu
->language
== language_cplus
4013 || cu
->language
== language_java
)
4015 const char *new_prefix
= determine_class_name (die
, cu
);
4016 TYPE_TAG_NAME (type
) = (char *) new_prefix
;
4020 /* The name is already allocated along with this objfile, so
4021 we don't need to duplicate it for the type. */
4022 TYPE_TAG_NAME (type
) = name
;
4026 if (die
->tag
== DW_TAG_structure_type
)
4028 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
4030 else if (die
->tag
== DW_TAG_union_type
)
4032 TYPE_CODE (type
) = TYPE_CODE_UNION
;
4036 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
4038 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
4041 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4044 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4048 TYPE_LENGTH (type
) = 0;
4051 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB_SUPPORTED
;
4052 if (die_is_declaration (die
, cu
))
4053 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
4055 /* We need to add the type field to the die immediately so we don't
4056 infinitely recurse when dealing with pointers to the structure
4057 type within the structure itself. */
4058 set_die_type (die
, type
, cu
);
4060 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
4062 struct field_info fi
;
4063 struct die_info
*child_die
;
4065 memset (&fi
, 0, sizeof (struct field_info
));
4067 child_die
= die
->child
;
4069 while (child_die
&& child_die
->tag
)
4071 if (child_die
->tag
== DW_TAG_member
4072 || child_die
->tag
== DW_TAG_variable
)
4074 /* NOTE: carlton/2002-11-05: A C++ static data member
4075 should be a DW_TAG_member that is a declaration, but
4076 all versions of G++ as of this writing (so through at
4077 least 3.2.1) incorrectly generate DW_TAG_variable
4078 tags for them instead. */
4079 dwarf2_add_field (&fi
, child_die
, cu
);
4081 else if (child_die
->tag
== DW_TAG_subprogram
)
4083 /* C++ member function. */
4084 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
4086 else if (child_die
->tag
== DW_TAG_inheritance
)
4088 /* C++ base class field. */
4089 dwarf2_add_field (&fi
, child_die
, cu
);
4091 child_die
= sibling_die (child_die
);
4094 /* Attach fields and member functions to the type. */
4096 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
4099 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
4101 /* Get the type which refers to the base class (possibly this
4102 class itself) which contains the vtable pointer for the current
4103 class from the DW_AT_containing_type attribute. */
4105 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4107 struct type
*t
= die_containing_type (die
, cu
);
4109 TYPE_VPTR_BASETYPE (type
) = t
;
4114 /* Our own class provides vtbl ptr. */
4115 for (i
= TYPE_NFIELDS (t
) - 1;
4116 i
>= TYPE_N_BASECLASSES (t
);
4119 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
4121 if (is_vtable_name (fieldname
, cu
))
4123 TYPE_VPTR_FIELDNO (type
) = i
;
4128 /* Complain if virtual function table field not found. */
4129 if (i
< TYPE_N_BASECLASSES (t
))
4130 complaint (&symfile_complaints
,
4131 _("virtual function table pointer not found when defining class '%s'"),
4132 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
4137 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
4140 else if (cu
->producer
4141 && strncmp (cu
->producer
,
4142 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
4144 /* The IBM XLC compiler does not provide direct indication
4145 of the containing type, but the vtable pointer is
4146 always named __vfp. */
4150 for (i
= TYPE_NFIELDS (type
) - 1;
4151 i
>= TYPE_N_BASECLASSES (type
);
4154 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
4156 TYPE_VPTR_FIELDNO (type
) = i
;
4157 TYPE_VPTR_BASETYPE (type
) = type
;
4165 do_cleanups (back_to
);
4170 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4172 struct objfile
*objfile
= cu
->objfile
;
4173 struct die_info
*child_die
= die
->child
;
4174 struct type
*this_type
;
4176 this_type
= get_die_type (die
, cu
);
4177 if (this_type
== NULL
)
4178 this_type
= read_structure_type (die
, cu
);
4180 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
4181 snapshots) has been known to create a die giving a declaration
4182 for a class that has, as a child, a die giving a definition for a
4183 nested class. So we have to process our children even if the
4184 current die is a declaration. Normally, of course, a declaration
4185 won't have any children at all. */
4187 while (child_die
!= NULL
&& child_die
->tag
)
4189 if (child_die
->tag
== DW_TAG_member
4190 || child_die
->tag
== DW_TAG_variable
4191 || child_die
->tag
== DW_TAG_inheritance
)
4196 process_die (child_die
, cu
);
4198 child_die
= sibling_die (child_die
);
4201 /* Do not consider external references. According to the DWARF standard,
4202 these DIEs are identified by the fact that they have no byte_size
4203 attribute, and a declaration attribute. */
4204 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
4205 || !die_is_declaration (die
, cu
))
4206 new_symbol (die
, this_type
, cu
);
4209 /* Given a DW_AT_enumeration_type die, set its type. We do not
4210 complete the type's fields yet, or create any symbols. */
4212 static struct type
*
4213 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4215 struct objfile
*objfile
= cu
->objfile
;
4217 struct attribute
*attr
;
4220 type
= alloc_type (objfile
);
4222 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4223 name
= dwarf2_full_name (die
, cu
);
4225 TYPE_TAG_NAME (type
) = (char *) name
;
4227 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4230 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4234 TYPE_LENGTH (type
) = 0;
4237 /* The enumeration DIE can be incomplete. In Ada, any type can be
4238 declared as private in the package spec, and then defined only
4239 inside the package body. Such types are known as Taft Amendment
4240 Types. When another package uses such a type, an incomplete DIE
4241 may be generated by the compiler. */
4242 if (die_is_declaration (die
, cu
))
4243 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
4245 return set_die_type (die
, type
, cu
);
4248 /* Determine the name of the type represented by DIE, which should be
4249 a named C++ or Java compound type. Return the name in question,
4250 allocated on the objfile obstack. */
4253 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
4255 const char *new_prefix
= NULL
;
4257 /* If we don't have namespace debug info, guess the name by trying
4258 to demangle the names of members, just like we did in
4259 guess_structure_name. */
4260 if (!processing_has_namespace_info
)
4262 struct die_info
*child
;
4264 for (child
= die
->child
;
4265 child
!= NULL
&& child
->tag
!= 0;
4266 child
= sibling_die (child
))
4268 if (child
->tag
== DW_TAG_subprogram
)
4271 = language_class_name_from_physname (cu
->language_defn
,
4275 if (phys_prefix
!= NULL
)
4278 = obsavestring (phys_prefix
, strlen (phys_prefix
),
4279 &cu
->objfile
->objfile_obstack
);
4280 xfree (phys_prefix
);
4287 if (new_prefix
== NULL
)
4288 new_prefix
= dwarf2_full_name (die
, cu
);
4293 /* Given a pointer to a die which begins an enumeration, process all
4294 the dies that define the members of the enumeration, and create the
4295 symbol for the enumeration type.
4297 NOTE: We reverse the order of the element list. */
4300 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4302 struct objfile
*objfile
= cu
->objfile
;
4303 struct die_info
*child_die
;
4304 struct field
*fields
;
4307 int unsigned_enum
= 1;
4309 struct type
*this_type
;
4313 this_type
= get_die_type (die
, cu
);
4314 if (this_type
== NULL
)
4315 this_type
= read_enumeration_type (die
, cu
);
4316 if (die
->child
!= NULL
)
4318 child_die
= die
->child
;
4319 while (child_die
&& child_die
->tag
)
4321 if (child_die
->tag
!= DW_TAG_enumerator
)
4323 process_die (child_die
, cu
);
4327 name
= dwarf2_name (child_die
, cu
);
4330 sym
= new_symbol (child_die
, this_type
, cu
);
4331 if (SYMBOL_VALUE (sym
) < 0)
4334 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4336 fields
= (struct field
*)
4338 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
4339 * sizeof (struct field
));
4342 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
4343 FIELD_TYPE (fields
[num_fields
]) = NULL
;
4344 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
4345 FIELD_BITSIZE (fields
[num_fields
]) = 0;
4346 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
4352 child_die
= sibling_die (child_die
);
4357 TYPE_NFIELDS (this_type
) = num_fields
;
4358 TYPE_FIELDS (this_type
) = (struct field
*)
4359 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
4360 memcpy (TYPE_FIELDS (this_type
), fields
,
4361 sizeof (struct field
) * num_fields
);
4365 TYPE_FLAGS (this_type
) |= TYPE_FLAG_UNSIGNED
;
4368 new_symbol (die
, this_type
, cu
);
4371 /* Extract all information from a DW_TAG_array_type DIE and put it in
4372 the DIE's type field. For now, this only handles one dimensional
4375 static struct type
*
4376 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4378 struct objfile
*objfile
= cu
->objfile
;
4379 struct die_info
*child_die
;
4380 struct type
*type
= NULL
;
4381 struct type
*element_type
, *range_type
, *index_type
;
4382 struct type
**range_types
= NULL
;
4383 struct attribute
*attr
;
4385 struct cleanup
*back_to
;
4388 element_type
= die_type (die
, cu
);
4390 /* Irix 6.2 native cc creates array types without children for
4391 arrays with unspecified length. */
4392 if (die
->child
== NULL
)
4394 index_type
= builtin_type_int32
;
4395 range_type
= create_range_type (NULL
, index_type
, 0, -1);
4396 type
= create_array_type (NULL
, element_type
, range_type
);
4397 return set_die_type (die
, type
, cu
);
4400 back_to
= make_cleanup (null_cleanup
, NULL
);
4401 child_die
= die
->child
;
4402 while (child_die
&& child_die
->tag
)
4404 if (child_die
->tag
== DW_TAG_subrange_type
)
4406 struct type
*child_type
= read_type_die (child_die
, cu
);
4407 if (child_type
!= NULL
)
4409 /* The range type was succesfully read. Save it for
4410 the array type creation. */
4411 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
4413 range_types
= (struct type
**)
4414 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
4415 * sizeof (struct type
*));
4417 make_cleanup (free_current_contents
, &range_types
);
4419 range_types
[ndim
++] = child_type
;
4422 child_die
= sibling_die (child_die
);
4425 /* Dwarf2 dimensions are output from left to right, create the
4426 necessary array types in backwards order. */
4428 type
= element_type
;
4430 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
4434 type
= create_array_type (NULL
, type
, range_types
[i
++]);
4439 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
4442 /* Understand Dwarf2 support for vector types (like they occur on
4443 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4444 array type. This is not part of the Dwarf2/3 standard yet, but a
4445 custom vendor extension. The main difference between a regular
4446 array and the vector variant is that vectors are passed by value
4448 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4450 make_vector_type (type
);
4452 name
= dwarf2_name (die
, cu
);
4454 TYPE_NAME (type
) = name
;
4456 do_cleanups (back_to
);
4458 /* Install the type in the die. */
4459 return set_die_type (die
, type
, cu
);
4462 static enum dwarf_array_dim_ordering
4463 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4465 struct attribute
*attr
;
4467 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4469 if (attr
) return DW_SND (attr
);
4472 GNU F77 is a special case, as at 08/2004 array type info is the
4473 opposite order to the dwarf2 specification, but data is still
4474 laid out as per normal fortran.
4476 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4480 if (cu
->language
== language_fortran
&&
4481 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4483 return DW_ORD_row_major
;
4486 switch (cu
->language_defn
->la_array_ordering
)
4488 case array_column_major
:
4489 return DW_ORD_col_major
;
4490 case array_row_major
:
4492 return DW_ORD_row_major
;
4496 /* Extract all information from a DW_TAG_set_type DIE and put it in
4497 the DIE's type field. */
4499 static struct type
*
4500 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4502 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
4504 return set_die_type (die
, set_type
, cu
);
4507 /* First cut: install each common block member as a global variable. */
4510 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4512 struct die_info
*child_die
;
4513 struct attribute
*attr
;
4515 CORE_ADDR base
= (CORE_ADDR
) 0;
4517 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4520 /* Support the .debug_loc offsets */
4521 if (attr_form_is_block (attr
))
4523 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4525 else if (attr_form_is_section_offset (attr
))
4527 dwarf2_complex_location_expr_complaint ();
4531 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4532 "common block member");
4535 if (die
->child
!= NULL
)
4537 child_die
= die
->child
;
4538 while (child_die
&& child_die
->tag
)
4540 sym
= new_symbol (child_die
, NULL
, cu
);
4541 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4544 SYMBOL_VALUE_ADDRESS (sym
) =
4545 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4546 add_symbol_to_list (sym
, &global_symbols
);
4548 child_die
= sibling_die (child_die
);
4553 /* Create a type for a C++ namespace. */
4555 static struct type
*
4556 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4558 struct objfile
*objfile
= cu
->objfile
;
4559 const char *previous_prefix
, *name
;
4563 /* For extensions, reuse the type of the original namespace. */
4564 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
4566 struct die_info
*ext_die
;
4567 struct dwarf2_cu
*ext_cu
= cu
;
4568 ext_die
= dwarf2_extension (die
, &ext_cu
);
4569 type
= read_type_die (ext_die
, ext_cu
);
4570 return set_die_type (die
, type
, cu
);
4573 name
= namespace_name (die
, &is_anonymous
, cu
);
4575 /* Now build the name of the current namespace. */
4577 previous_prefix
= determine_prefix (die
, cu
);
4578 if (previous_prefix
[0] != '\0')
4579 name
= typename_concat (&objfile
->objfile_obstack
,
4580 previous_prefix
, name
, cu
);
4582 /* Create the type. */
4583 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
4585 TYPE_NAME (type
) = (char *) name
;
4586 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4588 set_die_type (die
, type
, cu
);
4593 /* Read a C++ namespace. */
4596 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4598 struct objfile
*objfile
= cu
->objfile
;
4602 /* Add a symbol associated to this if we haven't seen the namespace
4603 before. Also, add a using directive if it's an anonymous
4606 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
4610 type
= read_type_die (die
, cu
);
4611 new_symbol (die
, type
, cu
);
4613 name
= namespace_name (die
, &is_anonymous
, cu
);
4616 const char *previous_prefix
= determine_prefix (die
, cu
);
4617 cp_add_using_directive (TYPE_NAME (type
),
4618 strlen (previous_prefix
),
4619 strlen (TYPE_NAME (type
)));
4623 if (die
->child
!= NULL
)
4625 struct die_info
*child_die
= die
->child
;
4627 while (child_die
&& child_die
->tag
)
4629 process_die (child_die
, cu
);
4630 child_die
= sibling_die (child_die
);
4635 /* Return the name of the namespace represented by DIE. Set
4636 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4640 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
4642 struct die_info
*current_die
;
4643 const char *name
= NULL
;
4645 /* Loop through the extensions until we find a name. */
4647 for (current_die
= die
;
4648 current_die
!= NULL
;
4649 current_die
= dwarf2_extension (die
, &cu
))
4651 name
= dwarf2_name (current_die
, cu
);
4656 /* Is it an anonymous namespace? */
4658 *is_anonymous
= (name
== NULL
);
4660 name
= "(anonymous namespace)";
4665 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4666 the user defined type vector. */
4668 static struct type
*
4669 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4671 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
4672 struct comp_unit_head
*cu_header
= &cu
->header
;
4674 struct attribute
*attr_byte_size
;
4675 struct attribute
*attr_address_class
;
4676 int byte_size
, addr_class
;
4678 type
= lookup_pointer_type (die_type (die
, cu
));
4680 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4682 byte_size
= DW_UNSND (attr_byte_size
);
4684 byte_size
= cu_header
->addr_size
;
4686 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
4687 if (attr_address_class
)
4688 addr_class
= DW_UNSND (attr_address_class
);
4690 addr_class
= DW_ADDR_none
;
4692 /* If the pointer size or address class is different than the
4693 default, create a type variant marked as such and set the
4694 length accordingly. */
4695 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
4697 if (gdbarch_address_class_type_flags_p (gdbarch
))
4701 type_flags
= gdbarch_address_class_type_flags
4702 (gdbarch
, byte_size
, addr_class
);
4703 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
4704 type
= make_type_with_address_space (type
, type_flags
);
4706 else if (TYPE_LENGTH (type
) != byte_size
)
4708 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
4711 /* Should we also complain about unhandled address classes? */
4715 TYPE_LENGTH (type
) = byte_size
;
4716 return set_die_type (die
, type
, cu
);
4719 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4720 the user defined type vector. */
4722 static struct type
*
4723 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4725 struct objfile
*objfile
= cu
->objfile
;
4727 struct type
*to_type
;
4728 struct type
*domain
;
4730 to_type
= die_type (die
, cu
);
4731 domain
= die_containing_type (die
, cu
);
4733 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
4734 type
= lookup_methodptr_type (to_type
);
4736 type
= lookup_memberptr_type (to_type
, domain
);
4738 return set_die_type (die
, type
, cu
);
4741 /* Extract all information from a DW_TAG_reference_type DIE and add to
4742 the user defined type vector. */
4744 static struct type
*
4745 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4747 struct comp_unit_head
*cu_header
= &cu
->header
;
4749 struct attribute
*attr
;
4751 type
= lookup_reference_type (die_type (die
, cu
));
4752 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4755 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4759 TYPE_LENGTH (type
) = cu_header
->addr_size
;
4761 return set_die_type (die
, type
, cu
);
4764 static struct type
*
4765 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4767 struct type
*base_type
, *cv_type
;
4769 base_type
= die_type (die
, cu
);
4770 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
4771 return set_die_type (die
, cv_type
, cu
);
4774 static struct type
*
4775 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4777 struct type
*base_type
, *cv_type
;
4779 base_type
= die_type (die
, cu
);
4780 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
4781 return set_die_type (die
, cv_type
, cu
);
4784 /* Extract all information from a DW_TAG_string_type DIE and add to
4785 the user defined type vector. It isn't really a user defined type,
4786 but it behaves like one, with other DIE's using an AT_user_def_type
4787 attribute to reference it. */
4789 static struct type
*
4790 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4792 struct objfile
*objfile
= cu
->objfile
;
4793 struct type
*type
, *range_type
, *index_type
, *char_type
;
4794 struct attribute
*attr
;
4795 unsigned int length
;
4797 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4800 length
= DW_UNSND (attr
);
4804 /* check for the DW_AT_byte_size attribute */
4805 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4808 length
= DW_UNSND (attr
);
4816 index_type
= builtin_type_int32
;
4817 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4818 type
= create_string_type (NULL
, range_type
);
4820 return set_die_type (die
, type
, cu
);
4823 /* Handle DIES due to C code like:
4827 int (*funcp)(int a, long l);
4831 ('funcp' generates a DW_TAG_subroutine_type DIE)
4834 static struct type
*
4835 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4837 struct type
*type
; /* Type that this function returns */
4838 struct type
*ftype
; /* Function that returns above type */
4839 struct attribute
*attr
;
4841 type
= die_type (die
, cu
);
4842 ftype
= make_function_type (type
, (struct type
**) 0);
4844 /* All functions in C++, Pascal and Java have prototypes. */
4845 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4846 if ((attr
&& (DW_UNSND (attr
) != 0))
4847 || cu
->language
== language_cplus
4848 || cu
->language
== language_java
4849 || cu
->language
== language_pascal
)
4850 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
4852 /* Store the calling convention in the type if it's available in
4853 the subroutine die. Otherwise set the calling convention to
4854 the default value DW_CC_normal. */
4855 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
4856 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
4858 if (die
->child
!= NULL
)
4860 struct die_info
*child_die
;
4864 /* Count the number of parameters.
4865 FIXME: GDB currently ignores vararg functions, but knows about
4866 vararg member functions. */
4867 child_die
= die
->child
;
4868 while (child_die
&& child_die
->tag
)
4870 if (child_die
->tag
== DW_TAG_formal_parameter
)
4872 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4873 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
4874 child_die
= sibling_die (child_die
);
4877 /* Allocate storage for parameters and fill them in. */
4878 TYPE_NFIELDS (ftype
) = nparams
;
4879 TYPE_FIELDS (ftype
) = (struct field
*)
4880 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
4882 child_die
= die
->child
;
4883 while (child_die
&& child_die
->tag
)
4885 if (child_die
->tag
== DW_TAG_formal_parameter
)
4887 /* Dwarf2 has no clean way to discern C++ static and non-static
4888 member functions. G++ helps GDB by marking the first
4889 parameter for non-static member functions (which is the
4890 this pointer) as artificial. We pass this information
4891 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4892 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
4894 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
4896 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
4897 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
4900 child_die
= sibling_die (child_die
);
4904 return set_die_type (die
, ftype
, cu
);
4907 static struct type
*
4908 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
4910 struct objfile
*objfile
= cu
->objfile
;
4911 struct attribute
*attr
;
4912 const char *name
= NULL
;
4913 struct type
*this_type
;
4915 name
= dwarf2_full_name (die
, cu
);
4916 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
4917 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
4918 TYPE_NAME (this_type
) = (char *) name
;
4919 set_die_type (die
, this_type
, cu
);
4920 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
4924 /* Find a representation of a given base type and install
4925 it in the TYPE field of the die. */
4927 static struct type
*
4928 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4930 struct objfile
*objfile
= cu
->objfile
;
4932 struct attribute
*attr
;
4933 int encoding
= 0, size
= 0;
4935 enum type_code code
= TYPE_CODE_INT
;
4937 struct type
*target_type
= NULL
;
4939 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
4942 encoding
= DW_UNSND (attr
);
4944 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4947 size
= DW_UNSND (attr
);
4949 name
= dwarf2_name (die
, cu
);
4952 complaint (&symfile_complaints
,
4953 _("DW_AT_name missing from DW_TAG_base_type"));
4958 case DW_ATE_address
:
4959 /* Turn DW_ATE_address into a void * pointer. */
4960 code
= TYPE_CODE_PTR
;
4961 type_flags
|= TYPE_FLAG_UNSIGNED
;
4962 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
4964 case DW_ATE_boolean
:
4965 code
= TYPE_CODE_BOOL
;
4966 type_flags
|= TYPE_FLAG_UNSIGNED
;
4968 case DW_ATE_complex_float
:
4969 code
= TYPE_CODE_COMPLEX
;
4970 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
4972 case DW_ATE_decimal_float
:
4973 code
= TYPE_CODE_DECFLOAT
;
4976 code
= TYPE_CODE_FLT
;
4980 case DW_ATE_unsigned
:
4981 type_flags
|= TYPE_FLAG_UNSIGNED
;
4983 case DW_ATE_signed_char
:
4984 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
4985 code
= TYPE_CODE_CHAR
;
4987 case DW_ATE_unsigned_char
:
4988 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
4989 code
= TYPE_CODE_CHAR
;
4990 type_flags
|= TYPE_FLAG_UNSIGNED
;
4993 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
4994 dwarf_type_encoding_name (encoding
));
4998 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
4999 TYPE_NAME (type
) = name
;
5000 TYPE_TARGET_TYPE (type
) = target_type
;
5002 if (name
&& strcmp (name
, "char") == 0)
5003 TYPE_FLAGS (type
) |= TYPE_FLAG_NOSIGN
;
5005 return set_die_type (die
, type
, cu
);
5008 /* Read the given DW_AT_subrange DIE. */
5010 static struct type
*
5011 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5013 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5014 struct type
*base_type
;
5015 struct type
*range_type
;
5016 struct attribute
*attr
;
5021 base_type
= die_type (die
, cu
);
5022 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
5024 complaint (&symfile_complaints
,
5025 _("DW_AT_type missing from DW_TAG_subrange_type"));
5027 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
5028 0, NULL
, cu
->objfile
);
5031 if (cu
->language
== language_fortran
)
5033 /* FORTRAN implies a lower bound of 1, if not given. */
5037 /* FIXME: For variable sized arrays either of these could be
5038 a variable rather than a constant value. We'll allow it,
5039 but we don't know how to handle it. */
5040 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
5042 low
= dwarf2_get_attr_constant_value (attr
, 0);
5044 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
5047 if (attr
->form
== DW_FORM_block1
)
5049 /* GCC encodes arrays with unspecified or dynamic length
5050 with a DW_FORM_block1 attribute.
5051 FIXME: GDB does not yet know how to handle dynamic
5052 arrays properly, treat them as arrays with unspecified
5055 FIXME: jimb/2003-09-22: GDB does not really know
5056 how to handle arrays of unspecified length
5057 either; we just represent them as zero-length
5058 arrays. Choose an appropriate upper bound given
5059 the lower bound we've computed above. */
5063 high
= dwarf2_get_attr_constant_value (attr
, 1);
5066 range_type
= create_range_type (NULL
, base_type
, low
, high
);
5068 name
= dwarf2_name (die
, cu
);
5070 TYPE_NAME (range_type
) = name
;
5072 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5074 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
5076 return set_die_type (die
, range_type
, cu
);
5079 static struct type
*
5080 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5084 /* For now, we only support the C meaning of an unspecified type: void. */
5086 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
5087 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
5089 return set_die_type (die
, type
, cu
);
5092 /* Trivial hash function for die_info: the hash value of a DIE
5093 is its offset in .debug_info for this objfile. */
5096 die_hash (const void *item
)
5098 const struct die_info
*die
= item
;
5102 /* Trivial comparison function for die_info structures: two DIEs
5103 are equal if they have the same offset. */
5106 die_eq (const void *item_lhs
, const void *item_rhs
)
5108 const struct die_info
*die_lhs
= item_lhs
;
5109 const struct die_info
*die_rhs
= item_rhs
;
5110 return die_lhs
->offset
== die_rhs
->offset
;
5113 /* Read a whole compilation unit into a linked list of dies. */
5115 static struct die_info
*
5116 read_comp_unit (gdb_byte
*info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
5119 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5123 &cu
->comp_unit_obstack
,
5124 hashtab_obstack_allocate
,
5125 dummy_obstack_deallocate
);
5127 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
5130 /* Read a single die and all its descendents. Set the die's sibling
5131 field to NULL; set other fields in the die correctly, and set all
5132 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
5133 location of the info_ptr after reading all of those dies. PARENT
5134 is the parent of the die in question. */
5136 static struct die_info
*
5137 read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
5138 struct dwarf2_cu
*cu
,
5139 gdb_byte
**new_info_ptr
,
5140 struct die_info
*parent
)
5142 struct die_info
*die
;
5146 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
5149 *new_info_ptr
= cur_ptr
;
5152 store_in_ref_table (die
, cu
);
5156 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
5162 *new_info_ptr
= cur_ptr
;
5165 die
->sibling
= NULL
;
5166 die
->parent
= parent
;
5170 /* Read a die, all of its descendents, and all of its siblings; set
5171 all of the fields of all of the dies correctly. Arguments are as
5172 in read_die_and_children. */
5174 static struct die_info
*
5175 read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
5176 struct dwarf2_cu
*cu
,
5177 gdb_byte
**new_info_ptr
,
5178 struct die_info
*parent
)
5180 struct die_info
*first_die
, *last_sibling
;
5184 first_die
= last_sibling
= NULL
;
5188 struct die_info
*die
5189 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
5193 *new_info_ptr
= cur_ptr
;
5200 last_sibling
->sibling
= die
;
5206 /* Decompress a section that was compressed using zlib. Store the
5207 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
5210 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
5211 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
5213 bfd
*abfd
= objfile
->obfd
;
5215 error (_("Support for zlib-compressed DWARF data (from '%s') "
5216 "is disabled in this copy of GDB"),
5217 bfd_get_filename (abfd
));
5219 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
5220 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
5221 bfd_size_type uncompressed_size
;
5222 gdb_byte
*uncompressed_buffer
;
5225 int header_size
= 12;
5227 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5228 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
5229 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5230 bfd_get_filename (abfd
));
5232 /* Read the zlib header. In this case, it should be "ZLIB" followed
5233 by the uncompressed section size, 8 bytes in big-endian order. */
5234 if (compressed_size
< header_size
5235 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
5236 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
5237 bfd_get_filename (abfd
));
5238 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
5239 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
5240 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
5241 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
5242 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
5243 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
5244 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
5245 uncompressed_size
+= compressed_buffer
[11];
5247 /* It is possible the section consists of several compressed
5248 buffers concatenated together, so we uncompress in a loop. */
5252 strm
.avail_in
= compressed_size
- header_size
;
5253 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
5254 strm
.avail_out
= uncompressed_size
;
5255 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
5257 rc
= inflateInit (&strm
);
5258 while (strm
.avail_in
> 0)
5261 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
5262 bfd_get_filename (abfd
), rc
);
5263 strm
.next_out
= ((Bytef
*) uncompressed_buffer
5264 + (uncompressed_size
- strm
.avail_out
));
5265 rc
= inflate (&strm
, Z_FINISH
);
5266 if (rc
!= Z_STREAM_END
)
5267 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
5268 bfd_get_filename (abfd
), rc
);
5269 rc
= inflateReset (&strm
);
5271 rc
= inflateEnd (&strm
);
5273 || strm
.avail_out
!= 0)
5274 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
5275 bfd_get_filename (abfd
), rc
);
5277 xfree (compressed_buffer
);
5278 *outbuf
= uncompressed_buffer
;
5279 *outsize
= uncompressed_size
;
5284 /* Read the contents of the section at OFFSET and of size SIZE from the
5285 object file specified by OBJFILE into the objfile_obstack and return it.
5286 If the section is compressed, uncompress it before returning. */
5289 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
5291 bfd
*abfd
= objfile
->obfd
;
5292 gdb_byte
*buf
, *retbuf
;
5293 bfd_size_type size
= bfd_get_section_size (sectp
);
5294 unsigned char header
[4];
5299 /* Check if the file has a 4-byte header indicating compression. */
5300 if (size
> sizeof (header
)
5301 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
5302 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
5304 /* Upon decompression, update the buffer and its size. */
5305 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
5307 zlib_decompress_section (objfile
, sectp
, &buf
, &size
);
5308 dwarf2_resize_section (sectp
, size
);
5313 /* If we get here, we are a normal, not-compressed section. */
5314 buf
= obstack_alloc (&objfile
->objfile_obstack
, size
);
5315 /* When debugging .o files, we may need to apply relocations; see
5316 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
5317 We never compress sections in .o files, so we only need to
5318 try this when the section is not compressed. */
5319 retbuf
= symfile_relocate_debug_section (abfd
, sectp
, buf
);
5323 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5324 || bfd_bread (buf
, size
, abfd
) != size
)
5325 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5326 bfd_get_filename (abfd
));
5331 /* In DWARF version 2, the description of the debugging information is
5332 stored in a separate .debug_abbrev section. Before we read any
5333 dies from a section we read in all abbreviations and install them
5334 in a hash table. This function also sets flags in CU describing
5335 the data found in the abbrev table. */
5338 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
5340 struct comp_unit_head
*cu_header
= &cu
->header
;
5341 gdb_byte
*abbrev_ptr
;
5342 struct abbrev_info
*cur_abbrev
;
5343 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
5344 unsigned int abbrev_form
, hash_number
;
5345 struct attr_abbrev
*cur_attrs
;
5346 unsigned int allocated_attrs
;
5348 /* Initialize dwarf2 abbrevs */
5349 obstack_init (&cu
->abbrev_obstack
);
5350 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
5352 * sizeof (struct abbrev_info
*)));
5353 memset (cu
->dwarf2_abbrevs
, 0,
5354 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
5356 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
5357 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5358 abbrev_ptr
+= bytes_read
;
5360 allocated_attrs
= ATTR_ALLOC_CHUNK
;
5361 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
5363 /* loop until we reach an abbrev number of 0 */
5364 while (abbrev_number
)
5366 cur_abbrev
= dwarf_alloc_abbrev (cu
);
5368 /* read in abbrev header */
5369 cur_abbrev
->number
= abbrev_number
;
5370 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5371 abbrev_ptr
+= bytes_read
;
5372 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
5375 if (cur_abbrev
->tag
== DW_TAG_namespace
)
5376 cu
->has_namespace_info
= 1;
5378 /* now read in declarations */
5379 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5380 abbrev_ptr
+= bytes_read
;
5381 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5382 abbrev_ptr
+= bytes_read
;
5385 if (cur_abbrev
->num_attrs
== allocated_attrs
)
5387 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
5389 = xrealloc (cur_attrs
, (allocated_attrs
5390 * sizeof (struct attr_abbrev
)));
5393 /* Record whether this compilation unit might have
5394 inter-compilation-unit references. If we don't know what form
5395 this attribute will have, then it might potentially be a
5396 DW_FORM_ref_addr, so we conservatively expect inter-CU
5399 if (abbrev_form
== DW_FORM_ref_addr
5400 || abbrev_form
== DW_FORM_indirect
)
5401 cu
->has_form_ref_addr
= 1;
5403 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
5404 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
5405 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5406 abbrev_ptr
+= bytes_read
;
5407 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5408 abbrev_ptr
+= bytes_read
;
5411 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
5412 (cur_abbrev
->num_attrs
5413 * sizeof (struct attr_abbrev
)));
5414 memcpy (cur_abbrev
->attrs
, cur_attrs
,
5415 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
5417 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
5418 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
5419 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
5421 /* Get next abbreviation.
5422 Under Irix6 the abbreviations for a compilation unit are not
5423 always properly terminated with an abbrev number of 0.
5424 Exit loop if we encounter an abbreviation which we have
5425 already read (which means we are about to read the abbreviations
5426 for the next compile unit) or if the end of the abbreviation
5427 table is reached. */
5428 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
5429 >= dwarf2_per_objfile
->abbrev_size
)
5431 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5432 abbrev_ptr
+= bytes_read
;
5433 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
5440 /* Release the memory used by the abbrev table for a compilation unit. */
5443 dwarf2_free_abbrev_table (void *ptr_to_cu
)
5445 struct dwarf2_cu
*cu
= ptr_to_cu
;
5447 obstack_free (&cu
->abbrev_obstack
, NULL
);
5448 cu
->dwarf2_abbrevs
= NULL
;
5451 /* Lookup an abbrev_info structure in the abbrev hash table. */
5453 static struct abbrev_info
*
5454 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
5456 unsigned int hash_number
;
5457 struct abbrev_info
*abbrev
;
5459 hash_number
= number
% ABBREV_HASH_SIZE
;
5460 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
5464 if (abbrev
->number
== number
)
5467 abbrev
= abbrev
->next
;
5472 /* Returns nonzero if TAG represents a type that we might generate a partial
5476 is_type_tag_for_partial (int tag
)
5481 /* Some types that would be reasonable to generate partial symbols for,
5482 that we don't at present. */
5483 case DW_TAG_array_type
:
5484 case DW_TAG_file_type
:
5485 case DW_TAG_ptr_to_member_type
:
5486 case DW_TAG_set_type
:
5487 case DW_TAG_string_type
:
5488 case DW_TAG_subroutine_type
:
5490 case DW_TAG_base_type
:
5491 case DW_TAG_class_type
:
5492 case DW_TAG_interface_type
:
5493 case DW_TAG_enumeration_type
:
5494 case DW_TAG_structure_type
:
5495 case DW_TAG_subrange_type
:
5496 case DW_TAG_typedef
:
5497 case DW_TAG_union_type
:
5504 /* Load all DIEs that are interesting for partial symbols into memory. */
5506 static struct partial_die_info
*
5507 load_partial_dies (bfd
*abfd
, gdb_byte
*info_ptr
, int building_psymtab
,
5508 struct dwarf2_cu
*cu
)
5510 struct partial_die_info
*part_die
;
5511 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
5512 struct abbrev_info
*abbrev
;
5513 unsigned int bytes_read
;
5514 unsigned int load_all
= 0;
5516 int nesting_level
= 1;
5521 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
5525 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5529 &cu
->comp_unit_obstack
,
5530 hashtab_obstack_allocate
,
5531 dummy_obstack_deallocate
);
5533 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5534 sizeof (struct partial_die_info
));
5538 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5540 /* A NULL abbrev means the end of a series of children. */
5543 if (--nesting_level
== 0)
5545 /* PART_DIE was probably the last thing allocated on the
5546 comp_unit_obstack, so we could call obstack_free
5547 here. We don't do that because the waste is small,
5548 and will be cleaned up when we're done with this
5549 compilation unit. This way, we're also more robust
5550 against other users of the comp_unit_obstack. */
5553 info_ptr
+= bytes_read
;
5554 last_die
= parent_die
;
5555 parent_die
= parent_die
->die_parent
;
5559 /* Check whether this DIE is interesting enough to save. Normally
5560 we would not be interested in members here, but there may be
5561 later variables referencing them via DW_AT_specification (for
5564 && !is_type_tag_for_partial (abbrev
->tag
)
5565 && abbrev
->tag
!= DW_TAG_enumerator
5566 && abbrev
->tag
!= DW_TAG_subprogram
5567 && abbrev
->tag
!= DW_TAG_variable
5568 && abbrev
->tag
!= DW_TAG_namespace
5569 && abbrev
->tag
!= DW_TAG_member
)
5571 /* Otherwise we skip to the next sibling, if any. */
5572 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5576 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5577 abfd
, info_ptr
, cu
);
5579 /* This two-pass algorithm for processing partial symbols has a
5580 high cost in cache pressure. Thus, handle some simple cases
5581 here which cover the majority of C partial symbols. DIEs
5582 which neither have specification tags in them, nor could have
5583 specification tags elsewhere pointing at them, can simply be
5584 processed and discarded.
5586 This segment is also optional; scan_partial_symbols and
5587 add_partial_symbol will handle these DIEs if we chain
5588 them in normally. When compilers which do not emit large
5589 quantities of duplicate debug information are more common,
5590 this code can probably be removed. */
5592 /* Any complete simple types at the top level (pretty much all
5593 of them, for a language without namespaces), can be processed
5595 if (parent_die
== NULL
5596 && part_die
->has_specification
== 0
5597 && part_die
->is_declaration
== 0
5598 && (part_die
->tag
== DW_TAG_typedef
5599 || part_die
->tag
== DW_TAG_base_type
5600 || part_die
->tag
== DW_TAG_subrange_type
))
5602 if (building_psymtab
&& part_die
->name
!= NULL
)
5603 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5604 VAR_DOMAIN
, LOC_TYPEDEF
,
5605 &cu
->objfile
->static_psymbols
,
5606 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5607 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5611 /* If we're at the second level, and we're an enumerator, and
5612 our parent has no specification (meaning possibly lives in a
5613 namespace elsewhere), then we can add the partial symbol now
5614 instead of queueing it. */
5615 if (part_die
->tag
== DW_TAG_enumerator
5616 && parent_die
!= NULL
5617 && parent_die
->die_parent
== NULL
5618 && parent_die
->tag
== DW_TAG_enumeration_type
5619 && parent_die
->has_specification
== 0)
5621 if (part_die
->name
== NULL
)
5622 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5623 else if (building_psymtab
)
5624 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5625 VAR_DOMAIN
, LOC_CONST
,
5626 (cu
->language
== language_cplus
5627 || cu
->language
== language_java
)
5628 ? &cu
->objfile
->global_psymbols
5629 : &cu
->objfile
->static_psymbols
,
5630 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5632 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5636 /* We'll save this DIE so link it in. */
5637 part_die
->die_parent
= parent_die
;
5638 part_die
->die_sibling
= NULL
;
5639 part_die
->die_child
= NULL
;
5641 if (last_die
&& last_die
== parent_die
)
5642 last_die
->die_child
= part_die
;
5644 last_die
->die_sibling
= part_die
;
5646 last_die
= part_die
;
5648 if (first_die
== NULL
)
5649 first_die
= part_die
;
5651 /* Maybe add the DIE to the hash table. Not all DIEs that we
5652 find interesting need to be in the hash table, because we
5653 also have the parent/sibling/child chains; only those that we
5654 might refer to by offset later during partial symbol reading.
5656 For now this means things that might have be the target of a
5657 DW_AT_specification, DW_AT_abstract_origin, or
5658 DW_AT_extension. DW_AT_extension will refer only to
5659 namespaces; DW_AT_abstract_origin refers to functions (and
5660 many things under the function DIE, but we do not recurse
5661 into function DIEs during partial symbol reading) and
5662 possibly variables as well; DW_AT_specification refers to
5663 declarations. Declarations ought to have the DW_AT_declaration
5664 flag. It happens that GCC forgets to put it in sometimes, but
5665 only for functions, not for types.
5667 Adding more things than necessary to the hash table is harmless
5668 except for the performance cost. Adding too few will result in
5669 wasted time in find_partial_die, when we reread the compilation
5670 unit with load_all_dies set. */
5673 || abbrev
->tag
== DW_TAG_subprogram
5674 || abbrev
->tag
== DW_TAG_variable
5675 || abbrev
->tag
== DW_TAG_namespace
5676 || part_die
->is_declaration
)
5680 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
5681 part_die
->offset
, INSERT
);
5685 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5686 sizeof (struct partial_die_info
));
5688 /* For some DIEs we want to follow their children (if any). For C
5689 we have no reason to follow the children of structures; for other
5690 languages we have to, both so that we can get at method physnames
5691 to infer fully qualified class names, and for DW_AT_specification. */
5692 if (last_die
->has_children
5694 || last_die
->tag
== DW_TAG_namespace
5695 || last_die
->tag
== DW_TAG_enumeration_type
5696 || (cu
->language
!= language_c
5697 && (last_die
->tag
== DW_TAG_class_type
5698 || last_die
->tag
== DW_TAG_interface_type
5699 || last_die
->tag
== DW_TAG_structure_type
5700 || last_die
->tag
== DW_TAG_union_type
))))
5703 parent_die
= last_die
;
5707 /* Otherwise we skip to the next sibling, if any. */
5708 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
5710 /* Back to the top, do it again. */
5714 /* Read a minimal amount of information into the minimal die structure. */
5717 read_partial_die (struct partial_die_info
*part_die
,
5718 struct abbrev_info
*abbrev
,
5719 unsigned int abbrev_len
, bfd
*abfd
,
5720 gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
5722 unsigned int bytes_read
, i
;
5723 struct attribute attr
;
5724 int has_low_pc_attr
= 0;
5725 int has_high_pc_attr
= 0;
5726 CORE_ADDR base_address
= 0;
5730 base_address_low_pc
,
5731 /* Overrides BASE_ADDRESS_LOW_PC. */
5732 base_address_entry_pc
5734 base_address_type
= base_address_none
;
5736 memset (part_die
, 0, sizeof (struct partial_die_info
));
5738 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5740 info_ptr
+= abbrev_len
;
5745 part_die
->tag
= abbrev
->tag
;
5746 part_die
->has_children
= abbrev
->has_children
;
5748 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5750 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
5752 /* Store the data if it is of an attribute we want to keep in a
5753 partial symbol table. */
5758 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
5759 if (part_die
->name
== NULL
)
5760 part_die
->name
= DW_STRING (&attr
);
5762 case DW_AT_comp_dir
:
5763 if (part_die
->dirname
== NULL
)
5764 part_die
->dirname
= DW_STRING (&attr
);
5766 case DW_AT_MIPS_linkage_name
:
5767 part_die
->name
= DW_STRING (&attr
);
5770 has_low_pc_attr
= 1;
5771 part_die
->lowpc
= DW_ADDR (&attr
);
5772 if (part_die
->tag
== DW_TAG_compile_unit
5773 && base_address_type
< base_address_low_pc
)
5775 base_address
= DW_ADDR (&attr
);
5776 base_address_type
= base_address_low_pc
;
5780 has_high_pc_attr
= 1;
5781 part_die
->highpc
= DW_ADDR (&attr
);
5783 case DW_AT_entry_pc
:
5784 if (part_die
->tag
== DW_TAG_compile_unit
5785 && base_address_type
< base_address_entry_pc
)
5787 base_address
= DW_ADDR (&attr
);
5788 base_address_type
= base_address_entry_pc
;
5792 if (part_die
->tag
== DW_TAG_compile_unit
)
5794 cu
->ranges_offset
= DW_UNSND (&attr
);
5795 cu
->has_ranges_offset
= 1;
5798 case DW_AT_location
:
5799 /* Support the .debug_loc offsets */
5800 if (attr_form_is_block (&attr
))
5802 part_die
->locdesc
= DW_BLOCK (&attr
);
5804 else if (attr_form_is_section_offset (&attr
))
5806 dwarf2_complex_location_expr_complaint ();
5810 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5811 "partial symbol information");
5814 case DW_AT_language
:
5815 part_die
->language
= DW_UNSND (&attr
);
5817 case DW_AT_external
:
5818 part_die
->is_external
= DW_UNSND (&attr
);
5820 case DW_AT_declaration
:
5821 part_die
->is_declaration
= DW_UNSND (&attr
);
5824 part_die
->has_type
= 1;
5826 case DW_AT_abstract_origin
:
5827 case DW_AT_specification
:
5828 case DW_AT_extension
:
5829 part_die
->has_specification
= 1;
5830 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
, cu
);
5833 /* Ignore absolute siblings, they might point outside of
5834 the current compile unit. */
5835 if (attr
.form
== DW_FORM_ref_addr
)
5836 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
5838 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
5839 + dwarf2_get_ref_die_offset (&attr
, cu
);
5841 case DW_AT_stmt_list
:
5842 part_die
->has_stmt_list
= 1;
5843 part_die
->line_offset
= DW_UNSND (&attr
);
5845 case DW_AT_byte_size
:
5846 part_die
->has_byte_size
= 1;
5848 case DW_AT_calling_convention
:
5849 /* DWARF doesn't provide a way to identify a program's source-level
5850 entry point. DW_AT_calling_convention attributes are only meant
5851 to describe functions' calling conventions.
5853 However, because it's a necessary piece of information in
5854 Fortran, and because DW_CC_program is the only piece of debugging
5855 information whose definition refers to a 'main program' at all,
5856 several compilers have begun marking Fortran main programs with
5857 DW_CC_program --- even when those functions use the standard
5858 calling conventions.
5860 So until DWARF specifies a way to provide this information and
5861 compilers pick up the new representation, we'll support this
5863 if (DW_UNSND (&attr
) == DW_CC_program
5864 && cu
->language
== language_fortran
)
5865 set_main_name (part_die
->name
);
5872 /* When using the GNU linker, .gnu.linkonce. sections are used to
5873 eliminate duplicate copies of functions and vtables and such.
5874 The linker will arbitrarily choose one and discard the others.
5875 The AT_*_pc values for such functions refer to local labels in
5876 these sections. If the section from that file was discarded, the
5877 labels are not in the output, so the relocs get a value of 0.
5878 If this is a discarded function, mark the pc bounds as invalid,
5879 so that GDB will ignore it. */
5880 if (has_low_pc_attr
&& has_high_pc_attr
5881 && part_die
->lowpc
< part_die
->highpc
5882 && (part_die
->lowpc
!= 0
5883 || dwarf2_per_objfile
->has_section_at_zero
))
5884 part_die
->has_pc_info
= 1;
5886 if (base_address_type
!= base_address_none
&& !cu
->header
.base_known
)
5888 gdb_assert (part_die
->tag
== DW_TAG_compile_unit
);
5889 cu
->header
.base_known
= 1;
5890 cu
->header
.base_address
= base_address
;
5896 /* Find a cached partial DIE at OFFSET in CU. */
5898 static struct partial_die_info
*
5899 find_partial_die_in_comp_unit (unsigned long offset
, struct dwarf2_cu
*cu
)
5901 struct partial_die_info
*lookup_die
= NULL
;
5902 struct partial_die_info part_die
;
5904 part_die
.offset
= offset
;
5905 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
5910 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
5912 static struct partial_die_info
*
5913 find_partial_die (unsigned long offset
, struct dwarf2_cu
*cu
)
5915 struct dwarf2_per_cu_data
*per_cu
= NULL
;
5916 struct partial_die_info
*pd
= NULL
;
5918 if (offset
>= cu
->header
.offset
5919 && offset
< cu
->header
.offset
+ cu
->header
.length
)
5921 pd
= find_partial_die_in_comp_unit (offset
, cu
);
5926 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
5928 if (per_cu
->cu
== NULL
)
5930 load_comp_unit (per_cu
, cu
->objfile
);
5931 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5932 dwarf2_per_objfile
->read_in_chain
= per_cu
;
5935 per_cu
->cu
->last_used
= 0;
5936 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
5938 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
5940 struct cleanup
*back_to
;
5941 struct partial_die_info comp_unit_die
;
5942 struct abbrev_info
*abbrev
;
5943 unsigned int bytes_read
;
5946 per_cu
->load_all_dies
= 1;
5948 /* Re-read the DIEs. */
5949 back_to
= make_cleanup (null_cleanup
, 0);
5950 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
5952 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
5953 back_to
= make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
5955 info_ptr
= per_cu
->cu
->header
.first_die_ptr
;
5956 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
5957 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
5958 per_cu
->cu
->objfile
->obfd
, info_ptr
,
5960 if (comp_unit_die
.has_children
)
5961 load_partial_dies (per_cu
->cu
->objfile
->obfd
, info_ptr
, 0, per_cu
->cu
);
5962 do_cleanups (back_to
);
5964 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
5968 internal_error (__FILE__
, __LINE__
,
5969 _("could not find partial DIE 0x%lx in cache [from module %s]\n"),
5970 offset
, bfd_get_filename (cu
->objfile
->obfd
));
5974 /* Adjust PART_DIE before generating a symbol for it. This function
5975 may set the is_external flag or change the DIE's name. */
5978 fixup_partial_die (struct partial_die_info
*part_die
,
5979 struct dwarf2_cu
*cu
)
5981 /* If we found a reference attribute and the DIE has no name, try
5982 to find a name in the referred to DIE. */
5984 if (part_die
->name
== NULL
&& part_die
->has_specification
)
5986 struct partial_die_info
*spec_die
;
5988 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
5990 fixup_partial_die (spec_die
, cu
);
5994 part_die
->name
= spec_die
->name
;
5996 /* Copy DW_AT_external attribute if it is set. */
5997 if (spec_die
->is_external
)
5998 part_die
->is_external
= spec_die
->is_external
;
6002 /* Set default names for some unnamed DIEs. */
6003 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
6004 || part_die
->tag
== DW_TAG_class_type
))
6005 part_die
->name
= "(anonymous class)";
6007 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
6008 part_die
->name
= "(anonymous namespace)";
6010 if (part_die
->tag
== DW_TAG_structure_type
6011 || part_die
->tag
== DW_TAG_class_type
6012 || part_die
->tag
== DW_TAG_union_type
)
6013 guess_structure_name (part_die
, cu
);
6016 /* Read the die from the .debug_info section buffer. Set DIEP to
6017 point to a newly allocated die with its information, except for its
6018 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6019 whether the die has children or not. */
6022 read_full_die (struct die_info
**diep
, bfd
*abfd
, gdb_byte
*info_ptr
,
6023 struct dwarf2_cu
*cu
, int *has_children
)
6025 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6026 struct abbrev_info
*abbrev
;
6027 struct die_info
*die
;
6029 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
6030 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6031 info_ptr
+= bytes_read
;
6039 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6042 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6044 bfd_get_filename (abfd
));
6046 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
6047 die
->offset
= offset
;
6048 die
->tag
= abbrev
->tag
;
6049 die
->abbrev
= abbrev_number
;
6051 die
->num_attrs
= abbrev
->num_attrs
;
6053 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6054 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6055 abfd
, info_ptr
, cu
);
6058 *has_children
= abbrev
->has_children
;
6062 /* Read an attribute value described by an attribute form. */
6065 read_attribute_value (struct attribute
*attr
, unsigned form
,
6066 bfd
*abfd
, gdb_byte
*info_ptr
,
6067 struct dwarf2_cu
*cu
)
6069 struct comp_unit_head
*cu_header
= &cu
->header
;
6070 unsigned int bytes_read
;
6071 struct dwarf_block
*blk
;
6077 case DW_FORM_ref_addr
:
6078 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6079 info_ptr
+= bytes_read
;
6081 case DW_FORM_block2
:
6082 blk
= dwarf_alloc_block (cu
);
6083 blk
->size
= read_2_bytes (abfd
, info_ptr
);
6085 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6086 info_ptr
+= blk
->size
;
6087 DW_BLOCK (attr
) = blk
;
6089 case DW_FORM_block4
:
6090 blk
= dwarf_alloc_block (cu
);
6091 blk
->size
= read_4_bytes (abfd
, info_ptr
);
6093 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6094 info_ptr
+= blk
->size
;
6095 DW_BLOCK (attr
) = blk
;
6098 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
6102 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
6106 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
6109 case DW_FORM_string
:
6110 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
6111 info_ptr
+= bytes_read
;
6114 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
6116 info_ptr
+= bytes_read
;
6119 blk
= dwarf_alloc_block (cu
);
6120 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6121 info_ptr
+= bytes_read
;
6122 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6123 info_ptr
+= blk
->size
;
6124 DW_BLOCK (attr
) = blk
;
6126 case DW_FORM_block1
:
6127 blk
= dwarf_alloc_block (cu
);
6128 blk
->size
= read_1_byte (abfd
, info_ptr
);
6130 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6131 info_ptr
+= blk
->size
;
6132 DW_BLOCK (attr
) = blk
;
6135 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6139 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6143 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
6144 info_ptr
+= bytes_read
;
6147 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6148 info_ptr
+= bytes_read
;
6151 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
6155 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
6159 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
6163 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
6166 case DW_FORM_ref_udata
:
6167 DW_ADDR (attr
) = (cu
->header
.offset
6168 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
6169 info_ptr
+= bytes_read
;
6171 case DW_FORM_indirect
:
6172 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6173 info_ptr
+= bytes_read
;
6174 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
6177 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
6178 dwarf_form_name (form
),
6179 bfd_get_filename (abfd
));
6182 /* We have seen instances where the compiler tried to emit a byte
6183 size attribute of -1 which ended up being encoded as an unsigned
6184 0xffffffff. Although 0xffffffff is technically a valid size value,
6185 an object of this size seems pretty unlikely so we can relatively
6186 safely treat these cases as if the size attribute was invalid and
6187 treat them as zero by default. */
6188 if (attr
->name
== DW_AT_byte_size
6189 && form
== DW_FORM_data4
6190 && DW_UNSND (attr
) >= 0xffffffff)
6193 (&symfile_complaints
,
6194 _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"),
6196 DW_UNSND (attr
) = 0;
6202 /* Read an attribute described by an abbreviated attribute. */
6205 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
6206 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6208 attr
->name
= abbrev
->name
;
6209 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
6212 /* read dwarf information from a buffer */
6215 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
6217 return bfd_get_8 (abfd
, buf
);
6221 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
6223 return bfd_get_signed_8 (abfd
, buf
);
6227 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
6229 return bfd_get_16 (abfd
, buf
);
6233 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6235 return bfd_get_signed_16 (abfd
, buf
);
6239 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
6241 return bfd_get_32 (abfd
, buf
);
6245 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6247 return bfd_get_signed_32 (abfd
, buf
);
6250 static unsigned long
6251 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
6253 return bfd_get_64 (abfd
, buf
);
6257 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
6258 unsigned int *bytes_read
)
6260 struct comp_unit_head
*cu_header
= &cu
->header
;
6261 CORE_ADDR retval
= 0;
6263 if (cu_header
->signed_addr_p
)
6265 switch (cu_header
->addr_size
)
6268 retval
= bfd_get_signed_16 (abfd
, buf
);
6271 retval
= bfd_get_signed_32 (abfd
, buf
);
6274 retval
= bfd_get_signed_64 (abfd
, buf
);
6277 internal_error (__FILE__
, __LINE__
,
6278 _("read_address: bad switch, signed [in module %s]"),
6279 bfd_get_filename (abfd
));
6284 switch (cu_header
->addr_size
)
6287 retval
= bfd_get_16 (abfd
, buf
);
6290 retval
= bfd_get_32 (abfd
, buf
);
6293 retval
= bfd_get_64 (abfd
, buf
);
6296 internal_error (__FILE__
, __LINE__
,
6297 _("read_address: bad switch, unsigned [in module %s]"),
6298 bfd_get_filename (abfd
));
6302 *bytes_read
= cu_header
->addr_size
;
6306 /* Read the initial length from a section. The (draft) DWARF 3
6307 specification allows the initial length to take up either 4 bytes
6308 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
6309 bytes describe the length and all offsets will be 8 bytes in length
6312 An older, non-standard 64-bit format is also handled by this
6313 function. The older format in question stores the initial length
6314 as an 8-byte quantity without an escape value. Lengths greater
6315 than 2^32 aren't very common which means that the initial 4 bytes
6316 is almost always zero. Since a length value of zero doesn't make
6317 sense for the 32-bit format, this initial zero can be considered to
6318 be an escape value which indicates the presence of the older 64-bit
6319 format. As written, the code can't detect (old format) lengths
6320 greater than 4GB. If it becomes necessary to handle lengths
6321 somewhat larger than 4GB, we could allow other small values (such
6322 as the non-sensical values of 1, 2, and 3) to also be used as
6323 escape values indicating the presence of the old format.
6325 The value returned via bytes_read should be used to increment the
6326 relevant pointer after calling read_initial_length().
6328 As a side effect, this function sets the fields initial_length_size
6329 and offset_size in cu_header to the values appropriate for the
6330 length field. (The format of the initial length field determines
6331 the width of file offsets to be fetched later with read_offset().)
6333 [ Note: read_initial_length() and read_offset() are based on the
6334 document entitled "DWARF Debugging Information Format", revision
6335 3, draft 8, dated November 19, 2001. This document was obtained
6338 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
6340 This document is only a draft and is subject to change. (So beware.)
6342 Details regarding the older, non-standard 64-bit format were
6343 determined empirically by examining 64-bit ELF files produced by
6344 the SGI toolchain on an IRIX 6.5 machine.
6346 - Kevin, July 16, 2002
6350 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, struct comp_unit_head
*cu_header
,
6351 unsigned int *bytes_read
)
6353 LONGEST length
= bfd_get_32 (abfd
, buf
);
6355 if (length
== 0xffffffff)
6357 length
= bfd_get_64 (abfd
, buf
+ 4);
6360 else if (length
== 0)
6362 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
6363 length
= bfd_get_64 (abfd
, buf
);
6373 gdb_assert (cu_header
->initial_length_size
== 0
6374 || cu_header
->initial_length_size
== 4
6375 || cu_header
->initial_length_size
== 8
6376 || cu_header
->initial_length_size
== 12);
6378 if (cu_header
->initial_length_size
!= 0
6379 && cu_header
->initial_length_size
!= *bytes_read
)
6380 complaint (&symfile_complaints
,
6381 _("intermixed 32-bit and 64-bit DWARF sections"));
6383 cu_header
->initial_length_size
= *bytes_read
;
6384 cu_header
->offset_size
= (*bytes_read
== 4) ? 4 : 8;
6390 /* Read an offset from the data stream. The size of the offset is
6391 given by cu_header->offset_size. */
6394 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
6395 unsigned int *bytes_read
)
6399 switch (cu_header
->offset_size
)
6402 retval
= bfd_get_32 (abfd
, buf
);
6406 retval
= bfd_get_64 (abfd
, buf
);
6410 internal_error (__FILE__
, __LINE__
,
6411 _("read_offset: bad switch [in module %s]"),
6412 bfd_get_filename (abfd
));
6419 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
6421 /* If the size of a host char is 8 bits, we can return a pointer
6422 to the buffer, otherwise we have to copy the data to a buffer
6423 allocated on the temporary obstack. */
6424 gdb_assert (HOST_CHAR_BIT
== 8);
6429 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6431 /* If the size of a host char is 8 bits, we can return a pointer
6432 to the string, otherwise we have to copy the string to a buffer
6433 allocated on the temporary obstack. */
6434 gdb_assert (HOST_CHAR_BIT
== 8);
6437 *bytes_read_ptr
= 1;
6440 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
6441 return (char *) buf
;
6445 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
6446 const struct comp_unit_head
*cu_header
,
6447 unsigned int *bytes_read_ptr
)
6449 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
6452 if (dwarf2_per_objfile
->str_buffer
== NULL
)
6454 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
6455 bfd_get_filename (abfd
));
6458 if (str_offset
>= dwarf2_per_objfile
->str_size
)
6460 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
6461 bfd_get_filename (abfd
));
6464 gdb_assert (HOST_CHAR_BIT
== 8);
6465 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
6467 return (char *) (dwarf2_per_objfile
->str_buffer
+ str_offset
);
6470 static unsigned long
6471 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6473 unsigned long result
;
6474 unsigned int num_read
;
6484 byte
= bfd_get_8 (abfd
, buf
);
6487 result
|= ((unsigned long)(byte
& 127) << shift
);
6488 if ((byte
& 128) == 0)
6494 *bytes_read_ptr
= num_read
;
6499 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6502 int i
, shift
, num_read
;
6511 byte
= bfd_get_8 (abfd
, buf
);
6514 result
|= ((long)(byte
& 127) << shift
);
6516 if ((byte
& 128) == 0)
6521 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
6522 result
|= -(((long)1) << shift
);
6523 *bytes_read_ptr
= num_read
;
6527 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6530 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
6536 byte
= bfd_get_8 (abfd
, buf
);
6538 if ((byte
& 128) == 0)
6544 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
6550 cu
->language
= language_c
;
6552 case DW_LANG_C_plus_plus
:
6553 cu
->language
= language_cplus
;
6555 case DW_LANG_Fortran77
:
6556 case DW_LANG_Fortran90
:
6557 case DW_LANG_Fortran95
:
6558 cu
->language
= language_fortran
;
6560 case DW_LANG_Mips_Assembler
:
6561 cu
->language
= language_asm
;
6564 cu
->language
= language_java
;
6568 cu
->language
= language_ada
;
6570 case DW_LANG_Modula2
:
6571 cu
->language
= language_m2
;
6573 case DW_LANG_Pascal83
:
6574 cu
->language
= language_pascal
;
6577 cu
->language
= language_objc
;
6579 case DW_LANG_Cobol74
:
6580 case DW_LANG_Cobol85
:
6582 cu
->language
= language_minimal
;
6585 cu
->language_defn
= language_def (cu
->language
);
6588 /* Return the named attribute or NULL if not there. */
6590 static struct attribute
*
6591 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
6594 struct attribute
*spec
= NULL
;
6596 for (i
= 0; i
< die
->num_attrs
; ++i
)
6598 if (die
->attrs
[i
].name
== name
)
6599 return &die
->attrs
[i
];
6600 if (die
->attrs
[i
].name
== DW_AT_specification
6601 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
6602 spec
= &die
->attrs
[i
];
6607 die
= follow_die_ref (die
, spec
, &cu
);
6608 return dwarf2_attr (die
, name
, cu
);
6614 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6615 and holds a non-zero value. This function should only be used for
6616 DW_FORM_flag attributes. */
6619 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
6621 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
6623 return (attr
&& DW_UNSND (attr
));
6627 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
6629 /* A DIE is a declaration if it has a DW_AT_declaration attribute
6630 which value is non-zero. However, we have to be careful with
6631 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
6632 (via dwarf2_flag_true_p) follows this attribute. So we may
6633 end up accidently finding a declaration attribute that belongs
6634 to a different DIE referenced by the specification attribute,
6635 even though the given DIE does not have a declaration attribute. */
6636 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
6637 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
6640 /* Return the die giving the specification for DIE, if there is
6641 one. *SPEC_CU is the CU containing DIE on input, and the CU
6642 containing the return value on output. */
6644 static struct die_info
*
6645 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
6647 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
6650 if (spec_attr
== NULL
)
6653 return follow_die_ref (die
, spec_attr
, spec_cu
);
6656 /* Free the line_header structure *LH, and any arrays and strings it
6659 free_line_header (struct line_header
*lh
)
6661 if (lh
->standard_opcode_lengths
)
6662 xfree (lh
->standard_opcode_lengths
);
6664 /* Remember that all the lh->file_names[i].name pointers are
6665 pointers into debug_line_buffer, and don't need to be freed. */
6667 xfree (lh
->file_names
);
6669 /* Similarly for the include directory names. */
6670 if (lh
->include_dirs
)
6671 xfree (lh
->include_dirs
);
6677 /* Add an entry to LH's include directory table. */
6679 add_include_dir (struct line_header
*lh
, char *include_dir
)
6681 /* Grow the array if necessary. */
6682 if (lh
->include_dirs_size
== 0)
6684 lh
->include_dirs_size
= 1; /* for testing */
6685 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
6686 * sizeof (*lh
->include_dirs
));
6688 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
6690 lh
->include_dirs_size
*= 2;
6691 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
6692 (lh
->include_dirs_size
6693 * sizeof (*lh
->include_dirs
)));
6696 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
6700 /* Add an entry to LH's file name table. */
6702 add_file_name (struct line_header
*lh
,
6704 unsigned int dir_index
,
6705 unsigned int mod_time
,
6706 unsigned int length
)
6708 struct file_entry
*fe
;
6710 /* Grow the array if necessary. */
6711 if (lh
->file_names_size
== 0)
6713 lh
->file_names_size
= 1; /* for testing */
6714 lh
->file_names
= xmalloc (lh
->file_names_size
6715 * sizeof (*lh
->file_names
));
6717 else if (lh
->num_file_names
>= lh
->file_names_size
)
6719 lh
->file_names_size
*= 2;
6720 lh
->file_names
= xrealloc (lh
->file_names
,
6721 (lh
->file_names_size
6722 * sizeof (*lh
->file_names
)));
6725 fe
= &lh
->file_names
[lh
->num_file_names
++];
6727 fe
->dir_index
= dir_index
;
6728 fe
->mod_time
= mod_time
;
6729 fe
->length
= length
;
6735 /* Read the statement program header starting at OFFSET in
6736 .debug_line, according to the endianness of ABFD. Return a pointer
6737 to a struct line_header, allocated using xmalloc.
6739 NOTE: the strings in the include directory and file name tables of
6740 the returned object point into debug_line_buffer, and must not be
6742 static struct line_header
*
6743 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
6744 struct dwarf2_cu
*cu
)
6746 struct cleanup
*back_to
;
6747 struct line_header
*lh
;
6749 unsigned int bytes_read
;
6751 char *cur_dir
, *cur_file
;
6753 if (dwarf2_per_objfile
->line_buffer
== NULL
)
6755 complaint (&symfile_complaints
, _("missing .debug_line section"));
6759 /* Make sure that at least there's room for the total_length field.
6760 That could be 12 bytes long, but we're just going to fudge that. */
6761 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
6763 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6767 lh
= xmalloc (sizeof (*lh
));
6768 memset (lh
, 0, sizeof (*lh
));
6769 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
6772 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
6774 /* Read in the header. */
6776 read_initial_length (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6777 line_ptr
+= bytes_read
;
6778 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
6779 + dwarf2_per_objfile
->line_size
))
6781 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6784 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
6785 lh
->version
= read_2_bytes (abfd
, line_ptr
);
6787 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6788 line_ptr
+= bytes_read
;
6789 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
6791 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
6793 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
6795 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
6797 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
6799 lh
->standard_opcode_lengths
6800 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
6802 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
6803 for (i
= 1; i
< lh
->opcode_base
; ++i
)
6805 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
6809 /* Read directory table. */
6810 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6812 line_ptr
+= bytes_read
;
6813 add_include_dir (lh
, cur_dir
);
6815 line_ptr
+= bytes_read
;
6817 /* Read file name table. */
6818 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6820 unsigned int dir_index
, mod_time
, length
;
6822 line_ptr
+= bytes_read
;
6823 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6824 line_ptr
+= bytes_read
;
6825 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6826 line_ptr
+= bytes_read
;
6827 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6828 line_ptr
+= bytes_read
;
6830 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6832 line_ptr
+= bytes_read
;
6833 lh
->statement_program_start
= line_ptr
;
6835 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
6836 + dwarf2_per_objfile
->line_size
))
6837 complaint (&symfile_complaints
,
6838 _("line number info header doesn't fit in `.debug_line' section"));
6840 discard_cleanups (back_to
);
6844 /* This function exists to work around a bug in certain compilers
6845 (particularly GCC 2.95), in which the first line number marker of a
6846 function does not show up until after the prologue, right before
6847 the second line number marker. This function shifts ADDRESS down
6848 to the beginning of the function if necessary, and is called on
6849 addresses passed to record_line. */
6852 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
6854 struct function_range
*fn
;
6856 /* Find the function_range containing address. */
6861 cu
->cached_fn
= cu
->first_fn
;
6865 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6871 while (fn
&& fn
!= cu
->cached_fn
)
6872 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6882 if (address
!= fn
->lowpc
)
6883 complaint (&symfile_complaints
,
6884 _("misplaced first line number at 0x%lx for '%s'"),
6885 (unsigned long) address
, fn
->name
);
6890 /* Decode the Line Number Program (LNP) for the given line_header
6891 structure and CU. The actual information extracted and the type
6892 of structures created from the LNP depends on the value of PST.
6894 1. If PST is NULL, then this procedure uses the data from the program
6895 to create all necessary symbol tables, and their linetables.
6896 The compilation directory of the file is passed in COMP_DIR,
6897 and must not be NULL.
6899 2. If PST is not NULL, this procedure reads the program to determine
6900 the list of files included by the unit represented by PST, and
6901 builds all the associated partial symbol tables. In this case,
6902 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
6903 is not used to compute the full name of the symtab, and therefore
6904 omitting it when building the partial symtab does not introduce
6905 the potential for inconsistency - a partial symtab and its associated
6906 symbtab having a different fullname -). */
6909 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
6910 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
6912 gdb_byte
*line_ptr
, *extended_end
;
6914 unsigned int bytes_read
, extended_len
;
6915 unsigned char op_code
, extended_op
, adj_opcode
;
6917 struct objfile
*objfile
= cu
->objfile
;
6918 const int decode_for_pst_p
= (pst
!= NULL
);
6919 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
6921 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6923 line_ptr
= lh
->statement_program_start
;
6924 line_end
= lh
->statement_program_end
;
6926 /* Read the statement sequences until there's nothing left. */
6927 while (line_ptr
< line_end
)
6929 /* state machine registers */
6930 CORE_ADDR address
= 0;
6931 unsigned int file
= 1;
6932 unsigned int line
= 1;
6933 unsigned int column
= 0;
6934 int is_stmt
= lh
->default_is_stmt
;
6935 int basic_block
= 0;
6936 int end_sequence
= 0;
6938 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
6940 /* Start a subfile for the current file of the state machine. */
6941 /* lh->include_dirs and lh->file_names are 0-based, but the
6942 directory and file name numbers in the statement program
6944 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
6948 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6950 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
6953 /* Decode the table. */
6954 while (!end_sequence
)
6956 op_code
= read_1_byte (abfd
, line_ptr
);
6959 if (op_code
>= lh
->opcode_base
)
6961 /* Special operand. */
6962 adj_opcode
= op_code
- lh
->opcode_base
;
6963 address
+= (adj_opcode
/ lh
->line_range
)
6964 * lh
->minimum_instruction_length
;
6965 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
6966 if (lh
->num_file_names
< file
)
6967 dwarf2_debug_line_missing_file_complaint ();
6970 lh
->file_names
[file
- 1].included_p
= 1;
6971 if (!decode_for_pst_p
)
6973 if (last_subfile
!= current_subfile
)
6976 record_line (last_subfile
, 0, address
);
6977 last_subfile
= current_subfile
;
6979 /* Append row to matrix using current values. */
6980 record_line (current_subfile
, line
,
6981 check_cu_functions (address
, cu
));
6986 else switch (op_code
)
6988 case DW_LNS_extended_op
:
6989 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6990 line_ptr
+= bytes_read
;
6991 extended_end
= line_ptr
+ extended_len
;
6992 extended_op
= read_1_byte (abfd
, line_ptr
);
6994 switch (extended_op
)
6996 case DW_LNE_end_sequence
:
6999 if (lh
->num_file_names
< file
)
7000 dwarf2_debug_line_missing_file_complaint ();
7003 lh
->file_names
[file
- 1].included_p
= 1;
7004 if (!decode_for_pst_p
)
7005 record_line (current_subfile
, 0, address
);
7008 case DW_LNE_set_address
:
7009 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
7010 line_ptr
+= bytes_read
;
7011 address
+= baseaddr
;
7013 case DW_LNE_define_file
:
7016 unsigned int dir_index
, mod_time
, length
;
7018 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
7019 line_ptr
+= bytes_read
;
7021 read_unsigned_leb128 (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
;
7029 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7033 complaint (&symfile_complaints
,
7034 _("mangled .debug_line section"));
7037 /* Make sure that we parsed the extended op correctly. If e.g.
7038 we expected a different address size than the producer used,
7039 we may have read the wrong number of bytes. */
7040 if (line_ptr
!= extended_end
)
7042 complaint (&symfile_complaints
,
7043 _("mangled .debug_line section"));
7048 if (lh
->num_file_names
< file
)
7049 dwarf2_debug_line_missing_file_complaint ();
7052 lh
->file_names
[file
- 1].included_p
= 1;
7053 if (!decode_for_pst_p
)
7055 if (last_subfile
!= current_subfile
)
7058 record_line (last_subfile
, 0, address
);
7059 last_subfile
= current_subfile
;
7061 record_line (current_subfile
, line
,
7062 check_cu_functions (address
, cu
));
7067 case DW_LNS_advance_pc
:
7068 address
+= lh
->minimum_instruction_length
7069 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7070 line_ptr
+= bytes_read
;
7072 case DW_LNS_advance_line
:
7073 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
7074 line_ptr
+= bytes_read
;
7076 case DW_LNS_set_file
:
7078 /* The arrays lh->include_dirs and lh->file_names are
7079 0-based, but the directory and file name numbers in
7080 the statement program are 1-based. */
7081 struct file_entry
*fe
;
7084 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7085 line_ptr
+= bytes_read
;
7086 if (lh
->num_file_names
< file
)
7087 dwarf2_debug_line_missing_file_complaint ();
7090 fe
= &lh
->file_names
[file
- 1];
7092 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7093 if (!decode_for_pst_p
)
7095 last_subfile
= current_subfile
;
7096 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7101 case DW_LNS_set_column
:
7102 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7103 line_ptr
+= bytes_read
;
7105 case DW_LNS_negate_stmt
:
7106 is_stmt
= (!is_stmt
);
7108 case DW_LNS_set_basic_block
:
7111 /* Add to the address register of the state machine the
7112 address increment value corresponding to special opcode
7113 255. I.e., this value is scaled by the minimum
7114 instruction length since special opcode 255 would have
7115 scaled the the increment. */
7116 case DW_LNS_const_add_pc
:
7117 address
+= (lh
->minimum_instruction_length
7118 * ((255 - lh
->opcode_base
) / lh
->line_range
));
7120 case DW_LNS_fixed_advance_pc
:
7121 address
+= read_2_bytes (abfd
, line_ptr
);
7126 /* Unknown standard opcode, ignore it. */
7129 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
7131 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7132 line_ptr
+= bytes_read
;
7139 if (decode_for_pst_p
)
7143 /* Now that we're done scanning the Line Header Program, we can
7144 create the psymtab of each included file. */
7145 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
7146 if (lh
->file_names
[file_index
].included_p
== 1)
7148 const struct file_entry fe
= lh
->file_names
[file_index
];
7149 char *include_name
= fe
.name
;
7150 char *dir_name
= NULL
;
7151 char *pst_filename
= pst
->filename
;
7154 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
7156 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
7158 include_name
= concat (dir_name
, SLASH_STRING
,
7159 include_name
, (char *)NULL
);
7160 make_cleanup (xfree
, include_name
);
7163 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
7165 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
7166 pst_filename
, (char *)NULL
);
7167 make_cleanup (xfree
, pst_filename
);
7170 if (strcmp (include_name
, pst_filename
) != 0)
7171 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
7176 /* Make sure a symtab is created for every file, even files
7177 which contain only variables (i.e. no code with associated
7181 struct file_entry
*fe
;
7183 for (i
= 0; i
< lh
->num_file_names
; i
++)
7186 fe
= &lh
->file_names
[i
];
7188 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7189 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7191 /* Skip the main file; we don't need it, and it must be
7192 allocated last, so that it will show up before the
7193 non-primary symtabs in the objfile's symtab list. */
7194 if (current_subfile
== first_subfile
)
7197 if (current_subfile
->symtab
== NULL
)
7198 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7200 fe
->symtab
= current_subfile
->symtab
;
7205 /* Start a subfile for DWARF. FILENAME is the name of the file and
7206 DIRNAME the name of the source directory which contains FILENAME
7207 or NULL if not known. COMP_DIR is the compilation directory for the
7208 linetable's compilation unit or NULL if not known.
7209 This routine tries to keep line numbers from identical absolute and
7210 relative file names in a common subfile.
7212 Using the `list' example from the GDB testsuite, which resides in
7213 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
7214 of /srcdir/list0.c yields the following debugging information for list0.c:
7216 DW_AT_name: /srcdir/list0.c
7217 DW_AT_comp_dir: /compdir
7218 files.files[0].name: list0.h
7219 files.files[0].dir: /srcdir
7220 files.files[1].name: list0.c
7221 files.files[1].dir: /srcdir
7223 The line number information for list0.c has to end up in a single
7224 subfile, so that `break /srcdir/list0.c:1' works as expected.
7225 start_subfile will ensure that this happens provided that we pass the
7226 concatenation of files.files[1].dir and files.files[1].name as the
7230 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
7234 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
7235 `start_symtab' will always pass the contents of DW_AT_comp_dir as
7236 second argument to start_subfile. To be consistent, we do the
7237 same here. In order not to lose the line information directory,
7238 we concatenate it to the filename when it makes sense.
7239 Note that the Dwarf3 standard says (speaking of filenames in line
7240 information): ``The directory index is ignored for file names
7241 that represent full path names''. Thus ignoring dirname in the
7242 `else' branch below isn't an issue. */
7244 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
7245 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
7247 fullname
= filename
;
7249 start_subfile (fullname
, comp_dir
);
7251 if (fullname
!= filename
)
7256 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
7257 struct dwarf2_cu
*cu
)
7259 struct objfile
*objfile
= cu
->objfile
;
7260 struct comp_unit_head
*cu_header
= &cu
->header
;
7262 /* NOTE drow/2003-01-30: There used to be a comment and some special
7263 code here to turn a symbol with DW_AT_external and a
7264 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
7265 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
7266 with some versions of binutils) where shared libraries could have
7267 relocations against symbols in their debug information - the
7268 minimal symbol would have the right address, but the debug info
7269 would not. It's no longer necessary, because we will explicitly
7270 apply relocations when we read in the debug information now. */
7272 /* A DW_AT_location attribute with no contents indicates that a
7273 variable has been optimized away. */
7274 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
7276 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7280 /* Handle one degenerate form of location expression specially, to
7281 preserve GDB's previous behavior when section offsets are
7282 specified. If this is just a DW_OP_addr then mark this symbol
7285 if (attr_form_is_block (attr
)
7286 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
7287 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
7291 SYMBOL_VALUE_ADDRESS (sym
) =
7292 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
7293 SYMBOL_CLASS (sym
) = LOC_STATIC
;
7294 fixup_symbol_section (sym
, objfile
);
7295 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
7296 SYMBOL_SECTION (sym
));
7300 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
7301 expression evaluator, and use LOC_COMPUTED only when necessary
7302 (i.e. when the value of a register or memory location is
7303 referenced, or a thread-local block, etc.). Then again, it might
7304 not be worthwhile. I'm assuming that it isn't unless performance
7305 or memory numbers show me otherwise. */
7307 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
7308 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
7311 /* Given a pointer to a DWARF information entry, figure out if we need
7312 to make a symbol table entry for it, and if so, create a new entry
7313 and return a pointer to it.
7314 If TYPE is NULL, determine symbol type from the die, otherwise
7315 used the passed type. */
7317 static struct symbol
*
7318 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
7320 struct objfile
*objfile
= cu
->objfile
;
7321 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7322 struct symbol
*sym
= NULL
;
7324 struct attribute
*attr
= NULL
;
7325 struct attribute
*attr2
= NULL
;
7328 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7330 if (die
->tag
!= DW_TAG_namespace
)
7331 name
= dwarf2_linkage_name (die
, cu
);
7333 name
= TYPE_NAME (type
);
7337 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
7338 sizeof (struct symbol
));
7339 OBJSTAT (objfile
, n_syms
++);
7340 memset (sym
, 0, sizeof (struct symbol
));
7342 /* Cache this symbol's name and the name's demangled form (if any). */
7343 SYMBOL_LANGUAGE (sym
) = cu
->language
;
7344 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
7346 /* Default assumptions.
7347 Use the passed type or decode it from the die. */
7348 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7349 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7351 SYMBOL_TYPE (sym
) = type
;
7353 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
7354 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
7357 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
7360 attr
= dwarf2_attr (die
, DW_AT_decl_file
, cu
);
7363 int file_index
= DW_UNSND (attr
);
7364 if (cu
->line_header
== NULL
7365 || file_index
> cu
->line_header
->num_file_names
)
7366 complaint (&symfile_complaints
,
7367 _("file index out of range"));
7368 else if (file_index
> 0)
7370 struct file_entry
*fe
;
7371 fe
= &cu
->line_header
->file_names
[file_index
- 1];
7372 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
7379 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7382 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
7384 SYMBOL_CLASS (sym
) = LOC_LABEL
;
7386 case DW_TAG_subprogram
:
7387 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7389 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
7390 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7391 if ((attr2
&& (DW_UNSND (attr2
) != 0))
7392 || cu
->language
== language_ada
)
7394 /* Subprograms marked external are stored as a global symbol.
7395 Ada subprograms, whether marked external or not, are always
7396 stored as a global symbol, because we want to be able to
7397 access them globally. For instance, we want to be able
7398 to break on a nested subprogram without having to
7399 specify the context. */
7400 add_symbol_to_list (sym
, &global_symbols
);
7404 add_symbol_to_list (sym
, cu
->list_in_scope
);
7407 case DW_TAG_variable
:
7408 /* Compilation with minimal debug info may result in variables
7409 with missing type entries. Change the misleading `void' type
7410 to something sensible. */
7411 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
7413 = builtin_type (gdbarch
)->nodebug_data_symbol
;
7415 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7418 dwarf2_const_value (attr
, sym
, cu
);
7419 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7420 if (attr2
&& (DW_UNSND (attr2
) != 0))
7421 add_symbol_to_list (sym
, &global_symbols
);
7423 add_symbol_to_list (sym
, cu
->list_in_scope
);
7426 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7429 var_decode_location (attr
, sym
, cu
);
7430 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7431 if (attr2
&& (DW_UNSND (attr2
) != 0))
7432 add_symbol_to_list (sym
, &global_symbols
);
7434 add_symbol_to_list (sym
, cu
->list_in_scope
);
7438 /* We do not know the address of this symbol.
7439 If it is an external symbol and we have type information
7440 for it, enter the symbol as a LOC_UNRESOLVED symbol.
7441 The address of the variable will then be determined from
7442 the minimal symbol table whenever the variable is
7444 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7445 if (attr2
&& (DW_UNSND (attr2
) != 0)
7446 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
7448 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
7449 add_symbol_to_list (sym
, &global_symbols
);
7453 case DW_TAG_formal_parameter
:
7454 SYMBOL_IS_ARGUMENT (sym
) = 1;
7455 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7458 var_decode_location (attr
, sym
, cu
);
7460 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7463 dwarf2_const_value (attr
, sym
, cu
);
7465 add_symbol_to_list (sym
, cu
->list_in_scope
);
7467 case DW_TAG_unspecified_parameters
:
7468 /* From varargs functions; gdb doesn't seem to have any
7469 interest in this information, so just ignore it for now.
7472 case DW_TAG_class_type
:
7473 case DW_TAG_interface_type
:
7474 case DW_TAG_structure_type
:
7475 case DW_TAG_union_type
:
7476 case DW_TAG_set_type
:
7477 case DW_TAG_enumeration_type
:
7478 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7479 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7481 /* Make sure that the symbol includes appropriate enclosing
7482 classes/namespaces in its name. These are calculated in
7483 read_structure_type, and the correct name is saved in
7486 if (cu
->language
== language_cplus
7487 || cu
->language
== language_java
)
7489 struct type
*type
= SYMBOL_TYPE (sym
);
7491 if (TYPE_TAG_NAME (type
) != NULL
)
7493 /* FIXME: carlton/2003-11-10: Should this use
7494 SYMBOL_SET_NAMES instead? (The same problem also
7495 arises further down in this function.) */
7496 /* The type's name is already allocated along with
7497 this objfile, so we don't need to duplicate it
7499 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
7504 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
7505 really ever be static objects: otherwise, if you try
7506 to, say, break of a class's method and you're in a file
7507 which doesn't mention that class, it won't work unless
7508 the check for all static symbols in lookup_symbol_aux
7509 saves you. See the OtherFileClass tests in
7510 gdb.c++/namespace.exp. */
7512 struct pending
**list_to_add
;
7514 list_to_add
= (cu
->list_in_scope
== &file_symbols
7515 && (cu
->language
== language_cplus
7516 || cu
->language
== language_java
)
7517 ? &global_symbols
: cu
->list_in_scope
);
7519 add_symbol_to_list (sym
, list_to_add
);
7521 /* The semantics of C++ state that "struct foo { ... }" also
7522 defines a typedef for "foo". A Java class declaration also
7523 defines a typedef for the class. */
7524 if (cu
->language
== language_cplus
7525 || cu
->language
== language_java
7526 || cu
->language
== language_ada
)
7528 /* The symbol's name is already allocated along with
7529 this objfile, so we don't need to duplicate it for
7531 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
7532 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
7536 case DW_TAG_typedef
:
7537 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7538 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7539 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7540 add_symbol_to_list (sym
, cu
->list_in_scope
);
7542 case DW_TAG_base_type
:
7543 case DW_TAG_subrange_type
:
7544 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7545 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7546 add_symbol_to_list (sym
, cu
->list_in_scope
);
7548 case DW_TAG_enumerator
:
7549 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7550 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7553 dwarf2_const_value (attr
, sym
, cu
);
7556 /* NOTE: carlton/2003-11-10: See comment above in the
7557 DW_TAG_class_type, etc. block. */
7559 struct pending
**list_to_add
;
7561 list_to_add
= (cu
->list_in_scope
== &file_symbols
7562 && (cu
->language
== language_cplus
7563 || cu
->language
== language_java
)
7564 ? &global_symbols
: cu
->list_in_scope
);
7566 add_symbol_to_list (sym
, list_to_add
);
7569 case DW_TAG_namespace
:
7570 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7571 add_symbol_to_list (sym
, &global_symbols
);
7574 /* Not a tag we recognize. Hopefully we aren't processing
7575 trash data, but since we must specifically ignore things
7576 we don't recognize, there is nothing else we should do at
7578 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
7579 dwarf_tag_name (die
->tag
));
7583 /* For the benefit of old versions of GCC, check for anonymous
7584 namespaces based on the demangled name. */
7585 if (!processing_has_namespace_info
7586 && cu
->language
== language_cplus
7587 && dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
) != NULL
)
7588 cp_scan_for_anonymous_namespaces (sym
);
7593 /* Copy constant value from an attribute to a symbol. */
7596 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
7597 struct dwarf2_cu
*cu
)
7599 struct objfile
*objfile
= cu
->objfile
;
7600 struct comp_unit_head
*cu_header
= &cu
->header
;
7601 struct dwarf_block
*blk
;
7606 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
7607 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7608 cu_header
->addr_size
,
7609 TYPE_LENGTH (SYMBOL_TYPE
7611 SYMBOL_VALUE_BYTES (sym
) =
7612 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
7613 /* NOTE: cagney/2003-05-09: In-lined store_address call with
7614 it's body - store_unsigned_integer. */
7615 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
7617 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7620 /* DW_STRING is already allocated on the obstack, point directly
7622 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
7623 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7625 case DW_FORM_block1
:
7626 case DW_FORM_block2
:
7627 case DW_FORM_block4
:
7629 blk
= DW_BLOCK (attr
);
7630 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
7631 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7633 TYPE_LENGTH (SYMBOL_TYPE
7635 SYMBOL_VALUE_BYTES (sym
) =
7636 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
7637 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
7638 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7641 /* The DW_AT_const_value attributes are supposed to carry the
7642 symbol's value "represented as it would be on the target
7643 architecture." By the time we get here, it's already been
7644 converted to host endianness, so we just need to sign- or
7645 zero-extend it as appropriate. */
7647 dwarf2_const_value_data (attr
, sym
, 8);
7650 dwarf2_const_value_data (attr
, sym
, 16);
7653 dwarf2_const_value_data (attr
, sym
, 32);
7656 dwarf2_const_value_data (attr
, sym
, 64);
7660 SYMBOL_VALUE (sym
) = DW_SND (attr
);
7661 SYMBOL_CLASS (sym
) = LOC_CONST
;
7665 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
7666 SYMBOL_CLASS (sym
) = LOC_CONST
;
7670 complaint (&symfile_complaints
,
7671 _("unsupported const value attribute form: '%s'"),
7672 dwarf_form_name (attr
->form
));
7673 SYMBOL_VALUE (sym
) = 0;
7674 SYMBOL_CLASS (sym
) = LOC_CONST
;
7680 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
7681 or zero-extend it as appropriate for the symbol's type. */
7683 dwarf2_const_value_data (struct attribute
*attr
,
7687 LONGEST l
= DW_UNSND (attr
);
7689 if (bits
< sizeof (l
) * 8)
7691 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
7692 l
&= ((LONGEST
) 1 << bits
) - 1;
7694 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
7697 SYMBOL_VALUE (sym
) = l
;
7698 SYMBOL_CLASS (sym
) = LOC_CONST
;
7702 /* Return the type of the die in question using its DW_AT_type attribute. */
7704 static struct type
*
7705 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7707 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7709 struct attribute
*type_attr
;
7710 struct die_info
*type_die
;
7712 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
7715 /* A missing DW_AT_type represents a void type. */
7716 return builtin_type (gdbarch
)->builtin_void
;
7719 type_die
= follow_die_ref (die
, type_attr
, &cu
);
7721 type
= tag_type_to_type (type_die
, cu
);
7724 dump_die (type_die
);
7725 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
7731 /* Return the containing type of the die in question using its
7732 DW_AT_containing_type attribute. */
7734 static struct type
*
7735 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7737 struct type
*type
= NULL
;
7738 struct attribute
*type_attr
;
7739 struct die_info
*type_die
= NULL
;
7741 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
7744 type_die
= follow_die_ref (die
, type_attr
, &cu
);
7745 type
= tag_type_to_type (type_die
, cu
);
7750 dump_die (type_die
);
7751 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
7757 static struct type
*
7758 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7760 struct type
*this_type
;
7762 this_type
= read_type_die (die
, cu
);
7766 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
7772 static struct type
*
7773 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7775 struct type
*this_type
;
7777 this_type
= get_die_type (die
, cu
);
7783 case DW_TAG_class_type
:
7784 case DW_TAG_interface_type
:
7785 case DW_TAG_structure_type
:
7786 case DW_TAG_union_type
:
7787 this_type
= read_structure_type (die
, cu
);
7789 case DW_TAG_enumeration_type
:
7790 this_type
= read_enumeration_type (die
, cu
);
7792 case DW_TAG_subprogram
:
7793 case DW_TAG_subroutine_type
:
7794 this_type
= read_subroutine_type (die
, cu
);
7796 case DW_TAG_array_type
:
7797 this_type
= read_array_type (die
, cu
);
7799 case DW_TAG_set_type
:
7800 this_type
= read_set_type (die
, cu
);
7802 case DW_TAG_pointer_type
:
7803 this_type
= read_tag_pointer_type (die
, cu
);
7805 case DW_TAG_ptr_to_member_type
:
7806 this_type
= read_tag_ptr_to_member_type (die
, cu
);
7808 case DW_TAG_reference_type
:
7809 this_type
= read_tag_reference_type (die
, cu
);
7811 case DW_TAG_const_type
:
7812 this_type
= read_tag_const_type (die
, cu
);
7814 case DW_TAG_volatile_type
:
7815 this_type
= read_tag_volatile_type (die
, cu
);
7817 case DW_TAG_string_type
:
7818 this_type
= read_tag_string_type (die
, cu
);
7820 case DW_TAG_typedef
:
7821 this_type
= read_typedef (die
, cu
);
7823 case DW_TAG_subrange_type
:
7824 this_type
= read_subrange_type (die
, cu
);
7826 case DW_TAG_base_type
:
7827 this_type
= read_base_type (die
, cu
);
7829 case DW_TAG_unspecified_type
:
7830 this_type
= read_unspecified_type (die
, cu
);
7832 case DW_TAG_namespace
:
7833 this_type
= read_namespace_type (die
, cu
);
7836 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
7837 dwarf_tag_name (die
->tag
));
7844 /* Return the name of the namespace/class that DIE is defined within,
7845 or "" if we can't tell. The caller should not xfree the result.
7847 For example, if we're within the method foo() in the following
7857 then determine_prefix on foo's die will return "N::C". */
7860 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
7862 struct die_info
*parent
, *spec_die
;
7863 struct dwarf2_cu
*spec_cu
;
7864 struct type
*parent_type
;
7866 if (cu
->language
!= language_cplus
7867 && cu
->language
!= language_java
)
7870 /* We have to be careful in the presence of DW_AT_specification.
7871 For example, with GCC 3.4, given the code
7875 // Definition of N::foo.
7879 then we'll have a tree of DIEs like this:
7881 1: DW_TAG_compile_unit
7882 2: DW_TAG_namespace // N
7883 3: DW_TAG_subprogram // declaration of N::foo
7884 4: DW_TAG_subprogram // definition of N::foo
7885 DW_AT_specification // refers to die #3
7887 Thus, when processing die #4, we have to pretend that we're in
7888 the context of its DW_AT_specification, namely the contex of die
7891 spec_die
= die_specification (die
, &spec_cu
);
7892 if (spec_die
== NULL
)
7893 parent
= die
->parent
;
7896 parent
= spec_die
->parent
;
7903 switch (parent
->tag
)
7905 case DW_TAG_namespace
:
7906 parent_type
= read_type_die (parent
, cu
);
7907 /* We give a name to even anonymous namespaces. */
7908 return TYPE_TAG_NAME (parent_type
);
7909 case DW_TAG_class_type
:
7910 case DW_TAG_interface_type
:
7911 case DW_TAG_structure_type
:
7912 case DW_TAG_union_type
:
7913 parent_type
= read_type_die (parent
, cu
);
7914 if (TYPE_TAG_NAME (parent_type
) != NULL
)
7915 return TYPE_TAG_NAME (parent_type
);
7917 /* An anonymous structure is only allowed non-static data
7918 members; no typedefs, no member functions, et cetera.
7919 So it does not need a prefix. */
7922 return determine_prefix (parent
, cu
);
7926 /* Return a newly-allocated string formed by concatenating PREFIX and
7927 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
7928 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
7929 perform an obconcat, otherwise allocate storage for the result. The CU argument
7930 is used to determine the language and hence, the appropriate separator. */
7932 #define MAX_SEP_LEN 2 /* sizeof ("::") */
7935 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
7936 struct dwarf2_cu
*cu
)
7940 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
7942 else if (cu
->language
== language_java
)
7949 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
7954 strcpy (retval
, prefix
);
7955 strcat (retval
, sep
);
7958 strcat (retval
, suffix
);
7964 /* We have an obstack. */
7965 return obconcat (obs
, prefix
, sep
, suffix
);
7969 /* Return sibling of die, NULL if no sibling. */
7971 static struct die_info
*
7972 sibling_die (struct die_info
*die
)
7974 return die
->sibling
;
7977 /* Get linkage name of a die, return NULL if not found. */
7980 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
7982 struct attribute
*attr
;
7984 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7985 if (attr
&& DW_STRING (attr
))
7986 return DW_STRING (attr
);
7987 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7988 if (attr
&& DW_STRING (attr
))
7989 return DW_STRING (attr
);
7993 /* Get name of a die, return NULL if not found. */
7996 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
7998 struct attribute
*attr
;
8000 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8001 if (attr
&& DW_STRING (attr
))
8002 return DW_STRING (attr
);
8006 /* Return the die that this die in an extension of, or NULL if there
8007 is none. *EXT_CU is the CU containing DIE on input, and the CU
8008 containing the return value on output. */
8010 static struct die_info
*
8011 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
8013 struct attribute
*attr
;
8015 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
8019 return follow_die_ref (die
, attr
, ext_cu
);
8022 /* Convert a DIE tag into its string name. */
8025 dwarf_tag_name (unsigned tag
)
8029 case DW_TAG_padding
:
8030 return "DW_TAG_padding";
8031 case DW_TAG_array_type
:
8032 return "DW_TAG_array_type";
8033 case DW_TAG_class_type
:
8034 return "DW_TAG_class_type";
8035 case DW_TAG_entry_point
:
8036 return "DW_TAG_entry_point";
8037 case DW_TAG_enumeration_type
:
8038 return "DW_TAG_enumeration_type";
8039 case DW_TAG_formal_parameter
:
8040 return "DW_TAG_formal_parameter";
8041 case DW_TAG_imported_declaration
:
8042 return "DW_TAG_imported_declaration";
8044 return "DW_TAG_label";
8045 case DW_TAG_lexical_block
:
8046 return "DW_TAG_lexical_block";
8048 return "DW_TAG_member";
8049 case DW_TAG_pointer_type
:
8050 return "DW_TAG_pointer_type";
8051 case DW_TAG_reference_type
:
8052 return "DW_TAG_reference_type";
8053 case DW_TAG_compile_unit
:
8054 return "DW_TAG_compile_unit";
8055 case DW_TAG_string_type
:
8056 return "DW_TAG_string_type";
8057 case DW_TAG_structure_type
:
8058 return "DW_TAG_structure_type";
8059 case DW_TAG_subroutine_type
:
8060 return "DW_TAG_subroutine_type";
8061 case DW_TAG_typedef
:
8062 return "DW_TAG_typedef";
8063 case DW_TAG_union_type
:
8064 return "DW_TAG_union_type";
8065 case DW_TAG_unspecified_parameters
:
8066 return "DW_TAG_unspecified_parameters";
8067 case DW_TAG_variant
:
8068 return "DW_TAG_variant";
8069 case DW_TAG_common_block
:
8070 return "DW_TAG_common_block";
8071 case DW_TAG_common_inclusion
:
8072 return "DW_TAG_common_inclusion";
8073 case DW_TAG_inheritance
:
8074 return "DW_TAG_inheritance";
8075 case DW_TAG_inlined_subroutine
:
8076 return "DW_TAG_inlined_subroutine";
8078 return "DW_TAG_module";
8079 case DW_TAG_ptr_to_member_type
:
8080 return "DW_TAG_ptr_to_member_type";
8081 case DW_TAG_set_type
:
8082 return "DW_TAG_set_type";
8083 case DW_TAG_subrange_type
:
8084 return "DW_TAG_subrange_type";
8085 case DW_TAG_with_stmt
:
8086 return "DW_TAG_with_stmt";
8087 case DW_TAG_access_declaration
:
8088 return "DW_TAG_access_declaration";
8089 case DW_TAG_base_type
:
8090 return "DW_TAG_base_type";
8091 case DW_TAG_catch_block
:
8092 return "DW_TAG_catch_block";
8093 case DW_TAG_const_type
:
8094 return "DW_TAG_const_type";
8095 case DW_TAG_constant
:
8096 return "DW_TAG_constant";
8097 case DW_TAG_enumerator
:
8098 return "DW_TAG_enumerator";
8099 case DW_TAG_file_type
:
8100 return "DW_TAG_file_type";
8102 return "DW_TAG_friend";
8103 case DW_TAG_namelist
:
8104 return "DW_TAG_namelist";
8105 case DW_TAG_namelist_item
:
8106 return "DW_TAG_namelist_item";
8107 case DW_TAG_packed_type
:
8108 return "DW_TAG_packed_type";
8109 case DW_TAG_subprogram
:
8110 return "DW_TAG_subprogram";
8111 case DW_TAG_template_type_param
:
8112 return "DW_TAG_template_type_param";
8113 case DW_TAG_template_value_param
:
8114 return "DW_TAG_template_value_param";
8115 case DW_TAG_thrown_type
:
8116 return "DW_TAG_thrown_type";
8117 case DW_TAG_try_block
:
8118 return "DW_TAG_try_block";
8119 case DW_TAG_variant_part
:
8120 return "DW_TAG_variant_part";
8121 case DW_TAG_variable
:
8122 return "DW_TAG_variable";
8123 case DW_TAG_volatile_type
:
8124 return "DW_TAG_volatile_type";
8125 case DW_TAG_dwarf_procedure
:
8126 return "DW_TAG_dwarf_procedure";
8127 case DW_TAG_restrict_type
:
8128 return "DW_TAG_restrict_type";
8129 case DW_TAG_interface_type
:
8130 return "DW_TAG_interface_type";
8131 case DW_TAG_namespace
:
8132 return "DW_TAG_namespace";
8133 case DW_TAG_imported_module
:
8134 return "DW_TAG_imported_module";
8135 case DW_TAG_unspecified_type
:
8136 return "DW_TAG_unspecified_type";
8137 case DW_TAG_partial_unit
:
8138 return "DW_TAG_partial_unit";
8139 case DW_TAG_imported_unit
:
8140 return "DW_TAG_imported_unit";
8141 case DW_TAG_condition
:
8142 return "DW_TAG_condition";
8143 case DW_TAG_shared_type
:
8144 return "DW_TAG_shared_type";
8145 case DW_TAG_MIPS_loop
:
8146 return "DW_TAG_MIPS_loop";
8147 case DW_TAG_HP_array_descriptor
:
8148 return "DW_TAG_HP_array_descriptor";
8149 case DW_TAG_format_label
:
8150 return "DW_TAG_format_label";
8151 case DW_TAG_function_template
:
8152 return "DW_TAG_function_template";
8153 case DW_TAG_class_template
:
8154 return "DW_TAG_class_template";
8155 case DW_TAG_GNU_BINCL
:
8156 return "DW_TAG_GNU_BINCL";
8157 case DW_TAG_GNU_EINCL
:
8158 return "DW_TAG_GNU_EINCL";
8159 case DW_TAG_upc_shared_type
:
8160 return "DW_TAG_upc_shared_type";
8161 case DW_TAG_upc_strict_type
:
8162 return "DW_TAG_upc_strict_type";
8163 case DW_TAG_upc_relaxed_type
:
8164 return "DW_TAG_upc_relaxed_type";
8165 case DW_TAG_PGI_kanji_type
:
8166 return "DW_TAG_PGI_kanji_type";
8167 case DW_TAG_PGI_interface_block
:
8168 return "DW_TAG_PGI_interface_block";
8170 return "DW_TAG_<unknown>";
8174 /* Convert a DWARF attribute code into its string name. */
8177 dwarf_attr_name (unsigned attr
)
8182 return "DW_AT_sibling";
8183 case DW_AT_location
:
8184 return "DW_AT_location";
8186 return "DW_AT_name";
8187 case DW_AT_ordering
:
8188 return "DW_AT_ordering";
8189 case DW_AT_subscr_data
:
8190 return "DW_AT_subscr_data";
8191 case DW_AT_byte_size
:
8192 return "DW_AT_byte_size";
8193 case DW_AT_bit_offset
:
8194 return "DW_AT_bit_offset";
8195 case DW_AT_bit_size
:
8196 return "DW_AT_bit_size";
8197 case DW_AT_element_list
:
8198 return "DW_AT_element_list";
8199 case DW_AT_stmt_list
:
8200 return "DW_AT_stmt_list";
8202 return "DW_AT_low_pc";
8204 return "DW_AT_high_pc";
8205 case DW_AT_language
:
8206 return "DW_AT_language";
8208 return "DW_AT_member";
8210 return "DW_AT_discr";
8211 case DW_AT_discr_value
:
8212 return "DW_AT_discr_value";
8213 case DW_AT_visibility
:
8214 return "DW_AT_visibility";
8216 return "DW_AT_import";
8217 case DW_AT_string_length
:
8218 return "DW_AT_string_length";
8219 case DW_AT_common_reference
:
8220 return "DW_AT_common_reference";
8221 case DW_AT_comp_dir
:
8222 return "DW_AT_comp_dir";
8223 case DW_AT_const_value
:
8224 return "DW_AT_const_value";
8225 case DW_AT_containing_type
:
8226 return "DW_AT_containing_type";
8227 case DW_AT_default_value
:
8228 return "DW_AT_default_value";
8230 return "DW_AT_inline";
8231 case DW_AT_is_optional
:
8232 return "DW_AT_is_optional";
8233 case DW_AT_lower_bound
:
8234 return "DW_AT_lower_bound";
8235 case DW_AT_producer
:
8236 return "DW_AT_producer";
8237 case DW_AT_prototyped
:
8238 return "DW_AT_prototyped";
8239 case DW_AT_return_addr
:
8240 return "DW_AT_return_addr";
8241 case DW_AT_start_scope
:
8242 return "DW_AT_start_scope";
8243 case DW_AT_bit_stride
:
8244 return "DW_AT_bit_stride";
8245 case DW_AT_upper_bound
:
8246 return "DW_AT_upper_bound";
8247 case DW_AT_abstract_origin
:
8248 return "DW_AT_abstract_origin";
8249 case DW_AT_accessibility
:
8250 return "DW_AT_accessibility";
8251 case DW_AT_address_class
:
8252 return "DW_AT_address_class";
8253 case DW_AT_artificial
:
8254 return "DW_AT_artificial";
8255 case DW_AT_base_types
:
8256 return "DW_AT_base_types";
8257 case DW_AT_calling_convention
:
8258 return "DW_AT_calling_convention";
8260 return "DW_AT_count";
8261 case DW_AT_data_member_location
:
8262 return "DW_AT_data_member_location";
8263 case DW_AT_decl_column
:
8264 return "DW_AT_decl_column";
8265 case DW_AT_decl_file
:
8266 return "DW_AT_decl_file";
8267 case DW_AT_decl_line
:
8268 return "DW_AT_decl_line";
8269 case DW_AT_declaration
:
8270 return "DW_AT_declaration";
8271 case DW_AT_discr_list
:
8272 return "DW_AT_discr_list";
8273 case DW_AT_encoding
:
8274 return "DW_AT_encoding";
8275 case DW_AT_external
:
8276 return "DW_AT_external";
8277 case DW_AT_frame_base
:
8278 return "DW_AT_frame_base";
8280 return "DW_AT_friend";
8281 case DW_AT_identifier_case
:
8282 return "DW_AT_identifier_case";
8283 case DW_AT_macro_info
:
8284 return "DW_AT_macro_info";
8285 case DW_AT_namelist_items
:
8286 return "DW_AT_namelist_items";
8287 case DW_AT_priority
:
8288 return "DW_AT_priority";
8290 return "DW_AT_segment";
8291 case DW_AT_specification
:
8292 return "DW_AT_specification";
8293 case DW_AT_static_link
:
8294 return "DW_AT_static_link";
8296 return "DW_AT_type";
8297 case DW_AT_use_location
:
8298 return "DW_AT_use_location";
8299 case DW_AT_variable_parameter
:
8300 return "DW_AT_variable_parameter";
8301 case DW_AT_virtuality
:
8302 return "DW_AT_virtuality";
8303 case DW_AT_vtable_elem_location
:
8304 return "DW_AT_vtable_elem_location";
8305 /* DWARF 3 values. */
8306 case DW_AT_allocated
:
8307 return "DW_AT_allocated";
8308 case DW_AT_associated
:
8309 return "DW_AT_associated";
8310 case DW_AT_data_location
:
8311 return "DW_AT_data_location";
8312 case DW_AT_byte_stride
:
8313 return "DW_AT_byte_stride";
8314 case DW_AT_entry_pc
:
8315 return "DW_AT_entry_pc";
8316 case DW_AT_use_UTF8
:
8317 return "DW_AT_use_UTF8";
8318 case DW_AT_extension
:
8319 return "DW_AT_extension";
8321 return "DW_AT_ranges";
8322 case DW_AT_trampoline
:
8323 return "DW_AT_trampoline";
8324 case DW_AT_call_column
:
8325 return "DW_AT_call_column";
8326 case DW_AT_call_file
:
8327 return "DW_AT_call_file";
8328 case DW_AT_call_line
:
8329 return "DW_AT_call_line";
8330 case DW_AT_description
:
8331 return "DW_AT_description";
8332 case DW_AT_binary_scale
:
8333 return "DW_AT_binary_scale";
8334 case DW_AT_decimal_scale
:
8335 return "DW_AT_decimal_scale";
8337 return "DW_AT_small";
8338 case DW_AT_decimal_sign
:
8339 return "DW_AT_decimal_sign";
8340 case DW_AT_digit_count
:
8341 return "DW_AT_digit_count";
8342 case DW_AT_picture_string
:
8343 return "DW_AT_picture_string";
8345 return "DW_AT_mutable";
8346 case DW_AT_threads_scaled
:
8347 return "DW_AT_threads_scaled";
8348 case DW_AT_explicit
:
8349 return "DW_AT_explicit";
8350 case DW_AT_object_pointer
:
8351 return "DW_AT_object_pointer";
8352 case DW_AT_endianity
:
8353 return "DW_AT_endianity";
8354 case DW_AT_elemental
:
8355 return "DW_AT_elemental";
8357 return "DW_AT_pure";
8358 case DW_AT_recursive
:
8359 return "DW_AT_recursive";
8361 /* SGI/MIPS extensions. */
8362 case DW_AT_MIPS_fde
:
8363 return "DW_AT_MIPS_fde";
8364 case DW_AT_MIPS_loop_begin
:
8365 return "DW_AT_MIPS_loop_begin";
8366 case DW_AT_MIPS_tail_loop_begin
:
8367 return "DW_AT_MIPS_tail_loop_begin";
8368 case DW_AT_MIPS_epilog_begin
:
8369 return "DW_AT_MIPS_epilog_begin";
8370 case DW_AT_MIPS_loop_unroll_factor
:
8371 return "DW_AT_MIPS_loop_unroll_factor";
8372 case DW_AT_MIPS_software_pipeline_depth
:
8373 return "DW_AT_MIPS_software_pipeline_depth";
8374 case DW_AT_MIPS_linkage_name
:
8375 return "DW_AT_MIPS_linkage_name";
8376 case DW_AT_MIPS_stride
:
8377 return "DW_AT_MIPS_stride";
8378 case DW_AT_MIPS_abstract_name
:
8379 return "DW_AT_MIPS_abstract_name";
8380 case DW_AT_MIPS_clone_origin
:
8381 return "DW_AT_MIPS_clone_origin";
8382 case DW_AT_MIPS_has_inlines
:
8383 return "DW_AT_MIPS_has_inlines";
8385 /* HP extensions. */
8386 case DW_AT_HP_block_index
:
8387 return "DW_AT_HP_block_index";
8388 case DW_AT_HP_unmodifiable
:
8389 return "DW_AT_HP_unmodifiable";
8390 case DW_AT_HP_actuals_stmt_list
:
8391 return "DW_AT_HP_actuals_stmt_list";
8392 case DW_AT_HP_proc_per_section
:
8393 return "DW_AT_HP_proc_per_section";
8394 case DW_AT_HP_raw_data_ptr
:
8395 return "DW_AT_HP_raw_data_ptr";
8396 case DW_AT_HP_pass_by_reference
:
8397 return "DW_AT_HP_pass_by_reference";
8398 case DW_AT_HP_opt_level
:
8399 return "DW_AT_HP_opt_level";
8400 case DW_AT_HP_prof_version_id
:
8401 return "DW_AT_HP_prof_version_id";
8402 case DW_AT_HP_opt_flags
:
8403 return "DW_AT_HP_opt_flags";
8404 case DW_AT_HP_cold_region_low_pc
:
8405 return "DW_AT_HP_cold_region_low_pc";
8406 case DW_AT_HP_cold_region_high_pc
:
8407 return "DW_AT_HP_cold_region_high_pc";
8408 case DW_AT_HP_all_variables_modifiable
:
8409 return "DW_AT_HP_all_variables_modifiable";
8410 case DW_AT_HP_linkage_name
:
8411 return "DW_AT_HP_linkage_name";
8412 case DW_AT_HP_prof_flags
:
8413 return "DW_AT_HP_prof_flags";
8414 /* GNU extensions. */
8415 case DW_AT_sf_names
:
8416 return "DW_AT_sf_names";
8417 case DW_AT_src_info
:
8418 return "DW_AT_src_info";
8419 case DW_AT_mac_info
:
8420 return "DW_AT_mac_info";
8421 case DW_AT_src_coords
:
8422 return "DW_AT_src_coords";
8423 case DW_AT_body_begin
:
8424 return "DW_AT_body_begin";
8425 case DW_AT_body_end
:
8426 return "DW_AT_body_end";
8427 case DW_AT_GNU_vector
:
8428 return "DW_AT_GNU_vector";
8429 /* VMS extensions. */
8430 case DW_AT_VMS_rtnbeg_pd_address
:
8431 return "DW_AT_VMS_rtnbeg_pd_address";
8432 /* UPC extension. */
8433 case DW_AT_upc_threads_scaled
:
8434 return "DW_AT_upc_threads_scaled";
8435 /* PGI (STMicroelectronics) extensions. */
8436 case DW_AT_PGI_lbase
:
8437 return "DW_AT_PGI_lbase";
8438 case DW_AT_PGI_soffset
:
8439 return "DW_AT_PGI_soffset";
8440 case DW_AT_PGI_lstride
:
8441 return "DW_AT_PGI_lstride";
8443 return "DW_AT_<unknown>";
8447 /* Convert a DWARF value form code into its string name. */
8450 dwarf_form_name (unsigned form
)
8455 return "DW_FORM_addr";
8456 case DW_FORM_block2
:
8457 return "DW_FORM_block2";
8458 case DW_FORM_block4
:
8459 return "DW_FORM_block4";
8461 return "DW_FORM_data2";
8463 return "DW_FORM_data4";
8465 return "DW_FORM_data8";
8466 case DW_FORM_string
:
8467 return "DW_FORM_string";
8469 return "DW_FORM_block";
8470 case DW_FORM_block1
:
8471 return "DW_FORM_block1";
8473 return "DW_FORM_data1";
8475 return "DW_FORM_flag";
8477 return "DW_FORM_sdata";
8479 return "DW_FORM_strp";
8481 return "DW_FORM_udata";
8482 case DW_FORM_ref_addr
:
8483 return "DW_FORM_ref_addr";
8485 return "DW_FORM_ref1";
8487 return "DW_FORM_ref2";
8489 return "DW_FORM_ref4";
8491 return "DW_FORM_ref8";
8492 case DW_FORM_ref_udata
:
8493 return "DW_FORM_ref_udata";
8494 case DW_FORM_indirect
:
8495 return "DW_FORM_indirect";
8497 return "DW_FORM_<unknown>";
8501 /* Convert a DWARF stack opcode into its string name. */
8504 dwarf_stack_op_name (unsigned op
)
8509 return "DW_OP_addr";
8511 return "DW_OP_deref";
8513 return "DW_OP_const1u";
8515 return "DW_OP_const1s";
8517 return "DW_OP_const2u";
8519 return "DW_OP_const2s";
8521 return "DW_OP_const4u";
8523 return "DW_OP_const4s";
8525 return "DW_OP_const8u";
8527 return "DW_OP_const8s";
8529 return "DW_OP_constu";
8531 return "DW_OP_consts";
8535 return "DW_OP_drop";
8537 return "DW_OP_over";
8539 return "DW_OP_pick";
8541 return "DW_OP_swap";
8545 return "DW_OP_xderef";
8553 return "DW_OP_minus";
8565 return "DW_OP_plus";
8566 case DW_OP_plus_uconst
:
8567 return "DW_OP_plus_uconst";
8573 return "DW_OP_shra";
8591 return "DW_OP_skip";
8593 return "DW_OP_lit0";
8595 return "DW_OP_lit1";
8597 return "DW_OP_lit2";
8599 return "DW_OP_lit3";
8601 return "DW_OP_lit4";
8603 return "DW_OP_lit5";
8605 return "DW_OP_lit6";
8607 return "DW_OP_lit7";
8609 return "DW_OP_lit8";
8611 return "DW_OP_lit9";
8613 return "DW_OP_lit10";
8615 return "DW_OP_lit11";
8617 return "DW_OP_lit12";
8619 return "DW_OP_lit13";
8621 return "DW_OP_lit14";
8623 return "DW_OP_lit15";
8625 return "DW_OP_lit16";
8627 return "DW_OP_lit17";
8629 return "DW_OP_lit18";
8631 return "DW_OP_lit19";
8633 return "DW_OP_lit20";
8635 return "DW_OP_lit21";
8637 return "DW_OP_lit22";
8639 return "DW_OP_lit23";
8641 return "DW_OP_lit24";
8643 return "DW_OP_lit25";
8645 return "DW_OP_lit26";
8647 return "DW_OP_lit27";
8649 return "DW_OP_lit28";
8651 return "DW_OP_lit29";
8653 return "DW_OP_lit30";
8655 return "DW_OP_lit31";
8657 return "DW_OP_reg0";
8659 return "DW_OP_reg1";
8661 return "DW_OP_reg2";
8663 return "DW_OP_reg3";
8665 return "DW_OP_reg4";
8667 return "DW_OP_reg5";
8669 return "DW_OP_reg6";
8671 return "DW_OP_reg7";
8673 return "DW_OP_reg8";
8675 return "DW_OP_reg9";
8677 return "DW_OP_reg10";
8679 return "DW_OP_reg11";
8681 return "DW_OP_reg12";
8683 return "DW_OP_reg13";
8685 return "DW_OP_reg14";
8687 return "DW_OP_reg15";
8689 return "DW_OP_reg16";
8691 return "DW_OP_reg17";
8693 return "DW_OP_reg18";
8695 return "DW_OP_reg19";
8697 return "DW_OP_reg20";
8699 return "DW_OP_reg21";
8701 return "DW_OP_reg22";
8703 return "DW_OP_reg23";
8705 return "DW_OP_reg24";
8707 return "DW_OP_reg25";
8709 return "DW_OP_reg26";
8711 return "DW_OP_reg27";
8713 return "DW_OP_reg28";
8715 return "DW_OP_reg29";
8717 return "DW_OP_reg30";
8719 return "DW_OP_reg31";
8721 return "DW_OP_breg0";
8723 return "DW_OP_breg1";
8725 return "DW_OP_breg2";
8727 return "DW_OP_breg3";
8729 return "DW_OP_breg4";
8731 return "DW_OP_breg5";
8733 return "DW_OP_breg6";
8735 return "DW_OP_breg7";
8737 return "DW_OP_breg8";
8739 return "DW_OP_breg9";
8741 return "DW_OP_breg10";
8743 return "DW_OP_breg11";
8745 return "DW_OP_breg12";
8747 return "DW_OP_breg13";
8749 return "DW_OP_breg14";
8751 return "DW_OP_breg15";
8753 return "DW_OP_breg16";
8755 return "DW_OP_breg17";
8757 return "DW_OP_breg18";
8759 return "DW_OP_breg19";
8761 return "DW_OP_breg20";
8763 return "DW_OP_breg21";
8765 return "DW_OP_breg22";
8767 return "DW_OP_breg23";
8769 return "DW_OP_breg24";
8771 return "DW_OP_breg25";
8773 return "DW_OP_breg26";
8775 return "DW_OP_breg27";
8777 return "DW_OP_breg28";
8779 return "DW_OP_breg29";
8781 return "DW_OP_breg30";
8783 return "DW_OP_breg31";
8785 return "DW_OP_regx";
8787 return "DW_OP_fbreg";
8789 return "DW_OP_bregx";
8791 return "DW_OP_piece";
8792 case DW_OP_deref_size
:
8793 return "DW_OP_deref_size";
8794 case DW_OP_xderef_size
:
8795 return "DW_OP_xderef_size";
8798 /* DWARF 3 extensions. */
8799 case DW_OP_push_object_address
:
8800 return "DW_OP_push_object_address";
8802 return "DW_OP_call2";
8804 return "DW_OP_call4";
8805 case DW_OP_call_ref
:
8806 return "DW_OP_call_ref";
8807 /* GNU extensions. */
8808 case DW_OP_form_tls_address
:
8809 return "DW_OP_form_tls_address";
8810 case DW_OP_call_frame_cfa
:
8811 return "DW_OP_call_frame_cfa";
8812 case DW_OP_bit_piece
:
8813 return "DW_OP_bit_piece";
8814 case DW_OP_GNU_push_tls_address
:
8815 return "DW_OP_GNU_push_tls_address";
8816 case DW_OP_GNU_uninit
:
8817 return "DW_OP_GNU_uninit";
8818 /* HP extensions. */
8819 case DW_OP_HP_is_value
:
8820 return "DW_OP_HP_is_value";
8821 case DW_OP_HP_fltconst4
:
8822 return "DW_OP_HP_fltconst4";
8823 case DW_OP_HP_fltconst8
:
8824 return "DW_OP_HP_fltconst8";
8825 case DW_OP_HP_mod_range
:
8826 return "DW_OP_HP_mod_range";
8827 case DW_OP_HP_unmod_range
:
8828 return "DW_OP_HP_unmod_range";
8830 return "DW_OP_HP_tls";
8832 return "OP_<unknown>";
8837 dwarf_bool_name (unsigned mybool
)
8845 /* Convert a DWARF type code into its string name. */
8848 dwarf_type_encoding_name (unsigned enc
)
8853 return "DW_ATE_void";
8854 case DW_ATE_address
:
8855 return "DW_ATE_address";
8856 case DW_ATE_boolean
:
8857 return "DW_ATE_boolean";
8858 case DW_ATE_complex_float
:
8859 return "DW_ATE_complex_float";
8861 return "DW_ATE_float";
8863 return "DW_ATE_signed";
8864 case DW_ATE_signed_char
:
8865 return "DW_ATE_signed_char";
8866 case DW_ATE_unsigned
:
8867 return "DW_ATE_unsigned";
8868 case DW_ATE_unsigned_char
:
8869 return "DW_ATE_unsigned_char";
8871 case DW_ATE_imaginary_float
:
8872 return "DW_ATE_imaginary_float";
8873 case DW_ATE_packed_decimal
:
8874 return "DW_ATE_packed_decimal";
8875 case DW_ATE_numeric_string
:
8876 return "DW_ATE_numeric_string";
8878 return "DW_ATE_edited";
8879 case DW_ATE_signed_fixed
:
8880 return "DW_ATE_signed_fixed";
8881 case DW_ATE_unsigned_fixed
:
8882 return "DW_ATE_unsigned_fixed";
8883 case DW_ATE_decimal_float
:
8884 return "DW_ATE_decimal_float";
8885 /* HP extensions. */
8886 case DW_ATE_HP_float80
:
8887 return "DW_ATE_HP_float80";
8888 case DW_ATE_HP_complex_float80
:
8889 return "DW_ATE_HP_complex_float80";
8890 case DW_ATE_HP_float128
:
8891 return "DW_ATE_HP_float128";
8892 case DW_ATE_HP_complex_float128
:
8893 return "DW_ATE_HP_complex_float128";
8894 case DW_ATE_HP_floathpintel
:
8895 return "DW_ATE_HP_floathpintel";
8896 case DW_ATE_HP_imaginary_float80
:
8897 return "DW_ATE_HP_imaginary_float80";
8898 case DW_ATE_HP_imaginary_float128
:
8899 return "DW_ATE_HP_imaginary_float128";
8901 return "DW_ATE_<unknown>";
8905 /* Convert a DWARF call frame info operation to its string name. */
8909 dwarf_cfi_name (unsigned cfi_opc
)
8913 case DW_CFA_advance_loc
:
8914 return "DW_CFA_advance_loc";
8916 return "DW_CFA_offset";
8917 case DW_CFA_restore
:
8918 return "DW_CFA_restore";
8920 return "DW_CFA_nop";
8921 case DW_CFA_set_loc
:
8922 return "DW_CFA_set_loc";
8923 case DW_CFA_advance_loc1
:
8924 return "DW_CFA_advance_loc1";
8925 case DW_CFA_advance_loc2
:
8926 return "DW_CFA_advance_loc2";
8927 case DW_CFA_advance_loc4
:
8928 return "DW_CFA_advance_loc4";
8929 case DW_CFA_offset_extended
:
8930 return "DW_CFA_offset_extended";
8931 case DW_CFA_restore_extended
:
8932 return "DW_CFA_restore_extended";
8933 case DW_CFA_undefined
:
8934 return "DW_CFA_undefined";
8935 case DW_CFA_same_value
:
8936 return "DW_CFA_same_value";
8937 case DW_CFA_register
:
8938 return "DW_CFA_register";
8939 case DW_CFA_remember_state
:
8940 return "DW_CFA_remember_state";
8941 case DW_CFA_restore_state
:
8942 return "DW_CFA_restore_state";
8943 case DW_CFA_def_cfa
:
8944 return "DW_CFA_def_cfa";
8945 case DW_CFA_def_cfa_register
:
8946 return "DW_CFA_def_cfa_register";
8947 case DW_CFA_def_cfa_offset
:
8948 return "DW_CFA_def_cfa_offset";
8950 case DW_CFA_def_cfa_expression
:
8951 return "DW_CFA_def_cfa_expression";
8952 case DW_CFA_expression
:
8953 return "DW_CFA_expression";
8954 case DW_CFA_offset_extended_sf
:
8955 return "DW_CFA_offset_extended_sf";
8956 case DW_CFA_def_cfa_sf
:
8957 return "DW_CFA_def_cfa_sf";
8958 case DW_CFA_def_cfa_offset_sf
:
8959 return "DW_CFA_def_cfa_offset_sf";
8960 case DW_CFA_val_offset
:
8961 return "DW_CFA_val_offset";
8962 case DW_CFA_val_offset_sf
:
8963 return "DW_CFA_val_offset_sf";
8964 case DW_CFA_val_expression
:
8965 return "DW_CFA_val_expression";
8966 /* SGI/MIPS specific. */
8967 case DW_CFA_MIPS_advance_loc8
:
8968 return "DW_CFA_MIPS_advance_loc8";
8969 /* GNU extensions. */
8970 case DW_CFA_GNU_window_save
:
8971 return "DW_CFA_GNU_window_save";
8972 case DW_CFA_GNU_args_size
:
8973 return "DW_CFA_GNU_args_size";
8974 case DW_CFA_GNU_negative_offset_extended
:
8975 return "DW_CFA_GNU_negative_offset_extended";
8977 return "DW_CFA_<unknown>";
8983 dump_die (struct die_info
*die
)
8987 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
8988 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
8989 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
8990 dwarf_bool_name (die
->child
!= NULL
));
8992 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
8993 for (i
= 0; i
< die
->num_attrs
; ++i
)
8995 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
8996 dwarf_attr_name (die
->attrs
[i
].name
),
8997 dwarf_form_name (die
->attrs
[i
].form
));
8998 switch (die
->attrs
[i
].form
)
9000 case DW_FORM_ref_addr
:
9002 fprintf_unfiltered (gdb_stderr
, "address: ");
9003 fputs_filtered (paddress (DW_ADDR (&die
->attrs
[i
])), gdb_stderr
);
9005 case DW_FORM_block2
:
9006 case DW_FORM_block4
:
9008 case DW_FORM_block1
:
9009 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
9014 fprintf_unfiltered (gdb_stderr
, "constant ref: %ld (adjusted)",
9015 (long) (DW_ADDR (&die
->attrs
[i
])));
9023 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
9025 case DW_FORM_string
:
9027 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
9028 DW_STRING (&die
->attrs
[i
])
9029 ? DW_STRING (&die
->attrs
[i
]) : "");
9032 if (DW_UNSND (&die
->attrs
[i
]))
9033 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
9035 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
9037 case DW_FORM_indirect
:
9038 /* the reader will have reduced the indirect form to
9039 the "base form" so this form should not occur */
9040 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
9043 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
9044 die
->attrs
[i
].form
);
9046 fprintf_unfiltered (gdb_stderr
, "\n");
9051 dump_die_list (struct die_info
*die
)
9056 if (die
->child
!= NULL
)
9057 dump_die_list (die
->child
);
9058 if (die
->sibling
!= NULL
)
9059 dump_die_list (die
->sibling
);
9064 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
9068 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
9074 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
9076 unsigned int result
= 0;
9080 case DW_FORM_ref_addr
:
9085 case DW_FORM_ref_udata
:
9086 result
= DW_ADDR (attr
);
9089 complaint (&symfile_complaints
,
9090 _("unsupported die ref attribute form: '%s'"),
9091 dwarf_form_name (attr
->form
));
9096 /* Return the constant value held by the given attribute. Return -1
9097 if the value held by the attribute is not constant. */
9100 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
9102 if (attr
->form
== DW_FORM_sdata
)
9103 return DW_SND (attr
);
9104 else if (attr
->form
== DW_FORM_udata
9105 || attr
->form
== DW_FORM_data1
9106 || attr
->form
== DW_FORM_data2
9107 || attr
->form
== DW_FORM_data4
9108 || attr
->form
== DW_FORM_data8
)
9109 return DW_UNSND (attr
);
9112 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
9113 dwarf_form_name (attr
->form
));
9114 return default_value
;
9118 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
9119 unit and add it to our queue. */
9122 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
9123 struct dwarf2_per_cu_data
*per_cu
)
9125 /* Mark the dependence relation so that we don't flush PER_CU
9127 dwarf2_add_dependence (this_cu
, per_cu
);
9129 /* If it's already on the queue, we have nothing to do. */
9133 /* If the compilation unit is already loaded, just mark it as
9135 if (per_cu
->cu
!= NULL
)
9137 per_cu
->cu
->last_used
= 0;
9141 /* Add it to the queue. */
9142 queue_comp_unit (per_cu
, this_cu
->objfile
);
9145 static struct die_info
*
9146 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
9147 struct dwarf2_cu
**ref_cu
)
9149 struct die_info
*die
;
9150 unsigned int offset
;
9151 struct die_info temp_die
;
9152 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
9154 offset
= dwarf2_get_ref_die_offset (attr
, cu
);
9156 if (DW_ADDR (attr
) < cu
->header
.offset
9157 || DW_ADDR (attr
) >= cu
->header
.offset
+ cu
->header
.length
)
9159 struct dwarf2_per_cu_data
*per_cu
;
9160 per_cu
= dwarf2_find_containing_comp_unit (DW_ADDR (attr
),
9163 /* If necessary, add it to the queue and load its DIEs. */
9164 maybe_queue_comp_unit (cu
, per_cu
);
9166 target_cu
= per_cu
->cu
;
9171 *ref_cu
= target_cu
;
9172 temp_die
.offset
= offset
;
9173 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
9177 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
9178 "at 0x%lx [in module %s]"),
9179 (long) offset
, (long) src_die
->offset
, cu
->objfile
->name
);
9182 /* Decode simple location descriptions.
9183 Given a pointer to a dwarf block that defines a location, compute
9184 the location and return the value.
9186 NOTE drow/2003-11-18: This function is called in two situations
9187 now: for the address of static or global variables (partial symbols
9188 only) and for offsets into structures which are expected to be
9189 (more or less) constant. The partial symbol case should go away,
9190 and only the constant case should remain. That will let this
9191 function complain more accurately. A few special modes are allowed
9192 without complaint for global variables (for instance, global
9193 register values and thread-local values).
9195 A location description containing no operations indicates that the
9196 object is optimized out. The return value is 0 for that case.
9197 FIXME drow/2003-11-16: No callers check for this case any more; soon all
9198 callers will only want a very basic result and this can become a
9201 Note that stack[0] is unused except as a default error return.
9202 Note that stack overflow is not yet handled. */
9205 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
9207 struct objfile
*objfile
= cu
->objfile
;
9208 struct comp_unit_head
*cu_header
= &cu
->header
;
9210 int size
= blk
->size
;
9211 gdb_byte
*data
= blk
->data
;
9212 CORE_ADDR stack
[64];
9214 unsigned int bytes_read
, unsnd
;
9258 stack
[++stacki
] = op
- DW_OP_lit0
;
9293 stack
[++stacki
] = op
- DW_OP_reg0
;
9295 dwarf2_complex_location_expr_complaint ();
9299 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9301 stack
[++stacki
] = unsnd
;
9303 dwarf2_complex_location_expr_complaint ();
9307 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
9313 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
9318 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
9323 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
9328 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
9333 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
9338 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
9343 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
9349 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
9354 stack
[stacki
+ 1] = stack
[stacki
];
9359 stack
[stacki
- 1] += stack
[stacki
];
9363 case DW_OP_plus_uconst
:
9364 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9369 stack
[stacki
- 1] -= stack
[stacki
];
9374 /* If we're not the last op, then we definitely can't encode
9375 this using GDB's address_class enum. This is valid for partial
9376 global symbols, although the variable's address will be bogus
9379 dwarf2_complex_location_expr_complaint ();
9382 case DW_OP_GNU_push_tls_address
:
9383 /* The top of the stack has the offset from the beginning
9384 of the thread control block at which the variable is located. */
9385 /* Nothing should follow this operator, so the top of stack would
9387 /* This is valid for partial global symbols, but the variable's
9388 address will be bogus in the psymtab. */
9390 dwarf2_complex_location_expr_complaint ();
9393 case DW_OP_GNU_uninit
:
9397 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
9398 dwarf_stack_op_name (op
));
9399 return (stack
[stacki
]);
9402 return (stack
[stacki
]);
9405 /* memory allocation interface */
9407 static struct dwarf_block
*
9408 dwarf_alloc_block (struct dwarf2_cu
*cu
)
9410 struct dwarf_block
*blk
;
9412 blk
= (struct dwarf_block
*)
9413 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
9417 static struct abbrev_info
*
9418 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
9420 struct abbrev_info
*abbrev
;
9422 abbrev
= (struct abbrev_info
*)
9423 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
9424 memset (abbrev
, 0, sizeof (struct abbrev_info
));
9428 static struct die_info
*
9429 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
9431 struct die_info
*die
;
9432 size_t size
= sizeof (struct die_info
);
9435 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
9437 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
9438 memset (die
, 0, sizeof (struct die_info
));
9443 /* Macro support. */
9446 /* Return the full name of file number I in *LH's file name table.
9447 Use COMP_DIR as the name of the current directory of the
9448 compilation. The result is allocated using xmalloc; the caller is
9449 responsible for freeing it. */
9451 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
9453 /* Is the file number a valid index into the line header's file name
9454 table? Remember that file numbers start with one, not zero. */
9455 if (1 <= file
&& file
<= lh
->num_file_names
)
9457 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9459 if (IS_ABSOLUTE_PATH (fe
->name
))
9460 return xstrdup (fe
->name
);
9468 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9474 dir_len
= strlen (dir
);
9475 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
9476 strcpy (full_name
, dir
);
9477 full_name
[dir_len
] = '/';
9478 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
9482 return xstrdup (fe
->name
);
9487 /* The compiler produced a bogus file number. We can at least
9488 record the macro definitions made in the file, even if we
9489 won't be able to find the file by name. */
9491 sprintf (fake_name
, "<bad macro file number %d>", file
);
9493 complaint (&symfile_complaints
,
9494 _("bad file number in macro information (%d)"),
9497 return xstrdup (fake_name
);
9502 static struct macro_source_file
*
9503 macro_start_file (int file
, int line
,
9504 struct macro_source_file
*current_file
,
9505 const char *comp_dir
,
9506 struct line_header
*lh
, struct objfile
*objfile
)
9508 /* The full name of this source file. */
9509 char *full_name
= file_full_name (file
, lh
, comp_dir
);
9511 /* We don't create a macro table for this compilation unit
9512 at all until we actually get a filename. */
9513 if (! pending_macros
)
9514 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
9515 objfile
->macro_cache
);
9518 /* If we have no current file, then this must be the start_file
9519 directive for the compilation unit's main source file. */
9520 current_file
= macro_set_main (pending_macros
, full_name
);
9522 current_file
= macro_include (current_file
, line
, full_name
);
9526 return current_file
;
9530 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
9531 followed by a null byte. */
9533 copy_string (const char *buf
, int len
)
9535 char *s
= xmalloc (len
+ 1);
9536 memcpy (s
, buf
, len
);
9544 consume_improper_spaces (const char *p
, const char *body
)
9548 complaint (&symfile_complaints
,
9549 _("macro definition contains spaces in formal argument list:\n`%s'"),
9561 parse_macro_definition (struct macro_source_file
*file
, int line
,
9566 /* The body string takes one of two forms. For object-like macro
9567 definitions, it should be:
9569 <macro name> " " <definition>
9571 For function-like macro definitions, it should be:
9573 <macro name> "() " <definition>
9575 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
9577 Spaces may appear only where explicitly indicated, and in the
9580 The Dwarf 2 spec says that an object-like macro's name is always
9581 followed by a space, but versions of GCC around March 2002 omit
9582 the space when the macro's definition is the empty string.
9584 The Dwarf 2 spec says that there should be no spaces between the
9585 formal arguments in a function-like macro's formal argument list,
9586 but versions of GCC around March 2002 include spaces after the
9590 /* Find the extent of the macro name. The macro name is terminated
9591 by either a space or null character (for an object-like macro) or
9592 an opening paren (for a function-like macro). */
9593 for (p
= body
; *p
; p
++)
9594 if (*p
== ' ' || *p
== '(')
9597 if (*p
== ' ' || *p
== '\0')
9599 /* It's an object-like macro. */
9600 int name_len
= p
- body
;
9601 char *name
= copy_string (body
, name_len
);
9602 const char *replacement
;
9605 replacement
= body
+ name_len
+ 1;
9608 dwarf2_macro_malformed_definition_complaint (body
);
9609 replacement
= body
+ name_len
;
9612 macro_define_object (file
, line
, name
, replacement
);
9618 /* It's a function-like macro. */
9619 char *name
= copy_string (body
, p
- body
);
9622 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
9626 p
= consume_improper_spaces (p
, body
);
9628 /* Parse the formal argument list. */
9629 while (*p
&& *p
!= ')')
9631 /* Find the extent of the current argument name. */
9632 const char *arg_start
= p
;
9634 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
9637 if (! *p
|| p
== arg_start
)
9638 dwarf2_macro_malformed_definition_complaint (body
);
9641 /* Make sure argv has room for the new argument. */
9642 if (argc
>= argv_size
)
9645 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
9648 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
9651 p
= consume_improper_spaces (p
, body
);
9653 /* Consume the comma, if present. */
9658 p
= consume_improper_spaces (p
, body
);
9667 /* Perfectly formed definition, no complaints. */
9668 macro_define_function (file
, line
, name
,
9669 argc
, (const char **) argv
,
9671 else if (*p
== '\0')
9673 /* Complain, but do define it. */
9674 dwarf2_macro_malformed_definition_complaint (body
);
9675 macro_define_function (file
, line
, name
,
9676 argc
, (const char **) argv
,
9680 /* Just complain. */
9681 dwarf2_macro_malformed_definition_complaint (body
);
9684 /* Just complain. */
9685 dwarf2_macro_malformed_definition_complaint (body
);
9691 for (i
= 0; i
< argc
; i
++)
9697 dwarf2_macro_malformed_definition_complaint (body
);
9702 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
9703 char *comp_dir
, bfd
*abfd
,
9704 struct dwarf2_cu
*cu
)
9706 gdb_byte
*mac_ptr
, *mac_end
;
9707 struct macro_source_file
*current_file
= 0;
9709 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
9711 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
9715 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
9716 mac_end
= dwarf2_per_objfile
->macinfo_buffer
9717 + dwarf2_per_objfile
->macinfo_size
;
9721 enum dwarf_macinfo_record_type macinfo_type
;
9723 /* Do we at least have room for a macinfo type byte? */
9724 if (mac_ptr
>= mac_end
)
9726 dwarf2_macros_too_long_complaint ();
9730 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
9733 switch (macinfo_type
)
9735 /* A zero macinfo type indicates the end of the macro
9740 case DW_MACINFO_define
:
9741 case DW_MACINFO_undef
:
9743 unsigned int bytes_read
;
9747 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9748 mac_ptr
+= bytes_read
;
9749 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
9750 mac_ptr
+= bytes_read
;
9753 complaint (&symfile_complaints
,
9754 _("debug info gives macro %s outside of any file: %s"),
9756 DW_MACINFO_define
? "definition" : macinfo_type
==
9757 DW_MACINFO_undef
? "undefinition" :
9758 "something-or-other", body
);
9761 if (macinfo_type
== DW_MACINFO_define
)
9762 parse_macro_definition (current_file
, line
, body
);
9763 else if (macinfo_type
== DW_MACINFO_undef
)
9764 macro_undef (current_file
, line
, body
);
9769 case DW_MACINFO_start_file
:
9771 unsigned int bytes_read
;
9774 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9775 mac_ptr
+= bytes_read
;
9776 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9777 mac_ptr
+= bytes_read
;
9779 current_file
= macro_start_file (file
, line
,
9780 current_file
, comp_dir
,
9785 case DW_MACINFO_end_file
:
9787 complaint (&symfile_complaints
,
9788 _("macro debug info has an unmatched `close_file' directive"));
9791 current_file
= current_file
->included_by
;
9794 enum dwarf_macinfo_record_type next_type
;
9796 /* GCC circa March 2002 doesn't produce the zero
9797 type byte marking the end of the compilation
9798 unit. Complain if it's not there, but exit no
9801 /* Do we at least have room for a macinfo type byte? */
9802 if (mac_ptr
>= mac_end
)
9804 dwarf2_macros_too_long_complaint ();
9808 /* We don't increment mac_ptr here, so this is just
9810 next_type
= read_1_byte (abfd
, mac_ptr
);
9812 complaint (&symfile_complaints
,
9813 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
9820 case DW_MACINFO_vendor_ext
:
9822 unsigned int bytes_read
;
9826 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9827 mac_ptr
+= bytes_read
;
9828 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
9829 mac_ptr
+= bytes_read
;
9831 /* We don't recognize any vendor extensions. */
9838 /* Check if the attribute's form is a DW_FORM_block*
9839 if so return true else false. */
9841 attr_form_is_block (struct attribute
*attr
)
9843 return (attr
== NULL
? 0 :
9844 attr
->form
== DW_FORM_block1
9845 || attr
->form
== DW_FORM_block2
9846 || attr
->form
== DW_FORM_block4
9847 || attr
->form
== DW_FORM_block
);
9850 /* Return non-zero if ATTR's value is a section offset --- classes
9851 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
9852 You may use DW_UNSND (attr) to retrieve such offsets.
9854 Section 7.5.4, "Attribute Encodings", explains that no attribute
9855 may have a value that belongs to more than one of these classes; it
9856 would be ambiguous if we did, because we use the same forms for all
9859 attr_form_is_section_offset (struct attribute
*attr
)
9861 return (attr
->form
== DW_FORM_data4
9862 || attr
->form
== DW_FORM_data8
);
9866 /* Return non-zero if ATTR's value falls in the 'constant' class, or
9867 zero otherwise. When this function returns true, you can apply
9868 dwarf2_get_attr_constant_value to it.
9870 However, note that for some attributes you must check
9871 attr_form_is_section_offset before using this test. DW_FORM_data4
9872 and DW_FORM_data8 are members of both the constant class, and of
9873 the classes that contain offsets into other debug sections
9874 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
9875 that, if an attribute's can be either a constant or one of the
9876 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
9877 taken as section offsets, not constants. */
9879 attr_form_is_constant (struct attribute
*attr
)
9896 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
9897 struct dwarf2_cu
*cu
)
9899 if (attr_form_is_section_offset (attr
)
9900 /* ".debug_loc" may not exist at all, or the offset may be outside
9901 the section. If so, fall through to the complaint in the
9903 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc_size
)
9905 struct dwarf2_loclist_baton
*baton
;
9907 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9908 sizeof (struct dwarf2_loclist_baton
));
9909 baton
->per_cu
= cu
->per_cu
;
9910 gdb_assert (baton
->per_cu
);
9912 /* We don't know how long the location list is, but make sure we
9913 don't run off the edge of the section. */
9914 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
9915 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
9916 baton
->base_address
= cu
->header
.base_address
;
9917 if (cu
->header
.base_known
== 0)
9918 complaint (&symfile_complaints
,
9919 _("Location list used without specifying the CU base address."));
9921 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
9922 SYMBOL_LOCATION_BATON (sym
) = baton
;
9926 struct dwarf2_locexpr_baton
*baton
;
9928 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9929 sizeof (struct dwarf2_locexpr_baton
));
9930 baton
->per_cu
= cu
->per_cu
;
9931 gdb_assert (baton
->per_cu
);
9933 if (attr_form_is_block (attr
))
9935 /* Note that we're just copying the block's data pointer
9936 here, not the actual data. We're still pointing into the
9937 info_buffer for SYM's objfile; right now we never release
9938 that buffer, but when we do clean up properly this may
9940 baton
->size
= DW_BLOCK (attr
)->size
;
9941 baton
->data
= DW_BLOCK (attr
)->data
;
9945 dwarf2_invalid_attrib_class_complaint ("location description",
9946 SYMBOL_NATURAL_NAME (sym
));
9951 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
9952 SYMBOL_LOCATION_BATON (sym
) = baton
;
9956 /* Return the OBJFILE associated with the compilation unit CU. */
9959 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
9961 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
9963 /* Return the master objfile, so that we can report and look up the
9964 correct file containing this variable. */
9965 if (objfile
->separate_debug_objfile_backlink
)
9966 objfile
= objfile
->separate_debug_objfile_backlink
;
9971 /* Return the address size given in the compilation unit header for CU. */
9974 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
9977 return per_cu
->cu
->header
.addr_size
;
9980 /* If the CU is not currently read in, we re-read its header. */
9981 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
9982 struct dwarf2_per_objfile
*per_objfile
9983 = objfile_data (objfile
, dwarf2_objfile_data_key
);
9984 gdb_byte
*info_ptr
= per_objfile
->info_buffer
+ per_cu
->offset
;
9986 struct comp_unit_head cu_header
;
9987 memset (&cu_header
, 0, sizeof cu_header
);
9988 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
9989 return cu_header
.addr_size
;
9993 /* Locate the compilation unit from CU's objfile which contains the
9994 DIE at OFFSET. Raises an error on failure. */
9996 static struct dwarf2_per_cu_data
*
9997 dwarf2_find_containing_comp_unit (unsigned long offset
,
9998 struct objfile
*objfile
)
10000 struct dwarf2_per_cu_data
*this_cu
;
10004 high
= dwarf2_per_objfile
->n_comp_units
- 1;
10007 int mid
= low
+ (high
- low
) / 2;
10008 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
10013 gdb_assert (low
== high
);
10014 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
10017 error (_("Dwarf Error: could not find partial DIE containing "
10018 "offset 0x%lx [in module %s]"),
10019 (long) offset
, bfd_get_filename (objfile
->obfd
));
10021 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
10022 return dwarf2_per_objfile
->all_comp_units
[low
-1];
10026 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
10027 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
10028 && offset
>= this_cu
->offset
+ this_cu
->length
)
10029 error (_("invalid dwarf2 offset %ld"), offset
);
10030 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
10035 /* Locate the compilation unit from OBJFILE which is located at exactly
10036 OFFSET. Raises an error on failure. */
10038 static struct dwarf2_per_cu_data
*
10039 dwarf2_find_comp_unit (unsigned long offset
, struct objfile
*objfile
)
10041 struct dwarf2_per_cu_data
*this_cu
;
10042 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10043 if (this_cu
->offset
!= offset
)
10044 error (_("no compilation unit with offset %ld."), offset
);
10048 /* Release one cached compilation unit, CU. We unlink it from the tree
10049 of compilation units, but we don't remove it from the read_in_chain;
10050 the caller is responsible for that. */
10053 free_one_comp_unit (void *data
)
10055 struct dwarf2_cu
*cu
= data
;
10057 if (cu
->per_cu
!= NULL
)
10058 cu
->per_cu
->cu
= NULL
;
10061 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10066 /* This cleanup function is passed the address of a dwarf2_cu on the stack
10067 when we're finished with it. We can't free the pointer itself, but be
10068 sure to unlink it from the cache. Also release any associated storage
10069 and perform cache maintenance.
10071 Only used during partial symbol parsing. */
10074 free_stack_comp_unit (void *data
)
10076 struct dwarf2_cu
*cu
= data
;
10078 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10079 cu
->partial_dies
= NULL
;
10081 if (cu
->per_cu
!= NULL
)
10083 /* This compilation unit is on the stack in our caller, so we
10084 should not xfree it. Just unlink it. */
10085 cu
->per_cu
->cu
= NULL
;
10088 /* If we had a per-cu pointer, then we may have other compilation
10089 units loaded, so age them now. */
10090 age_cached_comp_units ();
10094 /* Free all cached compilation units. */
10097 free_cached_comp_units (void *data
)
10099 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10101 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10102 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10103 while (per_cu
!= NULL
)
10105 struct dwarf2_per_cu_data
*next_cu
;
10107 next_cu
= per_cu
->cu
->read_in_chain
;
10109 free_one_comp_unit (per_cu
->cu
);
10110 *last_chain
= next_cu
;
10116 /* Increase the age counter on each cached compilation unit, and free
10117 any that are too old. */
10120 age_cached_comp_units (void)
10122 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10124 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
10125 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10126 while (per_cu
!= NULL
)
10128 per_cu
->cu
->last_used
++;
10129 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
10130 dwarf2_mark (per_cu
->cu
);
10131 per_cu
= per_cu
->cu
->read_in_chain
;
10134 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10135 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10136 while (per_cu
!= NULL
)
10138 struct dwarf2_per_cu_data
*next_cu
;
10140 next_cu
= per_cu
->cu
->read_in_chain
;
10142 if (!per_cu
->cu
->mark
)
10144 free_one_comp_unit (per_cu
->cu
);
10145 *last_chain
= next_cu
;
10148 last_chain
= &per_cu
->cu
->read_in_chain
;
10154 /* Remove a single compilation unit from the cache. */
10157 free_one_cached_comp_unit (void *target_cu
)
10159 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10161 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10162 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10163 while (per_cu
!= NULL
)
10165 struct dwarf2_per_cu_data
*next_cu
;
10167 next_cu
= per_cu
->cu
->read_in_chain
;
10169 if (per_cu
->cu
== target_cu
)
10171 free_one_comp_unit (per_cu
->cu
);
10172 *last_chain
= next_cu
;
10176 last_chain
= &per_cu
->cu
->read_in_chain
;
10182 /* Release all extra memory associated with OBJFILE. */
10185 dwarf2_free_objfile (struct objfile
*objfile
)
10187 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
10189 if (dwarf2_per_objfile
== NULL
)
10192 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
10193 free_cached_comp_units (NULL
);
10195 /* Everything else should be on the objfile obstack. */
10198 /* A pair of DIE offset and GDB type pointer. We store these
10199 in a hash table separate from the DIEs, and preserve them
10200 when the DIEs are flushed out of cache. */
10202 struct dwarf2_offset_and_type
10204 unsigned int offset
;
10208 /* Hash function for a dwarf2_offset_and_type. */
10211 offset_and_type_hash (const void *item
)
10213 const struct dwarf2_offset_and_type
*ofs
= item
;
10214 return ofs
->offset
;
10217 /* Equality function for a dwarf2_offset_and_type. */
10220 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
10222 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
10223 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
10224 return ofs_lhs
->offset
== ofs_rhs
->offset
;
10227 /* Set the type associated with DIE to TYPE. Save it in CU's hash
10228 table if necessary. For convenience, return TYPE. */
10230 static struct type
*
10231 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10233 struct dwarf2_offset_and_type
**slot
, ofs
;
10235 if (cu
->type_hash
== NULL
)
10237 gdb_assert (cu
->per_cu
!= NULL
);
10238 cu
->per_cu
->type_hash
10239 = htab_create_alloc_ex (cu
->header
.length
/ 24,
10240 offset_and_type_hash
,
10241 offset_and_type_eq
,
10243 &cu
->objfile
->objfile_obstack
,
10244 hashtab_obstack_allocate
,
10245 dummy_obstack_deallocate
);
10246 cu
->type_hash
= cu
->per_cu
->type_hash
;
10249 ofs
.offset
= die
->offset
;
10251 slot
= (struct dwarf2_offset_and_type
**)
10252 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
10253 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
10258 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
10259 not have a saved type. */
10261 static struct type
*
10262 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10264 struct dwarf2_offset_and_type
*slot
, ofs
;
10265 htab_t type_hash
= cu
->type_hash
;
10267 if (type_hash
== NULL
)
10270 ofs
.offset
= die
->offset
;
10271 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
10278 /* Set the mark field in CU and in every other compilation unit in the
10279 cache that we must keep because we are keeping CU. */
10281 /* Add a dependence relationship from CU to REF_PER_CU. */
10284 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
10285 struct dwarf2_per_cu_data
*ref_per_cu
)
10289 if (cu
->dependencies
== NULL
)
10291 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
10292 NULL
, &cu
->comp_unit_obstack
,
10293 hashtab_obstack_allocate
,
10294 dummy_obstack_deallocate
);
10296 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
10298 *slot
= ref_per_cu
;
10301 /* Set the mark field in CU and in every other compilation unit in the
10302 cache that we must keep because we are keeping CU. */
10305 dwarf2_mark_helper (void **slot
, void *data
)
10307 struct dwarf2_per_cu_data
*per_cu
;
10309 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
10310 if (per_cu
->cu
->mark
)
10312 per_cu
->cu
->mark
= 1;
10314 if (per_cu
->cu
->dependencies
!= NULL
)
10315 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10321 dwarf2_mark (struct dwarf2_cu
*cu
)
10326 if (cu
->dependencies
!= NULL
)
10327 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10331 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
10335 per_cu
->cu
->mark
= 0;
10336 per_cu
= per_cu
->cu
->read_in_chain
;
10340 /* Trivial hash function for partial_die_info: the hash value of a DIE
10341 is its offset in .debug_info for this objfile. */
10344 partial_die_hash (const void *item
)
10346 const struct partial_die_info
*part_die
= item
;
10347 return part_die
->offset
;
10350 /* Trivial comparison function for partial_die_info structures: two DIEs
10351 are equal if they have the same offset. */
10354 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
10356 const struct partial_die_info
*part_die_lhs
= item_lhs
;
10357 const struct partial_die_info
*part_die_rhs
= item_rhs
;
10358 return part_die_lhs
->offset
== part_die_rhs
->offset
;
10361 static struct cmd_list_element
*set_dwarf2_cmdlist
;
10362 static struct cmd_list_element
*show_dwarf2_cmdlist
;
10365 set_dwarf2_cmd (char *args
, int from_tty
)
10367 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
10371 show_dwarf2_cmd (char *args
, int from_tty
)
10373 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
10376 void _initialize_dwarf2_read (void);
10379 _initialize_dwarf2_read (void)
10381 dwarf2_objfile_data_key
= register_objfile_data ();
10383 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
10384 Set DWARF 2 specific variables.\n\
10385 Configure DWARF 2 variables such as the cache size"),
10386 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
10387 0/*allow-unknown*/, &maintenance_set_cmdlist
);
10389 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
10390 Show DWARF 2 specific variables\n\
10391 Show DWARF 2 variables such as the cache size"),
10392 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
10393 0/*allow-unknown*/, &maintenance_show_cmdlist
);
10395 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
10396 &dwarf2_max_cache_age
, _("\
10397 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
10398 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
10399 A higher limit means that cached compilation units will be stored\n\
10400 in memory longer, and more total memory will be used. Zero disables\n\
10401 caching, which can slow down startup."),
10403 show_dwarf2_max_cache_age
,
10404 &set_dwarf2_cmdlist
,
10405 &show_dwarf2_cmdlist
);