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
662 /* local function prototypes */
664 static void dwarf2_locate_sections (bfd
*, asection
*, PTR
);
667 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
670 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
672 static char *scan_partial_symbols (char *, struct objfile
*,
673 CORE_ADDR
*, CORE_ADDR
*,
674 const struct comp_unit_head
*);
676 static void add_partial_symbol (struct partial_die_info
*, struct objfile
*,
677 const struct comp_unit_head
*);
679 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
681 static void psymtab_to_symtab_1 (struct partial_symtab
*);
683 char *dwarf2_read_section (struct objfile
*, file_ptr
, unsigned int);
685 static void dwarf2_read_abbrevs (bfd
*, unsigned int);
687 static void dwarf2_empty_abbrev_table (PTR
);
689 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int);
691 static char *read_partial_die (struct partial_die_info
*,
693 const struct comp_unit_head
*);
695 static char *read_full_die (struct die_info
**, bfd
*, char *,
696 const struct comp_unit_head
*);
698 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
699 bfd
*, char *, const struct comp_unit_head
*);
701 static char *read_attribute_value (struct attribute
*, unsigned,
702 bfd
*, char *, const struct comp_unit_head
*);
704 static unsigned int read_1_byte (bfd
*, char *);
706 static int read_1_signed_byte (bfd
*, char *);
708 static unsigned int read_2_bytes (bfd
*, char *);
710 static unsigned int read_4_bytes (bfd
*, char *);
712 static unsigned long read_8_bytes (bfd
*, char *);
714 static CORE_ADDR
read_address (bfd
*, char *ptr
, const struct comp_unit_head
*,
717 static LONGEST
read_initial_length (bfd
*, char *,
718 struct comp_unit_head
*, int *bytes_read
);
720 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
723 static char *read_n_bytes (bfd
*, char *, unsigned int);
725 static char *read_string (bfd
*, char *, unsigned int *);
727 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
730 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
732 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
734 static void set_cu_language (unsigned int);
736 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
738 static int die_is_declaration (struct die_info
*);
740 static void free_line_header (struct line_header
*lh
);
742 static struct line_header
*(dwarf_decode_line_header
743 (unsigned int offset
,
745 const struct comp_unit_head
*cu_header
));
747 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
748 const struct comp_unit_head
*);
750 static void dwarf2_start_subfile (char *, char *);
752 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
753 struct objfile
*, const struct comp_unit_head
*);
755 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
756 struct objfile
*, const struct comp_unit_head
*);
758 static void dwarf2_const_value_data (struct attribute
*attr
,
762 static struct type
*die_type (struct die_info
*, struct objfile
*,
763 const struct comp_unit_head
*);
765 static struct type
*die_containing_type (struct die_info
*, struct objfile
*,
766 const struct comp_unit_head
*);
769 static struct type
*type_at_offset (unsigned int, struct objfile
*);
772 static struct type
*tag_type_to_type (struct die_info
*, struct objfile
*,
773 const struct comp_unit_head
*);
775 static void read_type_die (struct die_info
*, struct objfile
*,
776 const struct comp_unit_head
*);
778 static void read_typedef (struct die_info
*, struct objfile
*,
779 const struct comp_unit_head
*);
781 static void read_base_type (struct die_info
*, struct objfile
*);
783 static void read_file_scope (struct die_info
*, struct objfile
*,
784 const struct comp_unit_head
*);
786 static void read_func_scope (struct die_info
*, struct objfile
*,
787 const struct comp_unit_head
*);
789 static void read_lexical_block_scope (struct die_info
*, struct objfile
*,
790 const struct comp_unit_head
*);
792 static int dwarf2_get_pc_bounds (struct die_info
*,
793 CORE_ADDR
*, CORE_ADDR
*, struct objfile
*);
795 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
796 struct objfile
*, const struct comp_unit_head
*);
798 static void dwarf2_attach_fields_to_type (struct field_info
*,
799 struct type
*, struct objfile
*);
801 static void dwarf2_add_member_fn (struct field_info
*,
802 struct die_info
*, struct type
*,
803 struct objfile
*objfile
,
804 const struct comp_unit_head
*);
806 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
807 struct type
*, struct objfile
*);
809 static void read_structure_scope (struct die_info
*, struct objfile
*,
810 const struct comp_unit_head
*);
812 static void read_common_block (struct die_info
*, struct objfile
*,
813 const struct comp_unit_head
*);
815 static void read_enumeration (struct die_info
*, struct objfile
*,
816 const struct comp_unit_head
*);
818 static struct type
*dwarf_base_type (int, int, struct objfile
*);
820 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct objfile
*,
821 const struct comp_unit_head
*);
823 static void read_array_type (struct die_info
*, struct objfile
*,
824 const struct comp_unit_head
*);
826 static void read_tag_pointer_type (struct die_info
*, struct objfile
*,
827 const struct comp_unit_head
*);
829 static void read_tag_ptr_to_member_type (struct die_info
*, struct objfile
*,
830 const struct comp_unit_head
*);
832 static void read_tag_reference_type (struct die_info
*, struct objfile
*,
833 const struct comp_unit_head
*);
835 static void read_tag_const_type (struct die_info
*, struct objfile
*,
836 const struct comp_unit_head
*);
838 static void read_tag_volatile_type (struct die_info
*, struct objfile
*,
839 const struct comp_unit_head
*);
841 static void read_tag_string_type (struct die_info
*, struct objfile
*);
843 static void read_subroutine_type (struct die_info
*, struct objfile
*,
844 const struct comp_unit_head
*);
846 static struct die_info
*read_comp_unit (char *, bfd
*,
847 const struct comp_unit_head
*);
849 static void free_die_list (struct die_info
*);
851 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
853 static void process_die (struct die_info
*, struct objfile
*,
854 const struct comp_unit_head
*);
856 static char *dwarf2_linkage_name (struct die_info
*);
858 static char *dwarf_tag_name (unsigned int);
860 static char *dwarf_attr_name (unsigned int);
862 static char *dwarf_form_name (unsigned int);
864 static char *dwarf_stack_op_name (unsigned int);
866 static char *dwarf_bool_name (unsigned int);
868 static char *dwarf_type_encoding_name (unsigned int);
871 static char *dwarf_cfi_name (unsigned int);
873 struct die_info
*copy_die (struct die_info
*);
876 static struct die_info
*sibling_die (struct die_info
*);
878 static void dump_die (struct die_info
*);
880 static void dump_die_list (struct die_info
*);
882 static void store_in_ref_table (unsigned int, struct die_info
*);
884 static void dwarf2_empty_hash_tables (void);
886 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
888 static struct die_info
*follow_die_ref (unsigned int);
890 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
892 /* memory allocation interface */
894 static void dwarf2_free_tmp_obstack (PTR
);
896 static struct dwarf_block
*dwarf_alloc_block (void);
898 static struct abbrev_info
*dwarf_alloc_abbrev (void);
900 static struct die_info
*dwarf_alloc_die (void);
902 static void initialize_cu_func_list (void);
904 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
);
906 static void dwarf_decode_macros (struct line_header
*, unsigned int,
907 char *, bfd
*, const struct comp_unit_head
*,
910 /* Try to locate the sections we need for DWARF 2 debugging
911 information and return true if we have enough to do something. */
914 dwarf2_has_info (bfd
*abfd
)
916 dwarf_info_offset
= 0;
917 dwarf_abbrev_offset
= 0;
918 dwarf_line_offset
= 0;
919 dwarf_str_offset
= 0;
920 dwarf_macinfo_offset
= 0;
921 dwarf_frame_offset
= 0;
922 dwarf_eh_frame_offset
= 0;
923 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
924 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
934 /* This function is mapped across the sections and remembers the
935 offset and size of each of the debugging sections we are interested
939 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, PTR ignore_ptr
)
941 if (STREQ (sectp
->name
, INFO_SECTION
))
943 dwarf_info_offset
= sectp
->filepos
;
944 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
946 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
948 dwarf_abbrev_offset
= sectp
->filepos
;
949 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
951 else if (STREQ (sectp
->name
, LINE_SECTION
))
953 dwarf_line_offset
= sectp
->filepos
;
954 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
956 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
958 dwarf_pubnames_offset
= sectp
->filepos
;
959 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
961 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
963 dwarf_aranges_offset
= sectp
->filepos
;
964 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
966 else if (STREQ (sectp
->name
, LOC_SECTION
))
968 dwarf_loc_offset
= sectp
->filepos
;
969 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
971 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
973 dwarf_macinfo_offset
= sectp
->filepos
;
974 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
976 else if (STREQ (sectp
->name
, STR_SECTION
))
978 dwarf_str_offset
= sectp
->filepos
;
979 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
981 else if (STREQ (sectp
->name
, FRAME_SECTION
))
983 dwarf_frame_offset
= sectp
->filepos
;
984 dwarf_frame_size
= bfd_get_section_size_before_reloc (sectp
);
986 else if (STREQ (sectp
->name
, EH_FRAME_SECTION
))
988 dwarf_eh_frame_offset
= sectp
->filepos
;
989 dwarf_eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
993 /* Build a partial symbol table. */
996 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
999 /* We definitely need the .debug_info and .debug_abbrev sections */
1001 dwarf_info_buffer
= dwarf2_read_section (objfile
,
1004 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
1005 dwarf_abbrev_offset
,
1007 dwarf_line_buffer
= dwarf2_read_section (objfile
,
1011 if (dwarf_str_offset
)
1012 dwarf_str_buffer
= dwarf2_read_section (objfile
,
1016 dwarf_str_buffer
= NULL
;
1018 if (dwarf_macinfo_offset
)
1019 dwarf_macinfo_buffer
= dwarf2_read_section (objfile
,
1020 dwarf_macinfo_offset
,
1021 dwarf_macinfo_size
);
1023 dwarf_macinfo_buffer
= NULL
;
1026 || (objfile
->global_psymbols
.size
== 0
1027 && objfile
->static_psymbols
.size
== 0))
1029 init_psymbol_list (objfile
, 1024);
1033 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1035 /* Things are significantly easier if we have .debug_aranges and
1036 .debug_pubnames sections */
1038 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1042 /* only test this case for now */
1044 /* In this case we have to work a bit harder */
1045 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1050 /* Build the partial symbol table from the information in the
1051 .debug_pubnames and .debug_aranges sections. */
1054 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1056 bfd
*abfd
= objfile
->obfd
;
1057 char *aranges_buffer
, *pubnames_buffer
;
1058 char *aranges_ptr
, *pubnames_ptr
;
1059 unsigned int entry_length
, version
, info_offset
, info_size
;
1061 pubnames_buffer
= dwarf2_read_section (objfile
,
1062 dwarf_pubnames_offset
,
1063 dwarf_pubnames_size
);
1064 pubnames_ptr
= pubnames_buffer
;
1065 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
1067 struct comp_unit_head cu_header
;
1070 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1072 pubnames_ptr
+= bytes_read
;
1073 version
= read_1_byte (abfd
, pubnames_ptr
);
1075 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1077 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1081 aranges_buffer
= dwarf2_read_section (objfile
,
1082 dwarf_aranges_offset
,
1083 dwarf_aranges_size
);
1088 /* Read in the comp unit header information from the debug_info at
1092 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1093 char *info_ptr
, bfd
*abfd
)
1097 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1099 info_ptr
+= bytes_read
;
1100 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1102 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1104 info_ptr
+= bytes_read
;
1105 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1107 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1108 if (signed_addr
< 0)
1109 internal_error (__FILE__
, __LINE__
,
1110 "read_comp_unit_head: dwarf from non elf file");
1111 cu_header
->signed_addr_p
= signed_addr
;
1115 /* Build the partial symbol table by doing a quick pass through the
1116 .debug_info and .debug_abbrev sections. */
1119 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1121 /* Instead of reading this into a big buffer, we should probably use
1122 mmap() on architectures that support it. (FIXME) */
1123 bfd
*abfd
= objfile
->obfd
;
1124 char *info_ptr
, *abbrev_ptr
;
1125 char *beg_of_comp_unit
;
1126 struct partial_die_info comp_unit_die
;
1127 struct partial_symtab
*pst
;
1128 struct cleanup
*back_to
;
1129 CORE_ADDR lowpc
, highpc
;
1131 info_ptr
= dwarf_info_buffer
;
1132 abbrev_ptr
= dwarf_abbrev_buffer
;
1134 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1135 the partial symbol scan, like attribute values.
1137 We could reduce our peak memory consumption during partial symbol
1138 table construction by freeing stuff from this obstack more often
1139 --- say, after processing each compilation unit, or each die ---
1140 but it turns out that this saves almost nothing. For an
1141 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1142 on dwarf2_tmp_obstack. Some investigation showed:
1144 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1145 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1146 all fixed-length values not requiring dynamic allocation.
1148 2) 30% of the attributes used the form DW_FORM_string. For
1149 DW_FORM_string, read_attribute simply hands back a pointer to
1150 the null-terminated string in dwarf_info_buffer, so no dynamic
1151 allocation is needed there either.
1153 3) The remaining 1% of the attributes all used DW_FORM_block1.
1154 75% of those were DW_AT_frame_base location lists for
1155 functions; the rest were DW_AT_location attributes, probably
1156 for the global variables.
1158 Anyway, what this all means is that the memory the dwarf2
1159 reader uses as temporary space reading partial symbols is about
1160 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1162 obstack_init (&dwarf2_tmp_obstack
);
1163 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1165 /* Since the objects we're extracting from dwarf_info_buffer vary in
1166 length, only the individual functions to extract them (like
1167 read_comp_unit_head and read_partial_die) can really know whether
1168 the buffer is large enough to hold another complete object.
1170 At the moment, they don't actually check that. If
1171 dwarf_info_buffer holds just one extra byte after the last
1172 compilation unit's dies, then read_comp_unit_head will happily
1173 read off the end of the buffer. read_partial_die is similarly
1174 casual. Those functions should be fixed.
1176 For this loop condition, simply checking whether there's any data
1177 left at all should be sufficient. */
1178 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1180 struct comp_unit_head cu_header
;
1181 beg_of_comp_unit
= info_ptr
;
1182 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1184 if (cu_header
.version
!= 2)
1186 error ("Dwarf Error: wrong version in compilation unit header.");
1189 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
1191 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
1192 (long) cu_header
.abbrev_offset
,
1193 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1196 if (beg_of_comp_unit
+ cu_header
.length
+ cu_header
.initial_length_size
1197 > dwarf_info_buffer
+ dwarf_info_size
)
1199 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
1200 (long) cu_header
.length
,
1201 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1204 /* Read the abbrevs for this compilation unit into a table */
1205 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1206 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1208 /* Read the compilation unit die */
1209 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1212 /* Set the language we're debugging */
1213 set_cu_language (comp_unit_die
.language
);
1215 /* Allocate a new partial symbol table structure */
1216 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1217 comp_unit_die
.name
? comp_unit_die
.name
: "",
1218 comp_unit_die
.lowpc
,
1219 objfile
->global_psymbols
.next
,
1220 objfile
->static_psymbols
.next
);
1222 pst
->read_symtab_private
= (char *)
1223 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1224 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1225 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1226 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1227 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1228 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1229 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1230 DWARF_LINE_SIZE (pst
) = dwarf_line_size
;
1231 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1232 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1233 DWARF_MACINFO_BUFFER (pst
) = dwarf_macinfo_buffer
;
1234 DWARF_MACINFO_SIZE (pst
) = dwarf_macinfo_size
;
1235 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1237 /* Store the function that reads in the rest of the symbol table */
1238 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1240 /* Check if comp unit has_children.
1241 If so, read the rest of the partial symbols from this comp unit.
1242 If not, there's no more debug_info for this comp unit. */
1243 if (comp_unit_die
.has_children
)
1245 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
,
1248 /* If the compilation unit didn't have an explicit address range,
1249 then use the information extracted from its child dies. */
1250 if (! comp_unit_die
.has_pc_info
)
1252 comp_unit_die
.lowpc
= lowpc
;
1253 comp_unit_die
.highpc
= highpc
;
1256 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1257 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1259 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1260 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1261 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1262 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1263 sort_pst_symbols (pst
);
1265 /* If there is already a psymtab or symtab for a file of this
1266 name, remove it. (If there is a symtab, more drastic things
1267 also happen.) This happens in VxWorks. */
1268 free_named_symtabs (pst
->filename
);
1270 info_ptr
= beg_of_comp_unit
+ cu_header
.length
1271 + cu_header
.initial_length_size
;
1273 do_cleanups (back_to
);
1276 /* Read in all interesting dies to the end of the compilation unit. */
1279 scan_partial_symbols (char *info_ptr
, struct objfile
*objfile
,
1280 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1281 const struct comp_unit_head
*cu_header
)
1283 bfd
*abfd
= objfile
->obfd
;
1284 struct partial_die_info pdi
;
1286 /* This function is called after we've read in the comp_unit_die in
1287 order to read its children. We start the nesting level at 1 since
1288 we have pushed 1 level down in order to read the comp unit's children.
1289 The comp unit itself is at level 0, so we stop reading when we pop
1290 back to that level. */
1292 int nesting_level
= 1;
1294 *lowpc
= ((CORE_ADDR
) -1);
1295 *highpc
= ((CORE_ADDR
) 0);
1297 while (nesting_level
)
1299 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu_header
);
1305 case DW_TAG_subprogram
:
1306 if (pdi
.has_pc_info
)
1308 if (pdi
.lowpc
< *lowpc
)
1312 if (pdi
.highpc
> *highpc
)
1314 *highpc
= pdi
.highpc
;
1316 if ((pdi
.is_external
|| nesting_level
== 1)
1317 && !pdi
.is_declaration
)
1319 add_partial_symbol (&pdi
, objfile
, cu_header
);
1323 case DW_TAG_variable
:
1324 case DW_TAG_typedef
:
1325 case DW_TAG_class_type
:
1326 case DW_TAG_structure_type
:
1327 case DW_TAG_union_type
:
1328 case DW_TAG_enumeration_type
:
1329 if ((pdi
.is_external
|| nesting_level
== 1)
1330 && !pdi
.is_declaration
)
1332 add_partial_symbol (&pdi
, objfile
, cu_header
);
1335 case DW_TAG_enumerator
:
1336 /* File scope enumerators are added to the partial symbol
1338 if (nesting_level
== 2)
1339 add_partial_symbol (&pdi
, objfile
, cu_header
);
1341 case DW_TAG_base_type
:
1342 /* File scope base type definitions are added to the partial
1344 if (nesting_level
== 1)
1345 add_partial_symbol (&pdi
, objfile
, cu_header
);
1352 /* If the die has a sibling, skip to the sibling.
1353 Do not skip enumeration types, we want to record their
1355 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1357 info_ptr
= pdi
.sibling
;
1359 else if (pdi
.has_children
)
1361 /* Die has children, but the optional DW_AT_sibling attribute
1372 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1373 from `maint check'. */
1374 if (*lowpc
== ((CORE_ADDR
) -1))
1380 add_partial_symbol (struct partial_die_info
*pdi
, struct objfile
*objfile
,
1381 const struct comp_unit_head
*cu_header
)
1387 case DW_TAG_subprogram
:
1388 if (pdi
->is_external
)
1390 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1391 mst_text, objfile); */
1392 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1393 VAR_NAMESPACE
, LOC_BLOCK
,
1394 &objfile
->global_psymbols
,
1395 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1399 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1400 mst_file_text, objfile); */
1401 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1402 VAR_NAMESPACE
, LOC_BLOCK
,
1403 &objfile
->static_psymbols
,
1404 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1407 case DW_TAG_variable
:
1408 if (pdi
->is_external
)
1411 Don't enter into the minimal symbol tables as there is
1412 a minimal symbol table entry from the ELF symbols already.
1413 Enter into partial symbol table if it has a location
1414 descriptor or a type.
1415 If the location descriptor is missing, new_symbol will create
1416 a LOC_UNRESOLVED symbol, the address of the variable will then
1417 be determined from the minimal symbol table whenever the variable
1419 The address for the partial symbol table entry is not
1420 used by GDB, but it comes in handy for debugging partial symbol
1424 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1425 if (pdi
->locdesc
|| pdi
->has_type
)
1426 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1427 VAR_NAMESPACE
, LOC_STATIC
,
1428 &objfile
->global_psymbols
,
1429 0, addr
+ baseaddr
, cu_language
, objfile
);
1433 /* Static Variable. Skip symbols without location descriptors. */
1434 if (pdi
->locdesc
== NULL
)
1436 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1437 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1438 mst_file_data, objfile); */
1439 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1440 VAR_NAMESPACE
, LOC_STATIC
,
1441 &objfile
->static_psymbols
,
1442 0, addr
+ baseaddr
, cu_language
, objfile
);
1445 case DW_TAG_typedef
:
1446 case DW_TAG_base_type
:
1447 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1448 VAR_NAMESPACE
, LOC_TYPEDEF
,
1449 &objfile
->static_psymbols
,
1450 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1452 case DW_TAG_class_type
:
1453 case DW_TAG_structure_type
:
1454 case DW_TAG_union_type
:
1455 case DW_TAG_enumeration_type
:
1456 /* Skip aggregate types without children, these are external
1458 if (pdi
->has_children
== 0)
1460 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1461 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1462 &objfile
->static_psymbols
,
1463 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1465 if (cu_language
== language_cplus
)
1467 /* For C++, these implicitly act as typedefs as well. */
1468 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1469 VAR_NAMESPACE
, LOC_TYPEDEF
,
1470 &objfile
->static_psymbols
,
1471 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1474 case DW_TAG_enumerator
:
1475 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1476 VAR_NAMESPACE
, LOC_CONST
,
1477 &objfile
->static_psymbols
,
1478 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1485 /* Expand this partial symbol table into a full symbol table. */
1488 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1490 /* FIXME: This is barely more than a stub. */
1495 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1501 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1502 gdb_flush (gdb_stdout
);
1505 psymtab_to_symtab_1 (pst
);
1507 /* Finish up the debug error message. */
1509 printf_filtered ("done.\n");
1515 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1517 struct objfile
*objfile
= pst
->objfile
;
1518 bfd
*abfd
= objfile
->obfd
;
1519 struct comp_unit_head cu_header
;
1520 struct die_info
*dies
;
1521 unsigned long offset
;
1522 CORE_ADDR lowpc
, highpc
;
1523 struct die_info
*child_die
;
1525 struct symtab
*symtab
;
1526 struct cleanup
*back_to
;
1528 /* Set local variables from the partial symbol table info. */
1529 offset
= DWARF_INFO_OFFSET (pst
);
1530 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1531 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1532 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1533 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1534 dwarf_line_size
= DWARF_LINE_SIZE (pst
);
1535 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1536 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1537 dwarf_macinfo_buffer
= DWARF_MACINFO_BUFFER (pst
);
1538 dwarf_macinfo_size
= DWARF_MACINFO_SIZE (pst
);
1539 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1540 cu_header_offset
= offset
;
1541 info_ptr
= dwarf_info_buffer
+ offset
;
1543 obstack_init (&dwarf2_tmp_obstack
);
1544 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1547 make_cleanup (really_free_pendings
, NULL
);
1549 /* read in the comp_unit header */
1550 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1552 /* Read the abbrevs for this compilation unit */
1553 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1554 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1556 dies
= read_comp_unit (info_ptr
, abfd
, &cu_header
);
1558 make_cleanup_free_die_list (dies
);
1560 /* Do line number decoding in read_file_scope () */
1561 process_die (dies
, objfile
, &cu_header
);
1563 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1565 /* Some compilers don't define a DW_AT_high_pc attribute for
1566 the compilation unit. If the DW_AT_high_pc is missing,
1567 synthesize it, by scanning the DIE's below the compilation unit. */
1569 if (dies
->has_children
)
1571 child_die
= dies
->next
;
1572 while (child_die
&& child_die
->tag
)
1574 if (child_die
->tag
== DW_TAG_subprogram
)
1576 CORE_ADDR low
, high
;
1578 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1580 highpc
= max (highpc
, high
);
1583 child_die
= sibling_die (child_die
);
1587 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1589 /* Set symtab language to language from DW_AT_language.
1590 If the compilation is from a C file generated by language preprocessors,
1591 do not set the language if it was already deduced by start_subfile. */
1593 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1595 symtab
->language
= cu_language
;
1597 pst
->symtab
= symtab
;
1599 sort_symtab_syms (pst
->symtab
);
1601 do_cleanups (back_to
);
1604 /* Process a die and its children. */
1607 process_die (struct die_info
*die
, struct objfile
*objfile
,
1608 const struct comp_unit_head
*cu_header
)
1612 case DW_TAG_padding
:
1614 case DW_TAG_compile_unit
:
1615 read_file_scope (die
, objfile
, cu_header
);
1617 case DW_TAG_subprogram
:
1618 read_subroutine_type (die
, objfile
, cu_header
);
1619 read_func_scope (die
, objfile
, cu_header
);
1621 case DW_TAG_inlined_subroutine
:
1622 /* FIXME: These are ignored for now.
1623 They could be used to set breakpoints on all inlined instances
1624 of a function and make GDB `next' properly over inlined functions. */
1626 case DW_TAG_lexical_block
:
1627 read_lexical_block_scope (die
, objfile
, cu_header
);
1629 case DW_TAG_class_type
:
1630 case DW_TAG_structure_type
:
1631 case DW_TAG_union_type
:
1632 read_structure_scope (die
, objfile
, cu_header
);
1634 case DW_TAG_enumeration_type
:
1635 read_enumeration (die
, objfile
, cu_header
);
1637 case DW_TAG_subroutine_type
:
1638 read_subroutine_type (die
, objfile
, cu_header
);
1640 case DW_TAG_array_type
:
1641 read_array_type (die
, objfile
, cu_header
);
1643 case DW_TAG_pointer_type
:
1644 read_tag_pointer_type (die
, objfile
, cu_header
);
1646 case DW_TAG_ptr_to_member_type
:
1647 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
1649 case DW_TAG_reference_type
:
1650 read_tag_reference_type (die
, objfile
, cu_header
);
1652 case DW_TAG_string_type
:
1653 read_tag_string_type (die
, objfile
);
1655 case DW_TAG_base_type
:
1656 read_base_type (die
, objfile
);
1657 if (dwarf_attr (die
, DW_AT_name
))
1659 /* Add a typedef symbol for the base type definition. */
1660 new_symbol (die
, die
->type
, objfile
, cu_header
);
1663 case DW_TAG_common_block
:
1664 read_common_block (die
, objfile
, cu_header
);
1666 case DW_TAG_common_inclusion
:
1669 new_symbol (die
, NULL
, objfile
, cu_header
);
1675 initialize_cu_func_list (void)
1677 cu_first_fn
= cu_last_fn
= cu_cached_fn
= NULL
;
1681 read_file_scope (struct die_info
*die
, struct objfile
*objfile
,
1682 const struct comp_unit_head
*cu_header
)
1684 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
1685 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1686 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1687 struct attribute
*attr
;
1688 char *name
= "<unknown>";
1689 char *comp_dir
= NULL
;
1690 struct die_info
*child_die
;
1691 bfd
*abfd
= objfile
->obfd
;
1692 struct line_header
*line_header
= 0;
1694 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1696 if (die
->has_children
)
1698 child_die
= die
->next
;
1699 while (child_die
&& child_die
->tag
)
1701 if (child_die
->tag
== DW_TAG_subprogram
)
1703 CORE_ADDR low
, high
;
1705 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1707 lowpc
= min (lowpc
, low
);
1708 highpc
= max (highpc
, high
);
1711 child_die
= sibling_die (child_die
);
1716 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1717 from finish_block. */
1718 if (lowpc
== ((CORE_ADDR
) -1))
1723 attr
= dwarf_attr (die
, DW_AT_name
);
1726 name
= DW_STRING (attr
);
1728 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1731 comp_dir
= DW_STRING (attr
);
1734 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1735 directory, get rid of it. */
1736 char *cp
= strchr (comp_dir
, ':');
1738 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1743 if (objfile
->ei
.entry_point
>= lowpc
&&
1744 objfile
->ei
.entry_point
< highpc
)
1746 objfile
->ei
.entry_file_lowpc
= lowpc
;
1747 objfile
->ei
.entry_file_highpc
= highpc
;
1750 attr
= dwarf_attr (die
, DW_AT_language
);
1753 set_cu_language (DW_UNSND (attr
));
1756 /* We assume that we're processing GCC output. */
1757 processing_gcc_compilation
= 2;
1759 /* FIXME:Do something here. */
1760 if (dip
->at_producer
!= NULL
)
1762 handle_producer (dip
->at_producer
);
1766 /* The compilation unit may be in a different language or objfile,
1767 zero out all remembered fundamental types. */
1768 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1770 start_symtab (name
, comp_dir
, lowpc
);
1771 record_debugformat ("DWARF 2");
1773 initialize_cu_func_list ();
1775 /* Process all dies in compilation unit. */
1776 if (die
->has_children
)
1778 child_die
= die
->next
;
1779 while (child_die
&& child_die
->tag
)
1781 process_die (child_die
, objfile
, cu_header
);
1782 child_die
= sibling_die (child_die
);
1786 /* Decode line number information if present. */
1787 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1790 unsigned int line_offset
= DW_UNSND (attr
);
1791 line_header
= dwarf_decode_line_header (line_offset
,
1795 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
1796 (void *) line_header
);
1797 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu_header
);
1801 /* Decode macro information, if present. Dwarf 2 macro information
1802 refers to information in the line number info statement program
1803 header, so we can only read it if we've read the header
1805 attr
= dwarf_attr (die
, DW_AT_macro_info
);
1808 unsigned int macro_offset
= DW_UNSND (attr
);
1809 dwarf_decode_macros (line_header
, macro_offset
,
1810 comp_dir
, abfd
, cu_header
, objfile
);
1812 do_cleanups (back_to
);
1816 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
)
1818 struct function_range
*thisfn
;
1820 thisfn
= (struct function_range
*)
1821 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct function_range
));
1822 thisfn
->name
= name
;
1823 thisfn
->lowpc
= lowpc
;
1824 thisfn
->highpc
= highpc
;
1825 thisfn
->seen_line
= 0;
1826 thisfn
->next
= NULL
;
1828 if (cu_last_fn
== NULL
)
1829 cu_first_fn
= thisfn
;
1831 cu_last_fn
->next
= thisfn
;
1833 cu_last_fn
= thisfn
;
1837 read_func_scope (struct die_info
*die
, struct objfile
*objfile
,
1838 const struct comp_unit_head
*cu_header
)
1840 register struct context_stack
*new;
1843 struct die_info
*child_die
;
1844 struct attribute
*attr
;
1847 name
= dwarf2_linkage_name (die
);
1849 /* Ignore functions with missing or empty names and functions with
1850 missing or invalid low and high pc attributes. */
1851 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1857 /* Record the function range for dwarf_decode_lines. */
1858 add_to_cu_func_list (name
, lowpc
, highpc
);
1860 if (objfile
->ei
.entry_point
>= lowpc
&&
1861 objfile
->ei
.entry_point
< highpc
)
1863 objfile
->ei
.entry_func_lowpc
= lowpc
;
1864 objfile
->ei
.entry_func_highpc
= highpc
;
1867 /* Decode DW_AT_frame_base location descriptor if present, keep result
1868 for DW_OP_fbreg operands in decode_locdesc. */
1869 frame_base_reg
= -1;
1870 frame_base_offset
= 0;
1871 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1874 CORE_ADDR addr
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
1876 complain (&dwarf2_unsupported_at_frame_base
, name
);
1878 frame_base_reg
= addr
;
1881 frame_base_reg
= basereg
;
1882 frame_base_offset
= addr
;
1885 complain (&dwarf2_unsupported_at_frame_base
, name
);
1888 new = push_context (0, lowpc
);
1889 new->name
= new_symbol (die
, die
->type
, objfile
, cu_header
);
1890 list_in_scope
= &local_symbols
;
1892 if (die
->has_children
)
1894 child_die
= die
->next
;
1895 while (child_die
&& child_die
->tag
)
1897 process_die (child_die
, objfile
, cu_header
);
1898 child_die
= sibling_die (child_die
);
1902 new = pop_context ();
1903 /* Make a block for the local symbols within. */
1904 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1905 lowpc
, highpc
, objfile
);
1906 list_in_scope
= &file_symbols
;
1909 /* Process all the DIES contained within a lexical block scope. Start
1910 a new scope, process the dies, and then close the scope. */
1913 read_lexical_block_scope (struct die_info
*die
, struct objfile
*objfile
,
1914 const struct comp_unit_head
*cu_header
)
1916 register struct context_stack
*new;
1917 CORE_ADDR lowpc
, highpc
;
1918 struct die_info
*child_die
;
1920 /* Ignore blocks with missing or invalid low and high pc attributes. */
1921 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1926 push_context (0, lowpc
);
1927 if (die
->has_children
)
1929 child_die
= die
->next
;
1930 while (child_die
&& child_die
->tag
)
1932 process_die (child_die
, objfile
, cu_header
);
1933 child_die
= sibling_die (child_die
);
1936 new = pop_context ();
1938 if (local_symbols
!= NULL
)
1940 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1943 local_symbols
= new->locals
;
1946 /* Get low and high pc attributes from a die.
1947 Return 1 if the attributes are present and valid, otherwise, return 0. */
1950 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1951 struct objfile
*objfile
)
1953 struct attribute
*attr
;
1957 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1959 low
= DW_ADDR (attr
);
1962 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1964 high
= DW_ADDR (attr
);
1971 /* When using the GNU linker, .gnu.linkonce. sections are used to
1972 eliminate duplicate copies of functions and vtables and such.
1973 The linker will arbitrarily choose one and discard the others.
1974 The AT_*_pc values for such functions refer to local labels in
1975 these sections. If the section from that file was discarded, the
1976 labels are not in the output, so the relocs get a value of 0.
1977 If this is a discarded function, mark the pc bounds as invalid,
1978 so that GDB will ignore it. */
1979 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
1987 /* Add an aggregate field to the field list. */
1990 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
1991 struct objfile
*objfile
,
1992 const struct comp_unit_head
*cu_header
)
1994 struct nextfield
*new_field
;
1995 struct attribute
*attr
;
1997 char *fieldname
= "";
1999 /* Allocate a new field list entry and link it in. */
2000 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2001 make_cleanup (xfree
, new_field
);
2002 memset (new_field
, 0, sizeof (struct nextfield
));
2003 new_field
->next
= fip
->fields
;
2004 fip
->fields
= new_field
;
2007 /* Handle accessibility and virtuality of field.
2008 The default accessibility for members is public, the default
2009 accessibility for inheritance is private. */
2010 if (die
->tag
!= DW_TAG_inheritance
)
2011 new_field
->accessibility
= DW_ACCESS_public
;
2013 new_field
->accessibility
= DW_ACCESS_private
;
2014 new_field
->virtuality
= DW_VIRTUALITY_none
;
2016 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2018 new_field
->accessibility
= DW_UNSND (attr
);
2019 if (new_field
->accessibility
!= DW_ACCESS_public
)
2020 fip
->non_public_fields
= 1;
2021 attr
= dwarf_attr (die
, DW_AT_virtuality
);
2023 new_field
->virtuality
= DW_UNSND (attr
);
2025 fp
= &new_field
->field
;
2026 if (die
->tag
== DW_TAG_member
)
2028 /* Get type of field. */
2029 fp
->type
= die_type (die
, objfile
, cu_header
);
2031 /* Get bit size of field (zero if none). */
2032 attr
= dwarf_attr (die
, DW_AT_bit_size
);
2035 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
2039 FIELD_BITSIZE (*fp
) = 0;
2042 /* Get bit offset of field. */
2043 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2046 FIELD_BITPOS (*fp
) =
2047 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) * bits_per_byte
;
2050 FIELD_BITPOS (*fp
) = 0;
2051 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
2054 if (BITS_BIG_ENDIAN
)
2056 /* For big endian bits, the DW_AT_bit_offset gives the
2057 additional bit offset from the MSB of the containing
2058 anonymous object to the MSB of the field. We don't
2059 have to do anything special since we don't need to
2060 know the size of the anonymous object. */
2061 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
2065 /* For little endian bits, compute the bit offset to the
2066 MSB of the anonymous object, subtract off the number of
2067 bits from the MSB of the field to the MSB of the
2068 object, and then subtract off the number of bits of
2069 the field itself. The result is the bit offset of
2070 the LSB of the field. */
2072 int bit_offset
= DW_UNSND (attr
);
2074 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2077 /* The size of the anonymous object containing
2078 the bit field is explicit, so use the
2079 indicated size (in bytes). */
2080 anonymous_size
= DW_UNSND (attr
);
2084 /* The size of the anonymous object containing
2085 the bit field must be inferred from the type
2086 attribute of the data member containing the
2088 anonymous_size
= TYPE_LENGTH (fp
->type
);
2090 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2091 - bit_offset
- FIELD_BITSIZE (*fp
);
2095 /* Get name of field. */
2096 attr
= dwarf_attr (die
, DW_AT_name
);
2097 if (attr
&& DW_STRING (attr
))
2098 fieldname
= DW_STRING (attr
);
2099 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
2100 &objfile
->type_obstack
);
2102 /* Change accessibility for artificial fields (e.g. virtual table
2103 pointer or virtual base class pointer) to private. */
2104 if (dwarf_attr (die
, DW_AT_artificial
))
2106 new_field
->accessibility
= DW_ACCESS_private
;
2107 fip
->non_public_fields
= 1;
2110 else if (die
->tag
== DW_TAG_variable
)
2114 /* C++ static member.
2115 Get name of field. */
2116 attr
= dwarf_attr (die
, DW_AT_name
);
2117 if (attr
&& DW_STRING (attr
))
2118 fieldname
= DW_STRING (attr
);
2122 /* Get physical name. */
2123 physname
= dwarf2_linkage_name (die
);
2125 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
2126 &objfile
->type_obstack
));
2127 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
2128 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
2129 &objfile
->type_obstack
);
2131 else if (die
->tag
== DW_TAG_inheritance
)
2133 /* C++ base class field. */
2134 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2136 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
)
2138 FIELD_BITSIZE (*fp
) = 0;
2139 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
2140 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2141 fip
->nbaseclasses
++;
2145 /* Create the vector of fields, and attach it to the type. */
2148 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
2149 struct objfile
*objfile
)
2151 int nfields
= fip
->nfields
;
2153 /* Record the field count, allocate space for the array of fields,
2154 and create blank accessibility bitfields if necessary. */
2155 TYPE_NFIELDS (type
) = nfields
;
2156 TYPE_FIELDS (type
) = (struct field
*)
2157 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2158 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2160 if (fip
->non_public_fields
)
2162 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2164 TYPE_FIELD_PRIVATE_BITS (type
) =
2165 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2166 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2168 TYPE_FIELD_PROTECTED_BITS (type
) =
2169 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2170 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2172 TYPE_FIELD_IGNORE_BITS (type
) =
2173 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2174 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2177 /* If the type has baseclasses, allocate and clear a bit vector for
2178 TYPE_FIELD_VIRTUAL_BITS. */
2179 if (fip
->nbaseclasses
)
2181 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2184 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2185 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2186 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2187 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2188 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2191 /* Copy the saved-up fields into the field vector. Start from the head
2192 of the list, adding to the tail of the field array, so that they end
2193 up in the same order in the array in which they were added to the list. */
2194 while (nfields
-- > 0)
2196 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2197 switch (fip
->fields
->accessibility
)
2199 case DW_ACCESS_private
:
2200 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2203 case DW_ACCESS_protected
:
2204 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2207 case DW_ACCESS_public
:
2211 /* Unknown accessibility. Complain and treat it as public. */
2213 complain (&dwarf2_unsupported_accessibility
,
2214 fip
->fields
->accessibility
);
2218 if (nfields
< fip
->nbaseclasses
)
2220 switch (fip
->fields
->virtuality
)
2222 case DW_VIRTUALITY_virtual
:
2223 case DW_VIRTUALITY_pure_virtual
:
2224 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2228 fip
->fields
= fip
->fields
->next
;
2232 /* Add a member function to the proper fieldlist. */
2235 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2236 struct type
*type
, struct objfile
*objfile
,
2237 const struct comp_unit_head
*cu_header
)
2239 struct attribute
*attr
;
2240 struct fnfieldlist
*flp
;
2242 struct fn_field
*fnp
;
2245 struct nextfnfield
*new_fnfield
;
2247 /* Get name of member function. */
2248 attr
= dwarf_attr (die
, DW_AT_name
);
2249 if (attr
&& DW_STRING (attr
))
2250 fieldname
= DW_STRING (attr
);
2254 /* Get the mangled name. */
2255 physname
= dwarf2_linkage_name (die
);
2257 /* Look up member function name in fieldlist. */
2258 for (i
= 0; i
< fip
->nfnfields
; i
++)
2260 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2264 /* Create new list element if necessary. */
2265 if (i
< fip
->nfnfields
)
2266 flp
= &fip
->fnfieldlists
[i
];
2269 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2271 fip
->fnfieldlists
= (struct fnfieldlist
*)
2272 xrealloc (fip
->fnfieldlists
,
2273 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2274 * sizeof (struct fnfieldlist
));
2275 if (fip
->nfnfields
== 0)
2276 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2278 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2279 flp
->name
= fieldname
;
2285 /* Create a new member function field and chain it to the field list
2287 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2288 make_cleanup (xfree
, new_fnfield
);
2289 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2290 new_fnfield
->next
= flp
->head
;
2291 flp
->head
= new_fnfield
;
2294 /* Fill in the member function field info. */
2295 fnp
= &new_fnfield
->fnfield
;
2296 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2297 &objfile
->type_obstack
);
2298 fnp
->type
= alloc_type (objfile
);
2299 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2301 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2302 struct type
**arg_types
;
2303 int nparams
= TYPE_NFIELDS (die
->type
);
2306 /* Copy argument types from the subroutine type. */
2307 arg_types
= (struct type
**)
2308 TYPE_ALLOC (fnp
->type
, (nparams
+ 1) * sizeof (struct type
*));
2309 for (iparams
= 0; iparams
< nparams
; iparams
++)
2310 arg_types
[iparams
] = TYPE_FIELD_TYPE (die
->type
, iparams
);
2312 /* Set last entry in argument type vector. */
2313 if (TYPE_VARARGS (die
->type
))
2314 arg_types
[nparams
] = NULL
;
2316 arg_types
[nparams
] = dwarf2_fundamental_type (objfile
, FT_VOID
);
2318 smash_to_method_type (fnp
->type
, type
, return_type
, arg_types
);
2320 /* Handle static member functions.
2321 Dwarf2 has no clean way to discern C++ static and non-static
2322 member functions. G++ helps GDB by marking the first
2323 parameter for non-static member functions (which is the
2324 this pointer) as artificial. We obtain this information
2325 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2326 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2327 fnp
->voffset
= VOFFSET_STATIC
;
2330 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2332 /* Get fcontext from DW_AT_containing_type if present. */
2333 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2334 fnp
->fcontext
= die_containing_type (die
, objfile
, cu_header
);
2336 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2337 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2339 /* Get accessibility. */
2340 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2343 switch (DW_UNSND (attr
))
2345 case DW_ACCESS_private
:
2346 fnp
->is_private
= 1;
2348 case DW_ACCESS_protected
:
2349 fnp
->is_protected
= 1;
2354 /* Check for artificial methods. */
2355 attr
= dwarf_attr (die
, DW_AT_artificial
);
2356 if (attr
&& DW_UNSND (attr
) != 0)
2357 fnp
->is_artificial
= 1;
2359 /* Get index in virtual function table if it is a virtual member function. */
2360 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2362 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) + 2;
2365 /* Create the vector of member function fields, and attach it to the type. */
2368 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2369 struct objfile
*objfile
)
2371 struct fnfieldlist
*flp
;
2372 int total_length
= 0;
2375 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2376 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2377 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2379 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2381 struct nextfnfield
*nfp
= flp
->head
;
2382 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2385 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2386 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2387 fn_flp
->fn_fields
= (struct fn_field
*)
2388 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2389 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2390 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2392 total_length
+= flp
->length
;
2395 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2396 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2399 /* Called when we find the DIE that starts a structure or union scope
2400 (definition) to process all dies that define the members of the
2403 NOTE: we need to call struct_type regardless of whether or not the
2404 DIE has an at_name attribute, since it might be an anonymous
2405 structure or union. This gets the type entered into our set of
2408 However, if the structure is incomplete (an opaque struct/union)
2409 then suppress creating a symbol table entry for it since gdb only
2410 wants to find the one with the complete definition. Note that if
2411 it is complete, we just call new_symbol, which does it's own
2412 checking about whether the struct/union is anonymous or not (and
2413 suppresses creating a symbol table entry itself). */
2416 read_structure_scope (struct die_info
*die
, struct objfile
*objfile
,
2417 const struct comp_unit_head
*cu_header
)
2420 struct attribute
*attr
;
2422 type
= alloc_type (objfile
);
2424 INIT_CPLUS_SPECIFIC (type
);
2425 attr
= dwarf_attr (die
, DW_AT_name
);
2426 if (attr
&& DW_STRING (attr
))
2428 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2429 strlen (DW_STRING (attr
)),
2430 &objfile
->type_obstack
);
2433 if (die
->tag
== DW_TAG_structure_type
)
2435 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2437 else if (die
->tag
== DW_TAG_union_type
)
2439 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2443 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2445 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2448 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2451 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2455 TYPE_LENGTH (type
) = 0;
2458 /* We need to add the type field to the die immediately so we don't
2459 infinitely recurse when dealing with pointers to the structure
2460 type within the structure itself. */
2463 if (die
->has_children
&& ! die_is_declaration (die
))
2465 struct field_info fi
;
2466 struct die_info
*child_die
;
2467 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2469 memset (&fi
, 0, sizeof (struct field_info
));
2471 child_die
= die
->next
;
2473 while (child_die
&& child_die
->tag
)
2475 if (child_die
->tag
== DW_TAG_member
)
2477 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2479 else if (child_die
->tag
== DW_TAG_variable
)
2481 /* C++ static member. */
2482 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2484 else if (child_die
->tag
== DW_TAG_subprogram
)
2486 /* C++ member function. */
2487 process_die (child_die
, objfile
, cu_header
);
2488 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
, cu_header
);
2490 else if (child_die
->tag
== DW_TAG_inheritance
)
2492 /* C++ base class field. */
2493 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2497 process_die (child_die
, objfile
, cu_header
);
2499 child_die
= sibling_die (child_die
);
2502 /* Attach fields and member functions to the type. */
2504 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2507 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2509 /* Get the type which refers to the base class (possibly this
2510 class itself) which contains the vtable pointer for the current
2511 class from the DW_AT_containing_type attribute. */
2513 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2515 struct type
*t
= die_containing_type (die
, objfile
, cu_header
);
2517 TYPE_VPTR_BASETYPE (type
) = t
;
2520 static const char vptr_name
[] =
2521 {'_', 'v', 'p', 't', 'r', '\0'};
2524 /* Our own class provides vtbl ptr. */
2525 for (i
= TYPE_NFIELDS (t
) - 1;
2526 i
>= TYPE_N_BASECLASSES (t
);
2529 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2531 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2532 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2534 TYPE_VPTR_FIELDNO (type
) = i
;
2539 /* Complain if virtual function table field not found. */
2540 if (i
< TYPE_N_BASECLASSES (t
))
2541 complain (&dwarf2_vtbl_not_found_complaint
,
2542 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2546 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2551 new_symbol (die
, type
, objfile
, cu_header
);
2553 do_cleanups (back_to
);
2557 /* No children, must be stub. */
2558 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2562 /* Given a pointer to a die which begins an enumeration, process all
2563 the dies that define the members of the enumeration.
2565 This will be much nicer in draft 6 of the DWARF spec when our
2566 members will be dies instead squished into the DW_AT_element_list
2569 NOTE: We reverse the order of the element list. */
2572 read_enumeration (struct die_info
*die
, struct objfile
*objfile
,
2573 const struct comp_unit_head
*cu_header
)
2575 struct die_info
*child_die
;
2577 struct field
*fields
;
2578 struct attribute
*attr
;
2581 int unsigned_enum
= 1;
2583 type
= alloc_type (objfile
);
2585 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2586 attr
= dwarf_attr (die
, DW_AT_name
);
2587 if (attr
&& DW_STRING (attr
))
2589 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2590 strlen (DW_STRING (attr
)),
2591 &objfile
->type_obstack
);
2594 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2597 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2601 TYPE_LENGTH (type
) = 0;
2606 if (die
->has_children
)
2608 child_die
= die
->next
;
2609 while (child_die
&& child_die
->tag
)
2611 if (child_die
->tag
!= DW_TAG_enumerator
)
2613 process_die (child_die
, objfile
, cu_header
);
2617 attr
= dwarf_attr (child_die
, DW_AT_name
);
2620 sym
= new_symbol (child_die
, type
, objfile
, cu_header
);
2621 if (SYMBOL_VALUE (sym
) < 0)
2624 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2626 fields
= (struct field
*)
2628 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2629 * sizeof (struct field
));
2632 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2633 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2634 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2635 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2641 child_die
= sibling_die (child_die
);
2646 TYPE_NFIELDS (type
) = num_fields
;
2647 TYPE_FIELDS (type
) = (struct field
*)
2648 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2649 memcpy (TYPE_FIELDS (type
), fields
,
2650 sizeof (struct field
) * num_fields
);
2654 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2657 new_symbol (die
, type
, objfile
, cu_header
);
2660 /* Extract all information from a DW_TAG_array_type DIE and put it in
2661 the DIE's type field. For now, this only handles one dimensional
2665 read_array_type (struct die_info
*die
, struct objfile
*objfile
,
2666 const struct comp_unit_head
*cu_header
)
2668 struct die_info
*child_die
;
2669 struct type
*type
= NULL
;
2670 struct type
*element_type
, *range_type
, *index_type
;
2671 struct type
**range_types
= NULL
;
2672 struct attribute
*attr
;
2674 struct cleanup
*back_to
;
2676 /* Return if we've already decoded this type. */
2682 element_type
= die_type (die
, objfile
, cu_header
);
2684 /* Irix 6.2 native cc creates array types without children for
2685 arrays with unspecified length. */
2686 if (die
->has_children
== 0)
2688 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2689 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2690 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2694 back_to
= make_cleanup (null_cleanup
, NULL
);
2695 child_die
= die
->next
;
2696 while (child_die
&& child_die
->tag
)
2698 if (child_die
->tag
== DW_TAG_subrange_type
)
2700 unsigned int low
, high
;
2702 /* Default bounds to an array with unspecified length. */
2705 if (cu_language
== language_fortran
)
2707 /* FORTRAN implies a lower bound of 1, if not given. */
2711 index_type
= die_type (child_die
, objfile
, cu_header
);
2712 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2715 if (attr
->form
== DW_FORM_sdata
)
2717 low
= DW_SND (attr
);
2719 else if (attr
->form
== DW_FORM_udata
2720 || attr
->form
== DW_FORM_data1
2721 || attr
->form
== DW_FORM_data2
2722 || attr
->form
== DW_FORM_data4
2723 || attr
->form
== DW_FORM_data8
)
2725 low
= DW_UNSND (attr
);
2729 complain (&dwarf2_non_const_array_bound_ignored
,
2730 dwarf_form_name (attr
->form
));
2732 die
->type
= lookup_pointer_type (element_type
);
2739 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2742 if (attr
->form
== DW_FORM_sdata
)
2744 high
= 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 high
= DW_UNSND (attr
);
2754 else if (attr
->form
== DW_FORM_block1
)
2756 /* GCC encodes arrays with unspecified or dynamic length
2757 with a DW_FORM_block1 attribute.
2758 FIXME: GDB does not yet know how to handle dynamic
2759 arrays properly, treat them as arrays with unspecified
2765 complain (&dwarf2_non_const_array_bound_ignored
,
2766 dwarf_form_name (attr
->form
));
2768 die
->type
= lookup_pointer_type (element_type
);
2776 /* Create a range type and save it for array type creation. */
2777 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2779 range_types
= (struct type
**)
2780 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2781 * sizeof (struct type
*));
2783 make_cleanup (free_current_contents
, &range_types
);
2785 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2787 child_die
= sibling_die (child_die
);
2790 /* Dwarf2 dimensions are output from left to right, create the
2791 necessary array types in backwards order. */
2792 type
= element_type
;
2794 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2796 /* Understand Dwarf2 support for vector types (like they occur on
2797 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
2798 array type. This is not part of the Dwarf2/3 standard yet, but a
2799 custom vendor extension. The main difference between a regular
2800 array and the vector variant is that vectors are passed by value
2802 attr
= dwarf_attr (die
, DW_AT_GNU_vector
);
2804 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
2806 do_cleanups (back_to
);
2808 /* Install the type in the die. */
2812 /* First cut: install each common block member as a global variable. */
2815 read_common_block (struct die_info
*die
, struct objfile
*objfile
,
2816 const struct comp_unit_head
*cu_header
)
2818 struct die_info
*child_die
;
2819 struct attribute
*attr
;
2821 CORE_ADDR base
= (CORE_ADDR
) 0;
2823 attr
= dwarf_attr (die
, DW_AT_location
);
2826 base
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2828 if (die
->has_children
)
2830 child_die
= die
->next
;
2831 while (child_die
&& child_die
->tag
)
2833 sym
= new_symbol (child_die
, NULL
, objfile
, cu_header
);
2834 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2837 SYMBOL_VALUE_ADDRESS (sym
) =
2838 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2839 add_symbol_to_list (sym
, &global_symbols
);
2841 child_die
= sibling_die (child_die
);
2846 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2847 the user defined type vector. */
2850 read_tag_pointer_type (struct die_info
*die
, struct objfile
*objfile
,
2851 const struct comp_unit_head
*cu_header
)
2854 struct attribute
*attr
;
2861 type
= lookup_pointer_type (die_type (die
, objfile
, cu_header
));
2862 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2865 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2869 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2874 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2875 the user defined type vector. */
2878 read_tag_ptr_to_member_type (struct die_info
*die
, struct objfile
*objfile
,
2879 const struct comp_unit_head
*cu_header
)
2882 struct type
*to_type
;
2883 struct type
*domain
;
2890 type
= alloc_type (objfile
);
2891 to_type
= die_type (die
, objfile
, cu_header
);
2892 domain
= die_containing_type (die
, objfile
, cu_header
);
2893 smash_to_member_type (type
, domain
, to_type
);
2898 /* Extract all information from a DW_TAG_reference_type DIE and add to
2899 the user defined type vector. */
2902 read_tag_reference_type (struct die_info
*die
, struct objfile
*objfile
,
2903 const struct comp_unit_head
*cu_header
)
2906 struct attribute
*attr
;
2913 type
= lookup_reference_type (die_type (die
, objfile
, cu_header
));
2914 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2917 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2921 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2927 read_tag_const_type (struct die_info
*die
, struct objfile
*objfile
,
2928 const struct comp_unit_head
*cu_header
)
2930 struct type
*base_type
;
2937 base_type
= die_type (die
, objfile
, cu_header
);
2938 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
2942 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
2943 const struct comp_unit_head
*cu_header
)
2945 struct type
*base_type
;
2952 base_type
= die_type (die
, objfile
, cu_header
);
2953 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
2956 /* Extract all information from a DW_TAG_string_type DIE and add to
2957 the user defined type vector. It isn't really a user defined type,
2958 but it behaves like one, with other DIE's using an AT_user_def_type
2959 attribute to reference it. */
2962 read_tag_string_type (struct die_info
*die
, struct objfile
*objfile
)
2964 struct type
*type
, *range_type
, *index_type
, *char_type
;
2965 struct attribute
*attr
;
2966 unsigned int length
;
2973 attr
= dwarf_attr (die
, DW_AT_string_length
);
2976 length
= DW_UNSND (attr
);
2980 /* check for the DW_AT_byte_size attribute */
2981 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2984 length
= DW_UNSND (attr
);
2991 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2992 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2993 if (cu_language
== language_fortran
)
2995 /* Need to create a unique string type for bounds
2997 type
= create_string_type (0, range_type
);
3001 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
3002 type
= create_string_type (char_type
, range_type
);
3007 /* Handle DIES due to C code like:
3011 int (*funcp)(int a, long l);
3015 ('funcp' generates a DW_TAG_subroutine_type DIE)
3019 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
3020 const struct comp_unit_head
*cu_header
)
3022 struct type
*type
; /* Type that this function returns */
3023 struct type
*ftype
; /* Function that returns above type */
3024 struct attribute
*attr
;
3026 /* Decode the type that this subroutine returns */
3031 type
= die_type (die
, objfile
, cu_header
);
3032 ftype
= lookup_function_type (type
);
3034 /* All functions in C++ have prototypes. */
3035 attr
= dwarf_attr (die
, DW_AT_prototyped
);
3036 if ((attr
&& (DW_UNSND (attr
) != 0))
3037 || cu_language
== language_cplus
)
3038 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
3040 if (die
->has_children
)
3042 struct die_info
*child_die
;
3046 /* Count the number of parameters.
3047 FIXME: GDB currently ignores vararg functions, but knows about
3048 vararg member functions. */
3049 child_die
= die
->next
;
3050 while (child_die
&& child_die
->tag
)
3052 if (child_die
->tag
== DW_TAG_formal_parameter
)
3054 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
3055 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
3056 child_die
= sibling_die (child_die
);
3059 /* Allocate storage for parameters and fill them in. */
3060 TYPE_NFIELDS (ftype
) = nparams
;
3061 TYPE_FIELDS (ftype
) = (struct field
*)
3062 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
3064 child_die
= die
->next
;
3065 while (child_die
&& child_die
->tag
)
3067 if (child_die
->tag
== DW_TAG_formal_parameter
)
3069 /* Dwarf2 has no clean way to discern C++ static and non-static
3070 member functions. G++ helps GDB by marking the first
3071 parameter for non-static member functions (which is the
3072 this pointer) as artificial. We pass this information
3073 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
3074 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
3076 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
3078 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
3079 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
3083 child_die
= sibling_die (child_die
);
3091 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
3092 const struct comp_unit_head
*cu_header
)
3094 struct attribute
*attr
;
3099 attr
= dwarf_attr (die
, DW_AT_name
);
3100 if (attr
&& DW_STRING (attr
))
3102 name
= DW_STRING (attr
);
3104 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
3105 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, objfile
, cu_header
);
3109 /* Find a representation of a given base type and install
3110 it in the TYPE field of the die. */
3113 read_base_type (struct die_info
*die
, struct objfile
*objfile
)
3116 struct attribute
*attr
;
3117 int encoding
= 0, size
= 0;
3119 /* If we've already decoded this die, this is a no-op. */
3125 attr
= dwarf_attr (die
, DW_AT_encoding
);
3128 encoding
= DW_UNSND (attr
);
3130 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3133 size
= DW_UNSND (attr
);
3135 attr
= dwarf_attr (die
, DW_AT_name
);
3136 if (attr
&& DW_STRING (attr
))
3138 enum type_code code
= TYPE_CODE_INT
;
3143 case DW_ATE_address
:
3144 /* Turn DW_ATE_address into a void * pointer. */
3145 code
= TYPE_CODE_PTR
;
3146 type_flags
|= TYPE_FLAG_UNSIGNED
;
3148 case DW_ATE_boolean
:
3149 code
= TYPE_CODE_BOOL
;
3150 type_flags
|= TYPE_FLAG_UNSIGNED
;
3152 case DW_ATE_complex_float
:
3153 code
= TYPE_CODE_COMPLEX
;
3156 code
= TYPE_CODE_FLT
;
3159 case DW_ATE_signed_char
:
3161 case DW_ATE_unsigned
:
3162 case DW_ATE_unsigned_char
:
3163 type_flags
|= TYPE_FLAG_UNSIGNED
;
3166 complain (&dwarf2_unsupported_at_encoding
,
3167 dwarf_type_encoding_name (encoding
));
3170 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
3171 if (encoding
== DW_ATE_address
)
3172 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
3173 else if (encoding
== DW_ATE_complex_float
)
3176 TYPE_TARGET_TYPE (type
)
3177 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
3178 else if (size
== 16)
3179 TYPE_TARGET_TYPE (type
)
3180 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
3182 TYPE_TARGET_TYPE (type
)
3183 = dwarf2_fundamental_type (objfile
, FT_FLOAT
);
3188 type
= dwarf_base_type (encoding
, size
, objfile
);
3193 /* Read a whole compilation unit into a linked list of dies. */
3195 static struct die_info
*
3196 read_comp_unit (char *info_ptr
, bfd
*abfd
,
3197 const struct comp_unit_head
*cu_header
)
3199 struct die_info
*first_die
, *last_die
, *die
;
3203 /* Reset die reference table; we are
3204 building new ones now. */
3205 dwarf2_empty_hash_tables ();
3209 first_die
= last_die
= NULL
;
3212 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
, cu_header
);
3213 if (die
->has_children
)
3224 /* Enter die in reference hash table */
3225 store_in_ref_table (die
->offset
, die
);
3229 first_die
= last_die
= die
;
3233 last_die
->next
= die
;
3237 while (nesting_level
> 0);
3241 /* Free a linked list of dies. */
3244 free_die_list (struct die_info
*dies
)
3246 struct die_info
*die
, *next
;
3259 do_free_die_list_cleanup (void *dies
)
3261 free_die_list (dies
);
3264 static struct cleanup
*
3265 make_cleanup_free_die_list (struct die_info
*dies
)
3267 return make_cleanup (do_free_die_list_cleanup
, dies
);
3271 /* Read the contents of the section at OFFSET and of size SIZE from the
3272 object file specified by OBJFILE into the psymbol_obstack and return it. */
3275 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
3278 bfd
*abfd
= objfile
->obfd
;
3284 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3285 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
3286 (bfd_bread (buf
, size
, abfd
) != size
))
3289 error ("Dwarf Error: Can't read DWARF data from '%s'",
3290 bfd_get_filename (abfd
));
3295 /* In DWARF version 2, the description of the debugging information is
3296 stored in a separate .debug_abbrev section. Before we read any
3297 dies from a section we read in all abbreviations and install them
3301 dwarf2_read_abbrevs (bfd
*abfd
, unsigned int offset
)
3304 struct abbrev_info
*cur_abbrev
;
3305 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3306 unsigned int abbrev_form
, hash_number
;
3308 /* empty the table */
3309 dwarf2_empty_abbrev_table (NULL
);
3311 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3312 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3313 abbrev_ptr
+= bytes_read
;
3315 /* loop until we reach an abbrev number of 0 */
3316 while (abbrev_number
)
3318 cur_abbrev
= dwarf_alloc_abbrev ();
3320 /* read in abbrev header */
3321 cur_abbrev
->number
= abbrev_number
;
3322 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3323 abbrev_ptr
+= bytes_read
;
3324 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3327 /* now read in declarations */
3328 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3329 abbrev_ptr
+= bytes_read
;
3330 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3331 abbrev_ptr
+= bytes_read
;
3334 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3336 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3337 xrealloc (cur_abbrev
->attrs
,
3338 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3339 * sizeof (struct attr_abbrev
));
3341 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3342 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3343 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3344 abbrev_ptr
+= bytes_read
;
3345 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3346 abbrev_ptr
+= bytes_read
;
3349 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3350 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3351 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3353 /* Get next abbreviation.
3354 Under Irix6 the abbreviations for a compilation unit are not
3355 always properly terminated with an abbrev number of 0.
3356 Exit loop if we encounter an abbreviation which we have
3357 already read (which means we are about to read the abbreviations
3358 for the next compile unit) or if the end of the abbreviation
3359 table is reached. */
3360 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3361 >= dwarf_abbrev_size
)
3363 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3364 abbrev_ptr
+= bytes_read
;
3365 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3370 /* Empty the abbrev table for a new compilation unit. */
3374 dwarf2_empty_abbrev_table (PTR ignore
)
3377 struct abbrev_info
*abbrev
, *next
;
3379 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3382 abbrev
= dwarf2_abbrevs
[i
];
3385 next
= abbrev
->next
;
3386 xfree (abbrev
->attrs
);
3390 dwarf2_abbrevs
[i
] = NULL
;
3394 /* Lookup an abbrev_info structure in the abbrev hash table. */
3396 static struct abbrev_info
*
3397 dwarf2_lookup_abbrev (unsigned int number
)
3399 unsigned int hash_number
;
3400 struct abbrev_info
*abbrev
;
3402 hash_number
= number
% ABBREV_HASH_SIZE
;
3403 abbrev
= dwarf2_abbrevs
[hash_number
];
3407 if (abbrev
->number
== number
)
3410 abbrev
= abbrev
->next
;
3415 /* Read a minimal amount of information into the minimal die structure. */
3418 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3419 char *info_ptr
, const struct comp_unit_head
*cu_header
)
3421 unsigned int abbrev_number
, bytes_read
, i
;
3422 struct abbrev_info
*abbrev
;
3423 struct attribute attr
;
3424 struct attribute spec_attr
;
3425 int found_spec_attr
= 0;
3426 int has_low_pc_attr
= 0;
3427 int has_high_pc_attr
= 0;
3429 *part_die
= zeroed_partial_die
;
3430 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3431 info_ptr
+= bytes_read
;
3435 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3438 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3440 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3441 part_die
->tag
= abbrev
->tag
;
3442 part_die
->has_children
= abbrev
->has_children
;
3443 part_die
->abbrev
= abbrev_number
;
3445 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3447 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
3448 info_ptr
, cu_header
);
3450 /* Store the data if it is of an attribute we want to keep in a
3451 partial symbol table. */
3456 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3457 if (part_die
->name
== NULL
)
3458 part_die
->name
= DW_STRING (&attr
);
3460 case DW_AT_MIPS_linkage_name
:
3461 part_die
->name
= DW_STRING (&attr
);
3464 has_low_pc_attr
= 1;
3465 part_die
->lowpc
= DW_ADDR (&attr
);
3468 has_high_pc_attr
= 1;
3469 part_die
->highpc
= DW_ADDR (&attr
);
3471 case DW_AT_location
:
3472 part_die
->locdesc
= DW_BLOCK (&attr
);
3474 case DW_AT_language
:
3475 part_die
->language
= DW_UNSND (&attr
);
3477 case DW_AT_external
:
3478 part_die
->is_external
= DW_UNSND (&attr
);
3480 case DW_AT_declaration
:
3481 part_die
->is_declaration
= DW_UNSND (&attr
);
3484 part_die
->has_type
= 1;
3486 case DW_AT_abstract_origin
:
3487 case DW_AT_specification
:
3488 found_spec_attr
= 1;
3492 /* Ignore absolute siblings, they might point outside of
3493 the current compile unit. */
3494 if (attr
.form
== DW_FORM_ref_addr
)
3495 complain (&dwarf2_absolute_sibling_complaint
);
3498 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3505 /* If we found a reference attribute and the die has no name, try
3506 to find a name in the referred to die. */
3508 if (found_spec_attr
&& part_die
->name
== NULL
)
3510 struct partial_die_info spec_die
;
3514 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3515 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu_header
);
3518 part_die
->name
= spec_die
.name
;
3520 /* Copy DW_AT_external attribute if it is set. */
3521 if (spec_die
.is_external
)
3522 part_die
->is_external
= spec_die
.is_external
;
3526 /* When using the GNU linker, .gnu.linkonce. sections are used to
3527 eliminate duplicate copies of functions and vtables and such.
3528 The linker will arbitrarily choose one and discard the others.
3529 The AT_*_pc values for such functions refer to local labels in
3530 these sections. If the section from that file was discarded, the
3531 labels are not in the output, so the relocs get a value of 0.
3532 If this is a discarded function, mark the pc bounds as invalid,
3533 so that GDB will ignore it. */
3534 if (has_low_pc_attr
&& has_high_pc_attr
3535 && part_die
->lowpc
< part_die
->highpc
3536 && (part_die
->lowpc
!= 0
3537 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3538 part_die
->has_pc_info
= 1;
3542 /* Read the die from the .debug_info section buffer. And set diep to
3543 point to a newly allocated die with its information. */
3546 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
3547 const struct comp_unit_head
*cu_header
)
3549 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3550 struct abbrev_info
*abbrev
;
3551 struct die_info
*die
;
3553 offset
= info_ptr
- dwarf_info_buffer
;
3554 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3555 info_ptr
+= bytes_read
;
3558 die
= dwarf_alloc_die ();
3560 die
->abbrev
= abbrev_number
;
3566 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3569 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3571 die
= dwarf_alloc_die ();
3572 die
->offset
= offset
;
3573 die
->tag
= abbrev
->tag
;
3574 die
->has_children
= abbrev
->has_children
;
3575 die
->abbrev
= abbrev_number
;
3578 die
->num_attrs
= abbrev
->num_attrs
;
3579 die
->attrs
= (struct attribute
*)
3580 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3582 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3584 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3585 abfd
, info_ptr
, cu_header
);
3592 /* Read an attribute value described by an attribute form. */
3595 read_attribute_value (struct attribute
*attr
, unsigned form
,
3596 bfd
*abfd
, char *info_ptr
,
3597 const struct comp_unit_head
*cu_header
)
3599 unsigned int bytes_read
;
3600 struct dwarf_block
*blk
;
3606 case DW_FORM_ref_addr
:
3607 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
3608 info_ptr
+= bytes_read
;
3610 case DW_FORM_block2
:
3611 blk
= dwarf_alloc_block ();
3612 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3614 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3615 info_ptr
+= blk
->size
;
3616 DW_BLOCK (attr
) = blk
;
3618 case DW_FORM_block4
:
3619 blk
= dwarf_alloc_block ();
3620 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3622 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3623 info_ptr
+= blk
->size
;
3624 DW_BLOCK (attr
) = blk
;
3627 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3631 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3635 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3638 case DW_FORM_string
:
3639 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3640 info_ptr
+= bytes_read
;
3643 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
3645 info_ptr
+= bytes_read
;
3648 blk
= dwarf_alloc_block ();
3649 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3650 info_ptr
+= bytes_read
;
3651 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3652 info_ptr
+= blk
->size
;
3653 DW_BLOCK (attr
) = blk
;
3655 case DW_FORM_block1
:
3656 blk
= dwarf_alloc_block ();
3657 blk
->size
= read_1_byte (abfd
, info_ptr
);
3659 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3660 info_ptr
+= blk
->size
;
3661 DW_BLOCK (attr
) = blk
;
3664 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3668 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3672 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3673 info_ptr
+= bytes_read
;
3676 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3677 info_ptr
+= bytes_read
;
3680 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3684 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3688 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3692 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3695 case DW_FORM_ref_udata
:
3696 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3697 info_ptr
+= bytes_read
;
3699 case DW_FORM_indirect
:
3700 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3701 info_ptr
+= bytes_read
;
3702 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu_header
);
3705 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3706 dwarf_form_name (form
));
3711 /* Read an attribute described by an abbreviated attribute. */
3714 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
3715 bfd
*abfd
, char *info_ptr
,
3716 const struct comp_unit_head
*cu_header
)
3718 attr
->name
= abbrev
->name
;
3719 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu_header
);
3722 /* read dwarf information from a buffer */
3725 read_1_byte (bfd
*abfd
, char *buf
)
3727 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3731 read_1_signed_byte (bfd
*abfd
, char *buf
)
3733 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3737 read_2_bytes (bfd
*abfd
, char *buf
)
3739 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3743 read_2_signed_bytes (bfd
*abfd
, char *buf
)
3745 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3749 read_4_bytes (bfd
*abfd
, char *buf
)
3751 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3755 read_4_signed_bytes (bfd
*abfd
, char *buf
)
3757 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3760 static unsigned long
3761 read_8_bytes (bfd
*abfd
, char *buf
)
3763 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3767 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3770 CORE_ADDR retval
= 0;
3772 if (cu_header
->signed_addr_p
)
3774 switch (cu_header
->addr_size
)
3777 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3780 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3783 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
3786 internal_error (__FILE__
, __LINE__
,
3787 "read_address: bad switch, signed");
3792 switch (cu_header
->addr_size
)
3795 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3798 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3801 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3804 internal_error (__FILE__
, __LINE__
,
3805 "read_address: bad switch, unsigned");
3809 *bytes_read
= cu_header
->addr_size
;
3813 /* Reads the initial length from a section. The (draft) DWARF 2.1
3814 specification allows the initial length to take up either 4 bytes
3815 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
3816 bytes describe the length and all offsets will be 8 bytes in length
3819 The value returned via bytes_read should be used to increment
3820 the relevant pointer after calling read_initial_length().
3822 As a side effect, this function sets the fields initial_length_size
3823 and offset_size in cu_header to the values appropriate for the
3824 length field. (The format of the initial length field determines
3825 the width of file offsets to be fetched later with fetch_offset().)
3827 [ Note: read_initial_length() and read_offset() are based on the
3828 document entitled "DWARF Debugging Information Format", revision
3829 2.1, draft 4, dated July 20, 2000. This document was obtained
3832 http://reality.sgi.com/dehnert_engr/dwarf/dwarf2p1-draft4-000720.pdf
3834 This document is only a draft and is subject to change. (So beware.)
3836 - Kevin, Aug 4, 2000
3840 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
3845 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3847 if (retval
== 0xffffffff)
3849 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
3851 if (cu_header
!= NULL
)
3853 cu_header
->initial_length_size
= 12;
3854 cu_header
->offset_size
= 8;
3860 if (cu_header
!= NULL
)
3862 cu_header
->initial_length_size
= 4;
3863 cu_header
->offset_size
= 4;
3870 /* Read an offset from the data stream. The size of the offset is
3871 given by cu_header->offset_size. */
3874 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3879 switch (cu_header
->offset_size
)
3882 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3886 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3890 internal_error (__FILE__
, __LINE__
,
3891 "read_offset: bad switch");
3898 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
3900 /* If the size of a host char is 8 bits, we can return a pointer
3901 to the buffer, otherwise we have to copy the data to a buffer
3902 allocated on the temporary obstack. */
3903 gdb_assert (HOST_CHAR_BIT
== 8);
3908 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3910 /* If the size of a host char is 8 bits, we can return a pointer
3911 to the string, otherwise we have to copy the string to a buffer
3912 allocated on the temporary obstack. */
3913 gdb_assert (HOST_CHAR_BIT
== 8);
3916 *bytes_read_ptr
= 1;
3919 *bytes_read_ptr
= strlen (buf
) + 1;
3924 read_indirect_string (bfd
*abfd
, char *buf
,
3925 const struct comp_unit_head
*cu_header
,
3926 unsigned int *bytes_read_ptr
)
3928 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
3929 (int *) bytes_read_ptr
);
3931 if (dwarf_str_buffer
== NULL
)
3933 error ("DW_FORM_strp used without .debug_str section");
3936 if (str_offset
>= dwarf_str_size
)
3938 error ("DW_FORM_strp pointing outside of .debug_str section");
3941 gdb_assert (HOST_CHAR_BIT
== 8);
3942 if (dwarf_str_buffer
[str_offset
] == '\0')
3944 return dwarf_str_buffer
+ str_offset
;
3947 static unsigned long
3948 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3950 unsigned long result
;
3951 unsigned int num_read
;
3961 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3964 result
|= ((unsigned long)(byte
& 127) << shift
);
3965 if ((byte
& 128) == 0)
3971 *bytes_read_ptr
= num_read
;
3976 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3979 int i
, shift
, size
, num_read
;
3989 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3992 result
|= ((long)(byte
& 127) << shift
);
3994 if ((byte
& 128) == 0)
3999 if ((shift
< size
) && (byte
& 0x40))
4001 result
|= -(1 << shift
);
4003 *bytes_read_ptr
= num_read
;
4008 set_cu_language (unsigned int lang
)
4014 cu_language
= language_c
;
4016 case DW_LANG_C_plus_plus
:
4017 cu_language
= language_cplus
;
4019 case DW_LANG_Fortran77
:
4020 case DW_LANG_Fortran90
:
4021 case DW_LANG_Fortran95
:
4022 cu_language
= language_fortran
;
4024 case DW_LANG_Mips_Assembler
:
4025 cu_language
= language_asm
;
4028 cu_language
= language_java
;
4031 case DW_LANG_Cobol74
:
4032 case DW_LANG_Cobol85
:
4033 case DW_LANG_Pascal83
:
4034 case DW_LANG_Modula2
:
4036 cu_language
= language_unknown
;
4039 cu_language_defn
= language_def (cu_language
);
4042 /* Return the named attribute or NULL if not there. */
4044 static struct attribute
*
4045 dwarf_attr (struct die_info
*die
, unsigned int name
)
4048 struct attribute
*spec
= NULL
;
4050 for (i
= 0; i
< die
->num_attrs
; ++i
)
4052 if (die
->attrs
[i
].name
== name
)
4054 return &die
->attrs
[i
];
4056 if (die
->attrs
[i
].name
== DW_AT_specification
4057 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
4058 spec
= &die
->attrs
[i
];
4062 struct die_info
*ref_die
=
4063 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
4066 return dwarf_attr (ref_die
, name
);
4073 die_is_declaration (struct die_info
*die
)
4075 return (dwarf_attr (die
, DW_AT_declaration
)
4076 && ! dwarf_attr (die
, DW_AT_specification
));
4080 /* Free the line_header structure *LH, and any arrays and strings it
4083 free_line_header (struct line_header
*lh
)
4085 if (lh
->standard_opcode_lengths
)
4086 xfree (lh
->standard_opcode_lengths
);
4088 /* Remember that all the lh->file_names[i].name pointers are
4089 pointers into debug_line_buffer, and don't need to be freed. */
4091 xfree (lh
->file_names
);
4093 /* Similarly for the include directory names. */
4094 if (lh
->include_dirs
)
4095 xfree (lh
->include_dirs
);
4101 /* Add an entry to LH's include directory table. */
4103 add_include_dir (struct line_header
*lh
, char *include_dir
)
4105 /* Grow the array if necessary. */
4106 if (lh
->include_dirs_size
== 0)
4108 lh
->include_dirs_size
= 1; /* for testing */
4109 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
4110 * sizeof (*lh
->include_dirs
));
4112 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
4114 lh
->include_dirs_size
*= 2;
4115 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
4116 (lh
->include_dirs_size
4117 * sizeof (*lh
->include_dirs
)));
4120 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
4124 /* Add an entry to LH's file name table. */
4126 add_file_name (struct line_header
*lh
,
4128 unsigned int dir_index
,
4129 unsigned int mod_time
,
4130 unsigned int length
)
4132 struct file_entry
*fe
;
4134 /* Grow the array if necessary. */
4135 if (lh
->file_names_size
== 0)
4137 lh
->file_names_size
= 1; /* for testing */
4138 lh
->file_names
= xmalloc (lh
->file_names_size
4139 * sizeof (*lh
->file_names
));
4141 else if (lh
->num_file_names
>= lh
->file_names_size
)
4143 lh
->file_names_size
*= 2;
4144 lh
->file_names
= xrealloc (lh
->file_names
,
4145 (lh
->file_names_size
4146 * sizeof (*lh
->file_names
)));
4149 fe
= &lh
->file_names
[lh
->num_file_names
++];
4151 fe
->dir_index
= dir_index
;
4152 fe
->mod_time
= mod_time
;
4153 fe
->length
= length
;
4157 /* Read the statement program header starting at OFFSET in
4158 dwarf_line_buffer, according to the endianness of ABFD. Return a
4159 pointer to a struct line_header, allocated using xmalloc.
4161 NOTE: the strings in the include directory and file name tables of
4162 the returned object point into debug_line_buffer, and must not be
4164 static struct line_header
*
4165 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
4166 const struct comp_unit_head
*cu_header
)
4168 struct cleanup
*back_to
;
4169 struct line_header
*lh
;
4173 char *cur_dir
, *cur_file
;
4175 if (dwarf_line_buffer
== NULL
)
4177 complain (&dwarf2_missing_line_number_section
);
4181 /* Make sure that at least there's room for the total_length field. That
4182 could be 12 bytes long, but we're just going to fudge that. */
4183 if (offset
+ 4 >= dwarf_line_size
)
4185 complain (&dwarf2_statement_list_fits_in_line_number_section
);
4189 lh
= xmalloc (sizeof (*lh
));
4190 memset (lh
, 0, sizeof (*lh
));
4191 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
4194 line_ptr
= dwarf_line_buffer
+ offset
;
4196 /* read in the header */
4197 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
4198 line_ptr
+= bytes_read
;
4199 if (line_ptr
+ lh
->total_length
> dwarf_line_buffer
+ dwarf_line_size
)
4201 complain (&dwarf2_statement_list_fits_in_line_number_section
);
4204 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
4205 lh
->version
= read_2_bytes (abfd
, line_ptr
);
4207 lh
->header_length
= read_offset (abfd
, line_ptr
, cu_header
, &bytes_read
);
4208 line_ptr
+= bytes_read
;
4209 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
4211 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
4213 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
4215 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
4217 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
4219 lh
->standard_opcode_lengths
4220 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
4222 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
4223 for (i
= 1; i
< lh
->opcode_base
; ++i
)
4225 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
4229 /* Read directory table */
4230 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4232 line_ptr
+= bytes_read
;
4233 add_include_dir (lh
, cur_dir
);
4235 line_ptr
+= bytes_read
;
4237 /* Read file name table */
4238 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4240 unsigned int dir_index
, mod_time
, length
;
4242 line_ptr
+= bytes_read
;
4243 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4244 line_ptr
+= bytes_read
;
4245 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4246 line_ptr
+= bytes_read
;
4247 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4248 line_ptr
+= bytes_read
;
4250 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4252 line_ptr
+= bytes_read
;
4253 lh
->statement_program_start
= line_ptr
;
4255 if (line_ptr
> dwarf_line_buffer
+ dwarf_line_size
)
4256 complain (&dwarf2_line_header_too_long
);
4258 discard_cleanups (back_to
);
4262 /* This function exists to work around a bug in certain compilers
4263 (particularly GCC 2.95), in which the first line number marker of a
4264 function does not show up until after the prologue, right before
4265 the second line number marker. This function shifts ADDRESS down
4266 to the beginning of the function if necessary, and is called on
4267 addresses passed to record_line. */
4270 check_cu_functions (CORE_ADDR address
)
4272 struct function_range
*fn
;
4274 /* Find the function_range containing address. */
4279 cu_cached_fn
= cu_first_fn
;
4283 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4289 while (fn
&& fn
!= cu_cached_fn
)
4290 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4300 if (address
!= fn
->lowpc
)
4301 complain (&dwarf2_misplaced_line_number
,
4302 (unsigned long) address
, fn
->name
);
4307 /* Decode the line number information for the compilation unit whose
4308 line number info is at OFFSET in the .debug_line section.
4309 The compilation directory of the file is passed in COMP_DIR. */
4312 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
4313 const struct comp_unit_head
*cu_header
)
4317 unsigned int i
, bytes_read
;
4319 unsigned char op_code
, extended_op
, adj_opcode
;
4321 line_ptr
= lh
->statement_program_start
;
4322 line_end
= lh
->statement_program_end
;
4324 /* Read the statement sequences until there's nothing left. */
4325 while (line_ptr
< line_end
)
4327 /* state machine registers */
4328 CORE_ADDR address
= 0;
4329 unsigned int file
= 1;
4330 unsigned int line
= 1;
4331 unsigned int column
= 0;
4332 int is_stmt
= lh
->default_is_stmt
;
4333 int basic_block
= 0;
4334 int end_sequence
= 0;
4336 /* Start a subfile for the current file of the state machine. */
4337 if (lh
->num_file_names
>= file
)
4339 /* lh->include_dirs and lh->file_names are 0-based, but the
4340 directory and file name numbers in the statement program
4342 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
4345 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
4348 dwarf2_start_subfile (fe
->name
, dir
);
4351 /* Decode the table. */
4352 while (!end_sequence
)
4354 op_code
= read_1_byte (abfd
, line_ptr
);
4357 if (op_code
>= lh
->opcode_base
)
4358 { /* Special operand. */
4359 adj_opcode
= op_code
- lh
->opcode_base
;
4360 address
+= (adj_opcode
/ lh
->line_range
)
4361 * lh
->minimum_instruction_length
;
4362 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
4363 /* append row to matrix using current values */
4364 address
= check_cu_functions (address
);
4365 record_line (current_subfile
, line
, address
);
4368 else switch (op_code
)
4370 case DW_LNS_extended_op
:
4371 line_ptr
+= 1; /* ignore length */
4372 extended_op
= read_1_byte (abfd
, line_ptr
);
4374 switch (extended_op
)
4376 case DW_LNE_end_sequence
:
4378 record_line (current_subfile
, 0, address
);
4380 case DW_LNE_set_address
:
4381 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
4382 line_ptr
+= bytes_read
;
4383 address
+= baseaddr
;
4385 case DW_LNE_define_file
:
4388 unsigned int dir_index
, mod_time
, length
;
4390 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
4391 line_ptr
+= bytes_read
;
4393 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4394 line_ptr
+= bytes_read
;
4396 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4397 line_ptr
+= bytes_read
;
4399 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4400 line_ptr
+= bytes_read
;
4401 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4405 complain (&dwarf2_mangled_line_number_section
);
4410 address
= check_cu_functions (address
);
4411 record_line (current_subfile
, line
, address
);
4414 case DW_LNS_advance_pc
:
4415 address
+= lh
->minimum_instruction_length
4416 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4417 line_ptr
+= bytes_read
;
4419 case DW_LNS_advance_line
:
4420 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
4421 line_ptr
+= bytes_read
;
4423 case DW_LNS_set_file
:
4425 /* lh->include_dirs and lh->file_names are 0-based,
4426 but the directory and file name numbers in the
4427 statement program are 1-based. */
4428 struct file_entry
*fe
;
4430 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4431 line_ptr
+= bytes_read
;
4432 fe
= &lh
->file_names
[file
- 1];
4434 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
4437 dwarf2_start_subfile (fe
->name
, dir
);
4440 case DW_LNS_set_column
:
4441 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4442 line_ptr
+= bytes_read
;
4444 case DW_LNS_negate_stmt
:
4445 is_stmt
= (!is_stmt
);
4447 case DW_LNS_set_basic_block
:
4450 /* Add to the address register of the state machine the
4451 address increment value corresponding to special opcode
4452 255. Ie, this value is scaled by the minimum instruction
4453 length since special opcode 255 would have scaled the
4455 case DW_LNS_const_add_pc
:
4456 address
+= (lh
->minimum_instruction_length
4457 * ((255 - lh
->opcode_base
) / lh
->line_range
));
4459 case DW_LNS_fixed_advance_pc
:
4460 address
+= read_2_bytes (abfd
, line_ptr
);
4464 { /* Unknown standard opcode, ignore it. */
4466 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
4468 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4469 line_ptr
+= bytes_read
;
4477 /* Start a subfile for DWARF. FILENAME is the name of the file and
4478 DIRNAME the name of the source directory which contains FILENAME
4479 or NULL if not known.
4480 This routine tries to keep line numbers from identical absolute and
4481 relative file names in a common subfile.
4483 Using the `list' example from the GDB testsuite, which resides in
4484 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4485 of /srcdir/list0.c yields the following debugging information for list0.c:
4487 DW_AT_name: /srcdir/list0.c
4488 DW_AT_comp_dir: /compdir
4489 files.files[0].name: list0.h
4490 files.files[0].dir: /srcdir
4491 files.files[1].name: list0.c
4492 files.files[1].dir: /srcdir
4494 The line number information for list0.c has to end up in a single
4495 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4498 dwarf2_start_subfile (char *filename
, char *dirname
)
4500 /* If the filename isn't absolute, try to match an existing subfile
4501 with the full pathname. */
4503 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
4505 struct subfile
*subfile
;
4506 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4508 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4510 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
4512 current_subfile
= subfile
;
4519 start_subfile (filename
, dirname
);
4522 /* Given a pointer to a DWARF information entry, figure out if we need
4523 to make a symbol table entry for it, and if so, create a new entry
4524 and return a pointer to it.
4525 If TYPE is NULL, determine symbol type from the die, otherwise
4526 used the passed type. */
4528 static struct symbol
*
4529 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
4530 const struct comp_unit_head
*cu_header
)
4532 struct symbol
*sym
= NULL
;
4534 struct attribute
*attr
= NULL
;
4535 struct attribute
*attr2
= NULL
;
4538 name
= dwarf2_linkage_name (die
);
4541 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4542 sizeof (struct symbol
));
4543 OBJSTAT (objfile
, n_syms
++);
4544 memset (sym
, 0, sizeof (struct symbol
));
4545 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4546 &objfile
->symbol_obstack
);
4548 /* Default assumptions.
4549 Use the passed type or decode it from the die. */
4550 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4551 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4553 SYMBOL_TYPE (sym
) = type
;
4555 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
4556 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4559 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4562 /* If this symbol is from a C++ compilation, then attempt to
4563 cache the demangled form for future reference. This is a
4564 typical time versus space tradeoff, that was decided in favor
4565 of time because it sped up C++ symbol lookups by a factor of
4568 SYMBOL_LANGUAGE (sym
) = cu_language
;
4569 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4573 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4576 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4578 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4580 case DW_TAG_subprogram
:
4581 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4583 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4584 attr2
= dwarf_attr (die
, DW_AT_external
);
4585 if (attr2
&& (DW_UNSND (attr2
) != 0))
4587 add_symbol_to_list (sym
, &global_symbols
);
4591 add_symbol_to_list (sym
, list_in_scope
);
4594 case DW_TAG_variable
:
4595 /* Compilation with minimal debug info may result in variables
4596 with missing type entries. Change the misleading `void' type
4597 to something sensible. */
4598 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4599 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4600 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4601 "<variable, no debug info>",
4603 attr
= dwarf_attr (die
, DW_AT_const_value
);
4606 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4607 attr2
= dwarf_attr (die
, DW_AT_external
);
4608 if (attr2
&& (DW_UNSND (attr2
) != 0))
4609 add_symbol_to_list (sym
, &global_symbols
);
4611 add_symbol_to_list (sym
, list_in_scope
);
4614 attr
= dwarf_attr (die
, DW_AT_location
);
4617 attr2
= dwarf_attr (die
, DW_AT_external
);
4618 if (attr2
&& (DW_UNSND (attr2
) != 0))
4620 SYMBOL_VALUE_ADDRESS (sym
) =
4621 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4622 add_symbol_to_list (sym
, &global_symbols
);
4624 /* In shared libraries the address of the variable
4625 in the location descriptor might still be relocatable,
4626 so its value could be zero.
4627 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4628 value is zero, the address of the variable will then
4629 be determined from the minimal symbol table whenever
4630 the variable is referenced. */
4631 if (SYMBOL_VALUE_ADDRESS (sym
))
4633 fixup_symbol_section (sym
, objfile
);
4634 SYMBOL_VALUE_ADDRESS (sym
) +=
4635 ANOFFSET (objfile
->section_offsets
,
4636 SYMBOL_SECTION (sym
));
4637 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4640 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4644 SYMBOL_VALUE (sym
) = addr
=
4645 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4646 add_symbol_to_list (sym
, list_in_scope
);
4649 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4653 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4654 SYMBOL_VALUE (sym
) =
4655 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4659 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4660 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4664 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4668 fixup_symbol_section (sym
, objfile
);
4669 SYMBOL_VALUE_ADDRESS (sym
) =
4670 addr
+ ANOFFSET (objfile
->section_offsets
,
4671 SYMBOL_SECTION (sym
));
4672 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4678 /* We do not know the address of this symbol.
4679 If it is an external symbol and we have type information
4680 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4681 The address of the variable will then be determined from
4682 the minimal symbol table whenever the variable is
4684 attr2
= dwarf_attr (die
, DW_AT_external
);
4685 if (attr2
&& (DW_UNSND (attr2
) != 0)
4686 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4688 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4689 add_symbol_to_list (sym
, &global_symbols
);
4693 case DW_TAG_formal_parameter
:
4694 attr
= dwarf_attr (die
, DW_AT_location
);
4697 SYMBOL_VALUE (sym
) =
4698 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4701 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4702 SYMBOL_VALUE (sym
) =
4703 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4709 if (basereg
!= frame_base_reg
)
4710 complain (&dwarf2_complex_location_expr
);
4711 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4715 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4716 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4721 SYMBOL_CLASS (sym
) = LOC_ARG
;
4724 attr
= dwarf_attr (die
, DW_AT_const_value
);
4727 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4729 add_symbol_to_list (sym
, list_in_scope
);
4731 case DW_TAG_unspecified_parameters
:
4732 /* From varargs functions; gdb doesn't seem to have any
4733 interest in this information, so just ignore it for now.
4736 case DW_TAG_class_type
:
4737 case DW_TAG_structure_type
:
4738 case DW_TAG_union_type
:
4739 case DW_TAG_enumeration_type
:
4740 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4741 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4742 add_symbol_to_list (sym
, list_in_scope
);
4744 /* The semantics of C++ state that "struct foo { ... }" also
4745 defines a typedef for "foo". Synthesize a typedef symbol so
4746 that "ptype foo" works as expected. */
4747 if (cu_language
== language_cplus
)
4749 struct symbol
*typedef_sym
= (struct symbol
*)
4750 obstack_alloc (&objfile
->symbol_obstack
,
4751 sizeof (struct symbol
));
4752 *typedef_sym
= *sym
;
4753 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4754 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4755 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4756 obsavestring (SYMBOL_NAME (sym
),
4757 strlen (SYMBOL_NAME (sym
)),
4758 &objfile
->type_obstack
);
4759 add_symbol_to_list (typedef_sym
, list_in_scope
);
4762 case DW_TAG_typedef
:
4763 case DW_TAG_base_type
:
4764 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4765 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4766 add_symbol_to_list (sym
, list_in_scope
);
4768 case DW_TAG_enumerator
:
4769 attr
= dwarf_attr (die
, DW_AT_const_value
);
4772 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4774 add_symbol_to_list (sym
, list_in_scope
);
4777 /* Not a tag we recognize. Hopefully we aren't processing
4778 trash data, but since we must specifically ignore things
4779 we don't recognize, there is nothing else we should do at
4781 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4788 /* Copy constant value from an attribute to a symbol. */
4791 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
4792 struct objfile
*objfile
,
4793 const struct comp_unit_head
*cu_header
)
4795 struct dwarf_block
*blk
;
4800 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
4801 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4802 cu_header
->addr_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4803 SYMBOL_VALUE_BYTES (sym
) = (char *)
4804 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
4805 store_address (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
4807 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4809 case DW_FORM_block1
:
4810 case DW_FORM_block2
:
4811 case DW_FORM_block4
:
4813 blk
= DW_BLOCK (attr
);
4814 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4815 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4816 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4817 SYMBOL_VALUE_BYTES (sym
) = (char *)
4818 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4819 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4820 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4823 /* The DW_AT_const_value attributes are supposed to carry the
4824 symbol's value "represented as it would be on the target
4825 architecture." By the time we get here, it's already been
4826 converted to host endianness, so we just need to sign- or
4827 zero-extend it as appropriate. */
4829 dwarf2_const_value_data (attr
, sym
, 8);
4832 dwarf2_const_value_data (attr
, sym
, 16);
4835 dwarf2_const_value_data (attr
, sym
, 32);
4838 dwarf2_const_value_data (attr
, sym
, 64);
4842 SYMBOL_VALUE (sym
) = DW_SND (attr
);
4843 SYMBOL_CLASS (sym
) = LOC_CONST
;
4847 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4848 SYMBOL_CLASS (sym
) = LOC_CONST
;
4852 complain (&dwarf2_unsupported_const_value_attr
,
4853 dwarf_form_name (attr
->form
));
4854 SYMBOL_VALUE (sym
) = 0;
4855 SYMBOL_CLASS (sym
) = LOC_CONST
;
4861 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4862 or zero-extend it as appropriate for the symbol's type. */
4864 dwarf2_const_value_data (struct attribute
*attr
,
4868 LONGEST l
= DW_UNSND (attr
);
4870 if (bits
< sizeof (l
) * 8)
4872 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
4873 l
&= ((LONGEST
) 1 << bits
) - 1;
4875 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
4878 SYMBOL_VALUE (sym
) = l
;
4879 SYMBOL_CLASS (sym
) = LOC_CONST
;
4883 /* Return the type of the die in question using its DW_AT_type attribute. */
4885 static struct type
*
4886 die_type (struct die_info
*die
, struct objfile
*objfile
,
4887 const struct comp_unit_head
*cu_header
)
4890 struct attribute
*type_attr
;
4891 struct die_info
*type_die
;
4894 type_attr
= dwarf_attr (die
, DW_AT_type
);
4897 /* A missing DW_AT_type represents a void type. */
4898 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4902 ref
= dwarf2_get_ref_die_offset (type_attr
);
4903 type_die
= follow_die_ref (ref
);
4906 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4910 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4913 dump_die (type_die
);
4914 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4919 /* Return the containing type of the die in question using its
4920 DW_AT_containing_type attribute. */
4922 static struct type
*
4923 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
4924 const struct comp_unit_head
*cu_header
)
4926 struct type
*type
= NULL
;
4927 struct attribute
*type_attr
;
4928 struct die_info
*type_die
= NULL
;
4931 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4934 ref
= dwarf2_get_ref_die_offset (type_attr
);
4935 type_die
= follow_die_ref (ref
);
4938 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4941 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4946 dump_die (type_die
);
4947 error ("Dwarf Error: Problem turning containing type into gdb type.");
4953 static struct type
*
4954 type_at_offset (unsigned int offset
, struct objfile
*objfile
)
4956 struct die_info
*die
;
4959 die
= follow_die_ref (offset
);
4962 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4965 type
= tag_type_to_type (die
, objfile
);
4970 static struct type
*
4971 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
4972 const struct comp_unit_head
*cu_header
)
4980 read_type_die (die
, objfile
, cu_header
);
4984 error ("Dwarf Error: Cannot find type of die.");
4991 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
4992 const struct comp_unit_head
*cu_header
)
4996 case DW_TAG_class_type
:
4997 case DW_TAG_structure_type
:
4998 case DW_TAG_union_type
:
4999 read_structure_scope (die
, objfile
, cu_header
);
5001 case DW_TAG_enumeration_type
:
5002 read_enumeration (die
, objfile
, cu_header
);
5004 case DW_TAG_subprogram
:
5005 case DW_TAG_subroutine_type
:
5006 read_subroutine_type (die
, objfile
, cu_header
);
5008 case DW_TAG_array_type
:
5009 read_array_type (die
, objfile
, cu_header
);
5011 case DW_TAG_pointer_type
:
5012 read_tag_pointer_type (die
, objfile
, cu_header
);
5014 case DW_TAG_ptr_to_member_type
:
5015 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
5017 case DW_TAG_reference_type
:
5018 read_tag_reference_type (die
, objfile
, cu_header
);
5020 case DW_TAG_const_type
:
5021 read_tag_const_type (die
, objfile
, cu_header
);
5023 case DW_TAG_volatile_type
:
5024 read_tag_volatile_type (die
, objfile
, cu_header
);
5026 case DW_TAG_string_type
:
5027 read_tag_string_type (die
, objfile
);
5029 case DW_TAG_typedef
:
5030 read_typedef (die
, objfile
, cu_header
);
5032 case DW_TAG_base_type
:
5033 read_base_type (die
, objfile
);
5036 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
5041 static struct type
*
5042 dwarf_base_type (int encoding
, int size
, struct objfile
*objfile
)
5044 /* FIXME - this should not produce a new (struct type *)
5045 every time. It should cache base types. */
5049 case DW_ATE_address
:
5050 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
5052 case DW_ATE_boolean
:
5053 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
5055 case DW_ATE_complex_float
:
5058 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
5062 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
5068 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
5072 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
5079 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5082 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
5086 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5090 case DW_ATE_signed_char
:
5091 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5093 case DW_ATE_unsigned
:
5097 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5100 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
5104 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
5108 case DW_ATE_unsigned_char
:
5109 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5112 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5119 copy_die (struct die_info
*old_die
)
5121 struct die_info
*new_die
;
5124 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5125 memset (new_die
, 0, sizeof (struct die_info
));
5127 new_die
->tag
= old_die
->tag
;
5128 new_die
->has_children
= old_die
->has_children
;
5129 new_die
->abbrev
= old_die
->abbrev
;
5130 new_die
->offset
= old_die
->offset
;
5131 new_die
->type
= NULL
;
5133 num_attrs
= old_die
->num_attrs
;
5134 new_die
->num_attrs
= num_attrs
;
5135 new_die
->attrs
= (struct attribute
*)
5136 xmalloc (num_attrs
* sizeof (struct attribute
));
5138 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
5140 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
5141 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
5142 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
5145 new_die
->next
= NULL
;
5150 /* Return sibling of die, NULL if no sibling. */
5152 static struct die_info
*
5153 sibling_die (struct die_info
*die
)
5155 int nesting_level
= 0;
5157 if (!die
->has_children
)
5159 if (die
->next
&& (die
->next
->tag
== 0))
5172 if (die
->has_children
)
5182 while (nesting_level
);
5183 if (die
&& (die
->tag
== 0))
5194 /* Get linkage name of a die, return NULL if not found. */
5197 dwarf2_linkage_name (struct die_info
*die
)
5199 struct attribute
*attr
;
5201 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
5202 if (attr
&& DW_STRING (attr
))
5203 return DW_STRING (attr
);
5204 attr
= dwarf_attr (die
, DW_AT_name
);
5205 if (attr
&& DW_STRING (attr
))
5206 return DW_STRING (attr
);
5210 /* Convert a DIE tag into its string name. */
5213 dwarf_tag_name (register unsigned tag
)
5217 case DW_TAG_padding
:
5218 return "DW_TAG_padding";
5219 case DW_TAG_array_type
:
5220 return "DW_TAG_array_type";
5221 case DW_TAG_class_type
:
5222 return "DW_TAG_class_type";
5223 case DW_TAG_entry_point
:
5224 return "DW_TAG_entry_point";
5225 case DW_TAG_enumeration_type
:
5226 return "DW_TAG_enumeration_type";
5227 case DW_TAG_formal_parameter
:
5228 return "DW_TAG_formal_parameter";
5229 case DW_TAG_imported_declaration
:
5230 return "DW_TAG_imported_declaration";
5232 return "DW_TAG_label";
5233 case DW_TAG_lexical_block
:
5234 return "DW_TAG_lexical_block";
5236 return "DW_TAG_member";
5237 case DW_TAG_pointer_type
:
5238 return "DW_TAG_pointer_type";
5239 case DW_TAG_reference_type
:
5240 return "DW_TAG_reference_type";
5241 case DW_TAG_compile_unit
:
5242 return "DW_TAG_compile_unit";
5243 case DW_TAG_string_type
:
5244 return "DW_TAG_string_type";
5245 case DW_TAG_structure_type
:
5246 return "DW_TAG_structure_type";
5247 case DW_TAG_subroutine_type
:
5248 return "DW_TAG_subroutine_type";
5249 case DW_TAG_typedef
:
5250 return "DW_TAG_typedef";
5251 case DW_TAG_union_type
:
5252 return "DW_TAG_union_type";
5253 case DW_TAG_unspecified_parameters
:
5254 return "DW_TAG_unspecified_parameters";
5255 case DW_TAG_variant
:
5256 return "DW_TAG_variant";
5257 case DW_TAG_common_block
:
5258 return "DW_TAG_common_block";
5259 case DW_TAG_common_inclusion
:
5260 return "DW_TAG_common_inclusion";
5261 case DW_TAG_inheritance
:
5262 return "DW_TAG_inheritance";
5263 case DW_TAG_inlined_subroutine
:
5264 return "DW_TAG_inlined_subroutine";
5266 return "DW_TAG_module";
5267 case DW_TAG_ptr_to_member_type
:
5268 return "DW_TAG_ptr_to_member_type";
5269 case DW_TAG_set_type
:
5270 return "DW_TAG_set_type";
5271 case DW_TAG_subrange_type
:
5272 return "DW_TAG_subrange_type";
5273 case DW_TAG_with_stmt
:
5274 return "DW_TAG_with_stmt";
5275 case DW_TAG_access_declaration
:
5276 return "DW_TAG_access_declaration";
5277 case DW_TAG_base_type
:
5278 return "DW_TAG_base_type";
5279 case DW_TAG_catch_block
:
5280 return "DW_TAG_catch_block";
5281 case DW_TAG_const_type
:
5282 return "DW_TAG_const_type";
5283 case DW_TAG_constant
:
5284 return "DW_TAG_constant";
5285 case DW_TAG_enumerator
:
5286 return "DW_TAG_enumerator";
5287 case DW_TAG_file_type
:
5288 return "DW_TAG_file_type";
5290 return "DW_TAG_friend";
5291 case DW_TAG_namelist
:
5292 return "DW_TAG_namelist";
5293 case DW_TAG_namelist_item
:
5294 return "DW_TAG_namelist_item";
5295 case DW_TAG_packed_type
:
5296 return "DW_TAG_packed_type";
5297 case DW_TAG_subprogram
:
5298 return "DW_TAG_subprogram";
5299 case DW_TAG_template_type_param
:
5300 return "DW_TAG_template_type_param";
5301 case DW_TAG_template_value_param
:
5302 return "DW_TAG_template_value_param";
5303 case DW_TAG_thrown_type
:
5304 return "DW_TAG_thrown_type";
5305 case DW_TAG_try_block
:
5306 return "DW_TAG_try_block";
5307 case DW_TAG_variant_part
:
5308 return "DW_TAG_variant_part";
5309 case DW_TAG_variable
:
5310 return "DW_TAG_variable";
5311 case DW_TAG_volatile_type
:
5312 return "DW_TAG_volatile_type";
5313 case DW_TAG_MIPS_loop
:
5314 return "DW_TAG_MIPS_loop";
5315 case DW_TAG_format_label
:
5316 return "DW_TAG_format_label";
5317 case DW_TAG_function_template
:
5318 return "DW_TAG_function_template";
5319 case DW_TAG_class_template
:
5320 return "DW_TAG_class_template";
5322 return "DW_TAG_<unknown>";
5326 /* Convert a DWARF attribute code into its string name. */
5329 dwarf_attr_name (register unsigned attr
)
5334 return "DW_AT_sibling";
5335 case DW_AT_location
:
5336 return "DW_AT_location";
5338 return "DW_AT_name";
5339 case DW_AT_ordering
:
5340 return "DW_AT_ordering";
5341 case DW_AT_subscr_data
:
5342 return "DW_AT_subscr_data";
5343 case DW_AT_byte_size
:
5344 return "DW_AT_byte_size";
5345 case DW_AT_bit_offset
:
5346 return "DW_AT_bit_offset";
5347 case DW_AT_bit_size
:
5348 return "DW_AT_bit_size";
5349 case DW_AT_element_list
:
5350 return "DW_AT_element_list";
5351 case DW_AT_stmt_list
:
5352 return "DW_AT_stmt_list";
5354 return "DW_AT_low_pc";
5356 return "DW_AT_high_pc";
5357 case DW_AT_language
:
5358 return "DW_AT_language";
5360 return "DW_AT_member";
5362 return "DW_AT_discr";
5363 case DW_AT_discr_value
:
5364 return "DW_AT_discr_value";
5365 case DW_AT_visibility
:
5366 return "DW_AT_visibility";
5368 return "DW_AT_import";
5369 case DW_AT_string_length
:
5370 return "DW_AT_string_length";
5371 case DW_AT_common_reference
:
5372 return "DW_AT_common_reference";
5373 case DW_AT_comp_dir
:
5374 return "DW_AT_comp_dir";
5375 case DW_AT_const_value
:
5376 return "DW_AT_const_value";
5377 case DW_AT_containing_type
:
5378 return "DW_AT_containing_type";
5379 case DW_AT_default_value
:
5380 return "DW_AT_default_value";
5382 return "DW_AT_inline";
5383 case DW_AT_is_optional
:
5384 return "DW_AT_is_optional";
5385 case DW_AT_lower_bound
:
5386 return "DW_AT_lower_bound";
5387 case DW_AT_producer
:
5388 return "DW_AT_producer";
5389 case DW_AT_prototyped
:
5390 return "DW_AT_prototyped";
5391 case DW_AT_return_addr
:
5392 return "DW_AT_return_addr";
5393 case DW_AT_start_scope
:
5394 return "DW_AT_start_scope";
5395 case DW_AT_stride_size
:
5396 return "DW_AT_stride_size";
5397 case DW_AT_upper_bound
:
5398 return "DW_AT_upper_bound";
5399 case DW_AT_abstract_origin
:
5400 return "DW_AT_abstract_origin";
5401 case DW_AT_accessibility
:
5402 return "DW_AT_accessibility";
5403 case DW_AT_address_class
:
5404 return "DW_AT_address_class";
5405 case DW_AT_artificial
:
5406 return "DW_AT_artificial";
5407 case DW_AT_base_types
:
5408 return "DW_AT_base_types";
5409 case DW_AT_calling_convention
:
5410 return "DW_AT_calling_convention";
5412 return "DW_AT_count";
5413 case DW_AT_data_member_location
:
5414 return "DW_AT_data_member_location";
5415 case DW_AT_decl_column
:
5416 return "DW_AT_decl_column";
5417 case DW_AT_decl_file
:
5418 return "DW_AT_decl_file";
5419 case DW_AT_decl_line
:
5420 return "DW_AT_decl_line";
5421 case DW_AT_declaration
:
5422 return "DW_AT_declaration";
5423 case DW_AT_discr_list
:
5424 return "DW_AT_discr_list";
5425 case DW_AT_encoding
:
5426 return "DW_AT_encoding";
5427 case DW_AT_external
:
5428 return "DW_AT_external";
5429 case DW_AT_frame_base
:
5430 return "DW_AT_frame_base";
5432 return "DW_AT_friend";
5433 case DW_AT_identifier_case
:
5434 return "DW_AT_identifier_case";
5435 case DW_AT_macro_info
:
5436 return "DW_AT_macro_info";
5437 case DW_AT_namelist_items
:
5438 return "DW_AT_namelist_items";
5439 case DW_AT_priority
:
5440 return "DW_AT_priority";
5442 return "DW_AT_segment";
5443 case DW_AT_specification
:
5444 return "DW_AT_specification";
5445 case DW_AT_static_link
:
5446 return "DW_AT_static_link";
5448 return "DW_AT_type";
5449 case DW_AT_use_location
:
5450 return "DW_AT_use_location";
5451 case DW_AT_variable_parameter
:
5452 return "DW_AT_variable_parameter";
5453 case DW_AT_virtuality
:
5454 return "DW_AT_virtuality";
5455 case DW_AT_vtable_elem_location
:
5456 return "DW_AT_vtable_elem_location";
5459 case DW_AT_MIPS_fde
:
5460 return "DW_AT_MIPS_fde";
5461 case DW_AT_MIPS_loop_begin
:
5462 return "DW_AT_MIPS_loop_begin";
5463 case DW_AT_MIPS_tail_loop_begin
:
5464 return "DW_AT_MIPS_tail_loop_begin";
5465 case DW_AT_MIPS_epilog_begin
:
5466 return "DW_AT_MIPS_epilog_begin";
5467 case DW_AT_MIPS_loop_unroll_factor
:
5468 return "DW_AT_MIPS_loop_unroll_factor";
5469 case DW_AT_MIPS_software_pipeline_depth
:
5470 return "DW_AT_MIPS_software_pipeline_depth";
5471 case DW_AT_MIPS_linkage_name
:
5472 return "DW_AT_MIPS_linkage_name";
5475 case DW_AT_sf_names
:
5476 return "DW_AT_sf_names";
5477 case DW_AT_src_info
:
5478 return "DW_AT_src_info";
5479 case DW_AT_mac_info
:
5480 return "DW_AT_mac_info";
5481 case DW_AT_src_coords
:
5482 return "DW_AT_src_coords";
5483 case DW_AT_body_begin
:
5484 return "DW_AT_body_begin";
5485 case DW_AT_body_end
:
5486 return "DW_AT_body_end";
5487 case DW_AT_GNU_vector
:
5488 return "DW_AT_GNU_vector";
5490 return "DW_AT_<unknown>";
5494 /* Convert a DWARF value form code into its string name. */
5497 dwarf_form_name (register unsigned form
)
5502 return "DW_FORM_addr";
5503 case DW_FORM_block2
:
5504 return "DW_FORM_block2";
5505 case DW_FORM_block4
:
5506 return "DW_FORM_block4";
5508 return "DW_FORM_data2";
5510 return "DW_FORM_data4";
5512 return "DW_FORM_data8";
5513 case DW_FORM_string
:
5514 return "DW_FORM_string";
5516 return "DW_FORM_block";
5517 case DW_FORM_block1
:
5518 return "DW_FORM_block1";
5520 return "DW_FORM_data1";
5522 return "DW_FORM_flag";
5524 return "DW_FORM_sdata";
5526 return "DW_FORM_strp";
5528 return "DW_FORM_udata";
5529 case DW_FORM_ref_addr
:
5530 return "DW_FORM_ref_addr";
5532 return "DW_FORM_ref1";
5534 return "DW_FORM_ref2";
5536 return "DW_FORM_ref4";
5538 return "DW_FORM_ref8";
5539 case DW_FORM_ref_udata
:
5540 return "DW_FORM_ref_udata";
5541 case DW_FORM_indirect
:
5542 return "DW_FORM_indirect";
5544 return "DW_FORM_<unknown>";
5548 /* Convert a DWARF stack opcode into its string name. */
5551 dwarf_stack_op_name (register unsigned op
)
5556 return "DW_OP_addr";
5558 return "DW_OP_deref";
5560 return "DW_OP_const1u";
5562 return "DW_OP_const1s";
5564 return "DW_OP_const2u";
5566 return "DW_OP_const2s";
5568 return "DW_OP_const4u";
5570 return "DW_OP_const4s";
5572 return "DW_OP_const8u";
5574 return "DW_OP_const8s";
5576 return "DW_OP_constu";
5578 return "DW_OP_consts";
5582 return "DW_OP_drop";
5584 return "DW_OP_over";
5586 return "DW_OP_pick";
5588 return "DW_OP_swap";
5592 return "DW_OP_xderef";
5600 return "DW_OP_minus";
5612 return "DW_OP_plus";
5613 case DW_OP_plus_uconst
:
5614 return "DW_OP_plus_uconst";
5620 return "DW_OP_shra";
5638 return "DW_OP_skip";
5640 return "DW_OP_lit0";
5642 return "DW_OP_lit1";
5644 return "DW_OP_lit2";
5646 return "DW_OP_lit3";
5648 return "DW_OP_lit4";
5650 return "DW_OP_lit5";
5652 return "DW_OP_lit6";
5654 return "DW_OP_lit7";
5656 return "DW_OP_lit8";
5658 return "DW_OP_lit9";
5660 return "DW_OP_lit10";
5662 return "DW_OP_lit11";
5664 return "DW_OP_lit12";
5666 return "DW_OP_lit13";
5668 return "DW_OP_lit14";
5670 return "DW_OP_lit15";
5672 return "DW_OP_lit16";
5674 return "DW_OP_lit17";
5676 return "DW_OP_lit18";
5678 return "DW_OP_lit19";
5680 return "DW_OP_lit20";
5682 return "DW_OP_lit21";
5684 return "DW_OP_lit22";
5686 return "DW_OP_lit23";
5688 return "DW_OP_lit24";
5690 return "DW_OP_lit25";
5692 return "DW_OP_lit26";
5694 return "DW_OP_lit27";
5696 return "DW_OP_lit28";
5698 return "DW_OP_lit29";
5700 return "DW_OP_lit30";
5702 return "DW_OP_lit31";
5704 return "DW_OP_reg0";
5706 return "DW_OP_reg1";
5708 return "DW_OP_reg2";
5710 return "DW_OP_reg3";
5712 return "DW_OP_reg4";
5714 return "DW_OP_reg5";
5716 return "DW_OP_reg6";
5718 return "DW_OP_reg7";
5720 return "DW_OP_reg8";
5722 return "DW_OP_reg9";
5724 return "DW_OP_reg10";
5726 return "DW_OP_reg11";
5728 return "DW_OP_reg12";
5730 return "DW_OP_reg13";
5732 return "DW_OP_reg14";
5734 return "DW_OP_reg15";
5736 return "DW_OP_reg16";
5738 return "DW_OP_reg17";
5740 return "DW_OP_reg18";
5742 return "DW_OP_reg19";
5744 return "DW_OP_reg20";
5746 return "DW_OP_reg21";
5748 return "DW_OP_reg22";
5750 return "DW_OP_reg23";
5752 return "DW_OP_reg24";
5754 return "DW_OP_reg25";
5756 return "DW_OP_reg26";
5758 return "DW_OP_reg27";
5760 return "DW_OP_reg28";
5762 return "DW_OP_reg29";
5764 return "DW_OP_reg30";
5766 return "DW_OP_reg31";
5768 return "DW_OP_breg0";
5770 return "DW_OP_breg1";
5772 return "DW_OP_breg2";
5774 return "DW_OP_breg3";
5776 return "DW_OP_breg4";
5778 return "DW_OP_breg5";
5780 return "DW_OP_breg6";
5782 return "DW_OP_breg7";
5784 return "DW_OP_breg8";
5786 return "DW_OP_breg9";
5788 return "DW_OP_breg10";
5790 return "DW_OP_breg11";
5792 return "DW_OP_breg12";
5794 return "DW_OP_breg13";
5796 return "DW_OP_breg14";
5798 return "DW_OP_breg15";
5800 return "DW_OP_breg16";
5802 return "DW_OP_breg17";
5804 return "DW_OP_breg18";
5806 return "DW_OP_breg19";
5808 return "DW_OP_breg20";
5810 return "DW_OP_breg21";
5812 return "DW_OP_breg22";
5814 return "DW_OP_breg23";
5816 return "DW_OP_breg24";
5818 return "DW_OP_breg25";
5820 return "DW_OP_breg26";
5822 return "DW_OP_breg27";
5824 return "DW_OP_breg28";
5826 return "DW_OP_breg29";
5828 return "DW_OP_breg30";
5830 return "DW_OP_breg31";
5832 return "DW_OP_regx";
5834 return "DW_OP_fbreg";
5836 return "DW_OP_bregx";
5838 return "DW_OP_piece";
5839 case DW_OP_deref_size
:
5840 return "DW_OP_deref_size";
5841 case DW_OP_xderef_size
:
5842 return "DW_OP_xderef_size";
5846 return "OP_<unknown>";
5851 dwarf_bool_name (unsigned mybool
)
5859 /* Convert a DWARF type code into its string name. */
5862 dwarf_type_encoding_name (register unsigned enc
)
5866 case DW_ATE_address
:
5867 return "DW_ATE_address";
5868 case DW_ATE_boolean
:
5869 return "DW_ATE_boolean";
5870 case DW_ATE_complex_float
:
5871 return "DW_ATE_complex_float";
5873 return "DW_ATE_float";
5875 return "DW_ATE_signed";
5876 case DW_ATE_signed_char
:
5877 return "DW_ATE_signed_char";
5878 case DW_ATE_unsigned
:
5879 return "DW_ATE_unsigned";
5880 case DW_ATE_unsigned_char
:
5881 return "DW_ATE_unsigned_char";
5883 return "DW_ATE_<unknown>";
5887 /* Convert a DWARF call frame info operation to its string name. */
5891 dwarf_cfi_name (register unsigned cfi_opc
)
5895 case DW_CFA_advance_loc
:
5896 return "DW_CFA_advance_loc";
5898 return "DW_CFA_offset";
5899 case DW_CFA_restore
:
5900 return "DW_CFA_restore";
5902 return "DW_CFA_nop";
5903 case DW_CFA_set_loc
:
5904 return "DW_CFA_set_loc";
5905 case DW_CFA_advance_loc1
:
5906 return "DW_CFA_advance_loc1";
5907 case DW_CFA_advance_loc2
:
5908 return "DW_CFA_advance_loc2";
5909 case DW_CFA_advance_loc4
:
5910 return "DW_CFA_advance_loc4";
5911 case DW_CFA_offset_extended
:
5912 return "DW_CFA_offset_extended";
5913 case DW_CFA_restore_extended
:
5914 return "DW_CFA_restore_extended";
5915 case DW_CFA_undefined
:
5916 return "DW_CFA_undefined";
5917 case DW_CFA_same_value
:
5918 return "DW_CFA_same_value";
5919 case DW_CFA_register
:
5920 return "DW_CFA_register";
5921 case DW_CFA_remember_state
:
5922 return "DW_CFA_remember_state";
5923 case DW_CFA_restore_state
:
5924 return "DW_CFA_restore_state";
5925 case DW_CFA_def_cfa
:
5926 return "DW_CFA_def_cfa";
5927 case DW_CFA_def_cfa_register
:
5928 return "DW_CFA_def_cfa_register";
5929 case DW_CFA_def_cfa_offset
:
5930 return "DW_CFA_def_cfa_offset";
5933 case DW_CFA_def_cfa_expression
:
5934 return "DW_CFA_def_cfa_expression";
5935 case DW_CFA_expression
:
5936 return "DW_CFA_expression";
5937 case DW_CFA_offset_extended_sf
:
5938 return "DW_CFA_offset_extended_sf";
5939 case DW_CFA_def_cfa_sf
:
5940 return "DW_CFA_def_cfa_sf";
5941 case DW_CFA_def_cfa_offset_sf
:
5942 return "DW_CFA_def_cfa_offset_sf";
5944 /* SGI/MIPS specific */
5945 case DW_CFA_MIPS_advance_loc8
:
5946 return "DW_CFA_MIPS_advance_loc8";
5948 /* GNU extensions */
5949 case DW_CFA_GNU_window_save
:
5950 return "DW_CFA_GNU_window_save";
5951 case DW_CFA_GNU_args_size
:
5952 return "DW_CFA_GNU_args_size";
5953 case DW_CFA_GNU_negative_offset_extended
:
5954 return "DW_CFA_GNU_negative_offset_extended";
5957 return "DW_CFA_<unknown>";
5963 dump_die (struct die_info
*die
)
5967 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5968 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5969 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
5970 dwarf_bool_name (die
->has_children
));
5972 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
5973 for (i
= 0; i
< die
->num_attrs
; ++i
)
5975 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
5976 dwarf_attr_name (die
->attrs
[i
].name
),
5977 dwarf_form_name (die
->attrs
[i
].form
));
5978 switch (die
->attrs
[i
].form
)
5980 case DW_FORM_ref_addr
:
5982 fprintf_unfiltered (gdb_stderr
, "address: ");
5983 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
5985 case DW_FORM_block2
:
5986 case DW_FORM_block4
:
5988 case DW_FORM_block1
:
5989 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
6000 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
6002 case DW_FORM_string
:
6004 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
6005 DW_STRING (&die
->attrs
[i
])
6006 ? DW_STRING (&die
->attrs
[i
]) : "");
6009 if (DW_UNSND (&die
->attrs
[i
]))
6010 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
6012 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
6014 case DW_FORM_indirect
:
6015 /* the reader will have reduced the indirect form to
6016 the "base form" so this form should not occur */
6017 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
6020 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
6021 die
->attrs
[i
].form
);
6023 fprintf_unfiltered (gdb_stderr
, "\n");
6028 dump_die_list (struct die_info
*die
)
6038 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
6041 struct die_info
*old
;
6043 h
= (offset
% REF_HASH_SIZE
);
6044 old
= die_ref_table
[h
];
6045 die
->next_ref
= old
;
6046 die_ref_table
[h
] = die
;
6051 dwarf2_empty_hash_tables (void)
6053 memset (die_ref_table
, 0, sizeof (die_ref_table
));
6057 dwarf2_get_ref_die_offset (struct attribute
*attr
)
6059 unsigned int result
= 0;
6063 case DW_FORM_ref_addr
:
6064 result
= DW_ADDR (attr
);
6070 case DW_FORM_ref_udata
:
6071 result
= cu_header_offset
+ DW_UNSND (attr
);
6074 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
6079 static struct die_info
*
6080 follow_die_ref (unsigned int offset
)
6082 struct die_info
*die
;
6085 h
= (offset
% REF_HASH_SIZE
);
6086 die
= die_ref_table
[h
];
6089 if (die
->offset
== offset
)
6093 die
= die
->next_ref
;
6098 static struct type
*
6099 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
6101 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
6103 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
6107 /* Look for this particular type in the fundamental type vector. If
6108 one is not found, create and install one appropriate for the
6109 current language and the current target machine. */
6111 if (ftypes
[typeid] == NULL
)
6113 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
6116 return (ftypes
[typeid]);
6119 /* Decode simple location descriptions.
6120 Given a pointer to a dwarf block that defines a location, compute
6121 the location and return the value.
6123 FIXME: This is a kludge until we figure out a better
6124 way to handle the location descriptions.
6125 Gdb's design does not mesh well with the DWARF2 notion of a location
6126 computing interpreter, which is a shame because the flexibility goes unused.
6127 FIXME: Implement more operations as necessary.
6129 A location description containing no operations indicates that the
6130 object is optimized out. The global optimized_out flag is set for
6131 those, the return value is meaningless.
6133 When the result is a register number, the global isreg flag is set,
6134 otherwise it is cleared.
6136 When the result is a base register offset, the global offreg flag is set
6137 and the register number is returned in basereg, otherwise it is cleared.
6139 When the DW_OP_fbreg operation is encountered without a corresponding
6140 DW_AT_frame_base attribute, the global islocal flag is set.
6141 Hopefully the machine dependent code knows how to set up a virtual
6142 frame pointer for the local references.
6144 Note that stack[0] is unused except as a default error return.
6145 Note that stack overflow is not yet handled. */
6148 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
6149 const struct comp_unit_head
*cu_header
)
6152 int size
= blk
->size
;
6153 char *data
= blk
->data
;
6154 CORE_ADDR stack
[64];
6156 unsigned int bytes_read
, unsnd
;
6206 stack
[++stacki
] = op
- DW_OP_lit0
;
6242 stack
[++stacki
] = op
- DW_OP_reg0
;
6247 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6249 #if defined(HARRIS_TARGET) && defined(_M88K)
6250 /* The Harris 88110 gdb ports have long kept their special reg
6251 numbers between their gp-regs and their x-regs. This is
6252 not how our dwarf is generated. Punt. */
6255 stack
[++stacki
] = unsnd
;
6291 basereg
= op
- DW_OP_breg0
;
6292 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6298 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6300 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6305 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6307 if (frame_base_reg
>= 0)
6310 basereg
= frame_base_reg
;
6311 stack
[stacki
] += frame_base_offset
;
6315 complain (&dwarf2_missing_at_frame_base
);
6321 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
6322 cu_header
, &bytes_read
);
6327 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
6332 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
6337 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
6342 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
6347 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
6352 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
6357 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
6363 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6368 stack
[stacki
+ 1] = stack
[stacki
];
6373 stack
[stacki
- 1] += stack
[stacki
];
6377 case DW_OP_plus_uconst
:
6378 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6383 stack
[stacki
- 1] -= stack
[stacki
];
6389 /* If we're not the last op, then we definitely can't encode
6390 this using GDB's address_class enum. */
6392 complain (&dwarf2_complex_location_expr
);
6396 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
6397 return (stack
[stacki
]);
6400 return (stack
[stacki
]);
6403 /* memory allocation interface */
6407 dwarf2_free_tmp_obstack (PTR ignore
)
6409 obstack_free (&dwarf2_tmp_obstack
, NULL
);
6412 static struct dwarf_block
*
6413 dwarf_alloc_block (void)
6415 struct dwarf_block
*blk
;
6417 blk
= (struct dwarf_block
*)
6418 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
6422 static struct abbrev_info
*
6423 dwarf_alloc_abbrev (void)
6425 struct abbrev_info
*abbrev
;
6427 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
6428 memset (abbrev
, 0, sizeof (struct abbrev_info
));
6432 static struct die_info
*
6433 dwarf_alloc_die (void)
6435 struct die_info
*die
;
6437 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6438 memset (die
, 0, sizeof (struct die_info
));
6443 /* Macro support. */
6446 /* Return the full name of file number I in *LH's file name table.
6447 Use COMP_DIR as the name of the current directory of the
6448 compilation. The result is allocated using xmalloc; the caller is
6449 responsible for freeing it. */
6451 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
6453 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
6455 if (IS_ABSOLUTE_PATH (fe
->name
))
6456 return xstrdup (fe
->name
);
6464 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6470 dir_len
= strlen (dir
);
6471 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
6472 strcpy (full_name
, dir
);
6473 full_name
[dir_len
] = '/';
6474 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
6478 return xstrdup (fe
->name
);
6483 static struct macro_source_file
*
6484 macro_start_file (int file
, int line
,
6485 struct macro_source_file
*current_file
,
6486 const char *comp_dir
,
6487 struct line_header
*lh
, struct objfile
*objfile
)
6489 /* The full name of this source file. */
6490 char *full_name
= file_full_name (file
, lh
, comp_dir
);
6492 /* We don't create a macro table for this compilation unit
6493 at all until we actually get a filename. */
6494 if (! pending_macros
)
6495 pending_macros
= new_macro_table (&objfile
->symbol_obstack
,
6496 &objfile
->macro_cache
);
6499 /* If we have no current file, then this must be the start_file
6500 directive for the compilation unit's main source file. */
6501 current_file
= macro_set_main (pending_macros
, full_name
);
6503 current_file
= macro_include (current_file
, line
, full_name
);
6507 return current_file
;
6511 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
6512 followed by a null byte. */
6514 copy_string (const char *buf
, int len
)
6516 char *s
= xmalloc (len
+ 1);
6517 memcpy (s
, buf
, len
);
6525 consume_improper_spaces (const char *p
, const char *body
)
6529 complain (&dwarf2_macro_spaces_in_definition
, body
);
6540 parse_macro_definition (struct macro_source_file
*file
, int line
,
6545 /* The body string takes one of two forms. For object-like macro
6546 definitions, it should be:
6548 <macro name> " " <definition>
6550 For function-like macro definitions, it should be:
6552 <macro name> "() " <definition>
6554 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
6556 Spaces may appear only where explicitly indicated, and in the
6559 The Dwarf 2 spec says that an object-like macro's name is always
6560 followed by a space, but versions of GCC around March 2002 omit
6561 the space when the macro's definition is the empty string.
6563 The Dwarf 2 spec says that there should be no spaces between the
6564 formal arguments in a function-like macro's formal argument list,
6565 but versions of GCC around March 2002 include spaces after the
6569 /* Find the extent of the macro name. The macro name is terminated
6570 by either a space or null character (for an object-like macro) or
6571 an opening paren (for a function-like macro). */
6572 for (p
= body
; *p
; p
++)
6573 if (*p
== ' ' || *p
== '(')
6576 if (*p
== ' ' || *p
== '\0')
6578 /* It's an object-like macro. */
6579 int name_len
= p
- body
;
6580 char *name
= copy_string (body
, name_len
);
6581 const char *replacement
;
6584 replacement
= body
+ name_len
+ 1;
6587 complain (&dwarf2_macro_malformed_definition
, body
);
6588 replacement
= body
+ name_len
;
6591 macro_define_object (file
, line
, name
, replacement
);
6597 /* It's a function-like macro. */
6598 char *name
= copy_string (body
, p
- body
);
6601 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
6605 p
= consume_improper_spaces (p
, body
);
6607 /* Parse the formal argument list. */
6608 while (*p
&& *p
!= ')')
6610 /* Find the extent of the current argument name. */
6611 const char *arg_start
= p
;
6613 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
6616 if (! *p
|| p
== arg_start
)
6617 complain (&dwarf2_macro_malformed_definition
,
6621 /* Make sure argv has room for the new argument. */
6622 if (argc
>= argv_size
)
6625 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
6628 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
6631 p
= consume_improper_spaces (p
, body
);
6633 /* Consume the comma, if present. */
6638 p
= consume_improper_spaces (p
, body
);
6647 /* Perfectly formed definition, no complaints. */
6648 macro_define_function (file
, line
, name
,
6649 argc
, (const char **) argv
,
6651 else if (*p
== '\0')
6653 /* Complain, but do define it. */
6654 complain (&dwarf2_macro_malformed_definition
, body
);
6655 macro_define_function (file
, line
, name
,
6656 argc
, (const char **) argv
,
6660 /* Just complain. */
6661 complain (&dwarf2_macro_malformed_definition
, body
);
6664 /* Just complain. */
6665 complain (&dwarf2_macro_malformed_definition
, body
);
6671 for (i
= 0; i
< argc
; i
++)
6677 complain (&dwarf2_macro_malformed_definition
, body
);
6682 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
6683 char *comp_dir
, bfd
*abfd
,
6684 const struct comp_unit_head
*cu_header
,
6685 struct objfile
*objfile
)
6687 char *mac_ptr
, *mac_end
;
6688 struct macro_source_file
*current_file
= 0;
6690 if (dwarf_macinfo_buffer
== NULL
)
6692 complain (&dwarf2_missing_macinfo_section
);
6696 mac_ptr
= dwarf_macinfo_buffer
+ offset
;
6697 mac_end
= dwarf_macinfo_buffer
+ dwarf_macinfo_size
;
6701 enum dwarf_macinfo_record_type macinfo_type
;
6703 /* Do we at least have room for a macinfo type byte? */
6704 if (mac_ptr
>= mac_end
)
6706 complain (&dwarf2_macros_too_long
);
6710 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
6713 switch (macinfo_type
)
6715 /* A zero macinfo type indicates the end of the macro
6720 case DW_MACINFO_define
:
6721 case DW_MACINFO_undef
:
6727 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
6728 mac_ptr
+= bytes_read
;
6729 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
6730 mac_ptr
+= bytes_read
;
6733 complain (&dwarf2_macro_outside_file
,
6734 macinfo_type
== DW_MACINFO_define
? "definition" :
6735 macinfo_type
== DW_MACINFO_undef
? "undefinition" :
6736 "something-or-other",
6740 if (macinfo_type
== DW_MACINFO_define
)
6741 parse_macro_definition (current_file
, line
, body
);
6742 else if (macinfo_type
== DW_MACINFO_undef
)
6743 macro_undef (current_file
, line
, body
);
6748 case DW_MACINFO_start_file
:
6753 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
6754 mac_ptr
+= bytes_read
;
6755 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
6756 mac_ptr
+= bytes_read
;
6758 current_file
= macro_start_file (file
, line
,
6759 current_file
, comp_dir
,
6764 case DW_MACINFO_end_file
:
6766 complain (&dwarf2_macro_unmatched_end_file
);
6769 current_file
= current_file
->included_by
;
6772 enum dwarf_macinfo_record_type next_type
;
6774 /* GCC circa March 2002 doesn't produce the zero
6775 type byte marking the end of the compilation
6776 unit. Complain if it's not there, but exit no
6779 /* Do we at least have room for a macinfo type byte? */
6780 if (mac_ptr
>= mac_end
)
6782 complain (&dwarf2_macros_too_long
);
6786 /* We don't increment mac_ptr here, so this is just
6788 next_type
= read_1_byte (abfd
, mac_ptr
);
6790 complain (&dwarf2_macros_not_terminated
);
6797 case DW_MACINFO_vendor_ext
:
6803 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
6804 mac_ptr
+= bytes_read
;
6805 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
6806 mac_ptr
+= bytes_read
;
6808 /* We don't recognize any vendor extensions. */