1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
7 Inc. with support from Florida State University (under contract
8 with the Ada Joint Program Office), and Silicon Graphics, Inc.
9 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
10 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
13 This file is part of GDB.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 3 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>. */
33 #include "elf/dwarf2.h"
36 #include "expression.h"
37 #include "filenames.h" /* for DOSish file names */
40 #include "complaints.h"
42 #include "dwarf2expr.h"
43 #include "dwarf2loc.h"
44 #include "cp-support.h"
51 #include "gdb_string.h"
52 #include "gdb_assert.h"
53 #include <sys/types.h>
58 /* A note on memory usage for this file.
60 At the present time, this code reads the debug info sections into
61 the objfile's objfile_obstack. A definite improvement for startup
62 time, on platforms which do not emit relocations for debug
63 sections, would be to use mmap instead. The object's complete
64 debug information is loaded into memory, partly to simplify
65 absolute DIE references.
67 Whether using obstacks or mmap, the sections should remain loaded
68 until the objfile is released, and pointers into the section data
69 can be used for any other data associated to the objfile (symbol
70 names, type names, location expressions to name a few). */
73 /* .debug_info header for a compilation unit
74 Because of alignment constraints, this structure has padding and cannot
75 be mapped directly onto the beginning of the .debug_info section. */
76 typedef struct comp_unit_header
78 unsigned int length
; /* length of the .debug_info
80 unsigned short version
; /* version number -- 2 for DWARF
82 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
83 unsigned char addr_size
; /* byte size of an address -- 4 */
86 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
89 /* .debug_pubnames header
90 Because of alignment constraints, this structure has padding and cannot
91 be mapped directly onto the beginning of the .debug_info section. */
92 typedef struct pubnames_header
94 unsigned int length
; /* length of the .debug_pubnames
96 unsigned char version
; /* version number -- 2 for DWARF
98 unsigned int info_offset
; /* offset into .debug_info section */
99 unsigned int info_size
; /* byte size of .debug_info section
103 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
105 /* .debug_pubnames header
106 Because of alignment constraints, this structure has padding and cannot
107 be mapped directly onto the beginning of the .debug_info section. */
108 typedef struct aranges_header
110 unsigned int length
; /* byte len of the .debug_aranges
112 unsigned short version
; /* version number -- 2 for DWARF
114 unsigned int info_offset
; /* offset into .debug_info section */
115 unsigned char addr_size
; /* byte size of an address */
116 unsigned char seg_size
; /* byte size of segment descriptor */
119 #define _ACTUAL_ARANGES_HEADER_SIZE 12
121 /* .debug_line statement program prologue
122 Because of alignment constraints, this structure has padding and cannot
123 be mapped directly onto the beginning of the .debug_info section. */
124 typedef struct statement_prologue
126 unsigned int total_length
; /* byte length of the statement
128 unsigned short version
; /* version number -- 2 for DWARF
130 unsigned int prologue_length
; /* # bytes between prologue &
132 unsigned char minimum_instruction_length
; /* byte size of
134 unsigned char default_is_stmt
; /* initial value of is_stmt
137 unsigned char line_range
;
138 unsigned char opcode_base
; /* number assigned to first special
140 unsigned char *standard_opcode_lengths
;
144 /* When set, the file that we're processing is known to have debugging
145 info for C++ namespaces. GCC 3.3.x did not produce this information,
146 but later versions do. */
148 static int processing_has_namespace_info
;
150 static const struct objfile_data
*dwarf2_objfile_data_key
;
152 struct dwarf2_per_objfile
154 /* Sizes of debugging sections. */
155 unsigned int info_size
;
156 unsigned int abbrev_size
;
157 unsigned int line_size
;
158 unsigned int pubnames_size
;
159 unsigned int aranges_size
;
160 unsigned int loc_size
;
161 unsigned int macinfo_size
;
162 unsigned int str_size
;
163 unsigned int ranges_size
;
164 unsigned int frame_size
;
165 unsigned int eh_frame_size
;
167 /* Loaded data from the sections. */
168 gdb_byte
*info_buffer
;
169 gdb_byte
*abbrev_buffer
;
170 gdb_byte
*line_buffer
;
171 gdb_byte
*str_buffer
;
172 gdb_byte
*macinfo_buffer
;
173 gdb_byte
*ranges_buffer
;
174 gdb_byte
*loc_buffer
;
176 /* A list of all the compilation units. This is used to locate
177 the target compilation unit of a particular reference. */
178 struct dwarf2_per_cu_data
**all_comp_units
;
180 /* The number of compilation units in ALL_COMP_UNITS. */
183 /* A chain of compilation units that are currently read in, so that
184 they can be freed later. */
185 struct dwarf2_per_cu_data
*read_in_chain
;
187 /* A flag indicating wether this objfile has a section loaded at a
189 int has_section_at_zero
;
192 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
194 static asection
*dwarf_info_section
;
195 static asection
*dwarf_abbrev_section
;
196 static asection
*dwarf_line_section
;
197 static asection
*dwarf_pubnames_section
;
198 static asection
*dwarf_aranges_section
;
199 static asection
*dwarf_loc_section
;
200 static asection
*dwarf_macinfo_section
;
201 static asection
*dwarf_str_section
;
202 static asection
*dwarf_ranges_section
;
203 asection
*dwarf_frame_section
;
204 asection
*dwarf_eh_frame_section
;
206 /* names of the debugging sections */
208 /* Note that if the debugging section has been compressed, it might
209 have a name like .zdebug_info. */
211 #define INFO_SECTION "debug_info"
212 #define ABBREV_SECTION "debug_abbrev"
213 #define LINE_SECTION "debug_line"
214 #define PUBNAMES_SECTION "debug_pubnames"
215 #define ARANGES_SECTION "debug_aranges"
216 #define LOC_SECTION "debug_loc"
217 #define MACINFO_SECTION "debug_macinfo"
218 #define STR_SECTION "debug_str"
219 #define RANGES_SECTION "debug_ranges"
220 #define FRAME_SECTION "debug_frame"
221 #define EH_FRAME_SECTION "eh_frame"
223 /* local data types */
225 /* We hold several abbreviation tables in memory at the same time. */
226 #ifndef ABBREV_HASH_SIZE
227 #define ABBREV_HASH_SIZE 121
230 /* The data in a compilation unit header, after target2host
231 translation, looks like this. */
232 struct comp_unit_head
234 unsigned long length
;
236 unsigned int abbrev_offset
;
237 unsigned char addr_size
;
238 unsigned char signed_addr_p
;
240 /* Size of file offsets; either 4 or 8. */
241 unsigned int offset_size
;
243 /* Size of the length field; either 4 or 12. */
244 unsigned int initial_length_size
;
246 /* Offset to the first byte of this compilation unit header in the
247 .debug_info section, for resolving relative reference dies. */
250 /* Offset to first die in this cu from the start of the cu.
251 This will be the first byte following the compilation unit header. */
252 unsigned int first_die_offset
;
255 /* Internal state when decoding a particular compilation unit. */
258 /* The objfile containing this compilation unit. */
259 struct objfile
*objfile
;
261 /* The header of the compilation unit. */
262 struct comp_unit_head header
;
264 /* Base address of this compilation unit. */
265 CORE_ADDR base_address
;
267 /* Non-zero if base_address has been set. */
270 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
272 /* The language we are debugging. */
273 enum language language
;
274 const struct language_defn
*language_defn
;
276 const char *producer
;
278 /* The generic symbol table building routines have separate lists for
279 file scope symbols and all all other scopes (local scopes). So
280 we need to select the right one to pass to add_symbol_to_list().
281 We do it by keeping a pointer to the correct list in list_in_scope.
283 FIXME: The original dwarf code just treated the file scope as the
284 first local scope, and all other local scopes as nested local
285 scopes, and worked fine. Check to see if we really need to
286 distinguish these in buildsym.c. */
287 struct pending
**list_in_scope
;
289 /* DWARF abbreviation table associated with this compilation unit. */
290 struct abbrev_info
**dwarf2_abbrevs
;
292 /* Storage for the abbrev table. */
293 struct obstack abbrev_obstack
;
295 /* Hash table holding all the loaded partial DIEs. */
298 /* `.debug_ranges' offset for this `DW_TAG_compile_unit' DIE. */
299 unsigned long ranges_offset
;
301 /* Storage for things with the same lifetime as this read-in compilation
302 unit, including partial DIEs. */
303 struct obstack comp_unit_obstack
;
305 /* When multiple dwarf2_cu structures are living in memory, this field
306 chains them all together, so that they can be released efficiently.
307 We will probably also want a generation counter so that most-recently-used
308 compilation units are cached... */
309 struct dwarf2_per_cu_data
*read_in_chain
;
311 /* Backchain to our per_cu entry if the tree has been built. */
312 struct dwarf2_per_cu_data
*per_cu
;
314 /* Pointer to the die -> type map. Although it is stored
315 permanently in per_cu, we copy it here to avoid double
319 /* How many compilation units ago was this CU last referenced? */
322 /* A hash table of die offsets for following references. */
325 /* Full DIEs if read in. */
326 struct die_info
*dies
;
328 /* A set of pointers to dwarf2_per_cu_data objects for compilation
329 units referenced by this one. Only set during full symbol processing;
330 partial symbol tables do not have dependencies. */
333 /* Header data from the line table, during full symbol processing. */
334 struct line_header
*line_header
;
336 /* Mark used when releasing cached dies. */
337 unsigned int mark
: 1;
339 /* This flag will be set if this compilation unit might include
340 inter-compilation-unit references. */
341 unsigned int has_form_ref_addr
: 1;
343 /* This flag will be set if this compilation unit includes any
344 DW_TAG_namespace DIEs. If we know that there are explicit
345 DIEs for namespaces, we don't need to try to infer them
346 from mangled names. */
347 unsigned int has_namespace_info
: 1;
349 /* Field `ranges_offset' is filled in; flag as the value may be zero. */
350 unsigned int has_ranges_offset
: 1;
353 /* Persistent data held for a compilation unit, even when not
354 processing it. We put a pointer to this structure in the
355 read_symtab_private field of the psymtab. If we encounter
356 inter-compilation-unit references, we also maintain a sorted
357 list of all compilation units. */
359 struct dwarf2_per_cu_data
361 /* The start offset and length of this compilation unit. 2**30-1
362 bytes should suffice to store the length of any compilation unit
363 - if it doesn't, GDB will fall over anyway. */
364 unsigned long offset
;
365 unsigned long length
: 30;
367 /* Flag indicating this compilation unit will be read in before
368 any of the current compilation units are processed. */
369 unsigned long queued
: 1;
371 /* This flag will be set if we need to load absolutely all DIEs
372 for this compilation unit, instead of just the ones we think
373 are interesting. It gets set if we look for a DIE in the
374 hash table and don't find it. */
375 unsigned int load_all_dies
: 1;
377 /* Set iff currently read in. */
378 struct dwarf2_cu
*cu
;
380 /* If full symbols for this CU have been read in, then this field
381 holds a map of DIE offsets to types. It isn't always possible
382 to reconstruct this information later, so we have to preserve
386 /* The partial symbol table associated with this compilation unit,
387 or NULL for partial units (which do not have an associated
389 struct partial_symtab
*psymtab
;
392 /* The line number information for a compilation unit (found in the
393 .debug_line section) begins with a "statement program header",
394 which contains the following information. */
397 unsigned int total_length
;
398 unsigned short version
;
399 unsigned int header_length
;
400 unsigned char minimum_instruction_length
;
401 unsigned char default_is_stmt
;
403 unsigned char line_range
;
404 unsigned char opcode_base
;
406 /* standard_opcode_lengths[i] is the number of operands for the
407 standard opcode whose value is i. This means that
408 standard_opcode_lengths[0] is unused, and the last meaningful
409 element is standard_opcode_lengths[opcode_base - 1]. */
410 unsigned char *standard_opcode_lengths
;
412 /* The include_directories table. NOTE! These strings are not
413 allocated with xmalloc; instead, they are pointers into
414 debug_line_buffer. If you try to free them, `free' will get
416 unsigned int num_include_dirs
, include_dirs_size
;
419 /* The file_names table. NOTE! These strings are not allocated
420 with xmalloc; instead, they are pointers into debug_line_buffer.
421 Don't try to free them directly. */
422 unsigned int num_file_names
, file_names_size
;
426 unsigned int dir_index
;
427 unsigned int mod_time
;
429 int included_p
; /* Non-zero if referenced by the Line Number Program. */
430 struct symtab
*symtab
; /* The associated symbol table, if any. */
433 /* The start and end of the statement program following this
434 header. These point into dwarf2_per_objfile->line_buffer. */
435 gdb_byte
*statement_program_start
, *statement_program_end
;
438 /* When we construct a partial symbol table entry we only
439 need this much information. */
440 struct partial_die_info
442 /* Offset of this DIE. */
445 /* DWARF-2 tag for this DIE. */
446 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
448 /* Language code associated with this DIE. This is only used
449 for the compilation unit DIE. */
450 unsigned int language
: 8;
452 /* Assorted flags describing the data found in this DIE. */
453 unsigned int has_children
: 1;
454 unsigned int is_external
: 1;
455 unsigned int is_declaration
: 1;
456 unsigned int has_type
: 1;
457 unsigned int has_specification
: 1;
458 unsigned int has_stmt_list
: 1;
459 unsigned int has_pc_info
: 1;
461 /* Flag set if the SCOPE field of this structure has been
463 unsigned int scope_set
: 1;
465 /* Flag set if the DIE has a byte_size attribute. */
466 unsigned int has_byte_size
: 1;
468 /* The name of this DIE. Normally the value of DW_AT_name, but
469 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
474 /* The scope to prepend to our children. This is generally
475 allocated on the comp_unit_obstack, so will disappear
476 when this compilation unit leaves the cache. */
479 /* The location description associated with this DIE, if any. */
480 struct dwarf_block
*locdesc
;
482 /* If HAS_PC_INFO, the PC range associated with this DIE. */
486 /* Pointer into the info_buffer pointing at the target of
487 DW_AT_sibling, if any. */
490 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
491 DW_AT_specification (or DW_AT_abstract_origin or
493 unsigned int spec_offset
;
495 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
496 unsigned int line_offset
;
498 /* Pointers to this DIE's parent, first child, and next sibling,
500 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
503 /* This data structure holds the information of an abbrev. */
506 unsigned int number
; /* number identifying abbrev */
507 enum dwarf_tag tag
; /* dwarf tag */
508 unsigned short has_children
; /* boolean */
509 unsigned short num_attrs
; /* number of attributes */
510 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
511 struct abbrev_info
*next
; /* next in chain */
516 enum dwarf_attribute name
;
517 enum dwarf_form form
;
520 /* Attributes have a name and a value */
523 enum dwarf_attribute name
;
524 enum dwarf_form form
;
528 struct dwarf_block
*blk
;
536 /* This data structure holds a complete die structure. */
539 enum dwarf_tag tag
; /* Tag indicating type of die */
540 unsigned int abbrev
; /* Abbrev number */
541 unsigned int offset
; /* Offset in .debug_info section */
542 unsigned int num_attrs
; /* Number of attributes */
544 /* The dies in a compilation unit form an n-ary tree. PARENT
545 points to this die's parent; CHILD points to the first child of
546 this node; and all the children of a given node are chained
547 together via their SIBLING fields, terminated by a die whose
549 struct die_info
*child
; /* Its first child, if any. */
550 struct die_info
*sibling
; /* Its next sibling, if any. */
551 struct die_info
*parent
; /* Its parent, if any. */
553 /* An array of attributes, with NUM_ATTRS elements. There may be
554 zero, but it's not common and zero-sized arrays are not
555 sufficiently portable C. */
556 struct attribute attrs
[1];
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
,
847 struct dwarf2_cu
**);
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 const char *determine_class_name (struct die_info
*die
,
924 struct dwarf2_cu
*cu
);
926 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
928 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
930 static const char *namespace_name (struct die_info
*die
,
931 int *is_anonymous
, struct dwarf2_cu
*);
933 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
935 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
937 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
940 static struct die_info
*read_comp_unit (gdb_byte
*, bfd
*, struct dwarf2_cu
*);
942 static struct die_info
*read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
944 gdb_byte
**new_info_ptr
,
945 struct die_info
*parent
);
947 static struct die_info
*read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
949 gdb_byte
**new_info_ptr
,
950 struct die_info
*parent
);
952 static void process_die (struct die_info
*, struct dwarf2_cu
*);
954 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
956 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
958 static struct die_info
*dwarf2_extension (struct die_info
*die
,
959 struct dwarf2_cu
**);
961 static char *dwarf_tag_name (unsigned int);
963 static char *dwarf_attr_name (unsigned int);
965 static char *dwarf_form_name (unsigned int);
967 static char *dwarf_stack_op_name (unsigned int);
969 static char *dwarf_bool_name (unsigned int);
971 static char *dwarf_type_encoding_name (unsigned int);
974 static char *dwarf_cfi_name (unsigned int);
977 static struct die_info
*sibling_die (struct die_info
*);
979 static void dump_die (struct die_info
*);
981 static void dump_die_list (struct die_info
*);
983 static void store_in_ref_table (struct die_info
*,
986 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*,
989 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
991 static struct die_info
*follow_die_ref (struct die_info
*,
993 struct dwarf2_cu
**);
995 /* memory allocation interface */
997 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
999 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1001 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1003 static void initialize_cu_func_list (struct dwarf2_cu
*);
1005 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1006 struct dwarf2_cu
*);
1008 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1009 char *, bfd
*, struct dwarf2_cu
*);
1011 static int attr_form_is_block (struct attribute
*);
1013 static int attr_form_is_section_offset (struct attribute
*);
1015 static int attr_form_is_constant (struct attribute
*);
1017 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1019 struct dwarf2_cu
*cu
);
1021 static gdb_byte
*skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
1022 struct dwarf2_cu
*cu
);
1024 static void free_stack_comp_unit (void *);
1026 static hashval_t
partial_die_hash (const void *item
);
1028 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1030 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1031 (unsigned long offset
, struct objfile
*objfile
);
1033 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1034 (unsigned long offset
, struct objfile
*objfile
);
1036 static void free_one_comp_unit (void *);
1038 static void free_cached_comp_units (void *);
1040 static void age_cached_comp_units (void);
1042 static void free_one_cached_comp_unit (void *);
1044 static struct type
*set_die_type (struct die_info
*, struct type
*,
1045 struct dwarf2_cu
*);
1047 static void create_all_comp_units (struct objfile
*);
1049 static struct dwarf2_cu
*load_full_comp_unit (struct dwarf2_per_cu_data
*,
1052 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1054 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1055 struct dwarf2_per_cu_data
*);
1057 static void dwarf2_mark (struct dwarf2_cu
*);
1059 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1061 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1063 /* Try to locate the sections we need for DWARF 2 debugging
1064 information and return true if we have enough to do something. */
1067 dwarf2_has_info (struct objfile
*objfile
)
1069 struct dwarf2_per_objfile
*data
;
1071 /* Initialize per-objfile state. */
1072 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1073 memset (data
, 0, sizeof (*data
));
1074 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1075 dwarf2_per_objfile
= data
;
1077 dwarf_info_section
= 0;
1078 dwarf_abbrev_section
= 0;
1079 dwarf_line_section
= 0;
1080 dwarf_str_section
= 0;
1081 dwarf_macinfo_section
= 0;
1082 dwarf_frame_section
= 0;
1083 dwarf_eh_frame_section
= 0;
1084 dwarf_ranges_section
= 0;
1085 dwarf_loc_section
= 0;
1087 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1088 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
1091 /* When loading sections, we can either look for ".<name>", or for
1092 * ".z<name>", which indicates a compressed section. */
1095 section_is_p (asection
*sectp
, const char *name
)
1097 return ((sectp
->name
[0] == '.'
1098 && strcmp (sectp
->name
+ 1, name
) == 0)
1099 || (sectp
->name
[0] == '.' && sectp
->name
[1] == 'z'
1100 && strcmp (sectp
->name
+ 2, name
) == 0));
1103 /* This function is mapped across the sections and remembers the
1104 offset and size of each of the debugging sections we are interested
1108 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1110 if (section_is_p (sectp
, INFO_SECTION
))
1112 dwarf2_per_objfile
->info_size
= bfd_get_section_size (sectp
);
1113 dwarf_info_section
= sectp
;
1115 else if (section_is_p (sectp
, ABBREV_SECTION
))
1117 dwarf2_per_objfile
->abbrev_size
= bfd_get_section_size (sectp
);
1118 dwarf_abbrev_section
= sectp
;
1120 else if (section_is_p (sectp
, LINE_SECTION
))
1122 dwarf2_per_objfile
->line_size
= bfd_get_section_size (sectp
);
1123 dwarf_line_section
= sectp
;
1125 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1127 dwarf2_per_objfile
->pubnames_size
= bfd_get_section_size (sectp
);
1128 dwarf_pubnames_section
= sectp
;
1130 else if (section_is_p (sectp
, ARANGES_SECTION
))
1132 dwarf2_per_objfile
->aranges_size
= bfd_get_section_size (sectp
);
1133 dwarf_aranges_section
= sectp
;
1135 else if (section_is_p (sectp
, LOC_SECTION
))
1137 dwarf2_per_objfile
->loc_size
= bfd_get_section_size (sectp
);
1138 dwarf_loc_section
= sectp
;
1140 else if (section_is_p (sectp
, MACINFO_SECTION
))
1142 dwarf2_per_objfile
->macinfo_size
= bfd_get_section_size (sectp
);
1143 dwarf_macinfo_section
= sectp
;
1145 else if (section_is_p (sectp
, STR_SECTION
))
1147 dwarf2_per_objfile
->str_size
= bfd_get_section_size (sectp
);
1148 dwarf_str_section
= sectp
;
1150 else if (section_is_p (sectp
, FRAME_SECTION
))
1152 dwarf2_per_objfile
->frame_size
= bfd_get_section_size (sectp
);
1153 dwarf_frame_section
= sectp
;
1155 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1157 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1158 if (aflag
& SEC_HAS_CONTENTS
)
1160 dwarf2_per_objfile
->eh_frame_size
= bfd_get_section_size (sectp
);
1161 dwarf_eh_frame_section
= sectp
;
1164 else if (section_is_p (sectp
, RANGES_SECTION
))
1166 dwarf2_per_objfile
->ranges_size
= bfd_get_section_size (sectp
);
1167 dwarf_ranges_section
= sectp
;
1170 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1171 && bfd_section_vma (abfd
, sectp
) == 0)
1172 dwarf2_per_objfile
->has_section_at_zero
= 1;
1175 /* This function is called after decompressing a section, so
1176 dwarf2_per_objfile can record its new, uncompressed size. */
1179 dwarf2_resize_section (asection
*sectp
, bfd_size_type new_size
)
1181 if (section_is_p (sectp
, INFO_SECTION
))
1182 dwarf2_per_objfile
->info_size
= new_size
;
1183 else if (section_is_p (sectp
, ABBREV_SECTION
))
1184 dwarf2_per_objfile
->abbrev_size
= new_size
;
1185 else if (section_is_p (sectp
, LINE_SECTION
))
1186 dwarf2_per_objfile
->line_size
= new_size
;
1187 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1188 dwarf2_per_objfile
->pubnames_size
= new_size
;
1189 else if (section_is_p (sectp
, ARANGES_SECTION
))
1190 dwarf2_per_objfile
->aranges_size
= new_size
;
1191 else if (section_is_p (sectp
, LOC_SECTION
))
1192 dwarf2_per_objfile
->loc_size
= new_size
;
1193 else if (section_is_p (sectp
, MACINFO_SECTION
))
1194 dwarf2_per_objfile
->macinfo_size
= new_size
;
1195 else if (section_is_p (sectp
, STR_SECTION
))
1196 dwarf2_per_objfile
->str_size
= new_size
;
1197 else if (section_is_p (sectp
, FRAME_SECTION
))
1198 dwarf2_per_objfile
->frame_size
= new_size
;
1199 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1200 dwarf2_per_objfile
->eh_frame_size
= new_size
;
1201 else if (section_is_p (sectp
, RANGES_SECTION
))
1202 dwarf2_per_objfile
->ranges_size
= new_size
;
1204 internal_error (__FILE__
, __LINE__
,
1205 _("dwarf2_resize_section: missing section_is_p check: %s"),
1209 /* Build a partial symbol table. */
1212 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1214 /* We definitely need the .debug_info and .debug_abbrev sections */
1216 dwarf2_per_objfile
->info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1217 dwarf2_per_objfile
->abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1219 if (dwarf_line_section
)
1220 dwarf2_per_objfile
->line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1222 dwarf2_per_objfile
->line_buffer
= NULL
;
1224 if (dwarf_str_section
)
1225 dwarf2_per_objfile
->str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1227 dwarf2_per_objfile
->str_buffer
= NULL
;
1229 if (dwarf_macinfo_section
)
1230 dwarf2_per_objfile
->macinfo_buffer
= dwarf2_read_section (objfile
,
1231 dwarf_macinfo_section
);
1233 dwarf2_per_objfile
->macinfo_buffer
= NULL
;
1235 if (dwarf_ranges_section
)
1236 dwarf2_per_objfile
->ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1238 dwarf2_per_objfile
->ranges_buffer
= NULL
;
1240 if (dwarf_loc_section
)
1241 dwarf2_per_objfile
->loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1243 dwarf2_per_objfile
->loc_buffer
= NULL
;
1246 || (objfile
->global_psymbols
.size
== 0
1247 && objfile
->static_psymbols
.size
== 0))
1249 init_psymbol_list (objfile
, 1024);
1253 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1255 /* Things are significantly easier if we have .debug_aranges and
1256 .debug_pubnames sections */
1258 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1262 /* only test this case for now */
1264 /* In this case we have to work a bit harder */
1265 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1270 /* Build the partial symbol table from the information in the
1271 .debug_pubnames and .debug_aranges sections. */
1274 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1276 bfd
*abfd
= objfile
->obfd
;
1277 char *aranges_buffer
, *pubnames_buffer
;
1278 char *aranges_ptr
, *pubnames_ptr
;
1279 unsigned int entry_length
, version
, info_offset
, info_size
;
1281 pubnames_buffer
= dwarf2_read_section (objfile
,
1282 dwarf_pubnames_section
);
1283 pubnames_ptr
= pubnames_buffer
;
1284 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames_size
)
1286 struct comp_unit_head cu_header
;
1287 unsigned int bytes_read
;
1289 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1291 pubnames_ptr
+= bytes_read
;
1292 version
= read_1_byte (abfd
, pubnames_ptr
);
1294 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1296 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1300 aranges_buffer
= dwarf2_read_section (objfile
,
1301 dwarf_aranges_section
);
1306 /* Read in the comp unit header information from the debug_info at
1310 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1311 gdb_byte
*info_ptr
, bfd
*abfd
)
1314 unsigned int bytes_read
;
1315 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1317 info_ptr
+= bytes_read
;
1318 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1320 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1322 info_ptr
+= bytes_read
;
1323 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1325 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1326 if (signed_addr
< 0)
1327 internal_error (__FILE__
, __LINE__
,
1328 _("read_comp_unit_head: dwarf from non elf file"));
1329 cu_header
->signed_addr_p
= signed_addr
;
1334 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1337 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1339 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1341 if (header
->version
!= 2 && header
->version
!= 3)
1342 error (_("Dwarf Error: wrong version in compilation unit header "
1343 "(is %d, should be %d) [in module %s]"), header
->version
,
1344 2, bfd_get_filename (abfd
));
1346 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev_size
)
1347 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1348 "(offset 0x%lx + 6) [in module %s]"),
1349 (long) header
->abbrev_offset
,
1350 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1351 bfd_get_filename (abfd
));
1353 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1354 > dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1355 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1356 "(offset 0x%lx + 0) [in module %s]"),
1357 (long) header
->length
,
1358 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1359 bfd_get_filename (abfd
));
1364 /* Allocate a new partial symtab for file named NAME and mark this new
1365 partial symtab as being an include of PST. */
1368 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1369 struct objfile
*objfile
)
1371 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1373 subpst
->section_offsets
= pst
->section_offsets
;
1374 subpst
->textlow
= 0;
1375 subpst
->texthigh
= 0;
1377 subpst
->dependencies
= (struct partial_symtab
**)
1378 obstack_alloc (&objfile
->objfile_obstack
,
1379 sizeof (struct partial_symtab
*));
1380 subpst
->dependencies
[0] = pst
;
1381 subpst
->number_of_dependencies
= 1;
1383 subpst
->globals_offset
= 0;
1384 subpst
->n_global_syms
= 0;
1385 subpst
->statics_offset
= 0;
1386 subpst
->n_static_syms
= 0;
1387 subpst
->symtab
= NULL
;
1388 subpst
->read_symtab
= pst
->read_symtab
;
1391 /* No private part is necessary for include psymtabs. This property
1392 can be used to differentiate between such include psymtabs and
1393 the regular ones. */
1394 subpst
->read_symtab_private
= NULL
;
1397 /* Read the Line Number Program data and extract the list of files
1398 included by the source file represented by PST. Build an include
1399 partial symtab for each of these included files.
1401 This procedure assumes that there *is* a Line Number Program in
1402 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1403 before calling this procedure. */
1406 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1407 struct partial_die_info
*pdi
,
1408 struct partial_symtab
*pst
)
1410 struct objfile
*objfile
= cu
->objfile
;
1411 bfd
*abfd
= objfile
->obfd
;
1412 struct line_header
*lh
;
1414 lh
= dwarf_decode_line_header (pdi
->line_offset
, abfd
, cu
);
1416 return; /* No linetable, so no includes. */
1418 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1420 free_line_header (lh
);
1424 /* Build the partial symbol table by doing a quick pass through the
1425 .debug_info and .debug_abbrev sections. */
1428 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1430 /* Instead of reading this into a big buffer, we should probably use
1431 mmap() on architectures that support it. (FIXME) */
1432 bfd
*abfd
= objfile
->obfd
;
1434 gdb_byte
*beg_of_comp_unit
;
1435 struct partial_die_info comp_unit_die
;
1436 struct partial_symtab
*pst
;
1437 struct cleanup
*back_to
;
1438 CORE_ADDR lowpc
, highpc
, baseaddr
;
1440 info_ptr
= dwarf2_per_objfile
->info_buffer
;
1442 /* Any cached compilation units will be linked by the per-objfile
1443 read_in_chain. Make sure to free them when we're done. */
1444 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1446 create_all_comp_units (objfile
);
1448 objfile
->psymtabs_addrmap
= addrmap_create_mutable
1449 (&objfile
->objfile_obstack
);
1451 /* Since the objects we're extracting from .debug_info vary in
1452 length, only the individual functions to extract them (like
1453 read_comp_unit_head and load_partial_die) can really know whether
1454 the buffer is large enough to hold another complete object.
1456 At the moment, they don't actually check that. If .debug_info
1457 holds just one extra byte after the last compilation unit's dies,
1458 then read_comp_unit_head will happily read off the end of the
1459 buffer. read_partial_die is similarly casual. Those functions
1462 For this loop condition, simply checking whether there's any data
1463 left at all should be sufficient. */
1464 while (info_ptr
< (dwarf2_per_objfile
->info_buffer
1465 + dwarf2_per_objfile
->info_size
))
1467 struct cleanup
*back_to_inner
;
1468 struct dwarf2_cu cu
;
1469 struct abbrev_info
*abbrev
;
1470 unsigned int bytes_read
;
1471 struct dwarf2_per_cu_data
*this_cu
;
1473 beg_of_comp_unit
= info_ptr
;
1475 memset (&cu
, 0, sizeof (cu
));
1477 obstack_init (&cu
.comp_unit_obstack
);
1479 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1481 cu
.objfile
= objfile
;
1482 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1484 /* Complete the cu_header */
1485 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1486 cu
.header
.first_die_offset
= info_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
= obsavestring (comp_unit_die
.dirname
,
1522 strlen (comp_unit_die
.dirname
),
1523 &objfile
->objfile_obstack
);
1525 pst
->read_symtab_private
= (char *) this_cu
;
1527 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1529 /* Store the function that reads in the rest of the symbol table */
1530 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1532 /* If this compilation unit was already read in, free the
1533 cached copy in order to read it in again. This is
1534 necessary because we skipped some symbols when we first
1535 read in the compilation unit (see load_partial_dies).
1536 This problem could be avoided, but the benefit is
1538 if (this_cu
->cu
!= NULL
)
1539 free_one_cached_comp_unit (this_cu
->cu
);
1541 cu
.per_cu
= this_cu
;
1543 /* Note that this is a pointer to our stack frame, being
1544 added to a global data structure. It will be cleaned up
1545 in free_stack_comp_unit when we finish with this
1546 compilation unit. */
1549 this_cu
->psymtab
= pst
;
1551 /* Possibly set the default values of LOWPC and HIGHPC from
1553 if (cu
.has_ranges_offset
)
1555 if (dwarf2_ranges_read (cu
.ranges_offset
, &comp_unit_die
.lowpc
,
1556 &comp_unit_die
.highpc
, &cu
, pst
))
1557 comp_unit_die
.has_pc_info
= 1;
1560 /* Check if comp unit has_children.
1561 If so, read the rest of the partial symbols from this comp unit.
1562 If not, there's no more debug_info for this comp unit. */
1563 if (comp_unit_die
.has_children
)
1565 struct partial_die_info
*first_die
;
1567 lowpc
= ((CORE_ADDR
) -1);
1568 highpc
= ((CORE_ADDR
) 0);
1570 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1572 scan_partial_symbols (first_die
, &lowpc
, &highpc
, &cu
);
1574 /* If we didn't find a lowpc, set it to highpc to avoid
1575 complaints from `maint check'. */
1576 if (lowpc
== ((CORE_ADDR
) -1))
1579 /* If the compilation unit didn't have an explicit address range,
1580 then use the information extracted from its child dies. */
1581 if (! comp_unit_die
.has_pc_info
)
1583 comp_unit_die
.lowpc
= lowpc
;
1584 comp_unit_die
.highpc
= highpc
;
1587 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1588 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1590 /* Store the contiguous range; `DW_AT_ranges' range is stored above. The
1591 range can be also empty for CUs with no code. */
1592 if (!cu
.has_ranges_offset
&& pst
->textlow
< pst
->texthigh
)
1593 addrmap_set_empty (objfile
->psymtabs_addrmap
, pst
->textlow
,
1594 pst
->texthigh
- 1, pst
);
1596 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1597 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1598 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1599 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1600 sort_pst_symbols (pst
);
1602 /* If there is already a psymtab or symtab for a file of this
1603 name, remove it. (If there is a symtab, more drastic things
1604 also happen.) This happens in VxWorks. */
1605 free_named_symtabs (pst
->filename
);
1607 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1608 + cu
.header
.initial_length_size
;
1610 if (comp_unit_die
.has_stmt_list
)
1612 /* Get the list of files included in the current compilation unit,
1613 and build a psymtab for each of them. */
1614 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1617 do_cleanups (back_to_inner
);
1620 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
1621 &objfile
->objfile_obstack
);
1623 do_cleanups (back_to
);
1626 /* Load the DIEs for a secondary CU into memory. */
1629 load_comp_unit (struct dwarf2_per_cu_data
*this_cu
, struct objfile
*objfile
)
1631 bfd
*abfd
= objfile
->obfd
;
1632 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
1633 struct partial_die_info comp_unit_die
;
1634 struct dwarf2_cu
*cu
;
1635 struct abbrev_info
*abbrev
;
1636 unsigned int bytes_read
;
1637 struct cleanup
*back_to
;
1639 info_ptr
= dwarf2_per_objfile
->info_buffer
+ this_cu
->offset
;
1640 beg_of_comp_unit
= info_ptr
;
1642 cu
= xmalloc (sizeof (struct dwarf2_cu
));
1643 memset (cu
, 0, sizeof (struct dwarf2_cu
));
1645 obstack_init (&cu
->comp_unit_obstack
);
1647 cu
->objfile
= objfile
;
1648 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
1650 /* Complete the cu_header. */
1651 cu
->header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1652 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1654 /* Read the abbrevs for this compilation unit into a table. */
1655 dwarf2_read_abbrevs (abfd
, cu
);
1656 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
1658 /* Read the compilation unit die. */
1659 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1660 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1661 abfd
, info_ptr
, cu
);
1663 /* Set the language we're debugging. */
1664 set_cu_language (comp_unit_die
.language
, cu
);
1666 /* Link this compilation unit into the compilation unit tree. */
1668 cu
->per_cu
= this_cu
;
1669 cu
->type_hash
= cu
->per_cu
->type_hash
;
1671 /* Check if comp unit has_children.
1672 If so, read the rest of the partial symbols from this comp unit.
1673 If not, there's no more debug_info for this comp unit. */
1674 if (comp_unit_die
.has_children
)
1675 load_partial_dies (abfd
, info_ptr
, 0, cu
);
1677 do_cleanups (back_to
);
1680 /* Create a list of all compilation units in OBJFILE. We do this only
1681 if an inter-comp-unit reference is found; presumably if there is one,
1682 there will be many, and one will occur early in the .debug_info section.
1683 So there's no point in building this list incrementally. */
1686 create_all_comp_units (struct objfile
*objfile
)
1690 struct dwarf2_per_cu_data
**all_comp_units
;
1691 gdb_byte
*info_ptr
= dwarf2_per_objfile
->info_buffer
;
1695 all_comp_units
= xmalloc (n_allocated
1696 * sizeof (struct dwarf2_per_cu_data
*));
1698 while (info_ptr
< dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1700 struct comp_unit_head cu_header
;
1701 gdb_byte
*beg_of_comp_unit
;
1702 struct dwarf2_per_cu_data
*this_cu
;
1703 unsigned long offset
;
1704 unsigned int bytes_read
;
1706 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
1708 /* Read just enough information to find out where the next
1709 compilation unit is. */
1710 cu_header
.initial_length_size
= 0;
1711 cu_header
.length
= read_initial_length (objfile
->obfd
, info_ptr
,
1712 &cu_header
, &bytes_read
);
1714 /* Save the compilation unit for later lookup. */
1715 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
1716 sizeof (struct dwarf2_per_cu_data
));
1717 memset (this_cu
, 0, sizeof (*this_cu
));
1718 this_cu
->offset
= offset
;
1719 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
1721 if (n_comp_units
== n_allocated
)
1724 all_comp_units
= xrealloc (all_comp_units
,
1726 * sizeof (struct dwarf2_per_cu_data
*));
1728 all_comp_units
[n_comp_units
++] = this_cu
;
1730 info_ptr
= info_ptr
+ this_cu
->length
;
1733 dwarf2_per_objfile
->all_comp_units
1734 = obstack_alloc (&objfile
->objfile_obstack
,
1735 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1736 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
1737 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1738 xfree (all_comp_units
);
1739 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
1742 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1743 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1747 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1748 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
1750 struct objfile
*objfile
= cu
->objfile
;
1751 bfd
*abfd
= objfile
->obfd
;
1752 struct partial_die_info
*pdi
;
1754 /* Now, march along the PDI's, descending into ones which have
1755 interesting children but skipping the children of the other ones,
1756 until we reach the end of the compilation unit. */
1762 fixup_partial_die (pdi
, cu
);
1764 /* Anonymous namespaces have no name but have interesting
1765 children, so we need to look at them. Ditto for anonymous
1768 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1769 || pdi
->tag
== DW_TAG_enumeration_type
)
1773 case DW_TAG_subprogram
:
1774 if (pdi
->has_pc_info
)
1776 if (pdi
->lowpc
< *lowpc
)
1778 *lowpc
= pdi
->lowpc
;
1780 if (pdi
->highpc
> *highpc
)
1782 *highpc
= pdi
->highpc
;
1784 if (!pdi
->is_declaration
)
1786 add_partial_symbol (pdi
, cu
);
1790 case DW_TAG_variable
:
1791 case DW_TAG_typedef
:
1792 case DW_TAG_union_type
:
1793 if (!pdi
->is_declaration
)
1795 add_partial_symbol (pdi
, cu
);
1798 case DW_TAG_class_type
:
1799 case DW_TAG_interface_type
:
1800 case DW_TAG_structure_type
:
1801 if (!pdi
->is_declaration
)
1803 add_partial_symbol (pdi
, cu
);
1806 case DW_TAG_enumeration_type
:
1807 if (!pdi
->is_declaration
)
1808 add_partial_enumeration (pdi
, cu
);
1810 case DW_TAG_base_type
:
1811 case DW_TAG_subrange_type
:
1812 /* File scope base type definitions are added to the partial
1814 add_partial_symbol (pdi
, cu
);
1816 case DW_TAG_namespace
:
1817 add_partial_namespace (pdi
, lowpc
, highpc
, cu
);
1824 /* If the die has a sibling, skip to the sibling. */
1826 pdi
= pdi
->die_sibling
;
1830 /* Functions used to compute the fully scoped name of a partial DIE.
1832 Normally, this is simple. For C++, the parent DIE's fully scoped
1833 name is concatenated with "::" and the partial DIE's name. For
1834 Java, the same thing occurs except that "." is used instead of "::".
1835 Enumerators are an exception; they use the scope of their parent
1836 enumeration type, i.e. the name of the enumeration type is not
1837 prepended to the enumerator.
1839 There are two complexities. One is DW_AT_specification; in this
1840 case "parent" means the parent of the target of the specification,
1841 instead of the direct parent of the DIE. The other is compilers
1842 which do not emit DW_TAG_namespace; in this case we try to guess
1843 the fully qualified name of structure types from their members'
1844 linkage names. This must be done using the DIE's children rather
1845 than the children of any DW_AT_specification target. We only need
1846 to do this for structures at the top level, i.e. if the target of
1847 any DW_AT_specification (if any; otherwise the DIE itself) does not
1850 /* Compute the scope prefix associated with PDI's parent, in
1851 compilation unit CU. The result will be allocated on CU's
1852 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1853 field. NULL is returned if no prefix is necessary. */
1855 partial_die_parent_scope (struct partial_die_info
*pdi
,
1856 struct dwarf2_cu
*cu
)
1858 char *grandparent_scope
;
1859 struct partial_die_info
*parent
, *real_pdi
;
1861 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1862 then this means the parent of the specification DIE. */
1865 while (real_pdi
->has_specification
)
1866 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
1868 parent
= real_pdi
->die_parent
;
1872 if (parent
->scope_set
)
1873 return parent
->scope
;
1875 fixup_partial_die (parent
, cu
);
1877 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
1879 if (parent
->tag
== DW_TAG_namespace
1880 || parent
->tag
== DW_TAG_structure_type
1881 || parent
->tag
== DW_TAG_class_type
1882 || parent
->tag
== DW_TAG_interface_type
1883 || parent
->tag
== DW_TAG_union_type
)
1885 if (grandparent_scope
== NULL
)
1886 parent
->scope
= parent
->name
;
1888 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
1891 else if (parent
->tag
== DW_TAG_enumeration_type
)
1892 /* Enumerators should not get the name of the enumeration as a prefix. */
1893 parent
->scope
= grandparent_scope
;
1896 /* FIXME drow/2004-04-01: What should we be doing with
1897 function-local names? For partial symbols, we should probably be
1899 complaint (&symfile_complaints
,
1900 _("unhandled containing DIE tag %d for DIE at %d"),
1901 parent
->tag
, pdi
->offset
);
1902 parent
->scope
= grandparent_scope
;
1905 parent
->scope_set
= 1;
1906 return parent
->scope
;
1909 /* Return the fully scoped name associated with PDI, from compilation unit
1910 CU. The result will be allocated with malloc. */
1912 partial_die_full_name (struct partial_die_info
*pdi
,
1913 struct dwarf2_cu
*cu
)
1917 parent_scope
= partial_die_parent_scope (pdi
, cu
);
1918 if (parent_scope
== NULL
)
1921 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
1925 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
1927 struct objfile
*objfile
= cu
->objfile
;
1929 char *actual_name
= NULL
;
1930 const char *my_prefix
;
1931 const struct partial_symbol
*psym
= NULL
;
1933 int built_actual_name
= 0;
1935 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1937 if (pdi_needs_namespace (pdi
->tag
))
1939 actual_name
= partial_die_full_name (pdi
, cu
);
1941 built_actual_name
= 1;
1944 if (actual_name
== NULL
)
1945 actual_name
= pdi
->name
;
1949 case DW_TAG_subprogram
:
1950 if (pdi
->is_external
|| cu
->language
== language_ada
)
1952 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
1953 of the global scope. But in Ada, we want to be able to access
1954 nested procedures globally. So all Ada subprograms are stored
1955 in the global scope. */
1956 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1957 mst_text, objfile); */
1958 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1959 VAR_DOMAIN
, LOC_BLOCK
,
1960 &objfile
->global_psymbols
,
1961 0, pdi
->lowpc
+ baseaddr
,
1962 cu
->language
, objfile
);
1966 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1967 mst_file_text, objfile); */
1968 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1969 VAR_DOMAIN
, LOC_BLOCK
,
1970 &objfile
->static_psymbols
,
1971 0, pdi
->lowpc
+ baseaddr
,
1972 cu
->language
, objfile
);
1975 case DW_TAG_variable
:
1976 if (pdi
->is_external
)
1979 Don't enter into the minimal symbol tables as there is
1980 a minimal symbol table entry from the ELF symbols already.
1981 Enter into partial symbol table if it has a location
1982 descriptor or a type.
1983 If the location descriptor is missing, new_symbol will create
1984 a LOC_UNRESOLVED symbol, the address of the variable will then
1985 be determined from the minimal symbol table whenever the variable
1987 The address for the partial symbol table entry is not
1988 used by GDB, but it comes in handy for debugging partial symbol
1992 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1993 if (pdi
->locdesc
|| pdi
->has_type
)
1994 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1995 VAR_DOMAIN
, LOC_STATIC
,
1996 &objfile
->global_psymbols
,
1998 cu
->language
, objfile
);
2002 /* Static Variable. Skip symbols without location descriptors. */
2003 if (pdi
->locdesc
== NULL
)
2005 if (built_actual_name
)
2006 xfree (actual_name
);
2009 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2010 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2011 mst_file_data, objfile); */
2012 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2013 VAR_DOMAIN
, LOC_STATIC
,
2014 &objfile
->static_psymbols
,
2016 cu
->language
, objfile
);
2019 case DW_TAG_typedef
:
2020 case DW_TAG_base_type
:
2021 case DW_TAG_subrange_type
:
2022 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2023 VAR_DOMAIN
, LOC_TYPEDEF
,
2024 &objfile
->static_psymbols
,
2025 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2027 case DW_TAG_namespace
:
2028 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2029 VAR_DOMAIN
, LOC_TYPEDEF
,
2030 &objfile
->global_psymbols
,
2031 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2033 case DW_TAG_class_type
:
2034 case DW_TAG_interface_type
:
2035 case DW_TAG_structure_type
:
2036 case DW_TAG_union_type
:
2037 case DW_TAG_enumeration_type
:
2038 /* Skip external references. The DWARF standard says in the section
2039 about "Structure, Union, and Class Type Entries": "An incomplete
2040 structure, union or class type is represented by a structure,
2041 union or class entry that does not have a byte size attribute
2042 and that has a DW_AT_declaration attribute." */
2043 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2045 if (built_actual_name
)
2046 xfree (actual_name
);
2050 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2051 static vs. global. */
2052 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2053 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2054 (cu
->language
== language_cplus
2055 || cu
->language
== language_java
)
2056 ? &objfile
->global_psymbols
2057 : &objfile
->static_psymbols
,
2058 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2061 case DW_TAG_enumerator
:
2062 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2063 VAR_DOMAIN
, LOC_CONST
,
2064 (cu
->language
== language_cplus
2065 || cu
->language
== language_java
)
2066 ? &objfile
->global_psymbols
2067 : &objfile
->static_psymbols
,
2068 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2074 /* Check to see if we should scan the name for possible namespace
2075 info. Only do this if this is C++, if we don't have namespace
2076 debugging info in the file, if the psym is of an appropriate type
2077 (otherwise we'll have psym == NULL), and if we actually had a
2078 mangled name to begin with. */
2080 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2081 cases which do not set PSYM above? */
2083 if (cu
->language
== language_cplus
2084 && cu
->has_namespace_info
== 0
2086 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
2087 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
2090 if (built_actual_name
)
2091 xfree (actual_name
);
2094 /* Determine whether a die of type TAG living in a C++ class or
2095 namespace needs to have the name of the scope prepended to the
2096 name listed in the die. */
2099 pdi_needs_namespace (enum dwarf_tag tag
)
2103 case DW_TAG_namespace
:
2104 case DW_TAG_typedef
:
2105 case DW_TAG_class_type
:
2106 case DW_TAG_interface_type
:
2107 case DW_TAG_structure_type
:
2108 case DW_TAG_union_type
:
2109 case DW_TAG_enumeration_type
:
2110 case DW_TAG_enumerator
:
2117 /* Read a partial die corresponding to a namespace; also, add a symbol
2118 corresponding to that namespace to the symbol table. NAMESPACE is
2119 the name of the enclosing namespace. */
2122 add_partial_namespace (struct partial_die_info
*pdi
,
2123 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2124 struct dwarf2_cu
*cu
)
2126 struct objfile
*objfile
= cu
->objfile
;
2128 /* Add a symbol for the namespace. */
2130 add_partial_symbol (pdi
, cu
);
2132 /* Now scan partial symbols in that namespace. */
2134 if (pdi
->has_children
)
2135 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, cu
);
2138 /* See if we can figure out if the class lives in a namespace. We do
2139 this by looking for a member function; its demangled name will
2140 contain namespace info, if there is any. */
2143 guess_structure_name (struct partial_die_info
*struct_pdi
,
2144 struct dwarf2_cu
*cu
)
2146 if ((cu
->language
== language_cplus
2147 || cu
->language
== language_java
)
2148 && cu
->has_namespace_info
== 0
2149 && struct_pdi
->has_children
)
2151 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2152 what template types look like, because the demangler
2153 frequently doesn't give the same name as the debug info. We
2154 could fix this by only using the demangled name to get the
2155 prefix (but see comment in read_structure_type). */
2157 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
2158 struct partial_die_info
*real_pdi
;
2160 /* If this DIE (this DIE's specification, if any) has a parent, then
2161 we should not do this. We'll prepend the parent's fully qualified
2162 name when we create the partial symbol. */
2164 real_pdi
= struct_pdi
;
2165 while (real_pdi
->has_specification
)
2166 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2168 if (real_pdi
->die_parent
!= NULL
)
2171 while (child_pdi
!= NULL
)
2173 if (child_pdi
->tag
== DW_TAG_subprogram
)
2175 char *actual_class_name
2176 = language_class_name_from_physname (cu
->language_defn
,
2178 if (actual_class_name
!= NULL
)
2181 = obsavestring (actual_class_name
,
2182 strlen (actual_class_name
),
2183 &cu
->comp_unit_obstack
);
2184 xfree (actual_class_name
);
2189 child_pdi
= child_pdi
->die_sibling
;
2194 /* Read a partial die corresponding to an enumeration type. */
2197 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2198 struct dwarf2_cu
*cu
)
2200 struct objfile
*objfile
= cu
->objfile
;
2201 bfd
*abfd
= objfile
->obfd
;
2202 struct partial_die_info
*pdi
;
2204 if (enum_pdi
->name
!= NULL
)
2205 add_partial_symbol (enum_pdi
, cu
);
2207 pdi
= enum_pdi
->die_child
;
2210 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2211 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2213 add_partial_symbol (pdi
, cu
);
2214 pdi
= pdi
->die_sibling
;
2218 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2219 Return the corresponding abbrev, or NULL if the number is zero (indicating
2220 an empty DIE). In either case *BYTES_READ will be set to the length of
2221 the initial number. */
2223 static struct abbrev_info
*
2224 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2225 struct dwarf2_cu
*cu
)
2227 bfd
*abfd
= cu
->objfile
->obfd
;
2228 unsigned int abbrev_number
;
2229 struct abbrev_info
*abbrev
;
2231 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2233 if (abbrev_number
== 0)
2236 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2239 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2240 bfd_get_filename (abfd
));
2246 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2247 pointer to the end of a series of DIEs, terminated by an empty
2248 DIE. Any children of the skipped DIEs will also be skipped. */
2251 skip_children (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2253 struct abbrev_info
*abbrev
;
2254 unsigned int bytes_read
;
2258 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2260 return info_ptr
+ bytes_read
;
2262 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
2266 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2267 should point just after the initial uleb128 of a DIE, and the
2268 abbrev corresponding to that skipped uleb128 should be passed in
2269 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2273 skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
2274 struct dwarf2_cu
*cu
)
2276 unsigned int bytes_read
;
2277 struct attribute attr
;
2278 bfd
*abfd
= cu
->objfile
->obfd
;
2279 unsigned int form
, i
;
2281 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2283 /* The only abbrev we care about is DW_AT_sibling. */
2284 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2286 read_attribute (&attr
, &abbrev
->attrs
[i
],
2287 abfd
, info_ptr
, cu
);
2288 if (attr
.form
== DW_FORM_ref_addr
)
2289 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2291 return dwarf2_per_objfile
->info_buffer
2292 + dwarf2_get_ref_die_offset (&attr
, cu
);
2295 /* If it isn't DW_AT_sibling, skip this attribute. */
2296 form
= abbrev
->attrs
[i
].form
;
2301 case DW_FORM_ref_addr
:
2302 info_ptr
+= cu
->header
.addr_size
;
2321 case DW_FORM_string
:
2322 read_string (abfd
, info_ptr
, &bytes_read
);
2323 info_ptr
+= bytes_read
;
2326 info_ptr
+= cu
->header
.offset_size
;
2329 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2330 info_ptr
+= bytes_read
;
2332 case DW_FORM_block1
:
2333 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2335 case DW_FORM_block2
:
2336 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2338 case DW_FORM_block4
:
2339 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2343 case DW_FORM_ref_udata
:
2344 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2346 case DW_FORM_indirect
:
2347 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2348 info_ptr
+= bytes_read
;
2349 /* We need to continue parsing from here, so just go back to
2351 goto skip_attribute
;
2354 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2355 dwarf_form_name (form
),
2356 bfd_get_filename (abfd
));
2360 if (abbrev
->has_children
)
2361 return skip_children (info_ptr
, cu
);
2366 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2367 the next DIE after ORIG_PDI. */
2370 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, gdb_byte
*info_ptr
,
2371 bfd
*abfd
, struct dwarf2_cu
*cu
)
2373 /* Do we know the sibling already? */
2375 if (orig_pdi
->sibling
)
2376 return orig_pdi
->sibling
;
2378 /* Are there any children to deal with? */
2380 if (!orig_pdi
->has_children
)
2383 /* Skip the children the long way. */
2385 return skip_children (info_ptr
, cu
);
2388 /* Expand this partial symbol table into a full symbol table. */
2391 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2393 /* FIXME: This is barely more than a stub. */
2398 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2404 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2405 gdb_flush (gdb_stdout
);
2408 /* Restore our global data. */
2409 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2410 dwarf2_objfile_data_key
);
2412 psymtab_to_symtab_1 (pst
);
2414 /* Finish up the debug error message. */
2416 printf_filtered (_("done.\n"));
2421 /* Add PER_CU to the queue. */
2424 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2426 struct dwarf2_queue_item
*item
;
2429 item
= xmalloc (sizeof (*item
));
2430 item
->per_cu
= per_cu
;
2433 if (dwarf2_queue
== NULL
)
2434 dwarf2_queue
= item
;
2436 dwarf2_queue_tail
->next
= item
;
2438 dwarf2_queue_tail
= item
;
2440 /* Either PER_CU is the CU we want to process, or we're following a reference
2441 pointing into PER_CU. Either way, we need its DIEs now. */
2442 load_full_comp_unit (item
->per_cu
, objfile
);
2443 item
->per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
2444 dwarf2_per_objfile
->read_in_chain
= item
->per_cu
;
2447 /* Process the queue. */
2450 process_queue (struct objfile
*objfile
)
2452 struct dwarf2_queue_item
*item
, *next_item
;
2454 /* The queue starts out with one item, but following a DIE reference
2455 may load a new CU, adding it to the end of the queue. */
2456 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2458 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2459 process_full_comp_unit (item
->per_cu
);
2461 item
->per_cu
->queued
= 0;
2462 next_item
= item
->next
;
2466 dwarf2_queue_tail
= NULL
;
2469 /* Free all allocated queue entries. This function only releases anything if
2470 an error was thrown; if the queue was processed then it would have been
2471 freed as we went along. */
2474 dwarf2_release_queue (void *dummy
)
2476 struct dwarf2_queue_item
*item
, *last
;
2478 item
= dwarf2_queue
;
2481 /* Anything still marked queued is likely to be in an
2482 inconsistent state, so discard it. */
2483 if (item
->per_cu
->queued
)
2485 if (item
->per_cu
->cu
!= NULL
)
2486 free_one_cached_comp_unit (item
->per_cu
->cu
);
2487 item
->per_cu
->queued
= 0;
2495 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2498 /* Read in full symbols for PST, and anything it depends on. */
2501 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2503 struct dwarf2_per_cu_data
*per_cu
;
2504 struct cleanup
*back_to
;
2507 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2508 if (!pst
->dependencies
[i
]->readin
)
2510 /* Inform about additional files that need to be read in. */
2513 /* FIXME: i18n: Need to make this a single string. */
2514 fputs_filtered (" ", gdb_stdout
);
2516 fputs_filtered ("and ", gdb_stdout
);
2518 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2519 wrap_here (""); /* Flush output */
2520 gdb_flush (gdb_stdout
);
2522 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2525 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
2529 /* It's an include file, no symbols to read for it.
2530 Everything is in the parent symtab. */
2535 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2537 queue_comp_unit (per_cu
, pst
->objfile
);
2539 process_queue (pst
->objfile
);
2541 /* Age the cache, releasing compilation units that have not
2542 been used recently. */
2543 age_cached_comp_units ();
2545 do_cleanups (back_to
);
2548 /* Load the DIEs associated with PST and PER_CU into memory. */
2550 static struct dwarf2_cu
*
2551 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2553 bfd
*abfd
= objfile
->obfd
;
2554 struct dwarf2_cu
*cu
;
2555 unsigned long offset
;
2557 struct cleanup
*back_to
, *free_cu_cleanup
;
2558 struct attribute
*attr
;
2561 /* Set local variables from the partial symbol table info. */
2562 offset
= per_cu
->offset
;
2564 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2566 cu
= xmalloc (sizeof (struct dwarf2_cu
));
2567 memset (cu
, 0, sizeof (struct dwarf2_cu
));
2569 /* If an error occurs while loading, release our storage. */
2570 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
2572 cu
->objfile
= objfile
;
2574 /* read in the comp_unit header */
2575 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
2577 /* Read the abbrevs for this compilation unit */
2578 dwarf2_read_abbrevs (abfd
, cu
);
2579 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2581 cu
->header
.offset
= offset
;
2583 cu
->per_cu
= per_cu
;
2585 cu
->type_hash
= per_cu
->type_hash
;
2587 /* We use this obstack for block values in dwarf_alloc_block. */
2588 obstack_init (&cu
->comp_unit_obstack
);
2590 cu
->dies
= read_comp_unit (info_ptr
, abfd
, cu
);
2592 /* We try not to read any attributes in this function, because not
2593 all objfiles needed for references have been loaded yet, and symbol
2594 table processing isn't initialized. But we have to set the CU language,
2595 or we won't be able to build types correctly. */
2596 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
2598 set_cu_language (DW_UNSND (attr
), cu
);
2600 set_cu_language (language_minimal
, cu
);
2602 do_cleanups (back_to
);
2604 /* We've successfully allocated this compilation unit. Let our caller
2605 clean it up when finished with it. */
2606 discard_cleanups (free_cu_cleanup
);
2611 /* Generate full symbol information for PST and CU, whose DIEs have
2612 already been loaded into memory. */
2615 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2617 struct partial_symtab
*pst
= per_cu
->psymtab
;
2618 struct dwarf2_cu
*cu
= per_cu
->cu
;
2619 struct objfile
*objfile
= pst
->objfile
;
2620 bfd
*abfd
= objfile
->obfd
;
2621 CORE_ADDR lowpc
, highpc
;
2622 struct symtab
*symtab
;
2623 struct cleanup
*back_to
;
2624 struct attribute
*attr
;
2627 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2630 back_to
= make_cleanup (really_free_pendings
, NULL
);
2632 cu
->list_in_scope
= &file_symbols
;
2634 /* Find the base address of the compilation unit for range lists and
2635 location lists. It will normally be specified by DW_AT_low_pc.
2636 In DWARF-3 draft 4, the base address could be overridden by
2637 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2638 compilation units with discontinuous ranges. */
2641 cu
->base_address
= 0;
2643 attr
= dwarf2_attr (cu
->dies
, DW_AT_entry_pc
, cu
);
2646 cu
->base_address
= DW_ADDR (attr
);
2651 attr
= dwarf2_attr (cu
->dies
, DW_AT_low_pc
, cu
);
2654 cu
->base_address
= DW_ADDR (attr
);
2659 /* Do line number decoding in read_file_scope () */
2660 process_die (cu
->dies
, cu
);
2662 /* Some compilers don't define a DW_AT_high_pc attribute for the
2663 compilation unit. If the DW_AT_high_pc is missing, synthesize
2664 it, by scanning the DIE's below the compilation unit. */
2665 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
2667 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2669 /* Set symtab language to language from DW_AT_language.
2670 If the compilation is from a C file generated by language preprocessors,
2671 do not set the language if it was already deduced by start_subfile. */
2673 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
2675 symtab
->language
= cu
->language
;
2677 pst
->symtab
= symtab
;
2680 do_cleanups (back_to
);
2683 /* Process a die and its children. */
2686 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2690 case DW_TAG_padding
:
2692 case DW_TAG_compile_unit
:
2693 read_file_scope (die
, cu
);
2695 case DW_TAG_subprogram
:
2696 read_func_scope (die
, cu
);
2698 case DW_TAG_inlined_subroutine
:
2699 /* FIXME: These are ignored for now.
2700 They could be used to set breakpoints on all inlined instances
2701 of a function and make GDB `next' properly over inlined functions. */
2703 case DW_TAG_lexical_block
:
2704 case DW_TAG_try_block
:
2705 case DW_TAG_catch_block
:
2706 read_lexical_block_scope (die
, cu
);
2708 case DW_TAG_class_type
:
2709 case DW_TAG_interface_type
:
2710 case DW_TAG_structure_type
:
2711 case DW_TAG_union_type
:
2712 process_structure_scope (die
, cu
);
2714 case DW_TAG_enumeration_type
:
2715 process_enumeration_scope (die
, cu
);
2718 /* These dies have a type, but processing them does not create
2719 a symbol or recurse to process the children. Therefore we can
2720 read them on-demand through read_type_die. */
2721 case DW_TAG_subroutine_type
:
2722 case DW_TAG_set_type
:
2723 case DW_TAG_array_type
:
2724 case DW_TAG_pointer_type
:
2725 case DW_TAG_ptr_to_member_type
:
2726 case DW_TAG_reference_type
:
2727 case DW_TAG_string_type
:
2730 case DW_TAG_base_type
:
2731 case DW_TAG_subrange_type
:
2732 /* Add a typedef symbol for the type definition, if it has a
2734 new_symbol (die
, read_type_die (die
, cu
), cu
);
2736 case DW_TAG_common_block
:
2737 read_common_block (die
, cu
);
2739 case DW_TAG_common_inclusion
:
2741 case DW_TAG_namespace
:
2742 processing_has_namespace_info
= 1;
2743 read_namespace (die
, cu
);
2745 case DW_TAG_imported_declaration
:
2746 case DW_TAG_imported_module
:
2747 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2748 information contained in these. DW_TAG_imported_declaration
2749 dies shouldn't have children; DW_TAG_imported_module dies
2750 shouldn't in the C++ case, but conceivably could in the
2752 processing_has_namespace_info
= 1;
2753 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
2754 dwarf_tag_name (die
->tag
));
2757 new_symbol (die
, NULL
, cu
);
2762 /* Return the fully qualified name of DIE, based on its DW_AT_name.
2763 If scope qualifiers are appropriate they will be added. The result
2764 will be allocated on the objfile_obstack, or NULL if the DIE does
2768 dwarf2_full_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
2770 struct attribute
*attr
;
2771 char *prefix
, *name
;
2772 struct ui_file
*buf
= NULL
;
2774 name
= dwarf2_name (die
, cu
);
2778 /* These are the only languages we know how to qualify names in. */
2779 if (cu
->language
!= language_cplus
2780 && cu
->language
!= language_java
)
2783 /* If no prefix is necessary for this type of DIE, return the
2784 unqualified name. The other three tags listed could be handled
2785 in pdi_needs_namespace, but that requires broader changes. */
2786 if (!pdi_needs_namespace (die
->tag
)
2787 && die
->tag
!= DW_TAG_subprogram
2788 && die
->tag
!= DW_TAG_variable
2789 && die
->tag
!= DW_TAG_member
)
2792 prefix
= determine_prefix (die
, cu
);
2793 if (*prefix
!= '\0')
2794 name
= typename_concat (&cu
->objfile
->objfile_obstack
, prefix
,
2801 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2803 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2807 free_cu_line_header (void *arg
)
2809 struct dwarf2_cu
*cu
= arg
;
2811 free_line_header (cu
->line_header
);
2812 cu
->line_header
= NULL
;
2816 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2818 struct objfile
*objfile
= cu
->objfile
;
2819 struct comp_unit_head
*cu_header
= &cu
->header
;
2820 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2821 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2822 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2823 struct attribute
*attr
;
2825 char *comp_dir
= NULL
;
2826 struct die_info
*child_die
;
2827 bfd
*abfd
= objfile
->obfd
;
2828 struct line_header
*line_header
= 0;
2831 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2833 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2835 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2836 from finish_block. */
2837 if (lowpc
== ((CORE_ADDR
) -1))
2842 /* Find the filename. Do not use dwarf2_name here, since the filename
2843 is not a source language identifier. */
2844 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2847 name
= DW_STRING (attr
);
2850 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2852 comp_dir
= DW_STRING (attr
);
2853 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
2855 comp_dir
= ldirname (name
);
2856 if (comp_dir
!= NULL
)
2857 make_cleanup (xfree
, comp_dir
);
2859 if (comp_dir
!= NULL
)
2861 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2862 directory, get rid of it. */
2863 char *cp
= strchr (comp_dir
, ':');
2865 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2872 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2875 set_cu_language (DW_UNSND (attr
), cu
);
2878 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
2880 cu
->producer
= DW_STRING (attr
);
2882 /* We assume that we're processing GCC output. */
2883 processing_gcc_compilation
= 2;
2885 processing_has_namespace_info
= 0;
2887 start_symtab (name
, comp_dir
, lowpc
);
2888 record_debugformat ("DWARF 2");
2889 record_producer (cu
->producer
);
2891 initialize_cu_func_list (cu
);
2893 /* Decode line number information if present. We do this before
2894 processing child DIEs, so that the line header table is available
2895 for DW_AT_decl_file. */
2896 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2899 unsigned int line_offset
= DW_UNSND (attr
);
2900 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2903 cu
->line_header
= line_header
;
2904 make_cleanup (free_cu_line_header
, cu
);
2905 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
2909 /* Process all dies in compilation unit. */
2910 if (die
->child
!= NULL
)
2912 child_die
= die
->child
;
2913 while (child_die
&& child_die
->tag
)
2915 process_die (child_die
, cu
);
2916 child_die
= sibling_die (child_die
);
2920 /* Decode macro information, if present. Dwarf 2 macro information
2921 refers to information in the line number info statement program
2922 header, so we can only read it if we've read the header
2924 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2925 if (attr
&& line_header
)
2927 unsigned int macro_offset
= DW_UNSND (attr
);
2928 dwarf_decode_macros (line_header
, macro_offset
,
2929 comp_dir
, abfd
, cu
);
2931 do_cleanups (back_to
);
2935 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2936 struct dwarf2_cu
*cu
)
2938 struct function_range
*thisfn
;
2940 thisfn
= (struct function_range
*)
2941 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
2942 thisfn
->name
= name
;
2943 thisfn
->lowpc
= lowpc
;
2944 thisfn
->highpc
= highpc
;
2945 thisfn
->seen_line
= 0;
2946 thisfn
->next
= NULL
;
2948 if (cu
->last_fn
== NULL
)
2949 cu
->first_fn
= thisfn
;
2951 cu
->last_fn
->next
= thisfn
;
2953 cu
->last_fn
= thisfn
;
2957 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2959 struct objfile
*objfile
= cu
->objfile
;
2960 struct context_stack
*new;
2963 struct die_info
*child_die
;
2964 struct attribute
*attr
;
2967 struct block
*block
;
2969 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2971 name
= dwarf2_linkage_name (die
, cu
);
2973 /* Ignore functions with missing or empty names and functions with
2974 missing or invalid low and high pc attributes. */
2975 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2981 /* Record the function range for dwarf_decode_lines. */
2982 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
2984 new = push_context (0, lowpc
);
2985 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
2987 /* If there is a location expression for DW_AT_frame_base, record
2989 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
2991 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
2992 expression is being recorded directly in the function's symbol
2993 and not in a separate frame-base object. I guess this hack is
2994 to avoid adding some sort of frame-base adjunct/annex to the
2995 function's symbol :-(. The problem with doing this is that it
2996 results in a function symbol with a location expression that
2997 has nothing to do with the location of the function, ouch! The
2998 relationship should be: a function's symbol has-a frame base; a
2999 frame-base has-a location expression. */
3000 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3002 cu
->list_in_scope
= &local_symbols
;
3004 if (die
->child
!= NULL
)
3006 child_die
= die
->child
;
3007 while (child_die
&& child_die
->tag
)
3009 process_die (child_die
, cu
);
3010 child_die
= sibling_die (child_die
);
3014 new = pop_context ();
3015 /* Make a block for the local symbols within. */
3016 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3017 lowpc
, highpc
, objfile
);
3019 /* For C++, set the block's scope. */
3020 if (cu
->language
== language_cplus
)
3021 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
3022 determine_prefix (die
, cu
),
3023 processing_has_namespace_info
);
3025 /* If we have address ranges, record them. */
3026 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3028 /* In C++, we can have functions nested inside functions (e.g., when
3029 a function declares a class that has methods). This means that
3030 when we finish processing a function scope, we may need to go
3031 back to building a containing block's symbol lists. */
3032 local_symbols
= new->locals
;
3033 param_symbols
= new->params
;
3035 /* If we've finished processing a top-level function, subsequent
3036 symbols go in the file symbol list. */
3037 if (outermost_context_p ())
3038 cu
->list_in_scope
= &file_symbols
;
3041 /* Process all the DIES contained within a lexical block scope. Start
3042 a new scope, process the dies, and then close the scope. */
3045 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3047 struct objfile
*objfile
= cu
->objfile
;
3048 struct context_stack
*new;
3049 CORE_ADDR lowpc
, highpc
;
3050 struct die_info
*child_die
;
3053 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3055 /* Ignore blocks with missing or invalid low and high pc attributes. */
3056 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3057 as multiple lexical blocks? Handling children in a sane way would
3058 be nasty. Might be easier to properly extend generic blocks to
3060 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3065 push_context (0, lowpc
);
3066 if (die
->child
!= NULL
)
3068 child_die
= die
->child
;
3069 while (child_die
&& child_die
->tag
)
3071 process_die (child_die
, cu
);
3072 child_die
= sibling_die (child_die
);
3075 new = pop_context ();
3077 if (local_symbols
!= NULL
)
3080 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3083 /* Note that recording ranges after traversing children, as we
3084 do here, means that recording a parent's ranges entails
3085 walking across all its children's ranges as they appear in
3086 the address map, which is quadratic behavior.
3088 It would be nicer to record the parent's ranges before
3089 traversing its children, simply overriding whatever you find
3090 there. But since we don't even decide whether to create a
3091 block until after we've traversed its children, that's hard
3093 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3095 local_symbols
= new->locals
;
3098 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3099 Return 1 if the attributes are present and valid, otherwise, return 0.
3100 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3103 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
3104 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
3105 struct partial_symtab
*ranges_pst
)
3107 struct objfile
*objfile
= cu
->objfile
;
3108 struct comp_unit_head
*cu_header
= &cu
->header
;
3109 bfd
*obfd
= objfile
->obfd
;
3110 unsigned int addr_size
= cu_header
->addr_size
;
3111 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3112 /* Base address selection entry. */
3123 found_base
= cu
->base_known
;
3124 base
= cu
->base_address
;
3126 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3128 complaint (&symfile_complaints
,
3129 _("Offset %d out of bounds for DW_AT_ranges attribute"),
3133 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3135 /* Read in the largest possible address. */
3136 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
3137 if ((marker
& mask
) == mask
)
3139 /* If we found the largest possible address, then
3140 read the base address. */
3141 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3142 buffer
+= 2 * addr_size
;
3143 offset
+= 2 * addr_size
;
3149 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3153 CORE_ADDR range_beginning
, range_end
;
3155 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
3156 buffer
+= addr_size
;
3157 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
3158 buffer
+= addr_size
;
3159 offset
+= 2 * addr_size
;
3161 /* An end of list marker is a pair of zero addresses. */
3162 if (range_beginning
== 0 && range_end
== 0)
3163 /* Found the end of list entry. */
3166 /* Each base address selection entry is a pair of 2 values.
3167 The first is the largest possible address, the second is
3168 the base address. Check for a base address here. */
3169 if ((range_beginning
& mask
) == mask
)
3171 /* If we found the largest possible address, then
3172 read the base address. */
3173 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3180 /* We have no valid base address for the ranges
3182 complaint (&symfile_complaints
,
3183 _("Invalid .debug_ranges data (no base address)"));
3187 range_beginning
+= base
;
3190 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
3191 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3192 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
3195 /* FIXME: This is recording everything as a low-high
3196 segment of consecutive addresses. We should have a
3197 data structure for discontiguous block ranges
3201 low
= range_beginning
;
3207 if (range_beginning
< low
)
3208 low
= range_beginning
;
3209 if (range_end
> high
)
3215 /* If the first entry is an end-of-list marker, the range
3216 describes an empty scope, i.e. no instructions. */
3222 *high_return
= high
;
3226 /* Get low and high pc attributes from a die. Return 1 if the attributes
3227 are present and valid, otherwise, return 0. Return -1 if the range is
3228 discontinuous, i.e. derived from DW_AT_ranges information. */
3230 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
3231 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
3233 struct attribute
*attr
;
3238 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3241 high
= DW_ADDR (attr
);
3242 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3244 low
= DW_ADDR (attr
);
3246 /* Found high w/o low attribute. */
3249 /* Found consecutive range of addresses. */
3254 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3257 /* Value of the DW_AT_ranges attribute is the offset in the
3258 .debug_ranges section. */
3259 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, NULL
))
3261 /* Found discontinuous range of addresses. */
3269 /* When using the GNU linker, .gnu.linkonce. sections are used to
3270 eliminate duplicate copies of functions and vtables and such.
3271 The linker will arbitrarily choose one and discard the others.
3272 The AT_*_pc values for such functions refer to local labels in
3273 these sections. If the section from that file was discarded, the
3274 labels are not in the output, so the relocs get a value of 0.
3275 If this is a discarded function, mark the pc bounds as invalid,
3276 so that GDB will ignore it. */
3277 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3285 /* Get the low and high pc's represented by the scope DIE, and store
3286 them in *LOWPC and *HIGHPC. If the correct values can't be
3287 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3290 get_scope_pc_bounds (struct die_info
*die
,
3291 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3292 struct dwarf2_cu
*cu
)
3294 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3295 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3296 CORE_ADDR current_low
, current_high
;
3298 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3300 best_low
= current_low
;
3301 best_high
= current_high
;
3305 struct die_info
*child
= die
->child
;
3307 while (child
&& child
->tag
)
3309 switch (child
->tag
) {
3310 case DW_TAG_subprogram
:
3311 if (dwarf2_get_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
))
3313 best_low
= min (best_low
, current_low
);
3314 best_high
= max (best_high
, current_high
);
3317 case DW_TAG_namespace
:
3318 /* FIXME: carlton/2004-01-16: Should we do this for
3319 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3320 that current GCC's always emit the DIEs corresponding
3321 to definitions of methods of classes as children of a
3322 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3323 the DIEs giving the declarations, which could be
3324 anywhere). But I don't see any reason why the
3325 standards says that they have to be there. */
3326 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3328 if (current_low
!= ((CORE_ADDR
) -1))
3330 best_low
= min (best_low
, current_low
);
3331 best_high
= max (best_high
, current_high
);
3339 child
= sibling_die (child
);
3344 *highpc
= best_high
;
3347 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
3350 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
3351 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
3353 struct attribute
*attr
;
3355 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3358 CORE_ADDR high
= DW_ADDR (attr
);
3359 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3362 CORE_ADDR low
= DW_ADDR (attr
);
3363 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
3367 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3370 bfd
*obfd
= cu
->objfile
->obfd
;
3372 /* The value of the DW_AT_ranges attribute is the offset of the
3373 address range list in the .debug_ranges section. */
3374 unsigned long offset
= DW_UNSND (attr
);
3375 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3377 /* For some target architectures, but not others, the
3378 read_address function sign-extends the addresses it returns.
3379 To recognize base address selection entries, we need a
3381 unsigned int addr_size
= cu
->header
.addr_size
;
3382 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3384 /* The base address, to which the next pair is relative. Note
3385 that this 'base' is a DWARF concept: most entries in a range
3386 list are relative, to reduce the number of relocs against the
3387 debugging information. This is separate from this function's
3388 'baseaddr' argument, which GDB uses to relocate debugging
3389 information from a shared library based on the address at
3390 which the library was loaded. */
3391 CORE_ADDR base
= cu
->base_address
;
3392 int base_known
= cu
->base_known
;
3394 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3396 complaint (&symfile_complaints
,
3397 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
3404 unsigned int bytes_read
;
3405 CORE_ADDR start
, end
;
3407 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3408 buffer
+= bytes_read
;
3409 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3410 buffer
+= bytes_read
;
3412 /* Did we find the end of the range list? */
3413 if (start
== 0 && end
== 0)
3416 /* Did we find a base address selection entry? */
3417 else if ((start
& base_select_mask
) == base_select_mask
)
3423 /* We found an ordinary address range. */
3428 complaint (&symfile_complaints
,
3429 _("Invalid .debug_ranges data (no base address)"));
3433 record_block_range (block
,
3434 baseaddr
+ base
+ start
,
3435 baseaddr
+ base
+ end
- 1);
3441 /* Add an aggregate field to the field list. */
3444 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3445 struct dwarf2_cu
*cu
)
3447 struct objfile
*objfile
= cu
->objfile
;
3448 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3449 struct nextfield
*new_field
;
3450 struct attribute
*attr
;
3452 char *fieldname
= "";
3454 /* Allocate a new field list entry and link it in. */
3455 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3456 make_cleanup (xfree
, new_field
);
3457 memset (new_field
, 0, sizeof (struct nextfield
));
3458 new_field
->next
= fip
->fields
;
3459 fip
->fields
= new_field
;
3462 /* Handle accessibility and virtuality of field.
3463 The default accessibility for members is public, the default
3464 accessibility for inheritance is private. */
3465 if (die
->tag
!= DW_TAG_inheritance
)
3466 new_field
->accessibility
= DW_ACCESS_public
;
3468 new_field
->accessibility
= DW_ACCESS_private
;
3469 new_field
->virtuality
= DW_VIRTUALITY_none
;
3471 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3473 new_field
->accessibility
= DW_UNSND (attr
);
3474 if (new_field
->accessibility
!= DW_ACCESS_public
)
3475 fip
->non_public_fields
= 1;
3476 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3478 new_field
->virtuality
= DW_UNSND (attr
);
3480 fp
= &new_field
->field
;
3482 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3484 /* Data member other than a C++ static data member. */
3486 /* Get type of field. */
3487 fp
->type
= die_type (die
, cu
);
3489 FIELD_STATIC_KIND (*fp
) = 0;
3491 /* Get bit size of field (zero if none). */
3492 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3495 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3499 FIELD_BITSIZE (*fp
) = 0;
3502 /* Get bit offset of field. */
3503 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3508 if (attr_form_is_section_offset (attr
))
3510 dwarf2_complex_location_expr_complaint ();
3513 else if (attr_form_is_constant (attr
))
3514 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
3516 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
3518 FIELD_BITPOS (*fp
) = byte_offset
* bits_per_byte
;
3521 FIELD_BITPOS (*fp
) = 0;
3522 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3525 if (gdbarch_bits_big_endian (gdbarch
))
3527 /* For big endian bits, the DW_AT_bit_offset gives the
3528 additional bit offset from the MSB of the containing
3529 anonymous object to the MSB of the field. We don't
3530 have to do anything special since we don't need to
3531 know the size of the anonymous object. */
3532 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3536 /* For little endian bits, compute the bit offset to the
3537 MSB of the anonymous object, subtract off the number of
3538 bits from the MSB of the field to the MSB of the
3539 object, and then subtract off the number of bits of
3540 the field itself. The result is the bit offset of
3541 the LSB of the field. */
3543 int bit_offset
= DW_UNSND (attr
);
3545 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3548 /* The size of the anonymous object containing
3549 the bit field is explicit, so use the
3550 indicated size (in bytes). */
3551 anonymous_size
= DW_UNSND (attr
);
3555 /* The size of the anonymous object containing
3556 the bit field must be inferred from the type
3557 attribute of the data member containing the
3559 anonymous_size
= TYPE_LENGTH (fp
->type
);
3561 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
3562 - bit_offset
- FIELD_BITSIZE (*fp
);
3566 /* Get name of field. */
3567 fieldname
= dwarf2_name (die
, cu
);
3568 if (fieldname
== NULL
)
3571 /* The name is already allocated along with this objfile, so we don't
3572 need to duplicate it for the type. */
3573 fp
->name
= fieldname
;
3575 /* Change accessibility for artificial fields (e.g. virtual table
3576 pointer or virtual base class pointer) to private. */
3577 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
3579 new_field
->accessibility
= DW_ACCESS_private
;
3580 fip
->non_public_fields
= 1;
3583 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
3585 /* C++ static member. */
3587 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3588 is a declaration, but all versions of G++ as of this writing
3589 (so through at least 3.2.1) incorrectly generate
3590 DW_TAG_variable tags. */
3594 /* Get name of field. */
3595 fieldname
= dwarf2_name (die
, cu
);
3596 if (fieldname
== NULL
)
3599 /* Get physical name. */
3600 physname
= dwarf2_linkage_name (die
, cu
);
3602 /* The name is already allocated along with this objfile, so we don't
3603 need to duplicate it for the type. */
3604 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
3605 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3606 FIELD_NAME (*fp
) = fieldname
;
3608 else if (die
->tag
== DW_TAG_inheritance
)
3610 /* C++ base class field. */
3611 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3613 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
3615 FIELD_BITSIZE (*fp
) = 0;
3616 FIELD_STATIC_KIND (*fp
) = 0;
3617 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3618 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
3619 fip
->nbaseclasses
++;
3623 /* Create the vector of fields, and attach it to the type. */
3626 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3627 struct dwarf2_cu
*cu
)
3629 int nfields
= fip
->nfields
;
3631 /* Record the field count, allocate space for the array of fields,
3632 and create blank accessibility bitfields if necessary. */
3633 TYPE_NFIELDS (type
) = nfields
;
3634 TYPE_FIELDS (type
) = (struct field
*)
3635 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3636 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3638 if (fip
->non_public_fields
)
3640 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3642 TYPE_FIELD_PRIVATE_BITS (type
) =
3643 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3644 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3646 TYPE_FIELD_PROTECTED_BITS (type
) =
3647 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3648 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3650 TYPE_FIELD_IGNORE_BITS (type
) =
3651 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3652 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3655 /* If the type has baseclasses, allocate and clear a bit vector for
3656 TYPE_FIELD_VIRTUAL_BITS. */
3657 if (fip
->nbaseclasses
)
3659 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3660 unsigned char *pointer
;
3662 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3663 pointer
= TYPE_ALLOC (type
, num_bytes
);
3664 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
3665 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3666 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3669 /* Copy the saved-up fields into the field vector. Start from the head
3670 of the list, adding to the tail of the field array, so that they end
3671 up in the same order in the array in which they were added to the list. */
3672 while (nfields
-- > 0)
3674 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3675 switch (fip
->fields
->accessibility
)
3677 case DW_ACCESS_private
:
3678 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3681 case DW_ACCESS_protected
:
3682 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3685 case DW_ACCESS_public
:
3689 /* Unknown accessibility. Complain and treat it as public. */
3691 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
3692 fip
->fields
->accessibility
);
3696 if (nfields
< fip
->nbaseclasses
)
3698 switch (fip
->fields
->virtuality
)
3700 case DW_VIRTUALITY_virtual
:
3701 case DW_VIRTUALITY_pure_virtual
:
3702 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3706 fip
->fields
= fip
->fields
->next
;
3710 /* Add a member function to the proper fieldlist. */
3713 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3714 struct type
*type
, struct dwarf2_cu
*cu
)
3716 struct objfile
*objfile
= cu
->objfile
;
3717 struct attribute
*attr
;
3718 struct fnfieldlist
*flp
;
3720 struct fn_field
*fnp
;
3723 struct nextfnfield
*new_fnfield
;
3724 struct type
*this_type
;
3726 /* Get name of member function. */
3727 fieldname
= dwarf2_name (die
, cu
);
3728 if (fieldname
== NULL
)
3731 /* Get the mangled name. */
3732 physname
= dwarf2_linkage_name (die
, cu
);
3734 /* Look up member function name in fieldlist. */
3735 for (i
= 0; i
< fip
->nfnfields
; i
++)
3737 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3741 /* Create new list element if necessary. */
3742 if (i
< fip
->nfnfields
)
3743 flp
= &fip
->fnfieldlists
[i
];
3746 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3748 fip
->fnfieldlists
= (struct fnfieldlist
*)
3749 xrealloc (fip
->fnfieldlists
,
3750 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3751 * sizeof (struct fnfieldlist
));
3752 if (fip
->nfnfields
== 0)
3753 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3755 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3756 flp
->name
= fieldname
;
3762 /* Create a new member function field and chain it to the field list
3764 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3765 make_cleanup (xfree
, new_fnfield
);
3766 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3767 new_fnfield
->next
= flp
->head
;
3768 flp
->head
= new_fnfield
;
3771 /* Fill in the member function field info. */
3772 fnp
= &new_fnfield
->fnfield
;
3773 /* The name is already allocated along with this objfile, so we don't
3774 need to duplicate it for the type. */
3775 fnp
->physname
= physname
? physname
: "";
3776 fnp
->type
= alloc_type (objfile
);
3777 this_type
= read_type_die (die
, cu
);
3778 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
3780 int nparams
= TYPE_NFIELDS (this_type
);
3782 /* TYPE is the domain of this method, and THIS_TYPE is the type
3783 of the method itself (TYPE_CODE_METHOD). */
3784 smash_to_method_type (fnp
->type
, type
,
3785 TYPE_TARGET_TYPE (this_type
),
3786 TYPE_FIELDS (this_type
),
3787 TYPE_NFIELDS (this_type
),
3788 TYPE_VARARGS (this_type
));
3790 /* Handle static member functions.
3791 Dwarf2 has no clean way to discern C++ static and non-static
3792 member functions. G++ helps GDB by marking the first
3793 parameter for non-static member functions (which is the
3794 this pointer) as artificial. We obtain this information
3795 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3796 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
3797 fnp
->voffset
= VOFFSET_STATIC
;
3800 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
3803 /* Get fcontext from DW_AT_containing_type if present. */
3804 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3805 fnp
->fcontext
= die_containing_type (die
, cu
);
3807 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3808 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3810 /* Get accessibility. */
3811 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3814 switch (DW_UNSND (attr
))
3816 case DW_ACCESS_private
:
3817 fnp
->is_private
= 1;
3819 case DW_ACCESS_protected
:
3820 fnp
->is_protected
= 1;
3825 /* Check for artificial methods. */
3826 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3827 if (attr
&& DW_UNSND (attr
) != 0)
3828 fnp
->is_artificial
= 1;
3830 /* Get index in virtual function table if it is a virtual member function. */
3831 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3834 /* Support the .debug_loc offsets */
3835 if (attr_form_is_block (attr
))
3837 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3839 else if (attr_form_is_section_offset (attr
))
3841 dwarf2_complex_location_expr_complaint ();
3845 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3851 /* Create the vector of member function fields, and attach it to the type. */
3854 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3855 struct dwarf2_cu
*cu
)
3857 struct fnfieldlist
*flp
;
3858 int total_length
= 0;
3861 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3862 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3863 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3865 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3867 struct nextfnfield
*nfp
= flp
->head
;
3868 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3871 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3872 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3873 fn_flp
->fn_fields
= (struct fn_field
*)
3874 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3875 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3876 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3878 total_length
+= flp
->length
;
3881 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3882 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3885 /* Returns non-zero if NAME is the name of a vtable member in CU's
3886 language, zero otherwise. */
3888 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
3890 static const char vptr
[] = "_vptr";
3891 static const char vtable
[] = "vtable";
3893 /* Look for the C++ and Java forms of the vtable. */
3894 if ((cu
->language
== language_java
3895 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
3896 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
3897 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
3903 /* GCC outputs unnamed structures that are really pointers to member
3904 functions, with the ABI-specified layout. If DIE (from CU) describes
3905 such a structure, set its type, and return nonzero. Otherwise return
3908 GCC shouldn't do this; it should just output pointer to member DIEs.
3909 This is GCC PR debug/28767. */
3911 static struct type
*
3912 quirk_gcc_member_function_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
)
3914 struct objfile
*objfile
= cu
->objfile
;
3916 struct die_info
*pfn_die
, *delta_die
;
3917 struct attribute
*pfn_name
, *delta_name
;
3918 struct type
*pfn_type
, *domain_type
;
3920 /* Check for a structure with no name and two children. */
3921 if (die
->tag
!= DW_TAG_structure_type
3922 || dwarf2_attr (die
, DW_AT_name
, cu
) != NULL
3923 || die
->child
== NULL
3924 || die
->child
->sibling
== NULL
3925 || (die
->child
->sibling
->sibling
!= NULL
3926 && die
->child
->sibling
->sibling
->tag
!= DW_TAG_padding
))
3929 /* Check for __pfn and __delta members. */
3930 pfn_die
= die
->child
;
3931 pfn_name
= dwarf2_attr (pfn_die
, DW_AT_name
, cu
);
3932 if (pfn_die
->tag
!= DW_TAG_member
3934 || DW_STRING (pfn_name
) == NULL
3935 || strcmp ("__pfn", DW_STRING (pfn_name
)) != 0)
3938 delta_die
= pfn_die
->sibling
;
3939 delta_name
= dwarf2_attr (delta_die
, DW_AT_name
, cu
);
3940 if (delta_die
->tag
!= DW_TAG_member
3941 || delta_name
== NULL
3942 || DW_STRING (delta_name
) == NULL
3943 || strcmp ("__delta", DW_STRING (delta_name
)) != 0)
3946 /* Find the type of the method. */
3947 pfn_type
= die_type (pfn_die
, cu
);
3948 if (pfn_type
== NULL
3949 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
3950 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
3953 /* Look for the "this" argument. */
3954 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
3955 if (TYPE_NFIELDS (pfn_type
) == 0
3956 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
3959 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
3960 type
= alloc_type (objfile
);
3961 smash_to_method_type (type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
3962 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
3963 TYPE_VARARGS (pfn_type
));
3964 type
= lookup_methodptr_type (type
);
3965 return set_die_type (die
, type
, cu
);
3968 /* Called when we find the DIE that starts a structure or union scope
3969 (definition) to process all dies that define the members of the
3972 NOTE: we need to call struct_type regardless of whether or not the
3973 DIE has an at_name attribute, since it might be an anonymous
3974 structure or union. This gets the type entered into our set of
3977 However, if the structure is incomplete (an opaque struct/union)
3978 then suppress creating a symbol table entry for it since gdb only
3979 wants to find the one with the complete definition. Note that if
3980 it is complete, we just call new_symbol, which does it's own
3981 checking about whether the struct/union is anonymous or not (and
3982 suppresses creating a symbol table entry itself). */
3984 static struct type
*
3985 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3987 struct objfile
*objfile
= cu
->objfile
;
3989 struct attribute
*attr
;
3991 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3993 type
= quirk_gcc_member_function_pointer (die
, cu
);
3997 type
= alloc_type (objfile
);
3998 INIT_CPLUS_SPECIFIC (type
);
3999 name
= dwarf2_name (die
, cu
);
4002 if (cu
->language
== language_cplus
4003 || cu
->language
== language_java
)
4005 const char *new_prefix
= determine_class_name (die
, cu
);
4006 TYPE_TAG_NAME (type
) = (char *) new_prefix
;
4010 /* The name is already allocated along with this objfile, so
4011 we don't need to duplicate it for the type. */
4012 TYPE_TAG_NAME (type
) = name
;
4016 if (die
->tag
== DW_TAG_structure_type
)
4018 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
4020 else if (die
->tag
== DW_TAG_union_type
)
4022 TYPE_CODE (type
) = TYPE_CODE_UNION
;
4026 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
4028 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
4031 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4034 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4038 TYPE_LENGTH (type
) = 0;
4041 TYPE_STUB_SUPPORTED (type
) = 1;
4042 if (die_is_declaration (die
, cu
))
4043 TYPE_STUB (type
) = 1;
4045 /* We need to add the type field to the die immediately so we don't
4046 infinitely recurse when dealing with pointers to the structure
4047 type within the structure itself. */
4048 set_die_type (die
, type
, cu
);
4050 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
4052 struct field_info fi
;
4053 struct die_info
*child_die
;
4055 memset (&fi
, 0, sizeof (struct field_info
));
4057 child_die
= die
->child
;
4059 while (child_die
&& child_die
->tag
)
4061 if (child_die
->tag
== DW_TAG_member
4062 || child_die
->tag
== DW_TAG_variable
)
4064 /* NOTE: carlton/2002-11-05: A C++ static data member
4065 should be a DW_TAG_member that is a declaration, but
4066 all versions of G++ as of this writing (so through at
4067 least 3.2.1) incorrectly generate DW_TAG_variable
4068 tags for them instead. */
4069 dwarf2_add_field (&fi
, child_die
, cu
);
4071 else if (child_die
->tag
== DW_TAG_subprogram
)
4073 /* C++ member function. */
4074 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
4076 else if (child_die
->tag
== DW_TAG_inheritance
)
4078 /* C++ base class field. */
4079 dwarf2_add_field (&fi
, child_die
, cu
);
4081 child_die
= sibling_die (child_die
);
4084 /* Attach fields and member functions to the type. */
4086 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
4089 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
4091 /* Get the type which refers to the base class (possibly this
4092 class itself) which contains the vtable pointer for the current
4093 class from the DW_AT_containing_type attribute. */
4095 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4097 struct type
*t
= die_containing_type (die
, cu
);
4099 TYPE_VPTR_BASETYPE (type
) = t
;
4104 /* Our own class provides vtbl ptr. */
4105 for (i
= TYPE_NFIELDS (t
) - 1;
4106 i
>= TYPE_N_BASECLASSES (t
);
4109 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
4111 if (is_vtable_name (fieldname
, cu
))
4113 TYPE_VPTR_FIELDNO (type
) = i
;
4118 /* Complain if virtual function table field not found. */
4119 if (i
< TYPE_N_BASECLASSES (t
))
4120 complaint (&symfile_complaints
,
4121 _("virtual function table pointer not found when defining class '%s'"),
4122 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
4127 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
4130 else if (cu
->producer
4131 && strncmp (cu
->producer
,
4132 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
4134 /* The IBM XLC compiler does not provide direct indication
4135 of the containing type, but the vtable pointer is
4136 always named __vfp. */
4140 for (i
= TYPE_NFIELDS (type
) - 1;
4141 i
>= TYPE_N_BASECLASSES (type
);
4144 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
4146 TYPE_VPTR_FIELDNO (type
) = i
;
4147 TYPE_VPTR_BASETYPE (type
) = type
;
4155 do_cleanups (back_to
);
4160 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4162 struct objfile
*objfile
= cu
->objfile
;
4163 struct die_info
*child_die
= die
->child
;
4164 struct type
*this_type
;
4166 this_type
= get_die_type (die
, cu
);
4167 if (this_type
== NULL
)
4168 this_type
= read_structure_type (die
, cu
);
4170 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
4171 snapshots) has been known to create a die giving a declaration
4172 for a class that has, as a child, a die giving a definition for a
4173 nested class. So we have to process our children even if the
4174 current die is a declaration. Normally, of course, a declaration
4175 won't have any children at all. */
4177 while (child_die
!= NULL
&& child_die
->tag
)
4179 if (child_die
->tag
== DW_TAG_member
4180 || child_die
->tag
== DW_TAG_variable
4181 || child_die
->tag
== DW_TAG_inheritance
)
4186 process_die (child_die
, cu
);
4188 child_die
= sibling_die (child_die
);
4191 /* Do not consider external references. According to the DWARF standard,
4192 these DIEs are identified by the fact that they have no byte_size
4193 attribute, and a declaration attribute. */
4194 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
4195 || !die_is_declaration (die
, cu
))
4196 new_symbol (die
, this_type
, cu
);
4199 /* Given a DW_AT_enumeration_type die, set its type. We do not
4200 complete the type's fields yet, or create any symbols. */
4202 static struct type
*
4203 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4205 struct objfile
*objfile
= cu
->objfile
;
4207 struct attribute
*attr
;
4210 type
= alloc_type (objfile
);
4212 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4213 name
= dwarf2_full_name (die
, cu
);
4215 TYPE_TAG_NAME (type
) = (char *) name
;
4217 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4220 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4224 TYPE_LENGTH (type
) = 0;
4227 /* The enumeration DIE can be incomplete. In Ada, any type can be
4228 declared as private in the package spec, and then defined only
4229 inside the package body. Such types are known as Taft Amendment
4230 Types. When another package uses such a type, an incomplete DIE
4231 may be generated by the compiler. */
4232 if (die_is_declaration (die
, cu
))
4233 TYPE_STUB (type
) = 1;
4235 return set_die_type (die
, type
, cu
);
4238 /* Determine the name of the type represented by DIE, which should be
4239 a named C++ or Java compound type. Return the name in question,
4240 allocated on the objfile obstack. */
4243 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
4245 const char *new_prefix
= NULL
;
4247 /* If we don't have namespace debug info, guess the name by trying
4248 to demangle the names of members, just like we did in
4249 guess_structure_name. */
4250 if (!processing_has_namespace_info
)
4252 struct die_info
*child
;
4254 for (child
= die
->child
;
4255 child
!= NULL
&& child
->tag
!= 0;
4256 child
= sibling_die (child
))
4258 if (child
->tag
== DW_TAG_subprogram
)
4261 = language_class_name_from_physname (cu
->language_defn
,
4265 if (phys_prefix
!= NULL
)
4268 = obsavestring (phys_prefix
, strlen (phys_prefix
),
4269 &cu
->objfile
->objfile_obstack
);
4270 xfree (phys_prefix
);
4277 if (new_prefix
== NULL
)
4278 new_prefix
= dwarf2_full_name (die
, cu
);
4283 /* Given a pointer to a die which begins an enumeration, process all
4284 the dies that define the members of the enumeration, and create the
4285 symbol for the enumeration type.
4287 NOTE: We reverse the order of the element list. */
4290 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4292 struct objfile
*objfile
= cu
->objfile
;
4293 struct die_info
*child_die
;
4294 struct field
*fields
;
4297 int unsigned_enum
= 1;
4299 struct type
*this_type
;
4303 this_type
= get_die_type (die
, cu
);
4304 if (this_type
== NULL
)
4305 this_type
= read_enumeration_type (die
, cu
);
4306 if (die
->child
!= NULL
)
4308 child_die
= die
->child
;
4309 while (child_die
&& child_die
->tag
)
4311 if (child_die
->tag
!= DW_TAG_enumerator
)
4313 process_die (child_die
, cu
);
4317 name
= dwarf2_name (child_die
, cu
);
4320 sym
= new_symbol (child_die
, this_type
, cu
);
4321 if (SYMBOL_VALUE (sym
) < 0)
4324 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4326 fields
= (struct field
*)
4328 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
4329 * sizeof (struct field
));
4332 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
4333 FIELD_TYPE (fields
[num_fields
]) = NULL
;
4334 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
4335 FIELD_BITSIZE (fields
[num_fields
]) = 0;
4336 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
4342 child_die
= sibling_die (child_die
);
4347 TYPE_NFIELDS (this_type
) = num_fields
;
4348 TYPE_FIELDS (this_type
) = (struct field
*)
4349 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
4350 memcpy (TYPE_FIELDS (this_type
), fields
,
4351 sizeof (struct field
) * num_fields
);
4355 TYPE_UNSIGNED (this_type
) = 1;
4358 new_symbol (die
, this_type
, cu
);
4361 /* Extract all information from a DW_TAG_array_type DIE and put it in
4362 the DIE's type field. For now, this only handles one dimensional
4365 static struct type
*
4366 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4368 struct objfile
*objfile
= cu
->objfile
;
4369 struct die_info
*child_die
;
4370 struct type
*type
= NULL
;
4371 struct type
*element_type
, *range_type
, *index_type
;
4372 struct type
**range_types
= NULL
;
4373 struct attribute
*attr
;
4375 struct cleanup
*back_to
;
4378 element_type
= die_type (die
, cu
);
4380 /* Irix 6.2 native cc creates array types without children for
4381 arrays with unspecified length. */
4382 if (die
->child
== NULL
)
4384 index_type
= builtin_type_int32
;
4385 range_type
= create_range_type (NULL
, index_type
, 0, -1);
4386 type
= create_array_type (NULL
, element_type
, range_type
);
4387 return set_die_type (die
, type
, cu
);
4390 back_to
= make_cleanup (null_cleanup
, NULL
);
4391 child_die
= die
->child
;
4392 while (child_die
&& child_die
->tag
)
4394 if (child_die
->tag
== DW_TAG_subrange_type
)
4396 struct type
*child_type
= read_type_die (child_die
, cu
);
4397 if (child_type
!= NULL
)
4399 /* The range type was succesfully read. Save it for
4400 the array type creation. */
4401 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
4403 range_types
= (struct type
**)
4404 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
4405 * sizeof (struct type
*));
4407 make_cleanup (free_current_contents
, &range_types
);
4409 range_types
[ndim
++] = child_type
;
4412 child_die
= sibling_die (child_die
);
4415 /* Dwarf2 dimensions are output from left to right, create the
4416 necessary array types in backwards order. */
4418 type
= element_type
;
4420 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
4424 type
= create_array_type (NULL
, type
, range_types
[i
++]);
4429 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
4432 /* Understand Dwarf2 support for vector types (like they occur on
4433 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4434 array type. This is not part of the Dwarf2/3 standard yet, but a
4435 custom vendor extension. The main difference between a regular
4436 array and the vector variant is that vectors are passed by value
4438 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4440 make_vector_type (type
);
4442 name
= dwarf2_name (die
, cu
);
4444 TYPE_NAME (type
) = name
;
4446 do_cleanups (back_to
);
4448 /* Install the type in the die. */
4449 return set_die_type (die
, type
, cu
);
4452 static enum dwarf_array_dim_ordering
4453 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4455 struct attribute
*attr
;
4457 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4459 if (attr
) return DW_SND (attr
);
4462 GNU F77 is a special case, as at 08/2004 array type info is the
4463 opposite order to the dwarf2 specification, but data is still
4464 laid out as per normal fortran.
4466 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4470 if (cu
->language
== language_fortran
&&
4471 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4473 return DW_ORD_row_major
;
4476 switch (cu
->language_defn
->la_array_ordering
)
4478 case array_column_major
:
4479 return DW_ORD_col_major
;
4480 case array_row_major
:
4482 return DW_ORD_row_major
;
4486 /* Extract all information from a DW_TAG_set_type DIE and put it in
4487 the DIE's type field. */
4489 static struct type
*
4490 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4492 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
4494 return set_die_type (die
, set_type
, cu
);
4497 /* First cut: install each common block member as a global variable. */
4500 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4502 struct die_info
*child_die
;
4503 struct attribute
*attr
;
4505 CORE_ADDR base
= (CORE_ADDR
) 0;
4507 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4510 /* Support the .debug_loc offsets */
4511 if (attr_form_is_block (attr
))
4513 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4515 else if (attr_form_is_section_offset (attr
))
4517 dwarf2_complex_location_expr_complaint ();
4521 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4522 "common block member");
4525 if (die
->child
!= NULL
)
4527 child_die
= die
->child
;
4528 while (child_die
&& child_die
->tag
)
4530 sym
= new_symbol (child_die
, NULL
, cu
);
4531 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4534 SYMBOL_VALUE_ADDRESS (sym
) =
4535 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4536 add_symbol_to_list (sym
, &global_symbols
);
4538 child_die
= sibling_die (child_die
);
4543 /* Create a type for a C++ namespace. */
4545 static struct type
*
4546 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4548 struct objfile
*objfile
= cu
->objfile
;
4549 const char *previous_prefix
, *name
;
4553 /* For extensions, reuse the type of the original namespace. */
4554 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
4556 struct die_info
*ext_die
;
4557 struct dwarf2_cu
*ext_cu
= cu
;
4558 ext_die
= dwarf2_extension (die
, &ext_cu
);
4559 type
= read_type_die (ext_die
, ext_cu
);
4560 return set_die_type (die
, type
, cu
);
4563 name
= namespace_name (die
, &is_anonymous
, cu
);
4565 /* Now build the name of the current namespace. */
4567 previous_prefix
= determine_prefix (die
, cu
);
4568 if (previous_prefix
[0] != '\0')
4569 name
= typename_concat (&objfile
->objfile_obstack
,
4570 previous_prefix
, name
, cu
);
4572 /* Create the type. */
4573 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
4575 TYPE_NAME (type
) = (char *) name
;
4576 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4578 set_die_type (die
, type
, cu
);
4583 /* Read a C++ namespace. */
4586 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4588 struct objfile
*objfile
= cu
->objfile
;
4592 /* Add a symbol associated to this if we haven't seen the namespace
4593 before. Also, add a using directive if it's an anonymous
4596 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
4600 type
= read_type_die (die
, cu
);
4601 new_symbol (die
, type
, cu
);
4603 name
= namespace_name (die
, &is_anonymous
, cu
);
4606 const char *previous_prefix
= determine_prefix (die
, cu
);
4607 cp_add_using_directive (TYPE_NAME (type
),
4608 strlen (previous_prefix
),
4609 strlen (TYPE_NAME (type
)));
4613 if (die
->child
!= NULL
)
4615 struct die_info
*child_die
= die
->child
;
4617 while (child_die
&& child_die
->tag
)
4619 process_die (child_die
, cu
);
4620 child_die
= sibling_die (child_die
);
4625 /* Return the name of the namespace represented by DIE. Set
4626 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4630 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
4632 struct die_info
*current_die
;
4633 const char *name
= NULL
;
4635 /* Loop through the extensions until we find a name. */
4637 for (current_die
= die
;
4638 current_die
!= NULL
;
4639 current_die
= dwarf2_extension (die
, &cu
))
4641 name
= dwarf2_name (current_die
, cu
);
4646 /* Is it an anonymous namespace? */
4648 *is_anonymous
= (name
== NULL
);
4650 name
= "(anonymous namespace)";
4655 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4656 the user defined type vector. */
4658 static struct type
*
4659 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4661 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
4662 struct comp_unit_head
*cu_header
= &cu
->header
;
4664 struct attribute
*attr_byte_size
;
4665 struct attribute
*attr_address_class
;
4666 int byte_size
, addr_class
;
4668 type
= lookup_pointer_type (die_type (die
, cu
));
4670 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4672 byte_size
= DW_UNSND (attr_byte_size
);
4674 byte_size
= cu_header
->addr_size
;
4676 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
4677 if (attr_address_class
)
4678 addr_class
= DW_UNSND (attr_address_class
);
4680 addr_class
= DW_ADDR_none
;
4682 /* If the pointer size or address class is different than the
4683 default, create a type variant marked as such and set the
4684 length accordingly. */
4685 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
4687 if (gdbarch_address_class_type_flags_p (gdbarch
))
4691 type_flags
= gdbarch_address_class_type_flags
4692 (gdbarch
, byte_size
, addr_class
);
4693 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
4695 type
= make_type_with_address_space (type
, type_flags
);
4697 else if (TYPE_LENGTH (type
) != byte_size
)
4699 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
4702 /* Should we also complain about unhandled address classes? */
4706 TYPE_LENGTH (type
) = byte_size
;
4707 return set_die_type (die
, type
, cu
);
4710 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4711 the user defined type vector. */
4713 static struct type
*
4714 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4716 struct objfile
*objfile
= cu
->objfile
;
4718 struct type
*to_type
;
4719 struct type
*domain
;
4721 to_type
= die_type (die
, cu
);
4722 domain
= die_containing_type (die
, cu
);
4724 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
4725 type
= lookup_methodptr_type (to_type
);
4727 type
= lookup_memberptr_type (to_type
, domain
);
4729 return set_die_type (die
, type
, cu
);
4732 /* Extract all information from a DW_TAG_reference_type DIE and add to
4733 the user defined type vector. */
4735 static struct type
*
4736 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4738 struct comp_unit_head
*cu_header
= &cu
->header
;
4740 struct attribute
*attr
;
4742 type
= lookup_reference_type (die_type (die
, cu
));
4743 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4746 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4750 TYPE_LENGTH (type
) = cu_header
->addr_size
;
4752 return set_die_type (die
, type
, cu
);
4755 static struct type
*
4756 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4758 struct type
*base_type
, *cv_type
;
4760 base_type
= die_type (die
, cu
);
4761 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
4762 return set_die_type (die
, cv_type
, cu
);
4765 static struct type
*
4766 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4768 struct type
*base_type
, *cv_type
;
4770 base_type
= die_type (die
, cu
);
4771 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
4772 return set_die_type (die
, cv_type
, cu
);
4775 /* Extract all information from a DW_TAG_string_type DIE and add to
4776 the user defined type vector. It isn't really a user defined type,
4777 but it behaves like one, with other DIE's using an AT_user_def_type
4778 attribute to reference it. */
4780 static struct type
*
4781 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4783 struct objfile
*objfile
= cu
->objfile
;
4784 struct type
*type
, *range_type
, *index_type
, *char_type
;
4785 struct attribute
*attr
;
4786 unsigned int length
;
4788 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4791 length
= DW_UNSND (attr
);
4795 /* check for the DW_AT_byte_size attribute */
4796 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4799 length
= DW_UNSND (attr
);
4807 index_type
= builtin_type_int32
;
4808 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4809 type
= create_string_type (NULL
, range_type
);
4811 return set_die_type (die
, type
, cu
);
4814 /* Handle DIES due to C code like:
4818 int (*funcp)(int a, long l);
4822 ('funcp' generates a DW_TAG_subroutine_type DIE)
4825 static struct type
*
4826 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4828 struct type
*type
; /* Type that this function returns */
4829 struct type
*ftype
; /* Function that returns above type */
4830 struct attribute
*attr
;
4832 type
= die_type (die
, cu
);
4833 ftype
= make_function_type (type
, (struct type
**) 0);
4835 /* All functions in C++, Pascal and Java have prototypes. */
4836 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4837 if ((attr
&& (DW_UNSND (attr
) != 0))
4838 || cu
->language
== language_cplus
4839 || cu
->language
== language_java
4840 || cu
->language
== language_pascal
)
4841 TYPE_PROTOTYPED (ftype
) = 1;
4843 /* Store the calling convention in the type if it's available in
4844 the subroutine die. Otherwise set the calling convention to
4845 the default value DW_CC_normal. */
4846 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
4847 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
4849 if (die
->child
!= NULL
)
4851 struct die_info
*child_die
;
4855 /* Count the number of parameters.
4856 FIXME: GDB currently ignores vararg functions, but knows about
4857 vararg member functions. */
4858 child_die
= die
->child
;
4859 while (child_die
&& child_die
->tag
)
4861 if (child_die
->tag
== DW_TAG_formal_parameter
)
4863 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4864 TYPE_VARARGS (ftype
) = 1;
4865 child_die
= sibling_die (child_die
);
4868 /* Allocate storage for parameters and fill them in. */
4869 TYPE_NFIELDS (ftype
) = nparams
;
4870 TYPE_FIELDS (ftype
) = (struct field
*)
4871 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
4873 child_die
= die
->child
;
4874 while (child_die
&& child_die
->tag
)
4876 if (child_die
->tag
== DW_TAG_formal_parameter
)
4878 /* Dwarf2 has no clean way to discern C++ static and non-static
4879 member functions. G++ helps GDB by marking the first
4880 parameter for non-static member functions (which is the
4881 this pointer) as artificial. We pass this information
4882 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4883 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
4885 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
4887 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
4888 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
4891 child_die
= sibling_die (child_die
);
4895 return set_die_type (die
, ftype
, cu
);
4898 static struct type
*
4899 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
4901 struct objfile
*objfile
= cu
->objfile
;
4902 struct attribute
*attr
;
4903 const char *name
= NULL
;
4904 struct type
*this_type
;
4906 name
= dwarf2_full_name (die
, cu
);
4907 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
4908 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
4909 TYPE_NAME (this_type
) = (char *) name
;
4910 set_die_type (die
, this_type
, cu
);
4911 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
4915 /* Find a representation of a given base type and install
4916 it in the TYPE field of the die. */
4918 static struct type
*
4919 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4921 struct objfile
*objfile
= cu
->objfile
;
4923 struct attribute
*attr
;
4924 int encoding
= 0, size
= 0;
4926 enum type_code code
= TYPE_CODE_INT
;
4928 struct type
*target_type
= NULL
;
4930 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
4933 encoding
= DW_UNSND (attr
);
4935 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4938 size
= DW_UNSND (attr
);
4940 name
= dwarf2_name (die
, cu
);
4943 complaint (&symfile_complaints
,
4944 _("DW_AT_name missing from DW_TAG_base_type"));
4949 case DW_ATE_address
:
4950 /* Turn DW_ATE_address into a void * pointer. */
4951 code
= TYPE_CODE_PTR
;
4952 type_flags
|= TYPE_FLAG_UNSIGNED
;
4953 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
4955 case DW_ATE_boolean
:
4956 code
= TYPE_CODE_BOOL
;
4957 type_flags
|= TYPE_FLAG_UNSIGNED
;
4959 case DW_ATE_complex_float
:
4960 code
= TYPE_CODE_COMPLEX
;
4961 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
4963 case DW_ATE_decimal_float
:
4964 code
= TYPE_CODE_DECFLOAT
;
4967 code
= TYPE_CODE_FLT
;
4971 case DW_ATE_unsigned
:
4972 type_flags
|= TYPE_FLAG_UNSIGNED
;
4974 case DW_ATE_signed_char
:
4975 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
4976 code
= TYPE_CODE_CHAR
;
4978 case DW_ATE_unsigned_char
:
4979 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
4980 code
= TYPE_CODE_CHAR
;
4981 type_flags
|= TYPE_FLAG_UNSIGNED
;
4984 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
4985 dwarf_type_encoding_name (encoding
));
4989 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
4990 TYPE_NAME (type
) = name
;
4991 TYPE_TARGET_TYPE (type
) = target_type
;
4993 if (name
&& strcmp (name
, "char") == 0)
4994 TYPE_NOSIGN (type
) = 1;
4996 return set_die_type (die
, type
, cu
);
4999 /* Read the given DW_AT_subrange DIE. */
5001 static struct type
*
5002 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5004 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5005 struct type
*base_type
;
5006 struct type
*range_type
;
5007 struct attribute
*attr
;
5012 base_type
= die_type (die
, cu
);
5013 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
5015 complaint (&symfile_complaints
,
5016 _("DW_AT_type missing from DW_TAG_subrange_type"));
5018 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
5019 0, NULL
, cu
->objfile
);
5022 if (cu
->language
== language_fortran
)
5024 /* FORTRAN implies a lower bound of 1, if not given. */
5028 /* FIXME: For variable sized arrays either of these could be
5029 a variable rather than a constant value. We'll allow it,
5030 but we don't know how to handle it. */
5031 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
5033 low
= dwarf2_get_attr_constant_value (attr
, 0);
5035 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
5038 if (attr
->form
== DW_FORM_block1
)
5040 /* GCC encodes arrays with unspecified or dynamic length
5041 with a DW_FORM_block1 attribute.
5042 FIXME: GDB does not yet know how to handle dynamic
5043 arrays properly, treat them as arrays with unspecified
5046 FIXME: jimb/2003-09-22: GDB does not really know
5047 how to handle arrays of unspecified length
5048 either; we just represent them as zero-length
5049 arrays. Choose an appropriate upper bound given
5050 the lower bound we've computed above. */
5054 high
= dwarf2_get_attr_constant_value (attr
, 1);
5057 range_type
= create_range_type (NULL
, base_type
, low
, high
);
5059 name
= dwarf2_name (die
, cu
);
5061 TYPE_NAME (range_type
) = name
;
5063 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5065 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
5067 return set_die_type (die
, range_type
, cu
);
5070 static struct type
*
5071 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5075 /* For now, we only support the C meaning of an unspecified type: void. */
5077 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
5078 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
5080 return set_die_type (die
, type
, cu
);
5083 /* Trivial hash function for die_info: the hash value of a DIE
5084 is its offset in .debug_info for this objfile. */
5087 die_hash (const void *item
)
5089 const struct die_info
*die
= item
;
5093 /* Trivial comparison function for die_info structures: two DIEs
5094 are equal if they have the same offset. */
5097 die_eq (const void *item_lhs
, const void *item_rhs
)
5099 const struct die_info
*die_lhs
= item_lhs
;
5100 const struct die_info
*die_rhs
= item_rhs
;
5101 return die_lhs
->offset
== die_rhs
->offset
;
5104 /* Read a whole compilation unit into a linked list of dies. */
5106 static struct die_info
*
5107 read_comp_unit (gdb_byte
*info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
5110 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5114 &cu
->comp_unit_obstack
,
5115 hashtab_obstack_allocate
,
5116 dummy_obstack_deallocate
);
5118 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
5121 /* Read a single die and all its descendents. Set the die's sibling
5122 field to NULL; set other fields in the die correctly, and set all
5123 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
5124 location of the info_ptr after reading all of those dies. PARENT
5125 is the parent of the die in question. */
5127 static struct die_info
*
5128 read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
5129 struct dwarf2_cu
*cu
,
5130 gdb_byte
**new_info_ptr
,
5131 struct die_info
*parent
)
5133 struct die_info
*die
;
5137 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
5140 *new_info_ptr
= cur_ptr
;
5143 store_in_ref_table (die
, cu
);
5147 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
5153 *new_info_ptr
= cur_ptr
;
5156 die
->sibling
= NULL
;
5157 die
->parent
= parent
;
5161 /* Read a die, all of its descendents, and all of its siblings; set
5162 all of the fields of all of the dies correctly. Arguments are as
5163 in read_die_and_children. */
5165 static struct die_info
*
5166 read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
5167 struct dwarf2_cu
*cu
,
5168 gdb_byte
**new_info_ptr
,
5169 struct die_info
*parent
)
5171 struct die_info
*first_die
, *last_sibling
;
5175 first_die
= last_sibling
= NULL
;
5179 struct die_info
*die
5180 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
5184 *new_info_ptr
= cur_ptr
;
5191 last_sibling
->sibling
= die
;
5197 /* Decompress a section that was compressed using zlib. Store the
5198 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
5201 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
5202 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
5204 bfd
*abfd
= objfile
->obfd
;
5206 error (_("Support for zlib-compressed DWARF data (from '%s') "
5207 "is disabled in this copy of GDB"),
5208 bfd_get_filename (abfd
));
5210 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
5211 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
5212 bfd_size_type uncompressed_size
;
5213 gdb_byte
*uncompressed_buffer
;
5216 int header_size
= 12;
5218 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5219 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
5220 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5221 bfd_get_filename (abfd
));
5223 /* Read the zlib header. In this case, it should be "ZLIB" followed
5224 by the uncompressed section size, 8 bytes in big-endian order. */
5225 if (compressed_size
< header_size
5226 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
5227 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
5228 bfd_get_filename (abfd
));
5229 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
5230 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
5231 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
5232 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
5233 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
5234 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
5235 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
5236 uncompressed_size
+= compressed_buffer
[11];
5238 /* It is possible the section consists of several compressed
5239 buffers concatenated together, so we uncompress in a loop. */
5243 strm
.avail_in
= compressed_size
- header_size
;
5244 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
5245 strm
.avail_out
= uncompressed_size
;
5246 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
5248 rc
= inflateInit (&strm
);
5249 while (strm
.avail_in
> 0)
5252 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
5253 bfd_get_filename (abfd
), rc
);
5254 strm
.next_out
= ((Bytef
*) uncompressed_buffer
5255 + (uncompressed_size
- strm
.avail_out
));
5256 rc
= inflate (&strm
, Z_FINISH
);
5257 if (rc
!= Z_STREAM_END
)
5258 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
5259 bfd_get_filename (abfd
), rc
);
5260 rc
= inflateReset (&strm
);
5262 rc
= inflateEnd (&strm
);
5264 || strm
.avail_out
!= 0)
5265 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
5266 bfd_get_filename (abfd
), rc
);
5268 xfree (compressed_buffer
);
5269 *outbuf
= uncompressed_buffer
;
5270 *outsize
= uncompressed_size
;
5275 /* Read the contents of the section at OFFSET and of size SIZE from the
5276 object file specified by OBJFILE into the objfile_obstack and return it.
5277 If the section is compressed, uncompress it before returning. */
5280 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
5282 bfd
*abfd
= objfile
->obfd
;
5283 gdb_byte
*buf
, *retbuf
;
5284 bfd_size_type size
= bfd_get_section_size (sectp
);
5285 unsigned char header
[4];
5290 /* Check if the file has a 4-byte header indicating compression. */
5291 if (size
> sizeof (header
)
5292 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
5293 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
5295 /* Upon decompression, update the buffer and its size. */
5296 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
5298 zlib_decompress_section (objfile
, sectp
, &buf
, &size
);
5299 dwarf2_resize_section (sectp
, size
);
5304 /* If we get here, we are a normal, not-compressed section. */
5305 buf
= obstack_alloc (&objfile
->objfile_obstack
, size
);
5306 /* When debugging .o files, we may need to apply relocations; see
5307 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
5308 We never compress sections in .o files, so we only need to
5309 try this when the section is not compressed. */
5310 retbuf
= symfile_relocate_debug_section (abfd
, sectp
, buf
);
5314 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5315 || bfd_bread (buf
, size
, abfd
) != size
)
5316 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5317 bfd_get_filename (abfd
));
5322 /* In DWARF version 2, the description of the debugging information is
5323 stored in a separate .debug_abbrev section. Before we read any
5324 dies from a section we read in all abbreviations and install them
5325 in a hash table. This function also sets flags in CU describing
5326 the data found in the abbrev table. */
5329 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
5331 struct comp_unit_head
*cu_header
= &cu
->header
;
5332 gdb_byte
*abbrev_ptr
;
5333 struct abbrev_info
*cur_abbrev
;
5334 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
5335 unsigned int abbrev_form
, hash_number
;
5336 struct attr_abbrev
*cur_attrs
;
5337 unsigned int allocated_attrs
;
5339 /* Initialize dwarf2 abbrevs */
5340 obstack_init (&cu
->abbrev_obstack
);
5341 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
5343 * sizeof (struct abbrev_info
*)));
5344 memset (cu
->dwarf2_abbrevs
, 0,
5345 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
5347 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
5348 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5349 abbrev_ptr
+= bytes_read
;
5351 allocated_attrs
= ATTR_ALLOC_CHUNK
;
5352 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
5354 /* loop until we reach an abbrev number of 0 */
5355 while (abbrev_number
)
5357 cur_abbrev
= dwarf_alloc_abbrev (cu
);
5359 /* read in abbrev header */
5360 cur_abbrev
->number
= abbrev_number
;
5361 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5362 abbrev_ptr
+= bytes_read
;
5363 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
5366 if (cur_abbrev
->tag
== DW_TAG_namespace
)
5367 cu
->has_namespace_info
= 1;
5369 /* now read in declarations */
5370 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5371 abbrev_ptr
+= bytes_read
;
5372 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5373 abbrev_ptr
+= bytes_read
;
5376 if (cur_abbrev
->num_attrs
== allocated_attrs
)
5378 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
5380 = xrealloc (cur_attrs
, (allocated_attrs
5381 * sizeof (struct attr_abbrev
)));
5384 /* Record whether this compilation unit might have
5385 inter-compilation-unit references. If we don't know what form
5386 this attribute will have, then it might potentially be a
5387 DW_FORM_ref_addr, so we conservatively expect inter-CU
5390 if (abbrev_form
== DW_FORM_ref_addr
5391 || abbrev_form
== DW_FORM_indirect
)
5392 cu
->has_form_ref_addr
= 1;
5394 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
5395 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
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 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
5403 (cur_abbrev
->num_attrs
5404 * sizeof (struct attr_abbrev
)));
5405 memcpy (cur_abbrev
->attrs
, cur_attrs
,
5406 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
5408 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
5409 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
5410 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
5412 /* Get next abbreviation.
5413 Under Irix6 the abbreviations for a compilation unit are not
5414 always properly terminated with an abbrev number of 0.
5415 Exit loop if we encounter an abbreviation which we have
5416 already read (which means we are about to read the abbreviations
5417 for the next compile unit) or if the end of the abbreviation
5418 table is reached. */
5419 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
5420 >= dwarf2_per_objfile
->abbrev_size
)
5422 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5423 abbrev_ptr
+= bytes_read
;
5424 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
5431 /* Release the memory used by the abbrev table for a compilation unit. */
5434 dwarf2_free_abbrev_table (void *ptr_to_cu
)
5436 struct dwarf2_cu
*cu
= ptr_to_cu
;
5438 obstack_free (&cu
->abbrev_obstack
, NULL
);
5439 cu
->dwarf2_abbrevs
= NULL
;
5442 /* Lookup an abbrev_info structure in the abbrev hash table. */
5444 static struct abbrev_info
*
5445 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
5447 unsigned int hash_number
;
5448 struct abbrev_info
*abbrev
;
5450 hash_number
= number
% ABBREV_HASH_SIZE
;
5451 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
5455 if (abbrev
->number
== number
)
5458 abbrev
= abbrev
->next
;
5463 /* Returns nonzero if TAG represents a type that we might generate a partial
5467 is_type_tag_for_partial (int tag
)
5472 /* Some types that would be reasonable to generate partial symbols for,
5473 that we don't at present. */
5474 case DW_TAG_array_type
:
5475 case DW_TAG_file_type
:
5476 case DW_TAG_ptr_to_member_type
:
5477 case DW_TAG_set_type
:
5478 case DW_TAG_string_type
:
5479 case DW_TAG_subroutine_type
:
5481 case DW_TAG_base_type
:
5482 case DW_TAG_class_type
:
5483 case DW_TAG_interface_type
:
5484 case DW_TAG_enumeration_type
:
5485 case DW_TAG_structure_type
:
5486 case DW_TAG_subrange_type
:
5487 case DW_TAG_typedef
:
5488 case DW_TAG_union_type
:
5495 /* Load all DIEs that are interesting for partial symbols into memory. */
5497 static struct partial_die_info
*
5498 load_partial_dies (bfd
*abfd
, gdb_byte
*info_ptr
, int building_psymtab
,
5499 struct dwarf2_cu
*cu
)
5501 struct partial_die_info
*part_die
;
5502 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
5503 struct abbrev_info
*abbrev
;
5504 unsigned int bytes_read
;
5505 unsigned int load_all
= 0;
5507 int nesting_level
= 1;
5512 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
5516 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5520 &cu
->comp_unit_obstack
,
5521 hashtab_obstack_allocate
,
5522 dummy_obstack_deallocate
);
5524 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5525 sizeof (struct partial_die_info
));
5529 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5531 /* A NULL abbrev means the end of a series of children. */
5534 if (--nesting_level
== 0)
5536 /* PART_DIE was probably the last thing allocated on the
5537 comp_unit_obstack, so we could call obstack_free
5538 here. We don't do that because the waste is small,
5539 and will be cleaned up when we're done with this
5540 compilation unit. This way, we're also more robust
5541 against other users of the comp_unit_obstack. */
5544 info_ptr
+= bytes_read
;
5545 last_die
= parent_die
;
5546 parent_die
= parent_die
->die_parent
;
5550 /* Check whether this DIE is interesting enough to save. Normally
5551 we would not be interested in members here, but there may be
5552 later variables referencing them via DW_AT_specification (for
5555 && !is_type_tag_for_partial (abbrev
->tag
)
5556 && abbrev
->tag
!= DW_TAG_enumerator
5557 && abbrev
->tag
!= DW_TAG_subprogram
5558 && abbrev
->tag
!= DW_TAG_variable
5559 && abbrev
->tag
!= DW_TAG_namespace
5560 && abbrev
->tag
!= DW_TAG_member
)
5562 /* Otherwise we skip to the next sibling, if any. */
5563 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5567 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5568 abfd
, info_ptr
, cu
);
5570 /* This two-pass algorithm for processing partial symbols has a
5571 high cost in cache pressure. Thus, handle some simple cases
5572 here which cover the majority of C partial symbols. DIEs
5573 which neither have specification tags in them, nor could have
5574 specification tags elsewhere pointing at them, can simply be
5575 processed and discarded.
5577 This segment is also optional; scan_partial_symbols and
5578 add_partial_symbol will handle these DIEs if we chain
5579 them in normally. When compilers which do not emit large
5580 quantities of duplicate debug information are more common,
5581 this code can probably be removed. */
5583 /* Any complete simple types at the top level (pretty much all
5584 of them, for a language without namespaces), can be processed
5586 if (parent_die
== NULL
5587 && part_die
->has_specification
== 0
5588 && part_die
->is_declaration
== 0
5589 && (part_die
->tag
== DW_TAG_typedef
5590 || part_die
->tag
== DW_TAG_base_type
5591 || part_die
->tag
== DW_TAG_subrange_type
))
5593 if (building_psymtab
&& part_die
->name
!= NULL
)
5594 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5595 VAR_DOMAIN
, LOC_TYPEDEF
,
5596 &cu
->objfile
->static_psymbols
,
5597 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5598 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5602 /* If we're at the second level, and we're an enumerator, and
5603 our parent has no specification (meaning possibly lives in a
5604 namespace elsewhere), then we can add the partial symbol now
5605 instead of queueing it. */
5606 if (part_die
->tag
== DW_TAG_enumerator
5607 && parent_die
!= NULL
5608 && parent_die
->die_parent
== NULL
5609 && parent_die
->tag
== DW_TAG_enumeration_type
5610 && parent_die
->has_specification
== 0)
5612 if (part_die
->name
== NULL
)
5613 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5614 else if (building_psymtab
)
5615 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5616 VAR_DOMAIN
, LOC_CONST
,
5617 (cu
->language
== language_cplus
5618 || cu
->language
== language_java
)
5619 ? &cu
->objfile
->global_psymbols
5620 : &cu
->objfile
->static_psymbols
,
5621 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5623 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5627 /* We'll save this DIE so link it in. */
5628 part_die
->die_parent
= parent_die
;
5629 part_die
->die_sibling
= NULL
;
5630 part_die
->die_child
= NULL
;
5632 if (last_die
&& last_die
== parent_die
)
5633 last_die
->die_child
= part_die
;
5635 last_die
->die_sibling
= part_die
;
5637 last_die
= part_die
;
5639 if (first_die
== NULL
)
5640 first_die
= part_die
;
5642 /* Maybe add the DIE to the hash table. Not all DIEs that we
5643 find interesting need to be in the hash table, because we
5644 also have the parent/sibling/child chains; only those that we
5645 might refer to by offset later during partial symbol reading.
5647 For now this means things that might have be the target of a
5648 DW_AT_specification, DW_AT_abstract_origin, or
5649 DW_AT_extension. DW_AT_extension will refer only to
5650 namespaces; DW_AT_abstract_origin refers to functions (and
5651 many things under the function DIE, but we do not recurse
5652 into function DIEs during partial symbol reading) and
5653 possibly variables as well; DW_AT_specification refers to
5654 declarations. Declarations ought to have the DW_AT_declaration
5655 flag. It happens that GCC forgets to put it in sometimes, but
5656 only for functions, not for types.
5658 Adding more things than necessary to the hash table is harmless
5659 except for the performance cost. Adding too few will result in
5660 wasted time in find_partial_die, when we reread the compilation
5661 unit with load_all_dies set. */
5664 || abbrev
->tag
== DW_TAG_subprogram
5665 || abbrev
->tag
== DW_TAG_variable
5666 || abbrev
->tag
== DW_TAG_namespace
5667 || part_die
->is_declaration
)
5671 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
5672 part_die
->offset
, INSERT
);
5676 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5677 sizeof (struct partial_die_info
));
5679 /* For some DIEs we want to follow their children (if any). For C
5680 we have no reason to follow the children of structures; for other
5681 languages we have to, both so that we can get at method physnames
5682 to infer fully qualified class names, and for DW_AT_specification. */
5683 if (last_die
->has_children
5685 || last_die
->tag
== DW_TAG_namespace
5686 || last_die
->tag
== DW_TAG_enumeration_type
5687 || (cu
->language
!= language_c
5688 && (last_die
->tag
== DW_TAG_class_type
5689 || last_die
->tag
== DW_TAG_interface_type
5690 || last_die
->tag
== DW_TAG_structure_type
5691 || last_die
->tag
== DW_TAG_union_type
))))
5694 parent_die
= last_die
;
5698 /* Otherwise we skip to the next sibling, if any. */
5699 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
5701 /* Back to the top, do it again. */
5705 /* Read a minimal amount of information into the minimal die structure. */
5708 read_partial_die (struct partial_die_info
*part_die
,
5709 struct abbrev_info
*abbrev
,
5710 unsigned int abbrev_len
, bfd
*abfd
,
5711 gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
5713 unsigned int bytes_read
, i
;
5714 struct attribute attr
;
5715 int has_low_pc_attr
= 0;
5716 int has_high_pc_attr
= 0;
5717 CORE_ADDR base_address
= 0;
5721 base_address_low_pc
,
5722 /* Overrides BASE_ADDRESS_LOW_PC. */
5723 base_address_entry_pc
5725 base_address_type
= base_address_none
;
5727 memset (part_die
, 0, sizeof (struct partial_die_info
));
5729 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5731 info_ptr
+= abbrev_len
;
5736 part_die
->tag
= abbrev
->tag
;
5737 part_die
->has_children
= abbrev
->has_children
;
5739 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5741 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
5743 /* Store the data if it is of an attribute we want to keep in a
5744 partial symbol table. */
5749 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
5750 if (part_die
->name
== NULL
)
5751 part_die
->name
= DW_STRING (&attr
);
5753 case DW_AT_comp_dir
:
5754 if (part_die
->dirname
== NULL
)
5755 part_die
->dirname
= DW_STRING (&attr
);
5757 case DW_AT_MIPS_linkage_name
:
5758 part_die
->name
= DW_STRING (&attr
);
5761 has_low_pc_attr
= 1;
5762 part_die
->lowpc
= DW_ADDR (&attr
);
5763 if (part_die
->tag
== DW_TAG_compile_unit
5764 && base_address_type
< base_address_low_pc
)
5766 base_address
= DW_ADDR (&attr
);
5767 base_address_type
= base_address_low_pc
;
5771 has_high_pc_attr
= 1;
5772 part_die
->highpc
= DW_ADDR (&attr
);
5774 case DW_AT_entry_pc
:
5775 if (part_die
->tag
== DW_TAG_compile_unit
5776 && base_address_type
< base_address_entry_pc
)
5778 base_address
= DW_ADDR (&attr
);
5779 base_address_type
= base_address_entry_pc
;
5783 if (part_die
->tag
== DW_TAG_compile_unit
)
5785 cu
->ranges_offset
= DW_UNSND (&attr
);
5786 cu
->has_ranges_offset
= 1;
5789 case DW_AT_location
:
5790 /* Support the .debug_loc offsets */
5791 if (attr_form_is_block (&attr
))
5793 part_die
->locdesc
= DW_BLOCK (&attr
);
5795 else if (attr_form_is_section_offset (&attr
))
5797 dwarf2_complex_location_expr_complaint ();
5801 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5802 "partial symbol information");
5805 case DW_AT_language
:
5806 part_die
->language
= DW_UNSND (&attr
);
5808 case DW_AT_external
:
5809 part_die
->is_external
= DW_UNSND (&attr
);
5811 case DW_AT_declaration
:
5812 part_die
->is_declaration
= DW_UNSND (&attr
);
5815 part_die
->has_type
= 1;
5817 case DW_AT_abstract_origin
:
5818 case DW_AT_specification
:
5819 case DW_AT_extension
:
5820 part_die
->has_specification
= 1;
5821 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
, cu
);
5824 /* Ignore absolute siblings, they might point outside of
5825 the current compile unit. */
5826 if (attr
.form
== DW_FORM_ref_addr
)
5827 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
5829 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
5830 + dwarf2_get_ref_die_offset (&attr
, cu
);
5832 case DW_AT_stmt_list
:
5833 part_die
->has_stmt_list
= 1;
5834 part_die
->line_offset
= DW_UNSND (&attr
);
5836 case DW_AT_byte_size
:
5837 part_die
->has_byte_size
= 1;
5839 case DW_AT_calling_convention
:
5840 /* DWARF doesn't provide a way to identify a program's source-level
5841 entry point. DW_AT_calling_convention attributes are only meant
5842 to describe functions' calling conventions.
5844 However, because it's a necessary piece of information in
5845 Fortran, and because DW_CC_program is the only piece of debugging
5846 information whose definition refers to a 'main program' at all,
5847 several compilers have begun marking Fortran main programs with
5848 DW_CC_program --- even when those functions use the standard
5849 calling conventions.
5851 So until DWARF specifies a way to provide this information and
5852 compilers pick up the new representation, we'll support this
5854 if (DW_UNSND (&attr
) == DW_CC_program
5855 && cu
->language
== language_fortran
)
5856 set_main_name (part_die
->name
);
5863 /* When using the GNU linker, .gnu.linkonce. sections are used to
5864 eliminate duplicate copies of functions and vtables and such.
5865 The linker will arbitrarily choose one and discard the others.
5866 The AT_*_pc values for such functions refer to local labels in
5867 these sections. If the section from that file was discarded, the
5868 labels are not in the output, so the relocs get a value of 0.
5869 If this is a discarded function, mark the pc bounds as invalid,
5870 so that GDB will ignore it. */
5871 if (has_low_pc_attr
&& has_high_pc_attr
5872 && part_die
->lowpc
< part_die
->highpc
5873 && (part_die
->lowpc
!= 0
5874 || dwarf2_per_objfile
->has_section_at_zero
))
5875 part_die
->has_pc_info
= 1;
5877 if (base_address_type
!= base_address_none
&& !cu
->base_known
)
5879 gdb_assert (part_die
->tag
== DW_TAG_compile_unit
);
5881 cu
->base_address
= base_address
;
5887 /* Find a cached partial DIE at OFFSET in CU. */
5889 static struct partial_die_info
*
5890 find_partial_die_in_comp_unit (unsigned long offset
, struct dwarf2_cu
*cu
)
5892 struct partial_die_info
*lookup_die
= NULL
;
5893 struct partial_die_info part_die
;
5895 part_die
.offset
= offset
;
5896 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
5901 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
5903 static struct partial_die_info
*
5904 find_partial_die (unsigned long offset
, struct dwarf2_cu
*cu
)
5906 struct dwarf2_per_cu_data
*per_cu
= NULL
;
5907 struct partial_die_info
*pd
= NULL
;
5909 if (offset
>= cu
->header
.offset
5910 && offset
< cu
->header
.offset
+ cu
->header
.length
)
5912 pd
= find_partial_die_in_comp_unit (offset
, cu
);
5917 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
5919 if (per_cu
->cu
== NULL
)
5921 load_comp_unit (per_cu
, cu
->objfile
);
5922 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5923 dwarf2_per_objfile
->read_in_chain
= per_cu
;
5926 per_cu
->cu
->last_used
= 0;
5927 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
5929 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
5931 struct cleanup
*back_to
;
5932 struct partial_die_info comp_unit_die
;
5933 struct abbrev_info
*abbrev
;
5934 unsigned int bytes_read
;
5937 per_cu
->load_all_dies
= 1;
5939 /* Re-read the DIEs. */
5940 back_to
= make_cleanup (null_cleanup
, 0);
5941 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
5943 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
5944 back_to
= make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
5946 info_ptr
= (dwarf2_per_objfile
->info_buffer
5947 + per_cu
->cu
->header
.offset
5948 + per_cu
->cu
->header
.first_die_offset
);
5949 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
5950 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
5951 per_cu
->cu
->objfile
->obfd
, info_ptr
,
5953 if (comp_unit_die
.has_children
)
5954 load_partial_dies (per_cu
->cu
->objfile
->obfd
, info_ptr
, 0, per_cu
->cu
);
5955 do_cleanups (back_to
);
5957 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
5961 internal_error (__FILE__
, __LINE__
,
5962 _("could not find partial DIE 0x%lx in cache [from module %s]\n"),
5963 offset
, bfd_get_filename (cu
->objfile
->obfd
));
5967 /* Adjust PART_DIE before generating a symbol for it. This function
5968 may set the is_external flag or change the DIE's name. */
5971 fixup_partial_die (struct partial_die_info
*part_die
,
5972 struct dwarf2_cu
*cu
)
5974 /* If we found a reference attribute and the DIE has no name, try
5975 to find a name in the referred to DIE. */
5977 if (part_die
->name
== NULL
&& part_die
->has_specification
)
5979 struct partial_die_info
*spec_die
;
5981 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
5983 fixup_partial_die (spec_die
, cu
);
5987 part_die
->name
= spec_die
->name
;
5989 /* Copy DW_AT_external attribute if it is set. */
5990 if (spec_die
->is_external
)
5991 part_die
->is_external
= spec_die
->is_external
;
5995 /* Set default names for some unnamed DIEs. */
5996 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
5997 || part_die
->tag
== DW_TAG_class_type
))
5998 part_die
->name
= "(anonymous class)";
6000 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
6001 part_die
->name
= "(anonymous namespace)";
6003 if (part_die
->tag
== DW_TAG_structure_type
6004 || part_die
->tag
== DW_TAG_class_type
6005 || part_die
->tag
== DW_TAG_union_type
)
6006 guess_structure_name (part_die
, cu
);
6009 /* Read the die from the .debug_info section buffer. Set DIEP to
6010 point to a newly allocated die with its information, except for its
6011 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6012 whether the die has children or not. */
6015 read_full_die (struct die_info
**diep
, bfd
*abfd
, gdb_byte
*info_ptr
,
6016 struct dwarf2_cu
*cu
, int *has_children
)
6018 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6019 struct abbrev_info
*abbrev
;
6020 struct die_info
*die
;
6022 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
6023 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6024 info_ptr
+= bytes_read
;
6032 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6035 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6037 bfd_get_filename (abfd
));
6039 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
6040 die
->offset
= offset
;
6041 die
->tag
= abbrev
->tag
;
6042 die
->abbrev
= abbrev_number
;
6044 die
->num_attrs
= abbrev
->num_attrs
;
6046 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6047 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6048 abfd
, info_ptr
, cu
);
6051 *has_children
= abbrev
->has_children
;
6055 /* Read an attribute value described by an attribute form. */
6058 read_attribute_value (struct attribute
*attr
, unsigned form
,
6059 bfd
*abfd
, gdb_byte
*info_ptr
,
6060 struct dwarf2_cu
*cu
)
6062 struct comp_unit_head
*cu_header
= &cu
->header
;
6063 unsigned int bytes_read
;
6064 struct dwarf_block
*blk
;
6070 case DW_FORM_ref_addr
:
6071 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6072 info_ptr
+= bytes_read
;
6074 case DW_FORM_block2
:
6075 blk
= dwarf_alloc_block (cu
);
6076 blk
->size
= read_2_bytes (abfd
, info_ptr
);
6078 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6079 info_ptr
+= blk
->size
;
6080 DW_BLOCK (attr
) = blk
;
6082 case DW_FORM_block4
:
6083 blk
= dwarf_alloc_block (cu
);
6084 blk
->size
= read_4_bytes (abfd
, info_ptr
);
6086 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6087 info_ptr
+= blk
->size
;
6088 DW_BLOCK (attr
) = blk
;
6091 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
6095 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
6099 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
6102 case DW_FORM_string
:
6103 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
6104 info_ptr
+= bytes_read
;
6107 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
6109 info_ptr
+= bytes_read
;
6112 blk
= dwarf_alloc_block (cu
);
6113 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6114 info_ptr
+= bytes_read
;
6115 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6116 info_ptr
+= blk
->size
;
6117 DW_BLOCK (attr
) = blk
;
6119 case DW_FORM_block1
:
6120 blk
= dwarf_alloc_block (cu
);
6121 blk
->size
= read_1_byte (abfd
, info_ptr
);
6123 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6124 info_ptr
+= blk
->size
;
6125 DW_BLOCK (attr
) = blk
;
6128 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6132 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6136 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
6137 info_ptr
+= bytes_read
;
6140 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6141 info_ptr
+= bytes_read
;
6144 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
6148 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
6152 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
6156 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
6159 case DW_FORM_ref_udata
:
6160 DW_ADDR (attr
) = (cu
->header
.offset
6161 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
6162 info_ptr
+= bytes_read
;
6164 case DW_FORM_indirect
:
6165 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6166 info_ptr
+= bytes_read
;
6167 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
6170 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
6171 dwarf_form_name (form
),
6172 bfd_get_filename (abfd
));
6175 /* We have seen instances where the compiler tried to emit a byte
6176 size attribute of -1 which ended up being encoded as an unsigned
6177 0xffffffff. Although 0xffffffff is technically a valid size value,
6178 an object of this size seems pretty unlikely so we can relatively
6179 safely treat these cases as if the size attribute was invalid and
6180 treat them as zero by default. */
6181 if (attr
->name
== DW_AT_byte_size
6182 && form
== DW_FORM_data4
6183 && DW_UNSND (attr
) >= 0xffffffff)
6186 (&symfile_complaints
,
6187 _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"),
6189 DW_UNSND (attr
) = 0;
6195 /* Read an attribute described by an abbreviated attribute. */
6198 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
6199 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6201 attr
->name
= abbrev
->name
;
6202 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
6205 /* read dwarf information from a buffer */
6208 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
6210 return bfd_get_8 (abfd
, buf
);
6214 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
6216 return bfd_get_signed_8 (abfd
, buf
);
6220 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
6222 return bfd_get_16 (abfd
, buf
);
6226 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6228 return bfd_get_signed_16 (abfd
, buf
);
6232 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
6234 return bfd_get_32 (abfd
, buf
);
6238 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6240 return bfd_get_signed_32 (abfd
, buf
);
6243 static unsigned long
6244 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
6246 return bfd_get_64 (abfd
, buf
);
6250 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
6251 unsigned int *bytes_read
)
6253 struct comp_unit_head
*cu_header
= &cu
->header
;
6254 CORE_ADDR retval
= 0;
6256 if (cu_header
->signed_addr_p
)
6258 switch (cu_header
->addr_size
)
6261 retval
= bfd_get_signed_16 (abfd
, buf
);
6264 retval
= bfd_get_signed_32 (abfd
, buf
);
6267 retval
= bfd_get_signed_64 (abfd
, buf
);
6270 internal_error (__FILE__
, __LINE__
,
6271 _("read_address: bad switch, signed [in module %s]"),
6272 bfd_get_filename (abfd
));
6277 switch (cu_header
->addr_size
)
6280 retval
= bfd_get_16 (abfd
, buf
);
6283 retval
= bfd_get_32 (abfd
, buf
);
6286 retval
= bfd_get_64 (abfd
, buf
);
6289 internal_error (__FILE__
, __LINE__
,
6290 _("read_address: bad switch, unsigned [in module %s]"),
6291 bfd_get_filename (abfd
));
6295 *bytes_read
= cu_header
->addr_size
;
6299 /* Read the initial length from a section. The (draft) DWARF 3
6300 specification allows the initial length to take up either 4 bytes
6301 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
6302 bytes describe the length and all offsets will be 8 bytes in length
6305 An older, non-standard 64-bit format is also handled by this
6306 function. The older format in question stores the initial length
6307 as an 8-byte quantity without an escape value. Lengths greater
6308 than 2^32 aren't very common which means that the initial 4 bytes
6309 is almost always zero. Since a length value of zero doesn't make
6310 sense for the 32-bit format, this initial zero can be considered to
6311 be an escape value which indicates the presence of the older 64-bit
6312 format. As written, the code can't detect (old format) lengths
6313 greater than 4GB. If it becomes necessary to handle lengths
6314 somewhat larger than 4GB, we could allow other small values (such
6315 as the non-sensical values of 1, 2, and 3) to also be used as
6316 escape values indicating the presence of the old format.
6318 The value returned via bytes_read should be used to increment the
6319 relevant pointer after calling read_initial_length().
6321 As a side effect, this function sets the fields initial_length_size
6322 and offset_size in cu_header to the values appropriate for the
6323 length field. (The format of the initial length field determines
6324 the width of file offsets to be fetched later with read_offset().)
6326 [ Note: read_initial_length() and read_offset() are based on the
6327 document entitled "DWARF Debugging Information Format", revision
6328 3, draft 8, dated November 19, 2001. This document was obtained
6331 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
6333 This document is only a draft and is subject to change. (So beware.)
6335 Details regarding the older, non-standard 64-bit format were
6336 determined empirically by examining 64-bit ELF files produced by
6337 the SGI toolchain on an IRIX 6.5 machine.
6339 - Kevin, July 16, 2002
6343 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, struct comp_unit_head
*cu_header
,
6344 unsigned int *bytes_read
)
6346 LONGEST length
= bfd_get_32 (abfd
, buf
);
6348 if (length
== 0xffffffff)
6350 length
= bfd_get_64 (abfd
, buf
+ 4);
6353 else if (length
== 0)
6355 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
6356 length
= bfd_get_64 (abfd
, buf
);
6366 gdb_assert (cu_header
->initial_length_size
== 0
6367 || cu_header
->initial_length_size
== 4
6368 || cu_header
->initial_length_size
== 8
6369 || cu_header
->initial_length_size
== 12);
6371 if (cu_header
->initial_length_size
!= 0
6372 && cu_header
->initial_length_size
!= *bytes_read
)
6373 complaint (&symfile_complaints
,
6374 _("intermixed 32-bit and 64-bit DWARF sections"));
6376 cu_header
->initial_length_size
= *bytes_read
;
6377 cu_header
->offset_size
= (*bytes_read
== 4) ? 4 : 8;
6383 /* Read an offset from the data stream. The size of the offset is
6384 given by cu_header->offset_size. */
6387 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
6388 unsigned int *bytes_read
)
6392 switch (cu_header
->offset_size
)
6395 retval
= bfd_get_32 (abfd
, buf
);
6399 retval
= bfd_get_64 (abfd
, buf
);
6403 internal_error (__FILE__
, __LINE__
,
6404 _("read_offset: bad switch [in module %s]"),
6405 bfd_get_filename (abfd
));
6412 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
6414 /* If the size of a host char is 8 bits, we can return a pointer
6415 to the buffer, otherwise we have to copy the data to a buffer
6416 allocated on the temporary obstack. */
6417 gdb_assert (HOST_CHAR_BIT
== 8);
6422 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6424 /* If the size of a host char is 8 bits, we can return a pointer
6425 to the string, otherwise we have to copy the string to a buffer
6426 allocated on the temporary obstack. */
6427 gdb_assert (HOST_CHAR_BIT
== 8);
6430 *bytes_read_ptr
= 1;
6433 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
6434 return (char *) buf
;
6438 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
6439 const struct comp_unit_head
*cu_header
,
6440 unsigned int *bytes_read_ptr
)
6442 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
6445 if (dwarf2_per_objfile
->str_buffer
== NULL
)
6447 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
6448 bfd_get_filename (abfd
));
6451 if (str_offset
>= dwarf2_per_objfile
->str_size
)
6453 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
6454 bfd_get_filename (abfd
));
6457 gdb_assert (HOST_CHAR_BIT
== 8);
6458 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
6460 return (char *) (dwarf2_per_objfile
->str_buffer
+ str_offset
);
6463 static unsigned long
6464 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6466 unsigned long result
;
6467 unsigned int num_read
;
6477 byte
= bfd_get_8 (abfd
, buf
);
6480 result
|= ((unsigned long)(byte
& 127) << shift
);
6481 if ((byte
& 128) == 0)
6487 *bytes_read_ptr
= num_read
;
6492 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6495 int i
, shift
, num_read
;
6504 byte
= bfd_get_8 (abfd
, buf
);
6507 result
|= ((long)(byte
& 127) << shift
);
6509 if ((byte
& 128) == 0)
6514 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
6515 result
|= -(((long)1) << shift
);
6516 *bytes_read_ptr
= num_read
;
6520 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6523 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
6529 byte
= bfd_get_8 (abfd
, buf
);
6531 if ((byte
& 128) == 0)
6537 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
6543 cu
->language
= language_c
;
6545 case DW_LANG_C_plus_plus
:
6546 cu
->language
= language_cplus
;
6548 case DW_LANG_Fortran77
:
6549 case DW_LANG_Fortran90
:
6550 case DW_LANG_Fortran95
:
6551 cu
->language
= language_fortran
;
6553 case DW_LANG_Mips_Assembler
:
6554 cu
->language
= language_asm
;
6557 cu
->language
= language_java
;
6561 cu
->language
= language_ada
;
6563 case DW_LANG_Modula2
:
6564 cu
->language
= language_m2
;
6566 case DW_LANG_Pascal83
:
6567 cu
->language
= language_pascal
;
6570 cu
->language
= language_objc
;
6572 case DW_LANG_Cobol74
:
6573 case DW_LANG_Cobol85
:
6575 cu
->language
= language_minimal
;
6578 cu
->language_defn
= language_def (cu
->language
);
6581 /* Return the named attribute or NULL if not there. */
6583 static struct attribute
*
6584 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
6587 struct attribute
*spec
= NULL
;
6589 for (i
= 0; i
< die
->num_attrs
; ++i
)
6591 if (die
->attrs
[i
].name
== name
)
6592 return &die
->attrs
[i
];
6593 if (die
->attrs
[i
].name
== DW_AT_specification
6594 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
6595 spec
= &die
->attrs
[i
];
6600 die
= follow_die_ref (die
, spec
, &cu
);
6601 return dwarf2_attr (die
, name
, cu
);
6607 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6608 and holds a non-zero value. This function should only be used for
6609 DW_FORM_flag attributes. */
6612 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
6614 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
6616 return (attr
&& DW_UNSND (attr
));
6620 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
6622 /* A DIE is a declaration if it has a DW_AT_declaration attribute
6623 which value is non-zero. However, we have to be careful with
6624 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
6625 (via dwarf2_flag_true_p) follows this attribute. So we may
6626 end up accidently finding a declaration attribute that belongs
6627 to a different DIE referenced by the specification attribute,
6628 even though the given DIE does not have a declaration attribute. */
6629 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
6630 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
6633 /* Return the die giving the specification for DIE, if there is
6634 one. *SPEC_CU is the CU containing DIE on input, and the CU
6635 containing the return value on output. */
6637 static struct die_info
*
6638 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
6640 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
6643 if (spec_attr
== NULL
)
6646 return follow_die_ref (die
, spec_attr
, spec_cu
);
6649 /* Free the line_header structure *LH, and any arrays and strings it
6652 free_line_header (struct line_header
*lh
)
6654 if (lh
->standard_opcode_lengths
)
6655 xfree (lh
->standard_opcode_lengths
);
6657 /* Remember that all the lh->file_names[i].name pointers are
6658 pointers into debug_line_buffer, and don't need to be freed. */
6660 xfree (lh
->file_names
);
6662 /* Similarly for the include directory names. */
6663 if (lh
->include_dirs
)
6664 xfree (lh
->include_dirs
);
6670 /* Add an entry to LH's include directory table. */
6672 add_include_dir (struct line_header
*lh
, char *include_dir
)
6674 /* Grow the array if necessary. */
6675 if (lh
->include_dirs_size
== 0)
6677 lh
->include_dirs_size
= 1; /* for testing */
6678 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
6679 * sizeof (*lh
->include_dirs
));
6681 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
6683 lh
->include_dirs_size
*= 2;
6684 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
6685 (lh
->include_dirs_size
6686 * sizeof (*lh
->include_dirs
)));
6689 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
6693 /* Add an entry to LH's file name table. */
6695 add_file_name (struct line_header
*lh
,
6697 unsigned int dir_index
,
6698 unsigned int mod_time
,
6699 unsigned int length
)
6701 struct file_entry
*fe
;
6703 /* Grow the array if necessary. */
6704 if (lh
->file_names_size
== 0)
6706 lh
->file_names_size
= 1; /* for testing */
6707 lh
->file_names
= xmalloc (lh
->file_names_size
6708 * sizeof (*lh
->file_names
));
6710 else if (lh
->num_file_names
>= lh
->file_names_size
)
6712 lh
->file_names_size
*= 2;
6713 lh
->file_names
= xrealloc (lh
->file_names
,
6714 (lh
->file_names_size
6715 * sizeof (*lh
->file_names
)));
6718 fe
= &lh
->file_names
[lh
->num_file_names
++];
6720 fe
->dir_index
= dir_index
;
6721 fe
->mod_time
= mod_time
;
6722 fe
->length
= length
;
6728 /* Read the statement program header starting at OFFSET in
6729 .debug_line, according to the endianness of ABFD. Return a pointer
6730 to a struct line_header, allocated using xmalloc.
6732 NOTE: the strings in the include directory and file name tables of
6733 the returned object point into debug_line_buffer, and must not be
6735 static struct line_header
*
6736 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
6737 struct dwarf2_cu
*cu
)
6739 struct cleanup
*back_to
;
6740 struct line_header
*lh
;
6742 unsigned int bytes_read
;
6744 char *cur_dir
, *cur_file
;
6746 if (dwarf2_per_objfile
->line_buffer
== NULL
)
6748 complaint (&symfile_complaints
, _("missing .debug_line section"));
6752 /* Make sure that at least there's room for the total_length field.
6753 That could be 12 bytes long, but we're just going to fudge that. */
6754 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
6756 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6760 lh
= xmalloc (sizeof (*lh
));
6761 memset (lh
, 0, sizeof (*lh
));
6762 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
6765 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
6767 /* Read in the header. */
6769 read_initial_length (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6770 line_ptr
+= bytes_read
;
6771 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
6772 + dwarf2_per_objfile
->line_size
))
6774 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6777 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
6778 lh
->version
= read_2_bytes (abfd
, line_ptr
);
6780 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6781 line_ptr
+= bytes_read
;
6782 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
6784 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
6786 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
6788 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
6790 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
6792 lh
->standard_opcode_lengths
6793 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
6795 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
6796 for (i
= 1; i
< lh
->opcode_base
; ++i
)
6798 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
6802 /* Read directory table. */
6803 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6805 line_ptr
+= bytes_read
;
6806 add_include_dir (lh
, cur_dir
);
6808 line_ptr
+= bytes_read
;
6810 /* Read file name table. */
6811 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6813 unsigned int dir_index
, mod_time
, length
;
6815 line_ptr
+= bytes_read
;
6816 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6817 line_ptr
+= bytes_read
;
6818 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6819 line_ptr
+= bytes_read
;
6820 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6821 line_ptr
+= bytes_read
;
6823 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6825 line_ptr
+= bytes_read
;
6826 lh
->statement_program_start
= line_ptr
;
6828 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
6829 + dwarf2_per_objfile
->line_size
))
6830 complaint (&symfile_complaints
,
6831 _("line number info header doesn't fit in `.debug_line' section"));
6833 discard_cleanups (back_to
);
6837 /* This function exists to work around a bug in certain compilers
6838 (particularly GCC 2.95), in which the first line number marker of a
6839 function does not show up until after the prologue, right before
6840 the second line number marker. This function shifts ADDRESS down
6841 to the beginning of the function if necessary, and is called on
6842 addresses passed to record_line. */
6845 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
6847 struct function_range
*fn
;
6849 /* Find the function_range containing address. */
6854 cu
->cached_fn
= cu
->first_fn
;
6858 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6864 while (fn
&& fn
!= cu
->cached_fn
)
6865 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6875 if (address
!= fn
->lowpc
)
6876 complaint (&symfile_complaints
,
6877 _("misplaced first line number at 0x%lx for '%s'"),
6878 (unsigned long) address
, fn
->name
);
6883 /* Decode the Line Number Program (LNP) for the given line_header
6884 structure and CU. The actual information extracted and the type
6885 of structures created from the LNP depends on the value of PST.
6887 1. If PST is NULL, then this procedure uses the data from the program
6888 to create all necessary symbol tables, and their linetables.
6889 The compilation directory of the file is passed in COMP_DIR,
6890 and must not be NULL.
6892 2. If PST is not NULL, this procedure reads the program to determine
6893 the list of files included by the unit represented by PST, and
6894 builds all the associated partial symbol tables. In this case,
6895 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
6896 is not used to compute the full name of the symtab, and therefore
6897 omitting it when building the partial symtab does not introduce
6898 the potential for inconsistency - a partial symtab and its associated
6899 symbtab having a different fullname -). */
6902 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
6903 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
6905 gdb_byte
*line_ptr
, *extended_end
;
6907 unsigned int bytes_read
, extended_len
;
6908 unsigned char op_code
, extended_op
, adj_opcode
;
6910 struct objfile
*objfile
= cu
->objfile
;
6911 const int decode_for_pst_p
= (pst
!= NULL
);
6912 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
6914 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6916 line_ptr
= lh
->statement_program_start
;
6917 line_end
= lh
->statement_program_end
;
6919 /* Read the statement sequences until there's nothing left. */
6920 while (line_ptr
< line_end
)
6922 /* state machine registers */
6923 CORE_ADDR address
= 0;
6924 unsigned int file
= 1;
6925 unsigned int line
= 1;
6926 unsigned int column
= 0;
6927 int is_stmt
= lh
->default_is_stmt
;
6928 int basic_block
= 0;
6929 int end_sequence
= 0;
6931 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
6933 /* Start a subfile for the current file of the state machine. */
6934 /* lh->include_dirs and lh->file_names are 0-based, but the
6935 directory and file name numbers in the statement program
6937 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
6941 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6943 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
6946 /* Decode the table. */
6947 while (!end_sequence
)
6949 op_code
= read_1_byte (abfd
, line_ptr
);
6952 if (op_code
>= lh
->opcode_base
)
6954 /* Special operand. */
6955 adj_opcode
= op_code
- lh
->opcode_base
;
6956 address
+= (adj_opcode
/ lh
->line_range
)
6957 * lh
->minimum_instruction_length
;
6958 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
6959 if (lh
->num_file_names
< file
)
6960 dwarf2_debug_line_missing_file_complaint ();
6963 lh
->file_names
[file
- 1].included_p
= 1;
6964 if (!decode_for_pst_p
)
6966 if (last_subfile
!= current_subfile
)
6969 record_line (last_subfile
, 0, address
);
6970 last_subfile
= current_subfile
;
6972 /* Append row to matrix using current values. */
6973 record_line (current_subfile
, line
,
6974 check_cu_functions (address
, cu
));
6979 else switch (op_code
)
6981 case DW_LNS_extended_op
:
6982 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6983 line_ptr
+= bytes_read
;
6984 extended_end
= line_ptr
+ extended_len
;
6985 extended_op
= read_1_byte (abfd
, line_ptr
);
6987 switch (extended_op
)
6989 case DW_LNE_end_sequence
:
6992 if (lh
->num_file_names
< file
)
6993 dwarf2_debug_line_missing_file_complaint ();
6996 lh
->file_names
[file
- 1].included_p
= 1;
6997 if (!decode_for_pst_p
)
6998 record_line (current_subfile
, 0, address
);
7001 case DW_LNE_set_address
:
7002 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
7003 line_ptr
+= bytes_read
;
7004 address
+= baseaddr
;
7006 case DW_LNE_define_file
:
7009 unsigned int dir_index
, mod_time
, length
;
7011 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
7012 line_ptr
+= bytes_read
;
7014 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7015 line_ptr
+= bytes_read
;
7017 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7018 line_ptr
+= bytes_read
;
7020 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7021 line_ptr
+= bytes_read
;
7022 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7026 complaint (&symfile_complaints
,
7027 _("mangled .debug_line section"));
7030 /* Make sure that we parsed the extended op correctly. If e.g.
7031 we expected a different address size than the producer used,
7032 we may have read the wrong number of bytes. */
7033 if (line_ptr
!= extended_end
)
7035 complaint (&symfile_complaints
,
7036 _("mangled .debug_line section"));
7041 if (lh
->num_file_names
< file
)
7042 dwarf2_debug_line_missing_file_complaint ();
7045 lh
->file_names
[file
- 1].included_p
= 1;
7046 if (!decode_for_pst_p
)
7048 if (last_subfile
!= current_subfile
)
7051 record_line (last_subfile
, 0, address
);
7052 last_subfile
= current_subfile
;
7054 record_line (current_subfile
, line
,
7055 check_cu_functions (address
, cu
));
7060 case DW_LNS_advance_pc
:
7061 address
+= lh
->minimum_instruction_length
7062 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7063 line_ptr
+= bytes_read
;
7065 case DW_LNS_advance_line
:
7066 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
7067 line_ptr
+= bytes_read
;
7069 case DW_LNS_set_file
:
7071 /* The arrays lh->include_dirs and lh->file_names are
7072 0-based, but the directory and file name numbers in
7073 the statement program are 1-based. */
7074 struct file_entry
*fe
;
7077 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7078 line_ptr
+= bytes_read
;
7079 if (lh
->num_file_names
< file
)
7080 dwarf2_debug_line_missing_file_complaint ();
7083 fe
= &lh
->file_names
[file
- 1];
7085 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7086 if (!decode_for_pst_p
)
7088 last_subfile
= current_subfile
;
7089 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7094 case DW_LNS_set_column
:
7095 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7096 line_ptr
+= bytes_read
;
7098 case DW_LNS_negate_stmt
:
7099 is_stmt
= (!is_stmt
);
7101 case DW_LNS_set_basic_block
:
7104 /* Add to the address register of the state machine the
7105 address increment value corresponding to special opcode
7106 255. I.e., this value is scaled by the minimum
7107 instruction length since special opcode 255 would have
7108 scaled the the increment. */
7109 case DW_LNS_const_add_pc
:
7110 address
+= (lh
->minimum_instruction_length
7111 * ((255 - lh
->opcode_base
) / lh
->line_range
));
7113 case DW_LNS_fixed_advance_pc
:
7114 address
+= read_2_bytes (abfd
, line_ptr
);
7119 /* Unknown standard opcode, ignore it. */
7122 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
7124 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7125 line_ptr
+= bytes_read
;
7132 if (decode_for_pst_p
)
7136 /* Now that we're done scanning the Line Header Program, we can
7137 create the psymtab of each included file. */
7138 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
7139 if (lh
->file_names
[file_index
].included_p
== 1)
7141 const struct file_entry fe
= lh
->file_names
[file_index
];
7142 char *include_name
= fe
.name
;
7143 char *dir_name
= NULL
;
7144 char *pst_filename
= pst
->filename
;
7147 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
7149 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
7151 include_name
= concat (dir_name
, SLASH_STRING
,
7152 include_name
, (char *)NULL
);
7153 make_cleanup (xfree
, include_name
);
7156 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
7158 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
7159 pst_filename
, (char *)NULL
);
7160 make_cleanup (xfree
, pst_filename
);
7163 if (strcmp (include_name
, pst_filename
) != 0)
7164 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
7169 /* Make sure a symtab is created for every file, even files
7170 which contain only variables (i.e. no code with associated
7174 struct file_entry
*fe
;
7176 for (i
= 0; i
< lh
->num_file_names
; i
++)
7179 fe
= &lh
->file_names
[i
];
7181 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7182 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7184 /* Skip the main file; we don't need it, and it must be
7185 allocated last, so that it will show up before the
7186 non-primary symtabs in the objfile's symtab list. */
7187 if (current_subfile
== first_subfile
)
7190 if (current_subfile
->symtab
== NULL
)
7191 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7193 fe
->symtab
= current_subfile
->symtab
;
7198 /* Start a subfile for DWARF. FILENAME is the name of the file and
7199 DIRNAME the name of the source directory which contains FILENAME
7200 or NULL if not known. COMP_DIR is the compilation directory for the
7201 linetable's compilation unit or NULL if not known.
7202 This routine tries to keep line numbers from identical absolute and
7203 relative file names in a common subfile.
7205 Using the `list' example from the GDB testsuite, which resides in
7206 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
7207 of /srcdir/list0.c yields the following debugging information for list0.c:
7209 DW_AT_name: /srcdir/list0.c
7210 DW_AT_comp_dir: /compdir
7211 files.files[0].name: list0.h
7212 files.files[0].dir: /srcdir
7213 files.files[1].name: list0.c
7214 files.files[1].dir: /srcdir
7216 The line number information for list0.c has to end up in a single
7217 subfile, so that `break /srcdir/list0.c:1' works as expected.
7218 start_subfile will ensure that this happens provided that we pass the
7219 concatenation of files.files[1].dir and files.files[1].name as the
7223 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
7227 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
7228 `start_symtab' will always pass the contents of DW_AT_comp_dir as
7229 second argument to start_subfile. To be consistent, we do the
7230 same here. In order not to lose the line information directory,
7231 we concatenate it to the filename when it makes sense.
7232 Note that the Dwarf3 standard says (speaking of filenames in line
7233 information): ``The directory index is ignored for file names
7234 that represent full path names''. Thus ignoring dirname in the
7235 `else' branch below isn't an issue. */
7237 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
7238 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
7240 fullname
= filename
;
7242 start_subfile (fullname
, comp_dir
);
7244 if (fullname
!= filename
)
7249 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
7250 struct dwarf2_cu
*cu
)
7252 struct objfile
*objfile
= cu
->objfile
;
7253 struct comp_unit_head
*cu_header
= &cu
->header
;
7255 /* NOTE drow/2003-01-30: There used to be a comment and some special
7256 code here to turn a symbol with DW_AT_external and a
7257 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
7258 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
7259 with some versions of binutils) where shared libraries could have
7260 relocations against symbols in their debug information - the
7261 minimal symbol would have the right address, but the debug info
7262 would not. It's no longer necessary, because we will explicitly
7263 apply relocations when we read in the debug information now. */
7265 /* A DW_AT_location attribute with no contents indicates that a
7266 variable has been optimized away. */
7267 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
7269 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7273 /* Handle one degenerate form of location expression specially, to
7274 preserve GDB's previous behavior when section offsets are
7275 specified. If this is just a DW_OP_addr then mark this symbol
7278 if (attr_form_is_block (attr
)
7279 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
7280 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
7284 SYMBOL_VALUE_ADDRESS (sym
) =
7285 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
7286 SYMBOL_CLASS (sym
) = LOC_STATIC
;
7287 fixup_symbol_section (sym
, objfile
);
7288 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
7289 SYMBOL_SECTION (sym
));
7293 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
7294 expression evaluator, and use LOC_COMPUTED only when necessary
7295 (i.e. when the value of a register or memory location is
7296 referenced, or a thread-local block, etc.). Then again, it might
7297 not be worthwhile. I'm assuming that it isn't unless performance
7298 or memory numbers show me otherwise. */
7300 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
7301 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
7304 /* Given a pointer to a DWARF information entry, figure out if we need
7305 to make a symbol table entry for it, and if so, create a new entry
7306 and return a pointer to it.
7307 If TYPE is NULL, determine symbol type from the die, otherwise
7308 used the passed type. */
7310 static struct symbol
*
7311 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
7313 struct objfile
*objfile
= cu
->objfile
;
7314 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7315 struct symbol
*sym
= NULL
;
7317 struct attribute
*attr
= NULL
;
7318 struct attribute
*attr2
= NULL
;
7321 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7323 if (die
->tag
!= DW_TAG_namespace
)
7324 name
= dwarf2_linkage_name (die
, cu
);
7326 name
= TYPE_NAME (type
);
7330 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
7331 sizeof (struct symbol
));
7332 OBJSTAT (objfile
, n_syms
++);
7333 memset (sym
, 0, sizeof (struct symbol
));
7335 /* Cache this symbol's name and the name's demangled form (if any). */
7336 SYMBOL_LANGUAGE (sym
) = cu
->language
;
7337 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
7339 /* Default assumptions.
7340 Use the passed type or decode it from the die. */
7341 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7342 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7344 SYMBOL_TYPE (sym
) = type
;
7346 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
7347 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
7350 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
7353 attr
= dwarf2_attr (die
, DW_AT_decl_file
, cu
);
7356 int file_index
= DW_UNSND (attr
);
7357 if (cu
->line_header
== NULL
7358 || file_index
> cu
->line_header
->num_file_names
)
7359 complaint (&symfile_complaints
,
7360 _("file index out of range"));
7361 else if (file_index
> 0)
7363 struct file_entry
*fe
;
7364 fe
= &cu
->line_header
->file_names
[file_index
- 1];
7365 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
7372 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7375 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
7377 SYMBOL_CLASS (sym
) = LOC_LABEL
;
7379 case DW_TAG_subprogram
:
7380 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7382 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
7383 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7384 if ((attr2
&& (DW_UNSND (attr2
) != 0))
7385 || cu
->language
== language_ada
)
7387 /* Subprograms marked external are stored as a global symbol.
7388 Ada subprograms, whether marked external or not, are always
7389 stored as a global symbol, because we want to be able to
7390 access them globally. For instance, we want to be able
7391 to break on a nested subprogram without having to
7392 specify the context. */
7393 add_symbol_to_list (sym
, &global_symbols
);
7397 add_symbol_to_list (sym
, cu
->list_in_scope
);
7400 case DW_TAG_variable
:
7401 /* Compilation with minimal debug info may result in variables
7402 with missing type entries. Change the misleading `void' type
7403 to something sensible. */
7404 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
7406 = builtin_type (gdbarch
)->nodebug_data_symbol
;
7408 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7411 dwarf2_const_value (attr
, sym
, cu
);
7412 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7413 if (attr2
&& (DW_UNSND (attr2
) != 0))
7414 add_symbol_to_list (sym
, &global_symbols
);
7416 add_symbol_to_list (sym
, cu
->list_in_scope
);
7419 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7422 var_decode_location (attr
, sym
, cu
);
7423 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7424 if (attr2
&& (DW_UNSND (attr2
) != 0))
7425 add_symbol_to_list (sym
, &global_symbols
);
7427 add_symbol_to_list (sym
, cu
->list_in_scope
);
7431 /* We do not know the address of this symbol.
7432 If it is an external symbol and we have type information
7433 for it, enter the symbol as a LOC_UNRESOLVED symbol.
7434 The address of the variable will then be determined from
7435 the minimal symbol table whenever the variable is
7437 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7438 if (attr2
&& (DW_UNSND (attr2
) != 0)
7439 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
7441 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
7442 add_symbol_to_list (sym
, &global_symbols
);
7446 case DW_TAG_formal_parameter
:
7447 SYMBOL_IS_ARGUMENT (sym
) = 1;
7448 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7451 var_decode_location (attr
, sym
, cu
);
7453 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7456 dwarf2_const_value (attr
, sym
, cu
);
7458 add_symbol_to_list (sym
, cu
->list_in_scope
);
7460 case DW_TAG_unspecified_parameters
:
7461 /* From varargs functions; gdb doesn't seem to have any
7462 interest in this information, so just ignore it for now.
7465 case DW_TAG_class_type
:
7466 case DW_TAG_interface_type
:
7467 case DW_TAG_structure_type
:
7468 case DW_TAG_union_type
:
7469 case DW_TAG_set_type
:
7470 case DW_TAG_enumeration_type
:
7471 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7472 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7474 /* Make sure that the symbol includes appropriate enclosing
7475 classes/namespaces in its name. These are calculated in
7476 read_structure_type, and the correct name is saved in
7479 if (cu
->language
== language_cplus
7480 || cu
->language
== language_java
)
7482 struct type
*type
= SYMBOL_TYPE (sym
);
7484 if (TYPE_TAG_NAME (type
) != NULL
)
7486 /* FIXME: carlton/2003-11-10: Should this use
7487 SYMBOL_SET_NAMES instead? (The same problem also
7488 arises further down in this function.) */
7489 /* The type's name is already allocated along with
7490 this objfile, so we don't need to duplicate it
7492 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
7497 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
7498 really ever be static objects: otherwise, if you try
7499 to, say, break of a class's method and you're in a file
7500 which doesn't mention that class, it won't work unless
7501 the check for all static symbols in lookup_symbol_aux
7502 saves you. See the OtherFileClass tests in
7503 gdb.c++/namespace.exp. */
7505 struct pending
**list_to_add
;
7507 list_to_add
= (cu
->list_in_scope
== &file_symbols
7508 && (cu
->language
== language_cplus
7509 || cu
->language
== language_java
)
7510 ? &global_symbols
: cu
->list_in_scope
);
7512 add_symbol_to_list (sym
, list_to_add
);
7514 /* The semantics of C++ state that "struct foo { ... }" also
7515 defines a typedef for "foo". A Java class declaration also
7516 defines a typedef for the class. */
7517 if (cu
->language
== language_cplus
7518 || cu
->language
== language_java
7519 || cu
->language
== language_ada
)
7521 /* The symbol's name is already allocated along with
7522 this objfile, so we don't need to duplicate it for
7524 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
7525 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
7529 case DW_TAG_typedef
:
7530 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7531 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7532 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7533 add_symbol_to_list (sym
, cu
->list_in_scope
);
7535 case DW_TAG_base_type
:
7536 case DW_TAG_subrange_type
:
7537 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7538 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7539 add_symbol_to_list (sym
, cu
->list_in_scope
);
7541 case DW_TAG_enumerator
:
7542 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7543 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7546 dwarf2_const_value (attr
, sym
, cu
);
7549 /* NOTE: carlton/2003-11-10: See comment above in the
7550 DW_TAG_class_type, etc. block. */
7552 struct pending
**list_to_add
;
7554 list_to_add
= (cu
->list_in_scope
== &file_symbols
7555 && (cu
->language
== language_cplus
7556 || cu
->language
== language_java
)
7557 ? &global_symbols
: cu
->list_in_scope
);
7559 add_symbol_to_list (sym
, list_to_add
);
7562 case DW_TAG_namespace
:
7563 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7564 add_symbol_to_list (sym
, &global_symbols
);
7567 /* Not a tag we recognize. Hopefully we aren't processing
7568 trash data, but since we must specifically ignore things
7569 we don't recognize, there is nothing else we should do at
7571 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
7572 dwarf_tag_name (die
->tag
));
7576 /* For the benefit of old versions of GCC, check for anonymous
7577 namespaces based on the demangled name. */
7578 if (!processing_has_namespace_info
7579 && cu
->language
== language_cplus
7580 && dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
) != NULL
)
7581 cp_scan_for_anonymous_namespaces (sym
);
7586 /* Copy constant value from an attribute to a symbol. */
7589 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
7590 struct dwarf2_cu
*cu
)
7592 struct objfile
*objfile
= cu
->objfile
;
7593 struct comp_unit_head
*cu_header
= &cu
->header
;
7594 struct dwarf_block
*blk
;
7599 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
7600 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7601 cu_header
->addr_size
,
7602 TYPE_LENGTH (SYMBOL_TYPE
7604 SYMBOL_VALUE_BYTES (sym
) =
7605 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
7606 /* NOTE: cagney/2003-05-09: In-lined store_address call with
7607 it's body - store_unsigned_integer. */
7608 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
7610 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7613 /* DW_STRING is already allocated on the obstack, point directly
7615 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
7616 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7618 case DW_FORM_block1
:
7619 case DW_FORM_block2
:
7620 case DW_FORM_block4
:
7622 blk
= DW_BLOCK (attr
);
7623 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
7624 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7626 TYPE_LENGTH (SYMBOL_TYPE
7628 SYMBOL_VALUE_BYTES (sym
) =
7629 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
7630 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
7631 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7634 /* The DW_AT_const_value attributes are supposed to carry the
7635 symbol's value "represented as it would be on the target
7636 architecture." By the time we get here, it's already been
7637 converted to host endianness, so we just need to sign- or
7638 zero-extend it as appropriate. */
7640 dwarf2_const_value_data (attr
, sym
, 8);
7643 dwarf2_const_value_data (attr
, sym
, 16);
7646 dwarf2_const_value_data (attr
, sym
, 32);
7649 dwarf2_const_value_data (attr
, sym
, 64);
7653 SYMBOL_VALUE (sym
) = DW_SND (attr
);
7654 SYMBOL_CLASS (sym
) = LOC_CONST
;
7658 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
7659 SYMBOL_CLASS (sym
) = LOC_CONST
;
7663 complaint (&symfile_complaints
,
7664 _("unsupported const value attribute form: '%s'"),
7665 dwarf_form_name (attr
->form
));
7666 SYMBOL_VALUE (sym
) = 0;
7667 SYMBOL_CLASS (sym
) = LOC_CONST
;
7673 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
7674 or zero-extend it as appropriate for the symbol's type. */
7676 dwarf2_const_value_data (struct attribute
*attr
,
7680 LONGEST l
= DW_UNSND (attr
);
7682 if (bits
< sizeof (l
) * 8)
7684 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
7685 l
&= ((LONGEST
) 1 << bits
) - 1;
7687 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
7690 SYMBOL_VALUE (sym
) = l
;
7691 SYMBOL_CLASS (sym
) = LOC_CONST
;
7695 /* Return the type of the die in question using its DW_AT_type attribute. */
7697 static struct type
*
7698 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7700 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7702 struct attribute
*type_attr
;
7703 struct die_info
*type_die
;
7705 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
7708 /* A missing DW_AT_type represents a void type. */
7709 return builtin_type (gdbarch
)->builtin_void
;
7712 type_die
= follow_die_ref (die
, type_attr
, &cu
);
7714 type
= tag_type_to_type (type_die
, cu
);
7717 dump_die (type_die
);
7718 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
7724 /* Return the containing type of the die in question using its
7725 DW_AT_containing_type attribute. */
7727 static struct type
*
7728 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7730 struct type
*type
= NULL
;
7731 struct attribute
*type_attr
;
7732 struct die_info
*type_die
= NULL
;
7734 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
7737 type_die
= follow_die_ref (die
, type_attr
, &cu
);
7738 type
= tag_type_to_type (type_die
, cu
);
7743 dump_die (type_die
);
7744 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
7750 static struct type
*
7751 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7753 struct type
*this_type
;
7755 this_type
= read_type_die (die
, cu
);
7759 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
7765 static struct type
*
7766 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7768 struct type
*this_type
;
7770 this_type
= get_die_type (die
, cu
);
7776 case DW_TAG_class_type
:
7777 case DW_TAG_interface_type
:
7778 case DW_TAG_structure_type
:
7779 case DW_TAG_union_type
:
7780 this_type
= read_structure_type (die
, cu
);
7782 case DW_TAG_enumeration_type
:
7783 this_type
= read_enumeration_type (die
, cu
);
7785 case DW_TAG_subprogram
:
7786 case DW_TAG_subroutine_type
:
7787 this_type
= read_subroutine_type (die
, cu
);
7789 case DW_TAG_array_type
:
7790 this_type
= read_array_type (die
, cu
);
7792 case DW_TAG_set_type
:
7793 this_type
= read_set_type (die
, cu
);
7795 case DW_TAG_pointer_type
:
7796 this_type
= read_tag_pointer_type (die
, cu
);
7798 case DW_TAG_ptr_to_member_type
:
7799 this_type
= read_tag_ptr_to_member_type (die
, cu
);
7801 case DW_TAG_reference_type
:
7802 this_type
= read_tag_reference_type (die
, cu
);
7804 case DW_TAG_const_type
:
7805 this_type
= read_tag_const_type (die
, cu
);
7807 case DW_TAG_volatile_type
:
7808 this_type
= read_tag_volatile_type (die
, cu
);
7810 case DW_TAG_string_type
:
7811 this_type
= read_tag_string_type (die
, cu
);
7813 case DW_TAG_typedef
:
7814 this_type
= read_typedef (die
, cu
);
7816 case DW_TAG_subrange_type
:
7817 this_type
= read_subrange_type (die
, cu
);
7819 case DW_TAG_base_type
:
7820 this_type
= read_base_type (die
, cu
);
7822 case DW_TAG_unspecified_type
:
7823 this_type
= read_unspecified_type (die
, cu
);
7825 case DW_TAG_namespace
:
7826 this_type
= read_namespace_type (die
, cu
);
7829 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
7830 dwarf_tag_name (die
->tag
));
7837 /* Return the name of the namespace/class that DIE is defined within,
7838 or "" if we can't tell. The caller should not xfree the result.
7840 For example, if we're within the method foo() in the following
7850 then determine_prefix on foo's die will return "N::C". */
7853 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
7855 struct die_info
*parent
, *spec_die
;
7856 struct dwarf2_cu
*spec_cu
;
7857 struct type
*parent_type
;
7859 if (cu
->language
!= language_cplus
7860 && cu
->language
!= language_java
)
7863 /* We have to be careful in the presence of DW_AT_specification.
7864 For example, with GCC 3.4, given the code
7868 // Definition of N::foo.
7872 then we'll have a tree of DIEs like this:
7874 1: DW_TAG_compile_unit
7875 2: DW_TAG_namespace // N
7876 3: DW_TAG_subprogram // declaration of N::foo
7877 4: DW_TAG_subprogram // definition of N::foo
7878 DW_AT_specification // refers to die #3
7880 Thus, when processing die #4, we have to pretend that we're in
7881 the context of its DW_AT_specification, namely the contex of die
7884 spec_die
= die_specification (die
, &spec_cu
);
7885 if (spec_die
== NULL
)
7886 parent
= die
->parent
;
7889 parent
= spec_die
->parent
;
7896 switch (parent
->tag
)
7898 case DW_TAG_namespace
:
7899 parent_type
= read_type_die (parent
, cu
);
7900 /* We give a name to even anonymous namespaces. */
7901 return TYPE_TAG_NAME (parent_type
);
7902 case DW_TAG_class_type
:
7903 case DW_TAG_interface_type
:
7904 case DW_TAG_structure_type
:
7905 case DW_TAG_union_type
:
7906 parent_type
= read_type_die (parent
, cu
);
7907 if (TYPE_TAG_NAME (parent_type
) != NULL
)
7908 return TYPE_TAG_NAME (parent_type
);
7910 /* An anonymous structure is only allowed non-static data
7911 members; no typedefs, no member functions, et cetera.
7912 So it does not need a prefix. */
7915 return determine_prefix (parent
, cu
);
7919 /* Return a newly-allocated string formed by concatenating PREFIX and
7920 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
7921 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
7922 perform an obconcat, otherwise allocate storage for the result. The CU argument
7923 is used to determine the language and hence, the appropriate separator. */
7925 #define MAX_SEP_LEN 2 /* sizeof ("::") */
7928 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
7929 struct dwarf2_cu
*cu
)
7933 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
7935 else if (cu
->language
== language_java
)
7942 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
7947 strcpy (retval
, prefix
);
7948 strcat (retval
, sep
);
7951 strcat (retval
, suffix
);
7957 /* We have an obstack. */
7958 return obconcat (obs
, prefix
, sep
, suffix
);
7962 /* Return sibling of die, NULL if no sibling. */
7964 static struct die_info
*
7965 sibling_die (struct die_info
*die
)
7967 return die
->sibling
;
7970 /* Get linkage name of a die, return NULL if not found. */
7973 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
7975 struct attribute
*attr
;
7977 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7978 if (attr
&& DW_STRING (attr
))
7979 return DW_STRING (attr
);
7980 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7981 if (attr
&& DW_STRING (attr
))
7982 return DW_STRING (attr
);
7986 /* Get name of a die, return NULL if not found. */
7989 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
7991 struct attribute
*attr
;
7993 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7994 if (attr
&& DW_STRING (attr
))
7995 return DW_STRING (attr
);
7999 /* Return the die that this die in an extension of, or NULL if there
8000 is none. *EXT_CU is the CU containing DIE on input, and the CU
8001 containing the return value on output. */
8003 static struct die_info
*
8004 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
8006 struct attribute
*attr
;
8008 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
8012 return follow_die_ref (die
, attr
, ext_cu
);
8015 /* Convert a DIE tag into its string name. */
8018 dwarf_tag_name (unsigned tag
)
8022 case DW_TAG_padding
:
8023 return "DW_TAG_padding";
8024 case DW_TAG_array_type
:
8025 return "DW_TAG_array_type";
8026 case DW_TAG_class_type
:
8027 return "DW_TAG_class_type";
8028 case DW_TAG_entry_point
:
8029 return "DW_TAG_entry_point";
8030 case DW_TAG_enumeration_type
:
8031 return "DW_TAG_enumeration_type";
8032 case DW_TAG_formal_parameter
:
8033 return "DW_TAG_formal_parameter";
8034 case DW_TAG_imported_declaration
:
8035 return "DW_TAG_imported_declaration";
8037 return "DW_TAG_label";
8038 case DW_TAG_lexical_block
:
8039 return "DW_TAG_lexical_block";
8041 return "DW_TAG_member";
8042 case DW_TAG_pointer_type
:
8043 return "DW_TAG_pointer_type";
8044 case DW_TAG_reference_type
:
8045 return "DW_TAG_reference_type";
8046 case DW_TAG_compile_unit
:
8047 return "DW_TAG_compile_unit";
8048 case DW_TAG_string_type
:
8049 return "DW_TAG_string_type";
8050 case DW_TAG_structure_type
:
8051 return "DW_TAG_structure_type";
8052 case DW_TAG_subroutine_type
:
8053 return "DW_TAG_subroutine_type";
8054 case DW_TAG_typedef
:
8055 return "DW_TAG_typedef";
8056 case DW_TAG_union_type
:
8057 return "DW_TAG_union_type";
8058 case DW_TAG_unspecified_parameters
:
8059 return "DW_TAG_unspecified_parameters";
8060 case DW_TAG_variant
:
8061 return "DW_TAG_variant";
8062 case DW_TAG_common_block
:
8063 return "DW_TAG_common_block";
8064 case DW_TAG_common_inclusion
:
8065 return "DW_TAG_common_inclusion";
8066 case DW_TAG_inheritance
:
8067 return "DW_TAG_inheritance";
8068 case DW_TAG_inlined_subroutine
:
8069 return "DW_TAG_inlined_subroutine";
8071 return "DW_TAG_module";
8072 case DW_TAG_ptr_to_member_type
:
8073 return "DW_TAG_ptr_to_member_type";
8074 case DW_TAG_set_type
:
8075 return "DW_TAG_set_type";
8076 case DW_TAG_subrange_type
:
8077 return "DW_TAG_subrange_type";
8078 case DW_TAG_with_stmt
:
8079 return "DW_TAG_with_stmt";
8080 case DW_TAG_access_declaration
:
8081 return "DW_TAG_access_declaration";
8082 case DW_TAG_base_type
:
8083 return "DW_TAG_base_type";
8084 case DW_TAG_catch_block
:
8085 return "DW_TAG_catch_block";
8086 case DW_TAG_const_type
:
8087 return "DW_TAG_const_type";
8088 case DW_TAG_constant
:
8089 return "DW_TAG_constant";
8090 case DW_TAG_enumerator
:
8091 return "DW_TAG_enumerator";
8092 case DW_TAG_file_type
:
8093 return "DW_TAG_file_type";
8095 return "DW_TAG_friend";
8096 case DW_TAG_namelist
:
8097 return "DW_TAG_namelist";
8098 case DW_TAG_namelist_item
:
8099 return "DW_TAG_namelist_item";
8100 case DW_TAG_packed_type
:
8101 return "DW_TAG_packed_type";
8102 case DW_TAG_subprogram
:
8103 return "DW_TAG_subprogram";
8104 case DW_TAG_template_type_param
:
8105 return "DW_TAG_template_type_param";
8106 case DW_TAG_template_value_param
:
8107 return "DW_TAG_template_value_param";
8108 case DW_TAG_thrown_type
:
8109 return "DW_TAG_thrown_type";
8110 case DW_TAG_try_block
:
8111 return "DW_TAG_try_block";
8112 case DW_TAG_variant_part
:
8113 return "DW_TAG_variant_part";
8114 case DW_TAG_variable
:
8115 return "DW_TAG_variable";
8116 case DW_TAG_volatile_type
:
8117 return "DW_TAG_volatile_type";
8118 case DW_TAG_dwarf_procedure
:
8119 return "DW_TAG_dwarf_procedure";
8120 case DW_TAG_restrict_type
:
8121 return "DW_TAG_restrict_type";
8122 case DW_TAG_interface_type
:
8123 return "DW_TAG_interface_type";
8124 case DW_TAG_namespace
:
8125 return "DW_TAG_namespace";
8126 case DW_TAG_imported_module
:
8127 return "DW_TAG_imported_module";
8128 case DW_TAG_unspecified_type
:
8129 return "DW_TAG_unspecified_type";
8130 case DW_TAG_partial_unit
:
8131 return "DW_TAG_partial_unit";
8132 case DW_TAG_imported_unit
:
8133 return "DW_TAG_imported_unit";
8134 case DW_TAG_condition
:
8135 return "DW_TAG_condition";
8136 case DW_TAG_shared_type
:
8137 return "DW_TAG_shared_type";
8138 case DW_TAG_MIPS_loop
:
8139 return "DW_TAG_MIPS_loop";
8140 case DW_TAG_HP_array_descriptor
:
8141 return "DW_TAG_HP_array_descriptor";
8142 case DW_TAG_format_label
:
8143 return "DW_TAG_format_label";
8144 case DW_TAG_function_template
:
8145 return "DW_TAG_function_template";
8146 case DW_TAG_class_template
:
8147 return "DW_TAG_class_template";
8148 case DW_TAG_GNU_BINCL
:
8149 return "DW_TAG_GNU_BINCL";
8150 case DW_TAG_GNU_EINCL
:
8151 return "DW_TAG_GNU_EINCL";
8152 case DW_TAG_upc_shared_type
:
8153 return "DW_TAG_upc_shared_type";
8154 case DW_TAG_upc_strict_type
:
8155 return "DW_TAG_upc_strict_type";
8156 case DW_TAG_upc_relaxed_type
:
8157 return "DW_TAG_upc_relaxed_type";
8158 case DW_TAG_PGI_kanji_type
:
8159 return "DW_TAG_PGI_kanji_type";
8160 case DW_TAG_PGI_interface_block
:
8161 return "DW_TAG_PGI_interface_block";
8163 return "DW_TAG_<unknown>";
8167 /* Convert a DWARF attribute code into its string name. */
8170 dwarf_attr_name (unsigned attr
)
8175 return "DW_AT_sibling";
8176 case DW_AT_location
:
8177 return "DW_AT_location";
8179 return "DW_AT_name";
8180 case DW_AT_ordering
:
8181 return "DW_AT_ordering";
8182 case DW_AT_subscr_data
:
8183 return "DW_AT_subscr_data";
8184 case DW_AT_byte_size
:
8185 return "DW_AT_byte_size";
8186 case DW_AT_bit_offset
:
8187 return "DW_AT_bit_offset";
8188 case DW_AT_bit_size
:
8189 return "DW_AT_bit_size";
8190 case DW_AT_element_list
:
8191 return "DW_AT_element_list";
8192 case DW_AT_stmt_list
:
8193 return "DW_AT_stmt_list";
8195 return "DW_AT_low_pc";
8197 return "DW_AT_high_pc";
8198 case DW_AT_language
:
8199 return "DW_AT_language";
8201 return "DW_AT_member";
8203 return "DW_AT_discr";
8204 case DW_AT_discr_value
:
8205 return "DW_AT_discr_value";
8206 case DW_AT_visibility
:
8207 return "DW_AT_visibility";
8209 return "DW_AT_import";
8210 case DW_AT_string_length
:
8211 return "DW_AT_string_length";
8212 case DW_AT_common_reference
:
8213 return "DW_AT_common_reference";
8214 case DW_AT_comp_dir
:
8215 return "DW_AT_comp_dir";
8216 case DW_AT_const_value
:
8217 return "DW_AT_const_value";
8218 case DW_AT_containing_type
:
8219 return "DW_AT_containing_type";
8220 case DW_AT_default_value
:
8221 return "DW_AT_default_value";
8223 return "DW_AT_inline";
8224 case DW_AT_is_optional
:
8225 return "DW_AT_is_optional";
8226 case DW_AT_lower_bound
:
8227 return "DW_AT_lower_bound";
8228 case DW_AT_producer
:
8229 return "DW_AT_producer";
8230 case DW_AT_prototyped
:
8231 return "DW_AT_prototyped";
8232 case DW_AT_return_addr
:
8233 return "DW_AT_return_addr";
8234 case DW_AT_start_scope
:
8235 return "DW_AT_start_scope";
8236 case DW_AT_bit_stride
:
8237 return "DW_AT_bit_stride";
8238 case DW_AT_upper_bound
:
8239 return "DW_AT_upper_bound";
8240 case DW_AT_abstract_origin
:
8241 return "DW_AT_abstract_origin";
8242 case DW_AT_accessibility
:
8243 return "DW_AT_accessibility";
8244 case DW_AT_address_class
:
8245 return "DW_AT_address_class";
8246 case DW_AT_artificial
:
8247 return "DW_AT_artificial";
8248 case DW_AT_base_types
:
8249 return "DW_AT_base_types";
8250 case DW_AT_calling_convention
:
8251 return "DW_AT_calling_convention";
8253 return "DW_AT_count";
8254 case DW_AT_data_member_location
:
8255 return "DW_AT_data_member_location";
8256 case DW_AT_decl_column
:
8257 return "DW_AT_decl_column";
8258 case DW_AT_decl_file
:
8259 return "DW_AT_decl_file";
8260 case DW_AT_decl_line
:
8261 return "DW_AT_decl_line";
8262 case DW_AT_declaration
:
8263 return "DW_AT_declaration";
8264 case DW_AT_discr_list
:
8265 return "DW_AT_discr_list";
8266 case DW_AT_encoding
:
8267 return "DW_AT_encoding";
8268 case DW_AT_external
:
8269 return "DW_AT_external";
8270 case DW_AT_frame_base
:
8271 return "DW_AT_frame_base";
8273 return "DW_AT_friend";
8274 case DW_AT_identifier_case
:
8275 return "DW_AT_identifier_case";
8276 case DW_AT_macro_info
:
8277 return "DW_AT_macro_info";
8278 case DW_AT_namelist_items
:
8279 return "DW_AT_namelist_items";
8280 case DW_AT_priority
:
8281 return "DW_AT_priority";
8283 return "DW_AT_segment";
8284 case DW_AT_specification
:
8285 return "DW_AT_specification";
8286 case DW_AT_static_link
:
8287 return "DW_AT_static_link";
8289 return "DW_AT_type";
8290 case DW_AT_use_location
:
8291 return "DW_AT_use_location";
8292 case DW_AT_variable_parameter
:
8293 return "DW_AT_variable_parameter";
8294 case DW_AT_virtuality
:
8295 return "DW_AT_virtuality";
8296 case DW_AT_vtable_elem_location
:
8297 return "DW_AT_vtable_elem_location";
8298 /* DWARF 3 values. */
8299 case DW_AT_allocated
:
8300 return "DW_AT_allocated";
8301 case DW_AT_associated
:
8302 return "DW_AT_associated";
8303 case DW_AT_data_location
:
8304 return "DW_AT_data_location";
8305 case DW_AT_byte_stride
:
8306 return "DW_AT_byte_stride";
8307 case DW_AT_entry_pc
:
8308 return "DW_AT_entry_pc";
8309 case DW_AT_use_UTF8
:
8310 return "DW_AT_use_UTF8";
8311 case DW_AT_extension
:
8312 return "DW_AT_extension";
8314 return "DW_AT_ranges";
8315 case DW_AT_trampoline
:
8316 return "DW_AT_trampoline";
8317 case DW_AT_call_column
:
8318 return "DW_AT_call_column";
8319 case DW_AT_call_file
:
8320 return "DW_AT_call_file";
8321 case DW_AT_call_line
:
8322 return "DW_AT_call_line";
8323 case DW_AT_description
:
8324 return "DW_AT_description";
8325 case DW_AT_binary_scale
:
8326 return "DW_AT_binary_scale";
8327 case DW_AT_decimal_scale
:
8328 return "DW_AT_decimal_scale";
8330 return "DW_AT_small";
8331 case DW_AT_decimal_sign
:
8332 return "DW_AT_decimal_sign";
8333 case DW_AT_digit_count
:
8334 return "DW_AT_digit_count";
8335 case DW_AT_picture_string
:
8336 return "DW_AT_picture_string";
8338 return "DW_AT_mutable";
8339 case DW_AT_threads_scaled
:
8340 return "DW_AT_threads_scaled";
8341 case DW_AT_explicit
:
8342 return "DW_AT_explicit";
8343 case DW_AT_object_pointer
:
8344 return "DW_AT_object_pointer";
8345 case DW_AT_endianity
:
8346 return "DW_AT_endianity";
8347 case DW_AT_elemental
:
8348 return "DW_AT_elemental";
8350 return "DW_AT_pure";
8351 case DW_AT_recursive
:
8352 return "DW_AT_recursive";
8354 /* SGI/MIPS extensions. */
8355 case DW_AT_MIPS_fde
:
8356 return "DW_AT_MIPS_fde";
8357 case DW_AT_MIPS_loop_begin
:
8358 return "DW_AT_MIPS_loop_begin";
8359 case DW_AT_MIPS_tail_loop_begin
:
8360 return "DW_AT_MIPS_tail_loop_begin";
8361 case DW_AT_MIPS_epilog_begin
:
8362 return "DW_AT_MIPS_epilog_begin";
8363 case DW_AT_MIPS_loop_unroll_factor
:
8364 return "DW_AT_MIPS_loop_unroll_factor";
8365 case DW_AT_MIPS_software_pipeline_depth
:
8366 return "DW_AT_MIPS_software_pipeline_depth";
8367 case DW_AT_MIPS_linkage_name
:
8368 return "DW_AT_MIPS_linkage_name";
8369 case DW_AT_MIPS_stride
:
8370 return "DW_AT_MIPS_stride";
8371 case DW_AT_MIPS_abstract_name
:
8372 return "DW_AT_MIPS_abstract_name";
8373 case DW_AT_MIPS_clone_origin
:
8374 return "DW_AT_MIPS_clone_origin";
8375 case DW_AT_MIPS_has_inlines
:
8376 return "DW_AT_MIPS_has_inlines";
8378 /* HP extensions. */
8379 case DW_AT_HP_block_index
:
8380 return "DW_AT_HP_block_index";
8381 case DW_AT_HP_unmodifiable
:
8382 return "DW_AT_HP_unmodifiable";
8383 case DW_AT_HP_actuals_stmt_list
:
8384 return "DW_AT_HP_actuals_stmt_list";
8385 case DW_AT_HP_proc_per_section
:
8386 return "DW_AT_HP_proc_per_section";
8387 case DW_AT_HP_raw_data_ptr
:
8388 return "DW_AT_HP_raw_data_ptr";
8389 case DW_AT_HP_pass_by_reference
:
8390 return "DW_AT_HP_pass_by_reference";
8391 case DW_AT_HP_opt_level
:
8392 return "DW_AT_HP_opt_level";
8393 case DW_AT_HP_prof_version_id
:
8394 return "DW_AT_HP_prof_version_id";
8395 case DW_AT_HP_opt_flags
:
8396 return "DW_AT_HP_opt_flags";
8397 case DW_AT_HP_cold_region_low_pc
:
8398 return "DW_AT_HP_cold_region_low_pc";
8399 case DW_AT_HP_cold_region_high_pc
:
8400 return "DW_AT_HP_cold_region_high_pc";
8401 case DW_AT_HP_all_variables_modifiable
:
8402 return "DW_AT_HP_all_variables_modifiable";
8403 case DW_AT_HP_linkage_name
:
8404 return "DW_AT_HP_linkage_name";
8405 case DW_AT_HP_prof_flags
:
8406 return "DW_AT_HP_prof_flags";
8407 /* GNU extensions. */
8408 case DW_AT_sf_names
:
8409 return "DW_AT_sf_names";
8410 case DW_AT_src_info
:
8411 return "DW_AT_src_info";
8412 case DW_AT_mac_info
:
8413 return "DW_AT_mac_info";
8414 case DW_AT_src_coords
:
8415 return "DW_AT_src_coords";
8416 case DW_AT_body_begin
:
8417 return "DW_AT_body_begin";
8418 case DW_AT_body_end
:
8419 return "DW_AT_body_end";
8420 case DW_AT_GNU_vector
:
8421 return "DW_AT_GNU_vector";
8422 /* VMS extensions. */
8423 case DW_AT_VMS_rtnbeg_pd_address
:
8424 return "DW_AT_VMS_rtnbeg_pd_address";
8425 /* UPC extension. */
8426 case DW_AT_upc_threads_scaled
:
8427 return "DW_AT_upc_threads_scaled";
8428 /* PGI (STMicroelectronics) extensions. */
8429 case DW_AT_PGI_lbase
:
8430 return "DW_AT_PGI_lbase";
8431 case DW_AT_PGI_soffset
:
8432 return "DW_AT_PGI_soffset";
8433 case DW_AT_PGI_lstride
:
8434 return "DW_AT_PGI_lstride";
8436 return "DW_AT_<unknown>";
8440 /* Convert a DWARF value form code into its string name. */
8443 dwarf_form_name (unsigned form
)
8448 return "DW_FORM_addr";
8449 case DW_FORM_block2
:
8450 return "DW_FORM_block2";
8451 case DW_FORM_block4
:
8452 return "DW_FORM_block4";
8454 return "DW_FORM_data2";
8456 return "DW_FORM_data4";
8458 return "DW_FORM_data8";
8459 case DW_FORM_string
:
8460 return "DW_FORM_string";
8462 return "DW_FORM_block";
8463 case DW_FORM_block1
:
8464 return "DW_FORM_block1";
8466 return "DW_FORM_data1";
8468 return "DW_FORM_flag";
8470 return "DW_FORM_sdata";
8472 return "DW_FORM_strp";
8474 return "DW_FORM_udata";
8475 case DW_FORM_ref_addr
:
8476 return "DW_FORM_ref_addr";
8478 return "DW_FORM_ref1";
8480 return "DW_FORM_ref2";
8482 return "DW_FORM_ref4";
8484 return "DW_FORM_ref8";
8485 case DW_FORM_ref_udata
:
8486 return "DW_FORM_ref_udata";
8487 case DW_FORM_indirect
:
8488 return "DW_FORM_indirect";
8490 return "DW_FORM_<unknown>";
8494 /* Convert a DWARF stack opcode into its string name. */
8497 dwarf_stack_op_name (unsigned op
)
8502 return "DW_OP_addr";
8504 return "DW_OP_deref";
8506 return "DW_OP_const1u";
8508 return "DW_OP_const1s";
8510 return "DW_OP_const2u";
8512 return "DW_OP_const2s";
8514 return "DW_OP_const4u";
8516 return "DW_OP_const4s";
8518 return "DW_OP_const8u";
8520 return "DW_OP_const8s";
8522 return "DW_OP_constu";
8524 return "DW_OP_consts";
8528 return "DW_OP_drop";
8530 return "DW_OP_over";
8532 return "DW_OP_pick";
8534 return "DW_OP_swap";
8538 return "DW_OP_xderef";
8546 return "DW_OP_minus";
8558 return "DW_OP_plus";
8559 case DW_OP_plus_uconst
:
8560 return "DW_OP_plus_uconst";
8566 return "DW_OP_shra";
8584 return "DW_OP_skip";
8586 return "DW_OP_lit0";
8588 return "DW_OP_lit1";
8590 return "DW_OP_lit2";
8592 return "DW_OP_lit3";
8594 return "DW_OP_lit4";
8596 return "DW_OP_lit5";
8598 return "DW_OP_lit6";
8600 return "DW_OP_lit7";
8602 return "DW_OP_lit8";
8604 return "DW_OP_lit9";
8606 return "DW_OP_lit10";
8608 return "DW_OP_lit11";
8610 return "DW_OP_lit12";
8612 return "DW_OP_lit13";
8614 return "DW_OP_lit14";
8616 return "DW_OP_lit15";
8618 return "DW_OP_lit16";
8620 return "DW_OP_lit17";
8622 return "DW_OP_lit18";
8624 return "DW_OP_lit19";
8626 return "DW_OP_lit20";
8628 return "DW_OP_lit21";
8630 return "DW_OP_lit22";
8632 return "DW_OP_lit23";
8634 return "DW_OP_lit24";
8636 return "DW_OP_lit25";
8638 return "DW_OP_lit26";
8640 return "DW_OP_lit27";
8642 return "DW_OP_lit28";
8644 return "DW_OP_lit29";
8646 return "DW_OP_lit30";
8648 return "DW_OP_lit31";
8650 return "DW_OP_reg0";
8652 return "DW_OP_reg1";
8654 return "DW_OP_reg2";
8656 return "DW_OP_reg3";
8658 return "DW_OP_reg4";
8660 return "DW_OP_reg5";
8662 return "DW_OP_reg6";
8664 return "DW_OP_reg7";
8666 return "DW_OP_reg8";
8668 return "DW_OP_reg9";
8670 return "DW_OP_reg10";
8672 return "DW_OP_reg11";
8674 return "DW_OP_reg12";
8676 return "DW_OP_reg13";
8678 return "DW_OP_reg14";
8680 return "DW_OP_reg15";
8682 return "DW_OP_reg16";
8684 return "DW_OP_reg17";
8686 return "DW_OP_reg18";
8688 return "DW_OP_reg19";
8690 return "DW_OP_reg20";
8692 return "DW_OP_reg21";
8694 return "DW_OP_reg22";
8696 return "DW_OP_reg23";
8698 return "DW_OP_reg24";
8700 return "DW_OP_reg25";
8702 return "DW_OP_reg26";
8704 return "DW_OP_reg27";
8706 return "DW_OP_reg28";
8708 return "DW_OP_reg29";
8710 return "DW_OP_reg30";
8712 return "DW_OP_reg31";
8714 return "DW_OP_breg0";
8716 return "DW_OP_breg1";
8718 return "DW_OP_breg2";
8720 return "DW_OP_breg3";
8722 return "DW_OP_breg4";
8724 return "DW_OP_breg5";
8726 return "DW_OP_breg6";
8728 return "DW_OP_breg7";
8730 return "DW_OP_breg8";
8732 return "DW_OP_breg9";
8734 return "DW_OP_breg10";
8736 return "DW_OP_breg11";
8738 return "DW_OP_breg12";
8740 return "DW_OP_breg13";
8742 return "DW_OP_breg14";
8744 return "DW_OP_breg15";
8746 return "DW_OP_breg16";
8748 return "DW_OP_breg17";
8750 return "DW_OP_breg18";
8752 return "DW_OP_breg19";
8754 return "DW_OP_breg20";
8756 return "DW_OP_breg21";
8758 return "DW_OP_breg22";
8760 return "DW_OP_breg23";
8762 return "DW_OP_breg24";
8764 return "DW_OP_breg25";
8766 return "DW_OP_breg26";
8768 return "DW_OP_breg27";
8770 return "DW_OP_breg28";
8772 return "DW_OP_breg29";
8774 return "DW_OP_breg30";
8776 return "DW_OP_breg31";
8778 return "DW_OP_regx";
8780 return "DW_OP_fbreg";
8782 return "DW_OP_bregx";
8784 return "DW_OP_piece";
8785 case DW_OP_deref_size
:
8786 return "DW_OP_deref_size";
8787 case DW_OP_xderef_size
:
8788 return "DW_OP_xderef_size";
8791 /* DWARF 3 extensions. */
8792 case DW_OP_push_object_address
:
8793 return "DW_OP_push_object_address";
8795 return "DW_OP_call2";
8797 return "DW_OP_call4";
8798 case DW_OP_call_ref
:
8799 return "DW_OP_call_ref";
8800 /* GNU extensions. */
8801 case DW_OP_form_tls_address
:
8802 return "DW_OP_form_tls_address";
8803 case DW_OP_call_frame_cfa
:
8804 return "DW_OP_call_frame_cfa";
8805 case DW_OP_bit_piece
:
8806 return "DW_OP_bit_piece";
8807 case DW_OP_GNU_push_tls_address
:
8808 return "DW_OP_GNU_push_tls_address";
8809 case DW_OP_GNU_uninit
:
8810 return "DW_OP_GNU_uninit";
8811 /* HP extensions. */
8812 case DW_OP_HP_is_value
:
8813 return "DW_OP_HP_is_value";
8814 case DW_OP_HP_fltconst4
:
8815 return "DW_OP_HP_fltconst4";
8816 case DW_OP_HP_fltconst8
:
8817 return "DW_OP_HP_fltconst8";
8818 case DW_OP_HP_mod_range
:
8819 return "DW_OP_HP_mod_range";
8820 case DW_OP_HP_unmod_range
:
8821 return "DW_OP_HP_unmod_range";
8823 return "DW_OP_HP_tls";
8825 return "OP_<unknown>";
8830 dwarf_bool_name (unsigned mybool
)
8838 /* Convert a DWARF type code into its string name. */
8841 dwarf_type_encoding_name (unsigned enc
)
8846 return "DW_ATE_void";
8847 case DW_ATE_address
:
8848 return "DW_ATE_address";
8849 case DW_ATE_boolean
:
8850 return "DW_ATE_boolean";
8851 case DW_ATE_complex_float
:
8852 return "DW_ATE_complex_float";
8854 return "DW_ATE_float";
8856 return "DW_ATE_signed";
8857 case DW_ATE_signed_char
:
8858 return "DW_ATE_signed_char";
8859 case DW_ATE_unsigned
:
8860 return "DW_ATE_unsigned";
8861 case DW_ATE_unsigned_char
:
8862 return "DW_ATE_unsigned_char";
8864 case DW_ATE_imaginary_float
:
8865 return "DW_ATE_imaginary_float";
8866 case DW_ATE_packed_decimal
:
8867 return "DW_ATE_packed_decimal";
8868 case DW_ATE_numeric_string
:
8869 return "DW_ATE_numeric_string";
8871 return "DW_ATE_edited";
8872 case DW_ATE_signed_fixed
:
8873 return "DW_ATE_signed_fixed";
8874 case DW_ATE_unsigned_fixed
:
8875 return "DW_ATE_unsigned_fixed";
8876 case DW_ATE_decimal_float
:
8877 return "DW_ATE_decimal_float";
8878 /* HP extensions. */
8879 case DW_ATE_HP_float80
:
8880 return "DW_ATE_HP_float80";
8881 case DW_ATE_HP_complex_float80
:
8882 return "DW_ATE_HP_complex_float80";
8883 case DW_ATE_HP_float128
:
8884 return "DW_ATE_HP_float128";
8885 case DW_ATE_HP_complex_float128
:
8886 return "DW_ATE_HP_complex_float128";
8887 case DW_ATE_HP_floathpintel
:
8888 return "DW_ATE_HP_floathpintel";
8889 case DW_ATE_HP_imaginary_float80
:
8890 return "DW_ATE_HP_imaginary_float80";
8891 case DW_ATE_HP_imaginary_float128
:
8892 return "DW_ATE_HP_imaginary_float128";
8894 return "DW_ATE_<unknown>";
8898 /* Convert a DWARF call frame info operation to its string name. */
8902 dwarf_cfi_name (unsigned cfi_opc
)
8906 case DW_CFA_advance_loc
:
8907 return "DW_CFA_advance_loc";
8909 return "DW_CFA_offset";
8910 case DW_CFA_restore
:
8911 return "DW_CFA_restore";
8913 return "DW_CFA_nop";
8914 case DW_CFA_set_loc
:
8915 return "DW_CFA_set_loc";
8916 case DW_CFA_advance_loc1
:
8917 return "DW_CFA_advance_loc1";
8918 case DW_CFA_advance_loc2
:
8919 return "DW_CFA_advance_loc2";
8920 case DW_CFA_advance_loc4
:
8921 return "DW_CFA_advance_loc4";
8922 case DW_CFA_offset_extended
:
8923 return "DW_CFA_offset_extended";
8924 case DW_CFA_restore_extended
:
8925 return "DW_CFA_restore_extended";
8926 case DW_CFA_undefined
:
8927 return "DW_CFA_undefined";
8928 case DW_CFA_same_value
:
8929 return "DW_CFA_same_value";
8930 case DW_CFA_register
:
8931 return "DW_CFA_register";
8932 case DW_CFA_remember_state
:
8933 return "DW_CFA_remember_state";
8934 case DW_CFA_restore_state
:
8935 return "DW_CFA_restore_state";
8936 case DW_CFA_def_cfa
:
8937 return "DW_CFA_def_cfa";
8938 case DW_CFA_def_cfa_register
:
8939 return "DW_CFA_def_cfa_register";
8940 case DW_CFA_def_cfa_offset
:
8941 return "DW_CFA_def_cfa_offset";
8943 case DW_CFA_def_cfa_expression
:
8944 return "DW_CFA_def_cfa_expression";
8945 case DW_CFA_expression
:
8946 return "DW_CFA_expression";
8947 case DW_CFA_offset_extended_sf
:
8948 return "DW_CFA_offset_extended_sf";
8949 case DW_CFA_def_cfa_sf
:
8950 return "DW_CFA_def_cfa_sf";
8951 case DW_CFA_def_cfa_offset_sf
:
8952 return "DW_CFA_def_cfa_offset_sf";
8953 case DW_CFA_val_offset
:
8954 return "DW_CFA_val_offset";
8955 case DW_CFA_val_offset_sf
:
8956 return "DW_CFA_val_offset_sf";
8957 case DW_CFA_val_expression
:
8958 return "DW_CFA_val_expression";
8959 /* SGI/MIPS specific. */
8960 case DW_CFA_MIPS_advance_loc8
:
8961 return "DW_CFA_MIPS_advance_loc8";
8962 /* GNU extensions. */
8963 case DW_CFA_GNU_window_save
:
8964 return "DW_CFA_GNU_window_save";
8965 case DW_CFA_GNU_args_size
:
8966 return "DW_CFA_GNU_args_size";
8967 case DW_CFA_GNU_negative_offset_extended
:
8968 return "DW_CFA_GNU_negative_offset_extended";
8970 return "DW_CFA_<unknown>";
8976 dump_die (struct die_info
*die
)
8980 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
8981 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
8982 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
8983 dwarf_bool_name (die
->child
!= NULL
));
8985 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
8986 for (i
= 0; i
< die
->num_attrs
; ++i
)
8988 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
8989 dwarf_attr_name (die
->attrs
[i
].name
),
8990 dwarf_form_name (die
->attrs
[i
].form
));
8991 switch (die
->attrs
[i
].form
)
8993 case DW_FORM_ref_addr
:
8995 fprintf_unfiltered (gdb_stderr
, "address: ");
8996 fputs_filtered (paddress (DW_ADDR (&die
->attrs
[i
])), gdb_stderr
);
8998 case DW_FORM_block2
:
8999 case DW_FORM_block4
:
9001 case DW_FORM_block1
:
9002 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
9007 fprintf_unfiltered (gdb_stderr
, "constant ref: %ld (adjusted)",
9008 (long) (DW_ADDR (&die
->attrs
[i
])));
9016 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
9018 case DW_FORM_string
:
9020 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
9021 DW_STRING (&die
->attrs
[i
])
9022 ? DW_STRING (&die
->attrs
[i
]) : "");
9025 if (DW_UNSND (&die
->attrs
[i
]))
9026 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
9028 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
9030 case DW_FORM_indirect
:
9031 /* the reader will have reduced the indirect form to
9032 the "base form" so this form should not occur */
9033 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
9036 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
9037 die
->attrs
[i
].form
);
9039 fprintf_unfiltered (gdb_stderr
, "\n");
9044 dump_die_list (struct die_info
*die
)
9049 if (die
->child
!= NULL
)
9050 dump_die_list (die
->child
);
9051 if (die
->sibling
!= NULL
)
9052 dump_die_list (die
->sibling
);
9057 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
9061 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
9067 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
9069 unsigned int result
= 0;
9073 case DW_FORM_ref_addr
:
9078 case DW_FORM_ref_udata
:
9079 result
= DW_ADDR (attr
);
9082 complaint (&symfile_complaints
,
9083 _("unsupported die ref attribute form: '%s'"),
9084 dwarf_form_name (attr
->form
));
9089 /* Return the constant value held by the given attribute. Return -1
9090 if the value held by the attribute is not constant. */
9093 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
9095 if (attr
->form
== DW_FORM_sdata
)
9096 return DW_SND (attr
);
9097 else if (attr
->form
== DW_FORM_udata
9098 || attr
->form
== DW_FORM_data1
9099 || attr
->form
== DW_FORM_data2
9100 || attr
->form
== DW_FORM_data4
9101 || attr
->form
== DW_FORM_data8
)
9102 return DW_UNSND (attr
);
9105 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
9106 dwarf_form_name (attr
->form
));
9107 return default_value
;
9111 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
9112 unit and add it to our queue. */
9115 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
9116 struct dwarf2_per_cu_data
*per_cu
)
9118 /* Mark the dependence relation so that we don't flush PER_CU
9120 dwarf2_add_dependence (this_cu
, per_cu
);
9122 /* If it's already on the queue, we have nothing to do. */
9126 /* If the compilation unit is already loaded, just mark it as
9128 if (per_cu
->cu
!= NULL
)
9130 per_cu
->cu
->last_used
= 0;
9134 /* Add it to the queue. */
9135 queue_comp_unit (per_cu
, this_cu
->objfile
);
9138 static struct die_info
*
9139 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
9140 struct dwarf2_cu
**ref_cu
)
9142 struct die_info
*die
;
9143 unsigned int offset
;
9144 struct die_info temp_die
;
9145 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
9147 offset
= dwarf2_get_ref_die_offset (attr
, cu
);
9149 if (DW_ADDR (attr
) < cu
->header
.offset
9150 || DW_ADDR (attr
) >= cu
->header
.offset
+ cu
->header
.length
)
9152 struct dwarf2_per_cu_data
*per_cu
;
9153 per_cu
= dwarf2_find_containing_comp_unit (DW_ADDR (attr
),
9156 /* If necessary, add it to the queue and load its DIEs. */
9157 maybe_queue_comp_unit (cu
, per_cu
);
9159 target_cu
= per_cu
->cu
;
9164 *ref_cu
= target_cu
;
9165 temp_die
.offset
= offset
;
9166 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
9170 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
9171 "at 0x%lx [in module %s]"),
9172 (long) offset
, (long) src_die
->offset
, cu
->objfile
->name
);
9175 /* Decode simple location descriptions.
9176 Given a pointer to a dwarf block that defines a location, compute
9177 the location and return the value.
9179 NOTE drow/2003-11-18: This function is called in two situations
9180 now: for the address of static or global variables (partial symbols
9181 only) and for offsets into structures which are expected to be
9182 (more or less) constant. The partial symbol case should go away,
9183 and only the constant case should remain. That will let this
9184 function complain more accurately. A few special modes are allowed
9185 without complaint for global variables (for instance, global
9186 register values and thread-local values).
9188 A location description containing no operations indicates that the
9189 object is optimized out. The return value is 0 for that case.
9190 FIXME drow/2003-11-16: No callers check for this case any more; soon all
9191 callers will only want a very basic result and this can become a
9194 Note that stack[0] is unused except as a default error return.
9195 Note that stack overflow is not yet handled. */
9198 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
9200 struct objfile
*objfile
= cu
->objfile
;
9201 struct comp_unit_head
*cu_header
= &cu
->header
;
9203 int size
= blk
->size
;
9204 gdb_byte
*data
= blk
->data
;
9205 CORE_ADDR stack
[64];
9207 unsigned int bytes_read
, unsnd
;
9251 stack
[++stacki
] = op
- DW_OP_lit0
;
9286 stack
[++stacki
] = op
- DW_OP_reg0
;
9288 dwarf2_complex_location_expr_complaint ();
9292 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9294 stack
[++stacki
] = unsnd
;
9296 dwarf2_complex_location_expr_complaint ();
9300 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
9306 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
9311 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
9316 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
9321 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
9326 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
9331 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
9336 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
9342 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
9347 stack
[stacki
+ 1] = stack
[stacki
];
9352 stack
[stacki
- 1] += stack
[stacki
];
9356 case DW_OP_plus_uconst
:
9357 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9362 stack
[stacki
- 1] -= stack
[stacki
];
9367 /* If we're not the last op, then we definitely can't encode
9368 this using GDB's address_class enum. This is valid for partial
9369 global symbols, although the variable's address will be bogus
9372 dwarf2_complex_location_expr_complaint ();
9375 case DW_OP_GNU_push_tls_address
:
9376 /* The top of the stack has the offset from the beginning
9377 of the thread control block at which the variable is located. */
9378 /* Nothing should follow this operator, so the top of stack would
9380 /* This is valid for partial global symbols, but the variable's
9381 address will be bogus in the psymtab. */
9383 dwarf2_complex_location_expr_complaint ();
9386 case DW_OP_GNU_uninit
:
9390 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
9391 dwarf_stack_op_name (op
));
9392 return (stack
[stacki
]);
9395 return (stack
[stacki
]);
9398 /* memory allocation interface */
9400 static struct dwarf_block
*
9401 dwarf_alloc_block (struct dwarf2_cu
*cu
)
9403 struct dwarf_block
*blk
;
9405 blk
= (struct dwarf_block
*)
9406 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
9410 static struct abbrev_info
*
9411 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
9413 struct abbrev_info
*abbrev
;
9415 abbrev
= (struct abbrev_info
*)
9416 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
9417 memset (abbrev
, 0, sizeof (struct abbrev_info
));
9421 static struct die_info
*
9422 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
9424 struct die_info
*die
;
9425 size_t size
= sizeof (struct die_info
);
9428 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
9430 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
9431 memset (die
, 0, sizeof (struct die_info
));
9436 /* Macro support. */
9439 /* Return the full name of file number I in *LH's file name table.
9440 Use COMP_DIR as the name of the current directory of the
9441 compilation. The result is allocated using xmalloc; the caller is
9442 responsible for freeing it. */
9444 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
9446 /* Is the file number a valid index into the line header's file name
9447 table? Remember that file numbers start with one, not zero. */
9448 if (1 <= file
&& file
<= lh
->num_file_names
)
9450 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9452 if (IS_ABSOLUTE_PATH (fe
->name
))
9453 return xstrdup (fe
->name
);
9461 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9467 dir_len
= strlen (dir
);
9468 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
9469 strcpy (full_name
, dir
);
9470 full_name
[dir_len
] = '/';
9471 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
9475 return xstrdup (fe
->name
);
9480 /* The compiler produced a bogus file number. We can at least
9481 record the macro definitions made in the file, even if we
9482 won't be able to find the file by name. */
9484 sprintf (fake_name
, "<bad macro file number %d>", file
);
9486 complaint (&symfile_complaints
,
9487 _("bad file number in macro information (%d)"),
9490 return xstrdup (fake_name
);
9495 static struct macro_source_file
*
9496 macro_start_file (int file
, int line
,
9497 struct macro_source_file
*current_file
,
9498 const char *comp_dir
,
9499 struct line_header
*lh
, struct objfile
*objfile
)
9501 /* The full name of this source file. */
9502 char *full_name
= file_full_name (file
, lh
, comp_dir
);
9504 /* We don't create a macro table for this compilation unit
9505 at all until we actually get a filename. */
9506 if (! pending_macros
)
9507 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
9508 objfile
->macro_cache
);
9511 /* If we have no current file, then this must be the start_file
9512 directive for the compilation unit's main source file. */
9513 current_file
= macro_set_main (pending_macros
, full_name
);
9515 current_file
= macro_include (current_file
, line
, full_name
);
9519 return current_file
;
9523 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
9524 followed by a null byte. */
9526 copy_string (const char *buf
, int len
)
9528 char *s
= xmalloc (len
+ 1);
9529 memcpy (s
, buf
, len
);
9537 consume_improper_spaces (const char *p
, const char *body
)
9541 complaint (&symfile_complaints
,
9542 _("macro definition contains spaces in formal argument list:\n`%s'"),
9554 parse_macro_definition (struct macro_source_file
*file
, int line
,
9559 /* The body string takes one of two forms. For object-like macro
9560 definitions, it should be:
9562 <macro name> " " <definition>
9564 For function-like macro definitions, it should be:
9566 <macro name> "() " <definition>
9568 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
9570 Spaces may appear only where explicitly indicated, and in the
9573 The Dwarf 2 spec says that an object-like macro's name is always
9574 followed by a space, but versions of GCC around March 2002 omit
9575 the space when the macro's definition is the empty string.
9577 The Dwarf 2 spec says that there should be no spaces between the
9578 formal arguments in a function-like macro's formal argument list,
9579 but versions of GCC around March 2002 include spaces after the
9583 /* Find the extent of the macro name. The macro name is terminated
9584 by either a space or null character (for an object-like macro) or
9585 an opening paren (for a function-like macro). */
9586 for (p
= body
; *p
; p
++)
9587 if (*p
== ' ' || *p
== '(')
9590 if (*p
== ' ' || *p
== '\0')
9592 /* It's an object-like macro. */
9593 int name_len
= p
- body
;
9594 char *name
= copy_string (body
, name_len
);
9595 const char *replacement
;
9598 replacement
= body
+ name_len
+ 1;
9601 dwarf2_macro_malformed_definition_complaint (body
);
9602 replacement
= body
+ name_len
;
9605 macro_define_object (file
, line
, name
, replacement
);
9611 /* It's a function-like macro. */
9612 char *name
= copy_string (body
, p
- body
);
9615 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
9619 p
= consume_improper_spaces (p
, body
);
9621 /* Parse the formal argument list. */
9622 while (*p
&& *p
!= ')')
9624 /* Find the extent of the current argument name. */
9625 const char *arg_start
= p
;
9627 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
9630 if (! *p
|| p
== arg_start
)
9631 dwarf2_macro_malformed_definition_complaint (body
);
9634 /* Make sure argv has room for the new argument. */
9635 if (argc
>= argv_size
)
9638 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
9641 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
9644 p
= consume_improper_spaces (p
, body
);
9646 /* Consume the comma, if present. */
9651 p
= consume_improper_spaces (p
, body
);
9660 /* Perfectly formed definition, no complaints. */
9661 macro_define_function (file
, line
, name
,
9662 argc
, (const char **) argv
,
9664 else if (*p
== '\0')
9666 /* Complain, but do define it. */
9667 dwarf2_macro_malformed_definition_complaint (body
);
9668 macro_define_function (file
, line
, name
,
9669 argc
, (const char **) argv
,
9673 /* Just complain. */
9674 dwarf2_macro_malformed_definition_complaint (body
);
9677 /* Just complain. */
9678 dwarf2_macro_malformed_definition_complaint (body
);
9684 for (i
= 0; i
< argc
; i
++)
9690 dwarf2_macro_malformed_definition_complaint (body
);
9695 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
9696 char *comp_dir
, bfd
*abfd
,
9697 struct dwarf2_cu
*cu
)
9699 gdb_byte
*mac_ptr
, *mac_end
;
9700 struct macro_source_file
*current_file
= 0;
9702 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
9704 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
9708 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
9709 mac_end
= dwarf2_per_objfile
->macinfo_buffer
9710 + dwarf2_per_objfile
->macinfo_size
;
9714 enum dwarf_macinfo_record_type macinfo_type
;
9716 /* Do we at least have room for a macinfo type byte? */
9717 if (mac_ptr
>= mac_end
)
9719 dwarf2_macros_too_long_complaint ();
9723 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
9726 switch (macinfo_type
)
9728 /* A zero macinfo type indicates the end of the macro
9733 case DW_MACINFO_define
:
9734 case DW_MACINFO_undef
:
9736 unsigned int bytes_read
;
9740 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9741 mac_ptr
+= bytes_read
;
9742 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
9743 mac_ptr
+= bytes_read
;
9746 complaint (&symfile_complaints
,
9747 _("debug info gives macro %s outside of any file: %s"),
9749 DW_MACINFO_define
? "definition" : macinfo_type
==
9750 DW_MACINFO_undef
? "undefinition" :
9751 "something-or-other", body
);
9754 if (macinfo_type
== DW_MACINFO_define
)
9755 parse_macro_definition (current_file
, line
, body
);
9756 else if (macinfo_type
== DW_MACINFO_undef
)
9757 macro_undef (current_file
, line
, body
);
9762 case DW_MACINFO_start_file
:
9764 unsigned int bytes_read
;
9767 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9768 mac_ptr
+= bytes_read
;
9769 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9770 mac_ptr
+= bytes_read
;
9772 current_file
= macro_start_file (file
, line
,
9773 current_file
, comp_dir
,
9778 case DW_MACINFO_end_file
:
9780 complaint (&symfile_complaints
,
9781 _("macro debug info has an unmatched `close_file' directive"));
9784 current_file
= current_file
->included_by
;
9787 enum dwarf_macinfo_record_type next_type
;
9789 /* GCC circa March 2002 doesn't produce the zero
9790 type byte marking the end of the compilation
9791 unit. Complain if it's not there, but exit no
9794 /* Do we at least have room for a macinfo type byte? */
9795 if (mac_ptr
>= mac_end
)
9797 dwarf2_macros_too_long_complaint ();
9801 /* We don't increment mac_ptr here, so this is just
9803 next_type
= read_1_byte (abfd
, mac_ptr
);
9805 complaint (&symfile_complaints
,
9806 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
9813 case DW_MACINFO_vendor_ext
:
9815 unsigned int bytes_read
;
9819 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9820 mac_ptr
+= bytes_read
;
9821 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
9822 mac_ptr
+= bytes_read
;
9824 /* We don't recognize any vendor extensions. */
9831 /* Check if the attribute's form is a DW_FORM_block*
9832 if so return true else false. */
9834 attr_form_is_block (struct attribute
*attr
)
9836 return (attr
== NULL
? 0 :
9837 attr
->form
== DW_FORM_block1
9838 || attr
->form
== DW_FORM_block2
9839 || attr
->form
== DW_FORM_block4
9840 || attr
->form
== DW_FORM_block
);
9843 /* Return non-zero if ATTR's value is a section offset --- classes
9844 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
9845 You may use DW_UNSND (attr) to retrieve such offsets.
9847 Section 7.5.4, "Attribute Encodings", explains that no attribute
9848 may have a value that belongs to more than one of these classes; it
9849 would be ambiguous if we did, because we use the same forms for all
9852 attr_form_is_section_offset (struct attribute
*attr
)
9854 return (attr
->form
== DW_FORM_data4
9855 || attr
->form
== DW_FORM_data8
);
9859 /* Return non-zero if ATTR's value falls in the 'constant' class, or
9860 zero otherwise. When this function returns true, you can apply
9861 dwarf2_get_attr_constant_value to it.
9863 However, note that for some attributes you must check
9864 attr_form_is_section_offset before using this test. DW_FORM_data4
9865 and DW_FORM_data8 are members of both the constant class, and of
9866 the classes that contain offsets into other debug sections
9867 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
9868 that, if an attribute's can be either a constant or one of the
9869 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
9870 taken as section offsets, not constants. */
9872 attr_form_is_constant (struct attribute
*attr
)
9889 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
9890 struct dwarf2_cu
*cu
)
9892 if (attr_form_is_section_offset (attr
)
9893 /* ".debug_loc" may not exist at all, or the offset may be outside
9894 the section. If so, fall through to the complaint in the
9896 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc_size
)
9898 struct dwarf2_loclist_baton
*baton
;
9900 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9901 sizeof (struct dwarf2_loclist_baton
));
9902 baton
->per_cu
= cu
->per_cu
;
9903 gdb_assert (baton
->per_cu
);
9905 /* We don't know how long the location list is, but make sure we
9906 don't run off the edge of the section. */
9907 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
9908 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
9909 baton
->base_address
= cu
->base_address
;
9910 if (cu
->base_known
== 0)
9911 complaint (&symfile_complaints
,
9912 _("Location list used without specifying the CU base address."));
9914 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
9915 SYMBOL_LOCATION_BATON (sym
) = baton
;
9919 struct dwarf2_locexpr_baton
*baton
;
9921 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9922 sizeof (struct dwarf2_locexpr_baton
));
9923 baton
->per_cu
= cu
->per_cu
;
9924 gdb_assert (baton
->per_cu
);
9926 if (attr_form_is_block (attr
))
9928 /* Note that we're just copying the block's data pointer
9929 here, not the actual data. We're still pointing into the
9930 info_buffer for SYM's objfile; right now we never release
9931 that buffer, but when we do clean up properly this may
9933 baton
->size
= DW_BLOCK (attr
)->size
;
9934 baton
->data
= DW_BLOCK (attr
)->data
;
9938 dwarf2_invalid_attrib_class_complaint ("location description",
9939 SYMBOL_NATURAL_NAME (sym
));
9944 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
9945 SYMBOL_LOCATION_BATON (sym
) = baton
;
9949 /* Return the OBJFILE associated with the compilation unit CU. */
9952 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
9954 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
9956 /* Return the master objfile, so that we can report and look up the
9957 correct file containing this variable. */
9958 if (objfile
->separate_debug_objfile_backlink
)
9959 objfile
= objfile
->separate_debug_objfile_backlink
;
9964 /* Return the address size given in the compilation unit header for CU. */
9967 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
9970 return per_cu
->cu
->header
.addr_size
;
9973 /* If the CU is not currently read in, we re-read its header. */
9974 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
9975 struct dwarf2_per_objfile
*per_objfile
9976 = objfile_data (objfile
, dwarf2_objfile_data_key
);
9977 gdb_byte
*info_ptr
= per_objfile
->info_buffer
+ per_cu
->offset
;
9979 struct comp_unit_head cu_header
;
9980 memset (&cu_header
, 0, sizeof cu_header
);
9981 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
9982 return cu_header
.addr_size
;
9986 /* Locate the compilation unit from CU's objfile which contains the
9987 DIE at OFFSET. Raises an error on failure. */
9989 static struct dwarf2_per_cu_data
*
9990 dwarf2_find_containing_comp_unit (unsigned long offset
,
9991 struct objfile
*objfile
)
9993 struct dwarf2_per_cu_data
*this_cu
;
9997 high
= dwarf2_per_objfile
->n_comp_units
- 1;
10000 int mid
= low
+ (high
- low
) / 2;
10001 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
10006 gdb_assert (low
== high
);
10007 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
10010 error (_("Dwarf Error: could not find partial DIE containing "
10011 "offset 0x%lx [in module %s]"),
10012 (long) offset
, bfd_get_filename (objfile
->obfd
));
10014 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
10015 return dwarf2_per_objfile
->all_comp_units
[low
-1];
10019 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
10020 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
10021 && offset
>= this_cu
->offset
+ this_cu
->length
)
10022 error (_("invalid dwarf2 offset %ld"), offset
);
10023 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
10028 /* Locate the compilation unit from OBJFILE which is located at exactly
10029 OFFSET. Raises an error on failure. */
10031 static struct dwarf2_per_cu_data
*
10032 dwarf2_find_comp_unit (unsigned long offset
, struct objfile
*objfile
)
10034 struct dwarf2_per_cu_data
*this_cu
;
10035 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10036 if (this_cu
->offset
!= offset
)
10037 error (_("no compilation unit with offset %ld."), offset
);
10041 /* Release one cached compilation unit, CU. We unlink it from the tree
10042 of compilation units, but we don't remove it from the read_in_chain;
10043 the caller is responsible for that. */
10046 free_one_comp_unit (void *data
)
10048 struct dwarf2_cu
*cu
= data
;
10050 if (cu
->per_cu
!= NULL
)
10051 cu
->per_cu
->cu
= NULL
;
10054 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10059 /* This cleanup function is passed the address of a dwarf2_cu on the stack
10060 when we're finished with it. We can't free the pointer itself, but be
10061 sure to unlink it from the cache. Also release any associated storage
10062 and perform cache maintenance.
10064 Only used during partial symbol parsing. */
10067 free_stack_comp_unit (void *data
)
10069 struct dwarf2_cu
*cu
= data
;
10071 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10072 cu
->partial_dies
= NULL
;
10074 if (cu
->per_cu
!= NULL
)
10076 /* This compilation unit is on the stack in our caller, so we
10077 should not xfree it. Just unlink it. */
10078 cu
->per_cu
->cu
= NULL
;
10081 /* If we had a per-cu pointer, then we may have other compilation
10082 units loaded, so age them now. */
10083 age_cached_comp_units ();
10087 /* Free all cached compilation units. */
10090 free_cached_comp_units (void *data
)
10092 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10094 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10095 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10096 while (per_cu
!= NULL
)
10098 struct dwarf2_per_cu_data
*next_cu
;
10100 next_cu
= per_cu
->cu
->read_in_chain
;
10102 free_one_comp_unit (per_cu
->cu
);
10103 *last_chain
= next_cu
;
10109 /* Increase the age counter on each cached compilation unit, and free
10110 any that are too old. */
10113 age_cached_comp_units (void)
10115 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10117 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
10118 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10119 while (per_cu
!= NULL
)
10121 per_cu
->cu
->last_used
++;
10122 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
10123 dwarf2_mark (per_cu
->cu
);
10124 per_cu
= per_cu
->cu
->read_in_chain
;
10127 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10128 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10129 while (per_cu
!= NULL
)
10131 struct dwarf2_per_cu_data
*next_cu
;
10133 next_cu
= per_cu
->cu
->read_in_chain
;
10135 if (!per_cu
->cu
->mark
)
10137 free_one_comp_unit (per_cu
->cu
);
10138 *last_chain
= next_cu
;
10141 last_chain
= &per_cu
->cu
->read_in_chain
;
10147 /* Remove a single compilation unit from the cache. */
10150 free_one_cached_comp_unit (void *target_cu
)
10152 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10154 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10155 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10156 while (per_cu
!= NULL
)
10158 struct dwarf2_per_cu_data
*next_cu
;
10160 next_cu
= per_cu
->cu
->read_in_chain
;
10162 if (per_cu
->cu
== target_cu
)
10164 free_one_comp_unit (per_cu
->cu
);
10165 *last_chain
= next_cu
;
10169 last_chain
= &per_cu
->cu
->read_in_chain
;
10175 /* Release all extra memory associated with OBJFILE. */
10178 dwarf2_free_objfile (struct objfile
*objfile
)
10180 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
10182 if (dwarf2_per_objfile
== NULL
)
10185 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
10186 free_cached_comp_units (NULL
);
10188 /* Everything else should be on the objfile obstack. */
10191 /* A pair of DIE offset and GDB type pointer. We store these
10192 in a hash table separate from the DIEs, and preserve them
10193 when the DIEs are flushed out of cache. */
10195 struct dwarf2_offset_and_type
10197 unsigned int offset
;
10201 /* Hash function for a dwarf2_offset_and_type. */
10204 offset_and_type_hash (const void *item
)
10206 const struct dwarf2_offset_and_type
*ofs
= item
;
10207 return ofs
->offset
;
10210 /* Equality function for a dwarf2_offset_and_type. */
10213 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
10215 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
10216 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
10217 return ofs_lhs
->offset
== ofs_rhs
->offset
;
10220 /* Set the type associated with DIE to TYPE. Save it in CU's hash
10221 table if necessary. For convenience, return TYPE. */
10223 static struct type
*
10224 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10226 struct dwarf2_offset_and_type
**slot
, ofs
;
10228 if (cu
->type_hash
== NULL
)
10230 gdb_assert (cu
->per_cu
!= NULL
);
10231 cu
->per_cu
->type_hash
10232 = htab_create_alloc_ex (cu
->header
.length
/ 24,
10233 offset_and_type_hash
,
10234 offset_and_type_eq
,
10236 &cu
->objfile
->objfile_obstack
,
10237 hashtab_obstack_allocate
,
10238 dummy_obstack_deallocate
);
10239 cu
->type_hash
= cu
->per_cu
->type_hash
;
10242 ofs
.offset
= die
->offset
;
10244 slot
= (struct dwarf2_offset_and_type
**)
10245 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
10246 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
10251 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
10252 not have a saved type. */
10254 static struct type
*
10255 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10257 struct dwarf2_offset_and_type
*slot
, ofs
;
10258 htab_t type_hash
= cu
->type_hash
;
10260 if (type_hash
== NULL
)
10263 ofs
.offset
= die
->offset
;
10264 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
10271 /* Set the mark field in CU and in every other compilation unit in the
10272 cache that we must keep because we are keeping CU. */
10274 /* Add a dependence relationship from CU to REF_PER_CU. */
10277 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
10278 struct dwarf2_per_cu_data
*ref_per_cu
)
10282 if (cu
->dependencies
== NULL
)
10284 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
10285 NULL
, &cu
->comp_unit_obstack
,
10286 hashtab_obstack_allocate
,
10287 dummy_obstack_deallocate
);
10289 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
10291 *slot
= ref_per_cu
;
10294 /* Set the mark field in CU and in every other compilation unit in the
10295 cache that we must keep because we are keeping CU. */
10298 dwarf2_mark_helper (void **slot
, void *data
)
10300 struct dwarf2_per_cu_data
*per_cu
;
10302 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
10303 if (per_cu
->cu
->mark
)
10305 per_cu
->cu
->mark
= 1;
10307 if (per_cu
->cu
->dependencies
!= NULL
)
10308 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10314 dwarf2_mark (struct dwarf2_cu
*cu
)
10319 if (cu
->dependencies
!= NULL
)
10320 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10324 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
10328 per_cu
->cu
->mark
= 0;
10329 per_cu
= per_cu
->cu
->read_in_chain
;
10333 /* Trivial hash function for partial_die_info: the hash value of a DIE
10334 is its offset in .debug_info for this objfile. */
10337 partial_die_hash (const void *item
)
10339 const struct partial_die_info
*part_die
= item
;
10340 return part_die
->offset
;
10343 /* Trivial comparison function for partial_die_info structures: two DIEs
10344 are equal if they have the same offset. */
10347 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
10349 const struct partial_die_info
*part_die_lhs
= item_lhs
;
10350 const struct partial_die_info
*part_die_rhs
= item_rhs
;
10351 return part_die_lhs
->offset
== part_die_rhs
->offset
;
10354 static struct cmd_list_element
*set_dwarf2_cmdlist
;
10355 static struct cmd_list_element
*show_dwarf2_cmdlist
;
10358 set_dwarf2_cmd (char *args
, int from_tty
)
10360 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
10364 show_dwarf2_cmd (char *args
, int from_tty
)
10366 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
10369 void _initialize_dwarf2_read (void);
10372 _initialize_dwarf2_read (void)
10374 dwarf2_objfile_data_key
= register_objfile_data ();
10376 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
10377 Set DWARF 2 specific variables.\n\
10378 Configure DWARF 2 variables such as the cache size"),
10379 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
10380 0/*allow-unknown*/, &maintenance_set_cmdlist
);
10382 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
10383 Show DWARF 2 specific variables\n\
10384 Show DWARF 2 variables such as the cache size"),
10385 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
10386 0/*allow-unknown*/, &maintenance_show_cmdlist
);
10388 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
10389 &dwarf2_max_cache_age
, _("\
10390 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
10391 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
10392 A higher limit means that cached compilation units will be stored\n\
10393 in memory longer, and more total memory will be used. Zero disables\n\
10394 caching, which can slow down startup."),
10396 show_dwarf2_max_cache_age
,
10397 &set_dwarf2_cmdlist
,
10398 &show_dwarf2_cmdlist
);