1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
10 support in dwarfread.c
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or (at
17 your option) any later version.
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. */
35 #include "elf/dwarf2.h"
38 #include "expression.h"
39 #include "filenames.h" /* for DOSish file names */
43 #include "complaints.h"
46 #include "gdb_string.h"
47 #include "gdb_assert.h"
48 #include <sys/types.h>
50 #ifndef DWARF2_REG_TO_REGNUM
51 #define DWARF2_REG_TO_REGNUM(REG) (REG)
55 /* .debug_info header for a compilation unit
56 Because of alignment constraints, this structure has padding and cannot
57 be mapped directly onto the beginning of the .debug_info section. */
58 typedef struct comp_unit_header
60 unsigned int length
; /* length of the .debug_info
62 unsigned short version
; /* version number -- 2 for DWARF
64 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
65 unsigned char addr_size
; /* byte size of an address -- 4 */
68 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
71 /* .debug_pubnames header
72 Because of alignment constraints, this structure has padding and cannot
73 be mapped directly onto the beginning of the .debug_info section. */
74 typedef struct pubnames_header
76 unsigned int length
; /* length of the .debug_pubnames
78 unsigned char version
; /* version number -- 2 for DWARF
80 unsigned int info_offset
; /* offset into .debug_info section */
81 unsigned int info_size
; /* byte size of .debug_info section
85 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
87 /* .debug_pubnames header
88 Because of alignment constraints, this structure has padding and cannot
89 be mapped directly onto the beginning of the .debug_info section. */
90 typedef struct aranges_header
92 unsigned int length
; /* byte len of the .debug_aranges
94 unsigned short version
; /* version number -- 2 for DWARF
96 unsigned int info_offset
; /* offset into .debug_info section */
97 unsigned char addr_size
; /* byte size of an address */
98 unsigned char seg_size
; /* byte size of segment descriptor */
101 #define _ACTUAL_ARANGES_HEADER_SIZE 12
103 /* .debug_line statement program prologue
104 Because of alignment constraints, this structure has padding and cannot
105 be mapped directly onto the beginning of the .debug_info section. */
106 typedef struct statement_prologue
108 unsigned int total_length
; /* byte length of the statement
110 unsigned short version
; /* version number -- 2 for DWARF
112 unsigned int prologue_length
; /* # bytes between prologue &
114 unsigned char minimum_instruction_length
; /* byte size of
116 unsigned char default_is_stmt
; /* initial value of is_stmt
119 unsigned char line_range
;
120 unsigned char opcode_base
; /* number assigned to first special
122 unsigned char *standard_opcode_lengths
;
126 /* offsets and sizes of debugging sections */
128 static file_ptr dwarf_info_offset
;
129 static file_ptr dwarf_abbrev_offset
;
130 static file_ptr dwarf_line_offset
;
131 static file_ptr dwarf_pubnames_offset
;
132 static file_ptr dwarf_aranges_offset
;
133 static file_ptr dwarf_loc_offset
;
134 static file_ptr dwarf_macinfo_offset
;
135 static file_ptr dwarf_str_offset
;
136 file_ptr dwarf_frame_offset
;
137 file_ptr dwarf_eh_frame_offset
;
139 static unsigned int dwarf_info_size
;
140 static unsigned int dwarf_abbrev_size
;
141 static unsigned int dwarf_line_size
;
142 static unsigned int dwarf_pubnames_size
;
143 static unsigned int dwarf_aranges_size
;
144 static unsigned int dwarf_loc_size
;
145 static unsigned int dwarf_macinfo_size
;
146 static unsigned int dwarf_str_size
;
147 unsigned int dwarf_frame_size
;
148 unsigned int dwarf_eh_frame_size
;
150 /* names of the debugging sections */
152 #define INFO_SECTION ".debug_info"
153 #define ABBREV_SECTION ".debug_abbrev"
154 #define LINE_SECTION ".debug_line"
155 #define PUBNAMES_SECTION ".debug_pubnames"
156 #define ARANGES_SECTION ".debug_aranges"
157 #define LOC_SECTION ".debug_loc"
158 #define MACINFO_SECTION ".debug_macinfo"
159 #define STR_SECTION ".debug_str"
160 #define FRAME_SECTION ".debug_frame"
161 #define EH_FRAME_SECTION ".eh_frame"
163 /* local data types */
165 /* The data in a compilation unit header, after target2host
166 translation, looks like this. */
167 struct comp_unit_head
169 unsigned long length
;
171 unsigned int abbrev_offset
;
172 unsigned char addr_size
;
173 unsigned char signed_addr_p
;
174 unsigned int offset_size
; /* size of file offsets; either 4 or 8 */
175 unsigned int initial_length_size
; /* size of the length field; either
179 /* The line number information for a compilation unit (found in the
180 .debug_line section) begins with a "statement program header",
181 which contains the following information. */
184 unsigned int total_length
;
185 unsigned short version
;
186 unsigned int header_length
;
187 unsigned char minimum_instruction_length
;
188 unsigned char default_is_stmt
;
190 unsigned char line_range
;
191 unsigned char opcode_base
;
193 /* standard_opcode_lengths[i] is the number of operands for the
194 standard opcode whose value is i. This means that
195 standard_opcode_lengths[0] is unused, and the last meaningful
196 element is standard_opcode_lengths[opcode_base - 1]. */
197 unsigned char *standard_opcode_lengths
;
199 /* The include_directories table. NOTE! These strings are not
200 allocated with xmalloc; instead, they are pointers into
201 debug_line_buffer. If you try to free them, `free' will get
203 unsigned int num_include_dirs
, include_dirs_size
;
206 /* The file_names table. NOTE! These strings are not allocated
207 with xmalloc; instead, they are pointers into debug_line_buffer.
208 Don't try to free them directly. */
209 unsigned int num_file_names
, file_names_size
;
213 unsigned int dir_index
;
214 unsigned int mod_time
;
218 /* The start and end of the statement program following this
219 header. These point into dwarf_line_buffer. */
220 char *statement_program_start
, *statement_program_end
;
223 /* When we construct a partial symbol table entry we only
224 need this much information. */
225 struct partial_die_info
228 unsigned char has_children
;
229 unsigned char is_external
;
230 unsigned char is_declaration
;
231 unsigned char has_type
;
238 struct dwarf_block
*locdesc
;
239 unsigned int language
;
243 /* This data structure holds the information of an abbrev. */
246 unsigned int number
; /* number identifying abbrev */
247 enum dwarf_tag tag
; /* dwarf tag */
248 int has_children
; /* boolean */
249 unsigned int num_attrs
; /* number of attributes */
250 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
251 struct abbrev_info
*next
; /* next in chain */
256 enum dwarf_attribute name
;
257 enum dwarf_form form
;
260 /* This data structure holds a complete die structure. */
263 enum dwarf_tag tag
; /* Tag indicating type of die */
264 unsigned short has_children
; /* Does the die have children */
265 unsigned int abbrev
; /* Abbrev number */
266 unsigned int offset
; /* Offset in .debug_info section */
267 unsigned int num_attrs
; /* Number of attributes */
268 struct attribute
*attrs
; /* An array of attributes */
269 struct die_info
*next_ref
; /* Next die in ref hash table */
270 struct die_info
*next
; /* Next die in linked list */
271 struct type
*type
; /* Cached type information */
274 /* Attributes have a name and a value */
277 enum dwarf_attribute name
;
278 enum dwarf_form form
;
282 struct dwarf_block
*blk
;
290 struct function_range
293 CORE_ADDR lowpc
, highpc
;
295 struct function_range
*next
;
298 static struct function_range
*cu_first_fn
, *cu_last_fn
, *cu_cached_fn
;
300 /* Get at parts of an attribute structure */
302 #define DW_STRING(attr) ((attr)->u.str)
303 #define DW_UNSND(attr) ((attr)->u.unsnd)
304 #define DW_BLOCK(attr) ((attr)->u.blk)
305 #define DW_SND(attr) ((attr)->u.snd)
306 #define DW_ADDR(attr) ((attr)->u.addr)
308 /* Blocks are a bunch of untyped bytes. */
315 /* We only hold one compilation unit's abbrevs in
316 memory at any one time. */
317 #ifndef ABBREV_HASH_SIZE
318 #define ABBREV_HASH_SIZE 121
320 #ifndef ATTR_ALLOC_CHUNK
321 #define ATTR_ALLOC_CHUNK 4
324 static struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
326 /* A hash table of die offsets for following references. */
327 #ifndef REF_HASH_SIZE
328 #define REF_HASH_SIZE 1021
331 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
333 /* Obstack for allocating temporary storage used during symbol reading. */
334 static struct obstack dwarf2_tmp_obstack
;
336 /* Offset to the first byte of the current compilation unit header,
337 for resolving relative reference dies. */
338 static unsigned int cu_header_offset
;
340 /* Allocate fields for structs, unions and enums in this size. */
341 #ifndef DW_FIELD_ALLOC_CHUNK
342 #define DW_FIELD_ALLOC_CHUNK 4
345 /* The language we are debugging. */
346 static enum language cu_language
;
347 static const struct language_defn
*cu_language_defn
;
349 /* Actually data from the sections. */
350 static char *dwarf_info_buffer
;
351 static char *dwarf_abbrev_buffer
;
352 static char *dwarf_line_buffer
;
353 static char *dwarf_str_buffer
;
354 static char *dwarf_macinfo_buffer
;
356 /* A zeroed version of a partial die for initialization purposes. */
357 static struct partial_die_info zeroed_partial_die
;
359 /* The generic symbol table building routines have separate lists for
360 file scope symbols and all all other scopes (local scopes). So
361 we need to select the right one to pass to add_symbol_to_list().
362 We do it by keeping a pointer to the correct list in list_in_scope.
364 FIXME: The original dwarf code just treated the file scope as the first
365 local scope, and all other local scopes as nested local scopes, and worked
366 fine. Check to see if we really need to distinguish these
368 static struct pending
**list_in_scope
= &file_symbols
;
370 /* FIXME: decode_locdesc sets these variables to describe the location
371 to the caller. These ought to be a structure or something. If
372 none of the flags are set, the object lives at the address returned
373 by decode_locdesc. */
375 static int optimized_out
; /* No ops in location in expression,
376 so object was optimized out. */
377 static int isreg
; /* Object lives in register.
378 decode_locdesc's return value is
379 the register number. */
380 static int offreg
; /* Object's address is the sum of the
381 register specified by basereg, plus
382 the offset returned. */
383 static int basereg
; /* See `offreg'. */
384 static int isderef
; /* Value described by flags above is
385 the address of a pointer to the object. */
386 static int islocal
; /* Variable is at the returned offset
387 from the frame start, but there's
388 no identified frame pointer for
389 this function, so we can't say
390 which register it's relative to;
393 /* DW_AT_frame_base values for the current function.
394 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
395 contains the register number for the frame register.
396 frame_base_offset is the offset from the frame register to the
397 virtual stack frame. */
398 static int frame_base_reg
;
399 static CORE_ADDR frame_base_offset
;
401 /* This value is added to each symbol value. FIXME: Generalize to
402 the section_offsets structure used by dbxread (once this is done,
403 pass the appropriate section number to end_symtab). */
404 static CORE_ADDR baseaddr
; /* Add to each symbol value */
406 /* We put a pointer to this structure in the read_symtab_private field
408 The complete dwarf information for an objfile is kept in the
409 psymbol_obstack, so that absolute die references can be handled.
410 Most of the information in this structure is related to an entire
411 object file and could be passed via the sym_private field of the objfile.
412 It is however conceivable that dwarf2 might not be the only type
413 of symbols read from an object file. */
417 /* Pointer to start of dwarf info buffer for the objfile. */
419 char *dwarf_info_buffer
;
421 /* Offset in dwarf_info_buffer for this compilation unit. */
423 unsigned long dwarf_info_offset
;
425 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
427 char *dwarf_abbrev_buffer
;
429 /* Size of dwarf abbreviation section for the objfile. */
431 unsigned int dwarf_abbrev_size
;
433 /* Pointer to start of dwarf line buffer for the objfile. */
435 char *dwarf_line_buffer
;
437 /* Size of dwarf_line_buffer, in bytes. */
439 unsigned int dwarf_line_size
;
441 /* Pointer to start of dwarf string buffer for the objfile. */
443 char *dwarf_str_buffer
;
445 /* Size of dwarf string section for the objfile. */
447 unsigned int dwarf_str_size
;
449 /* Pointer to start of dwarf macro buffer for the objfile. */
451 char *dwarf_macinfo_buffer
;
453 /* Size of dwarf macinfo section for the objfile. */
455 unsigned int dwarf_macinfo_size
;
459 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
460 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
461 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
462 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
463 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
464 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
465 #define DWARF_LINE_SIZE(p) (PST_PRIVATE(p)->dwarf_line_size)
466 #define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer)
467 #define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size)
468 #define DWARF_MACINFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_macinfo_buffer)
469 #define DWARF_MACINFO_SIZE(p) (PST_PRIVATE(p)->dwarf_macinfo_size)
471 /* Maintain an array of referenced fundamental types for the current
472 compilation unit being read. For DWARF version 1, we have to construct
473 the fundamental types on the fly, since no information about the
474 fundamental types is supplied. Each such fundamental type is created by
475 calling a language dependent routine to create the type, and then a
476 pointer to that type is then placed in the array at the index specified
477 by it's FT_<TYPENAME> value. The array has a fixed size set by the
478 FT_NUM_MEMBERS compile time constant, which is the number of predefined
479 fundamental types gdb knows how to construct. */
480 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
482 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
483 but this would require a corresponding change in unpack_field_as_long
485 static int bits_per_byte
= 8;
487 /* The routines that read and process dies for a C struct or C++ class
488 pass lists of data member fields and lists of member function fields
489 in an instance of a field_info structure, as defined below. */
492 /* List of data member and baseclasses fields. */
495 struct nextfield
*next
;
502 /* Number of fields. */
505 /* Number of baseclasses. */
508 /* Set if the accesibility of one of the fields is not public. */
509 int non_public_fields
;
511 /* Member function fields array, entries are allocated in the order they
512 are encountered in the object file. */
515 struct nextfnfield
*next
;
516 struct fn_field fnfield
;
520 /* Member function fieldlist array, contains name of possibly overloaded
521 member function, number of overloaded member functions and a pointer
522 to the head of the member function field chain. */
527 struct nextfnfield
*head
;
531 /* Number of entries in the fnfieldlists array. */
535 /* Various complaints about symbol reading that don't abort the process */
537 static struct complaint dwarf2_const_ignored
=
539 "type qualifier 'const' ignored", 0, 0
541 static struct complaint dwarf2_volatile_ignored
=
543 "type qualifier 'volatile' ignored", 0, 0
545 static struct complaint dwarf2_non_const_array_bound_ignored
=
547 "non-constant array bounds form '%s' ignored", 0, 0
549 static struct complaint dwarf2_missing_line_number_section
=
551 "missing .debug_line section", 0, 0
553 static struct complaint dwarf2_statement_list_fits_in_line_number_section
=
555 "statement list doesn't fit in .debug_line section", 0, 0
557 static struct complaint dwarf2_mangled_line_number_section
=
559 "mangled .debug_line section", 0, 0
561 static struct complaint dwarf2_unsupported_die_ref_attr
=
563 "unsupported die ref attribute form: '%s'", 0, 0
565 static struct complaint dwarf2_unsupported_stack_op
=
567 "unsupported stack op: '%s'", 0, 0
569 static struct complaint dwarf2_complex_location_expr
=
571 "location expression too complex", 0, 0
573 static struct complaint dwarf2_unsupported_tag
=
575 "unsupported tag: '%s'", 0, 0
577 static struct complaint dwarf2_unsupported_at_encoding
=
579 "unsupported DW_AT_encoding: '%s'", 0, 0
581 static struct complaint dwarf2_unsupported_at_frame_base
=
583 "unsupported DW_AT_frame_base for function '%s'", 0, 0
585 static struct complaint dwarf2_unexpected_tag
=
587 "unexepected tag in read_type_die: '%s'", 0, 0
589 static struct complaint dwarf2_missing_at_frame_base
=
591 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
593 static struct complaint dwarf2_bad_static_member_name
=
595 "unrecognized static data member name '%s'", 0, 0
597 static struct complaint dwarf2_unsupported_accessibility
=
599 "unsupported accessibility %d", 0, 0
601 static struct complaint dwarf2_bad_member_name_complaint
=
603 "cannot extract member name from '%s'", 0, 0
605 static struct complaint dwarf2_missing_member_fn_type_complaint
=
607 "member function type missing for '%s'", 0, 0
609 static struct complaint dwarf2_vtbl_not_found_complaint
=
611 "virtual function table pointer not found when defining class '%s'", 0, 0
613 static struct complaint dwarf2_absolute_sibling_complaint
=
615 "ignoring absolute DW_AT_sibling", 0, 0
617 static struct complaint dwarf2_const_value_length_mismatch
=
619 "const value length mismatch for '%s', got %d, expected %d", 0, 0
621 static struct complaint dwarf2_unsupported_const_value_attr
=
623 "unsupported const value attribute form: '%s'", 0, 0
625 static struct complaint dwarf2_misplaced_line_number
=
627 "misplaced first line number at 0x%lx for '%s'", 0, 0
629 static struct complaint dwarf2_line_header_too_long
=
631 "line number info header doesn't fit in `.debug_line' section", 0, 0
633 static struct complaint dwarf2_missing_macinfo_section
=
635 "missing .debug_macinfo section", 0, 0
637 static struct complaint dwarf2_macros_too_long
=
639 "macro info runs off end of `.debug_macinfo' section", 0, 0
641 static struct complaint dwarf2_macros_not_terminated
=
643 "no terminating 0-type entry for macros in `.debug_macinfo' section", 0, 0
645 static struct complaint dwarf2_macro_outside_file
=
647 "debug info gives macro %s outside of any file: %s", 0, 0
649 static struct complaint dwarf2_macro_unmatched_end_file
=
651 "macro debug info has an unmatched `close_file' directive", 0, 0
653 static struct complaint dwarf2_macro_malformed_definition
=
655 "macro debug info contains a malformed macro definition:\n`%s'", 0, 0
657 static struct complaint dwarf2_macro_spaces_in_definition
=
659 "macro definition contains spaces in formal argument list:\n`%s'", 0, 0
661 static struct complaint dwarf2_invalid_attrib_class
=
663 "invalid attribute class or form for '%s' in '%s'", 0, 0
666 /* local function prototypes */
668 static void dwarf2_locate_sections (bfd
*, asection
*, PTR
);
671 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
674 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
676 static char *scan_partial_symbols (char *, struct objfile
*,
677 CORE_ADDR
*, CORE_ADDR
*,
678 const struct comp_unit_head
*);
680 static void add_partial_symbol (struct partial_die_info
*, struct objfile
*,
681 const struct comp_unit_head
*);
683 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
685 static void psymtab_to_symtab_1 (struct partial_symtab
*);
687 char *dwarf2_read_section (struct objfile
*, file_ptr
, unsigned int);
689 static void dwarf2_read_abbrevs (bfd
*, unsigned int);
691 static void dwarf2_empty_abbrev_table (PTR
);
693 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int);
695 static char *read_partial_die (struct partial_die_info
*,
697 const struct comp_unit_head
*);
699 static char *read_full_die (struct die_info
**, bfd
*, char *,
700 const struct comp_unit_head
*);
702 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
703 bfd
*, char *, const struct comp_unit_head
*);
705 static char *read_attribute_value (struct attribute
*, unsigned,
706 bfd
*, char *, const struct comp_unit_head
*);
708 static unsigned int read_1_byte (bfd
*, char *);
710 static int read_1_signed_byte (bfd
*, char *);
712 static unsigned int read_2_bytes (bfd
*, char *);
714 static unsigned int read_4_bytes (bfd
*, char *);
716 static unsigned long read_8_bytes (bfd
*, char *);
718 static CORE_ADDR
read_address (bfd
*, char *ptr
, const struct comp_unit_head
*,
721 static LONGEST
read_initial_length (bfd
*, char *,
722 struct comp_unit_head
*, int *bytes_read
);
724 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
727 static char *read_n_bytes (bfd
*, char *, unsigned int);
729 static char *read_string (bfd
*, char *, unsigned int *);
731 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
734 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
736 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
738 static void set_cu_language (unsigned int);
740 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
742 static int die_is_declaration (struct die_info
*);
744 static void free_line_header (struct line_header
*lh
);
746 static struct line_header
*(dwarf_decode_line_header
747 (unsigned int offset
,
749 const struct comp_unit_head
*cu_header
));
751 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
752 const struct comp_unit_head
*);
754 static void dwarf2_start_subfile (char *, char *);
756 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
757 struct objfile
*, const struct comp_unit_head
*);
759 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
760 struct objfile
*, const struct comp_unit_head
*);
762 static void dwarf2_const_value_data (struct attribute
*attr
,
766 static struct type
*die_type (struct die_info
*, struct objfile
*,
767 const struct comp_unit_head
*);
769 static struct type
*die_containing_type (struct die_info
*, struct objfile
*,
770 const struct comp_unit_head
*);
773 static struct type
*type_at_offset (unsigned int, struct objfile
*);
776 static struct type
*tag_type_to_type (struct die_info
*, struct objfile
*,
777 const struct comp_unit_head
*);
779 static void read_type_die (struct die_info
*, struct objfile
*,
780 const struct comp_unit_head
*);
782 static void read_typedef (struct die_info
*, struct objfile
*,
783 const struct comp_unit_head
*);
785 static void read_base_type (struct die_info
*, struct objfile
*);
787 static void read_file_scope (struct die_info
*, struct objfile
*,
788 const struct comp_unit_head
*);
790 static void read_func_scope (struct die_info
*, struct objfile
*,
791 const struct comp_unit_head
*);
793 static void read_lexical_block_scope (struct die_info
*, struct objfile
*,
794 const struct comp_unit_head
*);
796 static int dwarf2_get_pc_bounds (struct die_info
*,
797 CORE_ADDR
*, CORE_ADDR
*, struct objfile
*);
799 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
800 struct objfile
*, const struct comp_unit_head
*);
802 static void dwarf2_attach_fields_to_type (struct field_info
*,
803 struct type
*, struct objfile
*);
805 static void dwarf2_add_member_fn (struct field_info
*,
806 struct die_info
*, struct objfile
*objfile
,
807 const struct comp_unit_head
*);
809 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
810 struct type
*, struct objfile
*);
812 static void read_structure_scope (struct die_info
*, struct objfile
*,
813 const struct comp_unit_head
*);
815 static void read_common_block (struct die_info
*, struct objfile
*,
816 const struct comp_unit_head
*);
818 static void read_enumeration (struct die_info
*, struct objfile
*,
819 const struct comp_unit_head
*);
821 static struct type
*dwarf_base_type (int, int, struct objfile
*);
823 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct objfile
*,
824 const struct comp_unit_head
*);
826 static void read_array_type (struct die_info
*, struct objfile
*,
827 const struct comp_unit_head
*);
829 static void read_tag_pointer_type (struct die_info
*, struct objfile
*,
830 const struct comp_unit_head
*);
832 static void read_tag_ptr_to_member_type (struct die_info
*, struct objfile
*,
833 const struct comp_unit_head
*);
835 static void read_tag_reference_type (struct die_info
*, struct objfile
*,
836 const struct comp_unit_head
*);
838 static void read_tag_const_type (struct die_info
*, struct objfile
*,
839 const struct comp_unit_head
*);
841 static void read_tag_volatile_type (struct die_info
*, struct objfile
*,
842 const struct comp_unit_head
*);
844 static void read_tag_string_type (struct die_info
*, struct objfile
*);
846 static void read_subroutine_type (struct die_info
*, struct objfile
*,
847 const struct comp_unit_head
*);
849 static struct die_info
*read_comp_unit (char *, bfd
*,
850 const struct comp_unit_head
*);
852 static void free_die_list (struct die_info
*);
854 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
856 static void process_die (struct die_info
*, struct objfile
*,
857 const struct comp_unit_head
*);
859 static char *dwarf2_linkage_name (struct die_info
*);
861 static char *dwarf_tag_name (unsigned int);
863 static char *dwarf_attr_name (unsigned int);
865 static char *dwarf_form_name (unsigned int);
867 static char *dwarf_stack_op_name (unsigned int);
869 static char *dwarf_bool_name (unsigned int);
871 static char *dwarf_type_encoding_name (unsigned int);
874 static char *dwarf_cfi_name (unsigned int);
876 struct die_info
*copy_die (struct die_info
*);
879 static struct die_info
*sibling_die (struct die_info
*);
881 static void dump_die (struct die_info
*);
883 static void dump_die_list (struct die_info
*);
885 static void store_in_ref_table (unsigned int, struct die_info
*);
887 static void dwarf2_empty_hash_tables (void);
889 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
891 static struct die_info
*follow_die_ref (unsigned int);
893 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
895 /* memory allocation interface */
897 static void dwarf2_free_tmp_obstack (PTR
);
899 static struct dwarf_block
*dwarf_alloc_block (void);
901 static struct abbrev_info
*dwarf_alloc_abbrev (void);
903 static struct die_info
*dwarf_alloc_die (void);
905 static void initialize_cu_func_list (void);
907 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
);
909 static void dwarf_decode_macros (struct line_header
*, unsigned int,
910 char *, bfd
*, const struct comp_unit_head
*,
913 static int attr_form_is_block (struct attribute
*);
915 /* Try to locate the sections we need for DWARF 2 debugging
916 information and return true if we have enough to do something. */
919 dwarf2_has_info (bfd
*abfd
)
921 dwarf_info_offset
= 0;
922 dwarf_abbrev_offset
= 0;
923 dwarf_line_offset
= 0;
924 dwarf_str_offset
= 0;
925 dwarf_macinfo_offset
= 0;
926 dwarf_frame_offset
= 0;
927 dwarf_eh_frame_offset
= 0;
928 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
929 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
939 /* This function is mapped across the sections and remembers the
940 offset and size of each of the debugging sections we are interested
944 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, PTR ignore_ptr
)
946 if (STREQ (sectp
->name
, INFO_SECTION
))
948 dwarf_info_offset
= sectp
->filepos
;
949 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
951 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
953 dwarf_abbrev_offset
= sectp
->filepos
;
954 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
956 else if (STREQ (sectp
->name
, LINE_SECTION
))
958 dwarf_line_offset
= sectp
->filepos
;
959 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
961 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
963 dwarf_pubnames_offset
= sectp
->filepos
;
964 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
966 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
968 dwarf_aranges_offset
= sectp
->filepos
;
969 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
971 else if (STREQ (sectp
->name
, LOC_SECTION
))
973 dwarf_loc_offset
= sectp
->filepos
;
974 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
976 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
978 dwarf_macinfo_offset
= sectp
->filepos
;
979 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
981 else if (STREQ (sectp
->name
, STR_SECTION
))
983 dwarf_str_offset
= sectp
->filepos
;
984 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
986 else if (STREQ (sectp
->name
, FRAME_SECTION
))
988 dwarf_frame_offset
= sectp
->filepos
;
989 dwarf_frame_size
= bfd_get_section_size_before_reloc (sectp
);
991 else if (STREQ (sectp
->name
, EH_FRAME_SECTION
))
993 dwarf_eh_frame_offset
= sectp
->filepos
;
994 dwarf_eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
998 /* Build a partial symbol table. */
1001 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1004 /* We definitely need the .debug_info and .debug_abbrev sections */
1006 dwarf_info_buffer
= dwarf2_read_section (objfile
,
1009 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
1010 dwarf_abbrev_offset
,
1013 if (dwarf_line_offset
)
1014 dwarf_line_buffer
= dwarf2_read_section (objfile
,
1018 dwarf_line_buffer
= NULL
;
1020 if (dwarf_str_offset
)
1021 dwarf_str_buffer
= dwarf2_read_section (objfile
,
1025 dwarf_str_buffer
= NULL
;
1027 if (dwarf_macinfo_offset
)
1028 dwarf_macinfo_buffer
= dwarf2_read_section (objfile
,
1029 dwarf_macinfo_offset
,
1030 dwarf_macinfo_size
);
1032 dwarf_macinfo_buffer
= NULL
;
1035 || (objfile
->global_psymbols
.size
== 0
1036 && objfile
->static_psymbols
.size
== 0))
1038 init_psymbol_list (objfile
, 1024);
1042 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1044 /* Things are significantly easier if we have .debug_aranges and
1045 .debug_pubnames sections */
1047 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1051 /* only test this case for now */
1053 /* In this case we have to work a bit harder */
1054 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1059 /* Build the partial symbol table from the information in the
1060 .debug_pubnames and .debug_aranges sections. */
1063 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1065 bfd
*abfd
= objfile
->obfd
;
1066 char *aranges_buffer
, *pubnames_buffer
;
1067 char *aranges_ptr
, *pubnames_ptr
;
1068 unsigned int entry_length
, version
, info_offset
, info_size
;
1070 pubnames_buffer
= dwarf2_read_section (objfile
,
1071 dwarf_pubnames_offset
,
1072 dwarf_pubnames_size
);
1073 pubnames_ptr
= pubnames_buffer
;
1074 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
1076 struct comp_unit_head cu_header
;
1079 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1081 pubnames_ptr
+= bytes_read
;
1082 version
= read_1_byte (abfd
, pubnames_ptr
);
1084 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1086 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1090 aranges_buffer
= dwarf2_read_section (objfile
,
1091 dwarf_aranges_offset
,
1092 dwarf_aranges_size
);
1097 /* Read in the comp unit header information from the debug_info at
1101 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1102 char *info_ptr
, bfd
*abfd
)
1106 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1108 info_ptr
+= bytes_read
;
1109 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1111 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1113 info_ptr
+= bytes_read
;
1114 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1116 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1117 if (signed_addr
< 0)
1118 internal_error (__FILE__
, __LINE__
,
1119 "read_comp_unit_head: dwarf from non elf file");
1120 cu_header
->signed_addr_p
= signed_addr
;
1124 /* Build the partial symbol table by doing a quick pass through the
1125 .debug_info and .debug_abbrev sections. */
1128 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1130 /* Instead of reading this into a big buffer, we should probably use
1131 mmap() on architectures that support it. (FIXME) */
1132 bfd
*abfd
= objfile
->obfd
;
1133 char *info_ptr
, *abbrev_ptr
;
1134 char *beg_of_comp_unit
;
1135 struct partial_die_info comp_unit_die
;
1136 struct partial_symtab
*pst
;
1137 struct cleanup
*back_to
;
1138 CORE_ADDR lowpc
, highpc
;
1140 info_ptr
= dwarf_info_buffer
;
1141 abbrev_ptr
= dwarf_abbrev_buffer
;
1143 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1144 the partial symbol scan, like attribute values.
1146 We could reduce our peak memory consumption during partial symbol
1147 table construction by freeing stuff from this obstack more often
1148 --- say, after processing each compilation unit, or each die ---
1149 but it turns out that this saves almost nothing. For an
1150 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1151 on dwarf2_tmp_obstack. Some investigation showed:
1153 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1154 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1155 all fixed-length values not requiring dynamic allocation.
1157 2) 30% of the attributes used the form DW_FORM_string. For
1158 DW_FORM_string, read_attribute simply hands back a pointer to
1159 the null-terminated string in dwarf_info_buffer, so no dynamic
1160 allocation is needed there either.
1162 3) The remaining 1% of the attributes all used DW_FORM_block1.
1163 75% of those were DW_AT_frame_base location lists for
1164 functions; the rest were DW_AT_location attributes, probably
1165 for the global variables.
1167 Anyway, what this all means is that the memory the dwarf2
1168 reader uses as temporary space reading partial symbols is about
1169 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1171 obstack_init (&dwarf2_tmp_obstack
);
1172 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1174 /* Since the objects we're extracting from dwarf_info_buffer vary in
1175 length, only the individual functions to extract them (like
1176 read_comp_unit_head and read_partial_die) can really know whether
1177 the buffer is large enough to hold another complete object.
1179 At the moment, they don't actually check that. If
1180 dwarf_info_buffer holds just one extra byte after the last
1181 compilation unit's dies, then read_comp_unit_head will happily
1182 read off the end of the buffer. read_partial_die is similarly
1183 casual. Those functions should be fixed.
1185 For this loop condition, simply checking whether there's any data
1186 left at all should be sufficient. */
1187 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1189 struct comp_unit_head cu_header
;
1190 beg_of_comp_unit
= info_ptr
;
1191 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1193 if (cu_header
.version
!= 2)
1195 error ("Dwarf Error: wrong version in compilation unit header.");
1198 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
1200 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
1201 (long) cu_header
.abbrev_offset
,
1202 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1205 if (beg_of_comp_unit
+ cu_header
.length
+ cu_header
.initial_length_size
1206 > dwarf_info_buffer
+ dwarf_info_size
)
1208 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
1209 (long) cu_header
.length
,
1210 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1213 /* Read the abbrevs for this compilation unit into a table */
1214 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1215 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1217 /* Read the compilation unit die */
1218 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1221 /* Set the language we're debugging */
1222 set_cu_language (comp_unit_die
.language
);
1224 /* Allocate a new partial symbol table structure */
1225 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1226 comp_unit_die
.name
? comp_unit_die
.name
: "",
1227 comp_unit_die
.lowpc
,
1228 objfile
->global_psymbols
.next
,
1229 objfile
->static_psymbols
.next
);
1231 pst
->read_symtab_private
= (char *)
1232 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1233 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1234 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1235 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1236 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1237 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1238 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1239 DWARF_LINE_SIZE (pst
) = dwarf_line_size
;
1240 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1241 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1242 DWARF_MACINFO_BUFFER (pst
) = dwarf_macinfo_buffer
;
1243 DWARF_MACINFO_SIZE (pst
) = dwarf_macinfo_size
;
1244 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1246 /* Store the function that reads in the rest of the symbol table */
1247 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1249 /* Check if comp unit has_children.
1250 If so, read the rest of the partial symbols from this comp unit.
1251 If not, there's no more debug_info for this comp unit. */
1252 if (comp_unit_die
.has_children
)
1254 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
,
1257 /* If the compilation unit didn't have an explicit address range,
1258 then use the information extracted from its child dies. */
1259 if (! comp_unit_die
.has_pc_info
)
1261 comp_unit_die
.lowpc
= lowpc
;
1262 comp_unit_die
.highpc
= highpc
;
1265 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1266 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1268 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1269 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1270 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1271 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1272 sort_pst_symbols (pst
);
1274 /* If there is already a psymtab or symtab for a file of this
1275 name, remove it. (If there is a symtab, more drastic things
1276 also happen.) This happens in VxWorks. */
1277 free_named_symtabs (pst
->filename
);
1279 info_ptr
= beg_of_comp_unit
+ cu_header
.length
1280 + cu_header
.initial_length_size
;
1282 do_cleanups (back_to
);
1285 /* Read in all interesting dies to the end of the compilation unit. */
1288 scan_partial_symbols (char *info_ptr
, struct objfile
*objfile
,
1289 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1290 const struct comp_unit_head
*cu_header
)
1292 bfd
*abfd
= objfile
->obfd
;
1293 struct partial_die_info pdi
;
1295 /* This function is called after we've read in the comp_unit_die in
1296 order to read its children. We start the nesting level at 1 since
1297 we have pushed 1 level down in order to read the comp unit's children.
1298 The comp unit itself is at level 0, so we stop reading when we pop
1299 back to that level. */
1301 int nesting_level
= 1;
1303 *lowpc
= ((CORE_ADDR
) -1);
1304 *highpc
= ((CORE_ADDR
) 0);
1306 while (nesting_level
)
1308 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu_header
);
1314 case DW_TAG_subprogram
:
1315 if (pdi
.has_pc_info
)
1317 if (pdi
.lowpc
< *lowpc
)
1321 if (pdi
.highpc
> *highpc
)
1323 *highpc
= pdi
.highpc
;
1325 if ((pdi
.is_external
|| nesting_level
== 1)
1326 && !pdi
.is_declaration
)
1328 add_partial_symbol (&pdi
, objfile
, cu_header
);
1332 case DW_TAG_variable
:
1333 case DW_TAG_typedef
:
1334 case DW_TAG_class_type
:
1335 case DW_TAG_structure_type
:
1336 case DW_TAG_union_type
:
1337 case DW_TAG_enumeration_type
:
1338 if ((pdi
.is_external
|| nesting_level
== 1)
1339 && !pdi
.is_declaration
)
1341 add_partial_symbol (&pdi
, objfile
, cu_header
);
1344 case DW_TAG_enumerator
:
1345 /* File scope enumerators are added to the partial symbol
1347 if (nesting_level
== 2)
1348 add_partial_symbol (&pdi
, objfile
, cu_header
);
1350 case DW_TAG_base_type
:
1351 /* File scope base type definitions are added to the partial
1353 if (nesting_level
== 1)
1354 add_partial_symbol (&pdi
, objfile
, cu_header
);
1361 /* If the die has a sibling, skip to the sibling.
1362 Do not skip enumeration types, we want to record their
1364 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1366 info_ptr
= pdi
.sibling
;
1368 else if (pdi
.has_children
)
1370 /* Die has children, but the optional DW_AT_sibling attribute
1381 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1382 from `maint check'. */
1383 if (*lowpc
== ((CORE_ADDR
) -1))
1389 add_partial_symbol (struct partial_die_info
*pdi
, struct objfile
*objfile
,
1390 const struct comp_unit_head
*cu_header
)
1396 case DW_TAG_subprogram
:
1397 if (pdi
->is_external
)
1399 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1400 mst_text, objfile); */
1401 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1402 VAR_NAMESPACE
, LOC_BLOCK
,
1403 &objfile
->global_psymbols
,
1404 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1408 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1409 mst_file_text, objfile); */
1410 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1411 VAR_NAMESPACE
, LOC_BLOCK
,
1412 &objfile
->static_psymbols
,
1413 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1416 case DW_TAG_variable
:
1417 if (pdi
->is_external
)
1420 Don't enter into the minimal symbol tables as there is
1421 a minimal symbol table entry from the ELF symbols already.
1422 Enter into partial symbol table if it has a location
1423 descriptor or a type.
1424 If the location descriptor is missing, new_symbol will create
1425 a LOC_UNRESOLVED symbol, the address of the variable will then
1426 be determined from the minimal symbol table whenever the variable
1428 The address for the partial symbol table entry is not
1429 used by GDB, but it comes in handy for debugging partial symbol
1433 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1434 if (pdi
->locdesc
|| pdi
->has_type
)
1435 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1436 VAR_NAMESPACE
, LOC_STATIC
,
1437 &objfile
->global_psymbols
,
1438 0, addr
+ baseaddr
, cu_language
, objfile
);
1442 /* Static Variable. Skip symbols without location descriptors. */
1443 if (pdi
->locdesc
== NULL
)
1445 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1446 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1447 mst_file_data, objfile); */
1448 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1449 VAR_NAMESPACE
, LOC_STATIC
,
1450 &objfile
->static_psymbols
,
1451 0, addr
+ baseaddr
, cu_language
, objfile
);
1454 case DW_TAG_typedef
:
1455 case DW_TAG_base_type
:
1456 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1457 VAR_NAMESPACE
, LOC_TYPEDEF
,
1458 &objfile
->static_psymbols
,
1459 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1461 case DW_TAG_class_type
:
1462 case DW_TAG_structure_type
:
1463 case DW_TAG_union_type
:
1464 case DW_TAG_enumeration_type
:
1465 /* Skip aggregate types without children, these are external
1467 if (pdi
->has_children
== 0)
1469 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1470 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1471 &objfile
->static_psymbols
,
1472 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1474 if (cu_language
== language_cplus
)
1476 /* For C++, these implicitly act as typedefs as well. */
1477 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1478 VAR_NAMESPACE
, LOC_TYPEDEF
,
1479 &objfile
->static_psymbols
,
1480 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1483 case DW_TAG_enumerator
:
1484 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1485 VAR_NAMESPACE
, LOC_CONST
,
1486 &objfile
->static_psymbols
,
1487 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1494 /* Expand this partial symbol table into a full symbol table. */
1497 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1499 /* FIXME: This is barely more than a stub. */
1504 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1510 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1511 gdb_flush (gdb_stdout
);
1514 psymtab_to_symtab_1 (pst
);
1516 /* Finish up the debug error message. */
1518 printf_filtered ("done.\n");
1524 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1526 struct objfile
*objfile
= pst
->objfile
;
1527 bfd
*abfd
= objfile
->obfd
;
1528 struct comp_unit_head cu_header
;
1529 struct die_info
*dies
;
1530 unsigned long offset
;
1531 CORE_ADDR lowpc
, highpc
;
1532 struct die_info
*child_die
;
1534 struct symtab
*symtab
;
1535 struct cleanup
*back_to
;
1537 /* Set local variables from the partial symbol table info. */
1538 offset
= DWARF_INFO_OFFSET (pst
);
1539 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1540 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1541 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1542 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1543 dwarf_line_size
= DWARF_LINE_SIZE (pst
);
1544 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1545 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1546 dwarf_macinfo_buffer
= DWARF_MACINFO_BUFFER (pst
);
1547 dwarf_macinfo_size
= DWARF_MACINFO_SIZE (pst
);
1548 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1549 cu_header_offset
= offset
;
1550 info_ptr
= dwarf_info_buffer
+ offset
;
1552 obstack_init (&dwarf2_tmp_obstack
);
1553 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1556 make_cleanup (really_free_pendings
, NULL
);
1558 /* read in the comp_unit header */
1559 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1561 /* Read the abbrevs for this compilation unit */
1562 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1563 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1565 dies
= read_comp_unit (info_ptr
, abfd
, &cu_header
);
1567 make_cleanup_free_die_list (dies
);
1569 /* Do line number decoding in read_file_scope () */
1570 process_die (dies
, objfile
, &cu_header
);
1572 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1574 /* Some compilers don't define a DW_AT_high_pc attribute for
1575 the compilation unit. If the DW_AT_high_pc is missing,
1576 synthesize it, by scanning the DIE's below the compilation unit. */
1578 if (dies
->has_children
)
1580 child_die
= dies
->next
;
1581 while (child_die
&& child_die
->tag
)
1583 if (child_die
->tag
== DW_TAG_subprogram
)
1585 CORE_ADDR low
, high
;
1587 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1589 highpc
= max (highpc
, high
);
1592 child_die
= sibling_die (child_die
);
1596 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1598 /* Set symtab language to language from DW_AT_language.
1599 If the compilation is from a C file generated by language preprocessors,
1600 do not set the language if it was already deduced by start_subfile. */
1602 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1604 symtab
->language
= cu_language
;
1606 pst
->symtab
= symtab
;
1608 sort_symtab_syms (pst
->symtab
);
1610 do_cleanups (back_to
);
1613 /* Process a die and its children. */
1616 process_die (struct die_info
*die
, struct objfile
*objfile
,
1617 const struct comp_unit_head
*cu_header
)
1621 case DW_TAG_padding
:
1623 case DW_TAG_compile_unit
:
1624 read_file_scope (die
, objfile
, cu_header
);
1626 case DW_TAG_subprogram
:
1627 read_subroutine_type (die
, objfile
, cu_header
);
1628 read_func_scope (die
, objfile
, cu_header
);
1630 case DW_TAG_inlined_subroutine
:
1631 /* FIXME: These are ignored for now.
1632 They could be used to set breakpoints on all inlined instances
1633 of a function and make GDB `next' properly over inlined functions. */
1635 case DW_TAG_lexical_block
:
1636 read_lexical_block_scope (die
, objfile
, cu_header
);
1638 case DW_TAG_class_type
:
1639 case DW_TAG_structure_type
:
1640 case DW_TAG_union_type
:
1641 read_structure_scope (die
, objfile
, cu_header
);
1643 case DW_TAG_enumeration_type
:
1644 read_enumeration (die
, objfile
, cu_header
);
1646 case DW_TAG_subroutine_type
:
1647 read_subroutine_type (die
, objfile
, cu_header
);
1649 case DW_TAG_array_type
:
1650 read_array_type (die
, objfile
, cu_header
);
1652 case DW_TAG_pointer_type
:
1653 read_tag_pointer_type (die
, objfile
, cu_header
);
1655 case DW_TAG_ptr_to_member_type
:
1656 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
1658 case DW_TAG_reference_type
:
1659 read_tag_reference_type (die
, objfile
, cu_header
);
1661 case DW_TAG_string_type
:
1662 read_tag_string_type (die
, objfile
);
1664 case DW_TAG_base_type
:
1665 read_base_type (die
, objfile
);
1666 if (dwarf_attr (die
, DW_AT_name
))
1668 /* Add a typedef symbol for the base type definition. */
1669 new_symbol (die
, die
->type
, objfile
, cu_header
);
1672 case DW_TAG_common_block
:
1673 read_common_block (die
, objfile
, cu_header
);
1675 case DW_TAG_common_inclusion
:
1678 new_symbol (die
, NULL
, objfile
, cu_header
);
1684 initialize_cu_func_list (void)
1686 cu_first_fn
= cu_last_fn
= cu_cached_fn
= NULL
;
1690 read_file_scope (struct die_info
*die
, struct objfile
*objfile
,
1691 const struct comp_unit_head
*cu_header
)
1693 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
1694 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1695 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1696 struct attribute
*attr
;
1697 char *name
= "<unknown>";
1698 char *comp_dir
= NULL
;
1699 struct die_info
*child_die
;
1700 bfd
*abfd
= objfile
->obfd
;
1701 struct line_header
*line_header
= 0;
1703 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1705 if (die
->has_children
)
1707 child_die
= die
->next
;
1708 while (child_die
&& child_die
->tag
)
1710 if (child_die
->tag
== DW_TAG_subprogram
)
1712 CORE_ADDR low
, high
;
1714 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1716 lowpc
= min (lowpc
, low
);
1717 highpc
= max (highpc
, high
);
1720 child_die
= sibling_die (child_die
);
1725 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1726 from finish_block. */
1727 if (lowpc
== ((CORE_ADDR
) -1))
1732 attr
= dwarf_attr (die
, DW_AT_name
);
1735 name
= DW_STRING (attr
);
1737 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1740 comp_dir
= DW_STRING (attr
);
1743 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1744 directory, get rid of it. */
1745 char *cp
= strchr (comp_dir
, ':');
1747 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1752 if (objfile
->ei
.entry_point
>= lowpc
&&
1753 objfile
->ei
.entry_point
< highpc
)
1755 objfile
->ei
.entry_file_lowpc
= lowpc
;
1756 objfile
->ei
.entry_file_highpc
= highpc
;
1759 attr
= dwarf_attr (die
, DW_AT_language
);
1762 set_cu_language (DW_UNSND (attr
));
1765 /* We assume that we're processing GCC output. */
1766 processing_gcc_compilation
= 2;
1768 /* FIXME:Do something here. */
1769 if (dip
->at_producer
!= NULL
)
1771 handle_producer (dip
->at_producer
);
1775 /* The compilation unit may be in a different language or objfile,
1776 zero out all remembered fundamental types. */
1777 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1779 start_symtab (name
, comp_dir
, lowpc
);
1780 record_debugformat ("DWARF 2");
1782 initialize_cu_func_list ();
1784 /* Process all dies in compilation unit. */
1785 if (die
->has_children
)
1787 child_die
= die
->next
;
1788 while (child_die
&& child_die
->tag
)
1790 process_die (child_die
, objfile
, cu_header
);
1791 child_die
= sibling_die (child_die
);
1795 /* Decode line number information if present. */
1796 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1799 unsigned int line_offset
= DW_UNSND (attr
);
1800 line_header
= dwarf_decode_line_header (line_offset
,
1804 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
1805 (void *) line_header
);
1806 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu_header
);
1810 /* Decode macro information, if present. Dwarf 2 macro information
1811 refers to information in the line number info statement program
1812 header, so we can only read it if we've read the header
1814 attr
= dwarf_attr (die
, DW_AT_macro_info
);
1815 if (attr
&& line_header
)
1817 unsigned int macro_offset
= DW_UNSND (attr
);
1818 dwarf_decode_macros (line_header
, macro_offset
,
1819 comp_dir
, abfd
, cu_header
, objfile
);
1821 do_cleanups (back_to
);
1825 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
)
1827 struct function_range
*thisfn
;
1829 thisfn
= (struct function_range
*)
1830 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct function_range
));
1831 thisfn
->name
= name
;
1832 thisfn
->lowpc
= lowpc
;
1833 thisfn
->highpc
= highpc
;
1834 thisfn
->seen_line
= 0;
1835 thisfn
->next
= NULL
;
1837 if (cu_last_fn
== NULL
)
1838 cu_first_fn
= thisfn
;
1840 cu_last_fn
->next
= thisfn
;
1842 cu_last_fn
= thisfn
;
1846 read_func_scope (struct die_info
*die
, struct objfile
*objfile
,
1847 const struct comp_unit_head
*cu_header
)
1849 register struct context_stack
*new;
1852 struct die_info
*child_die
;
1853 struct attribute
*attr
;
1856 name
= dwarf2_linkage_name (die
);
1858 /* Ignore functions with missing or empty names and functions with
1859 missing or invalid low and high pc attributes. */
1860 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1866 /* Record the function range for dwarf_decode_lines. */
1867 add_to_cu_func_list (name
, lowpc
, highpc
);
1869 if (objfile
->ei
.entry_point
>= lowpc
&&
1870 objfile
->ei
.entry_point
< highpc
)
1872 objfile
->ei
.entry_func_lowpc
= lowpc
;
1873 objfile
->ei
.entry_func_highpc
= highpc
;
1876 /* Decode DW_AT_frame_base location descriptor if present, keep result
1877 for DW_OP_fbreg operands in decode_locdesc. */
1878 frame_base_reg
= -1;
1879 frame_base_offset
= 0;
1880 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1885 /* Support the .debug_loc offsets */
1886 if (attr_form_is_block (attr
))
1888 addr
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
1890 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
1892 complain (&dwarf2_complex_location_expr
);
1897 complain (&dwarf2_invalid_attrib_class
, "DW_AT_frame_base", name
);
1902 complain (&dwarf2_unsupported_at_frame_base
, name
);
1904 frame_base_reg
= addr
;
1907 frame_base_reg
= basereg
;
1908 frame_base_offset
= addr
;
1911 complain (&dwarf2_unsupported_at_frame_base
, name
);
1914 new = push_context (0, lowpc
);
1915 new->name
= new_symbol (die
, die
->type
, objfile
, cu_header
);
1916 list_in_scope
= &local_symbols
;
1918 if (die
->has_children
)
1920 child_die
= die
->next
;
1921 while (child_die
&& child_die
->tag
)
1923 process_die (child_die
, objfile
, cu_header
);
1924 child_die
= sibling_die (child_die
);
1928 new = pop_context ();
1929 /* Make a block for the local symbols within. */
1930 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1931 lowpc
, highpc
, objfile
);
1932 list_in_scope
= &file_symbols
;
1935 /* Process all the DIES contained within a lexical block scope. Start
1936 a new scope, process the dies, and then close the scope. */
1939 read_lexical_block_scope (struct die_info
*die
, struct objfile
*objfile
,
1940 const struct comp_unit_head
*cu_header
)
1942 register struct context_stack
*new;
1943 CORE_ADDR lowpc
, highpc
;
1944 struct die_info
*child_die
;
1946 /* Ignore blocks with missing or invalid low and high pc attributes. */
1947 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1952 push_context (0, lowpc
);
1953 if (die
->has_children
)
1955 child_die
= die
->next
;
1956 while (child_die
&& child_die
->tag
)
1958 process_die (child_die
, objfile
, cu_header
);
1959 child_die
= sibling_die (child_die
);
1962 new = pop_context ();
1964 if (local_symbols
!= NULL
)
1966 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1969 local_symbols
= new->locals
;
1972 /* Get low and high pc attributes from a die.
1973 Return 1 if the attributes are present and valid, otherwise, return 0. */
1976 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1977 struct objfile
*objfile
)
1979 struct attribute
*attr
;
1983 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1985 low
= DW_ADDR (attr
);
1988 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1990 high
= DW_ADDR (attr
);
1997 /* When using the GNU linker, .gnu.linkonce. sections are used to
1998 eliminate duplicate copies of functions and vtables and such.
1999 The linker will arbitrarily choose one and discard the others.
2000 The AT_*_pc values for such functions refer to local labels in
2001 these sections. If the section from that file was discarded, the
2002 labels are not in the output, so the relocs get a value of 0.
2003 If this is a discarded function, mark the pc bounds as invalid,
2004 so that GDB will ignore it. */
2005 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
2013 /* Add an aggregate field to the field list. */
2016 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
2017 struct objfile
*objfile
,
2018 const struct comp_unit_head
*cu_header
)
2020 struct nextfield
*new_field
;
2021 struct attribute
*attr
;
2023 char *fieldname
= "";
2025 /* Allocate a new field list entry and link it in. */
2026 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2027 make_cleanup (xfree
, new_field
);
2028 memset (new_field
, 0, sizeof (struct nextfield
));
2029 new_field
->next
= fip
->fields
;
2030 fip
->fields
= new_field
;
2033 /* Handle accessibility and virtuality of field.
2034 The default accessibility for members is public, the default
2035 accessibility for inheritance is private. */
2036 if (die
->tag
!= DW_TAG_inheritance
)
2037 new_field
->accessibility
= DW_ACCESS_public
;
2039 new_field
->accessibility
= DW_ACCESS_private
;
2040 new_field
->virtuality
= DW_VIRTUALITY_none
;
2042 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2044 new_field
->accessibility
= DW_UNSND (attr
);
2045 if (new_field
->accessibility
!= DW_ACCESS_public
)
2046 fip
->non_public_fields
= 1;
2047 attr
= dwarf_attr (die
, DW_AT_virtuality
);
2049 new_field
->virtuality
= DW_UNSND (attr
);
2051 fp
= &new_field
->field
;
2052 if (die
->tag
== DW_TAG_member
)
2054 /* Get type of field. */
2055 fp
->type
= die_type (die
, objfile
, cu_header
);
2057 /* Get bit size of field (zero if none). */
2058 attr
= dwarf_attr (die
, DW_AT_bit_size
);
2061 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
2065 FIELD_BITSIZE (*fp
) = 0;
2068 /* Get bit offset of field. */
2069 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2072 FIELD_BITPOS (*fp
) =
2073 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) * bits_per_byte
;
2076 FIELD_BITPOS (*fp
) = 0;
2077 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
2080 if (BITS_BIG_ENDIAN
)
2082 /* For big endian bits, the DW_AT_bit_offset gives the
2083 additional bit offset from the MSB of the containing
2084 anonymous object to the MSB of the field. We don't
2085 have to do anything special since we don't need to
2086 know the size of the anonymous object. */
2087 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
2091 /* For little endian bits, compute the bit offset to the
2092 MSB of the anonymous object, subtract off the number of
2093 bits from the MSB of the field to the MSB of the
2094 object, and then subtract off the number of bits of
2095 the field itself. The result is the bit offset of
2096 the LSB of the field. */
2098 int bit_offset
= DW_UNSND (attr
);
2100 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2103 /* The size of the anonymous object containing
2104 the bit field is explicit, so use the
2105 indicated size (in bytes). */
2106 anonymous_size
= DW_UNSND (attr
);
2110 /* The size of the anonymous object containing
2111 the bit field must be inferred from the type
2112 attribute of the data member containing the
2114 anonymous_size
= TYPE_LENGTH (fp
->type
);
2116 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2117 - bit_offset
- FIELD_BITSIZE (*fp
);
2121 /* Get name of field. */
2122 attr
= dwarf_attr (die
, DW_AT_name
);
2123 if (attr
&& DW_STRING (attr
))
2124 fieldname
= DW_STRING (attr
);
2125 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
2126 &objfile
->type_obstack
);
2128 /* Change accessibility for artificial fields (e.g. virtual table
2129 pointer or virtual base class pointer) to private. */
2130 if (dwarf_attr (die
, DW_AT_artificial
))
2132 new_field
->accessibility
= DW_ACCESS_private
;
2133 fip
->non_public_fields
= 1;
2136 else if (die
->tag
== DW_TAG_variable
)
2140 /* C++ static member.
2141 Get name of field. */
2142 attr
= dwarf_attr (die
, DW_AT_name
);
2143 if (attr
&& DW_STRING (attr
))
2144 fieldname
= DW_STRING (attr
);
2148 /* Get physical name. */
2149 physname
= dwarf2_linkage_name (die
);
2151 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
2152 &objfile
->type_obstack
));
2153 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
2154 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
2155 &objfile
->type_obstack
);
2157 else if (die
->tag
== DW_TAG_inheritance
)
2159 /* C++ base class field. */
2160 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2162 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
)
2164 FIELD_BITSIZE (*fp
) = 0;
2165 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
2166 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2167 fip
->nbaseclasses
++;
2171 /* Create the vector of fields, and attach it to the type. */
2174 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
2175 struct objfile
*objfile
)
2177 int nfields
= fip
->nfields
;
2179 /* Record the field count, allocate space for the array of fields,
2180 and create blank accessibility bitfields if necessary. */
2181 TYPE_NFIELDS (type
) = nfields
;
2182 TYPE_FIELDS (type
) = (struct field
*)
2183 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2184 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2186 if (fip
->non_public_fields
)
2188 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2190 TYPE_FIELD_PRIVATE_BITS (type
) =
2191 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2192 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2194 TYPE_FIELD_PROTECTED_BITS (type
) =
2195 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2196 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2198 TYPE_FIELD_IGNORE_BITS (type
) =
2199 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2200 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2203 /* If the type has baseclasses, allocate and clear a bit vector for
2204 TYPE_FIELD_VIRTUAL_BITS. */
2205 if (fip
->nbaseclasses
)
2207 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2210 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2211 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2212 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2213 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2214 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2217 /* Copy the saved-up fields into the field vector. Start from the head
2218 of the list, adding to the tail of the field array, so that they end
2219 up in the same order in the array in which they were added to the list. */
2220 while (nfields
-- > 0)
2222 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2223 switch (fip
->fields
->accessibility
)
2225 case DW_ACCESS_private
:
2226 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2229 case DW_ACCESS_protected
:
2230 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2233 case DW_ACCESS_public
:
2237 /* Unknown accessibility. Complain and treat it as public. */
2239 complain (&dwarf2_unsupported_accessibility
,
2240 fip
->fields
->accessibility
);
2244 if (nfields
< fip
->nbaseclasses
)
2246 switch (fip
->fields
->virtuality
)
2248 case DW_VIRTUALITY_virtual
:
2249 case DW_VIRTUALITY_pure_virtual
:
2250 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2254 fip
->fields
= fip
->fields
->next
;
2258 /* Add a member function to the proper fieldlist. */
2261 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2262 struct objfile
*objfile
,
2263 const struct comp_unit_head
*cu_header
)
2265 struct attribute
*attr
;
2266 struct fnfieldlist
*flp
;
2268 struct fn_field
*fnp
;
2271 struct nextfnfield
*new_fnfield
;
2273 /* Get name of member function. */
2274 attr
= dwarf_attr (die
, DW_AT_name
);
2275 if (attr
&& DW_STRING (attr
))
2276 fieldname
= DW_STRING (attr
);
2280 /* Get the mangled name. */
2281 physname
= dwarf2_linkage_name (die
);
2283 /* Look up member function name in fieldlist. */
2284 for (i
= 0; i
< fip
->nfnfields
; i
++)
2286 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2290 /* Create new list element if necessary. */
2291 if (i
< fip
->nfnfields
)
2292 flp
= &fip
->fnfieldlists
[i
];
2295 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2297 fip
->fnfieldlists
= (struct fnfieldlist
*)
2298 xrealloc (fip
->fnfieldlists
,
2299 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2300 * sizeof (struct fnfieldlist
));
2301 if (fip
->nfnfields
== 0)
2302 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2304 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2305 flp
->name
= fieldname
;
2311 /* Create a new member function field and chain it to the field list
2313 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2314 make_cleanup (xfree
, new_fnfield
);
2315 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2316 new_fnfield
->next
= flp
->head
;
2317 flp
->head
= new_fnfield
;
2320 /* Fill in the member function field info. */
2321 fnp
= &new_fnfield
->fnfield
;
2322 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2323 &objfile
->type_obstack
);
2324 fnp
->type
= alloc_type (objfile
);
2325 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2327 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2328 int nparams
= TYPE_NFIELDS (die
->type
);
2330 smash_to_method_type (fnp
->type
, die
->type
,
2331 TYPE_TARGET_TYPE (die
->type
),
2332 TYPE_FIELDS (die
->type
),
2333 TYPE_NFIELDS (die
->type
),
2334 TYPE_VARARGS (die
->type
));
2336 /* Handle static member functions.
2337 Dwarf2 has no clean way to discern C++ static and non-static
2338 member functions. G++ helps GDB by marking the first
2339 parameter for non-static member functions (which is the
2340 this pointer) as artificial. We obtain this information
2341 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2342 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2343 fnp
->voffset
= VOFFSET_STATIC
;
2346 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2348 /* Get fcontext from DW_AT_containing_type if present. */
2349 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2350 fnp
->fcontext
= die_containing_type (die
, objfile
, cu_header
);
2352 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2353 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2355 /* Get accessibility. */
2356 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2359 switch (DW_UNSND (attr
))
2361 case DW_ACCESS_private
:
2362 fnp
->is_private
= 1;
2364 case DW_ACCESS_protected
:
2365 fnp
->is_protected
= 1;
2370 /* Check for artificial methods. */
2371 attr
= dwarf_attr (die
, DW_AT_artificial
);
2372 if (attr
&& DW_UNSND (attr
) != 0)
2373 fnp
->is_artificial
= 1;
2375 /* Get index in virtual function table if it is a virtual member function. */
2376 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2379 /* Support the .debug_loc offsets */
2380 if (attr_form_is_block (attr
))
2382 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) + 2;
2384 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
2386 complain (&dwarf2_complex_location_expr
);
2390 complain (&dwarf2_invalid_attrib_class
, "DW_AT_vtable_elem_location",
2396 /* Create the vector of member function fields, and attach it to the type. */
2399 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2400 struct objfile
*objfile
)
2402 struct fnfieldlist
*flp
;
2403 int total_length
= 0;
2406 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2407 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2408 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2410 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2412 struct nextfnfield
*nfp
= flp
->head
;
2413 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2416 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2417 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2418 fn_flp
->fn_fields
= (struct fn_field
*)
2419 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2420 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2421 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2423 total_length
+= flp
->length
;
2426 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2427 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2430 /* Called when we find the DIE that starts a structure or union scope
2431 (definition) to process all dies that define the members of the
2434 NOTE: we need to call struct_type regardless of whether or not the
2435 DIE has an at_name attribute, since it might be an anonymous
2436 structure or union. This gets the type entered into our set of
2439 However, if the structure is incomplete (an opaque struct/union)
2440 then suppress creating a symbol table entry for it since gdb only
2441 wants to find the one with the complete definition. Note that if
2442 it is complete, we just call new_symbol, which does it's own
2443 checking about whether the struct/union is anonymous or not (and
2444 suppresses creating a symbol table entry itself). */
2447 read_structure_scope (struct die_info
*die
, struct objfile
*objfile
,
2448 const struct comp_unit_head
*cu_header
)
2451 struct attribute
*attr
;
2453 type
= alloc_type (objfile
);
2455 INIT_CPLUS_SPECIFIC (type
);
2456 attr
= dwarf_attr (die
, DW_AT_name
);
2457 if (attr
&& DW_STRING (attr
))
2459 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2460 strlen (DW_STRING (attr
)),
2461 &objfile
->type_obstack
);
2464 if (die
->tag
== DW_TAG_structure_type
)
2466 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2468 else if (die
->tag
== DW_TAG_union_type
)
2470 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2474 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2476 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2479 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2482 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2486 TYPE_LENGTH (type
) = 0;
2489 /* We need to add the type field to the die immediately so we don't
2490 infinitely recurse when dealing with pointers to the structure
2491 type within the structure itself. */
2494 if (die
->has_children
&& ! die_is_declaration (die
))
2496 struct field_info fi
;
2497 struct die_info
*child_die
;
2498 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2500 memset (&fi
, 0, sizeof (struct field_info
));
2502 child_die
= die
->next
;
2504 while (child_die
&& child_die
->tag
)
2506 if (child_die
->tag
== DW_TAG_member
)
2508 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2510 else if (child_die
->tag
== DW_TAG_variable
)
2512 /* C++ static member. */
2513 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2515 else if (child_die
->tag
== DW_TAG_subprogram
)
2517 /* C++ member function. */
2518 process_die (child_die
, objfile
, cu_header
);
2519 dwarf2_add_member_fn (&fi
, child_die
, objfile
, cu_header
);
2521 else if (child_die
->tag
== DW_TAG_inheritance
)
2523 /* C++ base class field. */
2524 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2528 process_die (child_die
, objfile
, cu_header
);
2530 child_die
= sibling_die (child_die
);
2533 /* Attach fields and member functions to the type. */
2535 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2538 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2540 /* Get the type which refers to the base class (possibly this
2541 class itself) which contains the vtable pointer for the current
2542 class from the DW_AT_containing_type attribute. */
2544 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2546 struct type
*t
= die_containing_type (die
, objfile
, cu_header
);
2548 TYPE_VPTR_BASETYPE (type
) = t
;
2551 static const char vptr_name
[] =
2552 {'_', 'v', 'p', 't', 'r', '\0'};
2555 /* Our own class provides vtbl ptr. */
2556 for (i
= TYPE_NFIELDS (t
) - 1;
2557 i
>= TYPE_N_BASECLASSES (t
);
2560 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2562 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2563 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2565 TYPE_VPTR_FIELDNO (type
) = i
;
2570 /* Complain if virtual function table field not found. */
2571 if (i
< TYPE_N_BASECLASSES (t
))
2572 complain (&dwarf2_vtbl_not_found_complaint
,
2573 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2577 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2582 new_symbol (die
, type
, objfile
, cu_header
);
2584 do_cleanups (back_to
);
2588 /* No children, must be stub. */
2589 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2593 /* Given a pointer to a die which begins an enumeration, process all
2594 the dies that define the members of the enumeration.
2596 This will be much nicer in draft 6 of the DWARF spec when our
2597 members will be dies instead squished into the DW_AT_element_list
2600 NOTE: We reverse the order of the element list. */
2603 read_enumeration (struct die_info
*die
, struct objfile
*objfile
,
2604 const struct comp_unit_head
*cu_header
)
2606 struct die_info
*child_die
;
2608 struct field
*fields
;
2609 struct attribute
*attr
;
2612 int unsigned_enum
= 1;
2614 type
= alloc_type (objfile
);
2616 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2617 attr
= dwarf_attr (die
, DW_AT_name
);
2618 if (attr
&& DW_STRING (attr
))
2620 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2621 strlen (DW_STRING (attr
)),
2622 &objfile
->type_obstack
);
2625 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2628 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2632 TYPE_LENGTH (type
) = 0;
2637 if (die
->has_children
)
2639 child_die
= die
->next
;
2640 while (child_die
&& child_die
->tag
)
2642 if (child_die
->tag
!= DW_TAG_enumerator
)
2644 process_die (child_die
, objfile
, cu_header
);
2648 attr
= dwarf_attr (child_die
, DW_AT_name
);
2651 sym
= new_symbol (child_die
, type
, objfile
, cu_header
);
2652 if (SYMBOL_VALUE (sym
) < 0)
2655 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2657 fields
= (struct field
*)
2659 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2660 * sizeof (struct field
));
2663 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2664 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2665 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2666 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2672 child_die
= sibling_die (child_die
);
2677 TYPE_NFIELDS (type
) = num_fields
;
2678 TYPE_FIELDS (type
) = (struct field
*)
2679 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2680 memcpy (TYPE_FIELDS (type
), fields
,
2681 sizeof (struct field
) * num_fields
);
2685 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2688 new_symbol (die
, type
, objfile
, cu_header
);
2691 /* Extract all information from a DW_TAG_array_type DIE and put it in
2692 the DIE's type field. For now, this only handles one dimensional
2696 read_array_type (struct die_info
*die
, struct objfile
*objfile
,
2697 const struct comp_unit_head
*cu_header
)
2699 struct die_info
*child_die
;
2700 struct type
*type
= NULL
;
2701 struct type
*element_type
, *range_type
, *index_type
;
2702 struct type
**range_types
= NULL
;
2703 struct attribute
*attr
;
2705 struct cleanup
*back_to
;
2707 /* Return if we've already decoded this type. */
2713 element_type
= die_type (die
, objfile
, cu_header
);
2715 /* Irix 6.2 native cc creates array types without children for
2716 arrays with unspecified length. */
2717 if (die
->has_children
== 0)
2719 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2720 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2721 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2725 back_to
= make_cleanup (null_cleanup
, NULL
);
2726 child_die
= die
->next
;
2727 while (child_die
&& child_die
->tag
)
2729 if (child_die
->tag
== DW_TAG_subrange_type
)
2731 unsigned int low
, high
;
2733 /* Default bounds to an array with unspecified length. */
2736 if (cu_language
== language_fortran
)
2738 /* FORTRAN implies a lower bound of 1, if not given. */
2742 index_type
= die_type (child_die
, objfile
, cu_header
);
2743 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2746 if (attr
->form
== DW_FORM_sdata
)
2748 low
= DW_SND (attr
);
2750 else if (attr
->form
== DW_FORM_udata
2751 || attr
->form
== DW_FORM_data1
2752 || attr
->form
== DW_FORM_data2
2753 || attr
->form
== DW_FORM_data4
2754 || attr
->form
== DW_FORM_data8
)
2756 low
= DW_UNSND (attr
);
2760 complain (&dwarf2_non_const_array_bound_ignored
,
2761 dwarf_form_name (attr
->form
));
2763 die
->type
= lookup_pointer_type (element_type
);
2770 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2773 if (attr
->form
== DW_FORM_sdata
)
2775 high
= DW_SND (attr
);
2777 else if (attr
->form
== DW_FORM_udata
2778 || attr
->form
== DW_FORM_data1
2779 || attr
->form
== DW_FORM_data2
2780 || attr
->form
== DW_FORM_data4
2781 || attr
->form
== DW_FORM_data8
)
2783 high
= DW_UNSND (attr
);
2785 else if (attr
->form
== DW_FORM_block1
)
2787 /* GCC encodes arrays with unspecified or dynamic length
2788 with a DW_FORM_block1 attribute.
2789 FIXME: GDB does not yet know how to handle dynamic
2790 arrays properly, treat them as arrays with unspecified
2796 complain (&dwarf2_non_const_array_bound_ignored
,
2797 dwarf_form_name (attr
->form
));
2799 die
->type
= lookup_pointer_type (element_type
);
2807 /* Create a range type and save it for array type creation. */
2808 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2810 range_types
= (struct type
**)
2811 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2812 * sizeof (struct type
*));
2814 make_cleanup (free_current_contents
, &range_types
);
2816 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2818 child_die
= sibling_die (child_die
);
2821 /* Dwarf2 dimensions are output from left to right, create the
2822 necessary array types in backwards order. */
2823 type
= element_type
;
2825 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2827 /* Understand Dwarf2 support for vector types (like they occur on
2828 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
2829 array type. This is not part of the Dwarf2/3 standard yet, but a
2830 custom vendor extension. The main difference between a regular
2831 array and the vector variant is that vectors are passed by value
2833 attr
= dwarf_attr (die
, DW_AT_GNU_vector
);
2835 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
2837 do_cleanups (back_to
);
2839 /* Install the type in the die. */
2843 /* First cut: install each common block member as a global variable. */
2846 read_common_block (struct die_info
*die
, struct objfile
*objfile
,
2847 const struct comp_unit_head
*cu_header
)
2849 struct die_info
*child_die
;
2850 struct attribute
*attr
;
2852 CORE_ADDR base
= (CORE_ADDR
) 0;
2854 attr
= dwarf_attr (die
, DW_AT_location
);
2857 /* Support the .debug_loc offsets */
2858 if (attr_form_is_block (attr
))
2860 base
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2862 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
2864 complain (&dwarf2_complex_location_expr
);
2868 complain (&dwarf2_invalid_attrib_class
, "DW_AT_location",
2869 "common block member");
2872 if (die
->has_children
)
2874 child_die
= die
->next
;
2875 while (child_die
&& child_die
->tag
)
2877 sym
= new_symbol (child_die
, NULL
, objfile
, cu_header
);
2878 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2881 SYMBOL_VALUE_ADDRESS (sym
) =
2882 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2883 add_symbol_to_list (sym
, &global_symbols
);
2885 child_die
= sibling_die (child_die
);
2890 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2891 the user defined type vector. */
2894 read_tag_pointer_type (struct die_info
*die
, struct objfile
*objfile
,
2895 const struct comp_unit_head
*cu_header
)
2898 struct attribute
*attr
;
2905 type
= lookup_pointer_type (die_type (die
, objfile
, cu_header
));
2906 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2909 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2913 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2918 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2919 the user defined type vector. */
2922 read_tag_ptr_to_member_type (struct die_info
*die
, struct objfile
*objfile
,
2923 const struct comp_unit_head
*cu_header
)
2926 struct type
*to_type
;
2927 struct type
*domain
;
2934 type
= alloc_type (objfile
);
2935 to_type
= die_type (die
, objfile
, cu_header
);
2936 domain
= die_containing_type (die
, objfile
, cu_header
);
2937 smash_to_member_type (type
, domain
, to_type
);
2942 /* Extract all information from a DW_TAG_reference_type DIE and add to
2943 the user defined type vector. */
2946 read_tag_reference_type (struct die_info
*die
, struct objfile
*objfile
,
2947 const struct comp_unit_head
*cu_header
)
2950 struct attribute
*attr
;
2957 type
= lookup_reference_type (die_type (die
, objfile
, cu_header
));
2958 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2961 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2965 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2971 read_tag_const_type (struct die_info
*die
, struct objfile
*objfile
,
2972 const struct comp_unit_head
*cu_header
)
2974 struct type
*base_type
;
2981 base_type
= die_type (die
, objfile
, cu_header
);
2982 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
2986 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
2987 const struct comp_unit_head
*cu_header
)
2989 struct type
*base_type
;
2996 base_type
= die_type (die
, objfile
, cu_header
);
2997 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
3000 /* Extract all information from a DW_TAG_string_type DIE and add to
3001 the user defined type vector. It isn't really a user defined type,
3002 but it behaves like one, with other DIE's using an AT_user_def_type
3003 attribute to reference it. */
3006 read_tag_string_type (struct die_info
*die
, struct objfile
*objfile
)
3008 struct type
*type
, *range_type
, *index_type
, *char_type
;
3009 struct attribute
*attr
;
3010 unsigned int length
;
3017 attr
= dwarf_attr (die
, DW_AT_string_length
);
3020 length
= DW_UNSND (attr
);
3024 /* check for the DW_AT_byte_size attribute */
3025 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3028 length
= DW_UNSND (attr
);
3035 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
3036 range_type
= create_range_type (NULL
, index_type
, 1, length
);
3037 if (cu_language
== language_fortran
)
3039 /* Need to create a unique string type for bounds
3041 type
= create_string_type (0, range_type
);
3045 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
3046 type
= create_string_type (char_type
, range_type
);
3051 /* Handle DIES due to C code like:
3055 int (*funcp)(int a, long l);
3059 ('funcp' generates a DW_TAG_subroutine_type DIE)
3063 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
3064 const struct comp_unit_head
*cu_header
)
3066 struct type
*type
; /* Type that this function returns */
3067 struct type
*ftype
; /* Function that returns above type */
3068 struct attribute
*attr
;
3070 /* Decode the type that this subroutine returns */
3075 type
= die_type (die
, objfile
, cu_header
);
3076 ftype
= lookup_function_type (type
);
3078 /* All functions in C++ have prototypes. */
3079 attr
= dwarf_attr (die
, DW_AT_prototyped
);
3080 if ((attr
&& (DW_UNSND (attr
) != 0))
3081 || cu_language
== language_cplus
)
3082 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
3084 if (die
->has_children
)
3086 struct die_info
*child_die
;
3090 /* Count the number of parameters.
3091 FIXME: GDB currently ignores vararg functions, but knows about
3092 vararg member functions. */
3093 child_die
= die
->next
;
3094 while (child_die
&& child_die
->tag
)
3096 if (child_die
->tag
== DW_TAG_formal_parameter
)
3098 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
3099 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
3100 child_die
= sibling_die (child_die
);
3103 /* Allocate storage for parameters and fill them in. */
3104 TYPE_NFIELDS (ftype
) = nparams
;
3105 TYPE_FIELDS (ftype
) = (struct field
*)
3106 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
3108 child_die
= die
->next
;
3109 while (child_die
&& child_die
->tag
)
3111 if (child_die
->tag
== DW_TAG_formal_parameter
)
3113 /* Dwarf2 has no clean way to discern C++ static and non-static
3114 member functions. G++ helps GDB by marking the first
3115 parameter for non-static member functions (which is the
3116 this pointer) as artificial. We pass this information
3117 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
3118 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
3120 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
3122 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
3123 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
3127 child_die
= sibling_die (child_die
);
3135 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
3136 const struct comp_unit_head
*cu_header
)
3138 struct attribute
*attr
;
3143 attr
= dwarf_attr (die
, DW_AT_name
);
3144 if (attr
&& DW_STRING (attr
))
3146 name
= DW_STRING (attr
);
3148 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
3149 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, objfile
, cu_header
);
3153 /* Find a representation of a given base type and install
3154 it in the TYPE field of the die. */
3157 read_base_type (struct die_info
*die
, struct objfile
*objfile
)
3160 struct attribute
*attr
;
3161 int encoding
= 0, size
= 0;
3163 /* If we've already decoded this die, this is a no-op. */
3169 attr
= dwarf_attr (die
, DW_AT_encoding
);
3172 encoding
= DW_UNSND (attr
);
3174 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3177 size
= DW_UNSND (attr
);
3179 attr
= dwarf_attr (die
, DW_AT_name
);
3180 if (attr
&& DW_STRING (attr
))
3182 enum type_code code
= TYPE_CODE_INT
;
3187 case DW_ATE_address
:
3188 /* Turn DW_ATE_address into a void * pointer. */
3189 code
= TYPE_CODE_PTR
;
3190 type_flags
|= TYPE_FLAG_UNSIGNED
;
3192 case DW_ATE_boolean
:
3193 code
= TYPE_CODE_BOOL
;
3194 type_flags
|= TYPE_FLAG_UNSIGNED
;
3196 case DW_ATE_complex_float
:
3197 code
= TYPE_CODE_COMPLEX
;
3200 code
= TYPE_CODE_FLT
;
3203 case DW_ATE_signed_char
:
3205 case DW_ATE_unsigned
:
3206 case DW_ATE_unsigned_char
:
3207 type_flags
|= TYPE_FLAG_UNSIGNED
;
3210 complain (&dwarf2_unsupported_at_encoding
,
3211 dwarf_type_encoding_name (encoding
));
3214 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
3215 if (encoding
== DW_ATE_address
)
3216 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
3217 else if (encoding
== DW_ATE_complex_float
)
3220 TYPE_TARGET_TYPE (type
)
3221 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
3222 else if (size
== 16)
3223 TYPE_TARGET_TYPE (type
)
3224 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
3226 TYPE_TARGET_TYPE (type
)
3227 = dwarf2_fundamental_type (objfile
, FT_FLOAT
);
3232 type
= dwarf_base_type (encoding
, size
, objfile
);
3237 /* Read a whole compilation unit into a linked list of dies. */
3239 static struct die_info
*
3240 read_comp_unit (char *info_ptr
, bfd
*abfd
,
3241 const struct comp_unit_head
*cu_header
)
3243 struct die_info
*first_die
, *last_die
, *die
;
3247 /* Reset die reference table; we are
3248 building new ones now. */
3249 dwarf2_empty_hash_tables ();
3253 first_die
= last_die
= NULL
;
3256 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
, cu_header
);
3257 if (die
->has_children
)
3268 /* Enter die in reference hash table */
3269 store_in_ref_table (die
->offset
, die
);
3273 first_die
= last_die
= die
;
3277 last_die
->next
= die
;
3281 while (nesting_level
> 0);
3285 /* Free a linked list of dies. */
3288 free_die_list (struct die_info
*dies
)
3290 struct die_info
*die
, *next
;
3303 do_free_die_list_cleanup (void *dies
)
3305 free_die_list (dies
);
3308 static struct cleanup
*
3309 make_cleanup_free_die_list (struct die_info
*dies
)
3311 return make_cleanup (do_free_die_list_cleanup
, dies
);
3315 /* Read the contents of the section at OFFSET and of size SIZE from the
3316 object file specified by OBJFILE into the psymbol_obstack and return it. */
3319 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
3322 bfd
*abfd
= objfile
->obfd
;
3328 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3329 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
3330 (bfd_bread (buf
, size
, abfd
) != size
))
3333 error ("Dwarf Error: Can't read DWARF data from '%s'",
3334 bfd_get_filename (abfd
));
3339 /* In DWARF version 2, the description of the debugging information is
3340 stored in a separate .debug_abbrev section. Before we read any
3341 dies from a section we read in all abbreviations and install them
3345 dwarf2_read_abbrevs (bfd
*abfd
, unsigned int offset
)
3348 struct abbrev_info
*cur_abbrev
;
3349 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3350 unsigned int abbrev_form
, hash_number
;
3352 /* empty the table */
3353 dwarf2_empty_abbrev_table (NULL
);
3355 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3356 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3357 abbrev_ptr
+= bytes_read
;
3359 /* loop until we reach an abbrev number of 0 */
3360 while (abbrev_number
)
3362 cur_abbrev
= dwarf_alloc_abbrev ();
3364 /* read in abbrev header */
3365 cur_abbrev
->number
= abbrev_number
;
3366 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3367 abbrev_ptr
+= bytes_read
;
3368 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3371 /* now read in declarations */
3372 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3373 abbrev_ptr
+= bytes_read
;
3374 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3375 abbrev_ptr
+= bytes_read
;
3378 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3380 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3381 xrealloc (cur_abbrev
->attrs
,
3382 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3383 * sizeof (struct attr_abbrev
));
3385 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3386 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3387 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3388 abbrev_ptr
+= bytes_read
;
3389 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3390 abbrev_ptr
+= bytes_read
;
3393 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3394 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3395 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3397 /* Get next abbreviation.
3398 Under Irix6 the abbreviations for a compilation unit are not
3399 always properly terminated with an abbrev number of 0.
3400 Exit loop if we encounter an abbreviation which we have
3401 already read (which means we are about to read the abbreviations
3402 for the next compile unit) or if the end of the abbreviation
3403 table is reached. */
3404 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3405 >= dwarf_abbrev_size
)
3407 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3408 abbrev_ptr
+= bytes_read
;
3409 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3414 /* Empty the abbrev table for a new compilation unit. */
3418 dwarf2_empty_abbrev_table (PTR ignore
)
3421 struct abbrev_info
*abbrev
, *next
;
3423 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3426 abbrev
= dwarf2_abbrevs
[i
];
3429 next
= abbrev
->next
;
3430 xfree (abbrev
->attrs
);
3434 dwarf2_abbrevs
[i
] = NULL
;
3438 /* Lookup an abbrev_info structure in the abbrev hash table. */
3440 static struct abbrev_info
*
3441 dwarf2_lookup_abbrev (unsigned int number
)
3443 unsigned int hash_number
;
3444 struct abbrev_info
*abbrev
;
3446 hash_number
= number
% ABBREV_HASH_SIZE
;
3447 abbrev
= dwarf2_abbrevs
[hash_number
];
3451 if (abbrev
->number
== number
)
3454 abbrev
= abbrev
->next
;
3459 /* Read a minimal amount of information into the minimal die structure. */
3462 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3463 char *info_ptr
, const struct comp_unit_head
*cu_header
)
3465 unsigned int abbrev_number
, bytes_read
, i
;
3466 struct abbrev_info
*abbrev
;
3467 struct attribute attr
;
3468 struct attribute spec_attr
;
3469 int found_spec_attr
= 0;
3470 int has_low_pc_attr
= 0;
3471 int has_high_pc_attr
= 0;
3473 *part_die
= zeroed_partial_die
;
3474 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3475 info_ptr
+= bytes_read
;
3479 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3482 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3484 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3485 part_die
->tag
= abbrev
->tag
;
3486 part_die
->has_children
= abbrev
->has_children
;
3487 part_die
->abbrev
= abbrev_number
;
3489 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3491 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
3492 info_ptr
, cu_header
);
3494 /* Store the data if it is of an attribute we want to keep in a
3495 partial symbol table. */
3500 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3501 if (part_die
->name
== NULL
)
3502 part_die
->name
= DW_STRING (&attr
);
3504 case DW_AT_MIPS_linkage_name
:
3505 part_die
->name
= DW_STRING (&attr
);
3508 has_low_pc_attr
= 1;
3509 part_die
->lowpc
= DW_ADDR (&attr
);
3512 has_high_pc_attr
= 1;
3513 part_die
->highpc
= DW_ADDR (&attr
);
3515 case DW_AT_location
:
3516 /* Support the .debug_loc offsets */
3517 if (attr_form_is_block (&attr
))
3519 part_die
->locdesc
= DW_BLOCK (&attr
);
3521 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
3523 complain (&dwarf2_complex_location_expr
);
3527 complain (&dwarf2_invalid_attrib_class
, "DW_AT_location",
3528 "partial symbol information");
3531 case DW_AT_language
:
3532 part_die
->language
= DW_UNSND (&attr
);
3534 case DW_AT_external
:
3535 part_die
->is_external
= DW_UNSND (&attr
);
3537 case DW_AT_declaration
:
3538 part_die
->is_declaration
= DW_UNSND (&attr
);
3541 part_die
->has_type
= 1;
3543 case DW_AT_abstract_origin
:
3544 case DW_AT_specification
:
3545 found_spec_attr
= 1;
3549 /* Ignore absolute siblings, they might point outside of
3550 the current compile unit. */
3551 if (attr
.form
== DW_FORM_ref_addr
)
3552 complain (&dwarf2_absolute_sibling_complaint
);
3555 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3562 /* If we found a reference attribute and the die has no name, try
3563 to find a name in the referred to die. */
3565 if (found_spec_attr
&& part_die
->name
== NULL
)
3567 struct partial_die_info spec_die
;
3571 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3572 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu_header
);
3575 part_die
->name
= spec_die
.name
;
3577 /* Copy DW_AT_external attribute if it is set. */
3578 if (spec_die
.is_external
)
3579 part_die
->is_external
= spec_die
.is_external
;
3583 /* When using the GNU linker, .gnu.linkonce. sections are used to
3584 eliminate duplicate copies of functions and vtables and such.
3585 The linker will arbitrarily choose one and discard the others.
3586 The AT_*_pc values for such functions refer to local labels in
3587 these sections. If the section from that file was discarded, the
3588 labels are not in the output, so the relocs get a value of 0.
3589 If this is a discarded function, mark the pc bounds as invalid,
3590 so that GDB will ignore it. */
3591 if (has_low_pc_attr
&& has_high_pc_attr
3592 && part_die
->lowpc
< part_die
->highpc
3593 && (part_die
->lowpc
!= 0
3594 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3595 part_die
->has_pc_info
= 1;
3599 /* Read the die from the .debug_info section buffer. And set diep to
3600 point to a newly allocated die with its information. */
3603 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
3604 const struct comp_unit_head
*cu_header
)
3606 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3607 struct abbrev_info
*abbrev
;
3608 struct die_info
*die
;
3610 offset
= info_ptr
- dwarf_info_buffer
;
3611 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3612 info_ptr
+= bytes_read
;
3615 die
= dwarf_alloc_die ();
3617 die
->abbrev
= abbrev_number
;
3623 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3626 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3628 die
= dwarf_alloc_die ();
3629 die
->offset
= offset
;
3630 die
->tag
= abbrev
->tag
;
3631 die
->has_children
= abbrev
->has_children
;
3632 die
->abbrev
= abbrev_number
;
3635 die
->num_attrs
= abbrev
->num_attrs
;
3636 die
->attrs
= (struct attribute
*)
3637 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3639 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3641 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3642 abfd
, info_ptr
, cu_header
);
3649 /* Read an attribute value described by an attribute form. */
3652 read_attribute_value (struct attribute
*attr
, unsigned form
,
3653 bfd
*abfd
, char *info_ptr
,
3654 const struct comp_unit_head
*cu_header
)
3656 unsigned int bytes_read
;
3657 struct dwarf_block
*blk
;
3663 case DW_FORM_ref_addr
:
3664 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
3665 info_ptr
+= bytes_read
;
3667 case DW_FORM_block2
:
3668 blk
= dwarf_alloc_block ();
3669 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3671 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3672 info_ptr
+= blk
->size
;
3673 DW_BLOCK (attr
) = blk
;
3675 case DW_FORM_block4
:
3676 blk
= dwarf_alloc_block ();
3677 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3679 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3680 info_ptr
+= blk
->size
;
3681 DW_BLOCK (attr
) = blk
;
3684 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3688 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3692 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3695 case DW_FORM_string
:
3696 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3697 info_ptr
+= bytes_read
;
3700 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
3702 info_ptr
+= bytes_read
;
3705 blk
= dwarf_alloc_block ();
3706 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3707 info_ptr
+= bytes_read
;
3708 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3709 info_ptr
+= blk
->size
;
3710 DW_BLOCK (attr
) = blk
;
3712 case DW_FORM_block1
:
3713 blk
= dwarf_alloc_block ();
3714 blk
->size
= read_1_byte (abfd
, info_ptr
);
3716 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3717 info_ptr
+= blk
->size
;
3718 DW_BLOCK (attr
) = blk
;
3721 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3725 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3729 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3730 info_ptr
+= bytes_read
;
3733 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3734 info_ptr
+= bytes_read
;
3737 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3741 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3745 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3749 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3752 case DW_FORM_ref_udata
:
3753 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3754 info_ptr
+= bytes_read
;
3756 case DW_FORM_indirect
:
3757 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3758 info_ptr
+= bytes_read
;
3759 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu_header
);
3762 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3763 dwarf_form_name (form
));
3768 /* Read an attribute described by an abbreviated attribute. */
3771 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
3772 bfd
*abfd
, char *info_ptr
,
3773 const struct comp_unit_head
*cu_header
)
3775 attr
->name
= abbrev
->name
;
3776 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu_header
);
3779 /* read dwarf information from a buffer */
3782 read_1_byte (bfd
*abfd
, char *buf
)
3784 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3788 read_1_signed_byte (bfd
*abfd
, char *buf
)
3790 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3794 read_2_bytes (bfd
*abfd
, char *buf
)
3796 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3800 read_2_signed_bytes (bfd
*abfd
, char *buf
)
3802 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3806 read_4_bytes (bfd
*abfd
, char *buf
)
3808 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3812 read_4_signed_bytes (bfd
*abfd
, char *buf
)
3814 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3817 static unsigned long
3818 read_8_bytes (bfd
*abfd
, char *buf
)
3820 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3824 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3827 CORE_ADDR retval
= 0;
3829 if (cu_header
->signed_addr_p
)
3831 switch (cu_header
->addr_size
)
3834 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3837 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3840 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
3843 internal_error (__FILE__
, __LINE__
,
3844 "read_address: bad switch, signed");
3849 switch (cu_header
->addr_size
)
3852 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3855 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3858 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3861 internal_error (__FILE__
, __LINE__
,
3862 "read_address: bad switch, unsigned");
3866 *bytes_read
= cu_header
->addr_size
;
3870 /* Read the initial length from a section. The (draft) DWARF 3
3871 specification allows the initial length to take up either 4 bytes
3872 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
3873 bytes describe the length and all offsets will be 8 bytes in length
3876 An older, non-standard 64-bit format is also handled by this
3877 function. The older format in question stores the initial length
3878 as an 8-byte quantity without an escape value. Lengths greater
3879 than 2^32 aren't very common which means that the initial 4 bytes
3880 is almost always zero. Since a length value of zero doesn't make
3881 sense for the 32-bit format, this initial zero can be considered to
3882 be an escape value which indicates the presence of the older 64-bit
3883 format. As written, the code can't detect (old format) lengths
3884 greater than 4GB. If it becomes necessary to handle lengths somewhat
3885 larger than 4GB, we could allow other small values (such as the
3886 non-sensical values of 1, 2, and 3) to also be used as escape values
3887 indicating the presence of the old format.
3889 The value returned via bytes_read should be used to increment
3890 the relevant pointer after calling read_initial_length().
3892 As a side effect, this function sets the fields initial_length_size
3893 and offset_size in cu_header to the values appropriate for the
3894 length field. (The format of the initial length field determines
3895 the width of file offsets to be fetched later with fetch_offset().)
3897 [ Note: read_initial_length() and read_offset() are based on the
3898 document entitled "DWARF Debugging Information Format", revision
3899 3, draft 8, dated November 19, 2001. This document was obtained
3902 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
3904 This document is only a draft and is subject to change. (So beware.)
3906 Details regarding the older, non-standard 64-bit format were
3907 determined empirically by examining 64-bit ELF files produced
3908 by the SGI toolchain on an IRIX 6.5 machine.
3910 - Kevin, July 16, 2002
3914 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
3919 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3921 if (retval
== 0xffffffff)
3923 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
3925 if (cu_header
!= NULL
)
3927 cu_header
->initial_length_size
= 12;
3928 cu_header
->offset_size
= 8;
3931 else if (retval
== 0)
3933 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
3935 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3937 if (cu_header
!= NULL
)
3939 cu_header
->initial_length_size
= 8;
3940 cu_header
->offset_size
= 8;
3946 if (cu_header
!= NULL
)
3948 cu_header
->initial_length_size
= 4;
3949 cu_header
->offset_size
= 4;
3956 /* Read an offset from the data stream. The size of the offset is
3957 given by cu_header->offset_size. */
3960 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3965 switch (cu_header
->offset_size
)
3968 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3972 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3976 internal_error (__FILE__
, __LINE__
,
3977 "read_offset: bad switch");
3984 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
3986 /* If the size of a host char is 8 bits, we can return a pointer
3987 to the buffer, otherwise we have to copy the data to a buffer
3988 allocated on the temporary obstack. */
3989 gdb_assert (HOST_CHAR_BIT
== 8);
3994 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3996 /* If the size of a host char is 8 bits, we can return a pointer
3997 to the string, otherwise we have to copy the string to a buffer
3998 allocated on the temporary obstack. */
3999 gdb_assert (HOST_CHAR_BIT
== 8);
4002 *bytes_read_ptr
= 1;
4005 *bytes_read_ptr
= strlen (buf
) + 1;
4010 read_indirect_string (bfd
*abfd
, char *buf
,
4011 const struct comp_unit_head
*cu_header
,
4012 unsigned int *bytes_read_ptr
)
4014 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
4015 (int *) bytes_read_ptr
);
4017 if (dwarf_str_buffer
== NULL
)
4019 error ("DW_FORM_strp used without .debug_str section");
4022 if (str_offset
>= dwarf_str_size
)
4024 error ("DW_FORM_strp pointing outside of .debug_str section");
4027 gdb_assert (HOST_CHAR_BIT
== 8);
4028 if (dwarf_str_buffer
[str_offset
] == '\0')
4030 return dwarf_str_buffer
+ str_offset
;
4033 static unsigned long
4034 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4036 unsigned long result
;
4037 unsigned int num_read
;
4047 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4050 result
|= ((unsigned long)(byte
& 127) << shift
);
4051 if ((byte
& 128) == 0)
4057 *bytes_read_ptr
= num_read
;
4062 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4065 int i
, shift
, size
, num_read
;
4075 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4078 result
|= ((long)(byte
& 127) << shift
);
4080 if ((byte
& 128) == 0)
4085 if ((shift
< size
) && (byte
& 0x40))
4087 result
|= -(1 << shift
);
4089 *bytes_read_ptr
= num_read
;
4094 set_cu_language (unsigned int lang
)
4100 cu_language
= language_c
;
4102 case DW_LANG_C_plus_plus
:
4103 cu_language
= language_cplus
;
4105 case DW_LANG_Fortran77
:
4106 case DW_LANG_Fortran90
:
4107 case DW_LANG_Fortran95
:
4108 cu_language
= language_fortran
;
4110 case DW_LANG_Mips_Assembler
:
4111 cu_language
= language_asm
;
4114 cu_language
= language_java
;
4118 case DW_LANG_Cobol74
:
4119 case DW_LANG_Cobol85
:
4120 case DW_LANG_Pascal83
:
4121 case DW_LANG_Modula2
:
4123 cu_language
= language_unknown
;
4126 cu_language_defn
= language_def (cu_language
);
4129 /* Return the named attribute or NULL if not there. */
4131 static struct attribute
*
4132 dwarf_attr (struct die_info
*die
, unsigned int name
)
4135 struct attribute
*spec
= NULL
;
4137 for (i
= 0; i
< die
->num_attrs
; ++i
)
4139 if (die
->attrs
[i
].name
== name
)
4141 return &die
->attrs
[i
];
4143 if (die
->attrs
[i
].name
== DW_AT_specification
4144 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
4145 spec
= &die
->attrs
[i
];
4149 struct die_info
*ref_die
=
4150 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
4153 return dwarf_attr (ref_die
, name
);
4160 die_is_declaration (struct die_info
*die
)
4162 return (dwarf_attr (die
, DW_AT_declaration
)
4163 && ! dwarf_attr (die
, DW_AT_specification
));
4167 /* Free the line_header structure *LH, and any arrays and strings it
4170 free_line_header (struct line_header
*lh
)
4172 if (lh
->standard_opcode_lengths
)
4173 xfree (lh
->standard_opcode_lengths
);
4175 /* Remember that all the lh->file_names[i].name pointers are
4176 pointers into debug_line_buffer, and don't need to be freed. */
4178 xfree (lh
->file_names
);
4180 /* Similarly for the include directory names. */
4181 if (lh
->include_dirs
)
4182 xfree (lh
->include_dirs
);
4188 /* Add an entry to LH's include directory table. */
4190 add_include_dir (struct line_header
*lh
, char *include_dir
)
4192 /* Grow the array if necessary. */
4193 if (lh
->include_dirs_size
== 0)
4195 lh
->include_dirs_size
= 1; /* for testing */
4196 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
4197 * sizeof (*lh
->include_dirs
));
4199 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
4201 lh
->include_dirs_size
*= 2;
4202 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
4203 (lh
->include_dirs_size
4204 * sizeof (*lh
->include_dirs
)));
4207 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
4211 /* Add an entry to LH's file name table. */
4213 add_file_name (struct line_header
*lh
,
4215 unsigned int dir_index
,
4216 unsigned int mod_time
,
4217 unsigned int length
)
4219 struct file_entry
*fe
;
4221 /* Grow the array if necessary. */
4222 if (lh
->file_names_size
== 0)
4224 lh
->file_names_size
= 1; /* for testing */
4225 lh
->file_names
= xmalloc (lh
->file_names_size
4226 * sizeof (*lh
->file_names
));
4228 else if (lh
->num_file_names
>= lh
->file_names_size
)
4230 lh
->file_names_size
*= 2;
4231 lh
->file_names
= xrealloc (lh
->file_names
,
4232 (lh
->file_names_size
4233 * sizeof (*lh
->file_names
)));
4236 fe
= &lh
->file_names
[lh
->num_file_names
++];
4238 fe
->dir_index
= dir_index
;
4239 fe
->mod_time
= mod_time
;
4240 fe
->length
= length
;
4244 /* Read the statement program header starting at OFFSET in
4245 dwarf_line_buffer, according to the endianness of ABFD. Return a
4246 pointer to a struct line_header, allocated using xmalloc.
4248 NOTE: the strings in the include directory and file name tables of
4249 the returned object point into debug_line_buffer, and must not be
4251 static struct line_header
*
4252 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
4253 const struct comp_unit_head
*cu_header
)
4255 struct cleanup
*back_to
;
4256 struct line_header
*lh
;
4260 char *cur_dir
, *cur_file
;
4262 if (dwarf_line_buffer
== NULL
)
4264 complain (&dwarf2_missing_line_number_section
);
4268 /* Make sure that at least there's room for the total_length field. That
4269 could be 12 bytes long, but we're just going to fudge that. */
4270 if (offset
+ 4 >= dwarf_line_size
)
4272 complain (&dwarf2_statement_list_fits_in_line_number_section
);
4276 lh
= xmalloc (sizeof (*lh
));
4277 memset (lh
, 0, sizeof (*lh
));
4278 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
4281 line_ptr
= dwarf_line_buffer
+ offset
;
4283 /* read in the header */
4284 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
4285 line_ptr
+= bytes_read
;
4286 if (line_ptr
+ lh
->total_length
> dwarf_line_buffer
+ dwarf_line_size
)
4288 complain (&dwarf2_statement_list_fits_in_line_number_section
);
4291 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
4292 lh
->version
= read_2_bytes (abfd
, line_ptr
);
4294 lh
->header_length
= read_offset (abfd
, line_ptr
, cu_header
, &bytes_read
);
4295 line_ptr
+= bytes_read
;
4296 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
4298 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
4300 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
4302 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
4304 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
4306 lh
->standard_opcode_lengths
4307 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
4309 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
4310 for (i
= 1; i
< lh
->opcode_base
; ++i
)
4312 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
4316 /* Read directory table */
4317 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4319 line_ptr
+= bytes_read
;
4320 add_include_dir (lh
, cur_dir
);
4322 line_ptr
+= bytes_read
;
4324 /* Read file name table */
4325 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4327 unsigned int dir_index
, mod_time
, length
;
4329 line_ptr
+= bytes_read
;
4330 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4331 line_ptr
+= bytes_read
;
4332 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4333 line_ptr
+= bytes_read
;
4334 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4335 line_ptr
+= bytes_read
;
4337 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4339 line_ptr
+= bytes_read
;
4340 lh
->statement_program_start
= line_ptr
;
4342 if (line_ptr
> dwarf_line_buffer
+ dwarf_line_size
)
4343 complain (&dwarf2_line_header_too_long
);
4345 discard_cleanups (back_to
);
4349 /* This function exists to work around a bug in certain compilers
4350 (particularly GCC 2.95), in which the first line number marker of a
4351 function does not show up until after the prologue, right before
4352 the second line number marker. This function shifts ADDRESS down
4353 to the beginning of the function if necessary, and is called on
4354 addresses passed to record_line. */
4357 check_cu_functions (CORE_ADDR address
)
4359 struct function_range
*fn
;
4361 /* Find the function_range containing address. */
4366 cu_cached_fn
= cu_first_fn
;
4370 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4376 while (fn
&& fn
!= cu_cached_fn
)
4377 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4387 if (address
!= fn
->lowpc
)
4388 complain (&dwarf2_misplaced_line_number
,
4389 (unsigned long) address
, fn
->name
);
4394 /* Decode the line number information for the compilation unit whose
4395 line number info is at OFFSET in the .debug_line section.
4396 The compilation directory of the file is passed in COMP_DIR. */
4399 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
4400 const struct comp_unit_head
*cu_header
)
4404 unsigned int i
, bytes_read
;
4406 unsigned char op_code
, extended_op
, adj_opcode
;
4408 line_ptr
= lh
->statement_program_start
;
4409 line_end
= lh
->statement_program_end
;
4411 /* Read the statement sequences until there's nothing left. */
4412 while (line_ptr
< line_end
)
4414 /* state machine registers */
4415 CORE_ADDR address
= 0;
4416 unsigned int file
= 1;
4417 unsigned int line
= 1;
4418 unsigned int column
= 0;
4419 int is_stmt
= lh
->default_is_stmt
;
4420 int basic_block
= 0;
4421 int end_sequence
= 0;
4423 /* Start a subfile for the current file of the state machine. */
4424 if (lh
->num_file_names
>= file
)
4426 /* lh->include_dirs and lh->file_names are 0-based, but the
4427 directory and file name numbers in the statement program
4429 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
4432 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
4435 dwarf2_start_subfile (fe
->name
, dir
);
4438 /* Decode the table. */
4439 while (!end_sequence
)
4441 op_code
= read_1_byte (abfd
, line_ptr
);
4444 if (op_code
>= lh
->opcode_base
)
4445 { /* Special operand. */
4446 adj_opcode
= op_code
- lh
->opcode_base
;
4447 address
+= (adj_opcode
/ lh
->line_range
)
4448 * lh
->minimum_instruction_length
;
4449 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
4450 /* append row to matrix using current values */
4451 address
= check_cu_functions (address
);
4452 record_line (current_subfile
, line
, address
);
4455 else switch (op_code
)
4457 case DW_LNS_extended_op
:
4458 line_ptr
+= 1; /* ignore length */
4459 extended_op
= read_1_byte (abfd
, line_ptr
);
4461 switch (extended_op
)
4463 case DW_LNE_end_sequence
:
4465 record_line (current_subfile
, 0, address
);
4467 case DW_LNE_set_address
:
4468 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
4469 line_ptr
+= bytes_read
;
4470 address
+= baseaddr
;
4472 case DW_LNE_define_file
:
4475 unsigned int dir_index
, mod_time
, length
;
4477 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
4478 line_ptr
+= bytes_read
;
4480 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4481 line_ptr
+= bytes_read
;
4483 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4484 line_ptr
+= bytes_read
;
4486 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4487 line_ptr
+= bytes_read
;
4488 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4492 complain (&dwarf2_mangled_line_number_section
);
4497 address
= check_cu_functions (address
);
4498 record_line (current_subfile
, line
, address
);
4501 case DW_LNS_advance_pc
:
4502 address
+= lh
->minimum_instruction_length
4503 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4504 line_ptr
+= bytes_read
;
4506 case DW_LNS_advance_line
:
4507 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
4508 line_ptr
+= bytes_read
;
4510 case DW_LNS_set_file
:
4512 /* lh->include_dirs and lh->file_names are 0-based,
4513 but the directory and file name numbers in the
4514 statement program are 1-based. */
4515 struct file_entry
*fe
;
4517 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4518 line_ptr
+= bytes_read
;
4519 fe
= &lh
->file_names
[file
- 1];
4521 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
4524 dwarf2_start_subfile (fe
->name
, dir
);
4527 case DW_LNS_set_column
:
4528 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4529 line_ptr
+= bytes_read
;
4531 case DW_LNS_negate_stmt
:
4532 is_stmt
= (!is_stmt
);
4534 case DW_LNS_set_basic_block
:
4537 /* Add to the address register of the state machine the
4538 address increment value corresponding to special opcode
4539 255. Ie, this value is scaled by the minimum instruction
4540 length since special opcode 255 would have scaled the
4542 case DW_LNS_const_add_pc
:
4543 address
+= (lh
->minimum_instruction_length
4544 * ((255 - lh
->opcode_base
) / lh
->line_range
));
4546 case DW_LNS_fixed_advance_pc
:
4547 address
+= read_2_bytes (abfd
, line_ptr
);
4551 { /* Unknown standard opcode, ignore it. */
4553 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
4555 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4556 line_ptr
+= bytes_read
;
4564 /* Start a subfile for DWARF. FILENAME is the name of the file and
4565 DIRNAME the name of the source directory which contains FILENAME
4566 or NULL if not known.
4567 This routine tries to keep line numbers from identical absolute and
4568 relative file names in a common subfile.
4570 Using the `list' example from the GDB testsuite, which resides in
4571 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4572 of /srcdir/list0.c yields the following debugging information for list0.c:
4574 DW_AT_name: /srcdir/list0.c
4575 DW_AT_comp_dir: /compdir
4576 files.files[0].name: list0.h
4577 files.files[0].dir: /srcdir
4578 files.files[1].name: list0.c
4579 files.files[1].dir: /srcdir
4581 The line number information for list0.c has to end up in a single
4582 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4585 dwarf2_start_subfile (char *filename
, char *dirname
)
4587 /* If the filename isn't absolute, try to match an existing subfile
4588 with the full pathname. */
4590 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
4592 struct subfile
*subfile
;
4593 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4595 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4597 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
4599 current_subfile
= subfile
;
4606 start_subfile (filename
, dirname
);
4609 /* Given a pointer to a DWARF information entry, figure out if we need
4610 to make a symbol table entry for it, and if so, create a new entry
4611 and return a pointer to it.
4612 If TYPE is NULL, determine symbol type from the die, otherwise
4613 used the passed type. */
4615 static struct symbol
*
4616 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
4617 const struct comp_unit_head
*cu_header
)
4619 struct symbol
*sym
= NULL
;
4621 struct attribute
*attr
= NULL
;
4622 struct attribute
*attr2
= NULL
;
4625 name
= dwarf2_linkage_name (die
);
4628 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4629 sizeof (struct symbol
));
4630 OBJSTAT (objfile
, n_syms
++);
4631 memset (sym
, 0, sizeof (struct symbol
));
4632 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4633 &objfile
->symbol_obstack
);
4635 /* Default assumptions.
4636 Use the passed type or decode it from the die. */
4637 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4638 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4640 SYMBOL_TYPE (sym
) = type
;
4642 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
4643 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4646 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4649 /* If this symbol is from a C++ compilation, then attempt to
4650 cache the demangled form for future reference. This is a
4651 typical time versus space tradeoff, that was decided in favor
4652 of time because it sped up C++ symbol lookups by a factor of
4655 SYMBOL_LANGUAGE (sym
) = cu_language
;
4656 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4660 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4663 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4665 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4667 case DW_TAG_subprogram
:
4668 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4670 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4671 attr2
= dwarf_attr (die
, DW_AT_external
);
4672 if (attr2
&& (DW_UNSND (attr2
) != 0))
4674 add_symbol_to_list (sym
, &global_symbols
);
4678 add_symbol_to_list (sym
, list_in_scope
);
4681 case DW_TAG_variable
:
4682 /* Compilation with minimal debug info may result in variables
4683 with missing type entries. Change the misleading `void' type
4684 to something sensible. */
4685 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4686 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4687 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4688 "<variable, no debug info>",
4690 attr
= dwarf_attr (die
, DW_AT_const_value
);
4693 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4694 attr2
= dwarf_attr (die
, DW_AT_external
);
4695 if (attr2
&& (DW_UNSND (attr2
) != 0))
4696 add_symbol_to_list (sym
, &global_symbols
);
4698 add_symbol_to_list (sym
, list_in_scope
);
4701 attr
= dwarf_attr (die
, DW_AT_location
);
4704 attr2
= dwarf_attr (die
, DW_AT_external
);
4705 if (attr2
&& (DW_UNSND (attr2
) != 0))
4707 /* Support the .debug_loc offsets */
4708 if (attr_form_is_block (attr
))
4710 SYMBOL_VALUE_ADDRESS (sym
) =
4711 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4713 else if (attr
->form
== DW_FORM_data4
4714 || attr
->form
== DW_FORM_data8
)
4716 complain (&dwarf2_complex_location_expr
);
4720 complain (&dwarf2_invalid_attrib_class
, "DW_AT_location",
4721 "external variable");
4723 add_symbol_to_list (sym
, &global_symbols
);
4725 /* In shared libraries the address of the variable
4726 in the location descriptor might still be relocatable,
4727 so its value could be zero.
4728 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4729 value is zero, the address of the variable will then
4730 be determined from the minimal symbol table whenever
4731 the variable is referenced. */
4732 if (SYMBOL_VALUE_ADDRESS (sym
))
4734 fixup_symbol_section (sym
, objfile
);
4735 SYMBOL_VALUE_ADDRESS (sym
) +=
4736 ANOFFSET (objfile
->section_offsets
,
4737 SYMBOL_SECTION (sym
));
4738 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4741 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4745 /* Support the .debug_loc offsets */
4746 if (attr_form_is_block (attr
))
4748 SYMBOL_VALUE (sym
) = addr
=
4749 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4751 else if (attr
->form
== DW_FORM_data4
4752 || attr
->form
== DW_FORM_data8
)
4754 complain (&dwarf2_complex_location_expr
);
4758 complain (&dwarf2_invalid_attrib_class
, "DW_AT_location",
4759 "external variable");
4762 add_symbol_to_list (sym
, list_in_scope
);
4765 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4769 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4770 SYMBOL_VALUE (sym
) =
4771 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4775 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4776 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4780 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4784 fixup_symbol_section (sym
, objfile
);
4785 SYMBOL_VALUE_ADDRESS (sym
) =
4786 addr
+ ANOFFSET (objfile
->section_offsets
,
4787 SYMBOL_SECTION (sym
));
4788 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4794 /* We do not know the address of this symbol.
4795 If it is an external symbol and we have type information
4796 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4797 The address of the variable will then be determined from
4798 the minimal symbol table whenever the variable is
4800 attr2
= dwarf_attr (die
, DW_AT_external
);
4801 if (attr2
&& (DW_UNSND (attr2
) != 0)
4802 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4804 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4805 add_symbol_to_list (sym
, &global_symbols
);
4809 case DW_TAG_formal_parameter
:
4810 attr
= dwarf_attr (die
, DW_AT_location
);
4813 SYMBOL_VALUE (sym
) =
4814 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4817 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4818 SYMBOL_VALUE (sym
) =
4819 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4825 if (basereg
!= frame_base_reg
)
4826 complain (&dwarf2_complex_location_expr
);
4827 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4831 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4832 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4837 SYMBOL_CLASS (sym
) = LOC_ARG
;
4840 attr
= dwarf_attr (die
, DW_AT_const_value
);
4843 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4845 add_symbol_to_list (sym
, list_in_scope
);
4847 case DW_TAG_unspecified_parameters
:
4848 /* From varargs functions; gdb doesn't seem to have any
4849 interest in this information, so just ignore it for now.
4852 case DW_TAG_class_type
:
4853 case DW_TAG_structure_type
:
4854 case DW_TAG_union_type
:
4855 case DW_TAG_enumeration_type
:
4856 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4857 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4858 add_symbol_to_list (sym
, list_in_scope
);
4860 /* The semantics of C++ state that "struct foo { ... }" also
4861 defines a typedef for "foo". Synthesize a typedef symbol so
4862 that "ptype foo" works as expected. */
4863 if (cu_language
== language_cplus
)
4865 struct symbol
*typedef_sym
= (struct symbol
*)
4866 obstack_alloc (&objfile
->symbol_obstack
,
4867 sizeof (struct symbol
));
4868 *typedef_sym
= *sym
;
4869 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4870 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4871 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4872 obsavestring (SYMBOL_NAME (sym
),
4873 strlen (SYMBOL_NAME (sym
)),
4874 &objfile
->type_obstack
);
4875 add_symbol_to_list (typedef_sym
, list_in_scope
);
4878 case DW_TAG_typedef
:
4879 case DW_TAG_base_type
:
4880 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4881 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4882 add_symbol_to_list (sym
, list_in_scope
);
4884 case DW_TAG_enumerator
:
4885 attr
= dwarf_attr (die
, DW_AT_const_value
);
4888 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4890 add_symbol_to_list (sym
, list_in_scope
);
4893 /* Not a tag we recognize. Hopefully we aren't processing
4894 trash data, but since we must specifically ignore things
4895 we don't recognize, there is nothing else we should do at
4897 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4904 /* Copy constant value from an attribute to a symbol. */
4907 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
4908 struct objfile
*objfile
,
4909 const struct comp_unit_head
*cu_header
)
4911 struct dwarf_block
*blk
;
4916 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
4917 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4918 cu_header
->addr_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4919 SYMBOL_VALUE_BYTES (sym
) = (char *)
4920 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
4921 store_address (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
4923 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4925 case DW_FORM_block1
:
4926 case DW_FORM_block2
:
4927 case DW_FORM_block4
:
4929 blk
= DW_BLOCK (attr
);
4930 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4931 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4932 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4933 SYMBOL_VALUE_BYTES (sym
) = (char *)
4934 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4935 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4936 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4939 /* The DW_AT_const_value attributes are supposed to carry the
4940 symbol's value "represented as it would be on the target
4941 architecture." By the time we get here, it's already been
4942 converted to host endianness, so we just need to sign- or
4943 zero-extend it as appropriate. */
4945 dwarf2_const_value_data (attr
, sym
, 8);
4948 dwarf2_const_value_data (attr
, sym
, 16);
4951 dwarf2_const_value_data (attr
, sym
, 32);
4954 dwarf2_const_value_data (attr
, sym
, 64);
4958 SYMBOL_VALUE (sym
) = DW_SND (attr
);
4959 SYMBOL_CLASS (sym
) = LOC_CONST
;
4963 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4964 SYMBOL_CLASS (sym
) = LOC_CONST
;
4968 complain (&dwarf2_unsupported_const_value_attr
,
4969 dwarf_form_name (attr
->form
));
4970 SYMBOL_VALUE (sym
) = 0;
4971 SYMBOL_CLASS (sym
) = LOC_CONST
;
4977 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4978 or zero-extend it as appropriate for the symbol's type. */
4980 dwarf2_const_value_data (struct attribute
*attr
,
4984 LONGEST l
= DW_UNSND (attr
);
4986 if (bits
< sizeof (l
) * 8)
4988 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
4989 l
&= ((LONGEST
) 1 << bits
) - 1;
4991 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
4994 SYMBOL_VALUE (sym
) = l
;
4995 SYMBOL_CLASS (sym
) = LOC_CONST
;
4999 /* Return the type of the die in question using its DW_AT_type attribute. */
5001 static struct type
*
5002 die_type (struct die_info
*die
, struct objfile
*objfile
,
5003 const struct comp_unit_head
*cu_header
)
5006 struct attribute
*type_attr
;
5007 struct die_info
*type_die
;
5010 type_attr
= dwarf_attr (die
, DW_AT_type
);
5013 /* A missing DW_AT_type represents a void type. */
5014 return dwarf2_fundamental_type (objfile
, FT_VOID
);
5018 ref
= dwarf2_get_ref_die_offset (type_attr
);
5019 type_die
= follow_die_ref (ref
);
5022 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
5026 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
5029 dump_die (type_die
);
5030 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
5035 /* Return the containing type of the die in question using its
5036 DW_AT_containing_type attribute. */
5038 static struct type
*
5039 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
5040 const struct comp_unit_head
*cu_header
)
5042 struct type
*type
= NULL
;
5043 struct attribute
*type_attr
;
5044 struct die_info
*type_die
= NULL
;
5047 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
5050 ref
= dwarf2_get_ref_die_offset (type_attr
);
5051 type_die
= follow_die_ref (ref
);
5054 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
5057 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
5062 dump_die (type_die
);
5063 error ("Dwarf Error: Problem turning containing type into gdb type.");
5069 static struct type
*
5070 type_at_offset (unsigned int offset
, struct objfile
*objfile
)
5072 struct die_info
*die
;
5075 die
= follow_die_ref (offset
);
5078 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
5081 type
= tag_type_to_type (die
, objfile
);
5086 static struct type
*
5087 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
5088 const struct comp_unit_head
*cu_header
)
5096 read_type_die (die
, objfile
, cu_header
);
5100 error ("Dwarf Error: Cannot find type of die.");
5107 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
5108 const struct comp_unit_head
*cu_header
)
5112 case DW_TAG_class_type
:
5113 case DW_TAG_structure_type
:
5114 case DW_TAG_union_type
:
5115 read_structure_scope (die
, objfile
, cu_header
);
5117 case DW_TAG_enumeration_type
:
5118 read_enumeration (die
, objfile
, cu_header
);
5120 case DW_TAG_subprogram
:
5121 case DW_TAG_subroutine_type
:
5122 read_subroutine_type (die
, objfile
, cu_header
);
5124 case DW_TAG_array_type
:
5125 read_array_type (die
, objfile
, cu_header
);
5127 case DW_TAG_pointer_type
:
5128 read_tag_pointer_type (die
, objfile
, cu_header
);
5130 case DW_TAG_ptr_to_member_type
:
5131 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
5133 case DW_TAG_reference_type
:
5134 read_tag_reference_type (die
, objfile
, cu_header
);
5136 case DW_TAG_const_type
:
5137 read_tag_const_type (die
, objfile
, cu_header
);
5139 case DW_TAG_volatile_type
:
5140 read_tag_volatile_type (die
, objfile
, cu_header
);
5142 case DW_TAG_string_type
:
5143 read_tag_string_type (die
, objfile
);
5145 case DW_TAG_typedef
:
5146 read_typedef (die
, objfile
, cu_header
);
5148 case DW_TAG_base_type
:
5149 read_base_type (die
, objfile
);
5152 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
5157 static struct type
*
5158 dwarf_base_type (int encoding
, int size
, struct objfile
*objfile
)
5160 /* FIXME - this should not produce a new (struct type *)
5161 every time. It should cache base types. */
5165 case DW_ATE_address
:
5166 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
5168 case DW_ATE_boolean
:
5169 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
5171 case DW_ATE_complex_float
:
5174 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
5178 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
5184 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
5188 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
5195 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5198 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
5202 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5206 case DW_ATE_signed_char
:
5207 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5209 case DW_ATE_unsigned
:
5213 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5216 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
5220 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
5224 case DW_ATE_unsigned_char
:
5225 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5228 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5235 copy_die (struct die_info
*old_die
)
5237 struct die_info
*new_die
;
5240 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5241 memset (new_die
, 0, sizeof (struct die_info
));
5243 new_die
->tag
= old_die
->tag
;
5244 new_die
->has_children
= old_die
->has_children
;
5245 new_die
->abbrev
= old_die
->abbrev
;
5246 new_die
->offset
= old_die
->offset
;
5247 new_die
->type
= NULL
;
5249 num_attrs
= old_die
->num_attrs
;
5250 new_die
->num_attrs
= num_attrs
;
5251 new_die
->attrs
= (struct attribute
*)
5252 xmalloc (num_attrs
* sizeof (struct attribute
));
5254 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
5256 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
5257 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
5258 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
5261 new_die
->next
= NULL
;
5266 /* Return sibling of die, NULL if no sibling. */
5268 static struct die_info
*
5269 sibling_die (struct die_info
*die
)
5271 int nesting_level
= 0;
5273 if (!die
->has_children
)
5275 if (die
->next
&& (die
->next
->tag
== 0))
5288 if (die
->has_children
)
5298 while (nesting_level
);
5299 if (die
&& (die
->tag
== 0))
5310 /* Get linkage name of a die, return NULL if not found. */
5313 dwarf2_linkage_name (struct die_info
*die
)
5315 struct attribute
*attr
;
5317 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
5318 if (attr
&& DW_STRING (attr
))
5319 return DW_STRING (attr
);
5320 attr
= dwarf_attr (die
, DW_AT_name
);
5321 if (attr
&& DW_STRING (attr
))
5322 return DW_STRING (attr
);
5326 /* Convert a DIE tag into its string name. */
5329 dwarf_tag_name (register unsigned tag
)
5333 case DW_TAG_padding
:
5334 return "DW_TAG_padding";
5335 case DW_TAG_array_type
:
5336 return "DW_TAG_array_type";
5337 case DW_TAG_class_type
:
5338 return "DW_TAG_class_type";
5339 case DW_TAG_entry_point
:
5340 return "DW_TAG_entry_point";
5341 case DW_TAG_enumeration_type
:
5342 return "DW_TAG_enumeration_type";
5343 case DW_TAG_formal_parameter
:
5344 return "DW_TAG_formal_parameter";
5345 case DW_TAG_imported_declaration
:
5346 return "DW_TAG_imported_declaration";
5348 return "DW_TAG_label";
5349 case DW_TAG_lexical_block
:
5350 return "DW_TAG_lexical_block";
5352 return "DW_TAG_member";
5353 case DW_TAG_pointer_type
:
5354 return "DW_TAG_pointer_type";
5355 case DW_TAG_reference_type
:
5356 return "DW_TAG_reference_type";
5357 case DW_TAG_compile_unit
:
5358 return "DW_TAG_compile_unit";
5359 case DW_TAG_string_type
:
5360 return "DW_TAG_string_type";
5361 case DW_TAG_structure_type
:
5362 return "DW_TAG_structure_type";
5363 case DW_TAG_subroutine_type
:
5364 return "DW_TAG_subroutine_type";
5365 case DW_TAG_typedef
:
5366 return "DW_TAG_typedef";
5367 case DW_TAG_union_type
:
5368 return "DW_TAG_union_type";
5369 case DW_TAG_unspecified_parameters
:
5370 return "DW_TAG_unspecified_parameters";
5371 case DW_TAG_variant
:
5372 return "DW_TAG_variant";
5373 case DW_TAG_common_block
:
5374 return "DW_TAG_common_block";
5375 case DW_TAG_common_inclusion
:
5376 return "DW_TAG_common_inclusion";
5377 case DW_TAG_inheritance
:
5378 return "DW_TAG_inheritance";
5379 case DW_TAG_inlined_subroutine
:
5380 return "DW_TAG_inlined_subroutine";
5382 return "DW_TAG_module";
5383 case DW_TAG_ptr_to_member_type
:
5384 return "DW_TAG_ptr_to_member_type";
5385 case DW_TAG_set_type
:
5386 return "DW_TAG_set_type";
5387 case DW_TAG_subrange_type
:
5388 return "DW_TAG_subrange_type";
5389 case DW_TAG_with_stmt
:
5390 return "DW_TAG_with_stmt";
5391 case DW_TAG_access_declaration
:
5392 return "DW_TAG_access_declaration";
5393 case DW_TAG_base_type
:
5394 return "DW_TAG_base_type";
5395 case DW_TAG_catch_block
:
5396 return "DW_TAG_catch_block";
5397 case DW_TAG_const_type
:
5398 return "DW_TAG_const_type";
5399 case DW_TAG_constant
:
5400 return "DW_TAG_constant";
5401 case DW_TAG_enumerator
:
5402 return "DW_TAG_enumerator";
5403 case DW_TAG_file_type
:
5404 return "DW_TAG_file_type";
5406 return "DW_TAG_friend";
5407 case DW_TAG_namelist
:
5408 return "DW_TAG_namelist";
5409 case DW_TAG_namelist_item
:
5410 return "DW_TAG_namelist_item";
5411 case DW_TAG_packed_type
:
5412 return "DW_TAG_packed_type";
5413 case DW_TAG_subprogram
:
5414 return "DW_TAG_subprogram";
5415 case DW_TAG_template_type_param
:
5416 return "DW_TAG_template_type_param";
5417 case DW_TAG_template_value_param
:
5418 return "DW_TAG_template_value_param";
5419 case DW_TAG_thrown_type
:
5420 return "DW_TAG_thrown_type";
5421 case DW_TAG_try_block
:
5422 return "DW_TAG_try_block";
5423 case DW_TAG_variant_part
:
5424 return "DW_TAG_variant_part";
5425 case DW_TAG_variable
:
5426 return "DW_TAG_variable";
5427 case DW_TAG_volatile_type
:
5428 return "DW_TAG_volatile_type";
5429 case DW_TAG_MIPS_loop
:
5430 return "DW_TAG_MIPS_loop";
5431 case DW_TAG_format_label
:
5432 return "DW_TAG_format_label";
5433 case DW_TAG_function_template
:
5434 return "DW_TAG_function_template";
5435 case DW_TAG_class_template
:
5436 return "DW_TAG_class_template";
5438 return "DW_TAG_<unknown>";
5442 /* Convert a DWARF attribute code into its string name. */
5445 dwarf_attr_name (register unsigned attr
)
5450 return "DW_AT_sibling";
5451 case DW_AT_location
:
5452 return "DW_AT_location";
5454 return "DW_AT_name";
5455 case DW_AT_ordering
:
5456 return "DW_AT_ordering";
5457 case DW_AT_subscr_data
:
5458 return "DW_AT_subscr_data";
5459 case DW_AT_byte_size
:
5460 return "DW_AT_byte_size";
5461 case DW_AT_bit_offset
:
5462 return "DW_AT_bit_offset";
5463 case DW_AT_bit_size
:
5464 return "DW_AT_bit_size";
5465 case DW_AT_element_list
:
5466 return "DW_AT_element_list";
5467 case DW_AT_stmt_list
:
5468 return "DW_AT_stmt_list";
5470 return "DW_AT_low_pc";
5472 return "DW_AT_high_pc";
5473 case DW_AT_language
:
5474 return "DW_AT_language";
5476 return "DW_AT_member";
5478 return "DW_AT_discr";
5479 case DW_AT_discr_value
:
5480 return "DW_AT_discr_value";
5481 case DW_AT_visibility
:
5482 return "DW_AT_visibility";
5484 return "DW_AT_import";
5485 case DW_AT_string_length
:
5486 return "DW_AT_string_length";
5487 case DW_AT_common_reference
:
5488 return "DW_AT_common_reference";
5489 case DW_AT_comp_dir
:
5490 return "DW_AT_comp_dir";
5491 case DW_AT_const_value
:
5492 return "DW_AT_const_value";
5493 case DW_AT_containing_type
:
5494 return "DW_AT_containing_type";
5495 case DW_AT_default_value
:
5496 return "DW_AT_default_value";
5498 return "DW_AT_inline";
5499 case DW_AT_is_optional
:
5500 return "DW_AT_is_optional";
5501 case DW_AT_lower_bound
:
5502 return "DW_AT_lower_bound";
5503 case DW_AT_producer
:
5504 return "DW_AT_producer";
5505 case DW_AT_prototyped
:
5506 return "DW_AT_prototyped";
5507 case DW_AT_return_addr
:
5508 return "DW_AT_return_addr";
5509 case DW_AT_start_scope
:
5510 return "DW_AT_start_scope";
5511 case DW_AT_stride_size
:
5512 return "DW_AT_stride_size";
5513 case DW_AT_upper_bound
:
5514 return "DW_AT_upper_bound";
5515 case DW_AT_abstract_origin
:
5516 return "DW_AT_abstract_origin";
5517 case DW_AT_accessibility
:
5518 return "DW_AT_accessibility";
5519 case DW_AT_address_class
:
5520 return "DW_AT_address_class";
5521 case DW_AT_artificial
:
5522 return "DW_AT_artificial";
5523 case DW_AT_base_types
:
5524 return "DW_AT_base_types";
5525 case DW_AT_calling_convention
:
5526 return "DW_AT_calling_convention";
5528 return "DW_AT_count";
5529 case DW_AT_data_member_location
:
5530 return "DW_AT_data_member_location";
5531 case DW_AT_decl_column
:
5532 return "DW_AT_decl_column";
5533 case DW_AT_decl_file
:
5534 return "DW_AT_decl_file";
5535 case DW_AT_decl_line
:
5536 return "DW_AT_decl_line";
5537 case DW_AT_declaration
:
5538 return "DW_AT_declaration";
5539 case DW_AT_discr_list
:
5540 return "DW_AT_discr_list";
5541 case DW_AT_encoding
:
5542 return "DW_AT_encoding";
5543 case DW_AT_external
:
5544 return "DW_AT_external";
5545 case DW_AT_frame_base
:
5546 return "DW_AT_frame_base";
5548 return "DW_AT_friend";
5549 case DW_AT_identifier_case
:
5550 return "DW_AT_identifier_case";
5551 case DW_AT_macro_info
:
5552 return "DW_AT_macro_info";
5553 case DW_AT_namelist_items
:
5554 return "DW_AT_namelist_items";
5555 case DW_AT_priority
:
5556 return "DW_AT_priority";
5558 return "DW_AT_segment";
5559 case DW_AT_specification
:
5560 return "DW_AT_specification";
5561 case DW_AT_static_link
:
5562 return "DW_AT_static_link";
5564 return "DW_AT_type";
5565 case DW_AT_use_location
:
5566 return "DW_AT_use_location";
5567 case DW_AT_variable_parameter
:
5568 return "DW_AT_variable_parameter";
5569 case DW_AT_virtuality
:
5570 return "DW_AT_virtuality";
5571 case DW_AT_vtable_elem_location
:
5572 return "DW_AT_vtable_elem_location";
5575 case DW_AT_MIPS_fde
:
5576 return "DW_AT_MIPS_fde";
5577 case DW_AT_MIPS_loop_begin
:
5578 return "DW_AT_MIPS_loop_begin";
5579 case DW_AT_MIPS_tail_loop_begin
:
5580 return "DW_AT_MIPS_tail_loop_begin";
5581 case DW_AT_MIPS_epilog_begin
:
5582 return "DW_AT_MIPS_epilog_begin";
5583 case DW_AT_MIPS_loop_unroll_factor
:
5584 return "DW_AT_MIPS_loop_unroll_factor";
5585 case DW_AT_MIPS_software_pipeline_depth
:
5586 return "DW_AT_MIPS_software_pipeline_depth";
5587 case DW_AT_MIPS_linkage_name
:
5588 return "DW_AT_MIPS_linkage_name";
5591 case DW_AT_sf_names
:
5592 return "DW_AT_sf_names";
5593 case DW_AT_src_info
:
5594 return "DW_AT_src_info";
5595 case DW_AT_mac_info
:
5596 return "DW_AT_mac_info";
5597 case DW_AT_src_coords
:
5598 return "DW_AT_src_coords";
5599 case DW_AT_body_begin
:
5600 return "DW_AT_body_begin";
5601 case DW_AT_body_end
:
5602 return "DW_AT_body_end";
5603 case DW_AT_GNU_vector
:
5604 return "DW_AT_GNU_vector";
5606 return "DW_AT_<unknown>";
5610 /* Convert a DWARF value form code into its string name. */
5613 dwarf_form_name (register unsigned form
)
5618 return "DW_FORM_addr";
5619 case DW_FORM_block2
:
5620 return "DW_FORM_block2";
5621 case DW_FORM_block4
:
5622 return "DW_FORM_block4";
5624 return "DW_FORM_data2";
5626 return "DW_FORM_data4";
5628 return "DW_FORM_data8";
5629 case DW_FORM_string
:
5630 return "DW_FORM_string";
5632 return "DW_FORM_block";
5633 case DW_FORM_block1
:
5634 return "DW_FORM_block1";
5636 return "DW_FORM_data1";
5638 return "DW_FORM_flag";
5640 return "DW_FORM_sdata";
5642 return "DW_FORM_strp";
5644 return "DW_FORM_udata";
5645 case DW_FORM_ref_addr
:
5646 return "DW_FORM_ref_addr";
5648 return "DW_FORM_ref1";
5650 return "DW_FORM_ref2";
5652 return "DW_FORM_ref4";
5654 return "DW_FORM_ref8";
5655 case DW_FORM_ref_udata
:
5656 return "DW_FORM_ref_udata";
5657 case DW_FORM_indirect
:
5658 return "DW_FORM_indirect";
5660 return "DW_FORM_<unknown>";
5664 /* Convert a DWARF stack opcode into its string name. */
5667 dwarf_stack_op_name (register unsigned op
)
5672 return "DW_OP_addr";
5674 return "DW_OP_deref";
5676 return "DW_OP_const1u";
5678 return "DW_OP_const1s";
5680 return "DW_OP_const2u";
5682 return "DW_OP_const2s";
5684 return "DW_OP_const4u";
5686 return "DW_OP_const4s";
5688 return "DW_OP_const8u";
5690 return "DW_OP_const8s";
5692 return "DW_OP_constu";
5694 return "DW_OP_consts";
5698 return "DW_OP_drop";
5700 return "DW_OP_over";
5702 return "DW_OP_pick";
5704 return "DW_OP_swap";
5708 return "DW_OP_xderef";
5716 return "DW_OP_minus";
5728 return "DW_OP_plus";
5729 case DW_OP_plus_uconst
:
5730 return "DW_OP_plus_uconst";
5736 return "DW_OP_shra";
5754 return "DW_OP_skip";
5756 return "DW_OP_lit0";
5758 return "DW_OP_lit1";
5760 return "DW_OP_lit2";
5762 return "DW_OP_lit3";
5764 return "DW_OP_lit4";
5766 return "DW_OP_lit5";
5768 return "DW_OP_lit6";
5770 return "DW_OP_lit7";
5772 return "DW_OP_lit8";
5774 return "DW_OP_lit9";
5776 return "DW_OP_lit10";
5778 return "DW_OP_lit11";
5780 return "DW_OP_lit12";
5782 return "DW_OP_lit13";
5784 return "DW_OP_lit14";
5786 return "DW_OP_lit15";
5788 return "DW_OP_lit16";
5790 return "DW_OP_lit17";
5792 return "DW_OP_lit18";
5794 return "DW_OP_lit19";
5796 return "DW_OP_lit20";
5798 return "DW_OP_lit21";
5800 return "DW_OP_lit22";
5802 return "DW_OP_lit23";
5804 return "DW_OP_lit24";
5806 return "DW_OP_lit25";
5808 return "DW_OP_lit26";
5810 return "DW_OP_lit27";
5812 return "DW_OP_lit28";
5814 return "DW_OP_lit29";
5816 return "DW_OP_lit30";
5818 return "DW_OP_lit31";
5820 return "DW_OP_reg0";
5822 return "DW_OP_reg1";
5824 return "DW_OP_reg2";
5826 return "DW_OP_reg3";
5828 return "DW_OP_reg4";
5830 return "DW_OP_reg5";
5832 return "DW_OP_reg6";
5834 return "DW_OP_reg7";
5836 return "DW_OP_reg8";
5838 return "DW_OP_reg9";
5840 return "DW_OP_reg10";
5842 return "DW_OP_reg11";
5844 return "DW_OP_reg12";
5846 return "DW_OP_reg13";
5848 return "DW_OP_reg14";
5850 return "DW_OP_reg15";
5852 return "DW_OP_reg16";
5854 return "DW_OP_reg17";
5856 return "DW_OP_reg18";
5858 return "DW_OP_reg19";
5860 return "DW_OP_reg20";
5862 return "DW_OP_reg21";
5864 return "DW_OP_reg22";
5866 return "DW_OP_reg23";
5868 return "DW_OP_reg24";
5870 return "DW_OP_reg25";
5872 return "DW_OP_reg26";
5874 return "DW_OP_reg27";
5876 return "DW_OP_reg28";
5878 return "DW_OP_reg29";
5880 return "DW_OP_reg30";
5882 return "DW_OP_reg31";
5884 return "DW_OP_breg0";
5886 return "DW_OP_breg1";
5888 return "DW_OP_breg2";
5890 return "DW_OP_breg3";
5892 return "DW_OP_breg4";
5894 return "DW_OP_breg5";
5896 return "DW_OP_breg6";
5898 return "DW_OP_breg7";
5900 return "DW_OP_breg8";
5902 return "DW_OP_breg9";
5904 return "DW_OP_breg10";
5906 return "DW_OP_breg11";
5908 return "DW_OP_breg12";
5910 return "DW_OP_breg13";
5912 return "DW_OP_breg14";
5914 return "DW_OP_breg15";
5916 return "DW_OP_breg16";
5918 return "DW_OP_breg17";
5920 return "DW_OP_breg18";
5922 return "DW_OP_breg19";
5924 return "DW_OP_breg20";
5926 return "DW_OP_breg21";
5928 return "DW_OP_breg22";
5930 return "DW_OP_breg23";
5932 return "DW_OP_breg24";
5934 return "DW_OP_breg25";
5936 return "DW_OP_breg26";
5938 return "DW_OP_breg27";
5940 return "DW_OP_breg28";
5942 return "DW_OP_breg29";
5944 return "DW_OP_breg30";
5946 return "DW_OP_breg31";
5948 return "DW_OP_regx";
5950 return "DW_OP_fbreg";
5952 return "DW_OP_bregx";
5954 return "DW_OP_piece";
5955 case DW_OP_deref_size
:
5956 return "DW_OP_deref_size";
5957 case DW_OP_xderef_size
:
5958 return "DW_OP_xderef_size";
5962 return "OP_<unknown>";
5967 dwarf_bool_name (unsigned mybool
)
5975 /* Convert a DWARF type code into its string name. */
5978 dwarf_type_encoding_name (register unsigned enc
)
5982 case DW_ATE_address
:
5983 return "DW_ATE_address";
5984 case DW_ATE_boolean
:
5985 return "DW_ATE_boolean";
5986 case DW_ATE_complex_float
:
5987 return "DW_ATE_complex_float";
5989 return "DW_ATE_float";
5991 return "DW_ATE_signed";
5992 case DW_ATE_signed_char
:
5993 return "DW_ATE_signed_char";
5994 case DW_ATE_unsigned
:
5995 return "DW_ATE_unsigned";
5996 case DW_ATE_unsigned_char
:
5997 return "DW_ATE_unsigned_char";
5999 return "DW_ATE_<unknown>";
6003 /* Convert a DWARF call frame info operation to its string name. */
6007 dwarf_cfi_name (register unsigned cfi_opc
)
6011 case DW_CFA_advance_loc
:
6012 return "DW_CFA_advance_loc";
6014 return "DW_CFA_offset";
6015 case DW_CFA_restore
:
6016 return "DW_CFA_restore";
6018 return "DW_CFA_nop";
6019 case DW_CFA_set_loc
:
6020 return "DW_CFA_set_loc";
6021 case DW_CFA_advance_loc1
:
6022 return "DW_CFA_advance_loc1";
6023 case DW_CFA_advance_loc2
:
6024 return "DW_CFA_advance_loc2";
6025 case DW_CFA_advance_loc4
:
6026 return "DW_CFA_advance_loc4";
6027 case DW_CFA_offset_extended
:
6028 return "DW_CFA_offset_extended";
6029 case DW_CFA_restore_extended
:
6030 return "DW_CFA_restore_extended";
6031 case DW_CFA_undefined
:
6032 return "DW_CFA_undefined";
6033 case DW_CFA_same_value
:
6034 return "DW_CFA_same_value";
6035 case DW_CFA_register
:
6036 return "DW_CFA_register";
6037 case DW_CFA_remember_state
:
6038 return "DW_CFA_remember_state";
6039 case DW_CFA_restore_state
:
6040 return "DW_CFA_restore_state";
6041 case DW_CFA_def_cfa
:
6042 return "DW_CFA_def_cfa";
6043 case DW_CFA_def_cfa_register
:
6044 return "DW_CFA_def_cfa_register";
6045 case DW_CFA_def_cfa_offset
:
6046 return "DW_CFA_def_cfa_offset";
6049 case DW_CFA_def_cfa_expression
:
6050 return "DW_CFA_def_cfa_expression";
6051 case DW_CFA_expression
:
6052 return "DW_CFA_expression";
6053 case DW_CFA_offset_extended_sf
:
6054 return "DW_CFA_offset_extended_sf";
6055 case DW_CFA_def_cfa_sf
:
6056 return "DW_CFA_def_cfa_sf";
6057 case DW_CFA_def_cfa_offset_sf
:
6058 return "DW_CFA_def_cfa_offset_sf";
6060 /* SGI/MIPS specific */
6061 case DW_CFA_MIPS_advance_loc8
:
6062 return "DW_CFA_MIPS_advance_loc8";
6064 /* GNU extensions */
6065 case DW_CFA_GNU_window_save
:
6066 return "DW_CFA_GNU_window_save";
6067 case DW_CFA_GNU_args_size
:
6068 return "DW_CFA_GNU_args_size";
6069 case DW_CFA_GNU_negative_offset_extended
:
6070 return "DW_CFA_GNU_negative_offset_extended";
6073 return "DW_CFA_<unknown>";
6079 dump_die (struct die_info
*die
)
6083 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
6084 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
6085 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
6086 dwarf_bool_name (die
->has_children
));
6088 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
6089 for (i
= 0; i
< die
->num_attrs
; ++i
)
6091 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
6092 dwarf_attr_name (die
->attrs
[i
].name
),
6093 dwarf_form_name (die
->attrs
[i
].form
));
6094 switch (die
->attrs
[i
].form
)
6096 case DW_FORM_ref_addr
:
6098 fprintf_unfiltered (gdb_stderr
, "address: ");
6099 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
6101 case DW_FORM_block2
:
6102 case DW_FORM_block4
:
6104 case DW_FORM_block1
:
6105 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
6116 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
6118 case DW_FORM_string
:
6120 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
6121 DW_STRING (&die
->attrs
[i
])
6122 ? DW_STRING (&die
->attrs
[i
]) : "");
6125 if (DW_UNSND (&die
->attrs
[i
]))
6126 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
6128 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
6130 case DW_FORM_indirect
:
6131 /* the reader will have reduced the indirect form to
6132 the "base form" so this form should not occur */
6133 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
6136 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
6137 die
->attrs
[i
].form
);
6139 fprintf_unfiltered (gdb_stderr
, "\n");
6144 dump_die_list (struct die_info
*die
)
6154 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
6157 struct die_info
*old
;
6159 h
= (offset
% REF_HASH_SIZE
);
6160 old
= die_ref_table
[h
];
6161 die
->next_ref
= old
;
6162 die_ref_table
[h
] = die
;
6167 dwarf2_empty_hash_tables (void)
6169 memset (die_ref_table
, 0, sizeof (die_ref_table
));
6173 dwarf2_get_ref_die_offset (struct attribute
*attr
)
6175 unsigned int result
= 0;
6179 case DW_FORM_ref_addr
:
6180 result
= DW_ADDR (attr
);
6186 case DW_FORM_ref_udata
:
6187 result
= cu_header_offset
+ DW_UNSND (attr
);
6190 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
6195 static struct die_info
*
6196 follow_die_ref (unsigned int offset
)
6198 struct die_info
*die
;
6201 h
= (offset
% REF_HASH_SIZE
);
6202 die
= die_ref_table
[h
];
6205 if (die
->offset
== offset
)
6209 die
= die
->next_ref
;
6214 static struct type
*
6215 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
6217 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
6219 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
6223 /* Look for this particular type in the fundamental type vector. If
6224 one is not found, create and install one appropriate for the
6225 current language and the current target machine. */
6227 if (ftypes
[typeid] == NULL
)
6229 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
6232 return (ftypes
[typeid]);
6235 /* Decode simple location descriptions.
6236 Given a pointer to a dwarf block that defines a location, compute
6237 the location and return the value.
6239 FIXME: This is a kludge until we figure out a better
6240 way to handle the location descriptions.
6241 Gdb's design does not mesh well with the DWARF2 notion of a location
6242 computing interpreter, which is a shame because the flexibility goes unused.
6243 FIXME: Implement more operations as necessary.
6245 A location description containing no operations indicates that the
6246 object is optimized out. The global optimized_out flag is set for
6247 those, the return value is meaningless.
6249 When the result is a register number, the global isreg flag is set,
6250 otherwise it is cleared.
6252 When the result is a base register offset, the global offreg flag is set
6253 and the register number is returned in basereg, otherwise it is cleared.
6255 When the DW_OP_fbreg operation is encountered without a corresponding
6256 DW_AT_frame_base attribute, the global islocal flag is set.
6257 Hopefully the machine dependent code knows how to set up a virtual
6258 frame pointer for the local references.
6260 Note that stack[0] is unused except as a default error return.
6261 Note that stack overflow is not yet handled. */
6264 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
6265 const struct comp_unit_head
*cu_header
)
6268 int size
= blk
->size
;
6269 char *data
= blk
->data
;
6270 CORE_ADDR stack
[64];
6272 unsigned int bytes_read
, unsnd
;
6322 stack
[++stacki
] = op
- DW_OP_lit0
;
6358 stack
[++stacki
] = op
- DW_OP_reg0
;
6363 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6365 stack
[++stacki
] = unsnd
;
6401 basereg
= op
- DW_OP_breg0
;
6402 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6408 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6410 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6415 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6417 if (frame_base_reg
>= 0)
6420 basereg
= frame_base_reg
;
6421 stack
[stacki
] += frame_base_offset
;
6425 complain (&dwarf2_missing_at_frame_base
);
6431 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
6432 cu_header
, &bytes_read
);
6437 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
6442 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
6447 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
6452 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
6457 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
6462 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
6467 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
6473 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6478 stack
[stacki
+ 1] = stack
[stacki
];
6483 stack
[stacki
- 1] += stack
[stacki
];
6487 case DW_OP_plus_uconst
:
6488 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6493 stack
[stacki
- 1] -= stack
[stacki
];
6499 /* If we're not the last op, then we definitely can't encode
6500 this using GDB's address_class enum. */
6502 complain (&dwarf2_complex_location_expr
);
6506 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
6507 return (stack
[stacki
]);
6510 return (stack
[stacki
]);
6513 /* memory allocation interface */
6517 dwarf2_free_tmp_obstack (PTR ignore
)
6519 obstack_free (&dwarf2_tmp_obstack
, NULL
);
6522 static struct dwarf_block
*
6523 dwarf_alloc_block (void)
6525 struct dwarf_block
*blk
;
6527 blk
= (struct dwarf_block
*)
6528 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
6532 static struct abbrev_info
*
6533 dwarf_alloc_abbrev (void)
6535 struct abbrev_info
*abbrev
;
6537 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
6538 memset (abbrev
, 0, sizeof (struct abbrev_info
));
6542 static struct die_info
*
6543 dwarf_alloc_die (void)
6545 struct die_info
*die
;
6547 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6548 memset (die
, 0, sizeof (struct die_info
));
6553 /* Macro support. */
6556 /* Return the full name of file number I in *LH's file name table.
6557 Use COMP_DIR as the name of the current directory of the
6558 compilation. The result is allocated using xmalloc; the caller is
6559 responsible for freeing it. */
6561 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
6563 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
6565 if (IS_ABSOLUTE_PATH (fe
->name
))
6566 return xstrdup (fe
->name
);
6574 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6580 dir_len
= strlen (dir
);
6581 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
6582 strcpy (full_name
, dir
);
6583 full_name
[dir_len
] = '/';
6584 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
6588 return xstrdup (fe
->name
);
6593 static struct macro_source_file
*
6594 macro_start_file (int file
, int line
,
6595 struct macro_source_file
*current_file
,
6596 const char *comp_dir
,
6597 struct line_header
*lh
, struct objfile
*objfile
)
6599 /* The full name of this source file. */
6600 char *full_name
= file_full_name (file
, lh
, comp_dir
);
6602 /* We don't create a macro table for this compilation unit
6603 at all until we actually get a filename. */
6604 if (! pending_macros
)
6605 pending_macros
= new_macro_table (&objfile
->symbol_obstack
,
6606 objfile
->macro_cache
);
6609 /* If we have no current file, then this must be the start_file
6610 directive for the compilation unit's main source file. */
6611 current_file
= macro_set_main (pending_macros
, full_name
);
6613 current_file
= macro_include (current_file
, line
, full_name
);
6617 return current_file
;
6621 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
6622 followed by a null byte. */
6624 copy_string (const char *buf
, int len
)
6626 char *s
= xmalloc (len
+ 1);
6627 memcpy (s
, buf
, len
);
6635 consume_improper_spaces (const char *p
, const char *body
)
6639 complain (&dwarf2_macro_spaces_in_definition
, body
);
6650 parse_macro_definition (struct macro_source_file
*file
, int line
,
6655 /* The body string takes one of two forms. For object-like macro
6656 definitions, it should be:
6658 <macro name> " " <definition>
6660 For function-like macro definitions, it should be:
6662 <macro name> "() " <definition>
6664 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
6666 Spaces may appear only where explicitly indicated, and in the
6669 The Dwarf 2 spec says that an object-like macro's name is always
6670 followed by a space, but versions of GCC around March 2002 omit
6671 the space when the macro's definition is the empty string.
6673 The Dwarf 2 spec says that there should be no spaces between the
6674 formal arguments in a function-like macro's formal argument list,
6675 but versions of GCC around March 2002 include spaces after the
6679 /* Find the extent of the macro name. The macro name is terminated
6680 by either a space or null character (for an object-like macro) or
6681 an opening paren (for a function-like macro). */
6682 for (p
= body
; *p
; p
++)
6683 if (*p
== ' ' || *p
== '(')
6686 if (*p
== ' ' || *p
== '\0')
6688 /* It's an object-like macro. */
6689 int name_len
= p
- body
;
6690 char *name
= copy_string (body
, name_len
);
6691 const char *replacement
;
6694 replacement
= body
+ name_len
+ 1;
6697 complain (&dwarf2_macro_malformed_definition
, body
);
6698 replacement
= body
+ name_len
;
6701 macro_define_object (file
, line
, name
, replacement
);
6707 /* It's a function-like macro. */
6708 char *name
= copy_string (body
, p
- body
);
6711 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
6715 p
= consume_improper_spaces (p
, body
);
6717 /* Parse the formal argument list. */
6718 while (*p
&& *p
!= ')')
6720 /* Find the extent of the current argument name. */
6721 const char *arg_start
= p
;
6723 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
6726 if (! *p
|| p
== arg_start
)
6727 complain (&dwarf2_macro_malformed_definition
,
6731 /* Make sure argv has room for the new argument. */
6732 if (argc
>= argv_size
)
6735 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
6738 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
6741 p
= consume_improper_spaces (p
, body
);
6743 /* Consume the comma, if present. */
6748 p
= consume_improper_spaces (p
, body
);
6757 /* Perfectly formed definition, no complaints. */
6758 macro_define_function (file
, line
, name
,
6759 argc
, (const char **) argv
,
6761 else if (*p
== '\0')
6763 /* Complain, but do define it. */
6764 complain (&dwarf2_macro_malformed_definition
, body
);
6765 macro_define_function (file
, line
, name
,
6766 argc
, (const char **) argv
,
6770 /* Just complain. */
6771 complain (&dwarf2_macro_malformed_definition
, body
);
6774 /* Just complain. */
6775 complain (&dwarf2_macro_malformed_definition
, body
);
6781 for (i
= 0; i
< argc
; i
++)
6787 complain (&dwarf2_macro_malformed_definition
, body
);
6792 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
6793 char *comp_dir
, bfd
*abfd
,
6794 const struct comp_unit_head
*cu_header
,
6795 struct objfile
*objfile
)
6797 char *mac_ptr
, *mac_end
;
6798 struct macro_source_file
*current_file
= 0;
6800 if (dwarf_macinfo_buffer
== NULL
)
6802 complain (&dwarf2_missing_macinfo_section
);
6806 mac_ptr
= dwarf_macinfo_buffer
+ offset
;
6807 mac_end
= dwarf_macinfo_buffer
+ dwarf_macinfo_size
;
6811 enum dwarf_macinfo_record_type macinfo_type
;
6813 /* Do we at least have room for a macinfo type byte? */
6814 if (mac_ptr
>= mac_end
)
6816 complain (&dwarf2_macros_too_long
);
6820 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
6823 switch (macinfo_type
)
6825 /* A zero macinfo type indicates the end of the macro
6830 case DW_MACINFO_define
:
6831 case DW_MACINFO_undef
:
6837 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
6838 mac_ptr
+= bytes_read
;
6839 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
6840 mac_ptr
+= bytes_read
;
6843 complain (&dwarf2_macro_outside_file
,
6844 macinfo_type
== DW_MACINFO_define
? "definition" :
6845 macinfo_type
== DW_MACINFO_undef
? "undefinition" :
6846 "something-or-other",
6850 if (macinfo_type
== DW_MACINFO_define
)
6851 parse_macro_definition (current_file
, line
, body
);
6852 else if (macinfo_type
== DW_MACINFO_undef
)
6853 macro_undef (current_file
, line
, body
);
6858 case DW_MACINFO_start_file
:
6863 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
6864 mac_ptr
+= bytes_read
;
6865 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
6866 mac_ptr
+= bytes_read
;
6868 current_file
= macro_start_file (file
, line
,
6869 current_file
, comp_dir
,
6874 case DW_MACINFO_end_file
:
6876 complain (&dwarf2_macro_unmatched_end_file
);
6879 current_file
= current_file
->included_by
;
6882 enum dwarf_macinfo_record_type next_type
;
6884 /* GCC circa March 2002 doesn't produce the zero
6885 type byte marking the end of the compilation
6886 unit. Complain if it's not there, but exit no
6889 /* Do we at least have room for a macinfo type byte? */
6890 if (mac_ptr
>= mac_end
)
6892 complain (&dwarf2_macros_too_long
);
6896 /* We don't increment mac_ptr here, so this is just
6898 next_type
= read_1_byte (abfd
, mac_ptr
);
6900 complain (&dwarf2_macros_not_terminated
);
6907 case DW_MACINFO_vendor_ext
:
6913 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
6914 mac_ptr
+= bytes_read
;
6915 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
6916 mac_ptr
+= bytes_read
;
6918 /* We don't recognize any vendor extensions. */
6925 /* Check if the attribute's form is a DW_FORM_block*
6926 if so return true else false. */
6928 attr_form_is_block (struct attribute
*attr
)
6930 return (attr
== NULL
? 0 :
6931 attr
->form
== DW_FORM_block1
6932 || attr
->form
== DW_FORM_block2
6933 || attr
->form
== DW_FORM_block4
6934 || attr
->form
== DW_FORM_block
);