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
,
1012 dwarf_line_buffer
= dwarf2_read_section (objfile
,
1016 if (dwarf_str_offset
)
1017 dwarf_str_buffer
= dwarf2_read_section (objfile
,
1021 dwarf_str_buffer
= NULL
;
1023 if (dwarf_macinfo_offset
)
1024 dwarf_macinfo_buffer
= dwarf2_read_section (objfile
,
1025 dwarf_macinfo_offset
,
1026 dwarf_macinfo_size
);
1028 dwarf_macinfo_buffer
= NULL
;
1031 || (objfile
->global_psymbols
.size
== 0
1032 && objfile
->static_psymbols
.size
== 0))
1034 init_psymbol_list (objfile
, 1024);
1038 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1040 /* Things are significantly easier if we have .debug_aranges and
1041 .debug_pubnames sections */
1043 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1047 /* only test this case for now */
1049 /* In this case we have to work a bit harder */
1050 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1055 /* Build the partial symbol table from the information in the
1056 .debug_pubnames and .debug_aranges sections. */
1059 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1061 bfd
*abfd
= objfile
->obfd
;
1062 char *aranges_buffer
, *pubnames_buffer
;
1063 char *aranges_ptr
, *pubnames_ptr
;
1064 unsigned int entry_length
, version
, info_offset
, info_size
;
1066 pubnames_buffer
= dwarf2_read_section (objfile
,
1067 dwarf_pubnames_offset
,
1068 dwarf_pubnames_size
);
1069 pubnames_ptr
= pubnames_buffer
;
1070 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
1072 struct comp_unit_head cu_header
;
1075 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1077 pubnames_ptr
+= bytes_read
;
1078 version
= read_1_byte (abfd
, pubnames_ptr
);
1080 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1082 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1086 aranges_buffer
= dwarf2_read_section (objfile
,
1087 dwarf_aranges_offset
,
1088 dwarf_aranges_size
);
1093 /* Read in the comp unit header information from the debug_info at
1097 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1098 char *info_ptr
, bfd
*abfd
)
1102 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1104 info_ptr
+= bytes_read
;
1105 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1107 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1109 info_ptr
+= bytes_read
;
1110 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1112 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1113 if (signed_addr
< 0)
1114 internal_error (__FILE__
, __LINE__
,
1115 "read_comp_unit_head: dwarf from non elf file");
1116 cu_header
->signed_addr_p
= signed_addr
;
1120 /* Build the partial symbol table by doing a quick pass through the
1121 .debug_info and .debug_abbrev sections. */
1124 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1126 /* Instead of reading this into a big buffer, we should probably use
1127 mmap() on architectures that support it. (FIXME) */
1128 bfd
*abfd
= objfile
->obfd
;
1129 char *info_ptr
, *abbrev_ptr
;
1130 char *beg_of_comp_unit
;
1131 struct partial_die_info comp_unit_die
;
1132 struct partial_symtab
*pst
;
1133 struct cleanup
*back_to
;
1134 CORE_ADDR lowpc
, highpc
;
1136 info_ptr
= dwarf_info_buffer
;
1137 abbrev_ptr
= dwarf_abbrev_buffer
;
1139 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1140 the partial symbol scan, like attribute values.
1142 We could reduce our peak memory consumption during partial symbol
1143 table construction by freeing stuff from this obstack more often
1144 --- say, after processing each compilation unit, or each die ---
1145 but it turns out that this saves almost nothing. For an
1146 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1147 on dwarf2_tmp_obstack. Some investigation showed:
1149 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1150 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1151 all fixed-length values not requiring dynamic allocation.
1153 2) 30% of the attributes used the form DW_FORM_string. For
1154 DW_FORM_string, read_attribute simply hands back a pointer to
1155 the null-terminated string in dwarf_info_buffer, so no dynamic
1156 allocation is needed there either.
1158 3) The remaining 1% of the attributes all used DW_FORM_block1.
1159 75% of those were DW_AT_frame_base location lists for
1160 functions; the rest were DW_AT_location attributes, probably
1161 for the global variables.
1163 Anyway, what this all means is that the memory the dwarf2
1164 reader uses as temporary space reading partial symbols is about
1165 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1167 obstack_init (&dwarf2_tmp_obstack
);
1168 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1170 /* Since the objects we're extracting from dwarf_info_buffer vary in
1171 length, only the individual functions to extract them (like
1172 read_comp_unit_head and read_partial_die) can really know whether
1173 the buffer is large enough to hold another complete object.
1175 At the moment, they don't actually check that. If
1176 dwarf_info_buffer holds just one extra byte after the last
1177 compilation unit's dies, then read_comp_unit_head will happily
1178 read off the end of the buffer. read_partial_die is similarly
1179 casual. Those functions should be fixed.
1181 For this loop condition, simply checking whether there's any data
1182 left at all should be sufficient. */
1183 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1185 struct comp_unit_head cu_header
;
1186 beg_of_comp_unit
= info_ptr
;
1187 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1189 if (cu_header
.version
!= 2)
1191 error ("Dwarf Error: wrong version in compilation unit header.");
1194 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
1196 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
1197 (long) cu_header
.abbrev_offset
,
1198 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1201 if (beg_of_comp_unit
+ cu_header
.length
+ cu_header
.initial_length_size
1202 > dwarf_info_buffer
+ dwarf_info_size
)
1204 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
1205 (long) cu_header
.length
,
1206 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1209 /* Read the abbrevs for this compilation unit into a table */
1210 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1211 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1213 /* Read the compilation unit die */
1214 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1217 /* Set the language we're debugging */
1218 set_cu_language (comp_unit_die
.language
);
1220 /* Allocate a new partial symbol table structure */
1221 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1222 comp_unit_die
.name
? comp_unit_die
.name
: "",
1223 comp_unit_die
.lowpc
,
1224 objfile
->global_psymbols
.next
,
1225 objfile
->static_psymbols
.next
);
1227 pst
->read_symtab_private
= (char *)
1228 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1229 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1230 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1231 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1232 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1233 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1234 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1235 DWARF_LINE_SIZE (pst
) = dwarf_line_size
;
1236 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1237 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1238 DWARF_MACINFO_BUFFER (pst
) = dwarf_macinfo_buffer
;
1239 DWARF_MACINFO_SIZE (pst
) = dwarf_macinfo_size
;
1240 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1242 /* Store the function that reads in the rest of the symbol table */
1243 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1245 /* Check if comp unit has_children.
1246 If so, read the rest of the partial symbols from this comp unit.
1247 If not, there's no more debug_info for this comp unit. */
1248 if (comp_unit_die
.has_children
)
1250 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
,
1253 /* If the compilation unit didn't have an explicit address range,
1254 then use the information extracted from its child dies. */
1255 if (! comp_unit_die
.has_pc_info
)
1257 comp_unit_die
.lowpc
= lowpc
;
1258 comp_unit_die
.highpc
= highpc
;
1261 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1262 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1264 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1265 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1266 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1267 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1268 sort_pst_symbols (pst
);
1270 /* If there is already a psymtab or symtab for a file of this
1271 name, remove it. (If there is a symtab, more drastic things
1272 also happen.) This happens in VxWorks. */
1273 free_named_symtabs (pst
->filename
);
1275 info_ptr
= beg_of_comp_unit
+ cu_header
.length
1276 + cu_header
.initial_length_size
;
1278 do_cleanups (back_to
);
1281 /* Read in all interesting dies to the end of the compilation unit. */
1284 scan_partial_symbols (char *info_ptr
, struct objfile
*objfile
,
1285 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1286 const struct comp_unit_head
*cu_header
)
1288 bfd
*abfd
= objfile
->obfd
;
1289 struct partial_die_info pdi
;
1291 /* This function is called after we've read in the comp_unit_die in
1292 order to read its children. We start the nesting level at 1 since
1293 we have pushed 1 level down in order to read the comp unit's children.
1294 The comp unit itself is at level 0, so we stop reading when we pop
1295 back to that level. */
1297 int nesting_level
= 1;
1299 *lowpc
= ((CORE_ADDR
) -1);
1300 *highpc
= ((CORE_ADDR
) 0);
1302 while (nesting_level
)
1304 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu_header
);
1310 case DW_TAG_subprogram
:
1311 if (pdi
.has_pc_info
)
1313 if (pdi
.lowpc
< *lowpc
)
1317 if (pdi
.highpc
> *highpc
)
1319 *highpc
= pdi
.highpc
;
1321 if ((pdi
.is_external
|| nesting_level
== 1)
1322 && !pdi
.is_declaration
)
1324 add_partial_symbol (&pdi
, objfile
, cu_header
);
1328 case DW_TAG_variable
:
1329 case DW_TAG_typedef
:
1330 case DW_TAG_class_type
:
1331 case DW_TAG_structure_type
:
1332 case DW_TAG_union_type
:
1333 case DW_TAG_enumeration_type
:
1334 if ((pdi
.is_external
|| nesting_level
== 1)
1335 && !pdi
.is_declaration
)
1337 add_partial_symbol (&pdi
, objfile
, cu_header
);
1340 case DW_TAG_enumerator
:
1341 /* File scope enumerators are added to the partial symbol
1343 if (nesting_level
== 2)
1344 add_partial_symbol (&pdi
, objfile
, cu_header
);
1346 case DW_TAG_base_type
:
1347 /* File scope base type definitions are added to the partial
1349 if (nesting_level
== 1)
1350 add_partial_symbol (&pdi
, objfile
, cu_header
);
1357 /* If the die has a sibling, skip to the sibling.
1358 Do not skip enumeration types, we want to record their
1360 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1362 info_ptr
= pdi
.sibling
;
1364 else if (pdi
.has_children
)
1366 /* Die has children, but the optional DW_AT_sibling attribute
1377 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1378 from `maint check'. */
1379 if (*lowpc
== ((CORE_ADDR
) -1))
1385 add_partial_symbol (struct partial_die_info
*pdi
, struct objfile
*objfile
,
1386 const struct comp_unit_head
*cu_header
)
1392 case DW_TAG_subprogram
:
1393 if (pdi
->is_external
)
1395 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1396 mst_text, objfile); */
1397 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1398 VAR_NAMESPACE
, LOC_BLOCK
,
1399 &objfile
->global_psymbols
,
1400 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1404 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1405 mst_file_text, objfile); */
1406 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1407 VAR_NAMESPACE
, LOC_BLOCK
,
1408 &objfile
->static_psymbols
,
1409 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1412 case DW_TAG_variable
:
1413 if (pdi
->is_external
)
1416 Don't enter into the minimal symbol tables as there is
1417 a minimal symbol table entry from the ELF symbols already.
1418 Enter into partial symbol table if it has a location
1419 descriptor or a type.
1420 If the location descriptor is missing, new_symbol will create
1421 a LOC_UNRESOLVED symbol, the address of the variable will then
1422 be determined from the minimal symbol table whenever the variable
1424 The address for the partial symbol table entry is not
1425 used by GDB, but it comes in handy for debugging partial symbol
1429 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1430 if (pdi
->locdesc
|| pdi
->has_type
)
1431 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1432 VAR_NAMESPACE
, LOC_STATIC
,
1433 &objfile
->global_psymbols
,
1434 0, addr
+ baseaddr
, cu_language
, objfile
);
1438 /* Static Variable. Skip symbols without location descriptors. */
1439 if (pdi
->locdesc
== NULL
)
1441 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1442 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1443 mst_file_data, objfile); */
1444 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1445 VAR_NAMESPACE
, LOC_STATIC
,
1446 &objfile
->static_psymbols
,
1447 0, addr
+ baseaddr
, cu_language
, objfile
);
1450 case DW_TAG_typedef
:
1451 case DW_TAG_base_type
:
1452 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1453 VAR_NAMESPACE
, LOC_TYPEDEF
,
1454 &objfile
->static_psymbols
,
1455 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1457 case DW_TAG_class_type
:
1458 case DW_TAG_structure_type
:
1459 case DW_TAG_union_type
:
1460 case DW_TAG_enumeration_type
:
1461 /* Skip aggregate types without children, these are external
1463 if (pdi
->has_children
== 0)
1465 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1466 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1467 &objfile
->static_psymbols
,
1468 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1470 if (cu_language
== language_cplus
)
1472 /* For C++, these implicitly act as typedefs as well. */
1473 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1474 VAR_NAMESPACE
, LOC_TYPEDEF
,
1475 &objfile
->static_psymbols
,
1476 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1479 case DW_TAG_enumerator
:
1480 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1481 VAR_NAMESPACE
, LOC_CONST
,
1482 &objfile
->static_psymbols
,
1483 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1490 /* Expand this partial symbol table into a full symbol table. */
1493 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1495 /* FIXME: This is barely more than a stub. */
1500 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1506 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1507 gdb_flush (gdb_stdout
);
1510 psymtab_to_symtab_1 (pst
);
1512 /* Finish up the debug error message. */
1514 printf_filtered ("done.\n");
1520 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1522 struct objfile
*objfile
= pst
->objfile
;
1523 bfd
*abfd
= objfile
->obfd
;
1524 struct comp_unit_head cu_header
;
1525 struct die_info
*dies
;
1526 unsigned long offset
;
1527 CORE_ADDR lowpc
, highpc
;
1528 struct die_info
*child_die
;
1530 struct symtab
*symtab
;
1531 struct cleanup
*back_to
;
1533 /* Set local variables from the partial symbol table info. */
1534 offset
= DWARF_INFO_OFFSET (pst
);
1535 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1536 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1537 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1538 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1539 dwarf_line_size
= DWARF_LINE_SIZE (pst
);
1540 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1541 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1542 dwarf_macinfo_buffer
= DWARF_MACINFO_BUFFER (pst
);
1543 dwarf_macinfo_size
= DWARF_MACINFO_SIZE (pst
);
1544 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1545 cu_header_offset
= offset
;
1546 info_ptr
= dwarf_info_buffer
+ offset
;
1548 obstack_init (&dwarf2_tmp_obstack
);
1549 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1552 make_cleanup (really_free_pendings
, NULL
);
1554 /* read in the comp_unit header */
1555 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1557 /* Read the abbrevs for this compilation unit */
1558 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1559 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1561 dies
= read_comp_unit (info_ptr
, abfd
, &cu_header
);
1563 make_cleanup_free_die_list (dies
);
1565 /* Do line number decoding in read_file_scope () */
1566 process_die (dies
, objfile
, &cu_header
);
1568 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1570 /* Some compilers don't define a DW_AT_high_pc attribute for
1571 the compilation unit. If the DW_AT_high_pc is missing,
1572 synthesize it, by scanning the DIE's below the compilation unit. */
1574 if (dies
->has_children
)
1576 child_die
= dies
->next
;
1577 while (child_die
&& child_die
->tag
)
1579 if (child_die
->tag
== DW_TAG_subprogram
)
1581 CORE_ADDR low
, high
;
1583 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1585 highpc
= max (highpc
, high
);
1588 child_die
= sibling_die (child_die
);
1592 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1594 /* Set symtab language to language from DW_AT_language.
1595 If the compilation is from a C file generated by language preprocessors,
1596 do not set the language if it was already deduced by start_subfile. */
1598 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1600 symtab
->language
= cu_language
;
1602 pst
->symtab
= symtab
;
1604 sort_symtab_syms (pst
->symtab
);
1606 do_cleanups (back_to
);
1609 /* Process a die and its children. */
1612 process_die (struct die_info
*die
, struct objfile
*objfile
,
1613 const struct comp_unit_head
*cu_header
)
1617 case DW_TAG_padding
:
1619 case DW_TAG_compile_unit
:
1620 read_file_scope (die
, objfile
, cu_header
);
1622 case DW_TAG_subprogram
:
1623 read_subroutine_type (die
, objfile
, cu_header
);
1624 read_func_scope (die
, objfile
, cu_header
);
1626 case DW_TAG_inlined_subroutine
:
1627 /* FIXME: These are ignored for now.
1628 They could be used to set breakpoints on all inlined instances
1629 of a function and make GDB `next' properly over inlined functions. */
1631 case DW_TAG_lexical_block
:
1632 read_lexical_block_scope (die
, objfile
, cu_header
);
1634 case DW_TAG_class_type
:
1635 case DW_TAG_structure_type
:
1636 case DW_TAG_union_type
:
1637 read_structure_scope (die
, objfile
, cu_header
);
1639 case DW_TAG_enumeration_type
:
1640 read_enumeration (die
, objfile
, cu_header
);
1642 case DW_TAG_subroutine_type
:
1643 read_subroutine_type (die
, objfile
, cu_header
);
1645 case DW_TAG_array_type
:
1646 read_array_type (die
, objfile
, cu_header
);
1648 case DW_TAG_pointer_type
:
1649 read_tag_pointer_type (die
, objfile
, cu_header
);
1651 case DW_TAG_ptr_to_member_type
:
1652 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
1654 case DW_TAG_reference_type
:
1655 read_tag_reference_type (die
, objfile
, cu_header
);
1657 case DW_TAG_string_type
:
1658 read_tag_string_type (die
, objfile
);
1660 case DW_TAG_base_type
:
1661 read_base_type (die
, objfile
);
1662 if (dwarf_attr (die
, DW_AT_name
))
1664 /* Add a typedef symbol for the base type definition. */
1665 new_symbol (die
, die
->type
, objfile
, cu_header
);
1668 case DW_TAG_common_block
:
1669 read_common_block (die
, objfile
, cu_header
);
1671 case DW_TAG_common_inclusion
:
1674 new_symbol (die
, NULL
, objfile
, cu_header
);
1680 initialize_cu_func_list (void)
1682 cu_first_fn
= cu_last_fn
= cu_cached_fn
= NULL
;
1686 read_file_scope (struct die_info
*die
, struct objfile
*objfile
,
1687 const struct comp_unit_head
*cu_header
)
1689 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
1690 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1691 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1692 struct attribute
*attr
;
1693 char *name
= "<unknown>";
1694 char *comp_dir
= NULL
;
1695 struct die_info
*child_die
;
1696 bfd
*abfd
= objfile
->obfd
;
1697 struct line_header
*line_header
= 0;
1699 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1701 if (die
->has_children
)
1703 child_die
= die
->next
;
1704 while (child_die
&& child_die
->tag
)
1706 if (child_die
->tag
== DW_TAG_subprogram
)
1708 CORE_ADDR low
, high
;
1710 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1712 lowpc
= min (lowpc
, low
);
1713 highpc
= max (highpc
, high
);
1716 child_die
= sibling_die (child_die
);
1721 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1722 from finish_block. */
1723 if (lowpc
== ((CORE_ADDR
) -1))
1728 attr
= dwarf_attr (die
, DW_AT_name
);
1731 name
= DW_STRING (attr
);
1733 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1736 comp_dir
= DW_STRING (attr
);
1739 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1740 directory, get rid of it. */
1741 char *cp
= strchr (comp_dir
, ':');
1743 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1748 if (objfile
->ei
.entry_point
>= lowpc
&&
1749 objfile
->ei
.entry_point
< highpc
)
1751 objfile
->ei
.entry_file_lowpc
= lowpc
;
1752 objfile
->ei
.entry_file_highpc
= highpc
;
1755 attr
= dwarf_attr (die
, DW_AT_language
);
1758 set_cu_language (DW_UNSND (attr
));
1761 /* We assume that we're processing GCC output. */
1762 processing_gcc_compilation
= 2;
1764 /* FIXME:Do something here. */
1765 if (dip
->at_producer
!= NULL
)
1767 handle_producer (dip
->at_producer
);
1771 /* The compilation unit may be in a different language or objfile,
1772 zero out all remembered fundamental types. */
1773 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1775 start_symtab (name
, comp_dir
, lowpc
);
1776 record_debugformat ("DWARF 2");
1778 initialize_cu_func_list ();
1780 /* Process all dies in compilation unit. */
1781 if (die
->has_children
)
1783 child_die
= die
->next
;
1784 while (child_die
&& child_die
->tag
)
1786 process_die (child_die
, objfile
, cu_header
);
1787 child_die
= sibling_die (child_die
);
1791 /* Decode line number information if present. */
1792 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1795 unsigned int line_offset
= DW_UNSND (attr
);
1796 line_header
= dwarf_decode_line_header (line_offset
,
1800 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
1801 (void *) line_header
);
1802 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu_header
);
1806 /* Decode macro information, if present. Dwarf 2 macro information
1807 refers to information in the line number info statement program
1808 header, so we can only read it if we've read the header
1810 attr
= dwarf_attr (die
, DW_AT_macro_info
);
1813 unsigned int macro_offset
= DW_UNSND (attr
);
1814 dwarf_decode_macros (line_header
, macro_offset
,
1815 comp_dir
, abfd
, cu_header
, objfile
);
1817 do_cleanups (back_to
);
1821 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
)
1823 struct function_range
*thisfn
;
1825 thisfn
= (struct function_range
*)
1826 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct function_range
));
1827 thisfn
->name
= name
;
1828 thisfn
->lowpc
= lowpc
;
1829 thisfn
->highpc
= highpc
;
1830 thisfn
->seen_line
= 0;
1831 thisfn
->next
= NULL
;
1833 if (cu_last_fn
== NULL
)
1834 cu_first_fn
= thisfn
;
1836 cu_last_fn
->next
= thisfn
;
1838 cu_last_fn
= thisfn
;
1842 read_func_scope (struct die_info
*die
, struct objfile
*objfile
,
1843 const struct comp_unit_head
*cu_header
)
1845 register struct context_stack
*new;
1848 struct die_info
*child_die
;
1849 struct attribute
*attr
;
1852 name
= dwarf2_linkage_name (die
);
1854 /* Ignore functions with missing or empty names and functions with
1855 missing or invalid low and high pc attributes. */
1856 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1862 /* Record the function range for dwarf_decode_lines. */
1863 add_to_cu_func_list (name
, lowpc
, highpc
);
1865 if (objfile
->ei
.entry_point
>= lowpc
&&
1866 objfile
->ei
.entry_point
< highpc
)
1868 objfile
->ei
.entry_func_lowpc
= lowpc
;
1869 objfile
->ei
.entry_func_highpc
= highpc
;
1872 /* Decode DW_AT_frame_base location descriptor if present, keep result
1873 for DW_OP_fbreg operands in decode_locdesc. */
1874 frame_base_reg
= -1;
1875 frame_base_offset
= 0;
1876 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1881 /* Support the .debug_loc offsets */
1882 if (attr_form_is_block (attr
))
1884 addr
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
1886 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
1888 complain (&dwarf2_complex_location_expr
);
1893 complain (&dwarf2_invalid_attrib_class
, "DW_AT_frame_base", name
);
1898 complain (&dwarf2_unsupported_at_frame_base
, name
);
1900 frame_base_reg
= addr
;
1903 frame_base_reg
= basereg
;
1904 frame_base_offset
= addr
;
1907 complain (&dwarf2_unsupported_at_frame_base
, name
);
1910 new = push_context (0, lowpc
);
1911 new->name
= new_symbol (die
, die
->type
, objfile
, cu_header
);
1912 list_in_scope
= &local_symbols
;
1914 if (die
->has_children
)
1916 child_die
= die
->next
;
1917 while (child_die
&& child_die
->tag
)
1919 process_die (child_die
, objfile
, cu_header
);
1920 child_die
= sibling_die (child_die
);
1924 new = pop_context ();
1925 /* Make a block for the local symbols within. */
1926 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1927 lowpc
, highpc
, objfile
);
1928 list_in_scope
= &file_symbols
;
1931 /* Process all the DIES contained within a lexical block scope. Start
1932 a new scope, process the dies, and then close the scope. */
1935 read_lexical_block_scope (struct die_info
*die
, struct objfile
*objfile
,
1936 const struct comp_unit_head
*cu_header
)
1938 register struct context_stack
*new;
1939 CORE_ADDR lowpc
, highpc
;
1940 struct die_info
*child_die
;
1942 /* Ignore blocks with missing or invalid low and high pc attributes. */
1943 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1948 push_context (0, lowpc
);
1949 if (die
->has_children
)
1951 child_die
= die
->next
;
1952 while (child_die
&& child_die
->tag
)
1954 process_die (child_die
, objfile
, cu_header
);
1955 child_die
= sibling_die (child_die
);
1958 new = pop_context ();
1960 if (local_symbols
!= NULL
)
1962 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1965 local_symbols
= new->locals
;
1968 /* Get low and high pc attributes from a die.
1969 Return 1 if the attributes are present and valid, otherwise, return 0. */
1972 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1973 struct objfile
*objfile
)
1975 struct attribute
*attr
;
1979 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1981 low
= DW_ADDR (attr
);
1984 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1986 high
= DW_ADDR (attr
);
1993 /* When using the GNU linker, .gnu.linkonce. sections are used to
1994 eliminate duplicate copies of functions and vtables and such.
1995 The linker will arbitrarily choose one and discard the others.
1996 The AT_*_pc values for such functions refer to local labels in
1997 these sections. If the section from that file was discarded, the
1998 labels are not in the output, so the relocs get a value of 0.
1999 If this is a discarded function, mark the pc bounds as invalid,
2000 so that GDB will ignore it. */
2001 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
2009 /* Add an aggregate field to the field list. */
2012 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
2013 struct objfile
*objfile
,
2014 const struct comp_unit_head
*cu_header
)
2016 struct nextfield
*new_field
;
2017 struct attribute
*attr
;
2019 char *fieldname
= "";
2021 /* Allocate a new field list entry and link it in. */
2022 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2023 make_cleanup (xfree
, new_field
);
2024 memset (new_field
, 0, sizeof (struct nextfield
));
2025 new_field
->next
= fip
->fields
;
2026 fip
->fields
= new_field
;
2029 /* Handle accessibility and virtuality of field.
2030 The default accessibility for members is public, the default
2031 accessibility for inheritance is private. */
2032 if (die
->tag
!= DW_TAG_inheritance
)
2033 new_field
->accessibility
= DW_ACCESS_public
;
2035 new_field
->accessibility
= DW_ACCESS_private
;
2036 new_field
->virtuality
= DW_VIRTUALITY_none
;
2038 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2040 new_field
->accessibility
= DW_UNSND (attr
);
2041 if (new_field
->accessibility
!= DW_ACCESS_public
)
2042 fip
->non_public_fields
= 1;
2043 attr
= dwarf_attr (die
, DW_AT_virtuality
);
2045 new_field
->virtuality
= DW_UNSND (attr
);
2047 fp
= &new_field
->field
;
2048 if (die
->tag
== DW_TAG_member
)
2050 /* Get type of field. */
2051 fp
->type
= die_type (die
, objfile
, cu_header
);
2053 /* Get bit size of field (zero if none). */
2054 attr
= dwarf_attr (die
, DW_AT_bit_size
);
2057 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
2061 FIELD_BITSIZE (*fp
) = 0;
2064 /* Get bit offset of field. */
2065 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2068 FIELD_BITPOS (*fp
) =
2069 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) * bits_per_byte
;
2072 FIELD_BITPOS (*fp
) = 0;
2073 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
2076 if (BITS_BIG_ENDIAN
)
2078 /* For big endian bits, the DW_AT_bit_offset gives the
2079 additional bit offset from the MSB of the containing
2080 anonymous object to the MSB of the field. We don't
2081 have to do anything special since we don't need to
2082 know the size of the anonymous object. */
2083 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
2087 /* For little endian bits, compute the bit offset to the
2088 MSB of the anonymous object, subtract off the number of
2089 bits from the MSB of the field to the MSB of the
2090 object, and then subtract off the number of bits of
2091 the field itself. The result is the bit offset of
2092 the LSB of the field. */
2094 int bit_offset
= DW_UNSND (attr
);
2096 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2099 /* The size of the anonymous object containing
2100 the bit field is explicit, so use the
2101 indicated size (in bytes). */
2102 anonymous_size
= DW_UNSND (attr
);
2106 /* The size of the anonymous object containing
2107 the bit field must be inferred from the type
2108 attribute of the data member containing the
2110 anonymous_size
= TYPE_LENGTH (fp
->type
);
2112 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2113 - bit_offset
- FIELD_BITSIZE (*fp
);
2117 /* Get name of field. */
2118 attr
= dwarf_attr (die
, DW_AT_name
);
2119 if (attr
&& DW_STRING (attr
))
2120 fieldname
= DW_STRING (attr
);
2121 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
2122 &objfile
->type_obstack
);
2124 /* Change accessibility for artificial fields (e.g. virtual table
2125 pointer or virtual base class pointer) to private. */
2126 if (dwarf_attr (die
, DW_AT_artificial
))
2128 new_field
->accessibility
= DW_ACCESS_private
;
2129 fip
->non_public_fields
= 1;
2132 else if (die
->tag
== DW_TAG_variable
)
2136 /* C++ static member.
2137 Get name of field. */
2138 attr
= dwarf_attr (die
, DW_AT_name
);
2139 if (attr
&& DW_STRING (attr
))
2140 fieldname
= DW_STRING (attr
);
2144 /* Get physical name. */
2145 physname
= dwarf2_linkage_name (die
);
2147 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
2148 &objfile
->type_obstack
));
2149 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
2150 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
2151 &objfile
->type_obstack
);
2153 else if (die
->tag
== DW_TAG_inheritance
)
2155 /* C++ base class field. */
2156 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2158 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
)
2160 FIELD_BITSIZE (*fp
) = 0;
2161 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
2162 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2163 fip
->nbaseclasses
++;
2167 /* Create the vector of fields, and attach it to the type. */
2170 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
2171 struct objfile
*objfile
)
2173 int nfields
= fip
->nfields
;
2175 /* Record the field count, allocate space for the array of fields,
2176 and create blank accessibility bitfields if necessary. */
2177 TYPE_NFIELDS (type
) = nfields
;
2178 TYPE_FIELDS (type
) = (struct field
*)
2179 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2180 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2182 if (fip
->non_public_fields
)
2184 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2186 TYPE_FIELD_PRIVATE_BITS (type
) =
2187 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2188 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2190 TYPE_FIELD_PROTECTED_BITS (type
) =
2191 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2192 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2194 TYPE_FIELD_IGNORE_BITS (type
) =
2195 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2196 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2199 /* If the type has baseclasses, allocate and clear a bit vector for
2200 TYPE_FIELD_VIRTUAL_BITS. */
2201 if (fip
->nbaseclasses
)
2203 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2206 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2207 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2208 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2209 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2210 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2213 /* Copy the saved-up fields into the field vector. Start from the head
2214 of the list, adding to the tail of the field array, so that they end
2215 up in the same order in the array in which they were added to the list. */
2216 while (nfields
-- > 0)
2218 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2219 switch (fip
->fields
->accessibility
)
2221 case DW_ACCESS_private
:
2222 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2225 case DW_ACCESS_protected
:
2226 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2229 case DW_ACCESS_public
:
2233 /* Unknown accessibility. Complain and treat it as public. */
2235 complain (&dwarf2_unsupported_accessibility
,
2236 fip
->fields
->accessibility
);
2240 if (nfields
< fip
->nbaseclasses
)
2242 switch (fip
->fields
->virtuality
)
2244 case DW_VIRTUALITY_virtual
:
2245 case DW_VIRTUALITY_pure_virtual
:
2246 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2250 fip
->fields
= fip
->fields
->next
;
2254 /* Add a member function to the proper fieldlist. */
2257 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2258 struct objfile
*objfile
,
2259 const struct comp_unit_head
*cu_header
)
2261 struct attribute
*attr
;
2262 struct fnfieldlist
*flp
;
2264 struct fn_field
*fnp
;
2267 struct nextfnfield
*new_fnfield
;
2269 /* Get name of member function. */
2270 attr
= dwarf_attr (die
, DW_AT_name
);
2271 if (attr
&& DW_STRING (attr
))
2272 fieldname
= DW_STRING (attr
);
2276 /* Get the mangled name. */
2277 physname
= dwarf2_linkage_name (die
);
2279 /* Look up member function name in fieldlist. */
2280 for (i
= 0; i
< fip
->nfnfields
; i
++)
2282 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2286 /* Create new list element if necessary. */
2287 if (i
< fip
->nfnfields
)
2288 flp
= &fip
->fnfieldlists
[i
];
2291 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2293 fip
->fnfieldlists
= (struct fnfieldlist
*)
2294 xrealloc (fip
->fnfieldlists
,
2295 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2296 * sizeof (struct fnfieldlist
));
2297 if (fip
->nfnfields
== 0)
2298 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2300 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2301 flp
->name
= fieldname
;
2307 /* Create a new member function field and chain it to the field list
2309 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2310 make_cleanup (xfree
, new_fnfield
);
2311 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2312 new_fnfield
->next
= flp
->head
;
2313 flp
->head
= new_fnfield
;
2316 /* Fill in the member function field info. */
2317 fnp
= &new_fnfield
->fnfield
;
2318 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2319 &objfile
->type_obstack
);
2320 fnp
->type
= alloc_type (objfile
);
2321 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2323 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2324 int nparams
= TYPE_NFIELDS (die
->type
);
2326 smash_to_method_type (fnp
->type
, die
->type
,
2327 TYPE_TARGET_TYPE (die
->type
),
2328 TYPE_FIELDS (die
->type
),
2329 TYPE_NFIELDS (die
->type
),
2330 TYPE_VARARGS (die
->type
));
2332 /* Handle static member functions.
2333 Dwarf2 has no clean way to discern C++ static and non-static
2334 member functions. G++ helps GDB by marking the first
2335 parameter for non-static member functions (which is the
2336 this pointer) as artificial. We obtain this information
2337 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2338 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2339 fnp
->voffset
= VOFFSET_STATIC
;
2342 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2344 /* Get fcontext from DW_AT_containing_type if present. */
2345 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2346 fnp
->fcontext
= die_containing_type (die
, objfile
, cu_header
);
2348 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2349 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2351 /* Get accessibility. */
2352 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2355 switch (DW_UNSND (attr
))
2357 case DW_ACCESS_private
:
2358 fnp
->is_private
= 1;
2360 case DW_ACCESS_protected
:
2361 fnp
->is_protected
= 1;
2366 /* Check for artificial methods. */
2367 attr
= dwarf_attr (die
, DW_AT_artificial
);
2368 if (attr
&& DW_UNSND (attr
) != 0)
2369 fnp
->is_artificial
= 1;
2371 /* Get index in virtual function table if it is a virtual member function. */
2372 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2375 /* Support the .debug_loc offsets */
2376 if (attr_form_is_block (attr
))
2378 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) + 2;
2380 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
2382 complain (&dwarf2_complex_location_expr
);
2386 complain (&dwarf2_invalid_attrib_class
, "DW_AT_vtable_elem_location",
2392 /* Create the vector of member function fields, and attach it to the type. */
2395 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2396 struct objfile
*objfile
)
2398 struct fnfieldlist
*flp
;
2399 int total_length
= 0;
2402 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2403 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2404 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2406 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2408 struct nextfnfield
*nfp
= flp
->head
;
2409 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2412 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2413 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2414 fn_flp
->fn_fields
= (struct fn_field
*)
2415 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2416 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2417 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2419 total_length
+= flp
->length
;
2422 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2423 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2426 /* Called when we find the DIE that starts a structure or union scope
2427 (definition) to process all dies that define the members of the
2430 NOTE: we need to call struct_type regardless of whether or not the
2431 DIE has an at_name attribute, since it might be an anonymous
2432 structure or union. This gets the type entered into our set of
2435 However, if the structure is incomplete (an opaque struct/union)
2436 then suppress creating a symbol table entry for it since gdb only
2437 wants to find the one with the complete definition. Note that if
2438 it is complete, we just call new_symbol, which does it's own
2439 checking about whether the struct/union is anonymous or not (and
2440 suppresses creating a symbol table entry itself). */
2443 read_structure_scope (struct die_info
*die
, struct objfile
*objfile
,
2444 const struct comp_unit_head
*cu_header
)
2447 struct attribute
*attr
;
2449 type
= alloc_type (objfile
);
2451 INIT_CPLUS_SPECIFIC (type
);
2452 attr
= dwarf_attr (die
, DW_AT_name
);
2453 if (attr
&& DW_STRING (attr
))
2455 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2456 strlen (DW_STRING (attr
)),
2457 &objfile
->type_obstack
);
2460 if (die
->tag
== DW_TAG_structure_type
)
2462 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2464 else if (die
->tag
== DW_TAG_union_type
)
2466 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2470 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2472 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2475 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2478 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2482 TYPE_LENGTH (type
) = 0;
2485 /* We need to add the type field to the die immediately so we don't
2486 infinitely recurse when dealing with pointers to the structure
2487 type within the structure itself. */
2490 if (die
->has_children
&& ! die_is_declaration (die
))
2492 struct field_info fi
;
2493 struct die_info
*child_die
;
2494 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2496 memset (&fi
, 0, sizeof (struct field_info
));
2498 child_die
= die
->next
;
2500 while (child_die
&& child_die
->tag
)
2502 if (child_die
->tag
== DW_TAG_member
)
2504 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2506 else if (child_die
->tag
== DW_TAG_variable
)
2508 /* C++ static member. */
2509 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2511 else if (child_die
->tag
== DW_TAG_subprogram
)
2513 /* C++ member function. */
2514 process_die (child_die
, objfile
, cu_header
);
2515 dwarf2_add_member_fn (&fi
, child_die
, objfile
, cu_header
);
2517 else if (child_die
->tag
== DW_TAG_inheritance
)
2519 /* C++ base class field. */
2520 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2524 process_die (child_die
, objfile
, cu_header
);
2526 child_die
= sibling_die (child_die
);
2529 /* Attach fields and member functions to the type. */
2531 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2534 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2536 /* Get the type which refers to the base class (possibly this
2537 class itself) which contains the vtable pointer for the current
2538 class from the DW_AT_containing_type attribute. */
2540 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2542 struct type
*t
= die_containing_type (die
, objfile
, cu_header
);
2544 TYPE_VPTR_BASETYPE (type
) = t
;
2547 static const char vptr_name
[] =
2548 {'_', 'v', 'p', 't', 'r', '\0'};
2551 /* Our own class provides vtbl ptr. */
2552 for (i
= TYPE_NFIELDS (t
) - 1;
2553 i
>= TYPE_N_BASECLASSES (t
);
2556 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2558 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2559 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2561 TYPE_VPTR_FIELDNO (type
) = i
;
2566 /* Complain if virtual function table field not found. */
2567 if (i
< TYPE_N_BASECLASSES (t
))
2568 complain (&dwarf2_vtbl_not_found_complaint
,
2569 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2573 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2578 new_symbol (die
, type
, objfile
, cu_header
);
2580 do_cleanups (back_to
);
2584 /* No children, must be stub. */
2585 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2589 /* Given a pointer to a die which begins an enumeration, process all
2590 the dies that define the members of the enumeration.
2592 This will be much nicer in draft 6 of the DWARF spec when our
2593 members will be dies instead squished into the DW_AT_element_list
2596 NOTE: We reverse the order of the element list. */
2599 read_enumeration (struct die_info
*die
, struct objfile
*objfile
,
2600 const struct comp_unit_head
*cu_header
)
2602 struct die_info
*child_die
;
2604 struct field
*fields
;
2605 struct attribute
*attr
;
2608 int unsigned_enum
= 1;
2610 type
= alloc_type (objfile
);
2612 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2613 attr
= dwarf_attr (die
, DW_AT_name
);
2614 if (attr
&& DW_STRING (attr
))
2616 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2617 strlen (DW_STRING (attr
)),
2618 &objfile
->type_obstack
);
2621 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2624 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2628 TYPE_LENGTH (type
) = 0;
2633 if (die
->has_children
)
2635 child_die
= die
->next
;
2636 while (child_die
&& child_die
->tag
)
2638 if (child_die
->tag
!= DW_TAG_enumerator
)
2640 process_die (child_die
, objfile
, cu_header
);
2644 attr
= dwarf_attr (child_die
, DW_AT_name
);
2647 sym
= new_symbol (child_die
, type
, objfile
, cu_header
);
2648 if (SYMBOL_VALUE (sym
) < 0)
2651 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2653 fields
= (struct field
*)
2655 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2656 * sizeof (struct field
));
2659 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2660 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2661 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2662 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2668 child_die
= sibling_die (child_die
);
2673 TYPE_NFIELDS (type
) = num_fields
;
2674 TYPE_FIELDS (type
) = (struct field
*)
2675 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2676 memcpy (TYPE_FIELDS (type
), fields
,
2677 sizeof (struct field
) * num_fields
);
2681 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2684 new_symbol (die
, type
, objfile
, cu_header
);
2687 /* Extract all information from a DW_TAG_array_type DIE and put it in
2688 the DIE's type field. For now, this only handles one dimensional
2692 read_array_type (struct die_info
*die
, struct objfile
*objfile
,
2693 const struct comp_unit_head
*cu_header
)
2695 struct die_info
*child_die
;
2696 struct type
*type
= NULL
;
2697 struct type
*element_type
, *range_type
, *index_type
;
2698 struct type
**range_types
= NULL
;
2699 struct attribute
*attr
;
2701 struct cleanup
*back_to
;
2703 /* Return if we've already decoded this type. */
2709 element_type
= die_type (die
, objfile
, cu_header
);
2711 /* Irix 6.2 native cc creates array types without children for
2712 arrays with unspecified length. */
2713 if (die
->has_children
== 0)
2715 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2716 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2717 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2721 back_to
= make_cleanup (null_cleanup
, NULL
);
2722 child_die
= die
->next
;
2723 while (child_die
&& child_die
->tag
)
2725 if (child_die
->tag
== DW_TAG_subrange_type
)
2727 unsigned int low
, high
;
2729 /* Default bounds to an array with unspecified length. */
2732 if (cu_language
== language_fortran
)
2734 /* FORTRAN implies a lower bound of 1, if not given. */
2738 index_type
= die_type (child_die
, objfile
, cu_header
);
2739 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2742 if (attr
->form
== DW_FORM_sdata
)
2744 low
= DW_SND (attr
);
2746 else if (attr
->form
== DW_FORM_udata
2747 || attr
->form
== DW_FORM_data1
2748 || attr
->form
== DW_FORM_data2
2749 || attr
->form
== DW_FORM_data4
2750 || attr
->form
== DW_FORM_data8
)
2752 low
= DW_UNSND (attr
);
2756 complain (&dwarf2_non_const_array_bound_ignored
,
2757 dwarf_form_name (attr
->form
));
2759 die
->type
= lookup_pointer_type (element_type
);
2766 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2769 if (attr
->form
== DW_FORM_sdata
)
2771 high
= DW_SND (attr
);
2773 else if (attr
->form
== DW_FORM_udata
2774 || attr
->form
== DW_FORM_data1
2775 || attr
->form
== DW_FORM_data2
2776 || attr
->form
== DW_FORM_data4
2777 || attr
->form
== DW_FORM_data8
)
2779 high
= DW_UNSND (attr
);
2781 else if (attr
->form
== DW_FORM_block1
)
2783 /* GCC encodes arrays with unspecified or dynamic length
2784 with a DW_FORM_block1 attribute.
2785 FIXME: GDB does not yet know how to handle dynamic
2786 arrays properly, treat them as arrays with unspecified
2792 complain (&dwarf2_non_const_array_bound_ignored
,
2793 dwarf_form_name (attr
->form
));
2795 die
->type
= lookup_pointer_type (element_type
);
2803 /* Create a range type and save it for array type creation. */
2804 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2806 range_types
= (struct type
**)
2807 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2808 * sizeof (struct type
*));
2810 make_cleanup (free_current_contents
, &range_types
);
2812 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2814 child_die
= sibling_die (child_die
);
2817 /* Dwarf2 dimensions are output from left to right, create the
2818 necessary array types in backwards order. */
2819 type
= element_type
;
2821 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2823 /* Understand Dwarf2 support for vector types (like they occur on
2824 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
2825 array type. This is not part of the Dwarf2/3 standard yet, but a
2826 custom vendor extension. The main difference between a regular
2827 array and the vector variant is that vectors are passed by value
2829 attr
= dwarf_attr (die
, DW_AT_GNU_vector
);
2831 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
2833 do_cleanups (back_to
);
2835 /* Install the type in the die. */
2839 /* First cut: install each common block member as a global variable. */
2842 read_common_block (struct die_info
*die
, struct objfile
*objfile
,
2843 const struct comp_unit_head
*cu_header
)
2845 struct die_info
*child_die
;
2846 struct attribute
*attr
;
2848 CORE_ADDR base
= (CORE_ADDR
) 0;
2850 attr
= dwarf_attr (die
, DW_AT_location
);
2853 /* Support the .debug_loc offsets */
2854 if (attr_form_is_block (attr
))
2856 base
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2858 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
2860 complain (&dwarf2_complex_location_expr
);
2864 complain (&dwarf2_invalid_attrib_class
, "DW_AT_location",
2865 "common block member");
2868 if (die
->has_children
)
2870 child_die
= die
->next
;
2871 while (child_die
&& child_die
->tag
)
2873 sym
= new_symbol (child_die
, NULL
, objfile
, cu_header
);
2874 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2877 SYMBOL_VALUE_ADDRESS (sym
) =
2878 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2879 add_symbol_to_list (sym
, &global_symbols
);
2881 child_die
= sibling_die (child_die
);
2886 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2887 the user defined type vector. */
2890 read_tag_pointer_type (struct die_info
*die
, struct objfile
*objfile
,
2891 const struct comp_unit_head
*cu_header
)
2894 struct attribute
*attr
;
2901 type
= lookup_pointer_type (die_type (die
, objfile
, cu_header
));
2902 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2905 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2909 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2914 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2915 the user defined type vector. */
2918 read_tag_ptr_to_member_type (struct die_info
*die
, struct objfile
*objfile
,
2919 const struct comp_unit_head
*cu_header
)
2922 struct type
*to_type
;
2923 struct type
*domain
;
2930 type
= alloc_type (objfile
);
2931 to_type
= die_type (die
, objfile
, cu_header
);
2932 domain
= die_containing_type (die
, objfile
, cu_header
);
2933 smash_to_member_type (type
, domain
, to_type
);
2938 /* Extract all information from a DW_TAG_reference_type DIE and add to
2939 the user defined type vector. */
2942 read_tag_reference_type (struct die_info
*die
, struct objfile
*objfile
,
2943 const struct comp_unit_head
*cu_header
)
2946 struct attribute
*attr
;
2953 type
= lookup_reference_type (die_type (die
, objfile
, cu_header
));
2954 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2957 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2961 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2967 read_tag_const_type (struct die_info
*die
, struct objfile
*objfile
,
2968 const struct comp_unit_head
*cu_header
)
2970 struct type
*base_type
;
2977 base_type
= die_type (die
, objfile
, cu_header
);
2978 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
2982 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
2983 const struct comp_unit_head
*cu_header
)
2985 struct type
*base_type
;
2992 base_type
= die_type (die
, objfile
, cu_header
);
2993 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
2996 /* Extract all information from a DW_TAG_string_type DIE and add to
2997 the user defined type vector. It isn't really a user defined type,
2998 but it behaves like one, with other DIE's using an AT_user_def_type
2999 attribute to reference it. */
3002 read_tag_string_type (struct die_info
*die
, struct objfile
*objfile
)
3004 struct type
*type
, *range_type
, *index_type
, *char_type
;
3005 struct attribute
*attr
;
3006 unsigned int length
;
3013 attr
= dwarf_attr (die
, DW_AT_string_length
);
3016 length
= DW_UNSND (attr
);
3020 /* check for the DW_AT_byte_size attribute */
3021 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3024 length
= DW_UNSND (attr
);
3031 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
3032 range_type
= create_range_type (NULL
, index_type
, 1, length
);
3033 if (cu_language
== language_fortran
)
3035 /* Need to create a unique string type for bounds
3037 type
= create_string_type (0, range_type
);
3041 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
3042 type
= create_string_type (char_type
, range_type
);
3047 /* Handle DIES due to C code like:
3051 int (*funcp)(int a, long l);
3055 ('funcp' generates a DW_TAG_subroutine_type DIE)
3059 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
3060 const struct comp_unit_head
*cu_header
)
3062 struct type
*type
; /* Type that this function returns */
3063 struct type
*ftype
; /* Function that returns above type */
3064 struct attribute
*attr
;
3066 /* Decode the type that this subroutine returns */
3071 type
= die_type (die
, objfile
, cu_header
);
3072 ftype
= lookup_function_type (type
);
3074 /* All functions in C++ have prototypes. */
3075 attr
= dwarf_attr (die
, DW_AT_prototyped
);
3076 if ((attr
&& (DW_UNSND (attr
) != 0))
3077 || cu_language
== language_cplus
)
3078 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
3080 if (die
->has_children
)
3082 struct die_info
*child_die
;
3086 /* Count the number of parameters.
3087 FIXME: GDB currently ignores vararg functions, but knows about
3088 vararg member functions. */
3089 child_die
= die
->next
;
3090 while (child_die
&& child_die
->tag
)
3092 if (child_die
->tag
== DW_TAG_formal_parameter
)
3094 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
3095 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
3096 child_die
= sibling_die (child_die
);
3099 /* Allocate storage for parameters and fill them in. */
3100 TYPE_NFIELDS (ftype
) = nparams
;
3101 TYPE_FIELDS (ftype
) = (struct field
*)
3102 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
3104 child_die
= die
->next
;
3105 while (child_die
&& child_die
->tag
)
3107 if (child_die
->tag
== DW_TAG_formal_parameter
)
3109 /* Dwarf2 has no clean way to discern C++ static and non-static
3110 member functions. G++ helps GDB by marking the first
3111 parameter for non-static member functions (which is the
3112 this pointer) as artificial. We pass this information
3113 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
3114 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
3116 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
3118 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
3119 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
3123 child_die
= sibling_die (child_die
);
3131 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
3132 const struct comp_unit_head
*cu_header
)
3134 struct attribute
*attr
;
3139 attr
= dwarf_attr (die
, DW_AT_name
);
3140 if (attr
&& DW_STRING (attr
))
3142 name
= DW_STRING (attr
);
3144 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
3145 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, objfile
, cu_header
);
3149 /* Find a representation of a given base type and install
3150 it in the TYPE field of the die. */
3153 read_base_type (struct die_info
*die
, struct objfile
*objfile
)
3156 struct attribute
*attr
;
3157 int encoding
= 0, size
= 0;
3159 /* If we've already decoded this die, this is a no-op. */
3165 attr
= dwarf_attr (die
, DW_AT_encoding
);
3168 encoding
= DW_UNSND (attr
);
3170 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3173 size
= DW_UNSND (attr
);
3175 attr
= dwarf_attr (die
, DW_AT_name
);
3176 if (attr
&& DW_STRING (attr
))
3178 enum type_code code
= TYPE_CODE_INT
;
3183 case DW_ATE_address
:
3184 /* Turn DW_ATE_address into a void * pointer. */
3185 code
= TYPE_CODE_PTR
;
3186 type_flags
|= TYPE_FLAG_UNSIGNED
;
3188 case DW_ATE_boolean
:
3189 code
= TYPE_CODE_BOOL
;
3190 type_flags
|= TYPE_FLAG_UNSIGNED
;
3192 case DW_ATE_complex_float
:
3193 code
= TYPE_CODE_COMPLEX
;
3196 code
= TYPE_CODE_FLT
;
3199 case DW_ATE_signed_char
:
3201 case DW_ATE_unsigned
:
3202 case DW_ATE_unsigned_char
:
3203 type_flags
|= TYPE_FLAG_UNSIGNED
;
3206 complain (&dwarf2_unsupported_at_encoding
,
3207 dwarf_type_encoding_name (encoding
));
3210 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
3211 if (encoding
== DW_ATE_address
)
3212 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
3213 else if (encoding
== DW_ATE_complex_float
)
3216 TYPE_TARGET_TYPE (type
)
3217 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
3218 else if (size
== 16)
3219 TYPE_TARGET_TYPE (type
)
3220 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
3222 TYPE_TARGET_TYPE (type
)
3223 = dwarf2_fundamental_type (objfile
, FT_FLOAT
);
3228 type
= dwarf_base_type (encoding
, size
, objfile
);
3233 /* Read a whole compilation unit into a linked list of dies. */
3235 static struct die_info
*
3236 read_comp_unit (char *info_ptr
, bfd
*abfd
,
3237 const struct comp_unit_head
*cu_header
)
3239 struct die_info
*first_die
, *last_die
, *die
;
3243 /* Reset die reference table; we are
3244 building new ones now. */
3245 dwarf2_empty_hash_tables ();
3249 first_die
= last_die
= NULL
;
3252 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
, cu_header
);
3253 if (die
->has_children
)
3264 /* Enter die in reference hash table */
3265 store_in_ref_table (die
->offset
, die
);
3269 first_die
= last_die
= die
;
3273 last_die
->next
= die
;
3277 while (nesting_level
> 0);
3281 /* Free a linked list of dies. */
3284 free_die_list (struct die_info
*dies
)
3286 struct die_info
*die
, *next
;
3299 do_free_die_list_cleanup (void *dies
)
3301 free_die_list (dies
);
3304 static struct cleanup
*
3305 make_cleanup_free_die_list (struct die_info
*dies
)
3307 return make_cleanup (do_free_die_list_cleanup
, dies
);
3311 /* Read the contents of the section at OFFSET and of size SIZE from the
3312 object file specified by OBJFILE into the psymbol_obstack and return it. */
3315 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
3318 bfd
*abfd
= objfile
->obfd
;
3324 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3325 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
3326 (bfd_bread (buf
, size
, abfd
) != size
))
3329 error ("Dwarf Error: Can't read DWARF data from '%s'",
3330 bfd_get_filename (abfd
));
3335 /* In DWARF version 2, the description of the debugging information is
3336 stored in a separate .debug_abbrev section. Before we read any
3337 dies from a section we read in all abbreviations and install them
3341 dwarf2_read_abbrevs (bfd
*abfd
, unsigned int offset
)
3344 struct abbrev_info
*cur_abbrev
;
3345 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3346 unsigned int abbrev_form
, hash_number
;
3348 /* empty the table */
3349 dwarf2_empty_abbrev_table (NULL
);
3351 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3352 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3353 abbrev_ptr
+= bytes_read
;
3355 /* loop until we reach an abbrev number of 0 */
3356 while (abbrev_number
)
3358 cur_abbrev
= dwarf_alloc_abbrev ();
3360 /* read in abbrev header */
3361 cur_abbrev
->number
= abbrev_number
;
3362 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3363 abbrev_ptr
+= bytes_read
;
3364 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3367 /* now read in declarations */
3368 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3369 abbrev_ptr
+= bytes_read
;
3370 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3371 abbrev_ptr
+= bytes_read
;
3374 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3376 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3377 xrealloc (cur_abbrev
->attrs
,
3378 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3379 * sizeof (struct attr_abbrev
));
3381 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3382 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3383 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3384 abbrev_ptr
+= bytes_read
;
3385 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3386 abbrev_ptr
+= bytes_read
;
3389 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3390 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3391 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3393 /* Get next abbreviation.
3394 Under Irix6 the abbreviations for a compilation unit are not
3395 always properly terminated with an abbrev number of 0.
3396 Exit loop if we encounter an abbreviation which we have
3397 already read (which means we are about to read the abbreviations
3398 for the next compile unit) or if the end of the abbreviation
3399 table is reached. */
3400 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3401 >= dwarf_abbrev_size
)
3403 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3404 abbrev_ptr
+= bytes_read
;
3405 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3410 /* Empty the abbrev table for a new compilation unit. */
3414 dwarf2_empty_abbrev_table (PTR ignore
)
3417 struct abbrev_info
*abbrev
, *next
;
3419 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3422 abbrev
= dwarf2_abbrevs
[i
];
3425 next
= abbrev
->next
;
3426 xfree (abbrev
->attrs
);
3430 dwarf2_abbrevs
[i
] = NULL
;
3434 /* Lookup an abbrev_info structure in the abbrev hash table. */
3436 static struct abbrev_info
*
3437 dwarf2_lookup_abbrev (unsigned int number
)
3439 unsigned int hash_number
;
3440 struct abbrev_info
*abbrev
;
3442 hash_number
= number
% ABBREV_HASH_SIZE
;
3443 abbrev
= dwarf2_abbrevs
[hash_number
];
3447 if (abbrev
->number
== number
)
3450 abbrev
= abbrev
->next
;
3455 /* Read a minimal amount of information into the minimal die structure. */
3458 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3459 char *info_ptr
, const struct comp_unit_head
*cu_header
)
3461 unsigned int abbrev_number
, bytes_read
, i
;
3462 struct abbrev_info
*abbrev
;
3463 struct attribute attr
;
3464 struct attribute spec_attr
;
3465 int found_spec_attr
= 0;
3466 int has_low_pc_attr
= 0;
3467 int has_high_pc_attr
= 0;
3469 *part_die
= zeroed_partial_die
;
3470 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3471 info_ptr
+= bytes_read
;
3475 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3478 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3480 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3481 part_die
->tag
= abbrev
->tag
;
3482 part_die
->has_children
= abbrev
->has_children
;
3483 part_die
->abbrev
= abbrev_number
;
3485 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3487 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
3488 info_ptr
, cu_header
);
3490 /* Store the data if it is of an attribute we want to keep in a
3491 partial symbol table. */
3496 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3497 if (part_die
->name
== NULL
)
3498 part_die
->name
= DW_STRING (&attr
);
3500 case DW_AT_MIPS_linkage_name
:
3501 part_die
->name
= DW_STRING (&attr
);
3504 has_low_pc_attr
= 1;
3505 part_die
->lowpc
= DW_ADDR (&attr
);
3508 has_high_pc_attr
= 1;
3509 part_die
->highpc
= DW_ADDR (&attr
);
3511 case DW_AT_location
:
3512 /* Support the .debug_loc offsets */
3513 if (attr_form_is_block (&attr
))
3515 part_die
->locdesc
= DW_BLOCK (&attr
);
3517 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
3519 complain (&dwarf2_complex_location_expr
);
3523 complain (&dwarf2_invalid_attrib_class
, "DW_AT_location",
3524 "partial symbol information");
3527 case DW_AT_language
:
3528 part_die
->language
= DW_UNSND (&attr
);
3530 case DW_AT_external
:
3531 part_die
->is_external
= DW_UNSND (&attr
);
3533 case DW_AT_declaration
:
3534 part_die
->is_declaration
= DW_UNSND (&attr
);
3537 part_die
->has_type
= 1;
3539 case DW_AT_abstract_origin
:
3540 case DW_AT_specification
:
3541 found_spec_attr
= 1;
3545 /* Ignore absolute siblings, they might point outside of
3546 the current compile unit. */
3547 if (attr
.form
== DW_FORM_ref_addr
)
3548 complain (&dwarf2_absolute_sibling_complaint
);
3551 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3558 /* If we found a reference attribute and the die has no name, try
3559 to find a name in the referred to die. */
3561 if (found_spec_attr
&& part_die
->name
== NULL
)
3563 struct partial_die_info spec_die
;
3567 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3568 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu_header
);
3571 part_die
->name
= spec_die
.name
;
3573 /* Copy DW_AT_external attribute if it is set. */
3574 if (spec_die
.is_external
)
3575 part_die
->is_external
= spec_die
.is_external
;
3579 /* When using the GNU linker, .gnu.linkonce. sections are used to
3580 eliminate duplicate copies of functions and vtables and such.
3581 The linker will arbitrarily choose one and discard the others.
3582 The AT_*_pc values for such functions refer to local labels in
3583 these sections. If the section from that file was discarded, the
3584 labels are not in the output, so the relocs get a value of 0.
3585 If this is a discarded function, mark the pc bounds as invalid,
3586 so that GDB will ignore it. */
3587 if (has_low_pc_attr
&& has_high_pc_attr
3588 && part_die
->lowpc
< part_die
->highpc
3589 && (part_die
->lowpc
!= 0
3590 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3591 part_die
->has_pc_info
= 1;
3595 /* Read the die from the .debug_info section buffer. And set diep to
3596 point to a newly allocated die with its information. */
3599 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
3600 const struct comp_unit_head
*cu_header
)
3602 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3603 struct abbrev_info
*abbrev
;
3604 struct die_info
*die
;
3606 offset
= info_ptr
- dwarf_info_buffer
;
3607 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3608 info_ptr
+= bytes_read
;
3611 die
= dwarf_alloc_die ();
3613 die
->abbrev
= abbrev_number
;
3619 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3622 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3624 die
= dwarf_alloc_die ();
3625 die
->offset
= offset
;
3626 die
->tag
= abbrev
->tag
;
3627 die
->has_children
= abbrev
->has_children
;
3628 die
->abbrev
= abbrev_number
;
3631 die
->num_attrs
= abbrev
->num_attrs
;
3632 die
->attrs
= (struct attribute
*)
3633 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3635 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3637 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3638 abfd
, info_ptr
, cu_header
);
3645 /* Read an attribute value described by an attribute form. */
3648 read_attribute_value (struct attribute
*attr
, unsigned form
,
3649 bfd
*abfd
, char *info_ptr
,
3650 const struct comp_unit_head
*cu_header
)
3652 unsigned int bytes_read
;
3653 struct dwarf_block
*blk
;
3659 case DW_FORM_ref_addr
:
3660 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
3661 info_ptr
+= bytes_read
;
3663 case DW_FORM_block2
:
3664 blk
= dwarf_alloc_block ();
3665 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3667 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3668 info_ptr
+= blk
->size
;
3669 DW_BLOCK (attr
) = blk
;
3671 case DW_FORM_block4
:
3672 blk
= dwarf_alloc_block ();
3673 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3675 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3676 info_ptr
+= blk
->size
;
3677 DW_BLOCK (attr
) = blk
;
3680 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3684 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3688 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3691 case DW_FORM_string
:
3692 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3693 info_ptr
+= bytes_read
;
3696 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
3698 info_ptr
+= bytes_read
;
3701 blk
= dwarf_alloc_block ();
3702 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3703 info_ptr
+= bytes_read
;
3704 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3705 info_ptr
+= blk
->size
;
3706 DW_BLOCK (attr
) = blk
;
3708 case DW_FORM_block1
:
3709 blk
= dwarf_alloc_block ();
3710 blk
->size
= read_1_byte (abfd
, info_ptr
);
3712 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3713 info_ptr
+= blk
->size
;
3714 DW_BLOCK (attr
) = blk
;
3717 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3721 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3725 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3726 info_ptr
+= bytes_read
;
3729 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3730 info_ptr
+= bytes_read
;
3733 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3737 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3741 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3745 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3748 case DW_FORM_ref_udata
:
3749 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3750 info_ptr
+= bytes_read
;
3752 case DW_FORM_indirect
:
3753 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3754 info_ptr
+= bytes_read
;
3755 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu_header
);
3758 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3759 dwarf_form_name (form
));
3764 /* Read an attribute described by an abbreviated attribute. */
3767 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
3768 bfd
*abfd
, char *info_ptr
,
3769 const struct comp_unit_head
*cu_header
)
3771 attr
->name
= abbrev
->name
;
3772 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu_header
);
3775 /* read dwarf information from a buffer */
3778 read_1_byte (bfd
*abfd
, char *buf
)
3780 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3784 read_1_signed_byte (bfd
*abfd
, char *buf
)
3786 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3790 read_2_bytes (bfd
*abfd
, char *buf
)
3792 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3796 read_2_signed_bytes (bfd
*abfd
, char *buf
)
3798 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3802 read_4_bytes (bfd
*abfd
, char *buf
)
3804 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3808 read_4_signed_bytes (bfd
*abfd
, char *buf
)
3810 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3813 static unsigned long
3814 read_8_bytes (bfd
*abfd
, char *buf
)
3816 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3820 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3823 CORE_ADDR retval
= 0;
3825 if (cu_header
->signed_addr_p
)
3827 switch (cu_header
->addr_size
)
3830 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3833 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3836 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
3839 internal_error (__FILE__
, __LINE__
,
3840 "read_address: bad switch, signed");
3845 switch (cu_header
->addr_size
)
3848 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3851 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3854 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3857 internal_error (__FILE__
, __LINE__
,
3858 "read_address: bad switch, unsigned");
3862 *bytes_read
= cu_header
->addr_size
;
3866 /* Read the initial length from a section. The (draft) DWARF 3
3867 specification allows the initial length to take up either 4 bytes
3868 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
3869 bytes describe the length and all offsets will be 8 bytes in length
3872 An older, non-standard 64-bit format is also handled by this
3873 function. The older format in question stores the initial length
3874 as an 8-byte quantity without an escape value. Lengths greater
3875 than 2^32 aren't very common which means that the initial 4 bytes
3876 is almost always zero. Since a length value of zero doesn't make
3877 sense for the 32-bit format, this initial zero can be considered to
3878 be an escape value which indicates the presence of the older 64-bit
3879 format. As written, the code can't detect (old format) lengths
3880 greater than 4GB. If it becomes necessary to handle lengths somewhat
3881 larger than 4GB, we could allow other small values (such as the
3882 non-sensical values of 1, 2, and 3) to also be used as escape values
3883 indicating the presence of the old format.
3885 The value returned via bytes_read should be used to increment
3886 the relevant pointer after calling read_initial_length().
3888 As a side effect, this function sets the fields initial_length_size
3889 and offset_size in cu_header to the values appropriate for the
3890 length field. (The format of the initial length field determines
3891 the width of file offsets to be fetched later with fetch_offset().)
3893 [ Note: read_initial_length() and read_offset() are based on the
3894 document entitled "DWARF Debugging Information Format", revision
3895 3, draft 8, dated November 19, 2001. This document was obtained
3898 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
3900 This document is only a draft and is subject to change. (So beware.)
3902 Details regarding the older, non-standard 64-bit format were
3903 determined empirically by examining 64-bit ELF files produced
3904 by the SGI toolchain on an IRIX 6.5 machine.
3906 - Kevin, July 16, 2002
3910 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
3915 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3917 if (retval
== 0xffffffff)
3919 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
3921 if (cu_header
!= NULL
)
3923 cu_header
->initial_length_size
= 12;
3924 cu_header
->offset_size
= 8;
3927 else if (retval
== 0)
3929 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
3931 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3933 if (cu_header
!= NULL
)
3935 cu_header
->initial_length_size
= 8;
3936 cu_header
->offset_size
= 8;
3942 if (cu_header
!= NULL
)
3944 cu_header
->initial_length_size
= 4;
3945 cu_header
->offset_size
= 4;
3952 /* Read an offset from the data stream. The size of the offset is
3953 given by cu_header->offset_size. */
3956 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3961 switch (cu_header
->offset_size
)
3964 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3968 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3972 internal_error (__FILE__
, __LINE__
,
3973 "read_offset: bad switch");
3980 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
3982 /* If the size of a host char is 8 bits, we can return a pointer
3983 to the buffer, otherwise we have to copy the data to a buffer
3984 allocated on the temporary obstack. */
3985 gdb_assert (HOST_CHAR_BIT
== 8);
3990 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3992 /* If the size of a host char is 8 bits, we can return a pointer
3993 to the string, otherwise we have to copy the string to a buffer
3994 allocated on the temporary obstack. */
3995 gdb_assert (HOST_CHAR_BIT
== 8);
3998 *bytes_read_ptr
= 1;
4001 *bytes_read_ptr
= strlen (buf
) + 1;
4006 read_indirect_string (bfd
*abfd
, char *buf
,
4007 const struct comp_unit_head
*cu_header
,
4008 unsigned int *bytes_read_ptr
)
4010 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
4011 (int *) bytes_read_ptr
);
4013 if (dwarf_str_buffer
== NULL
)
4015 error ("DW_FORM_strp used without .debug_str section");
4018 if (str_offset
>= dwarf_str_size
)
4020 error ("DW_FORM_strp pointing outside of .debug_str section");
4023 gdb_assert (HOST_CHAR_BIT
== 8);
4024 if (dwarf_str_buffer
[str_offset
] == '\0')
4026 return dwarf_str_buffer
+ str_offset
;
4029 static unsigned long
4030 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4032 unsigned long result
;
4033 unsigned int num_read
;
4043 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4046 result
|= ((unsigned long)(byte
& 127) << shift
);
4047 if ((byte
& 128) == 0)
4053 *bytes_read_ptr
= num_read
;
4058 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4061 int i
, shift
, size
, num_read
;
4071 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4074 result
|= ((long)(byte
& 127) << shift
);
4076 if ((byte
& 128) == 0)
4081 if ((shift
< size
) && (byte
& 0x40))
4083 result
|= -(1 << shift
);
4085 *bytes_read_ptr
= num_read
;
4090 set_cu_language (unsigned int lang
)
4096 cu_language
= language_c
;
4098 case DW_LANG_C_plus_plus
:
4099 cu_language
= language_cplus
;
4101 case DW_LANG_Fortran77
:
4102 case DW_LANG_Fortran90
:
4103 case DW_LANG_Fortran95
:
4104 cu_language
= language_fortran
;
4106 case DW_LANG_Mips_Assembler
:
4107 cu_language
= language_asm
;
4110 cu_language
= language_java
;
4113 case DW_LANG_Cobol74
:
4114 case DW_LANG_Cobol85
:
4115 case DW_LANG_Pascal83
:
4116 case DW_LANG_Modula2
:
4118 cu_language
= language_unknown
;
4121 cu_language_defn
= language_def (cu_language
);
4124 /* Return the named attribute or NULL if not there. */
4126 static struct attribute
*
4127 dwarf_attr (struct die_info
*die
, unsigned int name
)
4130 struct attribute
*spec
= NULL
;
4132 for (i
= 0; i
< die
->num_attrs
; ++i
)
4134 if (die
->attrs
[i
].name
== name
)
4136 return &die
->attrs
[i
];
4138 if (die
->attrs
[i
].name
== DW_AT_specification
4139 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
4140 spec
= &die
->attrs
[i
];
4144 struct die_info
*ref_die
=
4145 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
4148 return dwarf_attr (ref_die
, name
);
4155 die_is_declaration (struct die_info
*die
)
4157 return (dwarf_attr (die
, DW_AT_declaration
)
4158 && ! dwarf_attr (die
, DW_AT_specification
));
4162 /* Free the line_header structure *LH, and any arrays and strings it
4165 free_line_header (struct line_header
*lh
)
4167 if (lh
->standard_opcode_lengths
)
4168 xfree (lh
->standard_opcode_lengths
);
4170 /* Remember that all the lh->file_names[i].name pointers are
4171 pointers into debug_line_buffer, and don't need to be freed. */
4173 xfree (lh
->file_names
);
4175 /* Similarly for the include directory names. */
4176 if (lh
->include_dirs
)
4177 xfree (lh
->include_dirs
);
4183 /* Add an entry to LH's include directory table. */
4185 add_include_dir (struct line_header
*lh
, char *include_dir
)
4187 /* Grow the array if necessary. */
4188 if (lh
->include_dirs_size
== 0)
4190 lh
->include_dirs_size
= 1; /* for testing */
4191 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
4192 * sizeof (*lh
->include_dirs
));
4194 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
4196 lh
->include_dirs_size
*= 2;
4197 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
4198 (lh
->include_dirs_size
4199 * sizeof (*lh
->include_dirs
)));
4202 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
4206 /* Add an entry to LH's file name table. */
4208 add_file_name (struct line_header
*lh
,
4210 unsigned int dir_index
,
4211 unsigned int mod_time
,
4212 unsigned int length
)
4214 struct file_entry
*fe
;
4216 /* Grow the array if necessary. */
4217 if (lh
->file_names_size
== 0)
4219 lh
->file_names_size
= 1; /* for testing */
4220 lh
->file_names
= xmalloc (lh
->file_names_size
4221 * sizeof (*lh
->file_names
));
4223 else if (lh
->num_file_names
>= lh
->file_names_size
)
4225 lh
->file_names_size
*= 2;
4226 lh
->file_names
= xrealloc (lh
->file_names
,
4227 (lh
->file_names_size
4228 * sizeof (*lh
->file_names
)));
4231 fe
= &lh
->file_names
[lh
->num_file_names
++];
4233 fe
->dir_index
= dir_index
;
4234 fe
->mod_time
= mod_time
;
4235 fe
->length
= length
;
4239 /* Read the statement program header starting at OFFSET in
4240 dwarf_line_buffer, according to the endianness of ABFD. Return a
4241 pointer to a struct line_header, allocated using xmalloc.
4243 NOTE: the strings in the include directory and file name tables of
4244 the returned object point into debug_line_buffer, and must not be
4246 static struct line_header
*
4247 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
4248 const struct comp_unit_head
*cu_header
)
4250 struct cleanup
*back_to
;
4251 struct line_header
*lh
;
4255 char *cur_dir
, *cur_file
;
4257 if (dwarf_line_buffer
== NULL
)
4259 complain (&dwarf2_missing_line_number_section
);
4263 /* Make sure that at least there's room for the total_length field. That
4264 could be 12 bytes long, but we're just going to fudge that. */
4265 if (offset
+ 4 >= dwarf_line_size
)
4267 complain (&dwarf2_statement_list_fits_in_line_number_section
);
4271 lh
= xmalloc (sizeof (*lh
));
4272 memset (lh
, 0, sizeof (*lh
));
4273 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
4276 line_ptr
= dwarf_line_buffer
+ offset
;
4278 /* read in the header */
4279 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
4280 line_ptr
+= bytes_read
;
4281 if (line_ptr
+ lh
->total_length
> dwarf_line_buffer
+ dwarf_line_size
)
4283 complain (&dwarf2_statement_list_fits_in_line_number_section
);
4286 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
4287 lh
->version
= read_2_bytes (abfd
, line_ptr
);
4289 lh
->header_length
= read_offset (abfd
, line_ptr
, cu_header
, &bytes_read
);
4290 line_ptr
+= bytes_read
;
4291 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
4293 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
4295 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
4297 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
4299 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
4301 lh
->standard_opcode_lengths
4302 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
4304 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
4305 for (i
= 1; i
< lh
->opcode_base
; ++i
)
4307 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
4311 /* Read directory table */
4312 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4314 line_ptr
+= bytes_read
;
4315 add_include_dir (lh
, cur_dir
);
4317 line_ptr
+= bytes_read
;
4319 /* Read file name table */
4320 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4322 unsigned int dir_index
, mod_time
, length
;
4324 line_ptr
+= bytes_read
;
4325 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4326 line_ptr
+= bytes_read
;
4327 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4328 line_ptr
+= bytes_read
;
4329 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4330 line_ptr
+= bytes_read
;
4332 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4334 line_ptr
+= bytes_read
;
4335 lh
->statement_program_start
= line_ptr
;
4337 if (line_ptr
> dwarf_line_buffer
+ dwarf_line_size
)
4338 complain (&dwarf2_line_header_too_long
);
4340 discard_cleanups (back_to
);
4344 /* This function exists to work around a bug in certain compilers
4345 (particularly GCC 2.95), in which the first line number marker of a
4346 function does not show up until after the prologue, right before
4347 the second line number marker. This function shifts ADDRESS down
4348 to the beginning of the function if necessary, and is called on
4349 addresses passed to record_line. */
4352 check_cu_functions (CORE_ADDR address
)
4354 struct function_range
*fn
;
4356 /* Find the function_range containing address. */
4361 cu_cached_fn
= cu_first_fn
;
4365 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4371 while (fn
&& fn
!= cu_cached_fn
)
4372 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4382 if (address
!= fn
->lowpc
)
4383 complain (&dwarf2_misplaced_line_number
,
4384 (unsigned long) address
, fn
->name
);
4389 /* Decode the line number information for the compilation unit whose
4390 line number info is at OFFSET in the .debug_line section.
4391 The compilation directory of the file is passed in COMP_DIR. */
4394 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
4395 const struct comp_unit_head
*cu_header
)
4399 unsigned int i
, bytes_read
;
4401 unsigned char op_code
, extended_op
, adj_opcode
;
4403 line_ptr
= lh
->statement_program_start
;
4404 line_end
= lh
->statement_program_end
;
4406 /* Read the statement sequences until there's nothing left. */
4407 while (line_ptr
< line_end
)
4409 /* state machine registers */
4410 CORE_ADDR address
= 0;
4411 unsigned int file
= 1;
4412 unsigned int line
= 1;
4413 unsigned int column
= 0;
4414 int is_stmt
= lh
->default_is_stmt
;
4415 int basic_block
= 0;
4416 int end_sequence
= 0;
4418 /* Start a subfile for the current file of the state machine. */
4419 if (lh
->num_file_names
>= file
)
4421 /* lh->include_dirs and lh->file_names are 0-based, but the
4422 directory and file name numbers in the statement program
4424 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
4427 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
4430 dwarf2_start_subfile (fe
->name
, dir
);
4433 /* Decode the table. */
4434 while (!end_sequence
)
4436 op_code
= read_1_byte (abfd
, line_ptr
);
4439 if (op_code
>= lh
->opcode_base
)
4440 { /* Special operand. */
4441 adj_opcode
= op_code
- lh
->opcode_base
;
4442 address
+= (adj_opcode
/ lh
->line_range
)
4443 * lh
->minimum_instruction_length
;
4444 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
4445 /* append row to matrix using current values */
4446 address
= check_cu_functions (address
);
4447 record_line (current_subfile
, line
, address
);
4450 else switch (op_code
)
4452 case DW_LNS_extended_op
:
4453 line_ptr
+= 1; /* ignore length */
4454 extended_op
= read_1_byte (abfd
, line_ptr
);
4456 switch (extended_op
)
4458 case DW_LNE_end_sequence
:
4460 record_line (current_subfile
, 0, address
);
4462 case DW_LNE_set_address
:
4463 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
4464 line_ptr
+= bytes_read
;
4465 address
+= baseaddr
;
4467 case DW_LNE_define_file
:
4470 unsigned int dir_index
, mod_time
, length
;
4472 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
4473 line_ptr
+= bytes_read
;
4475 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4476 line_ptr
+= bytes_read
;
4478 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4479 line_ptr
+= bytes_read
;
4481 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4482 line_ptr
+= bytes_read
;
4483 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4487 complain (&dwarf2_mangled_line_number_section
);
4492 address
= check_cu_functions (address
);
4493 record_line (current_subfile
, line
, address
);
4496 case DW_LNS_advance_pc
:
4497 address
+= lh
->minimum_instruction_length
4498 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4499 line_ptr
+= bytes_read
;
4501 case DW_LNS_advance_line
:
4502 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
4503 line_ptr
+= bytes_read
;
4505 case DW_LNS_set_file
:
4507 /* lh->include_dirs and lh->file_names are 0-based,
4508 but the directory and file name numbers in the
4509 statement program are 1-based. */
4510 struct file_entry
*fe
;
4512 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4513 line_ptr
+= bytes_read
;
4514 fe
= &lh
->file_names
[file
- 1];
4516 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
4519 dwarf2_start_subfile (fe
->name
, dir
);
4522 case DW_LNS_set_column
:
4523 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4524 line_ptr
+= bytes_read
;
4526 case DW_LNS_negate_stmt
:
4527 is_stmt
= (!is_stmt
);
4529 case DW_LNS_set_basic_block
:
4532 /* Add to the address register of the state machine the
4533 address increment value corresponding to special opcode
4534 255. Ie, this value is scaled by the minimum instruction
4535 length since special opcode 255 would have scaled the
4537 case DW_LNS_const_add_pc
:
4538 address
+= (lh
->minimum_instruction_length
4539 * ((255 - lh
->opcode_base
) / lh
->line_range
));
4541 case DW_LNS_fixed_advance_pc
:
4542 address
+= read_2_bytes (abfd
, line_ptr
);
4546 { /* Unknown standard opcode, ignore it. */
4548 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
4550 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4551 line_ptr
+= bytes_read
;
4559 /* Start a subfile for DWARF. FILENAME is the name of the file and
4560 DIRNAME the name of the source directory which contains FILENAME
4561 or NULL if not known.
4562 This routine tries to keep line numbers from identical absolute and
4563 relative file names in a common subfile.
4565 Using the `list' example from the GDB testsuite, which resides in
4566 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4567 of /srcdir/list0.c yields the following debugging information for list0.c:
4569 DW_AT_name: /srcdir/list0.c
4570 DW_AT_comp_dir: /compdir
4571 files.files[0].name: list0.h
4572 files.files[0].dir: /srcdir
4573 files.files[1].name: list0.c
4574 files.files[1].dir: /srcdir
4576 The line number information for list0.c has to end up in a single
4577 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4580 dwarf2_start_subfile (char *filename
, char *dirname
)
4582 /* If the filename isn't absolute, try to match an existing subfile
4583 with the full pathname. */
4585 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
4587 struct subfile
*subfile
;
4588 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4590 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4592 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
4594 current_subfile
= subfile
;
4601 start_subfile (filename
, dirname
);
4604 /* Given a pointer to a DWARF information entry, figure out if we need
4605 to make a symbol table entry for it, and if so, create a new entry
4606 and return a pointer to it.
4607 If TYPE is NULL, determine symbol type from the die, otherwise
4608 used the passed type. */
4610 static struct symbol
*
4611 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
4612 const struct comp_unit_head
*cu_header
)
4614 struct symbol
*sym
= NULL
;
4616 struct attribute
*attr
= NULL
;
4617 struct attribute
*attr2
= NULL
;
4620 name
= dwarf2_linkage_name (die
);
4623 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4624 sizeof (struct symbol
));
4625 OBJSTAT (objfile
, n_syms
++);
4626 memset (sym
, 0, sizeof (struct symbol
));
4627 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4628 &objfile
->symbol_obstack
);
4630 /* Default assumptions.
4631 Use the passed type or decode it from the die. */
4632 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4633 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4635 SYMBOL_TYPE (sym
) = type
;
4637 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
4638 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4641 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4644 /* If this symbol is from a C++ compilation, then attempt to
4645 cache the demangled form for future reference. This is a
4646 typical time versus space tradeoff, that was decided in favor
4647 of time because it sped up C++ symbol lookups by a factor of
4650 SYMBOL_LANGUAGE (sym
) = cu_language
;
4651 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4655 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4658 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4660 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4662 case DW_TAG_subprogram
:
4663 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4665 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4666 attr2
= dwarf_attr (die
, DW_AT_external
);
4667 if (attr2
&& (DW_UNSND (attr2
) != 0))
4669 add_symbol_to_list (sym
, &global_symbols
);
4673 add_symbol_to_list (sym
, list_in_scope
);
4676 case DW_TAG_variable
:
4677 /* Compilation with minimal debug info may result in variables
4678 with missing type entries. Change the misleading `void' type
4679 to something sensible. */
4680 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4681 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4682 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4683 "<variable, no debug info>",
4685 attr
= dwarf_attr (die
, DW_AT_const_value
);
4688 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4689 attr2
= dwarf_attr (die
, DW_AT_external
);
4690 if (attr2
&& (DW_UNSND (attr2
) != 0))
4691 add_symbol_to_list (sym
, &global_symbols
);
4693 add_symbol_to_list (sym
, list_in_scope
);
4696 attr
= dwarf_attr (die
, DW_AT_location
);
4699 attr2
= dwarf_attr (die
, DW_AT_external
);
4700 if (attr2
&& (DW_UNSND (attr2
) != 0))
4702 /* Support the .debug_loc offsets */
4703 if (attr_form_is_block (attr
))
4705 SYMBOL_VALUE_ADDRESS (sym
) =
4706 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4708 else if (attr
->form
== DW_FORM_data4
4709 || attr
->form
== DW_FORM_data8
)
4711 complain (&dwarf2_complex_location_expr
);
4715 complain (&dwarf2_invalid_attrib_class
, "DW_AT_location",
4716 "external variable");
4718 add_symbol_to_list (sym
, &global_symbols
);
4720 /* In shared libraries the address of the variable
4721 in the location descriptor might still be relocatable,
4722 so its value could be zero.
4723 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4724 value is zero, the address of the variable will then
4725 be determined from the minimal symbol table whenever
4726 the variable is referenced. */
4727 if (SYMBOL_VALUE_ADDRESS (sym
))
4729 fixup_symbol_section (sym
, objfile
);
4730 SYMBOL_VALUE_ADDRESS (sym
) +=
4731 ANOFFSET (objfile
->section_offsets
,
4732 SYMBOL_SECTION (sym
));
4733 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4736 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4740 /* Support the .debug_loc offsets */
4741 if (attr_form_is_block (attr
))
4743 SYMBOL_VALUE (sym
) = addr
=
4744 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4746 else if (attr
->form
== DW_FORM_data4
4747 || attr
->form
== DW_FORM_data8
)
4749 complain (&dwarf2_complex_location_expr
);
4753 complain (&dwarf2_invalid_attrib_class
, "DW_AT_location",
4754 "external variable");
4757 add_symbol_to_list (sym
, list_in_scope
);
4760 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4764 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4765 SYMBOL_VALUE (sym
) =
4766 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4770 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4771 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4775 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4779 fixup_symbol_section (sym
, objfile
);
4780 SYMBOL_VALUE_ADDRESS (sym
) =
4781 addr
+ ANOFFSET (objfile
->section_offsets
,
4782 SYMBOL_SECTION (sym
));
4783 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4789 /* We do not know the address of this symbol.
4790 If it is an external symbol and we have type information
4791 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4792 The address of the variable will then be determined from
4793 the minimal symbol table whenever the variable is
4795 attr2
= dwarf_attr (die
, DW_AT_external
);
4796 if (attr2
&& (DW_UNSND (attr2
) != 0)
4797 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4799 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4800 add_symbol_to_list (sym
, &global_symbols
);
4804 case DW_TAG_formal_parameter
:
4805 attr
= dwarf_attr (die
, DW_AT_location
);
4808 SYMBOL_VALUE (sym
) =
4809 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4812 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4813 SYMBOL_VALUE (sym
) =
4814 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4820 if (basereg
!= frame_base_reg
)
4821 complain (&dwarf2_complex_location_expr
);
4822 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4826 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4827 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4832 SYMBOL_CLASS (sym
) = LOC_ARG
;
4835 attr
= dwarf_attr (die
, DW_AT_const_value
);
4838 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4840 add_symbol_to_list (sym
, list_in_scope
);
4842 case DW_TAG_unspecified_parameters
:
4843 /* From varargs functions; gdb doesn't seem to have any
4844 interest in this information, so just ignore it for now.
4847 case DW_TAG_class_type
:
4848 case DW_TAG_structure_type
:
4849 case DW_TAG_union_type
:
4850 case DW_TAG_enumeration_type
:
4851 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4852 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4853 add_symbol_to_list (sym
, list_in_scope
);
4855 /* The semantics of C++ state that "struct foo { ... }" also
4856 defines a typedef for "foo". Synthesize a typedef symbol so
4857 that "ptype foo" works as expected. */
4858 if (cu_language
== language_cplus
)
4860 struct symbol
*typedef_sym
= (struct symbol
*)
4861 obstack_alloc (&objfile
->symbol_obstack
,
4862 sizeof (struct symbol
));
4863 *typedef_sym
= *sym
;
4864 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4865 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4866 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4867 obsavestring (SYMBOL_NAME (sym
),
4868 strlen (SYMBOL_NAME (sym
)),
4869 &objfile
->type_obstack
);
4870 add_symbol_to_list (typedef_sym
, list_in_scope
);
4873 case DW_TAG_typedef
:
4874 case DW_TAG_base_type
:
4875 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4876 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4877 add_symbol_to_list (sym
, list_in_scope
);
4879 case DW_TAG_enumerator
:
4880 attr
= dwarf_attr (die
, DW_AT_const_value
);
4883 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4885 add_symbol_to_list (sym
, list_in_scope
);
4888 /* Not a tag we recognize. Hopefully we aren't processing
4889 trash data, but since we must specifically ignore things
4890 we don't recognize, there is nothing else we should do at
4892 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4899 /* Copy constant value from an attribute to a symbol. */
4902 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
4903 struct objfile
*objfile
,
4904 const struct comp_unit_head
*cu_header
)
4906 struct dwarf_block
*blk
;
4911 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
4912 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4913 cu_header
->addr_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4914 SYMBOL_VALUE_BYTES (sym
) = (char *)
4915 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
4916 store_address (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
4918 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4920 case DW_FORM_block1
:
4921 case DW_FORM_block2
:
4922 case DW_FORM_block4
:
4924 blk
= DW_BLOCK (attr
);
4925 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4926 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4927 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4928 SYMBOL_VALUE_BYTES (sym
) = (char *)
4929 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4930 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4931 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4934 /* The DW_AT_const_value attributes are supposed to carry the
4935 symbol's value "represented as it would be on the target
4936 architecture." By the time we get here, it's already been
4937 converted to host endianness, so we just need to sign- or
4938 zero-extend it as appropriate. */
4940 dwarf2_const_value_data (attr
, sym
, 8);
4943 dwarf2_const_value_data (attr
, sym
, 16);
4946 dwarf2_const_value_data (attr
, sym
, 32);
4949 dwarf2_const_value_data (attr
, sym
, 64);
4953 SYMBOL_VALUE (sym
) = DW_SND (attr
);
4954 SYMBOL_CLASS (sym
) = LOC_CONST
;
4958 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4959 SYMBOL_CLASS (sym
) = LOC_CONST
;
4963 complain (&dwarf2_unsupported_const_value_attr
,
4964 dwarf_form_name (attr
->form
));
4965 SYMBOL_VALUE (sym
) = 0;
4966 SYMBOL_CLASS (sym
) = LOC_CONST
;
4972 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4973 or zero-extend it as appropriate for the symbol's type. */
4975 dwarf2_const_value_data (struct attribute
*attr
,
4979 LONGEST l
= DW_UNSND (attr
);
4981 if (bits
< sizeof (l
) * 8)
4983 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
4984 l
&= ((LONGEST
) 1 << bits
) - 1;
4986 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
4989 SYMBOL_VALUE (sym
) = l
;
4990 SYMBOL_CLASS (sym
) = LOC_CONST
;
4994 /* Return the type of the die in question using its DW_AT_type attribute. */
4996 static struct type
*
4997 die_type (struct die_info
*die
, struct objfile
*objfile
,
4998 const struct comp_unit_head
*cu_header
)
5001 struct attribute
*type_attr
;
5002 struct die_info
*type_die
;
5005 type_attr
= dwarf_attr (die
, DW_AT_type
);
5008 /* A missing DW_AT_type represents a void type. */
5009 return dwarf2_fundamental_type (objfile
, FT_VOID
);
5013 ref
= dwarf2_get_ref_die_offset (type_attr
);
5014 type_die
= follow_die_ref (ref
);
5017 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
5021 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
5024 dump_die (type_die
);
5025 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
5030 /* Return the containing type of the die in question using its
5031 DW_AT_containing_type attribute. */
5033 static struct type
*
5034 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
5035 const struct comp_unit_head
*cu_header
)
5037 struct type
*type
= NULL
;
5038 struct attribute
*type_attr
;
5039 struct die_info
*type_die
= NULL
;
5042 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
5045 ref
= dwarf2_get_ref_die_offset (type_attr
);
5046 type_die
= follow_die_ref (ref
);
5049 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
5052 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
5057 dump_die (type_die
);
5058 error ("Dwarf Error: Problem turning containing type into gdb type.");
5064 static struct type
*
5065 type_at_offset (unsigned int offset
, struct objfile
*objfile
)
5067 struct die_info
*die
;
5070 die
= follow_die_ref (offset
);
5073 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
5076 type
= tag_type_to_type (die
, objfile
);
5081 static struct type
*
5082 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
5083 const struct comp_unit_head
*cu_header
)
5091 read_type_die (die
, objfile
, cu_header
);
5095 error ("Dwarf Error: Cannot find type of die.");
5102 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
5103 const struct comp_unit_head
*cu_header
)
5107 case DW_TAG_class_type
:
5108 case DW_TAG_structure_type
:
5109 case DW_TAG_union_type
:
5110 read_structure_scope (die
, objfile
, cu_header
);
5112 case DW_TAG_enumeration_type
:
5113 read_enumeration (die
, objfile
, cu_header
);
5115 case DW_TAG_subprogram
:
5116 case DW_TAG_subroutine_type
:
5117 read_subroutine_type (die
, objfile
, cu_header
);
5119 case DW_TAG_array_type
:
5120 read_array_type (die
, objfile
, cu_header
);
5122 case DW_TAG_pointer_type
:
5123 read_tag_pointer_type (die
, objfile
, cu_header
);
5125 case DW_TAG_ptr_to_member_type
:
5126 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
5128 case DW_TAG_reference_type
:
5129 read_tag_reference_type (die
, objfile
, cu_header
);
5131 case DW_TAG_const_type
:
5132 read_tag_const_type (die
, objfile
, cu_header
);
5134 case DW_TAG_volatile_type
:
5135 read_tag_volatile_type (die
, objfile
, cu_header
);
5137 case DW_TAG_string_type
:
5138 read_tag_string_type (die
, objfile
);
5140 case DW_TAG_typedef
:
5141 read_typedef (die
, objfile
, cu_header
);
5143 case DW_TAG_base_type
:
5144 read_base_type (die
, objfile
);
5147 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
5152 static struct type
*
5153 dwarf_base_type (int encoding
, int size
, struct objfile
*objfile
)
5155 /* FIXME - this should not produce a new (struct type *)
5156 every time. It should cache base types. */
5160 case DW_ATE_address
:
5161 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
5163 case DW_ATE_boolean
:
5164 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
5166 case DW_ATE_complex_float
:
5169 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
5173 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
5179 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
5183 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
5190 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5193 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
5197 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5201 case DW_ATE_signed_char
:
5202 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5204 case DW_ATE_unsigned
:
5208 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5211 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
5215 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
5219 case DW_ATE_unsigned_char
:
5220 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5223 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5230 copy_die (struct die_info
*old_die
)
5232 struct die_info
*new_die
;
5235 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5236 memset (new_die
, 0, sizeof (struct die_info
));
5238 new_die
->tag
= old_die
->tag
;
5239 new_die
->has_children
= old_die
->has_children
;
5240 new_die
->abbrev
= old_die
->abbrev
;
5241 new_die
->offset
= old_die
->offset
;
5242 new_die
->type
= NULL
;
5244 num_attrs
= old_die
->num_attrs
;
5245 new_die
->num_attrs
= num_attrs
;
5246 new_die
->attrs
= (struct attribute
*)
5247 xmalloc (num_attrs
* sizeof (struct attribute
));
5249 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
5251 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
5252 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
5253 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
5256 new_die
->next
= NULL
;
5261 /* Return sibling of die, NULL if no sibling. */
5263 static struct die_info
*
5264 sibling_die (struct die_info
*die
)
5266 int nesting_level
= 0;
5268 if (!die
->has_children
)
5270 if (die
->next
&& (die
->next
->tag
== 0))
5283 if (die
->has_children
)
5293 while (nesting_level
);
5294 if (die
&& (die
->tag
== 0))
5305 /* Get linkage name of a die, return NULL if not found. */
5308 dwarf2_linkage_name (struct die_info
*die
)
5310 struct attribute
*attr
;
5312 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
5313 if (attr
&& DW_STRING (attr
))
5314 return DW_STRING (attr
);
5315 attr
= dwarf_attr (die
, DW_AT_name
);
5316 if (attr
&& DW_STRING (attr
))
5317 return DW_STRING (attr
);
5321 /* Convert a DIE tag into its string name. */
5324 dwarf_tag_name (register unsigned tag
)
5328 case DW_TAG_padding
:
5329 return "DW_TAG_padding";
5330 case DW_TAG_array_type
:
5331 return "DW_TAG_array_type";
5332 case DW_TAG_class_type
:
5333 return "DW_TAG_class_type";
5334 case DW_TAG_entry_point
:
5335 return "DW_TAG_entry_point";
5336 case DW_TAG_enumeration_type
:
5337 return "DW_TAG_enumeration_type";
5338 case DW_TAG_formal_parameter
:
5339 return "DW_TAG_formal_parameter";
5340 case DW_TAG_imported_declaration
:
5341 return "DW_TAG_imported_declaration";
5343 return "DW_TAG_label";
5344 case DW_TAG_lexical_block
:
5345 return "DW_TAG_lexical_block";
5347 return "DW_TAG_member";
5348 case DW_TAG_pointer_type
:
5349 return "DW_TAG_pointer_type";
5350 case DW_TAG_reference_type
:
5351 return "DW_TAG_reference_type";
5352 case DW_TAG_compile_unit
:
5353 return "DW_TAG_compile_unit";
5354 case DW_TAG_string_type
:
5355 return "DW_TAG_string_type";
5356 case DW_TAG_structure_type
:
5357 return "DW_TAG_structure_type";
5358 case DW_TAG_subroutine_type
:
5359 return "DW_TAG_subroutine_type";
5360 case DW_TAG_typedef
:
5361 return "DW_TAG_typedef";
5362 case DW_TAG_union_type
:
5363 return "DW_TAG_union_type";
5364 case DW_TAG_unspecified_parameters
:
5365 return "DW_TAG_unspecified_parameters";
5366 case DW_TAG_variant
:
5367 return "DW_TAG_variant";
5368 case DW_TAG_common_block
:
5369 return "DW_TAG_common_block";
5370 case DW_TAG_common_inclusion
:
5371 return "DW_TAG_common_inclusion";
5372 case DW_TAG_inheritance
:
5373 return "DW_TAG_inheritance";
5374 case DW_TAG_inlined_subroutine
:
5375 return "DW_TAG_inlined_subroutine";
5377 return "DW_TAG_module";
5378 case DW_TAG_ptr_to_member_type
:
5379 return "DW_TAG_ptr_to_member_type";
5380 case DW_TAG_set_type
:
5381 return "DW_TAG_set_type";
5382 case DW_TAG_subrange_type
:
5383 return "DW_TAG_subrange_type";
5384 case DW_TAG_with_stmt
:
5385 return "DW_TAG_with_stmt";
5386 case DW_TAG_access_declaration
:
5387 return "DW_TAG_access_declaration";
5388 case DW_TAG_base_type
:
5389 return "DW_TAG_base_type";
5390 case DW_TAG_catch_block
:
5391 return "DW_TAG_catch_block";
5392 case DW_TAG_const_type
:
5393 return "DW_TAG_const_type";
5394 case DW_TAG_constant
:
5395 return "DW_TAG_constant";
5396 case DW_TAG_enumerator
:
5397 return "DW_TAG_enumerator";
5398 case DW_TAG_file_type
:
5399 return "DW_TAG_file_type";
5401 return "DW_TAG_friend";
5402 case DW_TAG_namelist
:
5403 return "DW_TAG_namelist";
5404 case DW_TAG_namelist_item
:
5405 return "DW_TAG_namelist_item";
5406 case DW_TAG_packed_type
:
5407 return "DW_TAG_packed_type";
5408 case DW_TAG_subprogram
:
5409 return "DW_TAG_subprogram";
5410 case DW_TAG_template_type_param
:
5411 return "DW_TAG_template_type_param";
5412 case DW_TAG_template_value_param
:
5413 return "DW_TAG_template_value_param";
5414 case DW_TAG_thrown_type
:
5415 return "DW_TAG_thrown_type";
5416 case DW_TAG_try_block
:
5417 return "DW_TAG_try_block";
5418 case DW_TAG_variant_part
:
5419 return "DW_TAG_variant_part";
5420 case DW_TAG_variable
:
5421 return "DW_TAG_variable";
5422 case DW_TAG_volatile_type
:
5423 return "DW_TAG_volatile_type";
5424 case DW_TAG_MIPS_loop
:
5425 return "DW_TAG_MIPS_loop";
5426 case DW_TAG_format_label
:
5427 return "DW_TAG_format_label";
5428 case DW_TAG_function_template
:
5429 return "DW_TAG_function_template";
5430 case DW_TAG_class_template
:
5431 return "DW_TAG_class_template";
5433 return "DW_TAG_<unknown>";
5437 /* Convert a DWARF attribute code into its string name. */
5440 dwarf_attr_name (register unsigned attr
)
5445 return "DW_AT_sibling";
5446 case DW_AT_location
:
5447 return "DW_AT_location";
5449 return "DW_AT_name";
5450 case DW_AT_ordering
:
5451 return "DW_AT_ordering";
5452 case DW_AT_subscr_data
:
5453 return "DW_AT_subscr_data";
5454 case DW_AT_byte_size
:
5455 return "DW_AT_byte_size";
5456 case DW_AT_bit_offset
:
5457 return "DW_AT_bit_offset";
5458 case DW_AT_bit_size
:
5459 return "DW_AT_bit_size";
5460 case DW_AT_element_list
:
5461 return "DW_AT_element_list";
5462 case DW_AT_stmt_list
:
5463 return "DW_AT_stmt_list";
5465 return "DW_AT_low_pc";
5467 return "DW_AT_high_pc";
5468 case DW_AT_language
:
5469 return "DW_AT_language";
5471 return "DW_AT_member";
5473 return "DW_AT_discr";
5474 case DW_AT_discr_value
:
5475 return "DW_AT_discr_value";
5476 case DW_AT_visibility
:
5477 return "DW_AT_visibility";
5479 return "DW_AT_import";
5480 case DW_AT_string_length
:
5481 return "DW_AT_string_length";
5482 case DW_AT_common_reference
:
5483 return "DW_AT_common_reference";
5484 case DW_AT_comp_dir
:
5485 return "DW_AT_comp_dir";
5486 case DW_AT_const_value
:
5487 return "DW_AT_const_value";
5488 case DW_AT_containing_type
:
5489 return "DW_AT_containing_type";
5490 case DW_AT_default_value
:
5491 return "DW_AT_default_value";
5493 return "DW_AT_inline";
5494 case DW_AT_is_optional
:
5495 return "DW_AT_is_optional";
5496 case DW_AT_lower_bound
:
5497 return "DW_AT_lower_bound";
5498 case DW_AT_producer
:
5499 return "DW_AT_producer";
5500 case DW_AT_prototyped
:
5501 return "DW_AT_prototyped";
5502 case DW_AT_return_addr
:
5503 return "DW_AT_return_addr";
5504 case DW_AT_start_scope
:
5505 return "DW_AT_start_scope";
5506 case DW_AT_stride_size
:
5507 return "DW_AT_stride_size";
5508 case DW_AT_upper_bound
:
5509 return "DW_AT_upper_bound";
5510 case DW_AT_abstract_origin
:
5511 return "DW_AT_abstract_origin";
5512 case DW_AT_accessibility
:
5513 return "DW_AT_accessibility";
5514 case DW_AT_address_class
:
5515 return "DW_AT_address_class";
5516 case DW_AT_artificial
:
5517 return "DW_AT_artificial";
5518 case DW_AT_base_types
:
5519 return "DW_AT_base_types";
5520 case DW_AT_calling_convention
:
5521 return "DW_AT_calling_convention";
5523 return "DW_AT_count";
5524 case DW_AT_data_member_location
:
5525 return "DW_AT_data_member_location";
5526 case DW_AT_decl_column
:
5527 return "DW_AT_decl_column";
5528 case DW_AT_decl_file
:
5529 return "DW_AT_decl_file";
5530 case DW_AT_decl_line
:
5531 return "DW_AT_decl_line";
5532 case DW_AT_declaration
:
5533 return "DW_AT_declaration";
5534 case DW_AT_discr_list
:
5535 return "DW_AT_discr_list";
5536 case DW_AT_encoding
:
5537 return "DW_AT_encoding";
5538 case DW_AT_external
:
5539 return "DW_AT_external";
5540 case DW_AT_frame_base
:
5541 return "DW_AT_frame_base";
5543 return "DW_AT_friend";
5544 case DW_AT_identifier_case
:
5545 return "DW_AT_identifier_case";
5546 case DW_AT_macro_info
:
5547 return "DW_AT_macro_info";
5548 case DW_AT_namelist_items
:
5549 return "DW_AT_namelist_items";
5550 case DW_AT_priority
:
5551 return "DW_AT_priority";
5553 return "DW_AT_segment";
5554 case DW_AT_specification
:
5555 return "DW_AT_specification";
5556 case DW_AT_static_link
:
5557 return "DW_AT_static_link";
5559 return "DW_AT_type";
5560 case DW_AT_use_location
:
5561 return "DW_AT_use_location";
5562 case DW_AT_variable_parameter
:
5563 return "DW_AT_variable_parameter";
5564 case DW_AT_virtuality
:
5565 return "DW_AT_virtuality";
5566 case DW_AT_vtable_elem_location
:
5567 return "DW_AT_vtable_elem_location";
5570 case DW_AT_MIPS_fde
:
5571 return "DW_AT_MIPS_fde";
5572 case DW_AT_MIPS_loop_begin
:
5573 return "DW_AT_MIPS_loop_begin";
5574 case DW_AT_MIPS_tail_loop_begin
:
5575 return "DW_AT_MIPS_tail_loop_begin";
5576 case DW_AT_MIPS_epilog_begin
:
5577 return "DW_AT_MIPS_epilog_begin";
5578 case DW_AT_MIPS_loop_unroll_factor
:
5579 return "DW_AT_MIPS_loop_unroll_factor";
5580 case DW_AT_MIPS_software_pipeline_depth
:
5581 return "DW_AT_MIPS_software_pipeline_depth";
5582 case DW_AT_MIPS_linkage_name
:
5583 return "DW_AT_MIPS_linkage_name";
5586 case DW_AT_sf_names
:
5587 return "DW_AT_sf_names";
5588 case DW_AT_src_info
:
5589 return "DW_AT_src_info";
5590 case DW_AT_mac_info
:
5591 return "DW_AT_mac_info";
5592 case DW_AT_src_coords
:
5593 return "DW_AT_src_coords";
5594 case DW_AT_body_begin
:
5595 return "DW_AT_body_begin";
5596 case DW_AT_body_end
:
5597 return "DW_AT_body_end";
5598 case DW_AT_GNU_vector
:
5599 return "DW_AT_GNU_vector";
5601 return "DW_AT_<unknown>";
5605 /* Convert a DWARF value form code into its string name. */
5608 dwarf_form_name (register unsigned form
)
5613 return "DW_FORM_addr";
5614 case DW_FORM_block2
:
5615 return "DW_FORM_block2";
5616 case DW_FORM_block4
:
5617 return "DW_FORM_block4";
5619 return "DW_FORM_data2";
5621 return "DW_FORM_data4";
5623 return "DW_FORM_data8";
5624 case DW_FORM_string
:
5625 return "DW_FORM_string";
5627 return "DW_FORM_block";
5628 case DW_FORM_block1
:
5629 return "DW_FORM_block1";
5631 return "DW_FORM_data1";
5633 return "DW_FORM_flag";
5635 return "DW_FORM_sdata";
5637 return "DW_FORM_strp";
5639 return "DW_FORM_udata";
5640 case DW_FORM_ref_addr
:
5641 return "DW_FORM_ref_addr";
5643 return "DW_FORM_ref1";
5645 return "DW_FORM_ref2";
5647 return "DW_FORM_ref4";
5649 return "DW_FORM_ref8";
5650 case DW_FORM_ref_udata
:
5651 return "DW_FORM_ref_udata";
5652 case DW_FORM_indirect
:
5653 return "DW_FORM_indirect";
5655 return "DW_FORM_<unknown>";
5659 /* Convert a DWARF stack opcode into its string name. */
5662 dwarf_stack_op_name (register unsigned op
)
5667 return "DW_OP_addr";
5669 return "DW_OP_deref";
5671 return "DW_OP_const1u";
5673 return "DW_OP_const1s";
5675 return "DW_OP_const2u";
5677 return "DW_OP_const2s";
5679 return "DW_OP_const4u";
5681 return "DW_OP_const4s";
5683 return "DW_OP_const8u";
5685 return "DW_OP_const8s";
5687 return "DW_OP_constu";
5689 return "DW_OP_consts";
5693 return "DW_OP_drop";
5695 return "DW_OP_over";
5697 return "DW_OP_pick";
5699 return "DW_OP_swap";
5703 return "DW_OP_xderef";
5711 return "DW_OP_minus";
5723 return "DW_OP_plus";
5724 case DW_OP_plus_uconst
:
5725 return "DW_OP_plus_uconst";
5731 return "DW_OP_shra";
5749 return "DW_OP_skip";
5751 return "DW_OP_lit0";
5753 return "DW_OP_lit1";
5755 return "DW_OP_lit2";
5757 return "DW_OP_lit3";
5759 return "DW_OP_lit4";
5761 return "DW_OP_lit5";
5763 return "DW_OP_lit6";
5765 return "DW_OP_lit7";
5767 return "DW_OP_lit8";
5769 return "DW_OP_lit9";
5771 return "DW_OP_lit10";
5773 return "DW_OP_lit11";
5775 return "DW_OP_lit12";
5777 return "DW_OP_lit13";
5779 return "DW_OP_lit14";
5781 return "DW_OP_lit15";
5783 return "DW_OP_lit16";
5785 return "DW_OP_lit17";
5787 return "DW_OP_lit18";
5789 return "DW_OP_lit19";
5791 return "DW_OP_lit20";
5793 return "DW_OP_lit21";
5795 return "DW_OP_lit22";
5797 return "DW_OP_lit23";
5799 return "DW_OP_lit24";
5801 return "DW_OP_lit25";
5803 return "DW_OP_lit26";
5805 return "DW_OP_lit27";
5807 return "DW_OP_lit28";
5809 return "DW_OP_lit29";
5811 return "DW_OP_lit30";
5813 return "DW_OP_lit31";
5815 return "DW_OP_reg0";
5817 return "DW_OP_reg1";
5819 return "DW_OP_reg2";
5821 return "DW_OP_reg3";
5823 return "DW_OP_reg4";
5825 return "DW_OP_reg5";
5827 return "DW_OP_reg6";
5829 return "DW_OP_reg7";
5831 return "DW_OP_reg8";
5833 return "DW_OP_reg9";
5835 return "DW_OP_reg10";
5837 return "DW_OP_reg11";
5839 return "DW_OP_reg12";
5841 return "DW_OP_reg13";
5843 return "DW_OP_reg14";
5845 return "DW_OP_reg15";
5847 return "DW_OP_reg16";
5849 return "DW_OP_reg17";
5851 return "DW_OP_reg18";
5853 return "DW_OP_reg19";
5855 return "DW_OP_reg20";
5857 return "DW_OP_reg21";
5859 return "DW_OP_reg22";
5861 return "DW_OP_reg23";
5863 return "DW_OP_reg24";
5865 return "DW_OP_reg25";
5867 return "DW_OP_reg26";
5869 return "DW_OP_reg27";
5871 return "DW_OP_reg28";
5873 return "DW_OP_reg29";
5875 return "DW_OP_reg30";
5877 return "DW_OP_reg31";
5879 return "DW_OP_breg0";
5881 return "DW_OP_breg1";
5883 return "DW_OP_breg2";
5885 return "DW_OP_breg3";
5887 return "DW_OP_breg4";
5889 return "DW_OP_breg5";
5891 return "DW_OP_breg6";
5893 return "DW_OP_breg7";
5895 return "DW_OP_breg8";
5897 return "DW_OP_breg9";
5899 return "DW_OP_breg10";
5901 return "DW_OP_breg11";
5903 return "DW_OP_breg12";
5905 return "DW_OP_breg13";
5907 return "DW_OP_breg14";
5909 return "DW_OP_breg15";
5911 return "DW_OP_breg16";
5913 return "DW_OP_breg17";
5915 return "DW_OP_breg18";
5917 return "DW_OP_breg19";
5919 return "DW_OP_breg20";
5921 return "DW_OP_breg21";
5923 return "DW_OP_breg22";
5925 return "DW_OP_breg23";
5927 return "DW_OP_breg24";
5929 return "DW_OP_breg25";
5931 return "DW_OP_breg26";
5933 return "DW_OP_breg27";
5935 return "DW_OP_breg28";
5937 return "DW_OP_breg29";
5939 return "DW_OP_breg30";
5941 return "DW_OP_breg31";
5943 return "DW_OP_regx";
5945 return "DW_OP_fbreg";
5947 return "DW_OP_bregx";
5949 return "DW_OP_piece";
5950 case DW_OP_deref_size
:
5951 return "DW_OP_deref_size";
5952 case DW_OP_xderef_size
:
5953 return "DW_OP_xderef_size";
5957 return "OP_<unknown>";
5962 dwarf_bool_name (unsigned mybool
)
5970 /* Convert a DWARF type code into its string name. */
5973 dwarf_type_encoding_name (register unsigned enc
)
5977 case DW_ATE_address
:
5978 return "DW_ATE_address";
5979 case DW_ATE_boolean
:
5980 return "DW_ATE_boolean";
5981 case DW_ATE_complex_float
:
5982 return "DW_ATE_complex_float";
5984 return "DW_ATE_float";
5986 return "DW_ATE_signed";
5987 case DW_ATE_signed_char
:
5988 return "DW_ATE_signed_char";
5989 case DW_ATE_unsigned
:
5990 return "DW_ATE_unsigned";
5991 case DW_ATE_unsigned_char
:
5992 return "DW_ATE_unsigned_char";
5994 return "DW_ATE_<unknown>";
5998 /* Convert a DWARF call frame info operation to its string name. */
6002 dwarf_cfi_name (register unsigned cfi_opc
)
6006 case DW_CFA_advance_loc
:
6007 return "DW_CFA_advance_loc";
6009 return "DW_CFA_offset";
6010 case DW_CFA_restore
:
6011 return "DW_CFA_restore";
6013 return "DW_CFA_nop";
6014 case DW_CFA_set_loc
:
6015 return "DW_CFA_set_loc";
6016 case DW_CFA_advance_loc1
:
6017 return "DW_CFA_advance_loc1";
6018 case DW_CFA_advance_loc2
:
6019 return "DW_CFA_advance_loc2";
6020 case DW_CFA_advance_loc4
:
6021 return "DW_CFA_advance_loc4";
6022 case DW_CFA_offset_extended
:
6023 return "DW_CFA_offset_extended";
6024 case DW_CFA_restore_extended
:
6025 return "DW_CFA_restore_extended";
6026 case DW_CFA_undefined
:
6027 return "DW_CFA_undefined";
6028 case DW_CFA_same_value
:
6029 return "DW_CFA_same_value";
6030 case DW_CFA_register
:
6031 return "DW_CFA_register";
6032 case DW_CFA_remember_state
:
6033 return "DW_CFA_remember_state";
6034 case DW_CFA_restore_state
:
6035 return "DW_CFA_restore_state";
6036 case DW_CFA_def_cfa
:
6037 return "DW_CFA_def_cfa";
6038 case DW_CFA_def_cfa_register
:
6039 return "DW_CFA_def_cfa_register";
6040 case DW_CFA_def_cfa_offset
:
6041 return "DW_CFA_def_cfa_offset";
6044 case DW_CFA_def_cfa_expression
:
6045 return "DW_CFA_def_cfa_expression";
6046 case DW_CFA_expression
:
6047 return "DW_CFA_expression";
6048 case DW_CFA_offset_extended_sf
:
6049 return "DW_CFA_offset_extended_sf";
6050 case DW_CFA_def_cfa_sf
:
6051 return "DW_CFA_def_cfa_sf";
6052 case DW_CFA_def_cfa_offset_sf
:
6053 return "DW_CFA_def_cfa_offset_sf";
6055 /* SGI/MIPS specific */
6056 case DW_CFA_MIPS_advance_loc8
:
6057 return "DW_CFA_MIPS_advance_loc8";
6059 /* GNU extensions */
6060 case DW_CFA_GNU_window_save
:
6061 return "DW_CFA_GNU_window_save";
6062 case DW_CFA_GNU_args_size
:
6063 return "DW_CFA_GNU_args_size";
6064 case DW_CFA_GNU_negative_offset_extended
:
6065 return "DW_CFA_GNU_negative_offset_extended";
6068 return "DW_CFA_<unknown>";
6074 dump_die (struct die_info
*die
)
6078 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
6079 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
6080 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
6081 dwarf_bool_name (die
->has_children
));
6083 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
6084 for (i
= 0; i
< die
->num_attrs
; ++i
)
6086 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
6087 dwarf_attr_name (die
->attrs
[i
].name
),
6088 dwarf_form_name (die
->attrs
[i
].form
));
6089 switch (die
->attrs
[i
].form
)
6091 case DW_FORM_ref_addr
:
6093 fprintf_unfiltered (gdb_stderr
, "address: ");
6094 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
6096 case DW_FORM_block2
:
6097 case DW_FORM_block4
:
6099 case DW_FORM_block1
:
6100 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
6111 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
6113 case DW_FORM_string
:
6115 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
6116 DW_STRING (&die
->attrs
[i
])
6117 ? DW_STRING (&die
->attrs
[i
]) : "");
6120 if (DW_UNSND (&die
->attrs
[i
]))
6121 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
6123 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
6125 case DW_FORM_indirect
:
6126 /* the reader will have reduced the indirect form to
6127 the "base form" so this form should not occur */
6128 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
6131 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
6132 die
->attrs
[i
].form
);
6134 fprintf_unfiltered (gdb_stderr
, "\n");
6139 dump_die_list (struct die_info
*die
)
6149 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
6152 struct die_info
*old
;
6154 h
= (offset
% REF_HASH_SIZE
);
6155 old
= die_ref_table
[h
];
6156 die
->next_ref
= old
;
6157 die_ref_table
[h
] = die
;
6162 dwarf2_empty_hash_tables (void)
6164 memset (die_ref_table
, 0, sizeof (die_ref_table
));
6168 dwarf2_get_ref_die_offset (struct attribute
*attr
)
6170 unsigned int result
= 0;
6174 case DW_FORM_ref_addr
:
6175 result
= DW_ADDR (attr
);
6181 case DW_FORM_ref_udata
:
6182 result
= cu_header_offset
+ DW_UNSND (attr
);
6185 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
6190 static struct die_info
*
6191 follow_die_ref (unsigned int offset
)
6193 struct die_info
*die
;
6196 h
= (offset
% REF_HASH_SIZE
);
6197 die
= die_ref_table
[h
];
6200 if (die
->offset
== offset
)
6204 die
= die
->next_ref
;
6209 static struct type
*
6210 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
6212 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
6214 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
6218 /* Look for this particular type in the fundamental type vector. If
6219 one is not found, create and install one appropriate for the
6220 current language and the current target machine. */
6222 if (ftypes
[typeid] == NULL
)
6224 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
6227 return (ftypes
[typeid]);
6230 /* Decode simple location descriptions.
6231 Given a pointer to a dwarf block that defines a location, compute
6232 the location and return the value.
6234 FIXME: This is a kludge until we figure out a better
6235 way to handle the location descriptions.
6236 Gdb's design does not mesh well with the DWARF2 notion of a location
6237 computing interpreter, which is a shame because the flexibility goes unused.
6238 FIXME: Implement more operations as necessary.
6240 A location description containing no operations indicates that the
6241 object is optimized out. The global optimized_out flag is set for
6242 those, the return value is meaningless.
6244 When the result is a register number, the global isreg flag is set,
6245 otherwise it is cleared.
6247 When the result is a base register offset, the global offreg flag is set
6248 and the register number is returned in basereg, otherwise it is cleared.
6250 When the DW_OP_fbreg operation is encountered without a corresponding
6251 DW_AT_frame_base attribute, the global islocal flag is set.
6252 Hopefully the machine dependent code knows how to set up a virtual
6253 frame pointer for the local references.
6255 Note that stack[0] is unused except as a default error return.
6256 Note that stack overflow is not yet handled. */
6259 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
6260 const struct comp_unit_head
*cu_header
)
6263 int size
= blk
->size
;
6264 char *data
= blk
->data
;
6265 CORE_ADDR stack
[64];
6267 unsigned int bytes_read
, unsnd
;
6317 stack
[++stacki
] = op
- DW_OP_lit0
;
6353 stack
[++stacki
] = op
- DW_OP_reg0
;
6358 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6360 stack
[++stacki
] = unsnd
;
6396 basereg
= op
- DW_OP_breg0
;
6397 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6403 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6405 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6410 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6412 if (frame_base_reg
>= 0)
6415 basereg
= frame_base_reg
;
6416 stack
[stacki
] += frame_base_offset
;
6420 complain (&dwarf2_missing_at_frame_base
);
6426 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
6427 cu_header
, &bytes_read
);
6432 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
6437 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
6442 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
6447 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
6452 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
6457 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
6462 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
6468 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6473 stack
[stacki
+ 1] = stack
[stacki
];
6478 stack
[stacki
- 1] += stack
[stacki
];
6482 case DW_OP_plus_uconst
:
6483 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6488 stack
[stacki
- 1] -= stack
[stacki
];
6494 /* If we're not the last op, then we definitely can't encode
6495 this using GDB's address_class enum. */
6497 complain (&dwarf2_complex_location_expr
);
6501 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
6502 return (stack
[stacki
]);
6505 return (stack
[stacki
]);
6508 /* memory allocation interface */
6512 dwarf2_free_tmp_obstack (PTR ignore
)
6514 obstack_free (&dwarf2_tmp_obstack
, NULL
);
6517 static struct dwarf_block
*
6518 dwarf_alloc_block (void)
6520 struct dwarf_block
*blk
;
6522 blk
= (struct dwarf_block
*)
6523 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
6527 static struct abbrev_info
*
6528 dwarf_alloc_abbrev (void)
6530 struct abbrev_info
*abbrev
;
6532 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
6533 memset (abbrev
, 0, sizeof (struct abbrev_info
));
6537 static struct die_info
*
6538 dwarf_alloc_die (void)
6540 struct die_info
*die
;
6542 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6543 memset (die
, 0, sizeof (struct die_info
));
6548 /* Macro support. */
6551 /* Return the full name of file number I in *LH's file name table.
6552 Use COMP_DIR as the name of the current directory of the
6553 compilation. The result is allocated using xmalloc; the caller is
6554 responsible for freeing it. */
6556 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
6558 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
6560 if (IS_ABSOLUTE_PATH (fe
->name
))
6561 return xstrdup (fe
->name
);
6569 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6575 dir_len
= strlen (dir
);
6576 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
6577 strcpy (full_name
, dir
);
6578 full_name
[dir_len
] = '/';
6579 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
6583 return xstrdup (fe
->name
);
6588 static struct macro_source_file
*
6589 macro_start_file (int file
, int line
,
6590 struct macro_source_file
*current_file
,
6591 const char *comp_dir
,
6592 struct line_header
*lh
, struct objfile
*objfile
)
6594 /* The full name of this source file. */
6595 char *full_name
= file_full_name (file
, lh
, comp_dir
);
6597 /* We don't create a macro table for this compilation unit
6598 at all until we actually get a filename. */
6599 if (! pending_macros
)
6600 pending_macros
= new_macro_table (&objfile
->symbol_obstack
,
6601 objfile
->macro_cache
);
6604 /* If we have no current file, then this must be the start_file
6605 directive for the compilation unit's main source file. */
6606 current_file
= macro_set_main (pending_macros
, full_name
);
6608 current_file
= macro_include (current_file
, line
, full_name
);
6612 return current_file
;
6616 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
6617 followed by a null byte. */
6619 copy_string (const char *buf
, int len
)
6621 char *s
= xmalloc (len
+ 1);
6622 memcpy (s
, buf
, len
);
6630 consume_improper_spaces (const char *p
, const char *body
)
6634 complain (&dwarf2_macro_spaces_in_definition
, body
);
6645 parse_macro_definition (struct macro_source_file
*file
, int line
,
6650 /* The body string takes one of two forms. For object-like macro
6651 definitions, it should be:
6653 <macro name> " " <definition>
6655 For function-like macro definitions, it should be:
6657 <macro name> "() " <definition>
6659 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
6661 Spaces may appear only where explicitly indicated, and in the
6664 The Dwarf 2 spec says that an object-like macro's name is always
6665 followed by a space, but versions of GCC around March 2002 omit
6666 the space when the macro's definition is the empty string.
6668 The Dwarf 2 spec says that there should be no spaces between the
6669 formal arguments in a function-like macro's formal argument list,
6670 but versions of GCC around March 2002 include spaces after the
6674 /* Find the extent of the macro name. The macro name is terminated
6675 by either a space or null character (for an object-like macro) or
6676 an opening paren (for a function-like macro). */
6677 for (p
= body
; *p
; p
++)
6678 if (*p
== ' ' || *p
== '(')
6681 if (*p
== ' ' || *p
== '\0')
6683 /* It's an object-like macro. */
6684 int name_len
= p
- body
;
6685 char *name
= copy_string (body
, name_len
);
6686 const char *replacement
;
6689 replacement
= body
+ name_len
+ 1;
6692 complain (&dwarf2_macro_malformed_definition
, body
);
6693 replacement
= body
+ name_len
;
6696 macro_define_object (file
, line
, name
, replacement
);
6702 /* It's a function-like macro. */
6703 char *name
= copy_string (body
, p
- body
);
6706 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
6710 p
= consume_improper_spaces (p
, body
);
6712 /* Parse the formal argument list. */
6713 while (*p
&& *p
!= ')')
6715 /* Find the extent of the current argument name. */
6716 const char *arg_start
= p
;
6718 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
6721 if (! *p
|| p
== arg_start
)
6722 complain (&dwarf2_macro_malformed_definition
,
6726 /* Make sure argv has room for the new argument. */
6727 if (argc
>= argv_size
)
6730 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
6733 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
6736 p
= consume_improper_spaces (p
, body
);
6738 /* Consume the comma, if present. */
6743 p
= consume_improper_spaces (p
, body
);
6752 /* Perfectly formed definition, no complaints. */
6753 macro_define_function (file
, line
, name
,
6754 argc
, (const char **) argv
,
6756 else if (*p
== '\0')
6758 /* Complain, but do define it. */
6759 complain (&dwarf2_macro_malformed_definition
, body
);
6760 macro_define_function (file
, line
, name
,
6761 argc
, (const char **) argv
,
6765 /* Just complain. */
6766 complain (&dwarf2_macro_malformed_definition
, body
);
6769 /* Just complain. */
6770 complain (&dwarf2_macro_malformed_definition
, body
);
6776 for (i
= 0; i
< argc
; i
++)
6782 complain (&dwarf2_macro_malformed_definition
, body
);
6787 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
6788 char *comp_dir
, bfd
*abfd
,
6789 const struct comp_unit_head
*cu_header
,
6790 struct objfile
*objfile
)
6792 char *mac_ptr
, *mac_end
;
6793 struct macro_source_file
*current_file
= 0;
6795 if (dwarf_macinfo_buffer
== NULL
)
6797 complain (&dwarf2_missing_macinfo_section
);
6801 mac_ptr
= dwarf_macinfo_buffer
+ offset
;
6802 mac_end
= dwarf_macinfo_buffer
+ dwarf_macinfo_size
;
6806 enum dwarf_macinfo_record_type macinfo_type
;
6808 /* Do we at least have room for a macinfo type byte? */
6809 if (mac_ptr
>= mac_end
)
6811 complain (&dwarf2_macros_too_long
);
6815 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
6818 switch (macinfo_type
)
6820 /* A zero macinfo type indicates the end of the macro
6825 case DW_MACINFO_define
:
6826 case DW_MACINFO_undef
:
6832 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
6833 mac_ptr
+= bytes_read
;
6834 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
6835 mac_ptr
+= bytes_read
;
6838 complain (&dwarf2_macro_outside_file
,
6839 macinfo_type
== DW_MACINFO_define
? "definition" :
6840 macinfo_type
== DW_MACINFO_undef
? "undefinition" :
6841 "something-or-other",
6845 if (macinfo_type
== DW_MACINFO_define
)
6846 parse_macro_definition (current_file
, line
, body
);
6847 else if (macinfo_type
== DW_MACINFO_undef
)
6848 macro_undef (current_file
, line
, body
);
6853 case DW_MACINFO_start_file
:
6858 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
6859 mac_ptr
+= bytes_read
;
6860 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
6861 mac_ptr
+= bytes_read
;
6863 current_file
= macro_start_file (file
, line
,
6864 current_file
, comp_dir
,
6869 case DW_MACINFO_end_file
:
6871 complain (&dwarf2_macro_unmatched_end_file
);
6874 current_file
= current_file
->included_by
;
6877 enum dwarf_macinfo_record_type next_type
;
6879 /* GCC circa March 2002 doesn't produce the zero
6880 type byte marking the end of the compilation
6881 unit. Complain if it's not there, but exit no
6884 /* Do we at least have room for a macinfo type byte? */
6885 if (mac_ptr
>= mac_end
)
6887 complain (&dwarf2_macros_too_long
);
6891 /* We don't increment mac_ptr here, so this is just
6893 next_type
= read_1_byte (abfd
, mac_ptr
);
6895 complain (&dwarf2_macros_not_terminated
);
6902 case DW_MACINFO_vendor_ext
:
6908 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
6909 mac_ptr
+= bytes_read
;
6910 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
6911 mac_ptr
+= bytes_read
;
6913 /* We don't recognize any vendor extensions. */
6920 /* Check if the attribute's form is a DW_FORM_block*
6921 if so return true else false. */
6923 attr_form_is_block (struct attribute
*attr
)
6925 return (attr
== NULL
? 0 :
6926 attr
->form
== DW_FORM_block1
6927 || attr
->form
== DW_FORM_block2
6928 || attr
->form
== DW_FORM_block4
6929 || attr
->form
== DW_FORM_block
);