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 void read_enumeration (struct die_info
*, struct dwarf2_cu
*);
814 static struct type
*dwarf_base_type (int, int, struct dwarf2_cu
*);
816 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
818 static void read_array_type (struct die_info
*, struct dwarf2_cu
*);
820 static void read_tag_pointer_type (struct die_info
*, struct dwarf2_cu
*);
822 static void read_tag_ptr_to_member_type (struct die_info
*,
825 static void read_tag_reference_type (struct die_info
*, struct dwarf2_cu
*);
827 static void read_tag_const_type (struct die_info
*, struct dwarf2_cu
*);
829 static void read_tag_volatile_type (struct die_info
*, struct dwarf2_cu
*);
831 static void read_tag_string_type (struct die_info
*, struct dwarf2_cu
*);
833 static void read_subroutine_type (struct die_info
*, struct dwarf2_cu
*);
835 static struct die_info
*read_comp_unit (char *, bfd
*, struct dwarf2_cu
*);
837 static struct die_info
*read_die_and_children (char *info_ptr
, bfd
*abfd
,
840 struct die_info
*parent
);
842 static struct die_info
*read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
845 struct die_info
*parent
);
847 static void free_die_list (struct die_info
*);
849 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
851 static void process_die (struct die_info
*, struct dwarf2_cu
*);
853 static char *dwarf2_linkage_name (struct die_info
*);
855 static char *dwarf2_name (struct die_info
*die
);
857 static struct die_info
*dwarf2_extension (struct die_info
*die
);
859 static char *dwarf_tag_name (unsigned int);
861 static char *dwarf_attr_name (unsigned int);
863 static char *dwarf_form_name (unsigned int);
865 static char *dwarf_stack_op_name (unsigned int);
867 static char *dwarf_bool_name (unsigned int);
869 static char *dwarf_type_encoding_name (unsigned int);
872 static char *dwarf_cfi_name (unsigned int);
874 struct die_info
*copy_die (struct die_info
*);
877 static struct die_info
*sibling_die (struct die_info
*);
879 static void dump_die (struct die_info
*);
881 static void dump_die_list (struct die_info
*);
883 static void store_in_ref_table (unsigned int, struct die_info
*);
885 static void dwarf2_empty_hash_tables (void);
887 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
889 static struct die_info
*follow_die_ref (unsigned int);
891 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
893 /* memory allocation interface */
895 static void dwarf2_free_tmp_obstack (void *);
897 static struct dwarf_block
*dwarf_alloc_block (void);
899 static struct abbrev_info
*dwarf_alloc_abbrev (void);
901 static struct die_info
*dwarf_alloc_die (void);
903 static void initialize_cu_func_list (void);
905 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
);
907 static void dwarf_decode_macros (struct line_header
*, unsigned int,
908 char *, bfd
*, struct dwarf2_cu
*);
910 static int attr_form_is_block (struct attribute
*);
913 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
914 struct dwarf2_cu
*cu
);
916 /* Try to locate the sections we need for DWARF 2 debugging
917 information and return true if we have enough to do something. */
920 dwarf2_has_info (bfd
*abfd
)
922 dwarf_info_section
= 0;
923 dwarf_abbrev_section
= 0;
924 dwarf_line_section
= 0;
925 dwarf_str_section
= 0;
926 dwarf_macinfo_section
= 0;
927 dwarf_frame_section
= 0;
928 dwarf_eh_frame_section
= 0;
929 dwarf_ranges_section
= 0;
930 dwarf_loc_section
= 0;
932 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
933 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
936 /* This function is mapped across the sections and remembers the
937 offset and size of each of the debugging sections we are interested
941 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, void *ignore_ptr
)
943 if (strcmp (sectp
->name
, INFO_SECTION
) == 0)
945 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
946 dwarf_info_section
= sectp
;
948 else if (strcmp (sectp
->name
, ABBREV_SECTION
) == 0)
950 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
951 dwarf_abbrev_section
= sectp
;
953 else if (strcmp (sectp
->name
, LINE_SECTION
) == 0)
955 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
956 dwarf_line_section
= sectp
;
958 else if (strcmp (sectp
->name
, PUBNAMES_SECTION
) == 0)
960 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
961 dwarf_pubnames_section
= sectp
;
963 else if (strcmp (sectp
->name
, ARANGES_SECTION
) == 0)
965 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
966 dwarf_aranges_section
= sectp
;
968 else if (strcmp (sectp
->name
, LOC_SECTION
) == 0)
970 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
971 dwarf_loc_section
= sectp
;
973 else if (strcmp (sectp
->name
, MACINFO_SECTION
) == 0)
975 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
976 dwarf_macinfo_section
= sectp
;
978 else if (strcmp (sectp
->name
, STR_SECTION
) == 0)
980 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
981 dwarf_str_section
= sectp
;
983 else if (strcmp (sectp
->name
, FRAME_SECTION
) == 0)
985 dwarf_frame_size
= bfd_get_section_size_before_reloc (sectp
);
986 dwarf_frame_section
= sectp
;
988 else if (strcmp (sectp
->name
, EH_FRAME_SECTION
) == 0)
990 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
991 if (aflag
& SEC_HAS_CONTENTS
)
993 dwarf_eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
994 dwarf_eh_frame_section
= sectp
;
997 else if (strcmp (sectp
->name
, RANGES_SECTION
) == 0)
999 dwarf_ranges_size
= bfd_get_section_size_before_reloc (sectp
);
1000 dwarf_ranges_section
= sectp
;
1004 /* Build a partial symbol table. */
1007 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1010 /* We definitely need the .debug_info and .debug_abbrev sections */
1012 dwarf_info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1013 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1015 if (dwarf_line_section
)
1016 dwarf_line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1018 dwarf_line_buffer
= NULL
;
1020 if (dwarf_str_section
)
1021 dwarf_str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1023 dwarf_str_buffer
= NULL
;
1025 if (dwarf_macinfo_section
)
1026 dwarf_macinfo_buffer
= dwarf2_read_section (objfile
,
1027 dwarf_macinfo_section
);
1029 dwarf_macinfo_buffer
= NULL
;
1031 if (dwarf_ranges_section
)
1032 dwarf_ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1034 dwarf_ranges_buffer
= NULL
;
1036 if (dwarf_loc_section
)
1037 dwarf_loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1039 dwarf_loc_buffer
= NULL
;
1042 || (objfile
->global_psymbols
.size
== 0
1043 && objfile
->static_psymbols
.size
== 0))
1045 init_psymbol_list (objfile
, 1024);
1049 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1051 /* Things are significantly easier if we have .debug_aranges and
1052 .debug_pubnames sections */
1054 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1058 /* only test this case for now */
1060 /* In this case we have to work a bit harder */
1061 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1066 /* Build the partial symbol table from the information in the
1067 .debug_pubnames and .debug_aranges sections. */
1070 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1072 bfd
*abfd
= objfile
->obfd
;
1073 char *aranges_buffer
, *pubnames_buffer
;
1074 char *aranges_ptr
, *pubnames_ptr
;
1075 unsigned int entry_length
, version
, info_offset
, info_size
;
1077 pubnames_buffer
= dwarf2_read_section (objfile
,
1078 dwarf_pubnames_section
);
1079 pubnames_ptr
= pubnames_buffer
;
1080 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
1082 struct comp_unit_head cu_header
;
1085 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1087 pubnames_ptr
+= bytes_read
;
1088 version
= read_1_byte (abfd
, pubnames_ptr
);
1090 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1092 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1096 aranges_buffer
= dwarf2_read_section (objfile
,
1097 dwarf_aranges_section
);
1102 /* Read in the comp unit header information from the debug_info at
1106 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1107 char *info_ptr
, bfd
*abfd
)
1111 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1113 info_ptr
+= bytes_read
;
1114 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1116 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1118 info_ptr
+= bytes_read
;
1119 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1121 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1122 if (signed_addr
< 0)
1123 internal_error (__FILE__
, __LINE__
,
1124 "read_comp_unit_head: dwarf from non elf file");
1125 cu_header
->signed_addr_p
= signed_addr
;
1129 /* Build the partial symbol table by doing a quick pass through the
1130 .debug_info and .debug_abbrev sections. */
1133 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1135 /* Instead of reading this into a big buffer, we should probably use
1136 mmap() on architectures that support it. (FIXME) */
1137 bfd
*abfd
= objfile
->obfd
;
1138 char *info_ptr
, *abbrev_ptr
;
1139 char *beg_of_comp_unit
;
1140 struct partial_die_info comp_unit_die
;
1141 struct partial_symtab
*pst
;
1142 struct cleanup
*back_to
;
1143 CORE_ADDR lowpc
, highpc
;
1145 info_ptr
= dwarf_info_buffer
;
1146 abbrev_ptr
= dwarf_abbrev_buffer
;
1148 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1149 the partial symbol scan, like attribute values.
1151 We could reduce our peak memory consumption during partial symbol
1152 table construction by freeing stuff from this obstack more often
1153 --- say, after processing each compilation unit, or each die ---
1154 but it turns out that this saves almost nothing. For an
1155 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1156 on dwarf2_tmp_obstack. Some investigation showed:
1158 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1159 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1160 all fixed-length values not requiring dynamic allocation.
1162 2) 30% of the attributes used the form DW_FORM_string. For
1163 DW_FORM_string, read_attribute simply hands back a pointer to
1164 the null-terminated string in dwarf_info_buffer, so no dynamic
1165 allocation is needed there either.
1167 3) The remaining 1% of the attributes all used DW_FORM_block1.
1168 75% of those were DW_AT_frame_base location lists for
1169 functions; the rest were DW_AT_location attributes, probably
1170 for the global variables.
1172 Anyway, what this all means is that the memory the dwarf2
1173 reader uses as temporary space reading partial symbols is about
1174 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1176 obstack_init (&dwarf2_tmp_obstack
);
1177 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1179 /* Since the objects we're extracting from dwarf_info_buffer vary in
1180 length, only the individual functions to extract them (like
1181 read_comp_unit_head and read_partial_die) can really know whether
1182 the buffer is large enough to hold another complete object.
1184 At the moment, they don't actually check that. If
1185 dwarf_info_buffer holds just one extra byte after the last
1186 compilation unit's dies, then read_comp_unit_head will happily
1187 read off the end of the buffer. read_partial_die is similarly
1188 casual. Those functions should be fixed.
1190 For this loop condition, simply checking whether there's any data
1191 left at all should be sufficient. */
1192 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1194 struct dwarf2_cu cu
;
1195 beg_of_comp_unit
= info_ptr
;
1197 cu
.objfile
= objfile
;
1198 info_ptr
= read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1200 if (cu
.header
.version
!= 2)
1202 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
));
1205 if (cu
.header
.abbrev_offset
>= dwarf_abbrev_size
)
1207 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6) [in module %s]",
1208 (long) cu
.header
.abbrev_offset
,
1209 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1210 bfd_get_filename (abfd
));
1213 if (beg_of_comp_unit
+ cu
.header
.length
+ cu
.header
.initial_length_size
1214 > dwarf_info_buffer
+ dwarf_info_size
)
1216 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0) [in module %s]",
1217 (long) cu
.header
.length
,
1218 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1219 bfd_get_filename (abfd
));
1222 /* Complete the cu_header */
1223 cu
.header
.offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1224 cu
.header
.first_die_ptr
= info_ptr
;
1225 cu
.header
.cu_head_ptr
= beg_of_comp_unit
;
1227 /* Read the abbrevs for this compilation unit into a table */
1228 dwarf2_read_abbrevs (abfd
, &cu
);
1229 make_cleanup (dwarf2_empty_abbrev_table
, cu
.header
.dwarf2_abbrevs
);
1231 /* Read the compilation unit die */
1232 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1235 /* Set the language we're debugging */
1236 set_cu_language (comp_unit_die
.language
);
1238 /* Allocate a new partial symbol table structure */
1239 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1240 comp_unit_die
.name
? comp_unit_die
.name
: "",
1241 comp_unit_die
.lowpc
,
1242 objfile
->global_psymbols
.next
,
1243 objfile
->static_psymbols
.next
);
1245 pst
->read_symtab_private
= (char *)
1246 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1247 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1248 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1249 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1250 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1251 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1252 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1253 DWARF_LINE_SIZE (pst
) = dwarf_line_size
;
1254 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1255 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1256 DWARF_MACINFO_BUFFER (pst
) = dwarf_macinfo_buffer
;
1257 DWARF_MACINFO_SIZE (pst
) = dwarf_macinfo_size
;
1258 DWARF_RANGES_BUFFER (pst
) = dwarf_ranges_buffer
;
1259 DWARF_RANGES_SIZE (pst
) = dwarf_ranges_size
;
1260 DWARF_LOC_BUFFER (pst
) = dwarf_loc_buffer
;
1261 DWARF_LOC_SIZE (pst
) = dwarf_loc_size
;
1262 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1264 /* Store the function that reads in the rest of the symbol table */
1265 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1267 /* Check if comp unit has_children.
1268 If so, read the rest of the partial symbols from this comp unit.
1269 If not, there's no more debug_info for this comp unit. */
1270 if (comp_unit_die
.has_children
)
1272 lowpc
= ((CORE_ADDR
) -1);
1273 highpc
= ((CORE_ADDR
) 0);
1275 info_ptr
= scan_partial_symbols (info_ptr
, &lowpc
, &highpc
,
1278 /* If we didn't find a lowpc, set it to highpc to avoid
1279 complaints from `maint check'. */
1280 if (lowpc
== ((CORE_ADDR
) -1))
1283 /* If the compilation unit didn't have an explicit address range,
1284 then use the information extracted from its child dies. */
1285 if (! comp_unit_die
.has_pc_info
)
1287 comp_unit_die
.lowpc
= lowpc
;
1288 comp_unit_die
.highpc
= highpc
;
1291 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1292 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1294 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1295 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1296 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1297 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1298 sort_pst_symbols (pst
);
1300 /* If there is already a psymtab or symtab for a file of this
1301 name, remove it. (If there is a symtab, more drastic things
1302 also happen.) This happens in VxWorks. */
1303 free_named_symtabs (pst
->filename
);
1305 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1306 + cu
.header
.initial_length_size
;
1308 do_cleanups (back_to
);
1311 /* Read in all interesting dies to the end of the compilation unit or
1312 to the end of the current namespace. NAMESPACE is NULL if we
1313 haven't yet encountered any DW_TAG_namespace entries; otherwise,
1314 it's the name of the current namespace. In particular, it's the
1315 empty string if we're currently in the global namespace but have
1316 previously encountered a DW_TAG_namespace. */
1319 scan_partial_symbols (char *info_ptr
, CORE_ADDR
*lowpc
,
1320 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
1321 const char *namespace)
1323 struct objfile
*objfile
= cu
->objfile
;
1324 bfd
*abfd
= objfile
->obfd
;
1325 struct partial_die_info pdi
;
1327 /* Now, march along the PDI's, descending into ones which have
1328 interesting children but skipping the children of the other ones,
1329 until we reach the end of the compilation unit. */
1333 /* This flag tells whether or not info_ptr has gotten updated
1335 int info_ptr_updated
= 0;
1337 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu
);
1339 /* Anonymous namespaces have no name but have interesting
1340 children, so we need to look at them. Ditto for anonymous
1343 if (pdi
.name
!= NULL
|| pdi
.tag
== DW_TAG_namespace
1344 || pdi
.tag
== DW_TAG_enumeration_type
)
1348 case DW_TAG_subprogram
:
1349 if (pdi
.has_pc_info
)
1351 if (pdi
.lowpc
< *lowpc
)
1355 if (pdi
.highpc
> *highpc
)
1357 *highpc
= pdi
.highpc
;
1359 if (!pdi
.is_declaration
)
1361 add_partial_symbol (&pdi
, cu
, namespace);
1365 case DW_TAG_variable
:
1366 case DW_TAG_typedef
:
1367 case DW_TAG_union_type
:
1368 case DW_TAG_class_type
:
1369 case DW_TAG_structure_type
:
1370 if (!pdi
.is_declaration
)
1372 add_partial_symbol (&pdi
, cu
, namespace);
1375 case DW_TAG_enumeration_type
:
1376 if (!pdi
.is_declaration
)
1378 info_ptr
= add_partial_enumeration (&pdi
, info_ptr
, cu
,
1380 info_ptr_updated
= 1;
1383 case DW_TAG_base_type
:
1384 /* File scope base type definitions are added to the partial
1386 add_partial_symbol (&pdi
, cu
, namespace);
1388 case DW_TAG_namespace
:
1389 /* We've hit a DW_TAG_namespace entry, so we know this
1390 file has been compiled using a compiler that
1391 generates them; update NAMESPACE to reflect that. */
1392 if (namespace == NULL
)
1394 info_ptr
= add_partial_namespace (&pdi
, info_ptr
, lowpc
, highpc
,
1396 info_ptr_updated
= 1;
1406 /* If the die has a sibling, skip to the sibling, unless another
1407 function has already updated info_ptr for us. */
1409 /* NOTE: carlton/2003-06-16: This is a bit hackish, but whether
1410 or not we want to update this depends on enough stuff (not
1411 only pdi.tag but also whether or not pdi.name is NULL) that
1412 this seems like the easiest way to handle the issue. */
1414 if (!info_ptr_updated
)
1415 info_ptr
= locate_pdi_sibling (&pdi
, info_ptr
, abfd
, cu
);
1422 add_partial_symbol (struct partial_die_info
*pdi
,
1423 struct dwarf2_cu
*cu
, const char *namespace)
1425 struct objfile
*objfile
= cu
->objfile
;
1427 const struct partial_symbol
*psym
= NULL
;
1431 case DW_TAG_subprogram
:
1432 if (pdi
->is_external
)
1434 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1435 mst_text, objfile); */
1436 psym
= add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1437 VAR_DOMAIN
, LOC_BLOCK
,
1438 &objfile
->global_psymbols
,
1439 0, pdi
->lowpc
+ baseaddr
,
1440 cu_language
, objfile
);
1444 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1445 mst_file_text, objfile); */
1446 psym
= add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1447 VAR_DOMAIN
, LOC_BLOCK
,
1448 &objfile
->static_psymbols
,
1449 0, pdi
->lowpc
+ baseaddr
,
1450 cu_language
, objfile
);
1453 case DW_TAG_variable
:
1454 if (pdi
->is_external
)
1457 Don't enter into the minimal symbol tables as there is
1458 a minimal symbol table entry from the ELF symbols already.
1459 Enter into partial symbol table if it has a location
1460 descriptor or a type.
1461 If the location descriptor is missing, new_symbol will create
1462 a LOC_UNRESOLVED symbol, the address of the variable will then
1463 be determined from the minimal symbol table whenever the variable
1465 The address for the partial symbol table entry is not
1466 used by GDB, but it comes in handy for debugging partial symbol
1470 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1471 if (pdi
->locdesc
|| pdi
->has_type
)
1472 psym
= add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1473 VAR_DOMAIN
, LOC_STATIC
,
1474 &objfile
->global_psymbols
,
1476 cu_language
, objfile
);
1480 /* Static Variable. Skip symbols without location descriptors. */
1481 if (pdi
->locdesc
== NULL
)
1483 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1484 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1485 mst_file_data, objfile); */
1486 psym
= add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1487 VAR_DOMAIN
, LOC_STATIC
,
1488 &objfile
->static_psymbols
,
1490 cu_language
, objfile
);
1493 case DW_TAG_typedef
:
1494 case DW_TAG_base_type
:
1495 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1496 VAR_DOMAIN
, LOC_TYPEDEF
,
1497 &objfile
->static_psymbols
,
1498 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1500 case DW_TAG_class_type
:
1501 case DW_TAG_structure_type
:
1502 case DW_TAG_union_type
:
1503 case DW_TAG_enumeration_type
:
1504 /* Skip aggregate types without children, these are external
1506 if (pdi
->has_children
== 0)
1508 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1509 STRUCT_DOMAIN
, LOC_TYPEDEF
,
1510 &objfile
->static_psymbols
,
1511 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1513 if (cu_language
== language_cplus
)
1515 /* For C++, these implicitly act as typedefs as well. */
1516 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1517 VAR_DOMAIN
, LOC_TYPEDEF
,
1518 &objfile
->static_psymbols
,
1519 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1522 case DW_TAG_enumerator
:
1523 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1524 VAR_DOMAIN
, LOC_CONST
,
1525 &objfile
->static_psymbols
,
1526 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1532 /* Check to see if we should scan the name for possible namespace
1533 info. Only do this if this is C++, if we don't have namespace
1534 debugging info in the file, if the psym is of an appropriate type
1535 (otherwise we'll have psym == NULL), and if we actually had a
1536 mangled name to begin with. */
1538 if (cu_language
== language_cplus
1539 && namespace == NULL
1541 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
1542 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
1546 /* Read a partial die corresponding to a namespace; also, add a symbol
1547 corresponding to that namespace to the symbol table. NAMESPACE is
1548 the name of the enclosing namespace. */
1551 add_partial_namespace (struct partial_die_info
*pdi
, char *info_ptr
,
1552 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1553 struct dwarf2_cu
*cu
, const char *namespace)
1555 struct objfile
*objfile
= cu
->objfile
;
1556 const char *new_name
= pdi
->name
;
1559 /* Calculate the full name of the namespace that we just entered. */
1561 if (new_name
== NULL
)
1562 new_name
= "(anonymous namespace)";
1563 full_name
= alloca (strlen (namespace) + 2 + strlen (new_name
) + 1);
1564 strcpy (full_name
, namespace);
1565 if (*namespace != '\0')
1566 strcat (full_name
, "::");
1567 strcat (full_name
, new_name
);
1569 /* FIXME: carlton/2003-06-27: Once we build qualified names for more
1570 symbols than just namespaces, we should replace this by a call to
1571 add_partial_symbol. */
1573 add_psymbol_to_list (full_name
, strlen (full_name
),
1574 VAR_DOMAIN
, LOC_TYPEDEF
,
1575 &objfile
->global_psymbols
,
1576 0, 0, cu_language
, objfile
);
1578 /* Now scan partial symbols in that namespace. */
1580 if (pdi
->has_children
)
1581 info_ptr
= scan_partial_symbols (info_ptr
, lowpc
, highpc
, cu
, full_name
);
1586 /* Read a partial die corresponding to an enumeration type. */
1589 add_partial_enumeration (struct partial_die_info
*enum_pdi
, char *info_ptr
,
1590 struct dwarf2_cu
*cu
, const char *namespace)
1592 struct objfile
*objfile
= cu
->objfile
;
1593 bfd
*abfd
= objfile
->obfd
;
1594 struct partial_die_info pdi
;
1596 if (enum_pdi
->name
!= NULL
)
1597 add_partial_symbol (enum_pdi
, cu
, namespace);
1601 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu
);
1604 if (pdi
.tag
!= DW_TAG_enumerator
|| pdi
.name
== NULL
)
1605 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
1607 add_partial_symbol (&pdi
, cu
, namespace);
1613 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the next DIE
1617 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, char *info_ptr
,
1618 bfd
*abfd
, struct dwarf2_cu
*cu
)
1620 /* Do we know the sibling already? */
1622 if (orig_pdi
->sibling
)
1623 return orig_pdi
->sibling
;
1625 /* Are there any children to deal with? */
1627 if (!orig_pdi
->has_children
)
1630 /* Okay, we don't know the sibling, but we have children that we
1631 want to skip. So read children until we run into one without a
1632 tag; return whatever follows it. */
1636 struct partial_die_info pdi
;
1638 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu
);
1643 info_ptr
= locate_pdi_sibling (&pdi
, info_ptr
, abfd
, cu
);
1647 /* Expand this partial symbol table into a full symbol table. */
1650 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1652 /* FIXME: This is barely more than a stub. */
1657 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1663 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1664 gdb_flush (gdb_stdout
);
1667 psymtab_to_symtab_1 (pst
);
1669 /* Finish up the debug error message. */
1671 printf_filtered ("done.\n");
1677 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1679 struct objfile
*objfile
= pst
->objfile
;
1680 bfd
*abfd
= objfile
->obfd
;
1681 struct dwarf2_cu cu
;
1682 struct die_info
*dies
;
1683 unsigned long offset
;
1684 CORE_ADDR lowpc
, highpc
;
1685 struct die_info
*child_die
;
1687 struct symtab
*symtab
;
1688 struct cleanup
*back_to
;
1689 struct attribute
*attr
;
1691 /* Set local variables from the partial symbol table info. */
1692 offset
= DWARF_INFO_OFFSET (pst
);
1693 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1694 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1695 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1696 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1697 dwarf_line_size
= DWARF_LINE_SIZE (pst
);
1698 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1699 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1700 dwarf_macinfo_buffer
= DWARF_MACINFO_BUFFER (pst
);
1701 dwarf_macinfo_size
= DWARF_MACINFO_SIZE (pst
);
1702 dwarf_ranges_buffer
= DWARF_RANGES_BUFFER (pst
);
1703 dwarf_ranges_size
= DWARF_RANGES_SIZE (pst
);
1704 dwarf_loc_buffer
= DWARF_LOC_BUFFER (pst
);
1705 dwarf_loc_size
= DWARF_LOC_SIZE (pst
);
1706 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1707 cu_header_offset
= offset
;
1708 info_ptr
= dwarf_info_buffer
+ offset
;
1710 obstack_init (&dwarf2_tmp_obstack
);
1711 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1714 make_cleanup (really_free_pendings
, NULL
);
1716 cu
.objfile
= objfile
;
1718 /* read in the comp_unit header */
1719 info_ptr
= read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1721 /* Read the abbrevs for this compilation unit */
1722 dwarf2_read_abbrevs (abfd
, &cu
);
1723 make_cleanup (dwarf2_empty_abbrev_table
, cu
.header
.dwarf2_abbrevs
);
1725 dies
= read_comp_unit (info_ptr
, abfd
, &cu
);
1727 make_cleanup_free_die_list (dies
);
1729 /* Find the base address of the compilation unit for range lists and
1730 location lists. It will normally be specified by DW_AT_low_pc.
1731 In DWARF-3 draft 4, the base address could be overridden by
1732 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1733 compilation units with discontinuous ranges. */
1735 cu
.header
.base_known
= 0;
1736 cu
.header
.base_address
= 0;
1738 attr
= dwarf_attr (dies
, DW_AT_entry_pc
);
1741 cu
.header
.base_address
= DW_ADDR (attr
);
1742 cu
.header
.base_known
= 1;
1746 attr
= dwarf_attr (dies
, DW_AT_low_pc
);
1749 cu
.header
.base_address
= DW_ADDR (attr
);
1750 cu
.header
.base_known
= 1;
1754 /* Do line number decoding in read_file_scope () */
1755 process_die (dies
, &cu
);
1757 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, &cu
))
1759 /* Some compilers don't define a DW_AT_high_pc attribute for
1760 the compilation unit. If the DW_AT_high_pc is missing,
1761 synthesize it, by scanning the DIE's below the compilation unit. */
1763 if (dies
->child
!= NULL
)
1765 child_die
= dies
->child
;
1766 while (child_die
&& child_die
->tag
)
1768 if (child_die
->tag
== DW_TAG_subprogram
)
1770 CORE_ADDR low
, high
;
1772 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, &cu
))
1774 highpc
= max (highpc
, high
);
1777 child_die
= sibling_die (child_die
);
1781 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1783 /* Set symtab language to language from DW_AT_language.
1784 If the compilation is from a C file generated by language preprocessors,
1785 do not set the language if it was already deduced by start_subfile. */
1787 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1789 symtab
->language
= cu_language
;
1791 pst
->symtab
= symtab
;
1794 do_cleanups (back_to
);
1797 /* Process a die and its children. */
1800 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
1804 case DW_TAG_padding
:
1806 case DW_TAG_compile_unit
:
1807 read_file_scope (die
, cu
);
1809 case DW_TAG_subprogram
:
1810 read_subroutine_type (die
, cu
);
1811 read_func_scope (die
, cu
);
1813 case DW_TAG_inlined_subroutine
:
1814 /* FIXME: These are ignored for now.
1815 They could be used to set breakpoints on all inlined instances
1816 of a function and make GDB `next' properly over inlined functions. */
1818 case DW_TAG_lexical_block
:
1819 case DW_TAG_try_block
:
1820 case DW_TAG_catch_block
:
1821 read_lexical_block_scope (die
, cu
);
1823 case DW_TAG_class_type
:
1824 case DW_TAG_structure_type
:
1825 case DW_TAG_union_type
:
1826 read_structure_scope (die
, cu
);
1828 case DW_TAG_enumeration_type
:
1829 read_enumeration (die
, cu
);
1831 case DW_TAG_subroutine_type
:
1832 read_subroutine_type (die
, cu
);
1834 case DW_TAG_array_type
:
1835 read_array_type (die
, cu
);
1837 case DW_TAG_pointer_type
:
1838 read_tag_pointer_type (die
, cu
);
1840 case DW_TAG_ptr_to_member_type
:
1841 read_tag_ptr_to_member_type (die
, cu
);
1843 case DW_TAG_reference_type
:
1844 read_tag_reference_type (die
, cu
);
1846 case DW_TAG_string_type
:
1847 read_tag_string_type (die
, cu
);
1849 case DW_TAG_base_type
:
1850 read_base_type (die
, cu
);
1851 if (dwarf_attr (die
, DW_AT_name
))
1853 /* Add a typedef symbol for the base type definition. */
1854 new_symbol (die
, die
->type
, cu
);
1857 case DW_TAG_common_block
:
1858 read_common_block (die
, cu
);
1860 case DW_TAG_common_inclusion
:
1862 case DW_TAG_namespace
:
1863 if (!processing_has_namespace_info
)
1865 processing_has_namespace_info
= 1;
1866 processing_current_namespace
= "";
1868 read_namespace (die
, cu
);
1870 case DW_TAG_imported_declaration
:
1871 case DW_TAG_imported_module
:
1872 /* FIXME: carlton/2002-10-16: Eventually, we should use the
1873 information contained in these. DW_TAG_imported_declaration
1874 dies shouldn't have children; DW_TAG_imported_module dies
1875 shouldn't in the C++ case, but conceivably could in the
1876 Fortran case, so we'll have to replace this gdb_assert if
1877 Fortran compilers start generating that info. */
1878 if (!processing_has_namespace_info
)
1880 processing_has_namespace_info
= 1;
1881 processing_current_namespace
= "";
1883 gdb_assert (die
->child
== NULL
);
1886 new_symbol (die
, NULL
, cu
);
1892 initialize_cu_func_list (void)
1894 cu_first_fn
= cu_last_fn
= cu_cached_fn
= NULL
;
1898 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
1900 struct objfile
*objfile
= cu
->objfile
;
1901 struct comp_unit_head
*cu_header
= &cu
->header
;
1902 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
1903 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1904 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1905 struct attribute
*attr
;
1906 char *name
= "<unknown>";
1907 char *comp_dir
= NULL
;
1908 struct die_info
*child_die
;
1909 bfd
*abfd
= objfile
->obfd
;
1910 struct line_header
*line_header
= 0;
1912 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
1914 if (die
->child
!= NULL
)
1916 child_die
= die
->child
;
1917 while (child_die
&& child_die
->tag
)
1919 if (child_die
->tag
== DW_TAG_subprogram
)
1921 CORE_ADDR low
, high
;
1923 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, cu
))
1925 lowpc
= min (lowpc
, low
);
1926 highpc
= max (highpc
, high
);
1929 child_die
= sibling_die (child_die
);
1934 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1935 from finish_block. */
1936 if (lowpc
== ((CORE_ADDR
) -1))
1941 attr
= dwarf_attr (die
, DW_AT_name
);
1944 name
= DW_STRING (attr
);
1946 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1949 comp_dir
= DW_STRING (attr
);
1952 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1953 directory, get rid of it. */
1954 char *cp
= strchr (comp_dir
, ':');
1956 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1961 if (objfile
->ei
.entry_point
>= lowpc
&&
1962 objfile
->ei
.entry_point
< highpc
)
1964 objfile
->ei
.deprecated_entry_file_lowpc
= lowpc
;
1965 objfile
->ei
.deprecated_entry_file_highpc
= highpc
;
1968 attr
= dwarf_attr (die
, DW_AT_language
);
1971 set_cu_language (DW_UNSND (attr
));
1974 /* We assume that we're processing GCC output. */
1975 processing_gcc_compilation
= 2;
1977 /* FIXME:Do something here. */
1978 if (dip
->at_producer
!= NULL
)
1980 handle_producer (dip
->at_producer
);
1984 /* The compilation unit may be in a different language or objfile,
1985 zero out all remembered fundamental types. */
1986 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1988 start_symtab (name
, comp_dir
, lowpc
);
1989 record_debugformat ("DWARF 2");
1991 initialize_cu_func_list ();
1993 /* Process all dies in compilation unit. */
1994 if (die
->child
!= NULL
)
1996 child_die
= die
->child
;
1997 while (child_die
&& child_die
->tag
)
1999 process_die (child_die
, cu
);
2000 child_die
= sibling_die (child_die
);
2004 /* Decode line number information if present. */
2005 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
2008 unsigned int line_offset
= DW_UNSND (attr
);
2009 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2012 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
2013 (void *) line_header
);
2014 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
);
2018 /* Decode macro information, if present. Dwarf 2 macro information
2019 refers to information in the line number info statement program
2020 header, so we can only read it if we've read the header
2022 attr
= dwarf_attr (die
, DW_AT_macro_info
);
2023 if (attr
&& line_header
)
2025 unsigned int macro_offset
= DW_UNSND (attr
);
2026 dwarf_decode_macros (line_header
, macro_offset
,
2027 comp_dir
, abfd
, cu
);
2029 do_cleanups (back_to
);
2033 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
)
2035 struct function_range
*thisfn
;
2037 thisfn
= (struct function_range
*)
2038 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct function_range
));
2039 thisfn
->name
= name
;
2040 thisfn
->lowpc
= lowpc
;
2041 thisfn
->highpc
= highpc
;
2042 thisfn
->seen_line
= 0;
2043 thisfn
->next
= NULL
;
2045 if (cu_last_fn
== NULL
)
2046 cu_first_fn
= thisfn
;
2048 cu_last_fn
->next
= thisfn
;
2050 cu_last_fn
= thisfn
;
2054 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2056 struct objfile
*objfile
= cu
->objfile
;
2057 struct context_stack
*new;
2060 struct die_info
*child_die
;
2061 struct attribute
*attr
;
2064 name
= dwarf2_linkage_name (die
);
2066 /* Ignore functions with missing or empty names and functions with
2067 missing or invalid low and high pc attributes. */
2068 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2074 /* Record the function range for dwarf_decode_lines. */
2075 add_to_cu_func_list (name
, lowpc
, highpc
);
2077 if (objfile
->ei
.entry_point
>= lowpc
&&
2078 objfile
->ei
.entry_point
< highpc
)
2080 objfile
->ei
.entry_func_lowpc
= lowpc
;
2081 objfile
->ei
.entry_func_highpc
= highpc
;
2084 new = push_context (0, lowpc
);
2085 new->name
= new_symbol (die
, die
->type
, cu
);
2087 /* If there is a location expression for DW_AT_frame_base, record
2089 attr
= dwarf_attr (die
, DW_AT_frame_base
);
2091 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
2093 list_in_scope
= &local_symbols
;
2095 if (die
->child
!= NULL
)
2097 child_die
= die
->child
;
2098 while (child_die
&& child_die
->tag
)
2100 process_die (child_die
, cu
);
2101 child_die
= sibling_die (child_die
);
2105 new = pop_context ();
2106 /* Make a block for the local symbols within. */
2107 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2108 lowpc
, highpc
, objfile
);
2110 /* In C++, we can have functions nested inside functions (e.g., when
2111 a function declares a class that has methods). This means that
2112 when we finish processing a function scope, we may need to go
2113 back to building a containing block's symbol lists. */
2114 local_symbols
= new->locals
;
2115 param_symbols
= new->params
;
2117 /* If we've finished processing a top-level function, subsequent
2118 symbols go in the file symbol list. */
2119 if (outermost_context_p ())
2120 list_in_scope
= &file_symbols
;
2123 /* Process all the DIES contained within a lexical block scope. Start
2124 a new scope, process the dies, and then close the scope. */
2127 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2129 struct objfile
*objfile
= cu
->objfile
;
2130 struct context_stack
*new;
2131 CORE_ADDR lowpc
, highpc
;
2132 struct die_info
*child_die
;
2134 /* Ignore blocks with missing or invalid low and high pc attributes. */
2135 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2136 as multiple lexical blocks? Handling children in a sane way would
2137 be nasty. Might be easier to properly extend generic blocks to
2139 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2144 push_context (0, lowpc
);
2145 if (die
->child
!= NULL
)
2147 child_die
= die
->child
;
2148 while (child_die
&& child_die
->tag
)
2150 process_die (child_die
, cu
);
2151 child_die
= sibling_die (child_die
);
2154 new = pop_context ();
2156 if (local_symbols
!= NULL
)
2158 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
2161 local_symbols
= new->locals
;
2164 /* Get low and high pc attributes from a die. Return 1 if the attributes
2165 are present and valid, otherwise, return 0. Return -1 if the range is
2166 discontinuous, i.e. derived from DW_AT_ranges information. */
2168 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
2169 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
2171 struct objfile
*objfile
= cu
->objfile
;
2172 struct comp_unit_head
*cu_header
= &cu
->header
;
2173 struct attribute
*attr
;
2174 bfd
*obfd
= objfile
->obfd
;
2179 attr
= dwarf_attr (die
, DW_AT_high_pc
);
2182 high
= DW_ADDR (attr
);
2183 attr
= dwarf_attr (die
, DW_AT_low_pc
);
2185 low
= DW_ADDR (attr
);
2187 /* Found high w/o low attribute. */
2190 /* Found consecutive range of addresses. */
2195 attr
= dwarf_attr (die
, DW_AT_ranges
);
2198 unsigned int addr_size
= cu_header
->addr_size
;
2199 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
2200 /* Value of the DW_AT_ranges attribute is the offset in the
2201 .debug_ranges section. */
2202 unsigned int offset
= DW_UNSND (attr
);
2203 /* Base address selection entry. */
2211 found_base
= cu_header
->base_known
;
2212 base
= cu_header
->base_address
;
2214 if (offset
>= dwarf_ranges_size
)
2216 complaint (&symfile_complaints
,
2217 "Offset %d out of bounds for DW_AT_ranges attribute",
2221 buffer
= dwarf_ranges_buffer
+ offset
;
2223 /* Read in the largest possible address. */
2224 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
2225 if ((marker
& mask
) == mask
)
2227 /* If we found the largest possible address, then
2228 read the base address. */
2229 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2230 buffer
+= 2 * addr_size
;
2231 offset
+= 2 * addr_size
;
2239 CORE_ADDR range_beginning
, range_end
;
2241 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
2242 buffer
+= addr_size
;
2243 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
2244 buffer
+= addr_size
;
2245 offset
+= 2 * addr_size
;
2247 /* An end of list marker is a pair of zero addresses. */
2248 if (range_beginning
== 0 && range_end
== 0)
2249 /* Found the end of list entry. */
2252 /* Each base address selection entry is a pair of 2 values.
2253 The first is the largest possible address, the second is
2254 the base address. Check for a base address here. */
2255 if ((range_beginning
& mask
) == mask
)
2257 /* If we found the largest possible address, then
2258 read the base address. */
2259 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2266 /* We have no valid base address for the ranges
2268 complaint (&symfile_complaints
,
2269 "Invalid .debug_ranges data (no base address)");
2273 range_beginning
+= base
;
2276 /* FIXME: This is recording everything as a low-high
2277 segment of consecutive addresses. We should have a
2278 data structure for discontiguous block ranges
2282 low
= range_beginning
;
2288 if (range_beginning
< low
)
2289 low
= range_beginning
;
2290 if (range_end
> high
)
2296 /* If the first entry is an end-of-list marker, the range
2297 describes an empty scope, i.e. no instructions. */
2307 /* When using the GNU linker, .gnu.linkonce. sections are used to
2308 eliminate duplicate copies of functions and vtables and such.
2309 The linker will arbitrarily choose one and discard the others.
2310 The AT_*_pc values for such functions refer to local labels in
2311 these sections. If the section from that file was discarded, the
2312 labels are not in the output, so the relocs get a value of 0.
2313 If this is a discarded function, mark the pc bounds as invalid,
2314 so that GDB will ignore it. */
2315 if (low
== 0 && (bfd_get_file_flags (obfd
) & HAS_RELOC
) == 0)
2323 /* Add an aggregate field to the field list. */
2326 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
2327 struct dwarf2_cu
*cu
)
2329 struct objfile
*objfile
= cu
->objfile
;
2330 struct nextfield
*new_field
;
2331 struct attribute
*attr
;
2333 char *fieldname
= "";
2335 /* Allocate a new field list entry and link it in. */
2336 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2337 make_cleanup (xfree
, new_field
);
2338 memset (new_field
, 0, sizeof (struct nextfield
));
2339 new_field
->next
= fip
->fields
;
2340 fip
->fields
= new_field
;
2343 /* Handle accessibility and virtuality of field.
2344 The default accessibility for members is public, the default
2345 accessibility for inheritance is private. */
2346 if (die
->tag
!= DW_TAG_inheritance
)
2347 new_field
->accessibility
= DW_ACCESS_public
;
2349 new_field
->accessibility
= DW_ACCESS_private
;
2350 new_field
->virtuality
= DW_VIRTUALITY_none
;
2352 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2354 new_field
->accessibility
= DW_UNSND (attr
);
2355 if (new_field
->accessibility
!= DW_ACCESS_public
)
2356 fip
->non_public_fields
= 1;
2357 attr
= dwarf_attr (die
, DW_AT_virtuality
);
2359 new_field
->virtuality
= DW_UNSND (attr
);
2361 fp
= &new_field
->field
;
2363 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
))
2365 /* Data member other than a C++ static data member. */
2367 /* Get type of field. */
2368 fp
->type
= die_type (die
, cu
);
2370 FIELD_STATIC_KIND (*fp
) = 0;
2372 /* Get bit size of field (zero if none). */
2373 attr
= dwarf_attr (die
, DW_AT_bit_size
);
2376 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
2380 FIELD_BITSIZE (*fp
) = 0;
2383 /* Get bit offset of field. */
2384 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2387 FIELD_BITPOS (*fp
) =
2388 decode_locdesc (DW_BLOCK (attr
), cu
) * bits_per_byte
;
2391 FIELD_BITPOS (*fp
) = 0;
2392 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
2395 if (BITS_BIG_ENDIAN
)
2397 /* For big endian bits, the DW_AT_bit_offset gives the
2398 additional bit offset from the MSB of the containing
2399 anonymous object to the MSB of the field. We don't
2400 have to do anything special since we don't need to
2401 know the size of the anonymous object. */
2402 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
2406 /* For little endian bits, compute the bit offset to the
2407 MSB of the anonymous object, subtract off the number of
2408 bits from the MSB of the field to the MSB of the
2409 object, and then subtract off the number of bits of
2410 the field itself. The result is the bit offset of
2411 the LSB of the field. */
2413 int bit_offset
= DW_UNSND (attr
);
2415 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2418 /* The size of the anonymous object containing
2419 the bit field is explicit, so use the
2420 indicated size (in bytes). */
2421 anonymous_size
= DW_UNSND (attr
);
2425 /* The size of the anonymous object containing
2426 the bit field must be inferred from the type
2427 attribute of the data member containing the
2429 anonymous_size
= TYPE_LENGTH (fp
->type
);
2431 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2432 - bit_offset
- FIELD_BITSIZE (*fp
);
2436 /* Get name of field. */
2437 attr
= dwarf_attr (die
, DW_AT_name
);
2438 if (attr
&& DW_STRING (attr
))
2439 fieldname
= DW_STRING (attr
);
2440 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
2441 &objfile
->type_obstack
);
2443 /* Change accessibility for artificial fields (e.g. virtual table
2444 pointer or virtual base class pointer) to private. */
2445 if (dwarf_attr (die
, DW_AT_artificial
))
2447 new_field
->accessibility
= DW_ACCESS_private
;
2448 fip
->non_public_fields
= 1;
2451 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
2453 /* C++ static member. */
2455 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2456 is a declaration, but all versions of G++ as of this writing
2457 (so through at least 3.2.1) incorrectly generate
2458 DW_TAG_variable tags. */
2462 /* Get name of field. */
2463 attr
= dwarf_attr (die
, DW_AT_name
);
2464 if (attr
&& DW_STRING (attr
))
2465 fieldname
= DW_STRING (attr
);
2469 /* Get physical name. */
2470 physname
= dwarf2_linkage_name (die
);
2472 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
2473 &objfile
->type_obstack
));
2474 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2475 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
2476 &objfile
->type_obstack
);
2478 else if (die
->tag
== DW_TAG_inheritance
)
2480 /* C++ base class field. */
2481 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2483 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
2485 FIELD_BITSIZE (*fp
) = 0;
2486 FIELD_STATIC_KIND (*fp
) = 0;
2487 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2488 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2489 fip
->nbaseclasses
++;
2493 /* Create the vector of fields, and attach it to the type. */
2496 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
2497 struct dwarf2_cu
*cu
)
2499 int nfields
= fip
->nfields
;
2501 /* Record the field count, allocate space for the array of fields,
2502 and create blank accessibility bitfields if necessary. */
2503 TYPE_NFIELDS (type
) = nfields
;
2504 TYPE_FIELDS (type
) = (struct field
*)
2505 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2506 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2508 if (fip
->non_public_fields
)
2510 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2512 TYPE_FIELD_PRIVATE_BITS (type
) =
2513 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2514 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2516 TYPE_FIELD_PROTECTED_BITS (type
) =
2517 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2518 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2520 TYPE_FIELD_IGNORE_BITS (type
) =
2521 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2522 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2525 /* If the type has baseclasses, allocate and clear a bit vector for
2526 TYPE_FIELD_VIRTUAL_BITS. */
2527 if (fip
->nbaseclasses
)
2529 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2532 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2533 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2534 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2535 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2536 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2539 /* Copy the saved-up fields into the field vector. Start from the head
2540 of the list, adding to the tail of the field array, so that they end
2541 up in the same order in the array in which they were added to the list. */
2542 while (nfields
-- > 0)
2544 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2545 switch (fip
->fields
->accessibility
)
2547 case DW_ACCESS_private
:
2548 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2551 case DW_ACCESS_protected
:
2552 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2555 case DW_ACCESS_public
:
2559 /* Unknown accessibility. Complain and treat it as public. */
2561 complaint (&symfile_complaints
, "unsupported accessibility %d",
2562 fip
->fields
->accessibility
);
2566 if (nfields
< fip
->nbaseclasses
)
2568 switch (fip
->fields
->virtuality
)
2570 case DW_VIRTUALITY_virtual
:
2571 case DW_VIRTUALITY_pure_virtual
:
2572 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2576 fip
->fields
= fip
->fields
->next
;
2580 /* Add a member function to the proper fieldlist. */
2583 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2584 struct type
*type
, struct dwarf2_cu
*cu
)
2586 struct objfile
*objfile
= cu
->objfile
;
2587 struct attribute
*attr
;
2588 struct fnfieldlist
*flp
;
2590 struct fn_field
*fnp
;
2593 struct nextfnfield
*new_fnfield
;
2595 /* Get name of member function. */
2596 attr
= dwarf_attr (die
, DW_AT_name
);
2597 if (attr
&& DW_STRING (attr
))
2598 fieldname
= DW_STRING (attr
);
2602 /* Get the mangled name. */
2603 physname
= dwarf2_linkage_name (die
);
2605 /* Look up member function name in fieldlist. */
2606 for (i
= 0; i
< fip
->nfnfields
; i
++)
2608 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
2612 /* Create new list element if necessary. */
2613 if (i
< fip
->nfnfields
)
2614 flp
= &fip
->fnfieldlists
[i
];
2617 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2619 fip
->fnfieldlists
= (struct fnfieldlist
*)
2620 xrealloc (fip
->fnfieldlists
,
2621 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2622 * sizeof (struct fnfieldlist
));
2623 if (fip
->nfnfields
== 0)
2624 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2626 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2627 flp
->name
= fieldname
;
2633 /* Create a new member function field and chain it to the field list
2635 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2636 make_cleanup (xfree
, new_fnfield
);
2637 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2638 new_fnfield
->next
= flp
->head
;
2639 flp
->head
= new_fnfield
;
2642 /* Fill in the member function field info. */
2643 fnp
= &new_fnfield
->fnfield
;
2644 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2645 &objfile
->type_obstack
);
2646 fnp
->type
= alloc_type (objfile
);
2647 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2649 int nparams
= TYPE_NFIELDS (die
->type
);
2651 /* TYPE is the domain of this method, and DIE->TYPE is the type
2652 of the method itself (TYPE_CODE_METHOD). */
2653 smash_to_method_type (fnp
->type
, type
,
2654 TYPE_TARGET_TYPE (die
->type
),
2655 TYPE_FIELDS (die
->type
),
2656 TYPE_NFIELDS (die
->type
),
2657 TYPE_VARARGS (die
->type
));
2659 /* Handle static member functions.
2660 Dwarf2 has no clean way to discern C++ static and non-static
2661 member functions. G++ helps GDB by marking the first
2662 parameter for non-static member functions (which is the
2663 this pointer) as artificial. We obtain this information
2664 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2665 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2666 fnp
->voffset
= VOFFSET_STATIC
;
2669 complaint (&symfile_complaints
, "member function type missing for '%s'",
2672 /* Get fcontext from DW_AT_containing_type if present. */
2673 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2674 fnp
->fcontext
= die_containing_type (die
, cu
);
2676 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2677 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2679 /* Get accessibility. */
2680 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2683 switch (DW_UNSND (attr
))
2685 case DW_ACCESS_private
:
2686 fnp
->is_private
= 1;
2688 case DW_ACCESS_protected
:
2689 fnp
->is_protected
= 1;
2694 /* Check for artificial methods. */
2695 attr
= dwarf_attr (die
, DW_AT_artificial
);
2696 if (attr
&& DW_UNSND (attr
) != 0)
2697 fnp
->is_artificial
= 1;
2699 /* Get index in virtual function table if it is a virtual member function. */
2700 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2703 /* Support the .debug_loc offsets */
2704 if (attr_form_is_block (attr
))
2706 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
2708 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
2710 dwarf2_complex_location_expr_complaint ();
2714 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
2720 /* Create the vector of member function fields, and attach it to the type. */
2723 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2724 struct dwarf2_cu
*cu
)
2726 struct fnfieldlist
*flp
;
2727 int total_length
= 0;
2730 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2731 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2732 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2734 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2736 struct nextfnfield
*nfp
= flp
->head
;
2737 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2740 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2741 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2742 fn_flp
->fn_fields
= (struct fn_field
*)
2743 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2744 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2745 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2747 total_length
+= flp
->length
;
2750 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2751 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2754 /* Called when we find the DIE that starts a structure or union scope
2755 (definition) to process all dies that define the members of the
2758 NOTE: we need to call struct_type regardless of whether or not the
2759 DIE has an at_name attribute, since it might be an anonymous
2760 structure or union. This gets the type entered into our set of
2763 However, if the structure is incomplete (an opaque struct/union)
2764 then suppress creating a symbol table entry for it since gdb only
2765 wants to find the one with the complete definition. Note that if
2766 it is complete, we just call new_symbol, which does it's own
2767 checking about whether the struct/union is anonymous or not (and
2768 suppresses creating a symbol table entry itself). */
2771 read_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2773 struct objfile
*objfile
= cu
->objfile
;
2775 struct attribute
*attr
;
2777 type
= alloc_type (objfile
);
2779 INIT_CPLUS_SPECIFIC (type
);
2780 attr
= dwarf_attr (die
, DW_AT_name
);
2781 if (attr
&& DW_STRING (attr
))
2783 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2784 strlen (DW_STRING (attr
)),
2785 &objfile
->type_obstack
);
2788 if (die
->tag
== DW_TAG_structure_type
)
2790 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2792 else if (die
->tag
== DW_TAG_union_type
)
2794 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2798 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2800 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2803 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2806 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2810 TYPE_LENGTH (type
) = 0;
2813 /* We need to add the type field to the die immediately so we don't
2814 infinitely recurse when dealing with pointers to the structure
2815 type within the structure itself. */
2818 if (die
->child
!= NULL
&& ! die_is_declaration (die
))
2820 struct field_info fi
;
2821 struct die_info
*child_die
;
2822 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2824 memset (&fi
, 0, sizeof (struct field_info
));
2826 child_die
= die
->child
;
2828 while (child_die
&& child_die
->tag
)
2830 if (child_die
->tag
== DW_TAG_member
2831 || child_die
->tag
== DW_TAG_variable
)
2833 /* NOTE: carlton/2002-11-05: A C++ static data member
2834 should be a DW_TAG_member that is a declaration, but
2835 all versions of G++ as of this writing (so through at
2836 least 3.2.1) incorrectly generate DW_TAG_variable
2837 tags for them instead. */
2838 dwarf2_add_field (&fi
, child_die
, cu
);
2840 else if (child_die
->tag
== DW_TAG_subprogram
)
2842 /* C++ member function. */
2843 process_die (child_die
, cu
);
2844 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
2846 else if (child_die
->tag
== DW_TAG_inheritance
)
2848 /* C++ base class field. */
2849 dwarf2_add_field (&fi
, child_die
, cu
);
2853 process_die (child_die
, cu
);
2855 child_die
= sibling_die (child_die
);
2858 /* Attach fields and member functions to the type. */
2860 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
2863 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
2865 /* Get the type which refers to the base class (possibly this
2866 class itself) which contains the vtable pointer for the current
2867 class from the DW_AT_containing_type attribute. */
2869 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2871 struct type
*t
= die_containing_type (die
, cu
);
2873 TYPE_VPTR_BASETYPE (type
) = t
;
2876 static const char vptr_name
[] =
2877 {'_', 'v', 'p', 't', 'r', '\0'};
2880 /* Our own class provides vtbl ptr. */
2881 for (i
= TYPE_NFIELDS (t
) - 1;
2882 i
>= TYPE_N_BASECLASSES (t
);
2885 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2887 if ((strncmp (fieldname
, vptr_name
,
2888 strlen (vptr_name
) - 1)
2890 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2892 TYPE_VPTR_FIELDNO (type
) = i
;
2897 /* Complain if virtual function table field not found. */
2898 if (i
< TYPE_N_BASECLASSES (t
))
2899 complaint (&symfile_complaints
,
2900 "virtual function table pointer not found when defining class '%s'",
2901 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
2906 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2911 new_symbol (die
, type
, cu
);
2913 do_cleanups (back_to
);
2917 /* No children, must be stub. */
2918 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2922 /* Given a pointer to a die which begins an enumeration, process all
2923 the dies that define the members of the enumeration.
2925 This will be much nicer in draft 6 of the DWARF spec when our
2926 members will be dies instead squished into the DW_AT_element_list
2929 NOTE: We reverse the order of the element list. */
2932 read_enumeration (struct die_info
*die
, struct dwarf2_cu
*cu
)
2934 struct objfile
*objfile
= cu
->objfile
;
2935 struct die_info
*child_die
;
2937 struct field
*fields
;
2938 struct attribute
*attr
;
2941 int unsigned_enum
= 1;
2943 type
= alloc_type (objfile
);
2945 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2946 attr
= dwarf_attr (die
, DW_AT_name
);
2947 if (attr
&& DW_STRING (attr
))
2949 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2950 strlen (DW_STRING (attr
)),
2951 &objfile
->type_obstack
);
2954 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2957 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2961 TYPE_LENGTH (type
) = 0;
2966 if (die
->child
!= NULL
)
2968 child_die
= die
->child
;
2969 while (child_die
&& child_die
->tag
)
2971 if (child_die
->tag
!= DW_TAG_enumerator
)
2973 process_die (child_die
, cu
);
2977 attr
= dwarf_attr (child_die
, DW_AT_name
);
2980 sym
= new_symbol (child_die
, type
, cu
);
2981 if (SYMBOL_VALUE (sym
) < 0)
2984 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2986 fields
= (struct field
*)
2988 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2989 * sizeof (struct field
));
2992 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
2993 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2994 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2995 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2996 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
3002 child_die
= sibling_die (child_die
);
3007 TYPE_NFIELDS (type
) = num_fields
;
3008 TYPE_FIELDS (type
) = (struct field
*)
3009 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
3010 memcpy (TYPE_FIELDS (type
), fields
,
3011 sizeof (struct field
) * num_fields
);
3015 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
3018 new_symbol (die
, type
, cu
);
3021 /* Extract all information from a DW_TAG_array_type DIE and put it in
3022 the DIE's type field. For now, this only handles one dimensional
3026 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3028 struct objfile
*objfile
= cu
->objfile
;
3029 struct die_info
*child_die
;
3030 struct type
*type
= NULL
;
3031 struct type
*element_type
, *range_type
, *index_type
;
3032 struct type
**range_types
= NULL
;
3033 struct attribute
*attr
;
3035 struct cleanup
*back_to
;
3037 /* Return if we've already decoded this type. */
3043 element_type
= die_type (die
, cu
);
3045 /* Irix 6.2 native cc creates array types without children for
3046 arrays with unspecified length. */
3047 if (die
->child
== NULL
)
3049 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
3050 range_type
= create_range_type (NULL
, index_type
, 0, -1);
3051 die
->type
= create_array_type (NULL
, element_type
, range_type
);
3055 back_to
= make_cleanup (null_cleanup
, NULL
);
3056 child_die
= die
->child
;
3057 while (child_die
&& child_die
->tag
)
3059 if (child_die
->tag
== DW_TAG_subrange_type
)
3061 unsigned int low
, high
;
3063 /* Default bounds to an array with unspecified length. */
3066 if (cu_language
== language_fortran
)
3068 /* FORTRAN implies a lower bound of 1, if not given. */
3072 index_type
= die_type (child_die
, cu
);
3073 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
3076 if (attr
->form
== DW_FORM_sdata
)
3078 low
= DW_SND (attr
);
3080 else if (attr
->form
== DW_FORM_udata
3081 || attr
->form
== DW_FORM_data1
3082 || attr
->form
== DW_FORM_data2
3083 || attr
->form
== DW_FORM_data4
3084 || attr
->form
== DW_FORM_data8
)
3086 low
= DW_UNSND (attr
);
3090 dwarf2_non_const_array_bound_ignored_complaint
3091 (dwarf_form_name (attr
->form
));
3095 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
3098 if (attr
->form
== DW_FORM_sdata
)
3100 high
= DW_SND (attr
);
3102 else if (attr
->form
== DW_FORM_udata
3103 || attr
->form
== DW_FORM_data1
3104 || attr
->form
== DW_FORM_data2
3105 || attr
->form
== DW_FORM_data4
3106 || attr
->form
== DW_FORM_data8
)
3108 high
= DW_UNSND (attr
);
3110 else if (attr
->form
== DW_FORM_block1
)
3112 /* GCC encodes arrays with unspecified or dynamic length
3113 with a DW_FORM_block1 attribute.
3114 FIXME: GDB does not yet know how to handle dynamic
3115 arrays properly, treat them as arrays with unspecified
3118 FIXME: jimb/2003-09-22: GDB does not really know
3119 how to handle arrays of unspecified length
3120 either; we just represent them as zero-length
3121 arrays. Choose an appropriate upper bound given
3122 the lower bound we've computed above. */
3127 dwarf2_non_const_array_bound_ignored_complaint
3128 (dwarf_form_name (attr
->form
));
3133 /* Create a range type and save it for array type creation. */
3134 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
3136 range_types
= (struct type
**)
3137 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
3138 * sizeof (struct type
*));
3140 make_cleanup (free_current_contents
, &range_types
);
3142 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
3144 child_die
= sibling_die (child_die
);
3147 /* Dwarf2 dimensions are output from left to right, create the
3148 necessary array types in backwards order. */
3149 type
= element_type
;
3151 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
3153 /* Understand Dwarf2 support for vector types (like they occur on
3154 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3155 array type. This is not part of the Dwarf2/3 standard yet, but a
3156 custom vendor extension. The main difference between a regular
3157 array and the vector variant is that vectors are passed by value
3159 attr
= dwarf_attr (die
, DW_AT_GNU_vector
);
3161 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
3163 do_cleanups (back_to
);
3165 /* Install the type in the die. */
3169 /* First cut: install each common block member as a global variable. */
3172 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
3174 struct die_info
*child_die
;
3175 struct attribute
*attr
;
3177 CORE_ADDR base
= (CORE_ADDR
) 0;
3179 attr
= dwarf_attr (die
, DW_AT_location
);
3182 /* Support the .debug_loc offsets */
3183 if (attr_form_is_block (attr
))
3185 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
3187 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3189 dwarf2_complex_location_expr_complaint ();
3193 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3194 "common block member");
3197 if (die
->child
!= NULL
)
3199 child_die
= die
->child
;
3200 while (child_die
&& child_die
->tag
)
3202 sym
= new_symbol (child_die
, NULL
, cu
);
3203 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
3206 SYMBOL_VALUE_ADDRESS (sym
) =
3207 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
3208 add_symbol_to_list (sym
, &global_symbols
);
3210 child_die
= sibling_die (child_die
);
3215 /* Read a C++ namespace. */
3218 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
3220 struct objfile
*objfile
= cu
->objfile
;
3221 const char *previous_namespace
= processing_current_namespace
;
3222 const char *name
= NULL
;
3224 struct die_info
*current_die
;
3226 /* Loop through the extensions until we find a name. */
3228 for (current_die
= die
;
3229 current_die
!= NULL
;
3230 current_die
= dwarf2_extension (die
))
3232 name
= dwarf2_name (current_die
);
3237 /* Is it an anonymous namespace? */
3239 is_anonymous
= (name
== NULL
);
3241 name
= "(anonymous namespace)";
3243 /* Now build the name of the current namespace. */
3245 if (previous_namespace
[0] == '\0')
3247 processing_current_namespace
= name
;
3251 /* We need temp_name around because processing_current_namespace
3252 is a const char *. */
3253 char *temp_name
= alloca (strlen (previous_namespace
)
3254 + 2 + strlen(name
) + 1);
3255 strcpy (temp_name
, previous_namespace
);
3256 strcat (temp_name
, "::");
3257 strcat (temp_name
, name
);
3259 processing_current_namespace
= temp_name
;
3262 /* Add a symbol associated to this if we haven't seen the namespace
3263 before. Also, add a using directive if it's an anonymous
3266 if (dwarf2_extension (die
) == NULL
)
3270 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
3271 this cast will hopefully become unnecessary. */
3272 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
3273 (char *) processing_current_namespace
,
3275 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
3277 new_symbol (die
, type
, cu
);
3280 cp_add_using_directive (processing_current_namespace
,
3281 strlen (previous_namespace
),
3282 strlen (processing_current_namespace
));
3285 if (die
->child
!= NULL
)
3287 struct die_info
*child_die
= die
->child
;
3289 while (child_die
&& child_die
->tag
)
3291 process_die (child_die
, cu
);
3292 child_die
= sibling_die (child_die
);
3296 processing_current_namespace
= previous_namespace
;
3299 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3300 the user defined type vector. */
3303 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3305 struct comp_unit_head
*cu_header
= &cu
->header
;
3307 struct attribute
*attr_byte_size
;
3308 struct attribute
*attr_address_class
;
3309 int byte_size
, addr_class
;
3316 type
= lookup_pointer_type (die_type (die
, cu
));
3318 attr_byte_size
= dwarf_attr (die
, DW_AT_byte_size
);
3320 byte_size
= DW_UNSND (attr_byte_size
);
3322 byte_size
= cu_header
->addr_size
;
3324 attr_address_class
= dwarf_attr (die
, DW_AT_address_class
);
3325 if (attr_address_class
)
3326 addr_class
= DW_UNSND (attr_address_class
);
3328 addr_class
= DW_ADDR_none
;
3330 /* If the pointer size or address class is different than the
3331 default, create a type variant marked as such and set the
3332 length accordingly. */
3333 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
3335 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3339 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
3340 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
3341 type
= make_type_with_address_space (type
, type_flags
);
3343 else if (TYPE_LENGTH (type
) != byte_size
)
3345 complaint (&symfile_complaints
, "invalid pointer size %d", byte_size
);
3348 /* Should we also complain about unhandled address classes? */
3352 TYPE_LENGTH (type
) = byte_size
;
3356 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3357 the user defined type vector. */
3360 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3362 struct objfile
*objfile
= cu
->objfile
;
3364 struct type
*to_type
;
3365 struct type
*domain
;
3372 type
= alloc_type (objfile
);
3373 to_type
= die_type (die
, cu
);
3374 domain
= die_containing_type (die
, cu
);
3375 smash_to_member_type (type
, domain
, to_type
);
3380 /* Extract all information from a DW_TAG_reference_type DIE and add to
3381 the user defined type vector. */
3384 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3386 struct comp_unit_head
*cu_header
= &cu
->header
;
3388 struct attribute
*attr
;
3395 type
= lookup_reference_type (die_type (die
, cu
));
3396 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3399 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3403 TYPE_LENGTH (type
) = cu_header
->addr_size
;
3409 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3411 struct type
*base_type
;
3418 base_type
= die_type (die
, cu
);
3419 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
3423 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3425 struct type
*base_type
;
3432 base_type
= die_type (die
, cu
);
3433 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
3436 /* Extract all information from a DW_TAG_string_type DIE and add to
3437 the user defined type vector. It isn't really a user defined type,
3438 but it behaves like one, with other DIE's using an AT_user_def_type
3439 attribute to reference it. */
3442 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3444 struct objfile
*objfile
= cu
->objfile
;
3445 struct type
*type
, *range_type
, *index_type
, *char_type
;
3446 struct attribute
*attr
;
3447 unsigned int length
;
3454 attr
= dwarf_attr (die
, DW_AT_string_length
);
3457 length
= DW_UNSND (attr
);
3461 /* check for the DW_AT_byte_size attribute */
3462 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3465 length
= DW_UNSND (attr
);
3472 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
3473 range_type
= create_range_type (NULL
, index_type
, 1, length
);
3474 if (cu_language
== language_fortran
)
3476 /* Need to create a unique string type for bounds
3478 type
= create_string_type (0, range_type
);
3482 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
3483 type
= create_string_type (char_type
, range_type
);
3488 /* Handle DIES due to C code like:
3492 int (*funcp)(int a, long l);
3496 ('funcp' generates a DW_TAG_subroutine_type DIE)
3500 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3502 struct type
*type
; /* Type that this function returns */
3503 struct type
*ftype
; /* Function that returns above type */
3504 struct attribute
*attr
;
3506 /* Decode the type that this subroutine returns */
3511 type
= die_type (die
, cu
);
3512 ftype
= lookup_function_type (type
);
3514 /* All functions in C++ have prototypes. */
3515 attr
= dwarf_attr (die
, DW_AT_prototyped
);
3516 if ((attr
&& (DW_UNSND (attr
) != 0))
3517 || cu_language
== language_cplus
)
3518 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
3520 if (die
->child
!= NULL
)
3522 struct die_info
*child_die
;
3526 /* Count the number of parameters.
3527 FIXME: GDB currently ignores vararg functions, but knows about
3528 vararg member functions. */
3529 child_die
= die
->child
;
3530 while (child_die
&& child_die
->tag
)
3532 if (child_die
->tag
== DW_TAG_formal_parameter
)
3534 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
3535 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
3536 child_die
= sibling_die (child_die
);
3539 /* Allocate storage for parameters and fill them in. */
3540 TYPE_NFIELDS (ftype
) = nparams
;
3541 TYPE_FIELDS (ftype
) = (struct field
*)
3542 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
3544 child_die
= die
->child
;
3545 while (child_die
&& child_die
->tag
)
3547 if (child_die
->tag
== DW_TAG_formal_parameter
)
3549 /* Dwarf2 has no clean way to discern C++ static and non-static
3550 member functions. G++ helps GDB by marking the first
3551 parameter for non-static member functions (which is the
3552 this pointer) as artificial. We pass this information
3553 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
3554 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
3556 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
3558 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
3559 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
3562 child_die
= sibling_die (child_die
);
3570 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
3572 struct objfile
*objfile
= cu
->objfile
;
3573 struct attribute
*attr
;
3578 attr
= dwarf_attr (die
, DW_AT_name
);
3579 if (attr
&& DW_STRING (attr
))
3581 name
= DW_STRING (attr
);
3583 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
3584 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, cu
);
3588 /* Find a representation of a given base type and install
3589 it in the TYPE field of the die. */
3592 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3594 struct objfile
*objfile
= cu
->objfile
;
3596 struct attribute
*attr
;
3597 int encoding
= 0, size
= 0;
3599 /* If we've already decoded this die, this is a no-op. */
3605 attr
= dwarf_attr (die
, DW_AT_encoding
);
3608 encoding
= DW_UNSND (attr
);
3610 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3613 size
= DW_UNSND (attr
);
3615 attr
= dwarf_attr (die
, DW_AT_name
);
3616 if (attr
&& DW_STRING (attr
))
3618 enum type_code code
= TYPE_CODE_INT
;
3623 case DW_ATE_address
:
3624 /* Turn DW_ATE_address into a void * pointer. */
3625 code
= TYPE_CODE_PTR
;
3626 type_flags
|= TYPE_FLAG_UNSIGNED
;
3628 case DW_ATE_boolean
:
3629 code
= TYPE_CODE_BOOL
;
3630 type_flags
|= TYPE_FLAG_UNSIGNED
;
3632 case DW_ATE_complex_float
:
3633 code
= TYPE_CODE_COMPLEX
;
3636 code
= TYPE_CODE_FLT
;
3639 case DW_ATE_signed_char
:
3641 case DW_ATE_unsigned
:
3642 case DW_ATE_unsigned_char
:
3643 type_flags
|= TYPE_FLAG_UNSIGNED
;
3646 complaint (&symfile_complaints
, "unsupported DW_AT_encoding: '%s'",
3647 dwarf_type_encoding_name (encoding
));
3650 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
3651 if (encoding
== DW_ATE_address
)
3652 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
3653 else if (encoding
== DW_ATE_complex_float
)
3656 TYPE_TARGET_TYPE (type
)
3657 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
3658 else if (size
== 16)
3659 TYPE_TARGET_TYPE (type
)
3660 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
3662 TYPE_TARGET_TYPE (type
)
3663 = dwarf2_fundamental_type (objfile
, FT_FLOAT
);
3668 type
= dwarf_base_type (encoding
, size
, cu
);
3673 /* Read a whole compilation unit into a linked list of dies. */
3675 static struct die_info
*
3676 read_comp_unit (char *info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
3678 /* Reset die reference table; we are
3679 building new ones now. */
3680 dwarf2_empty_hash_tables ();
3682 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
3685 /* Read a single die and all its descendents. Set the die's sibling
3686 field to NULL; set other fields in the die correctly, and set all
3687 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
3688 location of the info_ptr after reading all of those dies. PARENT
3689 is the parent of the die in question. */
3691 static struct die_info
*
3692 read_die_and_children (char *info_ptr
, bfd
*abfd
,
3693 struct dwarf2_cu
*cu
,
3694 char **new_info_ptr
,
3695 struct die_info
*parent
)
3697 struct die_info
*die
;
3701 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
3702 store_in_ref_table (die
->offset
, die
);
3706 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
3712 *new_info_ptr
= cur_ptr
;
3715 die
->sibling
= NULL
;
3716 die
->parent
= parent
;
3720 /* Read a die, all of its descendents, and all of its siblings; set
3721 all of the fields of all of the dies correctly. Arguments are as
3722 in read_die_and_children. */
3724 static struct die_info
*
3725 read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
3726 struct dwarf2_cu
*cu
,
3727 char **new_info_ptr
,
3728 struct die_info
*parent
)
3730 struct die_info
*first_die
, *last_sibling
;
3734 first_die
= last_sibling
= NULL
;
3738 struct die_info
*die
3739 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
3747 last_sibling
->sibling
= die
;
3752 *new_info_ptr
= cur_ptr
;
3762 /* Free a linked list of dies. */
3765 free_die_list (struct die_info
*dies
)
3767 struct die_info
*die
, *next
;
3772 if (die
->child
!= NULL
)
3773 free_die_list (die
->child
);
3774 next
= die
->sibling
;
3782 do_free_die_list_cleanup (void *dies
)
3784 free_die_list (dies
);
3787 static struct cleanup
*
3788 make_cleanup_free_die_list (struct die_info
*dies
)
3790 return make_cleanup (do_free_die_list_cleanup
, dies
);
3794 /* Read the contents of the section at OFFSET and of size SIZE from the
3795 object file specified by OBJFILE into the psymbol_obstack and return it. */
3798 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
3800 bfd
*abfd
= objfile
->obfd
;
3802 bfd_size_type size
= bfd_get_section_size_before_reloc (sectp
);
3807 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3809 = (char *) symfile_relocate_debug_section (abfd
, sectp
, (bfd_byte
*) buf
);
3813 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
3814 || bfd_bread (buf
, size
, abfd
) != size
)
3815 error ("Dwarf Error: Can't read DWARF data from '%s'",
3816 bfd_get_filename (abfd
));
3821 /* In DWARF version 2, the description of the debugging information is
3822 stored in a separate .debug_abbrev section. Before we read any
3823 dies from a section we read in all abbreviations and install them
3827 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
3829 struct comp_unit_head
*cu_header
= &cu
->header
;
3831 struct abbrev_info
*cur_abbrev
;
3832 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3833 unsigned int abbrev_form
, hash_number
;
3835 /* Initialize dwarf2 abbrevs */
3836 memset (cu_header
->dwarf2_abbrevs
, 0,
3837 ABBREV_HASH_SIZE
*sizeof (struct abbrev_info
*));
3839 abbrev_ptr
= dwarf_abbrev_buffer
+ cu_header
->abbrev_offset
;
3840 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3841 abbrev_ptr
+= bytes_read
;
3843 /* loop until we reach an abbrev number of 0 */
3844 while (abbrev_number
)
3846 cur_abbrev
= dwarf_alloc_abbrev ();
3848 /* read in abbrev header */
3849 cur_abbrev
->number
= abbrev_number
;
3850 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3851 abbrev_ptr
+= bytes_read
;
3852 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3855 /* now read in declarations */
3856 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3857 abbrev_ptr
+= bytes_read
;
3858 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3859 abbrev_ptr
+= bytes_read
;
3862 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3864 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3865 xrealloc (cur_abbrev
->attrs
,
3866 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3867 * sizeof (struct attr_abbrev
));
3869 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3870 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3871 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3872 abbrev_ptr
+= bytes_read
;
3873 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3874 abbrev_ptr
+= bytes_read
;
3877 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3878 cur_abbrev
->next
= cu_header
->dwarf2_abbrevs
[hash_number
];
3879 cu_header
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3881 /* Get next abbreviation.
3882 Under Irix6 the abbreviations for a compilation unit are not
3883 always properly terminated with an abbrev number of 0.
3884 Exit loop if we encounter an abbreviation which we have
3885 already read (which means we are about to read the abbreviations
3886 for the next compile unit) or if the end of the abbreviation
3887 table is reached. */
3888 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3889 >= dwarf_abbrev_size
)
3891 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3892 abbrev_ptr
+= bytes_read
;
3893 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
3898 /* Empty the abbrev table for a new compilation unit. */
3901 dwarf2_empty_abbrev_table (void *ptr_to_abbrevs_table
)
3904 struct abbrev_info
*abbrev
, *next
;
3905 struct abbrev_info
**abbrevs
;
3907 abbrevs
= (struct abbrev_info
**)ptr_to_abbrevs_table
;
3909 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3912 abbrev
= abbrevs
[i
];
3915 next
= abbrev
->next
;
3916 xfree (abbrev
->attrs
);
3924 /* Lookup an abbrev_info structure in the abbrev hash table. */
3926 static struct abbrev_info
*
3927 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
3929 struct comp_unit_head
*cu_header
= &cu
->header
;
3930 unsigned int hash_number
;
3931 struct abbrev_info
*abbrev
;
3933 hash_number
= number
% ABBREV_HASH_SIZE
;
3934 abbrev
= cu_header
->dwarf2_abbrevs
[hash_number
];
3938 if (abbrev
->number
== number
)
3941 abbrev
= abbrev
->next
;
3946 /* Read a minimal amount of information into the minimal die structure. */
3949 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3950 char *info_ptr
, struct dwarf2_cu
*cu
)
3952 unsigned int abbrev_number
, bytes_read
, i
;
3953 struct abbrev_info
*abbrev
;
3954 struct attribute attr
;
3955 struct attribute spec_attr
;
3956 int found_spec_attr
= 0;
3957 int has_low_pc_attr
= 0;
3958 int has_high_pc_attr
= 0;
3960 *part_die
= zeroed_partial_die
;
3961 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3962 info_ptr
+= bytes_read
;
3966 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
3969 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number
,
3970 bfd_get_filename (abfd
));
3972 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3973 part_die
->tag
= abbrev
->tag
;
3974 part_die
->has_children
= abbrev
->has_children
;
3975 part_die
->abbrev
= abbrev_number
;
3977 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3979 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
3981 /* Store the data if it is of an attribute we want to keep in a
3982 partial symbol table. */
3987 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3988 if (part_die
->name
== NULL
)
3989 part_die
->name
= DW_STRING (&attr
);
3991 case DW_AT_MIPS_linkage_name
:
3992 part_die
->name
= DW_STRING (&attr
);
3995 has_low_pc_attr
= 1;
3996 part_die
->lowpc
= DW_ADDR (&attr
);
3999 has_high_pc_attr
= 1;
4000 part_die
->highpc
= DW_ADDR (&attr
);
4002 case DW_AT_location
:
4003 /* Support the .debug_loc offsets */
4004 if (attr_form_is_block (&attr
))
4006 part_die
->locdesc
= DW_BLOCK (&attr
);
4008 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
4010 dwarf2_complex_location_expr_complaint ();
4014 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4015 "partial symbol information");
4018 case DW_AT_language
:
4019 part_die
->language
= DW_UNSND (&attr
);
4021 case DW_AT_external
:
4022 part_die
->is_external
= DW_UNSND (&attr
);
4024 case DW_AT_declaration
:
4025 part_die
->is_declaration
= DW_UNSND (&attr
);
4028 part_die
->has_type
= 1;
4030 case DW_AT_abstract_origin
:
4031 case DW_AT_specification
:
4032 found_spec_attr
= 1;
4036 /* Ignore absolute siblings, they might point outside of
4037 the current compile unit. */
4038 if (attr
.form
== DW_FORM_ref_addr
)
4039 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
4042 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
4049 /* If we found a reference attribute and the die has no name, try
4050 to find a name in the referred to die. */
4052 if (found_spec_attr
&& part_die
->name
== NULL
)
4054 struct partial_die_info spec_die
;
4057 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
4058 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu
);
4061 part_die
->name
= spec_die
.name
;
4063 /* Copy DW_AT_external attribute if it is set. */
4064 if (spec_die
.is_external
)
4065 part_die
->is_external
= spec_die
.is_external
;
4069 /* When using the GNU linker, .gnu.linkonce. sections are used to
4070 eliminate duplicate copies of functions and vtables and such.
4071 The linker will arbitrarily choose one and discard the others.
4072 The AT_*_pc values for such functions refer to local labels in
4073 these sections. If the section from that file was discarded, the
4074 labels are not in the output, so the relocs get a value of 0.
4075 If this is a discarded function, mark the pc bounds as invalid,
4076 so that GDB will ignore it. */
4077 if (has_low_pc_attr
&& has_high_pc_attr
4078 && part_die
->lowpc
< part_die
->highpc
4079 && (part_die
->lowpc
!= 0
4080 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
4081 part_die
->has_pc_info
= 1;
4085 /* Read the die from the .debug_info section buffer. Set DIEP to
4086 point to a newly allocated die with its information, except for its
4087 child, sibling, and parent fields. Set HAS_CHILDREN to tell
4088 whether the die has children or not. */
4091 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
4092 struct dwarf2_cu
*cu
, int *has_children
)
4094 unsigned int abbrev_number
, bytes_read
, i
, offset
;
4095 struct abbrev_info
*abbrev
;
4096 struct die_info
*die
;
4098 offset
= info_ptr
- dwarf_info_buffer
;
4099 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4100 info_ptr
+= bytes_read
;
4103 die
= dwarf_alloc_die ();
4105 die
->abbrev
= abbrev_number
;
4112 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4115 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
4117 bfd_get_filename (abfd
));
4119 die
= dwarf_alloc_die ();
4120 die
->offset
= offset
;
4121 die
->tag
= abbrev
->tag
;
4122 die
->abbrev
= abbrev_number
;
4125 die
->num_attrs
= abbrev
->num_attrs
;
4126 die
->attrs
= (struct attribute
*)
4127 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
4129 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4131 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
4132 abfd
, info_ptr
, cu
);
4136 *has_children
= abbrev
->has_children
;
4140 /* Read an attribute value described by an attribute form. */
4143 read_attribute_value (struct attribute
*attr
, unsigned form
,
4144 bfd
*abfd
, char *info_ptr
,
4145 struct dwarf2_cu
*cu
)
4147 struct comp_unit_head
*cu_header
= &cu
->header
;
4148 unsigned int bytes_read
;
4149 struct dwarf_block
*blk
;
4155 case DW_FORM_ref_addr
:
4156 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
4157 info_ptr
+= bytes_read
;
4159 case DW_FORM_block2
:
4160 blk
= dwarf_alloc_block ();
4161 blk
->size
= read_2_bytes (abfd
, info_ptr
);
4163 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4164 info_ptr
+= blk
->size
;
4165 DW_BLOCK (attr
) = blk
;
4167 case DW_FORM_block4
:
4168 blk
= dwarf_alloc_block ();
4169 blk
->size
= read_4_bytes (abfd
, info_ptr
);
4171 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4172 info_ptr
+= blk
->size
;
4173 DW_BLOCK (attr
) = blk
;
4176 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4180 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4184 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4187 case DW_FORM_string
:
4188 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
4189 info_ptr
+= bytes_read
;
4192 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
4194 info_ptr
+= bytes_read
;
4197 blk
= dwarf_alloc_block ();
4198 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4199 info_ptr
+= bytes_read
;
4200 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4201 info_ptr
+= blk
->size
;
4202 DW_BLOCK (attr
) = blk
;
4204 case DW_FORM_block1
:
4205 blk
= dwarf_alloc_block ();
4206 blk
->size
= read_1_byte (abfd
, info_ptr
);
4208 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4209 info_ptr
+= blk
->size
;
4210 DW_BLOCK (attr
) = blk
;
4213 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4217 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4221 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
4222 info_ptr
+= bytes_read
;
4225 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4226 info_ptr
+= bytes_read
;
4229 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4233 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4237 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4241 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4244 case DW_FORM_ref_udata
:
4245 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4246 info_ptr
+= bytes_read
;
4248 case DW_FORM_indirect
:
4249 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4250 info_ptr
+= bytes_read
;
4251 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
4254 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
4255 dwarf_form_name (form
),
4256 bfd_get_filename (abfd
));
4261 /* Read an attribute described by an abbreviated attribute. */
4264 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
4265 bfd
*abfd
, char *info_ptr
, struct dwarf2_cu
*cu
)
4267 attr
->name
= abbrev
->name
;
4268 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
4271 /* read dwarf information from a buffer */
4274 read_1_byte (bfd
*abfd
, char *buf
)
4276 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4280 read_1_signed_byte (bfd
*abfd
, char *buf
)
4282 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
4286 read_2_bytes (bfd
*abfd
, char *buf
)
4288 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4292 read_2_signed_bytes (bfd
*abfd
, char *buf
)
4294 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4298 read_4_bytes (bfd
*abfd
, char *buf
)
4300 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4304 read_4_signed_bytes (bfd
*abfd
, char *buf
)
4306 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4309 static unsigned long
4310 read_8_bytes (bfd
*abfd
, char *buf
)
4312 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4316 read_address (bfd
*abfd
, char *buf
, struct dwarf2_cu
*cu
, int *bytes_read
)
4318 struct comp_unit_head
*cu_header
= &cu
->header
;
4319 CORE_ADDR retval
= 0;
4321 if (cu_header
->signed_addr_p
)
4323 switch (cu_header
->addr_size
)
4326 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4329 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4332 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
4335 internal_error (__FILE__
, __LINE__
,
4336 "read_address: bad switch, signed [in module %s]",
4337 bfd_get_filename (abfd
));
4342 switch (cu_header
->addr_size
)
4345 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4348 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4351 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4354 internal_error (__FILE__
, __LINE__
,
4355 "read_address: bad switch, unsigned [in module %s]",
4356 bfd_get_filename (abfd
));
4360 *bytes_read
= cu_header
->addr_size
;
4364 /* Read the initial length from a section. The (draft) DWARF 3
4365 specification allows the initial length to take up either 4 bytes
4366 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
4367 bytes describe the length and all offsets will be 8 bytes in length
4370 An older, non-standard 64-bit format is also handled by this
4371 function. The older format in question stores the initial length
4372 as an 8-byte quantity without an escape value. Lengths greater
4373 than 2^32 aren't very common which means that the initial 4 bytes
4374 is almost always zero. Since a length value of zero doesn't make
4375 sense for the 32-bit format, this initial zero can be considered to
4376 be an escape value which indicates the presence of the older 64-bit
4377 format. As written, the code can't detect (old format) lengths
4378 greater than 4GB. If it becomes necessary to handle lengths somewhat
4379 larger than 4GB, we could allow other small values (such as the
4380 non-sensical values of 1, 2, and 3) to also be used as escape values
4381 indicating the presence of the old format.
4383 The value returned via bytes_read should be used to increment
4384 the relevant pointer after calling read_initial_length().
4386 As a side effect, this function sets the fields initial_length_size
4387 and offset_size in cu_header to the values appropriate for the
4388 length field. (The format of the initial length field determines
4389 the width of file offsets to be fetched later with fetch_offset().)
4391 [ Note: read_initial_length() and read_offset() are based on the
4392 document entitled "DWARF Debugging Information Format", revision
4393 3, draft 8, dated November 19, 2001. This document was obtained
4396 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
4398 This document is only a draft and is subject to change. (So beware.)
4400 Details regarding the older, non-standard 64-bit format were
4401 determined empirically by examining 64-bit ELF files produced
4402 by the SGI toolchain on an IRIX 6.5 machine.
4404 - Kevin, July 16, 2002
4408 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
4413 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4415 if (retval
== 0xffffffff)
4417 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
4419 if (cu_header
!= NULL
)
4421 cu_header
->initial_length_size
= 12;
4422 cu_header
->offset_size
= 8;
4425 else if (retval
== 0)
4427 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
4429 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4431 if (cu_header
!= NULL
)
4433 cu_header
->initial_length_size
= 8;
4434 cu_header
->offset_size
= 8;
4440 if (cu_header
!= NULL
)
4442 cu_header
->initial_length_size
= 4;
4443 cu_header
->offset_size
= 4;
4450 /* Read an offset from the data stream. The size of the offset is
4451 given by cu_header->offset_size. */
4454 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
4459 switch (cu_header
->offset_size
)
4462 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4466 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4470 internal_error (__FILE__
, __LINE__
,
4471 "read_offset: bad switch [in module %s]",
4472 bfd_get_filename (abfd
));
4479 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
4481 /* If the size of a host char is 8 bits, we can return a pointer
4482 to the buffer, otherwise we have to copy the data to a buffer
4483 allocated on the temporary obstack. */
4484 gdb_assert (HOST_CHAR_BIT
== 8);
4489 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4491 /* If the size of a host char is 8 bits, we can return a pointer
4492 to the string, otherwise we have to copy the string to a buffer
4493 allocated on the temporary obstack. */
4494 gdb_assert (HOST_CHAR_BIT
== 8);
4497 *bytes_read_ptr
= 1;
4500 *bytes_read_ptr
= strlen (buf
) + 1;
4505 read_indirect_string (bfd
*abfd
, char *buf
,
4506 const struct comp_unit_head
*cu_header
,
4507 unsigned int *bytes_read_ptr
)
4509 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
4510 (int *) bytes_read_ptr
);
4512 if (dwarf_str_buffer
== NULL
)
4514 error ("DW_FORM_strp used without .debug_str section [in module %s]",
4515 bfd_get_filename (abfd
));
4518 if (str_offset
>= dwarf_str_size
)
4520 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
4521 bfd_get_filename (abfd
));
4524 gdb_assert (HOST_CHAR_BIT
== 8);
4525 if (dwarf_str_buffer
[str_offset
] == '\0')
4527 return dwarf_str_buffer
+ str_offset
;
4530 static unsigned long
4531 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4533 unsigned long result
;
4534 unsigned int num_read
;
4544 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4547 result
|= ((unsigned long)(byte
& 127) << shift
);
4548 if ((byte
& 128) == 0)
4554 *bytes_read_ptr
= num_read
;
4559 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4562 int i
, shift
, size
, num_read
;
4572 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4575 result
|= ((long)(byte
& 127) << shift
);
4577 if ((byte
& 128) == 0)
4582 if ((shift
< size
) && (byte
& 0x40))
4584 result
|= -(1 << shift
);
4586 *bytes_read_ptr
= num_read
;
4591 set_cu_language (unsigned int lang
)
4597 cu_language
= language_c
;
4599 case DW_LANG_C_plus_plus
:
4600 cu_language
= language_cplus
;
4602 case DW_LANG_Fortran77
:
4603 case DW_LANG_Fortran90
:
4604 case DW_LANG_Fortran95
:
4605 cu_language
= language_fortran
;
4607 case DW_LANG_Mips_Assembler
:
4608 cu_language
= language_asm
;
4611 cu_language
= language_java
;
4615 case DW_LANG_Cobol74
:
4616 case DW_LANG_Cobol85
:
4617 case DW_LANG_Pascal83
:
4618 case DW_LANG_Modula2
:
4620 cu_language
= language_minimal
;
4623 cu_language_defn
= language_def (cu_language
);
4626 /* Return the named attribute or NULL if not there. */
4628 static struct attribute
*
4629 dwarf_attr (struct die_info
*die
, unsigned int name
)
4632 struct attribute
*spec
= NULL
;
4634 for (i
= 0; i
< die
->num_attrs
; ++i
)
4636 if (die
->attrs
[i
].name
== name
)
4638 return &die
->attrs
[i
];
4640 if (die
->attrs
[i
].name
== DW_AT_specification
4641 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
4642 spec
= &die
->attrs
[i
];
4646 struct die_info
*ref_die
=
4647 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
4650 return dwarf_attr (ref_die
, name
);
4657 die_is_declaration (struct die_info
*die
)
4659 return (dwarf_attr (die
, DW_AT_declaration
)
4660 && ! dwarf_attr (die
, DW_AT_specification
));
4664 /* Free the line_header structure *LH, and any arrays and strings it
4667 free_line_header (struct line_header
*lh
)
4669 if (lh
->standard_opcode_lengths
)
4670 xfree (lh
->standard_opcode_lengths
);
4672 /* Remember that all the lh->file_names[i].name pointers are
4673 pointers into debug_line_buffer, and don't need to be freed. */
4675 xfree (lh
->file_names
);
4677 /* Similarly for the include directory names. */
4678 if (lh
->include_dirs
)
4679 xfree (lh
->include_dirs
);
4685 /* Add an entry to LH's include directory table. */
4687 add_include_dir (struct line_header
*lh
, char *include_dir
)
4689 /* Grow the array if necessary. */
4690 if (lh
->include_dirs_size
== 0)
4692 lh
->include_dirs_size
= 1; /* for testing */
4693 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
4694 * sizeof (*lh
->include_dirs
));
4696 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
4698 lh
->include_dirs_size
*= 2;
4699 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
4700 (lh
->include_dirs_size
4701 * sizeof (*lh
->include_dirs
)));
4704 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
4708 /* Add an entry to LH's file name table. */
4710 add_file_name (struct line_header
*lh
,
4712 unsigned int dir_index
,
4713 unsigned int mod_time
,
4714 unsigned int length
)
4716 struct file_entry
*fe
;
4718 /* Grow the array if necessary. */
4719 if (lh
->file_names_size
== 0)
4721 lh
->file_names_size
= 1; /* for testing */
4722 lh
->file_names
= xmalloc (lh
->file_names_size
4723 * sizeof (*lh
->file_names
));
4725 else if (lh
->num_file_names
>= lh
->file_names_size
)
4727 lh
->file_names_size
*= 2;
4728 lh
->file_names
= xrealloc (lh
->file_names
,
4729 (lh
->file_names_size
4730 * sizeof (*lh
->file_names
)));
4733 fe
= &lh
->file_names
[lh
->num_file_names
++];
4735 fe
->dir_index
= dir_index
;
4736 fe
->mod_time
= mod_time
;
4737 fe
->length
= length
;
4741 /* Read the statement program header starting at OFFSET in
4742 dwarf_line_buffer, according to the endianness of ABFD. Return a
4743 pointer to a struct line_header, allocated using xmalloc.
4745 NOTE: the strings in the include directory and file name tables of
4746 the returned object point into debug_line_buffer, and must not be
4748 static struct line_header
*
4749 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
4750 struct dwarf2_cu
*cu
)
4752 struct cleanup
*back_to
;
4753 struct line_header
*lh
;
4757 char *cur_dir
, *cur_file
;
4759 if (dwarf_line_buffer
== NULL
)
4761 complaint (&symfile_complaints
, "missing .debug_line section");
4765 /* Make sure that at least there's room for the total_length field. That
4766 could be 12 bytes long, but we're just going to fudge that. */
4767 if (offset
+ 4 >= dwarf_line_size
)
4769 dwarf2_statement_list_fits_in_line_number_section_complaint ();
4773 lh
= xmalloc (sizeof (*lh
));
4774 memset (lh
, 0, sizeof (*lh
));
4775 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
4778 line_ptr
= dwarf_line_buffer
+ offset
;
4780 /* read in the header */
4781 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
4782 line_ptr
+= bytes_read
;
4783 if (line_ptr
+ lh
->total_length
> dwarf_line_buffer
+ dwarf_line_size
)
4785 dwarf2_statement_list_fits_in_line_number_section_complaint ();
4788 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
4789 lh
->version
= read_2_bytes (abfd
, line_ptr
);
4791 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
4792 line_ptr
+= bytes_read
;
4793 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
4795 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
4797 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
4799 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
4801 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
4803 lh
->standard_opcode_lengths
4804 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
4806 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
4807 for (i
= 1; i
< lh
->opcode_base
; ++i
)
4809 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
4813 /* Read directory table */
4814 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4816 line_ptr
+= bytes_read
;
4817 add_include_dir (lh
, cur_dir
);
4819 line_ptr
+= bytes_read
;
4821 /* Read file name table */
4822 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4824 unsigned int dir_index
, mod_time
, length
;
4826 line_ptr
+= bytes_read
;
4827 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4828 line_ptr
+= bytes_read
;
4829 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4830 line_ptr
+= bytes_read
;
4831 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4832 line_ptr
+= bytes_read
;
4834 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4836 line_ptr
+= bytes_read
;
4837 lh
->statement_program_start
= line_ptr
;
4839 if (line_ptr
> dwarf_line_buffer
+ dwarf_line_size
)
4840 complaint (&symfile_complaints
,
4841 "line number info header doesn't fit in `.debug_line' section");
4843 discard_cleanups (back_to
);
4847 /* This function exists to work around a bug in certain compilers
4848 (particularly GCC 2.95), in which the first line number marker of a
4849 function does not show up until after the prologue, right before
4850 the second line number marker. This function shifts ADDRESS down
4851 to the beginning of the function if necessary, and is called on
4852 addresses passed to record_line. */
4855 check_cu_functions (CORE_ADDR address
)
4857 struct function_range
*fn
;
4859 /* Find the function_range containing address. */
4864 cu_cached_fn
= cu_first_fn
;
4868 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4874 while (fn
&& fn
!= cu_cached_fn
)
4875 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4885 if (address
!= fn
->lowpc
)
4886 complaint (&symfile_complaints
,
4887 "misplaced first line number at 0x%lx for '%s'",
4888 (unsigned long) address
, fn
->name
);
4893 /* Decode the line number information for the compilation unit whose
4894 line number info is at OFFSET in the .debug_line section.
4895 The compilation directory of the file is passed in COMP_DIR. */
4898 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
4899 struct dwarf2_cu
*cu
)
4903 unsigned int bytes_read
;
4904 unsigned char op_code
, extended_op
, adj_opcode
;
4906 line_ptr
= lh
->statement_program_start
;
4907 line_end
= lh
->statement_program_end
;
4909 /* Read the statement sequences until there's nothing left. */
4910 while (line_ptr
< line_end
)
4912 /* state machine registers */
4913 CORE_ADDR address
= 0;
4914 unsigned int file
= 1;
4915 unsigned int line
= 1;
4916 unsigned int column
= 0;
4917 int is_stmt
= lh
->default_is_stmt
;
4918 int basic_block
= 0;
4919 int end_sequence
= 0;
4921 /* Start a subfile for the current file of the state machine. */
4922 if (lh
->num_file_names
>= file
)
4924 /* lh->include_dirs and lh->file_names are 0-based, but the
4925 directory and file name numbers in the statement program
4927 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
4930 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
4933 dwarf2_start_subfile (fe
->name
, dir
);
4936 /* Decode the table. */
4937 while (!end_sequence
)
4939 op_code
= read_1_byte (abfd
, line_ptr
);
4942 if (op_code
>= lh
->opcode_base
)
4943 { /* Special operand. */
4944 adj_opcode
= op_code
- lh
->opcode_base
;
4945 address
+= (adj_opcode
/ lh
->line_range
)
4946 * lh
->minimum_instruction_length
;
4947 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
4948 /* append row to matrix using current values */
4949 record_line (current_subfile
, line
,
4950 check_cu_functions (address
));
4953 else switch (op_code
)
4955 case DW_LNS_extended_op
:
4956 line_ptr
+= 1; /* ignore length */
4957 extended_op
= read_1_byte (abfd
, line_ptr
);
4959 switch (extended_op
)
4961 case DW_LNE_end_sequence
:
4963 record_line (current_subfile
, 0, address
);
4965 case DW_LNE_set_address
:
4966 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
4967 line_ptr
+= bytes_read
;
4968 address
+= baseaddr
;
4970 case DW_LNE_define_file
:
4973 unsigned int dir_index
, mod_time
, length
;
4975 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
4976 line_ptr
+= bytes_read
;
4978 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4979 line_ptr
+= bytes_read
;
4981 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4982 line_ptr
+= bytes_read
;
4984 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4985 line_ptr
+= bytes_read
;
4986 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4990 complaint (&symfile_complaints
,
4991 "mangled .debug_line section");
4996 record_line (current_subfile
, line
,
4997 check_cu_functions (address
));
5000 case DW_LNS_advance_pc
:
5001 address
+= lh
->minimum_instruction_length
5002 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5003 line_ptr
+= bytes_read
;
5005 case DW_LNS_advance_line
:
5006 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
5007 line_ptr
+= bytes_read
;
5009 case DW_LNS_set_file
:
5011 /* lh->include_dirs and lh->file_names are 0-based,
5012 but the directory and file name numbers in the
5013 statement program are 1-based. */
5014 struct file_entry
*fe
;
5016 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5017 line_ptr
+= bytes_read
;
5018 fe
= &lh
->file_names
[file
- 1];
5020 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
5023 dwarf2_start_subfile (fe
->name
, dir
);
5026 case DW_LNS_set_column
:
5027 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5028 line_ptr
+= bytes_read
;
5030 case DW_LNS_negate_stmt
:
5031 is_stmt
= (!is_stmt
);
5033 case DW_LNS_set_basic_block
:
5036 /* Add to the address register of the state machine the
5037 address increment value corresponding to special opcode
5038 255. Ie, this value is scaled by the minimum instruction
5039 length since special opcode 255 would have scaled the
5041 case DW_LNS_const_add_pc
:
5042 address
+= (lh
->minimum_instruction_length
5043 * ((255 - lh
->opcode_base
) / lh
->line_range
));
5045 case DW_LNS_fixed_advance_pc
:
5046 address
+= read_2_bytes (abfd
, line_ptr
);
5050 { /* Unknown standard opcode, ignore it. */
5052 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
5054 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5055 line_ptr
+= bytes_read
;
5063 /* Start a subfile for DWARF. FILENAME is the name of the file and
5064 DIRNAME the name of the source directory which contains FILENAME
5065 or NULL if not known.
5066 This routine tries to keep line numbers from identical absolute and
5067 relative file names in a common subfile.
5069 Using the `list' example from the GDB testsuite, which resides in
5070 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
5071 of /srcdir/list0.c yields the following debugging information for list0.c:
5073 DW_AT_name: /srcdir/list0.c
5074 DW_AT_comp_dir: /compdir
5075 files.files[0].name: list0.h
5076 files.files[0].dir: /srcdir
5077 files.files[1].name: list0.c
5078 files.files[1].dir: /srcdir
5080 The line number information for list0.c has to end up in a single
5081 subfile, so that `break /srcdir/list0.c:1' works as expected. */
5084 dwarf2_start_subfile (char *filename
, char *dirname
)
5086 /* If the filename isn't absolute, try to match an existing subfile
5087 with the full pathname. */
5089 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
5091 struct subfile
*subfile
;
5092 char *fullname
= concat (dirname
, "/", filename
, NULL
);
5094 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
5096 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
5098 current_subfile
= subfile
;
5105 start_subfile (filename
, dirname
);
5109 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
5110 struct dwarf2_cu
*cu
)
5112 struct objfile
*objfile
= cu
->objfile
;
5113 struct comp_unit_head
*cu_header
= &cu
->header
;
5115 /* NOTE drow/2003-01-30: There used to be a comment and some special
5116 code here to turn a symbol with DW_AT_external and a
5117 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
5118 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
5119 with some versions of binutils) where shared libraries could have
5120 relocations against symbols in their debug information - the
5121 minimal symbol would have the right address, but the debug info
5122 would not. It's no longer necessary, because we will explicitly
5123 apply relocations when we read in the debug information now. */
5125 /* A DW_AT_location attribute with no contents indicates that a
5126 variable has been optimized away. */
5127 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
5129 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
5133 /* Handle one degenerate form of location expression specially, to
5134 preserve GDB's previous behavior when section offsets are
5135 specified. If this is just a DW_OP_addr then mark this symbol
5138 if (attr_form_is_block (attr
)
5139 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
5140 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
5144 SYMBOL_VALUE_ADDRESS (sym
) =
5145 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
5146 fixup_symbol_section (sym
, objfile
);
5147 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
5148 SYMBOL_SECTION (sym
));
5149 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5153 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
5154 expression evaluator, and use LOC_COMPUTED only when necessary
5155 (i.e. when the value of a register or memory location is
5156 referenced, or a thread-local block, etc.). Then again, it might
5157 not be worthwhile. I'm assuming that it isn't unless performance
5158 or memory numbers show me otherwise. */
5160 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
5161 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
5164 /* Given a pointer to a DWARF information entry, figure out if we need
5165 to make a symbol table entry for it, and if so, create a new entry
5166 and return a pointer to it.
5167 If TYPE is NULL, determine symbol type from the die, otherwise
5168 used the passed type. */
5170 static struct symbol
*
5171 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
5173 struct objfile
*objfile
= cu
->objfile
;
5174 struct symbol
*sym
= NULL
;
5176 struct attribute
*attr
= NULL
;
5177 struct attribute
*attr2
= NULL
;
5179 if (die
->tag
!= DW_TAG_namespace
)
5180 name
= dwarf2_linkage_name (die
);
5182 name
= TYPE_NAME (type
);
5186 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
5187 sizeof (struct symbol
));
5188 OBJSTAT (objfile
, n_syms
++);
5189 memset (sym
, 0, sizeof (struct symbol
));
5191 /* Cache this symbol's name and the name's demangled form (if any). */
5192 SYMBOL_LANGUAGE (sym
) = cu_language
;
5193 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
5195 /* Default assumptions.
5196 Use the passed type or decode it from the die. */
5197 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5198 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5200 SYMBOL_TYPE (sym
) = type
;
5202 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
5203 attr
= dwarf_attr (die
, DW_AT_decl_line
);
5206 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
5211 attr
= dwarf_attr (die
, DW_AT_low_pc
);
5214 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
5216 SYMBOL_CLASS (sym
) = LOC_LABEL
;
5218 case DW_TAG_subprogram
:
5219 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
5221 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
5222 attr2
= dwarf_attr (die
, DW_AT_external
);
5223 if (attr2
&& (DW_UNSND (attr2
) != 0))
5225 add_symbol_to_list (sym
, &global_symbols
);
5229 add_symbol_to_list (sym
, list_in_scope
);
5232 case DW_TAG_variable
:
5233 /* Compilation with minimal debug info may result in variables
5234 with missing type entries. Change the misleading `void' type
5235 to something sensible. */
5236 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
5237 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
5238 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
5239 "<variable, no debug info>",
5241 attr
= dwarf_attr (die
, DW_AT_const_value
);
5244 dwarf2_const_value (attr
, sym
, cu
);
5245 attr2
= dwarf_attr (die
, DW_AT_external
);
5246 if (attr2
&& (DW_UNSND (attr2
) != 0))
5247 add_symbol_to_list (sym
, &global_symbols
);
5249 add_symbol_to_list (sym
, list_in_scope
);
5252 attr
= dwarf_attr (die
, DW_AT_location
);
5255 var_decode_location (attr
, sym
, cu
);
5256 attr2
= dwarf_attr (die
, DW_AT_external
);
5257 if (attr2
&& (DW_UNSND (attr2
) != 0))
5258 add_symbol_to_list (sym
, &global_symbols
);
5260 add_symbol_to_list (sym
, list_in_scope
);
5264 /* We do not know the address of this symbol.
5265 If it is an external symbol and we have type information
5266 for it, enter the symbol as a LOC_UNRESOLVED symbol.
5267 The address of the variable will then be determined from
5268 the minimal symbol table whenever the variable is
5270 attr2
= dwarf_attr (die
, DW_AT_external
);
5271 if (attr2
&& (DW_UNSND (attr2
) != 0)
5272 && dwarf_attr (die
, DW_AT_type
) != NULL
)
5274 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
5275 add_symbol_to_list (sym
, &global_symbols
);
5279 case DW_TAG_formal_parameter
:
5280 attr
= dwarf_attr (die
, DW_AT_location
);
5283 var_decode_location (attr
, sym
, cu
);
5284 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
5285 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
5286 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
5288 attr
= dwarf_attr (die
, DW_AT_const_value
);
5291 dwarf2_const_value (attr
, sym
, cu
);
5293 add_symbol_to_list (sym
, list_in_scope
);
5295 case DW_TAG_unspecified_parameters
:
5296 /* From varargs functions; gdb doesn't seem to have any
5297 interest in this information, so just ignore it for now.
5300 case DW_TAG_class_type
:
5301 case DW_TAG_structure_type
:
5302 case DW_TAG_union_type
:
5303 case DW_TAG_enumeration_type
:
5304 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5305 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
5306 add_symbol_to_list (sym
, list_in_scope
);
5308 /* The semantics of C++ state that "struct foo { ... }" also
5309 defines a typedef for "foo". Synthesize a typedef symbol so
5310 that "ptype foo" works as expected. */
5311 if (cu_language
== language_cplus
)
5313 struct symbol
*typedef_sym
= (struct symbol
*)
5314 obstack_alloc (&objfile
->symbol_obstack
,
5315 sizeof (struct symbol
));
5316 *typedef_sym
= *sym
;
5317 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
5318 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
5319 TYPE_NAME (SYMBOL_TYPE (sym
)) =
5320 obsavestring (DEPRECATED_SYMBOL_NAME (sym
),
5321 strlen (DEPRECATED_SYMBOL_NAME (sym
)),
5322 &objfile
->type_obstack
);
5323 add_symbol_to_list (typedef_sym
, list_in_scope
);
5326 case DW_TAG_typedef
:
5327 case DW_TAG_base_type
:
5328 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5329 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5330 add_symbol_to_list (sym
, list_in_scope
);
5332 case DW_TAG_enumerator
:
5333 attr
= dwarf_attr (die
, DW_AT_const_value
);
5336 dwarf2_const_value (attr
, sym
, cu
);
5338 add_symbol_to_list (sym
, list_in_scope
);
5340 case DW_TAG_namespace
:
5341 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5342 add_symbol_to_list (sym
, &global_symbols
);
5345 /* Not a tag we recognize. Hopefully we aren't processing
5346 trash data, but since we must specifically ignore things
5347 we don't recognize, there is nothing else we should do at
5349 complaint (&symfile_complaints
, "unsupported tag: '%s'",
5350 dwarf_tag_name (die
->tag
));
5357 /* Copy constant value from an attribute to a symbol. */
5360 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
5361 struct dwarf2_cu
*cu
)
5363 struct objfile
*objfile
= cu
->objfile
;
5364 struct comp_unit_head
*cu_header
= &cu
->header
;
5365 struct dwarf_block
*blk
;
5370 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
5371 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5372 cu_header
->addr_size
,
5373 TYPE_LENGTH (SYMBOL_TYPE
5375 SYMBOL_VALUE_BYTES (sym
) = (char *)
5376 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
5377 /* NOTE: cagney/2003-05-09: In-lined store_address call with
5378 it's body - store_unsigned_integer. */
5379 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
5381 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5383 case DW_FORM_block1
:
5384 case DW_FORM_block2
:
5385 case DW_FORM_block4
:
5387 blk
= DW_BLOCK (attr
);
5388 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
5389 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5391 TYPE_LENGTH (SYMBOL_TYPE
5393 SYMBOL_VALUE_BYTES (sym
) = (char *)
5394 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
5395 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
5396 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5399 /* The DW_AT_const_value attributes are supposed to carry the
5400 symbol's value "represented as it would be on the target
5401 architecture." By the time we get here, it's already been
5402 converted to host endianness, so we just need to sign- or
5403 zero-extend it as appropriate. */
5405 dwarf2_const_value_data (attr
, sym
, 8);
5408 dwarf2_const_value_data (attr
, sym
, 16);
5411 dwarf2_const_value_data (attr
, sym
, 32);
5414 dwarf2_const_value_data (attr
, sym
, 64);
5418 SYMBOL_VALUE (sym
) = DW_SND (attr
);
5419 SYMBOL_CLASS (sym
) = LOC_CONST
;
5423 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
5424 SYMBOL_CLASS (sym
) = LOC_CONST
;
5428 complaint (&symfile_complaints
,
5429 "unsupported const value attribute form: '%s'",
5430 dwarf_form_name (attr
->form
));
5431 SYMBOL_VALUE (sym
) = 0;
5432 SYMBOL_CLASS (sym
) = LOC_CONST
;
5438 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
5439 or zero-extend it as appropriate for the symbol's type. */
5441 dwarf2_const_value_data (struct attribute
*attr
,
5445 LONGEST l
= DW_UNSND (attr
);
5447 if (bits
< sizeof (l
) * 8)
5449 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
5450 l
&= ((LONGEST
) 1 << bits
) - 1;
5452 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
5455 SYMBOL_VALUE (sym
) = l
;
5456 SYMBOL_CLASS (sym
) = LOC_CONST
;
5460 /* Return the type of the die in question using its DW_AT_type attribute. */
5462 static struct type
*
5463 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5466 struct attribute
*type_attr
;
5467 struct die_info
*type_die
;
5470 type_attr
= dwarf_attr (die
, DW_AT_type
);
5473 /* A missing DW_AT_type represents a void type. */
5474 return dwarf2_fundamental_type (cu
->objfile
, FT_VOID
);
5478 ref
= dwarf2_get_ref_die_offset (type_attr
);
5479 type_die
= follow_die_ref (ref
);
5482 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
5483 ref
, cu
->objfile
->name
);
5487 type
= tag_type_to_type (type_die
, cu
);
5490 dump_die (type_die
);
5491 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
5497 /* Return the containing type of the die in question using its
5498 DW_AT_containing_type attribute. */
5500 static struct type
*
5501 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5503 struct type
*type
= NULL
;
5504 struct attribute
*type_attr
;
5505 struct die_info
*type_die
= NULL
;
5508 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
5511 ref
= dwarf2_get_ref_die_offset (type_attr
);
5512 type_die
= follow_die_ref (ref
);
5515 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref
,
5519 type
= tag_type_to_type (type_die
, cu
);
5524 dump_die (type_die
);
5525 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
5532 static struct type
*
5533 type_at_offset (unsigned int offset
, struct dwarf2_cu
*cu
)
5535 struct die_info
*die
;
5538 die
= follow_die_ref (offset
);
5541 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
5544 type
= tag_type_to_type (die
, cu
);
5549 static struct type
*
5550 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5558 read_type_die (die
, cu
);
5562 error ("Dwarf Error: Cannot find type of die [in module %s]",
5570 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
5574 case DW_TAG_class_type
:
5575 case DW_TAG_structure_type
:
5576 case DW_TAG_union_type
:
5577 read_structure_scope (die
, cu
);
5579 case DW_TAG_enumeration_type
:
5580 read_enumeration (die
, cu
);
5582 case DW_TAG_subprogram
:
5583 case DW_TAG_subroutine_type
:
5584 read_subroutine_type (die
, cu
);
5586 case DW_TAG_array_type
:
5587 read_array_type (die
, cu
);
5589 case DW_TAG_pointer_type
:
5590 read_tag_pointer_type (die
, cu
);
5592 case DW_TAG_ptr_to_member_type
:
5593 read_tag_ptr_to_member_type (die
, cu
);
5595 case DW_TAG_reference_type
:
5596 read_tag_reference_type (die
, cu
);
5598 case DW_TAG_const_type
:
5599 read_tag_const_type (die
, cu
);
5601 case DW_TAG_volatile_type
:
5602 read_tag_volatile_type (die
, cu
);
5604 case DW_TAG_string_type
:
5605 read_tag_string_type (die
, cu
);
5607 case DW_TAG_typedef
:
5608 read_typedef (die
, cu
);
5610 case DW_TAG_base_type
:
5611 read_base_type (die
, cu
);
5614 complaint (&symfile_complaints
, "unexepected tag in read_type_die: '%s'",
5615 dwarf_tag_name (die
->tag
));
5620 static struct type
*
5621 dwarf_base_type (int encoding
, int size
, struct dwarf2_cu
*cu
)
5623 struct objfile
*objfile
= cu
->objfile
;
5625 /* FIXME - this should not produce a new (struct type *)
5626 every time. It should cache base types. */
5630 case DW_ATE_address
:
5631 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
5633 case DW_ATE_boolean
:
5634 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
5636 case DW_ATE_complex_float
:
5639 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
5643 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
5649 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
5653 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
5660 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5663 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
5667 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5671 case DW_ATE_signed_char
:
5672 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5674 case DW_ATE_unsigned
:
5678 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5681 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
5685 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
5689 case DW_ATE_unsigned_char
:
5690 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5693 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5700 copy_die (struct die_info
*old_die
)
5702 struct die_info
*new_die
;
5705 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5706 memset (new_die
, 0, sizeof (struct die_info
));
5708 new_die
->tag
= old_die
->tag
;
5709 new_die
->has_children
= old_die
->has_children
;
5710 new_die
->abbrev
= old_die
->abbrev
;
5711 new_die
->offset
= old_die
->offset
;
5712 new_die
->type
= NULL
;
5714 num_attrs
= old_die
->num_attrs
;
5715 new_die
->num_attrs
= num_attrs
;
5716 new_die
->attrs
= (struct attribute
*)
5717 xmalloc (num_attrs
* sizeof (struct attribute
));
5719 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
5721 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
5722 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
5723 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
5726 new_die
->next
= NULL
;
5731 /* Return sibling of die, NULL if no sibling. */
5733 static struct die_info
*
5734 sibling_die (struct die_info
*die
)
5736 return die
->sibling
;
5739 /* Get linkage name of a die, return NULL if not found. */
5742 dwarf2_linkage_name (struct die_info
*die
)
5744 struct attribute
*attr
;
5746 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
5747 if (attr
&& DW_STRING (attr
))
5748 return DW_STRING (attr
);
5749 attr
= dwarf_attr (die
, DW_AT_name
);
5750 if (attr
&& DW_STRING (attr
))
5751 return DW_STRING (attr
);
5755 /* Get name of a die, return NULL if not found. */
5758 dwarf2_name (struct die_info
*die
)
5760 struct attribute
*attr
;
5762 attr
= dwarf_attr (die
, DW_AT_name
);
5763 if (attr
&& DW_STRING (attr
))
5764 return DW_STRING (attr
);
5768 /* Return the die that this die in an extension of, or NULL if there
5771 static struct die_info
*
5772 dwarf2_extension (struct die_info
*die
)
5774 struct attribute
*attr
;
5775 struct die_info
*extension_die
;
5778 attr
= dwarf_attr (die
, DW_AT_extension
);
5782 ref
= dwarf2_get_ref_die_offset (attr
);
5783 extension_die
= follow_die_ref (ref
);
5786 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
5789 return extension_die
;
5792 /* Convert a DIE tag into its string name. */
5795 dwarf_tag_name (unsigned tag
)
5799 case DW_TAG_padding
:
5800 return "DW_TAG_padding";
5801 case DW_TAG_array_type
:
5802 return "DW_TAG_array_type";
5803 case DW_TAG_class_type
:
5804 return "DW_TAG_class_type";
5805 case DW_TAG_entry_point
:
5806 return "DW_TAG_entry_point";
5807 case DW_TAG_enumeration_type
:
5808 return "DW_TAG_enumeration_type";
5809 case DW_TAG_formal_parameter
:
5810 return "DW_TAG_formal_parameter";
5811 case DW_TAG_imported_declaration
:
5812 return "DW_TAG_imported_declaration";
5814 return "DW_TAG_label";
5815 case DW_TAG_lexical_block
:
5816 return "DW_TAG_lexical_block";
5818 return "DW_TAG_member";
5819 case DW_TAG_pointer_type
:
5820 return "DW_TAG_pointer_type";
5821 case DW_TAG_reference_type
:
5822 return "DW_TAG_reference_type";
5823 case DW_TAG_compile_unit
:
5824 return "DW_TAG_compile_unit";
5825 case DW_TAG_string_type
:
5826 return "DW_TAG_string_type";
5827 case DW_TAG_structure_type
:
5828 return "DW_TAG_structure_type";
5829 case DW_TAG_subroutine_type
:
5830 return "DW_TAG_subroutine_type";
5831 case DW_TAG_typedef
:
5832 return "DW_TAG_typedef";
5833 case DW_TAG_union_type
:
5834 return "DW_TAG_union_type";
5835 case DW_TAG_unspecified_parameters
:
5836 return "DW_TAG_unspecified_parameters";
5837 case DW_TAG_variant
:
5838 return "DW_TAG_variant";
5839 case DW_TAG_common_block
:
5840 return "DW_TAG_common_block";
5841 case DW_TAG_common_inclusion
:
5842 return "DW_TAG_common_inclusion";
5843 case DW_TAG_inheritance
:
5844 return "DW_TAG_inheritance";
5845 case DW_TAG_inlined_subroutine
:
5846 return "DW_TAG_inlined_subroutine";
5848 return "DW_TAG_module";
5849 case DW_TAG_ptr_to_member_type
:
5850 return "DW_TAG_ptr_to_member_type";
5851 case DW_TAG_set_type
:
5852 return "DW_TAG_set_type";
5853 case DW_TAG_subrange_type
:
5854 return "DW_TAG_subrange_type";
5855 case DW_TAG_with_stmt
:
5856 return "DW_TAG_with_stmt";
5857 case DW_TAG_access_declaration
:
5858 return "DW_TAG_access_declaration";
5859 case DW_TAG_base_type
:
5860 return "DW_TAG_base_type";
5861 case DW_TAG_catch_block
:
5862 return "DW_TAG_catch_block";
5863 case DW_TAG_const_type
:
5864 return "DW_TAG_const_type";
5865 case DW_TAG_constant
:
5866 return "DW_TAG_constant";
5867 case DW_TAG_enumerator
:
5868 return "DW_TAG_enumerator";
5869 case DW_TAG_file_type
:
5870 return "DW_TAG_file_type";
5872 return "DW_TAG_friend";
5873 case DW_TAG_namelist
:
5874 return "DW_TAG_namelist";
5875 case DW_TAG_namelist_item
:
5876 return "DW_TAG_namelist_item";
5877 case DW_TAG_packed_type
:
5878 return "DW_TAG_packed_type";
5879 case DW_TAG_subprogram
:
5880 return "DW_TAG_subprogram";
5881 case DW_TAG_template_type_param
:
5882 return "DW_TAG_template_type_param";
5883 case DW_TAG_template_value_param
:
5884 return "DW_TAG_template_value_param";
5885 case DW_TAG_thrown_type
:
5886 return "DW_TAG_thrown_type";
5887 case DW_TAG_try_block
:
5888 return "DW_TAG_try_block";
5889 case DW_TAG_variant_part
:
5890 return "DW_TAG_variant_part";
5891 case DW_TAG_variable
:
5892 return "DW_TAG_variable";
5893 case DW_TAG_volatile_type
:
5894 return "DW_TAG_volatile_type";
5895 case DW_TAG_dwarf_procedure
:
5896 return "DW_TAG_dwarf_procedure";
5897 case DW_TAG_restrict_type
:
5898 return "DW_TAG_restrict_type";
5899 case DW_TAG_interface_type
:
5900 return "DW_TAG_interface_type";
5901 case DW_TAG_namespace
:
5902 return "DW_TAG_namespace";
5903 case DW_TAG_imported_module
:
5904 return "DW_TAG_imported_module";
5905 case DW_TAG_unspecified_type
:
5906 return "DW_TAG_unspecified_type";
5907 case DW_TAG_partial_unit
:
5908 return "DW_TAG_partial_unit";
5909 case DW_TAG_imported_unit
:
5910 return "DW_TAG_imported_unit";
5911 case DW_TAG_MIPS_loop
:
5912 return "DW_TAG_MIPS_loop";
5913 case DW_TAG_format_label
:
5914 return "DW_TAG_format_label";
5915 case DW_TAG_function_template
:
5916 return "DW_TAG_function_template";
5917 case DW_TAG_class_template
:
5918 return "DW_TAG_class_template";
5920 return "DW_TAG_<unknown>";
5924 /* Convert a DWARF attribute code into its string name. */
5927 dwarf_attr_name (unsigned attr
)
5932 return "DW_AT_sibling";
5933 case DW_AT_location
:
5934 return "DW_AT_location";
5936 return "DW_AT_name";
5937 case DW_AT_ordering
:
5938 return "DW_AT_ordering";
5939 case DW_AT_subscr_data
:
5940 return "DW_AT_subscr_data";
5941 case DW_AT_byte_size
:
5942 return "DW_AT_byte_size";
5943 case DW_AT_bit_offset
:
5944 return "DW_AT_bit_offset";
5945 case DW_AT_bit_size
:
5946 return "DW_AT_bit_size";
5947 case DW_AT_element_list
:
5948 return "DW_AT_element_list";
5949 case DW_AT_stmt_list
:
5950 return "DW_AT_stmt_list";
5952 return "DW_AT_low_pc";
5954 return "DW_AT_high_pc";
5955 case DW_AT_language
:
5956 return "DW_AT_language";
5958 return "DW_AT_member";
5960 return "DW_AT_discr";
5961 case DW_AT_discr_value
:
5962 return "DW_AT_discr_value";
5963 case DW_AT_visibility
:
5964 return "DW_AT_visibility";
5966 return "DW_AT_import";
5967 case DW_AT_string_length
:
5968 return "DW_AT_string_length";
5969 case DW_AT_common_reference
:
5970 return "DW_AT_common_reference";
5971 case DW_AT_comp_dir
:
5972 return "DW_AT_comp_dir";
5973 case DW_AT_const_value
:
5974 return "DW_AT_const_value";
5975 case DW_AT_containing_type
:
5976 return "DW_AT_containing_type";
5977 case DW_AT_default_value
:
5978 return "DW_AT_default_value";
5980 return "DW_AT_inline";
5981 case DW_AT_is_optional
:
5982 return "DW_AT_is_optional";
5983 case DW_AT_lower_bound
:
5984 return "DW_AT_lower_bound";
5985 case DW_AT_producer
:
5986 return "DW_AT_producer";
5987 case DW_AT_prototyped
:
5988 return "DW_AT_prototyped";
5989 case DW_AT_return_addr
:
5990 return "DW_AT_return_addr";
5991 case DW_AT_start_scope
:
5992 return "DW_AT_start_scope";
5993 case DW_AT_stride_size
:
5994 return "DW_AT_stride_size";
5995 case DW_AT_upper_bound
:
5996 return "DW_AT_upper_bound";
5997 case DW_AT_abstract_origin
:
5998 return "DW_AT_abstract_origin";
5999 case DW_AT_accessibility
:
6000 return "DW_AT_accessibility";
6001 case DW_AT_address_class
:
6002 return "DW_AT_address_class";
6003 case DW_AT_artificial
:
6004 return "DW_AT_artificial";
6005 case DW_AT_base_types
:
6006 return "DW_AT_base_types";
6007 case DW_AT_calling_convention
:
6008 return "DW_AT_calling_convention";
6010 return "DW_AT_count";
6011 case DW_AT_data_member_location
:
6012 return "DW_AT_data_member_location";
6013 case DW_AT_decl_column
:
6014 return "DW_AT_decl_column";
6015 case DW_AT_decl_file
:
6016 return "DW_AT_decl_file";
6017 case DW_AT_decl_line
:
6018 return "DW_AT_decl_line";
6019 case DW_AT_declaration
:
6020 return "DW_AT_declaration";
6021 case DW_AT_discr_list
:
6022 return "DW_AT_discr_list";
6023 case DW_AT_encoding
:
6024 return "DW_AT_encoding";
6025 case DW_AT_external
:
6026 return "DW_AT_external";
6027 case DW_AT_frame_base
:
6028 return "DW_AT_frame_base";
6030 return "DW_AT_friend";
6031 case DW_AT_identifier_case
:
6032 return "DW_AT_identifier_case";
6033 case DW_AT_macro_info
:
6034 return "DW_AT_macro_info";
6035 case DW_AT_namelist_items
:
6036 return "DW_AT_namelist_items";
6037 case DW_AT_priority
:
6038 return "DW_AT_priority";
6040 return "DW_AT_segment";
6041 case DW_AT_specification
:
6042 return "DW_AT_specification";
6043 case DW_AT_static_link
:
6044 return "DW_AT_static_link";
6046 return "DW_AT_type";
6047 case DW_AT_use_location
:
6048 return "DW_AT_use_location";
6049 case DW_AT_variable_parameter
:
6050 return "DW_AT_variable_parameter";
6051 case DW_AT_virtuality
:
6052 return "DW_AT_virtuality";
6053 case DW_AT_vtable_elem_location
:
6054 return "DW_AT_vtable_elem_location";
6055 case DW_AT_allocated
:
6056 return "DW_AT_allocated";
6057 case DW_AT_associated
:
6058 return "DW_AT_associated";
6059 case DW_AT_data_location
:
6060 return "DW_AT_data_location";
6062 return "DW_AT_stride";
6063 case DW_AT_entry_pc
:
6064 return "DW_AT_entry_pc";
6065 case DW_AT_use_UTF8
:
6066 return "DW_AT_use_UTF8";
6067 case DW_AT_extension
:
6068 return "DW_AT_extension";
6070 return "DW_AT_ranges";
6071 case DW_AT_trampoline
:
6072 return "DW_AT_trampoline";
6073 case DW_AT_call_column
:
6074 return "DW_AT_call_column";
6075 case DW_AT_call_file
:
6076 return "DW_AT_call_file";
6077 case DW_AT_call_line
:
6078 return "DW_AT_call_line";
6080 case DW_AT_MIPS_fde
:
6081 return "DW_AT_MIPS_fde";
6082 case DW_AT_MIPS_loop_begin
:
6083 return "DW_AT_MIPS_loop_begin";
6084 case DW_AT_MIPS_tail_loop_begin
:
6085 return "DW_AT_MIPS_tail_loop_begin";
6086 case DW_AT_MIPS_epilog_begin
:
6087 return "DW_AT_MIPS_epilog_begin";
6088 case DW_AT_MIPS_loop_unroll_factor
:
6089 return "DW_AT_MIPS_loop_unroll_factor";
6090 case DW_AT_MIPS_software_pipeline_depth
:
6091 return "DW_AT_MIPS_software_pipeline_depth";
6093 case DW_AT_MIPS_linkage_name
:
6094 return "DW_AT_MIPS_linkage_name";
6096 case DW_AT_sf_names
:
6097 return "DW_AT_sf_names";
6098 case DW_AT_src_info
:
6099 return "DW_AT_src_info";
6100 case DW_AT_mac_info
:
6101 return "DW_AT_mac_info";
6102 case DW_AT_src_coords
:
6103 return "DW_AT_src_coords";
6104 case DW_AT_body_begin
:
6105 return "DW_AT_body_begin";
6106 case DW_AT_body_end
:
6107 return "DW_AT_body_end";
6108 case DW_AT_GNU_vector
:
6109 return "DW_AT_GNU_vector";
6111 return "DW_AT_<unknown>";
6115 /* Convert a DWARF value form code into its string name. */
6118 dwarf_form_name (unsigned form
)
6123 return "DW_FORM_addr";
6124 case DW_FORM_block2
:
6125 return "DW_FORM_block2";
6126 case DW_FORM_block4
:
6127 return "DW_FORM_block4";
6129 return "DW_FORM_data2";
6131 return "DW_FORM_data4";
6133 return "DW_FORM_data8";
6134 case DW_FORM_string
:
6135 return "DW_FORM_string";
6137 return "DW_FORM_block";
6138 case DW_FORM_block1
:
6139 return "DW_FORM_block1";
6141 return "DW_FORM_data1";
6143 return "DW_FORM_flag";
6145 return "DW_FORM_sdata";
6147 return "DW_FORM_strp";
6149 return "DW_FORM_udata";
6150 case DW_FORM_ref_addr
:
6151 return "DW_FORM_ref_addr";
6153 return "DW_FORM_ref1";
6155 return "DW_FORM_ref2";
6157 return "DW_FORM_ref4";
6159 return "DW_FORM_ref8";
6160 case DW_FORM_ref_udata
:
6161 return "DW_FORM_ref_udata";
6162 case DW_FORM_indirect
:
6163 return "DW_FORM_indirect";
6165 return "DW_FORM_<unknown>";
6169 /* Convert a DWARF stack opcode into its string name. */
6172 dwarf_stack_op_name (unsigned op
)
6177 return "DW_OP_addr";
6179 return "DW_OP_deref";
6181 return "DW_OP_const1u";
6183 return "DW_OP_const1s";
6185 return "DW_OP_const2u";
6187 return "DW_OP_const2s";
6189 return "DW_OP_const4u";
6191 return "DW_OP_const4s";
6193 return "DW_OP_const8u";
6195 return "DW_OP_const8s";
6197 return "DW_OP_constu";
6199 return "DW_OP_consts";
6203 return "DW_OP_drop";
6205 return "DW_OP_over";
6207 return "DW_OP_pick";
6209 return "DW_OP_swap";
6213 return "DW_OP_xderef";
6221 return "DW_OP_minus";
6233 return "DW_OP_plus";
6234 case DW_OP_plus_uconst
:
6235 return "DW_OP_plus_uconst";
6241 return "DW_OP_shra";
6259 return "DW_OP_skip";
6261 return "DW_OP_lit0";
6263 return "DW_OP_lit1";
6265 return "DW_OP_lit2";
6267 return "DW_OP_lit3";
6269 return "DW_OP_lit4";
6271 return "DW_OP_lit5";
6273 return "DW_OP_lit6";
6275 return "DW_OP_lit7";
6277 return "DW_OP_lit8";
6279 return "DW_OP_lit9";
6281 return "DW_OP_lit10";
6283 return "DW_OP_lit11";
6285 return "DW_OP_lit12";
6287 return "DW_OP_lit13";
6289 return "DW_OP_lit14";
6291 return "DW_OP_lit15";
6293 return "DW_OP_lit16";
6295 return "DW_OP_lit17";
6297 return "DW_OP_lit18";
6299 return "DW_OP_lit19";
6301 return "DW_OP_lit20";
6303 return "DW_OP_lit21";
6305 return "DW_OP_lit22";
6307 return "DW_OP_lit23";
6309 return "DW_OP_lit24";
6311 return "DW_OP_lit25";
6313 return "DW_OP_lit26";
6315 return "DW_OP_lit27";
6317 return "DW_OP_lit28";
6319 return "DW_OP_lit29";
6321 return "DW_OP_lit30";
6323 return "DW_OP_lit31";
6325 return "DW_OP_reg0";
6327 return "DW_OP_reg1";
6329 return "DW_OP_reg2";
6331 return "DW_OP_reg3";
6333 return "DW_OP_reg4";
6335 return "DW_OP_reg5";
6337 return "DW_OP_reg6";
6339 return "DW_OP_reg7";
6341 return "DW_OP_reg8";
6343 return "DW_OP_reg9";
6345 return "DW_OP_reg10";
6347 return "DW_OP_reg11";
6349 return "DW_OP_reg12";
6351 return "DW_OP_reg13";
6353 return "DW_OP_reg14";
6355 return "DW_OP_reg15";
6357 return "DW_OP_reg16";
6359 return "DW_OP_reg17";
6361 return "DW_OP_reg18";
6363 return "DW_OP_reg19";
6365 return "DW_OP_reg20";
6367 return "DW_OP_reg21";
6369 return "DW_OP_reg22";
6371 return "DW_OP_reg23";
6373 return "DW_OP_reg24";
6375 return "DW_OP_reg25";
6377 return "DW_OP_reg26";
6379 return "DW_OP_reg27";
6381 return "DW_OP_reg28";
6383 return "DW_OP_reg29";
6385 return "DW_OP_reg30";
6387 return "DW_OP_reg31";
6389 return "DW_OP_breg0";
6391 return "DW_OP_breg1";
6393 return "DW_OP_breg2";
6395 return "DW_OP_breg3";
6397 return "DW_OP_breg4";
6399 return "DW_OP_breg5";
6401 return "DW_OP_breg6";
6403 return "DW_OP_breg7";
6405 return "DW_OP_breg8";
6407 return "DW_OP_breg9";
6409 return "DW_OP_breg10";
6411 return "DW_OP_breg11";
6413 return "DW_OP_breg12";
6415 return "DW_OP_breg13";
6417 return "DW_OP_breg14";
6419 return "DW_OP_breg15";
6421 return "DW_OP_breg16";
6423 return "DW_OP_breg17";
6425 return "DW_OP_breg18";
6427 return "DW_OP_breg19";
6429 return "DW_OP_breg20";
6431 return "DW_OP_breg21";
6433 return "DW_OP_breg22";
6435 return "DW_OP_breg23";
6437 return "DW_OP_breg24";
6439 return "DW_OP_breg25";
6441 return "DW_OP_breg26";
6443 return "DW_OP_breg27";
6445 return "DW_OP_breg28";
6447 return "DW_OP_breg29";
6449 return "DW_OP_breg30";
6451 return "DW_OP_breg31";
6453 return "DW_OP_regx";
6455 return "DW_OP_fbreg";
6457 return "DW_OP_bregx";
6459 return "DW_OP_piece";
6460 case DW_OP_deref_size
:
6461 return "DW_OP_deref_size";
6462 case DW_OP_xderef_size
:
6463 return "DW_OP_xderef_size";
6466 /* DWARF 3 extensions. */
6467 case DW_OP_push_object_address
:
6468 return "DW_OP_push_object_address";
6470 return "DW_OP_call2";
6472 return "DW_OP_call4";
6473 case DW_OP_call_ref
:
6474 return "DW_OP_call_ref";
6475 /* GNU extensions. */
6476 case DW_OP_GNU_push_tls_address
:
6477 return "DW_OP_GNU_push_tls_address";
6479 return "OP_<unknown>";
6484 dwarf_bool_name (unsigned mybool
)
6492 /* Convert a DWARF type code into its string name. */
6495 dwarf_type_encoding_name (unsigned enc
)
6499 case DW_ATE_address
:
6500 return "DW_ATE_address";
6501 case DW_ATE_boolean
:
6502 return "DW_ATE_boolean";
6503 case DW_ATE_complex_float
:
6504 return "DW_ATE_complex_float";
6506 return "DW_ATE_float";
6508 return "DW_ATE_signed";
6509 case DW_ATE_signed_char
:
6510 return "DW_ATE_signed_char";
6511 case DW_ATE_unsigned
:
6512 return "DW_ATE_unsigned";
6513 case DW_ATE_unsigned_char
:
6514 return "DW_ATE_unsigned_char";
6515 case DW_ATE_imaginary_float
:
6516 return "DW_ATE_imaginary_float";
6518 return "DW_ATE_<unknown>";
6522 /* Convert a DWARF call frame info operation to its string name. */
6526 dwarf_cfi_name (unsigned cfi_opc
)
6530 case DW_CFA_advance_loc
:
6531 return "DW_CFA_advance_loc";
6533 return "DW_CFA_offset";
6534 case DW_CFA_restore
:
6535 return "DW_CFA_restore";
6537 return "DW_CFA_nop";
6538 case DW_CFA_set_loc
:
6539 return "DW_CFA_set_loc";
6540 case DW_CFA_advance_loc1
:
6541 return "DW_CFA_advance_loc1";
6542 case DW_CFA_advance_loc2
:
6543 return "DW_CFA_advance_loc2";
6544 case DW_CFA_advance_loc4
:
6545 return "DW_CFA_advance_loc4";
6546 case DW_CFA_offset_extended
:
6547 return "DW_CFA_offset_extended";
6548 case DW_CFA_restore_extended
:
6549 return "DW_CFA_restore_extended";
6550 case DW_CFA_undefined
:
6551 return "DW_CFA_undefined";
6552 case DW_CFA_same_value
:
6553 return "DW_CFA_same_value";
6554 case DW_CFA_register
:
6555 return "DW_CFA_register";
6556 case DW_CFA_remember_state
:
6557 return "DW_CFA_remember_state";
6558 case DW_CFA_restore_state
:
6559 return "DW_CFA_restore_state";
6560 case DW_CFA_def_cfa
:
6561 return "DW_CFA_def_cfa";
6562 case DW_CFA_def_cfa_register
:
6563 return "DW_CFA_def_cfa_register";
6564 case DW_CFA_def_cfa_offset
:
6565 return "DW_CFA_def_cfa_offset";
6568 case DW_CFA_def_cfa_expression
:
6569 return "DW_CFA_def_cfa_expression";
6570 case DW_CFA_expression
:
6571 return "DW_CFA_expression";
6572 case DW_CFA_offset_extended_sf
:
6573 return "DW_CFA_offset_extended_sf";
6574 case DW_CFA_def_cfa_sf
:
6575 return "DW_CFA_def_cfa_sf";
6576 case DW_CFA_def_cfa_offset_sf
:
6577 return "DW_CFA_def_cfa_offset_sf";
6579 /* SGI/MIPS specific */
6580 case DW_CFA_MIPS_advance_loc8
:
6581 return "DW_CFA_MIPS_advance_loc8";
6583 /* GNU extensions */
6584 case DW_CFA_GNU_window_save
:
6585 return "DW_CFA_GNU_window_save";
6586 case DW_CFA_GNU_args_size
:
6587 return "DW_CFA_GNU_args_size";
6588 case DW_CFA_GNU_negative_offset_extended
:
6589 return "DW_CFA_GNU_negative_offset_extended";
6592 return "DW_CFA_<unknown>";
6598 dump_die (struct die_info
*die
)
6602 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
6603 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
6604 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
6605 dwarf_bool_name (die
->child
!= NULL
));
6607 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
6608 for (i
= 0; i
< die
->num_attrs
; ++i
)
6610 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
6611 dwarf_attr_name (die
->attrs
[i
].name
),
6612 dwarf_form_name (die
->attrs
[i
].form
));
6613 switch (die
->attrs
[i
].form
)
6615 case DW_FORM_ref_addr
:
6617 fprintf_unfiltered (gdb_stderr
, "address: ");
6618 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
6620 case DW_FORM_block2
:
6621 case DW_FORM_block4
:
6623 case DW_FORM_block1
:
6624 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
6635 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
6637 case DW_FORM_string
:
6639 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
6640 DW_STRING (&die
->attrs
[i
])
6641 ? DW_STRING (&die
->attrs
[i
]) : "");
6644 if (DW_UNSND (&die
->attrs
[i
]))
6645 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
6647 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
6649 case DW_FORM_indirect
:
6650 /* the reader will have reduced the indirect form to
6651 the "base form" so this form should not occur */
6652 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
6655 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
6656 die
->attrs
[i
].form
);
6658 fprintf_unfiltered (gdb_stderr
, "\n");
6663 dump_die_list (struct die_info
*die
)
6668 if (die
->child
!= NULL
)
6669 dump_die_list (die
->child
);
6670 if (die
->sibling
!= NULL
)
6671 dump_die_list (die
->sibling
);
6676 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
6679 struct die_info
*old
;
6681 h
= (offset
% REF_HASH_SIZE
);
6682 old
= die_ref_table
[h
];
6683 die
->next_ref
= old
;
6684 die_ref_table
[h
] = die
;
6689 dwarf2_empty_hash_tables (void)
6691 memset (die_ref_table
, 0, sizeof (die_ref_table
));
6695 dwarf2_get_ref_die_offset (struct attribute
*attr
)
6697 unsigned int result
= 0;
6701 case DW_FORM_ref_addr
:
6702 result
= DW_ADDR (attr
);
6708 case DW_FORM_ref_udata
:
6709 result
= cu_header_offset
+ DW_UNSND (attr
);
6712 complaint (&symfile_complaints
,
6713 "unsupported die ref attribute form: '%s'",
6714 dwarf_form_name (attr
->form
));
6719 static struct die_info
*
6720 follow_die_ref (unsigned int offset
)
6722 struct die_info
*die
;
6725 h
= (offset
% REF_HASH_SIZE
);
6726 die
= die_ref_table
[h
];
6729 if (die
->offset
== offset
)
6733 die
= die
->next_ref
;
6738 static struct type
*
6739 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
6741 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
6743 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
6744 typeid, objfile
->name
);
6747 /* Look for this particular type in the fundamental type vector. If
6748 one is not found, create and install one appropriate for the
6749 current language and the current target machine. */
6751 if (ftypes
[typeid] == NULL
)
6753 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
6756 return (ftypes
[typeid]);
6759 /* Decode simple location descriptions.
6760 Given a pointer to a dwarf block that defines a location, compute
6761 the location and return the value.
6763 NOTE drow/2003-11-18: This function is called in two situations
6764 now: for the address of static or global variables (partial symbols
6765 only) and for offsets into structures which are expected to be
6766 (more or less) constant. The partial symbol case should go away,
6767 and only the constant case should remain. That will let this
6768 function complain more accurately. A few special modes are allowed
6769 without complaint for global variables (for instance, global
6770 register values and thread-local values).
6772 A location description containing no operations indicates that the
6773 object is optimized out. The return value is 0 for that case.
6774 FIXME drow/2003-11-16: No callers check for this case any more; soon all
6775 callers will only want a very basic result and this can become a
6778 When the result is a register number, the global isreg flag is set,
6779 otherwise it is cleared.
6781 Note that stack[0] is unused except as a default error return.
6782 Note that stack overflow is not yet handled. */
6785 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
6787 struct objfile
*objfile
= cu
->objfile
;
6788 struct comp_unit_head
*cu_header
= &cu
->header
;
6790 int size
= blk
->size
;
6791 char *data
= blk
->data
;
6792 CORE_ADDR stack
[64];
6794 unsigned int bytes_read
, unsnd
;
6839 stack
[++stacki
] = op
- DW_OP_lit0
;
6875 stack
[++stacki
] = op
- DW_OP_reg0
;
6877 dwarf2_complex_location_expr_complaint ();
6882 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6884 stack
[++stacki
] = unsnd
;
6886 dwarf2_complex_location_expr_complaint ();
6890 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
6896 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
6901 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
6906 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
6911 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
6916 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
6921 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
6926 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
6932 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6937 stack
[stacki
+ 1] = stack
[stacki
];
6942 stack
[stacki
- 1] += stack
[stacki
];
6946 case DW_OP_plus_uconst
:
6947 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6952 stack
[stacki
- 1] -= stack
[stacki
];
6957 /* If we're not the last op, then we definitely can't encode
6958 this using GDB's address_class enum. This is valid for partial
6959 global symbols, although the variable's address will be bogus
6962 dwarf2_complex_location_expr_complaint ();
6965 case DW_OP_GNU_push_tls_address
:
6966 /* The top of the stack has the offset from the beginning
6967 of the thread control block at which the variable is located. */
6968 /* Nothing should follow this operator, so the top of stack would
6970 /* This is valid for partial global symbols, but the variable's
6971 address will be bogus in the psymtab. */
6973 dwarf2_complex_location_expr_complaint ();
6977 complaint (&symfile_complaints
, "unsupported stack op: '%s'",
6978 dwarf_stack_op_name (op
));
6979 return (stack
[stacki
]);
6982 return (stack
[stacki
]);
6985 /* memory allocation interface */
6988 dwarf2_free_tmp_obstack (void *ignore
)
6990 obstack_free (&dwarf2_tmp_obstack
, NULL
);
6993 static struct dwarf_block
*
6994 dwarf_alloc_block (void)
6996 struct dwarf_block
*blk
;
6998 blk
= (struct dwarf_block
*)
6999 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
7003 static struct abbrev_info
*
7004 dwarf_alloc_abbrev (void)
7006 struct abbrev_info
*abbrev
;
7008 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
7009 memset (abbrev
, 0, sizeof (struct abbrev_info
));
7013 static struct die_info
*
7014 dwarf_alloc_die (void)
7016 struct die_info
*die
;
7018 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
7019 memset (die
, 0, sizeof (struct die_info
));
7024 /* Macro support. */
7027 /* Return the full name of file number I in *LH's file name table.
7028 Use COMP_DIR as the name of the current directory of the
7029 compilation. The result is allocated using xmalloc; the caller is
7030 responsible for freeing it. */
7032 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
7034 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7036 if (IS_ABSOLUTE_PATH (fe
->name
))
7037 return xstrdup (fe
->name
);
7045 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7051 dir_len
= strlen (dir
);
7052 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
7053 strcpy (full_name
, dir
);
7054 full_name
[dir_len
] = '/';
7055 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
7059 return xstrdup (fe
->name
);
7064 static struct macro_source_file
*
7065 macro_start_file (int file
, int line
,
7066 struct macro_source_file
*current_file
,
7067 const char *comp_dir
,
7068 struct line_header
*lh
, struct objfile
*objfile
)
7070 /* The full name of this source file. */
7071 char *full_name
= file_full_name (file
, lh
, comp_dir
);
7073 /* We don't create a macro table for this compilation unit
7074 at all until we actually get a filename. */
7075 if (! pending_macros
)
7076 pending_macros
= new_macro_table (&objfile
->symbol_obstack
,
7077 objfile
->macro_cache
);
7080 /* If we have no current file, then this must be the start_file
7081 directive for the compilation unit's main source file. */
7082 current_file
= macro_set_main (pending_macros
, full_name
);
7084 current_file
= macro_include (current_file
, line
, full_name
);
7088 return current_file
;
7092 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
7093 followed by a null byte. */
7095 copy_string (const char *buf
, int len
)
7097 char *s
= xmalloc (len
+ 1);
7098 memcpy (s
, buf
, len
);
7106 consume_improper_spaces (const char *p
, const char *body
)
7110 complaint (&symfile_complaints
,
7111 "macro definition contains spaces in formal argument list:\n`%s'",
7123 parse_macro_definition (struct macro_source_file
*file
, int line
,
7128 /* The body string takes one of two forms. For object-like macro
7129 definitions, it should be:
7131 <macro name> " " <definition>
7133 For function-like macro definitions, it should be:
7135 <macro name> "() " <definition>
7137 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
7139 Spaces may appear only where explicitly indicated, and in the
7142 The Dwarf 2 spec says that an object-like macro's name is always
7143 followed by a space, but versions of GCC around March 2002 omit
7144 the space when the macro's definition is the empty string.
7146 The Dwarf 2 spec says that there should be no spaces between the
7147 formal arguments in a function-like macro's formal argument list,
7148 but versions of GCC around March 2002 include spaces after the
7152 /* Find the extent of the macro name. The macro name is terminated
7153 by either a space or null character (for an object-like macro) or
7154 an opening paren (for a function-like macro). */
7155 for (p
= body
; *p
; p
++)
7156 if (*p
== ' ' || *p
== '(')
7159 if (*p
== ' ' || *p
== '\0')
7161 /* It's an object-like macro. */
7162 int name_len
= p
- body
;
7163 char *name
= copy_string (body
, name_len
);
7164 const char *replacement
;
7167 replacement
= body
+ name_len
+ 1;
7170 dwarf2_macro_malformed_definition_complaint (body
);
7171 replacement
= body
+ name_len
;
7174 macro_define_object (file
, line
, name
, replacement
);
7180 /* It's a function-like macro. */
7181 char *name
= copy_string (body
, p
- body
);
7184 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
7188 p
= consume_improper_spaces (p
, body
);
7190 /* Parse the formal argument list. */
7191 while (*p
&& *p
!= ')')
7193 /* Find the extent of the current argument name. */
7194 const char *arg_start
= p
;
7196 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
7199 if (! *p
|| p
== arg_start
)
7200 dwarf2_macro_malformed_definition_complaint (body
);
7203 /* Make sure argv has room for the new argument. */
7204 if (argc
>= argv_size
)
7207 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
7210 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
7213 p
= consume_improper_spaces (p
, body
);
7215 /* Consume the comma, if present. */
7220 p
= consume_improper_spaces (p
, body
);
7229 /* Perfectly formed definition, no complaints. */
7230 macro_define_function (file
, line
, name
,
7231 argc
, (const char **) argv
,
7233 else if (*p
== '\0')
7235 /* Complain, but do define it. */
7236 dwarf2_macro_malformed_definition_complaint (body
);
7237 macro_define_function (file
, line
, name
,
7238 argc
, (const char **) argv
,
7242 /* Just complain. */
7243 dwarf2_macro_malformed_definition_complaint (body
);
7246 /* Just complain. */
7247 dwarf2_macro_malformed_definition_complaint (body
);
7253 for (i
= 0; i
< argc
; i
++)
7259 dwarf2_macro_malformed_definition_complaint (body
);
7264 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
7265 char *comp_dir
, bfd
*abfd
,
7266 struct dwarf2_cu
*cu
)
7268 char *mac_ptr
, *mac_end
;
7269 struct macro_source_file
*current_file
= 0;
7271 if (dwarf_macinfo_buffer
== NULL
)
7273 complaint (&symfile_complaints
, "missing .debug_macinfo section");
7277 mac_ptr
= dwarf_macinfo_buffer
+ offset
;
7278 mac_end
= dwarf_macinfo_buffer
+ dwarf_macinfo_size
;
7282 enum dwarf_macinfo_record_type macinfo_type
;
7284 /* Do we at least have room for a macinfo type byte? */
7285 if (mac_ptr
>= mac_end
)
7287 dwarf2_macros_too_long_complaint ();
7291 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
7294 switch (macinfo_type
)
7296 /* A zero macinfo type indicates the end of the macro
7301 case DW_MACINFO_define
:
7302 case DW_MACINFO_undef
:
7308 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7309 mac_ptr
+= bytes_read
;
7310 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
7311 mac_ptr
+= bytes_read
;
7314 complaint (&symfile_complaints
,
7315 "debug info gives macro %s outside of any file: %s",
7317 DW_MACINFO_define
? "definition" : macinfo_type
==
7318 DW_MACINFO_undef
? "undefinition" :
7319 "something-or-other", body
);
7322 if (macinfo_type
== DW_MACINFO_define
)
7323 parse_macro_definition (current_file
, line
, body
);
7324 else if (macinfo_type
== DW_MACINFO_undef
)
7325 macro_undef (current_file
, line
, body
);
7330 case DW_MACINFO_start_file
:
7335 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7336 mac_ptr
+= bytes_read
;
7337 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7338 mac_ptr
+= bytes_read
;
7340 current_file
= macro_start_file (file
, line
,
7341 current_file
, comp_dir
,
7346 case DW_MACINFO_end_file
:
7348 complaint (&symfile_complaints
,
7349 "macro debug info has an unmatched `close_file' directive");
7352 current_file
= current_file
->included_by
;
7355 enum dwarf_macinfo_record_type next_type
;
7357 /* GCC circa March 2002 doesn't produce the zero
7358 type byte marking the end of the compilation
7359 unit. Complain if it's not there, but exit no
7362 /* Do we at least have room for a macinfo type byte? */
7363 if (mac_ptr
>= mac_end
)
7365 dwarf2_macros_too_long_complaint ();
7369 /* We don't increment mac_ptr here, so this is just
7371 next_type
= read_1_byte (abfd
, mac_ptr
);
7373 complaint (&symfile_complaints
,
7374 "no terminating 0-type entry for macros in `.debug_macinfo' section");
7381 case DW_MACINFO_vendor_ext
:
7387 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7388 mac_ptr
+= bytes_read
;
7389 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
7390 mac_ptr
+= bytes_read
;
7392 /* We don't recognize any vendor extensions. */
7399 /* Check if the attribute's form is a DW_FORM_block*
7400 if so return true else false. */
7402 attr_form_is_block (struct attribute
*attr
)
7404 return (attr
== NULL
? 0 :
7405 attr
->form
== DW_FORM_block1
7406 || attr
->form
== DW_FORM_block2
7407 || attr
->form
== DW_FORM_block4
7408 || attr
->form
== DW_FORM_block
);
7412 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
7413 struct dwarf2_cu
*cu
)
7415 if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
7417 struct dwarf2_loclist_baton
*baton
;
7419 baton
= obstack_alloc (&cu
->objfile
->symbol_obstack
,
7420 sizeof (struct dwarf2_loclist_baton
));
7421 baton
->objfile
= cu
->objfile
;
7423 /* We don't know how long the location list is, but make sure we
7424 don't run off the edge of the section. */
7425 baton
->size
= dwarf_loc_size
- DW_UNSND (attr
);
7426 baton
->data
= dwarf_loc_buffer
+ DW_UNSND (attr
);
7427 baton
->base_address
= cu
->header
.base_address
;
7428 if (cu
->header
.base_known
== 0)
7429 complaint (&symfile_complaints
,
7430 "Location list used without specifying the CU base address.");
7432 SYMBOL_LOCATION_FUNCS (sym
) = &dwarf2_loclist_funcs
;
7433 SYMBOL_LOCATION_BATON (sym
) = baton
;
7437 struct dwarf2_locexpr_baton
*baton
;
7439 baton
= obstack_alloc (&cu
->objfile
->symbol_obstack
,
7440 sizeof (struct dwarf2_locexpr_baton
));
7441 baton
->objfile
= cu
->objfile
;
7443 if (attr_form_is_block (attr
))
7445 /* Note that we're just copying the block's data pointer
7446 here, not the actual data. We're still pointing into the
7447 dwarf_info_buffer for SYM's objfile; right now we never
7448 release that buffer, but when we do clean up properly
7449 this may need to change. */
7450 baton
->size
= DW_BLOCK (attr
)->size
;
7451 baton
->data
= DW_BLOCK (attr
)->data
;
7455 dwarf2_invalid_attrib_class_complaint ("location description",
7456 SYMBOL_NATURAL_NAME (sym
));
7461 SYMBOL_LOCATION_FUNCS (sym
) = &dwarf2_locexpr_funcs
;
7462 SYMBOL_LOCATION_BATON (sym
) = baton
;