1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 Free Software Foundation, Inc.
6 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
7 Inc. with support from Florida State University (under contract
8 with the Ada Joint Program Office), and Silicon Graphics, Inc.
9 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
10 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
11 support in dwarfread.c
13 This file is part of GDB.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or (at
18 your option) any later version.
20 This program is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. */
36 #include "elf/dwarf2.h"
39 #include "expression.h"
40 #include "filenames.h" /* for DOSish file names */
43 #include "complaints.h"
45 #include "dwarf2expr.h"
46 #include "dwarf2loc.h"
47 #include "cp-support.h"
50 #include "gdb_string.h"
51 #include "gdb_assert.h"
52 #include <sys/types.h>
54 #ifndef DWARF2_REG_TO_REGNUM
55 #define DWARF2_REG_TO_REGNUM(REG) (REG)
59 /* .debug_info header for a compilation unit
60 Because of alignment constraints, this structure has padding and cannot
61 be mapped directly onto the beginning of the .debug_info section. */
62 typedef struct comp_unit_header
64 unsigned int length
; /* length of the .debug_info
66 unsigned short version
; /* version number -- 2 for DWARF
68 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
69 unsigned char addr_size
; /* byte size of an address -- 4 */
72 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
75 /* .debug_pubnames header
76 Because of alignment constraints, this structure has padding and cannot
77 be mapped directly onto the beginning of the .debug_info section. */
78 typedef struct pubnames_header
80 unsigned int length
; /* length of the .debug_pubnames
82 unsigned char version
; /* version number -- 2 for DWARF
84 unsigned int info_offset
; /* offset into .debug_info section */
85 unsigned int info_size
; /* byte size of .debug_info section
89 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
91 /* .debug_pubnames header
92 Because of alignment constraints, this structure has padding and cannot
93 be mapped directly onto the beginning of the .debug_info section. */
94 typedef struct aranges_header
96 unsigned int length
; /* byte len of the .debug_aranges
98 unsigned short version
; /* version number -- 2 for DWARF
100 unsigned int info_offset
; /* offset into .debug_info section */
101 unsigned char addr_size
; /* byte size of an address */
102 unsigned char seg_size
; /* byte size of segment descriptor */
105 #define _ACTUAL_ARANGES_HEADER_SIZE 12
107 /* .debug_line statement program prologue
108 Because of alignment constraints, this structure has padding and cannot
109 be mapped directly onto the beginning of the .debug_info section. */
110 typedef struct statement_prologue
112 unsigned int total_length
; /* byte length of the statement
114 unsigned short version
; /* version number -- 2 for DWARF
116 unsigned int prologue_length
; /* # bytes between prologue &
118 unsigned char minimum_instruction_length
; /* byte size of
120 unsigned char default_is_stmt
; /* initial value of is_stmt
123 unsigned char line_range
;
124 unsigned char opcode_base
; /* number assigned to first special
126 unsigned char *standard_opcode_lengths
;
130 /* offsets and sizes of debugging sections */
132 static unsigned int dwarf_info_size
;
133 static unsigned int dwarf_abbrev_size
;
134 static unsigned int dwarf_line_size
;
135 static unsigned int dwarf_pubnames_size
;
136 static unsigned int dwarf_aranges_size
;
137 static unsigned int dwarf_loc_size
;
138 static unsigned int dwarf_macinfo_size
;
139 static unsigned int dwarf_str_size
;
140 static unsigned int dwarf_ranges_size
;
141 unsigned int dwarf_frame_size
;
142 unsigned int dwarf_eh_frame_size
;
144 static asection
*dwarf_info_section
;
145 static asection
*dwarf_abbrev_section
;
146 static asection
*dwarf_line_section
;
147 static asection
*dwarf_pubnames_section
;
148 static asection
*dwarf_aranges_section
;
149 static asection
*dwarf_loc_section
;
150 static asection
*dwarf_macinfo_section
;
151 static asection
*dwarf_str_section
;
152 static asection
*dwarf_ranges_section
;
153 asection
*dwarf_frame_section
;
154 asection
*dwarf_eh_frame_section
;
156 /* names of the debugging sections */
158 #define INFO_SECTION ".debug_info"
159 #define ABBREV_SECTION ".debug_abbrev"
160 #define LINE_SECTION ".debug_line"
161 #define PUBNAMES_SECTION ".debug_pubnames"
162 #define ARANGES_SECTION ".debug_aranges"
163 #define LOC_SECTION ".debug_loc"
164 #define MACINFO_SECTION ".debug_macinfo"
165 #define STR_SECTION ".debug_str"
166 #define RANGES_SECTION ".debug_ranges"
167 #define FRAME_SECTION ".debug_frame"
168 #define EH_FRAME_SECTION ".eh_frame"
170 /* local data types */
172 /* We hold several abbreviation tables in memory at the same time. */
173 #ifndef ABBREV_HASH_SIZE
174 #define ABBREV_HASH_SIZE 121
177 /* The data in a compilation unit header, after target2host
178 translation, looks like this. */
179 struct comp_unit_head
181 unsigned long length
;
183 unsigned int abbrev_offset
;
184 unsigned char addr_size
;
185 unsigned char signed_addr_p
;
186 unsigned int offset_size
; /* size of file offsets; either 4 or 8 */
187 unsigned int initial_length_size
; /* size of the length field; either
190 /* Offset to the first byte of this compilation unit header in the
191 * .debug_info section, for resolving relative reference dies. */
195 /* Pointer to this compilation unit header in the .debug_info
200 /* Pointer to the first die of this compilatio unit. This will
201 * be the first byte following the compilation unit header. */
205 /* Pointer to the next compilation unit header in the program. */
207 struct comp_unit_head
*next
;
209 /* DWARF abbreviation table associated with this compilation unit */
211 struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
213 /* Base address of this compilation unit. */
215 CORE_ADDR base_address
;
217 /* Non-zero if base_address has been set. */
222 /* Internal state when decoding a particular compilation unit. */
225 /* The objfile containing this compilation unit. */
226 struct objfile
*objfile
;
228 /* The header of the compilation unit.
230 FIXME drow/2003-11-10: Some of the things from the comp_unit_head
231 should be moved to the dwarf2_cu structure; for instance the abbrevs
233 struct comp_unit_head header
;
236 /* The line number information for a compilation unit (found in the
237 .debug_line section) begins with a "statement program header",
238 which contains the following information. */
241 unsigned int total_length
;
242 unsigned short version
;
243 unsigned int header_length
;
244 unsigned char minimum_instruction_length
;
245 unsigned char default_is_stmt
;
247 unsigned char line_range
;
248 unsigned char opcode_base
;
250 /* standard_opcode_lengths[i] is the number of operands for the
251 standard opcode whose value is i. This means that
252 standard_opcode_lengths[0] is unused, and the last meaningful
253 element is standard_opcode_lengths[opcode_base - 1]. */
254 unsigned char *standard_opcode_lengths
;
256 /* The include_directories table. NOTE! These strings are not
257 allocated with xmalloc; instead, they are pointers into
258 debug_line_buffer. If you try to free them, `free' will get
260 unsigned int num_include_dirs
, include_dirs_size
;
263 /* The file_names table. NOTE! These strings are not allocated
264 with xmalloc; instead, they are pointers into debug_line_buffer.
265 Don't try to free them directly. */
266 unsigned int num_file_names
, file_names_size
;
270 unsigned int dir_index
;
271 unsigned int mod_time
;
275 /* The start and end of the statement program following this
276 header. These point into dwarf_line_buffer. */
277 char *statement_program_start
, *statement_program_end
;
280 /* When we construct a partial symbol table entry we only
281 need this much information. */
282 struct partial_die_info
285 unsigned char has_children
;
286 unsigned char is_external
;
287 unsigned char is_declaration
;
288 unsigned char has_type
;
295 struct dwarf_block
*locdesc
;
296 unsigned int language
;
300 /* This data structure holds the information of an abbrev. */
303 unsigned int number
; /* number identifying abbrev */
304 enum dwarf_tag tag
; /* dwarf tag */
305 int has_children
; /* boolean */
306 unsigned int num_attrs
; /* number of attributes */
307 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
308 struct abbrev_info
*next
; /* next in chain */
313 enum dwarf_attribute name
;
314 enum dwarf_form form
;
317 /* This data structure holds a complete die structure. */
320 enum dwarf_tag tag
; /* Tag indicating type of die */
321 unsigned int abbrev
; /* Abbrev number */
322 unsigned int offset
; /* Offset in .debug_info section */
323 unsigned int num_attrs
; /* Number of attributes */
324 struct attribute
*attrs
; /* An array of attributes */
325 struct die_info
*next_ref
; /* Next die in ref hash table */
327 /* The dies in a compilation unit form an n-ary tree. PARENT
328 points to this die's parent; CHILD points to the first child of
329 this node; and all the children of a given node are chained
330 together via their SIBLING fields, terminated by a die whose
332 struct die_info
*child
; /* Its first child, if any. */
333 struct die_info
*sibling
; /* Its next sibling, if any. */
334 struct die_info
*parent
; /* Its parent, if any. */
336 struct type
*type
; /* Cached type information */
339 /* Attributes have a name and a value */
342 enum dwarf_attribute name
;
343 enum dwarf_form form
;
347 struct dwarf_block
*blk
;
355 struct function_range
358 CORE_ADDR lowpc
, highpc
;
360 struct function_range
*next
;
363 static struct function_range
*cu_first_fn
, *cu_last_fn
, *cu_cached_fn
;
365 /* Get at parts of an attribute structure */
367 #define DW_STRING(attr) ((attr)->u.str)
368 #define DW_UNSND(attr) ((attr)->u.unsnd)
369 #define DW_BLOCK(attr) ((attr)->u.blk)
370 #define DW_SND(attr) ((attr)->u.snd)
371 #define DW_ADDR(attr) ((attr)->u.addr)
373 /* Blocks are a bunch of untyped bytes. */
380 #ifndef ATTR_ALLOC_CHUNK
381 #define ATTR_ALLOC_CHUNK 4
384 /* A hash table of die offsets for following references. */
385 #ifndef REF_HASH_SIZE
386 #define REF_HASH_SIZE 1021
389 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
391 /* Obstack for allocating temporary storage used during symbol reading. */
392 static struct obstack dwarf2_tmp_obstack
;
394 /* Offset to the first byte of the current compilation unit header,
395 for resolving relative reference dies. */
396 static unsigned int cu_header_offset
;
398 /* Allocate fields for structs, unions and enums in this size. */
399 #ifndef DW_FIELD_ALLOC_CHUNK
400 #define DW_FIELD_ALLOC_CHUNK 4
403 /* The language we are debugging. */
404 static enum language cu_language
;
405 static const struct language_defn
*cu_language_defn
;
407 /* Actually data from the sections. */
408 static char *dwarf_info_buffer
;
409 static char *dwarf_abbrev_buffer
;
410 static char *dwarf_line_buffer
;
411 static char *dwarf_str_buffer
;
412 static char *dwarf_macinfo_buffer
;
413 static char *dwarf_ranges_buffer
;
414 static char *dwarf_loc_buffer
;
416 /* A zeroed version of a partial die for initialization purposes. */
417 static struct partial_die_info zeroed_partial_die
;
419 /* The generic symbol table building routines have separate lists for
420 file scope symbols and all all other scopes (local scopes). So
421 we need to select the right one to pass to add_symbol_to_list().
422 We do it by keeping a pointer to the correct list in list_in_scope.
424 FIXME: The original dwarf code just treated the file scope as the first
425 local scope, and all other local scopes as nested local scopes, and worked
426 fine. Check to see if we really need to distinguish these
428 static struct pending
**list_in_scope
= &file_symbols
;
430 /* FIXME: decode_locdesc sets these variables to describe the location
431 to the caller. These ought to be a structure or something. If
432 none of the flags are set, the object lives at the address returned
433 by decode_locdesc. */
435 static int isreg
; /* Object lives in register.
436 decode_locdesc's return value is
437 the register number. */
439 /* This value is added to each symbol value. FIXME: Generalize to
440 the section_offsets structure used by dbxread (once this is done,
441 pass the appropriate section number to end_symtab). */
442 static CORE_ADDR baseaddr
; /* Add to each symbol value */
444 /* We put a pointer to this structure in the read_symtab_private field
446 The complete dwarf information for an objfile is kept in the
447 psymbol_obstack, so that absolute die references can be handled.
448 Most of the information in this structure is related to an entire
449 object file and could be passed via the sym_private field of the objfile.
450 It is however conceivable that dwarf2 might not be the only type
451 of symbols read from an object file. */
455 /* Pointer to start of dwarf info buffer for the objfile. */
457 char *dwarf_info_buffer
;
459 /* Offset in dwarf_info_buffer for this compilation unit. */
461 unsigned long dwarf_info_offset
;
463 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
465 char *dwarf_abbrev_buffer
;
467 /* Size of dwarf abbreviation section for the objfile. */
469 unsigned int dwarf_abbrev_size
;
471 /* Pointer to start of dwarf line buffer for the objfile. */
473 char *dwarf_line_buffer
;
475 /* Size of dwarf_line_buffer, in bytes. */
477 unsigned int dwarf_line_size
;
479 /* Pointer to start of dwarf string buffer for the objfile. */
481 char *dwarf_str_buffer
;
483 /* Size of dwarf string section for the objfile. */
485 unsigned int dwarf_str_size
;
487 /* Pointer to start of dwarf macro buffer for the objfile. */
489 char *dwarf_macinfo_buffer
;
491 /* Size of dwarf macinfo section for the objfile. */
493 unsigned int dwarf_macinfo_size
;
495 /* Pointer to start of dwarf ranges buffer for the objfile. */
497 char *dwarf_ranges_buffer
;
499 /* Size of dwarf ranges buffer for the objfile. */
501 unsigned int dwarf_ranges_size
;
503 /* Pointer to start of dwarf locations buffer for the objfile. */
505 char *dwarf_loc_buffer
;
507 /* Size of dwarf locations buffer for the objfile. */
509 unsigned int dwarf_loc_size
;
512 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
513 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
514 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
515 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
516 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
517 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
518 #define DWARF_LINE_SIZE(p) (PST_PRIVATE(p)->dwarf_line_size)
519 #define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer)
520 #define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size)
521 #define DWARF_MACINFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_macinfo_buffer)
522 #define DWARF_MACINFO_SIZE(p) (PST_PRIVATE(p)->dwarf_macinfo_size)
523 #define DWARF_RANGES_BUFFER(p) (PST_PRIVATE(p)->dwarf_ranges_buffer)
524 #define DWARF_RANGES_SIZE(p) (PST_PRIVATE(p)->dwarf_ranges_size)
525 #define DWARF_LOC_BUFFER(p) (PST_PRIVATE(p)->dwarf_loc_buffer)
526 #define DWARF_LOC_SIZE(p) (PST_PRIVATE(p)->dwarf_loc_size)
528 /* Maintain an array of referenced fundamental types for the current
529 compilation unit being read. For DWARF version 1, we have to construct
530 the fundamental types on the fly, since no information about the
531 fundamental types is supplied. Each such fundamental type is created by
532 calling a language dependent routine to create the type, and then a
533 pointer to that type is then placed in the array at the index specified
534 by it's FT_<TYPENAME> value. The array has a fixed size set by the
535 FT_NUM_MEMBERS compile time constant, which is the number of predefined
536 fundamental types gdb knows how to construct. */
537 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
539 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
540 but this would require a corresponding change in unpack_field_as_long
542 static int bits_per_byte
= 8;
544 /* The routines that read and process dies for a C struct or C++ class
545 pass lists of data member fields and lists of member function fields
546 in an instance of a field_info structure, as defined below. */
549 /* List of data member and baseclasses fields. */
552 struct nextfield
*next
;
559 /* Number of fields. */
562 /* Number of baseclasses. */
565 /* Set if the accesibility of one of the fields is not public. */
566 int non_public_fields
;
568 /* Member function fields array, entries are allocated in the order they
569 are encountered in the object file. */
572 struct nextfnfield
*next
;
573 struct fn_field fnfield
;
577 /* Member function fieldlist array, contains name of possibly overloaded
578 member function, number of overloaded member functions and a pointer
579 to the head of the member function field chain. */
584 struct nextfnfield
*head
;
588 /* Number of entries in the fnfieldlists array. */
592 /* Various complaints about symbol reading that don't abort the process */
595 dwarf2_non_const_array_bound_ignored_complaint (const char *arg1
)
597 complaint (&symfile_complaints
, "non-constant array bounds form '%s' ignored",
602 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
604 complaint (&symfile_complaints
,
605 "statement list doesn't fit in .debug_line section");
609 dwarf2_complex_location_expr_complaint (void)
611 complaint (&symfile_complaints
, "location expression too complex");
615 dwarf2_unsupported_at_frame_base_complaint (const char *arg1
)
617 complaint (&symfile_complaints
,
618 "unsupported DW_AT_frame_base for function '%s'", arg1
);
622 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
625 complaint (&symfile_complaints
,
626 "const value length mismatch for '%s', got %d, expected %d", arg1
,
631 dwarf2_macros_too_long_complaint (void)
633 complaint (&symfile_complaints
,
634 "macro info runs off end of `.debug_macinfo' section");
638 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
640 complaint (&symfile_complaints
,
641 "macro debug info contains a malformed macro definition:\n`%s'",
646 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
648 complaint (&symfile_complaints
,
649 "invalid attribute class or form for '%s' in '%s'", arg1
, arg2
);
652 /* local function prototypes */
654 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
657 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
660 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
662 static char *scan_partial_symbols (char *, CORE_ADDR
*, CORE_ADDR
*,
664 const char *namespace);
666 static void add_partial_symbol (struct partial_die_info
*, struct dwarf2_cu
*,
667 const char *namespace);
669 static char *add_partial_namespace (struct partial_die_info
*pdi
,
671 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
672 struct dwarf2_cu
*cu
,
673 const char *namespace);
675 static char *add_partial_enumeration (struct partial_die_info
*enum_pdi
,
677 struct dwarf2_cu
*cu
,
678 const char *namespace);
680 static char *locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
683 struct dwarf2_cu
*cu
);
685 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
687 static void psymtab_to_symtab_1 (struct partial_symtab
*);
689 char *dwarf2_read_section (struct objfile
*, asection
*);
691 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
693 static void dwarf2_empty_abbrev_table (void *);
695 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
698 static char *read_partial_die (struct partial_die_info
*,
699 bfd
*, char *, struct dwarf2_cu
*);
701 static char *read_full_die (struct die_info
**, bfd
*, char *,
702 struct dwarf2_cu
*, int *);
704 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
705 bfd
*, char *, struct dwarf2_cu
*);
707 static char *read_attribute_value (struct attribute
*, unsigned,
708 bfd
*, char *, struct dwarf2_cu
*);
710 static unsigned int read_1_byte (bfd
*, char *);
712 static int read_1_signed_byte (bfd
*, char *);
714 static unsigned int read_2_bytes (bfd
*, char *);
716 static unsigned int read_4_bytes (bfd
*, char *);
718 static unsigned long read_8_bytes (bfd
*, char *);
720 static CORE_ADDR
read_address (bfd
*, char *ptr
, struct dwarf2_cu
*,
723 static LONGEST
read_initial_length (bfd
*, char *,
724 struct comp_unit_head
*, int *bytes_read
);
726 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
729 static char *read_n_bytes (bfd
*, char *, unsigned int);
731 static char *read_string (bfd
*, char *, unsigned int *);
733 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
736 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
738 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
740 static void set_cu_language (unsigned int);
742 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
744 static int die_is_declaration (struct die_info
*);
746 static void free_line_header (struct line_header
*lh
);
748 static struct line_header
*(dwarf_decode_line_header
749 (unsigned int offset
,
750 bfd
*abfd
, struct dwarf2_cu
*cu
));
752 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
755 static void dwarf2_start_subfile (char *, char *);
757 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
760 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
763 static void dwarf2_const_value_data (struct attribute
*attr
,
767 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
769 static struct type
*die_containing_type (struct die_info
*,
773 static struct type
*type_at_offset (unsigned int, struct objfile
*);
776 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
778 static void read_type_die (struct die_info
*, struct dwarf2_cu
*);
780 static void read_typedef (struct die_info
*, struct dwarf2_cu
*);
782 static void read_base_type (struct die_info
*, struct dwarf2_cu
*);
784 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
786 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
788 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
790 static int dwarf2_get_pc_bounds (struct die_info
*,
791 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
793 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
796 static void dwarf2_attach_fields_to_type (struct field_info
*,
797 struct type
*, struct dwarf2_cu
*);
799 static void dwarf2_add_member_fn (struct field_info
*,
800 struct die_info
*, struct type
*,
803 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
804 struct type
*, struct dwarf2_cu
*);
806 static void read_structure_scope (struct die_info
*, struct dwarf2_cu
*);
808 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
810 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
812 static const char *namespace_name (struct die_info
*die
,
815 static void read_enumeration (struct die_info
*, struct dwarf2_cu
*);
817 static struct type
*dwarf_base_type (int, int, struct dwarf2_cu
*);
819 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
821 static void read_array_type (struct die_info
*, struct dwarf2_cu
*);
823 static void read_tag_pointer_type (struct die_info
*, struct dwarf2_cu
*);
825 static void read_tag_ptr_to_member_type (struct die_info
*,
828 static void read_tag_reference_type (struct die_info
*, struct dwarf2_cu
*);
830 static void read_tag_const_type (struct die_info
*, struct dwarf2_cu
*);
832 static void read_tag_volatile_type (struct die_info
*, struct dwarf2_cu
*);
834 static void read_tag_string_type (struct die_info
*, struct dwarf2_cu
*);
836 static void read_subroutine_type (struct die_info
*, struct dwarf2_cu
*);
838 static struct die_info
*read_comp_unit (char *, bfd
*, struct dwarf2_cu
*);
840 static struct die_info
*read_die_and_children (char *info_ptr
, bfd
*abfd
,
843 struct die_info
*parent
);
845 static struct die_info
*read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
848 struct die_info
*parent
);
850 static void free_die_list (struct die_info
*);
852 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
854 static void process_die (struct die_info
*, struct dwarf2_cu
*);
856 static char *dwarf2_linkage_name (struct die_info
*);
858 static char *dwarf2_name (struct die_info
*die
);
860 static struct die_info
*dwarf2_extension (struct die_info
*die
);
862 static char *dwarf_tag_name (unsigned int);
864 static char *dwarf_attr_name (unsigned int);
866 static char *dwarf_form_name (unsigned int);
868 static char *dwarf_stack_op_name (unsigned int);
870 static char *dwarf_bool_name (unsigned int);
872 static char *dwarf_type_encoding_name (unsigned int);
875 static char *dwarf_cfi_name (unsigned int);
877 struct die_info
*copy_die (struct die_info
*);
880 static struct die_info
*sibling_die (struct die_info
*);
882 static void dump_die (struct die_info
*);
884 static void dump_die_list (struct die_info
*);
886 static void store_in_ref_table (unsigned int, struct die_info
*);
888 static void dwarf2_empty_hash_tables (void);
890 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
892 static struct die_info
*follow_die_ref (unsigned int);
894 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
896 /* memory allocation interface */
898 static void dwarf2_free_tmp_obstack (void *);
900 static struct dwarf_block
*dwarf_alloc_block (void);
902 static struct abbrev_info
*dwarf_alloc_abbrev (void);
904 static struct die_info
*dwarf_alloc_die (void);
906 static void initialize_cu_func_list (void);
908 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
);
910 static void dwarf_decode_macros (struct line_header
*, unsigned int,
911 char *, bfd
*, struct dwarf2_cu
*);
913 static int attr_form_is_block (struct attribute
*);
916 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
917 struct dwarf2_cu
*cu
);
919 /* Try to locate the sections we need for DWARF 2 debugging
920 information and return true if we have enough to do something. */
923 dwarf2_has_info (bfd
*abfd
)
925 dwarf_info_section
= 0;
926 dwarf_abbrev_section
= 0;
927 dwarf_line_section
= 0;
928 dwarf_str_section
= 0;
929 dwarf_macinfo_section
= 0;
930 dwarf_frame_section
= 0;
931 dwarf_eh_frame_section
= 0;
932 dwarf_ranges_section
= 0;
933 dwarf_loc_section
= 0;
935 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
936 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
939 /* This function is mapped across the sections and remembers the
940 offset and size of each of the debugging sections we are interested
944 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, void *ignore_ptr
)
946 if (strcmp (sectp
->name
, INFO_SECTION
) == 0)
948 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
949 dwarf_info_section
= sectp
;
951 else if (strcmp (sectp
->name
, ABBREV_SECTION
) == 0)
953 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
954 dwarf_abbrev_section
= sectp
;
956 else if (strcmp (sectp
->name
, LINE_SECTION
) == 0)
958 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
959 dwarf_line_section
= sectp
;
961 else if (strcmp (sectp
->name
, PUBNAMES_SECTION
) == 0)
963 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
964 dwarf_pubnames_section
= sectp
;
966 else if (strcmp (sectp
->name
, ARANGES_SECTION
) == 0)
968 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
969 dwarf_aranges_section
= sectp
;
971 else if (strcmp (sectp
->name
, LOC_SECTION
) == 0)
973 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
974 dwarf_loc_section
= sectp
;
976 else if (strcmp (sectp
->name
, MACINFO_SECTION
) == 0)
978 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
979 dwarf_macinfo_section
= sectp
;
981 else if (strcmp (sectp
->name
, STR_SECTION
) == 0)
983 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
984 dwarf_str_section
= sectp
;
986 else if (strcmp (sectp
->name
, FRAME_SECTION
) == 0)
988 dwarf_frame_size
= bfd_get_section_size_before_reloc (sectp
);
989 dwarf_frame_section
= sectp
;
991 else if (strcmp (sectp
->name
, EH_FRAME_SECTION
) == 0)
993 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
994 if (aflag
& SEC_HAS_CONTENTS
)
996 dwarf_eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
997 dwarf_eh_frame_section
= sectp
;
1000 else if (strcmp (sectp
->name
, RANGES_SECTION
) == 0)
1002 dwarf_ranges_size
= bfd_get_section_size_before_reloc (sectp
);
1003 dwarf_ranges_section
= sectp
;
1007 /* Build a partial symbol table. */
1010 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1013 /* We definitely need the .debug_info and .debug_abbrev sections */
1015 dwarf_info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1016 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1018 if (dwarf_line_section
)
1019 dwarf_line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1021 dwarf_line_buffer
= NULL
;
1023 if (dwarf_str_section
)
1024 dwarf_str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1026 dwarf_str_buffer
= NULL
;
1028 if (dwarf_macinfo_section
)
1029 dwarf_macinfo_buffer
= dwarf2_read_section (objfile
,
1030 dwarf_macinfo_section
);
1032 dwarf_macinfo_buffer
= NULL
;
1034 if (dwarf_ranges_section
)
1035 dwarf_ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1037 dwarf_ranges_buffer
= NULL
;
1039 if (dwarf_loc_section
)
1040 dwarf_loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1042 dwarf_loc_buffer
= NULL
;
1045 || (objfile
->global_psymbols
.size
== 0
1046 && objfile
->static_psymbols
.size
== 0))
1048 init_psymbol_list (objfile
, 1024);
1052 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1054 /* Things are significantly easier if we have .debug_aranges and
1055 .debug_pubnames sections */
1057 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1061 /* only test this case for now */
1063 /* In this case we have to work a bit harder */
1064 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1069 /* Build the partial symbol table from the information in the
1070 .debug_pubnames and .debug_aranges sections. */
1073 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1075 bfd
*abfd
= objfile
->obfd
;
1076 char *aranges_buffer
, *pubnames_buffer
;
1077 char *aranges_ptr
, *pubnames_ptr
;
1078 unsigned int entry_length
, version
, info_offset
, info_size
;
1080 pubnames_buffer
= dwarf2_read_section (objfile
,
1081 dwarf_pubnames_section
);
1082 pubnames_ptr
= pubnames_buffer
;
1083 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
1085 struct comp_unit_head cu_header
;
1088 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1090 pubnames_ptr
+= bytes_read
;
1091 version
= read_1_byte (abfd
, pubnames_ptr
);
1093 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1095 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1099 aranges_buffer
= dwarf2_read_section (objfile
,
1100 dwarf_aranges_section
);
1105 /* Read in the comp unit header information from the debug_info at
1109 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1110 char *info_ptr
, bfd
*abfd
)
1114 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1116 info_ptr
+= bytes_read
;
1117 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1119 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1121 info_ptr
+= bytes_read
;
1122 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1124 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1125 if (signed_addr
< 0)
1126 internal_error (__FILE__
, __LINE__
,
1127 "read_comp_unit_head: dwarf from non elf file");
1128 cu_header
->signed_addr_p
= signed_addr
;
1132 /* Build the partial symbol table by doing a quick pass through the
1133 .debug_info and .debug_abbrev sections. */
1136 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1138 /* Instead of reading this into a big buffer, we should probably use
1139 mmap() on architectures that support it. (FIXME) */
1140 bfd
*abfd
= objfile
->obfd
;
1141 char *info_ptr
, *abbrev_ptr
;
1142 char *beg_of_comp_unit
;
1143 struct partial_die_info comp_unit_die
;
1144 struct partial_symtab
*pst
;
1145 struct cleanup
*back_to
;
1146 CORE_ADDR lowpc
, highpc
;
1148 info_ptr
= dwarf_info_buffer
;
1149 abbrev_ptr
= dwarf_abbrev_buffer
;
1151 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1152 the partial symbol scan, like attribute values.
1154 We could reduce our peak memory consumption during partial symbol
1155 table construction by freeing stuff from this obstack more often
1156 --- say, after processing each compilation unit, or each die ---
1157 but it turns out that this saves almost nothing. For an
1158 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1159 on dwarf2_tmp_obstack. Some investigation showed:
1161 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1162 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1163 all fixed-length values not requiring dynamic allocation.
1165 2) 30% of the attributes used the form DW_FORM_string. For
1166 DW_FORM_string, read_attribute simply hands back a pointer to
1167 the null-terminated string in dwarf_info_buffer, so no dynamic
1168 allocation is needed there either.
1170 3) The remaining 1% of the attributes all used DW_FORM_block1.
1171 75% of those were DW_AT_frame_base location lists for
1172 functions; the rest were DW_AT_location attributes, probably
1173 for the global variables.
1175 Anyway, what this all means is that the memory the dwarf2
1176 reader uses as temporary space reading partial symbols is about
1177 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1179 obstack_init (&dwarf2_tmp_obstack
);
1180 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1182 /* Since the objects we're extracting from dwarf_info_buffer vary in
1183 length, only the individual functions to extract them (like
1184 read_comp_unit_head and read_partial_die) can really know whether
1185 the buffer is large enough to hold another complete object.
1187 At the moment, they don't actually check that. If
1188 dwarf_info_buffer holds just one extra byte after the last
1189 compilation unit's dies, then read_comp_unit_head will happily
1190 read off the end of the buffer. read_partial_die is similarly
1191 casual. Those functions should be fixed.
1193 For this loop condition, simply checking whether there's any data
1194 left at all should be sufficient. */
1195 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1197 struct dwarf2_cu cu
;
1198 beg_of_comp_unit
= info_ptr
;
1200 cu
.objfile
= objfile
;
1201 info_ptr
= read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1203 if (cu
.header
.version
!= 2)
1205 error ("Dwarf Error: wrong version in compilation unit header (is %d, should be %d) [in module %s]", cu
.header
.version
, 2, bfd_get_filename (abfd
));
1208 if (cu
.header
.abbrev_offset
>= dwarf_abbrev_size
)
1210 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6) [in module %s]",
1211 (long) cu
.header
.abbrev_offset
,
1212 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1213 bfd_get_filename (abfd
));
1216 if (beg_of_comp_unit
+ cu
.header
.length
+ cu
.header
.initial_length_size
1217 > dwarf_info_buffer
+ dwarf_info_size
)
1219 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0) [in module %s]",
1220 (long) cu
.header
.length
,
1221 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1222 bfd_get_filename (abfd
));
1225 /* Complete the cu_header */
1226 cu
.header
.offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1227 cu
.header
.first_die_ptr
= info_ptr
;
1228 cu
.header
.cu_head_ptr
= beg_of_comp_unit
;
1230 /* Read the abbrevs for this compilation unit into a table */
1231 dwarf2_read_abbrevs (abfd
, &cu
);
1232 make_cleanup (dwarf2_empty_abbrev_table
, cu
.header
.dwarf2_abbrevs
);
1234 /* Read the compilation unit die */
1235 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1238 /* Set the language we're debugging */
1239 set_cu_language (comp_unit_die
.language
);
1241 /* Allocate a new partial symbol table structure */
1242 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1243 comp_unit_die
.name
? comp_unit_die
.name
: "",
1244 comp_unit_die
.lowpc
,
1245 objfile
->global_psymbols
.next
,
1246 objfile
->static_psymbols
.next
);
1248 pst
->read_symtab_private
= (char *)
1249 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1250 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1251 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1252 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1253 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1254 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1255 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1256 DWARF_LINE_SIZE (pst
) = dwarf_line_size
;
1257 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1258 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1259 DWARF_MACINFO_BUFFER (pst
) = dwarf_macinfo_buffer
;
1260 DWARF_MACINFO_SIZE (pst
) = dwarf_macinfo_size
;
1261 DWARF_RANGES_BUFFER (pst
) = dwarf_ranges_buffer
;
1262 DWARF_RANGES_SIZE (pst
) = dwarf_ranges_size
;
1263 DWARF_LOC_BUFFER (pst
) = dwarf_loc_buffer
;
1264 DWARF_LOC_SIZE (pst
) = dwarf_loc_size
;
1265 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1267 /* Store the function that reads in the rest of the symbol table */
1268 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1270 /* Check if comp unit has_children.
1271 If so, read the rest of the partial symbols from this comp unit.
1272 If not, there's no more debug_info for this comp unit. */
1273 if (comp_unit_die
.has_children
)
1275 lowpc
= ((CORE_ADDR
) -1);
1276 highpc
= ((CORE_ADDR
) 0);
1278 info_ptr
= scan_partial_symbols (info_ptr
, &lowpc
, &highpc
,
1281 /* If we didn't find a lowpc, set it to highpc to avoid
1282 complaints from `maint check'. */
1283 if (lowpc
== ((CORE_ADDR
) -1))
1286 /* If the compilation unit didn't have an explicit address range,
1287 then use the information extracted from its child dies. */
1288 if (! comp_unit_die
.has_pc_info
)
1290 comp_unit_die
.lowpc
= lowpc
;
1291 comp_unit_die
.highpc
= highpc
;
1294 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1295 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1297 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1298 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1299 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1300 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1301 sort_pst_symbols (pst
);
1303 /* If there is already a psymtab or symtab for a file of this
1304 name, remove it. (If there is a symtab, more drastic things
1305 also happen.) This happens in VxWorks. */
1306 free_named_symtabs (pst
->filename
);
1308 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1309 + cu
.header
.initial_length_size
;
1311 do_cleanups (back_to
);
1314 /* Read in all interesting dies to the end of the compilation unit or
1315 to the end of the current namespace. NAMESPACE is NULL if we
1316 haven't yet encountered any DW_TAG_namespace entries; otherwise,
1317 it's the name of the current namespace. In particular, it's the
1318 empty string if we're currently in the global namespace but have
1319 previously encountered a DW_TAG_namespace. */
1322 scan_partial_symbols (char *info_ptr
, CORE_ADDR
*lowpc
,
1323 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
1324 const char *namespace)
1326 struct objfile
*objfile
= cu
->objfile
;
1327 bfd
*abfd
= objfile
->obfd
;
1328 struct partial_die_info pdi
;
1330 /* Now, march along the PDI's, descending into ones which have
1331 interesting children but skipping the children of the other ones,
1332 until we reach the end of the compilation unit. */
1336 /* This flag tells whether or not info_ptr has gotten updated
1338 int info_ptr_updated
= 0;
1340 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu
);
1342 /* Anonymous namespaces have no name but have interesting
1343 children, so we need to look at them. Ditto for anonymous
1346 if (pdi
.name
!= NULL
|| pdi
.tag
== DW_TAG_namespace
1347 || pdi
.tag
== DW_TAG_enumeration_type
)
1351 case DW_TAG_subprogram
:
1352 if (pdi
.has_pc_info
)
1354 if (pdi
.lowpc
< *lowpc
)
1358 if (pdi
.highpc
> *highpc
)
1360 *highpc
= pdi
.highpc
;
1362 if (!pdi
.is_declaration
)
1364 add_partial_symbol (&pdi
, cu
, namespace);
1368 case DW_TAG_variable
:
1369 case DW_TAG_typedef
:
1370 case DW_TAG_union_type
:
1371 case DW_TAG_class_type
:
1372 case DW_TAG_structure_type
:
1373 if (!pdi
.is_declaration
)
1375 add_partial_symbol (&pdi
, cu
, namespace);
1378 case DW_TAG_enumeration_type
:
1379 if (!pdi
.is_declaration
)
1381 info_ptr
= add_partial_enumeration (&pdi
, info_ptr
, cu
,
1383 info_ptr_updated
= 1;
1386 case DW_TAG_base_type
:
1387 /* File scope base type definitions are added to the partial
1389 add_partial_symbol (&pdi
, cu
, namespace);
1391 case DW_TAG_namespace
:
1392 /* We've hit a DW_TAG_namespace entry, so we know this
1393 file has been compiled using a compiler that
1394 generates them; update NAMESPACE to reflect that. */
1395 if (namespace == NULL
)
1397 info_ptr
= add_partial_namespace (&pdi
, info_ptr
, lowpc
, highpc
,
1399 info_ptr_updated
= 1;
1409 /* If the die has a sibling, skip to the sibling, unless another
1410 function has already updated info_ptr for us. */
1412 /* NOTE: carlton/2003-06-16: This is a bit hackish, but whether
1413 or not we want to update this depends on enough stuff (not
1414 only pdi.tag but also whether or not pdi.name is NULL) that
1415 this seems like the easiest way to handle the issue. */
1417 if (!info_ptr_updated
)
1418 info_ptr
= locate_pdi_sibling (&pdi
, info_ptr
, abfd
, cu
);
1425 add_partial_symbol (struct partial_die_info
*pdi
,
1426 struct dwarf2_cu
*cu
, const char *namespace)
1428 struct objfile
*objfile
= cu
->objfile
;
1430 char *actual_name
= pdi
->name
;
1431 const struct partial_symbol
*psym
= NULL
;
1435 case DW_TAG_subprogram
:
1436 if (pdi
->is_external
)
1438 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1439 mst_text, objfile); */
1440 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1441 VAR_DOMAIN
, LOC_BLOCK
,
1442 &objfile
->global_psymbols
,
1443 0, pdi
->lowpc
+ baseaddr
,
1444 cu_language
, objfile
);
1448 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1449 mst_file_text, objfile); */
1450 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1451 VAR_DOMAIN
, LOC_BLOCK
,
1452 &objfile
->static_psymbols
,
1453 0, pdi
->lowpc
+ baseaddr
,
1454 cu_language
, objfile
);
1457 case DW_TAG_variable
:
1458 if (pdi
->is_external
)
1461 Don't enter into the minimal symbol tables as there is
1462 a minimal symbol table entry from the ELF symbols already.
1463 Enter into partial symbol table if it has a location
1464 descriptor or a type.
1465 If the location descriptor is missing, new_symbol will create
1466 a LOC_UNRESOLVED symbol, the address of the variable will then
1467 be determined from the minimal symbol table whenever the variable
1469 The address for the partial symbol table entry is not
1470 used by GDB, but it comes in handy for debugging partial symbol
1474 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1475 if (pdi
->locdesc
|| pdi
->has_type
)
1476 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1477 VAR_DOMAIN
, LOC_STATIC
,
1478 &objfile
->global_psymbols
,
1480 cu_language
, objfile
);
1484 /* Static Variable. Skip symbols without location descriptors. */
1485 if (pdi
->locdesc
== NULL
)
1487 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1488 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
1489 mst_file_data, objfile); */
1490 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1491 VAR_DOMAIN
, LOC_STATIC
,
1492 &objfile
->static_psymbols
,
1494 cu_language
, objfile
);
1497 case DW_TAG_typedef
:
1498 case DW_TAG_base_type
:
1499 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1500 VAR_DOMAIN
, LOC_TYPEDEF
,
1501 &objfile
->static_psymbols
,
1502 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1504 case DW_TAG_class_type
:
1505 case DW_TAG_structure_type
:
1506 case DW_TAG_union_type
:
1507 case DW_TAG_enumeration_type
:
1508 /* Skip aggregate types without children, these are external
1510 if (pdi
->has_children
== 0)
1512 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1513 STRUCT_DOMAIN
, LOC_TYPEDEF
,
1514 &objfile
->static_psymbols
,
1515 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1517 if (cu_language
== language_cplus
)
1519 /* For C++, these implicitly act as typedefs as well. */
1520 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1521 VAR_DOMAIN
, LOC_TYPEDEF
,
1522 &objfile
->static_psymbols
,
1523 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1526 case DW_TAG_enumerator
:
1527 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1528 VAR_DOMAIN
, LOC_CONST
,
1529 &objfile
->static_psymbols
,
1530 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1536 /* Check to see if we should scan the name for possible namespace
1537 info. Only do this if this is C++, if we don't have namespace
1538 debugging info in the file, if the psym is of an appropriate type
1539 (otherwise we'll have psym == NULL), and if we actually had a
1540 mangled name to begin with. */
1542 if (cu_language
== language_cplus
1543 && namespace == NULL
1545 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
1546 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
1550 /* Read a partial die corresponding to a namespace; also, add a symbol
1551 corresponding to that namespace to the symbol table. NAMESPACE is
1552 the name of the enclosing namespace. */
1555 add_partial_namespace (struct partial_die_info
*pdi
, char *info_ptr
,
1556 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1557 struct dwarf2_cu
*cu
, const char *namespace)
1559 struct objfile
*objfile
= cu
->objfile
;
1560 const char *new_name
= pdi
->name
;
1563 /* Calculate the full name of the namespace that we just entered. */
1565 if (new_name
== NULL
)
1566 new_name
= "(anonymous namespace)";
1567 full_name
= alloca (strlen (namespace) + 2 + strlen (new_name
) + 1);
1568 strcpy (full_name
, namespace);
1569 if (*namespace != '\0')
1570 strcat (full_name
, "::");
1571 strcat (full_name
, new_name
);
1573 /* FIXME: carlton/2003-06-27: Once we build qualified names for more
1574 symbols than just namespaces, we should replace this by a call to
1575 add_partial_symbol. */
1577 add_psymbol_to_list (full_name
, strlen (full_name
),
1578 VAR_DOMAIN
, LOC_TYPEDEF
,
1579 &objfile
->global_psymbols
,
1580 0, 0, cu_language
, objfile
);
1582 /* Now scan partial symbols in that namespace. */
1584 if (pdi
->has_children
)
1585 info_ptr
= scan_partial_symbols (info_ptr
, lowpc
, highpc
, cu
, full_name
);
1590 /* Read a partial die corresponding to an enumeration type. */
1593 add_partial_enumeration (struct partial_die_info
*enum_pdi
, char *info_ptr
,
1594 struct dwarf2_cu
*cu
, const char *namespace)
1596 struct objfile
*objfile
= cu
->objfile
;
1597 bfd
*abfd
= objfile
->obfd
;
1598 struct partial_die_info pdi
;
1600 if (enum_pdi
->name
!= NULL
)
1601 add_partial_symbol (enum_pdi
, cu
, namespace);
1605 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu
);
1608 if (pdi
.tag
!= DW_TAG_enumerator
|| pdi
.name
== NULL
)
1609 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
1611 add_partial_symbol (&pdi
, cu
, namespace);
1617 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the next DIE
1621 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, char *info_ptr
,
1622 bfd
*abfd
, struct dwarf2_cu
*cu
)
1624 /* Do we know the sibling already? */
1626 if (orig_pdi
->sibling
)
1627 return orig_pdi
->sibling
;
1629 /* Are there any children to deal with? */
1631 if (!orig_pdi
->has_children
)
1634 /* Okay, we don't know the sibling, but we have children that we
1635 want to skip. So read children until we run into one without a
1636 tag; return whatever follows it. */
1640 struct partial_die_info pdi
;
1642 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu
);
1647 info_ptr
= locate_pdi_sibling (&pdi
, info_ptr
, abfd
, cu
);
1651 /* Expand this partial symbol table into a full symbol table. */
1654 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1656 /* FIXME: This is barely more than a stub. */
1661 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1667 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1668 gdb_flush (gdb_stdout
);
1671 psymtab_to_symtab_1 (pst
);
1673 /* Finish up the debug error message. */
1675 printf_filtered ("done.\n");
1681 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1683 struct objfile
*objfile
= pst
->objfile
;
1684 bfd
*abfd
= objfile
->obfd
;
1685 struct dwarf2_cu cu
;
1686 struct die_info
*dies
;
1687 unsigned long offset
;
1688 CORE_ADDR lowpc
, highpc
;
1689 struct die_info
*child_die
;
1691 struct symtab
*symtab
;
1692 struct cleanup
*back_to
;
1693 struct attribute
*attr
;
1695 /* Set local variables from the partial symbol table info. */
1696 offset
= DWARF_INFO_OFFSET (pst
);
1697 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1698 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1699 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1700 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1701 dwarf_line_size
= DWARF_LINE_SIZE (pst
);
1702 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1703 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1704 dwarf_macinfo_buffer
= DWARF_MACINFO_BUFFER (pst
);
1705 dwarf_macinfo_size
= DWARF_MACINFO_SIZE (pst
);
1706 dwarf_ranges_buffer
= DWARF_RANGES_BUFFER (pst
);
1707 dwarf_ranges_size
= DWARF_RANGES_SIZE (pst
);
1708 dwarf_loc_buffer
= DWARF_LOC_BUFFER (pst
);
1709 dwarf_loc_size
= DWARF_LOC_SIZE (pst
);
1710 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1711 cu_header_offset
= offset
;
1712 info_ptr
= dwarf_info_buffer
+ offset
;
1714 obstack_init (&dwarf2_tmp_obstack
);
1715 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1718 make_cleanup (really_free_pendings
, NULL
);
1720 cu
.objfile
= objfile
;
1722 /* read in the comp_unit header */
1723 info_ptr
= read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1725 /* Read the abbrevs for this compilation unit */
1726 dwarf2_read_abbrevs (abfd
, &cu
);
1727 make_cleanup (dwarf2_empty_abbrev_table
, cu
.header
.dwarf2_abbrevs
);
1729 dies
= read_comp_unit (info_ptr
, abfd
, &cu
);
1731 make_cleanup_free_die_list (dies
);
1733 /* Find the base address of the compilation unit for range lists and
1734 location lists. It will normally be specified by DW_AT_low_pc.
1735 In DWARF-3 draft 4, the base address could be overridden by
1736 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1737 compilation units with discontinuous ranges. */
1739 cu
.header
.base_known
= 0;
1740 cu
.header
.base_address
= 0;
1742 attr
= dwarf_attr (dies
, DW_AT_entry_pc
);
1745 cu
.header
.base_address
= DW_ADDR (attr
);
1746 cu
.header
.base_known
= 1;
1750 attr
= dwarf_attr (dies
, DW_AT_low_pc
);
1753 cu
.header
.base_address
= DW_ADDR (attr
);
1754 cu
.header
.base_known
= 1;
1758 /* Do line number decoding in read_file_scope () */
1759 process_die (dies
, &cu
);
1761 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, &cu
))
1763 /* Some compilers don't define a DW_AT_high_pc attribute for
1764 the compilation unit. If the DW_AT_high_pc is missing,
1765 synthesize it, by scanning the DIE's below the compilation unit. */
1767 if (dies
->child
!= NULL
)
1769 child_die
= dies
->child
;
1770 while (child_die
&& child_die
->tag
)
1772 if (child_die
->tag
== DW_TAG_subprogram
)
1774 CORE_ADDR low
, high
;
1776 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, &cu
))
1778 highpc
= max (highpc
, high
);
1781 child_die
= sibling_die (child_die
);
1785 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1787 /* Set symtab language to language from DW_AT_language.
1788 If the compilation is from a C file generated by language preprocessors,
1789 do not set the language if it was already deduced by start_subfile. */
1791 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1793 symtab
->language
= cu_language
;
1795 pst
->symtab
= symtab
;
1798 do_cleanups (back_to
);
1801 /* Process a die and its children. */
1804 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
1808 case DW_TAG_padding
:
1810 case DW_TAG_compile_unit
:
1811 read_file_scope (die
, cu
);
1813 case DW_TAG_subprogram
:
1814 read_subroutine_type (die
, cu
);
1815 read_func_scope (die
, cu
);
1817 case DW_TAG_inlined_subroutine
:
1818 /* FIXME: These are ignored for now.
1819 They could be used to set breakpoints on all inlined instances
1820 of a function and make GDB `next' properly over inlined functions. */
1822 case DW_TAG_lexical_block
:
1823 case DW_TAG_try_block
:
1824 case DW_TAG_catch_block
:
1825 read_lexical_block_scope (die
, cu
);
1827 case DW_TAG_class_type
:
1828 case DW_TAG_structure_type
:
1829 case DW_TAG_union_type
:
1830 read_structure_scope (die
, cu
);
1832 case DW_TAG_enumeration_type
:
1833 read_enumeration (die
, cu
);
1835 case DW_TAG_subroutine_type
:
1836 read_subroutine_type (die
, cu
);
1838 case DW_TAG_array_type
:
1839 read_array_type (die
, cu
);
1841 case DW_TAG_pointer_type
:
1842 read_tag_pointer_type (die
, cu
);
1844 case DW_TAG_ptr_to_member_type
:
1845 read_tag_ptr_to_member_type (die
, cu
);
1847 case DW_TAG_reference_type
:
1848 read_tag_reference_type (die
, cu
);
1850 case DW_TAG_string_type
:
1851 read_tag_string_type (die
, cu
);
1853 case DW_TAG_base_type
:
1854 read_base_type (die
, cu
);
1855 if (dwarf_attr (die
, DW_AT_name
))
1857 /* Add a typedef symbol for the base type definition. */
1858 new_symbol (die
, die
->type
, cu
);
1861 case DW_TAG_common_block
:
1862 read_common_block (die
, cu
);
1864 case DW_TAG_common_inclusion
:
1866 case DW_TAG_namespace
:
1867 if (!processing_has_namespace_info
)
1869 processing_has_namespace_info
= 1;
1870 processing_current_prefix
= "";
1872 read_namespace (die
, cu
);
1874 case DW_TAG_imported_declaration
:
1875 case DW_TAG_imported_module
:
1876 /* FIXME: carlton/2002-10-16: Eventually, we should use the
1877 information contained in these. DW_TAG_imported_declaration
1878 dies shouldn't have children; DW_TAG_imported_module dies
1879 shouldn't in the C++ case, but conceivably could in the
1880 Fortran case, so we'll have to replace this gdb_assert if
1881 Fortran compilers start generating that info. */
1882 if (!processing_has_namespace_info
)
1884 processing_has_namespace_info
= 1;
1885 processing_current_prefix
= "";
1887 gdb_assert (die
->child
== NULL
);
1890 new_symbol (die
, NULL
, cu
);
1896 initialize_cu_func_list (void)
1898 cu_first_fn
= cu_last_fn
= cu_cached_fn
= NULL
;
1902 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
1904 struct objfile
*objfile
= cu
->objfile
;
1905 struct comp_unit_head
*cu_header
= &cu
->header
;
1906 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
1907 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1908 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1909 struct attribute
*attr
;
1910 char *name
= "<unknown>";
1911 char *comp_dir
= NULL
;
1912 struct die_info
*child_die
;
1913 bfd
*abfd
= objfile
->obfd
;
1914 struct line_header
*line_header
= 0;
1916 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
1918 if (die
->child
!= NULL
)
1920 child_die
= die
->child
;
1921 while (child_die
&& child_die
->tag
)
1923 if (child_die
->tag
== DW_TAG_subprogram
)
1925 CORE_ADDR low
, high
;
1927 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, cu
))
1929 lowpc
= min (lowpc
, low
);
1930 highpc
= max (highpc
, high
);
1933 child_die
= sibling_die (child_die
);
1938 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1939 from finish_block. */
1940 if (lowpc
== ((CORE_ADDR
) -1))
1945 attr
= dwarf_attr (die
, DW_AT_name
);
1948 name
= DW_STRING (attr
);
1950 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1953 comp_dir
= DW_STRING (attr
);
1956 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1957 directory, get rid of it. */
1958 char *cp
= strchr (comp_dir
, ':');
1960 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1965 if (objfile
->ei
.entry_point
>= lowpc
&&
1966 objfile
->ei
.entry_point
< highpc
)
1968 objfile
->ei
.deprecated_entry_file_lowpc
= lowpc
;
1969 objfile
->ei
.deprecated_entry_file_highpc
= highpc
;
1972 attr
= dwarf_attr (die
, DW_AT_language
);
1975 set_cu_language (DW_UNSND (attr
));
1978 /* We assume that we're processing GCC output. */
1979 processing_gcc_compilation
= 2;
1981 /* FIXME:Do something here. */
1982 if (dip
->at_producer
!= NULL
)
1984 handle_producer (dip
->at_producer
);
1988 /* The compilation unit may be in a different language or objfile,
1989 zero out all remembered fundamental types. */
1990 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1992 start_symtab (name
, comp_dir
, lowpc
);
1993 record_debugformat ("DWARF 2");
1995 initialize_cu_func_list ();
1997 /* Process all dies in compilation unit. */
1998 if (die
->child
!= NULL
)
2000 child_die
= die
->child
;
2001 while (child_die
&& child_die
->tag
)
2003 process_die (child_die
, cu
);
2004 child_die
= sibling_die (child_die
);
2008 /* Decode line number information if present. */
2009 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
2012 unsigned int line_offset
= DW_UNSND (attr
);
2013 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2016 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
2017 (void *) line_header
);
2018 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
);
2022 /* Decode macro information, if present. Dwarf 2 macro information
2023 refers to information in the line number info statement program
2024 header, so we can only read it if we've read the header
2026 attr
= dwarf_attr (die
, DW_AT_macro_info
);
2027 if (attr
&& line_header
)
2029 unsigned int macro_offset
= DW_UNSND (attr
);
2030 dwarf_decode_macros (line_header
, macro_offset
,
2031 comp_dir
, abfd
, cu
);
2033 do_cleanups (back_to
);
2037 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
)
2039 struct function_range
*thisfn
;
2041 thisfn
= (struct function_range
*)
2042 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct function_range
));
2043 thisfn
->name
= name
;
2044 thisfn
->lowpc
= lowpc
;
2045 thisfn
->highpc
= highpc
;
2046 thisfn
->seen_line
= 0;
2047 thisfn
->next
= NULL
;
2049 if (cu_last_fn
== NULL
)
2050 cu_first_fn
= thisfn
;
2052 cu_last_fn
->next
= thisfn
;
2054 cu_last_fn
= thisfn
;
2058 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2060 struct objfile
*objfile
= cu
->objfile
;
2061 struct context_stack
*new;
2064 struct die_info
*child_die
;
2065 struct attribute
*attr
;
2068 name
= dwarf2_linkage_name (die
);
2070 /* Ignore functions with missing or empty names and functions with
2071 missing or invalid low and high pc attributes. */
2072 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2078 /* Record the function range for dwarf_decode_lines. */
2079 add_to_cu_func_list (name
, lowpc
, highpc
);
2081 if (objfile
->ei
.entry_point
>= lowpc
&&
2082 objfile
->ei
.entry_point
< highpc
)
2084 objfile
->ei
.entry_func_lowpc
= lowpc
;
2085 objfile
->ei
.entry_func_highpc
= highpc
;
2088 new = push_context (0, lowpc
);
2089 new->name
= new_symbol (die
, die
->type
, cu
);
2091 /* If there is a location expression for DW_AT_frame_base, record
2093 attr
= dwarf_attr (die
, DW_AT_frame_base
);
2095 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
2097 list_in_scope
= &local_symbols
;
2099 if (die
->child
!= NULL
)
2101 child_die
= die
->child
;
2102 while (child_die
&& child_die
->tag
)
2104 process_die (child_die
, cu
);
2105 child_die
= sibling_die (child_die
);
2109 new = pop_context ();
2110 /* Make a block for the local symbols within. */
2111 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2112 lowpc
, highpc
, objfile
);
2114 /* In C++, we can have functions nested inside functions (e.g., when
2115 a function declares a class that has methods). This means that
2116 when we finish processing a function scope, we may need to go
2117 back to building a containing block's symbol lists. */
2118 local_symbols
= new->locals
;
2119 param_symbols
= new->params
;
2121 /* If we've finished processing a top-level function, subsequent
2122 symbols go in the file symbol list. */
2123 if (outermost_context_p ())
2124 list_in_scope
= &file_symbols
;
2127 /* Process all the DIES contained within a lexical block scope. Start
2128 a new scope, process the dies, and then close the scope. */
2131 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2133 struct objfile
*objfile
= cu
->objfile
;
2134 struct context_stack
*new;
2135 CORE_ADDR lowpc
, highpc
;
2136 struct die_info
*child_die
;
2138 /* Ignore blocks with missing or invalid low and high pc attributes. */
2139 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2140 as multiple lexical blocks? Handling children in a sane way would
2141 be nasty. Might be easier to properly extend generic blocks to
2143 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2148 push_context (0, lowpc
);
2149 if (die
->child
!= NULL
)
2151 child_die
= die
->child
;
2152 while (child_die
&& child_die
->tag
)
2154 process_die (child_die
, cu
);
2155 child_die
= sibling_die (child_die
);
2158 new = pop_context ();
2160 if (local_symbols
!= NULL
)
2162 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
2165 local_symbols
= new->locals
;
2168 /* Get low and high pc attributes from a die. Return 1 if the attributes
2169 are present and valid, otherwise, return 0. Return -1 if the range is
2170 discontinuous, i.e. derived from DW_AT_ranges information. */
2172 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
2173 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
2175 struct objfile
*objfile
= cu
->objfile
;
2176 struct comp_unit_head
*cu_header
= &cu
->header
;
2177 struct attribute
*attr
;
2178 bfd
*obfd
= objfile
->obfd
;
2183 attr
= dwarf_attr (die
, DW_AT_high_pc
);
2186 high
= DW_ADDR (attr
);
2187 attr
= dwarf_attr (die
, DW_AT_low_pc
);
2189 low
= DW_ADDR (attr
);
2191 /* Found high w/o low attribute. */
2194 /* Found consecutive range of addresses. */
2199 attr
= dwarf_attr (die
, DW_AT_ranges
);
2202 unsigned int addr_size
= cu_header
->addr_size
;
2203 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
2204 /* Value of the DW_AT_ranges attribute is the offset in the
2205 .debug_ranges section. */
2206 unsigned int offset
= DW_UNSND (attr
);
2207 /* Base address selection entry. */
2215 found_base
= cu_header
->base_known
;
2216 base
= cu_header
->base_address
;
2218 if (offset
>= dwarf_ranges_size
)
2220 complaint (&symfile_complaints
,
2221 "Offset %d out of bounds for DW_AT_ranges attribute",
2225 buffer
= dwarf_ranges_buffer
+ offset
;
2227 /* Read in the largest possible address. */
2228 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
2229 if ((marker
& mask
) == mask
)
2231 /* If we found the largest possible address, then
2232 read the base address. */
2233 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2234 buffer
+= 2 * addr_size
;
2235 offset
+= 2 * addr_size
;
2243 CORE_ADDR range_beginning
, range_end
;
2245 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
2246 buffer
+= addr_size
;
2247 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
2248 buffer
+= addr_size
;
2249 offset
+= 2 * addr_size
;
2251 /* An end of list marker is a pair of zero addresses. */
2252 if (range_beginning
== 0 && range_end
== 0)
2253 /* Found the end of list entry. */
2256 /* Each base address selection entry is a pair of 2 values.
2257 The first is the largest possible address, the second is
2258 the base address. Check for a base address here. */
2259 if ((range_beginning
& mask
) == mask
)
2261 /* If we found the largest possible address, then
2262 read the base address. */
2263 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2270 /* We have no valid base address for the ranges
2272 complaint (&symfile_complaints
,
2273 "Invalid .debug_ranges data (no base address)");
2277 range_beginning
+= base
;
2280 /* FIXME: This is recording everything as a low-high
2281 segment of consecutive addresses. We should have a
2282 data structure for discontiguous block ranges
2286 low
= range_beginning
;
2292 if (range_beginning
< low
)
2293 low
= range_beginning
;
2294 if (range_end
> high
)
2300 /* If the first entry is an end-of-list marker, the range
2301 describes an empty scope, i.e. no instructions. */
2311 /* When using the GNU linker, .gnu.linkonce. sections are used to
2312 eliminate duplicate copies of functions and vtables and such.
2313 The linker will arbitrarily choose one and discard the others.
2314 The AT_*_pc values for such functions refer to local labels in
2315 these sections. If the section from that file was discarded, the
2316 labels are not in the output, so the relocs get a value of 0.
2317 If this is a discarded function, mark the pc bounds as invalid,
2318 so that GDB will ignore it. */
2319 if (low
== 0 && (bfd_get_file_flags (obfd
) & HAS_RELOC
) == 0)
2327 /* Add an aggregate field to the field list. */
2330 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
2331 struct dwarf2_cu
*cu
)
2333 struct objfile
*objfile
= cu
->objfile
;
2334 struct nextfield
*new_field
;
2335 struct attribute
*attr
;
2337 char *fieldname
= "";
2339 /* Allocate a new field list entry and link it in. */
2340 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2341 make_cleanup (xfree
, new_field
);
2342 memset (new_field
, 0, sizeof (struct nextfield
));
2343 new_field
->next
= fip
->fields
;
2344 fip
->fields
= new_field
;
2347 /* Handle accessibility and virtuality of field.
2348 The default accessibility for members is public, the default
2349 accessibility for inheritance is private. */
2350 if (die
->tag
!= DW_TAG_inheritance
)
2351 new_field
->accessibility
= DW_ACCESS_public
;
2353 new_field
->accessibility
= DW_ACCESS_private
;
2354 new_field
->virtuality
= DW_VIRTUALITY_none
;
2356 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2358 new_field
->accessibility
= DW_UNSND (attr
);
2359 if (new_field
->accessibility
!= DW_ACCESS_public
)
2360 fip
->non_public_fields
= 1;
2361 attr
= dwarf_attr (die
, DW_AT_virtuality
);
2363 new_field
->virtuality
= DW_UNSND (attr
);
2365 fp
= &new_field
->field
;
2367 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
))
2369 /* Data member other than a C++ static data member. */
2371 /* Get type of field. */
2372 fp
->type
= die_type (die
, cu
);
2374 FIELD_STATIC_KIND (*fp
) = 0;
2376 /* Get bit size of field (zero if none). */
2377 attr
= dwarf_attr (die
, DW_AT_bit_size
);
2380 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
2384 FIELD_BITSIZE (*fp
) = 0;
2387 /* Get bit offset of field. */
2388 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2391 FIELD_BITPOS (*fp
) =
2392 decode_locdesc (DW_BLOCK (attr
), cu
) * bits_per_byte
;
2395 FIELD_BITPOS (*fp
) = 0;
2396 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
2399 if (BITS_BIG_ENDIAN
)
2401 /* For big endian bits, the DW_AT_bit_offset gives the
2402 additional bit offset from the MSB of the containing
2403 anonymous object to the MSB of the field. We don't
2404 have to do anything special since we don't need to
2405 know the size of the anonymous object. */
2406 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
2410 /* For little endian bits, compute the bit offset to the
2411 MSB of the anonymous object, subtract off the number of
2412 bits from the MSB of the field to the MSB of the
2413 object, and then subtract off the number of bits of
2414 the field itself. The result is the bit offset of
2415 the LSB of the field. */
2417 int bit_offset
= DW_UNSND (attr
);
2419 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2422 /* The size of the anonymous object containing
2423 the bit field is explicit, so use the
2424 indicated size (in bytes). */
2425 anonymous_size
= DW_UNSND (attr
);
2429 /* The size of the anonymous object containing
2430 the bit field must be inferred from the type
2431 attribute of the data member containing the
2433 anonymous_size
= TYPE_LENGTH (fp
->type
);
2435 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2436 - bit_offset
- FIELD_BITSIZE (*fp
);
2440 /* Get name of field. */
2441 attr
= dwarf_attr (die
, DW_AT_name
);
2442 if (attr
&& DW_STRING (attr
))
2443 fieldname
= DW_STRING (attr
);
2444 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
2445 &objfile
->type_obstack
);
2447 /* Change accessibility for artificial fields (e.g. virtual table
2448 pointer or virtual base class pointer) to private. */
2449 if (dwarf_attr (die
, DW_AT_artificial
))
2451 new_field
->accessibility
= DW_ACCESS_private
;
2452 fip
->non_public_fields
= 1;
2455 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
2457 /* C++ static member. */
2459 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2460 is a declaration, but all versions of G++ as of this writing
2461 (so through at least 3.2.1) incorrectly generate
2462 DW_TAG_variable tags. */
2466 /* Get name of field. */
2467 attr
= dwarf_attr (die
, DW_AT_name
);
2468 if (attr
&& DW_STRING (attr
))
2469 fieldname
= DW_STRING (attr
);
2473 /* Get physical name. */
2474 physname
= dwarf2_linkage_name (die
);
2476 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
2477 &objfile
->type_obstack
));
2478 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2479 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
2480 &objfile
->type_obstack
);
2482 else if (die
->tag
== DW_TAG_inheritance
)
2484 /* C++ base class field. */
2485 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2487 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
2489 FIELD_BITSIZE (*fp
) = 0;
2490 FIELD_STATIC_KIND (*fp
) = 0;
2491 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2492 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2493 fip
->nbaseclasses
++;
2497 /* Create the vector of fields, and attach it to the type. */
2500 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
2501 struct dwarf2_cu
*cu
)
2503 int nfields
= fip
->nfields
;
2505 /* Record the field count, allocate space for the array of fields,
2506 and create blank accessibility bitfields if necessary. */
2507 TYPE_NFIELDS (type
) = nfields
;
2508 TYPE_FIELDS (type
) = (struct field
*)
2509 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2510 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2512 if (fip
->non_public_fields
)
2514 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2516 TYPE_FIELD_PRIVATE_BITS (type
) =
2517 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2518 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2520 TYPE_FIELD_PROTECTED_BITS (type
) =
2521 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2522 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2524 TYPE_FIELD_IGNORE_BITS (type
) =
2525 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2526 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2529 /* If the type has baseclasses, allocate and clear a bit vector for
2530 TYPE_FIELD_VIRTUAL_BITS. */
2531 if (fip
->nbaseclasses
)
2533 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2536 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2537 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2538 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2539 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2540 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2543 /* Copy the saved-up fields into the field vector. Start from the head
2544 of the list, adding to the tail of the field array, so that they end
2545 up in the same order in the array in which they were added to the list. */
2546 while (nfields
-- > 0)
2548 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2549 switch (fip
->fields
->accessibility
)
2551 case DW_ACCESS_private
:
2552 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2555 case DW_ACCESS_protected
:
2556 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2559 case DW_ACCESS_public
:
2563 /* Unknown accessibility. Complain and treat it as public. */
2565 complaint (&symfile_complaints
, "unsupported accessibility %d",
2566 fip
->fields
->accessibility
);
2570 if (nfields
< fip
->nbaseclasses
)
2572 switch (fip
->fields
->virtuality
)
2574 case DW_VIRTUALITY_virtual
:
2575 case DW_VIRTUALITY_pure_virtual
:
2576 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2580 fip
->fields
= fip
->fields
->next
;
2584 /* Add a member function to the proper fieldlist. */
2587 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2588 struct type
*type
, struct dwarf2_cu
*cu
)
2590 struct objfile
*objfile
= cu
->objfile
;
2591 struct attribute
*attr
;
2592 struct fnfieldlist
*flp
;
2594 struct fn_field
*fnp
;
2597 struct nextfnfield
*new_fnfield
;
2599 /* Get name of member function. */
2600 attr
= dwarf_attr (die
, DW_AT_name
);
2601 if (attr
&& DW_STRING (attr
))
2602 fieldname
= DW_STRING (attr
);
2606 /* Get the mangled name. */
2607 physname
= dwarf2_linkage_name (die
);
2609 /* Look up member function name in fieldlist. */
2610 for (i
= 0; i
< fip
->nfnfields
; i
++)
2612 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
2616 /* Create new list element if necessary. */
2617 if (i
< fip
->nfnfields
)
2618 flp
= &fip
->fnfieldlists
[i
];
2621 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2623 fip
->fnfieldlists
= (struct fnfieldlist
*)
2624 xrealloc (fip
->fnfieldlists
,
2625 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2626 * sizeof (struct fnfieldlist
));
2627 if (fip
->nfnfields
== 0)
2628 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2630 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2631 flp
->name
= fieldname
;
2637 /* Create a new member function field and chain it to the field list
2639 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2640 make_cleanup (xfree
, new_fnfield
);
2641 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2642 new_fnfield
->next
= flp
->head
;
2643 flp
->head
= new_fnfield
;
2646 /* Fill in the member function field info. */
2647 fnp
= &new_fnfield
->fnfield
;
2648 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2649 &objfile
->type_obstack
);
2650 fnp
->type
= alloc_type (objfile
);
2651 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2653 int nparams
= TYPE_NFIELDS (die
->type
);
2655 /* TYPE is the domain of this method, and DIE->TYPE is the type
2656 of the method itself (TYPE_CODE_METHOD). */
2657 smash_to_method_type (fnp
->type
, type
,
2658 TYPE_TARGET_TYPE (die
->type
),
2659 TYPE_FIELDS (die
->type
),
2660 TYPE_NFIELDS (die
->type
),
2661 TYPE_VARARGS (die
->type
));
2663 /* Handle static member functions.
2664 Dwarf2 has no clean way to discern C++ static and non-static
2665 member functions. G++ helps GDB by marking the first
2666 parameter for non-static member functions (which is the
2667 this pointer) as artificial. We obtain this information
2668 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2669 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2670 fnp
->voffset
= VOFFSET_STATIC
;
2673 complaint (&symfile_complaints
, "member function type missing for '%s'",
2676 /* Get fcontext from DW_AT_containing_type if present. */
2677 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2678 fnp
->fcontext
= die_containing_type (die
, cu
);
2680 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2681 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2683 /* Get accessibility. */
2684 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2687 switch (DW_UNSND (attr
))
2689 case DW_ACCESS_private
:
2690 fnp
->is_private
= 1;
2692 case DW_ACCESS_protected
:
2693 fnp
->is_protected
= 1;
2698 /* Check for artificial methods. */
2699 attr
= dwarf_attr (die
, DW_AT_artificial
);
2700 if (attr
&& DW_UNSND (attr
) != 0)
2701 fnp
->is_artificial
= 1;
2703 /* Get index in virtual function table if it is a virtual member function. */
2704 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2707 /* Support the .debug_loc offsets */
2708 if (attr_form_is_block (attr
))
2710 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
2712 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
2714 dwarf2_complex_location_expr_complaint ();
2718 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
2724 /* Create the vector of member function fields, and attach it to the type. */
2727 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2728 struct dwarf2_cu
*cu
)
2730 struct fnfieldlist
*flp
;
2731 int total_length
= 0;
2734 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2735 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2736 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2738 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2740 struct nextfnfield
*nfp
= flp
->head
;
2741 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2744 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2745 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2746 fn_flp
->fn_fields
= (struct fn_field
*)
2747 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2748 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2749 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2751 total_length
+= flp
->length
;
2754 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2755 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2758 /* Called when we find the DIE that starts a structure or union scope
2759 (definition) to process all dies that define the members of the
2762 NOTE: we need to call struct_type regardless of whether or not the
2763 DIE has an at_name attribute, since it might be an anonymous
2764 structure or union. This gets the type entered into our set of
2767 However, if the structure is incomplete (an opaque struct/union)
2768 then suppress creating a symbol table entry for it since gdb only
2769 wants to find the one with the complete definition. Note that if
2770 it is complete, we just call new_symbol, which does it's own
2771 checking about whether the struct/union is anonymous or not (and
2772 suppresses creating a symbol table entry itself). */
2775 read_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2777 struct objfile
*objfile
= cu
->objfile
;
2779 struct attribute
*attr
;
2781 type
= alloc_type (objfile
);
2783 INIT_CPLUS_SPECIFIC (type
);
2784 attr
= dwarf_attr (die
, DW_AT_name
);
2785 if (attr
&& DW_STRING (attr
))
2787 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2788 strlen (DW_STRING (attr
)),
2789 &objfile
->type_obstack
);
2792 if (die
->tag
== DW_TAG_structure_type
)
2794 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2796 else if (die
->tag
== DW_TAG_union_type
)
2798 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2802 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2804 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2807 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2810 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2814 TYPE_LENGTH (type
) = 0;
2817 /* We need to add the type field to the die immediately so we don't
2818 infinitely recurse when dealing with pointers to the structure
2819 type within the structure itself. */
2822 if (die
->child
!= NULL
&& ! die_is_declaration (die
))
2824 struct field_info fi
;
2825 struct die_info
*child_die
;
2826 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2828 memset (&fi
, 0, sizeof (struct field_info
));
2830 child_die
= die
->child
;
2832 while (child_die
&& child_die
->tag
)
2834 if (child_die
->tag
== DW_TAG_member
2835 || child_die
->tag
== DW_TAG_variable
)
2837 /* NOTE: carlton/2002-11-05: A C++ static data member
2838 should be a DW_TAG_member that is a declaration, but
2839 all versions of G++ as of this writing (so through at
2840 least 3.2.1) incorrectly generate DW_TAG_variable
2841 tags for them instead. */
2842 dwarf2_add_field (&fi
, child_die
, cu
);
2844 else if (child_die
->tag
== DW_TAG_subprogram
)
2846 /* C++ member function. */
2847 process_die (child_die
, cu
);
2848 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
2850 else if (child_die
->tag
== DW_TAG_inheritance
)
2852 /* C++ base class field. */
2853 dwarf2_add_field (&fi
, child_die
, cu
);
2857 process_die (child_die
, cu
);
2859 child_die
= sibling_die (child_die
);
2862 /* Attach fields and member functions to the type. */
2864 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
2867 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
2869 /* Get the type which refers to the base class (possibly this
2870 class itself) which contains the vtable pointer for the current
2871 class from the DW_AT_containing_type attribute. */
2873 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2875 struct type
*t
= die_containing_type (die
, cu
);
2877 TYPE_VPTR_BASETYPE (type
) = t
;
2880 static const char vptr_name
[] =
2881 {'_', 'v', 'p', 't', 'r', '\0'};
2884 /* Our own class provides vtbl ptr. */
2885 for (i
= TYPE_NFIELDS (t
) - 1;
2886 i
>= TYPE_N_BASECLASSES (t
);
2889 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2891 if ((strncmp (fieldname
, vptr_name
,
2892 strlen (vptr_name
) - 1)
2894 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2896 TYPE_VPTR_FIELDNO (type
) = i
;
2901 /* Complain if virtual function table field not found. */
2902 if (i
< TYPE_N_BASECLASSES (t
))
2903 complaint (&symfile_complaints
,
2904 "virtual function table pointer not found when defining class '%s'",
2905 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
2910 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2915 new_symbol (die
, type
, cu
);
2917 do_cleanups (back_to
);
2921 /* No children, must be stub. */
2922 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2926 /* Given a pointer to a die which begins an enumeration, process all
2927 the dies that define the members of the enumeration.
2929 This will be much nicer in draft 6 of the DWARF spec when our
2930 members will be dies instead squished into the DW_AT_element_list
2933 NOTE: We reverse the order of the element list. */
2936 read_enumeration (struct die_info
*die
, struct dwarf2_cu
*cu
)
2938 struct objfile
*objfile
= cu
->objfile
;
2939 struct die_info
*child_die
;
2941 struct field
*fields
;
2942 struct attribute
*attr
;
2945 int unsigned_enum
= 1;
2947 type
= alloc_type (objfile
);
2949 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2950 attr
= dwarf_attr (die
, DW_AT_name
);
2951 if (attr
&& DW_STRING (attr
))
2953 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2954 strlen (DW_STRING (attr
)),
2955 &objfile
->type_obstack
);
2958 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2961 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2965 TYPE_LENGTH (type
) = 0;
2970 if (die
->child
!= NULL
)
2972 child_die
= die
->child
;
2973 while (child_die
&& child_die
->tag
)
2975 if (child_die
->tag
!= DW_TAG_enumerator
)
2977 process_die (child_die
, cu
);
2981 attr
= dwarf_attr (child_die
, DW_AT_name
);
2984 sym
= new_symbol (child_die
, type
, cu
);
2985 if (SYMBOL_VALUE (sym
) < 0)
2988 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2990 fields
= (struct field
*)
2992 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2993 * sizeof (struct field
));
2996 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
2997 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2998 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2999 FIELD_BITSIZE (fields
[num_fields
]) = 0;
3000 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
3006 child_die
= sibling_die (child_die
);
3011 TYPE_NFIELDS (type
) = num_fields
;
3012 TYPE_FIELDS (type
) = (struct field
*)
3013 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
3014 memcpy (TYPE_FIELDS (type
), fields
,
3015 sizeof (struct field
) * num_fields
);
3019 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
3022 new_symbol (die
, type
, cu
);
3025 /* Extract all information from a DW_TAG_array_type DIE and put it in
3026 the DIE's type field. For now, this only handles one dimensional
3030 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3032 struct objfile
*objfile
= cu
->objfile
;
3033 struct die_info
*child_die
;
3034 struct type
*type
= NULL
;
3035 struct type
*element_type
, *range_type
, *index_type
;
3036 struct type
**range_types
= NULL
;
3037 struct attribute
*attr
;
3039 struct cleanup
*back_to
;
3041 /* Return if we've already decoded this type. */
3047 element_type
= die_type (die
, cu
);
3049 /* Irix 6.2 native cc creates array types without children for
3050 arrays with unspecified length. */
3051 if (die
->child
== NULL
)
3053 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
3054 range_type
= create_range_type (NULL
, index_type
, 0, -1);
3055 die
->type
= create_array_type (NULL
, element_type
, range_type
);
3059 back_to
= make_cleanup (null_cleanup
, NULL
);
3060 child_die
= die
->child
;
3061 while (child_die
&& child_die
->tag
)
3063 if (child_die
->tag
== DW_TAG_subrange_type
)
3065 unsigned int low
, high
;
3067 /* Default bounds to an array with unspecified length. */
3070 if (cu_language
== language_fortran
)
3072 /* FORTRAN implies a lower bound of 1, if not given. */
3076 index_type
= die_type (child_die
, cu
);
3077 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
3080 if (attr
->form
== DW_FORM_sdata
)
3082 low
= DW_SND (attr
);
3084 else if (attr
->form
== DW_FORM_udata
3085 || attr
->form
== DW_FORM_data1
3086 || attr
->form
== DW_FORM_data2
3087 || attr
->form
== DW_FORM_data4
3088 || attr
->form
== DW_FORM_data8
)
3090 low
= DW_UNSND (attr
);
3094 dwarf2_non_const_array_bound_ignored_complaint
3095 (dwarf_form_name (attr
->form
));
3099 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
3102 if (attr
->form
== DW_FORM_sdata
)
3104 high
= DW_SND (attr
);
3106 else if (attr
->form
== DW_FORM_udata
3107 || attr
->form
== DW_FORM_data1
3108 || attr
->form
== DW_FORM_data2
3109 || attr
->form
== DW_FORM_data4
3110 || attr
->form
== DW_FORM_data8
)
3112 high
= DW_UNSND (attr
);
3114 else if (attr
->form
== DW_FORM_block1
)
3116 /* GCC encodes arrays with unspecified or dynamic length
3117 with a DW_FORM_block1 attribute.
3118 FIXME: GDB does not yet know how to handle dynamic
3119 arrays properly, treat them as arrays with unspecified
3122 FIXME: jimb/2003-09-22: GDB does not really know
3123 how to handle arrays of unspecified length
3124 either; we just represent them as zero-length
3125 arrays. Choose an appropriate upper bound given
3126 the lower bound we've computed above. */
3131 dwarf2_non_const_array_bound_ignored_complaint
3132 (dwarf_form_name (attr
->form
));
3137 /* Create a range type and save it for array type creation. */
3138 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
3140 range_types
= (struct type
**)
3141 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
3142 * sizeof (struct type
*));
3144 make_cleanup (free_current_contents
, &range_types
);
3146 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
3148 child_die
= sibling_die (child_die
);
3151 /* Dwarf2 dimensions are output from left to right, create the
3152 necessary array types in backwards order. */
3153 type
= element_type
;
3155 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
3157 /* Understand Dwarf2 support for vector types (like they occur on
3158 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3159 array type. This is not part of the Dwarf2/3 standard yet, but a
3160 custom vendor extension. The main difference between a regular
3161 array and the vector variant is that vectors are passed by value
3163 attr
= dwarf_attr (die
, DW_AT_GNU_vector
);
3165 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
3167 do_cleanups (back_to
);
3169 /* Install the type in the die. */
3173 /* First cut: install each common block member as a global variable. */
3176 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
3178 struct die_info
*child_die
;
3179 struct attribute
*attr
;
3181 CORE_ADDR base
= (CORE_ADDR
) 0;
3183 attr
= dwarf_attr (die
, DW_AT_location
);
3186 /* Support the .debug_loc offsets */
3187 if (attr_form_is_block (attr
))
3189 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
3191 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3193 dwarf2_complex_location_expr_complaint ();
3197 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3198 "common block member");
3201 if (die
->child
!= NULL
)
3203 child_die
= die
->child
;
3204 while (child_die
&& child_die
->tag
)
3206 sym
= new_symbol (child_die
, NULL
, cu
);
3207 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
3210 SYMBOL_VALUE_ADDRESS (sym
) =
3211 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
3212 add_symbol_to_list (sym
, &global_symbols
);
3214 child_die
= sibling_die (child_die
);
3219 /* Read a C++ namespace. */
3222 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
3224 struct objfile
*objfile
= cu
->objfile
;
3225 const char *previous_prefix
= processing_current_prefix
;
3226 const char *name
= NULL
;
3228 struct die_info
*current_die
;
3230 name
= namespace_name (die
, &is_anonymous
);
3232 /* Now build the name of the current namespace. */
3234 if (previous_prefix
[0] == '\0')
3236 processing_current_prefix
= name
;
3240 /* We need temp_name around because processing_current_prefix
3241 is a const char *. */
3242 char *temp_name
= alloca (strlen (previous_prefix
)
3243 + 2 + strlen(name
) + 1);
3244 strcpy (temp_name
, previous_prefix
);
3245 strcat (temp_name
, "::");
3246 strcat (temp_name
, name
);
3248 processing_current_prefix
= temp_name
;
3251 /* Add a symbol associated to this if we haven't seen the namespace
3252 before. Also, add a using directive if it's an anonymous
3255 if (dwarf2_extension (die
) == NULL
)
3259 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
3260 this cast will hopefully become unnecessary. */
3261 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
3262 (char *) processing_current_prefix
,
3264 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
3266 new_symbol (die
, type
, cu
);
3269 cp_add_using_directive (processing_current_prefix
,
3270 strlen (previous_prefix
),
3271 strlen (processing_current_prefix
));
3274 if (die
->child
!= NULL
)
3276 struct die_info
*child_die
= die
->child
;
3278 while (child_die
&& child_die
->tag
)
3280 process_die (child_die
, cu
);
3281 child_die
= sibling_die (child_die
);
3285 processing_current_prefix
= previous_prefix
;
3288 /* Return the name of the namespace represented by DIE. Set
3289 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
3293 namespace_name (struct die_info
*die
, int *is_anonymous
)
3295 struct die_info
*current_die
;
3296 const char *name
= NULL
;
3298 /* Loop through the extensions until we find a name. */
3300 for (current_die
= die
;
3301 current_die
!= NULL
;
3302 current_die
= dwarf2_extension (die
))
3304 name
= dwarf2_name (current_die
);
3309 /* Is it an anonymous namespace? */
3311 *is_anonymous
= (name
== NULL
);
3313 name
= "(anonymous namespace)";
3318 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3319 the user defined type vector. */
3322 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3324 struct comp_unit_head
*cu_header
= &cu
->header
;
3326 struct attribute
*attr_byte_size
;
3327 struct attribute
*attr_address_class
;
3328 int byte_size
, addr_class
;
3335 type
= lookup_pointer_type (die_type (die
, cu
));
3337 attr_byte_size
= dwarf_attr (die
, DW_AT_byte_size
);
3339 byte_size
= DW_UNSND (attr_byte_size
);
3341 byte_size
= cu_header
->addr_size
;
3343 attr_address_class
= dwarf_attr (die
, DW_AT_address_class
);
3344 if (attr_address_class
)
3345 addr_class
= DW_UNSND (attr_address_class
);
3347 addr_class
= DW_ADDR_none
;
3349 /* If the pointer size or address class is different than the
3350 default, create a type variant marked as such and set the
3351 length accordingly. */
3352 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
3354 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3358 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
3359 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
3360 type
= make_type_with_address_space (type
, type_flags
);
3362 else if (TYPE_LENGTH (type
) != byte_size
)
3364 complaint (&symfile_complaints
, "invalid pointer size %d", byte_size
);
3367 /* Should we also complain about unhandled address classes? */
3371 TYPE_LENGTH (type
) = byte_size
;
3375 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3376 the user defined type vector. */
3379 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3381 struct objfile
*objfile
= cu
->objfile
;
3383 struct type
*to_type
;
3384 struct type
*domain
;
3391 type
= alloc_type (objfile
);
3392 to_type
= die_type (die
, cu
);
3393 domain
= die_containing_type (die
, cu
);
3394 smash_to_member_type (type
, domain
, to_type
);
3399 /* Extract all information from a DW_TAG_reference_type DIE and add to
3400 the user defined type vector. */
3403 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3405 struct comp_unit_head
*cu_header
= &cu
->header
;
3407 struct attribute
*attr
;
3414 type
= lookup_reference_type (die_type (die
, cu
));
3415 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3418 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3422 TYPE_LENGTH (type
) = cu_header
->addr_size
;
3428 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3430 struct type
*base_type
;
3437 base_type
= die_type (die
, cu
);
3438 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
3442 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3444 struct type
*base_type
;
3451 base_type
= die_type (die
, cu
);
3452 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
3455 /* Extract all information from a DW_TAG_string_type DIE and add to
3456 the user defined type vector. It isn't really a user defined type,
3457 but it behaves like one, with other DIE's using an AT_user_def_type
3458 attribute to reference it. */
3461 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3463 struct objfile
*objfile
= cu
->objfile
;
3464 struct type
*type
, *range_type
, *index_type
, *char_type
;
3465 struct attribute
*attr
;
3466 unsigned int length
;
3473 attr
= dwarf_attr (die
, DW_AT_string_length
);
3476 length
= DW_UNSND (attr
);
3480 /* check for the DW_AT_byte_size attribute */
3481 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3484 length
= DW_UNSND (attr
);
3491 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
3492 range_type
= create_range_type (NULL
, index_type
, 1, length
);
3493 if (cu_language
== language_fortran
)
3495 /* Need to create a unique string type for bounds
3497 type
= create_string_type (0, range_type
);
3501 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
3502 type
= create_string_type (char_type
, range_type
);
3507 /* Handle DIES due to C code like:
3511 int (*funcp)(int a, long l);
3515 ('funcp' generates a DW_TAG_subroutine_type DIE)
3519 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3521 struct type
*type
; /* Type that this function returns */
3522 struct type
*ftype
; /* Function that returns above type */
3523 struct attribute
*attr
;
3525 /* Decode the type that this subroutine returns */
3530 type
= die_type (die
, cu
);
3531 ftype
= lookup_function_type (type
);
3533 /* All functions in C++ have prototypes. */
3534 attr
= dwarf_attr (die
, DW_AT_prototyped
);
3535 if ((attr
&& (DW_UNSND (attr
) != 0))
3536 || cu_language
== language_cplus
)
3537 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
3539 if (die
->child
!= NULL
)
3541 struct die_info
*child_die
;
3545 /* Count the number of parameters.
3546 FIXME: GDB currently ignores vararg functions, but knows about
3547 vararg member functions. */
3548 child_die
= die
->child
;
3549 while (child_die
&& child_die
->tag
)
3551 if (child_die
->tag
== DW_TAG_formal_parameter
)
3553 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
3554 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
3555 child_die
= sibling_die (child_die
);
3558 /* Allocate storage for parameters and fill them in. */
3559 TYPE_NFIELDS (ftype
) = nparams
;
3560 TYPE_FIELDS (ftype
) = (struct field
*)
3561 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
3563 child_die
= die
->child
;
3564 while (child_die
&& child_die
->tag
)
3566 if (child_die
->tag
== DW_TAG_formal_parameter
)
3568 /* Dwarf2 has no clean way to discern C++ static and non-static
3569 member functions. G++ helps GDB by marking the first
3570 parameter for non-static member functions (which is the
3571 this pointer) as artificial. We pass this information
3572 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
3573 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
3575 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
3577 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
3578 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
3581 child_die
= sibling_die (child_die
);
3589 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
3591 struct objfile
*objfile
= cu
->objfile
;
3592 struct attribute
*attr
;
3597 attr
= dwarf_attr (die
, DW_AT_name
);
3598 if (attr
&& DW_STRING (attr
))
3600 name
= DW_STRING (attr
);
3602 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
3603 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, cu
);
3607 /* Find a representation of a given base type and install
3608 it in the TYPE field of the die. */
3611 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3613 struct objfile
*objfile
= cu
->objfile
;
3615 struct attribute
*attr
;
3616 int encoding
= 0, size
= 0;
3618 /* If we've already decoded this die, this is a no-op. */
3624 attr
= dwarf_attr (die
, DW_AT_encoding
);
3627 encoding
= DW_UNSND (attr
);
3629 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3632 size
= DW_UNSND (attr
);
3634 attr
= dwarf_attr (die
, DW_AT_name
);
3635 if (attr
&& DW_STRING (attr
))
3637 enum type_code code
= TYPE_CODE_INT
;
3642 case DW_ATE_address
:
3643 /* Turn DW_ATE_address into a void * pointer. */
3644 code
= TYPE_CODE_PTR
;
3645 type_flags
|= TYPE_FLAG_UNSIGNED
;
3647 case DW_ATE_boolean
:
3648 code
= TYPE_CODE_BOOL
;
3649 type_flags
|= TYPE_FLAG_UNSIGNED
;
3651 case DW_ATE_complex_float
:
3652 code
= TYPE_CODE_COMPLEX
;
3655 code
= TYPE_CODE_FLT
;
3658 case DW_ATE_signed_char
:
3660 case DW_ATE_unsigned
:
3661 case DW_ATE_unsigned_char
:
3662 type_flags
|= TYPE_FLAG_UNSIGNED
;
3665 complaint (&symfile_complaints
, "unsupported DW_AT_encoding: '%s'",
3666 dwarf_type_encoding_name (encoding
));
3669 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
3670 if (encoding
== DW_ATE_address
)
3671 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
3672 else if (encoding
== DW_ATE_complex_float
)
3675 TYPE_TARGET_TYPE (type
)
3676 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
3677 else if (size
== 16)
3678 TYPE_TARGET_TYPE (type
)
3679 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
3681 TYPE_TARGET_TYPE (type
)
3682 = dwarf2_fundamental_type (objfile
, FT_FLOAT
);
3687 type
= dwarf_base_type (encoding
, size
, cu
);
3692 /* Read a whole compilation unit into a linked list of dies. */
3694 static struct die_info
*
3695 read_comp_unit (char *info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
3697 /* Reset die reference table; we are
3698 building new ones now. */
3699 dwarf2_empty_hash_tables ();
3701 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
3704 /* Read a single die and all its descendents. Set the die's sibling
3705 field to NULL; set other fields in the die correctly, and set all
3706 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
3707 location of the info_ptr after reading all of those dies. PARENT
3708 is the parent of the die in question. */
3710 static struct die_info
*
3711 read_die_and_children (char *info_ptr
, bfd
*abfd
,
3712 struct dwarf2_cu
*cu
,
3713 char **new_info_ptr
,
3714 struct die_info
*parent
)
3716 struct die_info
*die
;
3720 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
3721 store_in_ref_table (die
->offset
, die
);
3725 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
3731 *new_info_ptr
= cur_ptr
;
3734 die
->sibling
= NULL
;
3735 die
->parent
= parent
;
3739 /* Read a die, all of its descendents, and all of its siblings; set
3740 all of the fields of all of the dies correctly. Arguments are as
3741 in read_die_and_children. */
3743 static struct die_info
*
3744 read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
3745 struct dwarf2_cu
*cu
,
3746 char **new_info_ptr
,
3747 struct die_info
*parent
)
3749 struct die_info
*first_die
, *last_sibling
;
3753 first_die
= last_sibling
= NULL
;
3757 struct die_info
*die
3758 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
3766 last_sibling
->sibling
= die
;
3771 *new_info_ptr
= cur_ptr
;
3781 /* Free a linked list of dies. */
3784 free_die_list (struct die_info
*dies
)
3786 struct die_info
*die
, *next
;
3791 if (die
->child
!= NULL
)
3792 free_die_list (die
->child
);
3793 next
= die
->sibling
;
3801 do_free_die_list_cleanup (void *dies
)
3803 free_die_list (dies
);
3806 static struct cleanup
*
3807 make_cleanup_free_die_list (struct die_info
*dies
)
3809 return make_cleanup (do_free_die_list_cleanup
, dies
);
3813 /* Read the contents of the section at OFFSET and of size SIZE from the
3814 object file specified by OBJFILE into the psymbol_obstack and return it. */
3817 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
3819 bfd
*abfd
= objfile
->obfd
;
3821 bfd_size_type size
= bfd_get_section_size_before_reloc (sectp
);
3826 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3828 = (char *) symfile_relocate_debug_section (abfd
, sectp
, (bfd_byte
*) buf
);
3832 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
3833 || bfd_bread (buf
, size
, abfd
) != size
)
3834 error ("Dwarf Error: Can't read DWARF data from '%s'",
3835 bfd_get_filename (abfd
));
3840 /* In DWARF version 2, the description of the debugging information is
3841 stored in a separate .debug_abbrev section. Before we read any
3842 dies from a section we read in all abbreviations and install them
3846 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
3848 struct comp_unit_head
*cu_header
= &cu
->header
;
3850 struct abbrev_info
*cur_abbrev
;
3851 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3852 unsigned int abbrev_form
, hash_number
;
3854 /* Initialize dwarf2 abbrevs */
3855 memset (cu_header
->dwarf2_abbrevs
, 0,
3856 ABBREV_HASH_SIZE
*sizeof (struct abbrev_info
*));
3858 abbrev_ptr
= dwarf_abbrev_buffer
+ cu_header
->abbrev_offset
;
3859 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3860 abbrev_ptr
+= bytes_read
;
3862 /* loop until we reach an abbrev number of 0 */
3863 while (abbrev_number
)
3865 cur_abbrev
= dwarf_alloc_abbrev ();
3867 /* read in abbrev header */
3868 cur_abbrev
->number
= abbrev_number
;
3869 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3870 abbrev_ptr
+= bytes_read
;
3871 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3874 /* now read in declarations */
3875 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3876 abbrev_ptr
+= bytes_read
;
3877 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3878 abbrev_ptr
+= bytes_read
;
3881 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3883 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3884 xrealloc (cur_abbrev
->attrs
,
3885 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3886 * sizeof (struct attr_abbrev
));
3888 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3889 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3890 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3891 abbrev_ptr
+= bytes_read
;
3892 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3893 abbrev_ptr
+= bytes_read
;
3896 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3897 cur_abbrev
->next
= cu_header
->dwarf2_abbrevs
[hash_number
];
3898 cu_header
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3900 /* Get next abbreviation.
3901 Under Irix6 the abbreviations for a compilation unit are not
3902 always properly terminated with an abbrev number of 0.
3903 Exit loop if we encounter an abbreviation which we have
3904 already read (which means we are about to read the abbreviations
3905 for the next compile unit) or if the end of the abbreviation
3906 table is reached. */
3907 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3908 >= dwarf_abbrev_size
)
3910 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3911 abbrev_ptr
+= bytes_read
;
3912 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
3917 /* Empty the abbrev table for a new compilation unit. */
3920 dwarf2_empty_abbrev_table (void *ptr_to_abbrevs_table
)
3923 struct abbrev_info
*abbrev
, *next
;
3924 struct abbrev_info
**abbrevs
;
3926 abbrevs
= (struct abbrev_info
**)ptr_to_abbrevs_table
;
3928 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3931 abbrev
= abbrevs
[i
];
3934 next
= abbrev
->next
;
3935 xfree (abbrev
->attrs
);
3943 /* Lookup an abbrev_info structure in the abbrev hash table. */
3945 static struct abbrev_info
*
3946 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
3948 struct comp_unit_head
*cu_header
= &cu
->header
;
3949 unsigned int hash_number
;
3950 struct abbrev_info
*abbrev
;
3952 hash_number
= number
% ABBREV_HASH_SIZE
;
3953 abbrev
= cu_header
->dwarf2_abbrevs
[hash_number
];
3957 if (abbrev
->number
== number
)
3960 abbrev
= abbrev
->next
;
3965 /* Read a minimal amount of information into the minimal die structure. */
3968 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3969 char *info_ptr
, struct dwarf2_cu
*cu
)
3971 unsigned int abbrev_number
, bytes_read
, i
;
3972 struct abbrev_info
*abbrev
;
3973 struct attribute attr
;
3974 struct attribute spec_attr
;
3975 int found_spec_attr
= 0;
3976 int has_low_pc_attr
= 0;
3977 int has_high_pc_attr
= 0;
3979 *part_die
= zeroed_partial_die
;
3980 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3981 info_ptr
+= bytes_read
;
3985 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
3988 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number
,
3989 bfd_get_filename (abfd
));
3991 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3992 part_die
->tag
= abbrev
->tag
;
3993 part_die
->has_children
= abbrev
->has_children
;
3994 part_die
->abbrev
= abbrev_number
;
3996 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3998 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
4000 /* Store the data if it is of an attribute we want to keep in a
4001 partial symbol table. */
4006 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
4007 if (part_die
->name
== NULL
)
4008 part_die
->name
= DW_STRING (&attr
);
4010 case DW_AT_MIPS_linkage_name
:
4011 part_die
->name
= DW_STRING (&attr
);
4014 has_low_pc_attr
= 1;
4015 part_die
->lowpc
= DW_ADDR (&attr
);
4018 has_high_pc_attr
= 1;
4019 part_die
->highpc
= DW_ADDR (&attr
);
4021 case DW_AT_location
:
4022 /* Support the .debug_loc offsets */
4023 if (attr_form_is_block (&attr
))
4025 part_die
->locdesc
= DW_BLOCK (&attr
);
4027 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
4029 dwarf2_complex_location_expr_complaint ();
4033 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4034 "partial symbol information");
4037 case DW_AT_language
:
4038 part_die
->language
= DW_UNSND (&attr
);
4040 case DW_AT_external
:
4041 part_die
->is_external
= DW_UNSND (&attr
);
4043 case DW_AT_declaration
:
4044 part_die
->is_declaration
= DW_UNSND (&attr
);
4047 part_die
->has_type
= 1;
4049 case DW_AT_abstract_origin
:
4050 case DW_AT_specification
:
4051 found_spec_attr
= 1;
4055 /* Ignore absolute siblings, they might point outside of
4056 the current compile unit. */
4057 if (attr
.form
== DW_FORM_ref_addr
)
4058 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
4061 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
4068 /* If we found a reference attribute and the die has no name, try
4069 to find a name in the referred to die. */
4071 if (found_spec_attr
&& part_die
->name
== NULL
)
4073 struct partial_die_info spec_die
;
4076 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
4077 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu
);
4080 part_die
->name
= spec_die
.name
;
4082 /* Copy DW_AT_external attribute if it is set. */
4083 if (spec_die
.is_external
)
4084 part_die
->is_external
= spec_die
.is_external
;
4088 /* When using the GNU linker, .gnu.linkonce. sections are used to
4089 eliminate duplicate copies of functions and vtables and such.
4090 The linker will arbitrarily choose one and discard the others.
4091 The AT_*_pc values for such functions refer to local labels in
4092 these sections. If the section from that file was discarded, the
4093 labels are not in the output, so the relocs get a value of 0.
4094 If this is a discarded function, mark the pc bounds as invalid,
4095 so that GDB will ignore it. */
4096 if (has_low_pc_attr
&& has_high_pc_attr
4097 && part_die
->lowpc
< part_die
->highpc
4098 && (part_die
->lowpc
!= 0
4099 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
4100 part_die
->has_pc_info
= 1;
4104 /* Read the die from the .debug_info section buffer. Set DIEP to
4105 point to a newly allocated die with its information, except for its
4106 child, sibling, and parent fields. Set HAS_CHILDREN to tell
4107 whether the die has children or not. */
4110 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
4111 struct dwarf2_cu
*cu
, int *has_children
)
4113 unsigned int abbrev_number
, bytes_read
, i
, offset
;
4114 struct abbrev_info
*abbrev
;
4115 struct die_info
*die
;
4117 offset
= info_ptr
- dwarf_info_buffer
;
4118 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4119 info_ptr
+= bytes_read
;
4122 die
= dwarf_alloc_die ();
4124 die
->abbrev
= abbrev_number
;
4131 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4134 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
4136 bfd_get_filename (abfd
));
4138 die
= dwarf_alloc_die ();
4139 die
->offset
= offset
;
4140 die
->tag
= abbrev
->tag
;
4141 die
->abbrev
= abbrev_number
;
4144 die
->num_attrs
= abbrev
->num_attrs
;
4145 die
->attrs
= (struct attribute
*)
4146 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
4148 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4150 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
4151 abfd
, info_ptr
, cu
);
4155 *has_children
= abbrev
->has_children
;
4159 /* Read an attribute value described by an attribute form. */
4162 read_attribute_value (struct attribute
*attr
, unsigned form
,
4163 bfd
*abfd
, char *info_ptr
,
4164 struct dwarf2_cu
*cu
)
4166 struct comp_unit_head
*cu_header
= &cu
->header
;
4167 unsigned int bytes_read
;
4168 struct dwarf_block
*blk
;
4174 case DW_FORM_ref_addr
:
4175 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
4176 info_ptr
+= bytes_read
;
4178 case DW_FORM_block2
:
4179 blk
= dwarf_alloc_block ();
4180 blk
->size
= read_2_bytes (abfd
, info_ptr
);
4182 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4183 info_ptr
+= blk
->size
;
4184 DW_BLOCK (attr
) = blk
;
4186 case DW_FORM_block4
:
4187 blk
= dwarf_alloc_block ();
4188 blk
->size
= read_4_bytes (abfd
, info_ptr
);
4190 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4191 info_ptr
+= blk
->size
;
4192 DW_BLOCK (attr
) = blk
;
4195 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4199 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4203 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4206 case DW_FORM_string
:
4207 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
4208 info_ptr
+= bytes_read
;
4211 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
4213 info_ptr
+= bytes_read
;
4216 blk
= dwarf_alloc_block ();
4217 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4218 info_ptr
+= bytes_read
;
4219 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4220 info_ptr
+= blk
->size
;
4221 DW_BLOCK (attr
) = blk
;
4223 case DW_FORM_block1
:
4224 blk
= dwarf_alloc_block ();
4225 blk
->size
= read_1_byte (abfd
, info_ptr
);
4227 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4228 info_ptr
+= blk
->size
;
4229 DW_BLOCK (attr
) = blk
;
4232 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4236 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4240 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
4241 info_ptr
+= bytes_read
;
4244 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4245 info_ptr
+= bytes_read
;
4248 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4252 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4256 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4260 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4263 case DW_FORM_ref_udata
:
4264 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4265 info_ptr
+= bytes_read
;
4267 case DW_FORM_indirect
:
4268 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4269 info_ptr
+= bytes_read
;
4270 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
4273 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
4274 dwarf_form_name (form
),
4275 bfd_get_filename (abfd
));
4280 /* Read an attribute described by an abbreviated attribute. */
4283 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
4284 bfd
*abfd
, char *info_ptr
, struct dwarf2_cu
*cu
)
4286 attr
->name
= abbrev
->name
;
4287 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
4290 /* read dwarf information from a buffer */
4293 read_1_byte (bfd
*abfd
, char *buf
)
4295 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4299 read_1_signed_byte (bfd
*abfd
, char *buf
)
4301 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
4305 read_2_bytes (bfd
*abfd
, char *buf
)
4307 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4311 read_2_signed_bytes (bfd
*abfd
, char *buf
)
4313 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4317 read_4_bytes (bfd
*abfd
, char *buf
)
4319 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4323 read_4_signed_bytes (bfd
*abfd
, char *buf
)
4325 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4328 static unsigned long
4329 read_8_bytes (bfd
*abfd
, char *buf
)
4331 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4335 read_address (bfd
*abfd
, char *buf
, struct dwarf2_cu
*cu
, int *bytes_read
)
4337 struct comp_unit_head
*cu_header
= &cu
->header
;
4338 CORE_ADDR retval
= 0;
4340 if (cu_header
->signed_addr_p
)
4342 switch (cu_header
->addr_size
)
4345 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4348 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4351 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
4354 internal_error (__FILE__
, __LINE__
,
4355 "read_address: bad switch, signed [in module %s]",
4356 bfd_get_filename (abfd
));
4361 switch (cu_header
->addr_size
)
4364 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4367 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4370 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4373 internal_error (__FILE__
, __LINE__
,
4374 "read_address: bad switch, unsigned [in module %s]",
4375 bfd_get_filename (abfd
));
4379 *bytes_read
= cu_header
->addr_size
;
4383 /* Read the initial length from a section. The (draft) DWARF 3
4384 specification allows the initial length to take up either 4 bytes
4385 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
4386 bytes describe the length and all offsets will be 8 bytes in length
4389 An older, non-standard 64-bit format is also handled by this
4390 function. The older format in question stores the initial length
4391 as an 8-byte quantity without an escape value. Lengths greater
4392 than 2^32 aren't very common which means that the initial 4 bytes
4393 is almost always zero. Since a length value of zero doesn't make
4394 sense for the 32-bit format, this initial zero can be considered to
4395 be an escape value which indicates the presence of the older 64-bit
4396 format. As written, the code can't detect (old format) lengths
4397 greater than 4GB. If it becomes necessary to handle lengths somewhat
4398 larger than 4GB, we could allow other small values (such as the
4399 non-sensical values of 1, 2, and 3) to also be used as escape values
4400 indicating the presence of the old format.
4402 The value returned via bytes_read should be used to increment
4403 the relevant pointer after calling read_initial_length().
4405 As a side effect, this function sets the fields initial_length_size
4406 and offset_size in cu_header to the values appropriate for the
4407 length field. (The format of the initial length field determines
4408 the width of file offsets to be fetched later with fetch_offset().)
4410 [ Note: read_initial_length() and read_offset() are based on the
4411 document entitled "DWARF Debugging Information Format", revision
4412 3, draft 8, dated November 19, 2001. This document was obtained
4415 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
4417 This document is only a draft and is subject to change. (So beware.)
4419 Details regarding the older, non-standard 64-bit format were
4420 determined empirically by examining 64-bit ELF files produced
4421 by the SGI toolchain on an IRIX 6.5 machine.
4423 - Kevin, July 16, 2002
4427 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
4432 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4434 if (retval
== 0xffffffff)
4436 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
4438 if (cu_header
!= NULL
)
4440 cu_header
->initial_length_size
= 12;
4441 cu_header
->offset_size
= 8;
4444 else if (retval
== 0)
4446 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
4448 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4450 if (cu_header
!= NULL
)
4452 cu_header
->initial_length_size
= 8;
4453 cu_header
->offset_size
= 8;
4459 if (cu_header
!= NULL
)
4461 cu_header
->initial_length_size
= 4;
4462 cu_header
->offset_size
= 4;
4469 /* Read an offset from the data stream. The size of the offset is
4470 given by cu_header->offset_size. */
4473 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
4478 switch (cu_header
->offset_size
)
4481 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4485 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4489 internal_error (__FILE__
, __LINE__
,
4490 "read_offset: bad switch [in module %s]",
4491 bfd_get_filename (abfd
));
4498 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
4500 /* If the size of a host char is 8 bits, we can return a pointer
4501 to the buffer, otherwise we have to copy the data to a buffer
4502 allocated on the temporary obstack. */
4503 gdb_assert (HOST_CHAR_BIT
== 8);
4508 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4510 /* If the size of a host char is 8 bits, we can return a pointer
4511 to the string, otherwise we have to copy the string to a buffer
4512 allocated on the temporary obstack. */
4513 gdb_assert (HOST_CHAR_BIT
== 8);
4516 *bytes_read_ptr
= 1;
4519 *bytes_read_ptr
= strlen (buf
) + 1;
4524 read_indirect_string (bfd
*abfd
, char *buf
,
4525 const struct comp_unit_head
*cu_header
,
4526 unsigned int *bytes_read_ptr
)
4528 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
4529 (int *) bytes_read_ptr
);
4531 if (dwarf_str_buffer
== NULL
)
4533 error ("DW_FORM_strp used without .debug_str section [in module %s]",
4534 bfd_get_filename (abfd
));
4537 if (str_offset
>= dwarf_str_size
)
4539 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
4540 bfd_get_filename (abfd
));
4543 gdb_assert (HOST_CHAR_BIT
== 8);
4544 if (dwarf_str_buffer
[str_offset
] == '\0')
4546 return dwarf_str_buffer
+ str_offset
;
4549 static unsigned long
4550 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4552 unsigned long result
;
4553 unsigned int num_read
;
4563 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4566 result
|= ((unsigned long)(byte
& 127) << shift
);
4567 if ((byte
& 128) == 0)
4573 *bytes_read_ptr
= num_read
;
4578 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4581 int i
, shift
, size
, num_read
;
4591 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4594 result
|= ((long)(byte
& 127) << shift
);
4596 if ((byte
& 128) == 0)
4601 if ((shift
< size
) && (byte
& 0x40))
4603 result
|= -(1 << shift
);
4605 *bytes_read_ptr
= num_read
;
4610 set_cu_language (unsigned int lang
)
4616 cu_language
= language_c
;
4618 case DW_LANG_C_plus_plus
:
4619 cu_language
= language_cplus
;
4621 case DW_LANG_Fortran77
:
4622 case DW_LANG_Fortran90
:
4623 case DW_LANG_Fortran95
:
4624 cu_language
= language_fortran
;
4626 case DW_LANG_Mips_Assembler
:
4627 cu_language
= language_asm
;
4630 cu_language
= language_java
;
4634 case DW_LANG_Cobol74
:
4635 case DW_LANG_Cobol85
:
4636 case DW_LANG_Pascal83
:
4637 case DW_LANG_Modula2
:
4639 cu_language
= language_minimal
;
4642 cu_language_defn
= language_def (cu_language
);
4645 /* Return the named attribute or NULL if not there. */
4647 static struct attribute
*
4648 dwarf_attr (struct die_info
*die
, unsigned int name
)
4651 struct attribute
*spec
= NULL
;
4653 for (i
= 0; i
< die
->num_attrs
; ++i
)
4655 if (die
->attrs
[i
].name
== name
)
4657 return &die
->attrs
[i
];
4659 if (die
->attrs
[i
].name
== DW_AT_specification
4660 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
4661 spec
= &die
->attrs
[i
];
4665 struct die_info
*ref_die
=
4666 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
4669 return dwarf_attr (ref_die
, name
);
4676 die_is_declaration (struct die_info
*die
)
4678 return (dwarf_attr (die
, DW_AT_declaration
)
4679 && ! dwarf_attr (die
, DW_AT_specification
));
4683 /* Free the line_header structure *LH, and any arrays and strings it
4686 free_line_header (struct line_header
*lh
)
4688 if (lh
->standard_opcode_lengths
)
4689 xfree (lh
->standard_opcode_lengths
);
4691 /* Remember that all the lh->file_names[i].name pointers are
4692 pointers into debug_line_buffer, and don't need to be freed. */
4694 xfree (lh
->file_names
);
4696 /* Similarly for the include directory names. */
4697 if (lh
->include_dirs
)
4698 xfree (lh
->include_dirs
);
4704 /* Add an entry to LH's include directory table. */
4706 add_include_dir (struct line_header
*lh
, char *include_dir
)
4708 /* Grow the array if necessary. */
4709 if (lh
->include_dirs_size
== 0)
4711 lh
->include_dirs_size
= 1; /* for testing */
4712 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
4713 * sizeof (*lh
->include_dirs
));
4715 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
4717 lh
->include_dirs_size
*= 2;
4718 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
4719 (lh
->include_dirs_size
4720 * sizeof (*lh
->include_dirs
)));
4723 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
4727 /* Add an entry to LH's file name table. */
4729 add_file_name (struct line_header
*lh
,
4731 unsigned int dir_index
,
4732 unsigned int mod_time
,
4733 unsigned int length
)
4735 struct file_entry
*fe
;
4737 /* Grow the array if necessary. */
4738 if (lh
->file_names_size
== 0)
4740 lh
->file_names_size
= 1; /* for testing */
4741 lh
->file_names
= xmalloc (lh
->file_names_size
4742 * sizeof (*lh
->file_names
));
4744 else if (lh
->num_file_names
>= lh
->file_names_size
)
4746 lh
->file_names_size
*= 2;
4747 lh
->file_names
= xrealloc (lh
->file_names
,
4748 (lh
->file_names_size
4749 * sizeof (*lh
->file_names
)));
4752 fe
= &lh
->file_names
[lh
->num_file_names
++];
4754 fe
->dir_index
= dir_index
;
4755 fe
->mod_time
= mod_time
;
4756 fe
->length
= length
;
4760 /* Read the statement program header starting at OFFSET in
4761 dwarf_line_buffer, according to the endianness of ABFD. Return a
4762 pointer to a struct line_header, allocated using xmalloc.
4764 NOTE: the strings in the include directory and file name tables of
4765 the returned object point into debug_line_buffer, and must not be
4767 static struct line_header
*
4768 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
4769 struct dwarf2_cu
*cu
)
4771 struct cleanup
*back_to
;
4772 struct line_header
*lh
;
4776 char *cur_dir
, *cur_file
;
4778 if (dwarf_line_buffer
== NULL
)
4780 complaint (&symfile_complaints
, "missing .debug_line section");
4784 /* Make sure that at least there's room for the total_length field. That
4785 could be 12 bytes long, but we're just going to fudge that. */
4786 if (offset
+ 4 >= dwarf_line_size
)
4788 dwarf2_statement_list_fits_in_line_number_section_complaint ();
4792 lh
= xmalloc (sizeof (*lh
));
4793 memset (lh
, 0, sizeof (*lh
));
4794 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
4797 line_ptr
= dwarf_line_buffer
+ offset
;
4799 /* read in the header */
4800 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
4801 line_ptr
+= bytes_read
;
4802 if (line_ptr
+ lh
->total_length
> dwarf_line_buffer
+ dwarf_line_size
)
4804 dwarf2_statement_list_fits_in_line_number_section_complaint ();
4807 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
4808 lh
->version
= read_2_bytes (abfd
, line_ptr
);
4810 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
4811 line_ptr
+= bytes_read
;
4812 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
4814 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
4816 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
4818 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
4820 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
4822 lh
->standard_opcode_lengths
4823 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
4825 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
4826 for (i
= 1; i
< lh
->opcode_base
; ++i
)
4828 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
4832 /* Read directory table */
4833 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4835 line_ptr
+= bytes_read
;
4836 add_include_dir (lh
, cur_dir
);
4838 line_ptr
+= bytes_read
;
4840 /* Read file name table */
4841 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4843 unsigned int dir_index
, mod_time
, length
;
4845 line_ptr
+= bytes_read
;
4846 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4847 line_ptr
+= bytes_read
;
4848 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4849 line_ptr
+= bytes_read
;
4850 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4851 line_ptr
+= bytes_read
;
4853 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4855 line_ptr
+= bytes_read
;
4856 lh
->statement_program_start
= line_ptr
;
4858 if (line_ptr
> dwarf_line_buffer
+ dwarf_line_size
)
4859 complaint (&symfile_complaints
,
4860 "line number info header doesn't fit in `.debug_line' section");
4862 discard_cleanups (back_to
);
4866 /* This function exists to work around a bug in certain compilers
4867 (particularly GCC 2.95), in which the first line number marker of a
4868 function does not show up until after the prologue, right before
4869 the second line number marker. This function shifts ADDRESS down
4870 to the beginning of the function if necessary, and is called on
4871 addresses passed to record_line. */
4874 check_cu_functions (CORE_ADDR address
)
4876 struct function_range
*fn
;
4878 /* Find the function_range containing address. */
4883 cu_cached_fn
= cu_first_fn
;
4887 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4893 while (fn
&& fn
!= cu_cached_fn
)
4894 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4904 if (address
!= fn
->lowpc
)
4905 complaint (&symfile_complaints
,
4906 "misplaced first line number at 0x%lx for '%s'",
4907 (unsigned long) address
, fn
->name
);
4912 /* Decode the line number information for the compilation unit whose
4913 line number info is at OFFSET in the .debug_line section.
4914 The compilation directory of the file is passed in COMP_DIR. */
4917 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
4918 struct dwarf2_cu
*cu
)
4922 unsigned int bytes_read
;
4923 unsigned char op_code
, extended_op
, adj_opcode
;
4925 line_ptr
= lh
->statement_program_start
;
4926 line_end
= lh
->statement_program_end
;
4928 /* Read the statement sequences until there's nothing left. */
4929 while (line_ptr
< line_end
)
4931 /* state machine registers */
4932 CORE_ADDR address
= 0;
4933 unsigned int file
= 1;
4934 unsigned int line
= 1;
4935 unsigned int column
= 0;
4936 int is_stmt
= lh
->default_is_stmt
;
4937 int basic_block
= 0;
4938 int end_sequence
= 0;
4940 /* Start a subfile for the current file of the state machine. */
4941 if (lh
->num_file_names
>= file
)
4943 /* lh->include_dirs and lh->file_names are 0-based, but the
4944 directory and file name numbers in the statement program
4946 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
4949 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
4952 dwarf2_start_subfile (fe
->name
, dir
);
4955 /* Decode the table. */
4956 while (!end_sequence
)
4958 op_code
= read_1_byte (abfd
, line_ptr
);
4961 if (op_code
>= lh
->opcode_base
)
4962 { /* Special operand. */
4963 adj_opcode
= op_code
- lh
->opcode_base
;
4964 address
+= (adj_opcode
/ lh
->line_range
)
4965 * lh
->minimum_instruction_length
;
4966 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
4967 /* append row to matrix using current values */
4968 record_line (current_subfile
, line
,
4969 check_cu_functions (address
));
4972 else switch (op_code
)
4974 case DW_LNS_extended_op
:
4975 line_ptr
+= 1; /* ignore length */
4976 extended_op
= read_1_byte (abfd
, line_ptr
);
4978 switch (extended_op
)
4980 case DW_LNE_end_sequence
:
4982 record_line (current_subfile
, 0, address
);
4984 case DW_LNE_set_address
:
4985 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
4986 line_ptr
+= bytes_read
;
4987 address
+= baseaddr
;
4989 case DW_LNE_define_file
:
4992 unsigned int dir_index
, mod_time
, length
;
4994 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
4995 line_ptr
+= bytes_read
;
4997 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4998 line_ptr
+= bytes_read
;
5000 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5001 line_ptr
+= bytes_read
;
5003 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5004 line_ptr
+= bytes_read
;
5005 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
5009 complaint (&symfile_complaints
,
5010 "mangled .debug_line section");
5015 record_line (current_subfile
, line
,
5016 check_cu_functions (address
));
5019 case DW_LNS_advance_pc
:
5020 address
+= lh
->minimum_instruction_length
5021 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5022 line_ptr
+= bytes_read
;
5024 case DW_LNS_advance_line
:
5025 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
5026 line_ptr
+= bytes_read
;
5028 case DW_LNS_set_file
:
5030 /* lh->include_dirs and lh->file_names are 0-based,
5031 but the directory and file name numbers in the
5032 statement program are 1-based. */
5033 struct file_entry
*fe
;
5035 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5036 line_ptr
+= bytes_read
;
5037 fe
= &lh
->file_names
[file
- 1];
5039 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
5042 dwarf2_start_subfile (fe
->name
, dir
);
5045 case DW_LNS_set_column
:
5046 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5047 line_ptr
+= bytes_read
;
5049 case DW_LNS_negate_stmt
:
5050 is_stmt
= (!is_stmt
);
5052 case DW_LNS_set_basic_block
:
5055 /* Add to the address register of the state machine the
5056 address increment value corresponding to special opcode
5057 255. Ie, this value is scaled by the minimum instruction
5058 length since special opcode 255 would have scaled the
5060 case DW_LNS_const_add_pc
:
5061 address
+= (lh
->minimum_instruction_length
5062 * ((255 - lh
->opcode_base
) / lh
->line_range
));
5064 case DW_LNS_fixed_advance_pc
:
5065 address
+= read_2_bytes (abfd
, line_ptr
);
5069 { /* Unknown standard opcode, ignore it. */
5071 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
5073 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5074 line_ptr
+= bytes_read
;
5082 /* Start a subfile for DWARF. FILENAME is the name of the file and
5083 DIRNAME the name of the source directory which contains FILENAME
5084 or NULL if not known.
5085 This routine tries to keep line numbers from identical absolute and
5086 relative file names in a common subfile.
5088 Using the `list' example from the GDB testsuite, which resides in
5089 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
5090 of /srcdir/list0.c yields the following debugging information for list0.c:
5092 DW_AT_name: /srcdir/list0.c
5093 DW_AT_comp_dir: /compdir
5094 files.files[0].name: list0.h
5095 files.files[0].dir: /srcdir
5096 files.files[1].name: list0.c
5097 files.files[1].dir: /srcdir
5099 The line number information for list0.c has to end up in a single
5100 subfile, so that `break /srcdir/list0.c:1' works as expected. */
5103 dwarf2_start_subfile (char *filename
, char *dirname
)
5105 /* If the filename isn't absolute, try to match an existing subfile
5106 with the full pathname. */
5108 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
5110 struct subfile
*subfile
;
5111 char *fullname
= concat (dirname
, "/", filename
, NULL
);
5113 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
5115 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
5117 current_subfile
= subfile
;
5124 start_subfile (filename
, dirname
);
5128 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
5129 struct dwarf2_cu
*cu
)
5131 struct objfile
*objfile
= cu
->objfile
;
5132 struct comp_unit_head
*cu_header
= &cu
->header
;
5134 /* NOTE drow/2003-01-30: There used to be a comment and some special
5135 code here to turn a symbol with DW_AT_external and a
5136 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
5137 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
5138 with some versions of binutils) where shared libraries could have
5139 relocations against symbols in their debug information - the
5140 minimal symbol would have the right address, but the debug info
5141 would not. It's no longer necessary, because we will explicitly
5142 apply relocations when we read in the debug information now. */
5144 /* A DW_AT_location attribute with no contents indicates that a
5145 variable has been optimized away. */
5146 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
5148 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
5152 /* Handle one degenerate form of location expression specially, to
5153 preserve GDB's previous behavior when section offsets are
5154 specified. If this is just a DW_OP_addr then mark this symbol
5157 if (attr_form_is_block (attr
)
5158 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
5159 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
5163 SYMBOL_VALUE_ADDRESS (sym
) =
5164 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
5165 fixup_symbol_section (sym
, objfile
);
5166 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
5167 SYMBOL_SECTION (sym
));
5168 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5172 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
5173 expression evaluator, and use LOC_COMPUTED only when necessary
5174 (i.e. when the value of a register or memory location is
5175 referenced, or a thread-local block, etc.). Then again, it might
5176 not be worthwhile. I'm assuming that it isn't unless performance
5177 or memory numbers show me otherwise. */
5179 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
5180 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
5183 /* Given a pointer to a DWARF information entry, figure out if we need
5184 to make a symbol table entry for it, and if so, create a new entry
5185 and return a pointer to it.
5186 If TYPE is NULL, determine symbol type from the die, otherwise
5187 used the passed type. */
5189 static struct symbol
*
5190 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
5192 struct objfile
*objfile
= cu
->objfile
;
5193 struct symbol
*sym
= NULL
;
5195 struct attribute
*attr
= NULL
;
5196 struct attribute
*attr2
= NULL
;
5198 if (die
->tag
!= DW_TAG_namespace
)
5199 name
= dwarf2_linkage_name (die
);
5201 name
= TYPE_NAME (type
);
5205 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
5206 sizeof (struct symbol
));
5207 OBJSTAT (objfile
, n_syms
++);
5208 memset (sym
, 0, sizeof (struct symbol
));
5210 /* Cache this symbol's name and the name's demangled form (if any). */
5211 SYMBOL_LANGUAGE (sym
) = cu_language
;
5212 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
5214 /* Default assumptions.
5215 Use the passed type or decode it from the die. */
5216 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5217 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5219 SYMBOL_TYPE (sym
) = type
;
5221 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
5222 attr
= dwarf_attr (die
, DW_AT_decl_line
);
5225 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
5230 attr
= dwarf_attr (die
, DW_AT_low_pc
);
5233 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
5235 SYMBOL_CLASS (sym
) = LOC_LABEL
;
5237 case DW_TAG_subprogram
:
5238 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
5240 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
5241 attr2
= dwarf_attr (die
, DW_AT_external
);
5242 if (attr2
&& (DW_UNSND (attr2
) != 0))
5244 add_symbol_to_list (sym
, &global_symbols
);
5248 add_symbol_to_list (sym
, list_in_scope
);
5251 case DW_TAG_variable
:
5252 /* Compilation with minimal debug info may result in variables
5253 with missing type entries. Change the misleading `void' type
5254 to something sensible. */
5255 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
5256 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
5257 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
5258 "<variable, no debug info>",
5260 attr
= dwarf_attr (die
, DW_AT_const_value
);
5263 dwarf2_const_value (attr
, sym
, cu
);
5264 attr2
= dwarf_attr (die
, DW_AT_external
);
5265 if (attr2
&& (DW_UNSND (attr2
) != 0))
5266 add_symbol_to_list (sym
, &global_symbols
);
5268 add_symbol_to_list (sym
, list_in_scope
);
5271 attr
= dwarf_attr (die
, DW_AT_location
);
5274 var_decode_location (attr
, sym
, cu
);
5275 attr2
= dwarf_attr (die
, DW_AT_external
);
5276 if (attr2
&& (DW_UNSND (attr2
) != 0))
5277 add_symbol_to_list (sym
, &global_symbols
);
5279 add_symbol_to_list (sym
, list_in_scope
);
5283 /* We do not know the address of this symbol.
5284 If it is an external symbol and we have type information
5285 for it, enter the symbol as a LOC_UNRESOLVED symbol.
5286 The address of the variable will then be determined from
5287 the minimal symbol table whenever the variable is
5289 attr2
= dwarf_attr (die
, DW_AT_external
);
5290 if (attr2
&& (DW_UNSND (attr2
) != 0)
5291 && dwarf_attr (die
, DW_AT_type
) != NULL
)
5293 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
5294 add_symbol_to_list (sym
, &global_symbols
);
5298 case DW_TAG_formal_parameter
:
5299 attr
= dwarf_attr (die
, DW_AT_location
);
5302 var_decode_location (attr
, sym
, cu
);
5303 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
5304 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
5305 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
5307 attr
= dwarf_attr (die
, DW_AT_const_value
);
5310 dwarf2_const_value (attr
, sym
, cu
);
5312 add_symbol_to_list (sym
, list_in_scope
);
5314 case DW_TAG_unspecified_parameters
:
5315 /* From varargs functions; gdb doesn't seem to have any
5316 interest in this information, so just ignore it for now.
5319 case DW_TAG_class_type
:
5320 case DW_TAG_structure_type
:
5321 case DW_TAG_union_type
:
5322 case DW_TAG_enumeration_type
:
5323 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5324 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
5325 add_symbol_to_list (sym
, list_in_scope
);
5327 /* The semantics of C++ state that "struct foo { ... }" also
5328 defines a typedef for "foo". Synthesize a typedef symbol so
5329 that "ptype foo" works as expected. */
5330 if (cu_language
== language_cplus
)
5332 struct symbol
*typedef_sym
= (struct symbol
*)
5333 obstack_alloc (&objfile
->symbol_obstack
,
5334 sizeof (struct symbol
));
5335 *typedef_sym
= *sym
;
5336 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
5337 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
5338 TYPE_NAME (SYMBOL_TYPE (sym
)) =
5339 obsavestring (DEPRECATED_SYMBOL_NAME (sym
),
5340 strlen (DEPRECATED_SYMBOL_NAME (sym
)),
5341 &objfile
->type_obstack
);
5342 add_symbol_to_list (typedef_sym
, list_in_scope
);
5345 case DW_TAG_typedef
:
5346 case DW_TAG_base_type
:
5347 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5348 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5349 add_symbol_to_list (sym
, list_in_scope
);
5351 case DW_TAG_enumerator
:
5352 attr
= dwarf_attr (die
, DW_AT_const_value
);
5355 dwarf2_const_value (attr
, sym
, cu
);
5357 add_symbol_to_list (sym
, list_in_scope
);
5359 case DW_TAG_namespace
:
5360 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5361 add_symbol_to_list (sym
, &global_symbols
);
5364 /* Not a tag we recognize. Hopefully we aren't processing
5365 trash data, but since we must specifically ignore things
5366 we don't recognize, there is nothing else we should do at
5368 complaint (&symfile_complaints
, "unsupported tag: '%s'",
5369 dwarf_tag_name (die
->tag
));
5376 /* Copy constant value from an attribute to a symbol. */
5379 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
5380 struct dwarf2_cu
*cu
)
5382 struct objfile
*objfile
= cu
->objfile
;
5383 struct comp_unit_head
*cu_header
= &cu
->header
;
5384 struct dwarf_block
*blk
;
5389 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
5390 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5391 cu_header
->addr_size
,
5392 TYPE_LENGTH (SYMBOL_TYPE
5394 SYMBOL_VALUE_BYTES (sym
) = (char *)
5395 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
5396 /* NOTE: cagney/2003-05-09: In-lined store_address call with
5397 it's body - store_unsigned_integer. */
5398 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
5400 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5402 case DW_FORM_block1
:
5403 case DW_FORM_block2
:
5404 case DW_FORM_block4
:
5406 blk
= DW_BLOCK (attr
);
5407 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
5408 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5410 TYPE_LENGTH (SYMBOL_TYPE
5412 SYMBOL_VALUE_BYTES (sym
) = (char *)
5413 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
5414 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
5415 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5418 /* The DW_AT_const_value attributes are supposed to carry the
5419 symbol's value "represented as it would be on the target
5420 architecture." By the time we get here, it's already been
5421 converted to host endianness, so we just need to sign- or
5422 zero-extend it as appropriate. */
5424 dwarf2_const_value_data (attr
, sym
, 8);
5427 dwarf2_const_value_data (attr
, sym
, 16);
5430 dwarf2_const_value_data (attr
, sym
, 32);
5433 dwarf2_const_value_data (attr
, sym
, 64);
5437 SYMBOL_VALUE (sym
) = DW_SND (attr
);
5438 SYMBOL_CLASS (sym
) = LOC_CONST
;
5442 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
5443 SYMBOL_CLASS (sym
) = LOC_CONST
;
5447 complaint (&symfile_complaints
,
5448 "unsupported const value attribute form: '%s'",
5449 dwarf_form_name (attr
->form
));
5450 SYMBOL_VALUE (sym
) = 0;
5451 SYMBOL_CLASS (sym
) = LOC_CONST
;
5457 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
5458 or zero-extend it as appropriate for the symbol's type. */
5460 dwarf2_const_value_data (struct attribute
*attr
,
5464 LONGEST l
= DW_UNSND (attr
);
5466 if (bits
< sizeof (l
) * 8)
5468 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
5469 l
&= ((LONGEST
) 1 << bits
) - 1;
5471 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
5474 SYMBOL_VALUE (sym
) = l
;
5475 SYMBOL_CLASS (sym
) = LOC_CONST
;
5479 /* Return the type of the die in question using its DW_AT_type attribute. */
5481 static struct type
*
5482 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5485 struct attribute
*type_attr
;
5486 struct die_info
*type_die
;
5489 type_attr
= dwarf_attr (die
, DW_AT_type
);
5492 /* A missing DW_AT_type represents a void type. */
5493 return dwarf2_fundamental_type (cu
->objfile
, FT_VOID
);
5497 ref
= dwarf2_get_ref_die_offset (type_attr
);
5498 type_die
= follow_die_ref (ref
);
5501 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
5502 ref
, cu
->objfile
->name
);
5506 type
= tag_type_to_type (type_die
, cu
);
5509 dump_die (type_die
);
5510 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
5516 /* Return the containing type of the die in question using its
5517 DW_AT_containing_type attribute. */
5519 static struct type
*
5520 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5522 struct type
*type
= NULL
;
5523 struct attribute
*type_attr
;
5524 struct die_info
*type_die
= NULL
;
5527 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
5530 ref
= dwarf2_get_ref_die_offset (type_attr
);
5531 type_die
= follow_die_ref (ref
);
5534 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref
,
5538 type
= tag_type_to_type (type_die
, cu
);
5543 dump_die (type_die
);
5544 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
5551 static struct type
*
5552 type_at_offset (unsigned int offset
, struct dwarf2_cu
*cu
)
5554 struct die_info
*die
;
5557 die
= follow_die_ref (offset
);
5560 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
5563 type
= tag_type_to_type (die
, cu
);
5568 static struct type
*
5569 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5577 read_type_die (die
, cu
);
5581 error ("Dwarf Error: Cannot find type of die [in module %s]",
5589 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
5593 case DW_TAG_class_type
:
5594 case DW_TAG_structure_type
:
5595 case DW_TAG_union_type
:
5596 read_structure_scope (die
, cu
);
5598 case DW_TAG_enumeration_type
:
5599 read_enumeration (die
, cu
);
5601 case DW_TAG_subprogram
:
5602 case DW_TAG_subroutine_type
:
5603 read_subroutine_type (die
, cu
);
5605 case DW_TAG_array_type
:
5606 read_array_type (die
, cu
);
5608 case DW_TAG_pointer_type
:
5609 read_tag_pointer_type (die
, cu
);
5611 case DW_TAG_ptr_to_member_type
:
5612 read_tag_ptr_to_member_type (die
, cu
);
5614 case DW_TAG_reference_type
:
5615 read_tag_reference_type (die
, cu
);
5617 case DW_TAG_const_type
:
5618 read_tag_const_type (die
, cu
);
5620 case DW_TAG_volatile_type
:
5621 read_tag_volatile_type (die
, cu
);
5623 case DW_TAG_string_type
:
5624 read_tag_string_type (die
, cu
);
5626 case DW_TAG_typedef
:
5627 read_typedef (die
, cu
);
5629 case DW_TAG_base_type
:
5630 read_base_type (die
, cu
);
5633 complaint (&symfile_complaints
, "unexepected tag in read_type_die: '%s'",
5634 dwarf_tag_name (die
->tag
));
5639 static struct type
*
5640 dwarf_base_type (int encoding
, int size
, struct dwarf2_cu
*cu
)
5642 struct objfile
*objfile
= cu
->objfile
;
5644 /* FIXME - this should not produce a new (struct type *)
5645 every time. It should cache base types. */
5649 case DW_ATE_address
:
5650 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
5652 case DW_ATE_boolean
:
5653 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
5655 case DW_ATE_complex_float
:
5658 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
5662 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
5668 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
5672 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
5679 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5682 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
5686 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5690 case DW_ATE_signed_char
:
5691 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5693 case DW_ATE_unsigned
:
5697 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5700 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
5704 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
5708 case DW_ATE_unsigned_char
:
5709 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5712 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5719 copy_die (struct die_info
*old_die
)
5721 struct die_info
*new_die
;
5724 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5725 memset (new_die
, 0, sizeof (struct die_info
));
5727 new_die
->tag
= old_die
->tag
;
5728 new_die
->has_children
= old_die
->has_children
;
5729 new_die
->abbrev
= old_die
->abbrev
;
5730 new_die
->offset
= old_die
->offset
;
5731 new_die
->type
= NULL
;
5733 num_attrs
= old_die
->num_attrs
;
5734 new_die
->num_attrs
= num_attrs
;
5735 new_die
->attrs
= (struct attribute
*)
5736 xmalloc (num_attrs
* sizeof (struct attribute
));
5738 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
5740 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
5741 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
5742 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
5745 new_die
->next
= NULL
;
5750 /* Return sibling of die, NULL if no sibling. */
5752 static struct die_info
*
5753 sibling_die (struct die_info
*die
)
5755 return die
->sibling
;
5758 /* Get linkage name of a die, return NULL if not found. */
5761 dwarf2_linkage_name (struct die_info
*die
)
5763 struct attribute
*attr
;
5765 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
5766 if (attr
&& DW_STRING (attr
))
5767 return DW_STRING (attr
);
5768 attr
= dwarf_attr (die
, DW_AT_name
);
5769 if (attr
&& DW_STRING (attr
))
5770 return DW_STRING (attr
);
5774 /* Get name of a die, return NULL if not found. */
5777 dwarf2_name (struct die_info
*die
)
5779 struct attribute
*attr
;
5781 attr
= dwarf_attr (die
, DW_AT_name
);
5782 if (attr
&& DW_STRING (attr
))
5783 return DW_STRING (attr
);
5787 /* Return the die that this die in an extension of, or NULL if there
5790 static struct die_info
*
5791 dwarf2_extension (struct die_info
*die
)
5793 struct attribute
*attr
;
5794 struct die_info
*extension_die
;
5797 attr
= dwarf_attr (die
, DW_AT_extension
);
5801 ref
= dwarf2_get_ref_die_offset (attr
);
5802 extension_die
= follow_die_ref (ref
);
5805 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
5808 return extension_die
;
5811 /* Convert a DIE tag into its string name. */
5814 dwarf_tag_name (unsigned tag
)
5818 case DW_TAG_padding
:
5819 return "DW_TAG_padding";
5820 case DW_TAG_array_type
:
5821 return "DW_TAG_array_type";
5822 case DW_TAG_class_type
:
5823 return "DW_TAG_class_type";
5824 case DW_TAG_entry_point
:
5825 return "DW_TAG_entry_point";
5826 case DW_TAG_enumeration_type
:
5827 return "DW_TAG_enumeration_type";
5828 case DW_TAG_formal_parameter
:
5829 return "DW_TAG_formal_parameter";
5830 case DW_TAG_imported_declaration
:
5831 return "DW_TAG_imported_declaration";
5833 return "DW_TAG_label";
5834 case DW_TAG_lexical_block
:
5835 return "DW_TAG_lexical_block";
5837 return "DW_TAG_member";
5838 case DW_TAG_pointer_type
:
5839 return "DW_TAG_pointer_type";
5840 case DW_TAG_reference_type
:
5841 return "DW_TAG_reference_type";
5842 case DW_TAG_compile_unit
:
5843 return "DW_TAG_compile_unit";
5844 case DW_TAG_string_type
:
5845 return "DW_TAG_string_type";
5846 case DW_TAG_structure_type
:
5847 return "DW_TAG_structure_type";
5848 case DW_TAG_subroutine_type
:
5849 return "DW_TAG_subroutine_type";
5850 case DW_TAG_typedef
:
5851 return "DW_TAG_typedef";
5852 case DW_TAG_union_type
:
5853 return "DW_TAG_union_type";
5854 case DW_TAG_unspecified_parameters
:
5855 return "DW_TAG_unspecified_parameters";
5856 case DW_TAG_variant
:
5857 return "DW_TAG_variant";
5858 case DW_TAG_common_block
:
5859 return "DW_TAG_common_block";
5860 case DW_TAG_common_inclusion
:
5861 return "DW_TAG_common_inclusion";
5862 case DW_TAG_inheritance
:
5863 return "DW_TAG_inheritance";
5864 case DW_TAG_inlined_subroutine
:
5865 return "DW_TAG_inlined_subroutine";
5867 return "DW_TAG_module";
5868 case DW_TAG_ptr_to_member_type
:
5869 return "DW_TAG_ptr_to_member_type";
5870 case DW_TAG_set_type
:
5871 return "DW_TAG_set_type";
5872 case DW_TAG_subrange_type
:
5873 return "DW_TAG_subrange_type";
5874 case DW_TAG_with_stmt
:
5875 return "DW_TAG_with_stmt";
5876 case DW_TAG_access_declaration
:
5877 return "DW_TAG_access_declaration";
5878 case DW_TAG_base_type
:
5879 return "DW_TAG_base_type";
5880 case DW_TAG_catch_block
:
5881 return "DW_TAG_catch_block";
5882 case DW_TAG_const_type
:
5883 return "DW_TAG_const_type";
5884 case DW_TAG_constant
:
5885 return "DW_TAG_constant";
5886 case DW_TAG_enumerator
:
5887 return "DW_TAG_enumerator";
5888 case DW_TAG_file_type
:
5889 return "DW_TAG_file_type";
5891 return "DW_TAG_friend";
5892 case DW_TAG_namelist
:
5893 return "DW_TAG_namelist";
5894 case DW_TAG_namelist_item
:
5895 return "DW_TAG_namelist_item";
5896 case DW_TAG_packed_type
:
5897 return "DW_TAG_packed_type";
5898 case DW_TAG_subprogram
:
5899 return "DW_TAG_subprogram";
5900 case DW_TAG_template_type_param
:
5901 return "DW_TAG_template_type_param";
5902 case DW_TAG_template_value_param
:
5903 return "DW_TAG_template_value_param";
5904 case DW_TAG_thrown_type
:
5905 return "DW_TAG_thrown_type";
5906 case DW_TAG_try_block
:
5907 return "DW_TAG_try_block";
5908 case DW_TAG_variant_part
:
5909 return "DW_TAG_variant_part";
5910 case DW_TAG_variable
:
5911 return "DW_TAG_variable";
5912 case DW_TAG_volatile_type
:
5913 return "DW_TAG_volatile_type";
5914 case DW_TAG_dwarf_procedure
:
5915 return "DW_TAG_dwarf_procedure";
5916 case DW_TAG_restrict_type
:
5917 return "DW_TAG_restrict_type";
5918 case DW_TAG_interface_type
:
5919 return "DW_TAG_interface_type";
5920 case DW_TAG_namespace
:
5921 return "DW_TAG_namespace";
5922 case DW_TAG_imported_module
:
5923 return "DW_TAG_imported_module";
5924 case DW_TAG_unspecified_type
:
5925 return "DW_TAG_unspecified_type";
5926 case DW_TAG_partial_unit
:
5927 return "DW_TAG_partial_unit";
5928 case DW_TAG_imported_unit
:
5929 return "DW_TAG_imported_unit";
5930 case DW_TAG_MIPS_loop
:
5931 return "DW_TAG_MIPS_loop";
5932 case DW_TAG_format_label
:
5933 return "DW_TAG_format_label";
5934 case DW_TAG_function_template
:
5935 return "DW_TAG_function_template";
5936 case DW_TAG_class_template
:
5937 return "DW_TAG_class_template";
5939 return "DW_TAG_<unknown>";
5943 /* Convert a DWARF attribute code into its string name. */
5946 dwarf_attr_name (unsigned attr
)
5951 return "DW_AT_sibling";
5952 case DW_AT_location
:
5953 return "DW_AT_location";
5955 return "DW_AT_name";
5956 case DW_AT_ordering
:
5957 return "DW_AT_ordering";
5958 case DW_AT_subscr_data
:
5959 return "DW_AT_subscr_data";
5960 case DW_AT_byte_size
:
5961 return "DW_AT_byte_size";
5962 case DW_AT_bit_offset
:
5963 return "DW_AT_bit_offset";
5964 case DW_AT_bit_size
:
5965 return "DW_AT_bit_size";
5966 case DW_AT_element_list
:
5967 return "DW_AT_element_list";
5968 case DW_AT_stmt_list
:
5969 return "DW_AT_stmt_list";
5971 return "DW_AT_low_pc";
5973 return "DW_AT_high_pc";
5974 case DW_AT_language
:
5975 return "DW_AT_language";
5977 return "DW_AT_member";
5979 return "DW_AT_discr";
5980 case DW_AT_discr_value
:
5981 return "DW_AT_discr_value";
5982 case DW_AT_visibility
:
5983 return "DW_AT_visibility";
5985 return "DW_AT_import";
5986 case DW_AT_string_length
:
5987 return "DW_AT_string_length";
5988 case DW_AT_common_reference
:
5989 return "DW_AT_common_reference";
5990 case DW_AT_comp_dir
:
5991 return "DW_AT_comp_dir";
5992 case DW_AT_const_value
:
5993 return "DW_AT_const_value";
5994 case DW_AT_containing_type
:
5995 return "DW_AT_containing_type";
5996 case DW_AT_default_value
:
5997 return "DW_AT_default_value";
5999 return "DW_AT_inline";
6000 case DW_AT_is_optional
:
6001 return "DW_AT_is_optional";
6002 case DW_AT_lower_bound
:
6003 return "DW_AT_lower_bound";
6004 case DW_AT_producer
:
6005 return "DW_AT_producer";
6006 case DW_AT_prototyped
:
6007 return "DW_AT_prototyped";
6008 case DW_AT_return_addr
:
6009 return "DW_AT_return_addr";
6010 case DW_AT_start_scope
:
6011 return "DW_AT_start_scope";
6012 case DW_AT_stride_size
:
6013 return "DW_AT_stride_size";
6014 case DW_AT_upper_bound
:
6015 return "DW_AT_upper_bound";
6016 case DW_AT_abstract_origin
:
6017 return "DW_AT_abstract_origin";
6018 case DW_AT_accessibility
:
6019 return "DW_AT_accessibility";
6020 case DW_AT_address_class
:
6021 return "DW_AT_address_class";
6022 case DW_AT_artificial
:
6023 return "DW_AT_artificial";
6024 case DW_AT_base_types
:
6025 return "DW_AT_base_types";
6026 case DW_AT_calling_convention
:
6027 return "DW_AT_calling_convention";
6029 return "DW_AT_count";
6030 case DW_AT_data_member_location
:
6031 return "DW_AT_data_member_location";
6032 case DW_AT_decl_column
:
6033 return "DW_AT_decl_column";
6034 case DW_AT_decl_file
:
6035 return "DW_AT_decl_file";
6036 case DW_AT_decl_line
:
6037 return "DW_AT_decl_line";
6038 case DW_AT_declaration
:
6039 return "DW_AT_declaration";
6040 case DW_AT_discr_list
:
6041 return "DW_AT_discr_list";
6042 case DW_AT_encoding
:
6043 return "DW_AT_encoding";
6044 case DW_AT_external
:
6045 return "DW_AT_external";
6046 case DW_AT_frame_base
:
6047 return "DW_AT_frame_base";
6049 return "DW_AT_friend";
6050 case DW_AT_identifier_case
:
6051 return "DW_AT_identifier_case";
6052 case DW_AT_macro_info
:
6053 return "DW_AT_macro_info";
6054 case DW_AT_namelist_items
:
6055 return "DW_AT_namelist_items";
6056 case DW_AT_priority
:
6057 return "DW_AT_priority";
6059 return "DW_AT_segment";
6060 case DW_AT_specification
:
6061 return "DW_AT_specification";
6062 case DW_AT_static_link
:
6063 return "DW_AT_static_link";
6065 return "DW_AT_type";
6066 case DW_AT_use_location
:
6067 return "DW_AT_use_location";
6068 case DW_AT_variable_parameter
:
6069 return "DW_AT_variable_parameter";
6070 case DW_AT_virtuality
:
6071 return "DW_AT_virtuality";
6072 case DW_AT_vtable_elem_location
:
6073 return "DW_AT_vtable_elem_location";
6074 case DW_AT_allocated
:
6075 return "DW_AT_allocated";
6076 case DW_AT_associated
:
6077 return "DW_AT_associated";
6078 case DW_AT_data_location
:
6079 return "DW_AT_data_location";
6081 return "DW_AT_stride";
6082 case DW_AT_entry_pc
:
6083 return "DW_AT_entry_pc";
6084 case DW_AT_use_UTF8
:
6085 return "DW_AT_use_UTF8";
6086 case DW_AT_extension
:
6087 return "DW_AT_extension";
6089 return "DW_AT_ranges";
6090 case DW_AT_trampoline
:
6091 return "DW_AT_trampoline";
6092 case DW_AT_call_column
:
6093 return "DW_AT_call_column";
6094 case DW_AT_call_file
:
6095 return "DW_AT_call_file";
6096 case DW_AT_call_line
:
6097 return "DW_AT_call_line";
6099 case DW_AT_MIPS_fde
:
6100 return "DW_AT_MIPS_fde";
6101 case DW_AT_MIPS_loop_begin
:
6102 return "DW_AT_MIPS_loop_begin";
6103 case DW_AT_MIPS_tail_loop_begin
:
6104 return "DW_AT_MIPS_tail_loop_begin";
6105 case DW_AT_MIPS_epilog_begin
:
6106 return "DW_AT_MIPS_epilog_begin";
6107 case DW_AT_MIPS_loop_unroll_factor
:
6108 return "DW_AT_MIPS_loop_unroll_factor";
6109 case DW_AT_MIPS_software_pipeline_depth
:
6110 return "DW_AT_MIPS_software_pipeline_depth";
6112 case DW_AT_MIPS_linkage_name
:
6113 return "DW_AT_MIPS_linkage_name";
6115 case DW_AT_sf_names
:
6116 return "DW_AT_sf_names";
6117 case DW_AT_src_info
:
6118 return "DW_AT_src_info";
6119 case DW_AT_mac_info
:
6120 return "DW_AT_mac_info";
6121 case DW_AT_src_coords
:
6122 return "DW_AT_src_coords";
6123 case DW_AT_body_begin
:
6124 return "DW_AT_body_begin";
6125 case DW_AT_body_end
:
6126 return "DW_AT_body_end";
6127 case DW_AT_GNU_vector
:
6128 return "DW_AT_GNU_vector";
6130 return "DW_AT_<unknown>";
6134 /* Convert a DWARF value form code into its string name. */
6137 dwarf_form_name (unsigned form
)
6142 return "DW_FORM_addr";
6143 case DW_FORM_block2
:
6144 return "DW_FORM_block2";
6145 case DW_FORM_block4
:
6146 return "DW_FORM_block4";
6148 return "DW_FORM_data2";
6150 return "DW_FORM_data4";
6152 return "DW_FORM_data8";
6153 case DW_FORM_string
:
6154 return "DW_FORM_string";
6156 return "DW_FORM_block";
6157 case DW_FORM_block1
:
6158 return "DW_FORM_block1";
6160 return "DW_FORM_data1";
6162 return "DW_FORM_flag";
6164 return "DW_FORM_sdata";
6166 return "DW_FORM_strp";
6168 return "DW_FORM_udata";
6169 case DW_FORM_ref_addr
:
6170 return "DW_FORM_ref_addr";
6172 return "DW_FORM_ref1";
6174 return "DW_FORM_ref2";
6176 return "DW_FORM_ref4";
6178 return "DW_FORM_ref8";
6179 case DW_FORM_ref_udata
:
6180 return "DW_FORM_ref_udata";
6181 case DW_FORM_indirect
:
6182 return "DW_FORM_indirect";
6184 return "DW_FORM_<unknown>";
6188 /* Convert a DWARF stack opcode into its string name. */
6191 dwarf_stack_op_name (unsigned op
)
6196 return "DW_OP_addr";
6198 return "DW_OP_deref";
6200 return "DW_OP_const1u";
6202 return "DW_OP_const1s";
6204 return "DW_OP_const2u";
6206 return "DW_OP_const2s";
6208 return "DW_OP_const4u";
6210 return "DW_OP_const4s";
6212 return "DW_OP_const8u";
6214 return "DW_OP_const8s";
6216 return "DW_OP_constu";
6218 return "DW_OP_consts";
6222 return "DW_OP_drop";
6224 return "DW_OP_over";
6226 return "DW_OP_pick";
6228 return "DW_OP_swap";
6232 return "DW_OP_xderef";
6240 return "DW_OP_minus";
6252 return "DW_OP_plus";
6253 case DW_OP_plus_uconst
:
6254 return "DW_OP_plus_uconst";
6260 return "DW_OP_shra";
6278 return "DW_OP_skip";
6280 return "DW_OP_lit0";
6282 return "DW_OP_lit1";
6284 return "DW_OP_lit2";
6286 return "DW_OP_lit3";
6288 return "DW_OP_lit4";
6290 return "DW_OP_lit5";
6292 return "DW_OP_lit6";
6294 return "DW_OP_lit7";
6296 return "DW_OP_lit8";
6298 return "DW_OP_lit9";
6300 return "DW_OP_lit10";
6302 return "DW_OP_lit11";
6304 return "DW_OP_lit12";
6306 return "DW_OP_lit13";
6308 return "DW_OP_lit14";
6310 return "DW_OP_lit15";
6312 return "DW_OP_lit16";
6314 return "DW_OP_lit17";
6316 return "DW_OP_lit18";
6318 return "DW_OP_lit19";
6320 return "DW_OP_lit20";
6322 return "DW_OP_lit21";
6324 return "DW_OP_lit22";
6326 return "DW_OP_lit23";
6328 return "DW_OP_lit24";
6330 return "DW_OP_lit25";
6332 return "DW_OP_lit26";
6334 return "DW_OP_lit27";
6336 return "DW_OP_lit28";
6338 return "DW_OP_lit29";
6340 return "DW_OP_lit30";
6342 return "DW_OP_lit31";
6344 return "DW_OP_reg0";
6346 return "DW_OP_reg1";
6348 return "DW_OP_reg2";
6350 return "DW_OP_reg3";
6352 return "DW_OP_reg4";
6354 return "DW_OP_reg5";
6356 return "DW_OP_reg6";
6358 return "DW_OP_reg7";
6360 return "DW_OP_reg8";
6362 return "DW_OP_reg9";
6364 return "DW_OP_reg10";
6366 return "DW_OP_reg11";
6368 return "DW_OP_reg12";
6370 return "DW_OP_reg13";
6372 return "DW_OP_reg14";
6374 return "DW_OP_reg15";
6376 return "DW_OP_reg16";
6378 return "DW_OP_reg17";
6380 return "DW_OP_reg18";
6382 return "DW_OP_reg19";
6384 return "DW_OP_reg20";
6386 return "DW_OP_reg21";
6388 return "DW_OP_reg22";
6390 return "DW_OP_reg23";
6392 return "DW_OP_reg24";
6394 return "DW_OP_reg25";
6396 return "DW_OP_reg26";
6398 return "DW_OP_reg27";
6400 return "DW_OP_reg28";
6402 return "DW_OP_reg29";
6404 return "DW_OP_reg30";
6406 return "DW_OP_reg31";
6408 return "DW_OP_breg0";
6410 return "DW_OP_breg1";
6412 return "DW_OP_breg2";
6414 return "DW_OP_breg3";
6416 return "DW_OP_breg4";
6418 return "DW_OP_breg5";
6420 return "DW_OP_breg6";
6422 return "DW_OP_breg7";
6424 return "DW_OP_breg8";
6426 return "DW_OP_breg9";
6428 return "DW_OP_breg10";
6430 return "DW_OP_breg11";
6432 return "DW_OP_breg12";
6434 return "DW_OP_breg13";
6436 return "DW_OP_breg14";
6438 return "DW_OP_breg15";
6440 return "DW_OP_breg16";
6442 return "DW_OP_breg17";
6444 return "DW_OP_breg18";
6446 return "DW_OP_breg19";
6448 return "DW_OP_breg20";
6450 return "DW_OP_breg21";
6452 return "DW_OP_breg22";
6454 return "DW_OP_breg23";
6456 return "DW_OP_breg24";
6458 return "DW_OP_breg25";
6460 return "DW_OP_breg26";
6462 return "DW_OP_breg27";
6464 return "DW_OP_breg28";
6466 return "DW_OP_breg29";
6468 return "DW_OP_breg30";
6470 return "DW_OP_breg31";
6472 return "DW_OP_regx";
6474 return "DW_OP_fbreg";
6476 return "DW_OP_bregx";
6478 return "DW_OP_piece";
6479 case DW_OP_deref_size
:
6480 return "DW_OP_deref_size";
6481 case DW_OP_xderef_size
:
6482 return "DW_OP_xderef_size";
6485 /* DWARF 3 extensions. */
6486 case DW_OP_push_object_address
:
6487 return "DW_OP_push_object_address";
6489 return "DW_OP_call2";
6491 return "DW_OP_call4";
6492 case DW_OP_call_ref
:
6493 return "DW_OP_call_ref";
6494 /* GNU extensions. */
6495 case DW_OP_GNU_push_tls_address
:
6496 return "DW_OP_GNU_push_tls_address";
6498 return "OP_<unknown>";
6503 dwarf_bool_name (unsigned mybool
)
6511 /* Convert a DWARF type code into its string name. */
6514 dwarf_type_encoding_name (unsigned enc
)
6518 case DW_ATE_address
:
6519 return "DW_ATE_address";
6520 case DW_ATE_boolean
:
6521 return "DW_ATE_boolean";
6522 case DW_ATE_complex_float
:
6523 return "DW_ATE_complex_float";
6525 return "DW_ATE_float";
6527 return "DW_ATE_signed";
6528 case DW_ATE_signed_char
:
6529 return "DW_ATE_signed_char";
6530 case DW_ATE_unsigned
:
6531 return "DW_ATE_unsigned";
6532 case DW_ATE_unsigned_char
:
6533 return "DW_ATE_unsigned_char";
6534 case DW_ATE_imaginary_float
:
6535 return "DW_ATE_imaginary_float";
6537 return "DW_ATE_<unknown>";
6541 /* Convert a DWARF call frame info operation to its string name. */
6545 dwarf_cfi_name (unsigned cfi_opc
)
6549 case DW_CFA_advance_loc
:
6550 return "DW_CFA_advance_loc";
6552 return "DW_CFA_offset";
6553 case DW_CFA_restore
:
6554 return "DW_CFA_restore";
6556 return "DW_CFA_nop";
6557 case DW_CFA_set_loc
:
6558 return "DW_CFA_set_loc";
6559 case DW_CFA_advance_loc1
:
6560 return "DW_CFA_advance_loc1";
6561 case DW_CFA_advance_loc2
:
6562 return "DW_CFA_advance_loc2";
6563 case DW_CFA_advance_loc4
:
6564 return "DW_CFA_advance_loc4";
6565 case DW_CFA_offset_extended
:
6566 return "DW_CFA_offset_extended";
6567 case DW_CFA_restore_extended
:
6568 return "DW_CFA_restore_extended";
6569 case DW_CFA_undefined
:
6570 return "DW_CFA_undefined";
6571 case DW_CFA_same_value
:
6572 return "DW_CFA_same_value";
6573 case DW_CFA_register
:
6574 return "DW_CFA_register";
6575 case DW_CFA_remember_state
:
6576 return "DW_CFA_remember_state";
6577 case DW_CFA_restore_state
:
6578 return "DW_CFA_restore_state";
6579 case DW_CFA_def_cfa
:
6580 return "DW_CFA_def_cfa";
6581 case DW_CFA_def_cfa_register
:
6582 return "DW_CFA_def_cfa_register";
6583 case DW_CFA_def_cfa_offset
:
6584 return "DW_CFA_def_cfa_offset";
6587 case DW_CFA_def_cfa_expression
:
6588 return "DW_CFA_def_cfa_expression";
6589 case DW_CFA_expression
:
6590 return "DW_CFA_expression";
6591 case DW_CFA_offset_extended_sf
:
6592 return "DW_CFA_offset_extended_sf";
6593 case DW_CFA_def_cfa_sf
:
6594 return "DW_CFA_def_cfa_sf";
6595 case DW_CFA_def_cfa_offset_sf
:
6596 return "DW_CFA_def_cfa_offset_sf";
6598 /* SGI/MIPS specific */
6599 case DW_CFA_MIPS_advance_loc8
:
6600 return "DW_CFA_MIPS_advance_loc8";
6602 /* GNU extensions */
6603 case DW_CFA_GNU_window_save
:
6604 return "DW_CFA_GNU_window_save";
6605 case DW_CFA_GNU_args_size
:
6606 return "DW_CFA_GNU_args_size";
6607 case DW_CFA_GNU_negative_offset_extended
:
6608 return "DW_CFA_GNU_negative_offset_extended";
6611 return "DW_CFA_<unknown>";
6617 dump_die (struct die_info
*die
)
6621 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
6622 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
6623 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
6624 dwarf_bool_name (die
->child
!= NULL
));
6626 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
6627 for (i
= 0; i
< die
->num_attrs
; ++i
)
6629 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
6630 dwarf_attr_name (die
->attrs
[i
].name
),
6631 dwarf_form_name (die
->attrs
[i
].form
));
6632 switch (die
->attrs
[i
].form
)
6634 case DW_FORM_ref_addr
:
6636 fprintf_unfiltered (gdb_stderr
, "address: ");
6637 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
6639 case DW_FORM_block2
:
6640 case DW_FORM_block4
:
6642 case DW_FORM_block1
:
6643 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
6654 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
6656 case DW_FORM_string
:
6658 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
6659 DW_STRING (&die
->attrs
[i
])
6660 ? DW_STRING (&die
->attrs
[i
]) : "");
6663 if (DW_UNSND (&die
->attrs
[i
]))
6664 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
6666 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
6668 case DW_FORM_indirect
:
6669 /* the reader will have reduced the indirect form to
6670 the "base form" so this form should not occur */
6671 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
6674 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
6675 die
->attrs
[i
].form
);
6677 fprintf_unfiltered (gdb_stderr
, "\n");
6682 dump_die_list (struct die_info
*die
)
6687 if (die
->child
!= NULL
)
6688 dump_die_list (die
->child
);
6689 if (die
->sibling
!= NULL
)
6690 dump_die_list (die
->sibling
);
6695 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
6698 struct die_info
*old
;
6700 h
= (offset
% REF_HASH_SIZE
);
6701 old
= die_ref_table
[h
];
6702 die
->next_ref
= old
;
6703 die_ref_table
[h
] = die
;
6708 dwarf2_empty_hash_tables (void)
6710 memset (die_ref_table
, 0, sizeof (die_ref_table
));
6714 dwarf2_get_ref_die_offset (struct attribute
*attr
)
6716 unsigned int result
= 0;
6720 case DW_FORM_ref_addr
:
6721 result
= DW_ADDR (attr
);
6727 case DW_FORM_ref_udata
:
6728 result
= cu_header_offset
+ DW_UNSND (attr
);
6731 complaint (&symfile_complaints
,
6732 "unsupported die ref attribute form: '%s'",
6733 dwarf_form_name (attr
->form
));
6738 static struct die_info
*
6739 follow_die_ref (unsigned int offset
)
6741 struct die_info
*die
;
6744 h
= (offset
% REF_HASH_SIZE
);
6745 die
= die_ref_table
[h
];
6748 if (die
->offset
== offset
)
6752 die
= die
->next_ref
;
6757 static struct type
*
6758 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
6760 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
6762 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
6763 typeid, objfile
->name
);
6766 /* Look for this particular type in the fundamental type vector. If
6767 one is not found, create and install one appropriate for the
6768 current language and the current target machine. */
6770 if (ftypes
[typeid] == NULL
)
6772 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
6775 return (ftypes
[typeid]);
6778 /* Decode simple location descriptions.
6779 Given a pointer to a dwarf block that defines a location, compute
6780 the location and return the value.
6782 NOTE drow/2003-11-18: This function is called in two situations
6783 now: for the address of static or global variables (partial symbols
6784 only) and for offsets into structures which are expected to be
6785 (more or less) constant. The partial symbol case should go away,
6786 and only the constant case should remain. That will let this
6787 function complain more accurately. A few special modes are allowed
6788 without complaint for global variables (for instance, global
6789 register values and thread-local values).
6791 A location description containing no operations indicates that the
6792 object is optimized out. The return value is 0 for that case.
6793 FIXME drow/2003-11-16: No callers check for this case any more; soon all
6794 callers will only want a very basic result and this can become a
6797 When the result is a register number, the global isreg flag is set,
6798 otherwise it is cleared.
6800 Note that stack[0] is unused except as a default error return.
6801 Note that stack overflow is not yet handled. */
6804 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
6806 struct objfile
*objfile
= cu
->objfile
;
6807 struct comp_unit_head
*cu_header
= &cu
->header
;
6809 int size
= blk
->size
;
6810 char *data
= blk
->data
;
6811 CORE_ADDR stack
[64];
6813 unsigned int bytes_read
, unsnd
;
6858 stack
[++stacki
] = op
- DW_OP_lit0
;
6894 stack
[++stacki
] = op
- DW_OP_reg0
;
6896 dwarf2_complex_location_expr_complaint ();
6901 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6903 stack
[++stacki
] = unsnd
;
6905 dwarf2_complex_location_expr_complaint ();
6909 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
6915 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
6920 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
6925 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
6930 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
6935 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
6940 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
6945 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
6951 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6956 stack
[stacki
+ 1] = stack
[stacki
];
6961 stack
[stacki
- 1] += stack
[stacki
];
6965 case DW_OP_plus_uconst
:
6966 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6971 stack
[stacki
- 1] -= stack
[stacki
];
6976 /* If we're not the last op, then we definitely can't encode
6977 this using GDB's address_class enum. This is valid for partial
6978 global symbols, although the variable's address will be bogus
6981 dwarf2_complex_location_expr_complaint ();
6984 case DW_OP_GNU_push_tls_address
:
6985 /* The top of the stack has the offset from the beginning
6986 of the thread control block at which the variable is located. */
6987 /* Nothing should follow this operator, so the top of stack would
6989 /* This is valid for partial global symbols, but the variable's
6990 address will be bogus in the psymtab. */
6992 dwarf2_complex_location_expr_complaint ();
6996 complaint (&symfile_complaints
, "unsupported stack op: '%s'",
6997 dwarf_stack_op_name (op
));
6998 return (stack
[stacki
]);
7001 return (stack
[stacki
]);
7004 /* memory allocation interface */
7007 dwarf2_free_tmp_obstack (void *ignore
)
7009 obstack_free (&dwarf2_tmp_obstack
, NULL
);
7012 static struct dwarf_block
*
7013 dwarf_alloc_block (void)
7015 struct dwarf_block
*blk
;
7017 blk
= (struct dwarf_block
*)
7018 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
7022 static struct abbrev_info
*
7023 dwarf_alloc_abbrev (void)
7025 struct abbrev_info
*abbrev
;
7027 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
7028 memset (abbrev
, 0, sizeof (struct abbrev_info
));
7032 static struct die_info
*
7033 dwarf_alloc_die (void)
7035 struct die_info
*die
;
7037 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
7038 memset (die
, 0, sizeof (struct die_info
));
7043 /* Macro support. */
7046 /* Return the full name of file number I in *LH's file name table.
7047 Use COMP_DIR as the name of the current directory of the
7048 compilation. The result is allocated using xmalloc; the caller is
7049 responsible for freeing it. */
7051 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
7053 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7055 if (IS_ABSOLUTE_PATH (fe
->name
))
7056 return xstrdup (fe
->name
);
7064 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7070 dir_len
= strlen (dir
);
7071 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
7072 strcpy (full_name
, dir
);
7073 full_name
[dir_len
] = '/';
7074 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
7078 return xstrdup (fe
->name
);
7083 static struct macro_source_file
*
7084 macro_start_file (int file
, int line
,
7085 struct macro_source_file
*current_file
,
7086 const char *comp_dir
,
7087 struct line_header
*lh
, struct objfile
*objfile
)
7089 /* The full name of this source file. */
7090 char *full_name
= file_full_name (file
, lh
, comp_dir
);
7092 /* We don't create a macro table for this compilation unit
7093 at all until we actually get a filename. */
7094 if (! pending_macros
)
7095 pending_macros
= new_macro_table (&objfile
->symbol_obstack
,
7096 objfile
->macro_cache
);
7099 /* If we have no current file, then this must be the start_file
7100 directive for the compilation unit's main source file. */
7101 current_file
= macro_set_main (pending_macros
, full_name
);
7103 current_file
= macro_include (current_file
, line
, full_name
);
7107 return current_file
;
7111 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
7112 followed by a null byte. */
7114 copy_string (const char *buf
, int len
)
7116 char *s
= xmalloc (len
+ 1);
7117 memcpy (s
, buf
, len
);
7125 consume_improper_spaces (const char *p
, const char *body
)
7129 complaint (&symfile_complaints
,
7130 "macro definition contains spaces in formal argument list:\n`%s'",
7142 parse_macro_definition (struct macro_source_file
*file
, int line
,
7147 /* The body string takes one of two forms. For object-like macro
7148 definitions, it should be:
7150 <macro name> " " <definition>
7152 For function-like macro definitions, it should be:
7154 <macro name> "() " <definition>
7156 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
7158 Spaces may appear only where explicitly indicated, and in the
7161 The Dwarf 2 spec says that an object-like macro's name is always
7162 followed by a space, but versions of GCC around March 2002 omit
7163 the space when the macro's definition is the empty string.
7165 The Dwarf 2 spec says that there should be no spaces between the
7166 formal arguments in a function-like macro's formal argument list,
7167 but versions of GCC around March 2002 include spaces after the
7171 /* Find the extent of the macro name. The macro name is terminated
7172 by either a space or null character (for an object-like macro) or
7173 an opening paren (for a function-like macro). */
7174 for (p
= body
; *p
; p
++)
7175 if (*p
== ' ' || *p
== '(')
7178 if (*p
== ' ' || *p
== '\0')
7180 /* It's an object-like macro. */
7181 int name_len
= p
- body
;
7182 char *name
= copy_string (body
, name_len
);
7183 const char *replacement
;
7186 replacement
= body
+ name_len
+ 1;
7189 dwarf2_macro_malformed_definition_complaint (body
);
7190 replacement
= body
+ name_len
;
7193 macro_define_object (file
, line
, name
, replacement
);
7199 /* It's a function-like macro. */
7200 char *name
= copy_string (body
, p
- body
);
7203 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
7207 p
= consume_improper_spaces (p
, body
);
7209 /* Parse the formal argument list. */
7210 while (*p
&& *p
!= ')')
7212 /* Find the extent of the current argument name. */
7213 const char *arg_start
= p
;
7215 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
7218 if (! *p
|| p
== arg_start
)
7219 dwarf2_macro_malformed_definition_complaint (body
);
7222 /* Make sure argv has room for the new argument. */
7223 if (argc
>= argv_size
)
7226 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
7229 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
7232 p
= consume_improper_spaces (p
, body
);
7234 /* Consume the comma, if present. */
7239 p
= consume_improper_spaces (p
, body
);
7248 /* Perfectly formed definition, no complaints. */
7249 macro_define_function (file
, line
, name
,
7250 argc
, (const char **) argv
,
7252 else if (*p
== '\0')
7254 /* Complain, but do define it. */
7255 dwarf2_macro_malformed_definition_complaint (body
);
7256 macro_define_function (file
, line
, name
,
7257 argc
, (const char **) argv
,
7261 /* Just complain. */
7262 dwarf2_macro_malformed_definition_complaint (body
);
7265 /* Just complain. */
7266 dwarf2_macro_malformed_definition_complaint (body
);
7272 for (i
= 0; i
< argc
; i
++)
7278 dwarf2_macro_malformed_definition_complaint (body
);
7283 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
7284 char *comp_dir
, bfd
*abfd
,
7285 struct dwarf2_cu
*cu
)
7287 char *mac_ptr
, *mac_end
;
7288 struct macro_source_file
*current_file
= 0;
7290 if (dwarf_macinfo_buffer
== NULL
)
7292 complaint (&symfile_complaints
, "missing .debug_macinfo section");
7296 mac_ptr
= dwarf_macinfo_buffer
+ offset
;
7297 mac_end
= dwarf_macinfo_buffer
+ dwarf_macinfo_size
;
7301 enum dwarf_macinfo_record_type macinfo_type
;
7303 /* Do we at least have room for a macinfo type byte? */
7304 if (mac_ptr
>= mac_end
)
7306 dwarf2_macros_too_long_complaint ();
7310 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
7313 switch (macinfo_type
)
7315 /* A zero macinfo type indicates the end of the macro
7320 case DW_MACINFO_define
:
7321 case DW_MACINFO_undef
:
7327 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7328 mac_ptr
+= bytes_read
;
7329 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
7330 mac_ptr
+= bytes_read
;
7333 complaint (&symfile_complaints
,
7334 "debug info gives macro %s outside of any file: %s",
7336 DW_MACINFO_define
? "definition" : macinfo_type
==
7337 DW_MACINFO_undef
? "undefinition" :
7338 "something-or-other", body
);
7341 if (macinfo_type
== DW_MACINFO_define
)
7342 parse_macro_definition (current_file
, line
, body
);
7343 else if (macinfo_type
== DW_MACINFO_undef
)
7344 macro_undef (current_file
, line
, body
);
7349 case DW_MACINFO_start_file
:
7354 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7355 mac_ptr
+= bytes_read
;
7356 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7357 mac_ptr
+= bytes_read
;
7359 current_file
= macro_start_file (file
, line
,
7360 current_file
, comp_dir
,
7365 case DW_MACINFO_end_file
:
7367 complaint (&symfile_complaints
,
7368 "macro debug info has an unmatched `close_file' directive");
7371 current_file
= current_file
->included_by
;
7374 enum dwarf_macinfo_record_type next_type
;
7376 /* GCC circa March 2002 doesn't produce the zero
7377 type byte marking the end of the compilation
7378 unit. Complain if it's not there, but exit no
7381 /* Do we at least have room for a macinfo type byte? */
7382 if (mac_ptr
>= mac_end
)
7384 dwarf2_macros_too_long_complaint ();
7388 /* We don't increment mac_ptr here, so this is just
7390 next_type
= read_1_byte (abfd
, mac_ptr
);
7392 complaint (&symfile_complaints
,
7393 "no terminating 0-type entry for macros in `.debug_macinfo' section");
7400 case DW_MACINFO_vendor_ext
:
7406 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7407 mac_ptr
+= bytes_read
;
7408 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
7409 mac_ptr
+= bytes_read
;
7411 /* We don't recognize any vendor extensions. */
7418 /* Check if the attribute's form is a DW_FORM_block*
7419 if so return true else false. */
7421 attr_form_is_block (struct attribute
*attr
)
7423 return (attr
== NULL
? 0 :
7424 attr
->form
== DW_FORM_block1
7425 || attr
->form
== DW_FORM_block2
7426 || attr
->form
== DW_FORM_block4
7427 || attr
->form
== DW_FORM_block
);
7431 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
7432 struct dwarf2_cu
*cu
)
7434 if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
7436 struct dwarf2_loclist_baton
*baton
;
7438 baton
= obstack_alloc (&cu
->objfile
->symbol_obstack
,
7439 sizeof (struct dwarf2_loclist_baton
));
7440 baton
->objfile
= cu
->objfile
;
7442 /* We don't know how long the location list is, but make sure we
7443 don't run off the edge of the section. */
7444 baton
->size
= dwarf_loc_size
- DW_UNSND (attr
);
7445 baton
->data
= dwarf_loc_buffer
+ DW_UNSND (attr
);
7446 baton
->base_address
= cu
->header
.base_address
;
7447 if (cu
->header
.base_known
== 0)
7448 complaint (&symfile_complaints
,
7449 "Location list used without specifying the CU base address.");
7451 SYMBOL_LOCATION_FUNCS (sym
) = &dwarf2_loclist_funcs
;
7452 SYMBOL_LOCATION_BATON (sym
) = baton
;
7456 struct dwarf2_locexpr_baton
*baton
;
7458 baton
= obstack_alloc (&cu
->objfile
->symbol_obstack
,
7459 sizeof (struct dwarf2_locexpr_baton
));
7460 baton
->objfile
= cu
->objfile
;
7462 if (attr_form_is_block (attr
))
7464 /* Note that we're just copying the block's data pointer
7465 here, not the actual data. We're still pointing into the
7466 dwarf_info_buffer for SYM's objfile; right now we never
7467 release that buffer, but when we do clean up properly
7468 this may need to change. */
7469 baton
->size
= DW_BLOCK (attr
)->size
;
7470 baton
->data
= DW_BLOCK (attr
)->data
;
7474 dwarf2_invalid_attrib_class_complaint ("location description",
7475 SYMBOL_NATURAL_NAME (sym
));
7480 SYMBOL_LOCATION_FUNCS (sym
) = &dwarf2_locexpr_funcs
;
7481 SYMBOL_LOCATION_BATON (sym
) = baton
;