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, 2009
5 Free Software Foundation, Inc.
7 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
8 Inc. with support from Florida State University (under contract
9 with the Ada Joint Program Office), and Silicon Graphics, Inc.
10 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
11 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
14 This file is part of GDB.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>. */
34 #include "elf/dwarf2.h"
37 #include "expression.h"
38 #include "filenames.h" /* for DOSish file names */
41 #include "complaints.h"
43 #include "dwarf2expr.h"
44 #include "dwarf2loc.h"
45 #include "cp-support.h"
52 #include "gdb_string.h"
53 #include "gdb_assert.h"
54 #include <sys/types.h>
63 /* .debug_info header for a compilation unit
64 Because of alignment constraints, this structure has padding and cannot
65 be mapped directly onto the beginning of the .debug_info section. */
66 typedef struct comp_unit_header
68 unsigned int length
; /* length of the .debug_info
70 unsigned short version
; /* version number -- 2 for DWARF
72 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
73 unsigned char addr_size
; /* byte size of an address -- 4 */
76 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
79 /* .debug_pubnames header
80 Because of alignment constraints, this structure has padding and cannot
81 be mapped directly onto the beginning of the .debug_info section. */
82 typedef struct pubnames_header
84 unsigned int length
; /* length of the .debug_pubnames
86 unsigned char version
; /* version number -- 2 for DWARF
88 unsigned int info_offset
; /* offset into .debug_info section */
89 unsigned int info_size
; /* byte size of .debug_info section
93 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
95 /* .debug_pubnames header
96 Because of alignment constraints, this structure has padding and cannot
97 be mapped directly onto the beginning of the .debug_info section. */
98 typedef struct aranges_header
100 unsigned int length
; /* byte len of the .debug_aranges
102 unsigned short version
; /* version number -- 2 for DWARF
104 unsigned int info_offset
; /* offset into .debug_info section */
105 unsigned char addr_size
; /* byte size of an address */
106 unsigned char seg_size
; /* byte size of segment descriptor */
109 #define _ACTUAL_ARANGES_HEADER_SIZE 12
111 /* .debug_line statement program prologue
112 Because of alignment constraints, this structure has padding and cannot
113 be mapped directly onto the beginning of the .debug_info section. */
114 typedef struct statement_prologue
116 unsigned int total_length
; /* byte length of the statement
118 unsigned short version
; /* version number -- 2 for DWARF
120 unsigned int prologue_length
; /* # bytes between prologue &
122 unsigned char minimum_instruction_length
; /* byte size of
124 unsigned char default_is_stmt
; /* initial value of is_stmt
127 unsigned char line_range
;
128 unsigned char opcode_base
; /* number assigned to first special
130 unsigned char *standard_opcode_lengths
;
134 /* When non-zero, dump DIEs after they are read in. */
135 static int dwarf2_die_debug
= 0;
139 /* When set, the file that we're processing is known to have debugging
140 info for C++ namespaces. GCC 3.3.x did not produce this information,
141 but later versions do. */
143 static int processing_has_namespace_info
;
145 static const struct objfile_data
*dwarf2_objfile_data_key
;
147 struct dwarf2_section_info
155 struct dwarf2_per_objfile
157 struct dwarf2_section_info info
;
158 struct dwarf2_section_info abbrev
;
159 struct dwarf2_section_info line
;
160 struct dwarf2_section_info pubnames
;
161 struct dwarf2_section_info aranges
;
162 struct dwarf2_section_info loc
;
163 struct dwarf2_section_info macinfo
;
164 struct dwarf2_section_info str
;
165 struct dwarf2_section_info ranges
;
166 struct dwarf2_section_info frame
;
167 struct dwarf2_section_info eh_frame
;
169 /* A list of all the compilation units. This is used to locate
170 the target compilation unit of a particular reference. */
171 struct dwarf2_per_cu_data
**all_comp_units
;
173 /* The number of compilation units in ALL_COMP_UNITS. */
176 /* A chain of compilation units that are currently read in, so that
177 they can be freed later. */
178 struct dwarf2_per_cu_data
*read_in_chain
;
180 /* A flag indicating wether this objfile has a section loaded at a
182 int has_section_at_zero
;
185 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
187 /* names of the debugging sections */
189 /* Note that if the debugging section has been compressed, it might
190 have a name like .zdebug_info. */
192 #define INFO_SECTION "debug_info"
193 #define ABBREV_SECTION "debug_abbrev"
194 #define LINE_SECTION "debug_line"
195 #define PUBNAMES_SECTION "debug_pubnames"
196 #define ARANGES_SECTION "debug_aranges"
197 #define LOC_SECTION "debug_loc"
198 #define MACINFO_SECTION "debug_macinfo"
199 #define STR_SECTION "debug_str"
200 #define RANGES_SECTION "debug_ranges"
201 #define FRAME_SECTION "debug_frame"
202 #define EH_FRAME_SECTION "eh_frame"
204 /* local data types */
206 /* We hold several abbreviation tables in memory at the same time. */
207 #ifndef ABBREV_HASH_SIZE
208 #define ABBREV_HASH_SIZE 121
211 /* The data in a compilation unit header, after target2host
212 translation, looks like this. */
213 struct comp_unit_head
217 unsigned char addr_size
;
218 unsigned char signed_addr_p
;
219 unsigned int abbrev_offset
;
221 /* Size of file offsets; either 4 or 8. */
222 unsigned int offset_size
;
224 /* Size of the length field; either 4 or 12. */
225 unsigned int initial_length_size
;
227 /* Offset to the first byte of this compilation unit header in the
228 .debug_info section, for resolving relative reference dies. */
231 /* Offset to first die in this cu from the start of the cu.
232 This will be the first byte following the compilation unit header. */
233 unsigned int first_die_offset
;
236 /* Internal state when decoding a particular compilation unit. */
239 /* The objfile containing this compilation unit. */
240 struct objfile
*objfile
;
242 /* The header of the compilation unit. */
243 struct comp_unit_head header
;
245 /* Base address of this compilation unit. */
246 CORE_ADDR base_address
;
248 /* Non-zero if base_address has been set. */
251 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
253 /* The language we are debugging. */
254 enum language language
;
255 const struct language_defn
*language_defn
;
257 const char *producer
;
259 /* The generic symbol table building routines have separate lists for
260 file scope symbols and all all other scopes (local scopes). So
261 we need to select the right one to pass to add_symbol_to_list().
262 We do it by keeping a pointer to the correct list in list_in_scope.
264 FIXME: The original dwarf code just treated the file scope as the
265 first local scope, and all other local scopes as nested local
266 scopes, and worked fine. Check to see if we really need to
267 distinguish these in buildsym.c. */
268 struct pending
**list_in_scope
;
270 /* DWARF abbreviation table associated with this compilation unit. */
271 struct abbrev_info
**dwarf2_abbrevs
;
273 /* Storage for the abbrev table. */
274 struct obstack abbrev_obstack
;
276 /* Hash table holding all the loaded partial DIEs. */
279 /* `.debug_ranges' offset for this `DW_TAG_compile_unit' DIE. */
280 unsigned int ranges_offset
;
282 /* Storage for things with the same lifetime as this read-in compilation
283 unit, including partial DIEs. */
284 struct obstack comp_unit_obstack
;
286 /* When multiple dwarf2_cu structures are living in memory, this field
287 chains them all together, so that they can be released efficiently.
288 We will probably also want a generation counter so that most-recently-used
289 compilation units are cached... */
290 struct dwarf2_per_cu_data
*read_in_chain
;
292 /* Backchain to our per_cu entry if the tree has been built. */
293 struct dwarf2_per_cu_data
*per_cu
;
295 /* Pointer to the die -> type map. Although it is stored
296 permanently in per_cu, we copy it here to avoid double
300 /* How many compilation units ago was this CU last referenced? */
303 /* A hash table of die offsets for following references. */
306 /* Full DIEs if read in. */
307 struct die_info
*dies
;
309 /* A set of pointers to dwarf2_per_cu_data objects for compilation
310 units referenced by this one. Only set during full symbol processing;
311 partial symbol tables do not have dependencies. */
314 /* Header data from the line table, during full symbol processing. */
315 struct line_header
*line_header
;
317 /* Mark used when releasing cached dies. */
318 unsigned int mark
: 1;
320 /* This flag will be set if this compilation unit might include
321 inter-compilation-unit references. */
322 unsigned int has_form_ref_addr
: 1;
324 /* This flag will be set if this compilation unit includes any
325 DW_TAG_namespace DIEs. If we know that there are explicit
326 DIEs for namespaces, we don't need to try to infer them
327 from mangled names. */
328 unsigned int has_namespace_info
: 1;
330 /* Field `ranges_offset' is filled in; flag as the value may be zero. */
331 unsigned int has_ranges_offset
: 1;
334 /* Persistent data held for a compilation unit, even when not
335 processing it. We put a pointer to this structure in the
336 read_symtab_private field of the psymtab. If we encounter
337 inter-compilation-unit references, we also maintain a sorted
338 list of all compilation units. */
340 struct dwarf2_per_cu_data
342 /* The start offset and length of this compilation unit. 2**30-1
343 bytes should suffice to store the length of any compilation unit
344 - if it doesn't, GDB will fall over anyway.
345 NOTE: Unlike comp_unit_head.length, this length includes
346 initial_length_size. */
348 unsigned int length
: 30;
350 /* Flag indicating this compilation unit will be read in before
351 any of the current compilation units are processed. */
352 unsigned int queued
: 1;
354 /* This flag will be set if we need to load absolutely all DIEs
355 for this compilation unit, instead of just the ones we think
356 are interesting. It gets set if we look for a DIE in the
357 hash table and don't find it. */
358 unsigned int load_all_dies
: 1;
360 /* Set iff currently read in. */
361 struct dwarf2_cu
*cu
;
363 /* If full symbols for this CU have been read in, then this field
364 holds a map of DIE offsets to types. It isn't always possible
365 to reconstruct this information later, so we have to preserve
369 /* The partial symbol table associated with this compilation unit,
370 or NULL for partial units (which do not have an associated
372 struct partial_symtab
*psymtab
;
375 /* The line number information for a compilation unit (found in the
376 .debug_line section) begins with a "statement program header",
377 which contains the following information. */
380 unsigned int total_length
;
381 unsigned short version
;
382 unsigned int header_length
;
383 unsigned char minimum_instruction_length
;
384 unsigned char default_is_stmt
;
386 unsigned char line_range
;
387 unsigned char opcode_base
;
389 /* standard_opcode_lengths[i] is the number of operands for the
390 standard opcode whose value is i. This means that
391 standard_opcode_lengths[0] is unused, and the last meaningful
392 element is standard_opcode_lengths[opcode_base - 1]. */
393 unsigned char *standard_opcode_lengths
;
395 /* The include_directories table. NOTE! These strings are not
396 allocated with xmalloc; instead, they are pointers into
397 debug_line_buffer. If you try to free them, `free' will get
399 unsigned int num_include_dirs
, include_dirs_size
;
402 /* The file_names table. NOTE! These strings are not allocated
403 with xmalloc; instead, they are pointers into debug_line_buffer.
404 Don't try to free them directly. */
405 unsigned int num_file_names
, file_names_size
;
409 unsigned int dir_index
;
410 unsigned int mod_time
;
412 int included_p
; /* Non-zero if referenced by the Line Number Program. */
413 struct symtab
*symtab
; /* The associated symbol table, if any. */
416 /* The start and end of the statement program following this
417 header. These point into dwarf2_per_objfile->line_buffer. */
418 gdb_byte
*statement_program_start
, *statement_program_end
;
421 /* When we construct a partial symbol table entry we only
422 need this much information. */
423 struct partial_die_info
425 /* Offset of this DIE. */
428 /* DWARF-2 tag for this DIE. */
429 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
431 /* Language code associated with this DIE. This is only used
432 for the compilation unit DIE. */
433 unsigned int language
: 8;
435 /* Assorted flags describing the data found in this DIE. */
436 unsigned int has_children
: 1;
437 unsigned int is_external
: 1;
438 unsigned int is_declaration
: 1;
439 unsigned int has_type
: 1;
440 unsigned int has_specification
: 1;
441 unsigned int has_stmt_list
: 1;
442 unsigned int has_pc_info
: 1;
444 /* Flag set if the SCOPE field of this structure has been
446 unsigned int scope_set
: 1;
448 /* Flag set if the DIE has a byte_size attribute. */
449 unsigned int has_byte_size
: 1;
451 /* The name of this DIE. Normally the value of DW_AT_name, but
452 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
457 /* The scope to prepend to our children. This is generally
458 allocated on the comp_unit_obstack, so will disappear
459 when this compilation unit leaves the cache. */
462 /* The location description associated with this DIE, if any. */
463 struct dwarf_block
*locdesc
;
465 /* If HAS_PC_INFO, the PC range associated with this DIE. */
469 /* Pointer into the info_buffer pointing at the target of
470 DW_AT_sibling, if any. */
473 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
474 DW_AT_specification (or DW_AT_abstract_origin or
476 unsigned int spec_offset
;
478 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
479 unsigned int line_offset
;
481 /* Pointers to this DIE's parent, first child, and next sibling,
483 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
486 /* This data structure holds the information of an abbrev. */
489 unsigned int number
; /* number identifying abbrev */
490 enum dwarf_tag tag
; /* dwarf tag */
491 unsigned short has_children
; /* boolean */
492 unsigned short num_attrs
; /* number of attributes */
493 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
494 struct abbrev_info
*next
; /* next in chain */
499 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
500 ENUM_BITFIELD(dwarf_form
) form
: 16;
503 /* Additional GDB-specific attribute forms. */
506 /* A string which has been updated to GDB's internal
507 representation (e.g. converted to canonical form) and does not
508 need to be updated again. */
509 GDB_FORM_cached_string
= 0xff
512 /* Attributes have a name and a value */
515 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
516 ENUM_BITFIELD(dwarf_form
) form
: 16;
520 struct dwarf_block
*blk
;
528 /* This data structure holds a complete die structure. */
531 /* DWARF-2 tag for this DIE. */
532 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
534 /* Number of attributes */
535 unsigned short num_attrs
;
540 /* Offset in .debug_info section */
543 /* The dies in a compilation unit form an n-ary tree. PARENT
544 points to this die's parent; CHILD points to the first child of
545 this node; and all the children of a given node are chained
546 together via their SIBLING fields, terminated by a die whose
548 struct die_info
*child
; /* Its first child, if any. */
549 struct die_info
*sibling
; /* Its next sibling, if any. */
550 struct die_info
*parent
; /* Its parent, if any. */
552 /* An array of attributes, with NUM_ATTRS elements. There may be
553 zero, but it's not common and zero-sized arrays are not
554 sufficiently portable C. */
555 struct attribute attrs
[1];
558 struct function_range
561 CORE_ADDR lowpc
, highpc
;
563 struct function_range
*next
;
566 /* Get at parts of an attribute structure */
568 #define DW_STRING(attr) ((attr)->u.str)
569 #define DW_UNSND(attr) ((attr)->u.unsnd)
570 #define DW_BLOCK(attr) ((attr)->u.blk)
571 #define DW_SND(attr) ((attr)->u.snd)
572 #define DW_ADDR(attr) ((attr)->u.addr)
574 /* Blocks are a bunch of untyped bytes. */
581 #ifndef ATTR_ALLOC_CHUNK
582 #define ATTR_ALLOC_CHUNK 4
585 /* Allocate fields for structs, unions and enums in this size. */
586 #ifndef DW_FIELD_ALLOC_CHUNK
587 #define DW_FIELD_ALLOC_CHUNK 4
590 /* A zeroed version of a partial die for initialization purposes. */
591 static struct partial_die_info zeroed_partial_die
;
593 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
594 but this would require a corresponding change in unpack_field_as_long
596 static int bits_per_byte
= 8;
598 /* The routines that read and process dies for a C struct or C++ class
599 pass lists of data member fields and lists of member function fields
600 in an instance of a field_info structure, as defined below. */
603 /* List of data member and baseclasses fields. */
606 struct nextfield
*next
;
613 /* Number of fields. */
616 /* Number of baseclasses. */
619 /* Set if the accesibility of one of the fields is not public. */
620 int non_public_fields
;
622 /* Member function fields array, entries are allocated in the order they
623 are encountered in the object file. */
626 struct nextfnfield
*next
;
627 struct fn_field fnfield
;
631 /* Member function fieldlist array, contains name of possibly overloaded
632 member function, number of overloaded member functions and a pointer
633 to the head of the member function field chain. */
638 struct nextfnfield
*head
;
642 /* Number of entries in the fnfieldlists array. */
646 /* One item on the queue of compilation units to read in full symbols
648 struct dwarf2_queue_item
650 struct dwarf2_per_cu_data
*per_cu
;
651 struct dwarf2_queue_item
*next
;
654 /* The current queue. */
655 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
657 /* Loaded secondary compilation units are kept in memory until they
658 have not been referenced for the processing of this many
659 compilation units. Set this to zero to disable caching. Cache
660 sizes of up to at least twenty will improve startup time for
661 typical inter-CU-reference binaries, at an obvious memory cost. */
662 static int dwarf2_max_cache_age
= 5;
664 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
665 struct cmd_list_element
*c
, const char *value
)
667 fprintf_filtered (file
, _("\
668 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
673 /* Various complaints about symbol reading that don't abort the process */
676 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
678 complaint (&symfile_complaints
,
679 _("statement list doesn't fit in .debug_line section"));
683 dwarf2_debug_line_missing_file_complaint (void)
685 complaint (&symfile_complaints
,
686 _(".debug_line section has line data without a file"));
690 dwarf2_debug_line_missing_end_sequence_complaint (void)
692 complaint (&symfile_complaints
,
693 _(".debug_line section has line program sequence without an end"));
697 dwarf2_complex_location_expr_complaint (void)
699 complaint (&symfile_complaints
, _("location expression too complex"));
703 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
706 complaint (&symfile_complaints
,
707 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
712 dwarf2_macros_too_long_complaint (void)
714 complaint (&symfile_complaints
,
715 _("macro info runs off end of `.debug_macinfo' section"));
719 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
721 complaint (&symfile_complaints
,
722 _("macro debug info contains a malformed macro definition:\n`%s'"),
727 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
729 complaint (&symfile_complaints
,
730 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
733 /* local function prototypes */
735 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
738 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
741 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
744 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
745 struct partial_die_info
*,
746 struct partial_symtab
*);
748 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
750 static void scan_partial_symbols (struct partial_die_info
*,
751 CORE_ADDR
*, CORE_ADDR
*,
752 int, struct dwarf2_cu
*);
754 static void add_partial_symbol (struct partial_die_info
*,
757 static int pdi_needs_namespace (enum dwarf_tag tag
);
759 static void add_partial_namespace (struct partial_die_info
*pdi
,
760 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
761 int need_pc
, struct dwarf2_cu
*cu
);
763 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
764 CORE_ADDR
*highpc
, int need_pc
,
765 struct dwarf2_cu
*cu
);
767 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
768 struct dwarf2_cu
*cu
);
770 static void add_partial_subprogram (struct partial_die_info
*pdi
,
771 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
772 int need_pc
, struct dwarf2_cu
*cu
);
774 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
777 struct dwarf2_cu
*cu
);
779 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
781 static void psymtab_to_symtab_1 (struct partial_symtab
*);
783 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
785 static void dwarf2_free_abbrev_table (void *);
787 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
790 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
793 static struct partial_die_info
*load_partial_dies (bfd
*, gdb_byte
*, int,
796 static gdb_byte
*read_partial_die (struct partial_die_info
*,
797 struct abbrev_info
*abbrev
, unsigned int,
798 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
800 static struct partial_die_info
*find_partial_die (unsigned int,
803 static void fixup_partial_die (struct partial_die_info
*,
806 static gdb_byte
*read_full_die (struct die_info
**, bfd
*, gdb_byte
*,
807 struct dwarf2_cu
*, int *);
809 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
810 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
812 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
813 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
815 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
817 static int read_1_signed_byte (bfd
*, gdb_byte
*);
819 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
821 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
823 static unsigned long read_8_bytes (bfd
*, gdb_byte
*);
825 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
828 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
830 static LONGEST read_checked_initial_length_and_offset
831 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
832 unsigned int *, unsigned int *);
834 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
837 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
839 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
841 static char *read_string (bfd
*, gdb_byte
*, unsigned int *);
843 static char *read_indirect_string (bfd
*, gdb_byte
*,
844 const struct comp_unit_head
*,
847 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
849 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
851 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
853 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
855 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
858 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
859 struct dwarf2_cu
*cu
);
861 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
863 static struct die_info
*die_specification (struct die_info
*die
,
864 struct dwarf2_cu
**);
866 static void free_line_header (struct line_header
*lh
);
868 static void add_file_name (struct line_header
*, char *, unsigned int,
869 unsigned int, unsigned int);
871 static struct line_header
*(dwarf_decode_line_header
872 (unsigned int offset
,
873 bfd
*abfd
, struct dwarf2_cu
*cu
));
875 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
876 struct dwarf2_cu
*, struct partial_symtab
*);
878 static void dwarf2_start_subfile (char *, char *, char *);
880 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
883 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
886 static void dwarf2_const_value_data (struct attribute
*attr
,
890 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
892 static struct type
*die_containing_type (struct die_info
*,
895 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
897 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
899 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
901 static char *typename_concat (struct obstack
*,
906 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
908 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
910 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
912 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
913 struct dwarf2_cu
*, struct partial_symtab
*);
915 static int dwarf2_get_pc_bounds (struct die_info
*,
916 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
918 static void get_scope_pc_bounds (struct die_info
*,
919 CORE_ADDR
*, CORE_ADDR
*,
922 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
923 CORE_ADDR
, struct dwarf2_cu
*);
925 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
928 static void dwarf2_attach_fields_to_type (struct field_info
*,
929 struct type
*, struct dwarf2_cu
*);
931 static void dwarf2_add_member_fn (struct field_info
*,
932 struct die_info
*, struct type
*,
935 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
936 struct type
*, struct dwarf2_cu
*);
938 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
940 static const char *determine_class_name (struct die_info
*die
,
941 struct dwarf2_cu
*cu
);
943 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
945 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
947 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
949 static const char *namespace_name (struct die_info
*die
,
950 int *is_anonymous
, struct dwarf2_cu
*);
952 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
954 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
956 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
959 static struct die_info
*read_comp_unit (gdb_byte
*, bfd
*, struct dwarf2_cu
*);
961 static struct die_info
*read_die_and_children_1 (gdb_byte
*info_ptr
, bfd
*abfd
,
963 gdb_byte
**new_info_ptr
,
964 struct die_info
*parent
);
966 static struct die_info
*read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
968 gdb_byte
**new_info_ptr
,
969 struct die_info
*parent
);
971 static struct die_info
*read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
973 gdb_byte
**new_info_ptr
,
974 struct die_info
*parent
);
976 static void process_die (struct die_info
*, struct dwarf2_cu
*);
978 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
980 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
983 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
985 static struct die_info
*dwarf2_extension (struct die_info
*die
,
986 struct dwarf2_cu
**);
988 static char *dwarf_tag_name (unsigned int);
990 static char *dwarf_attr_name (unsigned int);
992 static char *dwarf_form_name (unsigned int);
994 static char *dwarf_stack_op_name (unsigned int);
996 static char *dwarf_bool_name (unsigned int);
998 static char *dwarf_type_encoding_name (unsigned int);
1001 static char *dwarf_cfi_name (unsigned int);
1004 static struct die_info
*sibling_die (struct die_info
*);
1006 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1008 static void dump_die_for_error (struct die_info
*);
1010 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1013 /*static*/ void dump_die (struct die_info
*, int max_level
);
1015 static void store_in_ref_table (struct die_info
*,
1016 struct dwarf2_cu
*);
1018 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1020 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
1022 static struct die_info
*follow_die_ref (struct die_info
*,
1024 struct dwarf2_cu
**);
1026 /* memory allocation interface */
1028 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1030 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1032 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1034 static void initialize_cu_func_list (struct dwarf2_cu
*);
1036 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1037 struct dwarf2_cu
*);
1039 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1040 char *, bfd
*, struct dwarf2_cu
*);
1042 static int attr_form_is_block (struct attribute
*);
1044 static int attr_form_is_section_offset (struct attribute
*);
1046 static int attr_form_is_constant (struct attribute
*);
1048 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1050 struct dwarf2_cu
*cu
);
1052 static gdb_byte
*skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
1053 struct dwarf2_cu
*cu
);
1055 static void free_stack_comp_unit (void *);
1057 static hashval_t
partial_die_hash (const void *item
);
1059 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1061 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1062 (unsigned int offset
, struct objfile
*objfile
);
1064 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1065 (unsigned int offset
, struct objfile
*objfile
);
1067 static void free_one_comp_unit (void *);
1069 static void free_cached_comp_units (void *);
1071 static void age_cached_comp_units (void);
1073 static void free_one_cached_comp_unit (void *);
1075 static struct type
*set_die_type (struct die_info
*, struct type
*,
1076 struct dwarf2_cu
*);
1078 static void create_all_comp_units (struct objfile
*);
1080 static struct dwarf2_cu
*load_full_comp_unit (struct dwarf2_per_cu_data
*,
1083 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1085 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1086 struct dwarf2_per_cu_data
*);
1088 static void dwarf2_mark (struct dwarf2_cu
*);
1090 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1092 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1094 /* Try to locate the sections we need for DWARF 2 debugging
1095 information and return true if we have enough to do something. */
1098 dwarf2_has_info (struct objfile
*objfile
)
1100 struct dwarf2_per_objfile
*data
;
1102 /* Initialize per-objfile state. */
1103 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1104 memset (data
, 0, sizeof (*data
));
1105 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1106 dwarf2_per_objfile
= data
;
1108 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1109 return (data
->info
.asection
!= NULL
&& data
->abbrev
.asection
!= NULL
);
1112 /* When loading sections, we can either look for ".<name>", or for
1113 * ".z<name>", which indicates a compressed section. */
1116 section_is_p (const char *section_name
, const char *name
)
1118 return (section_name
[0] == '.'
1119 && (strcmp (section_name
+ 1, name
) == 0
1120 || (section_name
[1] == 'z'
1121 && strcmp (section_name
+ 2, name
) == 0)));
1124 /* This function is mapped across the sections and remembers the
1125 offset and size of each of the debugging sections we are interested
1129 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1131 if (section_is_p (sectp
->name
, INFO_SECTION
))
1133 dwarf2_per_objfile
->info
.asection
= sectp
;
1134 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1136 else if (section_is_p (sectp
->name
, ABBREV_SECTION
))
1138 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1139 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1141 else if (section_is_p (sectp
->name
, LINE_SECTION
))
1143 dwarf2_per_objfile
->line
.asection
= sectp
;
1144 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1146 else if (section_is_p (sectp
->name
, PUBNAMES_SECTION
))
1148 dwarf2_per_objfile
->pubnames
.asection
= sectp
;
1149 dwarf2_per_objfile
->pubnames
.size
= bfd_get_section_size (sectp
);
1151 else if (section_is_p (sectp
->name
, ARANGES_SECTION
))
1153 dwarf2_per_objfile
->aranges
.asection
= sectp
;
1154 dwarf2_per_objfile
->aranges
.size
= bfd_get_section_size (sectp
);
1156 else if (section_is_p (sectp
->name
, LOC_SECTION
))
1158 dwarf2_per_objfile
->loc
.asection
= sectp
;
1159 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1161 else if (section_is_p (sectp
->name
, MACINFO_SECTION
))
1163 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1164 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1166 else if (section_is_p (sectp
->name
, STR_SECTION
))
1168 dwarf2_per_objfile
->str
.asection
= sectp
;
1169 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1171 else if (section_is_p (sectp
->name
, FRAME_SECTION
))
1173 dwarf2_per_objfile
->frame
.asection
= sectp
;
1174 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1176 else if (section_is_p (sectp
->name
, EH_FRAME_SECTION
))
1178 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1179 if (aflag
& SEC_HAS_CONTENTS
)
1181 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1182 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1185 else if (section_is_p (sectp
->name
, RANGES_SECTION
))
1187 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1188 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1191 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1192 && bfd_section_vma (abfd
, sectp
) == 0)
1193 dwarf2_per_objfile
->has_section_at_zero
= 1;
1196 /* Decompress a section that was compressed using zlib. Store the
1197 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1200 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1201 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1203 bfd
*abfd
= objfile
->obfd
;
1205 error (_("Support for zlib-compressed DWARF data (from '%s') "
1206 "is disabled in this copy of GDB"),
1207 bfd_get_filename (abfd
));
1209 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1210 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1211 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1212 bfd_size_type uncompressed_size
;
1213 gdb_byte
*uncompressed_buffer
;
1216 int header_size
= 12;
1218 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1219 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
1220 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1221 bfd_get_filename (abfd
));
1223 /* Read the zlib header. In this case, it should be "ZLIB" followed
1224 by the uncompressed section size, 8 bytes in big-endian order. */
1225 if (compressed_size
< header_size
1226 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1227 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1228 bfd_get_filename (abfd
));
1229 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1230 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1231 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1232 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1233 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1234 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1235 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1236 uncompressed_size
+= compressed_buffer
[11];
1238 /* It is possible the section consists of several compressed
1239 buffers concatenated together, so we uncompress in a loop. */
1243 strm
.avail_in
= compressed_size
- header_size
;
1244 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1245 strm
.avail_out
= uncompressed_size
;
1246 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1248 rc
= inflateInit (&strm
);
1249 while (strm
.avail_in
> 0)
1252 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1253 bfd_get_filename (abfd
), rc
);
1254 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1255 + (uncompressed_size
- strm
.avail_out
));
1256 rc
= inflate (&strm
, Z_FINISH
);
1257 if (rc
!= Z_STREAM_END
)
1258 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1259 bfd_get_filename (abfd
), rc
);
1260 rc
= inflateReset (&strm
);
1262 rc
= inflateEnd (&strm
);
1264 || strm
.avail_out
!= 0)
1265 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1266 bfd_get_filename (abfd
), rc
);
1268 do_cleanups (cleanup
);
1269 *outbuf
= uncompressed_buffer
;
1270 *outsize
= uncompressed_size
;
1274 /* Read the contents of the section SECTP from object file specified by
1275 OBJFILE, store info about the section into INFO.
1276 If the section is compressed, uncompress it before returning. */
1279 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1281 bfd
*abfd
= objfile
->obfd
;
1282 asection
*sectp
= info
->asection
;
1283 gdb_byte
*buf
, *retbuf
;
1284 unsigned char header
[4];
1286 info
->buffer
= NULL
;
1287 info
->was_mmapped
= 0;
1289 if (info
->asection
== NULL
|| info
->size
== 0)
1292 /* Check if the file has a 4-byte header indicating compression. */
1293 if (info
->size
> sizeof (header
)
1294 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1295 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1297 /* Upon decompression, update the buffer and its size. */
1298 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1300 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1308 pagesize
= getpagesize ();
1310 /* Only try to mmap sections which are large enough: we don't want to
1311 waste space due to fragmentation. Also, only try mmap for sections
1312 without relocations. */
1314 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1316 off_t pg_offset
= sectp
->filepos
& ~(pagesize
- 1);
1317 size_t map_length
= info
->size
+ sectp
->filepos
- pg_offset
;
1318 caddr_t retbuf
= bfd_mmap (abfd
, 0, map_length
, PROT_READ
,
1319 MAP_PRIVATE
, pg_offset
);
1321 if (retbuf
!= MAP_FAILED
)
1323 info
->was_mmapped
= 1;
1324 info
->buffer
= retbuf
+ (sectp
->filepos
& (pagesize
- 1)) ;
1330 /* If we get here, we are a normal, not-compressed section. */
1332 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1334 /* When debugging .o files, we may need to apply relocations; see
1335 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1336 We never compress sections in .o files, so we only need to
1337 try this when the section is not compressed. */
1338 retbuf
= symfile_relocate_debug_section (abfd
, sectp
, buf
);
1341 info
->buffer
= retbuf
;
1345 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1346 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1347 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1348 bfd_get_filename (abfd
));
1351 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1355 dwarf2_get_section_info (struct objfile
*objfile
, const char *section_name
,
1356 asection
**sectp
, gdb_byte
**bufp
,
1357 bfd_size_type
*sizep
)
1359 struct dwarf2_per_objfile
*data
1360 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1361 struct dwarf2_section_info
*info
;
1362 if (section_is_p (section_name
, EH_FRAME_SECTION
))
1363 info
= &data
->eh_frame
;
1364 else if (section_is_p (section_name
, FRAME_SECTION
))
1365 info
= &data
->frame
;
1369 if (info
->asection
!= NULL
&& info
->size
!= 0 && info
->buffer
== NULL
)
1370 /* We haven't read this section in yet. Do it now. */
1371 dwarf2_read_section (objfile
, info
);
1373 *sectp
= info
->asection
;
1374 *bufp
= info
->buffer
;
1375 *sizep
= info
->size
;
1378 /* Build a partial symbol table. */
1381 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1383 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
1384 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->abbrev
);
1385 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->line
);
1386 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->str
);
1387 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->macinfo
);
1388 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
1389 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->loc
);
1390 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->eh_frame
);
1391 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->frame
);
1394 || (objfile
->global_psymbols
.size
== 0
1395 && objfile
->static_psymbols
.size
== 0))
1397 init_psymbol_list (objfile
, 1024);
1401 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1403 /* Things are significantly easier if we have .debug_aranges and
1404 .debug_pubnames sections */
1406 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1410 /* only test this case for now */
1412 /* In this case we have to work a bit harder */
1413 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1418 /* Build the partial symbol table from the information in the
1419 .debug_pubnames and .debug_aranges sections. */
1422 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1424 bfd
*abfd
= objfile
->obfd
;
1425 char *aranges_buffer
, *pubnames_buffer
;
1426 char *aranges_ptr
, *pubnames_ptr
;
1427 unsigned int entry_length
, version
, info_offset
, info_size
;
1429 pubnames_buffer
= dwarf2_read_section (objfile
,
1430 dwarf_pubnames_section
);
1431 pubnames_ptr
= pubnames_buffer
;
1432 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames
.size
)
1434 unsigned int bytes_read
;
1436 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &bytes_read
);
1437 pubnames_ptr
+= bytes_read
;
1438 version
= read_1_byte (abfd
, pubnames_ptr
);
1440 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1442 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1446 aranges_buffer
= dwarf2_read_section (objfile
,
1447 dwarf_aranges_section
);
1452 /* Return TRUE if OFFSET is within CU_HEADER. */
1455 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
1457 unsigned int bottom
= cu_header
->offset
;
1458 unsigned int top
= (cu_header
->offset
1460 + cu_header
->initial_length_size
);
1461 return (offset
>= bottom
&& offset
< top
);
1464 /* Read in the comp unit header information from the debug_info at
1468 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1469 gdb_byte
*info_ptr
, bfd
*abfd
)
1472 unsigned int bytes_read
;
1474 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
1475 cu_header
->initial_length_size
= bytes_read
;
1476 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
1477 info_ptr
+= bytes_read
;
1478 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1480 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1482 info_ptr
+= bytes_read
;
1483 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1485 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1486 if (signed_addr
< 0)
1487 internal_error (__FILE__
, __LINE__
,
1488 _("read_comp_unit_head: dwarf from non elf file"));
1489 cu_header
->signed_addr_p
= signed_addr
;
1495 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1498 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1500 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1502 if (header
->version
!= 2 && header
->version
!= 3)
1503 error (_("Dwarf Error: wrong version in compilation unit header "
1504 "(is %d, should be %d) [in module %s]"), header
->version
,
1505 2, bfd_get_filename (abfd
));
1507 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev
.size
)
1508 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1509 "(offset 0x%lx + 6) [in module %s]"),
1510 (long) header
->abbrev_offset
,
1511 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info
.buffer
),
1512 bfd_get_filename (abfd
));
1514 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1515 > dwarf2_per_objfile
->info
.buffer
+ dwarf2_per_objfile
->info
.size
)
1516 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1517 "(offset 0x%lx + 0) [in module %s]"),
1518 (long) header
->length
,
1519 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info
.buffer
),
1520 bfd_get_filename (abfd
));
1525 /* Allocate a new partial symtab for file named NAME and mark this new
1526 partial symtab as being an include of PST. */
1529 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1530 struct objfile
*objfile
)
1532 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1534 subpst
->section_offsets
= pst
->section_offsets
;
1535 subpst
->textlow
= 0;
1536 subpst
->texthigh
= 0;
1538 subpst
->dependencies
= (struct partial_symtab
**)
1539 obstack_alloc (&objfile
->objfile_obstack
,
1540 sizeof (struct partial_symtab
*));
1541 subpst
->dependencies
[0] = pst
;
1542 subpst
->number_of_dependencies
= 1;
1544 subpst
->globals_offset
= 0;
1545 subpst
->n_global_syms
= 0;
1546 subpst
->statics_offset
= 0;
1547 subpst
->n_static_syms
= 0;
1548 subpst
->symtab
= NULL
;
1549 subpst
->read_symtab
= pst
->read_symtab
;
1552 /* No private part is necessary for include psymtabs. This property
1553 can be used to differentiate between such include psymtabs and
1554 the regular ones. */
1555 subpst
->read_symtab_private
= NULL
;
1558 /* Read the Line Number Program data and extract the list of files
1559 included by the source file represented by PST. Build an include
1560 partial symtab for each of these included files.
1562 This procedure assumes that there *is* a Line Number Program in
1563 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1564 before calling this procedure. */
1567 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1568 struct partial_die_info
*pdi
,
1569 struct partial_symtab
*pst
)
1571 struct objfile
*objfile
= cu
->objfile
;
1572 bfd
*abfd
= objfile
->obfd
;
1573 struct line_header
*lh
;
1575 lh
= dwarf_decode_line_header (pdi
->line_offset
, abfd
, cu
);
1577 return; /* No linetable, so no includes. */
1579 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1581 free_line_header (lh
);
1585 /* Build the partial symbol table by doing a quick pass through the
1586 .debug_info and .debug_abbrev sections. */
1589 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1591 /* Instead of reading this into a big buffer, we should probably use
1592 mmap() on architectures that support it. (FIXME) */
1593 bfd
*abfd
= objfile
->obfd
;
1595 gdb_byte
*beg_of_comp_unit
;
1596 struct partial_die_info comp_unit_die
;
1597 struct partial_symtab
*pst
;
1598 struct cleanup
*back_to
;
1601 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
1603 /* Any cached compilation units will be linked by the per-objfile
1604 read_in_chain. Make sure to free them when we're done. */
1605 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1607 create_all_comp_units (objfile
);
1609 objfile
->psymtabs_addrmap
= addrmap_create_mutable
1610 (&objfile
->objfile_obstack
);
1612 /* Since the objects we're extracting from .debug_info vary in
1613 length, only the individual functions to extract them (like
1614 read_comp_unit_head and load_partial_die) can really know whether
1615 the buffer is large enough to hold another complete object.
1617 At the moment, they don't actually check that. If .debug_info
1618 holds just one extra byte after the last compilation unit's dies,
1619 then read_comp_unit_head will happily read off the end of the
1620 buffer. read_partial_die is similarly casual. Those functions
1623 For this loop condition, simply checking whether there's any data
1624 left at all should be sufficient. */
1625 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
1626 + dwarf2_per_objfile
->info
.size
))
1628 struct cleanup
*back_to_inner
;
1629 struct dwarf2_cu cu
;
1630 struct abbrev_info
*abbrev
;
1631 unsigned int bytes_read
;
1632 struct dwarf2_per_cu_data
*this_cu
;
1634 beg_of_comp_unit
= info_ptr
;
1636 memset (&cu
, 0, sizeof (cu
));
1638 obstack_init (&cu
.comp_unit_obstack
);
1640 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1642 cu
.objfile
= objfile
;
1643 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1645 /* Complete the cu_header */
1646 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info
.buffer
;
1647 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1649 cu
.list_in_scope
= &file_symbols
;
1651 /* Read the abbrevs for this compilation unit into a table */
1652 dwarf2_read_abbrevs (abfd
, &cu
);
1653 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1655 this_cu
= dwarf2_find_comp_unit (cu
.header
.offset
, objfile
);
1657 /* Read the compilation unit die */
1658 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, &cu
);
1659 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1660 abfd
, info_ptr
, &cu
);
1662 if (comp_unit_die
.tag
== DW_TAG_partial_unit
)
1664 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1665 + cu
.header
.initial_length_size
);
1666 do_cleanups (back_to_inner
);
1670 /* Set the language we're debugging */
1671 set_cu_language (comp_unit_die
.language
, &cu
);
1673 /* Allocate a new partial symbol table structure */
1674 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1675 comp_unit_die
.name
? comp_unit_die
.name
: "",
1676 /* TEXTLOW and TEXTHIGH are set below. */
1678 objfile
->global_psymbols
.next
,
1679 objfile
->static_psymbols
.next
);
1681 if (comp_unit_die
.dirname
)
1682 pst
->dirname
= obsavestring (comp_unit_die
.dirname
,
1683 strlen (comp_unit_die
.dirname
),
1684 &objfile
->objfile_obstack
);
1686 pst
->read_symtab_private
= (char *) this_cu
;
1688 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1690 /* Store the function that reads in the rest of the symbol table */
1691 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1693 /* If this compilation unit was already read in, free the
1694 cached copy in order to read it in again. This is
1695 necessary because we skipped some symbols when we first
1696 read in the compilation unit (see load_partial_dies).
1697 This problem could be avoided, but the benefit is
1699 if (this_cu
->cu
!= NULL
)
1700 free_one_cached_comp_unit (this_cu
->cu
);
1702 cu
.per_cu
= this_cu
;
1704 /* Note that this is a pointer to our stack frame, being
1705 added to a global data structure. It will be cleaned up
1706 in free_stack_comp_unit when we finish with this
1707 compilation unit. */
1710 this_cu
->psymtab
= pst
;
1712 /* Possibly set the default values of LOWPC and HIGHPC from
1714 if (cu
.has_ranges_offset
)
1716 if (dwarf2_ranges_read (cu
.ranges_offset
, &comp_unit_die
.lowpc
,
1717 &comp_unit_die
.highpc
, &cu
, pst
))
1718 comp_unit_die
.has_pc_info
= 1;
1720 else if (comp_unit_die
.has_pc_info
1721 && comp_unit_die
.lowpc
< comp_unit_die
.highpc
)
1722 /* Store the contiguous range if it is not empty; it can be empty for
1723 CUs with no code. */
1724 addrmap_set_empty (objfile
->psymtabs_addrmap
,
1725 comp_unit_die
.lowpc
+ baseaddr
,
1726 comp_unit_die
.highpc
+ baseaddr
- 1, pst
);
1728 /* Check if comp unit has_children.
1729 If so, read the rest of the partial symbols from this comp unit.
1730 If not, there's no more debug_info for this comp unit. */
1731 if (comp_unit_die
.has_children
)
1733 struct partial_die_info
*first_die
;
1734 CORE_ADDR lowpc
, highpc
;
1736 lowpc
= ((CORE_ADDR
) -1);
1737 highpc
= ((CORE_ADDR
) 0);
1739 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1741 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
1742 ! comp_unit_die
.has_pc_info
, &cu
);
1744 /* If we didn't find a lowpc, set it to highpc to avoid
1745 complaints from `maint check'. */
1746 if (lowpc
== ((CORE_ADDR
) -1))
1749 /* If the compilation unit didn't have an explicit address range,
1750 then use the information extracted from its child dies. */
1751 if (! comp_unit_die
.has_pc_info
)
1753 comp_unit_die
.lowpc
= lowpc
;
1754 comp_unit_die
.highpc
= highpc
;
1757 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1758 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1760 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1761 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1762 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1763 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1764 sort_pst_symbols (pst
);
1766 /* If there is already a psymtab or symtab for a file of this
1767 name, remove it. (If there is a symtab, more drastic things
1768 also happen.) This happens in VxWorks. */
1769 free_named_symtabs (pst
->filename
);
1771 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1772 + cu
.header
.initial_length_size
;
1774 if (comp_unit_die
.has_stmt_list
)
1776 /* Get the list of files included in the current compilation unit,
1777 and build a psymtab for each of them. */
1778 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1781 do_cleanups (back_to_inner
);
1784 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
1785 &objfile
->objfile_obstack
);
1787 do_cleanups (back_to
);
1790 /* Load the DIEs for a secondary CU into memory. */
1793 load_comp_unit (struct dwarf2_per_cu_data
*this_cu
, struct objfile
*objfile
)
1795 bfd
*abfd
= objfile
->obfd
;
1796 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
1797 struct partial_die_info comp_unit_die
;
1798 struct dwarf2_cu
*cu
;
1799 struct abbrev_info
*abbrev
;
1800 unsigned int bytes_read
;
1801 struct cleanup
*back_to
;
1803 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
1804 beg_of_comp_unit
= info_ptr
;
1806 cu
= xmalloc (sizeof (struct dwarf2_cu
));
1807 memset (cu
, 0, sizeof (struct dwarf2_cu
));
1809 obstack_init (&cu
->comp_unit_obstack
);
1811 cu
->objfile
= objfile
;
1812 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
1814 /* Complete the cu_header. */
1815 cu
->header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info
.buffer
;
1816 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1818 /* Read the abbrevs for this compilation unit into a table. */
1819 dwarf2_read_abbrevs (abfd
, cu
);
1820 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
1822 /* Read the compilation unit die. */
1823 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1824 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1825 abfd
, info_ptr
, cu
);
1827 /* Set the language we're debugging. */
1828 set_cu_language (comp_unit_die
.language
, cu
);
1830 /* Link this compilation unit into the compilation unit tree. */
1832 cu
->per_cu
= this_cu
;
1833 cu
->type_hash
= cu
->per_cu
->type_hash
;
1835 /* Check if comp unit has_children.
1836 If so, read the rest of the partial symbols from this comp unit.
1837 If not, there's no more debug_info for this comp unit. */
1838 if (comp_unit_die
.has_children
)
1839 load_partial_dies (abfd
, info_ptr
, 0, cu
);
1841 do_cleanups (back_to
);
1844 /* Create a list of all compilation units in OBJFILE. We do this only
1845 if an inter-comp-unit reference is found; presumably if there is one,
1846 there will be many, and one will occur early in the .debug_info section.
1847 So there's no point in building this list incrementally. */
1850 create_all_comp_units (struct objfile
*objfile
)
1854 struct dwarf2_per_cu_data
**all_comp_units
;
1855 gdb_byte
*info_ptr
= dwarf2_per_objfile
->info
.buffer
;
1859 all_comp_units
= xmalloc (n_allocated
1860 * sizeof (struct dwarf2_per_cu_data
*));
1862 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
+ dwarf2_per_objfile
->info
.size
)
1864 unsigned int length
, initial_length_size
;
1865 gdb_byte
*beg_of_comp_unit
;
1866 struct dwarf2_per_cu_data
*this_cu
;
1867 unsigned int offset
;
1869 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
1871 /* Read just enough information to find out where the next
1872 compilation unit is. */
1873 length
= read_initial_length (objfile
->obfd
, info_ptr
,
1874 &initial_length_size
);
1876 /* Save the compilation unit for later lookup. */
1877 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
1878 sizeof (struct dwarf2_per_cu_data
));
1879 memset (this_cu
, 0, sizeof (*this_cu
));
1880 this_cu
->offset
= offset
;
1881 this_cu
->length
= length
+ initial_length_size
;
1883 if (n_comp_units
== n_allocated
)
1886 all_comp_units
= xrealloc (all_comp_units
,
1888 * sizeof (struct dwarf2_per_cu_data
*));
1890 all_comp_units
[n_comp_units
++] = this_cu
;
1892 info_ptr
= info_ptr
+ this_cu
->length
;
1895 dwarf2_per_objfile
->all_comp_units
1896 = obstack_alloc (&objfile
->objfile_obstack
,
1897 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1898 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
1899 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1900 xfree (all_comp_units
);
1901 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
1904 /* Process all loaded DIEs for compilation unit CU, starting at
1905 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
1906 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
1907 DW_AT_ranges). If NEED_PC is set, then this function will set
1908 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
1909 and record the covered ranges in the addrmap. */
1912 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1913 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
1915 struct objfile
*objfile
= cu
->objfile
;
1916 bfd
*abfd
= objfile
->obfd
;
1917 struct partial_die_info
*pdi
;
1919 /* Now, march along the PDI's, descending into ones which have
1920 interesting children but skipping the children of the other ones,
1921 until we reach the end of the compilation unit. */
1927 fixup_partial_die (pdi
, cu
);
1929 /* Anonymous namespaces have no name but have interesting
1930 children, so we need to look at them. Ditto for anonymous
1933 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1934 || pdi
->tag
== DW_TAG_enumeration_type
)
1938 case DW_TAG_subprogram
:
1939 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
1941 case DW_TAG_variable
:
1942 case DW_TAG_typedef
:
1943 case DW_TAG_union_type
:
1944 if (!pdi
->is_declaration
)
1946 add_partial_symbol (pdi
, cu
);
1949 case DW_TAG_class_type
:
1950 case DW_TAG_interface_type
:
1951 case DW_TAG_structure_type
:
1952 if (!pdi
->is_declaration
)
1954 add_partial_symbol (pdi
, cu
);
1957 case DW_TAG_enumeration_type
:
1958 if (!pdi
->is_declaration
)
1959 add_partial_enumeration (pdi
, cu
);
1961 case DW_TAG_base_type
:
1962 case DW_TAG_subrange_type
:
1963 /* File scope base type definitions are added to the partial
1965 add_partial_symbol (pdi
, cu
);
1967 case DW_TAG_namespace
:
1968 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
1971 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
1978 /* If the die has a sibling, skip to the sibling. */
1980 pdi
= pdi
->die_sibling
;
1984 /* Functions used to compute the fully scoped name of a partial DIE.
1986 Normally, this is simple. For C++, the parent DIE's fully scoped
1987 name is concatenated with "::" and the partial DIE's name. For
1988 Java, the same thing occurs except that "." is used instead of "::".
1989 Enumerators are an exception; they use the scope of their parent
1990 enumeration type, i.e. the name of the enumeration type is not
1991 prepended to the enumerator.
1993 There are two complexities. One is DW_AT_specification; in this
1994 case "parent" means the parent of the target of the specification,
1995 instead of the direct parent of the DIE. The other is compilers
1996 which do not emit DW_TAG_namespace; in this case we try to guess
1997 the fully qualified name of structure types from their members'
1998 linkage names. This must be done using the DIE's children rather
1999 than the children of any DW_AT_specification target. We only need
2000 to do this for structures at the top level, i.e. if the target of
2001 any DW_AT_specification (if any; otherwise the DIE itself) does not
2004 /* Compute the scope prefix associated with PDI's parent, in
2005 compilation unit CU. The result will be allocated on CU's
2006 comp_unit_obstack, or a copy of the already allocated PDI->NAME
2007 field. NULL is returned if no prefix is necessary. */
2009 partial_die_parent_scope (struct partial_die_info
*pdi
,
2010 struct dwarf2_cu
*cu
)
2012 char *grandparent_scope
;
2013 struct partial_die_info
*parent
, *real_pdi
;
2015 /* We need to look at our parent DIE; if we have a DW_AT_specification,
2016 then this means the parent of the specification DIE. */
2019 while (real_pdi
->has_specification
)
2020 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2022 parent
= real_pdi
->die_parent
;
2026 if (parent
->scope_set
)
2027 return parent
->scope
;
2029 fixup_partial_die (parent
, cu
);
2031 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
2033 if (parent
->tag
== DW_TAG_namespace
2034 || parent
->tag
== DW_TAG_structure_type
2035 || parent
->tag
== DW_TAG_class_type
2036 || parent
->tag
== DW_TAG_interface_type
2037 || parent
->tag
== DW_TAG_union_type
)
2039 if (grandparent_scope
== NULL
)
2040 parent
->scope
= parent
->name
;
2042 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
2045 else if (parent
->tag
== DW_TAG_enumeration_type
)
2046 /* Enumerators should not get the name of the enumeration as a prefix. */
2047 parent
->scope
= grandparent_scope
;
2050 /* FIXME drow/2004-04-01: What should we be doing with
2051 function-local names? For partial symbols, we should probably be
2053 complaint (&symfile_complaints
,
2054 _("unhandled containing DIE tag %d for DIE at %d"),
2055 parent
->tag
, pdi
->offset
);
2056 parent
->scope
= grandparent_scope
;
2059 parent
->scope_set
= 1;
2060 return parent
->scope
;
2063 /* Return the fully scoped name associated with PDI, from compilation unit
2064 CU. The result will be allocated with malloc. */
2066 partial_die_full_name (struct partial_die_info
*pdi
,
2067 struct dwarf2_cu
*cu
)
2071 parent_scope
= partial_die_parent_scope (pdi
, cu
);
2072 if (parent_scope
== NULL
)
2075 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
2079 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
2081 struct objfile
*objfile
= cu
->objfile
;
2083 char *actual_name
= NULL
;
2084 const char *my_prefix
;
2085 const struct partial_symbol
*psym
= NULL
;
2087 int built_actual_name
= 0;
2089 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2091 if (pdi_needs_namespace (pdi
->tag
))
2093 actual_name
= partial_die_full_name (pdi
, cu
);
2095 built_actual_name
= 1;
2098 if (actual_name
== NULL
)
2099 actual_name
= pdi
->name
;
2103 case DW_TAG_subprogram
:
2104 if (pdi
->is_external
|| cu
->language
== language_ada
)
2106 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
2107 of the global scope. But in Ada, we want to be able to access
2108 nested procedures globally. So all Ada subprograms are stored
2109 in the global scope. */
2110 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2111 mst_text, objfile); */
2112 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2113 VAR_DOMAIN
, LOC_BLOCK
,
2114 &objfile
->global_psymbols
,
2115 0, pdi
->lowpc
+ baseaddr
,
2116 cu
->language
, objfile
);
2120 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2121 mst_file_text, objfile); */
2122 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2123 VAR_DOMAIN
, LOC_BLOCK
,
2124 &objfile
->static_psymbols
,
2125 0, pdi
->lowpc
+ baseaddr
,
2126 cu
->language
, objfile
);
2129 case DW_TAG_variable
:
2130 if (pdi
->is_external
)
2133 Don't enter into the minimal symbol tables as there is
2134 a minimal symbol table entry from the ELF symbols already.
2135 Enter into partial symbol table if it has a location
2136 descriptor or a type.
2137 If the location descriptor is missing, new_symbol will create
2138 a LOC_UNRESOLVED symbol, the address of the variable will then
2139 be determined from the minimal symbol table whenever the variable
2141 The address for the partial symbol table entry is not
2142 used by GDB, but it comes in handy for debugging partial symbol
2146 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2147 if (pdi
->locdesc
|| pdi
->has_type
)
2148 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2149 VAR_DOMAIN
, LOC_STATIC
,
2150 &objfile
->global_psymbols
,
2152 cu
->language
, objfile
);
2156 /* Static Variable. Skip symbols without location descriptors. */
2157 if (pdi
->locdesc
== NULL
)
2159 if (built_actual_name
)
2160 xfree (actual_name
);
2163 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2164 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2165 mst_file_data, objfile); */
2166 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2167 VAR_DOMAIN
, LOC_STATIC
,
2168 &objfile
->static_psymbols
,
2170 cu
->language
, objfile
);
2173 case DW_TAG_typedef
:
2174 case DW_TAG_base_type
:
2175 case DW_TAG_subrange_type
:
2176 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2177 VAR_DOMAIN
, LOC_TYPEDEF
,
2178 &objfile
->static_psymbols
,
2179 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2181 case DW_TAG_namespace
:
2182 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2183 VAR_DOMAIN
, LOC_TYPEDEF
,
2184 &objfile
->global_psymbols
,
2185 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2187 case DW_TAG_class_type
:
2188 case DW_TAG_interface_type
:
2189 case DW_TAG_structure_type
:
2190 case DW_TAG_union_type
:
2191 case DW_TAG_enumeration_type
:
2192 /* Skip external references. The DWARF standard says in the section
2193 about "Structure, Union, and Class Type Entries": "An incomplete
2194 structure, union or class type is represented by a structure,
2195 union or class entry that does not have a byte size attribute
2196 and that has a DW_AT_declaration attribute." */
2197 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2199 if (built_actual_name
)
2200 xfree (actual_name
);
2204 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2205 static vs. global. */
2206 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2207 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2208 (cu
->language
== language_cplus
2209 || cu
->language
== language_java
)
2210 ? &objfile
->global_psymbols
2211 : &objfile
->static_psymbols
,
2212 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2215 case DW_TAG_enumerator
:
2216 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2217 VAR_DOMAIN
, LOC_CONST
,
2218 (cu
->language
== language_cplus
2219 || cu
->language
== language_java
)
2220 ? &objfile
->global_psymbols
2221 : &objfile
->static_psymbols
,
2222 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2228 /* Check to see if we should scan the name for possible namespace
2229 info. Only do this if this is C++, if we don't have namespace
2230 debugging info in the file, if the psym is of an appropriate type
2231 (otherwise we'll have psym == NULL), and if we actually had a
2232 mangled name to begin with. */
2234 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2235 cases which do not set PSYM above? */
2237 if (cu
->language
== language_cplus
2238 && cu
->has_namespace_info
== 0
2240 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
2241 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
2244 if (built_actual_name
)
2245 xfree (actual_name
);
2248 /* Determine whether a die of type TAG living in a C++ class or
2249 namespace needs to have the name of the scope prepended to the
2250 name listed in the die. */
2253 pdi_needs_namespace (enum dwarf_tag tag
)
2257 case DW_TAG_namespace
:
2258 case DW_TAG_typedef
:
2259 case DW_TAG_class_type
:
2260 case DW_TAG_interface_type
:
2261 case DW_TAG_structure_type
:
2262 case DW_TAG_union_type
:
2263 case DW_TAG_enumeration_type
:
2264 case DW_TAG_enumerator
:
2271 /* Read a partial die corresponding to a namespace; also, add a symbol
2272 corresponding to that namespace to the symbol table. NAMESPACE is
2273 the name of the enclosing namespace. */
2276 add_partial_namespace (struct partial_die_info
*pdi
,
2277 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2278 int need_pc
, struct dwarf2_cu
*cu
)
2280 struct objfile
*objfile
= cu
->objfile
;
2282 /* Add a symbol for the namespace. */
2284 add_partial_symbol (pdi
, cu
);
2286 /* Now scan partial symbols in that namespace. */
2288 if (pdi
->has_children
)
2289 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2292 /* Read a partial die corresponding to a Fortran module. */
2295 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
2296 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
2298 /* Now scan partial symbols in that module.
2300 FIXME: Support the separate Fortran module namespaces. */
2302 if (pdi
->has_children
)
2303 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2306 /* Read a partial die corresponding to a subprogram and create a partial
2307 symbol for that subprogram. When the CU language allows it, this
2308 routine also defines a partial symbol for each nested subprogram
2309 that this subprogram contains.
2311 DIE my also be a lexical block, in which case we simply search
2312 recursively for suprograms defined inside that lexical block.
2313 Again, this is only performed when the CU language allows this
2314 type of definitions. */
2317 add_partial_subprogram (struct partial_die_info
*pdi
,
2318 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2319 int need_pc
, struct dwarf2_cu
*cu
)
2321 if (pdi
->tag
== DW_TAG_subprogram
)
2323 if (pdi
->has_pc_info
)
2325 if (pdi
->lowpc
< *lowpc
)
2326 *lowpc
= pdi
->lowpc
;
2327 if (pdi
->highpc
> *highpc
)
2328 *highpc
= pdi
->highpc
;
2332 struct objfile
*objfile
= cu
->objfile
;
2334 baseaddr
= ANOFFSET (objfile
->section_offsets
,
2335 SECT_OFF_TEXT (objfile
));
2336 addrmap_set_empty (objfile
->psymtabs_addrmap
,
2337 pdi
->lowpc
, pdi
->highpc
- 1,
2338 cu
->per_cu
->psymtab
);
2340 if (!pdi
->is_declaration
)
2341 add_partial_symbol (pdi
, cu
);
2345 if (! pdi
->has_children
)
2348 if (cu
->language
== language_ada
)
2350 pdi
= pdi
->die_child
;
2353 fixup_partial_die (pdi
, cu
);
2354 if (pdi
->tag
== DW_TAG_subprogram
2355 || pdi
->tag
== DW_TAG_lexical_block
)
2356 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
2357 pdi
= pdi
->die_sibling
;
2362 /* See if we can figure out if the class lives in a namespace. We do
2363 this by looking for a member function; its demangled name will
2364 contain namespace info, if there is any. */
2367 guess_structure_name (struct partial_die_info
*struct_pdi
,
2368 struct dwarf2_cu
*cu
)
2370 if ((cu
->language
== language_cplus
2371 || cu
->language
== language_java
)
2372 && cu
->has_namespace_info
== 0
2373 && struct_pdi
->has_children
)
2375 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2376 what template types look like, because the demangler
2377 frequently doesn't give the same name as the debug info. We
2378 could fix this by only using the demangled name to get the
2379 prefix (but see comment in read_structure_type). */
2381 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
2382 struct partial_die_info
*real_pdi
;
2384 /* If this DIE (this DIE's specification, if any) has a parent, then
2385 we should not do this. We'll prepend the parent's fully qualified
2386 name when we create the partial symbol. */
2388 real_pdi
= struct_pdi
;
2389 while (real_pdi
->has_specification
)
2390 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2392 if (real_pdi
->die_parent
!= NULL
)
2395 while (child_pdi
!= NULL
)
2397 if (child_pdi
->tag
== DW_TAG_subprogram
)
2399 char *actual_class_name
2400 = language_class_name_from_physname (cu
->language_defn
,
2402 if (actual_class_name
!= NULL
)
2405 = obsavestring (actual_class_name
,
2406 strlen (actual_class_name
),
2407 &cu
->comp_unit_obstack
);
2408 xfree (actual_class_name
);
2413 child_pdi
= child_pdi
->die_sibling
;
2418 /* Read a partial die corresponding to an enumeration type. */
2421 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2422 struct dwarf2_cu
*cu
)
2424 struct objfile
*objfile
= cu
->objfile
;
2425 bfd
*abfd
= objfile
->obfd
;
2426 struct partial_die_info
*pdi
;
2428 if (enum_pdi
->name
!= NULL
)
2429 add_partial_symbol (enum_pdi
, cu
);
2431 pdi
= enum_pdi
->die_child
;
2434 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2435 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2437 add_partial_symbol (pdi
, cu
);
2438 pdi
= pdi
->die_sibling
;
2442 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2443 Return the corresponding abbrev, or NULL if the number is zero (indicating
2444 an empty DIE). In either case *BYTES_READ will be set to the length of
2445 the initial number. */
2447 static struct abbrev_info
*
2448 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2449 struct dwarf2_cu
*cu
)
2451 bfd
*abfd
= cu
->objfile
->obfd
;
2452 unsigned int abbrev_number
;
2453 struct abbrev_info
*abbrev
;
2455 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2457 if (abbrev_number
== 0)
2460 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2463 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2464 bfd_get_filename (abfd
));
2470 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2471 pointer to the end of a series of DIEs, terminated by an empty
2472 DIE. Any children of the skipped DIEs will also be skipped. */
2475 skip_children (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2477 struct abbrev_info
*abbrev
;
2478 unsigned int bytes_read
;
2482 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2484 return info_ptr
+ bytes_read
;
2486 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
2490 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2491 should point just after the initial uleb128 of a DIE, and the
2492 abbrev corresponding to that skipped uleb128 should be passed in
2493 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2497 skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
2498 struct dwarf2_cu
*cu
)
2500 unsigned int bytes_read
;
2501 struct attribute attr
;
2502 bfd
*abfd
= cu
->objfile
->obfd
;
2503 unsigned int form
, i
;
2505 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2507 /* The only abbrev we care about is DW_AT_sibling. */
2508 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2510 read_attribute (&attr
, &abbrev
->attrs
[i
],
2511 abfd
, info_ptr
, cu
);
2512 if (attr
.form
== DW_FORM_ref_addr
)
2513 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2515 return dwarf2_per_objfile
->info
.buffer
2516 + dwarf2_get_ref_die_offset (&attr
);
2519 /* If it isn't DW_AT_sibling, skip this attribute. */
2520 form
= abbrev
->attrs
[i
].form
;
2525 case DW_FORM_ref_addr
:
2526 info_ptr
+= cu
->header
.addr_size
;
2545 case DW_FORM_string
:
2546 read_string (abfd
, info_ptr
, &bytes_read
);
2547 info_ptr
+= bytes_read
;
2550 info_ptr
+= cu
->header
.offset_size
;
2553 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2554 info_ptr
+= bytes_read
;
2556 case DW_FORM_block1
:
2557 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2559 case DW_FORM_block2
:
2560 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2562 case DW_FORM_block4
:
2563 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2567 case DW_FORM_ref_udata
:
2568 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2570 case DW_FORM_indirect
:
2571 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2572 info_ptr
+= bytes_read
;
2573 /* We need to continue parsing from here, so just go back to
2575 goto skip_attribute
;
2578 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2579 dwarf_form_name (form
),
2580 bfd_get_filename (abfd
));
2584 if (abbrev
->has_children
)
2585 return skip_children (info_ptr
, cu
);
2590 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2591 the next DIE after ORIG_PDI. */
2594 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, gdb_byte
*info_ptr
,
2595 bfd
*abfd
, struct dwarf2_cu
*cu
)
2597 /* Do we know the sibling already? */
2599 if (orig_pdi
->sibling
)
2600 return orig_pdi
->sibling
;
2602 /* Are there any children to deal with? */
2604 if (!orig_pdi
->has_children
)
2607 /* Skip the children the long way. */
2609 return skip_children (info_ptr
, cu
);
2612 /* Expand this partial symbol table into a full symbol table. */
2615 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2617 /* FIXME: This is barely more than a stub. */
2622 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2628 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2629 gdb_flush (gdb_stdout
);
2632 /* Restore our global data. */
2633 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2634 dwarf2_objfile_data_key
);
2636 /* If this psymtab is constructed from a debug-only objfile, the
2637 has_section_at_zero flag will not necessarily be correct. We
2638 can get the correct value for this flag by looking at the data
2639 associated with the (presumably stripped) associated objfile. */
2640 if (pst
->objfile
->separate_debug_objfile_backlink
)
2642 struct dwarf2_per_objfile
*dpo_backlink
2643 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
2644 dwarf2_objfile_data_key
);
2645 dwarf2_per_objfile
->has_section_at_zero
2646 = dpo_backlink
->has_section_at_zero
;
2649 psymtab_to_symtab_1 (pst
);
2651 /* Finish up the debug error message. */
2653 printf_filtered (_("done.\n"));
2658 /* Add PER_CU to the queue. */
2661 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2663 struct dwarf2_queue_item
*item
;
2666 item
= xmalloc (sizeof (*item
));
2667 item
->per_cu
= per_cu
;
2670 if (dwarf2_queue
== NULL
)
2671 dwarf2_queue
= item
;
2673 dwarf2_queue_tail
->next
= item
;
2675 dwarf2_queue_tail
= item
;
2677 /* Either PER_CU is the CU we want to process, or we're following a reference
2678 pointing into PER_CU. Either way, we need its DIEs now. */
2679 load_full_comp_unit (item
->per_cu
, objfile
);
2680 item
->per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
2681 dwarf2_per_objfile
->read_in_chain
= item
->per_cu
;
2684 /* Process the queue. */
2687 process_queue (struct objfile
*objfile
)
2689 struct dwarf2_queue_item
*item
, *next_item
;
2691 /* The queue starts out with one item, but following a DIE reference
2692 may load a new CU, adding it to the end of the queue. */
2693 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2695 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2696 process_full_comp_unit (item
->per_cu
);
2698 item
->per_cu
->queued
= 0;
2699 next_item
= item
->next
;
2703 dwarf2_queue_tail
= NULL
;
2706 /* Free all allocated queue entries. This function only releases anything if
2707 an error was thrown; if the queue was processed then it would have been
2708 freed as we went along. */
2711 dwarf2_release_queue (void *dummy
)
2713 struct dwarf2_queue_item
*item
, *last
;
2715 item
= dwarf2_queue
;
2718 /* Anything still marked queued is likely to be in an
2719 inconsistent state, so discard it. */
2720 if (item
->per_cu
->queued
)
2722 if (item
->per_cu
->cu
!= NULL
)
2723 free_one_cached_comp_unit (item
->per_cu
->cu
);
2724 item
->per_cu
->queued
= 0;
2732 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2735 /* Read in full symbols for PST, and anything it depends on. */
2738 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2740 struct dwarf2_per_cu_data
*per_cu
;
2741 struct cleanup
*back_to
;
2744 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2745 if (!pst
->dependencies
[i
]->readin
)
2747 /* Inform about additional files that need to be read in. */
2750 /* FIXME: i18n: Need to make this a single string. */
2751 fputs_filtered (" ", gdb_stdout
);
2753 fputs_filtered ("and ", gdb_stdout
);
2755 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2756 wrap_here (""); /* Flush output */
2757 gdb_flush (gdb_stdout
);
2759 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2762 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
2766 /* It's an include file, no symbols to read for it.
2767 Everything is in the parent symtab. */
2772 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2774 queue_comp_unit (per_cu
, pst
->objfile
);
2776 process_queue (pst
->objfile
);
2778 /* Age the cache, releasing compilation units that have not
2779 been used recently. */
2780 age_cached_comp_units ();
2782 do_cleanups (back_to
);
2785 /* Load the DIEs associated with PST and PER_CU into memory. */
2787 static struct dwarf2_cu
*
2788 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2790 bfd
*abfd
= objfile
->obfd
;
2791 struct dwarf2_cu
*cu
;
2792 unsigned int offset
;
2794 struct cleanup
*back_to
, *free_cu_cleanup
;
2795 struct attribute
*attr
;
2798 /* Set local variables from the partial symbol table info. */
2799 offset
= per_cu
->offset
;
2801 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
2803 cu
= xmalloc (sizeof (struct dwarf2_cu
));
2804 memset (cu
, 0, sizeof (struct dwarf2_cu
));
2806 /* If an error occurs while loading, release our storage. */
2807 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
2809 cu
->objfile
= objfile
;
2811 /* read in the comp_unit header */
2812 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
2814 /* Read the abbrevs for this compilation unit */
2815 dwarf2_read_abbrevs (abfd
, cu
);
2816 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2818 cu
->header
.offset
= offset
;
2820 cu
->per_cu
= per_cu
;
2822 cu
->type_hash
= per_cu
->type_hash
;
2824 /* We use this obstack for block values in dwarf_alloc_block. */
2825 obstack_init (&cu
->comp_unit_obstack
);
2827 cu
->dies
= read_comp_unit (info_ptr
, abfd
, cu
);
2829 /* We try not to read any attributes in this function, because not
2830 all objfiles needed for references have been loaded yet, and symbol
2831 table processing isn't initialized. But we have to set the CU language,
2832 or we won't be able to build types correctly. */
2833 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
2835 set_cu_language (DW_UNSND (attr
), cu
);
2837 set_cu_language (language_minimal
, cu
);
2839 do_cleanups (back_to
);
2841 /* We've successfully allocated this compilation unit. Let our caller
2842 clean it up when finished with it. */
2843 discard_cleanups (free_cu_cleanup
);
2848 /* Generate full symbol information for PST and CU, whose DIEs have
2849 already been loaded into memory. */
2852 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2854 struct partial_symtab
*pst
= per_cu
->psymtab
;
2855 struct dwarf2_cu
*cu
= per_cu
->cu
;
2856 struct objfile
*objfile
= pst
->objfile
;
2857 bfd
*abfd
= objfile
->obfd
;
2858 CORE_ADDR lowpc
, highpc
;
2859 struct symtab
*symtab
;
2860 struct cleanup
*back_to
;
2861 struct attribute
*attr
;
2864 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2867 back_to
= make_cleanup (really_free_pendings
, NULL
);
2869 cu
->list_in_scope
= &file_symbols
;
2871 /* Find the base address of the compilation unit for range lists and
2872 location lists. It will normally be specified by DW_AT_low_pc.
2873 In DWARF-3 draft 4, the base address could be overridden by
2874 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2875 compilation units with discontinuous ranges. */
2878 cu
->base_address
= 0;
2880 attr
= dwarf2_attr (cu
->dies
, DW_AT_entry_pc
, cu
);
2883 cu
->base_address
= DW_ADDR (attr
);
2888 attr
= dwarf2_attr (cu
->dies
, DW_AT_low_pc
, cu
);
2891 cu
->base_address
= DW_ADDR (attr
);
2896 /* Do line number decoding in read_file_scope () */
2897 process_die (cu
->dies
, cu
);
2899 /* Some compilers don't define a DW_AT_high_pc attribute for the
2900 compilation unit. If the DW_AT_high_pc is missing, synthesize
2901 it, by scanning the DIE's below the compilation unit. */
2902 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
2904 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2906 /* Set symtab language to language from DW_AT_language.
2907 If the compilation is from a C file generated by language preprocessors,
2908 do not set the language if it was already deduced by start_subfile. */
2910 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
2912 symtab
->language
= cu
->language
;
2914 pst
->symtab
= symtab
;
2917 do_cleanups (back_to
);
2920 /* Process a die and its children. */
2923 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2927 case DW_TAG_padding
:
2929 case DW_TAG_compile_unit
:
2930 read_file_scope (die
, cu
);
2932 case DW_TAG_subprogram
:
2933 read_func_scope (die
, cu
);
2935 case DW_TAG_inlined_subroutine
:
2936 /* FIXME: These are ignored for now.
2937 They could be used to set breakpoints on all inlined instances
2938 of a function and make GDB `next' properly over inlined functions. */
2940 case DW_TAG_lexical_block
:
2941 case DW_TAG_try_block
:
2942 case DW_TAG_catch_block
:
2943 read_lexical_block_scope (die
, cu
);
2945 case DW_TAG_class_type
:
2946 case DW_TAG_interface_type
:
2947 case DW_TAG_structure_type
:
2948 case DW_TAG_union_type
:
2949 process_structure_scope (die
, cu
);
2951 case DW_TAG_enumeration_type
:
2952 process_enumeration_scope (die
, cu
);
2955 /* These dies have a type, but processing them does not create
2956 a symbol or recurse to process the children. Therefore we can
2957 read them on-demand through read_type_die. */
2958 case DW_TAG_subroutine_type
:
2959 case DW_TAG_set_type
:
2960 case DW_TAG_array_type
:
2961 case DW_TAG_pointer_type
:
2962 case DW_TAG_ptr_to_member_type
:
2963 case DW_TAG_reference_type
:
2964 case DW_TAG_string_type
:
2967 case DW_TAG_base_type
:
2968 case DW_TAG_subrange_type
:
2969 case DW_TAG_typedef
:
2970 /* Add a typedef symbol for the type definition, if it has a
2972 new_symbol (die
, read_type_die (die
, cu
), cu
);
2974 case DW_TAG_common_block
:
2975 read_common_block (die
, cu
);
2977 case DW_TAG_common_inclusion
:
2979 case DW_TAG_namespace
:
2980 processing_has_namespace_info
= 1;
2981 read_namespace (die
, cu
);
2984 read_module (die
, cu
);
2986 case DW_TAG_imported_declaration
:
2987 case DW_TAG_imported_module
:
2988 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2989 information contained in these. DW_TAG_imported_declaration
2990 dies shouldn't have children; DW_TAG_imported_module dies
2991 shouldn't in the C++ case, but conceivably could in the
2993 processing_has_namespace_info
= 1;
2994 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
2995 dwarf_tag_name (die
->tag
));
2998 new_symbol (die
, NULL
, cu
);
3003 /* Return the fully qualified name of DIE, based on its DW_AT_name.
3004 If scope qualifiers are appropriate they will be added. The result
3005 will be allocated on the objfile_obstack, or NULL if the DIE does
3009 dwarf2_full_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
3011 struct attribute
*attr
;
3012 char *prefix
, *name
;
3013 struct ui_file
*buf
= NULL
;
3015 name
= dwarf2_name (die
, cu
);
3019 /* These are the only languages we know how to qualify names in. */
3020 if (cu
->language
!= language_cplus
3021 && cu
->language
!= language_java
)
3024 /* If no prefix is necessary for this type of DIE, return the
3025 unqualified name. The other three tags listed could be handled
3026 in pdi_needs_namespace, but that requires broader changes. */
3027 if (!pdi_needs_namespace (die
->tag
)
3028 && die
->tag
!= DW_TAG_subprogram
3029 && die
->tag
!= DW_TAG_variable
3030 && die
->tag
!= DW_TAG_member
)
3033 prefix
= determine_prefix (die
, cu
);
3034 if (*prefix
!= '\0')
3035 name
= typename_concat (&cu
->objfile
->objfile_obstack
, prefix
,
3042 initialize_cu_func_list (struct dwarf2_cu
*cu
)
3044 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
3048 free_cu_line_header (void *arg
)
3050 struct dwarf2_cu
*cu
= arg
;
3052 free_line_header (cu
->line_header
);
3053 cu
->line_header
= NULL
;
3057 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3059 struct objfile
*objfile
= cu
->objfile
;
3060 struct comp_unit_head
*cu_header
= &cu
->header
;
3061 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3062 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
3063 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
3064 struct attribute
*attr
;
3066 char *comp_dir
= NULL
;
3067 struct die_info
*child_die
;
3068 bfd
*abfd
= objfile
->obfd
;
3069 struct line_header
*line_header
= 0;
3072 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3074 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
3076 /* If we didn't find a lowpc, set it to highpc to avoid complaints
3077 from finish_block. */
3078 if (lowpc
== ((CORE_ADDR
) -1))
3083 /* Find the filename. Do not use dwarf2_name here, since the filename
3084 is not a source language identifier. */
3085 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3088 name
= DW_STRING (attr
);
3091 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
3093 comp_dir
= DW_STRING (attr
);
3094 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
3096 comp_dir
= ldirname (name
);
3097 if (comp_dir
!= NULL
)
3098 make_cleanup (xfree
, comp_dir
);
3100 if (comp_dir
!= NULL
)
3102 /* Irix 6.2 native cc prepends <machine>.: to the compilation
3103 directory, get rid of it. */
3104 char *cp
= strchr (comp_dir
, ':');
3106 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
3113 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
3116 set_cu_language (DW_UNSND (attr
), cu
);
3119 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
3121 cu
->producer
= DW_STRING (attr
);
3123 /* We assume that we're processing GCC output. */
3124 processing_gcc_compilation
= 2;
3126 processing_has_namespace_info
= 0;
3128 start_symtab (name
, comp_dir
, lowpc
);
3129 record_debugformat ("DWARF 2");
3130 record_producer (cu
->producer
);
3132 initialize_cu_func_list (cu
);
3134 /* Decode line number information if present. We do this before
3135 processing child DIEs, so that the line header table is available
3136 for DW_AT_decl_file. */
3137 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3140 unsigned int line_offset
= DW_UNSND (attr
);
3141 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3144 cu
->line_header
= line_header
;
3145 make_cleanup (free_cu_line_header
, cu
);
3146 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
3150 /* Process all dies in compilation unit. */
3151 if (die
->child
!= NULL
)
3153 child_die
= die
->child
;
3154 while (child_die
&& child_die
->tag
)
3156 process_die (child_die
, cu
);
3157 child_die
= sibling_die (child_die
);
3161 /* Decode macro information, if present. Dwarf 2 macro information
3162 refers to information in the line number info statement program
3163 header, so we can only read it if we've read the header
3165 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
3166 if (attr
&& line_header
)
3168 unsigned int macro_offset
= DW_UNSND (attr
);
3169 dwarf_decode_macros (line_header
, macro_offset
,
3170 comp_dir
, abfd
, cu
);
3172 do_cleanups (back_to
);
3176 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
3177 struct dwarf2_cu
*cu
)
3179 struct function_range
*thisfn
;
3181 thisfn
= (struct function_range
*)
3182 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
3183 thisfn
->name
= name
;
3184 thisfn
->lowpc
= lowpc
;
3185 thisfn
->highpc
= highpc
;
3186 thisfn
->seen_line
= 0;
3187 thisfn
->next
= NULL
;
3189 if (cu
->last_fn
== NULL
)
3190 cu
->first_fn
= thisfn
;
3192 cu
->last_fn
->next
= thisfn
;
3194 cu
->last_fn
= thisfn
;
3197 /* qsort helper for inherit_abstract_dies. */
3200 unsigned_int_compar (const void *ap
, const void *bp
)
3202 unsigned int a
= *(unsigned int *) ap
;
3203 unsigned int b
= *(unsigned int *) bp
;
3205 return (a
> b
) - (b
> a
);
3208 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
3209 Inherit only the children of the DW_AT_abstract_origin DIE not being already
3210 referenced by DW_AT_abstract_origin from the children of the current DIE. */
3213 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
3215 struct die_info
*child_die
;
3216 unsigned die_children_count
;
3217 /* CU offsets which were referenced by children of the current DIE. */
3219 unsigned *offsets_end
, *offsetp
;
3220 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
3221 struct die_info
*origin_die
;
3222 /* Iterator of the ORIGIN_DIE children. */
3223 struct die_info
*origin_child_die
;
3224 struct cleanup
*cleanups
;
3225 struct attribute
*attr
;
3227 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
3231 origin_die
= follow_die_ref (die
, attr
, &cu
);
3232 if (die
->tag
!= origin_die
->tag
)
3233 complaint (&symfile_complaints
,
3234 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
3235 die
->offset
, origin_die
->offset
);
3237 child_die
= die
->child
;
3238 die_children_count
= 0;
3239 while (child_die
&& child_die
->tag
)
3241 child_die
= sibling_die (child_die
);
3242 die_children_count
++;
3244 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
3245 cleanups
= make_cleanup (xfree
, offsets
);
3247 offsets_end
= offsets
;
3248 child_die
= die
->child
;
3249 while (child_die
&& child_die
->tag
)
3251 attr
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
3252 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
3253 counterpart may exist. */
3256 struct die_info
*child_origin_die
;
3258 child_origin_die
= follow_die_ref (child_die
, attr
, &cu
);
3259 if (child_die
->tag
!= child_origin_die
->tag
)
3260 complaint (&symfile_complaints
,
3261 _("Child DIE 0x%x and its abstract origin 0x%x have "
3262 "different tags"), child_die
->offset
,
3263 child_origin_die
->offset
);
3264 *offsets_end
++ = child_origin_die
->offset
;
3266 child_die
= sibling_die (child_die
);
3268 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
3269 unsigned_int_compar
);
3270 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
3271 if (offsetp
[-1] == *offsetp
)
3272 complaint (&symfile_complaints
, _("Multiple children of DIE 0x%x refer "
3273 "to DIE 0x%x as their abstract origin"),
3274 die
->offset
, *offsetp
);
3277 origin_child_die
= origin_die
->child
;
3278 while (origin_child_die
&& origin_child_die
->tag
)
3280 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
3281 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
3283 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
3285 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
3286 process_die (origin_child_die
, cu
);
3288 origin_child_die
= sibling_die (origin_child_die
);
3291 do_cleanups (cleanups
);
3295 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3297 struct objfile
*objfile
= cu
->objfile
;
3298 struct context_stack
*new;
3301 struct die_info
*child_die
;
3302 struct attribute
*attr
;
3305 struct block
*block
;
3307 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3309 name
= dwarf2_linkage_name (die
, cu
);
3311 /* Ignore functions with missing or empty names and functions with
3312 missing or invalid low and high pc attributes. */
3313 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3319 /* Record the function range for dwarf_decode_lines. */
3320 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
3322 new = push_context (0, lowpc
);
3323 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
3325 /* If there is a location expression for DW_AT_frame_base, record
3327 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3329 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3330 expression is being recorded directly in the function's symbol
3331 and not in a separate frame-base object. I guess this hack is
3332 to avoid adding some sort of frame-base adjunct/annex to the
3333 function's symbol :-(. The problem with doing this is that it
3334 results in a function symbol with a location expression that
3335 has nothing to do with the location of the function, ouch! The
3336 relationship should be: a function's symbol has-a frame base; a
3337 frame-base has-a location expression. */
3338 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3340 cu
->list_in_scope
= &local_symbols
;
3342 if (die
->child
!= NULL
)
3344 child_die
= die
->child
;
3345 while (child_die
&& child_die
->tag
)
3347 process_die (child_die
, cu
);
3348 child_die
= sibling_die (child_die
);
3352 inherit_abstract_dies (die
, cu
);
3354 new = pop_context ();
3355 /* Make a block for the local symbols within. */
3356 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3357 lowpc
, highpc
, objfile
);
3359 /* For C++, set the block's scope. */
3360 if (cu
->language
== language_cplus
)
3361 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
3362 determine_prefix (die
, cu
),
3363 processing_has_namespace_info
);
3365 /* If we have address ranges, record them. */
3366 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3368 /* In C++, we can have functions nested inside functions (e.g., when
3369 a function declares a class that has methods). This means that
3370 when we finish processing a function scope, we may need to go
3371 back to building a containing block's symbol lists. */
3372 local_symbols
= new->locals
;
3373 param_symbols
= new->params
;
3375 /* If we've finished processing a top-level function, subsequent
3376 symbols go in the file symbol list. */
3377 if (outermost_context_p ())
3378 cu
->list_in_scope
= &file_symbols
;
3381 /* Process all the DIES contained within a lexical block scope. Start
3382 a new scope, process the dies, and then close the scope. */
3385 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3387 struct objfile
*objfile
= cu
->objfile
;
3388 struct context_stack
*new;
3389 CORE_ADDR lowpc
, highpc
;
3390 struct die_info
*child_die
;
3393 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3395 /* Ignore blocks with missing or invalid low and high pc attributes. */
3396 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3397 as multiple lexical blocks? Handling children in a sane way would
3398 be nasty. Might be easier to properly extend generic blocks to
3400 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3405 push_context (0, lowpc
);
3406 if (die
->child
!= NULL
)
3408 child_die
= die
->child
;
3409 while (child_die
&& child_die
->tag
)
3411 process_die (child_die
, cu
);
3412 child_die
= sibling_die (child_die
);
3415 new = pop_context ();
3417 if (local_symbols
!= NULL
)
3420 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3423 /* Note that recording ranges after traversing children, as we
3424 do here, means that recording a parent's ranges entails
3425 walking across all its children's ranges as they appear in
3426 the address map, which is quadratic behavior.
3428 It would be nicer to record the parent's ranges before
3429 traversing its children, simply overriding whatever you find
3430 there. But since we don't even decide whether to create a
3431 block until after we've traversed its children, that's hard
3433 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3435 local_symbols
= new->locals
;
3438 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3439 Return 1 if the attributes are present and valid, otherwise, return 0.
3440 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3443 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
3444 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
3445 struct partial_symtab
*ranges_pst
)
3447 struct objfile
*objfile
= cu
->objfile
;
3448 struct comp_unit_head
*cu_header
= &cu
->header
;
3449 bfd
*obfd
= objfile
->obfd
;
3450 unsigned int addr_size
= cu_header
->addr_size
;
3451 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3452 /* Base address selection entry. */
3463 found_base
= cu
->base_known
;
3464 base
= cu
->base_address
;
3466 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
3468 complaint (&symfile_complaints
,
3469 _("Offset %d out of bounds for DW_AT_ranges attribute"),
3473 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
3475 /* Read in the largest possible address. */
3476 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
3477 if ((marker
& mask
) == mask
)
3479 /* If we found the largest possible address, then
3480 read the base address. */
3481 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3482 buffer
+= 2 * addr_size
;
3483 offset
+= 2 * addr_size
;
3489 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3493 CORE_ADDR range_beginning
, range_end
;
3495 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
3496 buffer
+= addr_size
;
3497 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
3498 buffer
+= addr_size
;
3499 offset
+= 2 * addr_size
;
3501 /* An end of list marker is a pair of zero addresses. */
3502 if (range_beginning
== 0 && range_end
== 0)
3503 /* Found the end of list entry. */
3506 /* Each base address selection entry is a pair of 2 values.
3507 The first is the largest possible address, the second is
3508 the base address. Check for a base address here. */
3509 if ((range_beginning
& mask
) == mask
)
3511 /* If we found the largest possible address, then
3512 read the base address. */
3513 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3520 /* We have no valid base address for the ranges
3522 complaint (&symfile_complaints
,
3523 _("Invalid .debug_ranges data (no base address)"));
3527 range_beginning
+= base
;
3530 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
3531 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3532 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
3535 /* FIXME: This is recording everything as a low-high
3536 segment of consecutive addresses. We should have a
3537 data structure for discontiguous block ranges
3541 low
= range_beginning
;
3547 if (range_beginning
< low
)
3548 low
= range_beginning
;
3549 if (range_end
> high
)
3555 /* If the first entry is an end-of-list marker, the range
3556 describes an empty scope, i.e. no instructions. */
3562 *high_return
= high
;
3566 /* Get low and high pc attributes from a die. Return 1 if the attributes
3567 are present and valid, otherwise, return 0. Return -1 if the range is
3568 discontinuous, i.e. derived from DW_AT_ranges information. */
3570 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
3571 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
3573 struct attribute
*attr
;
3578 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3581 high
= DW_ADDR (attr
);
3582 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3584 low
= DW_ADDR (attr
);
3586 /* Found high w/o low attribute. */
3589 /* Found consecutive range of addresses. */
3594 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3597 /* Value of the DW_AT_ranges attribute is the offset in the
3598 .debug_ranges section. */
3599 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, NULL
))
3601 /* Found discontinuous range of addresses. */
3609 /* When using the GNU linker, .gnu.linkonce. sections are used to
3610 eliminate duplicate copies of functions and vtables and such.
3611 The linker will arbitrarily choose one and discard the others.
3612 The AT_*_pc values for such functions refer to local labels in
3613 these sections. If the section from that file was discarded, the
3614 labels are not in the output, so the relocs get a value of 0.
3615 If this is a discarded function, mark the pc bounds as invalid,
3616 so that GDB will ignore it. */
3617 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3625 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
3626 its low and high PC addresses. Do nothing if these addresses could not
3627 be determined. Otherwise, set LOWPC to the low address if it is smaller,
3628 and HIGHPC to the high address if greater than HIGHPC. */
3631 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
3632 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3633 struct dwarf2_cu
*cu
)
3635 CORE_ADDR low
, high
;
3636 struct die_info
*child
= die
->child
;
3638 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
))
3640 *lowpc
= min (*lowpc
, low
);
3641 *highpc
= max (*highpc
, high
);
3644 /* If the language does not allow nested subprograms (either inside
3645 subprograms or lexical blocks), we're done. */
3646 if (cu
->language
!= language_ada
)
3649 /* Check all the children of the given DIE. If it contains nested
3650 subprograms, then check their pc bounds. Likewise, we need to
3651 check lexical blocks as well, as they may also contain subprogram
3653 while (child
&& child
->tag
)
3655 if (child
->tag
== DW_TAG_subprogram
3656 || child
->tag
== DW_TAG_lexical_block
)
3657 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
3658 child
= sibling_die (child
);
3662 /* Get the low and high pc's represented by the scope DIE, and store
3663 them in *LOWPC and *HIGHPC. If the correct values can't be
3664 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3667 get_scope_pc_bounds (struct die_info
*die
,
3668 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3669 struct dwarf2_cu
*cu
)
3671 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3672 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3673 CORE_ADDR current_low
, current_high
;
3675 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3677 best_low
= current_low
;
3678 best_high
= current_high
;
3682 struct die_info
*child
= die
->child
;
3684 while (child
&& child
->tag
)
3686 switch (child
->tag
) {
3687 case DW_TAG_subprogram
:
3688 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
3690 case DW_TAG_namespace
:
3691 /* FIXME: carlton/2004-01-16: Should we do this for
3692 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3693 that current GCC's always emit the DIEs corresponding
3694 to definitions of methods of classes as children of a
3695 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3696 the DIEs giving the declarations, which could be
3697 anywhere). But I don't see any reason why the
3698 standards says that they have to be there. */
3699 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3701 if (current_low
!= ((CORE_ADDR
) -1))
3703 best_low
= min (best_low
, current_low
);
3704 best_high
= max (best_high
, current_high
);
3712 child
= sibling_die (child
);
3717 *highpc
= best_high
;
3720 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
3723 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
3724 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
3726 struct attribute
*attr
;
3728 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3731 CORE_ADDR high
= DW_ADDR (attr
);
3732 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3735 CORE_ADDR low
= DW_ADDR (attr
);
3736 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
3740 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3743 bfd
*obfd
= cu
->objfile
->obfd
;
3745 /* The value of the DW_AT_ranges attribute is the offset of the
3746 address range list in the .debug_ranges section. */
3747 unsigned long offset
= DW_UNSND (attr
);
3748 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
3750 /* For some target architectures, but not others, the
3751 read_address function sign-extends the addresses it returns.
3752 To recognize base address selection entries, we need a
3754 unsigned int addr_size
= cu
->header
.addr_size
;
3755 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3757 /* The base address, to which the next pair is relative. Note
3758 that this 'base' is a DWARF concept: most entries in a range
3759 list are relative, to reduce the number of relocs against the
3760 debugging information. This is separate from this function's
3761 'baseaddr' argument, which GDB uses to relocate debugging
3762 information from a shared library based on the address at
3763 which the library was loaded. */
3764 CORE_ADDR base
= cu
->base_address
;
3765 int base_known
= cu
->base_known
;
3767 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
3769 complaint (&symfile_complaints
,
3770 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
3777 unsigned int bytes_read
;
3778 CORE_ADDR start
, end
;
3780 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3781 buffer
+= bytes_read
;
3782 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3783 buffer
+= bytes_read
;
3785 /* Did we find the end of the range list? */
3786 if (start
== 0 && end
== 0)
3789 /* Did we find a base address selection entry? */
3790 else if ((start
& base_select_mask
) == base_select_mask
)
3796 /* We found an ordinary address range. */
3801 complaint (&symfile_complaints
,
3802 _("Invalid .debug_ranges data (no base address)"));
3806 record_block_range (block
,
3807 baseaddr
+ base
+ start
,
3808 baseaddr
+ base
+ end
- 1);
3814 /* Add an aggregate field to the field list. */
3817 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3818 struct dwarf2_cu
*cu
)
3820 struct objfile
*objfile
= cu
->objfile
;
3821 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3822 struct nextfield
*new_field
;
3823 struct attribute
*attr
;
3825 char *fieldname
= "";
3827 /* Allocate a new field list entry and link it in. */
3828 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3829 make_cleanup (xfree
, new_field
);
3830 memset (new_field
, 0, sizeof (struct nextfield
));
3831 new_field
->next
= fip
->fields
;
3832 fip
->fields
= new_field
;
3835 /* Handle accessibility and virtuality of field.
3836 The default accessibility for members is public, the default
3837 accessibility for inheritance is private. */
3838 if (die
->tag
!= DW_TAG_inheritance
)
3839 new_field
->accessibility
= DW_ACCESS_public
;
3841 new_field
->accessibility
= DW_ACCESS_private
;
3842 new_field
->virtuality
= DW_VIRTUALITY_none
;
3844 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3846 new_field
->accessibility
= DW_UNSND (attr
);
3847 if (new_field
->accessibility
!= DW_ACCESS_public
)
3848 fip
->non_public_fields
= 1;
3849 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3851 new_field
->virtuality
= DW_UNSND (attr
);
3853 fp
= &new_field
->field
;
3855 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3857 /* Data member other than a C++ static data member. */
3859 /* Get type of field. */
3860 fp
->type
= die_type (die
, cu
);
3862 SET_FIELD_BITPOS (*fp
, 0);
3864 /* Get bit size of field (zero if none). */
3865 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3868 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3872 FIELD_BITSIZE (*fp
) = 0;
3875 /* Get bit offset of field. */
3876 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3881 if (attr_form_is_section_offset (attr
))
3883 dwarf2_complex_location_expr_complaint ();
3886 else if (attr_form_is_constant (attr
))
3887 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
3889 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
3891 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
3893 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3896 if (gdbarch_bits_big_endian (gdbarch
))
3898 /* For big endian bits, the DW_AT_bit_offset gives the
3899 additional bit offset from the MSB of the containing
3900 anonymous object to the MSB of the field. We don't
3901 have to do anything special since we don't need to
3902 know the size of the anonymous object. */
3903 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3907 /* For little endian bits, compute the bit offset to the
3908 MSB of the anonymous object, subtract off the number of
3909 bits from the MSB of the field to the MSB of the
3910 object, and then subtract off the number of bits of
3911 the field itself. The result is the bit offset of
3912 the LSB of the field. */
3914 int bit_offset
= DW_UNSND (attr
);
3916 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3919 /* The size of the anonymous object containing
3920 the bit field is explicit, so use the
3921 indicated size (in bytes). */
3922 anonymous_size
= DW_UNSND (attr
);
3926 /* The size of the anonymous object containing
3927 the bit field must be inferred from the type
3928 attribute of the data member containing the
3930 anonymous_size
= TYPE_LENGTH (fp
->type
);
3932 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
3933 - bit_offset
- FIELD_BITSIZE (*fp
);
3937 /* Get name of field. */
3938 fieldname
= dwarf2_name (die
, cu
);
3939 if (fieldname
== NULL
)
3942 /* The name is already allocated along with this objfile, so we don't
3943 need to duplicate it for the type. */
3944 fp
->name
= fieldname
;
3946 /* Change accessibility for artificial fields (e.g. virtual table
3947 pointer or virtual base class pointer) to private. */
3948 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
3950 new_field
->accessibility
= DW_ACCESS_private
;
3951 fip
->non_public_fields
= 1;
3954 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
3956 /* C++ static member. */
3958 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3959 is a declaration, but all versions of G++ as of this writing
3960 (so through at least 3.2.1) incorrectly generate
3961 DW_TAG_variable tags. */
3965 /* Get name of field. */
3966 fieldname
= dwarf2_name (die
, cu
);
3967 if (fieldname
== NULL
)
3970 /* Get physical name. */
3971 physname
= dwarf2_linkage_name (die
, cu
);
3973 /* The name is already allocated along with this objfile, so we don't
3974 need to duplicate it for the type. */
3975 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
3976 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3977 FIELD_NAME (*fp
) = fieldname
;
3979 else if (die
->tag
== DW_TAG_inheritance
)
3981 /* C++ base class field. */
3982 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3984 SET_FIELD_BITPOS (*fp
, decode_locdesc (DW_BLOCK (attr
), cu
)
3986 FIELD_BITSIZE (*fp
) = 0;
3987 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3988 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
3989 fip
->nbaseclasses
++;
3993 /* Create the vector of fields, and attach it to the type. */
3996 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3997 struct dwarf2_cu
*cu
)
3999 int nfields
= fip
->nfields
;
4001 /* Record the field count, allocate space for the array of fields,
4002 and create blank accessibility bitfields if necessary. */
4003 TYPE_NFIELDS (type
) = nfields
;
4004 TYPE_FIELDS (type
) = (struct field
*)
4005 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
4006 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
4008 if (fip
->non_public_fields
)
4010 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4012 TYPE_FIELD_PRIVATE_BITS (type
) =
4013 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4014 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
4016 TYPE_FIELD_PROTECTED_BITS (type
) =
4017 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4018 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
4020 TYPE_FIELD_IGNORE_BITS (type
) =
4021 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4022 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
4025 /* If the type has baseclasses, allocate and clear a bit vector for
4026 TYPE_FIELD_VIRTUAL_BITS. */
4027 if (fip
->nbaseclasses
)
4029 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
4030 unsigned char *pointer
;
4032 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4033 pointer
= TYPE_ALLOC (type
, num_bytes
);
4034 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
4035 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
4036 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
4039 /* Copy the saved-up fields into the field vector. Start from the head
4040 of the list, adding to the tail of the field array, so that they end
4041 up in the same order in the array in which they were added to the list. */
4042 while (nfields
-- > 0)
4044 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
4045 switch (fip
->fields
->accessibility
)
4047 case DW_ACCESS_private
:
4048 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
4051 case DW_ACCESS_protected
:
4052 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
4055 case DW_ACCESS_public
:
4059 /* Unknown accessibility. Complain and treat it as public. */
4061 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
4062 fip
->fields
->accessibility
);
4066 if (nfields
< fip
->nbaseclasses
)
4068 switch (fip
->fields
->virtuality
)
4070 case DW_VIRTUALITY_virtual
:
4071 case DW_VIRTUALITY_pure_virtual
:
4072 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
4076 fip
->fields
= fip
->fields
->next
;
4080 /* Add a member function to the proper fieldlist. */
4083 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
4084 struct type
*type
, struct dwarf2_cu
*cu
)
4086 struct objfile
*objfile
= cu
->objfile
;
4087 struct attribute
*attr
;
4088 struct fnfieldlist
*flp
;
4090 struct fn_field
*fnp
;
4093 struct nextfnfield
*new_fnfield
;
4094 struct type
*this_type
;
4096 /* Get name of member function. */
4097 fieldname
= dwarf2_name (die
, cu
);
4098 if (fieldname
== NULL
)
4101 /* Get the mangled name. */
4102 physname
= dwarf2_linkage_name (die
, cu
);
4104 /* Look up member function name in fieldlist. */
4105 for (i
= 0; i
< fip
->nfnfields
; i
++)
4107 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
4111 /* Create new list element if necessary. */
4112 if (i
< fip
->nfnfields
)
4113 flp
= &fip
->fnfieldlists
[i
];
4116 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4118 fip
->fnfieldlists
= (struct fnfieldlist
*)
4119 xrealloc (fip
->fnfieldlists
,
4120 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
4121 * sizeof (struct fnfieldlist
));
4122 if (fip
->nfnfields
== 0)
4123 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
4125 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
4126 flp
->name
= fieldname
;
4132 /* Create a new member function field and chain it to the field list
4134 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
4135 make_cleanup (xfree
, new_fnfield
);
4136 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
4137 new_fnfield
->next
= flp
->head
;
4138 flp
->head
= new_fnfield
;
4141 /* Fill in the member function field info. */
4142 fnp
= &new_fnfield
->fnfield
;
4143 /* The name is already allocated along with this objfile, so we don't
4144 need to duplicate it for the type. */
4145 fnp
->physname
= physname
? physname
: "";
4146 fnp
->type
= alloc_type (objfile
);
4147 this_type
= read_type_die (die
, cu
);
4148 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
4150 int nparams
= TYPE_NFIELDS (this_type
);
4152 /* TYPE is the domain of this method, and THIS_TYPE is the type
4153 of the method itself (TYPE_CODE_METHOD). */
4154 smash_to_method_type (fnp
->type
, type
,
4155 TYPE_TARGET_TYPE (this_type
),
4156 TYPE_FIELDS (this_type
),
4157 TYPE_NFIELDS (this_type
),
4158 TYPE_VARARGS (this_type
));
4160 /* Handle static member functions.
4161 Dwarf2 has no clean way to discern C++ static and non-static
4162 member functions. G++ helps GDB by marking the first
4163 parameter for non-static member functions (which is the
4164 this pointer) as artificial. We obtain this information
4165 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
4166 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
4167 fnp
->voffset
= VOFFSET_STATIC
;
4170 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
4173 /* Get fcontext from DW_AT_containing_type if present. */
4174 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4175 fnp
->fcontext
= die_containing_type (die
, cu
);
4177 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
4178 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
4180 /* Get accessibility. */
4181 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
4184 switch (DW_UNSND (attr
))
4186 case DW_ACCESS_private
:
4187 fnp
->is_private
= 1;
4189 case DW_ACCESS_protected
:
4190 fnp
->is_protected
= 1;
4195 /* Check for artificial methods. */
4196 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
4197 if (attr
&& DW_UNSND (attr
) != 0)
4198 fnp
->is_artificial
= 1;
4200 /* Get index in virtual function table if it is a virtual member function. */
4201 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
4204 /* Support the .debug_loc offsets */
4205 if (attr_form_is_block (attr
))
4207 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
4209 else if (attr_form_is_section_offset (attr
))
4211 dwarf2_complex_location_expr_complaint ();
4215 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
4221 /* Create the vector of member function fields, and attach it to the type. */
4224 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
4225 struct dwarf2_cu
*cu
)
4227 struct fnfieldlist
*flp
;
4228 int total_length
= 0;
4231 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4232 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
4233 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
4235 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
4237 struct nextfnfield
*nfp
= flp
->head
;
4238 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
4241 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
4242 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
4243 fn_flp
->fn_fields
= (struct fn_field
*)
4244 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
4245 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
4246 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
4248 total_length
+= flp
->length
;
4251 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
4252 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
4255 /* Returns non-zero if NAME is the name of a vtable member in CU's
4256 language, zero otherwise. */
4258 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
4260 static const char vptr
[] = "_vptr";
4261 static const char vtable
[] = "vtable";
4263 /* Look for the C++ and Java forms of the vtable. */
4264 if ((cu
->language
== language_java
4265 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
4266 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
4267 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
4273 /* GCC outputs unnamed structures that are really pointers to member
4274 functions, with the ABI-specified layout. If DIE (from CU) describes
4275 such a structure, set its type, and return nonzero. Otherwise return
4278 GCC shouldn't do this; it should just output pointer to member DIEs.
4279 This is GCC PR debug/28767. */
4281 static struct type
*
4282 quirk_gcc_member_function_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
)
4284 struct objfile
*objfile
= cu
->objfile
;
4286 struct die_info
*pfn_die
, *delta_die
;
4287 struct attribute
*pfn_name
, *delta_name
;
4288 struct type
*pfn_type
, *domain_type
;
4290 /* Check for a structure with no name and two children. */
4291 if (die
->tag
!= DW_TAG_structure_type
4292 || dwarf2_attr (die
, DW_AT_name
, cu
) != NULL
4293 || die
->child
== NULL
4294 || die
->child
->sibling
== NULL
4295 || (die
->child
->sibling
->sibling
!= NULL
4296 && die
->child
->sibling
->sibling
->tag
!= DW_TAG_padding
))
4299 /* Check for __pfn and __delta members. */
4300 pfn_die
= die
->child
;
4301 pfn_name
= dwarf2_attr (pfn_die
, DW_AT_name
, cu
);
4302 if (pfn_die
->tag
!= DW_TAG_member
4304 || DW_STRING (pfn_name
) == NULL
4305 || strcmp ("__pfn", DW_STRING (pfn_name
)) != 0)
4308 delta_die
= pfn_die
->sibling
;
4309 delta_name
= dwarf2_attr (delta_die
, DW_AT_name
, cu
);
4310 if (delta_die
->tag
!= DW_TAG_member
4311 || delta_name
== NULL
4312 || DW_STRING (delta_name
) == NULL
4313 || strcmp ("__delta", DW_STRING (delta_name
)) != 0)
4316 /* Find the type of the method. */
4317 pfn_type
= die_type (pfn_die
, cu
);
4318 if (pfn_type
== NULL
4319 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
4320 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
4323 /* Look for the "this" argument. */
4324 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
4325 if (TYPE_NFIELDS (pfn_type
) == 0
4326 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
4329 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
4330 type
= alloc_type (objfile
);
4331 smash_to_method_type (type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
4332 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
4333 TYPE_VARARGS (pfn_type
));
4334 type
= lookup_methodptr_type (type
);
4335 return set_die_type (die
, type
, cu
);
4338 /* Called when we find the DIE that starts a structure or union scope
4339 (definition) to process all dies that define the members of the
4342 NOTE: we need to call struct_type regardless of whether or not the
4343 DIE has an at_name attribute, since it might be an anonymous
4344 structure or union. This gets the type entered into our set of
4347 However, if the structure is incomplete (an opaque struct/union)
4348 then suppress creating a symbol table entry for it since gdb only
4349 wants to find the one with the complete definition. Note that if
4350 it is complete, we just call new_symbol, which does it's own
4351 checking about whether the struct/union is anonymous or not (and
4352 suppresses creating a symbol table entry itself). */
4354 static struct type
*
4355 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4357 struct objfile
*objfile
= cu
->objfile
;
4359 struct attribute
*attr
;
4361 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4363 type
= quirk_gcc_member_function_pointer (die
, cu
);
4367 type
= alloc_type (objfile
);
4368 INIT_CPLUS_SPECIFIC (type
);
4369 name
= dwarf2_name (die
, cu
);
4372 if (cu
->language
== language_cplus
4373 || cu
->language
== language_java
)
4375 const char *new_prefix
= determine_class_name (die
, cu
);
4376 TYPE_TAG_NAME (type
) = (char *) new_prefix
;
4380 /* The name is already allocated along with this objfile, so
4381 we don't need to duplicate it for the type. */
4382 TYPE_TAG_NAME (type
) = name
;
4386 if (die
->tag
== DW_TAG_structure_type
)
4388 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
4390 else if (die
->tag
== DW_TAG_union_type
)
4392 TYPE_CODE (type
) = TYPE_CODE_UNION
;
4396 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
4398 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
4401 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4404 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4408 TYPE_LENGTH (type
) = 0;
4411 TYPE_STUB_SUPPORTED (type
) = 1;
4412 if (die_is_declaration (die
, cu
))
4413 TYPE_STUB (type
) = 1;
4415 /* We need to add the type field to the die immediately so we don't
4416 infinitely recurse when dealing with pointers to the structure
4417 type within the structure itself. */
4418 set_die_type (die
, type
, cu
);
4420 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
4422 struct field_info fi
;
4423 struct die_info
*child_die
;
4425 memset (&fi
, 0, sizeof (struct field_info
));
4427 child_die
= die
->child
;
4429 while (child_die
&& child_die
->tag
)
4431 if (child_die
->tag
== DW_TAG_member
4432 || child_die
->tag
== DW_TAG_variable
)
4434 /* NOTE: carlton/2002-11-05: A C++ static data member
4435 should be a DW_TAG_member that is a declaration, but
4436 all versions of G++ as of this writing (so through at
4437 least 3.2.1) incorrectly generate DW_TAG_variable
4438 tags for them instead. */
4439 dwarf2_add_field (&fi
, child_die
, cu
);
4441 else if (child_die
->tag
== DW_TAG_subprogram
)
4443 /* C++ member function. */
4444 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
4446 else if (child_die
->tag
== DW_TAG_inheritance
)
4448 /* C++ base class field. */
4449 dwarf2_add_field (&fi
, child_die
, cu
);
4451 child_die
= sibling_die (child_die
);
4454 /* Attach fields and member functions to the type. */
4456 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
4459 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
4461 /* Get the type which refers to the base class (possibly this
4462 class itself) which contains the vtable pointer for the current
4463 class from the DW_AT_containing_type attribute. */
4465 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4467 struct type
*t
= die_containing_type (die
, cu
);
4469 TYPE_VPTR_BASETYPE (type
) = t
;
4474 /* Our own class provides vtbl ptr. */
4475 for (i
= TYPE_NFIELDS (t
) - 1;
4476 i
>= TYPE_N_BASECLASSES (t
);
4479 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
4481 if (is_vtable_name (fieldname
, cu
))
4483 TYPE_VPTR_FIELDNO (type
) = i
;
4488 /* Complain if virtual function table field not found. */
4489 if (i
< TYPE_N_BASECLASSES (t
))
4490 complaint (&symfile_complaints
,
4491 _("virtual function table pointer not found when defining class '%s'"),
4492 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
4497 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
4500 else if (cu
->producer
4501 && strncmp (cu
->producer
,
4502 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
4504 /* The IBM XLC compiler does not provide direct indication
4505 of the containing type, but the vtable pointer is
4506 always named __vfp. */
4510 for (i
= TYPE_NFIELDS (type
) - 1;
4511 i
>= TYPE_N_BASECLASSES (type
);
4514 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
4516 TYPE_VPTR_FIELDNO (type
) = i
;
4517 TYPE_VPTR_BASETYPE (type
) = type
;
4525 do_cleanups (back_to
);
4530 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4532 struct objfile
*objfile
= cu
->objfile
;
4533 struct die_info
*child_die
= die
->child
;
4534 struct type
*this_type
;
4536 this_type
= get_die_type (die
, cu
);
4537 if (this_type
== NULL
)
4538 this_type
= read_structure_type (die
, cu
);
4540 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
4541 snapshots) has been known to create a die giving a declaration
4542 for a class that has, as a child, a die giving a definition for a
4543 nested class. So we have to process our children even if the
4544 current die is a declaration. Normally, of course, a declaration
4545 won't have any children at all. */
4547 while (child_die
!= NULL
&& child_die
->tag
)
4549 if (child_die
->tag
== DW_TAG_member
4550 || child_die
->tag
== DW_TAG_variable
4551 || child_die
->tag
== DW_TAG_inheritance
)
4556 process_die (child_die
, cu
);
4558 child_die
= sibling_die (child_die
);
4561 /* Do not consider external references. According to the DWARF standard,
4562 these DIEs are identified by the fact that they have no byte_size
4563 attribute, and a declaration attribute. */
4564 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
4565 || !die_is_declaration (die
, cu
))
4566 new_symbol (die
, this_type
, cu
);
4569 /* Given a DW_AT_enumeration_type die, set its type. We do not
4570 complete the type's fields yet, or create any symbols. */
4572 static struct type
*
4573 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4575 struct objfile
*objfile
= cu
->objfile
;
4577 struct attribute
*attr
;
4580 type
= alloc_type (objfile
);
4582 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4583 name
= dwarf2_full_name (die
, cu
);
4585 TYPE_TAG_NAME (type
) = (char *) name
;
4587 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4590 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4594 TYPE_LENGTH (type
) = 0;
4597 /* The enumeration DIE can be incomplete. In Ada, any type can be
4598 declared as private in the package spec, and then defined only
4599 inside the package body. Such types are known as Taft Amendment
4600 Types. When another package uses such a type, an incomplete DIE
4601 may be generated by the compiler. */
4602 if (die_is_declaration (die
, cu
))
4603 TYPE_STUB (type
) = 1;
4605 return set_die_type (die
, type
, cu
);
4608 /* Determine the name of the type represented by DIE, which should be
4609 a named C++ or Java compound type. Return the name in question,
4610 allocated on the objfile obstack. */
4613 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
4615 const char *new_prefix
= NULL
;
4617 /* If we don't have namespace debug info, guess the name by trying
4618 to demangle the names of members, just like we did in
4619 guess_structure_name. */
4620 if (!processing_has_namespace_info
)
4622 struct die_info
*child
;
4624 for (child
= die
->child
;
4625 child
!= NULL
&& child
->tag
!= 0;
4626 child
= sibling_die (child
))
4628 if (child
->tag
== DW_TAG_subprogram
)
4631 = language_class_name_from_physname (cu
->language_defn
,
4635 if (phys_prefix
!= NULL
)
4638 = obsavestring (phys_prefix
, strlen (phys_prefix
),
4639 &cu
->objfile
->objfile_obstack
);
4640 xfree (phys_prefix
);
4647 if (new_prefix
== NULL
)
4648 new_prefix
= dwarf2_full_name (die
, cu
);
4653 /* Given a pointer to a die which begins an enumeration, process all
4654 the dies that define the members of the enumeration, and create the
4655 symbol for the enumeration type.
4657 NOTE: We reverse the order of the element list. */
4660 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4662 struct objfile
*objfile
= cu
->objfile
;
4663 struct die_info
*child_die
;
4664 struct field
*fields
;
4667 int unsigned_enum
= 1;
4669 struct type
*this_type
;
4673 this_type
= get_die_type (die
, cu
);
4674 if (this_type
== NULL
)
4675 this_type
= read_enumeration_type (die
, cu
);
4676 if (die
->child
!= NULL
)
4678 child_die
= die
->child
;
4679 while (child_die
&& child_die
->tag
)
4681 if (child_die
->tag
!= DW_TAG_enumerator
)
4683 process_die (child_die
, cu
);
4687 name
= dwarf2_name (child_die
, cu
);
4690 sym
= new_symbol (child_die
, this_type
, cu
);
4691 if (SYMBOL_VALUE (sym
) < 0)
4694 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4696 fields
= (struct field
*)
4698 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
4699 * sizeof (struct field
));
4702 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
4703 FIELD_TYPE (fields
[num_fields
]) = NULL
;
4704 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
4705 FIELD_BITSIZE (fields
[num_fields
]) = 0;
4711 child_die
= sibling_die (child_die
);
4716 TYPE_NFIELDS (this_type
) = num_fields
;
4717 TYPE_FIELDS (this_type
) = (struct field
*)
4718 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
4719 memcpy (TYPE_FIELDS (this_type
), fields
,
4720 sizeof (struct field
) * num_fields
);
4724 TYPE_UNSIGNED (this_type
) = 1;
4727 new_symbol (die
, this_type
, cu
);
4730 /* Extract all information from a DW_TAG_array_type DIE and put it in
4731 the DIE's type field. For now, this only handles one dimensional
4734 static struct type
*
4735 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4737 struct objfile
*objfile
= cu
->objfile
;
4738 struct die_info
*child_die
;
4739 struct type
*type
= NULL
;
4740 struct type
*element_type
, *range_type
, *index_type
;
4741 struct type
**range_types
= NULL
;
4742 struct attribute
*attr
;
4744 struct cleanup
*back_to
;
4747 element_type
= die_type (die
, cu
);
4749 /* Irix 6.2 native cc creates array types without children for
4750 arrays with unspecified length. */
4751 if (die
->child
== NULL
)
4753 index_type
= builtin_type_int32
;
4754 range_type
= create_range_type (NULL
, index_type
, 0, -1);
4755 type
= create_array_type (NULL
, element_type
, range_type
);
4756 return set_die_type (die
, type
, cu
);
4759 back_to
= make_cleanup (null_cleanup
, NULL
);
4760 child_die
= die
->child
;
4761 while (child_die
&& child_die
->tag
)
4763 if (child_die
->tag
== DW_TAG_subrange_type
)
4765 struct type
*child_type
= read_type_die (child_die
, cu
);
4766 if (child_type
!= NULL
)
4768 /* The range type was succesfully read. Save it for
4769 the array type creation. */
4770 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
4772 range_types
= (struct type
**)
4773 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
4774 * sizeof (struct type
*));
4776 make_cleanup (free_current_contents
, &range_types
);
4778 range_types
[ndim
++] = child_type
;
4781 child_die
= sibling_die (child_die
);
4784 /* Dwarf2 dimensions are output from left to right, create the
4785 necessary array types in backwards order. */
4787 type
= element_type
;
4789 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
4793 type
= create_array_type (NULL
, type
, range_types
[i
++]);
4798 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
4801 /* Understand Dwarf2 support for vector types (like they occur on
4802 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4803 array type. This is not part of the Dwarf2/3 standard yet, but a
4804 custom vendor extension. The main difference between a regular
4805 array and the vector variant is that vectors are passed by value
4807 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4809 make_vector_type (type
);
4811 name
= dwarf2_name (die
, cu
);
4813 TYPE_NAME (type
) = name
;
4815 do_cleanups (back_to
);
4817 /* Install the type in the die. */
4818 return set_die_type (die
, type
, cu
);
4821 static enum dwarf_array_dim_ordering
4822 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4824 struct attribute
*attr
;
4826 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4828 if (attr
) return DW_SND (attr
);
4831 GNU F77 is a special case, as at 08/2004 array type info is the
4832 opposite order to the dwarf2 specification, but data is still
4833 laid out as per normal fortran.
4835 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4839 if (cu
->language
== language_fortran
&&
4840 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4842 return DW_ORD_row_major
;
4845 switch (cu
->language_defn
->la_array_ordering
)
4847 case array_column_major
:
4848 return DW_ORD_col_major
;
4849 case array_row_major
:
4851 return DW_ORD_row_major
;
4855 /* Extract all information from a DW_TAG_set_type DIE and put it in
4856 the DIE's type field. */
4858 static struct type
*
4859 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4861 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
4863 return set_die_type (die
, set_type
, cu
);
4866 /* First cut: install each common block member as a global variable. */
4869 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4871 struct die_info
*child_die
;
4872 struct attribute
*attr
;
4874 CORE_ADDR base
= (CORE_ADDR
) 0;
4876 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4879 /* Support the .debug_loc offsets */
4880 if (attr_form_is_block (attr
))
4882 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4884 else if (attr_form_is_section_offset (attr
))
4886 dwarf2_complex_location_expr_complaint ();
4890 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4891 "common block member");
4894 if (die
->child
!= NULL
)
4896 child_die
= die
->child
;
4897 while (child_die
&& child_die
->tag
)
4899 sym
= new_symbol (child_die
, NULL
, cu
);
4900 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4903 SYMBOL_VALUE_ADDRESS (sym
) =
4904 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4905 add_symbol_to_list (sym
, &global_symbols
);
4907 child_die
= sibling_die (child_die
);
4912 /* Create a type for a C++ namespace. */
4914 static struct type
*
4915 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4917 struct objfile
*objfile
= cu
->objfile
;
4918 const char *previous_prefix
, *name
;
4922 /* For extensions, reuse the type of the original namespace. */
4923 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
4925 struct die_info
*ext_die
;
4926 struct dwarf2_cu
*ext_cu
= cu
;
4927 ext_die
= dwarf2_extension (die
, &ext_cu
);
4928 type
= read_type_die (ext_die
, ext_cu
);
4929 return set_die_type (die
, type
, cu
);
4932 name
= namespace_name (die
, &is_anonymous
, cu
);
4934 /* Now build the name of the current namespace. */
4936 previous_prefix
= determine_prefix (die
, cu
);
4937 if (previous_prefix
[0] != '\0')
4938 name
= typename_concat (&objfile
->objfile_obstack
,
4939 previous_prefix
, name
, cu
);
4941 /* Create the type. */
4942 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
4944 TYPE_NAME (type
) = (char *) name
;
4945 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4947 set_die_type (die
, type
, cu
);
4952 /* Read a C++ namespace. */
4955 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4957 struct objfile
*objfile
= cu
->objfile
;
4961 /* Add a symbol associated to this if we haven't seen the namespace
4962 before. Also, add a using directive if it's an anonymous
4965 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
4969 type
= read_type_die (die
, cu
);
4970 new_symbol (die
, type
, cu
);
4972 name
= namespace_name (die
, &is_anonymous
, cu
);
4975 const char *previous_prefix
= determine_prefix (die
, cu
);
4976 cp_add_using_directive (TYPE_NAME (type
),
4977 strlen (previous_prefix
),
4978 strlen (TYPE_NAME (type
)));
4982 if (die
->child
!= NULL
)
4984 struct die_info
*child_die
= die
->child
;
4986 while (child_die
&& child_die
->tag
)
4988 process_die (child_die
, cu
);
4989 child_die
= sibling_die (child_die
);
4994 /* Read a Fortran module. */
4997 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
4999 struct die_info
*child_die
= die
->child
;
5001 /* FIXME: Support the separate Fortran module namespaces. */
5003 while (child_die
&& child_die
->tag
)
5005 process_die (child_die
, cu
);
5006 child_die
= sibling_die (child_die
);
5010 /* Return the name of the namespace represented by DIE. Set
5011 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
5015 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
5017 struct die_info
*current_die
;
5018 const char *name
= NULL
;
5020 /* Loop through the extensions until we find a name. */
5022 for (current_die
= die
;
5023 current_die
!= NULL
;
5024 current_die
= dwarf2_extension (die
, &cu
))
5026 name
= dwarf2_name (current_die
, cu
);
5031 /* Is it an anonymous namespace? */
5033 *is_anonymous
= (name
== NULL
);
5035 name
= "(anonymous namespace)";
5040 /* Extract all information from a DW_TAG_pointer_type DIE and add to
5041 the user defined type vector. */
5043 static struct type
*
5044 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5046 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5047 struct comp_unit_head
*cu_header
= &cu
->header
;
5049 struct attribute
*attr_byte_size
;
5050 struct attribute
*attr_address_class
;
5051 int byte_size
, addr_class
;
5053 type
= lookup_pointer_type (die_type (die
, cu
));
5055 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5057 byte_size
= DW_UNSND (attr_byte_size
);
5059 byte_size
= cu_header
->addr_size
;
5061 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
5062 if (attr_address_class
)
5063 addr_class
= DW_UNSND (attr_address_class
);
5065 addr_class
= DW_ADDR_none
;
5067 /* If the pointer size or address class is different than the
5068 default, create a type variant marked as such and set the
5069 length accordingly. */
5070 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
5072 if (gdbarch_address_class_type_flags_p (gdbarch
))
5076 type_flags
= gdbarch_address_class_type_flags
5077 (gdbarch
, byte_size
, addr_class
);
5078 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
5080 type
= make_type_with_address_space (type
, type_flags
);
5082 else if (TYPE_LENGTH (type
) != byte_size
)
5084 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
5087 /* Should we also complain about unhandled address classes? */
5091 TYPE_LENGTH (type
) = byte_size
;
5092 return set_die_type (die
, type
, cu
);
5095 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
5096 the user defined type vector. */
5098 static struct type
*
5099 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5101 struct objfile
*objfile
= cu
->objfile
;
5103 struct type
*to_type
;
5104 struct type
*domain
;
5106 to_type
= die_type (die
, cu
);
5107 domain
= die_containing_type (die
, cu
);
5109 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
5110 type
= lookup_methodptr_type (to_type
);
5112 type
= lookup_memberptr_type (to_type
, domain
);
5114 return set_die_type (die
, type
, cu
);
5117 /* Extract all information from a DW_TAG_reference_type DIE and add to
5118 the user defined type vector. */
5120 static struct type
*
5121 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5123 struct comp_unit_head
*cu_header
= &cu
->header
;
5125 struct attribute
*attr
;
5127 type
= lookup_reference_type (die_type (die
, cu
));
5128 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5131 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5135 TYPE_LENGTH (type
) = cu_header
->addr_size
;
5137 return set_die_type (die
, type
, cu
);
5140 static struct type
*
5141 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5143 struct type
*base_type
, *cv_type
;
5145 base_type
= die_type (die
, cu
);
5146 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
5147 return set_die_type (die
, cv_type
, cu
);
5150 static struct type
*
5151 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5153 struct type
*base_type
, *cv_type
;
5155 base_type
= die_type (die
, cu
);
5156 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
5157 return set_die_type (die
, cv_type
, cu
);
5160 /* Extract all information from a DW_TAG_string_type DIE and add to
5161 the user defined type vector. It isn't really a user defined type,
5162 but it behaves like one, with other DIE's using an AT_user_def_type
5163 attribute to reference it. */
5165 static struct type
*
5166 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5168 struct objfile
*objfile
= cu
->objfile
;
5169 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5170 struct type
*type
, *range_type
, *index_type
, *char_type
;
5171 struct attribute
*attr
;
5172 unsigned int length
;
5174 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
5177 length
= DW_UNSND (attr
);
5181 /* check for the DW_AT_byte_size attribute */
5182 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5185 length
= DW_UNSND (attr
);
5193 index_type
= builtin_type_int32
;
5194 range_type
= create_range_type (NULL
, index_type
, 1, length
);
5195 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
5196 type
= create_string_type (NULL
, char_type
, range_type
);
5198 return set_die_type (die
, type
, cu
);
5201 /* Handle DIES due to C code like:
5205 int (*funcp)(int a, long l);
5209 ('funcp' generates a DW_TAG_subroutine_type DIE)
5212 static struct type
*
5213 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5215 struct type
*type
; /* Type that this function returns */
5216 struct type
*ftype
; /* Function that returns above type */
5217 struct attribute
*attr
;
5219 type
= die_type (die
, cu
);
5220 ftype
= make_function_type (type
, (struct type
**) 0, cu
->objfile
);
5222 /* All functions in C++, Pascal and Java have prototypes. */
5223 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
5224 if ((attr
&& (DW_UNSND (attr
) != 0))
5225 || cu
->language
== language_cplus
5226 || cu
->language
== language_java
5227 || cu
->language
== language_pascal
)
5228 TYPE_PROTOTYPED (ftype
) = 1;
5230 /* Store the calling convention in the type if it's available in
5231 the subroutine die. Otherwise set the calling convention to
5232 the default value DW_CC_normal. */
5233 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
5234 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
5236 if (die
->child
!= NULL
)
5238 struct die_info
*child_die
;
5242 /* Count the number of parameters.
5243 FIXME: GDB currently ignores vararg functions, but knows about
5244 vararg member functions. */
5245 child_die
= die
->child
;
5246 while (child_die
&& child_die
->tag
)
5248 if (child_die
->tag
== DW_TAG_formal_parameter
)
5250 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
5251 TYPE_VARARGS (ftype
) = 1;
5252 child_die
= sibling_die (child_die
);
5255 /* Allocate storage for parameters and fill them in. */
5256 TYPE_NFIELDS (ftype
) = nparams
;
5257 TYPE_FIELDS (ftype
) = (struct field
*)
5258 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
5260 child_die
= die
->child
;
5261 while (child_die
&& child_die
->tag
)
5263 if (child_die
->tag
== DW_TAG_formal_parameter
)
5265 /* Dwarf2 has no clean way to discern C++ static and non-static
5266 member functions. G++ helps GDB by marking the first
5267 parameter for non-static member functions (which is the
5268 this pointer) as artificial. We pass this information
5269 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
5270 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
5272 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
5274 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
5275 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
5278 child_die
= sibling_die (child_die
);
5282 return set_die_type (die
, ftype
, cu
);
5285 static struct type
*
5286 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
5288 struct objfile
*objfile
= cu
->objfile
;
5289 struct attribute
*attr
;
5290 const char *name
= NULL
;
5291 struct type
*this_type
;
5293 name
= dwarf2_full_name (die
, cu
);
5294 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
5295 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
5296 TYPE_NAME (this_type
) = (char *) name
;
5297 set_die_type (die
, this_type
, cu
);
5298 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
5302 /* Find a representation of a given base type and install
5303 it in the TYPE field of the die. */
5305 static struct type
*
5306 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5308 struct objfile
*objfile
= cu
->objfile
;
5310 struct attribute
*attr
;
5311 int encoding
= 0, size
= 0;
5313 enum type_code code
= TYPE_CODE_INT
;
5315 struct type
*target_type
= NULL
;
5317 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
5320 encoding
= DW_UNSND (attr
);
5322 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5325 size
= DW_UNSND (attr
);
5327 name
= dwarf2_name (die
, cu
);
5330 complaint (&symfile_complaints
,
5331 _("DW_AT_name missing from DW_TAG_base_type"));
5336 case DW_ATE_address
:
5337 /* Turn DW_ATE_address into a void * pointer. */
5338 code
= TYPE_CODE_PTR
;
5339 type_flags
|= TYPE_FLAG_UNSIGNED
;
5340 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
5342 case DW_ATE_boolean
:
5343 code
= TYPE_CODE_BOOL
;
5344 type_flags
|= TYPE_FLAG_UNSIGNED
;
5346 case DW_ATE_complex_float
:
5347 code
= TYPE_CODE_COMPLEX
;
5348 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
5350 case DW_ATE_decimal_float
:
5351 code
= TYPE_CODE_DECFLOAT
;
5354 code
= TYPE_CODE_FLT
;
5358 case DW_ATE_unsigned
:
5359 type_flags
|= TYPE_FLAG_UNSIGNED
;
5361 case DW_ATE_signed_char
:
5362 if (cu
->language
== language_ada
|| cu
->language
== language_m2
5363 || cu
->language
== language_pascal
)
5364 code
= TYPE_CODE_CHAR
;
5366 case DW_ATE_unsigned_char
:
5367 if (cu
->language
== language_ada
|| cu
->language
== language_m2
5368 || cu
->language
== language_pascal
)
5369 code
= TYPE_CODE_CHAR
;
5370 type_flags
|= TYPE_FLAG_UNSIGNED
;
5373 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
5374 dwarf_type_encoding_name (encoding
));
5378 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
5379 TYPE_NAME (type
) = name
;
5380 TYPE_TARGET_TYPE (type
) = target_type
;
5382 if (name
&& strcmp (name
, "char") == 0)
5383 TYPE_NOSIGN (type
) = 1;
5385 return set_die_type (die
, type
, cu
);
5388 /* Read the given DW_AT_subrange DIE. */
5390 static struct type
*
5391 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5393 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5394 struct type
*base_type
;
5395 struct type
*range_type
;
5396 struct attribute
*attr
;
5401 base_type
= die_type (die
, cu
);
5402 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
5404 complaint (&symfile_complaints
,
5405 _("DW_AT_type missing from DW_TAG_subrange_type"));
5407 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
5408 0, NULL
, cu
->objfile
);
5411 if (cu
->language
== language_fortran
)
5413 /* FORTRAN implies a lower bound of 1, if not given. */
5417 /* FIXME: For variable sized arrays either of these could be
5418 a variable rather than a constant value. We'll allow it,
5419 but we don't know how to handle it. */
5420 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
5422 low
= dwarf2_get_attr_constant_value (attr
, 0);
5424 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
5427 if (attr
->form
== DW_FORM_block1
)
5429 /* GCC encodes arrays with unspecified or dynamic length
5430 with a DW_FORM_block1 attribute.
5431 FIXME: GDB does not yet know how to handle dynamic
5432 arrays properly, treat them as arrays with unspecified
5435 FIXME: jimb/2003-09-22: GDB does not really know
5436 how to handle arrays of unspecified length
5437 either; we just represent them as zero-length
5438 arrays. Choose an appropriate upper bound given
5439 the lower bound we've computed above. */
5443 high
= dwarf2_get_attr_constant_value (attr
, 1);
5446 range_type
= create_range_type (NULL
, base_type
, low
, high
);
5448 name
= dwarf2_name (die
, cu
);
5450 TYPE_NAME (range_type
) = name
;
5452 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5454 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
5456 return set_die_type (die
, range_type
, cu
);
5459 static struct type
*
5460 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5464 /* For now, we only support the C meaning of an unspecified type: void. */
5466 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
5467 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
5469 return set_die_type (die
, type
, cu
);
5472 /* Trivial hash function for die_info: the hash value of a DIE
5473 is its offset in .debug_info for this objfile. */
5476 die_hash (const void *item
)
5478 const struct die_info
*die
= item
;
5482 /* Trivial comparison function for die_info structures: two DIEs
5483 are equal if they have the same offset. */
5486 die_eq (const void *item_lhs
, const void *item_rhs
)
5488 const struct die_info
*die_lhs
= item_lhs
;
5489 const struct die_info
*die_rhs
= item_rhs
;
5490 return die_lhs
->offset
== die_rhs
->offset
;
5493 /* Read a whole compilation unit into a linked list of dies. */
5495 static struct die_info
*
5496 read_comp_unit (gdb_byte
*info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
5499 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5503 &cu
->comp_unit_obstack
,
5504 hashtab_obstack_allocate
,
5505 dummy_obstack_deallocate
);
5507 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
5510 /* Main entry point for reading a DIE and all children.
5511 Read the DIE and dump it if requested. */
5513 static struct die_info
*
5514 read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
5515 struct dwarf2_cu
*cu
,
5516 gdb_byte
**new_info_ptr
,
5517 struct die_info
*parent
)
5519 struct die_info
*result
= read_die_and_children_1 (info_ptr
, abfd
, cu
,
5520 new_info_ptr
, parent
);
5522 if (dwarf2_die_debug
)
5524 fprintf_unfiltered (gdb_stdlog
, "Read die from .debug_info:\n");
5525 dump_die (result
, dwarf2_die_debug
);
5531 /* Read a single die and all its descendents. Set the die's sibling
5532 field to NULL; set other fields in the die correctly, and set all
5533 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
5534 location of the info_ptr after reading all of those dies. PARENT
5535 is the parent of the die in question. */
5537 static struct die_info
*
5538 read_die_and_children_1 (gdb_byte
*info_ptr
, bfd
*abfd
,
5539 struct dwarf2_cu
*cu
,
5540 gdb_byte
**new_info_ptr
,
5541 struct die_info
*parent
)
5543 struct die_info
*die
;
5547 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
5550 *new_info_ptr
= cur_ptr
;
5553 store_in_ref_table (die
, cu
);
5557 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
5563 *new_info_ptr
= cur_ptr
;
5566 die
->sibling
= NULL
;
5567 die
->parent
= parent
;
5571 /* Read a die, all of its descendents, and all of its siblings; set
5572 all of the fields of all of the dies correctly. Arguments are as
5573 in read_die_and_children. */
5575 static struct die_info
*
5576 read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
5577 struct dwarf2_cu
*cu
,
5578 gdb_byte
**new_info_ptr
,
5579 struct die_info
*parent
)
5581 struct die_info
*first_die
, *last_sibling
;
5585 first_die
= last_sibling
= NULL
;
5589 struct die_info
*die
5590 = read_die_and_children_1 (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
5594 *new_info_ptr
= cur_ptr
;
5601 last_sibling
->sibling
= die
;
5607 /* In DWARF version 2, the description of the debugging information is
5608 stored in a separate .debug_abbrev section. Before we read any
5609 dies from a section we read in all abbreviations and install them
5610 in a hash table. This function also sets flags in CU describing
5611 the data found in the abbrev table. */
5614 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
5616 struct comp_unit_head
*cu_header
= &cu
->header
;
5617 gdb_byte
*abbrev_ptr
;
5618 struct abbrev_info
*cur_abbrev
;
5619 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
5620 unsigned int abbrev_form
, hash_number
;
5621 struct attr_abbrev
*cur_attrs
;
5622 unsigned int allocated_attrs
;
5624 /* Initialize dwarf2 abbrevs */
5625 obstack_init (&cu
->abbrev_obstack
);
5626 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
5628 * sizeof (struct abbrev_info
*)));
5629 memset (cu
->dwarf2_abbrevs
, 0,
5630 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
5632 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
5633 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5634 abbrev_ptr
+= bytes_read
;
5636 allocated_attrs
= ATTR_ALLOC_CHUNK
;
5637 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
5639 /* loop until we reach an abbrev number of 0 */
5640 while (abbrev_number
)
5642 cur_abbrev
= dwarf_alloc_abbrev (cu
);
5644 /* read in abbrev header */
5645 cur_abbrev
->number
= abbrev_number
;
5646 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5647 abbrev_ptr
+= bytes_read
;
5648 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
5651 if (cur_abbrev
->tag
== DW_TAG_namespace
)
5652 cu
->has_namespace_info
= 1;
5654 /* now read in declarations */
5655 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5656 abbrev_ptr
+= bytes_read
;
5657 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5658 abbrev_ptr
+= bytes_read
;
5661 if (cur_abbrev
->num_attrs
== allocated_attrs
)
5663 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
5665 = xrealloc (cur_attrs
, (allocated_attrs
5666 * sizeof (struct attr_abbrev
)));
5669 /* Record whether this compilation unit might have
5670 inter-compilation-unit references. If we don't know what form
5671 this attribute will have, then it might potentially be a
5672 DW_FORM_ref_addr, so we conservatively expect inter-CU
5675 if (abbrev_form
== DW_FORM_ref_addr
5676 || abbrev_form
== DW_FORM_indirect
)
5677 cu
->has_form_ref_addr
= 1;
5679 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
5680 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
5681 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5682 abbrev_ptr
+= bytes_read
;
5683 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5684 abbrev_ptr
+= bytes_read
;
5687 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
5688 (cur_abbrev
->num_attrs
5689 * sizeof (struct attr_abbrev
)));
5690 memcpy (cur_abbrev
->attrs
, cur_attrs
,
5691 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
5693 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
5694 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
5695 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
5697 /* Get next abbreviation.
5698 Under Irix6 the abbreviations for a compilation unit are not
5699 always properly terminated with an abbrev number of 0.
5700 Exit loop if we encounter an abbreviation which we have
5701 already read (which means we are about to read the abbreviations
5702 for the next compile unit) or if the end of the abbreviation
5703 table is reached. */
5704 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
5705 >= dwarf2_per_objfile
->abbrev
.size
)
5707 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5708 abbrev_ptr
+= bytes_read
;
5709 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
5716 /* Release the memory used by the abbrev table for a compilation unit. */
5719 dwarf2_free_abbrev_table (void *ptr_to_cu
)
5721 struct dwarf2_cu
*cu
= ptr_to_cu
;
5723 obstack_free (&cu
->abbrev_obstack
, NULL
);
5724 cu
->dwarf2_abbrevs
= NULL
;
5727 /* Lookup an abbrev_info structure in the abbrev hash table. */
5729 static struct abbrev_info
*
5730 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
5732 unsigned int hash_number
;
5733 struct abbrev_info
*abbrev
;
5735 hash_number
= number
% ABBREV_HASH_SIZE
;
5736 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
5740 if (abbrev
->number
== number
)
5743 abbrev
= abbrev
->next
;
5748 /* Returns nonzero if TAG represents a type that we might generate a partial
5752 is_type_tag_for_partial (int tag
)
5757 /* Some types that would be reasonable to generate partial symbols for,
5758 that we don't at present. */
5759 case DW_TAG_array_type
:
5760 case DW_TAG_file_type
:
5761 case DW_TAG_ptr_to_member_type
:
5762 case DW_TAG_set_type
:
5763 case DW_TAG_string_type
:
5764 case DW_TAG_subroutine_type
:
5766 case DW_TAG_base_type
:
5767 case DW_TAG_class_type
:
5768 case DW_TAG_interface_type
:
5769 case DW_TAG_enumeration_type
:
5770 case DW_TAG_structure_type
:
5771 case DW_TAG_subrange_type
:
5772 case DW_TAG_typedef
:
5773 case DW_TAG_union_type
:
5780 /* Load all DIEs that are interesting for partial symbols into memory. */
5782 static struct partial_die_info
*
5783 load_partial_dies (bfd
*abfd
, gdb_byte
*info_ptr
, int building_psymtab
,
5784 struct dwarf2_cu
*cu
)
5786 struct partial_die_info
*part_die
;
5787 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
5788 struct abbrev_info
*abbrev
;
5789 unsigned int bytes_read
;
5790 unsigned int load_all
= 0;
5792 int nesting_level
= 1;
5797 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
5801 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5805 &cu
->comp_unit_obstack
,
5806 hashtab_obstack_allocate
,
5807 dummy_obstack_deallocate
);
5809 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5810 sizeof (struct partial_die_info
));
5814 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5816 /* A NULL abbrev means the end of a series of children. */
5819 if (--nesting_level
== 0)
5821 /* PART_DIE was probably the last thing allocated on the
5822 comp_unit_obstack, so we could call obstack_free
5823 here. We don't do that because the waste is small,
5824 and will be cleaned up when we're done with this
5825 compilation unit. This way, we're also more robust
5826 against other users of the comp_unit_obstack. */
5829 info_ptr
+= bytes_read
;
5830 last_die
= parent_die
;
5831 parent_die
= parent_die
->die_parent
;
5835 /* Check whether this DIE is interesting enough to save. Normally
5836 we would not be interested in members here, but there may be
5837 later variables referencing them via DW_AT_specification (for
5840 && !is_type_tag_for_partial (abbrev
->tag
)
5841 && abbrev
->tag
!= DW_TAG_enumerator
5842 && abbrev
->tag
!= DW_TAG_subprogram
5843 && abbrev
->tag
!= DW_TAG_lexical_block
5844 && abbrev
->tag
!= DW_TAG_variable
5845 && abbrev
->tag
!= DW_TAG_namespace
5846 && abbrev
->tag
!= DW_TAG_member
)
5848 /* Otherwise we skip to the next sibling, if any. */
5849 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5853 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5854 abfd
, info_ptr
, cu
);
5856 /* This two-pass algorithm for processing partial symbols has a
5857 high cost in cache pressure. Thus, handle some simple cases
5858 here which cover the majority of C partial symbols. DIEs
5859 which neither have specification tags in them, nor could have
5860 specification tags elsewhere pointing at them, can simply be
5861 processed and discarded.
5863 This segment is also optional; scan_partial_symbols and
5864 add_partial_symbol will handle these DIEs if we chain
5865 them in normally. When compilers which do not emit large
5866 quantities of duplicate debug information are more common,
5867 this code can probably be removed. */
5869 /* Any complete simple types at the top level (pretty much all
5870 of them, for a language without namespaces), can be processed
5872 if (parent_die
== NULL
5873 && part_die
->has_specification
== 0
5874 && part_die
->is_declaration
== 0
5875 && (part_die
->tag
== DW_TAG_typedef
5876 || part_die
->tag
== DW_TAG_base_type
5877 || part_die
->tag
== DW_TAG_subrange_type
))
5879 if (building_psymtab
&& part_die
->name
!= NULL
)
5880 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5881 VAR_DOMAIN
, LOC_TYPEDEF
,
5882 &cu
->objfile
->static_psymbols
,
5883 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5884 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5888 /* If we're at the second level, and we're an enumerator, and
5889 our parent has no specification (meaning possibly lives in a
5890 namespace elsewhere), then we can add the partial symbol now
5891 instead of queueing it. */
5892 if (part_die
->tag
== DW_TAG_enumerator
5893 && parent_die
!= NULL
5894 && parent_die
->die_parent
== NULL
5895 && parent_die
->tag
== DW_TAG_enumeration_type
5896 && parent_die
->has_specification
== 0)
5898 if (part_die
->name
== NULL
)
5899 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5900 else if (building_psymtab
)
5901 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5902 VAR_DOMAIN
, LOC_CONST
,
5903 (cu
->language
== language_cplus
5904 || cu
->language
== language_java
)
5905 ? &cu
->objfile
->global_psymbols
5906 : &cu
->objfile
->static_psymbols
,
5907 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5909 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5913 /* We'll save this DIE so link it in. */
5914 part_die
->die_parent
= parent_die
;
5915 part_die
->die_sibling
= NULL
;
5916 part_die
->die_child
= NULL
;
5918 if (last_die
&& last_die
== parent_die
)
5919 last_die
->die_child
= part_die
;
5921 last_die
->die_sibling
= part_die
;
5923 last_die
= part_die
;
5925 if (first_die
== NULL
)
5926 first_die
= part_die
;
5928 /* Maybe add the DIE to the hash table. Not all DIEs that we
5929 find interesting need to be in the hash table, because we
5930 also have the parent/sibling/child chains; only those that we
5931 might refer to by offset later during partial symbol reading.
5933 For now this means things that might have be the target of a
5934 DW_AT_specification, DW_AT_abstract_origin, or
5935 DW_AT_extension. DW_AT_extension will refer only to
5936 namespaces; DW_AT_abstract_origin refers to functions (and
5937 many things under the function DIE, but we do not recurse
5938 into function DIEs during partial symbol reading) and
5939 possibly variables as well; DW_AT_specification refers to
5940 declarations. Declarations ought to have the DW_AT_declaration
5941 flag. It happens that GCC forgets to put it in sometimes, but
5942 only for functions, not for types.
5944 Adding more things than necessary to the hash table is harmless
5945 except for the performance cost. Adding too few will result in
5946 wasted time in find_partial_die, when we reread the compilation
5947 unit with load_all_dies set. */
5950 || abbrev
->tag
== DW_TAG_subprogram
5951 || abbrev
->tag
== DW_TAG_variable
5952 || abbrev
->tag
== DW_TAG_namespace
5953 || part_die
->is_declaration
)
5957 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
5958 part_die
->offset
, INSERT
);
5962 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5963 sizeof (struct partial_die_info
));
5965 /* For some DIEs we want to follow their children (if any). For C
5966 we have no reason to follow the children of structures; for other
5967 languages we have to, both so that we can get at method physnames
5968 to infer fully qualified class names, and for DW_AT_specification.
5970 For Ada, we need to scan the children of subprograms and lexical
5971 blocks as well because Ada allows the definition of nested
5972 entities that could be interesting for the debugger, such as
5973 nested subprograms for instance. */
5974 if (last_die
->has_children
5976 || last_die
->tag
== DW_TAG_namespace
5977 || last_die
->tag
== DW_TAG_enumeration_type
5978 || (cu
->language
!= language_c
5979 && (last_die
->tag
== DW_TAG_class_type
5980 || last_die
->tag
== DW_TAG_interface_type
5981 || last_die
->tag
== DW_TAG_structure_type
5982 || last_die
->tag
== DW_TAG_union_type
))
5983 || (cu
->language
== language_ada
5984 && (last_die
->tag
== DW_TAG_subprogram
5985 || last_die
->tag
== DW_TAG_lexical_block
))))
5988 parent_die
= last_die
;
5992 /* Otherwise we skip to the next sibling, if any. */
5993 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
5995 /* Back to the top, do it again. */
5999 /* Read a minimal amount of information into the minimal die structure. */
6002 read_partial_die (struct partial_die_info
*part_die
,
6003 struct abbrev_info
*abbrev
,
6004 unsigned int abbrev_len
, bfd
*abfd
,
6005 gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6007 unsigned int bytes_read
, i
;
6008 struct attribute attr
;
6009 int has_low_pc_attr
= 0;
6010 int has_high_pc_attr
= 0;
6011 CORE_ADDR base_address
= 0;
6015 base_address_low_pc
,
6016 /* Overrides BASE_ADDRESS_LOW_PC. */
6017 base_address_entry_pc
6019 base_address_type
= base_address_none
;
6021 memset (part_die
, 0, sizeof (struct partial_die_info
));
6023 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
6025 info_ptr
+= abbrev_len
;
6030 part_die
->tag
= abbrev
->tag
;
6031 part_die
->has_children
= abbrev
->has_children
;
6033 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6035 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
6037 /* Store the data if it is of an attribute we want to keep in a
6038 partial symbol table. */
6042 switch (part_die
->tag
)
6044 case DW_TAG_compile_unit
:
6045 /* Compilation units have a DW_AT_name that is a filename, not
6046 a source language identifier. */
6047 case DW_TAG_enumeration_type
:
6048 case DW_TAG_enumerator
:
6049 /* These tags always have simple identifiers already; no need
6050 to canonicalize them. */
6051 part_die
->name
= DW_STRING (&attr
);
6055 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
6056 &cu
->comp_unit_obstack
);
6060 case DW_AT_comp_dir
:
6061 if (part_die
->dirname
== NULL
)
6062 part_die
->dirname
= DW_STRING (&attr
);
6064 case DW_AT_MIPS_linkage_name
:
6065 part_die
->name
= DW_STRING (&attr
);
6068 has_low_pc_attr
= 1;
6069 part_die
->lowpc
= DW_ADDR (&attr
);
6070 if (part_die
->tag
== DW_TAG_compile_unit
6071 && base_address_type
< base_address_low_pc
)
6073 base_address
= DW_ADDR (&attr
);
6074 base_address_type
= base_address_low_pc
;
6078 has_high_pc_attr
= 1;
6079 part_die
->highpc
= DW_ADDR (&attr
);
6081 case DW_AT_entry_pc
:
6082 if (part_die
->tag
== DW_TAG_compile_unit
6083 && base_address_type
< base_address_entry_pc
)
6085 base_address
= DW_ADDR (&attr
);
6086 base_address_type
= base_address_entry_pc
;
6090 if (part_die
->tag
== DW_TAG_compile_unit
)
6092 cu
->ranges_offset
= DW_UNSND (&attr
);
6093 cu
->has_ranges_offset
= 1;
6096 case DW_AT_location
:
6097 /* Support the .debug_loc offsets */
6098 if (attr_form_is_block (&attr
))
6100 part_die
->locdesc
= DW_BLOCK (&attr
);
6102 else if (attr_form_is_section_offset (&attr
))
6104 dwarf2_complex_location_expr_complaint ();
6108 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
6109 "partial symbol information");
6112 case DW_AT_language
:
6113 part_die
->language
= DW_UNSND (&attr
);
6115 case DW_AT_external
:
6116 part_die
->is_external
= DW_UNSND (&attr
);
6118 case DW_AT_declaration
:
6119 part_die
->is_declaration
= DW_UNSND (&attr
);
6122 part_die
->has_type
= 1;
6124 case DW_AT_abstract_origin
:
6125 case DW_AT_specification
:
6126 case DW_AT_extension
:
6127 part_die
->has_specification
= 1;
6128 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
6131 /* Ignore absolute siblings, they might point outside of
6132 the current compile unit. */
6133 if (attr
.form
== DW_FORM_ref_addr
)
6134 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
6136 part_die
->sibling
= dwarf2_per_objfile
->info
.buffer
6137 + dwarf2_get_ref_die_offset (&attr
);
6139 case DW_AT_stmt_list
:
6140 part_die
->has_stmt_list
= 1;
6141 part_die
->line_offset
= DW_UNSND (&attr
);
6143 case DW_AT_byte_size
:
6144 part_die
->has_byte_size
= 1;
6146 case DW_AT_calling_convention
:
6147 /* DWARF doesn't provide a way to identify a program's source-level
6148 entry point. DW_AT_calling_convention attributes are only meant
6149 to describe functions' calling conventions.
6151 However, because it's a necessary piece of information in
6152 Fortran, and because DW_CC_program is the only piece of debugging
6153 information whose definition refers to a 'main program' at all,
6154 several compilers have begun marking Fortran main programs with
6155 DW_CC_program --- even when those functions use the standard
6156 calling conventions.
6158 So until DWARF specifies a way to provide this information and
6159 compilers pick up the new representation, we'll support this
6161 if (DW_UNSND (&attr
) == DW_CC_program
6162 && cu
->language
== language_fortran
)
6163 set_main_name (part_die
->name
);
6170 /* When using the GNU linker, .gnu.linkonce. sections are used to
6171 eliminate duplicate copies of functions and vtables and such.
6172 The linker will arbitrarily choose one and discard the others.
6173 The AT_*_pc values for such functions refer to local labels in
6174 these sections. If the section from that file was discarded, the
6175 labels are not in the output, so the relocs get a value of 0.
6176 If this is a discarded function, mark the pc bounds as invalid,
6177 so that GDB will ignore it. */
6178 if (has_low_pc_attr
&& has_high_pc_attr
6179 && part_die
->lowpc
< part_die
->highpc
6180 && (part_die
->lowpc
!= 0
6181 || dwarf2_per_objfile
->has_section_at_zero
))
6182 part_die
->has_pc_info
= 1;
6184 if (base_address_type
!= base_address_none
&& !cu
->base_known
)
6186 gdb_assert (part_die
->tag
== DW_TAG_compile_unit
);
6188 cu
->base_address
= base_address
;
6194 /* Find a cached partial DIE at OFFSET in CU. */
6196 static struct partial_die_info
*
6197 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
6199 struct partial_die_info
*lookup_die
= NULL
;
6200 struct partial_die_info part_die
;
6202 part_die
.offset
= offset
;
6203 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
6208 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
6210 static struct partial_die_info
*
6211 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
6213 struct dwarf2_per_cu_data
*per_cu
= NULL
;
6214 struct partial_die_info
*pd
= NULL
;
6216 if (offset_in_cu_p (&cu
->header
, offset
))
6218 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6223 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
6225 if (per_cu
->cu
== NULL
)
6227 load_comp_unit (per_cu
, cu
->objfile
);
6228 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6229 dwarf2_per_objfile
->read_in_chain
= per_cu
;
6232 per_cu
->cu
->last_used
= 0;
6233 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6235 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
6237 struct cleanup
*back_to
;
6238 struct partial_die_info comp_unit_die
;
6239 struct abbrev_info
*abbrev
;
6240 unsigned int bytes_read
;
6243 per_cu
->load_all_dies
= 1;
6245 /* Re-read the DIEs. */
6246 back_to
= make_cleanup (null_cleanup
, 0);
6247 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
6249 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
6250 back_to
= make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
6252 info_ptr
= (dwarf2_per_objfile
->info
.buffer
6253 + per_cu
->cu
->header
.offset
6254 + per_cu
->cu
->header
.first_die_offset
);
6255 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
6256 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
6257 per_cu
->cu
->objfile
->obfd
, info_ptr
,
6259 if (comp_unit_die
.has_children
)
6260 load_partial_dies (per_cu
->cu
->objfile
->obfd
, info_ptr
, 0, per_cu
->cu
);
6261 do_cleanups (back_to
);
6263 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6267 internal_error (__FILE__
, __LINE__
,
6268 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
6269 offset
, bfd_get_filename (cu
->objfile
->obfd
));
6273 /* Adjust PART_DIE before generating a symbol for it. This function
6274 may set the is_external flag or change the DIE's name. */
6277 fixup_partial_die (struct partial_die_info
*part_die
,
6278 struct dwarf2_cu
*cu
)
6280 /* If we found a reference attribute and the DIE has no name, try
6281 to find a name in the referred to DIE. */
6283 if (part_die
->name
== NULL
&& part_die
->has_specification
)
6285 struct partial_die_info
*spec_die
;
6287 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
6289 fixup_partial_die (spec_die
, cu
);
6293 part_die
->name
= spec_die
->name
;
6295 /* Copy DW_AT_external attribute if it is set. */
6296 if (spec_die
->is_external
)
6297 part_die
->is_external
= spec_die
->is_external
;
6301 /* Set default names for some unnamed DIEs. */
6302 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
6303 || part_die
->tag
== DW_TAG_class_type
))
6304 part_die
->name
= "(anonymous class)";
6306 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
6307 part_die
->name
= "(anonymous namespace)";
6309 if (part_die
->tag
== DW_TAG_structure_type
6310 || part_die
->tag
== DW_TAG_class_type
6311 || part_die
->tag
== DW_TAG_union_type
)
6312 guess_structure_name (part_die
, cu
);
6315 /* Read the die from the .debug_info section buffer. Set DIEP to
6316 point to a newly allocated die with its information, except for its
6317 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6318 whether the die has children or not. */
6321 read_full_die (struct die_info
**diep
, bfd
*abfd
, gdb_byte
*info_ptr
,
6322 struct dwarf2_cu
*cu
, int *has_children
)
6324 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6325 struct abbrev_info
*abbrev
;
6326 struct die_info
*die
;
6328 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
6329 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6330 info_ptr
+= bytes_read
;
6338 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6341 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6343 bfd_get_filename (abfd
));
6345 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
6346 die
->offset
= offset
;
6347 die
->tag
= abbrev
->tag
;
6348 die
->abbrev
= abbrev_number
;
6350 die
->num_attrs
= abbrev
->num_attrs
;
6352 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6353 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6354 abfd
, info_ptr
, cu
);
6357 *has_children
= abbrev
->has_children
;
6361 /* Read an attribute value described by an attribute form. */
6364 read_attribute_value (struct attribute
*attr
, unsigned form
,
6365 bfd
*abfd
, gdb_byte
*info_ptr
,
6366 struct dwarf2_cu
*cu
)
6368 struct comp_unit_head
*cu_header
= &cu
->header
;
6369 unsigned int bytes_read
;
6370 struct dwarf_block
*blk
;
6376 case DW_FORM_ref_addr
:
6377 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6378 info_ptr
+= bytes_read
;
6380 case DW_FORM_block2
:
6381 blk
= dwarf_alloc_block (cu
);
6382 blk
->size
= read_2_bytes (abfd
, info_ptr
);
6384 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6385 info_ptr
+= blk
->size
;
6386 DW_BLOCK (attr
) = blk
;
6388 case DW_FORM_block4
:
6389 blk
= dwarf_alloc_block (cu
);
6390 blk
->size
= read_4_bytes (abfd
, info_ptr
);
6392 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6393 info_ptr
+= blk
->size
;
6394 DW_BLOCK (attr
) = blk
;
6397 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
6401 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
6405 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
6408 case DW_FORM_string
:
6409 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
6410 info_ptr
+= bytes_read
;
6413 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
6415 info_ptr
+= bytes_read
;
6418 blk
= dwarf_alloc_block (cu
);
6419 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6420 info_ptr
+= bytes_read
;
6421 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6422 info_ptr
+= blk
->size
;
6423 DW_BLOCK (attr
) = blk
;
6425 case DW_FORM_block1
:
6426 blk
= dwarf_alloc_block (cu
);
6427 blk
->size
= read_1_byte (abfd
, info_ptr
);
6429 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6430 info_ptr
+= blk
->size
;
6431 DW_BLOCK (attr
) = blk
;
6434 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6438 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6442 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
6443 info_ptr
+= bytes_read
;
6446 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6447 info_ptr
+= bytes_read
;
6450 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
6454 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
6458 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
6462 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
6465 case DW_FORM_ref_udata
:
6466 DW_ADDR (attr
) = (cu
->header
.offset
6467 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
6468 info_ptr
+= bytes_read
;
6470 case DW_FORM_indirect
:
6471 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6472 info_ptr
+= bytes_read
;
6473 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
6476 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
6477 dwarf_form_name (form
),
6478 bfd_get_filename (abfd
));
6481 /* We have seen instances where the compiler tried to emit a byte
6482 size attribute of -1 which ended up being encoded as an unsigned
6483 0xffffffff. Although 0xffffffff is technically a valid size value,
6484 an object of this size seems pretty unlikely so we can relatively
6485 safely treat these cases as if the size attribute was invalid and
6486 treat them as zero by default. */
6487 if (attr
->name
== DW_AT_byte_size
6488 && form
== DW_FORM_data4
6489 && DW_UNSND (attr
) >= 0xffffffff)
6492 (&symfile_complaints
,
6493 _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"),
6495 DW_UNSND (attr
) = 0;
6501 /* Read an attribute described by an abbreviated attribute. */
6504 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
6505 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6507 attr
->name
= abbrev
->name
;
6508 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
6511 /* read dwarf information from a buffer */
6514 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
6516 return bfd_get_8 (abfd
, buf
);
6520 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
6522 return bfd_get_signed_8 (abfd
, buf
);
6526 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
6528 return bfd_get_16 (abfd
, buf
);
6532 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6534 return bfd_get_signed_16 (abfd
, buf
);
6538 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
6540 return bfd_get_32 (abfd
, buf
);
6544 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6546 return bfd_get_signed_32 (abfd
, buf
);
6549 static unsigned long
6550 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
6552 return bfd_get_64 (abfd
, buf
);
6556 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
6557 unsigned int *bytes_read
)
6559 struct comp_unit_head
*cu_header
= &cu
->header
;
6560 CORE_ADDR retval
= 0;
6562 if (cu_header
->signed_addr_p
)
6564 switch (cu_header
->addr_size
)
6567 retval
= bfd_get_signed_16 (abfd
, buf
);
6570 retval
= bfd_get_signed_32 (abfd
, buf
);
6573 retval
= bfd_get_signed_64 (abfd
, buf
);
6576 internal_error (__FILE__
, __LINE__
,
6577 _("read_address: bad switch, signed [in module %s]"),
6578 bfd_get_filename (abfd
));
6583 switch (cu_header
->addr_size
)
6586 retval
= bfd_get_16 (abfd
, buf
);
6589 retval
= bfd_get_32 (abfd
, buf
);
6592 retval
= bfd_get_64 (abfd
, buf
);
6595 internal_error (__FILE__
, __LINE__
,
6596 _("read_address: bad switch, unsigned [in module %s]"),
6597 bfd_get_filename (abfd
));
6601 *bytes_read
= cu_header
->addr_size
;
6605 /* Read the initial length from a section. The (draft) DWARF 3
6606 specification allows the initial length to take up either 4 bytes
6607 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
6608 bytes describe the length and all offsets will be 8 bytes in length
6611 An older, non-standard 64-bit format is also handled by this
6612 function. The older format in question stores the initial length
6613 as an 8-byte quantity without an escape value. Lengths greater
6614 than 2^32 aren't very common which means that the initial 4 bytes
6615 is almost always zero. Since a length value of zero doesn't make
6616 sense for the 32-bit format, this initial zero can be considered to
6617 be an escape value which indicates the presence of the older 64-bit
6618 format. As written, the code can't detect (old format) lengths
6619 greater than 4GB. If it becomes necessary to handle lengths
6620 somewhat larger than 4GB, we could allow other small values (such
6621 as the non-sensical values of 1, 2, and 3) to also be used as
6622 escape values indicating the presence of the old format.
6624 The value returned via bytes_read should be used to increment the
6625 relevant pointer after calling read_initial_length().
6627 [ Note: read_initial_length() and read_offset() are based on the
6628 document entitled "DWARF Debugging Information Format", revision
6629 3, draft 8, dated November 19, 2001. This document was obtained
6632 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
6634 This document is only a draft and is subject to change. (So beware.)
6636 Details regarding the older, non-standard 64-bit format were
6637 determined empirically by examining 64-bit ELF files produced by
6638 the SGI toolchain on an IRIX 6.5 machine.
6640 - Kevin, July 16, 2002
6644 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
6646 LONGEST length
= bfd_get_32 (abfd
, buf
);
6648 if (length
== 0xffffffff)
6650 length
= bfd_get_64 (abfd
, buf
+ 4);
6653 else if (length
== 0)
6655 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
6656 length
= bfd_get_64 (abfd
, buf
);
6667 /* Cover function for read_initial_length.
6668 Returns the length of the object at BUF, and stores the size of the
6669 initial length in *BYTES_READ and stores the size that offsets will be in
6671 If the initial length size is not equivalent to that specified in
6672 CU_HEADER then issue a complaint.
6673 This is useful when reading non-comp-unit headers. */
6676 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
6677 const struct comp_unit_head
*cu_header
,
6678 unsigned int *bytes_read
,
6679 unsigned int *offset_size
)
6681 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
6683 gdb_assert (cu_header
->initial_length_size
== 4
6684 || cu_header
->initial_length_size
== 8
6685 || cu_header
->initial_length_size
== 12);
6687 if (cu_header
->initial_length_size
!= *bytes_read
)
6688 complaint (&symfile_complaints
,
6689 _("intermixed 32-bit and 64-bit DWARF sections"));
6691 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
6695 /* Read an offset from the data stream. The size of the offset is
6696 given by cu_header->offset_size. */
6699 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
6700 unsigned int *bytes_read
)
6702 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
6703 *bytes_read
= cu_header
->offset_size
;
6707 /* Read an offset from the data stream. */
6710 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
6714 switch (offset_size
)
6717 retval
= bfd_get_32 (abfd
, buf
);
6720 retval
= bfd_get_64 (abfd
, buf
);
6723 internal_error (__FILE__
, __LINE__
,
6724 _("read_offset_1: bad switch [in module %s]"),
6725 bfd_get_filename (abfd
));
6732 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
6734 /* If the size of a host char is 8 bits, we can return a pointer
6735 to the buffer, otherwise we have to copy the data to a buffer
6736 allocated on the temporary obstack. */
6737 gdb_assert (HOST_CHAR_BIT
== 8);
6742 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6744 /* If the size of a host char is 8 bits, we can return a pointer
6745 to the string, otherwise we have to copy the string to a buffer
6746 allocated on the temporary obstack. */
6747 gdb_assert (HOST_CHAR_BIT
== 8);
6750 *bytes_read_ptr
= 1;
6753 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
6754 return (char *) buf
;
6758 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
6759 const struct comp_unit_head
*cu_header
,
6760 unsigned int *bytes_read_ptr
)
6762 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
6764 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
6766 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
6767 bfd_get_filename (abfd
));
6770 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
6772 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
6773 bfd_get_filename (abfd
));
6776 gdb_assert (HOST_CHAR_BIT
== 8);
6777 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
6779 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
6782 static unsigned long
6783 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6785 unsigned long result
;
6786 unsigned int num_read
;
6796 byte
= bfd_get_8 (abfd
, buf
);
6799 result
|= ((unsigned long)(byte
& 127) << shift
);
6800 if ((byte
& 128) == 0)
6806 *bytes_read_ptr
= num_read
;
6811 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6814 int i
, shift
, num_read
;
6823 byte
= bfd_get_8 (abfd
, buf
);
6826 result
|= ((long)(byte
& 127) << shift
);
6828 if ((byte
& 128) == 0)
6833 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
6834 result
|= -(((long)1) << shift
);
6835 *bytes_read_ptr
= num_read
;
6839 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6842 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
6848 byte
= bfd_get_8 (abfd
, buf
);
6850 if ((byte
& 128) == 0)
6856 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
6863 cu
->language
= language_c
;
6865 case DW_LANG_C_plus_plus
:
6866 cu
->language
= language_cplus
;
6868 case DW_LANG_Fortran77
:
6869 case DW_LANG_Fortran90
:
6870 case DW_LANG_Fortran95
:
6871 cu
->language
= language_fortran
;
6873 case DW_LANG_Mips_Assembler
:
6874 cu
->language
= language_asm
;
6877 cu
->language
= language_java
;
6881 cu
->language
= language_ada
;
6883 case DW_LANG_Modula2
:
6884 cu
->language
= language_m2
;
6886 case DW_LANG_Pascal83
:
6887 cu
->language
= language_pascal
;
6890 cu
->language
= language_objc
;
6892 case DW_LANG_Cobol74
:
6893 case DW_LANG_Cobol85
:
6895 cu
->language
= language_minimal
;
6898 cu
->language_defn
= language_def (cu
->language
);
6901 /* Return the named attribute or NULL if not there. */
6903 static struct attribute
*
6904 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
6907 struct attribute
*spec
= NULL
;
6909 for (i
= 0; i
< die
->num_attrs
; ++i
)
6911 if (die
->attrs
[i
].name
== name
)
6912 return &die
->attrs
[i
];
6913 if (die
->attrs
[i
].name
== DW_AT_specification
6914 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
6915 spec
= &die
->attrs
[i
];
6920 die
= follow_die_ref (die
, spec
, &cu
);
6921 return dwarf2_attr (die
, name
, cu
);
6927 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6928 and holds a non-zero value. This function should only be used for
6929 DW_FORM_flag attributes. */
6932 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
6934 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
6936 return (attr
&& DW_UNSND (attr
));
6940 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
6942 /* A DIE is a declaration if it has a DW_AT_declaration attribute
6943 which value is non-zero. However, we have to be careful with
6944 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
6945 (via dwarf2_flag_true_p) follows this attribute. So we may
6946 end up accidently finding a declaration attribute that belongs
6947 to a different DIE referenced by the specification attribute,
6948 even though the given DIE does not have a declaration attribute. */
6949 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
6950 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
6953 /* Return the die giving the specification for DIE, if there is
6954 one. *SPEC_CU is the CU containing DIE on input, and the CU
6955 containing the return value on output. */
6957 static struct die_info
*
6958 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
6960 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
6963 if (spec_attr
== NULL
)
6966 return follow_die_ref (die
, spec_attr
, spec_cu
);
6969 /* Free the line_header structure *LH, and any arrays and strings it
6972 free_line_header (struct line_header
*lh
)
6974 if (lh
->standard_opcode_lengths
)
6975 xfree (lh
->standard_opcode_lengths
);
6977 /* Remember that all the lh->file_names[i].name pointers are
6978 pointers into debug_line_buffer, and don't need to be freed. */
6980 xfree (lh
->file_names
);
6982 /* Similarly for the include directory names. */
6983 if (lh
->include_dirs
)
6984 xfree (lh
->include_dirs
);
6990 /* Add an entry to LH's include directory table. */
6992 add_include_dir (struct line_header
*lh
, char *include_dir
)
6994 /* Grow the array if necessary. */
6995 if (lh
->include_dirs_size
== 0)
6997 lh
->include_dirs_size
= 1; /* for testing */
6998 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
6999 * sizeof (*lh
->include_dirs
));
7001 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
7003 lh
->include_dirs_size
*= 2;
7004 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
7005 (lh
->include_dirs_size
7006 * sizeof (*lh
->include_dirs
)));
7009 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
7013 /* Add an entry to LH's file name table. */
7015 add_file_name (struct line_header
*lh
,
7017 unsigned int dir_index
,
7018 unsigned int mod_time
,
7019 unsigned int length
)
7021 struct file_entry
*fe
;
7023 /* Grow the array if necessary. */
7024 if (lh
->file_names_size
== 0)
7026 lh
->file_names_size
= 1; /* for testing */
7027 lh
->file_names
= xmalloc (lh
->file_names_size
7028 * sizeof (*lh
->file_names
));
7030 else if (lh
->num_file_names
>= lh
->file_names_size
)
7032 lh
->file_names_size
*= 2;
7033 lh
->file_names
= xrealloc (lh
->file_names
,
7034 (lh
->file_names_size
7035 * sizeof (*lh
->file_names
)));
7038 fe
= &lh
->file_names
[lh
->num_file_names
++];
7040 fe
->dir_index
= dir_index
;
7041 fe
->mod_time
= mod_time
;
7042 fe
->length
= length
;
7048 /* Read the statement program header starting at OFFSET in
7049 .debug_line, according to the endianness of ABFD. Return a pointer
7050 to a struct line_header, allocated using xmalloc.
7052 NOTE: the strings in the include directory and file name tables of
7053 the returned object point into debug_line_buffer, and must not be
7055 static struct line_header
*
7056 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
7057 struct dwarf2_cu
*cu
)
7059 struct cleanup
*back_to
;
7060 struct line_header
*lh
;
7062 unsigned int bytes_read
, offset_size
;
7064 char *cur_dir
, *cur_file
;
7066 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
7068 complaint (&symfile_complaints
, _("missing .debug_line section"));
7072 /* Make sure that at least there's room for the total_length field.
7073 That could be 12 bytes long, but we're just going to fudge that. */
7074 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
7076 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7080 lh
= xmalloc (sizeof (*lh
));
7081 memset (lh
, 0, sizeof (*lh
));
7082 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
7085 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
7087 /* Read in the header. */
7089 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
7090 &bytes_read
, &offset_size
);
7091 line_ptr
+= bytes_read
;
7092 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
7093 + dwarf2_per_objfile
->line
.size
))
7095 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7098 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
7099 lh
->version
= read_2_bytes (abfd
, line_ptr
);
7101 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
7102 line_ptr
+= offset_size
;
7103 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
7105 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
7107 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
7109 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
7111 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
7113 lh
->standard_opcode_lengths
7114 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
7116 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
7117 for (i
= 1; i
< lh
->opcode_base
; ++i
)
7119 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
7123 /* Read directory table. */
7124 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7126 line_ptr
+= bytes_read
;
7127 add_include_dir (lh
, cur_dir
);
7129 line_ptr
+= bytes_read
;
7131 /* Read file name table. */
7132 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7134 unsigned int dir_index
, mod_time
, length
;
7136 line_ptr
+= bytes_read
;
7137 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7138 line_ptr
+= bytes_read
;
7139 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7140 line_ptr
+= bytes_read
;
7141 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7142 line_ptr
+= bytes_read
;
7144 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7146 line_ptr
+= bytes_read
;
7147 lh
->statement_program_start
= line_ptr
;
7149 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
7150 + dwarf2_per_objfile
->line
.size
))
7151 complaint (&symfile_complaints
,
7152 _("line number info header doesn't fit in `.debug_line' section"));
7154 discard_cleanups (back_to
);
7158 /* This function exists to work around a bug in certain compilers
7159 (particularly GCC 2.95), in which the first line number marker of a
7160 function does not show up until after the prologue, right before
7161 the second line number marker. This function shifts ADDRESS down
7162 to the beginning of the function if necessary, and is called on
7163 addresses passed to record_line. */
7166 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
7168 struct function_range
*fn
;
7170 /* Find the function_range containing address. */
7175 cu
->cached_fn
= cu
->first_fn
;
7179 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7185 while (fn
&& fn
!= cu
->cached_fn
)
7186 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7196 if (address
!= fn
->lowpc
)
7197 complaint (&symfile_complaints
,
7198 _("misplaced first line number at 0x%lx for '%s'"),
7199 (unsigned long) address
, fn
->name
);
7204 /* Decode the Line Number Program (LNP) for the given line_header
7205 structure and CU. The actual information extracted and the type
7206 of structures created from the LNP depends on the value of PST.
7208 1. If PST is NULL, then this procedure uses the data from the program
7209 to create all necessary symbol tables, and their linetables.
7210 The compilation directory of the file is passed in COMP_DIR,
7211 and must not be NULL.
7213 2. If PST is not NULL, this procedure reads the program to determine
7214 the list of files included by the unit represented by PST, and
7215 builds all the associated partial symbol tables. In this case,
7216 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
7217 is not used to compute the full name of the symtab, and therefore
7218 omitting it when building the partial symtab does not introduce
7219 the potential for inconsistency - a partial symtab and its associated
7220 symbtab having a different fullname -). */
7223 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
7224 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
7226 gdb_byte
*line_ptr
, *extended_end
;
7228 unsigned int bytes_read
, extended_len
;
7229 unsigned char op_code
, extended_op
, adj_opcode
;
7231 struct objfile
*objfile
= cu
->objfile
;
7232 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7233 const int decode_for_pst_p
= (pst
!= NULL
);
7234 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
7236 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7238 line_ptr
= lh
->statement_program_start
;
7239 line_end
= lh
->statement_program_end
;
7241 /* Read the statement sequences until there's nothing left. */
7242 while (line_ptr
< line_end
)
7244 /* state machine registers */
7245 CORE_ADDR address
= 0;
7246 unsigned int file
= 1;
7247 unsigned int line
= 1;
7248 unsigned int column
= 0;
7249 int is_stmt
= lh
->default_is_stmt
;
7250 int basic_block
= 0;
7251 int end_sequence
= 0;
7254 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
7256 /* Start a subfile for the current file of the state machine. */
7257 /* lh->include_dirs and lh->file_names are 0-based, but the
7258 directory and file name numbers in the statement program
7260 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7264 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7266 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7269 /* Decode the table. */
7270 while (!end_sequence
)
7272 op_code
= read_1_byte (abfd
, line_ptr
);
7274 if (line_ptr
> line_end
)
7276 dwarf2_debug_line_missing_end_sequence_complaint ();
7280 if (op_code
>= lh
->opcode_base
)
7282 /* Special operand. */
7283 adj_opcode
= op_code
- lh
->opcode_base
;
7284 address
+= (adj_opcode
/ lh
->line_range
)
7285 * lh
->minimum_instruction_length
;
7286 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
7287 if (lh
->num_file_names
< file
|| file
== 0)
7288 dwarf2_debug_line_missing_file_complaint ();
7291 lh
->file_names
[file
- 1].included_p
= 1;
7292 if (!decode_for_pst_p
)
7294 if (last_subfile
!= current_subfile
)
7296 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
7298 record_line (last_subfile
, 0, addr
);
7299 last_subfile
= current_subfile
;
7301 /* Append row to matrix using current values. */
7302 addr
= check_cu_functions (address
, cu
);
7303 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
7304 record_line (current_subfile
, line
, addr
);
7309 else switch (op_code
)
7311 case DW_LNS_extended_op
:
7312 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7313 line_ptr
+= bytes_read
;
7314 extended_end
= line_ptr
+ extended_len
;
7315 extended_op
= read_1_byte (abfd
, line_ptr
);
7317 switch (extended_op
)
7319 case DW_LNE_end_sequence
:
7322 case DW_LNE_set_address
:
7323 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
7324 line_ptr
+= bytes_read
;
7325 address
+= baseaddr
;
7327 case DW_LNE_define_file
:
7330 unsigned int dir_index
, mod_time
, length
;
7332 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
7333 line_ptr
+= bytes_read
;
7335 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7336 line_ptr
+= bytes_read
;
7338 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7339 line_ptr
+= bytes_read
;
7341 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7342 line_ptr
+= bytes_read
;
7343 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7346 case DW_LNE_set_discriminator
:
7347 /* The discriminator is not interesting to the debugger;
7349 line_ptr
= extended_end
;
7352 complaint (&symfile_complaints
,
7353 _("mangled .debug_line section"));
7356 /* Make sure that we parsed the extended op correctly. If e.g.
7357 we expected a different address size than the producer used,
7358 we may have read the wrong number of bytes. */
7359 if (line_ptr
!= extended_end
)
7361 complaint (&symfile_complaints
,
7362 _("mangled .debug_line section"));
7367 if (lh
->num_file_names
< file
|| file
== 0)
7368 dwarf2_debug_line_missing_file_complaint ();
7371 lh
->file_names
[file
- 1].included_p
= 1;
7372 if (!decode_for_pst_p
)
7374 if (last_subfile
!= current_subfile
)
7376 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
7378 record_line (last_subfile
, 0, addr
);
7379 last_subfile
= current_subfile
;
7381 addr
= check_cu_functions (address
, cu
);
7382 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
7383 record_line (current_subfile
, line
, addr
);
7388 case DW_LNS_advance_pc
:
7389 address
+= lh
->minimum_instruction_length
7390 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7391 line_ptr
+= bytes_read
;
7393 case DW_LNS_advance_line
:
7394 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
7395 line_ptr
+= bytes_read
;
7397 case DW_LNS_set_file
:
7399 /* The arrays lh->include_dirs and lh->file_names are
7400 0-based, but the directory and file name numbers in
7401 the statement program are 1-based. */
7402 struct file_entry
*fe
;
7405 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7406 line_ptr
+= bytes_read
;
7407 if (lh
->num_file_names
< file
|| file
== 0)
7408 dwarf2_debug_line_missing_file_complaint ();
7411 fe
= &lh
->file_names
[file
- 1];
7413 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7414 if (!decode_for_pst_p
)
7416 last_subfile
= current_subfile
;
7417 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7422 case DW_LNS_set_column
:
7423 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7424 line_ptr
+= bytes_read
;
7426 case DW_LNS_negate_stmt
:
7427 is_stmt
= (!is_stmt
);
7429 case DW_LNS_set_basic_block
:
7432 /* Add to the address register of the state machine the
7433 address increment value corresponding to special opcode
7434 255. I.e., this value is scaled by the minimum
7435 instruction length since special opcode 255 would have
7436 scaled the the increment. */
7437 case DW_LNS_const_add_pc
:
7438 address
+= (lh
->minimum_instruction_length
7439 * ((255 - lh
->opcode_base
) / lh
->line_range
));
7441 case DW_LNS_fixed_advance_pc
:
7442 address
+= read_2_bytes (abfd
, line_ptr
);
7447 /* Unknown standard opcode, ignore it. */
7450 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
7452 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7453 line_ptr
+= bytes_read
;
7458 if (lh
->num_file_names
< file
|| file
== 0)
7459 dwarf2_debug_line_missing_file_complaint ();
7462 lh
->file_names
[file
- 1].included_p
= 1;
7463 if (!decode_for_pst_p
)
7465 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
7466 record_line (current_subfile
, 0, addr
);
7471 if (decode_for_pst_p
)
7475 /* Now that we're done scanning the Line Header Program, we can
7476 create the psymtab of each included file. */
7477 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
7478 if (lh
->file_names
[file_index
].included_p
== 1)
7480 const struct file_entry fe
= lh
->file_names
[file_index
];
7481 char *include_name
= fe
.name
;
7482 char *dir_name
= NULL
;
7483 char *pst_filename
= pst
->filename
;
7486 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
7488 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
7490 include_name
= concat (dir_name
, SLASH_STRING
,
7491 include_name
, (char *)NULL
);
7492 make_cleanup (xfree
, include_name
);
7495 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
7497 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
7498 pst_filename
, (char *)NULL
);
7499 make_cleanup (xfree
, pst_filename
);
7502 if (strcmp (include_name
, pst_filename
) != 0)
7503 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
7508 /* Make sure a symtab is created for every file, even files
7509 which contain only variables (i.e. no code with associated
7513 struct file_entry
*fe
;
7515 for (i
= 0; i
< lh
->num_file_names
; i
++)
7518 fe
= &lh
->file_names
[i
];
7520 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7521 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7523 /* Skip the main file; we don't need it, and it must be
7524 allocated last, so that it will show up before the
7525 non-primary symtabs in the objfile's symtab list. */
7526 if (current_subfile
== first_subfile
)
7529 if (current_subfile
->symtab
== NULL
)
7530 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7532 fe
->symtab
= current_subfile
->symtab
;
7537 /* Start a subfile for DWARF. FILENAME is the name of the file and
7538 DIRNAME the name of the source directory which contains FILENAME
7539 or NULL if not known. COMP_DIR is the compilation directory for the
7540 linetable's compilation unit or NULL if not known.
7541 This routine tries to keep line numbers from identical absolute and
7542 relative file names in a common subfile.
7544 Using the `list' example from the GDB testsuite, which resides in
7545 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
7546 of /srcdir/list0.c yields the following debugging information for list0.c:
7548 DW_AT_name: /srcdir/list0.c
7549 DW_AT_comp_dir: /compdir
7550 files.files[0].name: list0.h
7551 files.files[0].dir: /srcdir
7552 files.files[1].name: list0.c
7553 files.files[1].dir: /srcdir
7555 The line number information for list0.c has to end up in a single
7556 subfile, so that `break /srcdir/list0.c:1' works as expected.
7557 start_subfile will ensure that this happens provided that we pass the
7558 concatenation of files.files[1].dir and files.files[1].name as the
7562 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
7566 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
7567 `start_symtab' will always pass the contents of DW_AT_comp_dir as
7568 second argument to start_subfile. To be consistent, we do the
7569 same here. In order not to lose the line information directory,
7570 we concatenate it to the filename when it makes sense.
7571 Note that the Dwarf3 standard says (speaking of filenames in line
7572 information): ``The directory index is ignored for file names
7573 that represent full path names''. Thus ignoring dirname in the
7574 `else' branch below isn't an issue. */
7576 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
7577 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
7579 fullname
= filename
;
7581 start_subfile (fullname
, comp_dir
);
7583 if (fullname
!= filename
)
7588 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
7589 struct dwarf2_cu
*cu
)
7591 struct objfile
*objfile
= cu
->objfile
;
7592 struct comp_unit_head
*cu_header
= &cu
->header
;
7594 /* NOTE drow/2003-01-30: There used to be a comment and some special
7595 code here to turn a symbol with DW_AT_external and a
7596 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
7597 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
7598 with some versions of binutils) where shared libraries could have
7599 relocations against symbols in their debug information - the
7600 minimal symbol would have the right address, but the debug info
7601 would not. It's no longer necessary, because we will explicitly
7602 apply relocations when we read in the debug information now. */
7604 /* A DW_AT_location attribute with no contents indicates that a
7605 variable has been optimized away. */
7606 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
7608 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7612 /* Handle one degenerate form of location expression specially, to
7613 preserve GDB's previous behavior when section offsets are
7614 specified. If this is just a DW_OP_addr then mark this symbol
7617 if (attr_form_is_block (attr
)
7618 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
7619 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
7623 SYMBOL_VALUE_ADDRESS (sym
) =
7624 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
7625 SYMBOL_CLASS (sym
) = LOC_STATIC
;
7626 fixup_symbol_section (sym
, objfile
);
7627 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
7628 SYMBOL_SECTION (sym
));
7632 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
7633 expression evaluator, and use LOC_COMPUTED only when necessary
7634 (i.e. when the value of a register or memory location is
7635 referenced, or a thread-local block, etc.). Then again, it might
7636 not be worthwhile. I'm assuming that it isn't unless performance
7637 or memory numbers show me otherwise. */
7639 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
7640 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
7643 /* Given a pointer to a DWARF information entry, figure out if we need
7644 to make a symbol table entry for it, and if so, create a new entry
7645 and return a pointer to it.
7646 If TYPE is NULL, determine symbol type from the die, otherwise
7647 used the passed type. */
7649 static struct symbol
*
7650 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
7652 struct objfile
*objfile
= cu
->objfile
;
7653 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7654 struct symbol
*sym
= NULL
;
7656 struct attribute
*attr
= NULL
;
7657 struct attribute
*attr2
= NULL
;
7660 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7662 if (die
->tag
!= DW_TAG_namespace
)
7663 name
= dwarf2_linkage_name (die
, cu
);
7665 name
= TYPE_NAME (type
);
7669 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
7670 sizeof (struct symbol
));
7671 OBJSTAT (objfile
, n_syms
++);
7672 memset (sym
, 0, sizeof (struct symbol
));
7674 /* Cache this symbol's name and the name's demangled form (if any). */
7675 SYMBOL_LANGUAGE (sym
) = cu
->language
;
7676 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
7678 /* Default assumptions.
7679 Use the passed type or decode it from the die. */
7680 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7681 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7683 SYMBOL_TYPE (sym
) = type
;
7685 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
7686 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
7689 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
7692 attr
= dwarf2_attr (die
, DW_AT_decl_file
, cu
);
7695 int file_index
= DW_UNSND (attr
);
7696 if (cu
->line_header
== NULL
7697 || file_index
> cu
->line_header
->num_file_names
)
7698 complaint (&symfile_complaints
,
7699 _("file index out of range"));
7700 else if (file_index
> 0)
7702 struct file_entry
*fe
;
7703 fe
= &cu
->line_header
->file_names
[file_index
- 1];
7704 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
7711 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7714 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
7716 SYMBOL_CLASS (sym
) = LOC_LABEL
;
7718 case DW_TAG_subprogram
:
7719 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7721 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
7722 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7723 if ((attr2
&& (DW_UNSND (attr2
) != 0))
7724 || cu
->language
== language_ada
)
7726 /* Subprograms marked external are stored as a global symbol.
7727 Ada subprograms, whether marked external or not, are always
7728 stored as a global symbol, because we want to be able to
7729 access them globally. For instance, we want to be able
7730 to break on a nested subprogram without having to
7731 specify the context. */
7732 add_symbol_to_list (sym
, &global_symbols
);
7736 add_symbol_to_list (sym
, cu
->list_in_scope
);
7739 case DW_TAG_variable
:
7740 /* Compilation with minimal debug info may result in variables
7741 with missing type entries. Change the misleading `void' type
7742 to something sensible. */
7743 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
7745 = builtin_type (gdbarch
)->nodebug_data_symbol
;
7747 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7750 dwarf2_const_value (attr
, sym
, cu
);
7751 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7752 if (attr2
&& (DW_UNSND (attr2
) != 0))
7753 add_symbol_to_list (sym
, &global_symbols
);
7755 add_symbol_to_list (sym
, cu
->list_in_scope
);
7758 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7761 var_decode_location (attr
, sym
, cu
);
7762 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7763 if (attr2
&& (DW_UNSND (attr2
) != 0))
7764 add_symbol_to_list (sym
, &global_symbols
);
7766 add_symbol_to_list (sym
, cu
->list_in_scope
);
7770 /* We do not know the address of this symbol.
7771 If it is an external symbol and we have type information
7772 for it, enter the symbol as a LOC_UNRESOLVED symbol.
7773 The address of the variable will then be determined from
7774 the minimal symbol table whenever the variable is
7776 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7777 if (attr2
&& (DW_UNSND (attr2
) != 0)
7778 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
7780 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
7781 add_symbol_to_list (sym
, cu
->list_in_scope
);
7783 else if (!die_is_declaration (die
, cu
))
7785 /* Use the default LOC_OPTIMIZED_OUT class. */
7786 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
7787 add_symbol_to_list (sym
, cu
->list_in_scope
);
7791 case DW_TAG_formal_parameter
:
7792 SYMBOL_IS_ARGUMENT (sym
) = 1;
7793 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7796 var_decode_location (attr
, sym
, cu
);
7798 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7801 dwarf2_const_value (attr
, sym
, cu
);
7803 add_symbol_to_list (sym
, cu
->list_in_scope
);
7805 case DW_TAG_unspecified_parameters
:
7806 /* From varargs functions; gdb doesn't seem to have any
7807 interest in this information, so just ignore it for now.
7810 case DW_TAG_class_type
:
7811 case DW_TAG_interface_type
:
7812 case DW_TAG_structure_type
:
7813 case DW_TAG_union_type
:
7814 case DW_TAG_set_type
:
7815 case DW_TAG_enumeration_type
:
7816 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7817 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7819 /* Make sure that the symbol includes appropriate enclosing
7820 classes/namespaces in its name. These are calculated in
7821 read_structure_type, and the correct name is saved in
7824 if (cu
->language
== language_cplus
7825 || cu
->language
== language_java
)
7827 struct type
*type
= SYMBOL_TYPE (sym
);
7829 if (TYPE_TAG_NAME (type
) != NULL
)
7831 /* FIXME: carlton/2003-11-10: Should this use
7832 SYMBOL_SET_NAMES instead? (The same problem also
7833 arises further down in this function.) */
7834 /* The type's name is already allocated along with
7835 this objfile, so we don't need to duplicate it
7837 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
7842 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
7843 really ever be static objects: otherwise, if you try
7844 to, say, break of a class's method and you're in a file
7845 which doesn't mention that class, it won't work unless
7846 the check for all static symbols in lookup_symbol_aux
7847 saves you. See the OtherFileClass tests in
7848 gdb.c++/namespace.exp. */
7850 struct pending
**list_to_add
;
7852 list_to_add
= (cu
->list_in_scope
== &file_symbols
7853 && (cu
->language
== language_cplus
7854 || cu
->language
== language_java
)
7855 ? &global_symbols
: cu
->list_in_scope
);
7857 add_symbol_to_list (sym
, list_to_add
);
7859 /* The semantics of C++ state that "struct foo { ... }" also
7860 defines a typedef for "foo". A Java class declaration also
7861 defines a typedef for the class. */
7862 if (cu
->language
== language_cplus
7863 || cu
->language
== language_java
7864 || cu
->language
== language_ada
)
7866 /* The symbol's name is already allocated along with
7867 this objfile, so we don't need to duplicate it for
7869 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
7870 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
7874 case DW_TAG_typedef
:
7875 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7876 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7877 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7878 add_symbol_to_list (sym
, cu
->list_in_scope
);
7880 case DW_TAG_base_type
:
7881 case DW_TAG_subrange_type
:
7882 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7883 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7884 add_symbol_to_list (sym
, cu
->list_in_scope
);
7886 case DW_TAG_enumerator
:
7887 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7888 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7891 dwarf2_const_value (attr
, sym
, cu
);
7894 /* NOTE: carlton/2003-11-10: See comment above in the
7895 DW_TAG_class_type, etc. block. */
7897 struct pending
**list_to_add
;
7899 list_to_add
= (cu
->list_in_scope
== &file_symbols
7900 && (cu
->language
== language_cplus
7901 || cu
->language
== language_java
)
7902 ? &global_symbols
: cu
->list_in_scope
);
7904 add_symbol_to_list (sym
, list_to_add
);
7907 case DW_TAG_namespace
:
7908 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7909 add_symbol_to_list (sym
, &global_symbols
);
7912 /* Not a tag we recognize. Hopefully we aren't processing
7913 trash data, but since we must specifically ignore things
7914 we don't recognize, there is nothing else we should do at
7916 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
7917 dwarf_tag_name (die
->tag
));
7921 /* For the benefit of old versions of GCC, check for anonymous
7922 namespaces based on the demangled name. */
7923 if (!processing_has_namespace_info
7924 && cu
->language
== language_cplus
7925 && dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
) != NULL
)
7926 cp_scan_for_anonymous_namespaces (sym
);
7931 /* Copy constant value from an attribute to a symbol. */
7934 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
7935 struct dwarf2_cu
*cu
)
7937 struct objfile
*objfile
= cu
->objfile
;
7938 struct comp_unit_head
*cu_header
= &cu
->header
;
7939 struct dwarf_block
*blk
;
7944 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
7945 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7946 cu_header
->addr_size
,
7947 TYPE_LENGTH (SYMBOL_TYPE
7949 SYMBOL_VALUE_BYTES (sym
) =
7950 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
7951 /* NOTE: cagney/2003-05-09: In-lined store_address call with
7952 it's body - store_unsigned_integer. */
7953 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
7955 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7957 case DW_FORM_string
:
7959 /* DW_STRING is already allocated on the obstack, point directly
7961 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
7962 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7964 case DW_FORM_block1
:
7965 case DW_FORM_block2
:
7966 case DW_FORM_block4
:
7968 blk
= DW_BLOCK (attr
);
7969 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
7970 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7972 TYPE_LENGTH (SYMBOL_TYPE
7974 SYMBOL_VALUE_BYTES (sym
) =
7975 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
7976 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
7977 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7980 /* The DW_AT_const_value attributes are supposed to carry the
7981 symbol's value "represented as it would be on the target
7982 architecture." By the time we get here, it's already been
7983 converted to host endianness, so we just need to sign- or
7984 zero-extend it as appropriate. */
7986 dwarf2_const_value_data (attr
, sym
, 8);
7989 dwarf2_const_value_data (attr
, sym
, 16);
7992 dwarf2_const_value_data (attr
, sym
, 32);
7995 dwarf2_const_value_data (attr
, sym
, 64);
7999 SYMBOL_VALUE (sym
) = DW_SND (attr
);
8000 SYMBOL_CLASS (sym
) = LOC_CONST
;
8004 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
8005 SYMBOL_CLASS (sym
) = LOC_CONST
;
8009 complaint (&symfile_complaints
,
8010 _("unsupported const value attribute form: '%s'"),
8011 dwarf_form_name (attr
->form
));
8012 SYMBOL_VALUE (sym
) = 0;
8013 SYMBOL_CLASS (sym
) = LOC_CONST
;
8019 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
8020 or zero-extend it as appropriate for the symbol's type. */
8022 dwarf2_const_value_data (struct attribute
*attr
,
8026 LONGEST l
= DW_UNSND (attr
);
8028 if (bits
< sizeof (l
) * 8)
8030 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
8031 l
&= ((LONGEST
) 1 << bits
) - 1;
8033 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
8036 SYMBOL_VALUE (sym
) = l
;
8037 SYMBOL_CLASS (sym
) = LOC_CONST
;
8041 /* Return the type of the die in question using its DW_AT_type attribute. */
8043 static struct type
*
8044 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8046 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
8048 struct attribute
*type_attr
;
8049 struct die_info
*type_die
;
8051 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
8054 /* A missing DW_AT_type represents a void type. */
8055 return builtin_type (gdbarch
)->builtin_void
;
8058 type_die
= follow_die_ref (die
, type_attr
, &cu
);
8060 type
= tag_type_to_type (type_die
, cu
);
8063 dump_die_for_error (type_die
);
8064 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
8070 /* Return the containing type of the die in question using its
8071 DW_AT_containing_type attribute. */
8073 static struct type
*
8074 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8076 struct type
*type
= NULL
;
8077 struct attribute
*type_attr
;
8078 struct die_info
*type_die
= NULL
;
8080 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
8083 type_die
= follow_die_ref (die
, type_attr
, &cu
);
8084 type
= tag_type_to_type (type_die
, cu
);
8089 dump_die_for_error (type_die
);
8090 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
8096 static struct type
*
8097 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8099 struct type
*this_type
;
8101 this_type
= read_type_die (die
, cu
);
8104 dump_die_for_error (die
);
8105 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
8111 static struct type
*
8112 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8114 struct type
*this_type
;
8116 this_type
= get_die_type (die
, cu
);
8122 case DW_TAG_class_type
:
8123 case DW_TAG_interface_type
:
8124 case DW_TAG_structure_type
:
8125 case DW_TAG_union_type
:
8126 this_type
= read_structure_type (die
, cu
);
8128 case DW_TAG_enumeration_type
:
8129 this_type
= read_enumeration_type (die
, cu
);
8131 case DW_TAG_subprogram
:
8132 case DW_TAG_subroutine_type
:
8133 this_type
= read_subroutine_type (die
, cu
);
8135 case DW_TAG_array_type
:
8136 this_type
= read_array_type (die
, cu
);
8138 case DW_TAG_set_type
:
8139 this_type
= read_set_type (die
, cu
);
8141 case DW_TAG_pointer_type
:
8142 this_type
= read_tag_pointer_type (die
, cu
);
8144 case DW_TAG_ptr_to_member_type
:
8145 this_type
= read_tag_ptr_to_member_type (die
, cu
);
8147 case DW_TAG_reference_type
:
8148 this_type
= read_tag_reference_type (die
, cu
);
8150 case DW_TAG_const_type
:
8151 this_type
= read_tag_const_type (die
, cu
);
8153 case DW_TAG_volatile_type
:
8154 this_type
= read_tag_volatile_type (die
, cu
);
8156 case DW_TAG_string_type
:
8157 this_type
= read_tag_string_type (die
, cu
);
8159 case DW_TAG_typedef
:
8160 this_type
= read_typedef (die
, cu
);
8162 case DW_TAG_subrange_type
:
8163 this_type
= read_subrange_type (die
, cu
);
8165 case DW_TAG_base_type
:
8166 this_type
= read_base_type (die
, cu
);
8168 case DW_TAG_unspecified_type
:
8169 this_type
= read_unspecified_type (die
, cu
);
8171 case DW_TAG_namespace
:
8172 this_type
= read_namespace_type (die
, cu
);
8175 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
8176 dwarf_tag_name (die
->tag
));
8183 /* Return the name of the namespace/class that DIE is defined within,
8184 or "" if we can't tell. The caller should not xfree the result.
8186 For example, if we're within the method foo() in the following
8196 then determine_prefix on foo's die will return "N::C". */
8199 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
8201 struct die_info
*parent
, *spec_die
;
8202 struct dwarf2_cu
*spec_cu
;
8203 struct type
*parent_type
;
8205 if (cu
->language
!= language_cplus
8206 && cu
->language
!= language_java
)
8209 /* We have to be careful in the presence of DW_AT_specification.
8210 For example, with GCC 3.4, given the code
8214 // Definition of N::foo.
8218 then we'll have a tree of DIEs like this:
8220 1: DW_TAG_compile_unit
8221 2: DW_TAG_namespace // N
8222 3: DW_TAG_subprogram // declaration of N::foo
8223 4: DW_TAG_subprogram // definition of N::foo
8224 DW_AT_specification // refers to die #3
8226 Thus, when processing die #4, we have to pretend that we're in
8227 the context of its DW_AT_specification, namely the contex of die
8230 spec_die
= die_specification (die
, &spec_cu
);
8231 if (spec_die
== NULL
)
8232 parent
= die
->parent
;
8235 parent
= spec_die
->parent
;
8242 switch (parent
->tag
)
8244 case DW_TAG_namespace
:
8245 parent_type
= read_type_die (parent
, cu
);
8246 /* We give a name to even anonymous namespaces. */
8247 return TYPE_TAG_NAME (parent_type
);
8248 case DW_TAG_class_type
:
8249 case DW_TAG_interface_type
:
8250 case DW_TAG_structure_type
:
8251 case DW_TAG_union_type
:
8252 parent_type
= read_type_die (parent
, cu
);
8253 if (TYPE_TAG_NAME (parent_type
) != NULL
)
8254 return TYPE_TAG_NAME (parent_type
);
8256 /* An anonymous structure is only allowed non-static data
8257 members; no typedefs, no member functions, et cetera.
8258 So it does not need a prefix. */
8261 return determine_prefix (parent
, cu
);
8265 /* Return a newly-allocated string formed by concatenating PREFIX and
8266 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
8267 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
8268 perform an obconcat, otherwise allocate storage for the result. The CU argument
8269 is used to determine the language and hence, the appropriate separator. */
8271 #define MAX_SEP_LEN 2 /* sizeof ("::") */
8274 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
8275 struct dwarf2_cu
*cu
)
8279 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
8281 else if (cu
->language
== language_java
)
8293 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
8294 strcpy (retval
, prefix
);
8295 strcat (retval
, sep
);
8296 strcat (retval
, suffix
);
8301 /* We have an obstack. */
8302 return obconcat (obs
, prefix
, sep
, suffix
);
8306 /* Return sibling of die, NULL if no sibling. */
8308 static struct die_info
*
8309 sibling_die (struct die_info
*die
)
8311 return die
->sibling
;
8314 /* Get linkage name of a die, return NULL if not found. */
8317 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8319 struct attribute
*attr
;
8321 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8322 if (attr
&& DW_STRING (attr
))
8323 return DW_STRING (attr
);
8324 return dwarf2_name (die
, cu
);
8327 /* Get name of a die, return NULL if not found. */
8330 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
8331 struct obstack
*obstack
)
8333 if (name
&& cu
->language
== language_cplus
)
8335 char *canon_name
= cp_canonicalize_string (name
);
8337 if (canon_name
!= NULL
)
8339 if (strcmp (canon_name
, name
) != 0)
8340 name
= obsavestring (canon_name
, strlen (canon_name
),
8349 /* Get name of a die, return NULL if not found. */
8352 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8354 struct attribute
*attr
;
8356 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8357 if (!attr
|| !DW_STRING (attr
))
8362 case DW_TAG_compile_unit
:
8363 /* Compilation units have a DW_AT_name that is a filename, not
8364 a source language identifier. */
8365 case DW_TAG_enumeration_type
:
8366 case DW_TAG_enumerator
:
8367 /* These tags always have simple identifiers already; no need
8368 to canonicalize them. */
8369 return DW_STRING (attr
);
8371 if (attr
->form
!= GDB_FORM_cached_string
)
8374 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
8375 &cu
->objfile
->objfile_obstack
);
8376 attr
->form
= GDB_FORM_cached_string
;
8378 return DW_STRING (attr
);
8382 /* Return the die that this die in an extension of, or NULL if there
8383 is none. *EXT_CU is the CU containing DIE on input, and the CU
8384 containing the return value on output. */
8386 static struct die_info
*
8387 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
8389 struct attribute
*attr
;
8391 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
8395 return follow_die_ref (die
, attr
, ext_cu
);
8398 /* Convert a DIE tag into its string name. */
8401 dwarf_tag_name (unsigned tag
)
8405 case DW_TAG_padding
:
8406 return "DW_TAG_padding";
8407 case DW_TAG_array_type
:
8408 return "DW_TAG_array_type";
8409 case DW_TAG_class_type
:
8410 return "DW_TAG_class_type";
8411 case DW_TAG_entry_point
:
8412 return "DW_TAG_entry_point";
8413 case DW_TAG_enumeration_type
:
8414 return "DW_TAG_enumeration_type";
8415 case DW_TAG_formal_parameter
:
8416 return "DW_TAG_formal_parameter";
8417 case DW_TAG_imported_declaration
:
8418 return "DW_TAG_imported_declaration";
8420 return "DW_TAG_label";
8421 case DW_TAG_lexical_block
:
8422 return "DW_TAG_lexical_block";
8424 return "DW_TAG_member";
8425 case DW_TAG_pointer_type
:
8426 return "DW_TAG_pointer_type";
8427 case DW_TAG_reference_type
:
8428 return "DW_TAG_reference_type";
8429 case DW_TAG_compile_unit
:
8430 return "DW_TAG_compile_unit";
8431 case DW_TAG_string_type
:
8432 return "DW_TAG_string_type";
8433 case DW_TAG_structure_type
:
8434 return "DW_TAG_structure_type";
8435 case DW_TAG_subroutine_type
:
8436 return "DW_TAG_subroutine_type";
8437 case DW_TAG_typedef
:
8438 return "DW_TAG_typedef";
8439 case DW_TAG_union_type
:
8440 return "DW_TAG_union_type";
8441 case DW_TAG_unspecified_parameters
:
8442 return "DW_TAG_unspecified_parameters";
8443 case DW_TAG_variant
:
8444 return "DW_TAG_variant";
8445 case DW_TAG_common_block
:
8446 return "DW_TAG_common_block";
8447 case DW_TAG_common_inclusion
:
8448 return "DW_TAG_common_inclusion";
8449 case DW_TAG_inheritance
:
8450 return "DW_TAG_inheritance";
8451 case DW_TAG_inlined_subroutine
:
8452 return "DW_TAG_inlined_subroutine";
8454 return "DW_TAG_module";
8455 case DW_TAG_ptr_to_member_type
:
8456 return "DW_TAG_ptr_to_member_type";
8457 case DW_TAG_set_type
:
8458 return "DW_TAG_set_type";
8459 case DW_TAG_subrange_type
:
8460 return "DW_TAG_subrange_type";
8461 case DW_TAG_with_stmt
:
8462 return "DW_TAG_with_stmt";
8463 case DW_TAG_access_declaration
:
8464 return "DW_TAG_access_declaration";
8465 case DW_TAG_base_type
:
8466 return "DW_TAG_base_type";
8467 case DW_TAG_catch_block
:
8468 return "DW_TAG_catch_block";
8469 case DW_TAG_const_type
:
8470 return "DW_TAG_const_type";
8471 case DW_TAG_constant
:
8472 return "DW_TAG_constant";
8473 case DW_TAG_enumerator
:
8474 return "DW_TAG_enumerator";
8475 case DW_TAG_file_type
:
8476 return "DW_TAG_file_type";
8478 return "DW_TAG_friend";
8479 case DW_TAG_namelist
:
8480 return "DW_TAG_namelist";
8481 case DW_TAG_namelist_item
:
8482 return "DW_TAG_namelist_item";
8483 case DW_TAG_packed_type
:
8484 return "DW_TAG_packed_type";
8485 case DW_TAG_subprogram
:
8486 return "DW_TAG_subprogram";
8487 case DW_TAG_template_type_param
:
8488 return "DW_TAG_template_type_param";
8489 case DW_TAG_template_value_param
:
8490 return "DW_TAG_template_value_param";
8491 case DW_TAG_thrown_type
:
8492 return "DW_TAG_thrown_type";
8493 case DW_TAG_try_block
:
8494 return "DW_TAG_try_block";
8495 case DW_TAG_variant_part
:
8496 return "DW_TAG_variant_part";
8497 case DW_TAG_variable
:
8498 return "DW_TAG_variable";
8499 case DW_TAG_volatile_type
:
8500 return "DW_TAG_volatile_type";
8501 case DW_TAG_dwarf_procedure
:
8502 return "DW_TAG_dwarf_procedure";
8503 case DW_TAG_restrict_type
:
8504 return "DW_TAG_restrict_type";
8505 case DW_TAG_interface_type
:
8506 return "DW_TAG_interface_type";
8507 case DW_TAG_namespace
:
8508 return "DW_TAG_namespace";
8509 case DW_TAG_imported_module
:
8510 return "DW_TAG_imported_module";
8511 case DW_TAG_unspecified_type
:
8512 return "DW_TAG_unspecified_type";
8513 case DW_TAG_partial_unit
:
8514 return "DW_TAG_partial_unit";
8515 case DW_TAG_imported_unit
:
8516 return "DW_TAG_imported_unit";
8517 case DW_TAG_condition
:
8518 return "DW_TAG_condition";
8519 case DW_TAG_shared_type
:
8520 return "DW_TAG_shared_type";
8521 case DW_TAG_MIPS_loop
:
8522 return "DW_TAG_MIPS_loop";
8523 case DW_TAG_HP_array_descriptor
:
8524 return "DW_TAG_HP_array_descriptor";
8525 case DW_TAG_format_label
:
8526 return "DW_TAG_format_label";
8527 case DW_TAG_function_template
:
8528 return "DW_TAG_function_template";
8529 case DW_TAG_class_template
:
8530 return "DW_TAG_class_template";
8531 case DW_TAG_GNU_BINCL
:
8532 return "DW_TAG_GNU_BINCL";
8533 case DW_TAG_GNU_EINCL
:
8534 return "DW_TAG_GNU_EINCL";
8535 case DW_TAG_upc_shared_type
:
8536 return "DW_TAG_upc_shared_type";
8537 case DW_TAG_upc_strict_type
:
8538 return "DW_TAG_upc_strict_type";
8539 case DW_TAG_upc_relaxed_type
:
8540 return "DW_TAG_upc_relaxed_type";
8541 case DW_TAG_PGI_kanji_type
:
8542 return "DW_TAG_PGI_kanji_type";
8543 case DW_TAG_PGI_interface_block
:
8544 return "DW_TAG_PGI_interface_block";
8546 return "DW_TAG_<unknown>";
8550 /* Convert a DWARF attribute code into its string name. */
8553 dwarf_attr_name (unsigned attr
)
8558 return "DW_AT_sibling";
8559 case DW_AT_location
:
8560 return "DW_AT_location";
8562 return "DW_AT_name";
8563 case DW_AT_ordering
:
8564 return "DW_AT_ordering";
8565 case DW_AT_subscr_data
:
8566 return "DW_AT_subscr_data";
8567 case DW_AT_byte_size
:
8568 return "DW_AT_byte_size";
8569 case DW_AT_bit_offset
:
8570 return "DW_AT_bit_offset";
8571 case DW_AT_bit_size
:
8572 return "DW_AT_bit_size";
8573 case DW_AT_element_list
:
8574 return "DW_AT_element_list";
8575 case DW_AT_stmt_list
:
8576 return "DW_AT_stmt_list";
8578 return "DW_AT_low_pc";
8580 return "DW_AT_high_pc";
8581 case DW_AT_language
:
8582 return "DW_AT_language";
8584 return "DW_AT_member";
8586 return "DW_AT_discr";
8587 case DW_AT_discr_value
:
8588 return "DW_AT_discr_value";
8589 case DW_AT_visibility
:
8590 return "DW_AT_visibility";
8592 return "DW_AT_import";
8593 case DW_AT_string_length
:
8594 return "DW_AT_string_length";
8595 case DW_AT_common_reference
:
8596 return "DW_AT_common_reference";
8597 case DW_AT_comp_dir
:
8598 return "DW_AT_comp_dir";
8599 case DW_AT_const_value
:
8600 return "DW_AT_const_value";
8601 case DW_AT_containing_type
:
8602 return "DW_AT_containing_type";
8603 case DW_AT_default_value
:
8604 return "DW_AT_default_value";
8606 return "DW_AT_inline";
8607 case DW_AT_is_optional
:
8608 return "DW_AT_is_optional";
8609 case DW_AT_lower_bound
:
8610 return "DW_AT_lower_bound";
8611 case DW_AT_producer
:
8612 return "DW_AT_producer";
8613 case DW_AT_prototyped
:
8614 return "DW_AT_prototyped";
8615 case DW_AT_return_addr
:
8616 return "DW_AT_return_addr";
8617 case DW_AT_start_scope
:
8618 return "DW_AT_start_scope";
8619 case DW_AT_bit_stride
:
8620 return "DW_AT_bit_stride";
8621 case DW_AT_upper_bound
:
8622 return "DW_AT_upper_bound";
8623 case DW_AT_abstract_origin
:
8624 return "DW_AT_abstract_origin";
8625 case DW_AT_accessibility
:
8626 return "DW_AT_accessibility";
8627 case DW_AT_address_class
:
8628 return "DW_AT_address_class";
8629 case DW_AT_artificial
:
8630 return "DW_AT_artificial";
8631 case DW_AT_base_types
:
8632 return "DW_AT_base_types";
8633 case DW_AT_calling_convention
:
8634 return "DW_AT_calling_convention";
8636 return "DW_AT_count";
8637 case DW_AT_data_member_location
:
8638 return "DW_AT_data_member_location";
8639 case DW_AT_decl_column
:
8640 return "DW_AT_decl_column";
8641 case DW_AT_decl_file
:
8642 return "DW_AT_decl_file";
8643 case DW_AT_decl_line
:
8644 return "DW_AT_decl_line";
8645 case DW_AT_declaration
:
8646 return "DW_AT_declaration";
8647 case DW_AT_discr_list
:
8648 return "DW_AT_discr_list";
8649 case DW_AT_encoding
:
8650 return "DW_AT_encoding";
8651 case DW_AT_external
:
8652 return "DW_AT_external";
8653 case DW_AT_frame_base
:
8654 return "DW_AT_frame_base";
8656 return "DW_AT_friend";
8657 case DW_AT_identifier_case
:
8658 return "DW_AT_identifier_case";
8659 case DW_AT_macro_info
:
8660 return "DW_AT_macro_info";
8661 case DW_AT_namelist_items
:
8662 return "DW_AT_namelist_items";
8663 case DW_AT_priority
:
8664 return "DW_AT_priority";
8666 return "DW_AT_segment";
8667 case DW_AT_specification
:
8668 return "DW_AT_specification";
8669 case DW_AT_static_link
:
8670 return "DW_AT_static_link";
8672 return "DW_AT_type";
8673 case DW_AT_use_location
:
8674 return "DW_AT_use_location";
8675 case DW_AT_variable_parameter
:
8676 return "DW_AT_variable_parameter";
8677 case DW_AT_virtuality
:
8678 return "DW_AT_virtuality";
8679 case DW_AT_vtable_elem_location
:
8680 return "DW_AT_vtable_elem_location";
8681 /* DWARF 3 values. */
8682 case DW_AT_allocated
:
8683 return "DW_AT_allocated";
8684 case DW_AT_associated
:
8685 return "DW_AT_associated";
8686 case DW_AT_data_location
:
8687 return "DW_AT_data_location";
8688 case DW_AT_byte_stride
:
8689 return "DW_AT_byte_stride";
8690 case DW_AT_entry_pc
:
8691 return "DW_AT_entry_pc";
8692 case DW_AT_use_UTF8
:
8693 return "DW_AT_use_UTF8";
8694 case DW_AT_extension
:
8695 return "DW_AT_extension";
8697 return "DW_AT_ranges";
8698 case DW_AT_trampoline
:
8699 return "DW_AT_trampoline";
8700 case DW_AT_call_column
:
8701 return "DW_AT_call_column";
8702 case DW_AT_call_file
:
8703 return "DW_AT_call_file";
8704 case DW_AT_call_line
:
8705 return "DW_AT_call_line";
8706 case DW_AT_description
:
8707 return "DW_AT_description";
8708 case DW_AT_binary_scale
:
8709 return "DW_AT_binary_scale";
8710 case DW_AT_decimal_scale
:
8711 return "DW_AT_decimal_scale";
8713 return "DW_AT_small";
8714 case DW_AT_decimal_sign
:
8715 return "DW_AT_decimal_sign";
8716 case DW_AT_digit_count
:
8717 return "DW_AT_digit_count";
8718 case DW_AT_picture_string
:
8719 return "DW_AT_picture_string";
8721 return "DW_AT_mutable";
8722 case DW_AT_threads_scaled
:
8723 return "DW_AT_threads_scaled";
8724 case DW_AT_explicit
:
8725 return "DW_AT_explicit";
8726 case DW_AT_object_pointer
:
8727 return "DW_AT_object_pointer";
8728 case DW_AT_endianity
:
8729 return "DW_AT_endianity";
8730 case DW_AT_elemental
:
8731 return "DW_AT_elemental";
8733 return "DW_AT_pure";
8734 case DW_AT_recursive
:
8735 return "DW_AT_recursive";
8736 /* SGI/MIPS extensions. */
8737 #ifdef MIPS /* collides with DW_AT_HP_block_index */
8738 case DW_AT_MIPS_fde
:
8739 return "DW_AT_MIPS_fde";
8741 case DW_AT_MIPS_loop_begin
:
8742 return "DW_AT_MIPS_loop_begin";
8743 case DW_AT_MIPS_tail_loop_begin
:
8744 return "DW_AT_MIPS_tail_loop_begin";
8745 case DW_AT_MIPS_epilog_begin
:
8746 return "DW_AT_MIPS_epilog_begin";
8747 case DW_AT_MIPS_loop_unroll_factor
:
8748 return "DW_AT_MIPS_loop_unroll_factor";
8749 case DW_AT_MIPS_software_pipeline_depth
:
8750 return "DW_AT_MIPS_software_pipeline_depth";
8751 case DW_AT_MIPS_linkage_name
:
8752 return "DW_AT_MIPS_linkage_name";
8753 case DW_AT_MIPS_stride
:
8754 return "DW_AT_MIPS_stride";
8755 case DW_AT_MIPS_abstract_name
:
8756 return "DW_AT_MIPS_abstract_name";
8757 case DW_AT_MIPS_clone_origin
:
8758 return "DW_AT_MIPS_clone_origin";
8759 case DW_AT_MIPS_has_inlines
:
8760 return "DW_AT_MIPS_has_inlines";
8761 /* HP extensions. */
8762 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
8763 case DW_AT_HP_block_index
:
8764 return "DW_AT_HP_block_index";
8766 case DW_AT_HP_unmodifiable
:
8767 return "DW_AT_HP_unmodifiable";
8768 case DW_AT_HP_actuals_stmt_list
:
8769 return "DW_AT_HP_actuals_stmt_list";
8770 case DW_AT_HP_proc_per_section
:
8771 return "DW_AT_HP_proc_per_section";
8772 case DW_AT_HP_raw_data_ptr
:
8773 return "DW_AT_HP_raw_data_ptr";
8774 case DW_AT_HP_pass_by_reference
:
8775 return "DW_AT_HP_pass_by_reference";
8776 case DW_AT_HP_opt_level
:
8777 return "DW_AT_HP_opt_level";
8778 case DW_AT_HP_prof_version_id
:
8779 return "DW_AT_HP_prof_version_id";
8780 case DW_AT_HP_opt_flags
:
8781 return "DW_AT_HP_opt_flags";
8782 case DW_AT_HP_cold_region_low_pc
:
8783 return "DW_AT_HP_cold_region_low_pc";
8784 case DW_AT_HP_cold_region_high_pc
:
8785 return "DW_AT_HP_cold_region_high_pc";
8786 case DW_AT_HP_all_variables_modifiable
:
8787 return "DW_AT_HP_all_variables_modifiable";
8788 case DW_AT_HP_linkage_name
:
8789 return "DW_AT_HP_linkage_name";
8790 case DW_AT_HP_prof_flags
:
8791 return "DW_AT_HP_prof_flags";
8792 /* GNU extensions. */
8793 case DW_AT_sf_names
:
8794 return "DW_AT_sf_names";
8795 case DW_AT_src_info
:
8796 return "DW_AT_src_info";
8797 case DW_AT_mac_info
:
8798 return "DW_AT_mac_info";
8799 case DW_AT_src_coords
:
8800 return "DW_AT_src_coords";
8801 case DW_AT_body_begin
:
8802 return "DW_AT_body_begin";
8803 case DW_AT_body_end
:
8804 return "DW_AT_body_end";
8805 case DW_AT_GNU_vector
:
8806 return "DW_AT_GNU_vector";
8807 /* VMS extensions. */
8808 case DW_AT_VMS_rtnbeg_pd_address
:
8809 return "DW_AT_VMS_rtnbeg_pd_address";
8810 /* UPC extension. */
8811 case DW_AT_upc_threads_scaled
:
8812 return "DW_AT_upc_threads_scaled";
8813 /* PGI (STMicroelectronics) extensions. */
8814 case DW_AT_PGI_lbase
:
8815 return "DW_AT_PGI_lbase";
8816 case DW_AT_PGI_soffset
:
8817 return "DW_AT_PGI_soffset";
8818 case DW_AT_PGI_lstride
:
8819 return "DW_AT_PGI_lstride";
8821 return "DW_AT_<unknown>";
8825 /* Convert a DWARF value form code into its string name. */
8828 dwarf_form_name (unsigned form
)
8833 return "DW_FORM_addr";
8834 case DW_FORM_block2
:
8835 return "DW_FORM_block2";
8836 case DW_FORM_block4
:
8837 return "DW_FORM_block4";
8839 return "DW_FORM_data2";
8841 return "DW_FORM_data4";
8843 return "DW_FORM_data8";
8844 case DW_FORM_string
:
8845 return "DW_FORM_string";
8847 return "DW_FORM_block";
8848 case DW_FORM_block1
:
8849 return "DW_FORM_block1";
8851 return "DW_FORM_data1";
8853 return "DW_FORM_flag";
8855 return "DW_FORM_sdata";
8857 return "DW_FORM_strp";
8859 return "DW_FORM_udata";
8860 case DW_FORM_ref_addr
:
8861 return "DW_FORM_ref_addr";
8863 return "DW_FORM_ref1";
8865 return "DW_FORM_ref2";
8867 return "DW_FORM_ref4";
8869 return "DW_FORM_ref8";
8870 case DW_FORM_ref_udata
:
8871 return "DW_FORM_ref_udata";
8872 case DW_FORM_indirect
:
8873 return "DW_FORM_indirect";
8874 case GDB_FORM_cached_string
:
8875 return "GDB_FORM_cached_string";
8877 return "DW_FORM_<unknown>";
8881 /* Convert a DWARF stack opcode into its string name. */
8884 dwarf_stack_op_name (unsigned op
)
8889 return "DW_OP_addr";
8891 return "DW_OP_deref";
8893 return "DW_OP_const1u";
8895 return "DW_OP_const1s";
8897 return "DW_OP_const2u";
8899 return "DW_OP_const2s";
8901 return "DW_OP_const4u";
8903 return "DW_OP_const4s";
8905 return "DW_OP_const8u";
8907 return "DW_OP_const8s";
8909 return "DW_OP_constu";
8911 return "DW_OP_consts";
8915 return "DW_OP_drop";
8917 return "DW_OP_over";
8919 return "DW_OP_pick";
8921 return "DW_OP_swap";
8925 return "DW_OP_xderef";
8933 return "DW_OP_minus";
8945 return "DW_OP_plus";
8946 case DW_OP_plus_uconst
:
8947 return "DW_OP_plus_uconst";
8953 return "DW_OP_shra";
8971 return "DW_OP_skip";
8973 return "DW_OP_lit0";
8975 return "DW_OP_lit1";
8977 return "DW_OP_lit2";
8979 return "DW_OP_lit3";
8981 return "DW_OP_lit4";
8983 return "DW_OP_lit5";
8985 return "DW_OP_lit6";
8987 return "DW_OP_lit7";
8989 return "DW_OP_lit8";
8991 return "DW_OP_lit9";
8993 return "DW_OP_lit10";
8995 return "DW_OP_lit11";
8997 return "DW_OP_lit12";
8999 return "DW_OP_lit13";
9001 return "DW_OP_lit14";
9003 return "DW_OP_lit15";
9005 return "DW_OP_lit16";
9007 return "DW_OP_lit17";
9009 return "DW_OP_lit18";
9011 return "DW_OP_lit19";
9013 return "DW_OP_lit20";
9015 return "DW_OP_lit21";
9017 return "DW_OP_lit22";
9019 return "DW_OP_lit23";
9021 return "DW_OP_lit24";
9023 return "DW_OP_lit25";
9025 return "DW_OP_lit26";
9027 return "DW_OP_lit27";
9029 return "DW_OP_lit28";
9031 return "DW_OP_lit29";
9033 return "DW_OP_lit30";
9035 return "DW_OP_lit31";
9037 return "DW_OP_reg0";
9039 return "DW_OP_reg1";
9041 return "DW_OP_reg2";
9043 return "DW_OP_reg3";
9045 return "DW_OP_reg4";
9047 return "DW_OP_reg5";
9049 return "DW_OP_reg6";
9051 return "DW_OP_reg7";
9053 return "DW_OP_reg8";
9055 return "DW_OP_reg9";
9057 return "DW_OP_reg10";
9059 return "DW_OP_reg11";
9061 return "DW_OP_reg12";
9063 return "DW_OP_reg13";
9065 return "DW_OP_reg14";
9067 return "DW_OP_reg15";
9069 return "DW_OP_reg16";
9071 return "DW_OP_reg17";
9073 return "DW_OP_reg18";
9075 return "DW_OP_reg19";
9077 return "DW_OP_reg20";
9079 return "DW_OP_reg21";
9081 return "DW_OP_reg22";
9083 return "DW_OP_reg23";
9085 return "DW_OP_reg24";
9087 return "DW_OP_reg25";
9089 return "DW_OP_reg26";
9091 return "DW_OP_reg27";
9093 return "DW_OP_reg28";
9095 return "DW_OP_reg29";
9097 return "DW_OP_reg30";
9099 return "DW_OP_reg31";
9101 return "DW_OP_breg0";
9103 return "DW_OP_breg1";
9105 return "DW_OP_breg2";
9107 return "DW_OP_breg3";
9109 return "DW_OP_breg4";
9111 return "DW_OP_breg5";
9113 return "DW_OP_breg6";
9115 return "DW_OP_breg7";
9117 return "DW_OP_breg8";
9119 return "DW_OP_breg9";
9121 return "DW_OP_breg10";
9123 return "DW_OP_breg11";
9125 return "DW_OP_breg12";
9127 return "DW_OP_breg13";
9129 return "DW_OP_breg14";
9131 return "DW_OP_breg15";
9133 return "DW_OP_breg16";
9135 return "DW_OP_breg17";
9137 return "DW_OP_breg18";
9139 return "DW_OP_breg19";
9141 return "DW_OP_breg20";
9143 return "DW_OP_breg21";
9145 return "DW_OP_breg22";
9147 return "DW_OP_breg23";
9149 return "DW_OP_breg24";
9151 return "DW_OP_breg25";
9153 return "DW_OP_breg26";
9155 return "DW_OP_breg27";
9157 return "DW_OP_breg28";
9159 return "DW_OP_breg29";
9161 return "DW_OP_breg30";
9163 return "DW_OP_breg31";
9165 return "DW_OP_regx";
9167 return "DW_OP_fbreg";
9169 return "DW_OP_bregx";
9171 return "DW_OP_piece";
9172 case DW_OP_deref_size
:
9173 return "DW_OP_deref_size";
9174 case DW_OP_xderef_size
:
9175 return "DW_OP_xderef_size";
9178 /* DWARF 3 extensions. */
9179 case DW_OP_push_object_address
:
9180 return "DW_OP_push_object_address";
9182 return "DW_OP_call2";
9184 return "DW_OP_call4";
9185 case DW_OP_call_ref
:
9186 return "DW_OP_call_ref";
9187 /* GNU extensions. */
9188 case DW_OP_form_tls_address
:
9189 return "DW_OP_form_tls_address";
9190 case DW_OP_call_frame_cfa
:
9191 return "DW_OP_call_frame_cfa";
9192 case DW_OP_bit_piece
:
9193 return "DW_OP_bit_piece";
9194 case DW_OP_GNU_push_tls_address
:
9195 return "DW_OP_GNU_push_tls_address";
9196 case DW_OP_GNU_uninit
:
9197 return "DW_OP_GNU_uninit";
9198 /* HP extensions. */
9199 case DW_OP_HP_is_value
:
9200 return "DW_OP_HP_is_value";
9201 case DW_OP_HP_fltconst4
:
9202 return "DW_OP_HP_fltconst4";
9203 case DW_OP_HP_fltconst8
:
9204 return "DW_OP_HP_fltconst8";
9205 case DW_OP_HP_mod_range
:
9206 return "DW_OP_HP_mod_range";
9207 case DW_OP_HP_unmod_range
:
9208 return "DW_OP_HP_unmod_range";
9210 return "DW_OP_HP_tls";
9212 return "OP_<unknown>";
9217 dwarf_bool_name (unsigned mybool
)
9225 /* Convert a DWARF type code into its string name. */
9228 dwarf_type_encoding_name (unsigned enc
)
9233 return "DW_ATE_void";
9234 case DW_ATE_address
:
9235 return "DW_ATE_address";
9236 case DW_ATE_boolean
:
9237 return "DW_ATE_boolean";
9238 case DW_ATE_complex_float
:
9239 return "DW_ATE_complex_float";
9241 return "DW_ATE_float";
9243 return "DW_ATE_signed";
9244 case DW_ATE_signed_char
:
9245 return "DW_ATE_signed_char";
9246 case DW_ATE_unsigned
:
9247 return "DW_ATE_unsigned";
9248 case DW_ATE_unsigned_char
:
9249 return "DW_ATE_unsigned_char";
9251 case DW_ATE_imaginary_float
:
9252 return "DW_ATE_imaginary_float";
9253 case DW_ATE_packed_decimal
:
9254 return "DW_ATE_packed_decimal";
9255 case DW_ATE_numeric_string
:
9256 return "DW_ATE_numeric_string";
9258 return "DW_ATE_edited";
9259 case DW_ATE_signed_fixed
:
9260 return "DW_ATE_signed_fixed";
9261 case DW_ATE_unsigned_fixed
:
9262 return "DW_ATE_unsigned_fixed";
9263 case DW_ATE_decimal_float
:
9264 return "DW_ATE_decimal_float";
9265 /* HP extensions. */
9266 case DW_ATE_HP_float80
:
9267 return "DW_ATE_HP_float80";
9268 case DW_ATE_HP_complex_float80
:
9269 return "DW_ATE_HP_complex_float80";
9270 case DW_ATE_HP_float128
:
9271 return "DW_ATE_HP_float128";
9272 case DW_ATE_HP_complex_float128
:
9273 return "DW_ATE_HP_complex_float128";
9274 case DW_ATE_HP_floathpintel
:
9275 return "DW_ATE_HP_floathpintel";
9276 case DW_ATE_HP_imaginary_float80
:
9277 return "DW_ATE_HP_imaginary_float80";
9278 case DW_ATE_HP_imaginary_float128
:
9279 return "DW_ATE_HP_imaginary_float128";
9281 return "DW_ATE_<unknown>";
9285 /* Convert a DWARF call frame info operation to its string name. */
9289 dwarf_cfi_name (unsigned cfi_opc
)
9293 case DW_CFA_advance_loc
:
9294 return "DW_CFA_advance_loc";
9296 return "DW_CFA_offset";
9297 case DW_CFA_restore
:
9298 return "DW_CFA_restore";
9300 return "DW_CFA_nop";
9301 case DW_CFA_set_loc
:
9302 return "DW_CFA_set_loc";
9303 case DW_CFA_advance_loc1
:
9304 return "DW_CFA_advance_loc1";
9305 case DW_CFA_advance_loc2
:
9306 return "DW_CFA_advance_loc2";
9307 case DW_CFA_advance_loc4
:
9308 return "DW_CFA_advance_loc4";
9309 case DW_CFA_offset_extended
:
9310 return "DW_CFA_offset_extended";
9311 case DW_CFA_restore_extended
:
9312 return "DW_CFA_restore_extended";
9313 case DW_CFA_undefined
:
9314 return "DW_CFA_undefined";
9315 case DW_CFA_same_value
:
9316 return "DW_CFA_same_value";
9317 case DW_CFA_register
:
9318 return "DW_CFA_register";
9319 case DW_CFA_remember_state
:
9320 return "DW_CFA_remember_state";
9321 case DW_CFA_restore_state
:
9322 return "DW_CFA_restore_state";
9323 case DW_CFA_def_cfa
:
9324 return "DW_CFA_def_cfa";
9325 case DW_CFA_def_cfa_register
:
9326 return "DW_CFA_def_cfa_register";
9327 case DW_CFA_def_cfa_offset
:
9328 return "DW_CFA_def_cfa_offset";
9330 case DW_CFA_def_cfa_expression
:
9331 return "DW_CFA_def_cfa_expression";
9332 case DW_CFA_expression
:
9333 return "DW_CFA_expression";
9334 case DW_CFA_offset_extended_sf
:
9335 return "DW_CFA_offset_extended_sf";
9336 case DW_CFA_def_cfa_sf
:
9337 return "DW_CFA_def_cfa_sf";
9338 case DW_CFA_def_cfa_offset_sf
:
9339 return "DW_CFA_def_cfa_offset_sf";
9340 case DW_CFA_val_offset
:
9341 return "DW_CFA_val_offset";
9342 case DW_CFA_val_offset_sf
:
9343 return "DW_CFA_val_offset_sf";
9344 case DW_CFA_val_expression
:
9345 return "DW_CFA_val_expression";
9346 /* SGI/MIPS specific. */
9347 case DW_CFA_MIPS_advance_loc8
:
9348 return "DW_CFA_MIPS_advance_loc8";
9349 /* GNU extensions. */
9350 case DW_CFA_GNU_window_save
:
9351 return "DW_CFA_GNU_window_save";
9352 case DW_CFA_GNU_args_size
:
9353 return "DW_CFA_GNU_args_size";
9354 case DW_CFA_GNU_negative_offset_extended
:
9355 return "DW_CFA_GNU_negative_offset_extended";
9357 return "DW_CFA_<unknown>";
9363 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
9367 print_spaces (indent
, f
);
9368 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
9369 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
9371 if (die
->parent
!= NULL
)
9373 print_spaces (indent
, f
);
9374 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
9375 die
->parent
->offset
);
9378 print_spaces (indent
, f
);
9379 fprintf_unfiltered (f
, " has children: %s\n",
9380 dwarf_bool_name (die
->child
!= NULL
));
9382 print_spaces (indent
, f
);
9383 fprintf_unfiltered (f
, " attributes:\n");
9385 for (i
= 0; i
< die
->num_attrs
; ++i
)
9387 print_spaces (indent
, f
);
9388 fprintf_unfiltered (f
, " %s (%s) ",
9389 dwarf_attr_name (die
->attrs
[i
].name
),
9390 dwarf_form_name (die
->attrs
[i
].form
));
9392 switch (die
->attrs
[i
].form
)
9394 case DW_FORM_ref_addr
:
9396 fprintf_unfiltered (f
, "address: ");
9397 fputs_filtered (paddress (DW_ADDR (&die
->attrs
[i
])), f
);
9399 case DW_FORM_block2
:
9400 case DW_FORM_block4
:
9402 case DW_FORM_block1
:
9403 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
9408 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
9409 (long) (DW_ADDR (&die
->attrs
[i
])));
9417 fprintf_unfiltered (f
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
9419 case DW_FORM_string
:
9421 case GDB_FORM_cached_string
:
9422 fprintf_unfiltered (f
, "string: \"%s\"",
9423 DW_STRING (&die
->attrs
[i
])
9424 ? DW_STRING (&die
->attrs
[i
]) : "");
9427 if (DW_UNSND (&die
->attrs
[i
]))
9428 fprintf_unfiltered (f
, "flag: TRUE");
9430 fprintf_unfiltered (f
, "flag: FALSE");
9432 case DW_FORM_indirect
:
9433 /* the reader will have reduced the indirect form to
9434 the "base form" so this form should not occur */
9435 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
9438 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
9439 die
->attrs
[i
].form
);
9442 fprintf_unfiltered (f
, "\n");
9447 dump_die_for_error (struct die_info
*die
)
9449 dump_die_shallow (gdb_stderr
, 0, die
);
9453 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
9455 int indent
= level
* 4;
9457 gdb_assert (die
!= NULL
);
9459 if (level
>= max_level
)
9462 dump_die_shallow (f
, indent
, die
);
9464 if (die
->child
!= NULL
)
9466 print_spaces (indent
, f
);
9467 fprintf_unfiltered (f
, " Children:");
9468 if (level
+ 1 < max_level
)
9470 fprintf_unfiltered (f
, "\n");
9471 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
9475 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
9479 if (die
->sibling
!= NULL
&& level
> 0)
9481 dump_die_1 (f
, level
, max_level
, die
->sibling
);
9485 /* This is called from the pdie macro in gdbinit.in.
9486 It's not static so gcc will keep a copy callable from gdb. */
9489 dump_die (struct die_info
*die
, int max_level
)
9491 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
9495 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
9499 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
9505 dwarf2_get_ref_die_offset (struct attribute
*attr
)
9507 unsigned int result
= 0;
9511 case DW_FORM_ref_addr
:
9516 case DW_FORM_ref_udata
:
9517 result
= DW_ADDR (attr
);
9520 complaint (&symfile_complaints
,
9521 _("unsupported die ref attribute form: '%s'"),
9522 dwarf_form_name (attr
->form
));
9527 /* Return the constant value held by the given attribute. Return -1
9528 if the value held by the attribute is not constant. */
9531 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
9533 if (attr
->form
== DW_FORM_sdata
)
9534 return DW_SND (attr
);
9535 else if (attr
->form
== DW_FORM_udata
9536 || attr
->form
== DW_FORM_data1
9537 || attr
->form
== DW_FORM_data2
9538 || attr
->form
== DW_FORM_data4
9539 || attr
->form
== DW_FORM_data8
)
9540 return DW_UNSND (attr
);
9543 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
9544 dwarf_form_name (attr
->form
));
9545 return default_value
;
9549 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
9550 unit and add it to our queue. */
9553 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
9554 struct dwarf2_per_cu_data
*per_cu
)
9556 /* Mark the dependence relation so that we don't flush PER_CU
9558 dwarf2_add_dependence (this_cu
, per_cu
);
9560 /* If it's already on the queue, we have nothing to do. */
9564 /* If the compilation unit is already loaded, just mark it as
9566 if (per_cu
->cu
!= NULL
)
9568 per_cu
->cu
->last_used
= 0;
9572 /* Add it to the queue. */
9573 queue_comp_unit (per_cu
, this_cu
->objfile
);
9576 /* Follow reference attribute ATTR of SRC_DIE.
9577 On entry *REF_CU is the CU of SRC_DIE.
9578 On exit *REF_CU is the CU of the result. */
9580 static struct die_info
*
9581 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
9582 struct dwarf2_cu
**ref_cu
)
9584 struct die_info
*die
;
9585 unsigned int offset
;
9586 struct die_info temp_die
;
9587 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
9589 offset
= dwarf2_get_ref_die_offset (attr
);
9591 if (! offset_in_cu_p (&cu
->header
, offset
))
9593 struct dwarf2_per_cu_data
*per_cu
;
9594 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9596 /* If necessary, add it to the queue and load its DIEs. */
9597 maybe_queue_comp_unit (cu
, per_cu
);
9599 target_cu
= per_cu
->cu
;
9604 *ref_cu
= target_cu
;
9605 temp_die
.offset
= offset
;
9606 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
9610 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
9611 "at 0x%lx [in module %s]"),
9612 (long) offset
, (long) src_die
->offset
, cu
->objfile
->name
);
9615 /* Decode simple location descriptions.
9616 Given a pointer to a dwarf block that defines a location, compute
9617 the location and return the value.
9619 NOTE drow/2003-11-18: This function is called in two situations
9620 now: for the address of static or global variables (partial symbols
9621 only) and for offsets into structures which are expected to be
9622 (more or less) constant. The partial symbol case should go away,
9623 and only the constant case should remain. That will let this
9624 function complain more accurately. A few special modes are allowed
9625 without complaint for global variables (for instance, global
9626 register values and thread-local values).
9628 A location description containing no operations indicates that the
9629 object is optimized out. The return value is 0 for that case.
9630 FIXME drow/2003-11-16: No callers check for this case any more; soon all
9631 callers will only want a very basic result and this can become a
9634 Note that stack[0] is unused except as a default error return.
9635 Note that stack overflow is not yet handled. */
9638 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
9640 struct objfile
*objfile
= cu
->objfile
;
9641 struct comp_unit_head
*cu_header
= &cu
->header
;
9643 int size
= blk
->size
;
9644 gdb_byte
*data
= blk
->data
;
9645 CORE_ADDR stack
[64];
9647 unsigned int bytes_read
, unsnd
;
9691 stack
[++stacki
] = op
- DW_OP_lit0
;
9726 stack
[++stacki
] = op
- DW_OP_reg0
;
9728 dwarf2_complex_location_expr_complaint ();
9732 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9734 stack
[++stacki
] = unsnd
;
9736 dwarf2_complex_location_expr_complaint ();
9740 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
9746 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
9751 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
9756 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
9761 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
9766 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
9771 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
9776 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
9782 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
9787 stack
[stacki
+ 1] = stack
[stacki
];
9792 stack
[stacki
- 1] += stack
[stacki
];
9796 case DW_OP_plus_uconst
:
9797 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9802 stack
[stacki
- 1] -= stack
[stacki
];
9807 /* If we're not the last op, then we definitely can't encode
9808 this using GDB's address_class enum. This is valid for partial
9809 global symbols, although the variable's address will be bogus
9812 dwarf2_complex_location_expr_complaint ();
9815 case DW_OP_GNU_push_tls_address
:
9816 /* The top of the stack has the offset from the beginning
9817 of the thread control block at which the variable is located. */
9818 /* Nothing should follow this operator, so the top of stack would
9820 /* This is valid for partial global symbols, but the variable's
9821 address will be bogus in the psymtab. */
9823 dwarf2_complex_location_expr_complaint ();
9826 case DW_OP_GNU_uninit
:
9830 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
9831 dwarf_stack_op_name (op
));
9832 return (stack
[stacki
]);
9835 return (stack
[stacki
]);
9838 /* memory allocation interface */
9840 static struct dwarf_block
*
9841 dwarf_alloc_block (struct dwarf2_cu
*cu
)
9843 struct dwarf_block
*blk
;
9845 blk
= (struct dwarf_block
*)
9846 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
9850 static struct abbrev_info
*
9851 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
9853 struct abbrev_info
*abbrev
;
9855 abbrev
= (struct abbrev_info
*)
9856 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
9857 memset (abbrev
, 0, sizeof (struct abbrev_info
));
9861 static struct die_info
*
9862 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
9864 struct die_info
*die
;
9865 size_t size
= sizeof (struct die_info
);
9868 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
9870 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
9871 memset (die
, 0, sizeof (struct die_info
));
9876 /* Macro support. */
9879 /* Return the full name of file number I in *LH's file name table.
9880 Use COMP_DIR as the name of the current directory of the
9881 compilation. The result is allocated using xmalloc; the caller is
9882 responsible for freeing it. */
9884 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
9886 /* Is the file number a valid index into the line header's file name
9887 table? Remember that file numbers start with one, not zero. */
9888 if (1 <= file
&& file
<= lh
->num_file_names
)
9890 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9892 if (IS_ABSOLUTE_PATH (fe
->name
))
9893 return xstrdup (fe
->name
);
9901 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9907 dir_len
= strlen (dir
);
9908 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
9909 strcpy (full_name
, dir
);
9910 full_name
[dir_len
] = '/';
9911 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
9915 return xstrdup (fe
->name
);
9920 /* The compiler produced a bogus file number. We can at least
9921 record the macro definitions made in the file, even if we
9922 won't be able to find the file by name. */
9924 sprintf (fake_name
, "<bad macro file number %d>", file
);
9926 complaint (&symfile_complaints
,
9927 _("bad file number in macro information (%d)"),
9930 return xstrdup (fake_name
);
9935 static struct macro_source_file
*
9936 macro_start_file (int file
, int line
,
9937 struct macro_source_file
*current_file
,
9938 const char *comp_dir
,
9939 struct line_header
*lh
, struct objfile
*objfile
)
9941 /* The full name of this source file. */
9942 char *full_name
= file_full_name (file
, lh
, comp_dir
);
9944 /* We don't create a macro table for this compilation unit
9945 at all until we actually get a filename. */
9946 if (! pending_macros
)
9947 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
9948 objfile
->macro_cache
);
9951 /* If we have no current file, then this must be the start_file
9952 directive for the compilation unit's main source file. */
9953 current_file
= macro_set_main (pending_macros
, full_name
);
9955 current_file
= macro_include (current_file
, line
, full_name
);
9959 return current_file
;
9963 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
9964 followed by a null byte. */
9966 copy_string (const char *buf
, int len
)
9968 char *s
= xmalloc (len
+ 1);
9969 memcpy (s
, buf
, len
);
9977 consume_improper_spaces (const char *p
, const char *body
)
9981 complaint (&symfile_complaints
,
9982 _("macro definition contains spaces in formal argument list:\n`%s'"),
9994 parse_macro_definition (struct macro_source_file
*file
, int line
,
9999 /* The body string takes one of two forms. For object-like macro
10000 definitions, it should be:
10002 <macro name> " " <definition>
10004 For function-like macro definitions, it should be:
10006 <macro name> "() " <definition>
10008 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
10010 Spaces may appear only where explicitly indicated, and in the
10013 The Dwarf 2 spec says that an object-like macro's name is always
10014 followed by a space, but versions of GCC around March 2002 omit
10015 the space when the macro's definition is the empty string.
10017 The Dwarf 2 spec says that there should be no spaces between the
10018 formal arguments in a function-like macro's formal argument list,
10019 but versions of GCC around March 2002 include spaces after the
10023 /* Find the extent of the macro name. The macro name is terminated
10024 by either a space or null character (for an object-like macro) or
10025 an opening paren (for a function-like macro). */
10026 for (p
= body
; *p
; p
++)
10027 if (*p
== ' ' || *p
== '(')
10030 if (*p
== ' ' || *p
== '\0')
10032 /* It's an object-like macro. */
10033 int name_len
= p
- body
;
10034 char *name
= copy_string (body
, name_len
);
10035 const char *replacement
;
10038 replacement
= body
+ name_len
+ 1;
10041 dwarf2_macro_malformed_definition_complaint (body
);
10042 replacement
= body
+ name_len
;
10045 macro_define_object (file
, line
, name
, replacement
);
10049 else if (*p
== '(')
10051 /* It's a function-like macro. */
10052 char *name
= copy_string (body
, p
- body
);
10055 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
10059 p
= consume_improper_spaces (p
, body
);
10061 /* Parse the formal argument list. */
10062 while (*p
&& *p
!= ')')
10064 /* Find the extent of the current argument name. */
10065 const char *arg_start
= p
;
10067 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
10070 if (! *p
|| p
== arg_start
)
10071 dwarf2_macro_malformed_definition_complaint (body
);
10074 /* Make sure argv has room for the new argument. */
10075 if (argc
>= argv_size
)
10078 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
10081 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
10084 p
= consume_improper_spaces (p
, body
);
10086 /* Consume the comma, if present. */
10091 p
= consume_improper_spaces (p
, body
);
10100 /* Perfectly formed definition, no complaints. */
10101 macro_define_function (file
, line
, name
,
10102 argc
, (const char **) argv
,
10104 else if (*p
== '\0')
10106 /* Complain, but do define it. */
10107 dwarf2_macro_malformed_definition_complaint (body
);
10108 macro_define_function (file
, line
, name
,
10109 argc
, (const char **) argv
,
10113 /* Just complain. */
10114 dwarf2_macro_malformed_definition_complaint (body
);
10117 /* Just complain. */
10118 dwarf2_macro_malformed_definition_complaint (body
);
10124 for (i
= 0; i
< argc
; i
++)
10130 dwarf2_macro_malformed_definition_complaint (body
);
10135 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
10136 char *comp_dir
, bfd
*abfd
,
10137 struct dwarf2_cu
*cu
)
10139 gdb_byte
*mac_ptr
, *mac_end
;
10140 struct macro_source_file
*current_file
= 0;
10141 enum dwarf_macinfo_record_type macinfo_type
;
10142 int at_commandline
;
10144 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
10146 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
10150 /* First pass: Find the name of the base filename.
10151 This filename is needed in order to process all macros whose definition
10152 (or undefinition) comes from the command line. These macros are defined
10153 before the first DW_MACINFO_start_file entry, and yet still need to be
10154 associated to the base file.
10156 To determine the base file name, we scan the macro definitions until we
10157 reach the first DW_MACINFO_start_file entry. We then initialize
10158 CURRENT_FILE accordingly so that any macro definition found before the
10159 first DW_MACINFO_start_file can still be associated to the base file. */
10161 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
10162 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
10163 + dwarf2_per_objfile
->macinfo
.size
;
10167 /* Do we at least have room for a macinfo type byte? */
10168 if (mac_ptr
>= mac_end
)
10170 /* Complaint is printed during the second pass as GDB will probably
10171 stop the first pass earlier upon finding DW_MACINFO_start_file. */
10175 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
10178 switch (macinfo_type
)
10180 /* A zero macinfo type indicates the end of the macro
10185 case DW_MACINFO_define
:
10186 case DW_MACINFO_undef
:
10187 /* Only skip the data by MAC_PTR. */
10189 unsigned int bytes_read
;
10191 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10192 mac_ptr
+= bytes_read
;
10193 read_string (abfd
, mac_ptr
, &bytes_read
);
10194 mac_ptr
+= bytes_read
;
10198 case DW_MACINFO_start_file
:
10200 unsigned int bytes_read
;
10203 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10204 mac_ptr
+= bytes_read
;
10205 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10206 mac_ptr
+= bytes_read
;
10208 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
10213 case DW_MACINFO_end_file
:
10214 /* No data to skip by MAC_PTR. */
10217 case DW_MACINFO_vendor_ext
:
10218 /* Only skip the data by MAC_PTR. */
10220 unsigned int bytes_read
;
10222 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10223 mac_ptr
+= bytes_read
;
10224 read_string (abfd
, mac_ptr
, &bytes_read
);
10225 mac_ptr
+= bytes_read
;
10232 } while (macinfo_type
!= 0 && current_file
== NULL
);
10234 /* Second pass: Process all entries.
10236 Use the AT_COMMAND_LINE flag to determine whether we are still processing
10237 command-line macro definitions/undefinitions. This flag is unset when we
10238 reach the first DW_MACINFO_start_file entry. */
10240 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
10242 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
10243 GDB is still reading the definitions from command line. First
10244 DW_MACINFO_start_file will need to be ignored as it was already executed
10245 to create CURRENT_FILE for the main source holding also the command line
10246 definitions. On first met DW_MACINFO_start_file this flag is reset to
10247 normally execute all the remaining DW_MACINFO_start_file macinfos. */
10249 at_commandline
= 1;
10253 /* Do we at least have room for a macinfo type byte? */
10254 if (mac_ptr
>= mac_end
)
10256 dwarf2_macros_too_long_complaint ();
10260 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
10263 switch (macinfo_type
)
10265 /* A zero macinfo type indicates the end of the macro
10270 case DW_MACINFO_define
:
10271 case DW_MACINFO_undef
:
10273 unsigned int bytes_read
;
10277 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10278 mac_ptr
+= bytes_read
;
10279 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
10280 mac_ptr
+= bytes_read
;
10282 if (! current_file
)
10284 /* DWARF violation as no main source is present. */
10285 complaint (&symfile_complaints
,
10286 _("debug info with no main source gives macro %s "
10289 DW_MACINFO_define
? _("definition") : macinfo_type
==
10290 DW_MACINFO_undef
? _("undefinition") :
10291 "something-or-other", line
, body
);
10294 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
10295 complaint (&symfile_complaints
,
10296 _("debug info gives %s macro %s with %s line %d: %s"),
10297 at_commandline
? _("command-line") : _("in-file"),
10299 DW_MACINFO_define
? _("definition") : macinfo_type
==
10300 DW_MACINFO_undef
? _("undefinition") :
10301 "something-or-other",
10302 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
10304 if (macinfo_type
== DW_MACINFO_define
)
10305 parse_macro_definition (current_file
, line
, body
);
10306 else if (macinfo_type
== DW_MACINFO_undef
)
10307 macro_undef (current_file
, line
, body
);
10311 case DW_MACINFO_start_file
:
10313 unsigned int bytes_read
;
10316 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10317 mac_ptr
+= bytes_read
;
10318 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10319 mac_ptr
+= bytes_read
;
10321 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
10322 complaint (&symfile_complaints
,
10323 _("debug info gives source %d included "
10324 "from %s at %s line %d"),
10325 file
, at_commandline
? _("command-line") : _("file"),
10326 line
== 0 ? _("zero") : _("non-zero"), line
);
10328 if (at_commandline
)
10330 /* This DW_MACINFO_start_file was executed in the pass one. */
10331 at_commandline
= 0;
10334 current_file
= macro_start_file (file
, line
,
10335 current_file
, comp_dir
,
10340 case DW_MACINFO_end_file
:
10341 if (! current_file
)
10342 complaint (&symfile_complaints
,
10343 _("macro debug info has an unmatched `close_file' directive"));
10346 current_file
= current_file
->included_by
;
10347 if (! current_file
)
10349 enum dwarf_macinfo_record_type next_type
;
10351 /* GCC circa March 2002 doesn't produce the zero
10352 type byte marking the end of the compilation
10353 unit. Complain if it's not there, but exit no
10356 /* Do we at least have room for a macinfo type byte? */
10357 if (mac_ptr
>= mac_end
)
10359 dwarf2_macros_too_long_complaint ();
10363 /* We don't increment mac_ptr here, so this is just
10365 next_type
= read_1_byte (abfd
, mac_ptr
);
10366 if (next_type
!= 0)
10367 complaint (&symfile_complaints
,
10368 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
10375 case DW_MACINFO_vendor_ext
:
10377 unsigned int bytes_read
;
10381 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10382 mac_ptr
+= bytes_read
;
10383 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
10384 mac_ptr
+= bytes_read
;
10386 /* We don't recognize any vendor extensions. */
10390 } while (macinfo_type
!= 0);
10393 /* Check if the attribute's form is a DW_FORM_block*
10394 if so return true else false. */
10396 attr_form_is_block (struct attribute
*attr
)
10398 return (attr
== NULL
? 0 :
10399 attr
->form
== DW_FORM_block1
10400 || attr
->form
== DW_FORM_block2
10401 || attr
->form
== DW_FORM_block4
10402 || attr
->form
== DW_FORM_block
);
10405 /* Return non-zero if ATTR's value is a section offset --- classes
10406 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
10407 You may use DW_UNSND (attr) to retrieve such offsets.
10409 Section 7.5.4, "Attribute Encodings", explains that no attribute
10410 may have a value that belongs to more than one of these classes; it
10411 would be ambiguous if we did, because we use the same forms for all
10414 attr_form_is_section_offset (struct attribute
*attr
)
10416 return (attr
->form
== DW_FORM_data4
10417 || attr
->form
== DW_FORM_data8
);
10421 /* Return non-zero if ATTR's value falls in the 'constant' class, or
10422 zero otherwise. When this function returns true, you can apply
10423 dwarf2_get_attr_constant_value to it.
10425 However, note that for some attributes you must check
10426 attr_form_is_section_offset before using this test. DW_FORM_data4
10427 and DW_FORM_data8 are members of both the constant class, and of
10428 the classes that contain offsets into other debug sections
10429 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
10430 that, if an attribute's can be either a constant or one of the
10431 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
10432 taken as section offsets, not constants. */
10434 attr_form_is_constant (struct attribute
*attr
)
10436 switch (attr
->form
)
10438 case DW_FORM_sdata
:
10439 case DW_FORM_udata
:
10440 case DW_FORM_data1
:
10441 case DW_FORM_data2
:
10442 case DW_FORM_data4
:
10443 case DW_FORM_data8
:
10451 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
10452 struct dwarf2_cu
*cu
)
10454 if (attr_form_is_section_offset (attr
)
10455 /* ".debug_loc" may not exist at all, or the offset may be outside
10456 the section. If so, fall through to the complaint in the
10458 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc
.size
)
10460 struct dwarf2_loclist_baton
*baton
;
10462 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
10463 sizeof (struct dwarf2_loclist_baton
));
10464 baton
->per_cu
= cu
->per_cu
;
10465 gdb_assert (baton
->per_cu
);
10467 /* We don't know how long the location list is, but make sure we
10468 don't run off the edge of the section. */
10469 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
10470 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
10471 baton
->base_address
= cu
->base_address
;
10472 if (cu
->base_known
== 0)
10473 complaint (&symfile_complaints
,
10474 _("Location list used without specifying the CU base address."));
10476 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
10477 SYMBOL_LOCATION_BATON (sym
) = baton
;
10481 struct dwarf2_locexpr_baton
*baton
;
10483 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
10484 sizeof (struct dwarf2_locexpr_baton
));
10485 baton
->per_cu
= cu
->per_cu
;
10486 gdb_assert (baton
->per_cu
);
10488 if (attr_form_is_block (attr
))
10490 /* Note that we're just copying the block's data pointer
10491 here, not the actual data. We're still pointing into the
10492 info_buffer for SYM's objfile; right now we never release
10493 that buffer, but when we do clean up properly this may
10495 baton
->size
= DW_BLOCK (attr
)->size
;
10496 baton
->data
= DW_BLOCK (attr
)->data
;
10500 dwarf2_invalid_attrib_class_complaint ("location description",
10501 SYMBOL_NATURAL_NAME (sym
));
10503 baton
->data
= NULL
;
10506 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
10507 SYMBOL_LOCATION_BATON (sym
) = baton
;
10511 /* Return the OBJFILE associated with the compilation unit CU. */
10514 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
10516 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10518 /* Return the master objfile, so that we can report and look up the
10519 correct file containing this variable. */
10520 if (objfile
->separate_debug_objfile_backlink
)
10521 objfile
= objfile
->separate_debug_objfile_backlink
;
10526 /* Return the address size given in the compilation unit header for CU. */
10529 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
10532 return per_cu
->cu
->header
.addr_size
;
10535 /* If the CU is not currently read in, we re-read its header. */
10536 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10537 struct dwarf2_per_objfile
*per_objfile
10538 = objfile_data (objfile
, dwarf2_objfile_data_key
);
10539 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
10541 struct comp_unit_head cu_header
;
10542 memset (&cu_header
, 0, sizeof cu_header
);
10543 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
10544 return cu_header
.addr_size
;
10548 /* Locate the compilation unit from CU's objfile which contains the
10549 DIE at OFFSET. Raises an error on failure. */
10551 static struct dwarf2_per_cu_data
*
10552 dwarf2_find_containing_comp_unit (unsigned int offset
,
10553 struct objfile
*objfile
)
10555 struct dwarf2_per_cu_data
*this_cu
;
10559 high
= dwarf2_per_objfile
->n_comp_units
- 1;
10562 int mid
= low
+ (high
- low
) / 2;
10563 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
10568 gdb_assert (low
== high
);
10569 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
10572 error (_("Dwarf Error: could not find partial DIE containing "
10573 "offset 0x%lx [in module %s]"),
10574 (long) offset
, bfd_get_filename (objfile
->obfd
));
10576 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
10577 return dwarf2_per_objfile
->all_comp_units
[low
-1];
10581 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
10582 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
10583 && offset
>= this_cu
->offset
+ this_cu
->length
)
10584 error (_("invalid dwarf2 offset %u"), offset
);
10585 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
10590 /* Locate the compilation unit from OBJFILE which is located at exactly
10591 OFFSET. Raises an error on failure. */
10593 static struct dwarf2_per_cu_data
*
10594 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
10596 struct dwarf2_per_cu_data
*this_cu
;
10597 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10598 if (this_cu
->offset
!= offset
)
10599 error (_("no compilation unit with offset %u."), offset
);
10603 /* Release one cached compilation unit, CU. We unlink it from the tree
10604 of compilation units, but we don't remove it from the read_in_chain;
10605 the caller is responsible for that. */
10608 free_one_comp_unit (void *data
)
10610 struct dwarf2_cu
*cu
= data
;
10612 if (cu
->per_cu
!= NULL
)
10613 cu
->per_cu
->cu
= NULL
;
10616 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10621 /* This cleanup function is passed the address of a dwarf2_cu on the stack
10622 when we're finished with it. We can't free the pointer itself, but be
10623 sure to unlink it from the cache. Also release any associated storage
10624 and perform cache maintenance.
10626 Only used during partial symbol parsing. */
10629 free_stack_comp_unit (void *data
)
10631 struct dwarf2_cu
*cu
= data
;
10633 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10634 cu
->partial_dies
= NULL
;
10636 if (cu
->per_cu
!= NULL
)
10638 /* This compilation unit is on the stack in our caller, so we
10639 should not xfree it. Just unlink it. */
10640 cu
->per_cu
->cu
= NULL
;
10643 /* If we had a per-cu pointer, then we may have other compilation
10644 units loaded, so age them now. */
10645 age_cached_comp_units ();
10649 /* Free all cached compilation units. */
10652 free_cached_comp_units (void *data
)
10654 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10656 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10657 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10658 while (per_cu
!= NULL
)
10660 struct dwarf2_per_cu_data
*next_cu
;
10662 next_cu
= per_cu
->cu
->read_in_chain
;
10664 free_one_comp_unit (per_cu
->cu
);
10665 *last_chain
= next_cu
;
10671 /* Increase the age counter on each cached compilation unit, and free
10672 any that are too old. */
10675 age_cached_comp_units (void)
10677 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10679 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
10680 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10681 while (per_cu
!= NULL
)
10683 per_cu
->cu
->last_used
++;
10684 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
10685 dwarf2_mark (per_cu
->cu
);
10686 per_cu
= per_cu
->cu
->read_in_chain
;
10689 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10690 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10691 while (per_cu
!= NULL
)
10693 struct dwarf2_per_cu_data
*next_cu
;
10695 next_cu
= per_cu
->cu
->read_in_chain
;
10697 if (!per_cu
->cu
->mark
)
10699 free_one_comp_unit (per_cu
->cu
);
10700 *last_chain
= next_cu
;
10703 last_chain
= &per_cu
->cu
->read_in_chain
;
10709 /* Remove a single compilation unit from the cache. */
10712 free_one_cached_comp_unit (void *target_cu
)
10714 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10716 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10717 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10718 while (per_cu
!= NULL
)
10720 struct dwarf2_per_cu_data
*next_cu
;
10722 next_cu
= per_cu
->cu
->read_in_chain
;
10724 if (per_cu
->cu
== target_cu
)
10726 free_one_comp_unit (per_cu
->cu
);
10727 *last_chain
= next_cu
;
10731 last_chain
= &per_cu
->cu
->read_in_chain
;
10737 /* Release all extra memory associated with OBJFILE. */
10740 dwarf2_free_objfile (struct objfile
*objfile
)
10742 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
10744 if (dwarf2_per_objfile
== NULL
)
10747 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
10748 free_cached_comp_units (NULL
);
10750 /* Everything else should be on the objfile obstack. */
10753 /* A pair of DIE offset and GDB type pointer. We store these
10754 in a hash table separate from the DIEs, and preserve them
10755 when the DIEs are flushed out of cache. */
10757 struct dwarf2_offset_and_type
10759 unsigned int offset
;
10763 /* Hash function for a dwarf2_offset_and_type. */
10766 offset_and_type_hash (const void *item
)
10768 const struct dwarf2_offset_and_type
*ofs
= item
;
10769 return ofs
->offset
;
10772 /* Equality function for a dwarf2_offset_and_type. */
10775 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
10777 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
10778 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
10779 return ofs_lhs
->offset
== ofs_rhs
->offset
;
10782 /* Set the type associated with DIE to TYPE. Save it in CU's hash
10783 table if necessary. For convenience, return TYPE. */
10785 static struct type
*
10786 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10788 struct dwarf2_offset_and_type
**slot
, ofs
;
10790 if (cu
->type_hash
== NULL
)
10792 gdb_assert (cu
->per_cu
!= NULL
);
10793 cu
->per_cu
->type_hash
10794 = htab_create_alloc_ex (cu
->header
.length
/ 24,
10795 offset_and_type_hash
,
10796 offset_and_type_eq
,
10798 &cu
->objfile
->objfile_obstack
,
10799 hashtab_obstack_allocate
,
10800 dummy_obstack_deallocate
);
10801 cu
->type_hash
= cu
->per_cu
->type_hash
;
10804 ofs
.offset
= die
->offset
;
10806 slot
= (struct dwarf2_offset_and_type
**)
10807 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
10808 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
10813 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
10814 not have a saved type. */
10816 static struct type
*
10817 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10819 struct dwarf2_offset_and_type
*slot
, ofs
;
10820 htab_t type_hash
= cu
->type_hash
;
10822 if (type_hash
== NULL
)
10825 ofs
.offset
= die
->offset
;
10826 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
10833 /* Add a dependence relationship from CU to REF_PER_CU. */
10836 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
10837 struct dwarf2_per_cu_data
*ref_per_cu
)
10841 if (cu
->dependencies
== NULL
)
10843 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
10844 NULL
, &cu
->comp_unit_obstack
,
10845 hashtab_obstack_allocate
,
10846 dummy_obstack_deallocate
);
10848 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
10850 *slot
= ref_per_cu
;
10853 /* Subroutine of dwarf2_mark to pass to htab_traverse.
10854 Set the mark field in every compilation unit in the
10855 cache that we must keep because we are keeping CU. */
10858 dwarf2_mark_helper (void **slot
, void *data
)
10860 struct dwarf2_per_cu_data
*per_cu
;
10862 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
10863 if (per_cu
->cu
->mark
)
10865 per_cu
->cu
->mark
= 1;
10867 if (per_cu
->cu
->dependencies
!= NULL
)
10868 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10873 /* Set the mark field in CU and in every other compilation unit in the
10874 cache that we must keep because we are keeping CU. */
10877 dwarf2_mark (struct dwarf2_cu
*cu
)
10882 if (cu
->dependencies
!= NULL
)
10883 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10887 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
10891 per_cu
->cu
->mark
= 0;
10892 per_cu
= per_cu
->cu
->read_in_chain
;
10896 /* Trivial hash function for partial_die_info: the hash value of a DIE
10897 is its offset in .debug_info for this objfile. */
10900 partial_die_hash (const void *item
)
10902 const struct partial_die_info
*part_die
= item
;
10903 return part_die
->offset
;
10906 /* Trivial comparison function for partial_die_info structures: two DIEs
10907 are equal if they have the same offset. */
10910 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
10912 const struct partial_die_info
*part_die_lhs
= item_lhs
;
10913 const struct partial_die_info
*part_die_rhs
= item_rhs
;
10914 return part_die_lhs
->offset
== part_die_rhs
->offset
;
10917 static struct cmd_list_element
*set_dwarf2_cmdlist
;
10918 static struct cmd_list_element
*show_dwarf2_cmdlist
;
10921 set_dwarf2_cmd (char *args
, int from_tty
)
10923 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
10927 show_dwarf2_cmd (char *args
, int from_tty
)
10929 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
10932 /* If section described by INFO was mmapped, munmap it now. */
10935 munmap_section_buffer (struct dwarf2_section_info
*info
)
10937 if (info
->was_mmapped
)
10940 intptr_t begin
= (intptr_t) info
->buffer
;
10941 intptr_t map_begin
= begin
& ~(pagesize
- 1);
10942 size_t map_length
= info
->size
+ begin
- map_begin
;
10943 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
10945 /* Without HAVE_MMAP, we should never be here to begin with. */
10951 /* munmap debug sections for OBJFILE, if necessary. */
10954 dwarf2_per_objfile_cleanup (struct objfile
*objfile
, void *d
)
10956 struct dwarf2_per_objfile
*data
= d
;
10957 munmap_section_buffer (&data
->info
);
10958 munmap_section_buffer (&data
->abbrev
);
10959 munmap_section_buffer (&data
->line
);
10960 munmap_section_buffer (&data
->str
);
10961 munmap_section_buffer (&data
->macinfo
);
10962 munmap_section_buffer (&data
->ranges
);
10963 munmap_section_buffer (&data
->loc
);
10964 munmap_section_buffer (&data
->frame
);
10965 munmap_section_buffer (&data
->eh_frame
);
10968 void _initialize_dwarf2_read (void);
10971 _initialize_dwarf2_read (void)
10973 dwarf2_objfile_data_key
10974 = register_objfile_data_with_cleanup (dwarf2_per_objfile_cleanup
);
10976 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
10977 Set DWARF 2 specific variables.\n\
10978 Configure DWARF 2 variables such as the cache size"),
10979 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
10980 0/*allow-unknown*/, &maintenance_set_cmdlist
);
10982 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
10983 Show DWARF 2 specific variables\n\
10984 Show DWARF 2 variables such as the cache size"),
10985 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
10986 0/*allow-unknown*/, &maintenance_show_cmdlist
);
10988 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
10989 &dwarf2_max_cache_age
, _("\
10990 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
10991 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
10992 A higher limit means that cached compilation units will be stored\n\
10993 in memory longer, and more total memory will be used. Zero disables\n\
10994 caching, which can slow down startup."),
10996 show_dwarf2_max_cache_age
,
10997 &set_dwarf2_cmdlist
,
10998 &show_dwarf2_cmdlist
);
11000 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
11001 Set debugging of the dwarf2 DIE reader."), _("\
11002 Show debugging of the dwarf2 DIE reader."), _("\
11003 When enabled (non-zero), DIEs are dumped after they are read in.\n\
11004 The value is the maximum depth to print."),
11007 &setdebuglist
, &showdebuglist
);