1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
7 Inc. with support from Florida State University (under contract
8 with the Ada Joint Program Office), and Silicon Graphics, Inc.
9 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
10 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
13 This file is part of GDB.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 3 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>. */
33 #include "elf/dwarf2.h"
36 #include "expression.h"
37 #include "filenames.h" /* for DOSish file names */
40 #include "complaints.h"
42 #include "dwarf2expr.h"
43 #include "dwarf2loc.h"
44 #include "cp-support.h"
51 #include "gdb_string.h"
52 #include "gdb_assert.h"
53 #include <sys/types.h>
58 /* A note on memory usage for this file.
60 At the present time, this code reads the debug info sections into
61 the objfile's objfile_obstack. A definite improvement for startup
62 time, on platforms which do not emit relocations for debug
63 sections, would be to use mmap instead. The object's complete
64 debug information is loaded into memory, partly to simplify
65 absolute DIE references.
67 Whether using obstacks or mmap, the sections should remain loaded
68 until the objfile is released, and pointers into the section data
69 can be used for any other data associated to the objfile (symbol
70 names, type names, location expressions to name a few). */
73 /* .debug_info header for a compilation unit
74 Because of alignment constraints, this structure has padding and cannot
75 be mapped directly onto the beginning of the .debug_info section. */
76 typedef struct comp_unit_header
78 unsigned int length
; /* length of the .debug_info
80 unsigned short version
; /* version number -- 2 for DWARF
82 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
83 unsigned char addr_size
; /* byte size of an address -- 4 */
86 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
89 /* .debug_pubnames header
90 Because of alignment constraints, this structure has padding and cannot
91 be mapped directly onto the beginning of the .debug_info section. */
92 typedef struct pubnames_header
94 unsigned int length
; /* length of the .debug_pubnames
96 unsigned char version
; /* version number -- 2 for DWARF
98 unsigned int info_offset
; /* offset into .debug_info section */
99 unsigned int info_size
; /* byte size of .debug_info section
103 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
105 /* .debug_pubnames header
106 Because of alignment constraints, this structure has padding and cannot
107 be mapped directly onto the beginning of the .debug_info section. */
108 typedef struct aranges_header
110 unsigned int length
; /* byte len of the .debug_aranges
112 unsigned short version
; /* version number -- 2 for DWARF
114 unsigned int info_offset
; /* offset into .debug_info section */
115 unsigned char addr_size
; /* byte size of an address */
116 unsigned char seg_size
; /* byte size of segment descriptor */
119 #define _ACTUAL_ARANGES_HEADER_SIZE 12
121 /* .debug_line statement program prologue
122 Because of alignment constraints, this structure has padding and cannot
123 be mapped directly onto the beginning of the .debug_info section. */
124 typedef struct statement_prologue
126 unsigned int total_length
; /* byte length of the statement
128 unsigned short version
; /* version number -- 2 for DWARF
130 unsigned int prologue_length
; /* # bytes between prologue &
132 unsigned char minimum_instruction_length
; /* byte size of
134 unsigned char default_is_stmt
; /* initial value of is_stmt
137 unsigned char line_range
;
138 unsigned char opcode_base
; /* number assigned to first special
140 unsigned char *standard_opcode_lengths
;
144 static const struct objfile_data
*dwarf2_objfile_data_key
;
146 struct dwarf2_per_objfile
148 /* Sizes of debugging sections. */
149 unsigned int info_size
;
150 unsigned int abbrev_size
;
151 unsigned int line_size
;
152 unsigned int pubnames_size
;
153 unsigned int aranges_size
;
154 unsigned int loc_size
;
155 unsigned int macinfo_size
;
156 unsigned int str_size
;
157 unsigned int ranges_size
;
158 unsigned int frame_size
;
159 unsigned int eh_frame_size
;
161 /* Loaded data from the sections. */
162 gdb_byte
*info_buffer
;
163 gdb_byte
*abbrev_buffer
;
164 gdb_byte
*line_buffer
;
165 gdb_byte
*str_buffer
;
166 gdb_byte
*macinfo_buffer
;
167 gdb_byte
*ranges_buffer
;
168 gdb_byte
*loc_buffer
;
170 /* A list of all the compilation units. This is used to locate
171 the target compilation unit of a particular reference. */
172 struct dwarf2_per_cu_data
**all_comp_units
;
174 /* The number of compilation units in ALL_COMP_UNITS. */
177 /* A chain of compilation units that are currently read in, so that
178 they can be freed later. */
179 struct dwarf2_per_cu_data
*read_in_chain
;
181 /* A flag indicating wether this objfile has a section loaded at a
183 int has_section_at_zero
;
186 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
188 static asection
*dwarf_info_section
;
189 static asection
*dwarf_abbrev_section
;
190 static asection
*dwarf_line_section
;
191 static asection
*dwarf_pubnames_section
;
192 static asection
*dwarf_aranges_section
;
193 static asection
*dwarf_loc_section
;
194 static asection
*dwarf_macinfo_section
;
195 static asection
*dwarf_str_section
;
196 static asection
*dwarf_ranges_section
;
197 asection
*dwarf_frame_section
;
198 asection
*dwarf_eh_frame_section
;
200 /* names of the debugging sections */
202 /* Note that if the debugging section has been compressed, it might
203 have a name like .zdebug_info. */
205 #define INFO_SECTION "debug_info"
206 #define ABBREV_SECTION "debug_abbrev"
207 #define LINE_SECTION "debug_line"
208 #define PUBNAMES_SECTION "debug_pubnames"
209 #define ARANGES_SECTION "debug_aranges"
210 #define LOC_SECTION "debug_loc"
211 #define MACINFO_SECTION "debug_macinfo"
212 #define STR_SECTION "debug_str"
213 #define RANGES_SECTION "debug_ranges"
214 #define FRAME_SECTION "debug_frame"
215 #define EH_FRAME_SECTION "eh_frame"
217 /* local data types */
219 /* We hold several abbreviation tables in memory at the same time. */
220 #ifndef ABBREV_HASH_SIZE
221 #define ABBREV_HASH_SIZE 121
224 /* The data in a compilation unit header, after target2host
225 translation, looks like this. */
226 struct comp_unit_head
228 unsigned long length
;
230 unsigned int abbrev_offset
;
231 unsigned char addr_size
;
232 unsigned char signed_addr_p
;
234 /* Size of file offsets; either 4 or 8. */
235 unsigned int offset_size
;
237 /* Size of the length field; either 4 or 12. */
238 unsigned int initial_length_size
;
240 /* Offset to the first byte of this compilation unit header in the
241 .debug_info section, for resolving relative reference dies. */
244 /* Pointer to this compilation unit header in the .debug_info
246 gdb_byte
*cu_head_ptr
;
248 /* Pointer to the first die of this compilation unit. This will be
249 the first byte following the compilation unit header. */
250 gdb_byte
*first_die_ptr
;
252 /* Pointer to the next compilation unit header in the program. */
253 struct comp_unit_head
*next
;
255 /* Base address of this compilation unit. */
256 CORE_ADDR base_address
;
258 /* Non-zero if base_address has been set. */
262 /* Internal state when decoding a particular compilation unit. */
265 /* The objfile containing this compilation unit. */
266 struct objfile
*objfile
;
268 /* The header of the compilation unit.
270 FIXME drow/2003-11-10: Some of the things from the comp_unit_head
271 should logically be moved to the dwarf2_cu structure. */
272 struct comp_unit_head header
;
274 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
276 /* The language we are debugging. */
277 enum language language
;
278 const struct language_defn
*language_defn
;
280 const char *producer
;
282 /* The generic symbol table building routines have separate lists for
283 file scope symbols and all all other scopes (local scopes). So
284 we need to select the right one to pass to add_symbol_to_list().
285 We do it by keeping a pointer to the correct list in list_in_scope.
287 FIXME: The original dwarf code just treated the file scope as the
288 first local scope, and all other local scopes as nested local
289 scopes, and worked fine. Check to see if we really need to
290 distinguish these in buildsym.c. */
291 struct pending
**list_in_scope
;
293 /* DWARF abbreviation table associated with this compilation unit. */
294 struct abbrev_info
**dwarf2_abbrevs
;
296 /* Storage for the abbrev table. */
297 struct obstack abbrev_obstack
;
299 /* Hash table holding all the loaded partial DIEs. */
302 /* `.debug_ranges' offset for this `DW_TAG_compile_unit' DIE. */
303 unsigned long ranges_offset
;
305 /* Storage for things with the same lifetime as this read-in compilation
306 unit, including partial DIEs. */
307 struct obstack comp_unit_obstack
;
309 /* When multiple dwarf2_cu structures are living in memory, this field
310 chains them all together, so that they can be released efficiently.
311 We will probably also want a generation counter so that most-recently-used
312 compilation units are cached... */
313 struct dwarf2_per_cu_data
*read_in_chain
;
315 /* Backchain to our per_cu entry if the tree has been built. */
316 struct dwarf2_per_cu_data
*per_cu
;
318 /* Pointer to the die -> type map. Although it is stored
319 permanently in per_cu, we copy it here to avoid double
323 /* How many compilation units ago was this CU last referenced? */
326 /* A hash table of die offsets for following references. */
329 /* Full DIEs if read in. */
330 struct die_info
*dies
;
332 /* A set of pointers to dwarf2_per_cu_data objects for compilation
333 units referenced by this one. Only set during full symbol processing;
334 partial symbol tables do not have dependencies. */
337 /* Header data from the line table, during full symbol processing. */
338 struct line_header
*line_header
;
340 /* Mark used when releasing cached dies. */
341 unsigned int mark
: 1;
343 /* This flag will be set if this compilation unit might include
344 inter-compilation-unit references. */
345 unsigned int has_form_ref_addr
: 1;
347 /* This flag will be set if this compilation unit includes any
348 DW_TAG_namespace DIEs. If we know that there are explicit
349 DIEs for namespaces, we don't need to try to infer them
350 from mangled names. */
351 unsigned int has_namespace_info
: 1;
353 /* Field `ranges_offset' is filled in; flag as the value may be zero. */
354 unsigned int has_ranges_offset
: 1;
357 /* Persistent data held for a compilation unit, even when not
358 processing it. We put a pointer to this structure in the
359 read_symtab_private field of the psymtab. If we encounter
360 inter-compilation-unit references, we also maintain a sorted
361 list of all compilation units. */
363 struct dwarf2_per_cu_data
365 /* The start offset and length of this compilation unit. 2**30-1
366 bytes should suffice to store the length of any compilation unit
367 - if it doesn't, GDB will fall over anyway. */
368 unsigned long offset
;
369 unsigned long length
: 30;
371 /* Flag indicating this compilation unit will be read in before
372 any of the current compilation units are processed. */
373 unsigned long queued
: 1;
375 /* This flag will be set if we need to load absolutely all DIEs
376 for this compilation unit, instead of just the ones we think
377 are interesting. It gets set if we look for a DIE in the
378 hash table and don't find it. */
379 unsigned int load_all_dies
: 1;
381 /* Set iff currently read in. */
382 struct dwarf2_cu
*cu
;
384 /* If full symbols for this CU have been read in, then this field
385 holds a map of DIE offsets to types. It isn't always possible
386 to reconstruct this information later, so we have to preserve
390 /* The partial symbol table associated with this compilation unit,
391 or NULL for partial units (which do not have an associated
393 struct partial_symtab
*psymtab
;
396 /* The line number information for a compilation unit (found in the
397 .debug_line section) begins with a "statement program header",
398 which contains the following information. */
401 unsigned int total_length
;
402 unsigned short version
;
403 unsigned int header_length
;
404 unsigned char minimum_instruction_length
;
405 unsigned char default_is_stmt
;
407 unsigned char line_range
;
408 unsigned char opcode_base
;
410 /* standard_opcode_lengths[i] is the number of operands for the
411 standard opcode whose value is i. This means that
412 standard_opcode_lengths[0] is unused, and the last meaningful
413 element is standard_opcode_lengths[opcode_base - 1]. */
414 unsigned char *standard_opcode_lengths
;
416 /* The include_directories table. NOTE! These strings are not
417 allocated with xmalloc; instead, they are pointers into
418 debug_line_buffer. If you try to free them, `free' will get
420 unsigned int num_include_dirs
, include_dirs_size
;
423 /* The file_names table. NOTE! These strings are not allocated
424 with xmalloc; instead, they are pointers into debug_line_buffer.
425 Don't try to free them directly. */
426 unsigned int num_file_names
, file_names_size
;
430 unsigned int dir_index
;
431 unsigned int mod_time
;
433 int included_p
; /* Non-zero if referenced by the Line Number Program. */
434 struct symtab
*symtab
; /* The associated symbol table, if any. */
437 /* The start and end of the statement program following this
438 header. These point into dwarf2_per_objfile->line_buffer. */
439 gdb_byte
*statement_program_start
, *statement_program_end
;
442 /* When we construct a partial symbol table entry we only
443 need this much information. */
444 struct partial_die_info
446 /* Offset of this DIE. */
449 /* DWARF-2 tag for this DIE. */
450 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
452 /* Language code associated with this DIE. This is only used
453 for the compilation unit DIE. */
454 unsigned int language
: 8;
456 /* Assorted flags describing the data found in this DIE. */
457 unsigned int has_children
: 1;
458 unsigned int is_external
: 1;
459 unsigned int is_declaration
: 1;
460 unsigned int has_type
: 1;
461 unsigned int has_specification
: 1;
462 unsigned int has_stmt_list
: 1;
463 unsigned int has_pc_info
: 1;
465 /* Flag set if the SCOPE field of this structure has been
467 unsigned int scope_set
: 1;
469 /* Flag set if the DIE has a byte_size attribute. */
470 unsigned int has_byte_size
: 1;
472 /* The name of this DIE. Normally the value of DW_AT_name, but
473 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
478 /* The scope to prepend to our children. This is generally
479 allocated on the comp_unit_obstack, so will disappear
480 when this compilation unit leaves the cache. */
483 /* The location description associated with this DIE, if any. */
484 struct dwarf_block
*locdesc
;
486 /* If HAS_PC_INFO, the PC range associated with this DIE. */
490 /* Pointer into the info_buffer pointing at the target of
491 DW_AT_sibling, if any. */
494 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
495 DW_AT_specification (or DW_AT_abstract_origin or
497 unsigned int spec_offset
;
499 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
500 unsigned int line_offset
;
502 /* Pointers to this DIE's parent, first child, and next sibling,
504 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
507 /* This data structure holds the information of an abbrev. */
510 unsigned int number
; /* number identifying abbrev */
511 enum dwarf_tag tag
; /* dwarf tag */
512 unsigned short has_children
; /* boolean */
513 unsigned short num_attrs
; /* number of attributes */
514 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
515 struct abbrev_info
*next
; /* next in chain */
520 enum dwarf_attribute name
;
521 enum dwarf_form form
;
524 /* This data structure holds a complete die structure. */
527 enum dwarf_tag tag
; /* Tag indicating type of die */
528 unsigned int abbrev
; /* Abbrev number */
529 unsigned int offset
; /* Offset in .debug_info section */
530 unsigned int num_attrs
; /* Number of attributes */
531 struct attribute
*attrs
; /* An array of attributes */
533 /* The dies in a compilation unit form an n-ary tree. PARENT
534 points to this die's parent; CHILD points to the first child of
535 this node; and all the children of a given node are chained
536 together via their SIBLING fields, terminated by a die whose
538 struct die_info
*child
; /* Its first child, if any. */
539 struct die_info
*sibling
; /* Its next sibling, if any. */
540 struct die_info
*parent
; /* Its parent, if any. */
543 /* Attributes have a name and a value */
546 enum dwarf_attribute name
;
547 enum dwarf_form form
;
551 struct dwarf_block
*blk
;
559 struct function_range
562 CORE_ADDR lowpc
, highpc
;
564 struct function_range
*next
;
567 /* Get at parts of an attribute structure */
569 #define DW_STRING(attr) ((attr)->u.str)
570 #define DW_UNSND(attr) ((attr)->u.unsnd)
571 #define DW_BLOCK(attr) ((attr)->u.blk)
572 #define DW_SND(attr) ((attr)->u.snd)
573 #define DW_ADDR(attr) ((attr)->u.addr)
575 /* Blocks are a bunch of untyped bytes. */
582 #ifndef ATTR_ALLOC_CHUNK
583 #define ATTR_ALLOC_CHUNK 4
586 /* Allocate fields for structs, unions and enums in this size. */
587 #ifndef DW_FIELD_ALLOC_CHUNK
588 #define DW_FIELD_ALLOC_CHUNK 4
591 /* A zeroed version of a partial die for initialization purposes. */
592 static struct partial_die_info zeroed_partial_die
;
594 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
595 but this would require a corresponding change in unpack_field_as_long
597 static int bits_per_byte
= 8;
599 /* The routines that read and process dies for a C struct or C++ class
600 pass lists of data member fields and lists of member function fields
601 in an instance of a field_info structure, as defined below. */
604 /* List of data member and baseclasses fields. */
607 struct nextfield
*next
;
614 /* Number of fields. */
617 /* Number of baseclasses. */
620 /* Set if the accesibility of one of the fields is not public. */
621 int non_public_fields
;
623 /* Member function fields array, entries are allocated in the order they
624 are encountered in the object file. */
627 struct nextfnfield
*next
;
628 struct fn_field fnfield
;
632 /* Member function fieldlist array, contains name of possibly overloaded
633 member function, number of overloaded member functions and a pointer
634 to the head of the member function field chain. */
639 struct nextfnfield
*head
;
643 /* Number of entries in the fnfieldlists array. */
647 /* One item on the queue of compilation units to read in full symbols
649 struct dwarf2_queue_item
651 struct dwarf2_per_cu_data
*per_cu
;
652 struct dwarf2_queue_item
*next
;
655 /* The current queue. */
656 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
658 /* Loaded secondary compilation units are kept in memory until they
659 have not been referenced for the processing of this many
660 compilation units. Set this to zero to disable caching. Cache
661 sizes of up to at least twenty will improve startup time for
662 typical inter-CU-reference binaries, at an obvious memory cost. */
663 static int dwarf2_max_cache_age
= 5;
665 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
666 struct cmd_list_element
*c
, const char *value
)
668 fprintf_filtered (file
, _("\
669 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
674 /* Various complaints about symbol reading that don't abort the process */
677 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
679 complaint (&symfile_complaints
,
680 _("statement list doesn't fit in .debug_line section"));
684 dwarf2_debug_line_missing_file_complaint (void)
686 complaint (&symfile_complaints
,
687 _(".debug_line section has line data without a file"));
691 dwarf2_complex_location_expr_complaint (void)
693 complaint (&symfile_complaints
, _("location expression too complex"));
697 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
700 complaint (&symfile_complaints
,
701 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
706 dwarf2_macros_too_long_complaint (void)
708 complaint (&symfile_complaints
,
709 _("macro info runs off end of `.debug_macinfo' section"));
713 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
715 complaint (&symfile_complaints
,
716 _("macro debug info contains a malformed macro definition:\n`%s'"),
721 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
723 complaint (&symfile_complaints
,
724 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
727 /* local function prototypes */
729 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
732 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
735 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
738 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
739 struct partial_die_info
*,
740 struct partial_symtab
*);
742 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
744 static void scan_partial_symbols (struct partial_die_info
*,
745 CORE_ADDR
*, CORE_ADDR
*,
748 static void add_partial_symbol (struct partial_die_info
*,
751 static int pdi_needs_namespace (enum dwarf_tag tag
);
753 static void add_partial_namespace (struct partial_die_info
*pdi
,
754 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
755 struct dwarf2_cu
*cu
);
757 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
758 struct dwarf2_cu
*cu
);
760 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
763 struct dwarf2_cu
*cu
);
765 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
767 static void psymtab_to_symtab_1 (struct partial_symtab
*);
769 gdb_byte
*dwarf2_read_section (struct objfile
*, asection
*);
771 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
773 static void dwarf2_free_abbrev_table (void *);
775 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
778 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
781 static struct partial_die_info
*load_partial_dies (bfd
*, gdb_byte
*, int,
784 static gdb_byte
*read_partial_die (struct partial_die_info
*,
785 struct abbrev_info
*abbrev
, unsigned int,
786 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
788 static struct partial_die_info
*find_partial_die (unsigned long,
791 static void fixup_partial_die (struct partial_die_info
*,
794 static gdb_byte
*read_full_die (struct die_info
**, bfd
*, gdb_byte
*,
795 struct dwarf2_cu
*, int *);
797 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
798 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
800 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
801 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
803 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
805 static int read_1_signed_byte (bfd
*, gdb_byte
*);
807 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
809 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
811 static unsigned long read_8_bytes (bfd
*, gdb_byte
*);
813 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
816 static LONGEST
read_initial_length (bfd
*, gdb_byte
*,
817 struct comp_unit_head
*, unsigned int *);
819 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
822 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
824 static char *read_string (bfd
*, gdb_byte
*, unsigned int *);
826 static char *read_indirect_string (bfd
*, gdb_byte
*,
827 const struct comp_unit_head
*,
830 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
832 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
834 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
836 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
838 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
841 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
842 struct dwarf2_cu
*cu
);
844 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
846 static struct die_info
*die_specification (struct die_info
*die
,
849 static void free_line_header (struct line_header
*lh
);
851 static void add_file_name (struct line_header
*, char *, unsigned int,
852 unsigned int, unsigned int);
854 static struct line_header
*(dwarf_decode_line_header
855 (unsigned int offset
,
856 bfd
*abfd
, struct dwarf2_cu
*cu
));
858 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
859 struct dwarf2_cu
*, struct partial_symtab
*);
861 static void dwarf2_start_subfile (char *, char *, char *);
863 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
866 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
869 static void dwarf2_const_value_data (struct attribute
*attr
,
873 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
875 static struct type
*die_containing_type (struct die_info
*,
878 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
880 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
882 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
884 static char *typename_concat (struct obstack
*,
889 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
891 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
893 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
895 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
896 struct dwarf2_cu
*, struct partial_symtab
*);
898 static int dwarf2_get_pc_bounds (struct die_info
*,
899 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
901 static void get_scope_pc_bounds (struct die_info
*,
902 CORE_ADDR
*, CORE_ADDR
*,
905 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
906 CORE_ADDR
, struct dwarf2_cu
*);
908 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
911 static void dwarf2_attach_fields_to_type (struct field_info
*,
912 struct type
*, struct dwarf2_cu
*);
914 static void dwarf2_add_member_fn (struct field_info
*,
915 struct die_info
*, struct type
*,
918 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
919 struct type
*, struct dwarf2_cu
*);
921 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
923 static char *determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
925 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
927 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
929 static const char *namespace_name (struct die_info
*die
,
930 int *is_anonymous
, struct dwarf2_cu
*);
932 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
934 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
936 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
939 static struct die_info
*read_comp_unit (gdb_byte
*, bfd
*, struct dwarf2_cu
*);
941 static struct die_info
*read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
943 gdb_byte
**new_info_ptr
,
944 struct die_info
*parent
);
946 static struct die_info
*read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
948 gdb_byte
**new_info_ptr
,
949 struct die_info
*parent
);
951 static void process_die (struct die_info
*, struct dwarf2_cu
*);
953 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
955 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
957 static struct die_info
*dwarf2_extension (struct die_info
*die
,
960 static char *dwarf_tag_name (unsigned int);
962 static char *dwarf_attr_name (unsigned int);
964 static char *dwarf_form_name (unsigned int);
966 static char *dwarf_stack_op_name (unsigned int);
968 static char *dwarf_bool_name (unsigned int);
970 static char *dwarf_type_encoding_name (unsigned int);
973 static char *dwarf_cfi_name (unsigned int);
976 static struct die_info
*sibling_die (struct die_info
*);
978 static void dump_die (struct die_info
*);
980 static void dump_die_list (struct die_info
*);
982 static void store_in_ref_table (struct die_info
*,
985 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*,
988 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
990 static struct die_info
*follow_die_ref (struct die_info
*,
994 /* memory allocation interface */
996 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
998 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1000 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*);
1002 static void initialize_cu_func_list (struct dwarf2_cu
*);
1004 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1005 struct dwarf2_cu
*);
1007 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1008 char *, bfd
*, struct dwarf2_cu
*);
1010 static int attr_form_is_block (struct attribute
*);
1012 static int attr_form_is_section_offset (struct attribute
*);
1014 static int attr_form_is_constant (struct attribute
*);
1016 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1018 struct dwarf2_cu
*cu
);
1020 static gdb_byte
*skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
1021 struct dwarf2_cu
*cu
);
1023 static void free_stack_comp_unit (void *);
1025 static hashval_t
partial_die_hash (const void *item
);
1027 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1029 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1030 (unsigned long offset
, struct objfile
*objfile
);
1032 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1033 (unsigned long offset
, struct objfile
*objfile
);
1035 static void free_one_comp_unit (void *);
1037 static void free_cached_comp_units (void *);
1039 static void age_cached_comp_units (void);
1041 static void free_one_cached_comp_unit (void *);
1043 static struct type
*set_die_type (struct die_info
*, struct type
*,
1044 struct dwarf2_cu
*);
1046 static void create_all_comp_units (struct objfile
*);
1048 static struct dwarf2_cu
*load_full_comp_unit (struct dwarf2_per_cu_data
*,
1051 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1053 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1054 struct dwarf2_per_cu_data
*);
1056 static void dwarf2_mark (struct dwarf2_cu
*);
1058 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1060 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1062 /* Try to locate the sections we need for DWARF 2 debugging
1063 information and return true if we have enough to do something. */
1066 dwarf2_has_info (struct objfile
*objfile
)
1068 struct dwarf2_per_objfile
*data
;
1070 /* Initialize per-objfile state. */
1071 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1072 memset (data
, 0, sizeof (*data
));
1073 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1074 dwarf2_per_objfile
= data
;
1076 dwarf_info_section
= 0;
1077 dwarf_abbrev_section
= 0;
1078 dwarf_line_section
= 0;
1079 dwarf_str_section
= 0;
1080 dwarf_macinfo_section
= 0;
1081 dwarf_frame_section
= 0;
1082 dwarf_eh_frame_section
= 0;
1083 dwarf_ranges_section
= 0;
1084 dwarf_loc_section
= 0;
1086 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1087 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
1090 /* When loading sections, we can either look for ".<name>", or for
1091 * ".z<name>", which indicates a compressed section. */
1094 section_is_p (asection
*sectp
, const char *name
)
1096 return ((sectp
->name
[0] == '.'
1097 && strcmp (sectp
->name
+ 1, name
) == 0)
1098 || (sectp
->name
[0] == '.' && sectp
->name
[1] == 'z'
1099 && strcmp (sectp
->name
+ 2, name
) == 0));
1102 /* This function is mapped across the sections and remembers the
1103 offset and size of each of the debugging sections we are interested
1107 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1109 if (section_is_p (sectp
, INFO_SECTION
))
1111 dwarf2_per_objfile
->info_size
= bfd_get_section_size (sectp
);
1112 dwarf_info_section
= sectp
;
1114 else if (section_is_p (sectp
, ABBREV_SECTION
))
1116 dwarf2_per_objfile
->abbrev_size
= bfd_get_section_size (sectp
);
1117 dwarf_abbrev_section
= sectp
;
1119 else if (section_is_p (sectp
, LINE_SECTION
))
1121 dwarf2_per_objfile
->line_size
= bfd_get_section_size (sectp
);
1122 dwarf_line_section
= sectp
;
1124 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1126 dwarf2_per_objfile
->pubnames_size
= bfd_get_section_size (sectp
);
1127 dwarf_pubnames_section
= sectp
;
1129 else if (section_is_p (sectp
, ARANGES_SECTION
))
1131 dwarf2_per_objfile
->aranges_size
= bfd_get_section_size (sectp
);
1132 dwarf_aranges_section
= sectp
;
1134 else if (section_is_p (sectp
, LOC_SECTION
))
1136 dwarf2_per_objfile
->loc_size
= bfd_get_section_size (sectp
);
1137 dwarf_loc_section
= sectp
;
1139 else if (section_is_p (sectp
, MACINFO_SECTION
))
1141 dwarf2_per_objfile
->macinfo_size
= bfd_get_section_size (sectp
);
1142 dwarf_macinfo_section
= sectp
;
1144 else if (section_is_p (sectp
, STR_SECTION
))
1146 dwarf2_per_objfile
->str_size
= bfd_get_section_size (sectp
);
1147 dwarf_str_section
= sectp
;
1149 else if (section_is_p (sectp
, FRAME_SECTION
))
1151 dwarf2_per_objfile
->frame_size
= bfd_get_section_size (sectp
);
1152 dwarf_frame_section
= sectp
;
1154 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1156 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1157 if (aflag
& SEC_HAS_CONTENTS
)
1159 dwarf2_per_objfile
->eh_frame_size
= bfd_get_section_size (sectp
);
1160 dwarf_eh_frame_section
= sectp
;
1163 else if (section_is_p (sectp
, RANGES_SECTION
))
1165 dwarf2_per_objfile
->ranges_size
= bfd_get_section_size (sectp
);
1166 dwarf_ranges_section
= sectp
;
1169 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1170 && bfd_section_vma (abfd
, sectp
) == 0)
1171 dwarf2_per_objfile
->has_section_at_zero
= 1;
1174 /* This function is called after decompressing a section, so
1175 dwarf2_per_objfile can record its new, uncompressed size. */
1178 dwarf2_resize_section (asection
*sectp
, bfd_size_type new_size
)
1180 if (section_is_p (sectp
, INFO_SECTION
))
1181 dwarf2_per_objfile
->info_size
= new_size
;
1182 else if (section_is_p (sectp
, ABBREV_SECTION
))
1183 dwarf2_per_objfile
->abbrev_size
= new_size
;
1184 else if (section_is_p (sectp
, LINE_SECTION
))
1185 dwarf2_per_objfile
->line_size
= new_size
;
1186 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1187 dwarf2_per_objfile
->pubnames_size
= new_size
;
1188 else if (section_is_p (sectp
, ARANGES_SECTION
))
1189 dwarf2_per_objfile
->aranges_size
= new_size
;
1190 else if (section_is_p (sectp
, LOC_SECTION
))
1191 dwarf2_per_objfile
->loc_size
= new_size
;
1192 else if (section_is_p (sectp
, MACINFO_SECTION
))
1193 dwarf2_per_objfile
->macinfo_size
= new_size
;
1194 else if (section_is_p (sectp
, STR_SECTION
))
1195 dwarf2_per_objfile
->str_size
= new_size
;
1196 else if (section_is_p (sectp
, FRAME_SECTION
))
1197 dwarf2_per_objfile
->frame_size
= new_size
;
1198 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1199 dwarf2_per_objfile
->eh_frame_size
= new_size
;
1200 else if (section_is_p (sectp
, RANGES_SECTION
))
1201 dwarf2_per_objfile
->ranges_size
= new_size
;
1203 internal_error (__FILE__
, __LINE__
,
1204 _("dwarf2_resize_section: missing section_is_p check: %s"),
1208 /* Build a partial symbol table. */
1211 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1213 /* We definitely need the .debug_info and .debug_abbrev sections */
1215 dwarf2_per_objfile
->info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1216 dwarf2_per_objfile
->abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1218 if (dwarf_line_section
)
1219 dwarf2_per_objfile
->line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1221 dwarf2_per_objfile
->line_buffer
= NULL
;
1223 if (dwarf_str_section
)
1224 dwarf2_per_objfile
->str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1226 dwarf2_per_objfile
->str_buffer
= NULL
;
1228 if (dwarf_macinfo_section
)
1229 dwarf2_per_objfile
->macinfo_buffer
= dwarf2_read_section (objfile
,
1230 dwarf_macinfo_section
);
1232 dwarf2_per_objfile
->macinfo_buffer
= NULL
;
1234 if (dwarf_ranges_section
)
1235 dwarf2_per_objfile
->ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1237 dwarf2_per_objfile
->ranges_buffer
= NULL
;
1239 if (dwarf_loc_section
)
1240 dwarf2_per_objfile
->loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1242 dwarf2_per_objfile
->loc_buffer
= NULL
;
1245 || (objfile
->global_psymbols
.size
== 0
1246 && objfile
->static_psymbols
.size
== 0))
1248 init_psymbol_list (objfile
, 1024);
1252 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1254 /* Things are significantly easier if we have .debug_aranges and
1255 .debug_pubnames sections */
1257 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1261 /* only test this case for now */
1263 /* In this case we have to work a bit harder */
1264 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1269 /* Build the partial symbol table from the information in the
1270 .debug_pubnames and .debug_aranges sections. */
1273 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1275 bfd
*abfd
= objfile
->obfd
;
1276 char *aranges_buffer
, *pubnames_buffer
;
1277 char *aranges_ptr
, *pubnames_ptr
;
1278 unsigned int entry_length
, version
, info_offset
, info_size
;
1280 pubnames_buffer
= dwarf2_read_section (objfile
,
1281 dwarf_pubnames_section
);
1282 pubnames_ptr
= pubnames_buffer
;
1283 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames_size
)
1285 struct comp_unit_head cu_header
;
1286 unsigned int bytes_read
;
1288 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1290 pubnames_ptr
+= bytes_read
;
1291 version
= read_1_byte (abfd
, pubnames_ptr
);
1293 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1295 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1299 aranges_buffer
= dwarf2_read_section (objfile
,
1300 dwarf_aranges_section
);
1305 /* Read in the comp unit header information from the debug_info at
1309 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1310 gdb_byte
*info_ptr
, bfd
*abfd
)
1313 unsigned int bytes_read
;
1314 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1316 info_ptr
+= bytes_read
;
1317 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1319 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1321 info_ptr
+= bytes_read
;
1322 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1324 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1325 if (signed_addr
< 0)
1326 internal_error (__FILE__
, __LINE__
,
1327 _("read_comp_unit_head: dwarf from non elf file"));
1328 cu_header
->signed_addr_p
= signed_addr
;
1333 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1336 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1338 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1340 if (header
->version
!= 2 && header
->version
!= 3)
1341 error (_("Dwarf Error: wrong version in compilation unit header "
1342 "(is %d, should be %d) [in module %s]"), header
->version
,
1343 2, bfd_get_filename (abfd
));
1345 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev_size
)
1346 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1347 "(offset 0x%lx + 6) [in module %s]"),
1348 (long) header
->abbrev_offset
,
1349 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1350 bfd_get_filename (abfd
));
1352 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1353 > dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1354 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1355 "(offset 0x%lx + 0) [in module %s]"),
1356 (long) header
->length
,
1357 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1358 bfd_get_filename (abfd
));
1363 /* Allocate a new partial symtab for file named NAME and mark this new
1364 partial symtab as being an include of PST. */
1367 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1368 struct objfile
*objfile
)
1370 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1372 subpst
->section_offsets
= pst
->section_offsets
;
1373 subpst
->textlow
= 0;
1374 subpst
->texthigh
= 0;
1376 subpst
->dependencies
= (struct partial_symtab
**)
1377 obstack_alloc (&objfile
->objfile_obstack
,
1378 sizeof (struct partial_symtab
*));
1379 subpst
->dependencies
[0] = pst
;
1380 subpst
->number_of_dependencies
= 1;
1382 subpst
->globals_offset
= 0;
1383 subpst
->n_global_syms
= 0;
1384 subpst
->statics_offset
= 0;
1385 subpst
->n_static_syms
= 0;
1386 subpst
->symtab
= NULL
;
1387 subpst
->read_symtab
= pst
->read_symtab
;
1390 /* No private part is necessary for include psymtabs. This property
1391 can be used to differentiate between such include psymtabs and
1392 the regular ones. */
1393 subpst
->read_symtab_private
= NULL
;
1396 /* Read the Line Number Program data and extract the list of files
1397 included by the source file represented by PST. Build an include
1398 partial symtab for each of these included files.
1400 This procedure assumes that there *is* a Line Number Program in
1401 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1402 before calling this procedure. */
1405 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1406 struct partial_die_info
*pdi
,
1407 struct partial_symtab
*pst
)
1409 struct objfile
*objfile
= cu
->objfile
;
1410 bfd
*abfd
= objfile
->obfd
;
1411 struct line_header
*lh
;
1413 lh
= dwarf_decode_line_header (pdi
->line_offset
, abfd
, cu
);
1415 return; /* No linetable, so no includes. */
1417 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1419 free_line_header (lh
);
1423 /* Build the partial symbol table by doing a quick pass through the
1424 .debug_info and .debug_abbrev sections. */
1427 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1429 /* Instead of reading this into a big buffer, we should probably use
1430 mmap() on architectures that support it. (FIXME) */
1431 bfd
*abfd
= objfile
->obfd
;
1433 gdb_byte
*beg_of_comp_unit
;
1434 struct partial_die_info comp_unit_die
;
1435 struct partial_symtab
*pst
;
1436 struct cleanup
*back_to
;
1437 CORE_ADDR lowpc
, highpc
, baseaddr
;
1439 info_ptr
= dwarf2_per_objfile
->info_buffer
;
1441 /* Any cached compilation units will be linked by the per-objfile
1442 read_in_chain. Make sure to free them when we're done. */
1443 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1445 create_all_comp_units (objfile
);
1447 objfile
->psymtabs_addrmap
= addrmap_create_mutable
1448 (&objfile
->objfile_obstack
);
1450 /* Since the objects we're extracting from .debug_info vary in
1451 length, only the individual functions to extract them (like
1452 read_comp_unit_head and load_partial_die) can really know whether
1453 the buffer is large enough to hold another complete object.
1455 At the moment, they don't actually check that. If .debug_info
1456 holds just one extra byte after the last compilation unit's dies,
1457 then read_comp_unit_head will happily read off the end of the
1458 buffer. read_partial_die is similarly casual. Those functions
1461 For this loop condition, simply checking whether there's any data
1462 left at all should be sufficient. */
1463 while (info_ptr
< (dwarf2_per_objfile
->info_buffer
1464 + dwarf2_per_objfile
->info_size
))
1466 struct cleanup
*back_to_inner
;
1467 struct dwarf2_cu cu
;
1468 struct abbrev_info
*abbrev
;
1469 unsigned int bytes_read
;
1470 struct dwarf2_per_cu_data
*this_cu
;
1472 beg_of_comp_unit
= info_ptr
;
1474 memset (&cu
, 0, sizeof (cu
));
1476 obstack_init (&cu
.comp_unit_obstack
);
1478 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1480 cu
.objfile
= objfile
;
1481 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1483 /* Complete the cu_header */
1484 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1485 cu
.header
.first_die_ptr
= info_ptr
;
1486 cu
.header
.cu_head_ptr
= beg_of_comp_unit
;
1488 cu
.list_in_scope
= &file_symbols
;
1490 /* Read the abbrevs for this compilation unit into a table */
1491 dwarf2_read_abbrevs (abfd
, &cu
);
1492 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1494 this_cu
= dwarf2_find_comp_unit (cu
.header
.offset
, objfile
);
1496 /* Read the compilation unit die */
1497 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, &cu
);
1498 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1499 abfd
, info_ptr
, &cu
);
1501 if (comp_unit_die
.tag
== DW_TAG_partial_unit
)
1503 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1504 + cu
.header
.initial_length_size
);
1505 do_cleanups (back_to_inner
);
1509 /* Set the language we're debugging */
1510 set_cu_language (comp_unit_die
.language
, &cu
);
1512 /* Allocate a new partial symbol table structure */
1513 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1514 comp_unit_die
.name
? comp_unit_die
.name
: "",
1515 /* TEXTLOW and TEXTHIGH are set below. */
1517 objfile
->global_psymbols
.next
,
1518 objfile
->static_psymbols
.next
);
1520 if (comp_unit_die
.dirname
)
1521 pst
->dirname
= xstrdup (comp_unit_die
.dirname
);
1523 pst
->read_symtab_private
= (char *) this_cu
;
1525 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1527 /* Store the function that reads in the rest of the symbol table */
1528 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1530 /* If this compilation unit was already read in, free the
1531 cached copy in order to read it in again. This is
1532 necessary because we skipped some symbols when we first
1533 read in the compilation unit (see load_partial_dies).
1534 This problem could be avoided, but the benefit is
1536 if (this_cu
->cu
!= NULL
)
1537 free_one_cached_comp_unit (this_cu
->cu
);
1539 cu
.per_cu
= this_cu
;
1541 /* Note that this is a pointer to our stack frame, being
1542 added to a global data structure. It will be cleaned up
1543 in free_stack_comp_unit when we finish with this
1544 compilation unit. */
1547 this_cu
->psymtab
= pst
;
1549 /* Possibly set the default values of LOWPC and HIGHPC from
1551 if (cu
.has_ranges_offset
)
1553 if (dwarf2_ranges_read (cu
.ranges_offset
, &comp_unit_die
.lowpc
,
1554 &comp_unit_die
.highpc
, &cu
, pst
))
1555 comp_unit_die
.has_pc_info
= 1;
1558 /* Check if comp unit has_children.
1559 If so, read the rest of the partial symbols from this comp unit.
1560 If not, there's no more debug_info for this comp unit. */
1561 if (comp_unit_die
.has_children
)
1563 struct partial_die_info
*first_die
;
1565 lowpc
= ((CORE_ADDR
) -1);
1566 highpc
= ((CORE_ADDR
) 0);
1568 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1570 scan_partial_symbols (first_die
, &lowpc
, &highpc
, &cu
);
1572 /* If we didn't find a lowpc, set it to highpc to avoid
1573 complaints from `maint check'. */
1574 if (lowpc
== ((CORE_ADDR
) -1))
1577 /* If the compilation unit didn't have an explicit address range,
1578 then use the information extracted from its child dies. */
1579 if (! comp_unit_die
.has_pc_info
)
1581 comp_unit_die
.lowpc
= lowpc
;
1582 comp_unit_die
.highpc
= highpc
;
1585 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1586 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1588 /* Store the contiguous range; `DW_AT_ranges' range is stored above. The
1589 range can be also empty for CUs with no code. */
1590 if (!cu
.has_ranges_offset
&& pst
->textlow
< pst
->texthigh
)
1591 addrmap_set_empty (objfile
->psymtabs_addrmap
, pst
->textlow
,
1592 pst
->texthigh
- 1, pst
);
1594 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1595 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1596 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1597 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1598 sort_pst_symbols (pst
);
1600 /* If there is already a psymtab or symtab for a file of this
1601 name, remove it. (If there is a symtab, more drastic things
1602 also happen.) This happens in VxWorks. */
1603 free_named_symtabs (pst
->filename
);
1605 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1606 + cu
.header
.initial_length_size
;
1608 if (comp_unit_die
.has_stmt_list
)
1610 /* Get the list of files included in the current compilation unit,
1611 and build a psymtab for each of them. */
1612 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1615 do_cleanups (back_to_inner
);
1618 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
1619 &objfile
->objfile_obstack
);
1621 do_cleanups (back_to
);
1624 /* Load the DIEs for a secondary CU into memory. */
1627 load_comp_unit (struct dwarf2_per_cu_data
*this_cu
, struct objfile
*objfile
)
1629 bfd
*abfd
= objfile
->obfd
;
1630 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
1631 struct partial_die_info comp_unit_die
;
1632 struct dwarf2_cu
*cu
;
1633 struct abbrev_info
*abbrev
;
1634 unsigned int bytes_read
;
1635 struct cleanup
*back_to
;
1637 info_ptr
= dwarf2_per_objfile
->info_buffer
+ this_cu
->offset
;
1638 beg_of_comp_unit
= info_ptr
;
1640 cu
= xmalloc (sizeof (struct dwarf2_cu
));
1641 memset (cu
, 0, sizeof (struct dwarf2_cu
));
1643 obstack_init (&cu
->comp_unit_obstack
);
1645 cu
->objfile
= objfile
;
1646 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
1648 /* Complete the cu_header. */
1649 cu
->header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1650 cu
->header
.first_die_ptr
= info_ptr
;
1651 cu
->header
.cu_head_ptr
= beg_of_comp_unit
;
1653 /* Read the abbrevs for this compilation unit into a table. */
1654 dwarf2_read_abbrevs (abfd
, cu
);
1655 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
1657 /* Read the compilation unit die. */
1658 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1659 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1660 abfd
, info_ptr
, cu
);
1662 /* Set the language we're debugging. */
1663 set_cu_language (comp_unit_die
.language
, cu
);
1665 /* Link this compilation unit into the compilation unit tree. */
1667 cu
->per_cu
= this_cu
;
1668 cu
->type_hash
= cu
->per_cu
->type_hash
;
1670 /* Check if comp unit has_children.
1671 If so, read the rest of the partial symbols from this comp unit.
1672 If not, there's no more debug_info for this comp unit. */
1673 if (comp_unit_die
.has_children
)
1674 load_partial_dies (abfd
, info_ptr
, 0, cu
);
1676 do_cleanups (back_to
);
1679 /* Create a list of all compilation units in OBJFILE. We do this only
1680 if an inter-comp-unit reference is found; presumably if there is one,
1681 there will be many, and one will occur early in the .debug_info section.
1682 So there's no point in building this list incrementally. */
1685 create_all_comp_units (struct objfile
*objfile
)
1689 struct dwarf2_per_cu_data
**all_comp_units
;
1690 gdb_byte
*info_ptr
= dwarf2_per_objfile
->info_buffer
;
1694 all_comp_units
= xmalloc (n_allocated
1695 * sizeof (struct dwarf2_per_cu_data
*));
1697 while (info_ptr
< dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1699 struct comp_unit_head cu_header
;
1700 gdb_byte
*beg_of_comp_unit
;
1701 struct dwarf2_per_cu_data
*this_cu
;
1702 unsigned long offset
;
1703 unsigned int bytes_read
;
1705 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
1707 /* Read just enough information to find out where the next
1708 compilation unit is. */
1709 cu_header
.initial_length_size
= 0;
1710 cu_header
.length
= read_initial_length (objfile
->obfd
, info_ptr
,
1711 &cu_header
, &bytes_read
);
1713 /* Save the compilation unit for later lookup. */
1714 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
1715 sizeof (struct dwarf2_per_cu_data
));
1716 memset (this_cu
, 0, sizeof (*this_cu
));
1717 this_cu
->offset
= offset
;
1718 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
1720 if (n_comp_units
== n_allocated
)
1723 all_comp_units
= xrealloc (all_comp_units
,
1725 * sizeof (struct dwarf2_per_cu_data
*));
1727 all_comp_units
[n_comp_units
++] = this_cu
;
1729 info_ptr
= info_ptr
+ this_cu
->length
;
1732 dwarf2_per_objfile
->all_comp_units
1733 = obstack_alloc (&objfile
->objfile_obstack
,
1734 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1735 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
1736 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1737 xfree (all_comp_units
);
1738 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
1741 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1742 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1746 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1747 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
1749 struct objfile
*objfile
= cu
->objfile
;
1750 bfd
*abfd
= objfile
->obfd
;
1751 struct partial_die_info
*pdi
;
1753 /* Now, march along the PDI's, descending into ones which have
1754 interesting children but skipping the children of the other ones,
1755 until we reach the end of the compilation unit. */
1761 fixup_partial_die (pdi
, cu
);
1763 /* Anonymous namespaces have no name but have interesting
1764 children, so we need to look at them. Ditto for anonymous
1767 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1768 || pdi
->tag
== DW_TAG_enumeration_type
)
1772 case DW_TAG_subprogram
:
1773 if (pdi
->has_pc_info
)
1775 if (pdi
->lowpc
< *lowpc
)
1777 *lowpc
= pdi
->lowpc
;
1779 if (pdi
->highpc
> *highpc
)
1781 *highpc
= pdi
->highpc
;
1783 if (!pdi
->is_declaration
)
1785 add_partial_symbol (pdi
, cu
);
1789 case DW_TAG_variable
:
1790 case DW_TAG_typedef
:
1791 case DW_TAG_union_type
:
1792 if (!pdi
->is_declaration
)
1794 add_partial_symbol (pdi
, cu
);
1797 case DW_TAG_class_type
:
1798 case DW_TAG_interface_type
:
1799 case DW_TAG_structure_type
:
1800 if (!pdi
->is_declaration
)
1802 add_partial_symbol (pdi
, cu
);
1805 case DW_TAG_enumeration_type
:
1806 if (!pdi
->is_declaration
)
1807 add_partial_enumeration (pdi
, cu
);
1809 case DW_TAG_base_type
:
1810 case DW_TAG_subrange_type
:
1811 /* File scope base type definitions are added to the partial
1813 add_partial_symbol (pdi
, cu
);
1815 case DW_TAG_namespace
:
1816 add_partial_namespace (pdi
, lowpc
, highpc
, cu
);
1823 /* If the die has a sibling, skip to the sibling. */
1825 pdi
= pdi
->die_sibling
;
1829 /* Functions used to compute the fully scoped name of a partial DIE.
1831 Normally, this is simple. For C++, the parent DIE's fully scoped
1832 name is concatenated with "::" and the partial DIE's name. For
1833 Java, the same thing occurs except that "." is used instead of "::".
1834 Enumerators are an exception; they use the scope of their parent
1835 enumeration type, i.e. the name of the enumeration type is not
1836 prepended to the enumerator.
1838 There are two complexities. One is DW_AT_specification; in this
1839 case "parent" means the parent of the target of the specification,
1840 instead of the direct parent of the DIE. The other is compilers
1841 which do not emit DW_TAG_namespace; in this case we try to guess
1842 the fully qualified name of structure types from their members'
1843 linkage names. This must be done using the DIE's children rather
1844 than the children of any DW_AT_specification target. We only need
1845 to do this for structures at the top level, i.e. if the target of
1846 any DW_AT_specification (if any; otherwise the DIE itself) does not
1849 /* Compute the scope prefix associated with PDI's parent, in
1850 compilation unit CU. The result will be allocated on CU's
1851 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1852 field. NULL is returned if no prefix is necessary. */
1854 partial_die_parent_scope (struct partial_die_info
*pdi
,
1855 struct dwarf2_cu
*cu
)
1857 char *grandparent_scope
;
1858 struct partial_die_info
*parent
, *real_pdi
;
1860 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1861 then this means the parent of the specification DIE. */
1864 while (real_pdi
->has_specification
)
1865 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
1867 parent
= real_pdi
->die_parent
;
1871 if (parent
->scope_set
)
1872 return parent
->scope
;
1874 fixup_partial_die (parent
, cu
);
1876 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
1878 if (parent
->tag
== DW_TAG_namespace
1879 || parent
->tag
== DW_TAG_structure_type
1880 || parent
->tag
== DW_TAG_class_type
1881 || parent
->tag
== DW_TAG_interface_type
1882 || parent
->tag
== DW_TAG_union_type
)
1884 if (grandparent_scope
== NULL
)
1885 parent
->scope
= parent
->name
;
1887 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
1890 else if (parent
->tag
== DW_TAG_enumeration_type
)
1891 /* Enumerators should not get the name of the enumeration as a prefix. */
1892 parent
->scope
= grandparent_scope
;
1895 /* FIXME drow/2004-04-01: What should we be doing with
1896 function-local names? For partial symbols, we should probably be
1898 complaint (&symfile_complaints
,
1899 _("unhandled containing DIE tag %d for DIE at %d"),
1900 parent
->tag
, pdi
->offset
);
1901 parent
->scope
= grandparent_scope
;
1904 parent
->scope_set
= 1;
1905 return parent
->scope
;
1908 /* Return the fully scoped name associated with PDI, from compilation unit
1909 CU. The result will be allocated with malloc. */
1911 partial_die_full_name (struct partial_die_info
*pdi
,
1912 struct dwarf2_cu
*cu
)
1916 parent_scope
= partial_die_parent_scope (pdi
, cu
);
1917 if (parent_scope
== NULL
)
1920 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
1924 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
1926 struct objfile
*objfile
= cu
->objfile
;
1928 char *actual_name
= NULL
;
1929 const char *my_prefix
;
1930 const struct partial_symbol
*psym
= NULL
;
1932 int built_actual_name
= 0;
1934 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1936 if (pdi_needs_namespace (pdi
->tag
))
1938 actual_name
= partial_die_full_name (pdi
, cu
);
1940 built_actual_name
= 1;
1943 if (actual_name
== NULL
)
1944 actual_name
= pdi
->name
;
1948 case DW_TAG_subprogram
:
1949 if (pdi
->is_external
|| cu
->language
== language_ada
)
1951 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
1952 of the global scope. But in Ada, we want to be able to access
1953 nested procedures globally. So all Ada subprograms are stored
1954 in the global scope. */
1955 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1956 mst_text, objfile); */
1957 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1958 VAR_DOMAIN
, LOC_BLOCK
,
1959 &objfile
->global_psymbols
,
1960 0, pdi
->lowpc
+ baseaddr
,
1961 cu
->language
, objfile
);
1965 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1966 mst_file_text, objfile); */
1967 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1968 VAR_DOMAIN
, LOC_BLOCK
,
1969 &objfile
->static_psymbols
,
1970 0, pdi
->lowpc
+ baseaddr
,
1971 cu
->language
, objfile
);
1974 case DW_TAG_variable
:
1975 if (pdi
->is_external
)
1978 Don't enter into the minimal symbol tables as there is
1979 a minimal symbol table entry from the ELF symbols already.
1980 Enter into partial symbol table if it has a location
1981 descriptor or a type.
1982 If the location descriptor is missing, new_symbol will create
1983 a LOC_UNRESOLVED symbol, the address of the variable will then
1984 be determined from the minimal symbol table whenever the variable
1986 The address for the partial symbol table entry is not
1987 used by GDB, but it comes in handy for debugging partial symbol
1991 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1992 if (pdi
->locdesc
|| pdi
->has_type
)
1993 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1994 VAR_DOMAIN
, LOC_STATIC
,
1995 &objfile
->global_psymbols
,
1997 cu
->language
, objfile
);
2001 /* Static Variable. Skip symbols without location descriptors. */
2002 if (pdi
->locdesc
== NULL
)
2004 if (built_actual_name
)
2005 xfree (actual_name
);
2008 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2009 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2010 mst_file_data, objfile); */
2011 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2012 VAR_DOMAIN
, LOC_STATIC
,
2013 &objfile
->static_psymbols
,
2015 cu
->language
, objfile
);
2018 case DW_TAG_typedef
:
2019 case DW_TAG_base_type
:
2020 case DW_TAG_subrange_type
:
2021 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2022 VAR_DOMAIN
, LOC_TYPEDEF
,
2023 &objfile
->static_psymbols
,
2024 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2026 case DW_TAG_namespace
:
2027 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2028 VAR_DOMAIN
, LOC_TYPEDEF
,
2029 &objfile
->global_psymbols
,
2030 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2032 case DW_TAG_class_type
:
2033 case DW_TAG_interface_type
:
2034 case DW_TAG_structure_type
:
2035 case DW_TAG_union_type
:
2036 case DW_TAG_enumeration_type
:
2037 /* Skip external references. The DWARF standard says in the section
2038 about "Structure, Union, and Class Type Entries": "An incomplete
2039 structure, union or class type is represented by a structure,
2040 union or class entry that does not have a byte size attribute
2041 and that has a DW_AT_declaration attribute." */
2042 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2044 if (built_actual_name
)
2045 xfree (actual_name
);
2049 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2050 static vs. global. */
2051 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2052 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2053 (cu
->language
== language_cplus
2054 || cu
->language
== language_java
)
2055 ? &objfile
->global_psymbols
2056 : &objfile
->static_psymbols
,
2057 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2060 case DW_TAG_enumerator
:
2061 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2062 VAR_DOMAIN
, LOC_CONST
,
2063 (cu
->language
== language_cplus
2064 || cu
->language
== language_java
)
2065 ? &objfile
->global_psymbols
2066 : &objfile
->static_psymbols
,
2067 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2073 /* Check to see if we should scan the name for possible namespace
2074 info. Only do this if this is C++, if we don't have namespace
2075 debugging info in the file, if the psym is of an appropriate type
2076 (otherwise we'll have psym == NULL), and if we actually had a
2077 mangled name to begin with. */
2079 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2080 cases which do not set PSYM above? */
2082 if (cu
->language
== language_cplus
2083 && cu
->has_namespace_info
== 0
2085 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
2086 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
2089 if (built_actual_name
)
2090 xfree (actual_name
);
2093 /* Determine whether a die of type TAG living in a C++ class or
2094 namespace needs to have the name of the scope prepended to the
2095 name listed in the die. */
2098 pdi_needs_namespace (enum dwarf_tag tag
)
2102 case DW_TAG_namespace
:
2103 case DW_TAG_typedef
:
2104 case DW_TAG_class_type
:
2105 case DW_TAG_interface_type
:
2106 case DW_TAG_structure_type
:
2107 case DW_TAG_union_type
:
2108 case DW_TAG_enumeration_type
:
2109 case DW_TAG_enumerator
:
2116 /* Read a partial die corresponding to a namespace; also, add a symbol
2117 corresponding to that namespace to the symbol table. NAMESPACE is
2118 the name of the enclosing namespace. */
2121 add_partial_namespace (struct partial_die_info
*pdi
,
2122 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2123 struct dwarf2_cu
*cu
)
2125 struct objfile
*objfile
= cu
->objfile
;
2127 /* Add a symbol for the namespace. */
2129 add_partial_symbol (pdi
, cu
);
2131 /* Now scan partial symbols in that namespace. */
2133 if (pdi
->has_children
)
2134 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, cu
);
2137 /* See if we can figure out if the class lives in a namespace. We do
2138 this by looking for a member function; its demangled name will
2139 contain namespace info, if there is any. */
2142 guess_structure_name (struct partial_die_info
*struct_pdi
,
2143 struct dwarf2_cu
*cu
)
2145 if ((cu
->language
== language_cplus
2146 || cu
->language
== language_java
)
2147 && cu
->has_namespace_info
== 0
2148 && struct_pdi
->has_children
)
2150 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2151 what template types look like, because the demangler
2152 frequently doesn't give the same name as the debug info. We
2153 could fix this by only using the demangled name to get the
2154 prefix (but see comment in read_structure_type). */
2156 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
2157 struct partial_die_info
*real_pdi
;
2159 /* If this DIE (this DIE's specification, if any) has a parent, then
2160 we should not do this. We'll prepend the parent's fully qualified
2161 name when we create the partial symbol. */
2163 real_pdi
= struct_pdi
;
2164 while (real_pdi
->has_specification
)
2165 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2167 if (real_pdi
->die_parent
!= NULL
)
2170 while (child_pdi
!= NULL
)
2172 if (child_pdi
->tag
== DW_TAG_subprogram
)
2174 char *actual_class_name
2175 = language_class_name_from_physname (cu
->language_defn
,
2177 if (actual_class_name
!= NULL
)
2180 = obsavestring (actual_class_name
,
2181 strlen (actual_class_name
),
2182 &cu
->comp_unit_obstack
);
2183 xfree (actual_class_name
);
2188 child_pdi
= child_pdi
->die_sibling
;
2193 /* Read a partial die corresponding to an enumeration type. */
2196 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2197 struct dwarf2_cu
*cu
)
2199 struct objfile
*objfile
= cu
->objfile
;
2200 bfd
*abfd
= objfile
->obfd
;
2201 struct partial_die_info
*pdi
;
2203 if (enum_pdi
->name
!= NULL
)
2204 add_partial_symbol (enum_pdi
, cu
);
2206 pdi
= enum_pdi
->die_child
;
2209 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2210 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2212 add_partial_symbol (pdi
, cu
);
2213 pdi
= pdi
->die_sibling
;
2217 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2218 Return the corresponding abbrev, or NULL if the number is zero (indicating
2219 an empty DIE). In either case *BYTES_READ will be set to the length of
2220 the initial number. */
2222 static struct abbrev_info
*
2223 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2224 struct dwarf2_cu
*cu
)
2226 bfd
*abfd
= cu
->objfile
->obfd
;
2227 unsigned int abbrev_number
;
2228 struct abbrev_info
*abbrev
;
2230 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2232 if (abbrev_number
== 0)
2235 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2238 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2239 bfd_get_filename (abfd
));
2245 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2246 pointer to the end of a series of DIEs, terminated by an empty
2247 DIE. Any children of the skipped DIEs will also be skipped. */
2250 skip_children (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2252 struct abbrev_info
*abbrev
;
2253 unsigned int bytes_read
;
2257 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2259 return info_ptr
+ bytes_read
;
2261 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
2265 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2266 should point just after the initial uleb128 of a DIE, and the
2267 abbrev corresponding to that skipped uleb128 should be passed in
2268 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2272 skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
2273 struct dwarf2_cu
*cu
)
2275 unsigned int bytes_read
;
2276 struct attribute attr
;
2277 bfd
*abfd
= cu
->objfile
->obfd
;
2278 unsigned int form
, i
;
2280 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2282 /* The only abbrev we care about is DW_AT_sibling. */
2283 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2285 read_attribute (&attr
, &abbrev
->attrs
[i
],
2286 abfd
, info_ptr
, cu
);
2287 if (attr
.form
== DW_FORM_ref_addr
)
2288 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2290 return dwarf2_per_objfile
->info_buffer
2291 + dwarf2_get_ref_die_offset (&attr
, cu
);
2294 /* If it isn't DW_AT_sibling, skip this attribute. */
2295 form
= abbrev
->attrs
[i
].form
;
2300 case DW_FORM_ref_addr
:
2301 info_ptr
+= cu
->header
.addr_size
;
2320 case DW_FORM_string
:
2321 read_string (abfd
, info_ptr
, &bytes_read
);
2322 info_ptr
+= bytes_read
;
2325 info_ptr
+= cu
->header
.offset_size
;
2328 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2329 info_ptr
+= bytes_read
;
2331 case DW_FORM_block1
:
2332 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2334 case DW_FORM_block2
:
2335 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2337 case DW_FORM_block4
:
2338 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2342 case DW_FORM_ref_udata
:
2343 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2345 case DW_FORM_indirect
:
2346 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2347 info_ptr
+= bytes_read
;
2348 /* We need to continue parsing from here, so just go back to
2350 goto skip_attribute
;
2353 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2354 dwarf_form_name (form
),
2355 bfd_get_filename (abfd
));
2359 if (abbrev
->has_children
)
2360 return skip_children (info_ptr
, cu
);
2365 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2366 the next DIE after ORIG_PDI. */
2369 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, gdb_byte
*info_ptr
,
2370 bfd
*abfd
, struct dwarf2_cu
*cu
)
2372 /* Do we know the sibling already? */
2374 if (orig_pdi
->sibling
)
2375 return orig_pdi
->sibling
;
2377 /* Are there any children to deal with? */
2379 if (!orig_pdi
->has_children
)
2382 /* Skip the children the long way. */
2384 return skip_children (info_ptr
, cu
);
2387 /* Expand this partial symbol table into a full symbol table. */
2390 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2392 /* FIXME: This is barely more than a stub. */
2397 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2403 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2404 gdb_flush (gdb_stdout
);
2407 /* Restore our global data. */
2408 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2409 dwarf2_objfile_data_key
);
2411 psymtab_to_symtab_1 (pst
);
2413 /* Finish up the debug error message. */
2415 printf_filtered (_("done.\n"));
2420 /* Add PER_CU to the queue. */
2423 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2425 struct dwarf2_queue_item
*item
;
2428 item
= xmalloc (sizeof (*item
));
2429 item
->per_cu
= per_cu
;
2432 if (dwarf2_queue
== NULL
)
2433 dwarf2_queue
= item
;
2435 dwarf2_queue_tail
->next
= item
;
2437 dwarf2_queue_tail
= item
;
2440 /* Process the queue. */
2443 process_queue (struct objfile
*objfile
)
2445 struct dwarf2_queue_item
*item
, *next_item
;
2447 /* Initially, there is just one item on the queue. Load its DIEs,
2448 and the DIEs of any other compilation units it requires,
2451 for (item
= dwarf2_queue
; item
!= NULL
; item
= item
->next
)
2453 /* Read in this compilation unit. This may add new items to
2454 the end of the queue. */
2455 load_full_comp_unit (item
->per_cu
, objfile
);
2457 item
->per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
2458 dwarf2_per_objfile
->read_in_chain
= item
->per_cu
;
2461 /* Now everything left on the queue needs to be read in. Process
2462 them, one at a time, removing from the queue as we finish. */
2463 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2465 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2466 process_full_comp_unit (item
->per_cu
);
2468 item
->per_cu
->queued
= 0;
2469 next_item
= item
->next
;
2473 dwarf2_queue_tail
= NULL
;
2476 /* Free all allocated queue entries. This function only releases anything if
2477 an error was thrown; if the queue was processed then it would have been
2478 freed as we went along. */
2481 dwarf2_release_queue (void *dummy
)
2483 struct dwarf2_queue_item
*item
, *last
;
2485 item
= dwarf2_queue
;
2488 /* Anything still marked queued is likely to be in an
2489 inconsistent state, so discard it. */
2490 if (item
->per_cu
->queued
)
2492 if (item
->per_cu
->cu
!= NULL
)
2493 free_one_cached_comp_unit (item
->per_cu
->cu
);
2494 item
->per_cu
->queued
= 0;
2502 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2505 /* Read in full symbols for PST, and anything it depends on. */
2508 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2510 struct dwarf2_per_cu_data
*per_cu
;
2511 struct cleanup
*back_to
;
2514 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2515 if (!pst
->dependencies
[i
]->readin
)
2517 /* Inform about additional files that need to be read in. */
2520 /* FIXME: i18n: Need to make this a single string. */
2521 fputs_filtered (" ", gdb_stdout
);
2523 fputs_filtered ("and ", gdb_stdout
);
2525 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2526 wrap_here (""); /* Flush output */
2527 gdb_flush (gdb_stdout
);
2529 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2532 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
2536 /* It's an include file, no symbols to read for it.
2537 Everything is in the parent symtab. */
2542 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2544 queue_comp_unit (per_cu
);
2546 process_queue (pst
->objfile
);
2548 /* Age the cache, releasing compilation units that have not
2549 been used recently. */
2550 age_cached_comp_units ();
2552 do_cleanups (back_to
);
2555 /* Load the DIEs associated with PST and PER_CU into memory. */
2557 static struct dwarf2_cu
*
2558 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2560 bfd
*abfd
= objfile
->obfd
;
2561 struct dwarf2_cu
*cu
;
2562 unsigned long offset
;
2564 struct cleanup
*back_to
, *free_cu_cleanup
;
2565 struct attribute
*attr
;
2568 /* Set local variables from the partial symbol table info. */
2569 offset
= per_cu
->offset
;
2571 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2573 cu
= xmalloc (sizeof (struct dwarf2_cu
));
2574 memset (cu
, 0, sizeof (struct dwarf2_cu
));
2576 /* If an error occurs while loading, release our storage. */
2577 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
2579 cu
->objfile
= objfile
;
2581 /* read in the comp_unit header */
2582 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
2584 /* Read the abbrevs for this compilation unit */
2585 dwarf2_read_abbrevs (abfd
, cu
);
2586 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2588 cu
->header
.offset
= offset
;
2590 cu
->per_cu
= per_cu
;
2592 cu
->type_hash
= per_cu
->type_hash
;
2594 /* We use this obstack for block values in dwarf_alloc_block. */
2595 obstack_init (&cu
->comp_unit_obstack
);
2597 cu
->dies
= read_comp_unit (info_ptr
, abfd
, cu
);
2599 /* We try not to read any attributes in this function, because not
2600 all objfiles needed for references have been loaded yet, and symbol
2601 table processing isn't initialized. But we have to set the CU language,
2602 or we won't be able to build types correctly. */
2603 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
2605 set_cu_language (DW_UNSND (attr
), cu
);
2607 set_cu_language (language_minimal
, cu
);
2609 do_cleanups (back_to
);
2611 /* We've successfully allocated this compilation unit. Let our caller
2612 clean it up when finished with it. */
2613 discard_cleanups (free_cu_cleanup
);
2618 /* Generate full symbol information for PST and CU, whose DIEs have
2619 already been loaded into memory. */
2622 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2624 struct partial_symtab
*pst
= per_cu
->psymtab
;
2625 struct dwarf2_cu
*cu
= per_cu
->cu
;
2626 struct objfile
*objfile
= pst
->objfile
;
2627 bfd
*abfd
= objfile
->obfd
;
2628 CORE_ADDR lowpc
, highpc
;
2629 struct symtab
*symtab
;
2630 struct cleanup
*back_to
;
2631 struct attribute
*attr
;
2634 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2636 /* We're in the global namespace. */
2637 processing_current_prefix
= "";
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
);
2773 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2775 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2779 free_cu_line_header (void *arg
)
2781 struct dwarf2_cu
*cu
= arg
;
2783 free_line_header (cu
->line_header
);
2784 cu
->line_header
= NULL
;
2788 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2790 struct objfile
*objfile
= cu
->objfile
;
2791 struct comp_unit_head
*cu_header
= &cu
->header
;
2792 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2793 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2794 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2795 struct attribute
*attr
;
2797 char *comp_dir
= NULL
;
2798 struct die_info
*child_die
;
2799 bfd
*abfd
= objfile
->obfd
;
2800 struct line_header
*line_header
= 0;
2803 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2805 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2807 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2808 from finish_block. */
2809 if (lowpc
== ((CORE_ADDR
) -1))
2814 /* Find the filename. Do not use dwarf2_name here, since the filename
2815 is not a source language identifier. */
2816 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2819 name
= DW_STRING (attr
);
2822 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2824 comp_dir
= DW_STRING (attr
);
2825 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
2827 comp_dir
= ldirname (name
);
2828 if (comp_dir
!= NULL
)
2829 make_cleanup (xfree
, comp_dir
);
2831 if (comp_dir
!= NULL
)
2833 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2834 directory, get rid of it. */
2835 char *cp
= strchr (comp_dir
, ':');
2837 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2844 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2847 set_cu_language (DW_UNSND (attr
), cu
);
2850 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
2852 cu
->producer
= DW_STRING (attr
);
2854 /* We assume that we're processing GCC output. */
2855 processing_gcc_compilation
= 2;
2857 start_symtab (name
, comp_dir
, lowpc
);
2858 record_debugformat ("DWARF 2");
2859 record_producer (cu
->producer
);
2861 initialize_cu_func_list (cu
);
2863 /* Decode line number information if present. We do this before
2864 processing child DIEs, so that the line header table is available
2865 for DW_AT_decl_file. */
2866 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2869 unsigned int line_offset
= DW_UNSND (attr
);
2870 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2873 cu
->line_header
= line_header
;
2874 make_cleanup (free_cu_line_header
, cu
);
2875 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
2879 /* Process all dies in compilation unit. */
2880 if (die
->child
!= NULL
)
2882 child_die
= die
->child
;
2883 while (child_die
&& child_die
->tag
)
2885 process_die (child_die
, cu
);
2886 child_die
= sibling_die (child_die
);
2890 /* Decode macro information, if present. Dwarf 2 macro information
2891 refers to information in the line number info statement program
2892 header, so we can only read it if we've read the header
2894 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2895 if (attr
&& line_header
)
2897 unsigned int macro_offset
= DW_UNSND (attr
);
2898 dwarf_decode_macros (line_header
, macro_offset
,
2899 comp_dir
, abfd
, cu
);
2901 do_cleanups (back_to
);
2905 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2906 struct dwarf2_cu
*cu
)
2908 struct function_range
*thisfn
;
2910 thisfn
= (struct function_range
*)
2911 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
2912 thisfn
->name
= name
;
2913 thisfn
->lowpc
= lowpc
;
2914 thisfn
->highpc
= highpc
;
2915 thisfn
->seen_line
= 0;
2916 thisfn
->next
= NULL
;
2918 if (cu
->last_fn
== NULL
)
2919 cu
->first_fn
= thisfn
;
2921 cu
->last_fn
->next
= thisfn
;
2923 cu
->last_fn
= thisfn
;
2927 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2929 struct objfile
*objfile
= cu
->objfile
;
2930 struct context_stack
*new;
2933 struct die_info
*child_die
;
2934 struct attribute
*attr
;
2936 const char *previous_prefix
= processing_current_prefix
;
2937 struct cleanup
*back_to
= NULL
;
2939 struct block
*block
;
2941 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2943 name
= dwarf2_linkage_name (die
, cu
);
2945 /* Ignore functions with missing or empty names and functions with
2946 missing or invalid low and high pc attributes. */
2947 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2950 if (cu
->language
== language_cplus
2951 || cu
->language
== language_java
)
2953 struct die_info
*spec_die
= die_specification (die
, cu
);
2955 /* NOTE: carlton/2004-01-23: We have to be careful in the
2956 presence of DW_AT_specification. For example, with GCC 3.4,
2961 // Definition of N::foo.
2965 then we'll have a tree of DIEs like this:
2967 1: DW_TAG_compile_unit
2968 2: DW_TAG_namespace // N
2969 3: DW_TAG_subprogram // declaration of N::foo
2970 4: DW_TAG_subprogram // definition of N::foo
2971 DW_AT_specification // refers to die #3
2973 Thus, when processing die #4, we have to pretend that we're
2974 in the context of its DW_AT_specification, namely the contex
2977 if (spec_die
!= NULL
)
2979 char *specification_prefix
= determine_prefix (spec_die
, cu
);
2980 processing_current_prefix
= specification_prefix
;
2981 back_to
= make_cleanup (xfree
, specification_prefix
);
2988 /* Record the function range for dwarf_decode_lines. */
2989 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
2991 new = push_context (0, lowpc
);
2992 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
2994 /* If there is a location expression for DW_AT_frame_base, record
2996 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
2998 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
2999 expression is being recorded directly in the function's symbol
3000 and not in a separate frame-base object. I guess this hack is
3001 to avoid adding some sort of frame-base adjunct/annex to the
3002 function's symbol :-(. The problem with doing this is that it
3003 results in a function symbol with a location expression that
3004 has nothing to do with the location of the function, ouch! The
3005 relationship should be: a function's symbol has-a frame base; a
3006 frame-base has-a location expression. */
3007 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3009 cu
->list_in_scope
= &local_symbols
;
3011 if (die
->child
!= NULL
)
3013 child_die
= die
->child
;
3014 while (child_die
&& child_die
->tag
)
3016 process_die (child_die
, cu
);
3017 child_die
= sibling_die (child_die
);
3021 new = pop_context ();
3022 /* Make a block for the local symbols within. */
3023 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3024 lowpc
, highpc
, objfile
);
3026 /* If we have address ranges, record them. */
3027 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3029 /* In C++, we can have functions nested inside functions (e.g., when
3030 a function declares a class that has methods). This means that
3031 when we finish processing a function scope, we may need to go
3032 back to building a containing block's symbol lists. */
3033 local_symbols
= new->locals
;
3034 param_symbols
= new->params
;
3036 /* If we've finished processing a top-level function, subsequent
3037 symbols go in the file symbol list. */
3038 if (outermost_context_p ())
3039 cu
->list_in_scope
= &file_symbols
;
3041 processing_current_prefix
= previous_prefix
;
3042 if (back_to
!= NULL
)
3043 do_cleanups (back_to
);
3046 /* Process all the DIES contained within a lexical block scope. Start
3047 a new scope, process the dies, and then close the scope. */
3050 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3052 struct objfile
*objfile
= cu
->objfile
;
3053 struct context_stack
*new;
3054 CORE_ADDR lowpc
, highpc
;
3055 struct die_info
*child_die
;
3058 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3060 /* Ignore blocks with missing or invalid low and high pc attributes. */
3061 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3062 as multiple lexical blocks? Handling children in a sane way would
3063 be nasty. Might be easier to properly extend generic blocks to
3065 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3070 push_context (0, lowpc
);
3071 if (die
->child
!= NULL
)
3073 child_die
= die
->child
;
3074 while (child_die
&& child_die
->tag
)
3076 process_die (child_die
, cu
);
3077 child_die
= sibling_die (child_die
);
3080 new = pop_context ();
3082 if (local_symbols
!= NULL
)
3085 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3088 /* Note that recording ranges after traversing children, as we
3089 do here, means that recording a parent's ranges entails
3090 walking across all its children's ranges as they appear in
3091 the address map, which is quadratic behavior.
3093 It would be nicer to record the parent's ranges before
3094 traversing its children, simply overriding whatever you find
3095 there. But since we don't even decide whether to create a
3096 block until after we've traversed its children, that's hard
3098 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3100 local_symbols
= new->locals
;
3103 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3104 Return 1 if the attributes are present and valid, otherwise, return 0.
3105 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3108 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
3109 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
3110 struct partial_symtab
*ranges_pst
)
3112 struct objfile
*objfile
= cu
->objfile
;
3113 struct comp_unit_head
*cu_header
= &cu
->header
;
3114 bfd
*obfd
= objfile
->obfd
;
3115 unsigned int addr_size
= cu_header
->addr_size
;
3116 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3117 /* Base address selection entry. */
3128 found_base
= cu_header
->base_known
;
3129 base
= cu_header
->base_address
;
3131 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3133 complaint (&symfile_complaints
,
3134 _("Offset %d out of bounds for DW_AT_ranges attribute"),
3138 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3140 /* Read in the largest possible address. */
3141 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
3142 if ((marker
& mask
) == mask
)
3144 /* If we found the largest possible address, then
3145 read the base address. */
3146 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3147 buffer
+= 2 * addr_size
;
3148 offset
+= 2 * addr_size
;
3154 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3158 CORE_ADDR range_beginning
, range_end
;
3160 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
3161 buffer
+= addr_size
;
3162 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
3163 buffer
+= addr_size
;
3164 offset
+= 2 * addr_size
;
3166 /* An end of list marker is a pair of zero addresses. */
3167 if (range_beginning
== 0 && range_end
== 0)
3168 /* Found the end of list entry. */
3171 /* Each base address selection entry is a pair of 2 values.
3172 The first is the largest possible address, the second is
3173 the base address. Check for a base address here. */
3174 if ((range_beginning
& mask
) == mask
)
3176 /* If we found the largest possible address, then
3177 read the base address. */
3178 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3185 /* We have no valid base address for the ranges
3187 complaint (&symfile_complaints
,
3188 _("Invalid .debug_ranges data (no base address)"));
3192 range_beginning
+= base
;
3195 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
3196 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3197 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
3200 /* FIXME: This is recording everything as a low-high
3201 segment of consecutive addresses. We should have a
3202 data structure for discontiguous block ranges
3206 low
= range_beginning
;
3212 if (range_beginning
< low
)
3213 low
= range_beginning
;
3214 if (range_end
> high
)
3220 /* If the first entry is an end-of-list marker, the range
3221 describes an empty scope, i.e. no instructions. */
3227 *high_return
= high
;
3231 /* Get low and high pc attributes from a die. Return 1 if the attributes
3232 are present and valid, otherwise, return 0. Return -1 if the range is
3233 discontinuous, i.e. derived from DW_AT_ranges information. */
3235 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
3236 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
3238 struct attribute
*attr
;
3243 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3246 high
= DW_ADDR (attr
);
3247 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3249 low
= DW_ADDR (attr
);
3251 /* Found high w/o low attribute. */
3254 /* Found consecutive range of addresses. */
3259 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3262 /* Value of the DW_AT_ranges attribute is the offset in the
3263 .debug_ranges section. */
3264 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, NULL
))
3266 /* Found discontinuous range of addresses. */
3274 /* When using the GNU linker, .gnu.linkonce. sections are used to
3275 eliminate duplicate copies of functions and vtables and such.
3276 The linker will arbitrarily choose one and discard the others.
3277 The AT_*_pc values for such functions refer to local labels in
3278 these sections. If the section from that file was discarded, the
3279 labels are not in the output, so the relocs get a value of 0.
3280 If this is a discarded function, mark the pc bounds as invalid,
3281 so that GDB will ignore it. */
3282 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3290 /* Get the low and high pc's represented by the scope DIE, and store
3291 them in *LOWPC and *HIGHPC. If the correct values can't be
3292 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3295 get_scope_pc_bounds (struct die_info
*die
,
3296 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3297 struct dwarf2_cu
*cu
)
3299 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3300 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3301 CORE_ADDR current_low
, current_high
;
3303 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3305 best_low
= current_low
;
3306 best_high
= current_high
;
3310 struct die_info
*child
= die
->child
;
3312 while (child
&& child
->tag
)
3314 switch (child
->tag
) {
3315 case DW_TAG_subprogram
:
3316 if (dwarf2_get_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
))
3318 best_low
= min (best_low
, current_low
);
3319 best_high
= max (best_high
, current_high
);
3322 case DW_TAG_namespace
:
3323 /* FIXME: carlton/2004-01-16: Should we do this for
3324 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3325 that current GCC's always emit the DIEs corresponding
3326 to definitions of methods of classes as children of a
3327 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3328 the DIEs giving the declarations, which could be
3329 anywhere). But I don't see any reason why the
3330 standards says that they have to be there. */
3331 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3333 if (current_low
!= ((CORE_ADDR
) -1))
3335 best_low
= min (best_low
, current_low
);
3336 best_high
= max (best_high
, current_high
);
3344 child
= sibling_die (child
);
3349 *highpc
= best_high
;
3352 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
3355 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
3356 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
3358 struct attribute
*attr
;
3360 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3363 CORE_ADDR high
= DW_ADDR (attr
);
3364 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3367 CORE_ADDR low
= DW_ADDR (attr
);
3368 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
3372 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3375 bfd
*obfd
= cu
->objfile
->obfd
;
3377 /* The value of the DW_AT_ranges attribute is the offset of the
3378 address range list in the .debug_ranges section. */
3379 unsigned long offset
= DW_UNSND (attr
);
3380 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3382 /* For some target architectures, but not others, the
3383 read_address function sign-extends the addresses it returns.
3384 To recognize base address selection entries, we need a
3386 unsigned int addr_size
= cu
->header
.addr_size
;
3387 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3389 /* The base address, to which the next pair is relative. Note
3390 that this 'base' is a DWARF concept: most entries in a range
3391 list are relative, to reduce the number of relocs against the
3392 debugging information. This is separate from this function's
3393 'baseaddr' argument, which GDB uses to relocate debugging
3394 information from a shared library based on the address at
3395 which the library was loaded. */
3396 CORE_ADDR base
= cu
->header
.base_address
;
3397 int base_known
= cu
->header
.base_known
;
3399 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3401 complaint (&symfile_complaints
,
3402 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
3409 unsigned int bytes_read
;
3410 CORE_ADDR start
, end
;
3412 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3413 buffer
+= bytes_read
;
3414 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3415 buffer
+= bytes_read
;
3417 /* Did we find the end of the range list? */
3418 if (start
== 0 && end
== 0)
3421 /* Did we find a base address selection entry? */
3422 else if ((start
& base_select_mask
) == base_select_mask
)
3428 /* We found an ordinary address range. */
3433 complaint (&symfile_complaints
,
3434 _("Invalid .debug_ranges data (no base address)"));
3438 record_block_range (block
,
3439 baseaddr
+ base
+ start
,
3440 baseaddr
+ base
+ end
- 1);
3446 /* Add an aggregate field to the field list. */
3449 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3450 struct dwarf2_cu
*cu
)
3452 struct objfile
*objfile
= cu
->objfile
;
3453 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3454 struct nextfield
*new_field
;
3455 struct attribute
*attr
;
3457 char *fieldname
= "";
3459 /* Allocate a new field list entry and link it in. */
3460 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3461 make_cleanup (xfree
, new_field
);
3462 memset (new_field
, 0, sizeof (struct nextfield
));
3463 new_field
->next
= fip
->fields
;
3464 fip
->fields
= new_field
;
3467 /* Handle accessibility and virtuality of field.
3468 The default accessibility for members is public, the default
3469 accessibility for inheritance is private. */
3470 if (die
->tag
!= DW_TAG_inheritance
)
3471 new_field
->accessibility
= DW_ACCESS_public
;
3473 new_field
->accessibility
= DW_ACCESS_private
;
3474 new_field
->virtuality
= DW_VIRTUALITY_none
;
3476 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3478 new_field
->accessibility
= DW_UNSND (attr
);
3479 if (new_field
->accessibility
!= DW_ACCESS_public
)
3480 fip
->non_public_fields
= 1;
3481 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3483 new_field
->virtuality
= DW_UNSND (attr
);
3485 fp
= &new_field
->field
;
3487 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3489 /* Data member other than a C++ static data member. */
3491 /* Get type of field. */
3492 fp
->type
= die_type (die
, cu
);
3494 FIELD_STATIC_KIND (*fp
) = 0;
3496 /* Get bit size of field (zero if none). */
3497 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3500 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3504 FIELD_BITSIZE (*fp
) = 0;
3507 /* Get bit offset of field. */
3508 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3513 if (attr_form_is_section_offset (attr
))
3515 dwarf2_complex_location_expr_complaint ();
3518 else if (attr_form_is_constant (attr
))
3519 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
3521 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
3523 FIELD_BITPOS (*fp
) = byte_offset
* bits_per_byte
;
3526 FIELD_BITPOS (*fp
) = 0;
3527 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3530 if (gdbarch_bits_big_endian (gdbarch
))
3532 /* For big endian bits, the DW_AT_bit_offset gives the
3533 additional bit offset from the MSB of the containing
3534 anonymous object to the MSB of the field. We don't
3535 have to do anything special since we don't need to
3536 know the size of the anonymous object. */
3537 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3541 /* For little endian bits, compute the bit offset to the
3542 MSB of the anonymous object, subtract off the number of
3543 bits from the MSB of the field to the MSB of the
3544 object, and then subtract off the number of bits of
3545 the field itself. The result is the bit offset of
3546 the LSB of the field. */
3548 int bit_offset
= DW_UNSND (attr
);
3550 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3553 /* The size of the anonymous object containing
3554 the bit field is explicit, so use the
3555 indicated size (in bytes). */
3556 anonymous_size
= DW_UNSND (attr
);
3560 /* The size of the anonymous object containing
3561 the bit field must be inferred from the type
3562 attribute of the data member containing the
3564 anonymous_size
= TYPE_LENGTH (fp
->type
);
3566 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
3567 - bit_offset
- FIELD_BITSIZE (*fp
);
3571 /* Get name of field. */
3572 fieldname
= dwarf2_name (die
, cu
);
3573 if (fieldname
== NULL
)
3576 /* The name is already allocated along with this objfile, so we don't
3577 need to duplicate it for the type. */
3578 fp
->name
= fieldname
;
3580 /* Change accessibility for artificial fields (e.g. virtual table
3581 pointer or virtual base class pointer) to private. */
3582 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
3584 new_field
->accessibility
= DW_ACCESS_private
;
3585 fip
->non_public_fields
= 1;
3588 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
3590 /* C++ static member. */
3592 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3593 is a declaration, but all versions of G++ as of this writing
3594 (so through at least 3.2.1) incorrectly generate
3595 DW_TAG_variable tags. */
3599 /* Get name of field. */
3600 fieldname
= dwarf2_name (die
, cu
);
3601 if (fieldname
== NULL
)
3604 /* Get physical name. */
3605 physname
= dwarf2_linkage_name (die
, cu
);
3607 /* The name is already allocated along with this objfile, so we don't
3608 need to duplicate it for the type. */
3609 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
3610 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3611 FIELD_NAME (*fp
) = fieldname
;
3613 else if (die
->tag
== DW_TAG_inheritance
)
3615 /* C++ base class field. */
3616 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3618 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
3620 FIELD_BITSIZE (*fp
) = 0;
3621 FIELD_STATIC_KIND (*fp
) = 0;
3622 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3623 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
3624 fip
->nbaseclasses
++;
3628 /* Create the vector of fields, and attach it to the type. */
3631 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3632 struct dwarf2_cu
*cu
)
3634 int nfields
= fip
->nfields
;
3636 /* Record the field count, allocate space for the array of fields,
3637 and create blank accessibility bitfields if necessary. */
3638 TYPE_NFIELDS (type
) = nfields
;
3639 TYPE_FIELDS (type
) = (struct field
*)
3640 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3641 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3643 if (fip
->non_public_fields
)
3645 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3647 TYPE_FIELD_PRIVATE_BITS (type
) =
3648 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3649 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3651 TYPE_FIELD_PROTECTED_BITS (type
) =
3652 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3653 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3655 TYPE_FIELD_IGNORE_BITS (type
) =
3656 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3657 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3660 /* If the type has baseclasses, allocate and clear a bit vector for
3661 TYPE_FIELD_VIRTUAL_BITS. */
3662 if (fip
->nbaseclasses
)
3664 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3665 unsigned char *pointer
;
3667 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3668 pointer
= TYPE_ALLOC (type
, num_bytes
);
3669 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
3670 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3671 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3674 /* Copy the saved-up fields into the field vector. Start from the head
3675 of the list, adding to the tail of the field array, so that they end
3676 up in the same order in the array in which they were added to the list. */
3677 while (nfields
-- > 0)
3679 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3680 switch (fip
->fields
->accessibility
)
3682 case DW_ACCESS_private
:
3683 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3686 case DW_ACCESS_protected
:
3687 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3690 case DW_ACCESS_public
:
3694 /* Unknown accessibility. Complain and treat it as public. */
3696 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
3697 fip
->fields
->accessibility
);
3701 if (nfields
< fip
->nbaseclasses
)
3703 switch (fip
->fields
->virtuality
)
3705 case DW_VIRTUALITY_virtual
:
3706 case DW_VIRTUALITY_pure_virtual
:
3707 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3711 fip
->fields
= fip
->fields
->next
;
3715 /* Add a member function to the proper fieldlist. */
3718 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3719 struct type
*type
, struct dwarf2_cu
*cu
)
3721 struct objfile
*objfile
= cu
->objfile
;
3722 struct attribute
*attr
;
3723 struct fnfieldlist
*flp
;
3725 struct fn_field
*fnp
;
3728 struct nextfnfield
*new_fnfield
;
3729 struct type
*this_type
;
3731 /* Get name of member function. */
3732 fieldname
= dwarf2_name (die
, cu
);
3733 if (fieldname
== NULL
)
3736 /* Get the mangled name. */
3737 physname
= dwarf2_linkage_name (die
, cu
);
3739 /* Look up member function name in fieldlist. */
3740 for (i
= 0; i
< fip
->nfnfields
; i
++)
3742 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3746 /* Create new list element if necessary. */
3747 if (i
< fip
->nfnfields
)
3748 flp
= &fip
->fnfieldlists
[i
];
3751 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3753 fip
->fnfieldlists
= (struct fnfieldlist
*)
3754 xrealloc (fip
->fnfieldlists
,
3755 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3756 * sizeof (struct fnfieldlist
));
3757 if (fip
->nfnfields
== 0)
3758 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3760 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3761 flp
->name
= fieldname
;
3767 /* Create a new member function field and chain it to the field list
3769 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3770 make_cleanup (xfree
, new_fnfield
);
3771 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3772 new_fnfield
->next
= flp
->head
;
3773 flp
->head
= new_fnfield
;
3776 /* Fill in the member function field info. */
3777 fnp
= &new_fnfield
->fnfield
;
3778 /* The name is already allocated along with this objfile, so we don't
3779 need to duplicate it for the type. */
3780 fnp
->physname
= physname
? physname
: "";
3781 fnp
->type
= alloc_type (objfile
);
3782 this_type
= read_type_die (die
, cu
);
3783 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
3785 int nparams
= TYPE_NFIELDS (this_type
);
3787 /* TYPE is the domain of this method, and THIS_TYPE is the type
3788 of the method itself (TYPE_CODE_METHOD). */
3789 smash_to_method_type (fnp
->type
, type
,
3790 TYPE_TARGET_TYPE (this_type
),
3791 TYPE_FIELDS (this_type
),
3792 TYPE_NFIELDS (this_type
),
3793 TYPE_VARARGS (this_type
));
3795 /* Handle static member functions.
3796 Dwarf2 has no clean way to discern C++ static and non-static
3797 member functions. G++ helps GDB by marking the first
3798 parameter for non-static member functions (which is the
3799 this pointer) as artificial. We obtain this information
3800 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3801 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
3802 fnp
->voffset
= VOFFSET_STATIC
;
3805 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
3808 /* Get fcontext from DW_AT_containing_type if present. */
3809 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3810 fnp
->fcontext
= die_containing_type (die
, cu
);
3812 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3813 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3815 /* Get accessibility. */
3816 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3819 switch (DW_UNSND (attr
))
3821 case DW_ACCESS_private
:
3822 fnp
->is_private
= 1;
3824 case DW_ACCESS_protected
:
3825 fnp
->is_protected
= 1;
3830 /* Check for artificial methods. */
3831 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3832 if (attr
&& DW_UNSND (attr
) != 0)
3833 fnp
->is_artificial
= 1;
3835 /* Get index in virtual function table if it is a virtual member function. */
3836 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3839 /* Support the .debug_loc offsets */
3840 if (attr_form_is_block (attr
))
3842 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3844 else if (attr_form_is_section_offset (attr
))
3846 dwarf2_complex_location_expr_complaint ();
3850 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3856 /* Create the vector of member function fields, and attach it to the type. */
3859 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3860 struct dwarf2_cu
*cu
)
3862 struct fnfieldlist
*flp
;
3863 int total_length
= 0;
3866 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3867 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3868 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3870 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3872 struct nextfnfield
*nfp
= flp
->head
;
3873 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3876 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3877 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3878 fn_flp
->fn_fields
= (struct fn_field
*)
3879 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3880 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3881 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3883 total_length
+= flp
->length
;
3886 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3887 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3890 /* Returns non-zero if NAME is the name of a vtable member in CU's
3891 language, zero otherwise. */
3893 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
3895 static const char vptr
[] = "_vptr";
3896 static const char vtable
[] = "vtable";
3898 /* Look for the C++ and Java forms of the vtable. */
3899 if ((cu
->language
== language_java
3900 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
3901 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
3902 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
3908 /* GCC outputs unnamed structures that are really pointers to member
3909 functions, with the ABI-specified layout. If DIE (from CU) describes
3910 such a structure, set its type, and return nonzero. Otherwise return
3913 GCC shouldn't do this; it should just output pointer to member DIEs.
3914 This is GCC PR debug/28767. */
3916 static struct type
*
3917 quirk_gcc_member_function_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
)
3919 struct objfile
*objfile
= cu
->objfile
;
3921 struct die_info
*pfn_die
, *delta_die
;
3922 struct attribute
*pfn_name
, *delta_name
;
3923 struct type
*pfn_type
, *domain_type
;
3925 /* Check for a structure with no name and two children. */
3926 if (die
->tag
!= DW_TAG_structure_type
3927 || dwarf2_attr (die
, DW_AT_name
, cu
) != NULL
3928 || die
->child
== NULL
3929 || die
->child
->sibling
== NULL
3930 || (die
->child
->sibling
->sibling
!= NULL
3931 && die
->child
->sibling
->sibling
->tag
!= DW_TAG_padding
))
3934 /* Check for __pfn and __delta members. */
3935 pfn_die
= die
->child
;
3936 pfn_name
= dwarf2_attr (pfn_die
, DW_AT_name
, cu
);
3937 if (pfn_die
->tag
!= DW_TAG_member
3939 || DW_STRING (pfn_name
) == NULL
3940 || strcmp ("__pfn", DW_STRING (pfn_name
)) != 0)
3943 delta_die
= pfn_die
->sibling
;
3944 delta_name
= dwarf2_attr (delta_die
, DW_AT_name
, cu
);
3945 if (delta_die
->tag
!= DW_TAG_member
3946 || delta_name
== NULL
3947 || DW_STRING (delta_name
) == NULL
3948 || strcmp ("__delta", DW_STRING (delta_name
)) != 0)
3951 /* Find the type of the method. */
3952 pfn_type
= die_type (pfn_die
, cu
);
3953 if (pfn_type
== NULL
3954 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
3955 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
3958 /* Look for the "this" argument. */
3959 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
3960 if (TYPE_NFIELDS (pfn_type
) == 0
3961 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
3964 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
3965 type
= alloc_type (objfile
);
3966 smash_to_method_type (type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
3967 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
3968 TYPE_VARARGS (pfn_type
));
3969 type
= lookup_methodptr_type (type
);
3970 return set_die_type (die
, type
, cu
);
3973 /* Called when we find the DIE that starts a structure or union scope
3974 (definition) to process all dies that define the members of the
3977 NOTE: we need to call struct_type regardless of whether or not the
3978 DIE has an at_name attribute, since it might be an anonymous
3979 structure or union. This gets the type entered into our set of
3982 However, if the structure is incomplete (an opaque struct/union)
3983 then suppress creating a symbol table entry for it since gdb only
3984 wants to find the one with the complete definition. Note that if
3985 it is complete, we just call new_symbol, which does it's own
3986 checking about whether the struct/union is anonymous or not (and
3987 suppresses creating a symbol table entry itself). */
3989 static struct type
*
3990 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3992 struct objfile
*objfile
= cu
->objfile
;
3994 struct attribute
*attr
;
3995 const char *previous_prefix
= processing_current_prefix
;
3996 struct cleanup
*back_to
= NULL
;
3999 type
= quirk_gcc_member_function_pointer (die
, cu
);
4003 type
= alloc_type (objfile
);
4004 INIT_CPLUS_SPECIFIC (type
);
4005 name
= dwarf2_name (die
, cu
);
4008 if (cu
->language
== language_cplus
4009 || cu
->language
== language_java
)
4011 char *new_prefix
= determine_class_name (die
, cu
);
4012 TYPE_TAG_NAME (type
) = obsavestring (new_prefix
,
4013 strlen (new_prefix
),
4014 &objfile
->objfile_obstack
);
4015 back_to
= make_cleanup (xfree
, new_prefix
);
4016 processing_current_prefix
= 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
;
4064 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
4066 memset (&fi
, 0, sizeof (struct field_info
));
4068 child_die
= die
->child
;
4070 while (child_die
&& child_die
->tag
)
4072 if (child_die
->tag
== DW_TAG_member
4073 || child_die
->tag
== DW_TAG_variable
)
4075 /* NOTE: carlton/2002-11-05: A C++ static data member
4076 should be a DW_TAG_member that is a declaration, but
4077 all versions of G++ as of this writing (so through at
4078 least 3.2.1) incorrectly generate DW_TAG_variable
4079 tags for them instead. */
4080 dwarf2_add_field (&fi
, child_die
, cu
);
4082 else if (child_die
->tag
== DW_TAG_subprogram
)
4084 /* C++ member function. */
4085 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
4087 else if (child_die
->tag
== DW_TAG_inheritance
)
4089 /* C++ base class field. */
4090 dwarf2_add_field (&fi
, child_die
, cu
);
4092 child_die
= sibling_die (child_die
);
4095 /* Attach fields and member functions to the type. */
4097 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
4100 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
4102 /* Get the type which refers to the base class (possibly this
4103 class itself) which contains the vtable pointer for the current
4104 class from the DW_AT_containing_type attribute. */
4106 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4108 struct type
*t
= die_containing_type (die
, cu
);
4110 TYPE_VPTR_BASETYPE (type
) = t
;
4115 /* Our own class provides vtbl ptr. */
4116 for (i
= TYPE_NFIELDS (t
) - 1;
4117 i
>= TYPE_N_BASECLASSES (t
);
4120 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
4122 if (is_vtable_name (fieldname
, cu
))
4124 TYPE_VPTR_FIELDNO (type
) = i
;
4129 /* Complain if virtual function table field not found. */
4130 if (i
< TYPE_N_BASECLASSES (t
))
4131 complaint (&symfile_complaints
,
4132 _("virtual function table pointer not found when defining class '%s'"),
4133 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
4138 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
4141 else if (cu
->producer
4142 && strncmp (cu
->producer
,
4143 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
4145 /* The IBM XLC compiler does not provide direct indication
4146 of the containing type, but the vtable pointer is
4147 always named __vfp. */
4151 for (i
= TYPE_NFIELDS (type
) - 1;
4152 i
>= TYPE_N_BASECLASSES (type
);
4155 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
4157 TYPE_VPTR_FIELDNO (type
) = i
;
4158 TYPE_VPTR_BASETYPE (type
) = type
;
4165 do_cleanups (back_to
);
4168 processing_current_prefix
= previous_prefix
;
4169 if (back_to
!= NULL
)
4170 do_cleanups (back_to
);
4176 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4178 struct objfile
*objfile
= cu
->objfile
;
4179 const char *previous_prefix
= processing_current_prefix
;
4180 struct die_info
*child_die
= die
->child
;
4181 struct type
*this_type
;
4183 this_type
= get_die_type (die
, cu
);
4184 if (this_type
== NULL
)
4185 this_type
= read_structure_type (die
, cu
);
4186 if (TYPE_TAG_NAME (this_type
) != NULL
)
4187 processing_current_prefix
= TYPE_TAG_NAME (this_type
);
4189 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
4190 snapshots) has been known to create a die giving a declaration
4191 for a class that has, as a child, a die giving a definition for a
4192 nested class. So we have to process our children even if the
4193 current die is a declaration. Normally, of course, a declaration
4194 won't have any children at all. */
4196 while (child_die
!= NULL
&& child_die
->tag
)
4198 if (child_die
->tag
== DW_TAG_member
4199 || child_die
->tag
== DW_TAG_variable
4200 || child_die
->tag
== DW_TAG_inheritance
)
4205 process_die (child_die
, cu
);
4207 child_die
= sibling_die (child_die
);
4210 /* Do not consider external references. According to the DWARF standard,
4211 these DIEs are identified by the fact that they have no byte_size
4212 attribute, and a declaration attribute. */
4213 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
4214 || !die_is_declaration (die
, cu
))
4215 new_symbol (die
, this_type
, cu
);
4217 processing_current_prefix
= previous_prefix
;
4220 /* Given a DW_AT_enumeration_type die, set its type. We do not
4221 complete the type's fields yet, or create any symbols. */
4223 static struct type
*
4224 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4226 struct objfile
*objfile
= cu
->objfile
;
4228 struct attribute
*attr
;
4231 type
= alloc_type (objfile
);
4233 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4234 name
= dwarf2_name (die
, cu
);
4237 if (processing_has_namespace_info
)
4239 TYPE_TAG_NAME (type
) = typename_concat (&objfile
->objfile_obstack
,
4240 processing_current_prefix
,
4245 /* The name is already allocated along with this objfile, so
4246 we don't need to duplicate it for the type. */
4247 TYPE_TAG_NAME (type
) = name
;
4251 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4254 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4258 TYPE_LENGTH (type
) = 0;
4261 /* The enumeration DIE can be incomplete. In Ada, any type can be
4262 declared as private in the package spec, and then defined only
4263 inside the package body. Such types are known as Taft Amendment
4264 Types. When another package uses such a type, an incomplete DIE
4265 may be generated by the compiler. */
4266 if (die_is_declaration (die
, cu
))
4267 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
4269 return set_die_type (die
, type
, cu
);
4272 /* Determine the name of the type represented by DIE, which should be
4273 a named C++ or Java compound type. Return the name in question; the caller
4274 is responsible for xfree()'ing it. */
4277 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
4279 struct cleanup
*back_to
= NULL
;
4280 struct die_info
*spec_die
= die_specification (die
, cu
);
4281 char *new_prefix
= NULL
;
4283 /* If this is the definition of a class that is declared by another
4284 die, then processing_current_prefix may not be accurate; see
4285 read_func_scope for a similar example. */
4286 if (spec_die
!= NULL
)
4288 char *specification_prefix
= determine_prefix (spec_die
, cu
);
4289 processing_current_prefix
= specification_prefix
;
4290 back_to
= make_cleanup (xfree
, specification_prefix
);
4293 /* If we don't have namespace debug info, guess the name by trying
4294 to demangle the names of members, just like we did in
4295 guess_structure_name. */
4296 if (!processing_has_namespace_info
)
4298 struct die_info
*child
;
4300 for (child
= die
->child
;
4301 child
!= NULL
&& child
->tag
!= 0;
4302 child
= sibling_die (child
))
4304 if (child
->tag
== DW_TAG_subprogram
)
4307 = language_class_name_from_physname (cu
->language_defn
,
4311 if (new_prefix
!= NULL
)
4317 if (new_prefix
== NULL
)
4319 const char *name
= dwarf2_name (die
, cu
);
4320 new_prefix
= typename_concat (NULL
, processing_current_prefix
,
4321 name
? name
: "<<anonymous>>",
4325 if (back_to
!= NULL
)
4326 do_cleanups (back_to
);
4331 /* Given a pointer to a die which begins an enumeration, process all
4332 the dies that define the members of the enumeration, and create the
4333 symbol for the enumeration type.
4335 NOTE: We reverse the order of the element list. */
4338 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4340 struct objfile
*objfile
= cu
->objfile
;
4341 struct die_info
*child_die
;
4342 struct field
*fields
;
4345 int unsigned_enum
= 1;
4347 struct type
*this_type
;
4351 this_type
= get_die_type (die
, cu
);
4352 if (this_type
== NULL
)
4353 this_type
= read_enumeration_type (die
, cu
);
4354 if (die
->child
!= NULL
)
4356 child_die
= die
->child
;
4357 while (child_die
&& child_die
->tag
)
4359 if (child_die
->tag
!= DW_TAG_enumerator
)
4361 process_die (child_die
, cu
);
4365 name
= dwarf2_name (child_die
, cu
);
4368 sym
= new_symbol (child_die
, this_type
, cu
);
4369 if (SYMBOL_VALUE (sym
) < 0)
4372 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4374 fields
= (struct field
*)
4376 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
4377 * sizeof (struct field
));
4380 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
4381 FIELD_TYPE (fields
[num_fields
]) = NULL
;
4382 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
4383 FIELD_BITSIZE (fields
[num_fields
]) = 0;
4384 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
4390 child_die
= sibling_die (child_die
);
4395 TYPE_NFIELDS (this_type
) = num_fields
;
4396 TYPE_FIELDS (this_type
) = (struct field
*)
4397 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
4398 memcpy (TYPE_FIELDS (this_type
), fields
,
4399 sizeof (struct field
) * num_fields
);
4403 TYPE_FLAGS (this_type
) |= TYPE_FLAG_UNSIGNED
;
4406 new_symbol (die
, this_type
, cu
);
4409 /* Extract all information from a DW_TAG_array_type DIE and put it in
4410 the DIE's type field. For now, this only handles one dimensional
4413 static struct type
*
4414 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4416 struct objfile
*objfile
= cu
->objfile
;
4417 struct die_info
*child_die
;
4418 struct type
*type
= NULL
;
4419 struct type
*element_type
, *range_type
, *index_type
;
4420 struct type
**range_types
= NULL
;
4421 struct attribute
*attr
;
4423 struct cleanup
*back_to
;
4426 element_type
= die_type (die
, cu
);
4428 /* Irix 6.2 native cc creates array types without children for
4429 arrays with unspecified length. */
4430 if (die
->child
== NULL
)
4432 index_type
= builtin_type_int32
;
4433 range_type
= create_range_type (NULL
, index_type
, 0, -1);
4434 type
= create_array_type (NULL
, element_type
, range_type
);
4435 return set_die_type (die
, type
, cu
);
4438 back_to
= make_cleanup (null_cleanup
, NULL
);
4439 child_die
= die
->child
;
4440 while (child_die
&& child_die
->tag
)
4442 if (child_die
->tag
== DW_TAG_subrange_type
)
4444 struct type
*child_type
= read_type_die (child_die
, cu
);
4445 if (child_type
!= NULL
)
4447 /* The range type was succesfully read. Save it for
4448 the array type creation. */
4449 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
4451 range_types
= (struct type
**)
4452 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
4453 * sizeof (struct type
*));
4455 make_cleanup (free_current_contents
, &range_types
);
4457 range_types
[ndim
++] = child_type
;
4460 child_die
= sibling_die (child_die
);
4463 /* Dwarf2 dimensions are output from left to right, create the
4464 necessary array types in backwards order. */
4466 type
= element_type
;
4468 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
4472 type
= create_array_type (NULL
, type
, range_types
[i
++]);
4477 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
4480 /* Understand Dwarf2 support for vector types (like they occur on
4481 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4482 array type. This is not part of the Dwarf2/3 standard yet, but a
4483 custom vendor extension. The main difference between a regular
4484 array and the vector variant is that vectors are passed by value
4486 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4488 make_vector_type (type
);
4490 name
= dwarf2_name (die
, cu
);
4492 TYPE_NAME (type
) = name
;
4494 do_cleanups (back_to
);
4496 /* Install the type in the die. */
4497 return set_die_type (die
, type
, cu
);
4500 static enum dwarf_array_dim_ordering
4501 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4503 struct attribute
*attr
;
4505 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4507 if (attr
) return DW_SND (attr
);
4510 GNU F77 is a special case, as at 08/2004 array type info is the
4511 opposite order to the dwarf2 specification, but data is still
4512 laid out as per normal fortran.
4514 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4518 if (cu
->language
== language_fortran
&&
4519 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4521 return DW_ORD_row_major
;
4524 switch (cu
->language_defn
->la_array_ordering
)
4526 case array_column_major
:
4527 return DW_ORD_col_major
;
4528 case array_row_major
:
4530 return DW_ORD_row_major
;
4534 /* Extract all information from a DW_TAG_set_type DIE and put it in
4535 the DIE's type field. */
4537 static struct type
*
4538 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4540 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
4542 return set_die_type (die
, set_type
, cu
);
4545 /* First cut: install each common block member as a global variable. */
4548 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4550 struct die_info
*child_die
;
4551 struct attribute
*attr
;
4553 CORE_ADDR base
= (CORE_ADDR
) 0;
4555 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4558 /* Support the .debug_loc offsets */
4559 if (attr_form_is_block (attr
))
4561 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4563 else if (attr_form_is_section_offset (attr
))
4565 dwarf2_complex_location_expr_complaint ();
4569 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4570 "common block member");
4573 if (die
->child
!= NULL
)
4575 child_die
= die
->child
;
4576 while (child_die
&& child_die
->tag
)
4578 sym
= new_symbol (child_die
, NULL
, cu
);
4579 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4582 SYMBOL_VALUE_ADDRESS (sym
) =
4583 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4584 add_symbol_to_list (sym
, &global_symbols
);
4586 child_die
= sibling_die (child_die
);
4591 /* Read a C++ namespace. */
4594 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4596 struct objfile
*objfile
= cu
->objfile
;
4597 const char *previous_prefix
= processing_current_prefix
;
4600 struct die_info
*current_die
;
4601 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4603 name
= namespace_name (die
, &is_anonymous
, cu
);
4605 /* Now build the name of the current namespace. */
4607 if (previous_prefix
[0] == '\0')
4609 processing_current_prefix
= name
;
4613 char *temp_name
= typename_concat (NULL
, previous_prefix
, name
, cu
);
4614 make_cleanup (xfree
, temp_name
);
4615 processing_current_prefix
= temp_name
;
4618 /* Add a symbol associated to this if we haven't seen the namespace
4619 before. Also, add a using directive if it's an anonymous
4622 if (dwarf2_extension (die
, cu
) == NULL
)
4626 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
4627 this cast will hopefully become unnecessary. */
4628 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
4629 (char *) processing_current_prefix
,
4631 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4633 new_symbol (die
, type
, cu
);
4634 set_die_type (die
, type
, cu
);
4637 cp_add_using_directive (processing_current_prefix
,
4638 strlen (previous_prefix
),
4639 strlen (processing_current_prefix
));
4642 if (die
->child
!= NULL
)
4644 struct die_info
*child_die
= die
->child
;
4646 while (child_die
&& child_die
->tag
)
4648 process_die (child_die
, cu
);
4649 child_die
= sibling_die (child_die
);
4653 processing_current_prefix
= previous_prefix
;
4654 do_cleanups (back_to
);
4657 /* Return the name of the namespace represented by DIE. Set
4658 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4662 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
4664 struct die_info
*current_die
;
4665 const char *name
= NULL
;
4667 /* Loop through the extensions until we find a name. */
4669 for (current_die
= die
;
4670 current_die
!= NULL
;
4671 current_die
= dwarf2_extension (die
, cu
))
4673 name
= dwarf2_name (current_die
, cu
);
4678 /* Is it an anonymous namespace? */
4680 *is_anonymous
= (name
== NULL
);
4682 name
= "(anonymous namespace)";
4687 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4688 the user defined type vector. */
4690 static struct type
*
4691 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4693 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
4694 struct comp_unit_head
*cu_header
= &cu
->header
;
4696 struct attribute
*attr_byte_size
;
4697 struct attribute
*attr_address_class
;
4698 int byte_size
, addr_class
;
4700 type
= lookup_pointer_type (die_type (die
, cu
));
4702 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4704 byte_size
= DW_UNSND (attr_byte_size
);
4706 byte_size
= cu_header
->addr_size
;
4708 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
4709 if (attr_address_class
)
4710 addr_class
= DW_UNSND (attr_address_class
);
4712 addr_class
= DW_ADDR_none
;
4714 /* If the pointer size or address class is different than the
4715 default, create a type variant marked as such and set the
4716 length accordingly. */
4717 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
4719 if (gdbarch_address_class_type_flags_p (gdbarch
))
4723 type_flags
= gdbarch_address_class_type_flags
4724 (gdbarch
, byte_size
, addr_class
);
4725 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
4726 type
= make_type_with_address_space (type
, type_flags
);
4728 else if (TYPE_LENGTH (type
) != byte_size
)
4730 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
4733 /* Should we also complain about unhandled address classes? */
4737 TYPE_LENGTH (type
) = byte_size
;
4738 return set_die_type (die
, type
, cu
);
4741 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4742 the user defined type vector. */
4744 static struct type
*
4745 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4747 struct objfile
*objfile
= cu
->objfile
;
4749 struct type
*to_type
;
4750 struct type
*domain
;
4752 to_type
= die_type (die
, cu
);
4753 domain
= die_containing_type (die
, cu
);
4755 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
4756 type
= lookup_methodptr_type (to_type
);
4758 type
= lookup_memberptr_type (to_type
, domain
);
4760 return set_die_type (die
, type
, cu
);
4763 /* Extract all information from a DW_TAG_reference_type DIE and add to
4764 the user defined type vector. */
4766 static struct type
*
4767 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4769 struct comp_unit_head
*cu_header
= &cu
->header
;
4771 struct attribute
*attr
;
4773 type
= lookup_reference_type (die_type (die
, cu
));
4774 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4777 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4781 TYPE_LENGTH (type
) = cu_header
->addr_size
;
4783 return set_die_type (die
, type
, cu
);
4786 static struct type
*
4787 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4789 struct type
*base_type
, *cv_type
;
4791 base_type
= die_type (die
, cu
);
4792 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
4793 return set_die_type (die
, cv_type
, cu
);
4796 static struct type
*
4797 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4799 struct type
*base_type
, *cv_type
;
4801 base_type
= die_type (die
, cu
);
4802 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
4803 return set_die_type (die
, cv_type
, cu
);
4806 /* Extract all information from a DW_TAG_string_type DIE and add to
4807 the user defined type vector. It isn't really a user defined type,
4808 but it behaves like one, with other DIE's using an AT_user_def_type
4809 attribute to reference it. */
4811 static struct type
*
4812 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4814 struct objfile
*objfile
= cu
->objfile
;
4815 struct type
*type
, *range_type
, *index_type
, *char_type
;
4816 struct attribute
*attr
;
4817 unsigned int length
;
4819 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4822 length
= DW_UNSND (attr
);
4826 /* check for the DW_AT_byte_size attribute */
4827 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4830 length
= DW_UNSND (attr
);
4838 index_type
= builtin_type_int32
;
4839 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4840 type
= create_string_type (NULL
, range_type
);
4842 return set_die_type (die
, type
, cu
);
4845 /* Handle DIES due to C code like:
4849 int (*funcp)(int a, long l);
4853 ('funcp' generates a DW_TAG_subroutine_type DIE)
4856 static struct type
*
4857 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4859 struct type
*type
; /* Type that this function returns */
4860 struct type
*ftype
; /* Function that returns above type */
4861 struct attribute
*attr
;
4863 type
= die_type (die
, cu
);
4864 ftype
= make_function_type (type
, (struct type
**) 0);
4866 /* All functions in C++, Pascal and Java have prototypes. */
4867 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4868 if ((attr
&& (DW_UNSND (attr
) != 0))
4869 || cu
->language
== language_cplus
4870 || cu
->language
== language_java
4871 || cu
->language
== language_pascal
)
4872 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
4874 /* Store the calling convention in the type if it's available in
4875 the subroutine die. Otherwise set the calling convention to
4876 the default value DW_CC_normal. */
4877 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
4878 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
4880 if (die
->child
!= NULL
)
4882 struct die_info
*child_die
;
4886 /* Count the number of parameters.
4887 FIXME: GDB currently ignores vararg functions, but knows about
4888 vararg member functions. */
4889 child_die
= die
->child
;
4890 while (child_die
&& child_die
->tag
)
4892 if (child_die
->tag
== DW_TAG_formal_parameter
)
4894 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4895 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
4896 child_die
= sibling_die (child_die
);
4899 /* Allocate storage for parameters and fill them in. */
4900 TYPE_NFIELDS (ftype
) = nparams
;
4901 TYPE_FIELDS (ftype
) = (struct field
*)
4902 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
4904 child_die
= die
->child
;
4905 while (child_die
&& child_die
->tag
)
4907 if (child_die
->tag
== DW_TAG_formal_parameter
)
4909 /* Dwarf2 has no clean way to discern C++ static and non-static
4910 member functions. G++ helps GDB by marking the first
4911 parameter for non-static member functions (which is the
4912 this pointer) as artificial. We pass this information
4913 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4914 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
4916 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
4918 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
4919 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
4922 child_die
= sibling_die (child_die
);
4926 return set_die_type (die
, ftype
, cu
);
4929 static struct type
*
4930 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
4932 struct objfile
*objfile
= cu
->objfile
;
4933 struct attribute
*attr
;
4935 struct type
*this_type
;
4937 name
= dwarf2_name (die
, cu
);
4938 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
4939 TYPE_FLAG_TARGET_STUB
, name
, objfile
);
4940 set_die_type (die
, this_type
, cu
);
4941 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
4945 /* Find a representation of a given base type and install
4946 it in the TYPE field of the die. */
4948 static struct type
*
4949 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4951 struct objfile
*objfile
= cu
->objfile
;
4953 struct attribute
*attr
;
4954 int encoding
= 0, size
= 0;
4956 enum type_code code
= TYPE_CODE_INT
;
4958 struct type
*target_type
= NULL
;
4960 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
4963 encoding
= DW_UNSND (attr
);
4965 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4968 size
= DW_UNSND (attr
);
4970 name
= dwarf2_name (die
, cu
);
4973 complaint (&symfile_complaints
,
4974 _("DW_AT_name missing from DW_TAG_base_type"));
4979 case DW_ATE_address
:
4980 /* Turn DW_ATE_address into a void * pointer. */
4981 code
= TYPE_CODE_PTR
;
4982 type_flags
|= TYPE_FLAG_UNSIGNED
;
4983 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
4985 case DW_ATE_boolean
:
4986 code
= TYPE_CODE_BOOL
;
4987 type_flags
|= TYPE_FLAG_UNSIGNED
;
4989 case DW_ATE_complex_float
:
4990 code
= TYPE_CODE_COMPLEX
;
4991 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
4993 case DW_ATE_decimal_float
:
4994 code
= TYPE_CODE_DECFLOAT
;
4997 code
= TYPE_CODE_FLT
;
5001 case DW_ATE_unsigned
:
5002 type_flags
|= TYPE_FLAG_UNSIGNED
;
5004 case DW_ATE_signed_char
:
5005 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5006 code
= TYPE_CODE_CHAR
;
5008 case DW_ATE_unsigned_char
:
5009 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5010 code
= TYPE_CODE_CHAR
;
5011 type_flags
|= TYPE_FLAG_UNSIGNED
;
5014 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
5015 dwarf_type_encoding_name (encoding
));
5019 type
= init_type (code
, size
, type_flags
, name
, objfile
);
5020 TYPE_TARGET_TYPE (type
) = target_type
;
5022 return set_die_type (die
, type
, cu
);
5025 /* Read the given DW_AT_subrange DIE. */
5027 static struct type
*
5028 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5030 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5031 struct type
*base_type
;
5032 struct type
*range_type
;
5033 struct attribute
*attr
;
5038 base_type
= die_type (die
, cu
);
5039 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
5041 complaint (&symfile_complaints
,
5042 _("DW_AT_type missing from DW_TAG_subrange_type"));
5044 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
5045 0, NULL
, cu
->objfile
);
5048 if (cu
->language
== language_fortran
)
5050 /* FORTRAN implies a lower bound of 1, if not given. */
5054 /* FIXME: For variable sized arrays either of these could be
5055 a variable rather than a constant value. We'll allow it,
5056 but we don't know how to handle it. */
5057 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
5059 low
= dwarf2_get_attr_constant_value (attr
, 0);
5061 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
5064 if (attr
->form
== DW_FORM_block1
)
5066 /* GCC encodes arrays with unspecified or dynamic length
5067 with a DW_FORM_block1 attribute.
5068 FIXME: GDB does not yet know how to handle dynamic
5069 arrays properly, treat them as arrays with unspecified
5072 FIXME: jimb/2003-09-22: GDB does not really know
5073 how to handle arrays of unspecified length
5074 either; we just represent them as zero-length
5075 arrays. Choose an appropriate upper bound given
5076 the lower bound we've computed above. */
5080 high
= dwarf2_get_attr_constant_value (attr
, 1);
5083 range_type
= create_range_type (NULL
, base_type
, low
, high
);
5085 name
= dwarf2_name (die
, cu
);
5087 TYPE_NAME (range_type
) = name
;
5089 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5091 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
5093 return set_die_type (die
, range_type
, cu
);
5096 static struct type
*
5097 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5101 /* For now, we only support the C meaning of an unspecified type: void. */
5103 type
= init_type (TYPE_CODE_VOID
, 0, 0, dwarf2_name (die
, cu
),
5106 return set_die_type (die
, type
, cu
);
5109 /* Trivial hash function for die_info: the hash value of a DIE
5110 is its offset in .debug_info for this objfile. */
5113 die_hash (const void *item
)
5115 const struct die_info
*die
= item
;
5119 /* Trivial comparison function for die_info structures: two DIEs
5120 are equal if they have the same offset. */
5123 die_eq (const void *item_lhs
, const void *item_rhs
)
5125 const struct die_info
*die_lhs
= item_lhs
;
5126 const struct die_info
*die_rhs
= item_rhs
;
5127 return die_lhs
->offset
== die_rhs
->offset
;
5130 /* Read a whole compilation unit into a linked list of dies. */
5132 static struct die_info
*
5133 read_comp_unit (gdb_byte
*info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
5136 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5140 &cu
->comp_unit_obstack
,
5141 hashtab_obstack_allocate
,
5142 dummy_obstack_deallocate
);
5144 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
5147 /* Read a single die and all its descendents. Set the die's sibling
5148 field to NULL; set other fields in the die correctly, and set all
5149 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
5150 location of the info_ptr after reading all of those dies. PARENT
5151 is the parent of the die in question. */
5153 static struct die_info
*
5154 read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
5155 struct dwarf2_cu
*cu
,
5156 gdb_byte
**new_info_ptr
,
5157 struct die_info
*parent
)
5159 struct die_info
*die
;
5163 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
5166 *new_info_ptr
= cur_ptr
;
5169 store_in_ref_table (die
, cu
);
5173 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
5179 *new_info_ptr
= cur_ptr
;
5182 die
->sibling
= NULL
;
5183 die
->parent
= parent
;
5187 /* Read a die, all of its descendents, and all of its siblings; set
5188 all of the fields of all of the dies correctly. Arguments are as
5189 in read_die_and_children. */
5191 static struct die_info
*
5192 read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
5193 struct dwarf2_cu
*cu
,
5194 gdb_byte
**new_info_ptr
,
5195 struct die_info
*parent
)
5197 struct die_info
*first_die
, *last_sibling
;
5201 first_die
= last_sibling
= NULL
;
5205 struct die_info
*die
5206 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
5210 *new_info_ptr
= cur_ptr
;
5217 last_sibling
->sibling
= die
;
5223 /* Decompress a section that was compressed using zlib. Store the
5224 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
5227 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
5228 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
5230 bfd
*abfd
= objfile
->obfd
;
5232 error (_("Support for zlib-compressed DWARF data (from '%s') "
5233 "is disabled in this copy of GDB"),
5234 bfd_get_filename (abfd
));
5236 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
5237 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
5238 bfd_size_type uncompressed_size
;
5239 gdb_byte
*uncompressed_buffer
;
5242 int header_size
= 12;
5244 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5245 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
5246 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5247 bfd_get_filename (abfd
));
5249 /* Read the zlib header. In this case, it should be "ZLIB" followed
5250 by the uncompressed section size, 8 bytes in big-endian order. */
5251 if (compressed_size
< header_size
5252 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
5253 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
5254 bfd_get_filename (abfd
));
5255 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
5256 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
5257 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
5258 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
5259 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
5260 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
5261 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
5262 uncompressed_size
+= compressed_buffer
[11];
5264 /* It is possible the section consists of several compressed
5265 buffers concatenated together, so we uncompress in a loop. */
5269 strm
.avail_in
= compressed_size
- header_size
;
5270 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
5271 strm
.avail_out
= uncompressed_size
;
5272 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
5274 rc
= inflateInit (&strm
);
5275 while (strm
.avail_in
> 0)
5278 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
5279 bfd_get_filename (abfd
), rc
);
5280 strm
.next_out
= ((Bytef
*) uncompressed_buffer
5281 + (uncompressed_size
- strm
.avail_out
));
5282 rc
= inflate (&strm
, Z_FINISH
);
5283 if (rc
!= Z_STREAM_END
)
5284 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
5285 bfd_get_filename (abfd
), rc
);
5286 rc
= inflateReset (&strm
);
5288 rc
= inflateEnd (&strm
);
5290 || strm
.avail_out
!= 0)
5291 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
5292 bfd_get_filename (abfd
), rc
);
5294 xfree (compressed_buffer
);
5295 *outbuf
= uncompressed_buffer
;
5296 *outsize
= uncompressed_size
;
5301 /* Read the contents of the section at OFFSET and of size SIZE from the
5302 object file specified by OBJFILE into the objfile_obstack and return it.
5303 If the section is compressed, uncompress it before returning. */
5306 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
5308 bfd
*abfd
= objfile
->obfd
;
5309 gdb_byte
*buf
, *retbuf
;
5310 bfd_size_type size
= bfd_get_section_size (sectp
);
5311 unsigned char header
[4];
5316 /* Check if the file has a 4-byte header indicating compression. */
5317 if (size
> sizeof (header
)
5318 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
5319 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
5321 /* Upon decompression, update the buffer and its size. */
5322 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
5324 zlib_decompress_section (objfile
, sectp
, &buf
, &size
);
5325 dwarf2_resize_section (sectp
, size
);
5330 /* If we get here, we are a normal, not-compressed section. */
5331 buf
= obstack_alloc (&objfile
->objfile_obstack
, size
);
5332 /* When debugging .o files, we may need to apply relocations; see
5333 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
5334 We never compress sections in .o files, so we only need to
5335 try this when the section is not compressed. */
5336 retbuf
= symfile_relocate_debug_section (abfd
, sectp
, buf
);
5340 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5341 || bfd_bread (buf
, size
, abfd
) != size
)
5342 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5343 bfd_get_filename (abfd
));
5348 /* In DWARF version 2, the description of the debugging information is
5349 stored in a separate .debug_abbrev section. Before we read any
5350 dies from a section we read in all abbreviations and install them
5351 in a hash table. This function also sets flags in CU describing
5352 the data found in the abbrev table. */
5355 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
5357 struct comp_unit_head
*cu_header
= &cu
->header
;
5358 gdb_byte
*abbrev_ptr
;
5359 struct abbrev_info
*cur_abbrev
;
5360 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
5361 unsigned int abbrev_form
, hash_number
;
5362 struct attr_abbrev
*cur_attrs
;
5363 unsigned int allocated_attrs
;
5365 /* Initialize dwarf2 abbrevs */
5366 obstack_init (&cu
->abbrev_obstack
);
5367 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
5369 * sizeof (struct abbrev_info
*)));
5370 memset (cu
->dwarf2_abbrevs
, 0,
5371 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
5373 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
5374 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5375 abbrev_ptr
+= bytes_read
;
5377 allocated_attrs
= ATTR_ALLOC_CHUNK
;
5378 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
5380 /* loop until we reach an abbrev number of 0 */
5381 while (abbrev_number
)
5383 cur_abbrev
= dwarf_alloc_abbrev (cu
);
5385 /* read in abbrev header */
5386 cur_abbrev
->number
= abbrev_number
;
5387 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5388 abbrev_ptr
+= bytes_read
;
5389 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
5392 if (cur_abbrev
->tag
== DW_TAG_namespace
)
5393 cu
->has_namespace_info
= 1;
5395 /* now read in declarations */
5396 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5397 abbrev_ptr
+= bytes_read
;
5398 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5399 abbrev_ptr
+= bytes_read
;
5402 if (cur_abbrev
->num_attrs
== allocated_attrs
)
5404 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
5406 = xrealloc (cur_attrs
, (allocated_attrs
5407 * sizeof (struct attr_abbrev
)));
5410 /* Record whether this compilation unit might have
5411 inter-compilation-unit references. If we don't know what form
5412 this attribute will have, then it might potentially be a
5413 DW_FORM_ref_addr, so we conservatively expect inter-CU
5416 if (abbrev_form
== DW_FORM_ref_addr
5417 || abbrev_form
== DW_FORM_indirect
)
5418 cu
->has_form_ref_addr
= 1;
5420 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
5421 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
5422 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5423 abbrev_ptr
+= bytes_read
;
5424 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5425 abbrev_ptr
+= bytes_read
;
5428 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
5429 (cur_abbrev
->num_attrs
5430 * sizeof (struct attr_abbrev
)));
5431 memcpy (cur_abbrev
->attrs
, cur_attrs
,
5432 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
5434 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
5435 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
5436 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
5438 /* Get next abbreviation.
5439 Under Irix6 the abbreviations for a compilation unit are not
5440 always properly terminated with an abbrev number of 0.
5441 Exit loop if we encounter an abbreviation which we have
5442 already read (which means we are about to read the abbreviations
5443 for the next compile unit) or if the end of the abbreviation
5444 table is reached. */
5445 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
5446 >= dwarf2_per_objfile
->abbrev_size
)
5448 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5449 abbrev_ptr
+= bytes_read
;
5450 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
5457 /* Release the memory used by the abbrev table for a compilation unit. */
5460 dwarf2_free_abbrev_table (void *ptr_to_cu
)
5462 struct dwarf2_cu
*cu
= ptr_to_cu
;
5464 obstack_free (&cu
->abbrev_obstack
, NULL
);
5465 cu
->dwarf2_abbrevs
= NULL
;
5468 /* Lookup an abbrev_info structure in the abbrev hash table. */
5470 static struct abbrev_info
*
5471 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
5473 unsigned int hash_number
;
5474 struct abbrev_info
*abbrev
;
5476 hash_number
= number
% ABBREV_HASH_SIZE
;
5477 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
5481 if (abbrev
->number
== number
)
5484 abbrev
= abbrev
->next
;
5489 /* Returns nonzero if TAG represents a type that we might generate a partial
5493 is_type_tag_for_partial (int tag
)
5498 /* Some types that would be reasonable to generate partial symbols for,
5499 that we don't at present. */
5500 case DW_TAG_array_type
:
5501 case DW_TAG_file_type
:
5502 case DW_TAG_ptr_to_member_type
:
5503 case DW_TAG_set_type
:
5504 case DW_TAG_string_type
:
5505 case DW_TAG_subroutine_type
:
5507 case DW_TAG_base_type
:
5508 case DW_TAG_class_type
:
5509 case DW_TAG_interface_type
:
5510 case DW_TAG_enumeration_type
:
5511 case DW_TAG_structure_type
:
5512 case DW_TAG_subrange_type
:
5513 case DW_TAG_typedef
:
5514 case DW_TAG_union_type
:
5521 /* Load all DIEs that are interesting for partial symbols into memory. */
5523 static struct partial_die_info
*
5524 load_partial_dies (bfd
*abfd
, gdb_byte
*info_ptr
, int building_psymtab
,
5525 struct dwarf2_cu
*cu
)
5527 struct partial_die_info
*part_die
;
5528 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
5529 struct abbrev_info
*abbrev
;
5530 unsigned int bytes_read
;
5531 unsigned int load_all
= 0;
5533 int nesting_level
= 1;
5538 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
5542 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5546 &cu
->comp_unit_obstack
,
5547 hashtab_obstack_allocate
,
5548 dummy_obstack_deallocate
);
5550 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5551 sizeof (struct partial_die_info
));
5555 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5557 /* A NULL abbrev means the end of a series of children. */
5560 if (--nesting_level
== 0)
5562 /* PART_DIE was probably the last thing allocated on the
5563 comp_unit_obstack, so we could call obstack_free
5564 here. We don't do that because the waste is small,
5565 and will be cleaned up when we're done with this
5566 compilation unit. This way, we're also more robust
5567 against other users of the comp_unit_obstack. */
5570 info_ptr
+= bytes_read
;
5571 last_die
= parent_die
;
5572 parent_die
= parent_die
->die_parent
;
5576 /* Check whether this DIE is interesting enough to save. Normally
5577 we would not be interested in members here, but there may be
5578 later variables referencing them via DW_AT_specification (for
5581 && !is_type_tag_for_partial (abbrev
->tag
)
5582 && abbrev
->tag
!= DW_TAG_enumerator
5583 && abbrev
->tag
!= DW_TAG_subprogram
5584 && abbrev
->tag
!= DW_TAG_variable
5585 && abbrev
->tag
!= DW_TAG_namespace
5586 && abbrev
->tag
!= DW_TAG_member
)
5588 /* Otherwise we skip to the next sibling, if any. */
5589 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5593 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5594 abfd
, info_ptr
, cu
);
5596 /* This two-pass algorithm for processing partial symbols has a
5597 high cost in cache pressure. Thus, handle some simple cases
5598 here which cover the majority of C partial symbols. DIEs
5599 which neither have specification tags in them, nor could have
5600 specification tags elsewhere pointing at them, can simply be
5601 processed and discarded.
5603 This segment is also optional; scan_partial_symbols and
5604 add_partial_symbol will handle these DIEs if we chain
5605 them in normally. When compilers which do not emit large
5606 quantities of duplicate debug information are more common,
5607 this code can probably be removed. */
5609 /* Any complete simple types at the top level (pretty much all
5610 of them, for a language without namespaces), can be processed
5612 if (parent_die
== NULL
5613 && part_die
->has_specification
== 0
5614 && part_die
->is_declaration
== 0
5615 && (part_die
->tag
== DW_TAG_typedef
5616 || part_die
->tag
== DW_TAG_base_type
5617 || part_die
->tag
== DW_TAG_subrange_type
))
5619 if (building_psymtab
&& part_die
->name
!= NULL
)
5620 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5621 VAR_DOMAIN
, LOC_TYPEDEF
,
5622 &cu
->objfile
->static_psymbols
,
5623 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5624 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5628 /* If we're at the second level, and we're an enumerator, and
5629 our parent has no specification (meaning possibly lives in a
5630 namespace elsewhere), then we can add the partial symbol now
5631 instead of queueing it. */
5632 if (part_die
->tag
== DW_TAG_enumerator
5633 && parent_die
!= NULL
5634 && parent_die
->die_parent
== NULL
5635 && parent_die
->tag
== DW_TAG_enumeration_type
5636 && parent_die
->has_specification
== 0)
5638 if (part_die
->name
== NULL
)
5639 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5640 else if (building_psymtab
)
5641 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5642 VAR_DOMAIN
, LOC_CONST
,
5643 (cu
->language
== language_cplus
5644 || cu
->language
== language_java
)
5645 ? &cu
->objfile
->global_psymbols
5646 : &cu
->objfile
->static_psymbols
,
5647 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5649 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5653 /* We'll save this DIE so link it in. */
5654 part_die
->die_parent
= parent_die
;
5655 part_die
->die_sibling
= NULL
;
5656 part_die
->die_child
= NULL
;
5658 if (last_die
&& last_die
== parent_die
)
5659 last_die
->die_child
= part_die
;
5661 last_die
->die_sibling
= part_die
;
5663 last_die
= part_die
;
5665 if (first_die
== NULL
)
5666 first_die
= part_die
;
5668 /* Maybe add the DIE to the hash table. Not all DIEs that we
5669 find interesting need to be in the hash table, because we
5670 also have the parent/sibling/child chains; only those that we
5671 might refer to by offset later during partial symbol reading.
5673 For now this means things that might have be the target of a
5674 DW_AT_specification, DW_AT_abstract_origin, or
5675 DW_AT_extension. DW_AT_extension will refer only to
5676 namespaces; DW_AT_abstract_origin refers to functions (and
5677 many things under the function DIE, but we do not recurse
5678 into function DIEs during partial symbol reading) and
5679 possibly variables as well; DW_AT_specification refers to
5680 declarations. Declarations ought to have the DW_AT_declaration
5681 flag. It happens that GCC forgets to put it in sometimes, but
5682 only for functions, not for types.
5684 Adding more things than necessary to the hash table is harmless
5685 except for the performance cost. Adding too few will result in
5686 wasted time in find_partial_die, when we reread the compilation
5687 unit with load_all_dies set. */
5690 || abbrev
->tag
== DW_TAG_subprogram
5691 || abbrev
->tag
== DW_TAG_variable
5692 || abbrev
->tag
== DW_TAG_namespace
5693 || part_die
->is_declaration
)
5697 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
5698 part_die
->offset
, INSERT
);
5702 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5703 sizeof (struct partial_die_info
));
5705 /* For some DIEs we want to follow their children (if any). For C
5706 we have no reason to follow the children of structures; for other
5707 languages we have to, both so that we can get at method physnames
5708 to infer fully qualified class names, and for DW_AT_specification. */
5709 if (last_die
->has_children
5711 || last_die
->tag
== DW_TAG_namespace
5712 || last_die
->tag
== DW_TAG_enumeration_type
5713 || (cu
->language
!= language_c
5714 && (last_die
->tag
== DW_TAG_class_type
5715 || last_die
->tag
== DW_TAG_interface_type
5716 || last_die
->tag
== DW_TAG_structure_type
5717 || last_die
->tag
== DW_TAG_union_type
))))
5720 parent_die
= last_die
;
5724 /* Otherwise we skip to the next sibling, if any. */
5725 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
5727 /* Back to the top, do it again. */
5731 /* Read a minimal amount of information into the minimal die structure. */
5734 read_partial_die (struct partial_die_info
*part_die
,
5735 struct abbrev_info
*abbrev
,
5736 unsigned int abbrev_len
, bfd
*abfd
,
5737 gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
5739 unsigned int bytes_read
, i
;
5740 struct attribute attr
;
5741 int has_low_pc_attr
= 0;
5742 int has_high_pc_attr
= 0;
5743 CORE_ADDR base_address
= 0;
5747 base_address_low_pc
,
5748 /* Overrides BASE_ADDRESS_LOW_PC. */
5749 base_address_entry_pc
5751 base_address_type
= base_address_none
;
5753 memset (part_die
, 0, sizeof (struct partial_die_info
));
5755 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5757 info_ptr
+= abbrev_len
;
5762 part_die
->tag
= abbrev
->tag
;
5763 part_die
->has_children
= abbrev
->has_children
;
5765 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5767 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
5769 /* Store the data if it is of an attribute we want to keep in a
5770 partial symbol table. */
5775 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
5776 if (part_die
->name
== NULL
)
5777 part_die
->name
= DW_STRING (&attr
);
5779 case DW_AT_comp_dir
:
5780 if (part_die
->dirname
== NULL
)
5781 part_die
->dirname
= DW_STRING (&attr
);
5783 case DW_AT_MIPS_linkage_name
:
5784 part_die
->name
= DW_STRING (&attr
);
5787 has_low_pc_attr
= 1;
5788 part_die
->lowpc
= DW_ADDR (&attr
);
5789 if (part_die
->tag
== DW_TAG_compile_unit
5790 && base_address_type
< base_address_low_pc
)
5792 base_address
= DW_ADDR (&attr
);
5793 base_address_type
= base_address_low_pc
;
5797 has_high_pc_attr
= 1;
5798 part_die
->highpc
= DW_ADDR (&attr
);
5800 case DW_AT_entry_pc
:
5801 if (part_die
->tag
== DW_TAG_compile_unit
5802 && base_address_type
< base_address_entry_pc
)
5804 base_address
= DW_ADDR (&attr
);
5805 base_address_type
= base_address_entry_pc
;
5809 if (part_die
->tag
== DW_TAG_compile_unit
)
5811 cu
->ranges_offset
= DW_UNSND (&attr
);
5812 cu
->has_ranges_offset
= 1;
5815 case DW_AT_location
:
5816 /* Support the .debug_loc offsets */
5817 if (attr_form_is_block (&attr
))
5819 part_die
->locdesc
= DW_BLOCK (&attr
);
5821 else if (attr_form_is_section_offset (&attr
))
5823 dwarf2_complex_location_expr_complaint ();
5827 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5828 "partial symbol information");
5831 case DW_AT_language
:
5832 part_die
->language
= DW_UNSND (&attr
);
5834 case DW_AT_external
:
5835 part_die
->is_external
= DW_UNSND (&attr
);
5837 case DW_AT_declaration
:
5838 part_die
->is_declaration
= DW_UNSND (&attr
);
5841 part_die
->has_type
= 1;
5843 case DW_AT_abstract_origin
:
5844 case DW_AT_specification
:
5845 case DW_AT_extension
:
5846 part_die
->has_specification
= 1;
5847 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
, cu
);
5850 /* Ignore absolute siblings, they might point outside of
5851 the current compile unit. */
5852 if (attr
.form
== DW_FORM_ref_addr
)
5853 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
5855 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
5856 + dwarf2_get_ref_die_offset (&attr
, cu
);
5858 case DW_AT_stmt_list
:
5859 part_die
->has_stmt_list
= 1;
5860 part_die
->line_offset
= DW_UNSND (&attr
);
5862 case DW_AT_byte_size
:
5863 part_die
->has_byte_size
= 1;
5865 case DW_AT_calling_convention
:
5866 /* DWARF doesn't provide a way to identify a program's source-level
5867 entry point. DW_AT_calling_convention attributes are only meant
5868 to describe functions' calling conventions.
5870 However, because it's a necessary piece of information in
5871 Fortran, and because DW_CC_program is the only piece of debugging
5872 information whose definition refers to a 'main program' at all,
5873 several compilers have begun marking Fortran main programs with
5874 DW_CC_program --- even when those functions use the standard
5875 calling conventions.
5877 So until DWARF specifies a way to provide this information and
5878 compilers pick up the new representation, we'll support this
5880 if (DW_UNSND (&attr
) == DW_CC_program
5881 && cu
->language
== language_fortran
)
5882 set_main_name (part_die
->name
);
5889 /* When using the GNU linker, .gnu.linkonce. sections are used to
5890 eliminate duplicate copies of functions and vtables and such.
5891 The linker will arbitrarily choose one and discard the others.
5892 The AT_*_pc values for such functions refer to local labels in
5893 these sections. If the section from that file was discarded, the
5894 labels are not in the output, so the relocs get a value of 0.
5895 If this is a discarded function, mark the pc bounds as invalid,
5896 so that GDB will ignore it. */
5897 if (has_low_pc_attr
&& has_high_pc_attr
5898 && part_die
->lowpc
< part_die
->highpc
5899 && (part_die
->lowpc
!= 0
5900 || dwarf2_per_objfile
->has_section_at_zero
))
5901 part_die
->has_pc_info
= 1;
5903 if (base_address_type
!= base_address_none
&& !cu
->header
.base_known
)
5905 gdb_assert (part_die
->tag
== DW_TAG_compile_unit
);
5906 cu
->header
.base_known
= 1;
5907 cu
->header
.base_address
= base_address
;
5913 /* Find a cached partial DIE at OFFSET in CU. */
5915 static struct partial_die_info
*
5916 find_partial_die_in_comp_unit (unsigned long offset
, struct dwarf2_cu
*cu
)
5918 struct partial_die_info
*lookup_die
= NULL
;
5919 struct partial_die_info part_die
;
5921 part_die
.offset
= offset
;
5922 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
5927 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
5929 static struct partial_die_info
*
5930 find_partial_die (unsigned long offset
, struct dwarf2_cu
*cu
)
5932 struct dwarf2_per_cu_data
*per_cu
= NULL
;
5933 struct partial_die_info
*pd
= NULL
;
5935 if (offset
>= cu
->header
.offset
5936 && offset
< cu
->header
.offset
+ cu
->header
.length
)
5938 pd
= find_partial_die_in_comp_unit (offset
, cu
);
5943 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
5945 if (per_cu
->cu
== NULL
)
5947 load_comp_unit (per_cu
, cu
->objfile
);
5948 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5949 dwarf2_per_objfile
->read_in_chain
= per_cu
;
5952 per_cu
->cu
->last_used
= 0;
5953 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
5955 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
5957 struct cleanup
*back_to
;
5958 struct partial_die_info comp_unit_die
;
5959 struct abbrev_info
*abbrev
;
5960 unsigned int bytes_read
;
5963 per_cu
->load_all_dies
= 1;
5965 /* Re-read the DIEs. */
5966 back_to
= make_cleanup (null_cleanup
, 0);
5967 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
5969 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
5970 back_to
= make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
5972 info_ptr
= per_cu
->cu
->header
.first_die_ptr
;
5973 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
5974 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
5975 per_cu
->cu
->objfile
->obfd
, info_ptr
,
5977 if (comp_unit_die
.has_children
)
5978 load_partial_dies (per_cu
->cu
->objfile
->obfd
, info_ptr
, 0, per_cu
->cu
);
5979 do_cleanups (back_to
);
5981 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
5985 internal_error (__FILE__
, __LINE__
,
5986 _("could not find partial DIE 0x%lx in cache [from module %s]\n"),
5987 offset
, bfd_get_filename (cu
->objfile
->obfd
));
5991 /* Adjust PART_DIE before generating a symbol for it. This function
5992 may set the is_external flag or change the DIE's name. */
5995 fixup_partial_die (struct partial_die_info
*part_die
,
5996 struct dwarf2_cu
*cu
)
5998 /* If we found a reference attribute and the DIE has no name, try
5999 to find a name in the referred to DIE. */
6001 if (part_die
->name
== NULL
&& part_die
->has_specification
)
6003 struct partial_die_info
*spec_die
;
6005 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
6007 fixup_partial_die (spec_die
, cu
);
6011 part_die
->name
= spec_die
->name
;
6013 /* Copy DW_AT_external attribute if it is set. */
6014 if (spec_die
->is_external
)
6015 part_die
->is_external
= spec_die
->is_external
;
6019 /* Set default names for some unnamed DIEs. */
6020 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
6021 || part_die
->tag
== DW_TAG_class_type
))
6022 part_die
->name
= "(anonymous class)";
6024 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
6025 part_die
->name
= "(anonymous namespace)";
6027 if (part_die
->tag
== DW_TAG_structure_type
6028 || part_die
->tag
== DW_TAG_class_type
6029 || part_die
->tag
== DW_TAG_union_type
)
6030 guess_structure_name (part_die
, cu
);
6033 /* Read the die from the .debug_info section buffer. Set DIEP to
6034 point to a newly allocated die with its information, except for its
6035 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6036 whether the die has children or not. */
6039 read_full_die (struct die_info
**diep
, bfd
*abfd
, gdb_byte
*info_ptr
,
6040 struct dwarf2_cu
*cu
, int *has_children
)
6042 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6043 struct abbrev_info
*abbrev
;
6044 struct die_info
*die
;
6046 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
6047 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6048 info_ptr
+= bytes_read
;
6056 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6059 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6061 bfd_get_filename (abfd
));
6063 die
= dwarf_alloc_die (cu
);
6064 die
->offset
= offset
;
6065 die
->tag
= abbrev
->tag
;
6066 die
->abbrev
= abbrev_number
;
6068 die
->num_attrs
= abbrev
->num_attrs
;
6069 die
->attrs
= (struct attribute
*)
6070 obstack_alloc (&cu
->comp_unit_obstack
,
6071 die
->num_attrs
* sizeof (struct attribute
));
6073 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6075 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6076 abfd
, info_ptr
, cu
);
6078 /* If this attribute is an absolute reference to a different
6079 compilation unit, make sure that compilation unit is loaded
6081 if (die
->attrs
[i
].form
== DW_FORM_ref_addr
6082 && (DW_ADDR (&die
->attrs
[i
]) < cu
->header
.offset
6083 || (DW_ADDR (&die
->attrs
[i
])
6084 >= cu
->header
.offset
+ cu
->header
.length
)))
6086 struct dwarf2_per_cu_data
*per_cu
;
6087 per_cu
= dwarf2_find_containing_comp_unit (DW_ADDR (&die
->attrs
[i
]),
6090 /* Mark the dependence relation so that we don't flush PER_CU
6092 dwarf2_add_dependence (cu
, per_cu
);
6094 /* If it's already on the queue, we have nothing to do. */
6098 /* If the compilation unit is already loaded, just mark it as
6100 if (per_cu
->cu
!= NULL
)
6102 per_cu
->cu
->last_used
= 0;
6106 /* Add it to the queue. */
6107 queue_comp_unit (per_cu
);
6112 *has_children
= abbrev
->has_children
;
6116 /* Read an attribute value described by an attribute form. */
6119 read_attribute_value (struct attribute
*attr
, unsigned form
,
6120 bfd
*abfd
, gdb_byte
*info_ptr
,
6121 struct dwarf2_cu
*cu
)
6123 struct comp_unit_head
*cu_header
= &cu
->header
;
6124 unsigned int bytes_read
;
6125 struct dwarf_block
*blk
;
6131 case DW_FORM_ref_addr
:
6132 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6133 info_ptr
+= bytes_read
;
6135 case DW_FORM_block2
:
6136 blk
= dwarf_alloc_block (cu
);
6137 blk
->size
= read_2_bytes (abfd
, info_ptr
);
6139 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6140 info_ptr
+= blk
->size
;
6141 DW_BLOCK (attr
) = blk
;
6143 case DW_FORM_block4
:
6144 blk
= dwarf_alloc_block (cu
);
6145 blk
->size
= read_4_bytes (abfd
, info_ptr
);
6147 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6148 info_ptr
+= blk
->size
;
6149 DW_BLOCK (attr
) = blk
;
6152 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
6156 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
6160 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
6163 case DW_FORM_string
:
6164 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
6165 info_ptr
+= bytes_read
;
6168 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
6170 info_ptr
+= bytes_read
;
6173 blk
= dwarf_alloc_block (cu
);
6174 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6175 info_ptr
+= bytes_read
;
6176 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6177 info_ptr
+= blk
->size
;
6178 DW_BLOCK (attr
) = blk
;
6180 case DW_FORM_block1
:
6181 blk
= dwarf_alloc_block (cu
);
6182 blk
->size
= read_1_byte (abfd
, info_ptr
);
6184 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6185 info_ptr
+= blk
->size
;
6186 DW_BLOCK (attr
) = blk
;
6189 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6193 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6197 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
6198 info_ptr
+= bytes_read
;
6201 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6202 info_ptr
+= bytes_read
;
6205 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
6209 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
6213 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
6217 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
6220 case DW_FORM_ref_udata
:
6221 DW_ADDR (attr
) = (cu
->header
.offset
6222 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
6223 info_ptr
+= bytes_read
;
6225 case DW_FORM_indirect
:
6226 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6227 info_ptr
+= bytes_read
;
6228 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
6231 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
6232 dwarf_form_name (form
),
6233 bfd_get_filename (abfd
));
6236 /* We have seen instances where the compiler tried to emit a byte
6237 size attribute of -1 which ended up being encoded as an unsigned
6238 0xffffffff. Although 0xffffffff is technically a valid size value,
6239 an object of this size seems pretty unlikely so we can relatively
6240 safely treat these cases as if the size attribute was invalid and
6241 treat them as zero by default. */
6242 if (attr
->name
== DW_AT_byte_size
6243 && form
== DW_FORM_data4
6244 && DW_UNSND (attr
) >= 0xffffffff)
6247 (&symfile_complaints
,
6248 _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"),
6250 DW_UNSND (attr
) = 0;
6256 /* Read an attribute described by an abbreviated attribute. */
6259 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
6260 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6262 attr
->name
= abbrev
->name
;
6263 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
6266 /* read dwarf information from a buffer */
6269 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
6271 return bfd_get_8 (abfd
, buf
);
6275 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
6277 return bfd_get_signed_8 (abfd
, buf
);
6281 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
6283 return bfd_get_16 (abfd
, buf
);
6287 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6289 return bfd_get_signed_16 (abfd
, buf
);
6293 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
6295 return bfd_get_32 (abfd
, buf
);
6299 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6301 return bfd_get_signed_32 (abfd
, buf
);
6304 static unsigned long
6305 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
6307 return bfd_get_64 (abfd
, buf
);
6311 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
6312 unsigned int *bytes_read
)
6314 struct comp_unit_head
*cu_header
= &cu
->header
;
6315 CORE_ADDR retval
= 0;
6317 if (cu_header
->signed_addr_p
)
6319 switch (cu_header
->addr_size
)
6322 retval
= bfd_get_signed_16 (abfd
, buf
);
6325 retval
= bfd_get_signed_32 (abfd
, buf
);
6328 retval
= bfd_get_signed_64 (abfd
, buf
);
6331 internal_error (__FILE__
, __LINE__
,
6332 _("read_address: bad switch, signed [in module %s]"),
6333 bfd_get_filename (abfd
));
6338 switch (cu_header
->addr_size
)
6341 retval
= bfd_get_16 (abfd
, buf
);
6344 retval
= bfd_get_32 (abfd
, buf
);
6347 retval
= bfd_get_64 (abfd
, buf
);
6350 internal_error (__FILE__
, __LINE__
,
6351 _("read_address: bad switch, unsigned [in module %s]"),
6352 bfd_get_filename (abfd
));
6356 *bytes_read
= cu_header
->addr_size
;
6360 /* Read the initial length from a section. The (draft) DWARF 3
6361 specification allows the initial length to take up either 4 bytes
6362 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
6363 bytes describe the length and all offsets will be 8 bytes in length
6366 An older, non-standard 64-bit format is also handled by this
6367 function. The older format in question stores the initial length
6368 as an 8-byte quantity without an escape value. Lengths greater
6369 than 2^32 aren't very common which means that the initial 4 bytes
6370 is almost always zero. Since a length value of zero doesn't make
6371 sense for the 32-bit format, this initial zero can be considered to
6372 be an escape value which indicates the presence of the older 64-bit
6373 format. As written, the code can't detect (old format) lengths
6374 greater than 4GB. If it becomes necessary to handle lengths
6375 somewhat larger than 4GB, we could allow other small values (such
6376 as the non-sensical values of 1, 2, and 3) to also be used as
6377 escape values indicating the presence of the old format.
6379 The value returned via bytes_read should be used to increment the
6380 relevant pointer after calling read_initial_length().
6382 As a side effect, this function sets the fields initial_length_size
6383 and offset_size in cu_header to the values appropriate for the
6384 length field. (The format of the initial length field determines
6385 the width of file offsets to be fetched later with read_offset().)
6387 [ Note: read_initial_length() and read_offset() are based on the
6388 document entitled "DWARF Debugging Information Format", revision
6389 3, draft 8, dated November 19, 2001. This document was obtained
6392 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
6394 This document is only a draft and is subject to change. (So beware.)
6396 Details regarding the older, non-standard 64-bit format were
6397 determined empirically by examining 64-bit ELF files produced by
6398 the SGI toolchain on an IRIX 6.5 machine.
6400 - Kevin, July 16, 2002
6404 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, struct comp_unit_head
*cu_header
,
6405 unsigned int *bytes_read
)
6407 LONGEST length
= bfd_get_32 (abfd
, buf
);
6409 if (length
== 0xffffffff)
6411 length
= bfd_get_64 (abfd
, buf
+ 4);
6414 else if (length
== 0)
6416 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
6417 length
= bfd_get_64 (abfd
, buf
);
6427 gdb_assert (cu_header
->initial_length_size
== 0
6428 || cu_header
->initial_length_size
== 4
6429 || cu_header
->initial_length_size
== 8
6430 || cu_header
->initial_length_size
== 12);
6432 if (cu_header
->initial_length_size
!= 0
6433 && cu_header
->initial_length_size
!= *bytes_read
)
6434 complaint (&symfile_complaints
,
6435 _("intermixed 32-bit and 64-bit DWARF sections"));
6437 cu_header
->initial_length_size
= *bytes_read
;
6438 cu_header
->offset_size
= (*bytes_read
== 4) ? 4 : 8;
6444 /* Read an offset from the data stream. The size of the offset is
6445 given by cu_header->offset_size. */
6448 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
6449 unsigned int *bytes_read
)
6453 switch (cu_header
->offset_size
)
6456 retval
= bfd_get_32 (abfd
, buf
);
6460 retval
= bfd_get_64 (abfd
, buf
);
6464 internal_error (__FILE__
, __LINE__
,
6465 _("read_offset: bad switch [in module %s]"),
6466 bfd_get_filename (abfd
));
6473 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
6475 /* If the size of a host char is 8 bits, we can return a pointer
6476 to the buffer, otherwise we have to copy the data to a buffer
6477 allocated on the temporary obstack. */
6478 gdb_assert (HOST_CHAR_BIT
== 8);
6483 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6485 /* If the size of a host char is 8 bits, we can return a pointer
6486 to the string, otherwise we have to copy the string to a buffer
6487 allocated on the temporary obstack. */
6488 gdb_assert (HOST_CHAR_BIT
== 8);
6491 *bytes_read_ptr
= 1;
6494 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
6495 return (char *) buf
;
6499 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
6500 const struct comp_unit_head
*cu_header
,
6501 unsigned int *bytes_read_ptr
)
6503 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
6506 if (dwarf2_per_objfile
->str_buffer
== NULL
)
6508 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
6509 bfd_get_filename (abfd
));
6512 if (str_offset
>= dwarf2_per_objfile
->str_size
)
6514 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
6515 bfd_get_filename (abfd
));
6518 gdb_assert (HOST_CHAR_BIT
== 8);
6519 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
6521 return (char *) (dwarf2_per_objfile
->str_buffer
+ str_offset
);
6524 static unsigned long
6525 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6527 unsigned long result
;
6528 unsigned int num_read
;
6538 byte
= bfd_get_8 (abfd
, buf
);
6541 result
|= ((unsigned long)(byte
& 127) << shift
);
6542 if ((byte
& 128) == 0)
6548 *bytes_read_ptr
= num_read
;
6553 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6556 int i
, shift
, num_read
;
6565 byte
= bfd_get_8 (abfd
, buf
);
6568 result
|= ((long)(byte
& 127) << shift
);
6570 if ((byte
& 128) == 0)
6575 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
6576 result
|= -(((long)1) << shift
);
6577 *bytes_read_ptr
= num_read
;
6581 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6584 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
6590 byte
= bfd_get_8 (abfd
, buf
);
6592 if ((byte
& 128) == 0)
6598 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
6604 cu
->language
= language_c
;
6606 case DW_LANG_C_plus_plus
:
6607 cu
->language
= language_cplus
;
6609 case DW_LANG_Fortran77
:
6610 case DW_LANG_Fortran90
:
6611 case DW_LANG_Fortran95
:
6612 cu
->language
= language_fortran
;
6614 case DW_LANG_Mips_Assembler
:
6615 cu
->language
= language_asm
;
6618 cu
->language
= language_java
;
6622 cu
->language
= language_ada
;
6624 case DW_LANG_Modula2
:
6625 cu
->language
= language_m2
;
6627 case DW_LANG_Pascal83
:
6628 cu
->language
= language_pascal
;
6631 cu
->language
= language_objc
;
6633 case DW_LANG_Cobol74
:
6634 case DW_LANG_Cobol85
:
6636 cu
->language
= language_minimal
;
6639 cu
->language_defn
= language_def (cu
->language
);
6642 /* Return the named attribute or NULL if not there. */
6644 static struct attribute
*
6645 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
6648 struct attribute
*spec
= NULL
;
6650 for (i
= 0; i
< die
->num_attrs
; ++i
)
6652 if (die
->attrs
[i
].name
== name
)
6653 return &die
->attrs
[i
];
6654 if (die
->attrs
[i
].name
== DW_AT_specification
6655 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
6656 spec
= &die
->attrs
[i
];
6660 return dwarf2_attr (follow_die_ref (die
, spec
, cu
), name
, cu
);
6665 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6666 and holds a non-zero value. This function should only be used for
6667 DW_FORM_flag attributes. */
6670 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
6672 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
6674 return (attr
&& DW_UNSND (attr
));
6678 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
6680 /* A DIE is a declaration if it has a DW_AT_declaration attribute
6681 which value is non-zero. However, we have to be careful with
6682 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
6683 (via dwarf2_flag_true_p) follows this attribute. So we may
6684 end up accidently finding a declaration attribute that belongs
6685 to a different DIE referenced by the specification attribute,
6686 even though the given DIE does not have a declaration attribute. */
6687 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
6688 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
6691 /* Return the die giving the specification for DIE, if there is
6694 static struct die_info
*
6695 die_specification (struct die_info
*die
, struct dwarf2_cu
*cu
)
6697 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
, cu
);
6699 if (spec_attr
== NULL
)
6702 return follow_die_ref (die
, spec_attr
, cu
);
6705 /* Free the line_header structure *LH, and any arrays and strings it
6708 free_line_header (struct line_header
*lh
)
6710 if (lh
->standard_opcode_lengths
)
6711 xfree (lh
->standard_opcode_lengths
);
6713 /* Remember that all the lh->file_names[i].name pointers are
6714 pointers into debug_line_buffer, and don't need to be freed. */
6716 xfree (lh
->file_names
);
6718 /* Similarly for the include directory names. */
6719 if (lh
->include_dirs
)
6720 xfree (lh
->include_dirs
);
6726 /* Add an entry to LH's include directory table. */
6728 add_include_dir (struct line_header
*lh
, char *include_dir
)
6730 /* Grow the array if necessary. */
6731 if (lh
->include_dirs_size
== 0)
6733 lh
->include_dirs_size
= 1; /* for testing */
6734 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
6735 * sizeof (*lh
->include_dirs
));
6737 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
6739 lh
->include_dirs_size
*= 2;
6740 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
6741 (lh
->include_dirs_size
6742 * sizeof (*lh
->include_dirs
)));
6745 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
6749 /* Add an entry to LH's file name table. */
6751 add_file_name (struct line_header
*lh
,
6753 unsigned int dir_index
,
6754 unsigned int mod_time
,
6755 unsigned int length
)
6757 struct file_entry
*fe
;
6759 /* Grow the array if necessary. */
6760 if (lh
->file_names_size
== 0)
6762 lh
->file_names_size
= 1; /* for testing */
6763 lh
->file_names
= xmalloc (lh
->file_names_size
6764 * sizeof (*lh
->file_names
));
6766 else if (lh
->num_file_names
>= lh
->file_names_size
)
6768 lh
->file_names_size
*= 2;
6769 lh
->file_names
= xrealloc (lh
->file_names
,
6770 (lh
->file_names_size
6771 * sizeof (*lh
->file_names
)));
6774 fe
= &lh
->file_names
[lh
->num_file_names
++];
6776 fe
->dir_index
= dir_index
;
6777 fe
->mod_time
= mod_time
;
6778 fe
->length
= length
;
6784 /* Read the statement program header starting at OFFSET in
6785 .debug_line, according to the endianness of ABFD. Return a pointer
6786 to a struct line_header, allocated using xmalloc.
6788 NOTE: the strings in the include directory and file name tables of
6789 the returned object point into debug_line_buffer, and must not be
6791 static struct line_header
*
6792 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
6793 struct dwarf2_cu
*cu
)
6795 struct cleanup
*back_to
;
6796 struct line_header
*lh
;
6798 unsigned int bytes_read
;
6800 char *cur_dir
, *cur_file
;
6802 if (dwarf2_per_objfile
->line_buffer
== NULL
)
6804 complaint (&symfile_complaints
, _("missing .debug_line section"));
6808 /* Make sure that at least there's room for the total_length field.
6809 That could be 12 bytes long, but we're just going to fudge that. */
6810 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
6812 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6816 lh
= xmalloc (sizeof (*lh
));
6817 memset (lh
, 0, sizeof (*lh
));
6818 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
6821 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
6823 /* Read in the header. */
6825 read_initial_length (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6826 line_ptr
+= bytes_read
;
6827 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
6828 + dwarf2_per_objfile
->line_size
))
6830 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6833 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
6834 lh
->version
= read_2_bytes (abfd
, line_ptr
);
6836 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6837 line_ptr
+= bytes_read
;
6838 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
6840 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
6842 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
6844 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
6846 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
6848 lh
->standard_opcode_lengths
6849 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
6851 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
6852 for (i
= 1; i
< lh
->opcode_base
; ++i
)
6854 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
6858 /* Read directory table. */
6859 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6861 line_ptr
+= bytes_read
;
6862 add_include_dir (lh
, cur_dir
);
6864 line_ptr
+= bytes_read
;
6866 /* Read file name table. */
6867 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6869 unsigned int dir_index
, mod_time
, length
;
6871 line_ptr
+= bytes_read
;
6872 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6873 line_ptr
+= bytes_read
;
6874 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6875 line_ptr
+= bytes_read
;
6876 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6877 line_ptr
+= bytes_read
;
6879 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6881 line_ptr
+= bytes_read
;
6882 lh
->statement_program_start
= line_ptr
;
6884 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
6885 + dwarf2_per_objfile
->line_size
))
6886 complaint (&symfile_complaints
,
6887 _("line number info header doesn't fit in `.debug_line' section"));
6889 discard_cleanups (back_to
);
6893 /* This function exists to work around a bug in certain compilers
6894 (particularly GCC 2.95), in which the first line number marker of a
6895 function does not show up until after the prologue, right before
6896 the second line number marker. This function shifts ADDRESS down
6897 to the beginning of the function if necessary, and is called on
6898 addresses passed to record_line. */
6901 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
6903 struct function_range
*fn
;
6905 /* Find the function_range containing address. */
6910 cu
->cached_fn
= cu
->first_fn
;
6914 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6920 while (fn
&& fn
!= cu
->cached_fn
)
6921 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6931 if (address
!= fn
->lowpc
)
6932 complaint (&symfile_complaints
,
6933 _("misplaced first line number at 0x%lx for '%s'"),
6934 (unsigned long) address
, fn
->name
);
6939 /* Decode the Line Number Program (LNP) for the given line_header
6940 structure and CU. The actual information extracted and the type
6941 of structures created from the LNP depends on the value of PST.
6943 1. If PST is NULL, then this procedure uses the data from the program
6944 to create all necessary symbol tables, and their linetables.
6945 The compilation directory of the file is passed in COMP_DIR,
6946 and must not be NULL.
6948 2. If PST is not NULL, this procedure reads the program to determine
6949 the list of files included by the unit represented by PST, and
6950 builds all the associated partial symbol tables. In this case,
6951 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
6952 is not used to compute the full name of the symtab, and therefore
6953 omitting it when building the partial symtab does not introduce
6954 the potential for inconsistency - a partial symtab and its associated
6955 symbtab having a different fullname -). */
6958 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
6959 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
6961 gdb_byte
*line_ptr
, *extended_end
;
6963 unsigned int bytes_read
, extended_len
;
6964 unsigned char op_code
, extended_op
, adj_opcode
;
6966 struct objfile
*objfile
= cu
->objfile
;
6967 const int decode_for_pst_p
= (pst
!= NULL
);
6968 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
6970 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6972 line_ptr
= lh
->statement_program_start
;
6973 line_end
= lh
->statement_program_end
;
6975 /* Read the statement sequences until there's nothing left. */
6976 while (line_ptr
< line_end
)
6978 /* state machine registers */
6979 CORE_ADDR address
= 0;
6980 unsigned int file
= 1;
6981 unsigned int line
= 1;
6982 unsigned int column
= 0;
6983 int is_stmt
= lh
->default_is_stmt
;
6984 int basic_block
= 0;
6985 int end_sequence
= 0;
6987 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
6989 /* Start a subfile for the current file of the state machine. */
6990 /* lh->include_dirs and lh->file_names are 0-based, but the
6991 directory and file name numbers in the statement program
6993 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
6997 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6999 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7002 /* Decode the table. */
7003 while (!end_sequence
)
7005 op_code
= read_1_byte (abfd
, line_ptr
);
7008 if (op_code
>= lh
->opcode_base
)
7010 /* Special operand. */
7011 adj_opcode
= op_code
- lh
->opcode_base
;
7012 address
+= (adj_opcode
/ lh
->line_range
)
7013 * lh
->minimum_instruction_length
;
7014 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
7015 if (lh
->num_file_names
< file
)
7016 dwarf2_debug_line_missing_file_complaint ();
7019 lh
->file_names
[file
- 1].included_p
= 1;
7020 if (!decode_for_pst_p
)
7022 if (last_subfile
!= current_subfile
)
7025 record_line (last_subfile
, 0, address
);
7026 last_subfile
= current_subfile
;
7028 /* Append row to matrix using current values. */
7029 record_line (current_subfile
, line
,
7030 check_cu_functions (address
, cu
));
7035 else switch (op_code
)
7037 case DW_LNS_extended_op
:
7038 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7039 line_ptr
+= bytes_read
;
7040 extended_end
= line_ptr
+ extended_len
;
7041 extended_op
= read_1_byte (abfd
, line_ptr
);
7043 switch (extended_op
)
7045 case DW_LNE_end_sequence
:
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
)
7054 record_line (current_subfile
, 0, address
);
7057 case DW_LNE_set_address
:
7058 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
7059 line_ptr
+= bytes_read
;
7060 address
+= baseaddr
;
7062 case DW_LNE_define_file
:
7065 unsigned int dir_index
, mod_time
, length
;
7067 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
7068 line_ptr
+= bytes_read
;
7070 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7071 line_ptr
+= bytes_read
;
7073 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7074 line_ptr
+= bytes_read
;
7076 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7077 line_ptr
+= bytes_read
;
7078 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7082 complaint (&symfile_complaints
,
7083 _("mangled .debug_line section"));
7086 /* Make sure that we parsed the extended op correctly. If e.g.
7087 we expected a different address size than the producer used,
7088 we may have read the wrong number of bytes. */
7089 if (line_ptr
!= extended_end
)
7091 complaint (&symfile_complaints
,
7092 _("mangled .debug_line section"));
7097 if (lh
->num_file_names
< file
)
7098 dwarf2_debug_line_missing_file_complaint ();
7101 lh
->file_names
[file
- 1].included_p
= 1;
7102 if (!decode_for_pst_p
)
7104 if (last_subfile
!= current_subfile
)
7107 record_line (last_subfile
, 0, address
);
7108 last_subfile
= current_subfile
;
7110 record_line (current_subfile
, line
,
7111 check_cu_functions (address
, cu
));
7116 case DW_LNS_advance_pc
:
7117 address
+= lh
->minimum_instruction_length
7118 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7119 line_ptr
+= bytes_read
;
7121 case DW_LNS_advance_line
:
7122 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
7123 line_ptr
+= bytes_read
;
7125 case DW_LNS_set_file
:
7127 /* The arrays lh->include_dirs and lh->file_names are
7128 0-based, but the directory and file name numbers in
7129 the statement program are 1-based. */
7130 struct file_entry
*fe
;
7133 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7134 line_ptr
+= bytes_read
;
7135 if (lh
->num_file_names
< file
)
7136 dwarf2_debug_line_missing_file_complaint ();
7139 fe
= &lh
->file_names
[file
- 1];
7141 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7142 if (!decode_for_pst_p
)
7144 last_subfile
= current_subfile
;
7145 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7150 case DW_LNS_set_column
:
7151 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7152 line_ptr
+= bytes_read
;
7154 case DW_LNS_negate_stmt
:
7155 is_stmt
= (!is_stmt
);
7157 case DW_LNS_set_basic_block
:
7160 /* Add to the address register of the state machine the
7161 address increment value corresponding to special opcode
7162 255. I.e., this value is scaled by the minimum
7163 instruction length since special opcode 255 would have
7164 scaled the the increment. */
7165 case DW_LNS_const_add_pc
:
7166 address
+= (lh
->minimum_instruction_length
7167 * ((255 - lh
->opcode_base
) / lh
->line_range
));
7169 case DW_LNS_fixed_advance_pc
:
7170 address
+= read_2_bytes (abfd
, line_ptr
);
7175 /* Unknown standard opcode, ignore it. */
7178 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
7180 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7181 line_ptr
+= bytes_read
;
7188 if (decode_for_pst_p
)
7192 /* Now that we're done scanning the Line Header Program, we can
7193 create the psymtab of each included file. */
7194 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
7195 if (lh
->file_names
[file_index
].included_p
== 1)
7197 const struct file_entry fe
= lh
->file_names
[file_index
];
7198 char *include_name
= fe
.name
;
7199 char *dir_name
= NULL
;
7200 char *pst_filename
= pst
->filename
;
7203 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
7205 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
7207 include_name
= concat (dir_name
, SLASH_STRING
,
7208 include_name
, (char *)NULL
);
7209 make_cleanup (xfree
, include_name
);
7212 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
7214 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
7215 pst_filename
, (char *)NULL
);
7216 make_cleanup (xfree
, pst_filename
);
7219 if (strcmp (include_name
, pst_filename
) != 0)
7220 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
7225 /* Make sure a symtab is created for every file, even files
7226 which contain only variables (i.e. no code with associated
7230 struct file_entry
*fe
;
7232 for (i
= 0; i
< lh
->num_file_names
; i
++)
7235 fe
= &lh
->file_names
[i
];
7237 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7238 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7240 /* Skip the main file; we don't need it, and it must be
7241 allocated last, so that it will show up before the
7242 non-primary symtabs in the objfile's symtab list. */
7243 if (current_subfile
== first_subfile
)
7246 if (current_subfile
->symtab
== NULL
)
7247 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7249 fe
->symtab
= current_subfile
->symtab
;
7254 /* Start a subfile for DWARF. FILENAME is the name of the file and
7255 DIRNAME the name of the source directory which contains FILENAME
7256 or NULL if not known. COMP_DIR is the compilation directory for the
7257 linetable's compilation unit or NULL if not known.
7258 This routine tries to keep line numbers from identical absolute and
7259 relative file names in a common subfile.
7261 Using the `list' example from the GDB testsuite, which resides in
7262 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
7263 of /srcdir/list0.c yields the following debugging information for list0.c:
7265 DW_AT_name: /srcdir/list0.c
7266 DW_AT_comp_dir: /compdir
7267 files.files[0].name: list0.h
7268 files.files[0].dir: /srcdir
7269 files.files[1].name: list0.c
7270 files.files[1].dir: /srcdir
7272 The line number information for list0.c has to end up in a single
7273 subfile, so that `break /srcdir/list0.c:1' works as expected.
7274 start_subfile will ensure that this happens provided that we pass the
7275 concatenation of files.files[1].dir and files.files[1].name as the
7279 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
7283 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
7284 `start_symtab' will always pass the contents of DW_AT_comp_dir as
7285 second argument to start_subfile. To be consistent, we do the
7286 same here. In order not to lose the line information directory,
7287 we concatenate it to the filename when it makes sense.
7288 Note that the Dwarf3 standard says (speaking of filenames in line
7289 information): ``The directory index is ignored for file names
7290 that represent full path names''. Thus ignoring dirname in the
7291 `else' branch below isn't an issue. */
7293 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
7294 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
7296 fullname
= filename
;
7298 start_subfile (fullname
, comp_dir
);
7300 if (fullname
!= filename
)
7305 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
7306 struct dwarf2_cu
*cu
)
7308 struct objfile
*objfile
= cu
->objfile
;
7309 struct comp_unit_head
*cu_header
= &cu
->header
;
7311 /* NOTE drow/2003-01-30: There used to be a comment and some special
7312 code here to turn a symbol with DW_AT_external and a
7313 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
7314 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
7315 with some versions of binutils) where shared libraries could have
7316 relocations against symbols in their debug information - the
7317 minimal symbol would have the right address, but the debug info
7318 would not. It's no longer necessary, because we will explicitly
7319 apply relocations when we read in the debug information now. */
7321 /* A DW_AT_location attribute with no contents indicates that a
7322 variable has been optimized away. */
7323 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
7325 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7329 /* Handle one degenerate form of location expression specially, to
7330 preserve GDB's previous behavior when section offsets are
7331 specified. If this is just a DW_OP_addr then mark this symbol
7334 if (attr_form_is_block (attr
)
7335 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
7336 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
7340 SYMBOL_VALUE_ADDRESS (sym
) =
7341 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
7342 SYMBOL_CLASS (sym
) = LOC_STATIC
;
7343 fixup_symbol_section (sym
, objfile
);
7344 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
7345 SYMBOL_SECTION (sym
));
7349 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
7350 expression evaluator, and use LOC_COMPUTED only when necessary
7351 (i.e. when the value of a register or memory location is
7352 referenced, or a thread-local block, etc.). Then again, it might
7353 not be worthwhile. I'm assuming that it isn't unless performance
7354 or memory numbers show me otherwise. */
7356 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
7357 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
7360 /* Given a pointer to a DWARF information entry, figure out if we need
7361 to make a symbol table entry for it, and if so, create a new entry
7362 and return a pointer to it.
7363 If TYPE is NULL, determine symbol type from the die, otherwise
7364 used the passed type. */
7366 static struct symbol
*
7367 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
7369 struct objfile
*objfile
= cu
->objfile
;
7370 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7371 struct symbol
*sym
= NULL
;
7373 struct attribute
*attr
= NULL
;
7374 struct attribute
*attr2
= NULL
;
7377 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7379 if (die
->tag
!= DW_TAG_namespace
)
7380 name
= dwarf2_linkage_name (die
, cu
);
7382 name
= TYPE_NAME (type
);
7386 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
7387 sizeof (struct symbol
));
7388 OBJSTAT (objfile
, n_syms
++);
7389 memset (sym
, 0, sizeof (struct symbol
));
7391 /* Cache this symbol's name and the name's demangled form (if any). */
7392 SYMBOL_LANGUAGE (sym
) = cu
->language
;
7393 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
7395 /* Default assumptions.
7396 Use the passed type or decode it from the die. */
7397 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7398 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7400 SYMBOL_TYPE (sym
) = type
;
7402 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
7403 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
7406 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
7409 attr
= dwarf2_attr (die
, DW_AT_decl_file
, cu
);
7412 int file_index
= DW_UNSND (attr
);
7413 if (cu
->line_header
== NULL
7414 || file_index
> cu
->line_header
->num_file_names
)
7415 complaint (&symfile_complaints
,
7416 _("file index out of range"));
7417 else if (file_index
> 0)
7419 struct file_entry
*fe
;
7420 fe
= &cu
->line_header
->file_names
[file_index
- 1];
7421 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
7428 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7431 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
7433 SYMBOL_CLASS (sym
) = LOC_LABEL
;
7435 case DW_TAG_subprogram
:
7436 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7438 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
7439 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7440 if ((attr2
&& (DW_UNSND (attr2
) != 0))
7441 || cu
->language
== language_ada
)
7443 /* Subprograms marked external are stored as a global symbol.
7444 Ada subprograms, whether marked external or not, are always
7445 stored as a global symbol, because we want to be able to
7446 access them globally. For instance, we want to be able
7447 to break on a nested subprogram without having to
7448 specify the context. */
7449 add_symbol_to_list (sym
, &global_symbols
);
7453 add_symbol_to_list (sym
, cu
->list_in_scope
);
7456 case DW_TAG_variable
:
7457 /* Compilation with minimal debug info may result in variables
7458 with missing type entries. Change the misleading `void' type
7459 to something sensible. */
7460 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
7462 = builtin_type (gdbarch
)->nodebug_data_symbol
;
7464 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7467 dwarf2_const_value (attr
, sym
, cu
);
7468 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7469 if (attr2
&& (DW_UNSND (attr2
) != 0))
7470 add_symbol_to_list (sym
, &global_symbols
);
7472 add_symbol_to_list (sym
, cu
->list_in_scope
);
7475 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7478 var_decode_location (attr
, sym
, cu
);
7479 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7480 if (attr2
&& (DW_UNSND (attr2
) != 0))
7481 add_symbol_to_list (sym
, &global_symbols
);
7483 add_symbol_to_list (sym
, cu
->list_in_scope
);
7487 /* We do not know the address of this symbol.
7488 If it is an external symbol and we have type information
7489 for it, enter the symbol as a LOC_UNRESOLVED symbol.
7490 The address of the variable will then be determined from
7491 the minimal symbol table whenever the variable is
7493 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7494 if (attr2
&& (DW_UNSND (attr2
) != 0)
7495 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
7497 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
7498 add_symbol_to_list (sym
, &global_symbols
);
7502 case DW_TAG_formal_parameter
:
7503 SYMBOL_IS_ARGUMENT (sym
) = 1;
7504 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7507 var_decode_location (attr
, sym
, cu
);
7509 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7512 dwarf2_const_value (attr
, sym
, cu
);
7514 add_symbol_to_list (sym
, cu
->list_in_scope
);
7516 case DW_TAG_unspecified_parameters
:
7517 /* From varargs functions; gdb doesn't seem to have any
7518 interest in this information, so just ignore it for now.
7521 case DW_TAG_class_type
:
7522 case DW_TAG_interface_type
:
7523 case DW_TAG_structure_type
:
7524 case DW_TAG_union_type
:
7525 case DW_TAG_set_type
:
7526 case DW_TAG_enumeration_type
:
7527 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7528 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7530 /* Make sure that the symbol includes appropriate enclosing
7531 classes/namespaces in its name. These are calculated in
7532 read_structure_type, and the correct name is saved in
7535 if (cu
->language
== language_cplus
7536 || cu
->language
== language_java
)
7538 struct type
*type
= SYMBOL_TYPE (sym
);
7540 if (TYPE_TAG_NAME (type
) != NULL
)
7542 /* FIXME: carlton/2003-11-10: Should this use
7543 SYMBOL_SET_NAMES instead? (The same problem also
7544 arises further down in this function.) */
7545 /* The type's name is already allocated along with
7546 this objfile, so we don't need to duplicate it
7548 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
7553 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
7554 really ever be static objects: otherwise, if you try
7555 to, say, break of a class's method and you're in a file
7556 which doesn't mention that class, it won't work unless
7557 the check for all static symbols in lookup_symbol_aux
7558 saves you. See the OtherFileClass tests in
7559 gdb.c++/namespace.exp. */
7561 struct pending
**list_to_add
;
7563 list_to_add
= (cu
->list_in_scope
== &file_symbols
7564 && (cu
->language
== language_cplus
7565 || cu
->language
== language_java
)
7566 ? &global_symbols
: cu
->list_in_scope
);
7568 add_symbol_to_list (sym
, list_to_add
);
7570 /* The semantics of C++ state that "struct foo { ... }" also
7571 defines a typedef for "foo". A Java class declaration also
7572 defines a typedef for the class. */
7573 if (cu
->language
== language_cplus
7574 || cu
->language
== language_java
7575 || cu
->language
== language_ada
)
7577 /* The symbol's name is already allocated along with
7578 this objfile, so we don't need to duplicate it for
7580 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
7581 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
7585 case DW_TAG_typedef
:
7586 if (processing_has_namespace_info
7587 && processing_current_prefix
[0] != '\0')
7589 SYMBOL_LINKAGE_NAME (sym
) = typename_concat (&objfile
->objfile_obstack
,
7590 processing_current_prefix
,
7593 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7594 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7595 add_symbol_to_list (sym
, cu
->list_in_scope
);
7597 case DW_TAG_base_type
:
7598 case DW_TAG_subrange_type
:
7599 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7600 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7601 add_symbol_to_list (sym
, cu
->list_in_scope
);
7603 case DW_TAG_enumerator
:
7604 if (processing_has_namespace_info
7605 && processing_current_prefix
[0] != '\0')
7607 SYMBOL_LINKAGE_NAME (sym
) = typename_concat (&objfile
->objfile_obstack
,
7608 processing_current_prefix
,
7611 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7614 dwarf2_const_value (attr
, sym
, cu
);
7617 /* NOTE: carlton/2003-11-10: See comment above in the
7618 DW_TAG_class_type, etc. block. */
7620 struct pending
**list_to_add
;
7622 list_to_add
= (cu
->list_in_scope
== &file_symbols
7623 && (cu
->language
== language_cplus
7624 || cu
->language
== language_java
)
7625 ? &global_symbols
: cu
->list_in_scope
);
7627 add_symbol_to_list (sym
, list_to_add
);
7630 case DW_TAG_namespace
:
7631 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7632 add_symbol_to_list (sym
, &global_symbols
);
7635 /* Not a tag we recognize. Hopefully we aren't processing
7636 trash data, but since we must specifically ignore things
7637 we don't recognize, there is nothing else we should do at
7639 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
7640 dwarf_tag_name (die
->tag
));
7647 /* Copy constant value from an attribute to a symbol. */
7650 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
7651 struct dwarf2_cu
*cu
)
7653 struct objfile
*objfile
= cu
->objfile
;
7654 struct comp_unit_head
*cu_header
= &cu
->header
;
7655 struct dwarf_block
*blk
;
7660 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
7661 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
7662 cu_header
->addr_size
,
7663 TYPE_LENGTH (SYMBOL_TYPE
7665 SYMBOL_VALUE_BYTES (sym
) =
7666 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
7667 /* NOTE: cagney/2003-05-09: In-lined store_address call with
7668 it's body - store_unsigned_integer. */
7669 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
7671 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7674 /* DW_STRING is already allocated on the obstack, point directly
7676 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
7677 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7679 case DW_FORM_block1
:
7680 case DW_FORM_block2
:
7681 case DW_FORM_block4
:
7683 blk
= DW_BLOCK (attr
);
7684 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
7685 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
7687 TYPE_LENGTH (SYMBOL_TYPE
7689 SYMBOL_VALUE_BYTES (sym
) =
7690 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
7691 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
7692 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7695 /* The DW_AT_const_value attributes are supposed to carry the
7696 symbol's value "represented as it would be on the target
7697 architecture." By the time we get here, it's already been
7698 converted to host endianness, so we just need to sign- or
7699 zero-extend it as appropriate. */
7701 dwarf2_const_value_data (attr
, sym
, 8);
7704 dwarf2_const_value_data (attr
, sym
, 16);
7707 dwarf2_const_value_data (attr
, sym
, 32);
7710 dwarf2_const_value_data (attr
, sym
, 64);
7714 SYMBOL_VALUE (sym
) = DW_SND (attr
);
7715 SYMBOL_CLASS (sym
) = LOC_CONST
;
7719 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
7720 SYMBOL_CLASS (sym
) = LOC_CONST
;
7724 complaint (&symfile_complaints
,
7725 _("unsupported const value attribute form: '%s'"),
7726 dwarf_form_name (attr
->form
));
7727 SYMBOL_VALUE (sym
) = 0;
7728 SYMBOL_CLASS (sym
) = LOC_CONST
;
7734 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
7735 or zero-extend it as appropriate for the symbol's type. */
7737 dwarf2_const_value_data (struct attribute
*attr
,
7741 LONGEST l
= DW_UNSND (attr
);
7743 if (bits
< sizeof (l
) * 8)
7745 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
7746 l
&= ((LONGEST
) 1 << bits
) - 1;
7748 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
7751 SYMBOL_VALUE (sym
) = l
;
7752 SYMBOL_CLASS (sym
) = LOC_CONST
;
7756 /* Return the type of the die in question using its DW_AT_type attribute. */
7758 static struct type
*
7759 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7761 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7763 struct attribute
*type_attr
;
7764 struct die_info
*type_die
;
7766 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
7769 /* A missing DW_AT_type represents a void type. */
7770 return builtin_type (gdbarch
)->builtin_void
;
7773 type_die
= follow_die_ref (die
, type_attr
, cu
);
7775 type
= tag_type_to_type (type_die
, cu
);
7778 dump_die (type_die
);
7779 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
7785 /* Return the containing type of the die in question using its
7786 DW_AT_containing_type attribute. */
7788 static struct type
*
7789 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7791 struct type
*type
= NULL
;
7792 struct attribute
*type_attr
;
7793 struct die_info
*type_die
= NULL
;
7795 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
7798 type_die
= follow_die_ref (die
, type_attr
, cu
);
7799 type
= tag_type_to_type (type_die
, cu
);
7804 dump_die (type_die
);
7805 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
7811 static struct type
*
7812 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7814 struct type
*this_type
;
7816 this_type
= read_type_die (die
, cu
);
7820 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
7826 static struct type
*
7827 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7830 const char *old_prefix
;
7831 struct cleanup
*back_to
;
7832 struct type
*this_type
;
7834 this_type
= get_die_type (die
, cu
);
7838 prefix
= determine_prefix (die
, cu
);
7839 old_prefix
= processing_current_prefix
;
7840 back_to
= make_cleanup (xfree
, prefix
);
7841 processing_current_prefix
= prefix
;
7845 case DW_TAG_class_type
:
7846 case DW_TAG_interface_type
:
7847 case DW_TAG_structure_type
:
7848 case DW_TAG_union_type
:
7849 this_type
= read_structure_type (die
, cu
);
7851 case DW_TAG_enumeration_type
:
7852 this_type
= read_enumeration_type (die
, cu
);
7854 case DW_TAG_subprogram
:
7855 case DW_TAG_subroutine_type
:
7856 this_type
= read_subroutine_type (die
, cu
);
7858 case DW_TAG_array_type
:
7859 this_type
= read_array_type (die
, cu
);
7861 case DW_TAG_set_type
:
7862 this_type
= read_set_type (die
, cu
);
7864 case DW_TAG_pointer_type
:
7865 this_type
= read_tag_pointer_type (die
, cu
);
7867 case DW_TAG_ptr_to_member_type
:
7868 this_type
= read_tag_ptr_to_member_type (die
, cu
);
7870 case DW_TAG_reference_type
:
7871 this_type
= read_tag_reference_type (die
, cu
);
7873 case DW_TAG_const_type
:
7874 this_type
= read_tag_const_type (die
, cu
);
7876 case DW_TAG_volatile_type
:
7877 this_type
= read_tag_volatile_type (die
, cu
);
7879 case DW_TAG_string_type
:
7880 this_type
= read_tag_string_type (die
, cu
);
7882 case DW_TAG_typedef
:
7883 this_type
= read_typedef (die
, cu
);
7885 case DW_TAG_subrange_type
:
7886 this_type
= read_subrange_type (die
, cu
);
7888 case DW_TAG_base_type
:
7889 this_type
= read_base_type (die
, cu
);
7891 case DW_TAG_unspecified_type
:
7892 this_type
= read_unspecified_type (die
, cu
);
7895 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
7896 dwarf_tag_name (die
->tag
));
7900 processing_current_prefix
= old_prefix
;
7901 do_cleanups (back_to
);
7905 /* Return the name of the namespace/class that DIE is defined within,
7906 or "" if we can't tell. The caller should xfree the result. */
7908 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
7909 therein) for an example of how to use this function to deal with
7910 DW_AT_specification. */
7913 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
7915 struct die_info
*parent
;
7917 if (cu
->language
!= language_cplus
7918 && cu
->language
!= language_java
)
7921 parent
= die
->parent
;
7925 return xstrdup ("");
7929 switch (parent
->tag
) {
7930 case DW_TAG_namespace
:
7932 /* FIXME: carlton/2004-03-05: Should I follow extension dies
7933 before doing this check? */
7934 struct type
*parent_type
= get_die_type (parent
, cu
);
7935 if (parent_type
!= NULL
&& TYPE_TAG_NAME (parent_type
) != NULL
)
7937 return xstrdup (TYPE_TAG_NAME (parent_type
));
7942 char *parent_prefix
= determine_prefix (parent
, cu
);
7943 char *retval
= typename_concat (NULL
, parent_prefix
,
7944 namespace_name (parent
, &dummy
,
7947 xfree (parent_prefix
);
7952 case DW_TAG_class_type
:
7953 case DW_TAG_interface_type
:
7954 case DW_TAG_structure_type
:
7956 struct type
*parent_type
= get_die_type (parent
, cu
);
7957 if (parent_type
!= NULL
&& TYPE_TAG_NAME (parent_type
) != NULL
)
7959 return xstrdup (TYPE_TAG_NAME (parent_type
));
7963 const char *old_prefix
= processing_current_prefix
;
7964 char *new_prefix
= determine_prefix (parent
, cu
);
7967 processing_current_prefix
= new_prefix
;
7968 retval
= determine_class_name (parent
, cu
);
7969 processing_current_prefix
= old_prefix
;
7976 return determine_prefix (parent
, cu
);
7981 /* Return a newly-allocated string formed by concatenating PREFIX and
7982 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
7983 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
7984 perform an obconcat, otherwise allocate storage for the result. The CU argument
7985 is used to determine the language and hence, the appropriate separator. */
7987 #define MAX_SEP_LEN 2 /* sizeof ("::") */
7990 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
7991 struct dwarf2_cu
*cu
)
7995 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
7997 else if (cu
->language
== language_java
)
8004 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
8009 strcpy (retval
, prefix
);
8010 strcat (retval
, sep
);
8013 strcat (retval
, suffix
);
8019 /* We have an obstack. */
8020 return obconcat (obs
, prefix
, sep
, suffix
);
8024 /* Return sibling of die, NULL if no sibling. */
8026 static struct die_info
*
8027 sibling_die (struct die_info
*die
)
8029 return die
->sibling
;
8032 /* Get linkage name of a die, return NULL if not found. */
8035 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8037 struct attribute
*attr
;
8039 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8040 if (attr
&& DW_STRING (attr
))
8041 return DW_STRING (attr
);
8042 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8043 if (attr
&& DW_STRING (attr
))
8044 return DW_STRING (attr
);
8048 /* Get name of a die, return NULL if not found. */
8051 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8053 struct attribute
*attr
;
8055 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8056 if (attr
&& DW_STRING (attr
))
8057 return DW_STRING (attr
);
8061 /* Return the die that this die in an extension of, or NULL if there
8064 static struct die_info
*
8065 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
*cu
)
8067 struct attribute
*attr
;
8069 attr
= dwarf2_attr (die
, DW_AT_extension
, cu
);
8073 return follow_die_ref (die
, attr
, cu
);
8076 /* Convert a DIE tag into its string name. */
8079 dwarf_tag_name (unsigned tag
)
8083 case DW_TAG_padding
:
8084 return "DW_TAG_padding";
8085 case DW_TAG_array_type
:
8086 return "DW_TAG_array_type";
8087 case DW_TAG_class_type
:
8088 return "DW_TAG_class_type";
8089 case DW_TAG_entry_point
:
8090 return "DW_TAG_entry_point";
8091 case DW_TAG_enumeration_type
:
8092 return "DW_TAG_enumeration_type";
8093 case DW_TAG_formal_parameter
:
8094 return "DW_TAG_formal_parameter";
8095 case DW_TAG_imported_declaration
:
8096 return "DW_TAG_imported_declaration";
8098 return "DW_TAG_label";
8099 case DW_TAG_lexical_block
:
8100 return "DW_TAG_lexical_block";
8102 return "DW_TAG_member";
8103 case DW_TAG_pointer_type
:
8104 return "DW_TAG_pointer_type";
8105 case DW_TAG_reference_type
:
8106 return "DW_TAG_reference_type";
8107 case DW_TAG_compile_unit
:
8108 return "DW_TAG_compile_unit";
8109 case DW_TAG_string_type
:
8110 return "DW_TAG_string_type";
8111 case DW_TAG_structure_type
:
8112 return "DW_TAG_structure_type";
8113 case DW_TAG_subroutine_type
:
8114 return "DW_TAG_subroutine_type";
8115 case DW_TAG_typedef
:
8116 return "DW_TAG_typedef";
8117 case DW_TAG_union_type
:
8118 return "DW_TAG_union_type";
8119 case DW_TAG_unspecified_parameters
:
8120 return "DW_TAG_unspecified_parameters";
8121 case DW_TAG_variant
:
8122 return "DW_TAG_variant";
8123 case DW_TAG_common_block
:
8124 return "DW_TAG_common_block";
8125 case DW_TAG_common_inclusion
:
8126 return "DW_TAG_common_inclusion";
8127 case DW_TAG_inheritance
:
8128 return "DW_TAG_inheritance";
8129 case DW_TAG_inlined_subroutine
:
8130 return "DW_TAG_inlined_subroutine";
8132 return "DW_TAG_module";
8133 case DW_TAG_ptr_to_member_type
:
8134 return "DW_TAG_ptr_to_member_type";
8135 case DW_TAG_set_type
:
8136 return "DW_TAG_set_type";
8137 case DW_TAG_subrange_type
:
8138 return "DW_TAG_subrange_type";
8139 case DW_TAG_with_stmt
:
8140 return "DW_TAG_with_stmt";
8141 case DW_TAG_access_declaration
:
8142 return "DW_TAG_access_declaration";
8143 case DW_TAG_base_type
:
8144 return "DW_TAG_base_type";
8145 case DW_TAG_catch_block
:
8146 return "DW_TAG_catch_block";
8147 case DW_TAG_const_type
:
8148 return "DW_TAG_const_type";
8149 case DW_TAG_constant
:
8150 return "DW_TAG_constant";
8151 case DW_TAG_enumerator
:
8152 return "DW_TAG_enumerator";
8153 case DW_TAG_file_type
:
8154 return "DW_TAG_file_type";
8156 return "DW_TAG_friend";
8157 case DW_TAG_namelist
:
8158 return "DW_TAG_namelist";
8159 case DW_TAG_namelist_item
:
8160 return "DW_TAG_namelist_item";
8161 case DW_TAG_packed_type
:
8162 return "DW_TAG_packed_type";
8163 case DW_TAG_subprogram
:
8164 return "DW_TAG_subprogram";
8165 case DW_TAG_template_type_param
:
8166 return "DW_TAG_template_type_param";
8167 case DW_TAG_template_value_param
:
8168 return "DW_TAG_template_value_param";
8169 case DW_TAG_thrown_type
:
8170 return "DW_TAG_thrown_type";
8171 case DW_TAG_try_block
:
8172 return "DW_TAG_try_block";
8173 case DW_TAG_variant_part
:
8174 return "DW_TAG_variant_part";
8175 case DW_TAG_variable
:
8176 return "DW_TAG_variable";
8177 case DW_TAG_volatile_type
:
8178 return "DW_TAG_volatile_type";
8179 case DW_TAG_dwarf_procedure
:
8180 return "DW_TAG_dwarf_procedure";
8181 case DW_TAG_restrict_type
:
8182 return "DW_TAG_restrict_type";
8183 case DW_TAG_interface_type
:
8184 return "DW_TAG_interface_type";
8185 case DW_TAG_namespace
:
8186 return "DW_TAG_namespace";
8187 case DW_TAG_imported_module
:
8188 return "DW_TAG_imported_module";
8189 case DW_TAG_unspecified_type
:
8190 return "DW_TAG_unspecified_type";
8191 case DW_TAG_partial_unit
:
8192 return "DW_TAG_partial_unit";
8193 case DW_TAG_imported_unit
:
8194 return "DW_TAG_imported_unit";
8195 case DW_TAG_condition
:
8196 return "DW_TAG_condition";
8197 case DW_TAG_shared_type
:
8198 return "DW_TAG_shared_type";
8199 case DW_TAG_MIPS_loop
:
8200 return "DW_TAG_MIPS_loop";
8201 case DW_TAG_HP_array_descriptor
:
8202 return "DW_TAG_HP_array_descriptor";
8203 case DW_TAG_format_label
:
8204 return "DW_TAG_format_label";
8205 case DW_TAG_function_template
:
8206 return "DW_TAG_function_template";
8207 case DW_TAG_class_template
:
8208 return "DW_TAG_class_template";
8209 case DW_TAG_GNU_BINCL
:
8210 return "DW_TAG_GNU_BINCL";
8211 case DW_TAG_GNU_EINCL
:
8212 return "DW_TAG_GNU_EINCL";
8213 case DW_TAG_upc_shared_type
:
8214 return "DW_TAG_upc_shared_type";
8215 case DW_TAG_upc_strict_type
:
8216 return "DW_TAG_upc_strict_type";
8217 case DW_TAG_upc_relaxed_type
:
8218 return "DW_TAG_upc_relaxed_type";
8219 case DW_TAG_PGI_kanji_type
:
8220 return "DW_TAG_PGI_kanji_type";
8221 case DW_TAG_PGI_interface_block
:
8222 return "DW_TAG_PGI_interface_block";
8224 return "DW_TAG_<unknown>";
8228 /* Convert a DWARF attribute code into its string name. */
8231 dwarf_attr_name (unsigned attr
)
8236 return "DW_AT_sibling";
8237 case DW_AT_location
:
8238 return "DW_AT_location";
8240 return "DW_AT_name";
8241 case DW_AT_ordering
:
8242 return "DW_AT_ordering";
8243 case DW_AT_subscr_data
:
8244 return "DW_AT_subscr_data";
8245 case DW_AT_byte_size
:
8246 return "DW_AT_byte_size";
8247 case DW_AT_bit_offset
:
8248 return "DW_AT_bit_offset";
8249 case DW_AT_bit_size
:
8250 return "DW_AT_bit_size";
8251 case DW_AT_element_list
:
8252 return "DW_AT_element_list";
8253 case DW_AT_stmt_list
:
8254 return "DW_AT_stmt_list";
8256 return "DW_AT_low_pc";
8258 return "DW_AT_high_pc";
8259 case DW_AT_language
:
8260 return "DW_AT_language";
8262 return "DW_AT_member";
8264 return "DW_AT_discr";
8265 case DW_AT_discr_value
:
8266 return "DW_AT_discr_value";
8267 case DW_AT_visibility
:
8268 return "DW_AT_visibility";
8270 return "DW_AT_import";
8271 case DW_AT_string_length
:
8272 return "DW_AT_string_length";
8273 case DW_AT_common_reference
:
8274 return "DW_AT_common_reference";
8275 case DW_AT_comp_dir
:
8276 return "DW_AT_comp_dir";
8277 case DW_AT_const_value
:
8278 return "DW_AT_const_value";
8279 case DW_AT_containing_type
:
8280 return "DW_AT_containing_type";
8281 case DW_AT_default_value
:
8282 return "DW_AT_default_value";
8284 return "DW_AT_inline";
8285 case DW_AT_is_optional
:
8286 return "DW_AT_is_optional";
8287 case DW_AT_lower_bound
:
8288 return "DW_AT_lower_bound";
8289 case DW_AT_producer
:
8290 return "DW_AT_producer";
8291 case DW_AT_prototyped
:
8292 return "DW_AT_prototyped";
8293 case DW_AT_return_addr
:
8294 return "DW_AT_return_addr";
8295 case DW_AT_start_scope
:
8296 return "DW_AT_start_scope";
8297 case DW_AT_bit_stride
:
8298 return "DW_AT_bit_stride";
8299 case DW_AT_upper_bound
:
8300 return "DW_AT_upper_bound";
8301 case DW_AT_abstract_origin
:
8302 return "DW_AT_abstract_origin";
8303 case DW_AT_accessibility
:
8304 return "DW_AT_accessibility";
8305 case DW_AT_address_class
:
8306 return "DW_AT_address_class";
8307 case DW_AT_artificial
:
8308 return "DW_AT_artificial";
8309 case DW_AT_base_types
:
8310 return "DW_AT_base_types";
8311 case DW_AT_calling_convention
:
8312 return "DW_AT_calling_convention";
8314 return "DW_AT_count";
8315 case DW_AT_data_member_location
:
8316 return "DW_AT_data_member_location";
8317 case DW_AT_decl_column
:
8318 return "DW_AT_decl_column";
8319 case DW_AT_decl_file
:
8320 return "DW_AT_decl_file";
8321 case DW_AT_decl_line
:
8322 return "DW_AT_decl_line";
8323 case DW_AT_declaration
:
8324 return "DW_AT_declaration";
8325 case DW_AT_discr_list
:
8326 return "DW_AT_discr_list";
8327 case DW_AT_encoding
:
8328 return "DW_AT_encoding";
8329 case DW_AT_external
:
8330 return "DW_AT_external";
8331 case DW_AT_frame_base
:
8332 return "DW_AT_frame_base";
8334 return "DW_AT_friend";
8335 case DW_AT_identifier_case
:
8336 return "DW_AT_identifier_case";
8337 case DW_AT_macro_info
:
8338 return "DW_AT_macro_info";
8339 case DW_AT_namelist_items
:
8340 return "DW_AT_namelist_items";
8341 case DW_AT_priority
:
8342 return "DW_AT_priority";
8344 return "DW_AT_segment";
8345 case DW_AT_specification
:
8346 return "DW_AT_specification";
8347 case DW_AT_static_link
:
8348 return "DW_AT_static_link";
8350 return "DW_AT_type";
8351 case DW_AT_use_location
:
8352 return "DW_AT_use_location";
8353 case DW_AT_variable_parameter
:
8354 return "DW_AT_variable_parameter";
8355 case DW_AT_virtuality
:
8356 return "DW_AT_virtuality";
8357 case DW_AT_vtable_elem_location
:
8358 return "DW_AT_vtable_elem_location";
8359 /* DWARF 3 values. */
8360 case DW_AT_allocated
:
8361 return "DW_AT_allocated";
8362 case DW_AT_associated
:
8363 return "DW_AT_associated";
8364 case DW_AT_data_location
:
8365 return "DW_AT_data_location";
8366 case DW_AT_byte_stride
:
8367 return "DW_AT_byte_stride";
8368 case DW_AT_entry_pc
:
8369 return "DW_AT_entry_pc";
8370 case DW_AT_use_UTF8
:
8371 return "DW_AT_use_UTF8";
8372 case DW_AT_extension
:
8373 return "DW_AT_extension";
8375 return "DW_AT_ranges";
8376 case DW_AT_trampoline
:
8377 return "DW_AT_trampoline";
8378 case DW_AT_call_column
:
8379 return "DW_AT_call_column";
8380 case DW_AT_call_file
:
8381 return "DW_AT_call_file";
8382 case DW_AT_call_line
:
8383 return "DW_AT_call_line";
8384 case DW_AT_description
:
8385 return "DW_AT_description";
8386 case DW_AT_binary_scale
:
8387 return "DW_AT_binary_scale";
8388 case DW_AT_decimal_scale
:
8389 return "DW_AT_decimal_scale";
8391 return "DW_AT_small";
8392 case DW_AT_decimal_sign
:
8393 return "DW_AT_decimal_sign";
8394 case DW_AT_digit_count
:
8395 return "DW_AT_digit_count";
8396 case DW_AT_picture_string
:
8397 return "DW_AT_picture_string";
8399 return "DW_AT_mutable";
8400 case DW_AT_threads_scaled
:
8401 return "DW_AT_threads_scaled";
8402 case DW_AT_explicit
:
8403 return "DW_AT_explicit";
8404 case DW_AT_object_pointer
:
8405 return "DW_AT_object_pointer";
8406 case DW_AT_endianity
:
8407 return "DW_AT_endianity";
8408 case DW_AT_elemental
:
8409 return "DW_AT_elemental";
8411 return "DW_AT_pure";
8412 case DW_AT_recursive
:
8413 return "DW_AT_recursive";
8415 /* SGI/MIPS extensions. */
8416 case DW_AT_MIPS_fde
:
8417 return "DW_AT_MIPS_fde";
8418 case DW_AT_MIPS_loop_begin
:
8419 return "DW_AT_MIPS_loop_begin";
8420 case DW_AT_MIPS_tail_loop_begin
:
8421 return "DW_AT_MIPS_tail_loop_begin";
8422 case DW_AT_MIPS_epilog_begin
:
8423 return "DW_AT_MIPS_epilog_begin";
8424 case DW_AT_MIPS_loop_unroll_factor
:
8425 return "DW_AT_MIPS_loop_unroll_factor";
8426 case DW_AT_MIPS_software_pipeline_depth
:
8427 return "DW_AT_MIPS_software_pipeline_depth";
8428 case DW_AT_MIPS_linkage_name
:
8429 return "DW_AT_MIPS_linkage_name";
8430 case DW_AT_MIPS_stride
:
8431 return "DW_AT_MIPS_stride";
8432 case DW_AT_MIPS_abstract_name
:
8433 return "DW_AT_MIPS_abstract_name";
8434 case DW_AT_MIPS_clone_origin
:
8435 return "DW_AT_MIPS_clone_origin";
8436 case DW_AT_MIPS_has_inlines
:
8437 return "DW_AT_MIPS_has_inlines";
8439 /* HP extensions. */
8440 case DW_AT_HP_block_index
:
8441 return "DW_AT_HP_block_index";
8442 case DW_AT_HP_unmodifiable
:
8443 return "DW_AT_HP_unmodifiable";
8444 case DW_AT_HP_actuals_stmt_list
:
8445 return "DW_AT_HP_actuals_stmt_list";
8446 case DW_AT_HP_proc_per_section
:
8447 return "DW_AT_HP_proc_per_section";
8448 case DW_AT_HP_raw_data_ptr
:
8449 return "DW_AT_HP_raw_data_ptr";
8450 case DW_AT_HP_pass_by_reference
:
8451 return "DW_AT_HP_pass_by_reference";
8452 case DW_AT_HP_opt_level
:
8453 return "DW_AT_HP_opt_level";
8454 case DW_AT_HP_prof_version_id
:
8455 return "DW_AT_HP_prof_version_id";
8456 case DW_AT_HP_opt_flags
:
8457 return "DW_AT_HP_opt_flags";
8458 case DW_AT_HP_cold_region_low_pc
:
8459 return "DW_AT_HP_cold_region_low_pc";
8460 case DW_AT_HP_cold_region_high_pc
:
8461 return "DW_AT_HP_cold_region_high_pc";
8462 case DW_AT_HP_all_variables_modifiable
:
8463 return "DW_AT_HP_all_variables_modifiable";
8464 case DW_AT_HP_linkage_name
:
8465 return "DW_AT_HP_linkage_name";
8466 case DW_AT_HP_prof_flags
:
8467 return "DW_AT_HP_prof_flags";
8468 /* GNU extensions. */
8469 case DW_AT_sf_names
:
8470 return "DW_AT_sf_names";
8471 case DW_AT_src_info
:
8472 return "DW_AT_src_info";
8473 case DW_AT_mac_info
:
8474 return "DW_AT_mac_info";
8475 case DW_AT_src_coords
:
8476 return "DW_AT_src_coords";
8477 case DW_AT_body_begin
:
8478 return "DW_AT_body_begin";
8479 case DW_AT_body_end
:
8480 return "DW_AT_body_end";
8481 case DW_AT_GNU_vector
:
8482 return "DW_AT_GNU_vector";
8483 /* VMS extensions. */
8484 case DW_AT_VMS_rtnbeg_pd_address
:
8485 return "DW_AT_VMS_rtnbeg_pd_address";
8486 /* UPC extension. */
8487 case DW_AT_upc_threads_scaled
:
8488 return "DW_AT_upc_threads_scaled";
8489 /* PGI (STMicroelectronics) extensions. */
8490 case DW_AT_PGI_lbase
:
8491 return "DW_AT_PGI_lbase";
8492 case DW_AT_PGI_soffset
:
8493 return "DW_AT_PGI_soffset";
8494 case DW_AT_PGI_lstride
:
8495 return "DW_AT_PGI_lstride";
8497 return "DW_AT_<unknown>";
8501 /* Convert a DWARF value form code into its string name. */
8504 dwarf_form_name (unsigned form
)
8509 return "DW_FORM_addr";
8510 case DW_FORM_block2
:
8511 return "DW_FORM_block2";
8512 case DW_FORM_block4
:
8513 return "DW_FORM_block4";
8515 return "DW_FORM_data2";
8517 return "DW_FORM_data4";
8519 return "DW_FORM_data8";
8520 case DW_FORM_string
:
8521 return "DW_FORM_string";
8523 return "DW_FORM_block";
8524 case DW_FORM_block1
:
8525 return "DW_FORM_block1";
8527 return "DW_FORM_data1";
8529 return "DW_FORM_flag";
8531 return "DW_FORM_sdata";
8533 return "DW_FORM_strp";
8535 return "DW_FORM_udata";
8536 case DW_FORM_ref_addr
:
8537 return "DW_FORM_ref_addr";
8539 return "DW_FORM_ref1";
8541 return "DW_FORM_ref2";
8543 return "DW_FORM_ref4";
8545 return "DW_FORM_ref8";
8546 case DW_FORM_ref_udata
:
8547 return "DW_FORM_ref_udata";
8548 case DW_FORM_indirect
:
8549 return "DW_FORM_indirect";
8551 return "DW_FORM_<unknown>";
8555 /* Convert a DWARF stack opcode into its string name. */
8558 dwarf_stack_op_name (unsigned op
)
8563 return "DW_OP_addr";
8565 return "DW_OP_deref";
8567 return "DW_OP_const1u";
8569 return "DW_OP_const1s";
8571 return "DW_OP_const2u";
8573 return "DW_OP_const2s";
8575 return "DW_OP_const4u";
8577 return "DW_OP_const4s";
8579 return "DW_OP_const8u";
8581 return "DW_OP_const8s";
8583 return "DW_OP_constu";
8585 return "DW_OP_consts";
8589 return "DW_OP_drop";
8591 return "DW_OP_over";
8593 return "DW_OP_pick";
8595 return "DW_OP_swap";
8599 return "DW_OP_xderef";
8607 return "DW_OP_minus";
8619 return "DW_OP_plus";
8620 case DW_OP_plus_uconst
:
8621 return "DW_OP_plus_uconst";
8627 return "DW_OP_shra";
8645 return "DW_OP_skip";
8647 return "DW_OP_lit0";
8649 return "DW_OP_lit1";
8651 return "DW_OP_lit2";
8653 return "DW_OP_lit3";
8655 return "DW_OP_lit4";
8657 return "DW_OP_lit5";
8659 return "DW_OP_lit6";
8661 return "DW_OP_lit7";
8663 return "DW_OP_lit8";
8665 return "DW_OP_lit9";
8667 return "DW_OP_lit10";
8669 return "DW_OP_lit11";
8671 return "DW_OP_lit12";
8673 return "DW_OP_lit13";
8675 return "DW_OP_lit14";
8677 return "DW_OP_lit15";
8679 return "DW_OP_lit16";
8681 return "DW_OP_lit17";
8683 return "DW_OP_lit18";
8685 return "DW_OP_lit19";
8687 return "DW_OP_lit20";
8689 return "DW_OP_lit21";
8691 return "DW_OP_lit22";
8693 return "DW_OP_lit23";
8695 return "DW_OP_lit24";
8697 return "DW_OP_lit25";
8699 return "DW_OP_lit26";
8701 return "DW_OP_lit27";
8703 return "DW_OP_lit28";
8705 return "DW_OP_lit29";
8707 return "DW_OP_lit30";
8709 return "DW_OP_lit31";
8711 return "DW_OP_reg0";
8713 return "DW_OP_reg1";
8715 return "DW_OP_reg2";
8717 return "DW_OP_reg3";
8719 return "DW_OP_reg4";
8721 return "DW_OP_reg5";
8723 return "DW_OP_reg6";
8725 return "DW_OP_reg7";
8727 return "DW_OP_reg8";
8729 return "DW_OP_reg9";
8731 return "DW_OP_reg10";
8733 return "DW_OP_reg11";
8735 return "DW_OP_reg12";
8737 return "DW_OP_reg13";
8739 return "DW_OP_reg14";
8741 return "DW_OP_reg15";
8743 return "DW_OP_reg16";
8745 return "DW_OP_reg17";
8747 return "DW_OP_reg18";
8749 return "DW_OP_reg19";
8751 return "DW_OP_reg20";
8753 return "DW_OP_reg21";
8755 return "DW_OP_reg22";
8757 return "DW_OP_reg23";
8759 return "DW_OP_reg24";
8761 return "DW_OP_reg25";
8763 return "DW_OP_reg26";
8765 return "DW_OP_reg27";
8767 return "DW_OP_reg28";
8769 return "DW_OP_reg29";
8771 return "DW_OP_reg30";
8773 return "DW_OP_reg31";
8775 return "DW_OP_breg0";
8777 return "DW_OP_breg1";
8779 return "DW_OP_breg2";
8781 return "DW_OP_breg3";
8783 return "DW_OP_breg4";
8785 return "DW_OP_breg5";
8787 return "DW_OP_breg6";
8789 return "DW_OP_breg7";
8791 return "DW_OP_breg8";
8793 return "DW_OP_breg9";
8795 return "DW_OP_breg10";
8797 return "DW_OP_breg11";
8799 return "DW_OP_breg12";
8801 return "DW_OP_breg13";
8803 return "DW_OP_breg14";
8805 return "DW_OP_breg15";
8807 return "DW_OP_breg16";
8809 return "DW_OP_breg17";
8811 return "DW_OP_breg18";
8813 return "DW_OP_breg19";
8815 return "DW_OP_breg20";
8817 return "DW_OP_breg21";
8819 return "DW_OP_breg22";
8821 return "DW_OP_breg23";
8823 return "DW_OP_breg24";
8825 return "DW_OP_breg25";
8827 return "DW_OP_breg26";
8829 return "DW_OP_breg27";
8831 return "DW_OP_breg28";
8833 return "DW_OP_breg29";
8835 return "DW_OP_breg30";
8837 return "DW_OP_breg31";
8839 return "DW_OP_regx";
8841 return "DW_OP_fbreg";
8843 return "DW_OP_bregx";
8845 return "DW_OP_piece";
8846 case DW_OP_deref_size
:
8847 return "DW_OP_deref_size";
8848 case DW_OP_xderef_size
:
8849 return "DW_OP_xderef_size";
8852 /* DWARF 3 extensions. */
8853 case DW_OP_push_object_address
:
8854 return "DW_OP_push_object_address";
8856 return "DW_OP_call2";
8858 return "DW_OP_call4";
8859 case DW_OP_call_ref
:
8860 return "DW_OP_call_ref";
8861 /* GNU extensions. */
8862 case DW_OP_form_tls_address
:
8863 return "DW_OP_form_tls_address";
8864 case DW_OP_call_frame_cfa
:
8865 return "DW_OP_call_frame_cfa";
8866 case DW_OP_bit_piece
:
8867 return "DW_OP_bit_piece";
8868 case DW_OP_GNU_push_tls_address
:
8869 return "DW_OP_GNU_push_tls_address";
8870 case DW_OP_GNU_uninit
:
8871 return "DW_OP_GNU_uninit";
8872 /* HP extensions. */
8873 case DW_OP_HP_is_value
:
8874 return "DW_OP_HP_is_value";
8875 case DW_OP_HP_fltconst4
:
8876 return "DW_OP_HP_fltconst4";
8877 case DW_OP_HP_fltconst8
:
8878 return "DW_OP_HP_fltconst8";
8879 case DW_OP_HP_mod_range
:
8880 return "DW_OP_HP_mod_range";
8881 case DW_OP_HP_unmod_range
:
8882 return "DW_OP_HP_unmod_range";
8884 return "DW_OP_HP_tls";
8886 return "OP_<unknown>";
8891 dwarf_bool_name (unsigned mybool
)
8899 /* Convert a DWARF type code into its string name. */
8902 dwarf_type_encoding_name (unsigned enc
)
8907 return "DW_ATE_void";
8908 case DW_ATE_address
:
8909 return "DW_ATE_address";
8910 case DW_ATE_boolean
:
8911 return "DW_ATE_boolean";
8912 case DW_ATE_complex_float
:
8913 return "DW_ATE_complex_float";
8915 return "DW_ATE_float";
8917 return "DW_ATE_signed";
8918 case DW_ATE_signed_char
:
8919 return "DW_ATE_signed_char";
8920 case DW_ATE_unsigned
:
8921 return "DW_ATE_unsigned";
8922 case DW_ATE_unsigned_char
:
8923 return "DW_ATE_unsigned_char";
8925 case DW_ATE_imaginary_float
:
8926 return "DW_ATE_imaginary_float";
8927 case DW_ATE_packed_decimal
:
8928 return "DW_ATE_packed_decimal";
8929 case DW_ATE_numeric_string
:
8930 return "DW_ATE_numeric_string";
8932 return "DW_ATE_edited";
8933 case DW_ATE_signed_fixed
:
8934 return "DW_ATE_signed_fixed";
8935 case DW_ATE_unsigned_fixed
:
8936 return "DW_ATE_unsigned_fixed";
8937 case DW_ATE_decimal_float
:
8938 return "DW_ATE_decimal_float";
8939 /* HP extensions. */
8940 case DW_ATE_HP_float80
:
8941 return "DW_ATE_HP_float80";
8942 case DW_ATE_HP_complex_float80
:
8943 return "DW_ATE_HP_complex_float80";
8944 case DW_ATE_HP_float128
:
8945 return "DW_ATE_HP_float128";
8946 case DW_ATE_HP_complex_float128
:
8947 return "DW_ATE_HP_complex_float128";
8948 case DW_ATE_HP_floathpintel
:
8949 return "DW_ATE_HP_floathpintel";
8950 case DW_ATE_HP_imaginary_float80
:
8951 return "DW_ATE_HP_imaginary_float80";
8952 case DW_ATE_HP_imaginary_float128
:
8953 return "DW_ATE_HP_imaginary_float128";
8955 return "DW_ATE_<unknown>";
8959 /* Convert a DWARF call frame info operation to its string name. */
8963 dwarf_cfi_name (unsigned cfi_opc
)
8967 case DW_CFA_advance_loc
:
8968 return "DW_CFA_advance_loc";
8970 return "DW_CFA_offset";
8971 case DW_CFA_restore
:
8972 return "DW_CFA_restore";
8974 return "DW_CFA_nop";
8975 case DW_CFA_set_loc
:
8976 return "DW_CFA_set_loc";
8977 case DW_CFA_advance_loc1
:
8978 return "DW_CFA_advance_loc1";
8979 case DW_CFA_advance_loc2
:
8980 return "DW_CFA_advance_loc2";
8981 case DW_CFA_advance_loc4
:
8982 return "DW_CFA_advance_loc4";
8983 case DW_CFA_offset_extended
:
8984 return "DW_CFA_offset_extended";
8985 case DW_CFA_restore_extended
:
8986 return "DW_CFA_restore_extended";
8987 case DW_CFA_undefined
:
8988 return "DW_CFA_undefined";
8989 case DW_CFA_same_value
:
8990 return "DW_CFA_same_value";
8991 case DW_CFA_register
:
8992 return "DW_CFA_register";
8993 case DW_CFA_remember_state
:
8994 return "DW_CFA_remember_state";
8995 case DW_CFA_restore_state
:
8996 return "DW_CFA_restore_state";
8997 case DW_CFA_def_cfa
:
8998 return "DW_CFA_def_cfa";
8999 case DW_CFA_def_cfa_register
:
9000 return "DW_CFA_def_cfa_register";
9001 case DW_CFA_def_cfa_offset
:
9002 return "DW_CFA_def_cfa_offset";
9004 case DW_CFA_def_cfa_expression
:
9005 return "DW_CFA_def_cfa_expression";
9006 case DW_CFA_expression
:
9007 return "DW_CFA_expression";
9008 case DW_CFA_offset_extended_sf
:
9009 return "DW_CFA_offset_extended_sf";
9010 case DW_CFA_def_cfa_sf
:
9011 return "DW_CFA_def_cfa_sf";
9012 case DW_CFA_def_cfa_offset_sf
:
9013 return "DW_CFA_def_cfa_offset_sf";
9014 case DW_CFA_val_offset
:
9015 return "DW_CFA_val_offset";
9016 case DW_CFA_val_offset_sf
:
9017 return "DW_CFA_val_offset_sf";
9018 case DW_CFA_val_expression
:
9019 return "DW_CFA_val_expression";
9020 /* SGI/MIPS specific. */
9021 case DW_CFA_MIPS_advance_loc8
:
9022 return "DW_CFA_MIPS_advance_loc8";
9023 /* GNU extensions. */
9024 case DW_CFA_GNU_window_save
:
9025 return "DW_CFA_GNU_window_save";
9026 case DW_CFA_GNU_args_size
:
9027 return "DW_CFA_GNU_args_size";
9028 case DW_CFA_GNU_negative_offset_extended
:
9029 return "DW_CFA_GNU_negative_offset_extended";
9031 return "DW_CFA_<unknown>";
9037 dump_die (struct die_info
*die
)
9041 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
9042 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
9043 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
9044 dwarf_bool_name (die
->child
!= NULL
));
9046 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
9047 for (i
= 0; i
< die
->num_attrs
; ++i
)
9049 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
9050 dwarf_attr_name (die
->attrs
[i
].name
),
9051 dwarf_form_name (die
->attrs
[i
].form
));
9052 switch (die
->attrs
[i
].form
)
9054 case DW_FORM_ref_addr
:
9056 fprintf_unfiltered (gdb_stderr
, "address: ");
9057 fputs_filtered (paddress (DW_ADDR (&die
->attrs
[i
])), gdb_stderr
);
9059 case DW_FORM_block2
:
9060 case DW_FORM_block4
:
9062 case DW_FORM_block1
:
9063 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
9068 fprintf_unfiltered (gdb_stderr
, "constant ref: %ld (adjusted)",
9069 (long) (DW_ADDR (&die
->attrs
[i
])));
9077 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
9079 case DW_FORM_string
:
9081 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
9082 DW_STRING (&die
->attrs
[i
])
9083 ? DW_STRING (&die
->attrs
[i
]) : "");
9086 if (DW_UNSND (&die
->attrs
[i
]))
9087 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
9089 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
9091 case DW_FORM_indirect
:
9092 /* the reader will have reduced the indirect form to
9093 the "base form" so this form should not occur */
9094 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
9097 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
9098 die
->attrs
[i
].form
);
9100 fprintf_unfiltered (gdb_stderr
, "\n");
9105 dump_die_list (struct die_info
*die
)
9110 if (die
->child
!= NULL
)
9111 dump_die_list (die
->child
);
9112 if (die
->sibling
!= NULL
)
9113 dump_die_list (die
->sibling
);
9118 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
9122 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
9128 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
9130 unsigned int result
= 0;
9134 case DW_FORM_ref_addr
:
9139 case DW_FORM_ref_udata
:
9140 result
= DW_ADDR (attr
);
9143 complaint (&symfile_complaints
,
9144 _("unsupported die ref attribute form: '%s'"),
9145 dwarf_form_name (attr
->form
));
9150 /* Return the constant value held by the given attribute. Return -1
9151 if the value held by the attribute is not constant. */
9154 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
9156 if (attr
->form
== DW_FORM_sdata
)
9157 return DW_SND (attr
);
9158 else if (attr
->form
== DW_FORM_udata
9159 || attr
->form
== DW_FORM_data1
9160 || attr
->form
== DW_FORM_data2
9161 || attr
->form
== DW_FORM_data4
9162 || attr
->form
== DW_FORM_data8
)
9163 return DW_UNSND (attr
);
9166 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
9167 dwarf_form_name (attr
->form
));
9168 return default_value
;
9172 static struct die_info
*
9173 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
9174 struct dwarf2_cu
*cu
)
9176 struct die_info
*die
;
9177 unsigned int offset
;
9178 struct die_info temp_die
;
9179 struct dwarf2_cu
*target_cu
;
9181 offset
= dwarf2_get_ref_die_offset (attr
, cu
);
9183 if (DW_ADDR (attr
) < cu
->header
.offset
9184 || DW_ADDR (attr
) >= cu
->header
.offset
+ cu
->header
.length
)
9186 struct dwarf2_per_cu_data
*per_cu
;
9187 per_cu
= dwarf2_find_containing_comp_unit (DW_ADDR (attr
),
9189 target_cu
= per_cu
->cu
;
9194 temp_die
.offset
= offset
;
9195 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
9199 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
9200 "at 0x%lx [in module %s]"),
9201 (long) offset
, (long) src_die
->offset
, cu
->objfile
->name
);
9204 /* Decode simple location descriptions.
9205 Given a pointer to a dwarf block that defines a location, compute
9206 the location and return the value.
9208 NOTE drow/2003-11-18: This function is called in two situations
9209 now: for the address of static or global variables (partial symbols
9210 only) and for offsets into structures which are expected to be
9211 (more or less) constant. The partial symbol case should go away,
9212 and only the constant case should remain. That will let this
9213 function complain more accurately. A few special modes are allowed
9214 without complaint for global variables (for instance, global
9215 register values and thread-local values).
9217 A location description containing no operations indicates that the
9218 object is optimized out. The return value is 0 for that case.
9219 FIXME drow/2003-11-16: No callers check for this case any more; soon all
9220 callers will only want a very basic result and this can become a
9223 Note that stack[0] is unused except as a default error return.
9224 Note that stack overflow is not yet handled. */
9227 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
9229 struct objfile
*objfile
= cu
->objfile
;
9230 struct comp_unit_head
*cu_header
= &cu
->header
;
9232 int size
= blk
->size
;
9233 gdb_byte
*data
= blk
->data
;
9234 CORE_ADDR stack
[64];
9236 unsigned int bytes_read
, unsnd
;
9280 stack
[++stacki
] = op
- DW_OP_lit0
;
9315 stack
[++stacki
] = op
- DW_OP_reg0
;
9317 dwarf2_complex_location_expr_complaint ();
9321 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9323 stack
[++stacki
] = unsnd
;
9325 dwarf2_complex_location_expr_complaint ();
9329 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
9335 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
9340 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
9345 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
9350 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
9355 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
9360 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
9365 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
9371 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
9376 stack
[stacki
+ 1] = stack
[stacki
];
9381 stack
[stacki
- 1] += stack
[stacki
];
9385 case DW_OP_plus_uconst
:
9386 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9391 stack
[stacki
- 1] -= stack
[stacki
];
9396 /* If we're not the last op, then we definitely can't encode
9397 this using GDB's address_class enum. This is valid for partial
9398 global symbols, although the variable's address will be bogus
9401 dwarf2_complex_location_expr_complaint ();
9404 case DW_OP_GNU_push_tls_address
:
9405 /* The top of the stack has the offset from the beginning
9406 of the thread control block at which the variable is located. */
9407 /* Nothing should follow this operator, so the top of stack would
9409 /* This is valid for partial global symbols, but the variable's
9410 address will be bogus in the psymtab. */
9412 dwarf2_complex_location_expr_complaint ();
9415 case DW_OP_GNU_uninit
:
9419 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
9420 dwarf_stack_op_name (op
));
9421 return (stack
[stacki
]);
9424 return (stack
[stacki
]);
9427 /* memory allocation interface */
9429 static struct dwarf_block
*
9430 dwarf_alloc_block (struct dwarf2_cu
*cu
)
9432 struct dwarf_block
*blk
;
9434 blk
= (struct dwarf_block
*)
9435 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
9439 static struct abbrev_info
*
9440 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
9442 struct abbrev_info
*abbrev
;
9444 abbrev
= (struct abbrev_info
*)
9445 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
9446 memset (abbrev
, 0, sizeof (struct abbrev_info
));
9450 static struct die_info
*
9451 dwarf_alloc_die (struct dwarf2_cu
*cu
)
9453 struct die_info
*die
;
9455 die
= (struct die_info
*)
9456 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct die_info
));
9457 memset (die
, 0, sizeof (struct die_info
));
9462 /* Macro support. */
9465 /* Return the full name of file number I in *LH's file name table.
9466 Use COMP_DIR as the name of the current directory of the
9467 compilation. The result is allocated using xmalloc; the caller is
9468 responsible for freeing it. */
9470 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
9472 /* Is the file number a valid index into the line header's file name
9473 table? Remember that file numbers start with one, not zero. */
9474 if (1 <= file
&& file
<= lh
->num_file_names
)
9476 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9478 if (IS_ABSOLUTE_PATH (fe
->name
))
9479 return xstrdup (fe
->name
);
9487 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9493 dir_len
= strlen (dir
);
9494 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
9495 strcpy (full_name
, dir
);
9496 full_name
[dir_len
] = '/';
9497 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
9501 return xstrdup (fe
->name
);
9506 /* The compiler produced a bogus file number. We can at least
9507 record the macro definitions made in the file, even if we
9508 won't be able to find the file by name. */
9510 sprintf (fake_name
, "<bad macro file number %d>", file
);
9512 complaint (&symfile_complaints
,
9513 _("bad file number in macro information (%d)"),
9516 return xstrdup (fake_name
);
9521 static struct macro_source_file
*
9522 macro_start_file (int file
, int line
,
9523 struct macro_source_file
*current_file
,
9524 const char *comp_dir
,
9525 struct line_header
*lh
, struct objfile
*objfile
)
9527 /* The full name of this source file. */
9528 char *full_name
= file_full_name (file
, lh
, comp_dir
);
9530 /* We don't create a macro table for this compilation unit
9531 at all until we actually get a filename. */
9532 if (! pending_macros
)
9533 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
9534 objfile
->macro_cache
);
9537 /* If we have no current file, then this must be the start_file
9538 directive for the compilation unit's main source file. */
9539 current_file
= macro_set_main (pending_macros
, full_name
);
9541 current_file
= macro_include (current_file
, line
, full_name
);
9545 return current_file
;
9549 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
9550 followed by a null byte. */
9552 copy_string (const char *buf
, int len
)
9554 char *s
= xmalloc (len
+ 1);
9555 memcpy (s
, buf
, len
);
9563 consume_improper_spaces (const char *p
, const char *body
)
9567 complaint (&symfile_complaints
,
9568 _("macro definition contains spaces in formal argument list:\n`%s'"),
9580 parse_macro_definition (struct macro_source_file
*file
, int line
,
9585 /* The body string takes one of two forms. For object-like macro
9586 definitions, it should be:
9588 <macro name> " " <definition>
9590 For function-like macro definitions, it should be:
9592 <macro name> "() " <definition>
9594 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
9596 Spaces may appear only where explicitly indicated, and in the
9599 The Dwarf 2 spec says that an object-like macro's name is always
9600 followed by a space, but versions of GCC around March 2002 omit
9601 the space when the macro's definition is the empty string.
9603 The Dwarf 2 spec says that there should be no spaces between the
9604 formal arguments in a function-like macro's formal argument list,
9605 but versions of GCC around March 2002 include spaces after the
9609 /* Find the extent of the macro name. The macro name is terminated
9610 by either a space or null character (for an object-like macro) or
9611 an opening paren (for a function-like macro). */
9612 for (p
= body
; *p
; p
++)
9613 if (*p
== ' ' || *p
== '(')
9616 if (*p
== ' ' || *p
== '\0')
9618 /* It's an object-like macro. */
9619 int name_len
= p
- body
;
9620 char *name
= copy_string (body
, name_len
);
9621 const char *replacement
;
9624 replacement
= body
+ name_len
+ 1;
9627 dwarf2_macro_malformed_definition_complaint (body
);
9628 replacement
= body
+ name_len
;
9631 macro_define_object (file
, line
, name
, replacement
);
9637 /* It's a function-like macro. */
9638 char *name
= copy_string (body
, p
- body
);
9641 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
9645 p
= consume_improper_spaces (p
, body
);
9647 /* Parse the formal argument list. */
9648 while (*p
&& *p
!= ')')
9650 /* Find the extent of the current argument name. */
9651 const char *arg_start
= p
;
9653 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
9656 if (! *p
|| p
== arg_start
)
9657 dwarf2_macro_malformed_definition_complaint (body
);
9660 /* Make sure argv has room for the new argument. */
9661 if (argc
>= argv_size
)
9664 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
9667 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
9670 p
= consume_improper_spaces (p
, body
);
9672 /* Consume the comma, if present. */
9677 p
= consume_improper_spaces (p
, body
);
9686 /* Perfectly formed definition, no complaints. */
9687 macro_define_function (file
, line
, name
,
9688 argc
, (const char **) argv
,
9690 else if (*p
== '\0')
9692 /* Complain, but do define it. */
9693 dwarf2_macro_malformed_definition_complaint (body
);
9694 macro_define_function (file
, line
, name
,
9695 argc
, (const char **) argv
,
9699 /* Just complain. */
9700 dwarf2_macro_malformed_definition_complaint (body
);
9703 /* Just complain. */
9704 dwarf2_macro_malformed_definition_complaint (body
);
9710 for (i
= 0; i
< argc
; i
++)
9716 dwarf2_macro_malformed_definition_complaint (body
);
9721 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
9722 char *comp_dir
, bfd
*abfd
,
9723 struct dwarf2_cu
*cu
)
9725 gdb_byte
*mac_ptr
, *mac_end
;
9726 struct macro_source_file
*current_file
= 0;
9728 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
9730 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
9734 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
9735 mac_end
= dwarf2_per_objfile
->macinfo_buffer
9736 + dwarf2_per_objfile
->macinfo_size
;
9740 enum dwarf_macinfo_record_type macinfo_type
;
9742 /* Do we at least have room for a macinfo type byte? */
9743 if (mac_ptr
>= mac_end
)
9745 dwarf2_macros_too_long_complaint ();
9749 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
9752 switch (macinfo_type
)
9754 /* A zero macinfo type indicates the end of the macro
9759 case DW_MACINFO_define
:
9760 case DW_MACINFO_undef
:
9762 unsigned int bytes_read
;
9766 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9767 mac_ptr
+= bytes_read
;
9768 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
9769 mac_ptr
+= bytes_read
;
9772 complaint (&symfile_complaints
,
9773 _("debug info gives macro %s outside of any file: %s"),
9775 DW_MACINFO_define
? "definition" : macinfo_type
==
9776 DW_MACINFO_undef
? "undefinition" :
9777 "something-or-other", body
);
9780 if (macinfo_type
== DW_MACINFO_define
)
9781 parse_macro_definition (current_file
, line
, body
);
9782 else if (macinfo_type
== DW_MACINFO_undef
)
9783 macro_undef (current_file
, line
, body
);
9788 case DW_MACINFO_start_file
:
9790 unsigned int bytes_read
;
9793 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9794 mac_ptr
+= bytes_read
;
9795 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9796 mac_ptr
+= bytes_read
;
9798 current_file
= macro_start_file (file
, line
,
9799 current_file
, comp_dir
,
9804 case DW_MACINFO_end_file
:
9806 complaint (&symfile_complaints
,
9807 _("macro debug info has an unmatched `close_file' directive"));
9810 current_file
= current_file
->included_by
;
9813 enum dwarf_macinfo_record_type next_type
;
9815 /* GCC circa March 2002 doesn't produce the zero
9816 type byte marking the end of the compilation
9817 unit. Complain if it's not there, but exit no
9820 /* Do we at least have room for a macinfo type byte? */
9821 if (mac_ptr
>= mac_end
)
9823 dwarf2_macros_too_long_complaint ();
9827 /* We don't increment mac_ptr here, so this is just
9829 next_type
= read_1_byte (abfd
, mac_ptr
);
9831 complaint (&symfile_complaints
,
9832 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
9839 case DW_MACINFO_vendor_ext
:
9841 unsigned int bytes_read
;
9845 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9846 mac_ptr
+= bytes_read
;
9847 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
9848 mac_ptr
+= bytes_read
;
9850 /* We don't recognize any vendor extensions. */
9857 /* Check if the attribute's form is a DW_FORM_block*
9858 if so return true else false. */
9860 attr_form_is_block (struct attribute
*attr
)
9862 return (attr
== NULL
? 0 :
9863 attr
->form
== DW_FORM_block1
9864 || attr
->form
== DW_FORM_block2
9865 || attr
->form
== DW_FORM_block4
9866 || attr
->form
== DW_FORM_block
);
9869 /* Return non-zero if ATTR's value is a section offset --- classes
9870 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
9871 You may use DW_UNSND (attr) to retrieve such offsets.
9873 Section 7.5.4, "Attribute Encodings", explains that no attribute
9874 may have a value that belongs to more than one of these classes; it
9875 would be ambiguous if we did, because we use the same forms for all
9878 attr_form_is_section_offset (struct attribute
*attr
)
9880 return (attr
->form
== DW_FORM_data4
9881 || attr
->form
== DW_FORM_data8
);
9885 /* Return non-zero if ATTR's value falls in the 'constant' class, or
9886 zero otherwise. When this function returns true, you can apply
9887 dwarf2_get_attr_constant_value to it.
9889 However, note that for some attributes you must check
9890 attr_form_is_section_offset before using this test. DW_FORM_data4
9891 and DW_FORM_data8 are members of both the constant class, and of
9892 the classes that contain offsets into other debug sections
9893 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
9894 that, if an attribute's can be either a constant or one of the
9895 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
9896 taken as section offsets, not constants. */
9898 attr_form_is_constant (struct attribute
*attr
)
9915 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
9916 struct dwarf2_cu
*cu
)
9918 if (attr_form_is_section_offset (attr
)
9919 /* ".debug_loc" may not exist at all, or the offset may be outside
9920 the section. If so, fall through to the complaint in the
9922 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc_size
)
9924 struct dwarf2_loclist_baton
*baton
;
9926 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9927 sizeof (struct dwarf2_loclist_baton
));
9928 baton
->per_cu
= cu
->per_cu
;
9929 gdb_assert (baton
->per_cu
);
9931 /* We don't know how long the location list is, but make sure we
9932 don't run off the edge of the section. */
9933 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
9934 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
9935 baton
->base_address
= cu
->header
.base_address
;
9936 if (cu
->header
.base_known
== 0)
9937 complaint (&symfile_complaints
,
9938 _("Location list used without specifying the CU base address."));
9940 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
9941 SYMBOL_LOCATION_BATON (sym
) = baton
;
9945 struct dwarf2_locexpr_baton
*baton
;
9947 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9948 sizeof (struct dwarf2_locexpr_baton
));
9949 baton
->per_cu
= cu
->per_cu
;
9950 gdb_assert (baton
->per_cu
);
9952 if (attr_form_is_block (attr
))
9954 /* Note that we're just copying the block's data pointer
9955 here, not the actual data. We're still pointing into the
9956 info_buffer for SYM's objfile; right now we never release
9957 that buffer, but when we do clean up properly this may
9959 baton
->size
= DW_BLOCK (attr
)->size
;
9960 baton
->data
= DW_BLOCK (attr
)->data
;
9964 dwarf2_invalid_attrib_class_complaint ("location description",
9965 SYMBOL_NATURAL_NAME (sym
));
9970 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
9971 SYMBOL_LOCATION_BATON (sym
) = baton
;
9975 /* Return the OBJFILE associated with the compilation unit CU. */
9978 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
9980 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
9982 /* Return the master objfile, so that we can report and look up the
9983 correct file containing this variable. */
9984 if (objfile
->separate_debug_objfile_backlink
)
9985 objfile
= objfile
->separate_debug_objfile_backlink
;
9990 /* Return the address size given in the compilation unit header for CU. */
9993 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
9996 return per_cu
->cu
->header
.addr_size
;
9999 /* If the CU is not currently read in, we re-read its header. */
10000 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10001 struct dwarf2_per_objfile
*per_objfile
10002 = objfile_data (objfile
, dwarf2_objfile_data_key
);
10003 gdb_byte
*info_ptr
= per_objfile
->info_buffer
+ per_cu
->offset
;
10005 struct comp_unit_head cu_header
;
10006 memset (&cu_header
, 0, sizeof cu_header
);
10007 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
10008 return cu_header
.addr_size
;
10012 /* Locate the compilation unit from CU's objfile which contains the
10013 DIE at OFFSET. Raises an error on failure. */
10015 static struct dwarf2_per_cu_data
*
10016 dwarf2_find_containing_comp_unit (unsigned long offset
,
10017 struct objfile
*objfile
)
10019 struct dwarf2_per_cu_data
*this_cu
;
10023 high
= dwarf2_per_objfile
->n_comp_units
- 1;
10026 int mid
= low
+ (high
- low
) / 2;
10027 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
10032 gdb_assert (low
== high
);
10033 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
10036 error (_("Dwarf Error: could not find partial DIE containing "
10037 "offset 0x%lx [in module %s]"),
10038 (long) offset
, bfd_get_filename (objfile
->obfd
));
10040 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
10041 return dwarf2_per_objfile
->all_comp_units
[low
-1];
10045 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
10046 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
10047 && offset
>= this_cu
->offset
+ this_cu
->length
)
10048 error (_("invalid dwarf2 offset %ld"), offset
);
10049 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
10054 /* Locate the compilation unit from OBJFILE which is located at exactly
10055 OFFSET. Raises an error on failure. */
10057 static struct dwarf2_per_cu_data
*
10058 dwarf2_find_comp_unit (unsigned long offset
, struct objfile
*objfile
)
10060 struct dwarf2_per_cu_data
*this_cu
;
10061 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10062 if (this_cu
->offset
!= offset
)
10063 error (_("no compilation unit with offset %ld."), offset
);
10067 /* Release one cached compilation unit, CU. We unlink it from the tree
10068 of compilation units, but we don't remove it from the read_in_chain;
10069 the caller is responsible for that. */
10072 free_one_comp_unit (void *data
)
10074 struct dwarf2_cu
*cu
= data
;
10076 if (cu
->per_cu
!= NULL
)
10077 cu
->per_cu
->cu
= NULL
;
10080 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10085 /* This cleanup function is passed the address of a dwarf2_cu on the stack
10086 when we're finished with it. We can't free the pointer itself, but be
10087 sure to unlink it from the cache. Also release any associated storage
10088 and perform cache maintenance.
10090 Only used during partial symbol parsing. */
10093 free_stack_comp_unit (void *data
)
10095 struct dwarf2_cu
*cu
= data
;
10097 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10098 cu
->partial_dies
= NULL
;
10100 if (cu
->per_cu
!= NULL
)
10102 /* This compilation unit is on the stack in our caller, so we
10103 should not xfree it. Just unlink it. */
10104 cu
->per_cu
->cu
= NULL
;
10107 /* If we had a per-cu pointer, then we may have other compilation
10108 units loaded, so age them now. */
10109 age_cached_comp_units ();
10113 /* Free all cached compilation units. */
10116 free_cached_comp_units (void *data
)
10118 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10120 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10121 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10122 while (per_cu
!= NULL
)
10124 struct dwarf2_per_cu_data
*next_cu
;
10126 next_cu
= per_cu
->cu
->read_in_chain
;
10128 free_one_comp_unit (per_cu
->cu
);
10129 *last_chain
= next_cu
;
10135 /* Increase the age counter on each cached compilation unit, and free
10136 any that are too old. */
10139 age_cached_comp_units (void)
10141 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10143 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
10144 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10145 while (per_cu
!= NULL
)
10147 per_cu
->cu
->last_used
++;
10148 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
10149 dwarf2_mark (per_cu
->cu
);
10150 per_cu
= per_cu
->cu
->read_in_chain
;
10153 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10154 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10155 while (per_cu
!= NULL
)
10157 struct dwarf2_per_cu_data
*next_cu
;
10159 next_cu
= per_cu
->cu
->read_in_chain
;
10161 if (!per_cu
->cu
->mark
)
10163 free_one_comp_unit (per_cu
->cu
);
10164 *last_chain
= next_cu
;
10167 last_chain
= &per_cu
->cu
->read_in_chain
;
10173 /* Remove a single compilation unit from the cache. */
10176 free_one_cached_comp_unit (void *target_cu
)
10178 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10180 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10181 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10182 while (per_cu
!= NULL
)
10184 struct dwarf2_per_cu_data
*next_cu
;
10186 next_cu
= per_cu
->cu
->read_in_chain
;
10188 if (per_cu
->cu
== target_cu
)
10190 free_one_comp_unit (per_cu
->cu
);
10191 *last_chain
= next_cu
;
10195 last_chain
= &per_cu
->cu
->read_in_chain
;
10201 /* Release all extra memory associated with OBJFILE. */
10204 dwarf2_free_objfile (struct objfile
*objfile
)
10206 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
10208 if (dwarf2_per_objfile
== NULL
)
10211 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
10212 free_cached_comp_units (NULL
);
10214 /* Everything else should be on the objfile obstack. */
10217 /* A pair of DIE offset and GDB type pointer. We store these
10218 in a hash table separate from the DIEs, and preserve them
10219 when the DIEs are flushed out of cache. */
10221 struct dwarf2_offset_and_type
10223 unsigned int offset
;
10227 /* Hash function for a dwarf2_offset_and_type. */
10230 offset_and_type_hash (const void *item
)
10232 const struct dwarf2_offset_and_type
*ofs
= item
;
10233 return ofs
->offset
;
10236 /* Equality function for a dwarf2_offset_and_type. */
10239 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
10241 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
10242 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
10243 return ofs_lhs
->offset
== ofs_rhs
->offset
;
10246 /* Set the type associated with DIE to TYPE. Save it in CU's hash
10247 table if necessary. For convenience, return TYPE. */
10249 static struct type
*
10250 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10252 struct dwarf2_offset_and_type
**slot
, ofs
;
10254 if (cu
->type_hash
== NULL
)
10256 gdb_assert (cu
->per_cu
!= NULL
);
10257 cu
->per_cu
->type_hash
10258 = htab_create_alloc_ex (cu
->header
.length
/ 24,
10259 offset_and_type_hash
,
10260 offset_and_type_eq
,
10262 &cu
->objfile
->objfile_obstack
,
10263 hashtab_obstack_allocate
,
10264 dummy_obstack_deallocate
);
10265 cu
->type_hash
= cu
->per_cu
->type_hash
;
10268 ofs
.offset
= die
->offset
;
10270 slot
= (struct dwarf2_offset_and_type
**)
10271 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
10272 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
10277 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
10278 not have a saved type. */
10280 static struct type
*
10281 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10283 struct dwarf2_offset_and_type
*slot
, ofs
;
10284 htab_t type_hash
= cu
->type_hash
;
10286 if (type_hash
== NULL
)
10289 ofs
.offset
= die
->offset
;
10290 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
10297 /* Set the mark field in CU and in every other compilation unit in the
10298 cache that we must keep because we are keeping CU. */
10300 /* Add a dependence relationship from CU to REF_PER_CU. */
10303 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
10304 struct dwarf2_per_cu_data
*ref_per_cu
)
10308 if (cu
->dependencies
== NULL
)
10310 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
10311 NULL
, &cu
->comp_unit_obstack
,
10312 hashtab_obstack_allocate
,
10313 dummy_obstack_deallocate
);
10315 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
10317 *slot
= ref_per_cu
;
10320 /* Set the mark field in CU and in every other compilation unit in the
10321 cache that we must keep because we are keeping CU. */
10324 dwarf2_mark_helper (void **slot
, void *data
)
10326 struct dwarf2_per_cu_data
*per_cu
;
10328 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
10329 if (per_cu
->cu
->mark
)
10331 per_cu
->cu
->mark
= 1;
10333 if (per_cu
->cu
->dependencies
!= NULL
)
10334 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10340 dwarf2_mark (struct dwarf2_cu
*cu
)
10345 if (cu
->dependencies
!= NULL
)
10346 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10350 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
10354 per_cu
->cu
->mark
= 0;
10355 per_cu
= per_cu
->cu
->read_in_chain
;
10359 /* Trivial hash function for partial_die_info: the hash value of a DIE
10360 is its offset in .debug_info for this objfile. */
10363 partial_die_hash (const void *item
)
10365 const struct partial_die_info
*part_die
= item
;
10366 return part_die
->offset
;
10369 /* Trivial comparison function for partial_die_info structures: two DIEs
10370 are equal if they have the same offset. */
10373 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
10375 const struct partial_die_info
*part_die_lhs
= item_lhs
;
10376 const struct partial_die_info
*part_die_rhs
= item_rhs
;
10377 return part_die_lhs
->offset
== part_die_rhs
->offset
;
10380 static struct cmd_list_element
*set_dwarf2_cmdlist
;
10381 static struct cmd_list_element
*show_dwarf2_cmdlist
;
10384 set_dwarf2_cmd (char *args
, int from_tty
)
10386 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
10390 show_dwarf2_cmd (char *args
, int from_tty
)
10392 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
10395 void _initialize_dwarf2_read (void);
10398 _initialize_dwarf2_read (void)
10400 dwarf2_objfile_data_key
= register_objfile_data ();
10402 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
10403 Set DWARF 2 specific variables.\n\
10404 Configure DWARF 2 variables such as the cache size"),
10405 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
10406 0/*allow-unknown*/, &maintenance_set_cmdlist
);
10408 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
10409 Show DWARF 2 specific variables\n\
10410 Show DWARF 2 variables such as the cache size"),
10411 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
10412 0/*allow-unknown*/, &maintenance_show_cmdlist
);
10414 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
10415 &dwarf2_max_cache_age
, _("\
10416 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
10417 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
10418 A higher limit means that cached compilation units will be stored\n\
10419 in memory longer, and more total memory will be used. Zero disables\n\
10420 caching, which can slow down startup."),
10422 show_dwarf2_max_cache_age
,
10423 &set_dwarf2_cmdlist
,
10424 &show_dwarf2_cmdlist
);