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 char addr_size
;
237 unsigned char signed_addr_p
;
238 unsigned int abbrev_offset
;
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_BITFIELD(dwarf_attribute
) name
: 16;
517 ENUM_BITFIELD(dwarf_form
) form
: 16;
520 /* Attributes have a name and a value */
523 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
524 ENUM_BITFIELD(dwarf_form
) form
: 16;
528 struct dwarf_block
*blk
;
536 /* This data structure holds a complete die structure. */
539 /* DWARF-2 tag for this DIE. */
540 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
542 /* Number of attributes */
543 unsigned short num_attrs
;
548 /* Offset in .debug_info section */
551 /* The dies in a compilation unit form an n-ary tree. PARENT
552 points to this die's parent; CHILD points to the first child of
553 this node; and all the children of a given node are chained
554 together via their SIBLING fields, terminated by a die whose
556 struct die_info
*child
; /* Its first child, if any. */
557 struct die_info
*sibling
; /* Its next sibling, if any. */
558 struct die_info
*parent
; /* Its parent, if any. */
560 /* An array of attributes, with NUM_ATTRS elements. There may be
561 zero, but it's not common and zero-sized arrays are not
562 sufficiently portable C. */
563 struct attribute attrs
[1];
566 struct function_range
569 CORE_ADDR lowpc
, highpc
;
571 struct function_range
*next
;
574 /* Get at parts of an attribute structure */
576 #define DW_STRING(attr) ((attr)->u.str)
577 #define DW_UNSND(attr) ((attr)->u.unsnd)
578 #define DW_BLOCK(attr) ((attr)->u.blk)
579 #define DW_SND(attr) ((attr)->u.snd)
580 #define DW_ADDR(attr) ((attr)->u.addr)
582 /* Blocks are a bunch of untyped bytes. */
589 #ifndef ATTR_ALLOC_CHUNK
590 #define ATTR_ALLOC_CHUNK 4
593 /* Allocate fields for structs, unions and enums in this size. */
594 #ifndef DW_FIELD_ALLOC_CHUNK
595 #define DW_FIELD_ALLOC_CHUNK 4
598 /* A zeroed version of a partial die for initialization purposes. */
599 static struct partial_die_info zeroed_partial_die
;
601 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
602 but this would require a corresponding change in unpack_field_as_long
604 static int bits_per_byte
= 8;
606 /* The routines that read and process dies for a C struct or C++ class
607 pass lists of data member fields and lists of member function fields
608 in an instance of a field_info structure, as defined below. */
611 /* List of data member and baseclasses fields. */
614 struct nextfield
*next
;
621 /* Number of fields. */
624 /* Number of baseclasses. */
627 /* Set if the accesibility of one of the fields is not public. */
628 int non_public_fields
;
630 /* Member function fields array, entries are allocated in the order they
631 are encountered in the object file. */
634 struct nextfnfield
*next
;
635 struct fn_field fnfield
;
639 /* Member function fieldlist array, contains name of possibly overloaded
640 member function, number of overloaded member functions and a pointer
641 to the head of the member function field chain. */
646 struct nextfnfield
*head
;
650 /* Number of entries in the fnfieldlists array. */
654 /* One item on the queue of compilation units to read in full symbols
656 struct dwarf2_queue_item
658 struct dwarf2_per_cu_data
*per_cu
;
659 struct dwarf2_queue_item
*next
;
662 /* The current queue. */
663 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
665 /* Loaded secondary compilation units are kept in memory until they
666 have not been referenced for the processing of this many
667 compilation units. Set this to zero to disable caching. Cache
668 sizes of up to at least twenty will improve startup time for
669 typical inter-CU-reference binaries, at an obvious memory cost. */
670 static int dwarf2_max_cache_age
= 5;
672 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
673 struct cmd_list_element
*c
, const char *value
)
675 fprintf_filtered (file
, _("\
676 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
681 /* Various complaints about symbol reading that don't abort the process */
684 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
686 complaint (&symfile_complaints
,
687 _("statement list doesn't fit in .debug_line section"));
691 dwarf2_debug_line_missing_file_complaint (void)
693 complaint (&symfile_complaints
,
694 _(".debug_line section has line data without a file"));
698 dwarf2_complex_location_expr_complaint (void)
700 complaint (&symfile_complaints
, _("location expression too complex"));
704 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
707 complaint (&symfile_complaints
,
708 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
713 dwarf2_macros_too_long_complaint (void)
715 complaint (&symfile_complaints
,
716 _("macro info runs off end of `.debug_macinfo' section"));
720 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
722 complaint (&symfile_complaints
,
723 _("macro debug info contains a malformed macro definition:\n`%s'"),
728 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
730 complaint (&symfile_complaints
,
731 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
734 /* local function prototypes */
736 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
739 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
742 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
745 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
746 struct partial_die_info
*,
747 struct partial_symtab
*);
749 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
751 static void scan_partial_symbols (struct partial_die_info
*,
752 CORE_ADDR
*, CORE_ADDR
*,
755 static void add_partial_symbol (struct partial_die_info
*,
758 static int pdi_needs_namespace (enum dwarf_tag tag
);
760 static void add_partial_namespace (struct partial_die_info
*pdi
,
761 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
762 struct dwarf2_cu
*cu
);
764 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
765 struct dwarf2_cu
*cu
);
767 static void add_partial_subprogram (struct partial_die_info
*pdi
,
768 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
769 struct dwarf2_cu
*cu
);
771 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
774 struct dwarf2_cu
*cu
);
776 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
778 static void psymtab_to_symtab_1 (struct partial_symtab
*);
780 gdb_byte
*dwarf2_read_section (struct objfile
*, asection
*);
782 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
784 static void dwarf2_free_abbrev_table (void *);
786 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
789 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
792 static struct partial_die_info
*load_partial_dies (bfd
*, gdb_byte
*, int,
795 static gdb_byte
*read_partial_die (struct partial_die_info
*,
796 struct abbrev_info
*abbrev
, unsigned int,
797 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
799 static struct partial_die_info
*find_partial_die (unsigned long,
802 static void fixup_partial_die (struct partial_die_info
*,
805 static gdb_byte
*read_full_die (struct die_info
**, bfd
*, gdb_byte
*,
806 struct dwarf2_cu
*, int *);
808 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
809 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
811 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
812 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
814 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
816 static int read_1_signed_byte (bfd
*, gdb_byte
*);
818 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
820 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
822 static unsigned long read_8_bytes (bfd
*, gdb_byte
*);
824 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
827 static LONGEST
read_initial_length (bfd
*, gdb_byte
*,
828 struct comp_unit_head
*, unsigned int *);
830 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
833 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
835 static char *read_string (bfd
*, gdb_byte
*, unsigned int *);
837 static char *read_indirect_string (bfd
*, gdb_byte
*,
838 const struct comp_unit_head
*,
841 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
843 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
845 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
847 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
849 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
852 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
853 struct dwarf2_cu
*cu
);
855 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
857 static struct die_info
*die_specification (struct die_info
*die
,
858 struct dwarf2_cu
**);
860 static void free_line_header (struct line_header
*lh
);
862 static void add_file_name (struct line_header
*, char *, unsigned int,
863 unsigned int, unsigned int);
865 static struct line_header
*(dwarf_decode_line_header
866 (unsigned int offset
,
867 bfd
*abfd
, struct dwarf2_cu
*cu
));
869 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
870 struct dwarf2_cu
*, struct partial_symtab
*);
872 static void dwarf2_start_subfile (char *, char *, char *);
874 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
877 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
880 static void dwarf2_const_value_data (struct attribute
*attr
,
884 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
886 static struct type
*die_containing_type (struct die_info
*,
889 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
891 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
893 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
895 static char *typename_concat (struct obstack
*,
900 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
902 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
904 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
906 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
907 struct dwarf2_cu
*, struct partial_symtab
*);
909 static int dwarf2_get_pc_bounds (struct die_info
*,
910 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
912 static void get_scope_pc_bounds (struct die_info
*,
913 CORE_ADDR
*, CORE_ADDR
*,
916 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
917 CORE_ADDR
, struct dwarf2_cu
*);
919 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
922 static void dwarf2_attach_fields_to_type (struct field_info
*,
923 struct type
*, struct dwarf2_cu
*);
925 static void dwarf2_add_member_fn (struct field_info
*,
926 struct die_info
*, struct type
*,
929 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
930 struct type
*, struct dwarf2_cu
*);
932 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
934 static const char *determine_class_name (struct die_info
*die
,
935 struct dwarf2_cu
*cu
);
937 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
939 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
941 static const char *namespace_name (struct die_info
*die
,
942 int *is_anonymous
, struct dwarf2_cu
*);
944 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
946 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
948 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
951 static struct die_info
*read_comp_unit (gdb_byte
*, bfd
*, struct dwarf2_cu
*);
953 static struct die_info
*read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
955 gdb_byte
**new_info_ptr
,
956 struct die_info
*parent
);
958 static struct die_info
*read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
960 gdb_byte
**new_info_ptr
,
961 struct die_info
*parent
);
963 static void process_die (struct die_info
*, struct dwarf2_cu
*);
965 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
967 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
969 static struct die_info
*dwarf2_extension (struct die_info
*die
,
970 struct dwarf2_cu
**);
972 static char *dwarf_tag_name (unsigned int);
974 static char *dwarf_attr_name (unsigned int);
976 static char *dwarf_form_name (unsigned int);
978 static char *dwarf_stack_op_name (unsigned int);
980 static char *dwarf_bool_name (unsigned int);
982 static char *dwarf_type_encoding_name (unsigned int);
985 static char *dwarf_cfi_name (unsigned int);
988 static struct die_info
*sibling_die (struct die_info
*);
990 static void dump_die (struct die_info
*);
992 static void dump_die_list (struct die_info
*);
994 static void store_in_ref_table (struct die_info
*,
997 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*,
1000 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
1002 static struct die_info
*follow_die_ref (struct die_info
*,
1004 struct dwarf2_cu
**);
1006 /* memory allocation interface */
1008 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1010 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1012 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1014 static void initialize_cu_func_list (struct dwarf2_cu
*);
1016 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1017 struct dwarf2_cu
*);
1019 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1020 char *, bfd
*, struct dwarf2_cu
*);
1022 static int attr_form_is_block (struct attribute
*);
1024 static int attr_form_is_section_offset (struct attribute
*);
1026 static int attr_form_is_constant (struct attribute
*);
1028 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1030 struct dwarf2_cu
*cu
);
1032 static gdb_byte
*skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
1033 struct dwarf2_cu
*cu
);
1035 static void free_stack_comp_unit (void *);
1037 static hashval_t
partial_die_hash (const void *item
);
1039 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1041 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1042 (unsigned long offset
, struct objfile
*objfile
);
1044 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1045 (unsigned long offset
, struct objfile
*objfile
);
1047 static void free_one_comp_unit (void *);
1049 static void free_cached_comp_units (void *);
1051 static void age_cached_comp_units (void);
1053 static void free_one_cached_comp_unit (void *);
1055 static struct type
*set_die_type (struct die_info
*, struct type
*,
1056 struct dwarf2_cu
*);
1058 static void create_all_comp_units (struct objfile
*);
1060 static struct dwarf2_cu
*load_full_comp_unit (struct dwarf2_per_cu_data
*,
1063 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1065 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1066 struct dwarf2_per_cu_data
*);
1068 static void dwarf2_mark (struct dwarf2_cu
*);
1070 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1072 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1074 /* Try to locate the sections we need for DWARF 2 debugging
1075 information and return true if we have enough to do something. */
1078 dwarf2_has_info (struct objfile
*objfile
)
1080 struct dwarf2_per_objfile
*data
;
1082 /* Initialize per-objfile state. */
1083 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1084 memset (data
, 0, sizeof (*data
));
1085 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1086 dwarf2_per_objfile
= data
;
1088 dwarf_info_section
= 0;
1089 dwarf_abbrev_section
= 0;
1090 dwarf_line_section
= 0;
1091 dwarf_str_section
= 0;
1092 dwarf_macinfo_section
= 0;
1093 dwarf_frame_section
= 0;
1094 dwarf_eh_frame_section
= 0;
1095 dwarf_ranges_section
= 0;
1096 dwarf_loc_section
= 0;
1098 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1099 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
1102 /* When loading sections, we can either look for ".<name>", or for
1103 * ".z<name>", which indicates a compressed section. */
1106 section_is_p (asection
*sectp
, const char *name
)
1108 return ((sectp
->name
[0] == '.'
1109 && strcmp (sectp
->name
+ 1, name
) == 0)
1110 || (sectp
->name
[0] == '.' && sectp
->name
[1] == 'z'
1111 && strcmp (sectp
->name
+ 2, name
) == 0));
1114 /* This function is mapped across the sections and remembers the
1115 offset and size of each of the debugging sections we are interested
1119 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1121 if (section_is_p (sectp
, INFO_SECTION
))
1123 dwarf2_per_objfile
->info_size
= bfd_get_section_size (sectp
);
1124 dwarf_info_section
= sectp
;
1126 else if (section_is_p (sectp
, ABBREV_SECTION
))
1128 dwarf2_per_objfile
->abbrev_size
= bfd_get_section_size (sectp
);
1129 dwarf_abbrev_section
= sectp
;
1131 else if (section_is_p (sectp
, LINE_SECTION
))
1133 dwarf2_per_objfile
->line_size
= bfd_get_section_size (sectp
);
1134 dwarf_line_section
= sectp
;
1136 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1138 dwarf2_per_objfile
->pubnames_size
= bfd_get_section_size (sectp
);
1139 dwarf_pubnames_section
= sectp
;
1141 else if (section_is_p (sectp
, ARANGES_SECTION
))
1143 dwarf2_per_objfile
->aranges_size
= bfd_get_section_size (sectp
);
1144 dwarf_aranges_section
= sectp
;
1146 else if (section_is_p (sectp
, LOC_SECTION
))
1148 dwarf2_per_objfile
->loc_size
= bfd_get_section_size (sectp
);
1149 dwarf_loc_section
= sectp
;
1151 else if (section_is_p (sectp
, MACINFO_SECTION
))
1153 dwarf2_per_objfile
->macinfo_size
= bfd_get_section_size (sectp
);
1154 dwarf_macinfo_section
= sectp
;
1156 else if (section_is_p (sectp
, STR_SECTION
))
1158 dwarf2_per_objfile
->str_size
= bfd_get_section_size (sectp
);
1159 dwarf_str_section
= sectp
;
1161 else if (section_is_p (sectp
, FRAME_SECTION
))
1163 dwarf2_per_objfile
->frame_size
= bfd_get_section_size (sectp
);
1164 dwarf_frame_section
= sectp
;
1166 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1168 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1169 if (aflag
& SEC_HAS_CONTENTS
)
1171 dwarf2_per_objfile
->eh_frame_size
= bfd_get_section_size (sectp
);
1172 dwarf_eh_frame_section
= sectp
;
1175 else if (section_is_p (sectp
, RANGES_SECTION
))
1177 dwarf2_per_objfile
->ranges_size
= bfd_get_section_size (sectp
);
1178 dwarf_ranges_section
= sectp
;
1181 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1182 && bfd_section_vma (abfd
, sectp
) == 0)
1183 dwarf2_per_objfile
->has_section_at_zero
= 1;
1186 /* This function is called after decompressing a section, so
1187 dwarf2_per_objfile can record its new, uncompressed size. */
1190 dwarf2_resize_section (asection
*sectp
, bfd_size_type new_size
)
1192 if (section_is_p (sectp
, INFO_SECTION
))
1193 dwarf2_per_objfile
->info_size
= new_size
;
1194 else if (section_is_p (sectp
, ABBREV_SECTION
))
1195 dwarf2_per_objfile
->abbrev_size
= new_size
;
1196 else if (section_is_p (sectp
, LINE_SECTION
))
1197 dwarf2_per_objfile
->line_size
= new_size
;
1198 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1199 dwarf2_per_objfile
->pubnames_size
= new_size
;
1200 else if (section_is_p (sectp
, ARANGES_SECTION
))
1201 dwarf2_per_objfile
->aranges_size
= new_size
;
1202 else if (section_is_p (sectp
, LOC_SECTION
))
1203 dwarf2_per_objfile
->loc_size
= new_size
;
1204 else if (section_is_p (sectp
, MACINFO_SECTION
))
1205 dwarf2_per_objfile
->macinfo_size
= new_size
;
1206 else if (section_is_p (sectp
, STR_SECTION
))
1207 dwarf2_per_objfile
->str_size
= new_size
;
1208 else if (section_is_p (sectp
, FRAME_SECTION
))
1209 dwarf2_per_objfile
->frame_size
= new_size
;
1210 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1211 dwarf2_per_objfile
->eh_frame_size
= new_size
;
1212 else if (section_is_p (sectp
, RANGES_SECTION
))
1213 dwarf2_per_objfile
->ranges_size
= new_size
;
1215 internal_error (__FILE__
, __LINE__
,
1216 _("dwarf2_resize_section: missing section_is_p check: %s"),
1220 /* Build a partial symbol table. */
1223 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1225 /* We definitely need the .debug_info and .debug_abbrev sections */
1227 dwarf2_per_objfile
->info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1228 dwarf2_per_objfile
->abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1230 if (dwarf_line_section
)
1231 dwarf2_per_objfile
->line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1233 dwarf2_per_objfile
->line_buffer
= NULL
;
1235 if (dwarf_str_section
)
1236 dwarf2_per_objfile
->str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1238 dwarf2_per_objfile
->str_buffer
= NULL
;
1240 if (dwarf_macinfo_section
)
1241 dwarf2_per_objfile
->macinfo_buffer
= dwarf2_read_section (objfile
,
1242 dwarf_macinfo_section
);
1244 dwarf2_per_objfile
->macinfo_buffer
= NULL
;
1246 if (dwarf_ranges_section
)
1247 dwarf2_per_objfile
->ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1249 dwarf2_per_objfile
->ranges_buffer
= NULL
;
1251 if (dwarf_loc_section
)
1252 dwarf2_per_objfile
->loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1254 dwarf2_per_objfile
->loc_buffer
= NULL
;
1257 || (objfile
->global_psymbols
.size
== 0
1258 && objfile
->static_psymbols
.size
== 0))
1260 init_psymbol_list (objfile
, 1024);
1264 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1266 /* Things are significantly easier if we have .debug_aranges and
1267 .debug_pubnames sections */
1269 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1273 /* only test this case for now */
1275 /* In this case we have to work a bit harder */
1276 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1281 /* Build the partial symbol table from the information in the
1282 .debug_pubnames and .debug_aranges sections. */
1285 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1287 bfd
*abfd
= objfile
->obfd
;
1288 char *aranges_buffer
, *pubnames_buffer
;
1289 char *aranges_ptr
, *pubnames_ptr
;
1290 unsigned int entry_length
, version
, info_offset
, info_size
;
1292 pubnames_buffer
= dwarf2_read_section (objfile
,
1293 dwarf_pubnames_section
);
1294 pubnames_ptr
= pubnames_buffer
;
1295 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames_size
)
1297 struct comp_unit_head cu_header
;
1298 unsigned int bytes_read
;
1300 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1302 pubnames_ptr
+= bytes_read
;
1303 version
= read_1_byte (abfd
, pubnames_ptr
);
1305 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1307 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1311 aranges_buffer
= dwarf2_read_section (objfile
,
1312 dwarf_aranges_section
);
1317 /* Read in the comp unit header information from the debug_info at
1321 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1322 gdb_byte
*info_ptr
, bfd
*abfd
)
1325 unsigned int bytes_read
;
1326 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1328 info_ptr
+= bytes_read
;
1329 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1331 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1333 info_ptr
+= bytes_read
;
1334 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1336 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1337 if (signed_addr
< 0)
1338 internal_error (__FILE__
, __LINE__
,
1339 _("read_comp_unit_head: dwarf from non elf file"));
1340 cu_header
->signed_addr_p
= signed_addr
;
1345 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1348 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1350 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1352 if (header
->version
!= 2 && header
->version
!= 3)
1353 error (_("Dwarf Error: wrong version in compilation unit header "
1354 "(is %d, should be %d) [in module %s]"), header
->version
,
1355 2, bfd_get_filename (abfd
));
1357 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev_size
)
1358 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1359 "(offset 0x%lx + 6) [in module %s]"),
1360 (long) header
->abbrev_offset
,
1361 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1362 bfd_get_filename (abfd
));
1364 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1365 > dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1366 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1367 "(offset 0x%lx + 0) [in module %s]"),
1368 (long) header
->length
,
1369 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1370 bfd_get_filename (abfd
));
1375 /* Allocate a new partial symtab for file named NAME and mark this new
1376 partial symtab as being an include of PST. */
1379 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1380 struct objfile
*objfile
)
1382 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1384 subpst
->section_offsets
= pst
->section_offsets
;
1385 subpst
->textlow
= 0;
1386 subpst
->texthigh
= 0;
1388 subpst
->dependencies
= (struct partial_symtab
**)
1389 obstack_alloc (&objfile
->objfile_obstack
,
1390 sizeof (struct partial_symtab
*));
1391 subpst
->dependencies
[0] = pst
;
1392 subpst
->number_of_dependencies
= 1;
1394 subpst
->globals_offset
= 0;
1395 subpst
->n_global_syms
= 0;
1396 subpst
->statics_offset
= 0;
1397 subpst
->n_static_syms
= 0;
1398 subpst
->symtab
= NULL
;
1399 subpst
->read_symtab
= pst
->read_symtab
;
1402 /* No private part is necessary for include psymtabs. This property
1403 can be used to differentiate between such include psymtabs and
1404 the regular ones. */
1405 subpst
->read_symtab_private
= NULL
;
1408 /* Read the Line Number Program data and extract the list of files
1409 included by the source file represented by PST. Build an include
1410 partial symtab for each of these included files.
1412 This procedure assumes that there *is* a Line Number Program in
1413 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1414 before calling this procedure. */
1417 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1418 struct partial_die_info
*pdi
,
1419 struct partial_symtab
*pst
)
1421 struct objfile
*objfile
= cu
->objfile
;
1422 bfd
*abfd
= objfile
->obfd
;
1423 struct line_header
*lh
;
1425 lh
= dwarf_decode_line_header (pdi
->line_offset
, abfd
, cu
);
1427 return; /* No linetable, so no includes. */
1429 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1431 free_line_header (lh
);
1435 /* Build the partial symbol table by doing a quick pass through the
1436 .debug_info and .debug_abbrev sections. */
1439 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1441 /* Instead of reading this into a big buffer, we should probably use
1442 mmap() on architectures that support it. (FIXME) */
1443 bfd
*abfd
= objfile
->obfd
;
1445 gdb_byte
*beg_of_comp_unit
;
1446 struct partial_die_info comp_unit_die
;
1447 struct partial_symtab
*pst
;
1448 struct cleanup
*back_to
;
1449 CORE_ADDR lowpc
, highpc
, baseaddr
;
1451 info_ptr
= dwarf2_per_objfile
->info_buffer
;
1453 /* Any cached compilation units will be linked by the per-objfile
1454 read_in_chain. Make sure to free them when we're done. */
1455 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1457 create_all_comp_units (objfile
);
1459 objfile
->psymtabs_addrmap
= addrmap_create_mutable
1460 (&objfile
->objfile_obstack
);
1462 /* Since the objects we're extracting from .debug_info vary in
1463 length, only the individual functions to extract them (like
1464 read_comp_unit_head and load_partial_die) can really know whether
1465 the buffer is large enough to hold another complete object.
1467 At the moment, they don't actually check that. If .debug_info
1468 holds just one extra byte after the last compilation unit's dies,
1469 then read_comp_unit_head will happily read off the end of the
1470 buffer. read_partial_die is similarly casual. Those functions
1473 For this loop condition, simply checking whether there's any data
1474 left at all should be sufficient. */
1475 while (info_ptr
< (dwarf2_per_objfile
->info_buffer
1476 + dwarf2_per_objfile
->info_size
))
1478 struct cleanup
*back_to_inner
;
1479 struct dwarf2_cu cu
;
1480 struct abbrev_info
*abbrev
;
1481 unsigned int bytes_read
;
1482 struct dwarf2_per_cu_data
*this_cu
;
1484 beg_of_comp_unit
= info_ptr
;
1486 memset (&cu
, 0, sizeof (cu
));
1488 obstack_init (&cu
.comp_unit_obstack
);
1490 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1492 cu
.objfile
= objfile
;
1493 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1495 /* Complete the cu_header */
1496 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1497 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1499 cu
.list_in_scope
= &file_symbols
;
1501 /* Read the abbrevs for this compilation unit into a table */
1502 dwarf2_read_abbrevs (abfd
, &cu
);
1503 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1505 this_cu
= dwarf2_find_comp_unit (cu
.header
.offset
, objfile
);
1507 /* Read the compilation unit die */
1508 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, &cu
);
1509 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1510 abfd
, info_ptr
, &cu
);
1512 if (comp_unit_die
.tag
== DW_TAG_partial_unit
)
1514 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1515 + cu
.header
.initial_length_size
);
1516 do_cleanups (back_to_inner
);
1520 /* Set the language we're debugging */
1521 set_cu_language (comp_unit_die
.language
, &cu
);
1523 /* Allocate a new partial symbol table structure */
1524 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1525 comp_unit_die
.name
? comp_unit_die
.name
: "",
1526 /* TEXTLOW and TEXTHIGH are set below. */
1528 objfile
->global_psymbols
.next
,
1529 objfile
->static_psymbols
.next
);
1531 if (comp_unit_die
.dirname
)
1532 pst
->dirname
= obsavestring (comp_unit_die
.dirname
,
1533 strlen (comp_unit_die
.dirname
),
1534 &objfile
->objfile_obstack
);
1536 pst
->read_symtab_private
= (char *) this_cu
;
1538 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1540 /* Store the function that reads in the rest of the symbol table */
1541 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1543 /* If this compilation unit was already read in, free the
1544 cached copy in order to read it in again. This is
1545 necessary because we skipped some symbols when we first
1546 read in the compilation unit (see load_partial_dies).
1547 This problem could be avoided, but the benefit is
1549 if (this_cu
->cu
!= NULL
)
1550 free_one_cached_comp_unit (this_cu
->cu
);
1552 cu
.per_cu
= this_cu
;
1554 /* Note that this is a pointer to our stack frame, being
1555 added to a global data structure. It will be cleaned up
1556 in free_stack_comp_unit when we finish with this
1557 compilation unit. */
1560 this_cu
->psymtab
= pst
;
1562 /* Possibly set the default values of LOWPC and HIGHPC from
1564 if (cu
.has_ranges_offset
)
1566 if (dwarf2_ranges_read (cu
.ranges_offset
, &comp_unit_die
.lowpc
,
1567 &comp_unit_die
.highpc
, &cu
, pst
))
1568 comp_unit_die
.has_pc_info
= 1;
1571 /* Check if comp unit has_children.
1572 If so, read the rest of the partial symbols from this comp unit.
1573 If not, there's no more debug_info for this comp unit. */
1574 if (comp_unit_die
.has_children
)
1576 struct partial_die_info
*first_die
;
1578 lowpc
= ((CORE_ADDR
) -1);
1579 highpc
= ((CORE_ADDR
) 0);
1581 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1583 scan_partial_symbols (first_die
, &lowpc
, &highpc
, &cu
);
1585 /* If we didn't find a lowpc, set it to highpc to avoid
1586 complaints from `maint check'. */
1587 if (lowpc
== ((CORE_ADDR
) -1))
1590 /* If the compilation unit didn't have an explicit address range,
1591 then use the information extracted from its child dies. */
1592 if (! comp_unit_die
.has_pc_info
)
1594 comp_unit_die
.lowpc
= lowpc
;
1595 comp_unit_die
.highpc
= highpc
;
1598 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1599 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1601 /* Store the contiguous range; `DW_AT_ranges' range is stored above. The
1602 range can be also empty for CUs with no code. */
1603 if (!cu
.has_ranges_offset
&& pst
->textlow
< pst
->texthigh
)
1604 addrmap_set_empty (objfile
->psymtabs_addrmap
, pst
->textlow
,
1605 pst
->texthigh
- 1, pst
);
1607 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1608 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1609 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1610 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1611 sort_pst_symbols (pst
);
1613 /* If there is already a psymtab or symtab for a file of this
1614 name, remove it. (If there is a symtab, more drastic things
1615 also happen.) This happens in VxWorks. */
1616 free_named_symtabs (pst
->filename
);
1618 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1619 + cu
.header
.initial_length_size
;
1621 if (comp_unit_die
.has_stmt_list
)
1623 /* Get the list of files included in the current compilation unit,
1624 and build a psymtab for each of them. */
1625 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1628 do_cleanups (back_to_inner
);
1631 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
1632 &objfile
->objfile_obstack
);
1634 do_cleanups (back_to
);
1637 /* Load the DIEs for a secondary CU into memory. */
1640 load_comp_unit (struct dwarf2_per_cu_data
*this_cu
, struct objfile
*objfile
)
1642 bfd
*abfd
= objfile
->obfd
;
1643 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
1644 struct partial_die_info comp_unit_die
;
1645 struct dwarf2_cu
*cu
;
1646 struct abbrev_info
*abbrev
;
1647 unsigned int bytes_read
;
1648 struct cleanup
*back_to
;
1650 info_ptr
= dwarf2_per_objfile
->info_buffer
+ this_cu
->offset
;
1651 beg_of_comp_unit
= info_ptr
;
1653 cu
= xmalloc (sizeof (struct dwarf2_cu
));
1654 memset (cu
, 0, sizeof (struct dwarf2_cu
));
1656 obstack_init (&cu
->comp_unit_obstack
);
1658 cu
->objfile
= objfile
;
1659 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
1661 /* Complete the cu_header. */
1662 cu
->header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1663 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1665 /* Read the abbrevs for this compilation unit into a table. */
1666 dwarf2_read_abbrevs (abfd
, cu
);
1667 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
1669 /* Read the compilation unit die. */
1670 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1671 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1672 abfd
, info_ptr
, cu
);
1674 /* Set the language we're debugging. */
1675 set_cu_language (comp_unit_die
.language
, cu
);
1677 /* Link this compilation unit into the compilation unit tree. */
1679 cu
->per_cu
= this_cu
;
1680 cu
->type_hash
= cu
->per_cu
->type_hash
;
1682 /* Check if comp unit has_children.
1683 If so, read the rest of the partial symbols from this comp unit.
1684 If not, there's no more debug_info for this comp unit. */
1685 if (comp_unit_die
.has_children
)
1686 load_partial_dies (abfd
, info_ptr
, 0, cu
);
1688 do_cleanups (back_to
);
1691 /* Create a list of all compilation units in OBJFILE. We do this only
1692 if an inter-comp-unit reference is found; presumably if there is one,
1693 there will be many, and one will occur early in the .debug_info section.
1694 So there's no point in building this list incrementally. */
1697 create_all_comp_units (struct objfile
*objfile
)
1701 struct dwarf2_per_cu_data
**all_comp_units
;
1702 gdb_byte
*info_ptr
= dwarf2_per_objfile
->info_buffer
;
1706 all_comp_units
= xmalloc (n_allocated
1707 * sizeof (struct dwarf2_per_cu_data
*));
1709 while (info_ptr
< dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1711 struct comp_unit_head cu_header
;
1712 gdb_byte
*beg_of_comp_unit
;
1713 struct dwarf2_per_cu_data
*this_cu
;
1714 unsigned long offset
;
1715 unsigned int bytes_read
;
1717 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
1719 /* Read just enough information to find out where the next
1720 compilation unit is. */
1721 cu_header
.initial_length_size
= 0;
1722 cu_header
.length
= read_initial_length (objfile
->obfd
, info_ptr
,
1723 &cu_header
, &bytes_read
);
1725 /* Save the compilation unit for later lookup. */
1726 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
1727 sizeof (struct dwarf2_per_cu_data
));
1728 memset (this_cu
, 0, sizeof (*this_cu
));
1729 this_cu
->offset
= offset
;
1730 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
1732 if (n_comp_units
== n_allocated
)
1735 all_comp_units
= xrealloc (all_comp_units
,
1737 * sizeof (struct dwarf2_per_cu_data
*));
1739 all_comp_units
[n_comp_units
++] = this_cu
;
1741 info_ptr
= info_ptr
+ this_cu
->length
;
1744 dwarf2_per_objfile
->all_comp_units
1745 = obstack_alloc (&objfile
->objfile_obstack
,
1746 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1747 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
1748 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1749 xfree (all_comp_units
);
1750 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
1753 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1754 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1758 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1759 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
1761 struct objfile
*objfile
= cu
->objfile
;
1762 bfd
*abfd
= objfile
->obfd
;
1763 struct partial_die_info
*pdi
;
1765 /* Now, march along the PDI's, descending into ones which have
1766 interesting children but skipping the children of the other ones,
1767 until we reach the end of the compilation unit. */
1773 fixup_partial_die (pdi
, cu
);
1775 /* Anonymous namespaces have no name but have interesting
1776 children, so we need to look at them. Ditto for anonymous
1779 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1780 || pdi
->tag
== DW_TAG_enumeration_type
)
1784 case DW_TAG_subprogram
:
1785 add_partial_subprogram (pdi
, lowpc
, highpc
, cu
);
1787 case DW_TAG_variable
:
1788 case DW_TAG_typedef
:
1789 case DW_TAG_union_type
:
1790 if (!pdi
->is_declaration
)
1792 add_partial_symbol (pdi
, cu
);
1795 case DW_TAG_class_type
:
1796 case DW_TAG_interface_type
:
1797 case DW_TAG_structure_type
:
1798 if (!pdi
->is_declaration
)
1800 add_partial_symbol (pdi
, cu
);
1803 case DW_TAG_enumeration_type
:
1804 if (!pdi
->is_declaration
)
1805 add_partial_enumeration (pdi
, cu
);
1807 case DW_TAG_base_type
:
1808 case DW_TAG_subrange_type
:
1809 /* File scope base type definitions are added to the partial
1811 add_partial_symbol (pdi
, cu
);
1813 case DW_TAG_namespace
:
1814 add_partial_namespace (pdi
, lowpc
, highpc
, cu
);
1821 /* If the die has a sibling, skip to the sibling. */
1823 pdi
= pdi
->die_sibling
;
1827 /* Functions used to compute the fully scoped name of a partial DIE.
1829 Normally, this is simple. For C++, the parent DIE's fully scoped
1830 name is concatenated with "::" and the partial DIE's name. For
1831 Java, the same thing occurs except that "." is used instead of "::".
1832 Enumerators are an exception; they use the scope of their parent
1833 enumeration type, i.e. the name of the enumeration type is not
1834 prepended to the enumerator.
1836 There are two complexities. One is DW_AT_specification; in this
1837 case "parent" means the parent of the target of the specification,
1838 instead of the direct parent of the DIE. The other is compilers
1839 which do not emit DW_TAG_namespace; in this case we try to guess
1840 the fully qualified name of structure types from their members'
1841 linkage names. This must be done using the DIE's children rather
1842 than the children of any DW_AT_specification target. We only need
1843 to do this for structures at the top level, i.e. if the target of
1844 any DW_AT_specification (if any; otherwise the DIE itself) does not
1847 /* Compute the scope prefix associated with PDI's parent, in
1848 compilation unit CU. The result will be allocated on CU's
1849 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1850 field. NULL is returned if no prefix is necessary. */
1852 partial_die_parent_scope (struct partial_die_info
*pdi
,
1853 struct dwarf2_cu
*cu
)
1855 char *grandparent_scope
;
1856 struct partial_die_info
*parent
, *real_pdi
;
1858 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1859 then this means the parent of the specification DIE. */
1862 while (real_pdi
->has_specification
)
1863 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
1865 parent
= real_pdi
->die_parent
;
1869 if (parent
->scope_set
)
1870 return parent
->scope
;
1872 fixup_partial_die (parent
, cu
);
1874 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
1876 if (parent
->tag
== DW_TAG_namespace
1877 || parent
->tag
== DW_TAG_structure_type
1878 || parent
->tag
== DW_TAG_class_type
1879 || parent
->tag
== DW_TAG_interface_type
1880 || parent
->tag
== DW_TAG_union_type
)
1882 if (grandparent_scope
== NULL
)
1883 parent
->scope
= parent
->name
;
1885 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
1888 else if (parent
->tag
== DW_TAG_enumeration_type
)
1889 /* Enumerators should not get the name of the enumeration as a prefix. */
1890 parent
->scope
= grandparent_scope
;
1893 /* FIXME drow/2004-04-01: What should we be doing with
1894 function-local names? For partial symbols, we should probably be
1896 complaint (&symfile_complaints
,
1897 _("unhandled containing DIE tag %d for DIE at %d"),
1898 parent
->tag
, pdi
->offset
);
1899 parent
->scope
= grandparent_scope
;
1902 parent
->scope_set
= 1;
1903 return parent
->scope
;
1906 /* Return the fully scoped name associated with PDI, from compilation unit
1907 CU. The result will be allocated with malloc. */
1909 partial_die_full_name (struct partial_die_info
*pdi
,
1910 struct dwarf2_cu
*cu
)
1914 parent_scope
= partial_die_parent_scope (pdi
, cu
);
1915 if (parent_scope
== NULL
)
1918 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
1922 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
1924 struct objfile
*objfile
= cu
->objfile
;
1926 char *actual_name
= NULL
;
1927 const char *my_prefix
;
1928 const struct partial_symbol
*psym
= NULL
;
1930 int built_actual_name
= 0;
1932 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1934 if (pdi_needs_namespace (pdi
->tag
))
1936 actual_name
= partial_die_full_name (pdi
, cu
);
1938 built_actual_name
= 1;
1941 if (actual_name
== NULL
)
1942 actual_name
= pdi
->name
;
1946 case DW_TAG_subprogram
:
1947 if (pdi
->is_external
|| cu
->language
== language_ada
)
1949 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
1950 of the global scope. But in Ada, we want to be able to access
1951 nested procedures globally. So all Ada subprograms are stored
1952 in the global scope. */
1953 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1954 mst_text, objfile); */
1955 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1956 VAR_DOMAIN
, LOC_BLOCK
,
1957 &objfile
->global_psymbols
,
1958 0, pdi
->lowpc
+ baseaddr
,
1959 cu
->language
, objfile
);
1963 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1964 mst_file_text, objfile); */
1965 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1966 VAR_DOMAIN
, LOC_BLOCK
,
1967 &objfile
->static_psymbols
,
1968 0, pdi
->lowpc
+ baseaddr
,
1969 cu
->language
, objfile
);
1972 case DW_TAG_variable
:
1973 if (pdi
->is_external
)
1976 Don't enter into the minimal symbol tables as there is
1977 a minimal symbol table entry from the ELF symbols already.
1978 Enter into partial symbol table if it has a location
1979 descriptor or a type.
1980 If the location descriptor is missing, new_symbol will create
1981 a LOC_UNRESOLVED symbol, the address of the variable will then
1982 be determined from the minimal symbol table whenever the variable
1984 The address for the partial symbol table entry is not
1985 used by GDB, but it comes in handy for debugging partial symbol
1989 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1990 if (pdi
->locdesc
|| pdi
->has_type
)
1991 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1992 VAR_DOMAIN
, LOC_STATIC
,
1993 &objfile
->global_psymbols
,
1995 cu
->language
, objfile
);
1999 /* Static Variable. Skip symbols without location descriptors. */
2000 if (pdi
->locdesc
== NULL
)
2002 if (built_actual_name
)
2003 xfree (actual_name
);
2006 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2007 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2008 mst_file_data, objfile); */
2009 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2010 VAR_DOMAIN
, LOC_STATIC
,
2011 &objfile
->static_psymbols
,
2013 cu
->language
, objfile
);
2016 case DW_TAG_typedef
:
2017 case DW_TAG_base_type
:
2018 case DW_TAG_subrange_type
:
2019 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2020 VAR_DOMAIN
, LOC_TYPEDEF
,
2021 &objfile
->static_psymbols
,
2022 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2024 case DW_TAG_namespace
:
2025 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2026 VAR_DOMAIN
, LOC_TYPEDEF
,
2027 &objfile
->global_psymbols
,
2028 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2030 case DW_TAG_class_type
:
2031 case DW_TAG_interface_type
:
2032 case DW_TAG_structure_type
:
2033 case DW_TAG_union_type
:
2034 case DW_TAG_enumeration_type
:
2035 /* Skip external references. The DWARF standard says in the section
2036 about "Structure, Union, and Class Type Entries": "An incomplete
2037 structure, union or class type is represented by a structure,
2038 union or class entry that does not have a byte size attribute
2039 and that has a DW_AT_declaration attribute." */
2040 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2042 if (built_actual_name
)
2043 xfree (actual_name
);
2047 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2048 static vs. global. */
2049 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2050 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2051 (cu
->language
== language_cplus
2052 || cu
->language
== language_java
)
2053 ? &objfile
->global_psymbols
2054 : &objfile
->static_psymbols
,
2055 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2058 case DW_TAG_enumerator
:
2059 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2060 VAR_DOMAIN
, LOC_CONST
,
2061 (cu
->language
== language_cplus
2062 || cu
->language
== language_java
)
2063 ? &objfile
->global_psymbols
2064 : &objfile
->static_psymbols
,
2065 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2071 /* Check to see if we should scan the name for possible namespace
2072 info. Only do this if this is C++, if we don't have namespace
2073 debugging info in the file, if the psym is of an appropriate type
2074 (otherwise we'll have psym == NULL), and if we actually had a
2075 mangled name to begin with. */
2077 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2078 cases which do not set PSYM above? */
2080 if (cu
->language
== language_cplus
2081 && cu
->has_namespace_info
== 0
2083 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
2084 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
2087 if (built_actual_name
)
2088 xfree (actual_name
);
2091 /* Determine whether a die of type TAG living in a C++ class or
2092 namespace needs to have the name of the scope prepended to the
2093 name listed in the die. */
2096 pdi_needs_namespace (enum dwarf_tag tag
)
2100 case DW_TAG_namespace
:
2101 case DW_TAG_typedef
:
2102 case DW_TAG_class_type
:
2103 case DW_TAG_interface_type
:
2104 case DW_TAG_structure_type
:
2105 case DW_TAG_union_type
:
2106 case DW_TAG_enumeration_type
:
2107 case DW_TAG_enumerator
:
2114 /* Read a partial die corresponding to a namespace; also, add a symbol
2115 corresponding to that namespace to the symbol table. NAMESPACE is
2116 the name of the enclosing namespace. */
2119 add_partial_namespace (struct partial_die_info
*pdi
,
2120 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2121 struct dwarf2_cu
*cu
)
2123 struct objfile
*objfile
= cu
->objfile
;
2125 /* Add a symbol for the namespace. */
2127 add_partial_symbol (pdi
, cu
);
2129 /* Now scan partial symbols in that namespace. */
2131 if (pdi
->has_children
)
2132 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, cu
);
2135 /* Read a partial die corresponding to a subprogram and create a partial
2136 symbol for that subprogram. When the CU language allows it, this
2137 routine also defines a partial symbol for each nested subprogram
2138 that this subprogram contains.
2140 DIE my also be a lexical block, in which case we simply search
2141 recursively for suprograms defined inside that lexical block.
2142 Again, this is only performed when the CU language allows this
2143 type of definitions. */
2146 add_partial_subprogram (struct partial_die_info
*pdi
,
2147 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2148 struct dwarf2_cu
*cu
)
2150 if (pdi
->tag
== DW_TAG_subprogram
)
2152 if (pdi
->has_pc_info
)
2154 if (pdi
->lowpc
< *lowpc
)
2155 *lowpc
= pdi
->lowpc
;
2156 if (pdi
->highpc
> *highpc
)
2157 *highpc
= pdi
->highpc
;
2158 if (!pdi
->is_declaration
)
2159 add_partial_symbol (pdi
, cu
);
2163 if (! pdi
->has_children
)
2166 if (cu
->language
== language_ada
)
2168 pdi
= pdi
->die_child
;
2171 fixup_partial_die (pdi
, cu
);
2172 if (pdi
->tag
== DW_TAG_subprogram
2173 || pdi
->tag
== DW_TAG_lexical_block
)
2174 add_partial_subprogram (pdi
, lowpc
, highpc
, cu
);
2175 pdi
= pdi
->die_sibling
;
2180 /* See if we can figure out if the class lives in a namespace. We do
2181 this by looking for a member function; its demangled name will
2182 contain namespace info, if there is any. */
2185 guess_structure_name (struct partial_die_info
*struct_pdi
,
2186 struct dwarf2_cu
*cu
)
2188 if ((cu
->language
== language_cplus
2189 || cu
->language
== language_java
)
2190 && cu
->has_namespace_info
== 0
2191 && struct_pdi
->has_children
)
2193 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2194 what template types look like, because the demangler
2195 frequently doesn't give the same name as the debug info. We
2196 could fix this by only using the demangled name to get the
2197 prefix (but see comment in read_structure_type). */
2199 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
2200 struct partial_die_info
*real_pdi
;
2202 /* If this DIE (this DIE's specification, if any) has a parent, then
2203 we should not do this. We'll prepend the parent's fully qualified
2204 name when we create the partial symbol. */
2206 real_pdi
= struct_pdi
;
2207 while (real_pdi
->has_specification
)
2208 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2210 if (real_pdi
->die_parent
!= NULL
)
2213 while (child_pdi
!= NULL
)
2215 if (child_pdi
->tag
== DW_TAG_subprogram
)
2217 char *actual_class_name
2218 = language_class_name_from_physname (cu
->language_defn
,
2220 if (actual_class_name
!= NULL
)
2223 = obsavestring (actual_class_name
,
2224 strlen (actual_class_name
),
2225 &cu
->comp_unit_obstack
);
2226 xfree (actual_class_name
);
2231 child_pdi
= child_pdi
->die_sibling
;
2236 /* Read a partial die corresponding to an enumeration type. */
2239 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2240 struct dwarf2_cu
*cu
)
2242 struct objfile
*objfile
= cu
->objfile
;
2243 bfd
*abfd
= objfile
->obfd
;
2244 struct partial_die_info
*pdi
;
2246 if (enum_pdi
->name
!= NULL
)
2247 add_partial_symbol (enum_pdi
, cu
);
2249 pdi
= enum_pdi
->die_child
;
2252 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2253 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2255 add_partial_symbol (pdi
, cu
);
2256 pdi
= pdi
->die_sibling
;
2260 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2261 Return the corresponding abbrev, or NULL if the number is zero (indicating
2262 an empty DIE). In either case *BYTES_READ will be set to the length of
2263 the initial number. */
2265 static struct abbrev_info
*
2266 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2267 struct dwarf2_cu
*cu
)
2269 bfd
*abfd
= cu
->objfile
->obfd
;
2270 unsigned int abbrev_number
;
2271 struct abbrev_info
*abbrev
;
2273 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2275 if (abbrev_number
== 0)
2278 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2281 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2282 bfd_get_filename (abfd
));
2288 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2289 pointer to the end of a series of DIEs, terminated by an empty
2290 DIE. Any children of the skipped DIEs will also be skipped. */
2293 skip_children (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2295 struct abbrev_info
*abbrev
;
2296 unsigned int bytes_read
;
2300 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2302 return info_ptr
+ bytes_read
;
2304 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
2308 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2309 should point just after the initial uleb128 of a DIE, and the
2310 abbrev corresponding to that skipped uleb128 should be passed in
2311 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2315 skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
2316 struct dwarf2_cu
*cu
)
2318 unsigned int bytes_read
;
2319 struct attribute attr
;
2320 bfd
*abfd
= cu
->objfile
->obfd
;
2321 unsigned int form
, i
;
2323 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2325 /* The only abbrev we care about is DW_AT_sibling. */
2326 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2328 read_attribute (&attr
, &abbrev
->attrs
[i
],
2329 abfd
, info_ptr
, cu
);
2330 if (attr
.form
== DW_FORM_ref_addr
)
2331 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2333 return dwarf2_per_objfile
->info_buffer
2334 + dwarf2_get_ref_die_offset (&attr
, cu
);
2337 /* If it isn't DW_AT_sibling, skip this attribute. */
2338 form
= abbrev
->attrs
[i
].form
;
2343 case DW_FORM_ref_addr
:
2344 info_ptr
+= cu
->header
.addr_size
;
2363 case DW_FORM_string
:
2364 read_string (abfd
, info_ptr
, &bytes_read
);
2365 info_ptr
+= bytes_read
;
2368 info_ptr
+= cu
->header
.offset_size
;
2371 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2372 info_ptr
+= bytes_read
;
2374 case DW_FORM_block1
:
2375 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2377 case DW_FORM_block2
:
2378 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2380 case DW_FORM_block4
:
2381 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2385 case DW_FORM_ref_udata
:
2386 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2388 case DW_FORM_indirect
:
2389 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2390 info_ptr
+= bytes_read
;
2391 /* We need to continue parsing from here, so just go back to
2393 goto skip_attribute
;
2396 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2397 dwarf_form_name (form
),
2398 bfd_get_filename (abfd
));
2402 if (abbrev
->has_children
)
2403 return skip_children (info_ptr
, cu
);
2408 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2409 the next DIE after ORIG_PDI. */
2412 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, gdb_byte
*info_ptr
,
2413 bfd
*abfd
, struct dwarf2_cu
*cu
)
2415 /* Do we know the sibling already? */
2417 if (orig_pdi
->sibling
)
2418 return orig_pdi
->sibling
;
2420 /* Are there any children to deal with? */
2422 if (!orig_pdi
->has_children
)
2425 /* Skip the children the long way. */
2427 return skip_children (info_ptr
, cu
);
2430 /* Expand this partial symbol table into a full symbol table. */
2433 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2435 /* FIXME: This is barely more than a stub. */
2440 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2446 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2447 gdb_flush (gdb_stdout
);
2450 /* Restore our global data. */
2451 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2452 dwarf2_objfile_data_key
);
2454 psymtab_to_symtab_1 (pst
);
2456 /* Finish up the debug error message. */
2458 printf_filtered (_("done.\n"));
2463 /* Add PER_CU to the queue. */
2466 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2468 struct dwarf2_queue_item
*item
;
2471 item
= xmalloc (sizeof (*item
));
2472 item
->per_cu
= per_cu
;
2475 if (dwarf2_queue
== NULL
)
2476 dwarf2_queue
= item
;
2478 dwarf2_queue_tail
->next
= item
;
2480 dwarf2_queue_tail
= item
;
2482 /* Either PER_CU is the CU we want to process, or we're following a reference
2483 pointing into PER_CU. Either way, we need its DIEs now. */
2484 load_full_comp_unit (item
->per_cu
, objfile
);
2485 item
->per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
2486 dwarf2_per_objfile
->read_in_chain
= item
->per_cu
;
2489 /* Process the queue. */
2492 process_queue (struct objfile
*objfile
)
2494 struct dwarf2_queue_item
*item
, *next_item
;
2496 /* The queue starts out with one item, but following a DIE reference
2497 may load a new CU, adding it to the end of the queue. */
2498 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2500 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2501 process_full_comp_unit (item
->per_cu
);
2503 item
->per_cu
->queued
= 0;
2504 next_item
= item
->next
;
2508 dwarf2_queue_tail
= NULL
;
2511 /* Free all allocated queue entries. This function only releases anything if
2512 an error was thrown; if the queue was processed then it would have been
2513 freed as we went along. */
2516 dwarf2_release_queue (void *dummy
)
2518 struct dwarf2_queue_item
*item
, *last
;
2520 item
= dwarf2_queue
;
2523 /* Anything still marked queued is likely to be in an
2524 inconsistent state, so discard it. */
2525 if (item
->per_cu
->queued
)
2527 if (item
->per_cu
->cu
!= NULL
)
2528 free_one_cached_comp_unit (item
->per_cu
->cu
);
2529 item
->per_cu
->queued
= 0;
2537 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2540 /* Read in full symbols for PST, and anything it depends on. */
2543 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2545 struct dwarf2_per_cu_data
*per_cu
;
2546 struct cleanup
*back_to
;
2549 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2550 if (!pst
->dependencies
[i
]->readin
)
2552 /* Inform about additional files that need to be read in. */
2555 /* FIXME: i18n: Need to make this a single string. */
2556 fputs_filtered (" ", gdb_stdout
);
2558 fputs_filtered ("and ", gdb_stdout
);
2560 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2561 wrap_here (""); /* Flush output */
2562 gdb_flush (gdb_stdout
);
2564 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2567 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
2571 /* It's an include file, no symbols to read for it.
2572 Everything is in the parent symtab. */
2577 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2579 queue_comp_unit (per_cu
, pst
->objfile
);
2581 process_queue (pst
->objfile
);
2583 /* Age the cache, releasing compilation units that have not
2584 been used recently. */
2585 age_cached_comp_units ();
2587 do_cleanups (back_to
);
2590 /* Load the DIEs associated with PST and PER_CU into memory. */
2592 static struct dwarf2_cu
*
2593 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2595 bfd
*abfd
= objfile
->obfd
;
2596 struct dwarf2_cu
*cu
;
2597 unsigned long offset
;
2599 struct cleanup
*back_to
, *free_cu_cleanup
;
2600 struct attribute
*attr
;
2603 /* Set local variables from the partial symbol table info. */
2604 offset
= per_cu
->offset
;
2606 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2608 cu
= xmalloc (sizeof (struct dwarf2_cu
));
2609 memset (cu
, 0, sizeof (struct dwarf2_cu
));
2611 /* If an error occurs while loading, release our storage. */
2612 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
2614 cu
->objfile
= objfile
;
2616 /* read in the comp_unit header */
2617 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
2619 /* Read the abbrevs for this compilation unit */
2620 dwarf2_read_abbrevs (abfd
, cu
);
2621 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2623 cu
->header
.offset
= offset
;
2625 cu
->per_cu
= per_cu
;
2627 cu
->type_hash
= per_cu
->type_hash
;
2629 /* We use this obstack for block values in dwarf_alloc_block. */
2630 obstack_init (&cu
->comp_unit_obstack
);
2632 cu
->dies
= read_comp_unit (info_ptr
, abfd
, cu
);
2634 /* We try not to read any attributes in this function, because not
2635 all objfiles needed for references have been loaded yet, and symbol
2636 table processing isn't initialized. But we have to set the CU language,
2637 or we won't be able to build types correctly. */
2638 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
2640 set_cu_language (DW_UNSND (attr
), cu
);
2642 set_cu_language (language_minimal
, cu
);
2644 do_cleanups (back_to
);
2646 /* We've successfully allocated this compilation unit. Let our caller
2647 clean it up when finished with it. */
2648 discard_cleanups (free_cu_cleanup
);
2653 /* Generate full symbol information for PST and CU, whose DIEs have
2654 already been loaded into memory. */
2657 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2659 struct partial_symtab
*pst
= per_cu
->psymtab
;
2660 struct dwarf2_cu
*cu
= per_cu
->cu
;
2661 struct objfile
*objfile
= pst
->objfile
;
2662 bfd
*abfd
= objfile
->obfd
;
2663 CORE_ADDR lowpc
, highpc
;
2664 struct symtab
*symtab
;
2665 struct cleanup
*back_to
;
2666 struct attribute
*attr
;
2669 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2672 back_to
= make_cleanup (really_free_pendings
, NULL
);
2674 cu
->list_in_scope
= &file_symbols
;
2676 /* Find the base address of the compilation unit for range lists and
2677 location lists. It will normally be specified by DW_AT_low_pc.
2678 In DWARF-3 draft 4, the base address could be overridden by
2679 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2680 compilation units with discontinuous ranges. */
2683 cu
->base_address
= 0;
2685 attr
= dwarf2_attr (cu
->dies
, DW_AT_entry_pc
, cu
);
2688 cu
->base_address
= DW_ADDR (attr
);
2693 attr
= dwarf2_attr (cu
->dies
, DW_AT_low_pc
, cu
);
2696 cu
->base_address
= DW_ADDR (attr
);
2701 /* Do line number decoding in read_file_scope () */
2702 process_die (cu
->dies
, cu
);
2704 /* Some compilers don't define a DW_AT_high_pc attribute for the
2705 compilation unit. If the DW_AT_high_pc is missing, synthesize
2706 it, by scanning the DIE's below the compilation unit. */
2707 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
2709 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2711 /* Set symtab language to language from DW_AT_language.
2712 If the compilation is from a C file generated by language preprocessors,
2713 do not set the language if it was already deduced by start_subfile. */
2715 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
2717 symtab
->language
= cu
->language
;
2719 pst
->symtab
= symtab
;
2722 do_cleanups (back_to
);
2725 /* Process a die and its children. */
2728 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2732 case DW_TAG_padding
:
2734 case DW_TAG_compile_unit
:
2735 read_file_scope (die
, cu
);
2737 case DW_TAG_subprogram
:
2738 read_func_scope (die
, cu
);
2740 case DW_TAG_inlined_subroutine
:
2741 /* FIXME: These are ignored for now.
2742 They could be used to set breakpoints on all inlined instances
2743 of a function and make GDB `next' properly over inlined functions. */
2745 case DW_TAG_lexical_block
:
2746 case DW_TAG_try_block
:
2747 case DW_TAG_catch_block
:
2748 read_lexical_block_scope (die
, cu
);
2750 case DW_TAG_class_type
:
2751 case DW_TAG_interface_type
:
2752 case DW_TAG_structure_type
:
2753 case DW_TAG_union_type
:
2754 process_structure_scope (die
, cu
);
2756 case DW_TAG_enumeration_type
:
2757 process_enumeration_scope (die
, cu
);
2760 /* These dies have a type, but processing them does not create
2761 a symbol or recurse to process the children. Therefore we can
2762 read them on-demand through read_type_die. */
2763 case DW_TAG_subroutine_type
:
2764 case DW_TAG_set_type
:
2765 case DW_TAG_array_type
:
2766 case DW_TAG_pointer_type
:
2767 case DW_TAG_ptr_to_member_type
:
2768 case DW_TAG_reference_type
:
2769 case DW_TAG_string_type
:
2772 case DW_TAG_base_type
:
2773 case DW_TAG_subrange_type
:
2774 /* Add a typedef symbol for the type definition, if it has a
2776 new_symbol (die
, read_type_die (die
, cu
), cu
);
2778 case DW_TAG_common_block
:
2779 read_common_block (die
, cu
);
2781 case DW_TAG_common_inclusion
:
2783 case DW_TAG_namespace
:
2784 processing_has_namespace_info
= 1;
2785 read_namespace (die
, cu
);
2787 case DW_TAG_imported_declaration
:
2788 case DW_TAG_imported_module
:
2789 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2790 information contained in these. DW_TAG_imported_declaration
2791 dies shouldn't have children; DW_TAG_imported_module dies
2792 shouldn't in the C++ case, but conceivably could in the
2794 processing_has_namespace_info
= 1;
2795 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
2796 dwarf_tag_name (die
->tag
));
2799 new_symbol (die
, NULL
, cu
);
2804 /* Return the fully qualified name of DIE, based on its DW_AT_name.
2805 If scope qualifiers are appropriate they will be added. The result
2806 will be allocated on the objfile_obstack, or NULL if the DIE does
2810 dwarf2_full_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
2812 struct attribute
*attr
;
2813 char *prefix
, *name
;
2814 struct ui_file
*buf
= NULL
;
2816 name
= dwarf2_name (die
, cu
);
2820 /* These are the only languages we know how to qualify names in. */
2821 if (cu
->language
!= language_cplus
2822 && cu
->language
!= language_java
)
2825 /* If no prefix is necessary for this type of DIE, return the
2826 unqualified name. The other three tags listed could be handled
2827 in pdi_needs_namespace, but that requires broader changes. */
2828 if (!pdi_needs_namespace (die
->tag
)
2829 && die
->tag
!= DW_TAG_subprogram
2830 && die
->tag
!= DW_TAG_variable
2831 && die
->tag
!= DW_TAG_member
)
2834 prefix
= determine_prefix (die
, cu
);
2835 if (*prefix
!= '\0')
2836 name
= typename_concat (&cu
->objfile
->objfile_obstack
, prefix
,
2843 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2845 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2849 free_cu_line_header (void *arg
)
2851 struct dwarf2_cu
*cu
= arg
;
2853 free_line_header (cu
->line_header
);
2854 cu
->line_header
= NULL
;
2858 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2860 struct objfile
*objfile
= cu
->objfile
;
2861 struct comp_unit_head
*cu_header
= &cu
->header
;
2862 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2863 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2864 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2865 struct attribute
*attr
;
2867 char *comp_dir
= NULL
;
2868 struct die_info
*child_die
;
2869 bfd
*abfd
= objfile
->obfd
;
2870 struct line_header
*line_header
= 0;
2873 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2875 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2877 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2878 from finish_block. */
2879 if (lowpc
== ((CORE_ADDR
) -1))
2884 /* Find the filename. Do not use dwarf2_name here, since the filename
2885 is not a source language identifier. */
2886 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2889 name
= DW_STRING (attr
);
2892 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2894 comp_dir
= DW_STRING (attr
);
2895 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
2897 comp_dir
= ldirname (name
);
2898 if (comp_dir
!= NULL
)
2899 make_cleanup (xfree
, comp_dir
);
2901 if (comp_dir
!= NULL
)
2903 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2904 directory, get rid of it. */
2905 char *cp
= strchr (comp_dir
, ':');
2907 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2914 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2917 set_cu_language (DW_UNSND (attr
), cu
);
2920 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
2922 cu
->producer
= DW_STRING (attr
);
2924 /* We assume that we're processing GCC output. */
2925 processing_gcc_compilation
= 2;
2927 processing_has_namespace_info
= 0;
2929 start_symtab (name
, comp_dir
, lowpc
);
2930 record_debugformat ("DWARF 2");
2931 record_producer (cu
->producer
);
2933 initialize_cu_func_list (cu
);
2935 /* Decode line number information if present. We do this before
2936 processing child DIEs, so that the line header table is available
2937 for DW_AT_decl_file. */
2938 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2941 unsigned int line_offset
= DW_UNSND (attr
);
2942 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2945 cu
->line_header
= line_header
;
2946 make_cleanup (free_cu_line_header
, cu
);
2947 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
2951 /* Process all dies in compilation unit. */
2952 if (die
->child
!= NULL
)
2954 child_die
= die
->child
;
2955 while (child_die
&& child_die
->tag
)
2957 process_die (child_die
, cu
);
2958 child_die
= sibling_die (child_die
);
2962 /* Decode macro information, if present. Dwarf 2 macro information
2963 refers to information in the line number info statement program
2964 header, so we can only read it if we've read the header
2966 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2967 if (attr
&& line_header
)
2969 unsigned int macro_offset
= DW_UNSND (attr
);
2970 dwarf_decode_macros (line_header
, macro_offset
,
2971 comp_dir
, abfd
, cu
);
2973 do_cleanups (back_to
);
2977 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2978 struct dwarf2_cu
*cu
)
2980 struct function_range
*thisfn
;
2982 thisfn
= (struct function_range
*)
2983 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
2984 thisfn
->name
= name
;
2985 thisfn
->lowpc
= lowpc
;
2986 thisfn
->highpc
= highpc
;
2987 thisfn
->seen_line
= 0;
2988 thisfn
->next
= NULL
;
2990 if (cu
->last_fn
== NULL
)
2991 cu
->first_fn
= thisfn
;
2993 cu
->last_fn
->next
= thisfn
;
2995 cu
->last_fn
= thisfn
;
2999 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3001 struct objfile
*objfile
= cu
->objfile
;
3002 struct context_stack
*new;
3005 struct die_info
*child_die
;
3006 struct attribute
*attr
;
3009 struct block
*block
;
3011 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3013 name
= dwarf2_linkage_name (die
, cu
);
3015 /* Ignore functions with missing or empty names and functions with
3016 missing or invalid low and high pc attributes. */
3017 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3023 /* Record the function range for dwarf_decode_lines. */
3024 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
3026 new = push_context (0, lowpc
);
3027 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
3029 /* If there is a location expression for DW_AT_frame_base, record
3031 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3033 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3034 expression is being recorded directly in the function's symbol
3035 and not in a separate frame-base object. I guess this hack is
3036 to avoid adding some sort of frame-base adjunct/annex to the
3037 function's symbol :-(. The problem with doing this is that it
3038 results in a function symbol with a location expression that
3039 has nothing to do with the location of the function, ouch! The
3040 relationship should be: a function's symbol has-a frame base; a
3041 frame-base has-a location expression. */
3042 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3044 cu
->list_in_scope
= &local_symbols
;
3046 if (die
->child
!= NULL
)
3048 child_die
= die
->child
;
3049 while (child_die
&& child_die
->tag
)
3051 process_die (child_die
, cu
);
3052 child_die
= sibling_die (child_die
);
3056 new = pop_context ();
3057 /* Make a block for the local symbols within. */
3058 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3059 lowpc
, highpc
, objfile
);
3061 /* For C++, set the block's scope. */
3062 if (cu
->language
== language_cplus
)
3063 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
3064 determine_prefix (die
, cu
),
3065 processing_has_namespace_info
);
3067 /* If we have address ranges, record them. */
3068 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3070 /* In C++, we can have functions nested inside functions (e.g., when
3071 a function declares a class that has methods). This means that
3072 when we finish processing a function scope, we may need to go
3073 back to building a containing block's symbol lists. */
3074 local_symbols
= new->locals
;
3075 param_symbols
= new->params
;
3077 /* If we've finished processing a top-level function, subsequent
3078 symbols go in the file symbol list. */
3079 if (outermost_context_p ())
3080 cu
->list_in_scope
= &file_symbols
;
3083 /* Process all the DIES contained within a lexical block scope. Start
3084 a new scope, process the dies, and then close the scope. */
3087 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3089 struct objfile
*objfile
= cu
->objfile
;
3090 struct context_stack
*new;
3091 CORE_ADDR lowpc
, highpc
;
3092 struct die_info
*child_die
;
3095 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3097 /* Ignore blocks with missing or invalid low and high pc attributes. */
3098 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3099 as multiple lexical blocks? Handling children in a sane way would
3100 be nasty. Might be easier to properly extend generic blocks to
3102 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3107 push_context (0, lowpc
);
3108 if (die
->child
!= NULL
)
3110 child_die
= die
->child
;
3111 while (child_die
&& child_die
->tag
)
3113 process_die (child_die
, cu
);
3114 child_die
= sibling_die (child_die
);
3117 new = pop_context ();
3119 if (local_symbols
!= NULL
)
3122 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3125 /* Note that recording ranges after traversing children, as we
3126 do here, means that recording a parent's ranges entails
3127 walking across all its children's ranges as they appear in
3128 the address map, which is quadratic behavior.
3130 It would be nicer to record the parent's ranges before
3131 traversing its children, simply overriding whatever you find
3132 there. But since we don't even decide whether to create a
3133 block until after we've traversed its children, that's hard
3135 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3137 local_symbols
= new->locals
;
3140 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3141 Return 1 if the attributes are present and valid, otherwise, return 0.
3142 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3145 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
3146 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
3147 struct partial_symtab
*ranges_pst
)
3149 struct objfile
*objfile
= cu
->objfile
;
3150 struct comp_unit_head
*cu_header
= &cu
->header
;
3151 bfd
*obfd
= objfile
->obfd
;
3152 unsigned int addr_size
= cu_header
->addr_size
;
3153 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3154 /* Base address selection entry. */
3165 found_base
= cu
->base_known
;
3166 base
= cu
->base_address
;
3168 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3170 complaint (&symfile_complaints
,
3171 _("Offset %d out of bounds for DW_AT_ranges attribute"),
3175 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3177 /* Read in the largest possible address. */
3178 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
3179 if ((marker
& mask
) == mask
)
3181 /* If we found the largest possible address, then
3182 read the base address. */
3183 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3184 buffer
+= 2 * addr_size
;
3185 offset
+= 2 * addr_size
;
3191 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3195 CORE_ADDR range_beginning
, range_end
;
3197 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
3198 buffer
+= addr_size
;
3199 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
3200 buffer
+= addr_size
;
3201 offset
+= 2 * addr_size
;
3203 /* An end of list marker is a pair of zero addresses. */
3204 if (range_beginning
== 0 && range_end
== 0)
3205 /* Found the end of list entry. */
3208 /* Each base address selection entry is a pair of 2 values.
3209 The first is the largest possible address, the second is
3210 the base address. Check for a base address here. */
3211 if ((range_beginning
& mask
) == mask
)
3213 /* If we found the largest possible address, then
3214 read the base address. */
3215 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3222 /* We have no valid base address for the ranges
3224 complaint (&symfile_complaints
,
3225 _("Invalid .debug_ranges data (no base address)"));
3229 range_beginning
+= base
;
3232 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
3233 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3234 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
3237 /* FIXME: This is recording everything as a low-high
3238 segment of consecutive addresses. We should have a
3239 data structure for discontiguous block ranges
3243 low
= range_beginning
;
3249 if (range_beginning
< low
)
3250 low
= range_beginning
;
3251 if (range_end
> high
)
3257 /* If the first entry is an end-of-list marker, the range
3258 describes an empty scope, i.e. no instructions. */
3264 *high_return
= high
;
3268 /* Get low and high pc attributes from a die. Return 1 if the attributes
3269 are present and valid, otherwise, return 0. Return -1 if the range is
3270 discontinuous, i.e. derived from DW_AT_ranges information. */
3272 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
3273 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
3275 struct attribute
*attr
;
3280 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3283 high
= DW_ADDR (attr
);
3284 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3286 low
= DW_ADDR (attr
);
3288 /* Found high w/o low attribute. */
3291 /* Found consecutive range of addresses. */
3296 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3299 /* Value of the DW_AT_ranges attribute is the offset in the
3300 .debug_ranges section. */
3301 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, NULL
))
3303 /* Found discontinuous range of addresses. */
3311 /* When using the GNU linker, .gnu.linkonce. sections are used to
3312 eliminate duplicate copies of functions and vtables and such.
3313 The linker will arbitrarily choose one and discard the others.
3314 The AT_*_pc values for such functions refer to local labels in
3315 these sections. If the section from that file was discarded, the
3316 labels are not in the output, so the relocs get a value of 0.
3317 If this is a discarded function, mark the pc bounds as invalid,
3318 so that GDB will ignore it. */
3319 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3327 /* Get the low and high pc's represented by the scope DIE, and store
3328 them in *LOWPC and *HIGHPC. If the correct values can't be
3329 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3332 get_scope_pc_bounds (struct die_info
*die
,
3333 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3334 struct dwarf2_cu
*cu
)
3336 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3337 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3338 CORE_ADDR current_low
, current_high
;
3340 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3342 best_low
= current_low
;
3343 best_high
= current_high
;
3347 struct die_info
*child
= die
->child
;
3349 while (child
&& child
->tag
)
3351 switch (child
->tag
) {
3352 case DW_TAG_subprogram
:
3353 if (dwarf2_get_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
))
3355 best_low
= min (best_low
, current_low
);
3356 best_high
= max (best_high
, current_high
);
3359 case DW_TAG_namespace
:
3360 /* FIXME: carlton/2004-01-16: Should we do this for
3361 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3362 that current GCC's always emit the DIEs corresponding
3363 to definitions of methods of classes as children of a
3364 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3365 the DIEs giving the declarations, which could be
3366 anywhere). But I don't see any reason why the
3367 standards says that they have to be there. */
3368 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3370 if (current_low
!= ((CORE_ADDR
) -1))
3372 best_low
= min (best_low
, current_low
);
3373 best_high
= max (best_high
, current_high
);
3381 child
= sibling_die (child
);
3386 *highpc
= best_high
;
3389 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
3392 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
3393 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
3395 struct attribute
*attr
;
3397 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3400 CORE_ADDR high
= DW_ADDR (attr
);
3401 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3404 CORE_ADDR low
= DW_ADDR (attr
);
3405 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
3409 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3412 bfd
*obfd
= cu
->objfile
->obfd
;
3414 /* The value of the DW_AT_ranges attribute is the offset of the
3415 address range list in the .debug_ranges section. */
3416 unsigned long offset
= DW_UNSND (attr
);
3417 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3419 /* For some target architectures, but not others, the
3420 read_address function sign-extends the addresses it returns.
3421 To recognize base address selection entries, we need a
3423 unsigned int addr_size
= cu
->header
.addr_size
;
3424 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3426 /* The base address, to which the next pair is relative. Note
3427 that this 'base' is a DWARF concept: most entries in a range
3428 list are relative, to reduce the number of relocs against the
3429 debugging information. This is separate from this function's
3430 'baseaddr' argument, which GDB uses to relocate debugging
3431 information from a shared library based on the address at
3432 which the library was loaded. */
3433 CORE_ADDR base
= cu
->base_address
;
3434 int base_known
= cu
->base_known
;
3436 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3438 complaint (&symfile_complaints
,
3439 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
3446 unsigned int bytes_read
;
3447 CORE_ADDR start
, end
;
3449 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3450 buffer
+= bytes_read
;
3451 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3452 buffer
+= bytes_read
;
3454 /* Did we find the end of the range list? */
3455 if (start
== 0 && end
== 0)
3458 /* Did we find a base address selection entry? */
3459 else if ((start
& base_select_mask
) == base_select_mask
)
3465 /* We found an ordinary address range. */
3470 complaint (&symfile_complaints
,
3471 _("Invalid .debug_ranges data (no base address)"));
3475 record_block_range (block
,
3476 baseaddr
+ base
+ start
,
3477 baseaddr
+ base
+ end
- 1);
3483 /* Add an aggregate field to the field list. */
3486 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3487 struct dwarf2_cu
*cu
)
3489 struct objfile
*objfile
= cu
->objfile
;
3490 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3491 struct nextfield
*new_field
;
3492 struct attribute
*attr
;
3494 char *fieldname
= "";
3496 /* Allocate a new field list entry and link it in. */
3497 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3498 make_cleanup (xfree
, new_field
);
3499 memset (new_field
, 0, sizeof (struct nextfield
));
3500 new_field
->next
= fip
->fields
;
3501 fip
->fields
= new_field
;
3504 /* Handle accessibility and virtuality of field.
3505 The default accessibility for members is public, the default
3506 accessibility for inheritance is private. */
3507 if (die
->tag
!= DW_TAG_inheritance
)
3508 new_field
->accessibility
= DW_ACCESS_public
;
3510 new_field
->accessibility
= DW_ACCESS_private
;
3511 new_field
->virtuality
= DW_VIRTUALITY_none
;
3513 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3515 new_field
->accessibility
= DW_UNSND (attr
);
3516 if (new_field
->accessibility
!= DW_ACCESS_public
)
3517 fip
->non_public_fields
= 1;
3518 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3520 new_field
->virtuality
= DW_UNSND (attr
);
3522 fp
= &new_field
->field
;
3524 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3526 /* Data member other than a C++ static data member. */
3528 /* Get type of field. */
3529 fp
->type
= die_type (die
, cu
);
3531 FIELD_STATIC_KIND (*fp
) = 0;
3533 /* Get bit size of field (zero if none). */
3534 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3537 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3541 FIELD_BITSIZE (*fp
) = 0;
3544 /* Get bit offset of field. */
3545 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3550 if (attr_form_is_section_offset (attr
))
3552 dwarf2_complex_location_expr_complaint ();
3555 else if (attr_form_is_constant (attr
))
3556 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
3558 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
3560 FIELD_BITPOS (*fp
) = byte_offset
* bits_per_byte
;
3563 FIELD_BITPOS (*fp
) = 0;
3564 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3567 if (gdbarch_bits_big_endian (gdbarch
))
3569 /* For big endian bits, the DW_AT_bit_offset gives the
3570 additional bit offset from the MSB of the containing
3571 anonymous object to the MSB of the field. We don't
3572 have to do anything special since we don't need to
3573 know the size of the anonymous object. */
3574 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3578 /* For little endian bits, compute the bit offset to the
3579 MSB of the anonymous object, subtract off the number of
3580 bits from the MSB of the field to the MSB of the
3581 object, and then subtract off the number of bits of
3582 the field itself. The result is the bit offset of
3583 the LSB of the field. */
3585 int bit_offset
= DW_UNSND (attr
);
3587 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3590 /* The size of the anonymous object containing
3591 the bit field is explicit, so use the
3592 indicated size (in bytes). */
3593 anonymous_size
= DW_UNSND (attr
);
3597 /* The size of the anonymous object containing
3598 the bit field must be inferred from the type
3599 attribute of the data member containing the
3601 anonymous_size
= TYPE_LENGTH (fp
->type
);
3603 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
3604 - bit_offset
- FIELD_BITSIZE (*fp
);
3608 /* Get name of field. */
3609 fieldname
= dwarf2_name (die
, cu
);
3610 if (fieldname
== NULL
)
3613 /* The name is already allocated along with this objfile, so we don't
3614 need to duplicate it for the type. */
3615 fp
->name
= fieldname
;
3617 /* Change accessibility for artificial fields (e.g. virtual table
3618 pointer or virtual base class pointer) to private. */
3619 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
3621 new_field
->accessibility
= DW_ACCESS_private
;
3622 fip
->non_public_fields
= 1;
3625 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
3627 /* C++ static member. */
3629 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3630 is a declaration, but all versions of G++ as of this writing
3631 (so through at least 3.2.1) incorrectly generate
3632 DW_TAG_variable tags. */
3636 /* Get name of field. */
3637 fieldname
= dwarf2_name (die
, cu
);
3638 if (fieldname
== NULL
)
3641 /* Get physical name. */
3642 physname
= dwarf2_linkage_name (die
, cu
);
3644 /* The name is already allocated along with this objfile, so we don't
3645 need to duplicate it for the type. */
3646 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
3647 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3648 FIELD_NAME (*fp
) = fieldname
;
3650 else if (die
->tag
== DW_TAG_inheritance
)
3652 /* C++ base class field. */
3653 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3655 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
3657 FIELD_BITSIZE (*fp
) = 0;
3658 FIELD_STATIC_KIND (*fp
) = 0;
3659 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3660 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
3661 fip
->nbaseclasses
++;
3665 /* Create the vector of fields, and attach it to the type. */
3668 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3669 struct dwarf2_cu
*cu
)
3671 int nfields
= fip
->nfields
;
3673 /* Record the field count, allocate space for the array of fields,
3674 and create blank accessibility bitfields if necessary. */
3675 TYPE_NFIELDS (type
) = nfields
;
3676 TYPE_FIELDS (type
) = (struct field
*)
3677 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3678 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3680 if (fip
->non_public_fields
)
3682 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3684 TYPE_FIELD_PRIVATE_BITS (type
) =
3685 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3686 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3688 TYPE_FIELD_PROTECTED_BITS (type
) =
3689 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3690 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3692 TYPE_FIELD_IGNORE_BITS (type
) =
3693 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3694 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3697 /* If the type has baseclasses, allocate and clear a bit vector for
3698 TYPE_FIELD_VIRTUAL_BITS. */
3699 if (fip
->nbaseclasses
)
3701 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3702 unsigned char *pointer
;
3704 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3705 pointer
= TYPE_ALLOC (type
, num_bytes
);
3706 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
3707 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3708 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3711 /* Copy the saved-up fields into the field vector. Start from the head
3712 of the list, adding to the tail of the field array, so that they end
3713 up in the same order in the array in which they were added to the list. */
3714 while (nfields
-- > 0)
3716 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3717 switch (fip
->fields
->accessibility
)
3719 case DW_ACCESS_private
:
3720 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3723 case DW_ACCESS_protected
:
3724 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3727 case DW_ACCESS_public
:
3731 /* Unknown accessibility. Complain and treat it as public. */
3733 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
3734 fip
->fields
->accessibility
);
3738 if (nfields
< fip
->nbaseclasses
)
3740 switch (fip
->fields
->virtuality
)
3742 case DW_VIRTUALITY_virtual
:
3743 case DW_VIRTUALITY_pure_virtual
:
3744 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3748 fip
->fields
= fip
->fields
->next
;
3752 /* Add a member function to the proper fieldlist. */
3755 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3756 struct type
*type
, struct dwarf2_cu
*cu
)
3758 struct objfile
*objfile
= cu
->objfile
;
3759 struct attribute
*attr
;
3760 struct fnfieldlist
*flp
;
3762 struct fn_field
*fnp
;
3765 struct nextfnfield
*new_fnfield
;
3766 struct type
*this_type
;
3768 /* Get name of member function. */
3769 fieldname
= dwarf2_name (die
, cu
);
3770 if (fieldname
== NULL
)
3773 /* Get the mangled name. */
3774 physname
= dwarf2_linkage_name (die
, cu
);
3776 /* Look up member function name in fieldlist. */
3777 for (i
= 0; i
< fip
->nfnfields
; i
++)
3779 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3783 /* Create new list element if necessary. */
3784 if (i
< fip
->nfnfields
)
3785 flp
= &fip
->fnfieldlists
[i
];
3788 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3790 fip
->fnfieldlists
= (struct fnfieldlist
*)
3791 xrealloc (fip
->fnfieldlists
,
3792 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3793 * sizeof (struct fnfieldlist
));
3794 if (fip
->nfnfields
== 0)
3795 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3797 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3798 flp
->name
= fieldname
;
3804 /* Create a new member function field and chain it to the field list
3806 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3807 make_cleanup (xfree
, new_fnfield
);
3808 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3809 new_fnfield
->next
= flp
->head
;
3810 flp
->head
= new_fnfield
;
3813 /* Fill in the member function field info. */
3814 fnp
= &new_fnfield
->fnfield
;
3815 /* The name is already allocated along with this objfile, so we don't
3816 need to duplicate it for the type. */
3817 fnp
->physname
= physname
? physname
: "";
3818 fnp
->type
= alloc_type (objfile
);
3819 this_type
= read_type_die (die
, cu
);
3820 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
3822 int nparams
= TYPE_NFIELDS (this_type
);
3824 /* TYPE is the domain of this method, and THIS_TYPE is the type
3825 of the method itself (TYPE_CODE_METHOD). */
3826 smash_to_method_type (fnp
->type
, type
,
3827 TYPE_TARGET_TYPE (this_type
),
3828 TYPE_FIELDS (this_type
),
3829 TYPE_NFIELDS (this_type
),
3830 TYPE_VARARGS (this_type
));
3832 /* Handle static member functions.
3833 Dwarf2 has no clean way to discern C++ static and non-static
3834 member functions. G++ helps GDB by marking the first
3835 parameter for non-static member functions (which is the
3836 this pointer) as artificial. We obtain this information
3837 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3838 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
3839 fnp
->voffset
= VOFFSET_STATIC
;
3842 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
3845 /* Get fcontext from DW_AT_containing_type if present. */
3846 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3847 fnp
->fcontext
= die_containing_type (die
, cu
);
3849 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3850 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3852 /* Get accessibility. */
3853 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3856 switch (DW_UNSND (attr
))
3858 case DW_ACCESS_private
:
3859 fnp
->is_private
= 1;
3861 case DW_ACCESS_protected
:
3862 fnp
->is_protected
= 1;
3867 /* Check for artificial methods. */
3868 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3869 if (attr
&& DW_UNSND (attr
) != 0)
3870 fnp
->is_artificial
= 1;
3872 /* Get index in virtual function table if it is a virtual member function. */
3873 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3876 /* Support the .debug_loc offsets */
3877 if (attr_form_is_block (attr
))
3879 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3881 else if (attr_form_is_section_offset (attr
))
3883 dwarf2_complex_location_expr_complaint ();
3887 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3893 /* Create the vector of member function fields, and attach it to the type. */
3896 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3897 struct dwarf2_cu
*cu
)
3899 struct fnfieldlist
*flp
;
3900 int total_length
= 0;
3903 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3904 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3905 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3907 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3909 struct nextfnfield
*nfp
= flp
->head
;
3910 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3913 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3914 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3915 fn_flp
->fn_fields
= (struct fn_field
*)
3916 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3917 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3918 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3920 total_length
+= flp
->length
;
3923 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3924 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3927 /* Returns non-zero if NAME is the name of a vtable member in CU's
3928 language, zero otherwise. */
3930 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
3932 static const char vptr
[] = "_vptr";
3933 static const char vtable
[] = "vtable";
3935 /* Look for the C++ and Java forms of the vtable. */
3936 if ((cu
->language
== language_java
3937 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
3938 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
3939 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
3945 /* GCC outputs unnamed structures that are really pointers to member
3946 functions, with the ABI-specified layout. If DIE (from CU) describes
3947 such a structure, set its type, and return nonzero. Otherwise return
3950 GCC shouldn't do this; it should just output pointer to member DIEs.
3951 This is GCC PR debug/28767. */
3953 static struct type
*
3954 quirk_gcc_member_function_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
)
3956 struct objfile
*objfile
= cu
->objfile
;
3958 struct die_info
*pfn_die
, *delta_die
;
3959 struct attribute
*pfn_name
, *delta_name
;
3960 struct type
*pfn_type
, *domain_type
;
3962 /* Check for a structure with no name and two children. */
3963 if (die
->tag
!= DW_TAG_structure_type
3964 || dwarf2_attr (die
, DW_AT_name
, cu
) != NULL
3965 || die
->child
== NULL
3966 || die
->child
->sibling
== NULL
3967 || (die
->child
->sibling
->sibling
!= NULL
3968 && die
->child
->sibling
->sibling
->tag
!= DW_TAG_padding
))
3971 /* Check for __pfn and __delta members. */
3972 pfn_die
= die
->child
;
3973 pfn_name
= dwarf2_attr (pfn_die
, DW_AT_name
, cu
);
3974 if (pfn_die
->tag
!= DW_TAG_member
3976 || DW_STRING (pfn_name
) == NULL
3977 || strcmp ("__pfn", DW_STRING (pfn_name
)) != 0)
3980 delta_die
= pfn_die
->sibling
;
3981 delta_name
= dwarf2_attr (delta_die
, DW_AT_name
, cu
);
3982 if (delta_die
->tag
!= DW_TAG_member
3983 || delta_name
== NULL
3984 || DW_STRING (delta_name
) == NULL
3985 || strcmp ("__delta", DW_STRING (delta_name
)) != 0)
3988 /* Find the type of the method. */
3989 pfn_type
= die_type (pfn_die
, cu
);
3990 if (pfn_type
== NULL
3991 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
3992 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
3995 /* Look for the "this" argument. */
3996 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
3997 if (TYPE_NFIELDS (pfn_type
) == 0
3998 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
4001 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
4002 type
= alloc_type (objfile
);
4003 smash_to_method_type (type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
4004 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
4005 TYPE_VARARGS (pfn_type
));
4006 type
= lookup_methodptr_type (type
);
4007 return set_die_type (die
, type
, cu
);
4010 /* Called when we find the DIE that starts a structure or union scope
4011 (definition) to process all dies that define the members of the
4014 NOTE: we need to call struct_type regardless of whether or not the
4015 DIE has an at_name attribute, since it might be an anonymous
4016 structure or union. This gets the type entered into our set of
4019 However, if the structure is incomplete (an opaque struct/union)
4020 then suppress creating a symbol table entry for it since gdb only
4021 wants to find the one with the complete definition. Note that if
4022 it is complete, we just call new_symbol, which does it's own
4023 checking about whether the struct/union is anonymous or not (and
4024 suppresses creating a symbol table entry itself). */
4026 static struct type
*
4027 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4029 struct objfile
*objfile
= cu
->objfile
;
4031 struct attribute
*attr
;
4033 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4035 type
= quirk_gcc_member_function_pointer (die
, cu
);
4039 type
= alloc_type (objfile
);
4040 INIT_CPLUS_SPECIFIC (type
);
4041 name
= dwarf2_name (die
, cu
);
4044 if (cu
->language
== language_cplus
4045 || cu
->language
== language_java
)
4047 const char *new_prefix
= determine_class_name (die
, cu
);
4048 TYPE_TAG_NAME (type
) = (char *) new_prefix
;
4052 /* The name is already allocated along with this objfile, so
4053 we don't need to duplicate it for the type. */
4054 TYPE_TAG_NAME (type
) = name
;
4058 if (die
->tag
== DW_TAG_structure_type
)
4060 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
4062 else if (die
->tag
== DW_TAG_union_type
)
4064 TYPE_CODE (type
) = TYPE_CODE_UNION
;
4068 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
4070 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
4073 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4076 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4080 TYPE_LENGTH (type
) = 0;
4083 TYPE_STUB_SUPPORTED (type
) = 1;
4084 if (die_is_declaration (die
, cu
))
4085 TYPE_STUB (type
) = 1;
4087 /* We need to add the type field to the die immediately so we don't
4088 infinitely recurse when dealing with pointers to the structure
4089 type within the structure itself. */
4090 set_die_type (die
, type
, cu
);
4092 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
4094 struct field_info fi
;
4095 struct die_info
*child_die
;
4097 memset (&fi
, 0, sizeof (struct field_info
));
4099 child_die
= die
->child
;
4101 while (child_die
&& child_die
->tag
)
4103 if (child_die
->tag
== DW_TAG_member
4104 || child_die
->tag
== DW_TAG_variable
)
4106 /* NOTE: carlton/2002-11-05: A C++ static data member
4107 should be a DW_TAG_member that is a declaration, but
4108 all versions of G++ as of this writing (so through at
4109 least 3.2.1) incorrectly generate DW_TAG_variable
4110 tags for them instead. */
4111 dwarf2_add_field (&fi
, child_die
, cu
);
4113 else if (child_die
->tag
== DW_TAG_subprogram
)
4115 /* C++ member function. */
4116 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
4118 else if (child_die
->tag
== DW_TAG_inheritance
)
4120 /* C++ base class field. */
4121 dwarf2_add_field (&fi
, child_die
, cu
);
4123 child_die
= sibling_die (child_die
);
4126 /* Attach fields and member functions to the type. */
4128 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
4131 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
4133 /* Get the type which refers to the base class (possibly this
4134 class itself) which contains the vtable pointer for the current
4135 class from the DW_AT_containing_type attribute. */
4137 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4139 struct type
*t
= die_containing_type (die
, cu
);
4141 TYPE_VPTR_BASETYPE (type
) = t
;
4146 /* Our own class provides vtbl ptr. */
4147 for (i
= TYPE_NFIELDS (t
) - 1;
4148 i
>= TYPE_N_BASECLASSES (t
);
4151 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
4153 if (is_vtable_name (fieldname
, cu
))
4155 TYPE_VPTR_FIELDNO (type
) = i
;
4160 /* Complain if virtual function table field not found. */
4161 if (i
< TYPE_N_BASECLASSES (t
))
4162 complaint (&symfile_complaints
,
4163 _("virtual function table pointer not found when defining class '%s'"),
4164 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
4169 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
4172 else if (cu
->producer
4173 && strncmp (cu
->producer
,
4174 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
4176 /* The IBM XLC compiler does not provide direct indication
4177 of the containing type, but the vtable pointer is
4178 always named __vfp. */
4182 for (i
= TYPE_NFIELDS (type
) - 1;
4183 i
>= TYPE_N_BASECLASSES (type
);
4186 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
4188 TYPE_VPTR_FIELDNO (type
) = i
;
4189 TYPE_VPTR_BASETYPE (type
) = type
;
4197 do_cleanups (back_to
);
4202 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4204 struct objfile
*objfile
= cu
->objfile
;
4205 struct die_info
*child_die
= die
->child
;
4206 struct type
*this_type
;
4208 this_type
= get_die_type (die
, cu
);
4209 if (this_type
== NULL
)
4210 this_type
= read_structure_type (die
, cu
);
4212 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
4213 snapshots) has been known to create a die giving a declaration
4214 for a class that has, as a child, a die giving a definition for a
4215 nested class. So we have to process our children even if the
4216 current die is a declaration. Normally, of course, a declaration
4217 won't have any children at all. */
4219 while (child_die
!= NULL
&& child_die
->tag
)
4221 if (child_die
->tag
== DW_TAG_member
4222 || child_die
->tag
== DW_TAG_variable
4223 || child_die
->tag
== DW_TAG_inheritance
)
4228 process_die (child_die
, cu
);
4230 child_die
= sibling_die (child_die
);
4233 /* Do not consider external references. According to the DWARF standard,
4234 these DIEs are identified by the fact that they have no byte_size
4235 attribute, and a declaration attribute. */
4236 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
4237 || !die_is_declaration (die
, cu
))
4238 new_symbol (die
, this_type
, cu
);
4241 /* Given a DW_AT_enumeration_type die, set its type. We do not
4242 complete the type's fields yet, or create any symbols. */
4244 static struct type
*
4245 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4247 struct objfile
*objfile
= cu
->objfile
;
4249 struct attribute
*attr
;
4252 type
= alloc_type (objfile
);
4254 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4255 name
= dwarf2_full_name (die
, cu
);
4257 TYPE_TAG_NAME (type
) = (char *) name
;
4259 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4262 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4266 TYPE_LENGTH (type
) = 0;
4269 /* The enumeration DIE can be incomplete. In Ada, any type can be
4270 declared as private in the package spec, and then defined only
4271 inside the package body. Such types are known as Taft Amendment
4272 Types. When another package uses such a type, an incomplete DIE
4273 may be generated by the compiler. */
4274 if (die_is_declaration (die
, cu
))
4275 TYPE_STUB (type
) = 1;
4277 return set_die_type (die
, type
, cu
);
4280 /* Determine the name of the type represented by DIE, which should be
4281 a named C++ or Java compound type. Return the name in question,
4282 allocated on the objfile obstack. */
4285 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
4287 const char *new_prefix
= NULL
;
4289 /* If we don't have namespace debug info, guess the name by trying
4290 to demangle the names of members, just like we did in
4291 guess_structure_name. */
4292 if (!processing_has_namespace_info
)
4294 struct die_info
*child
;
4296 for (child
= die
->child
;
4297 child
!= NULL
&& child
->tag
!= 0;
4298 child
= sibling_die (child
))
4300 if (child
->tag
== DW_TAG_subprogram
)
4303 = language_class_name_from_physname (cu
->language_defn
,
4307 if (phys_prefix
!= NULL
)
4310 = obsavestring (phys_prefix
, strlen (phys_prefix
),
4311 &cu
->objfile
->objfile_obstack
);
4312 xfree (phys_prefix
);
4319 if (new_prefix
== NULL
)
4320 new_prefix
= dwarf2_full_name (die
, cu
);
4325 /* Given a pointer to a die which begins an enumeration, process all
4326 the dies that define the members of the enumeration, and create the
4327 symbol for the enumeration type.
4329 NOTE: We reverse the order of the element list. */
4332 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4334 struct objfile
*objfile
= cu
->objfile
;
4335 struct die_info
*child_die
;
4336 struct field
*fields
;
4339 int unsigned_enum
= 1;
4341 struct type
*this_type
;
4345 this_type
= get_die_type (die
, cu
);
4346 if (this_type
== NULL
)
4347 this_type
= read_enumeration_type (die
, cu
);
4348 if (die
->child
!= NULL
)
4350 child_die
= die
->child
;
4351 while (child_die
&& child_die
->tag
)
4353 if (child_die
->tag
!= DW_TAG_enumerator
)
4355 process_die (child_die
, cu
);
4359 name
= dwarf2_name (child_die
, cu
);
4362 sym
= new_symbol (child_die
, this_type
, cu
);
4363 if (SYMBOL_VALUE (sym
) < 0)
4366 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4368 fields
= (struct field
*)
4370 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
4371 * sizeof (struct field
));
4374 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
4375 FIELD_TYPE (fields
[num_fields
]) = NULL
;
4376 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
4377 FIELD_BITSIZE (fields
[num_fields
]) = 0;
4378 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
4384 child_die
= sibling_die (child_die
);
4389 TYPE_NFIELDS (this_type
) = num_fields
;
4390 TYPE_FIELDS (this_type
) = (struct field
*)
4391 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
4392 memcpy (TYPE_FIELDS (this_type
), fields
,
4393 sizeof (struct field
) * num_fields
);
4397 TYPE_UNSIGNED (this_type
) = 1;
4400 new_symbol (die
, this_type
, cu
);
4403 /* Extract all information from a DW_TAG_array_type DIE and put it in
4404 the DIE's type field. For now, this only handles one dimensional
4407 static struct type
*
4408 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4410 struct objfile
*objfile
= cu
->objfile
;
4411 struct die_info
*child_die
;
4412 struct type
*type
= NULL
;
4413 struct type
*element_type
, *range_type
, *index_type
;
4414 struct type
**range_types
= NULL
;
4415 struct attribute
*attr
;
4417 struct cleanup
*back_to
;
4420 element_type
= die_type (die
, cu
);
4422 /* Irix 6.2 native cc creates array types without children for
4423 arrays with unspecified length. */
4424 if (die
->child
== NULL
)
4426 index_type
= builtin_type_int32
;
4427 range_type
= create_range_type (NULL
, index_type
, 0, -1);
4428 type
= create_array_type (NULL
, element_type
, range_type
);
4429 return set_die_type (die
, type
, cu
);
4432 back_to
= make_cleanup (null_cleanup
, NULL
);
4433 child_die
= die
->child
;
4434 while (child_die
&& child_die
->tag
)
4436 if (child_die
->tag
== DW_TAG_subrange_type
)
4438 struct type
*child_type
= read_type_die (child_die
, cu
);
4439 if (child_type
!= NULL
)
4441 /* The range type was succesfully read. Save it for
4442 the array type creation. */
4443 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
4445 range_types
= (struct type
**)
4446 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
4447 * sizeof (struct type
*));
4449 make_cleanup (free_current_contents
, &range_types
);
4451 range_types
[ndim
++] = child_type
;
4454 child_die
= sibling_die (child_die
);
4457 /* Dwarf2 dimensions are output from left to right, create the
4458 necessary array types in backwards order. */
4460 type
= element_type
;
4462 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
4466 type
= create_array_type (NULL
, type
, range_types
[i
++]);
4471 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
4474 /* Understand Dwarf2 support for vector types (like they occur on
4475 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4476 array type. This is not part of the Dwarf2/3 standard yet, but a
4477 custom vendor extension. The main difference between a regular
4478 array and the vector variant is that vectors are passed by value
4480 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4482 make_vector_type (type
);
4484 name
= dwarf2_name (die
, cu
);
4486 TYPE_NAME (type
) = name
;
4488 do_cleanups (back_to
);
4490 /* Install the type in the die. */
4491 return set_die_type (die
, type
, cu
);
4494 static enum dwarf_array_dim_ordering
4495 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4497 struct attribute
*attr
;
4499 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4501 if (attr
) return DW_SND (attr
);
4504 GNU F77 is a special case, as at 08/2004 array type info is the
4505 opposite order to the dwarf2 specification, but data is still
4506 laid out as per normal fortran.
4508 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4512 if (cu
->language
== language_fortran
&&
4513 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4515 return DW_ORD_row_major
;
4518 switch (cu
->language_defn
->la_array_ordering
)
4520 case array_column_major
:
4521 return DW_ORD_col_major
;
4522 case array_row_major
:
4524 return DW_ORD_row_major
;
4528 /* Extract all information from a DW_TAG_set_type DIE and put it in
4529 the DIE's type field. */
4531 static struct type
*
4532 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4534 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
4536 return set_die_type (die
, set_type
, cu
);
4539 /* First cut: install each common block member as a global variable. */
4542 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4544 struct die_info
*child_die
;
4545 struct attribute
*attr
;
4547 CORE_ADDR base
= (CORE_ADDR
) 0;
4549 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4552 /* Support the .debug_loc offsets */
4553 if (attr_form_is_block (attr
))
4555 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4557 else if (attr_form_is_section_offset (attr
))
4559 dwarf2_complex_location_expr_complaint ();
4563 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4564 "common block member");
4567 if (die
->child
!= NULL
)
4569 child_die
= die
->child
;
4570 while (child_die
&& child_die
->tag
)
4572 sym
= new_symbol (child_die
, NULL
, cu
);
4573 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4576 SYMBOL_VALUE_ADDRESS (sym
) =
4577 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4578 add_symbol_to_list (sym
, &global_symbols
);
4580 child_die
= sibling_die (child_die
);
4585 /* Create a type for a C++ namespace. */
4587 static struct type
*
4588 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4590 struct objfile
*objfile
= cu
->objfile
;
4591 const char *previous_prefix
, *name
;
4595 /* For extensions, reuse the type of the original namespace. */
4596 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
4598 struct die_info
*ext_die
;
4599 struct dwarf2_cu
*ext_cu
= cu
;
4600 ext_die
= dwarf2_extension (die
, &ext_cu
);
4601 type
= read_type_die (ext_die
, ext_cu
);
4602 return set_die_type (die
, type
, cu
);
4605 name
= namespace_name (die
, &is_anonymous
, cu
);
4607 /* Now build the name of the current namespace. */
4609 previous_prefix
= determine_prefix (die
, cu
);
4610 if (previous_prefix
[0] != '\0')
4611 name
= typename_concat (&objfile
->objfile_obstack
,
4612 previous_prefix
, name
, cu
);
4614 /* Create the type. */
4615 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
4617 TYPE_NAME (type
) = (char *) name
;
4618 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4620 set_die_type (die
, type
, cu
);
4625 /* Read a C++ namespace. */
4628 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4630 struct objfile
*objfile
= cu
->objfile
;
4634 /* Add a symbol associated to this if we haven't seen the namespace
4635 before. Also, add a using directive if it's an anonymous
4638 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
4642 type
= read_type_die (die
, cu
);
4643 new_symbol (die
, type
, cu
);
4645 name
= namespace_name (die
, &is_anonymous
, cu
);
4648 const char *previous_prefix
= determine_prefix (die
, cu
);
4649 cp_add_using_directive (TYPE_NAME (type
),
4650 strlen (previous_prefix
),
4651 strlen (TYPE_NAME (type
)));
4655 if (die
->child
!= NULL
)
4657 struct die_info
*child_die
= die
->child
;
4659 while (child_die
&& child_die
->tag
)
4661 process_die (child_die
, cu
);
4662 child_die
= sibling_die (child_die
);
4667 /* Return the name of the namespace represented by DIE. Set
4668 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4672 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
4674 struct die_info
*current_die
;
4675 const char *name
= NULL
;
4677 /* Loop through the extensions until we find a name. */
4679 for (current_die
= die
;
4680 current_die
!= NULL
;
4681 current_die
= dwarf2_extension (die
, &cu
))
4683 name
= dwarf2_name (current_die
, cu
);
4688 /* Is it an anonymous namespace? */
4690 *is_anonymous
= (name
== NULL
);
4692 name
= "(anonymous namespace)";
4697 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4698 the user defined type vector. */
4700 static struct type
*
4701 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4703 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
4704 struct comp_unit_head
*cu_header
= &cu
->header
;
4706 struct attribute
*attr_byte_size
;
4707 struct attribute
*attr_address_class
;
4708 int byte_size
, addr_class
;
4710 type
= lookup_pointer_type (die_type (die
, cu
));
4712 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4714 byte_size
= DW_UNSND (attr_byte_size
);
4716 byte_size
= cu_header
->addr_size
;
4718 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
4719 if (attr_address_class
)
4720 addr_class
= DW_UNSND (attr_address_class
);
4722 addr_class
= DW_ADDR_none
;
4724 /* If the pointer size or address class is different than the
4725 default, create a type variant marked as such and set the
4726 length accordingly. */
4727 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
4729 if (gdbarch_address_class_type_flags_p (gdbarch
))
4733 type_flags
= gdbarch_address_class_type_flags
4734 (gdbarch
, byte_size
, addr_class
);
4735 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
4737 type
= make_type_with_address_space (type
, type_flags
);
4739 else if (TYPE_LENGTH (type
) != byte_size
)
4741 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
4744 /* Should we also complain about unhandled address classes? */
4748 TYPE_LENGTH (type
) = byte_size
;
4749 return set_die_type (die
, type
, cu
);
4752 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4753 the user defined type vector. */
4755 static struct type
*
4756 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4758 struct objfile
*objfile
= cu
->objfile
;
4760 struct type
*to_type
;
4761 struct type
*domain
;
4763 to_type
= die_type (die
, cu
);
4764 domain
= die_containing_type (die
, cu
);
4766 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
4767 type
= lookup_methodptr_type (to_type
);
4769 type
= lookup_memberptr_type (to_type
, domain
);
4771 return set_die_type (die
, type
, cu
);
4774 /* Extract all information from a DW_TAG_reference_type DIE and add to
4775 the user defined type vector. */
4777 static struct type
*
4778 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4780 struct comp_unit_head
*cu_header
= &cu
->header
;
4782 struct attribute
*attr
;
4784 type
= lookup_reference_type (die_type (die
, cu
));
4785 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4788 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4792 TYPE_LENGTH (type
) = cu_header
->addr_size
;
4794 return set_die_type (die
, type
, cu
);
4797 static struct type
*
4798 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4800 struct type
*base_type
, *cv_type
;
4802 base_type
= die_type (die
, cu
);
4803 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
4804 return set_die_type (die
, cv_type
, cu
);
4807 static struct type
*
4808 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4810 struct type
*base_type
, *cv_type
;
4812 base_type
= die_type (die
, cu
);
4813 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
4814 return set_die_type (die
, cv_type
, cu
);
4817 /* Extract all information from a DW_TAG_string_type DIE and add to
4818 the user defined type vector. It isn't really a user defined type,
4819 but it behaves like one, with other DIE's using an AT_user_def_type
4820 attribute to reference it. */
4822 static struct type
*
4823 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4825 struct objfile
*objfile
= cu
->objfile
;
4826 struct type
*type
, *range_type
, *index_type
, *char_type
;
4827 struct attribute
*attr
;
4828 unsigned int length
;
4830 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4833 length
= DW_UNSND (attr
);
4837 /* check for the DW_AT_byte_size attribute */
4838 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4841 length
= DW_UNSND (attr
);
4849 index_type
= builtin_type_int32
;
4850 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4851 type
= create_string_type (NULL
, range_type
);
4853 return set_die_type (die
, type
, cu
);
4856 /* Handle DIES due to C code like:
4860 int (*funcp)(int a, long l);
4864 ('funcp' generates a DW_TAG_subroutine_type DIE)
4867 static struct type
*
4868 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4870 struct type
*type
; /* Type that this function returns */
4871 struct type
*ftype
; /* Function that returns above type */
4872 struct attribute
*attr
;
4874 type
= die_type (die
, cu
);
4875 ftype
= make_function_type (type
, (struct type
**) 0);
4877 /* All functions in C++, Pascal and Java have prototypes. */
4878 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4879 if ((attr
&& (DW_UNSND (attr
) != 0))
4880 || cu
->language
== language_cplus
4881 || cu
->language
== language_java
4882 || cu
->language
== language_pascal
)
4883 TYPE_PROTOTYPED (ftype
) = 1;
4885 /* Store the calling convention in the type if it's available in
4886 the subroutine die. Otherwise set the calling convention to
4887 the default value DW_CC_normal. */
4888 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
4889 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
4891 if (die
->child
!= NULL
)
4893 struct die_info
*child_die
;
4897 /* Count the number of parameters.
4898 FIXME: GDB currently ignores vararg functions, but knows about
4899 vararg member functions. */
4900 child_die
= die
->child
;
4901 while (child_die
&& child_die
->tag
)
4903 if (child_die
->tag
== DW_TAG_formal_parameter
)
4905 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4906 TYPE_VARARGS (ftype
) = 1;
4907 child_die
= sibling_die (child_die
);
4910 /* Allocate storage for parameters and fill them in. */
4911 TYPE_NFIELDS (ftype
) = nparams
;
4912 TYPE_FIELDS (ftype
) = (struct field
*)
4913 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
4915 child_die
= die
->child
;
4916 while (child_die
&& child_die
->tag
)
4918 if (child_die
->tag
== DW_TAG_formal_parameter
)
4920 /* Dwarf2 has no clean way to discern C++ static and non-static
4921 member functions. G++ helps GDB by marking the first
4922 parameter for non-static member functions (which is the
4923 this pointer) as artificial. We pass this information
4924 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4925 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
4927 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
4929 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
4930 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
4933 child_die
= sibling_die (child_die
);
4937 return set_die_type (die
, ftype
, cu
);
4940 static struct type
*
4941 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
4943 struct objfile
*objfile
= cu
->objfile
;
4944 struct attribute
*attr
;
4945 const char *name
= NULL
;
4946 struct type
*this_type
;
4948 name
= dwarf2_full_name (die
, cu
);
4949 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
4950 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
4951 TYPE_NAME (this_type
) = (char *) name
;
4952 set_die_type (die
, this_type
, cu
);
4953 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
4957 /* Find a representation of a given base type and install
4958 it in the TYPE field of the die. */
4960 static struct type
*
4961 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4963 struct objfile
*objfile
= cu
->objfile
;
4965 struct attribute
*attr
;
4966 int encoding
= 0, size
= 0;
4968 enum type_code code
= TYPE_CODE_INT
;
4970 struct type
*target_type
= NULL
;
4972 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
4975 encoding
= DW_UNSND (attr
);
4977 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4980 size
= DW_UNSND (attr
);
4982 name
= dwarf2_name (die
, cu
);
4985 complaint (&symfile_complaints
,
4986 _("DW_AT_name missing from DW_TAG_base_type"));
4991 case DW_ATE_address
:
4992 /* Turn DW_ATE_address into a void * pointer. */
4993 code
= TYPE_CODE_PTR
;
4994 type_flags
|= TYPE_FLAG_UNSIGNED
;
4995 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
4997 case DW_ATE_boolean
:
4998 code
= TYPE_CODE_BOOL
;
4999 type_flags
|= TYPE_FLAG_UNSIGNED
;
5001 case DW_ATE_complex_float
:
5002 code
= TYPE_CODE_COMPLEX
;
5003 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
5005 case DW_ATE_decimal_float
:
5006 code
= TYPE_CODE_DECFLOAT
;
5009 code
= TYPE_CODE_FLT
;
5013 case DW_ATE_unsigned
:
5014 type_flags
|= TYPE_FLAG_UNSIGNED
;
5016 case DW_ATE_signed_char
:
5017 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5018 code
= TYPE_CODE_CHAR
;
5020 case DW_ATE_unsigned_char
:
5021 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5022 code
= TYPE_CODE_CHAR
;
5023 type_flags
|= TYPE_FLAG_UNSIGNED
;
5026 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
5027 dwarf_type_encoding_name (encoding
));
5031 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
5032 TYPE_NAME (type
) = name
;
5033 TYPE_TARGET_TYPE (type
) = target_type
;
5035 if (name
&& strcmp (name
, "char") == 0)
5036 TYPE_NOSIGN (type
) = 1;
5038 return set_die_type (die
, type
, cu
);
5041 /* Read the given DW_AT_subrange DIE. */
5043 static struct type
*
5044 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5046 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5047 struct type
*base_type
;
5048 struct type
*range_type
;
5049 struct attribute
*attr
;
5054 base_type
= die_type (die
, cu
);
5055 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
5057 complaint (&symfile_complaints
,
5058 _("DW_AT_type missing from DW_TAG_subrange_type"));
5060 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
5061 0, NULL
, cu
->objfile
);
5064 if (cu
->language
== language_fortran
)
5066 /* FORTRAN implies a lower bound of 1, if not given. */
5070 /* FIXME: For variable sized arrays either of these could be
5071 a variable rather than a constant value. We'll allow it,
5072 but we don't know how to handle it. */
5073 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
5075 low
= dwarf2_get_attr_constant_value (attr
, 0);
5077 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
5080 if (attr
->form
== DW_FORM_block1
)
5082 /* GCC encodes arrays with unspecified or dynamic length
5083 with a DW_FORM_block1 attribute.
5084 FIXME: GDB does not yet know how to handle dynamic
5085 arrays properly, treat them as arrays with unspecified
5088 FIXME: jimb/2003-09-22: GDB does not really know
5089 how to handle arrays of unspecified length
5090 either; we just represent them as zero-length
5091 arrays. Choose an appropriate upper bound given
5092 the lower bound we've computed above. */
5096 high
= dwarf2_get_attr_constant_value (attr
, 1);
5099 range_type
= create_range_type (NULL
, base_type
, low
, high
);
5101 name
= dwarf2_name (die
, cu
);
5103 TYPE_NAME (range_type
) = name
;
5105 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5107 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
5109 return set_die_type (die
, range_type
, cu
);
5112 static struct type
*
5113 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5117 /* For now, we only support the C meaning of an unspecified type: void. */
5119 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
5120 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
5122 return set_die_type (die
, type
, cu
);
5125 /* Trivial hash function for die_info: the hash value of a DIE
5126 is its offset in .debug_info for this objfile. */
5129 die_hash (const void *item
)
5131 const struct die_info
*die
= item
;
5135 /* Trivial comparison function for die_info structures: two DIEs
5136 are equal if they have the same offset. */
5139 die_eq (const void *item_lhs
, const void *item_rhs
)
5141 const struct die_info
*die_lhs
= item_lhs
;
5142 const struct die_info
*die_rhs
= item_rhs
;
5143 return die_lhs
->offset
== die_rhs
->offset
;
5146 /* Read a whole compilation unit into a linked list of dies. */
5148 static struct die_info
*
5149 read_comp_unit (gdb_byte
*info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
5152 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5156 &cu
->comp_unit_obstack
,
5157 hashtab_obstack_allocate
,
5158 dummy_obstack_deallocate
);
5160 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
5163 /* Read a single die and all its descendents. Set the die's sibling
5164 field to NULL; set other fields in the die correctly, and set all
5165 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
5166 location of the info_ptr after reading all of those dies. PARENT
5167 is the parent of the die in question. */
5169 static struct die_info
*
5170 read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
5171 struct dwarf2_cu
*cu
,
5172 gdb_byte
**new_info_ptr
,
5173 struct die_info
*parent
)
5175 struct die_info
*die
;
5179 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
5182 *new_info_ptr
= cur_ptr
;
5185 store_in_ref_table (die
, cu
);
5189 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
5195 *new_info_ptr
= cur_ptr
;
5198 die
->sibling
= NULL
;
5199 die
->parent
= parent
;
5203 /* Read a die, all of its descendents, and all of its siblings; set
5204 all of the fields of all of the dies correctly. Arguments are as
5205 in read_die_and_children. */
5207 static struct die_info
*
5208 read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
5209 struct dwarf2_cu
*cu
,
5210 gdb_byte
**new_info_ptr
,
5211 struct die_info
*parent
)
5213 struct die_info
*first_die
, *last_sibling
;
5217 first_die
= last_sibling
= NULL
;
5221 struct die_info
*die
5222 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
5226 *new_info_ptr
= cur_ptr
;
5233 last_sibling
->sibling
= die
;
5239 /* Decompress a section that was compressed using zlib. Store the
5240 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
5243 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
5244 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
5246 bfd
*abfd
= objfile
->obfd
;
5248 error (_("Support for zlib-compressed DWARF data (from '%s') "
5249 "is disabled in this copy of GDB"),
5250 bfd_get_filename (abfd
));
5252 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
5253 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
5254 bfd_size_type uncompressed_size
;
5255 gdb_byte
*uncompressed_buffer
;
5258 int header_size
= 12;
5260 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5261 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
5262 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5263 bfd_get_filename (abfd
));
5265 /* Read the zlib header. In this case, it should be "ZLIB" followed
5266 by the uncompressed section size, 8 bytes in big-endian order. */
5267 if (compressed_size
< header_size
5268 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
5269 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
5270 bfd_get_filename (abfd
));
5271 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
5272 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
5273 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
5274 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
5275 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
5276 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
5277 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
5278 uncompressed_size
+= compressed_buffer
[11];
5280 /* It is possible the section consists of several compressed
5281 buffers concatenated together, so we uncompress in a loop. */
5285 strm
.avail_in
= compressed_size
- header_size
;
5286 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
5287 strm
.avail_out
= uncompressed_size
;
5288 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
5290 rc
= inflateInit (&strm
);
5291 while (strm
.avail_in
> 0)
5294 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
5295 bfd_get_filename (abfd
), rc
);
5296 strm
.next_out
= ((Bytef
*) uncompressed_buffer
5297 + (uncompressed_size
- strm
.avail_out
));
5298 rc
= inflate (&strm
, Z_FINISH
);
5299 if (rc
!= Z_STREAM_END
)
5300 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
5301 bfd_get_filename (abfd
), rc
);
5302 rc
= inflateReset (&strm
);
5304 rc
= inflateEnd (&strm
);
5306 || strm
.avail_out
!= 0)
5307 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
5308 bfd_get_filename (abfd
), rc
);
5310 xfree (compressed_buffer
);
5311 *outbuf
= uncompressed_buffer
;
5312 *outsize
= uncompressed_size
;
5317 /* Read the contents of the section at OFFSET and of size SIZE from the
5318 object file specified by OBJFILE into the objfile_obstack and return it.
5319 If the section is compressed, uncompress it before returning. */
5322 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
5324 bfd
*abfd
= objfile
->obfd
;
5325 gdb_byte
*buf
, *retbuf
;
5326 bfd_size_type size
= bfd_get_section_size (sectp
);
5327 unsigned char header
[4];
5332 /* Check if the file has a 4-byte header indicating compression. */
5333 if (size
> sizeof (header
)
5334 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
5335 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
5337 /* Upon decompression, update the buffer and its size. */
5338 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
5340 zlib_decompress_section (objfile
, sectp
, &buf
, &size
);
5341 dwarf2_resize_section (sectp
, size
);
5346 /* If we get here, we are a normal, not-compressed section. */
5347 buf
= obstack_alloc (&objfile
->objfile_obstack
, size
);
5348 /* When debugging .o files, we may need to apply relocations; see
5349 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
5350 We never compress sections in .o files, so we only need to
5351 try this when the section is not compressed. */
5352 retbuf
= symfile_relocate_debug_section (abfd
, sectp
, buf
);
5356 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5357 || bfd_bread (buf
, size
, abfd
) != size
)
5358 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5359 bfd_get_filename (abfd
));
5364 /* In DWARF version 2, the description of the debugging information is
5365 stored in a separate .debug_abbrev section. Before we read any
5366 dies from a section we read in all abbreviations and install them
5367 in a hash table. This function also sets flags in CU describing
5368 the data found in the abbrev table. */
5371 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
5373 struct comp_unit_head
*cu_header
= &cu
->header
;
5374 gdb_byte
*abbrev_ptr
;
5375 struct abbrev_info
*cur_abbrev
;
5376 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
5377 unsigned int abbrev_form
, hash_number
;
5378 struct attr_abbrev
*cur_attrs
;
5379 unsigned int allocated_attrs
;
5381 /* Initialize dwarf2 abbrevs */
5382 obstack_init (&cu
->abbrev_obstack
);
5383 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
5385 * sizeof (struct abbrev_info
*)));
5386 memset (cu
->dwarf2_abbrevs
, 0,
5387 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
5389 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
5390 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5391 abbrev_ptr
+= bytes_read
;
5393 allocated_attrs
= ATTR_ALLOC_CHUNK
;
5394 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
5396 /* loop until we reach an abbrev number of 0 */
5397 while (abbrev_number
)
5399 cur_abbrev
= dwarf_alloc_abbrev (cu
);
5401 /* read in abbrev header */
5402 cur_abbrev
->number
= abbrev_number
;
5403 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5404 abbrev_ptr
+= bytes_read
;
5405 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
5408 if (cur_abbrev
->tag
== DW_TAG_namespace
)
5409 cu
->has_namespace_info
= 1;
5411 /* now read in declarations */
5412 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5413 abbrev_ptr
+= bytes_read
;
5414 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5415 abbrev_ptr
+= bytes_read
;
5418 if (cur_abbrev
->num_attrs
== allocated_attrs
)
5420 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
5422 = xrealloc (cur_attrs
, (allocated_attrs
5423 * sizeof (struct attr_abbrev
)));
5426 /* Record whether this compilation unit might have
5427 inter-compilation-unit references. If we don't know what form
5428 this attribute will have, then it might potentially be a
5429 DW_FORM_ref_addr, so we conservatively expect inter-CU
5432 if (abbrev_form
== DW_FORM_ref_addr
5433 || abbrev_form
== DW_FORM_indirect
)
5434 cu
->has_form_ref_addr
= 1;
5436 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
5437 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
5438 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5439 abbrev_ptr
+= bytes_read
;
5440 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5441 abbrev_ptr
+= bytes_read
;
5444 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
5445 (cur_abbrev
->num_attrs
5446 * sizeof (struct attr_abbrev
)));
5447 memcpy (cur_abbrev
->attrs
, cur_attrs
,
5448 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
5450 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
5451 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
5452 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
5454 /* Get next abbreviation.
5455 Under Irix6 the abbreviations for a compilation unit are not
5456 always properly terminated with an abbrev number of 0.
5457 Exit loop if we encounter an abbreviation which we have
5458 already read (which means we are about to read the abbreviations
5459 for the next compile unit) or if the end of the abbreviation
5460 table is reached. */
5461 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
5462 >= dwarf2_per_objfile
->abbrev_size
)
5464 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5465 abbrev_ptr
+= bytes_read
;
5466 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
5473 /* Release the memory used by the abbrev table for a compilation unit. */
5476 dwarf2_free_abbrev_table (void *ptr_to_cu
)
5478 struct dwarf2_cu
*cu
= ptr_to_cu
;
5480 obstack_free (&cu
->abbrev_obstack
, NULL
);
5481 cu
->dwarf2_abbrevs
= NULL
;
5484 /* Lookup an abbrev_info structure in the abbrev hash table. */
5486 static struct abbrev_info
*
5487 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
5489 unsigned int hash_number
;
5490 struct abbrev_info
*abbrev
;
5492 hash_number
= number
% ABBREV_HASH_SIZE
;
5493 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
5497 if (abbrev
->number
== number
)
5500 abbrev
= abbrev
->next
;
5505 /* Returns nonzero if TAG represents a type that we might generate a partial
5509 is_type_tag_for_partial (int tag
)
5514 /* Some types that would be reasonable to generate partial symbols for,
5515 that we don't at present. */
5516 case DW_TAG_array_type
:
5517 case DW_TAG_file_type
:
5518 case DW_TAG_ptr_to_member_type
:
5519 case DW_TAG_set_type
:
5520 case DW_TAG_string_type
:
5521 case DW_TAG_subroutine_type
:
5523 case DW_TAG_base_type
:
5524 case DW_TAG_class_type
:
5525 case DW_TAG_interface_type
:
5526 case DW_TAG_enumeration_type
:
5527 case DW_TAG_structure_type
:
5528 case DW_TAG_subrange_type
:
5529 case DW_TAG_typedef
:
5530 case DW_TAG_union_type
:
5537 /* Load all DIEs that are interesting for partial symbols into memory. */
5539 static struct partial_die_info
*
5540 load_partial_dies (bfd
*abfd
, gdb_byte
*info_ptr
, int building_psymtab
,
5541 struct dwarf2_cu
*cu
)
5543 struct partial_die_info
*part_die
;
5544 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
5545 struct abbrev_info
*abbrev
;
5546 unsigned int bytes_read
;
5547 unsigned int load_all
= 0;
5549 int nesting_level
= 1;
5554 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
5558 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5562 &cu
->comp_unit_obstack
,
5563 hashtab_obstack_allocate
,
5564 dummy_obstack_deallocate
);
5566 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5567 sizeof (struct partial_die_info
));
5571 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5573 /* A NULL abbrev means the end of a series of children. */
5576 if (--nesting_level
== 0)
5578 /* PART_DIE was probably the last thing allocated on the
5579 comp_unit_obstack, so we could call obstack_free
5580 here. We don't do that because the waste is small,
5581 and will be cleaned up when we're done with this
5582 compilation unit. This way, we're also more robust
5583 against other users of the comp_unit_obstack. */
5586 info_ptr
+= bytes_read
;
5587 last_die
= parent_die
;
5588 parent_die
= parent_die
->die_parent
;
5592 /* Check whether this DIE is interesting enough to save. Normally
5593 we would not be interested in members here, but there may be
5594 later variables referencing them via DW_AT_specification (for
5597 && !is_type_tag_for_partial (abbrev
->tag
)
5598 && abbrev
->tag
!= DW_TAG_enumerator
5599 && abbrev
->tag
!= DW_TAG_subprogram
5600 && abbrev
->tag
!= DW_TAG_lexical_block
5601 && abbrev
->tag
!= DW_TAG_variable
5602 && abbrev
->tag
!= DW_TAG_namespace
5603 && abbrev
->tag
!= DW_TAG_member
)
5605 /* Otherwise we skip to the next sibling, if any. */
5606 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5610 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5611 abfd
, info_ptr
, cu
);
5613 /* This two-pass algorithm for processing partial symbols has a
5614 high cost in cache pressure. Thus, handle some simple cases
5615 here which cover the majority of C partial symbols. DIEs
5616 which neither have specification tags in them, nor could have
5617 specification tags elsewhere pointing at them, can simply be
5618 processed and discarded.
5620 This segment is also optional; scan_partial_symbols and
5621 add_partial_symbol will handle these DIEs if we chain
5622 them in normally. When compilers which do not emit large
5623 quantities of duplicate debug information are more common,
5624 this code can probably be removed. */
5626 /* Any complete simple types at the top level (pretty much all
5627 of them, for a language without namespaces), can be processed
5629 if (parent_die
== NULL
5630 && part_die
->has_specification
== 0
5631 && part_die
->is_declaration
== 0
5632 && (part_die
->tag
== DW_TAG_typedef
5633 || part_die
->tag
== DW_TAG_base_type
5634 || part_die
->tag
== DW_TAG_subrange_type
))
5636 if (building_psymtab
&& part_die
->name
!= NULL
)
5637 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5638 VAR_DOMAIN
, LOC_TYPEDEF
,
5639 &cu
->objfile
->static_psymbols
,
5640 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5641 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5645 /* If we're at the second level, and we're an enumerator, and
5646 our parent has no specification (meaning possibly lives in a
5647 namespace elsewhere), then we can add the partial symbol now
5648 instead of queueing it. */
5649 if (part_die
->tag
== DW_TAG_enumerator
5650 && parent_die
!= NULL
5651 && parent_die
->die_parent
== NULL
5652 && parent_die
->tag
== DW_TAG_enumeration_type
5653 && parent_die
->has_specification
== 0)
5655 if (part_die
->name
== NULL
)
5656 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5657 else if (building_psymtab
)
5658 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5659 VAR_DOMAIN
, LOC_CONST
,
5660 (cu
->language
== language_cplus
5661 || cu
->language
== language_java
)
5662 ? &cu
->objfile
->global_psymbols
5663 : &cu
->objfile
->static_psymbols
,
5664 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5666 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5670 /* We'll save this DIE so link it in. */
5671 part_die
->die_parent
= parent_die
;
5672 part_die
->die_sibling
= NULL
;
5673 part_die
->die_child
= NULL
;
5675 if (last_die
&& last_die
== parent_die
)
5676 last_die
->die_child
= part_die
;
5678 last_die
->die_sibling
= part_die
;
5680 last_die
= part_die
;
5682 if (first_die
== NULL
)
5683 first_die
= part_die
;
5685 /* Maybe add the DIE to the hash table. Not all DIEs that we
5686 find interesting need to be in the hash table, because we
5687 also have the parent/sibling/child chains; only those that we
5688 might refer to by offset later during partial symbol reading.
5690 For now this means things that might have be the target of a
5691 DW_AT_specification, DW_AT_abstract_origin, or
5692 DW_AT_extension. DW_AT_extension will refer only to
5693 namespaces; DW_AT_abstract_origin refers to functions (and
5694 many things under the function DIE, but we do not recurse
5695 into function DIEs during partial symbol reading) and
5696 possibly variables as well; DW_AT_specification refers to
5697 declarations. Declarations ought to have the DW_AT_declaration
5698 flag. It happens that GCC forgets to put it in sometimes, but
5699 only for functions, not for types.
5701 Adding more things than necessary to the hash table is harmless
5702 except for the performance cost. Adding too few will result in
5703 wasted time in find_partial_die, when we reread the compilation
5704 unit with load_all_dies set. */
5707 || abbrev
->tag
== DW_TAG_subprogram
5708 || abbrev
->tag
== DW_TAG_variable
5709 || abbrev
->tag
== DW_TAG_namespace
5710 || part_die
->is_declaration
)
5714 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
5715 part_die
->offset
, INSERT
);
5719 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5720 sizeof (struct partial_die_info
));
5722 /* For some DIEs we want to follow their children (if any). For C
5723 we have no reason to follow the children of structures; for other
5724 languages we have to, both so that we can get at method physnames
5725 to infer fully qualified class names, and for DW_AT_specification.
5727 For Ada, we need to scan the children of subprograms and lexical
5728 blocks as well because Ada allows the definition of nested
5729 entities that could be interesting for the debugger, such as
5730 nested subprograms for instance. */
5731 if (last_die
->has_children
5733 || last_die
->tag
== DW_TAG_namespace
5734 || last_die
->tag
== DW_TAG_enumeration_type
5735 || (cu
->language
!= language_c
5736 && (last_die
->tag
== DW_TAG_class_type
5737 || last_die
->tag
== DW_TAG_interface_type
5738 || last_die
->tag
== DW_TAG_structure_type
5739 || last_die
->tag
== DW_TAG_union_type
))
5740 || (cu
->language
== language_ada
5741 && (last_die
->tag
== DW_TAG_subprogram
5742 || last_die
->tag
== DW_TAG_lexical_block
))))
5745 parent_die
= last_die
;
5749 /* Otherwise we skip to the next sibling, if any. */
5750 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
5752 /* Back to the top, do it again. */
5756 /* Read a minimal amount of information into the minimal die structure. */
5759 read_partial_die (struct partial_die_info
*part_die
,
5760 struct abbrev_info
*abbrev
,
5761 unsigned int abbrev_len
, bfd
*abfd
,
5762 gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
5764 unsigned int bytes_read
, i
;
5765 struct attribute attr
;
5766 int has_low_pc_attr
= 0;
5767 int has_high_pc_attr
= 0;
5768 CORE_ADDR base_address
= 0;
5772 base_address_low_pc
,
5773 /* Overrides BASE_ADDRESS_LOW_PC. */
5774 base_address_entry_pc
5776 base_address_type
= base_address_none
;
5778 memset (part_die
, 0, sizeof (struct partial_die_info
));
5780 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5782 info_ptr
+= abbrev_len
;
5787 part_die
->tag
= abbrev
->tag
;
5788 part_die
->has_children
= abbrev
->has_children
;
5790 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5792 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
5794 /* Store the data if it is of an attribute we want to keep in a
5795 partial symbol table. */
5800 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
5801 if (part_die
->name
== NULL
)
5802 part_die
->name
= DW_STRING (&attr
);
5804 case DW_AT_comp_dir
:
5805 if (part_die
->dirname
== NULL
)
5806 part_die
->dirname
= DW_STRING (&attr
);
5808 case DW_AT_MIPS_linkage_name
:
5809 part_die
->name
= DW_STRING (&attr
);
5812 has_low_pc_attr
= 1;
5813 part_die
->lowpc
= DW_ADDR (&attr
);
5814 if (part_die
->tag
== DW_TAG_compile_unit
5815 && base_address_type
< base_address_low_pc
)
5817 base_address
= DW_ADDR (&attr
);
5818 base_address_type
= base_address_low_pc
;
5822 has_high_pc_attr
= 1;
5823 part_die
->highpc
= DW_ADDR (&attr
);
5825 case DW_AT_entry_pc
:
5826 if (part_die
->tag
== DW_TAG_compile_unit
5827 && base_address_type
< base_address_entry_pc
)
5829 base_address
= DW_ADDR (&attr
);
5830 base_address_type
= base_address_entry_pc
;
5834 if (part_die
->tag
== DW_TAG_compile_unit
)
5836 cu
->ranges_offset
= DW_UNSND (&attr
);
5837 cu
->has_ranges_offset
= 1;
5840 case DW_AT_location
:
5841 /* Support the .debug_loc offsets */
5842 if (attr_form_is_block (&attr
))
5844 part_die
->locdesc
= DW_BLOCK (&attr
);
5846 else if (attr_form_is_section_offset (&attr
))
5848 dwarf2_complex_location_expr_complaint ();
5852 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5853 "partial symbol information");
5856 case DW_AT_language
:
5857 part_die
->language
= DW_UNSND (&attr
);
5859 case DW_AT_external
:
5860 part_die
->is_external
= DW_UNSND (&attr
);
5862 case DW_AT_declaration
:
5863 part_die
->is_declaration
= DW_UNSND (&attr
);
5866 part_die
->has_type
= 1;
5868 case DW_AT_abstract_origin
:
5869 case DW_AT_specification
:
5870 case DW_AT_extension
:
5871 part_die
->has_specification
= 1;
5872 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
, cu
);
5875 /* Ignore absolute siblings, they might point outside of
5876 the current compile unit. */
5877 if (attr
.form
== DW_FORM_ref_addr
)
5878 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
5880 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
5881 + dwarf2_get_ref_die_offset (&attr
, cu
);
5883 case DW_AT_stmt_list
:
5884 part_die
->has_stmt_list
= 1;
5885 part_die
->line_offset
= DW_UNSND (&attr
);
5887 case DW_AT_byte_size
:
5888 part_die
->has_byte_size
= 1;
5890 case DW_AT_calling_convention
:
5891 /* DWARF doesn't provide a way to identify a program's source-level
5892 entry point. DW_AT_calling_convention attributes are only meant
5893 to describe functions' calling conventions.
5895 However, because it's a necessary piece of information in
5896 Fortran, and because DW_CC_program is the only piece of debugging
5897 information whose definition refers to a 'main program' at all,
5898 several compilers have begun marking Fortran main programs with
5899 DW_CC_program --- even when those functions use the standard
5900 calling conventions.
5902 So until DWARF specifies a way to provide this information and
5903 compilers pick up the new representation, we'll support this
5905 if (DW_UNSND (&attr
) == DW_CC_program
5906 && cu
->language
== language_fortran
)
5907 set_main_name (part_die
->name
);
5914 /* When using the GNU linker, .gnu.linkonce. sections are used to
5915 eliminate duplicate copies of functions and vtables and such.
5916 The linker will arbitrarily choose one and discard the others.
5917 The AT_*_pc values for such functions refer to local labels in
5918 these sections. If the section from that file was discarded, the
5919 labels are not in the output, so the relocs get a value of 0.
5920 If this is a discarded function, mark the pc bounds as invalid,
5921 so that GDB will ignore it. */
5922 if (has_low_pc_attr
&& has_high_pc_attr
5923 && part_die
->lowpc
< part_die
->highpc
5924 && (part_die
->lowpc
!= 0
5925 || dwarf2_per_objfile
->has_section_at_zero
))
5926 part_die
->has_pc_info
= 1;
5928 if (base_address_type
!= base_address_none
&& !cu
->base_known
)
5930 gdb_assert (part_die
->tag
== DW_TAG_compile_unit
);
5932 cu
->base_address
= base_address
;
5938 /* Find a cached partial DIE at OFFSET in CU. */
5940 static struct partial_die_info
*
5941 find_partial_die_in_comp_unit (unsigned long offset
, struct dwarf2_cu
*cu
)
5943 struct partial_die_info
*lookup_die
= NULL
;
5944 struct partial_die_info part_die
;
5946 part_die
.offset
= offset
;
5947 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
5952 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
5954 static struct partial_die_info
*
5955 find_partial_die (unsigned long offset
, struct dwarf2_cu
*cu
)
5957 struct dwarf2_per_cu_data
*per_cu
= NULL
;
5958 struct partial_die_info
*pd
= NULL
;
5960 if (offset
>= cu
->header
.offset
5961 && offset
< cu
->header
.offset
+ cu
->header
.length
)
5963 pd
= find_partial_die_in_comp_unit (offset
, cu
);
5968 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
5970 if (per_cu
->cu
== NULL
)
5972 load_comp_unit (per_cu
, cu
->objfile
);
5973 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5974 dwarf2_per_objfile
->read_in_chain
= per_cu
;
5977 per_cu
->cu
->last_used
= 0;
5978 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
5980 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
5982 struct cleanup
*back_to
;
5983 struct partial_die_info comp_unit_die
;
5984 struct abbrev_info
*abbrev
;
5985 unsigned int bytes_read
;
5988 per_cu
->load_all_dies
= 1;
5990 /* Re-read the DIEs. */
5991 back_to
= make_cleanup (null_cleanup
, 0);
5992 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
5994 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
5995 back_to
= make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
5997 info_ptr
= (dwarf2_per_objfile
->info_buffer
5998 + per_cu
->cu
->header
.offset
5999 + per_cu
->cu
->header
.first_die_offset
);
6000 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
6001 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
6002 per_cu
->cu
->objfile
->obfd
, info_ptr
,
6004 if (comp_unit_die
.has_children
)
6005 load_partial_dies (per_cu
->cu
->objfile
->obfd
, info_ptr
, 0, per_cu
->cu
);
6006 do_cleanups (back_to
);
6008 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6012 internal_error (__FILE__
, __LINE__
,
6013 _("could not find partial DIE 0x%lx in cache [from module %s]\n"),
6014 offset
, bfd_get_filename (cu
->objfile
->obfd
));
6018 /* Adjust PART_DIE before generating a symbol for it. This function
6019 may set the is_external flag or change the DIE's name. */
6022 fixup_partial_die (struct partial_die_info
*part_die
,
6023 struct dwarf2_cu
*cu
)
6025 /* If we found a reference attribute and the DIE has no name, try
6026 to find a name in the referred to DIE. */
6028 if (part_die
->name
== NULL
&& part_die
->has_specification
)
6030 struct partial_die_info
*spec_die
;
6032 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
6034 fixup_partial_die (spec_die
, cu
);
6038 part_die
->name
= spec_die
->name
;
6040 /* Copy DW_AT_external attribute if it is set. */
6041 if (spec_die
->is_external
)
6042 part_die
->is_external
= spec_die
->is_external
;
6046 /* Set default names for some unnamed DIEs. */
6047 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
6048 || part_die
->tag
== DW_TAG_class_type
))
6049 part_die
->name
= "(anonymous class)";
6051 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
6052 part_die
->name
= "(anonymous namespace)";
6054 if (part_die
->tag
== DW_TAG_structure_type
6055 || part_die
->tag
== DW_TAG_class_type
6056 || part_die
->tag
== DW_TAG_union_type
)
6057 guess_structure_name (part_die
, cu
);
6060 /* Read the die from the .debug_info section buffer. Set DIEP to
6061 point to a newly allocated die with its information, except for its
6062 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6063 whether the die has children or not. */
6066 read_full_die (struct die_info
**diep
, bfd
*abfd
, gdb_byte
*info_ptr
,
6067 struct dwarf2_cu
*cu
, int *has_children
)
6069 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6070 struct abbrev_info
*abbrev
;
6071 struct die_info
*die
;
6073 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
6074 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6075 info_ptr
+= bytes_read
;
6083 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6086 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6088 bfd_get_filename (abfd
));
6090 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
6091 die
->offset
= offset
;
6092 die
->tag
= abbrev
->tag
;
6093 die
->abbrev
= abbrev_number
;
6095 die
->num_attrs
= abbrev
->num_attrs
;
6097 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6098 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6099 abfd
, info_ptr
, cu
);
6102 *has_children
= abbrev
->has_children
;
6106 /* Read an attribute value described by an attribute form. */
6109 read_attribute_value (struct attribute
*attr
, unsigned form
,
6110 bfd
*abfd
, gdb_byte
*info_ptr
,
6111 struct dwarf2_cu
*cu
)
6113 struct comp_unit_head
*cu_header
= &cu
->header
;
6114 unsigned int bytes_read
;
6115 struct dwarf_block
*blk
;
6121 case DW_FORM_ref_addr
:
6122 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6123 info_ptr
+= bytes_read
;
6125 case DW_FORM_block2
:
6126 blk
= dwarf_alloc_block (cu
);
6127 blk
->size
= read_2_bytes (abfd
, info_ptr
);
6129 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6130 info_ptr
+= blk
->size
;
6131 DW_BLOCK (attr
) = blk
;
6133 case DW_FORM_block4
:
6134 blk
= dwarf_alloc_block (cu
);
6135 blk
->size
= read_4_bytes (abfd
, info_ptr
);
6137 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6138 info_ptr
+= blk
->size
;
6139 DW_BLOCK (attr
) = blk
;
6142 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
6146 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
6150 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
6153 case DW_FORM_string
:
6154 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
6155 info_ptr
+= bytes_read
;
6158 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
6160 info_ptr
+= bytes_read
;
6163 blk
= dwarf_alloc_block (cu
);
6164 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6165 info_ptr
+= bytes_read
;
6166 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6167 info_ptr
+= blk
->size
;
6168 DW_BLOCK (attr
) = blk
;
6170 case DW_FORM_block1
:
6171 blk
= dwarf_alloc_block (cu
);
6172 blk
->size
= read_1_byte (abfd
, info_ptr
);
6174 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6175 info_ptr
+= blk
->size
;
6176 DW_BLOCK (attr
) = blk
;
6179 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6183 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6187 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
6188 info_ptr
+= bytes_read
;
6191 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6192 info_ptr
+= bytes_read
;
6195 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
6199 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
6203 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
6207 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
6210 case DW_FORM_ref_udata
:
6211 DW_ADDR (attr
) = (cu
->header
.offset
6212 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
6213 info_ptr
+= bytes_read
;
6215 case DW_FORM_indirect
:
6216 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6217 info_ptr
+= bytes_read
;
6218 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
6221 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
6222 dwarf_form_name (form
),
6223 bfd_get_filename (abfd
));
6226 /* We have seen instances where the compiler tried to emit a byte
6227 size attribute of -1 which ended up being encoded as an unsigned
6228 0xffffffff. Although 0xffffffff is technically a valid size value,
6229 an object of this size seems pretty unlikely so we can relatively
6230 safely treat these cases as if the size attribute was invalid and
6231 treat them as zero by default. */
6232 if (attr
->name
== DW_AT_byte_size
6233 && form
== DW_FORM_data4
6234 && DW_UNSND (attr
) >= 0xffffffff)
6237 (&symfile_complaints
,
6238 _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"),
6240 DW_UNSND (attr
) = 0;
6246 /* Read an attribute described by an abbreviated attribute. */
6249 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
6250 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6252 attr
->name
= abbrev
->name
;
6253 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
6256 /* read dwarf information from a buffer */
6259 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
6261 return bfd_get_8 (abfd
, buf
);
6265 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
6267 return bfd_get_signed_8 (abfd
, buf
);
6271 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
6273 return bfd_get_16 (abfd
, buf
);
6277 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6279 return bfd_get_signed_16 (abfd
, buf
);
6283 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
6285 return bfd_get_32 (abfd
, buf
);
6289 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6291 return bfd_get_signed_32 (abfd
, buf
);
6294 static unsigned long
6295 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
6297 return bfd_get_64 (abfd
, buf
);
6301 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
6302 unsigned int *bytes_read
)
6304 struct comp_unit_head
*cu_header
= &cu
->header
;
6305 CORE_ADDR retval
= 0;
6307 if (cu_header
->signed_addr_p
)
6309 switch (cu_header
->addr_size
)
6312 retval
= bfd_get_signed_16 (abfd
, buf
);
6315 retval
= bfd_get_signed_32 (abfd
, buf
);
6318 retval
= bfd_get_signed_64 (abfd
, buf
);
6321 internal_error (__FILE__
, __LINE__
,
6322 _("read_address: bad switch, signed [in module %s]"),
6323 bfd_get_filename (abfd
));
6328 switch (cu_header
->addr_size
)
6331 retval
= bfd_get_16 (abfd
, buf
);
6334 retval
= bfd_get_32 (abfd
, buf
);
6337 retval
= bfd_get_64 (abfd
, buf
);
6340 internal_error (__FILE__
, __LINE__
,
6341 _("read_address: bad switch, unsigned [in module %s]"),
6342 bfd_get_filename (abfd
));
6346 *bytes_read
= cu_header
->addr_size
;
6350 /* Read the initial length from a section. The (draft) DWARF 3
6351 specification allows the initial length to take up either 4 bytes
6352 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
6353 bytes describe the length and all offsets will be 8 bytes in length
6356 An older, non-standard 64-bit format is also handled by this
6357 function. The older format in question stores the initial length
6358 as an 8-byte quantity without an escape value. Lengths greater
6359 than 2^32 aren't very common which means that the initial 4 bytes
6360 is almost always zero. Since a length value of zero doesn't make
6361 sense for the 32-bit format, this initial zero can be considered to
6362 be an escape value which indicates the presence of the older 64-bit
6363 format. As written, the code can't detect (old format) lengths
6364 greater than 4GB. If it becomes necessary to handle lengths
6365 somewhat larger than 4GB, we could allow other small values (such
6366 as the non-sensical values of 1, 2, and 3) to also be used as
6367 escape values indicating the presence of the old format.
6369 The value returned via bytes_read should be used to increment the
6370 relevant pointer after calling read_initial_length().
6372 As a side effect, this function sets the fields initial_length_size
6373 and offset_size in cu_header to the values appropriate for the
6374 length field. (The format of the initial length field determines
6375 the width of file offsets to be fetched later with read_offset().)
6377 [ Note: read_initial_length() and read_offset() are based on the
6378 document entitled "DWARF Debugging Information Format", revision
6379 3, draft 8, dated November 19, 2001. This document was obtained
6382 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
6384 This document is only a draft and is subject to change. (So beware.)
6386 Details regarding the older, non-standard 64-bit format were
6387 determined empirically by examining 64-bit ELF files produced by
6388 the SGI toolchain on an IRIX 6.5 machine.
6390 - Kevin, July 16, 2002
6394 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, struct comp_unit_head
*cu_header
,
6395 unsigned int *bytes_read
)
6397 LONGEST length
= bfd_get_32 (abfd
, buf
);
6399 if (length
== 0xffffffff)
6401 length
= bfd_get_64 (abfd
, buf
+ 4);
6404 else if (length
== 0)
6406 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
6407 length
= bfd_get_64 (abfd
, buf
);
6417 gdb_assert (cu_header
->initial_length_size
== 0
6418 || cu_header
->initial_length_size
== 4
6419 || cu_header
->initial_length_size
== 8
6420 || cu_header
->initial_length_size
== 12);
6422 if (cu_header
->initial_length_size
!= 0
6423 && cu_header
->initial_length_size
!= *bytes_read
)
6424 complaint (&symfile_complaints
,
6425 _("intermixed 32-bit and 64-bit DWARF sections"));
6427 cu_header
->initial_length_size
= *bytes_read
;
6428 cu_header
->offset_size
= (*bytes_read
== 4) ? 4 : 8;
6434 /* Read an offset from the data stream. The size of the offset is
6435 given by cu_header->offset_size. */
6438 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
6439 unsigned int *bytes_read
)
6443 switch (cu_header
->offset_size
)
6446 retval
= bfd_get_32 (abfd
, buf
);
6450 retval
= bfd_get_64 (abfd
, buf
);
6454 internal_error (__FILE__
, __LINE__
,
6455 _("read_offset: bad switch [in module %s]"),
6456 bfd_get_filename (abfd
));
6463 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
6465 /* If the size of a host char is 8 bits, we can return a pointer
6466 to the buffer, otherwise we have to copy the data to a buffer
6467 allocated on the temporary obstack. */
6468 gdb_assert (HOST_CHAR_BIT
== 8);
6473 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6475 /* If the size of a host char is 8 bits, we can return a pointer
6476 to the string, otherwise we have to copy the string to a buffer
6477 allocated on the temporary obstack. */
6478 gdb_assert (HOST_CHAR_BIT
== 8);
6481 *bytes_read_ptr
= 1;
6484 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
6485 return (char *) buf
;
6489 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
6490 const struct comp_unit_head
*cu_header
,
6491 unsigned int *bytes_read_ptr
)
6493 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
6496 if (dwarf2_per_objfile
->str_buffer
== NULL
)
6498 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
6499 bfd_get_filename (abfd
));
6502 if (str_offset
>= dwarf2_per_objfile
->str_size
)
6504 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
6505 bfd_get_filename (abfd
));
6508 gdb_assert (HOST_CHAR_BIT
== 8);
6509 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
6511 return (char *) (dwarf2_per_objfile
->str_buffer
+ str_offset
);
6514 static unsigned long
6515 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6517 unsigned long result
;
6518 unsigned int num_read
;
6528 byte
= bfd_get_8 (abfd
, buf
);
6531 result
|= ((unsigned long)(byte
& 127) << shift
);
6532 if ((byte
& 128) == 0)
6538 *bytes_read_ptr
= num_read
;
6543 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6546 int i
, shift
, num_read
;
6555 byte
= bfd_get_8 (abfd
, buf
);
6558 result
|= ((long)(byte
& 127) << shift
);
6560 if ((byte
& 128) == 0)
6565 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
6566 result
|= -(((long)1) << shift
);
6567 *bytes_read_ptr
= num_read
;
6571 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6574 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
6580 byte
= bfd_get_8 (abfd
, buf
);
6582 if ((byte
& 128) == 0)
6588 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
6594 cu
->language
= language_c
;
6596 case DW_LANG_C_plus_plus
:
6597 cu
->language
= language_cplus
;
6599 case DW_LANG_Fortran77
:
6600 case DW_LANG_Fortran90
:
6601 case DW_LANG_Fortran95
:
6602 cu
->language
= language_fortran
;
6604 case DW_LANG_Mips_Assembler
:
6605 cu
->language
= language_asm
;
6608 cu
->language
= language_java
;
6612 cu
->language
= language_ada
;
6614 case DW_LANG_Modula2
:
6615 cu
->language
= language_m2
;
6617 case DW_LANG_Pascal83
:
6618 cu
->language
= language_pascal
;
6621 cu
->language
= language_objc
;
6623 case DW_LANG_Cobol74
:
6624 case DW_LANG_Cobol85
:
6626 cu
->language
= language_minimal
;
6629 cu
->language_defn
= language_def (cu
->language
);
6632 /* Return the named attribute or NULL if not there. */
6634 static struct attribute
*
6635 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
6638 struct attribute
*spec
= NULL
;
6640 for (i
= 0; i
< die
->num_attrs
; ++i
)
6642 if (die
->attrs
[i
].name
== name
)
6643 return &die
->attrs
[i
];
6644 if (die
->attrs
[i
].name
== DW_AT_specification
6645 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
6646 spec
= &die
->attrs
[i
];
6651 die
= follow_die_ref (die
, spec
, &cu
);
6652 return dwarf2_attr (die
, name
, cu
);
6658 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6659 and holds a non-zero value. This function should only be used for
6660 DW_FORM_flag attributes. */
6663 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
6665 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
6667 return (attr
&& DW_UNSND (attr
));
6671 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
6673 /* A DIE is a declaration if it has a DW_AT_declaration attribute
6674 which value is non-zero. However, we have to be careful with
6675 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
6676 (via dwarf2_flag_true_p) follows this attribute. So we may
6677 end up accidently finding a declaration attribute that belongs
6678 to a different DIE referenced by the specification attribute,
6679 even though the given DIE does not have a declaration attribute. */
6680 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
6681 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
6684 /* Return the die giving the specification for DIE, if there is
6685 one. *SPEC_CU is the CU containing DIE on input, and the CU
6686 containing the return value on output. */
6688 static struct die_info
*
6689 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
6691 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
6694 if (spec_attr
== NULL
)
6697 return follow_die_ref (die
, spec_attr
, spec_cu
);
6700 /* Free the line_header structure *LH, and any arrays and strings it
6703 free_line_header (struct line_header
*lh
)
6705 if (lh
->standard_opcode_lengths
)
6706 xfree (lh
->standard_opcode_lengths
);
6708 /* Remember that all the lh->file_names[i].name pointers are
6709 pointers into debug_line_buffer, and don't need to be freed. */
6711 xfree (lh
->file_names
);
6713 /* Similarly for the include directory names. */
6714 if (lh
->include_dirs
)
6715 xfree (lh
->include_dirs
);
6721 /* Add an entry to LH's include directory table. */
6723 add_include_dir (struct line_header
*lh
, char *include_dir
)
6725 /* Grow the array if necessary. */
6726 if (lh
->include_dirs_size
== 0)
6728 lh
->include_dirs_size
= 1; /* for testing */
6729 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
6730 * sizeof (*lh
->include_dirs
));
6732 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
6734 lh
->include_dirs_size
*= 2;
6735 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
6736 (lh
->include_dirs_size
6737 * sizeof (*lh
->include_dirs
)));
6740 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
6744 /* Add an entry to LH's file name table. */
6746 add_file_name (struct line_header
*lh
,
6748 unsigned int dir_index
,
6749 unsigned int mod_time
,
6750 unsigned int length
)
6752 struct file_entry
*fe
;
6754 /* Grow the array if necessary. */
6755 if (lh
->file_names_size
== 0)
6757 lh
->file_names_size
= 1; /* for testing */
6758 lh
->file_names
= xmalloc (lh
->file_names_size
6759 * sizeof (*lh
->file_names
));
6761 else if (lh
->num_file_names
>= lh
->file_names_size
)
6763 lh
->file_names_size
*= 2;
6764 lh
->file_names
= xrealloc (lh
->file_names
,
6765 (lh
->file_names_size
6766 * sizeof (*lh
->file_names
)));
6769 fe
= &lh
->file_names
[lh
->num_file_names
++];
6771 fe
->dir_index
= dir_index
;
6772 fe
->mod_time
= mod_time
;
6773 fe
->length
= length
;
6779 /* Read the statement program header starting at OFFSET in
6780 .debug_line, according to the endianness of ABFD. Return a pointer
6781 to a struct line_header, allocated using xmalloc.
6783 NOTE: the strings in the include directory and file name tables of
6784 the returned object point into debug_line_buffer, and must not be
6786 static struct line_header
*
6787 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
6788 struct dwarf2_cu
*cu
)
6790 struct cleanup
*back_to
;
6791 struct line_header
*lh
;
6793 unsigned int bytes_read
;
6795 char *cur_dir
, *cur_file
;
6797 if (dwarf2_per_objfile
->line_buffer
== NULL
)
6799 complaint (&symfile_complaints
, _("missing .debug_line section"));
6803 /* Make sure that at least there's room for the total_length field.
6804 That could be 12 bytes long, but we're just going to fudge that. */
6805 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
6807 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6811 lh
= xmalloc (sizeof (*lh
));
6812 memset (lh
, 0, sizeof (*lh
));
6813 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
6816 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
6818 /* Read in the header. */
6820 read_initial_length (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6821 line_ptr
+= bytes_read
;
6822 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
6823 + dwarf2_per_objfile
->line_size
))
6825 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6828 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
6829 lh
->version
= read_2_bytes (abfd
, line_ptr
);
6831 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6832 line_ptr
+= bytes_read
;
6833 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
6835 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
6837 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
6839 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
6841 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
6843 lh
->standard_opcode_lengths
6844 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
6846 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
6847 for (i
= 1; i
< lh
->opcode_base
; ++i
)
6849 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
6853 /* Read directory table. */
6854 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6856 line_ptr
+= bytes_read
;
6857 add_include_dir (lh
, cur_dir
);
6859 line_ptr
+= bytes_read
;
6861 /* Read file name table. */
6862 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6864 unsigned int dir_index
, mod_time
, length
;
6866 line_ptr
+= bytes_read
;
6867 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6868 line_ptr
+= bytes_read
;
6869 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6870 line_ptr
+= bytes_read
;
6871 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6872 line_ptr
+= bytes_read
;
6874 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6876 line_ptr
+= bytes_read
;
6877 lh
->statement_program_start
= line_ptr
;
6879 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
6880 + dwarf2_per_objfile
->line_size
))
6881 complaint (&symfile_complaints
,
6882 _("line number info header doesn't fit in `.debug_line' section"));
6884 discard_cleanups (back_to
);
6888 /* This function exists to work around a bug in certain compilers
6889 (particularly GCC 2.95), in which the first line number marker of a
6890 function does not show up until after the prologue, right before
6891 the second line number marker. This function shifts ADDRESS down
6892 to the beginning of the function if necessary, and is called on
6893 addresses passed to record_line. */
6896 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
6898 struct function_range
*fn
;
6900 /* Find the function_range containing address. */
6905 cu
->cached_fn
= cu
->first_fn
;
6909 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6915 while (fn
&& fn
!= cu
->cached_fn
)
6916 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6926 if (address
!= fn
->lowpc
)
6927 complaint (&symfile_complaints
,
6928 _("misplaced first line number at 0x%lx for '%s'"),
6929 (unsigned long) address
, fn
->name
);
6934 /* Decode the Line Number Program (LNP) for the given line_header
6935 structure and CU. The actual information extracted and the type
6936 of structures created from the LNP depends on the value of PST.
6938 1. If PST is NULL, then this procedure uses the data from the program
6939 to create all necessary symbol tables, and their linetables.
6940 The compilation directory of the file is passed in COMP_DIR,
6941 and must not be NULL.
6943 2. If PST is not NULL, this procedure reads the program to determine
6944 the list of files included by the unit represented by PST, and
6945 builds all the associated partial symbol tables. In this case,
6946 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
6947 is not used to compute the full name of the symtab, and therefore
6948 omitting it when building the partial symtab does not introduce
6949 the potential for inconsistency - a partial symtab and its associated
6950 symbtab having a different fullname -). */
6953 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
6954 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
6956 gdb_byte
*line_ptr
, *extended_end
;
6958 unsigned int bytes_read
, extended_len
;
6959 unsigned char op_code
, extended_op
, adj_opcode
;
6961 struct objfile
*objfile
= cu
->objfile
;
6962 const int decode_for_pst_p
= (pst
!= NULL
);
6963 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
6965 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6967 line_ptr
= lh
->statement_program_start
;
6968 line_end
= lh
->statement_program_end
;
6970 /* Read the statement sequences until there's nothing left. */
6971 while (line_ptr
< line_end
)
6973 /* state machine registers */
6974 CORE_ADDR address
= 0;
6975 unsigned int file
= 1;
6976 unsigned int line
= 1;
6977 unsigned int column
= 0;
6978 int is_stmt
= lh
->default_is_stmt
;
6979 int basic_block
= 0;
6980 int end_sequence
= 0;
6982 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
6984 /* Start a subfile for the current file of the state machine. */
6985 /* lh->include_dirs and lh->file_names are 0-based, but the
6986 directory and file name numbers in the statement program
6988 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
6992 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6994 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
6997 /* Decode the table. */
6998 while (!end_sequence
)
7000 op_code
= read_1_byte (abfd
, line_ptr
);
7003 if (op_code
>= lh
->opcode_base
)
7005 /* Special operand. */
7006 adj_opcode
= op_code
- lh
->opcode_base
;
7007 address
+= (adj_opcode
/ lh
->line_range
)
7008 * lh
->minimum_instruction_length
;
7009 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
7010 if (lh
->num_file_names
< file
)
7011 dwarf2_debug_line_missing_file_complaint ();
7014 lh
->file_names
[file
- 1].included_p
= 1;
7015 if (!decode_for_pst_p
)
7017 if (last_subfile
!= current_subfile
)
7020 record_line (last_subfile
, 0, address
);
7021 last_subfile
= current_subfile
;
7023 /* Append row to matrix using current values. */
7024 record_line (current_subfile
, line
,
7025 check_cu_functions (address
, cu
));
7030 else switch (op_code
)
7032 case DW_LNS_extended_op
:
7033 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7034 line_ptr
+= bytes_read
;
7035 extended_end
= line_ptr
+ extended_len
;
7036 extended_op
= read_1_byte (abfd
, line_ptr
);
7038 switch (extended_op
)
7040 case DW_LNE_end_sequence
:
7043 if (lh
->num_file_names
< file
)
7044 dwarf2_debug_line_missing_file_complaint ();
7047 lh
->file_names
[file
- 1].included_p
= 1;
7048 if (!decode_for_pst_p
)
7049 record_line (current_subfile
, 0, address
);
7052 case DW_LNE_set_address
:
7053 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
7054 line_ptr
+= bytes_read
;
7055 address
+= baseaddr
;
7057 case DW_LNE_define_file
:
7060 unsigned int dir_index
, mod_time
, length
;
7062 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
7063 line_ptr
+= bytes_read
;
7065 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7066 line_ptr
+= bytes_read
;
7068 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7069 line_ptr
+= bytes_read
;
7071 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7072 line_ptr
+= bytes_read
;
7073 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7077 complaint (&symfile_complaints
,
7078 _("mangled .debug_line section"));
7081 /* Make sure that we parsed the extended op correctly. If e.g.
7082 we expected a different address size than the producer used,
7083 we may have read the wrong number of bytes. */
7084 if (line_ptr
!= extended_end
)
7086 complaint (&symfile_complaints
,
7087 _("mangled .debug_line section"));
7092 if (lh
->num_file_names
< file
)
7093 dwarf2_debug_line_missing_file_complaint ();
7096 lh
->file_names
[file
- 1].included_p
= 1;
7097 if (!decode_for_pst_p
)
7099 if (last_subfile
!= current_subfile
)
7102 record_line (last_subfile
, 0, address
);
7103 last_subfile
= current_subfile
;
7105 record_line (current_subfile
, line
,
7106 check_cu_functions (address
, cu
));
7111 case DW_LNS_advance_pc
:
7112 address
+= lh
->minimum_instruction_length
7113 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7114 line_ptr
+= bytes_read
;
7116 case DW_LNS_advance_line
:
7117 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
7118 line_ptr
+= bytes_read
;
7120 case DW_LNS_set_file
:
7122 /* The arrays lh->include_dirs and lh->file_names are
7123 0-based, but the directory and file name numbers in
7124 the statement program are 1-based. */
7125 struct file_entry
*fe
;
7128 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7129 line_ptr
+= bytes_read
;
7130 if (lh
->num_file_names
< file
)
7131 dwarf2_debug_line_missing_file_complaint ();
7134 fe
= &lh
->file_names
[file
- 1];
7136 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7137 if (!decode_for_pst_p
)
7139 last_subfile
= current_subfile
;
7140 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7145 case DW_LNS_set_column
:
7146 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7147 line_ptr
+= bytes_read
;
7149 case DW_LNS_negate_stmt
:
7150 is_stmt
= (!is_stmt
);
7152 case DW_LNS_set_basic_block
:
7155 /* Add to the address register of the state machine the
7156 address increment value corresponding to special opcode
7157 255. I.e., this value is scaled by the minimum
7158 instruction length since special opcode 255 would have
7159 scaled the the increment. */
7160 case DW_LNS_const_add_pc
:
7161 address
+= (lh
->minimum_instruction_length
7162 * ((255 - lh
->opcode_base
) / lh
->line_range
));
7164 case DW_LNS_fixed_advance_pc
:
7165 address
+= read_2_bytes (abfd
, line_ptr
);
7170 /* Unknown standard opcode, ignore it. */
7173 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
7175 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7176 line_ptr
+= bytes_read
;
7183 if (decode_for_pst_p
)
7187 /* Now that we're done scanning the Line Header Program, we can
7188 create the psymtab of each included file. */
7189 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
7190 if (lh
->file_names
[file_index
].included_p
== 1)
7192 const struct file_entry fe
= lh
->file_names
[file_index
];
7193 char *include_name
= fe
.name
;
7194 char *dir_name
= NULL
;
7195 char *pst_filename
= pst
->filename
;
7198 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
7200 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
7202 include_name
= concat (dir_name
, SLASH_STRING
,
7203 include_name
, (char *)NULL
);
7204 make_cleanup (xfree
, include_name
);
7207 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
7209 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
7210 pst_filename
, (char *)NULL
);
7211 make_cleanup (xfree
, pst_filename
);
7214 if (strcmp (include_name
, pst_filename
) != 0)
7215 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
7220 /* Make sure a symtab is created for every file, even files
7221 which contain only variables (i.e. no code with associated
7225 struct file_entry
*fe
;
7227 for (i
= 0; i
< lh
->num_file_names
; i
++)
7230 fe
= &lh
->file_names
[i
];
7232 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7233 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7235 /* Skip the main file; we don't need it, and it must be
7236 allocated last, so that it will show up before the
7237 non-primary symtabs in the objfile's symtab list. */
7238 if (current_subfile
== first_subfile
)
7241 if (current_subfile
->symtab
== NULL
)
7242 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7244 fe
->symtab
= current_subfile
->symtab
;
7249 /* Start a subfile for DWARF. FILENAME is the name of the file and
7250 DIRNAME the name of the source directory which contains FILENAME
7251 or NULL if not known. COMP_DIR is the compilation directory for the
7252 linetable's compilation unit or NULL if not known.
7253 This routine tries to keep line numbers from identical absolute and
7254 relative file names in a common subfile.
7256 Using the `list' example from the GDB testsuite, which resides in
7257 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
7258 of /srcdir/list0.c yields the following debugging information for list0.c:
7260 DW_AT_name: /srcdir/list0.c
7261 DW_AT_comp_dir: /compdir
7262 files.files[0].name: list0.h
7263 files.files[0].dir: /srcdir
7264 files.files[1].name: list0.c
7265 files.files[1].dir: /srcdir
7267 The line number information for list0.c has to end up in a single
7268 subfile, so that `break /srcdir/list0.c:1' works as expected.
7269 start_subfile will ensure that this happens provided that we pass the
7270 concatenation of files.files[1].dir and files.files[1].name as the
7274 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
7278 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
7279 `start_symtab' will always pass the contents of DW_AT_comp_dir as
7280 second argument to start_subfile. To be consistent, we do the
7281 same here. In order not to lose the line information directory,
7282 we concatenate it to the filename when it makes sense.
7283 Note that the Dwarf3 standard says (speaking of filenames in line
7284 information): ``The directory index is ignored for file names
7285 that represent full path names''. Thus ignoring dirname in the
7286 `else' branch below isn't an issue. */
7288 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
7289 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
7291 fullname
= filename
;
7293 start_subfile (fullname
, comp_dir
);
7295 if (fullname
!= filename
)
7300 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
7301 struct dwarf2_cu
*cu
)
7303 struct objfile
*objfile
= cu
->objfile
;
7304 struct comp_unit_head
*cu_header
= &cu
->header
;
7306 /* NOTE drow/2003-01-30: There used to be a comment and some special
7307 code here to turn a symbol with DW_AT_external and a
7308 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
7309 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
7310 with some versions of binutils) where shared libraries could have
7311 relocations against symbols in their debug information - the
7312 minimal symbol would have the right address, but the debug info
7313 would not. It's no longer necessary, because we will explicitly
7314 apply relocations when we read in the debug information now. */
7316 /* A DW_AT_location attribute with no contents indicates that a
7317 variable has been optimized away. */
7318 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
7320 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7324 /* Handle one degenerate form of location expression specially, to
7325 preserve GDB's previous behavior when section offsets are
7326 specified. If this is just a DW_OP_addr then mark this symbol
7329 if (attr_form_is_block (attr
)
7330 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
7331 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
7335 SYMBOL_VALUE_ADDRESS (sym
) =
7336 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
7337 SYMBOL_CLASS (sym
) = LOC_STATIC
;
7338 fixup_symbol_section (sym
, objfile
);
7339 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
7340 SYMBOL_SECTION (sym
));
7344 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
7345 expression evaluator, and use LOC_COMPUTED only when necessary
7346 (i.e. when the value of a register or memory location is
7347 referenced, or a thread-local block, etc.). Then again, it might
7348 not be worthwhile. I'm assuming that it isn't unless performance
7349 or memory numbers show me otherwise. */
7351 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
7352 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
7355 /* Given a pointer to a DWARF information entry, figure out if we need
7356 to make a symbol table entry for it, and if so, create a new entry
7357 and return a pointer to it.
7358 If TYPE is NULL, determine symbol type from the die, otherwise
7359 used the passed type. */
7361 static struct symbol
*
7362 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
7364 struct objfile
*objfile
= cu
->objfile
;
7365 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7366 struct symbol
*sym
= NULL
;
7368 struct attribute
*attr
= NULL
;
7369 struct attribute
*attr2
= NULL
;
7372 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7374 if (die
->tag
!= DW_TAG_namespace
)
7375 name
= dwarf2_linkage_name (die
, cu
);
7377 name
= TYPE_NAME (type
);
7381 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
7382 sizeof (struct symbol
));
7383 OBJSTAT (objfile
, n_syms
++);
7384 memset (sym
, 0, sizeof (struct symbol
));
7386 /* Cache this symbol's name and the name's demangled form (if any). */
7387 SYMBOL_LANGUAGE (sym
) = cu
->language
;
7388 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
7390 /* Default assumptions.
7391 Use the passed type or decode it from the die. */
7392 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7393 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7395 SYMBOL_TYPE (sym
) = type
;
7397 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
7398 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
7401 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
7404 attr
= dwarf2_attr (die
, DW_AT_decl_file
, cu
);
7407 int file_index
= DW_UNSND (attr
);
7408 if (cu
->line_header
== NULL
7409 || file_index
> cu
->line_header
->num_file_names
)
7410 complaint (&symfile_complaints
,
7411 _("file index out of range"));
7412 else if (file_index
> 0)
7414 struct file_entry
*fe
;
7415 fe
= &cu
->line_header
->file_names
[file_index
- 1];
7416 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
7423 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7426 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
7428 SYMBOL_CLASS (sym
) = LOC_LABEL
;
7430 case DW_TAG_subprogram
:
7431 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7433 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
7434 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7435 if ((attr2
&& (DW_UNSND (attr2
) != 0))
7436 || cu
->language
== language_ada
)
7438 /* Subprograms marked external are stored as a global symbol.
7439 Ada subprograms, whether marked external or not, are always
7440 stored as a global symbol, because we want to be able to
7441 access them globally. For instance, we want to be able
7442 to break on a nested subprogram without having to
7443 specify the context. */
7444 add_symbol_to_list (sym
, &global_symbols
);
7448 add_symbol_to_list (sym
, cu
->list_in_scope
);
7451 case DW_TAG_variable
:
7452 /* Compilation with minimal debug info may result in variables
7453 with missing type entries. Change the misleading `void' type
7454 to something sensible. */
7455 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
7457 = builtin_type (gdbarch
)->nodebug_data_symbol
;
7459 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7462 dwarf2_const_value (attr
, sym
, cu
);
7463 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7464 if (attr2
&& (DW_UNSND (attr2
) != 0))
7465 add_symbol_to_list (sym
, &global_symbols
);
7467 add_symbol_to_list (sym
, cu
->list_in_scope
);
7470 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7473 var_decode_location (attr
, sym
, cu
);
7474 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7475 if (attr2
&& (DW_UNSND (attr2
) != 0))
7476 add_symbol_to_list (sym
, &global_symbols
);
7478 add_symbol_to_list (sym
, cu
->list_in_scope
);
7482 /* We do not know the address of this symbol.
7483 If it is an external symbol and we have type information
7484 for it, enter the symbol as a LOC_UNRESOLVED symbol.
7485 The address of the variable will then be determined from
7486 the minimal symbol table whenever the variable is
7488 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7489 if (attr2
&& (DW_UNSND (attr2
) != 0)
7490 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
7492 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
7493 add_symbol_to_list (sym
, &global_symbols
);
7497 case DW_TAG_formal_parameter
:
7498 SYMBOL_IS_ARGUMENT (sym
) = 1;
7499 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7502 var_decode_location (attr
, sym
, cu
);
7504 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7507 dwarf2_const_value (attr
, sym
, cu
);
7509 add_symbol_to_list (sym
, cu
->list_in_scope
);
7511 case DW_TAG_unspecified_parameters
:
7512 /* From varargs functions; gdb doesn't seem to have any
7513 interest in this information, so just ignore it for now.
7516 case DW_TAG_class_type
:
7517 case DW_TAG_interface_type
:
7518 case DW_TAG_structure_type
:
7519 case DW_TAG_union_type
:
7520 case DW_TAG_set_type
:
7521 case DW_TAG_enumeration_type
:
7522 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7523 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7525 /* Make sure that the symbol includes appropriate enclosing
7526 classes/namespaces in its name. These are calculated in
7527 read_structure_type, and the correct name is saved in
7530 if (cu
->language
== language_cplus
7531 || cu
->language
== language_java
)
7533 struct type
*type
= SYMBOL_TYPE (sym
);
7535 if (TYPE_TAG_NAME (type
) != NULL
)
7537 /* FIXME: carlton/2003-11-10: Should this use
7538 SYMBOL_SET_NAMES instead? (The same problem also
7539 arises further down in this function.) */
7540 /* The type's name is already allocated along with
7541 this objfile, so we don't need to duplicate it
7543 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
7548 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
7549 really ever be static objects: otherwise, if you try
7550 to, say, break of a class's method and you're in a file
7551 which doesn't mention that class, it won't work unless
7552 the check for all static symbols in lookup_symbol_aux
7553 saves you. See the OtherFileClass tests in
7554 gdb.c++/namespace.exp. */
7556 struct pending
**list_to_add
;
7558 list_to_add
= (cu
->list_in_scope
== &file_symbols
7559 && (cu
->language
== language_cplus
7560 || cu
->language
== language_java
)
7561 ? &global_symbols
: cu
->list_in_scope
);
7563 add_symbol_to_list (sym
, list_to_add
);
7565 /* The semantics of C++ state that "struct foo { ... }" also
7566 defines a typedef for "foo". A Java class declaration also
7567 defines a typedef for the class. */
7568 if (cu
->language
== language_cplus
7569 || cu
->language
== language_java
7570 || cu
->language
== language_ada
)
7572 /* The symbol's name is already allocated along with
7573 this objfile, so we don't need to duplicate it for
7575 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
7576 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
7580 case DW_TAG_typedef
:
7581 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7582 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7583 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7584 add_symbol_to_list (sym
, cu
->list_in_scope
);
7586 case DW_TAG_base_type
:
7587 case DW_TAG_subrange_type
:
7588 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7589 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7590 add_symbol_to_list (sym
, cu
->list_in_scope
);
7592 case DW_TAG_enumerator
:
7593 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7594 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7597 dwarf2_const_value (attr
, sym
, cu
);
7600 /* NOTE: carlton/2003-11-10: See comment above in the
7601 DW_TAG_class_type, etc. block. */
7603 struct pending
**list_to_add
;
7605 list_to_add
= (cu
->list_in_scope
== &file_symbols
7606 && (cu
->language
== language_cplus
7607 || cu
->language
== language_java
)
7608 ? &global_symbols
: cu
->list_in_scope
);
7610 add_symbol_to_list (sym
, list_to_add
);
7613 case DW_TAG_namespace
:
7614 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7615 add_symbol_to_list (sym
, &global_symbols
);
7618 /* Not a tag we recognize. Hopefully we aren't processing
7619 trash data, but since we must specifically ignore things
7620 we don't recognize, there is nothing else we should do at
7622 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
7623 dwarf_tag_name (die
->tag
));
7627 /* For the benefit of old versions of GCC, check for anonymous
7628 namespaces based on the demangled name. */
7629 if (!processing_has_namespace_info
7630 && cu
->language
== language_cplus
7631 && dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
) != NULL
)
7632 cp_scan_for_anonymous_namespaces (sym
);
7637 /* Copy constant value from an attribute to a symbol. */
7640 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
7641 struct dwarf2_cu
*cu
)
7643 struct objfile
*objfile
= cu
->objfile
;
7644 struct comp_unit_head
*cu_header
= &cu
->header
;
7645 struct dwarf_block
*blk
;
7650 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
7651 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7652 cu_header
->addr_size
,
7653 TYPE_LENGTH (SYMBOL_TYPE
7655 SYMBOL_VALUE_BYTES (sym
) =
7656 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
7657 /* NOTE: cagney/2003-05-09: In-lined store_address call with
7658 it's body - store_unsigned_integer. */
7659 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
7661 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7664 /* DW_STRING is already allocated on the obstack, point directly
7666 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
7667 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7669 case DW_FORM_block1
:
7670 case DW_FORM_block2
:
7671 case DW_FORM_block4
:
7673 blk
= DW_BLOCK (attr
);
7674 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
7675 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7677 TYPE_LENGTH (SYMBOL_TYPE
7679 SYMBOL_VALUE_BYTES (sym
) =
7680 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
7681 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
7682 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7685 /* The DW_AT_const_value attributes are supposed to carry the
7686 symbol's value "represented as it would be on the target
7687 architecture." By the time we get here, it's already been
7688 converted to host endianness, so we just need to sign- or
7689 zero-extend it as appropriate. */
7691 dwarf2_const_value_data (attr
, sym
, 8);
7694 dwarf2_const_value_data (attr
, sym
, 16);
7697 dwarf2_const_value_data (attr
, sym
, 32);
7700 dwarf2_const_value_data (attr
, sym
, 64);
7704 SYMBOL_VALUE (sym
) = DW_SND (attr
);
7705 SYMBOL_CLASS (sym
) = LOC_CONST
;
7709 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
7710 SYMBOL_CLASS (sym
) = LOC_CONST
;
7714 complaint (&symfile_complaints
,
7715 _("unsupported const value attribute form: '%s'"),
7716 dwarf_form_name (attr
->form
));
7717 SYMBOL_VALUE (sym
) = 0;
7718 SYMBOL_CLASS (sym
) = LOC_CONST
;
7724 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
7725 or zero-extend it as appropriate for the symbol's type. */
7727 dwarf2_const_value_data (struct attribute
*attr
,
7731 LONGEST l
= DW_UNSND (attr
);
7733 if (bits
< sizeof (l
) * 8)
7735 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
7736 l
&= ((LONGEST
) 1 << bits
) - 1;
7738 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
7741 SYMBOL_VALUE (sym
) = l
;
7742 SYMBOL_CLASS (sym
) = LOC_CONST
;
7746 /* Return the type of the die in question using its DW_AT_type attribute. */
7748 static struct type
*
7749 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7751 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7753 struct attribute
*type_attr
;
7754 struct die_info
*type_die
;
7756 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
7759 /* A missing DW_AT_type represents a void type. */
7760 return builtin_type (gdbarch
)->builtin_void
;
7763 type_die
= follow_die_ref (die
, type_attr
, &cu
);
7765 type
= tag_type_to_type (type_die
, cu
);
7768 dump_die (type_die
);
7769 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
7775 /* Return the containing type of the die in question using its
7776 DW_AT_containing_type attribute. */
7778 static struct type
*
7779 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7781 struct type
*type
= NULL
;
7782 struct attribute
*type_attr
;
7783 struct die_info
*type_die
= NULL
;
7785 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
7788 type_die
= follow_die_ref (die
, type_attr
, &cu
);
7789 type
= tag_type_to_type (type_die
, cu
);
7794 dump_die (type_die
);
7795 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
7801 static struct type
*
7802 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7804 struct type
*this_type
;
7806 this_type
= read_type_die (die
, cu
);
7810 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
7816 static struct type
*
7817 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7819 struct type
*this_type
;
7821 this_type
= get_die_type (die
, cu
);
7827 case DW_TAG_class_type
:
7828 case DW_TAG_interface_type
:
7829 case DW_TAG_structure_type
:
7830 case DW_TAG_union_type
:
7831 this_type
= read_structure_type (die
, cu
);
7833 case DW_TAG_enumeration_type
:
7834 this_type
= read_enumeration_type (die
, cu
);
7836 case DW_TAG_subprogram
:
7837 case DW_TAG_subroutine_type
:
7838 this_type
= read_subroutine_type (die
, cu
);
7840 case DW_TAG_array_type
:
7841 this_type
= read_array_type (die
, cu
);
7843 case DW_TAG_set_type
:
7844 this_type
= read_set_type (die
, cu
);
7846 case DW_TAG_pointer_type
:
7847 this_type
= read_tag_pointer_type (die
, cu
);
7849 case DW_TAG_ptr_to_member_type
:
7850 this_type
= read_tag_ptr_to_member_type (die
, cu
);
7852 case DW_TAG_reference_type
:
7853 this_type
= read_tag_reference_type (die
, cu
);
7855 case DW_TAG_const_type
:
7856 this_type
= read_tag_const_type (die
, cu
);
7858 case DW_TAG_volatile_type
:
7859 this_type
= read_tag_volatile_type (die
, cu
);
7861 case DW_TAG_string_type
:
7862 this_type
= read_tag_string_type (die
, cu
);
7864 case DW_TAG_typedef
:
7865 this_type
= read_typedef (die
, cu
);
7867 case DW_TAG_subrange_type
:
7868 this_type
= read_subrange_type (die
, cu
);
7870 case DW_TAG_base_type
:
7871 this_type
= read_base_type (die
, cu
);
7873 case DW_TAG_unspecified_type
:
7874 this_type
= read_unspecified_type (die
, cu
);
7876 case DW_TAG_namespace
:
7877 this_type
= read_namespace_type (die
, cu
);
7880 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
7881 dwarf_tag_name (die
->tag
));
7888 /* Return the name of the namespace/class that DIE is defined within,
7889 or "" if we can't tell. The caller should not xfree the result.
7891 For example, if we're within the method foo() in the following
7901 then determine_prefix on foo's die will return "N::C". */
7904 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
7906 struct die_info
*parent
, *spec_die
;
7907 struct dwarf2_cu
*spec_cu
;
7908 struct type
*parent_type
;
7910 if (cu
->language
!= language_cplus
7911 && cu
->language
!= language_java
)
7914 /* We have to be careful in the presence of DW_AT_specification.
7915 For example, with GCC 3.4, given the code
7919 // Definition of N::foo.
7923 then we'll have a tree of DIEs like this:
7925 1: DW_TAG_compile_unit
7926 2: DW_TAG_namespace // N
7927 3: DW_TAG_subprogram // declaration of N::foo
7928 4: DW_TAG_subprogram // definition of N::foo
7929 DW_AT_specification // refers to die #3
7931 Thus, when processing die #4, we have to pretend that we're in
7932 the context of its DW_AT_specification, namely the contex of die
7935 spec_die
= die_specification (die
, &spec_cu
);
7936 if (spec_die
== NULL
)
7937 parent
= die
->parent
;
7940 parent
= spec_die
->parent
;
7947 switch (parent
->tag
)
7949 case DW_TAG_namespace
:
7950 parent_type
= read_type_die (parent
, cu
);
7951 /* We give a name to even anonymous namespaces. */
7952 return TYPE_TAG_NAME (parent_type
);
7953 case DW_TAG_class_type
:
7954 case DW_TAG_interface_type
:
7955 case DW_TAG_structure_type
:
7956 case DW_TAG_union_type
:
7957 parent_type
= read_type_die (parent
, cu
);
7958 if (TYPE_TAG_NAME (parent_type
) != NULL
)
7959 return TYPE_TAG_NAME (parent_type
);
7961 /* An anonymous structure is only allowed non-static data
7962 members; no typedefs, no member functions, et cetera.
7963 So it does not need a prefix. */
7966 return determine_prefix (parent
, cu
);
7970 /* Return a newly-allocated string formed by concatenating PREFIX and
7971 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
7972 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
7973 perform an obconcat, otherwise allocate storage for the result. The CU argument
7974 is used to determine the language and hence, the appropriate separator. */
7976 #define MAX_SEP_LEN 2 /* sizeof ("::") */
7979 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
7980 struct dwarf2_cu
*cu
)
7984 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
7986 else if (cu
->language
== language_java
)
7993 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
7998 strcpy (retval
, prefix
);
7999 strcat (retval
, sep
);
8002 strcat (retval
, suffix
);
8008 /* We have an obstack. */
8009 return obconcat (obs
, prefix
, sep
, suffix
);
8013 /* Return sibling of die, NULL if no sibling. */
8015 static struct die_info
*
8016 sibling_die (struct die_info
*die
)
8018 return die
->sibling
;
8021 /* Get linkage name of a die, return NULL if not found. */
8024 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8026 struct attribute
*attr
;
8028 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8029 if (attr
&& DW_STRING (attr
))
8030 return DW_STRING (attr
);
8031 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8032 if (attr
&& DW_STRING (attr
))
8033 return DW_STRING (attr
);
8037 /* Get name of a die, return NULL if not found. */
8040 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8042 struct attribute
*attr
;
8044 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8045 if (attr
&& DW_STRING (attr
))
8046 return DW_STRING (attr
);
8050 /* Return the die that this die in an extension of, or NULL if there
8051 is none. *EXT_CU is the CU containing DIE on input, and the CU
8052 containing the return value on output. */
8054 static struct die_info
*
8055 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
8057 struct attribute
*attr
;
8059 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
8063 return follow_die_ref (die
, attr
, ext_cu
);
8066 /* Convert a DIE tag into its string name. */
8069 dwarf_tag_name (unsigned tag
)
8073 case DW_TAG_padding
:
8074 return "DW_TAG_padding";
8075 case DW_TAG_array_type
:
8076 return "DW_TAG_array_type";
8077 case DW_TAG_class_type
:
8078 return "DW_TAG_class_type";
8079 case DW_TAG_entry_point
:
8080 return "DW_TAG_entry_point";
8081 case DW_TAG_enumeration_type
:
8082 return "DW_TAG_enumeration_type";
8083 case DW_TAG_formal_parameter
:
8084 return "DW_TAG_formal_parameter";
8085 case DW_TAG_imported_declaration
:
8086 return "DW_TAG_imported_declaration";
8088 return "DW_TAG_label";
8089 case DW_TAG_lexical_block
:
8090 return "DW_TAG_lexical_block";
8092 return "DW_TAG_member";
8093 case DW_TAG_pointer_type
:
8094 return "DW_TAG_pointer_type";
8095 case DW_TAG_reference_type
:
8096 return "DW_TAG_reference_type";
8097 case DW_TAG_compile_unit
:
8098 return "DW_TAG_compile_unit";
8099 case DW_TAG_string_type
:
8100 return "DW_TAG_string_type";
8101 case DW_TAG_structure_type
:
8102 return "DW_TAG_structure_type";
8103 case DW_TAG_subroutine_type
:
8104 return "DW_TAG_subroutine_type";
8105 case DW_TAG_typedef
:
8106 return "DW_TAG_typedef";
8107 case DW_TAG_union_type
:
8108 return "DW_TAG_union_type";
8109 case DW_TAG_unspecified_parameters
:
8110 return "DW_TAG_unspecified_parameters";
8111 case DW_TAG_variant
:
8112 return "DW_TAG_variant";
8113 case DW_TAG_common_block
:
8114 return "DW_TAG_common_block";
8115 case DW_TAG_common_inclusion
:
8116 return "DW_TAG_common_inclusion";
8117 case DW_TAG_inheritance
:
8118 return "DW_TAG_inheritance";
8119 case DW_TAG_inlined_subroutine
:
8120 return "DW_TAG_inlined_subroutine";
8122 return "DW_TAG_module";
8123 case DW_TAG_ptr_to_member_type
:
8124 return "DW_TAG_ptr_to_member_type";
8125 case DW_TAG_set_type
:
8126 return "DW_TAG_set_type";
8127 case DW_TAG_subrange_type
:
8128 return "DW_TAG_subrange_type";
8129 case DW_TAG_with_stmt
:
8130 return "DW_TAG_with_stmt";
8131 case DW_TAG_access_declaration
:
8132 return "DW_TAG_access_declaration";
8133 case DW_TAG_base_type
:
8134 return "DW_TAG_base_type";
8135 case DW_TAG_catch_block
:
8136 return "DW_TAG_catch_block";
8137 case DW_TAG_const_type
:
8138 return "DW_TAG_const_type";
8139 case DW_TAG_constant
:
8140 return "DW_TAG_constant";
8141 case DW_TAG_enumerator
:
8142 return "DW_TAG_enumerator";
8143 case DW_TAG_file_type
:
8144 return "DW_TAG_file_type";
8146 return "DW_TAG_friend";
8147 case DW_TAG_namelist
:
8148 return "DW_TAG_namelist";
8149 case DW_TAG_namelist_item
:
8150 return "DW_TAG_namelist_item";
8151 case DW_TAG_packed_type
:
8152 return "DW_TAG_packed_type";
8153 case DW_TAG_subprogram
:
8154 return "DW_TAG_subprogram";
8155 case DW_TAG_template_type_param
:
8156 return "DW_TAG_template_type_param";
8157 case DW_TAG_template_value_param
:
8158 return "DW_TAG_template_value_param";
8159 case DW_TAG_thrown_type
:
8160 return "DW_TAG_thrown_type";
8161 case DW_TAG_try_block
:
8162 return "DW_TAG_try_block";
8163 case DW_TAG_variant_part
:
8164 return "DW_TAG_variant_part";
8165 case DW_TAG_variable
:
8166 return "DW_TAG_variable";
8167 case DW_TAG_volatile_type
:
8168 return "DW_TAG_volatile_type";
8169 case DW_TAG_dwarf_procedure
:
8170 return "DW_TAG_dwarf_procedure";
8171 case DW_TAG_restrict_type
:
8172 return "DW_TAG_restrict_type";
8173 case DW_TAG_interface_type
:
8174 return "DW_TAG_interface_type";
8175 case DW_TAG_namespace
:
8176 return "DW_TAG_namespace";
8177 case DW_TAG_imported_module
:
8178 return "DW_TAG_imported_module";
8179 case DW_TAG_unspecified_type
:
8180 return "DW_TAG_unspecified_type";
8181 case DW_TAG_partial_unit
:
8182 return "DW_TAG_partial_unit";
8183 case DW_TAG_imported_unit
:
8184 return "DW_TAG_imported_unit";
8185 case DW_TAG_condition
:
8186 return "DW_TAG_condition";
8187 case DW_TAG_shared_type
:
8188 return "DW_TAG_shared_type";
8189 case DW_TAG_MIPS_loop
:
8190 return "DW_TAG_MIPS_loop";
8191 case DW_TAG_HP_array_descriptor
:
8192 return "DW_TAG_HP_array_descriptor";
8193 case DW_TAG_format_label
:
8194 return "DW_TAG_format_label";
8195 case DW_TAG_function_template
:
8196 return "DW_TAG_function_template";
8197 case DW_TAG_class_template
:
8198 return "DW_TAG_class_template";
8199 case DW_TAG_GNU_BINCL
:
8200 return "DW_TAG_GNU_BINCL";
8201 case DW_TAG_GNU_EINCL
:
8202 return "DW_TAG_GNU_EINCL";
8203 case DW_TAG_upc_shared_type
:
8204 return "DW_TAG_upc_shared_type";
8205 case DW_TAG_upc_strict_type
:
8206 return "DW_TAG_upc_strict_type";
8207 case DW_TAG_upc_relaxed_type
:
8208 return "DW_TAG_upc_relaxed_type";
8209 case DW_TAG_PGI_kanji_type
:
8210 return "DW_TAG_PGI_kanji_type";
8211 case DW_TAG_PGI_interface_block
:
8212 return "DW_TAG_PGI_interface_block";
8214 return "DW_TAG_<unknown>";
8218 /* Convert a DWARF attribute code into its string name. */
8221 dwarf_attr_name (unsigned attr
)
8226 return "DW_AT_sibling";
8227 case DW_AT_location
:
8228 return "DW_AT_location";
8230 return "DW_AT_name";
8231 case DW_AT_ordering
:
8232 return "DW_AT_ordering";
8233 case DW_AT_subscr_data
:
8234 return "DW_AT_subscr_data";
8235 case DW_AT_byte_size
:
8236 return "DW_AT_byte_size";
8237 case DW_AT_bit_offset
:
8238 return "DW_AT_bit_offset";
8239 case DW_AT_bit_size
:
8240 return "DW_AT_bit_size";
8241 case DW_AT_element_list
:
8242 return "DW_AT_element_list";
8243 case DW_AT_stmt_list
:
8244 return "DW_AT_stmt_list";
8246 return "DW_AT_low_pc";
8248 return "DW_AT_high_pc";
8249 case DW_AT_language
:
8250 return "DW_AT_language";
8252 return "DW_AT_member";
8254 return "DW_AT_discr";
8255 case DW_AT_discr_value
:
8256 return "DW_AT_discr_value";
8257 case DW_AT_visibility
:
8258 return "DW_AT_visibility";
8260 return "DW_AT_import";
8261 case DW_AT_string_length
:
8262 return "DW_AT_string_length";
8263 case DW_AT_common_reference
:
8264 return "DW_AT_common_reference";
8265 case DW_AT_comp_dir
:
8266 return "DW_AT_comp_dir";
8267 case DW_AT_const_value
:
8268 return "DW_AT_const_value";
8269 case DW_AT_containing_type
:
8270 return "DW_AT_containing_type";
8271 case DW_AT_default_value
:
8272 return "DW_AT_default_value";
8274 return "DW_AT_inline";
8275 case DW_AT_is_optional
:
8276 return "DW_AT_is_optional";
8277 case DW_AT_lower_bound
:
8278 return "DW_AT_lower_bound";
8279 case DW_AT_producer
:
8280 return "DW_AT_producer";
8281 case DW_AT_prototyped
:
8282 return "DW_AT_prototyped";
8283 case DW_AT_return_addr
:
8284 return "DW_AT_return_addr";
8285 case DW_AT_start_scope
:
8286 return "DW_AT_start_scope";
8287 case DW_AT_bit_stride
:
8288 return "DW_AT_bit_stride";
8289 case DW_AT_upper_bound
:
8290 return "DW_AT_upper_bound";
8291 case DW_AT_abstract_origin
:
8292 return "DW_AT_abstract_origin";
8293 case DW_AT_accessibility
:
8294 return "DW_AT_accessibility";
8295 case DW_AT_address_class
:
8296 return "DW_AT_address_class";
8297 case DW_AT_artificial
:
8298 return "DW_AT_artificial";
8299 case DW_AT_base_types
:
8300 return "DW_AT_base_types";
8301 case DW_AT_calling_convention
:
8302 return "DW_AT_calling_convention";
8304 return "DW_AT_count";
8305 case DW_AT_data_member_location
:
8306 return "DW_AT_data_member_location";
8307 case DW_AT_decl_column
:
8308 return "DW_AT_decl_column";
8309 case DW_AT_decl_file
:
8310 return "DW_AT_decl_file";
8311 case DW_AT_decl_line
:
8312 return "DW_AT_decl_line";
8313 case DW_AT_declaration
:
8314 return "DW_AT_declaration";
8315 case DW_AT_discr_list
:
8316 return "DW_AT_discr_list";
8317 case DW_AT_encoding
:
8318 return "DW_AT_encoding";
8319 case DW_AT_external
:
8320 return "DW_AT_external";
8321 case DW_AT_frame_base
:
8322 return "DW_AT_frame_base";
8324 return "DW_AT_friend";
8325 case DW_AT_identifier_case
:
8326 return "DW_AT_identifier_case";
8327 case DW_AT_macro_info
:
8328 return "DW_AT_macro_info";
8329 case DW_AT_namelist_items
:
8330 return "DW_AT_namelist_items";
8331 case DW_AT_priority
:
8332 return "DW_AT_priority";
8334 return "DW_AT_segment";
8335 case DW_AT_specification
:
8336 return "DW_AT_specification";
8337 case DW_AT_static_link
:
8338 return "DW_AT_static_link";
8340 return "DW_AT_type";
8341 case DW_AT_use_location
:
8342 return "DW_AT_use_location";
8343 case DW_AT_variable_parameter
:
8344 return "DW_AT_variable_parameter";
8345 case DW_AT_virtuality
:
8346 return "DW_AT_virtuality";
8347 case DW_AT_vtable_elem_location
:
8348 return "DW_AT_vtable_elem_location";
8349 /* DWARF 3 values. */
8350 case DW_AT_allocated
:
8351 return "DW_AT_allocated";
8352 case DW_AT_associated
:
8353 return "DW_AT_associated";
8354 case DW_AT_data_location
:
8355 return "DW_AT_data_location";
8356 case DW_AT_byte_stride
:
8357 return "DW_AT_byte_stride";
8358 case DW_AT_entry_pc
:
8359 return "DW_AT_entry_pc";
8360 case DW_AT_use_UTF8
:
8361 return "DW_AT_use_UTF8";
8362 case DW_AT_extension
:
8363 return "DW_AT_extension";
8365 return "DW_AT_ranges";
8366 case DW_AT_trampoline
:
8367 return "DW_AT_trampoline";
8368 case DW_AT_call_column
:
8369 return "DW_AT_call_column";
8370 case DW_AT_call_file
:
8371 return "DW_AT_call_file";
8372 case DW_AT_call_line
:
8373 return "DW_AT_call_line";
8374 case DW_AT_description
:
8375 return "DW_AT_description";
8376 case DW_AT_binary_scale
:
8377 return "DW_AT_binary_scale";
8378 case DW_AT_decimal_scale
:
8379 return "DW_AT_decimal_scale";
8381 return "DW_AT_small";
8382 case DW_AT_decimal_sign
:
8383 return "DW_AT_decimal_sign";
8384 case DW_AT_digit_count
:
8385 return "DW_AT_digit_count";
8386 case DW_AT_picture_string
:
8387 return "DW_AT_picture_string";
8389 return "DW_AT_mutable";
8390 case DW_AT_threads_scaled
:
8391 return "DW_AT_threads_scaled";
8392 case DW_AT_explicit
:
8393 return "DW_AT_explicit";
8394 case DW_AT_object_pointer
:
8395 return "DW_AT_object_pointer";
8396 case DW_AT_endianity
:
8397 return "DW_AT_endianity";
8398 case DW_AT_elemental
:
8399 return "DW_AT_elemental";
8401 return "DW_AT_pure";
8402 case DW_AT_recursive
:
8403 return "DW_AT_recursive";
8405 /* SGI/MIPS extensions. */
8406 case DW_AT_MIPS_fde
:
8407 return "DW_AT_MIPS_fde";
8408 case DW_AT_MIPS_loop_begin
:
8409 return "DW_AT_MIPS_loop_begin";
8410 case DW_AT_MIPS_tail_loop_begin
:
8411 return "DW_AT_MIPS_tail_loop_begin";
8412 case DW_AT_MIPS_epilog_begin
:
8413 return "DW_AT_MIPS_epilog_begin";
8414 case DW_AT_MIPS_loop_unroll_factor
:
8415 return "DW_AT_MIPS_loop_unroll_factor";
8416 case DW_AT_MIPS_software_pipeline_depth
:
8417 return "DW_AT_MIPS_software_pipeline_depth";
8418 case DW_AT_MIPS_linkage_name
:
8419 return "DW_AT_MIPS_linkage_name";
8420 case DW_AT_MIPS_stride
:
8421 return "DW_AT_MIPS_stride";
8422 case DW_AT_MIPS_abstract_name
:
8423 return "DW_AT_MIPS_abstract_name";
8424 case DW_AT_MIPS_clone_origin
:
8425 return "DW_AT_MIPS_clone_origin";
8426 case DW_AT_MIPS_has_inlines
:
8427 return "DW_AT_MIPS_has_inlines";
8429 /* HP extensions. */
8430 case DW_AT_HP_block_index
:
8431 return "DW_AT_HP_block_index";
8432 case DW_AT_HP_unmodifiable
:
8433 return "DW_AT_HP_unmodifiable";
8434 case DW_AT_HP_actuals_stmt_list
:
8435 return "DW_AT_HP_actuals_stmt_list";
8436 case DW_AT_HP_proc_per_section
:
8437 return "DW_AT_HP_proc_per_section";
8438 case DW_AT_HP_raw_data_ptr
:
8439 return "DW_AT_HP_raw_data_ptr";
8440 case DW_AT_HP_pass_by_reference
:
8441 return "DW_AT_HP_pass_by_reference";
8442 case DW_AT_HP_opt_level
:
8443 return "DW_AT_HP_opt_level";
8444 case DW_AT_HP_prof_version_id
:
8445 return "DW_AT_HP_prof_version_id";
8446 case DW_AT_HP_opt_flags
:
8447 return "DW_AT_HP_opt_flags";
8448 case DW_AT_HP_cold_region_low_pc
:
8449 return "DW_AT_HP_cold_region_low_pc";
8450 case DW_AT_HP_cold_region_high_pc
:
8451 return "DW_AT_HP_cold_region_high_pc";
8452 case DW_AT_HP_all_variables_modifiable
:
8453 return "DW_AT_HP_all_variables_modifiable";
8454 case DW_AT_HP_linkage_name
:
8455 return "DW_AT_HP_linkage_name";
8456 case DW_AT_HP_prof_flags
:
8457 return "DW_AT_HP_prof_flags";
8458 /* GNU extensions. */
8459 case DW_AT_sf_names
:
8460 return "DW_AT_sf_names";
8461 case DW_AT_src_info
:
8462 return "DW_AT_src_info";
8463 case DW_AT_mac_info
:
8464 return "DW_AT_mac_info";
8465 case DW_AT_src_coords
:
8466 return "DW_AT_src_coords";
8467 case DW_AT_body_begin
:
8468 return "DW_AT_body_begin";
8469 case DW_AT_body_end
:
8470 return "DW_AT_body_end";
8471 case DW_AT_GNU_vector
:
8472 return "DW_AT_GNU_vector";
8473 /* VMS extensions. */
8474 case DW_AT_VMS_rtnbeg_pd_address
:
8475 return "DW_AT_VMS_rtnbeg_pd_address";
8476 /* UPC extension. */
8477 case DW_AT_upc_threads_scaled
:
8478 return "DW_AT_upc_threads_scaled";
8479 /* PGI (STMicroelectronics) extensions. */
8480 case DW_AT_PGI_lbase
:
8481 return "DW_AT_PGI_lbase";
8482 case DW_AT_PGI_soffset
:
8483 return "DW_AT_PGI_soffset";
8484 case DW_AT_PGI_lstride
:
8485 return "DW_AT_PGI_lstride";
8487 return "DW_AT_<unknown>";
8491 /* Convert a DWARF value form code into its string name. */
8494 dwarf_form_name (unsigned form
)
8499 return "DW_FORM_addr";
8500 case DW_FORM_block2
:
8501 return "DW_FORM_block2";
8502 case DW_FORM_block4
:
8503 return "DW_FORM_block4";
8505 return "DW_FORM_data2";
8507 return "DW_FORM_data4";
8509 return "DW_FORM_data8";
8510 case DW_FORM_string
:
8511 return "DW_FORM_string";
8513 return "DW_FORM_block";
8514 case DW_FORM_block1
:
8515 return "DW_FORM_block1";
8517 return "DW_FORM_data1";
8519 return "DW_FORM_flag";
8521 return "DW_FORM_sdata";
8523 return "DW_FORM_strp";
8525 return "DW_FORM_udata";
8526 case DW_FORM_ref_addr
:
8527 return "DW_FORM_ref_addr";
8529 return "DW_FORM_ref1";
8531 return "DW_FORM_ref2";
8533 return "DW_FORM_ref4";
8535 return "DW_FORM_ref8";
8536 case DW_FORM_ref_udata
:
8537 return "DW_FORM_ref_udata";
8538 case DW_FORM_indirect
:
8539 return "DW_FORM_indirect";
8541 return "DW_FORM_<unknown>";
8545 /* Convert a DWARF stack opcode into its string name. */
8548 dwarf_stack_op_name (unsigned op
)
8553 return "DW_OP_addr";
8555 return "DW_OP_deref";
8557 return "DW_OP_const1u";
8559 return "DW_OP_const1s";
8561 return "DW_OP_const2u";
8563 return "DW_OP_const2s";
8565 return "DW_OP_const4u";
8567 return "DW_OP_const4s";
8569 return "DW_OP_const8u";
8571 return "DW_OP_const8s";
8573 return "DW_OP_constu";
8575 return "DW_OP_consts";
8579 return "DW_OP_drop";
8581 return "DW_OP_over";
8583 return "DW_OP_pick";
8585 return "DW_OP_swap";
8589 return "DW_OP_xderef";
8597 return "DW_OP_minus";
8609 return "DW_OP_plus";
8610 case DW_OP_plus_uconst
:
8611 return "DW_OP_plus_uconst";
8617 return "DW_OP_shra";
8635 return "DW_OP_skip";
8637 return "DW_OP_lit0";
8639 return "DW_OP_lit1";
8641 return "DW_OP_lit2";
8643 return "DW_OP_lit3";
8645 return "DW_OP_lit4";
8647 return "DW_OP_lit5";
8649 return "DW_OP_lit6";
8651 return "DW_OP_lit7";
8653 return "DW_OP_lit8";
8655 return "DW_OP_lit9";
8657 return "DW_OP_lit10";
8659 return "DW_OP_lit11";
8661 return "DW_OP_lit12";
8663 return "DW_OP_lit13";
8665 return "DW_OP_lit14";
8667 return "DW_OP_lit15";
8669 return "DW_OP_lit16";
8671 return "DW_OP_lit17";
8673 return "DW_OP_lit18";
8675 return "DW_OP_lit19";
8677 return "DW_OP_lit20";
8679 return "DW_OP_lit21";
8681 return "DW_OP_lit22";
8683 return "DW_OP_lit23";
8685 return "DW_OP_lit24";
8687 return "DW_OP_lit25";
8689 return "DW_OP_lit26";
8691 return "DW_OP_lit27";
8693 return "DW_OP_lit28";
8695 return "DW_OP_lit29";
8697 return "DW_OP_lit30";
8699 return "DW_OP_lit31";
8701 return "DW_OP_reg0";
8703 return "DW_OP_reg1";
8705 return "DW_OP_reg2";
8707 return "DW_OP_reg3";
8709 return "DW_OP_reg4";
8711 return "DW_OP_reg5";
8713 return "DW_OP_reg6";
8715 return "DW_OP_reg7";
8717 return "DW_OP_reg8";
8719 return "DW_OP_reg9";
8721 return "DW_OP_reg10";
8723 return "DW_OP_reg11";
8725 return "DW_OP_reg12";
8727 return "DW_OP_reg13";
8729 return "DW_OP_reg14";
8731 return "DW_OP_reg15";
8733 return "DW_OP_reg16";
8735 return "DW_OP_reg17";
8737 return "DW_OP_reg18";
8739 return "DW_OP_reg19";
8741 return "DW_OP_reg20";
8743 return "DW_OP_reg21";
8745 return "DW_OP_reg22";
8747 return "DW_OP_reg23";
8749 return "DW_OP_reg24";
8751 return "DW_OP_reg25";
8753 return "DW_OP_reg26";
8755 return "DW_OP_reg27";
8757 return "DW_OP_reg28";
8759 return "DW_OP_reg29";
8761 return "DW_OP_reg30";
8763 return "DW_OP_reg31";
8765 return "DW_OP_breg0";
8767 return "DW_OP_breg1";
8769 return "DW_OP_breg2";
8771 return "DW_OP_breg3";
8773 return "DW_OP_breg4";
8775 return "DW_OP_breg5";
8777 return "DW_OP_breg6";
8779 return "DW_OP_breg7";
8781 return "DW_OP_breg8";
8783 return "DW_OP_breg9";
8785 return "DW_OP_breg10";
8787 return "DW_OP_breg11";
8789 return "DW_OP_breg12";
8791 return "DW_OP_breg13";
8793 return "DW_OP_breg14";
8795 return "DW_OP_breg15";
8797 return "DW_OP_breg16";
8799 return "DW_OP_breg17";
8801 return "DW_OP_breg18";
8803 return "DW_OP_breg19";
8805 return "DW_OP_breg20";
8807 return "DW_OP_breg21";
8809 return "DW_OP_breg22";
8811 return "DW_OP_breg23";
8813 return "DW_OP_breg24";
8815 return "DW_OP_breg25";
8817 return "DW_OP_breg26";
8819 return "DW_OP_breg27";
8821 return "DW_OP_breg28";
8823 return "DW_OP_breg29";
8825 return "DW_OP_breg30";
8827 return "DW_OP_breg31";
8829 return "DW_OP_regx";
8831 return "DW_OP_fbreg";
8833 return "DW_OP_bregx";
8835 return "DW_OP_piece";
8836 case DW_OP_deref_size
:
8837 return "DW_OP_deref_size";
8838 case DW_OP_xderef_size
:
8839 return "DW_OP_xderef_size";
8842 /* DWARF 3 extensions. */
8843 case DW_OP_push_object_address
:
8844 return "DW_OP_push_object_address";
8846 return "DW_OP_call2";
8848 return "DW_OP_call4";
8849 case DW_OP_call_ref
:
8850 return "DW_OP_call_ref";
8851 /* GNU extensions. */
8852 case DW_OP_form_tls_address
:
8853 return "DW_OP_form_tls_address";
8854 case DW_OP_call_frame_cfa
:
8855 return "DW_OP_call_frame_cfa";
8856 case DW_OP_bit_piece
:
8857 return "DW_OP_bit_piece";
8858 case DW_OP_GNU_push_tls_address
:
8859 return "DW_OP_GNU_push_tls_address";
8860 case DW_OP_GNU_uninit
:
8861 return "DW_OP_GNU_uninit";
8862 /* HP extensions. */
8863 case DW_OP_HP_is_value
:
8864 return "DW_OP_HP_is_value";
8865 case DW_OP_HP_fltconst4
:
8866 return "DW_OP_HP_fltconst4";
8867 case DW_OP_HP_fltconst8
:
8868 return "DW_OP_HP_fltconst8";
8869 case DW_OP_HP_mod_range
:
8870 return "DW_OP_HP_mod_range";
8871 case DW_OP_HP_unmod_range
:
8872 return "DW_OP_HP_unmod_range";
8874 return "DW_OP_HP_tls";
8876 return "OP_<unknown>";
8881 dwarf_bool_name (unsigned mybool
)
8889 /* Convert a DWARF type code into its string name. */
8892 dwarf_type_encoding_name (unsigned enc
)
8897 return "DW_ATE_void";
8898 case DW_ATE_address
:
8899 return "DW_ATE_address";
8900 case DW_ATE_boolean
:
8901 return "DW_ATE_boolean";
8902 case DW_ATE_complex_float
:
8903 return "DW_ATE_complex_float";
8905 return "DW_ATE_float";
8907 return "DW_ATE_signed";
8908 case DW_ATE_signed_char
:
8909 return "DW_ATE_signed_char";
8910 case DW_ATE_unsigned
:
8911 return "DW_ATE_unsigned";
8912 case DW_ATE_unsigned_char
:
8913 return "DW_ATE_unsigned_char";
8915 case DW_ATE_imaginary_float
:
8916 return "DW_ATE_imaginary_float";
8917 case DW_ATE_packed_decimal
:
8918 return "DW_ATE_packed_decimal";
8919 case DW_ATE_numeric_string
:
8920 return "DW_ATE_numeric_string";
8922 return "DW_ATE_edited";
8923 case DW_ATE_signed_fixed
:
8924 return "DW_ATE_signed_fixed";
8925 case DW_ATE_unsigned_fixed
:
8926 return "DW_ATE_unsigned_fixed";
8927 case DW_ATE_decimal_float
:
8928 return "DW_ATE_decimal_float";
8929 /* HP extensions. */
8930 case DW_ATE_HP_float80
:
8931 return "DW_ATE_HP_float80";
8932 case DW_ATE_HP_complex_float80
:
8933 return "DW_ATE_HP_complex_float80";
8934 case DW_ATE_HP_float128
:
8935 return "DW_ATE_HP_float128";
8936 case DW_ATE_HP_complex_float128
:
8937 return "DW_ATE_HP_complex_float128";
8938 case DW_ATE_HP_floathpintel
:
8939 return "DW_ATE_HP_floathpintel";
8940 case DW_ATE_HP_imaginary_float80
:
8941 return "DW_ATE_HP_imaginary_float80";
8942 case DW_ATE_HP_imaginary_float128
:
8943 return "DW_ATE_HP_imaginary_float128";
8945 return "DW_ATE_<unknown>";
8949 /* Convert a DWARF call frame info operation to its string name. */
8953 dwarf_cfi_name (unsigned cfi_opc
)
8957 case DW_CFA_advance_loc
:
8958 return "DW_CFA_advance_loc";
8960 return "DW_CFA_offset";
8961 case DW_CFA_restore
:
8962 return "DW_CFA_restore";
8964 return "DW_CFA_nop";
8965 case DW_CFA_set_loc
:
8966 return "DW_CFA_set_loc";
8967 case DW_CFA_advance_loc1
:
8968 return "DW_CFA_advance_loc1";
8969 case DW_CFA_advance_loc2
:
8970 return "DW_CFA_advance_loc2";
8971 case DW_CFA_advance_loc4
:
8972 return "DW_CFA_advance_loc4";
8973 case DW_CFA_offset_extended
:
8974 return "DW_CFA_offset_extended";
8975 case DW_CFA_restore_extended
:
8976 return "DW_CFA_restore_extended";
8977 case DW_CFA_undefined
:
8978 return "DW_CFA_undefined";
8979 case DW_CFA_same_value
:
8980 return "DW_CFA_same_value";
8981 case DW_CFA_register
:
8982 return "DW_CFA_register";
8983 case DW_CFA_remember_state
:
8984 return "DW_CFA_remember_state";
8985 case DW_CFA_restore_state
:
8986 return "DW_CFA_restore_state";
8987 case DW_CFA_def_cfa
:
8988 return "DW_CFA_def_cfa";
8989 case DW_CFA_def_cfa_register
:
8990 return "DW_CFA_def_cfa_register";
8991 case DW_CFA_def_cfa_offset
:
8992 return "DW_CFA_def_cfa_offset";
8994 case DW_CFA_def_cfa_expression
:
8995 return "DW_CFA_def_cfa_expression";
8996 case DW_CFA_expression
:
8997 return "DW_CFA_expression";
8998 case DW_CFA_offset_extended_sf
:
8999 return "DW_CFA_offset_extended_sf";
9000 case DW_CFA_def_cfa_sf
:
9001 return "DW_CFA_def_cfa_sf";
9002 case DW_CFA_def_cfa_offset_sf
:
9003 return "DW_CFA_def_cfa_offset_sf";
9004 case DW_CFA_val_offset
:
9005 return "DW_CFA_val_offset";
9006 case DW_CFA_val_offset_sf
:
9007 return "DW_CFA_val_offset_sf";
9008 case DW_CFA_val_expression
:
9009 return "DW_CFA_val_expression";
9010 /* SGI/MIPS specific. */
9011 case DW_CFA_MIPS_advance_loc8
:
9012 return "DW_CFA_MIPS_advance_loc8";
9013 /* GNU extensions. */
9014 case DW_CFA_GNU_window_save
:
9015 return "DW_CFA_GNU_window_save";
9016 case DW_CFA_GNU_args_size
:
9017 return "DW_CFA_GNU_args_size";
9018 case DW_CFA_GNU_negative_offset_extended
:
9019 return "DW_CFA_GNU_negative_offset_extended";
9021 return "DW_CFA_<unknown>";
9027 dump_die (struct die_info
*die
)
9031 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
9032 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
9033 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
9034 dwarf_bool_name (die
->child
!= NULL
));
9036 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
9037 for (i
= 0; i
< die
->num_attrs
; ++i
)
9039 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
9040 dwarf_attr_name (die
->attrs
[i
].name
),
9041 dwarf_form_name (die
->attrs
[i
].form
));
9042 switch (die
->attrs
[i
].form
)
9044 case DW_FORM_ref_addr
:
9046 fprintf_unfiltered (gdb_stderr
, "address: ");
9047 fputs_filtered (paddress (DW_ADDR (&die
->attrs
[i
])), gdb_stderr
);
9049 case DW_FORM_block2
:
9050 case DW_FORM_block4
:
9052 case DW_FORM_block1
:
9053 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
9058 fprintf_unfiltered (gdb_stderr
, "constant ref: %ld (adjusted)",
9059 (long) (DW_ADDR (&die
->attrs
[i
])));
9067 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
9069 case DW_FORM_string
:
9071 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
9072 DW_STRING (&die
->attrs
[i
])
9073 ? DW_STRING (&die
->attrs
[i
]) : "");
9076 if (DW_UNSND (&die
->attrs
[i
]))
9077 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
9079 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
9081 case DW_FORM_indirect
:
9082 /* the reader will have reduced the indirect form to
9083 the "base form" so this form should not occur */
9084 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
9087 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
9088 die
->attrs
[i
].form
);
9090 fprintf_unfiltered (gdb_stderr
, "\n");
9095 dump_die_list (struct die_info
*die
)
9100 if (die
->child
!= NULL
)
9101 dump_die_list (die
->child
);
9102 if (die
->sibling
!= NULL
)
9103 dump_die_list (die
->sibling
);
9108 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
9112 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
9118 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
9120 unsigned int result
= 0;
9124 case DW_FORM_ref_addr
:
9129 case DW_FORM_ref_udata
:
9130 result
= DW_ADDR (attr
);
9133 complaint (&symfile_complaints
,
9134 _("unsupported die ref attribute form: '%s'"),
9135 dwarf_form_name (attr
->form
));
9140 /* Return the constant value held by the given attribute. Return -1
9141 if the value held by the attribute is not constant. */
9144 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
9146 if (attr
->form
== DW_FORM_sdata
)
9147 return DW_SND (attr
);
9148 else if (attr
->form
== DW_FORM_udata
9149 || attr
->form
== DW_FORM_data1
9150 || attr
->form
== DW_FORM_data2
9151 || attr
->form
== DW_FORM_data4
9152 || attr
->form
== DW_FORM_data8
)
9153 return DW_UNSND (attr
);
9156 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
9157 dwarf_form_name (attr
->form
));
9158 return default_value
;
9162 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
9163 unit and add it to our queue. */
9166 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
9167 struct dwarf2_per_cu_data
*per_cu
)
9169 /* Mark the dependence relation so that we don't flush PER_CU
9171 dwarf2_add_dependence (this_cu
, per_cu
);
9173 /* If it's already on the queue, we have nothing to do. */
9177 /* If the compilation unit is already loaded, just mark it as
9179 if (per_cu
->cu
!= NULL
)
9181 per_cu
->cu
->last_used
= 0;
9185 /* Add it to the queue. */
9186 queue_comp_unit (per_cu
, this_cu
->objfile
);
9189 static struct die_info
*
9190 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
9191 struct dwarf2_cu
**ref_cu
)
9193 struct die_info
*die
;
9194 unsigned int offset
;
9195 struct die_info temp_die
;
9196 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
9198 offset
= dwarf2_get_ref_die_offset (attr
, cu
);
9200 if (DW_ADDR (attr
) < cu
->header
.offset
9201 || DW_ADDR (attr
) >= cu
->header
.offset
+ cu
->header
.length
)
9203 struct dwarf2_per_cu_data
*per_cu
;
9204 per_cu
= dwarf2_find_containing_comp_unit (DW_ADDR (attr
),
9207 /* If necessary, add it to the queue and load its DIEs. */
9208 maybe_queue_comp_unit (cu
, per_cu
);
9210 target_cu
= per_cu
->cu
;
9215 *ref_cu
= target_cu
;
9216 temp_die
.offset
= offset
;
9217 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
9221 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
9222 "at 0x%lx [in module %s]"),
9223 (long) offset
, (long) src_die
->offset
, cu
->objfile
->name
);
9226 /* Decode simple location descriptions.
9227 Given a pointer to a dwarf block that defines a location, compute
9228 the location and return the value.
9230 NOTE drow/2003-11-18: This function is called in two situations
9231 now: for the address of static or global variables (partial symbols
9232 only) and for offsets into structures which are expected to be
9233 (more or less) constant. The partial symbol case should go away,
9234 and only the constant case should remain. That will let this
9235 function complain more accurately. A few special modes are allowed
9236 without complaint for global variables (for instance, global
9237 register values and thread-local values).
9239 A location description containing no operations indicates that the
9240 object is optimized out. The return value is 0 for that case.
9241 FIXME drow/2003-11-16: No callers check for this case any more; soon all
9242 callers will only want a very basic result and this can become a
9245 Note that stack[0] is unused except as a default error return.
9246 Note that stack overflow is not yet handled. */
9249 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
9251 struct objfile
*objfile
= cu
->objfile
;
9252 struct comp_unit_head
*cu_header
= &cu
->header
;
9254 int size
= blk
->size
;
9255 gdb_byte
*data
= blk
->data
;
9256 CORE_ADDR stack
[64];
9258 unsigned int bytes_read
, unsnd
;
9302 stack
[++stacki
] = op
- DW_OP_lit0
;
9337 stack
[++stacki
] = op
- DW_OP_reg0
;
9339 dwarf2_complex_location_expr_complaint ();
9343 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9345 stack
[++stacki
] = unsnd
;
9347 dwarf2_complex_location_expr_complaint ();
9351 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
9357 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
9362 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
9367 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
9372 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
9377 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
9382 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
9387 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
9393 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
9398 stack
[stacki
+ 1] = stack
[stacki
];
9403 stack
[stacki
- 1] += stack
[stacki
];
9407 case DW_OP_plus_uconst
:
9408 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9413 stack
[stacki
- 1] -= stack
[stacki
];
9418 /* If we're not the last op, then we definitely can't encode
9419 this using GDB's address_class enum. This is valid for partial
9420 global symbols, although the variable's address will be bogus
9423 dwarf2_complex_location_expr_complaint ();
9426 case DW_OP_GNU_push_tls_address
:
9427 /* The top of the stack has the offset from the beginning
9428 of the thread control block at which the variable is located. */
9429 /* Nothing should follow this operator, so the top of stack would
9431 /* This is valid for partial global symbols, but the variable's
9432 address will be bogus in the psymtab. */
9434 dwarf2_complex_location_expr_complaint ();
9437 case DW_OP_GNU_uninit
:
9441 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
9442 dwarf_stack_op_name (op
));
9443 return (stack
[stacki
]);
9446 return (stack
[stacki
]);
9449 /* memory allocation interface */
9451 static struct dwarf_block
*
9452 dwarf_alloc_block (struct dwarf2_cu
*cu
)
9454 struct dwarf_block
*blk
;
9456 blk
= (struct dwarf_block
*)
9457 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
9461 static struct abbrev_info
*
9462 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
9464 struct abbrev_info
*abbrev
;
9466 abbrev
= (struct abbrev_info
*)
9467 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
9468 memset (abbrev
, 0, sizeof (struct abbrev_info
));
9472 static struct die_info
*
9473 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
9475 struct die_info
*die
;
9476 size_t size
= sizeof (struct die_info
);
9479 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
9481 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
9482 memset (die
, 0, sizeof (struct die_info
));
9487 /* Macro support. */
9490 /* Return the full name of file number I in *LH's file name table.
9491 Use COMP_DIR as the name of the current directory of the
9492 compilation. The result is allocated using xmalloc; the caller is
9493 responsible for freeing it. */
9495 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
9497 /* Is the file number a valid index into the line header's file name
9498 table? Remember that file numbers start with one, not zero. */
9499 if (1 <= file
&& file
<= lh
->num_file_names
)
9501 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9503 if (IS_ABSOLUTE_PATH (fe
->name
))
9504 return xstrdup (fe
->name
);
9512 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9518 dir_len
= strlen (dir
);
9519 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
9520 strcpy (full_name
, dir
);
9521 full_name
[dir_len
] = '/';
9522 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
9526 return xstrdup (fe
->name
);
9531 /* The compiler produced a bogus file number. We can at least
9532 record the macro definitions made in the file, even if we
9533 won't be able to find the file by name. */
9535 sprintf (fake_name
, "<bad macro file number %d>", file
);
9537 complaint (&symfile_complaints
,
9538 _("bad file number in macro information (%d)"),
9541 return xstrdup (fake_name
);
9546 static struct macro_source_file
*
9547 macro_start_file (int file
, int line
,
9548 struct macro_source_file
*current_file
,
9549 const char *comp_dir
,
9550 struct line_header
*lh
, struct objfile
*objfile
)
9552 /* The full name of this source file. */
9553 char *full_name
= file_full_name (file
, lh
, comp_dir
);
9555 /* We don't create a macro table for this compilation unit
9556 at all until we actually get a filename. */
9557 if (! pending_macros
)
9558 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
9559 objfile
->macro_cache
);
9562 /* If we have no current file, then this must be the start_file
9563 directive for the compilation unit's main source file. */
9564 current_file
= macro_set_main (pending_macros
, full_name
);
9566 current_file
= macro_include (current_file
, line
, full_name
);
9570 return current_file
;
9574 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
9575 followed by a null byte. */
9577 copy_string (const char *buf
, int len
)
9579 char *s
= xmalloc (len
+ 1);
9580 memcpy (s
, buf
, len
);
9588 consume_improper_spaces (const char *p
, const char *body
)
9592 complaint (&symfile_complaints
,
9593 _("macro definition contains spaces in formal argument list:\n`%s'"),
9605 parse_macro_definition (struct macro_source_file
*file
, int line
,
9610 /* The body string takes one of two forms. For object-like macro
9611 definitions, it should be:
9613 <macro name> " " <definition>
9615 For function-like macro definitions, it should be:
9617 <macro name> "() " <definition>
9619 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
9621 Spaces may appear only where explicitly indicated, and in the
9624 The Dwarf 2 spec says that an object-like macro's name is always
9625 followed by a space, but versions of GCC around March 2002 omit
9626 the space when the macro's definition is the empty string.
9628 The Dwarf 2 spec says that there should be no spaces between the
9629 formal arguments in a function-like macro's formal argument list,
9630 but versions of GCC around March 2002 include spaces after the
9634 /* Find the extent of the macro name. The macro name is terminated
9635 by either a space or null character (for an object-like macro) or
9636 an opening paren (for a function-like macro). */
9637 for (p
= body
; *p
; p
++)
9638 if (*p
== ' ' || *p
== '(')
9641 if (*p
== ' ' || *p
== '\0')
9643 /* It's an object-like macro. */
9644 int name_len
= p
- body
;
9645 char *name
= copy_string (body
, name_len
);
9646 const char *replacement
;
9649 replacement
= body
+ name_len
+ 1;
9652 dwarf2_macro_malformed_definition_complaint (body
);
9653 replacement
= body
+ name_len
;
9656 macro_define_object (file
, line
, name
, replacement
);
9662 /* It's a function-like macro. */
9663 char *name
= copy_string (body
, p
- body
);
9666 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
9670 p
= consume_improper_spaces (p
, body
);
9672 /* Parse the formal argument list. */
9673 while (*p
&& *p
!= ')')
9675 /* Find the extent of the current argument name. */
9676 const char *arg_start
= p
;
9678 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
9681 if (! *p
|| p
== arg_start
)
9682 dwarf2_macro_malformed_definition_complaint (body
);
9685 /* Make sure argv has room for the new argument. */
9686 if (argc
>= argv_size
)
9689 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
9692 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
9695 p
= consume_improper_spaces (p
, body
);
9697 /* Consume the comma, if present. */
9702 p
= consume_improper_spaces (p
, body
);
9711 /* Perfectly formed definition, no complaints. */
9712 macro_define_function (file
, line
, name
,
9713 argc
, (const char **) argv
,
9715 else if (*p
== '\0')
9717 /* Complain, but do define it. */
9718 dwarf2_macro_malformed_definition_complaint (body
);
9719 macro_define_function (file
, line
, name
,
9720 argc
, (const char **) argv
,
9724 /* Just complain. */
9725 dwarf2_macro_malformed_definition_complaint (body
);
9728 /* Just complain. */
9729 dwarf2_macro_malformed_definition_complaint (body
);
9735 for (i
= 0; i
< argc
; i
++)
9741 dwarf2_macro_malformed_definition_complaint (body
);
9746 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
9747 char *comp_dir
, bfd
*abfd
,
9748 struct dwarf2_cu
*cu
)
9750 gdb_byte
*mac_ptr
, *mac_end
;
9751 struct macro_source_file
*current_file
= 0;
9753 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
9755 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
9759 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
9760 mac_end
= dwarf2_per_objfile
->macinfo_buffer
9761 + dwarf2_per_objfile
->macinfo_size
;
9765 enum dwarf_macinfo_record_type macinfo_type
;
9767 /* Do we at least have room for a macinfo type byte? */
9768 if (mac_ptr
>= mac_end
)
9770 dwarf2_macros_too_long_complaint ();
9774 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
9777 switch (macinfo_type
)
9779 /* A zero macinfo type indicates the end of the macro
9784 case DW_MACINFO_define
:
9785 case DW_MACINFO_undef
:
9787 unsigned int bytes_read
;
9791 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9792 mac_ptr
+= bytes_read
;
9793 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
9794 mac_ptr
+= bytes_read
;
9797 complaint (&symfile_complaints
,
9798 _("debug info gives macro %s outside of any file: %s"),
9800 DW_MACINFO_define
? "definition" : macinfo_type
==
9801 DW_MACINFO_undef
? "undefinition" :
9802 "something-or-other", body
);
9805 if (macinfo_type
== DW_MACINFO_define
)
9806 parse_macro_definition (current_file
, line
, body
);
9807 else if (macinfo_type
== DW_MACINFO_undef
)
9808 macro_undef (current_file
, line
, body
);
9813 case DW_MACINFO_start_file
:
9815 unsigned int bytes_read
;
9818 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9819 mac_ptr
+= bytes_read
;
9820 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9821 mac_ptr
+= bytes_read
;
9823 current_file
= macro_start_file (file
, line
,
9824 current_file
, comp_dir
,
9829 case DW_MACINFO_end_file
:
9831 complaint (&symfile_complaints
,
9832 _("macro debug info has an unmatched `close_file' directive"));
9835 current_file
= current_file
->included_by
;
9838 enum dwarf_macinfo_record_type next_type
;
9840 /* GCC circa March 2002 doesn't produce the zero
9841 type byte marking the end of the compilation
9842 unit. Complain if it's not there, but exit no
9845 /* Do we at least have room for a macinfo type byte? */
9846 if (mac_ptr
>= mac_end
)
9848 dwarf2_macros_too_long_complaint ();
9852 /* We don't increment mac_ptr here, so this is just
9854 next_type
= read_1_byte (abfd
, mac_ptr
);
9856 complaint (&symfile_complaints
,
9857 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
9864 case DW_MACINFO_vendor_ext
:
9866 unsigned int bytes_read
;
9870 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9871 mac_ptr
+= bytes_read
;
9872 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
9873 mac_ptr
+= bytes_read
;
9875 /* We don't recognize any vendor extensions. */
9882 /* Check if the attribute's form is a DW_FORM_block*
9883 if so return true else false. */
9885 attr_form_is_block (struct attribute
*attr
)
9887 return (attr
== NULL
? 0 :
9888 attr
->form
== DW_FORM_block1
9889 || attr
->form
== DW_FORM_block2
9890 || attr
->form
== DW_FORM_block4
9891 || attr
->form
== DW_FORM_block
);
9894 /* Return non-zero if ATTR's value is a section offset --- classes
9895 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
9896 You may use DW_UNSND (attr) to retrieve such offsets.
9898 Section 7.5.4, "Attribute Encodings", explains that no attribute
9899 may have a value that belongs to more than one of these classes; it
9900 would be ambiguous if we did, because we use the same forms for all
9903 attr_form_is_section_offset (struct attribute
*attr
)
9905 return (attr
->form
== DW_FORM_data4
9906 || attr
->form
== DW_FORM_data8
);
9910 /* Return non-zero if ATTR's value falls in the 'constant' class, or
9911 zero otherwise. When this function returns true, you can apply
9912 dwarf2_get_attr_constant_value to it.
9914 However, note that for some attributes you must check
9915 attr_form_is_section_offset before using this test. DW_FORM_data4
9916 and DW_FORM_data8 are members of both the constant class, and of
9917 the classes that contain offsets into other debug sections
9918 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
9919 that, if an attribute's can be either a constant or one of the
9920 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
9921 taken as section offsets, not constants. */
9923 attr_form_is_constant (struct attribute
*attr
)
9940 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
9941 struct dwarf2_cu
*cu
)
9943 if (attr_form_is_section_offset (attr
)
9944 /* ".debug_loc" may not exist at all, or the offset may be outside
9945 the section. If so, fall through to the complaint in the
9947 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc_size
)
9949 struct dwarf2_loclist_baton
*baton
;
9951 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9952 sizeof (struct dwarf2_loclist_baton
));
9953 baton
->per_cu
= cu
->per_cu
;
9954 gdb_assert (baton
->per_cu
);
9956 /* We don't know how long the location list is, but make sure we
9957 don't run off the edge of the section. */
9958 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
9959 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
9960 baton
->base_address
= cu
->base_address
;
9961 if (cu
->base_known
== 0)
9962 complaint (&symfile_complaints
,
9963 _("Location list used without specifying the CU base address."));
9965 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
9966 SYMBOL_LOCATION_BATON (sym
) = baton
;
9970 struct dwarf2_locexpr_baton
*baton
;
9972 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9973 sizeof (struct dwarf2_locexpr_baton
));
9974 baton
->per_cu
= cu
->per_cu
;
9975 gdb_assert (baton
->per_cu
);
9977 if (attr_form_is_block (attr
))
9979 /* Note that we're just copying the block's data pointer
9980 here, not the actual data. We're still pointing into the
9981 info_buffer for SYM's objfile; right now we never release
9982 that buffer, but when we do clean up properly this may
9984 baton
->size
= DW_BLOCK (attr
)->size
;
9985 baton
->data
= DW_BLOCK (attr
)->data
;
9989 dwarf2_invalid_attrib_class_complaint ("location description",
9990 SYMBOL_NATURAL_NAME (sym
));
9995 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
9996 SYMBOL_LOCATION_BATON (sym
) = baton
;
10000 /* Return the OBJFILE associated with the compilation unit CU. */
10003 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
10005 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10007 /* Return the master objfile, so that we can report and look up the
10008 correct file containing this variable. */
10009 if (objfile
->separate_debug_objfile_backlink
)
10010 objfile
= objfile
->separate_debug_objfile_backlink
;
10015 /* Return the address size given in the compilation unit header for CU. */
10018 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
10021 return per_cu
->cu
->header
.addr_size
;
10024 /* If the CU is not currently read in, we re-read its header. */
10025 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10026 struct dwarf2_per_objfile
*per_objfile
10027 = objfile_data (objfile
, dwarf2_objfile_data_key
);
10028 gdb_byte
*info_ptr
= per_objfile
->info_buffer
+ per_cu
->offset
;
10030 struct comp_unit_head cu_header
;
10031 memset (&cu_header
, 0, sizeof cu_header
);
10032 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
10033 return cu_header
.addr_size
;
10037 /* Locate the compilation unit from CU's objfile which contains the
10038 DIE at OFFSET. Raises an error on failure. */
10040 static struct dwarf2_per_cu_data
*
10041 dwarf2_find_containing_comp_unit (unsigned long offset
,
10042 struct objfile
*objfile
)
10044 struct dwarf2_per_cu_data
*this_cu
;
10048 high
= dwarf2_per_objfile
->n_comp_units
- 1;
10051 int mid
= low
+ (high
- low
) / 2;
10052 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
10057 gdb_assert (low
== high
);
10058 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
10061 error (_("Dwarf Error: could not find partial DIE containing "
10062 "offset 0x%lx [in module %s]"),
10063 (long) offset
, bfd_get_filename (objfile
->obfd
));
10065 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
10066 return dwarf2_per_objfile
->all_comp_units
[low
-1];
10070 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
10071 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
10072 && offset
>= this_cu
->offset
+ this_cu
->length
)
10073 error (_("invalid dwarf2 offset %ld"), offset
);
10074 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
10079 /* Locate the compilation unit from OBJFILE which is located at exactly
10080 OFFSET. Raises an error on failure. */
10082 static struct dwarf2_per_cu_data
*
10083 dwarf2_find_comp_unit (unsigned long offset
, struct objfile
*objfile
)
10085 struct dwarf2_per_cu_data
*this_cu
;
10086 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10087 if (this_cu
->offset
!= offset
)
10088 error (_("no compilation unit with offset %ld."), offset
);
10092 /* Release one cached compilation unit, CU. We unlink it from the tree
10093 of compilation units, but we don't remove it from the read_in_chain;
10094 the caller is responsible for that. */
10097 free_one_comp_unit (void *data
)
10099 struct dwarf2_cu
*cu
= data
;
10101 if (cu
->per_cu
!= NULL
)
10102 cu
->per_cu
->cu
= NULL
;
10105 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10110 /* This cleanup function is passed the address of a dwarf2_cu on the stack
10111 when we're finished with it. We can't free the pointer itself, but be
10112 sure to unlink it from the cache. Also release any associated storage
10113 and perform cache maintenance.
10115 Only used during partial symbol parsing. */
10118 free_stack_comp_unit (void *data
)
10120 struct dwarf2_cu
*cu
= data
;
10122 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10123 cu
->partial_dies
= NULL
;
10125 if (cu
->per_cu
!= NULL
)
10127 /* This compilation unit is on the stack in our caller, so we
10128 should not xfree it. Just unlink it. */
10129 cu
->per_cu
->cu
= NULL
;
10132 /* If we had a per-cu pointer, then we may have other compilation
10133 units loaded, so age them now. */
10134 age_cached_comp_units ();
10138 /* Free all cached compilation units. */
10141 free_cached_comp_units (void *data
)
10143 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10145 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10146 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10147 while (per_cu
!= NULL
)
10149 struct dwarf2_per_cu_data
*next_cu
;
10151 next_cu
= per_cu
->cu
->read_in_chain
;
10153 free_one_comp_unit (per_cu
->cu
);
10154 *last_chain
= next_cu
;
10160 /* Increase the age counter on each cached compilation unit, and free
10161 any that are too old. */
10164 age_cached_comp_units (void)
10166 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10168 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
10169 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10170 while (per_cu
!= NULL
)
10172 per_cu
->cu
->last_used
++;
10173 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
10174 dwarf2_mark (per_cu
->cu
);
10175 per_cu
= per_cu
->cu
->read_in_chain
;
10178 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10179 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10180 while (per_cu
!= NULL
)
10182 struct dwarf2_per_cu_data
*next_cu
;
10184 next_cu
= per_cu
->cu
->read_in_chain
;
10186 if (!per_cu
->cu
->mark
)
10188 free_one_comp_unit (per_cu
->cu
);
10189 *last_chain
= next_cu
;
10192 last_chain
= &per_cu
->cu
->read_in_chain
;
10198 /* Remove a single compilation unit from the cache. */
10201 free_one_cached_comp_unit (void *target_cu
)
10203 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10205 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10206 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10207 while (per_cu
!= NULL
)
10209 struct dwarf2_per_cu_data
*next_cu
;
10211 next_cu
= per_cu
->cu
->read_in_chain
;
10213 if (per_cu
->cu
== target_cu
)
10215 free_one_comp_unit (per_cu
->cu
);
10216 *last_chain
= next_cu
;
10220 last_chain
= &per_cu
->cu
->read_in_chain
;
10226 /* Release all extra memory associated with OBJFILE. */
10229 dwarf2_free_objfile (struct objfile
*objfile
)
10231 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
10233 if (dwarf2_per_objfile
== NULL
)
10236 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
10237 free_cached_comp_units (NULL
);
10239 /* Everything else should be on the objfile obstack. */
10242 /* A pair of DIE offset and GDB type pointer. We store these
10243 in a hash table separate from the DIEs, and preserve them
10244 when the DIEs are flushed out of cache. */
10246 struct dwarf2_offset_and_type
10248 unsigned int offset
;
10252 /* Hash function for a dwarf2_offset_and_type. */
10255 offset_and_type_hash (const void *item
)
10257 const struct dwarf2_offset_and_type
*ofs
= item
;
10258 return ofs
->offset
;
10261 /* Equality function for a dwarf2_offset_and_type. */
10264 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
10266 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
10267 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
10268 return ofs_lhs
->offset
== ofs_rhs
->offset
;
10271 /* Set the type associated with DIE to TYPE. Save it in CU's hash
10272 table if necessary. For convenience, return TYPE. */
10274 static struct type
*
10275 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10277 struct dwarf2_offset_and_type
**slot
, ofs
;
10279 if (cu
->type_hash
== NULL
)
10281 gdb_assert (cu
->per_cu
!= NULL
);
10282 cu
->per_cu
->type_hash
10283 = htab_create_alloc_ex (cu
->header
.length
/ 24,
10284 offset_and_type_hash
,
10285 offset_and_type_eq
,
10287 &cu
->objfile
->objfile_obstack
,
10288 hashtab_obstack_allocate
,
10289 dummy_obstack_deallocate
);
10290 cu
->type_hash
= cu
->per_cu
->type_hash
;
10293 ofs
.offset
= die
->offset
;
10295 slot
= (struct dwarf2_offset_and_type
**)
10296 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
10297 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
10302 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
10303 not have a saved type. */
10305 static struct type
*
10306 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10308 struct dwarf2_offset_and_type
*slot
, ofs
;
10309 htab_t type_hash
= cu
->type_hash
;
10311 if (type_hash
== NULL
)
10314 ofs
.offset
= die
->offset
;
10315 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
10322 /* Set the mark field in CU and in every other compilation unit in the
10323 cache that we must keep because we are keeping CU. */
10325 /* Add a dependence relationship from CU to REF_PER_CU. */
10328 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
10329 struct dwarf2_per_cu_data
*ref_per_cu
)
10333 if (cu
->dependencies
== NULL
)
10335 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
10336 NULL
, &cu
->comp_unit_obstack
,
10337 hashtab_obstack_allocate
,
10338 dummy_obstack_deallocate
);
10340 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
10342 *slot
= ref_per_cu
;
10345 /* Set the mark field in CU and in every other compilation unit in the
10346 cache that we must keep because we are keeping CU. */
10349 dwarf2_mark_helper (void **slot
, void *data
)
10351 struct dwarf2_per_cu_data
*per_cu
;
10353 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
10354 if (per_cu
->cu
->mark
)
10356 per_cu
->cu
->mark
= 1;
10358 if (per_cu
->cu
->dependencies
!= NULL
)
10359 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10365 dwarf2_mark (struct dwarf2_cu
*cu
)
10370 if (cu
->dependencies
!= NULL
)
10371 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10375 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
10379 per_cu
->cu
->mark
= 0;
10380 per_cu
= per_cu
->cu
->read_in_chain
;
10384 /* Trivial hash function for partial_die_info: the hash value of a DIE
10385 is its offset in .debug_info for this objfile. */
10388 partial_die_hash (const void *item
)
10390 const struct partial_die_info
*part_die
= item
;
10391 return part_die
->offset
;
10394 /* Trivial comparison function for partial_die_info structures: two DIEs
10395 are equal if they have the same offset. */
10398 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
10400 const struct partial_die_info
*part_die_lhs
= item_lhs
;
10401 const struct partial_die_info
*part_die_rhs
= item_rhs
;
10402 return part_die_lhs
->offset
== part_die_rhs
->offset
;
10405 static struct cmd_list_element
*set_dwarf2_cmdlist
;
10406 static struct cmd_list_element
*show_dwarf2_cmdlist
;
10409 set_dwarf2_cmd (char *args
, int from_tty
)
10411 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
10415 show_dwarf2_cmd (char *args
, int from_tty
)
10417 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
10420 void _initialize_dwarf2_read (void);
10423 _initialize_dwarf2_read (void)
10425 dwarf2_objfile_data_key
= register_objfile_data ();
10427 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
10428 Set DWARF 2 specific variables.\n\
10429 Configure DWARF 2 variables such as the cache size"),
10430 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
10431 0/*allow-unknown*/, &maintenance_set_cmdlist
);
10433 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
10434 Show DWARF 2 specific variables\n\
10435 Show DWARF 2 variables such as the cache size"),
10436 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
10437 0/*allow-unknown*/, &maintenance_show_cmdlist
);
10439 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
10440 &dwarf2_max_cache_age
, _("\
10441 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
10442 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
10443 A higher limit means that cached compilation units will be stored\n\
10444 in memory longer, and more total memory will be used. Zero disables\n\
10445 caching, which can slow down startup."),
10447 show_dwarf2_max_cache_age
,
10448 &set_dwarf2_cmdlist
,
10449 &show_dwarf2_cmdlist
);