1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
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 */
42 #include "complaints.h"
44 #include "dwarf2expr.h"
45 #include "dwarf2loc.h"
46 #include "cp-support.h"
49 #include "gdb_string.h"
50 #include "gdb_assert.h"
51 #include <sys/types.h>
53 #ifndef DWARF2_REG_TO_REGNUM
54 #define DWARF2_REG_TO_REGNUM(REG) (REG)
58 /* .debug_info header for a compilation unit
59 Because of alignment constraints, this structure has padding and cannot
60 be mapped directly onto the beginning of the .debug_info section. */
61 typedef struct comp_unit_header
63 unsigned int length
; /* length of the .debug_info
65 unsigned short version
; /* version number -- 2 for DWARF
67 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
68 unsigned char addr_size
; /* byte size of an address -- 4 */
71 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
74 /* .debug_pubnames header
75 Because of alignment constraints, this structure has padding and cannot
76 be mapped directly onto the beginning of the .debug_info section. */
77 typedef struct pubnames_header
79 unsigned int length
; /* length of the .debug_pubnames
81 unsigned char version
; /* version number -- 2 for DWARF
83 unsigned int info_offset
; /* offset into .debug_info section */
84 unsigned int info_size
; /* byte size of .debug_info section
88 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
90 /* .debug_pubnames header
91 Because of alignment constraints, this structure has padding and cannot
92 be mapped directly onto the beginning of the .debug_info section. */
93 typedef struct aranges_header
95 unsigned int length
; /* byte len of the .debug_aranges
97 unsigned short version
; /* version number -- 2 for DWARF
99 unsigned int info_offset
; /* offset into .debug_info section */
100 unsigned char addr_size
; /* byte size of an address */
101 unsigned char seg_size
; /* byte size of segment descriptor */
104 #define _ACTUAL_ARANGES_HEADER_SIZE 12
106 /* .debug_line statement program prologue
107 Because of alignment constraints, this structure has padding and cannot
108 be mapped directly onto the beginning of the .debug_info section. */
109 typedef struct statement_prologue
111 unsigned int total_length
; /* byte length of the statement
113 unsigned short version
; /* version number -- 2 for DWARF
115 unsigned int prologue_length
; /* # bytes between prologue &
117 unsigned char minimum_instruction_length
; /* byte size of
119 unsigned char default_is_stmt
; /* initial value of is_stmt
122 unsigned char line_range
;
123 unsigned char opcode_base
; /* number assigned to first special
125 unsigned char *standard_opcode_lengths
;
129 /* offsets and sizes of debugging sections */
131 static unsigned int dwarf_info_size
;
132 static unsigned int dwarf_abbrev_size
;
133 static unsigned int dwarf_line_size
;
134 static unsigned int dwarf_pubnames_size
;
135 static unsigned int dwarf_aranges_size
;
136 static unsigned int dwarf_loc_size
;
137 static unsigned int dwarf_macinfo_size
;
138 static unsigned int dwarf_str_size
;
139 static unsigned int dwarf_ranges_size
;
140 unsigned int dwarf_frame_size
;
141 unsigned int dwarf_eh_frame_size
;
143 static asection
*dwarf_info_section
;
144 static asection
*dwarf_abbrev_section
;
145 static asection
*dwarf_line_section
;
146 static asection
*dwarf_pubnames_section
;
147 static asection
*dwarf_aranges_section
;
148 static asection
*dwarf_loc_section
;
149 static asection
*dwarf_macinfo_section
;
150 static asection
*dwarf_str_section
;
151 static asection
*dwarf_ranges_section
;
152 asection
*dwarf_frame_section
;
153 asection
*dwarf_eh_frame_section
;
155 /* names of the debugging sections */
157 #define INFO_SECTION ".debug_info"
158 #define ABBREV_SECTION ".debug_abbrev"
159 #define LINE_SECTION ".debug_line"
160 #define PUBNAMES_SECTION ".debug_pubnames"
161 #define ARANGES_SECTION ".debug_aranges"
162 #define LOC_SECTION ".debug_loc"
163 #define MACINFO_SECTION ".debug_macinfo"
164 #define STR_SECTION ".debug_str"
165 #define RANGES_SECTION ".debug_ranges"
166 #define FRAME_SECTION ".debug_frame"
167 #define EH_FRAME_SECTION ".eh_frame"
169 /* local data types */
171 /* We hold several abbreviation tables in memory at the same time. */
172 #ifndef ABBREV_HASH_SIZE
173 #define ABBREV_HASH_SIZE 121
176 /* The data in a compilation unit header, after target2host
177 translation, looks like this. */
178 struct comp_unit_head
180 unsigned long length
;
182 unsigned int abbrev_offset
;
183 unsigned char addr_size
;
184 unsigned char signed_addr_p
;
185 unsigned int offset_size
; /* size of file offsets; either 4 or 8 */
186 unsigned int initial_length_size
; /* size of the length field; either
189 /* Offset to the first byte of this compilation unit header in the
190 * .debug_info section, for resolving relative reference dies. */
194 /* Pointer to this compilation unit header in the .debug_info
199 /* Pointer to the first die of this compilatio unit. This will
200 * be the first byte following the compilation unit header. */
204 /* Pointer to the next compilation unit header in the program. */
206 struct comp_unit_head
*next
;
208 /* DWARF abbreviation table associated with this compilation unit */
210 struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
212 /* Base address of this compilation unit. */
214 CORE_ADDR base_address
;
216 /* Non-zero if base_address has been set. */
221 /* Internal state when decoding a particular compilation unit. */
224 /* The objfile containing this compilation unit. */
225 struct objfile
*objfile
;
227 /* The header of the compilation unit.
229 FIXME drow/2003-11-10: Some of the things from the comp_unit_head
230 should be moved to the dwarf2_cu structure; for instance the abbrevs
232 struct comp_unit_head header
;
235 /* The line number information for a compilation unit (found in the
236 .debug_line section) begins with a "statement program header",
237 which contains the following information. */
240 unsigned int total_length
;
241 unsigned short version
;
242 unsigned int header_length
;
243 unsigned char minimum_instruction_length
;
244 unsigned char default_is_stmt
;
246 unsigned char line_range
;
247 unsigned char opcode_base
;
249 /* standard_opcode_lengths[i] is the number of operands for the
250 standard opcode whose value is i. This means that
251 standard_opcode_lengths[0] is unused, and the last meaningful
252 element is standard_opcode_lengths[opcode_base - 1]. */
253 unsigned char *standard_opcode_lengths
;
255 /* The include_directories table. NOTE! These strings are not
256 allocated with xmalloc; instead, they are pointers into
257 debug_line_buffer. If you try to free them, `free' will get
259 unsigned int num_include_dirs
, include_dirs_size
;
262 /* The file_names table. NOTE! These strings are not allocated
263 with xmalloc; instead, they are pointers into debug_line_buffer.
264 Don't try to free them directly. */
265 unsigned int num_file_names
, file_names_size
;
269 unsigned int dir_index
;
270 unsigned int mod_time
;
274 /* The start and end of the statement program following this
275 header. These point into dwarf_line_buffer. */
276 char *statement_program_start
, *statement_program_end
;
279 /* When we construct a partial symbol table entry we only
280 need this much information. */
281 struct partial_die_info
284 unsigned char has_children
;
285 unsigned char is_external
;
286 unsigned char is_declaration
;
287 unsigned char has_type
;
294 struct dwarf_block
*locdesc
;
295 unsigned int language
;
299 /* This data structure holds the information of an abbrev. */
302 unsigned int number
; /* number identifying abbrev */
303 enum dwarf_tag tag
; /* dwarf tag */
304 int has_children
; /* boolean */
305 unsigned int num_attrs
; /* number of attributes */
306 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
307 struct abbrev_info
*next
; /* next in chain */
312 enum dwarf_attribute name
;
313 enum dwarf_form form
;
316 /* This data structure holds a complete die structure. */
319 enum dwarf_tag tag
; /* Tag indicating type of die */
320 unsigned int abbrev
; /* Abbrev number */
321 unsigned int offset
; /* Offset in .debug_info section */
322 unsigned int num_attrs
; /* Number of attributes */
323 struct attribute
*attrs
; /* An array of attributes */
324 struct die_info
*next_ref
; /* Next die in ref hash table */
326 /* The dies in a compilation unit form an n-ary tree. PARENT
327 points to this die's parent; CHILD points to the first child of
328 this node; and all the children of a given node are chained
329 together via their SIBLING fields, terminated by a die whose
331 struct die_info
*child
; /* Its first child, if any. */
332 struct die_info
*sibling
; /* Its next sibling, if any. */
333 struct die_info
*parent
; /* Its parent, if any. */
335 struct type
*type
; /* Cached type information */
338 /* Attributes have a name and a value */
341 enum dwarf_attribute name
;
342 enum dwarf_form form
;
346 struct dwarf_block
*blk
;
354 struct function_range
357 CORE_ADDR lowpc
, highpc
;
359 struct function_range
*next
;
362 static struct function_range
*cu_first_fn
, *cu_last_fn
, *cu_cached_fn
;
364 /* Get at parts of an attribute structure */
366 #define DW_STRING(attr) ((attr)->u.str)
367 #define DW_UNSND(attr) ((attr)->u.unsnd)
368 #define DW_BLOCK(attr) ((attr)->u.blk)
369 #define DW_SND(attr) ((attr)->u.snd)
370 #define DW_ADDR(attr) ((attr)->u.addr)
372 /* Blocks are a bunch of untyped bytes. */
379 #ifndef ATTR_ALLOC_CHUNK
380 #define ATTR_ALLOC_CHUNK 4
383 /* A hash table of die offsets for following references. */
384 #ifndef REF_HASH_SIZE
385 #define REF_HASH_SIZE 1021
388 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
390 /* Obstack for allocating temporary storage used during symbol reading. */
391 static struct obstack dwarf2_tmp_obstack
;
393 /* Offset to the first byte of the current compilation unit header,
394 for resolving relative reference dies. */
395 static unsigned int cu_header_offset
;
397 /* Allocate fields for structs, unions and enums in this size. */
398 #ifndef DW_FIELD_ALLOC_CHUNK
399 #define DW_FIELD_ALLOC_CHUNK 4
402 /* The language we are debugging. */
403 static enum language cu_language
;
404 static const struct language_defn
*cu_language_defn
;
406 /* Actually data from the sections. */
407 static char *dwarf_info_buffer
;
408 static char *dwarf_abbrev_buffer
;
409 static char *dwarf_line_buffer
;
410 static char *dwarf_str_buffer
;
411 static char *dwarf_macinfo_buffer
;
412 static char *dwarf_ranges_buffer
;
413 static char *dwarf_loc_buffer
;
415 /* A zeroed version of a partial die for initialization purposes. */
416 static struct partial_die_info zeroed_partial_die
;
418 /* The generic symbol table building routines have separate lists for
419 file scope symbols and all all other scopes (local scopes). So
420 we need to select the right one to pass to add_symbol_to_list().
421 We do it by keeping a pointer to the correct list in list_in_scope.
423 FIXME: The original dwarf code just treated the file scope as the first
424 local scope, and all other local scopes as nested local scopes, and worked
425 fine. Check to see if we really need to distinguish these
427 static struct pending
**list_in_scope
= &file_symbols
;
429 /* FIXME: decode_locdesc sets these variables to describe the location
430 to the caller. These ought to be a structure or something. If
431 none of the flags are set, the object lives at the address returned
432 by decode_locdesc. */
434 static int isreg
; /* Object lives in register.
435 decode_locdesc's return value is
436 the register number. */
438 /* This value is added to each symbol value. FIXME: Generalize to
439 the section_offsets structure used by dbxread (once this is done,
440 pass the appropriate section number to end_symtab). */
441 static CORE_ADDR baseaddr
; /* Add to each symbol value */
443 /* We put a pointer to this structure in the read_symtab_private field
445 The complete dwarf information for an objfile is kept in the
446 psymbol_obstack, so that absolute die references can be handled.
447 Most of the information in this structure is related to an entire
448 object file and could be passed via the sym_private field of the objfile.
449 It is however conceivable that dwarf2 might not be the only type
450 of symbols read from an object file. */
454 /* Pointer to start of dwarf info buffer for the objfile. */
456 char *dwarf_info_buffer
;
458 /* Offset in dwarf_info_buffer for this compilation unit. */
460 unsigned long dwarf_info_offset
;
462 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
464 char *dwarf_abbrev_buffer
;
466 /* Size of dwarf abbreviation section for the objfile. */
468 unsigned int dwarf_abbrev_size
;
470 /* Pointer to start of dwarf line buffer for the objfile. */
472 char *dwarf_line_buffer
;
474 /* Size of dwarf_line_buffer, in bytes. */
476 unsigned int dwarf_line_size
;
478 /* Pointer to start of dwarf string buffer for the objfile. */
480 char *dwarf_str_buffer
;
482 /* Size of dwarf string section for the objfile. */
484 unsigned int dwarf_str_size
;
486 /* Pointer to start of dwarf macro buffer for the objfile. */
488 char *dwarf_macinfo_buffer
;
490 /* Size of dwarf macinfo section for the objfile. */
492 unsigned int dwarf_macinfo_size
;
494 /* Pointer to start of dwarf ranges buffer for the objfile. */
496 char *dwarf_ranges_buffer
;
498 /* Size of dwarf ranges buffer for the objfile. */
500 unsigned int dwarf_ranges_size
;
502 /* Pointer to start of dwarf locations buffer for the objfile. */
504 char *dwarf_loc_buffer
;
506 /* Size of dwarf locations buffer for the objfile. */
508 unsigned int dwarf_loc_size
;
511 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
512 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
513 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
514 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
515 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
516 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
517 #define DWARF_LINE_SIZE(p) (PST_PRIVATE(p)->dwarf_line_size)
518 #define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer)
519 #define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size)
520 #define DWARF_MACINFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_macinfo_buffer)
521 #define DWARF_MACINFO_SIZE(p) (PST_PRIVATE(p)->dwarf_macinfo_size)
522 #define DWARF_RANGES_BUFFER(p) (PST_PRIVATE(p)->dwarf_ranges_buffer)
523 #define DWARF_RANGES_SIZE(p) (PST_PRIVATE(p)->dwarf_ranges_size)
524 #define DWARF_LOC_BUFFER(p) (PST_PRIVATE(p)->dwarf_loc_buffer)
525 #define DWARF_LOC_SIZE(p) (PST_PRIVATE(p)->dwarf_loc_size)
527 /* Maintain an array of referenced fundamental types for the current
528 compilation unit being read. For DWARF version 1, we have to construct
529 the fundamental types on the fly, since no information about the
530 fundamental types is supplied. Each such fundamental type is created by
531 calling a language dependent routine to create the type, and then a
532 pointer to that type is then placed in the array at the index specified
533 by it's FT_<TYPENAME> value. The array has a fixed size set by the
534 FT_NUM_MEMBERS compile time constant, which is the number of predefined
535 fundamental types gdb knows how to construct. */
536 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
538 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
539 but this would require a corresponding change in unpack_field_as_long
541 static int bits_per_byte
= 8;
543 /* The routines that read and process dies for a C struct or C++ class
544 pass lists of data member fields and lists of member function fields
545 in an instance of a field_info structure, as defined below. */
548 /* List of data member and baseclasses fields. */
551 struct nextfield
*next
;
558 /* Number of fields. */
561 /* Number of baseclasses. */
564 /* Set if the accesibility of one of the fields is not public. */
565 int non_public_fields
;
567 /* Member function fields array, entries are allocated in the order they
568 are encountered in the object file. */
571 struct nextfnfield
*next
;
572 struct fn_field fnfield
;
576 /* Member function fieldlist array, contains name of possibly overloaded
577 member function, number of overloaded member functions and a pointer
578 to the head of the member function field chain. */
583 struct nextfnfield
*head
;
587 /* Number of entries in the fnfieldlists array. */
591 /* Various complaints about symbol reading that don't abort the process */
594 dwarf2_non_const_array_bound_ignored_complaint (const char *arg1
)
596 complaint (&symfile_complaints
, "non-constant array bounds form '%s' ignored",
601 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
603 complaint (&symfile_complaints
,
604 "statement list doesn't fit in .debug_line section");
608 dwarf2_complex_location_expr_complaint (void)
610 complaint (&symfile_complaints
, "location expression too complex");
614 dwarf2_unsupported_at_frame_base_complaint (const char *arg1
)
616 complaint (&symfile_complaints
,
617 "unsupported DW_AT_frame_base for function '%s'", arg1
);
621 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
624 complaint (&symfile_complaints
,
625 "const value length mismatch for '%s', got %d, expected %d", arg1
,
630 dwarf2_macros_too_long_complaint (void)
632 complaint (&symfile_complaints
,
633 "macro info runs off end of `.debug_macinfo' section");
637 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
639 complaint (&symfile_complaints
,
640 "macro debug info contains a malformed macro definition:\n`%s'",
645 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
647 complaint (&symfile_complaints
,
648 "invalid attribute class or form for '%s' in '%s'", arg1
, arg2
);
651 /* local function prototypes */
653 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
656 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
659 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
661 static char *scan_partial_symbols (char *, CORE_ADDR
*, CORE_ADDR
*,
663 const char *namespace);
665 static void add_partial_symbol (struct partial_die_info
*, struct dwarf2_cu
*,
666 const char *namespace);
668 static char *add_partial_namespace (struct partial_die_info
*pdi
,
670 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
671 struct dwarf2_cu
*cu
,
672 const char *namespace);
674 static char *add_partial_enumeration (struct partial_die_info
*enum_pdi
,
676 struct dwarf2_cu
*cu
,
677 const char *namespace);
679 static char *locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
682 struct dwarf2_cu
*cu
);
684 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
686 static void psymtab_to_symtab_1 (struct partial_symtab
*);
688 char *dwarf2_read_section (struct objfile
*, asection
*);
690 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
692 static void dwarf2_empty_abbrev_table (void *);
694 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
697 static char *read_partial_die (struct partial_die_info
*,
698 bfd
*, char *, struct dwarf2_cu
*);
700 static char *read_full_die (struct die_info
**, bfd
*, char *,
701 struct dwarf2_cu
*, int *);
703 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
704 bfd
*, char *, struct dwarf2_cu
*);
706 static char *read_attribute_value (struct attribute
*, unsigned,
707 bfd
*, char *, struct dwarf2_cu
*);
709 static unsigned int read_1_byte (bfd
*, char *);
711 static int read_1_signed_byte (bfd
*, char *);
713 static unsigned int read_2_bytes (bfd
*, char *);
715 static unsigned int read_4_bytes (bfd
*, char *);
717 static unsigned long read_8_bytes (bfd
*, char *);
719 static CORE_ADDR
read_address (bfd
*, char *ptr
, struct dwarf2_cu
*,
722 static LONGEST
read_initial_length (bfd
*, char *,
723 struct comp_unit_head
*, int *bytes_read
);
725 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
728 static char *read_n_bytes (bfd
*, char *, unsigned int);
730 static char *read_string (bfd
*, char *, unsigned int *);
732 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
735 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
737 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
739 static void set_cu_language (unsigned int);
741 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
743 static int die_is_declaration (struct die_info
*);
745 static void free_line_header (struct line_header
*lh
);
747 static struct line_header
*(dwarf_decode_line_header
748 (unsigned int offset
,
749 bfd
*abfd
, struct dwarf2_cu
*cu
));
751 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
754 static void dwarf2_start_subfile (char *, char *);
756 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
759 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
762 static void dwarf2_const_value_data (struct attribute
*attr
,
766 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
768 static struct type
*die_containing_type (struct die_info
*,
772 static struct type
*type_at_offset (unsigned int, struct objfile
*);
775 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
777 static void read_type_die (struct die_info
*, struct dwarf2_cu
*);
779 static void read_typedef (struct die_info
*, struct dwarf2_cu
*);
781 static void read_base_type (struct die_info
*, struct dwarf2_cu
*);
783 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
785 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
787 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
789 static int dwarf2_get_pc_bounds (struct die_info
*,
790 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
792 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
795 static void dwarf2_attach_fields_to_type (struct field_info
*,
796 struct type
*, struct dwarf2_cu
*);
798 static void dwarf2_add_member_fn (struct field_info
*,
799 struct die_info
*, struct type
*,
802 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
803 struct type
*, struct dwarf2_cu
*);
805 static void read_structure_scope (struct die_info
*, struct dwarf2_cu
*);
807 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
809 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
811 static void read_enumeration (struct die_info
*, struct dwarf2_cu
*);
813 static struct type
*dwarf_base_type (int, int, struct dwarf2_cu
*);
815 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
817 static void read_array_type (struct die_info
*, struct dwarf2_cu
*);
819 static void read_tag_pointer_type (struct die_info
*, struct dwarf2_cu
*);
821 static void read_tag_ptr_to_member_type (struct die_info
*,
824 static void read_tag_reference_type (struct die_info
*, struct dwarf2_cu
*);
826 static void read_tag_const_type (struct die_info
*, struct dwarf2_cu
*);
828 static void read_tag_volatile_type (struct die_info
*, struct dwarf2_cu
*);
830 static void read_tag_string_type (struct die_info
*, struct dwarf2_cu
*);
832 static void read_subroutine_type (struct die_info
*, struct dwarf2_cu
*);
834 static struct die_info
*read_comp_unit (char *, bfd
*, struct dwarf2_cu
*);
836 static struct die_info
*read_die_and_children (char *info_ptr
, bfd
*abfd
,
839 struct die_info
*parent
);
841 static struct die_info
*read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
844 struct die_info
*parent
);
846 static void free_die_list (struct die_info
*);
848 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
850 static void process_die (struct die_info
*, struct dwarf2_cu
*);
852 static char *dwarf2_linkage_name (struct die_info
*);
854 static char *dwarf2_name (struct die_info
*die
);
856 static struct die_info
*dwarf2_extension (struct die_info
*die
);
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 (void *);
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
*, struct dwarf2_cu
*);
909 static int attr_form_is_block (struct attribute
*);
912 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
913 struct dwarf2_cu
*cu
);
915 /* Try to locate the sections we need for DWARF 2 debugging
916 information and return true if we have enough to do something. */
919 dwarf2_has_info (bfd
*abfd
)
921 dwarf_info_section
= 0;
922 dwarf_abbrev_section
= 0;
923 dwarf_line_section
= 0;
924 dwarf_str_section
= 0;
925 dwarf_macinfo_section
= 0;
926 dwarf_frame_section
= 0;
927 dwarf_eh_frame_section
= 0;
928 dwarf_ranges_section
= 0;
929 dwarf_loc_section
= 0;
931 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
932 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
935 /* This function is mapped across the sections and remembers the
936 offset and size of each of the debugging sections we are interested
940 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, void *ignore_ptr
)
942 if (strcmp (sectp
->name
, INFO_SECTION
) == 0)
944 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
945 dwarf_info_section
= sectp
;
947 else if (strcmp (sectp
->name
, ABBREV_SECTION
) == 0)
949 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
950 dwarf_abbrev_section
= sectp
;
952 else if (strcmp (sectp
->name
, LINE_SECTION
) == 0)
954 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
955 dwarf_line_section
= sectp
;
957 else if (strcmp (sectp
->name
, PUBNAMES_SECTION
) == 0)
959 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
960 dwarf_pubnames_section
= sectp
;
962 else if (strcmp (sectp
->name
, ARANGES_SECTION
) == 0)
964 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
965 dwarf_aranges_section
= sectp
;
967 else if (strcmp (sectp
->name
, LOC_SECTION
) == 0)
969 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
970 dwarf_loc_section
= sectp
;
972 else if (strcmp (sectp
->name
, MACINFO_SECTION
) == 0)
974 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
975 dwarf_macinfo_section
= sectp
;
977 else if (strcmp (sectp
->name
, STR_SECTION
) == 0)
979 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
980 dwarf_str_section
= sectp
;
982 else if (strcmp (sectp
->name
, FRAME_SECTION
) == 0)
984 dwarf_frame_size
= bfd_get_section_size_before_reloc (sectp
);
985 dwarf_frame_section
= sectp
;
987 else if (strcmp (sectp
->name
, EH_FRAME_SECTION
) == 0)
989 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
990 if (aflag
& SEC_HAS_CONTENTS
)
992 dwarf_eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
993 dwarf_eh_frame_section
= sectp
;
996 else if (strcmp (sectp
->name
, RANGES_SECTION
) == 0)
998 dwarf_ranges_size
= bfd_get_section_size_before_reloc (sectp
);
999 dwarf_ranges_section
= sectp
;
1003 /* Build a partial symbol table. */
1006 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1009 /* We definitely need the .debug_info and .debug_abbrev sections */
1011 dwarf_info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1012 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1014 if (dwarf_line_section
)
1015 dwarf_line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1017 dwarf_line_buffer
= NULL
;
1019 if (dwarf_str_section
)
1020 dwarf_str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1022 dwarf_str_buffer
= NULL
;
1024 if (dwarf_macinfo_section
)
1025 dwarf_macinfo_buffer
= dwarf2_read_section (objfile
,
1026 dwarf_macinfo_section
);
1028 dwarf_macinfo_buffer
= NULL
;
1030 if (dwarf_ranges_section
)
1031 dwarf_ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1033 dwarf_ranges_buffer
= NULL
;
1035 if (dwarf_loc_section
)
1036 dwarf_loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1038 dwarf_loc_buffer
= NULL
;
1041 || (objfile
->global_psymbols
.size
== 0
1042 && objfile
->static_psymbols
.size
== 0))
1044 init_psymbol_list (objfile
, 1024);
1048 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1050 /* Things are significantly easier if we have .debug_aranges and
1051 .debug_pubnames sections */
1053 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1057 /* only test this case for now */
1059 /* In this case we have to work a bit harder */
1060 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1065 /* Build the partial symbol table from the information in the
1066 .debug_pubnames and .debug_aranges sections. */
1069 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1071 bfd
*abfd
= objfile
->obfd
;
1072 char *aranges_buffer
, *pubnames_buffer
;
1073 char *aranges_ptr
, *pubnames_ptr
;
1074 unsigned int entry_length
, version
, info_offset
, info_size
;
1076 pubnames_buffer
= dwarf2_read_section (objfile
,
1077 dwarf_pubnames_section
);
1078 pubnames_ptr
= pubnames_buffer
;
1079 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
1081 struct comp_unit_head cu_header
;
1084 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1086 pubnames_ptr
+= bytes_read
;
1087 version
= read_1_byte (abfd
, pubnames_ptr
);
1089 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1091 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1095 aranges_buffer
= dwarf2_read_section (objfile
,
1096 dwarf_aranges_section
);
1101 /* Read in the comp unit header information from the debug_info at
1105 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1106 char *info_ptr
, bfd
*abfd
)
1110 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1112 info_ptr
+= bytes_read
;
1113 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1115 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1117 info_ptr
+= bytes_read
;
1118 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1120 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1121 if (signed_addr
< 0)
1122 internal_error (__FILE__
, __LINE__
,
1123 "read_comp_unit_head: dwarf from non elf file");
1124 cu_header
->signed_addr_p
= signed_addr
;
1128 /* Build the partial symbol table by doing a quick pass through the
1129 .debug_info and .debug_abbrev sections. */
1132 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1134 /* Instead of reading this into a big buffer, we should probably use
1135 mmap() on architectures that support it. (FIXME) */
1136 bfd
*abfd
= objfile
->obfd
;
1137 char *info_ptr
, *abbrev_ptr
;
1138 char *beg_of_comp_unit
;
1139 struct partial_die_info comp_unit_die
;
1140 struct partial_symtab
*pst
;
1141 struct cleanup
*back_to
;
1142 CORE_ADDR lowpc
, highpc
;
1144 info_ptr
= dwarf_info_buffer
;
1145 abbrev_ptr
= dwarf_abbrev_buffer
;
1147 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1148 the partial symbol scan, like attribute values.
1150 We could reduce our peak memory consumption during partial symbol
1151 table construction by freeing stuff from this obstack more often
1152 --- say, after processing each compilation unit, or each die ---
1153 but it turns out that this saves almost nothing. For an
1154 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1155 on dwarf2_tmp_obstack. Some investigation showed:
1157 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1158 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1159 all fixed-length values not requiring dynamic allocation.
1161 2) 30% of the attributes used the form DW_FORM_string. For
1162 DW_FORM_string, read_attribute simply hands back a pointer to
1163 the null-terminated string in dwarf_info_buffer, so no dynamic
1164 allocation is needed there either.
1166 3) The remaining 1% of the attributes all used DW_FORM_block1.
1167 75% of those were DW_AT_frame_base location lists for
1168 functions; the rest were DW_AT_location attributes, probably
1169 for the global variables.
1171 Anyway, what this all means is that the memory the dwarf2
1172 reader uses as temporary space reading partial symbols is about
1173 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1175 obstack_init (&dwarf2_tmp_obstack
);
1176 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1178 /* Since the objects we're extracting from dwarf_info_buffer vary in
1179 length, only the individual functions to extract them (like
1180 read_comp_unit_head and read_partial_die) can really know whether
1181 the buffer is large enough to hold another complete object.
1183 At the moment, they don't actually check that. If
1184 dwarf_info_buffer holds just one extra byte after the last
1185 compilation unit's dies, then read_comp_unit_head will happily
1186 read off the end of the buffer. read_partial_die is similarly
1187 casual. Those functions should be fixed.
1189 For this loop condition, simply checking whether there's any data
1190 left at all should be sufficient. */
1191 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1193 struct dwarf2_cu cu
;
1194 beg_of_comp_unit
= info_ptr
;
1196 cu
.objfile
= objfile
;
1197 info_ptr
= read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1199 if (cu
.header
.version
!= 2)
1201 error ("Dwarf Error: wrong version in compilation unit header (is %d, should be %d) [in module %s]", cu
.header
.version
, 2, bfd_get_filename (abfd
));
1204 if (cu
.header
.abbrev_offset
>= dwarf_abbrev_size
)
1206 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6) [in module %s]",
1207 (long) cu
.header
.abbrev_offset
,
1208 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1209 bfd_get_filename (abfd
));
1212 if (beg_of_comp_unit
+ cu
.header
.length
+ cu
.header
.initial_length_size
1213 > dwarf_info_buffer
+ dwarf_info_size
)
1215 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0) [in module %s]",
1216 (long) cu
.header
.length
,
1217 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1218 bfd_get_filename (abfd
));
1221 /* Complete the cu_header */
1222 cu
.header
.offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1223 cu
.header
.first_die_ptr
= info_ptr
;
1224 cu
.header
.cu_head_ptr
= beg_of_comp_unit
;
1226 /* Read the abbrevs for this compilation unit into a table */
1227 dwarf2_read_abbrevs (abfd
, &cu
);
1228 make_cleanup (dwarf2_empty_abbrev_table
, cu
.header
.dwarf2_abbrevs
);
1230 /* Read the compilation unit die */
1231 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1234 /* Set the language we're debugging */
1235 set_cu_language (comp_unit_die
.language
);
1237 /* Allocate a new partial symbol table structure */
1238 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1239 comp_unit_die
.name
? comp_unit_die
.name
: "",
1240 comp_unit_die
.lowpc
,
1241 objfile
->global_psymbols
.next
,
1242 objfile
->static_psymbols
.next
);
1244 pst
->read_symtab_private
= (char *)
1245 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1246 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1247 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1248 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1249 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1250 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1251 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1252 DWARF_LINE_SIZE (pst
) = dwarf_line_size
;
1253 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1254 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1255 DWARF_MACINFO_BUFFER (pst
) = dwarf_macinfo_buffer
;
1256 DWARF_MACINFO_SIZE (pst
) = dwarf_macinfo_size
;
1257 DWARF_RANGES_BUFFER (pst
) = dwarf_ranges_buffer
;
1258 DWARF_RANGES_SIZE (pst
) = dwarf_ranges_size
;
1259 DWARF_LOC_BUFFER (pst
) = dwarf_loc_buffer
;
1260 DWARF_LOC_SIZE (pst
) = dwarf_loc_size
;
1261 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1263 /* Store the function that reads in the rest of the symbol table */
1264 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1266 /* Check if comp unit has_children.
1267 If so, read the rest of the partial symbols from this comp unit.
1268 If not, there's no more debug_info for this comp unit. */
1269 if (comp_unit_die
.has_children
)
1271 lowpc
= ((CORE_ADDR
) -1);
1272 highpc
= ((CORE_ADDR
) 0);
1274 info_ptr
= scan_partial_symbols (info_ptr
, &lowpc
, &highpc
,
1277 /* If we didn't find a lowpc, set it to highpc to avoid
1278 complaints from `maint check'. */
1279 if (lowpc
== ((CORE_ADDR
) -1))
1282 /* If the compilation unit didn't have an explicit address range,
1283 then use the information extracted from its child dies. */
1284 if (! comp_unit_die
.has_pc_info
)
1286 comp_unit_die
.lowpc
= lowpc
;
1287 comp_unit_die
.highpc
= highpc
;
1290 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1291 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1293 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1294 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1295 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1296 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1297 sort_pst_symbols (pst
);
1299 /* If there is already a psymtab or symtab for a file of this
1300 name, remove it. (If there is a symtab, more drastic things
1301 also happen.) This happens in VxWorks. */
1302 free_named_symtabs (pst
->filename
);
1304 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1305 + cu
.header
.initial_length_size
;
1307 do_cleanups (back_to
);
1310 /* Read in all interesting dies to the end of the compilation unit or
1311 to the end of the current namespace. NAMESPACE is NULL if we
1312 haven't yet encountered any DW_TAG_namespace entries; otherwise,
1313 it's the name of the current namespace. In particular, it's the
1314 empty string if we're currently in the global namespace but have
1315 previously encountered a DW_TAG_namespace. */
1318 scan_partial_symbols (char *info_ptr
, CORE_ADDR
*lowpc
,
1319 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
1320 const char *namespace)
1322 struct objfile
*objfile
= cu
->objfile
;
1323 bfd
*abfd
= objfile
->obfd
;
1324 struct partial_die_info pdi
;
1326 /* Now, march along the PDI's, descending into ones which have
1327 interesting children but skipping the children of the other ones,
1328 until we reach the end of the compilation unit. */
1332 /* This flag tells whether or not info_ptr has gotten updated
1334 int info_ptr_updated
= 0;
1336 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu
);
1338 /* Anonymous namespaces have no name but have interesting
1339 children, so we need to look at them. Ditto for anonymous
1342 if (pdi
.name
!= NULL
|| pdi
.tag
== DW_TAG_namespace
1343 || pdi
.tag
== DW_TAG_enumeration_type
)
1347 case DW_TAG_subprogram
:
1348 if (pdi
.has_pc_info
)
1350 if (pdi
.lowpc
< *lowpc
)
1354 if (pdi
.highpc
> *highpc
)
1356 *highpc
= pdi
.highpc
;
1358 if (!pdi
.is_declaration
)
1360 add_partial_symbol (&pdi
, cu
, namespace);
1364 case DW_TAG_variable
:
1365 case DW_TAG_typedef
:
1366 case DW_TAG_union_type
:
1367 case DW_TAG_class_type
:
1368 case DW_TAG_structure_type
:
1369 if (!pdi
.is_declaration
)
1371 add_partial_symbol (&pdi
, cu
, namespace);
1374 case DW_TAG_enumeration_type
:
1375 if (!pdi
.is_declaration
)
1377 info_ptr
= add_partial_enumeration (&pdi
, info_ptr
, cu
,
1379 info_ptr_updated
= 1;
1382 case DW_TAG_base_type
:
1383 /* File scope base type definitions are added to the partial
1385 add_partial_symbol (&pdi
, cu
, namespace);
1387 case DW_TAG_namespace
:
1388 /* We've hit a DW_TAG_namespace entry, so we know this
1389 file has been compiled using a compiler that
1390 generates them; update NAMESPACE to reflect that. */
1391 if (namespace == NULL
)
1393 info_ptr
= add_partial_namespace (&pdi
, info_ptr
, lowpc
, highpc
,
1395 info_ptr_updated
= 1;
1405 /* If the die has a sibling, skip to the sibling, unless another
1406 function has already updated info_ptr for us. */
1408 /* NOTE: carlton/2003-06-16: This is a bit hackish, but whether
1409 or not we want to update this depends on enough stuff (not
1410 only pdi.tag but also whether or not pdi.name is NULL) that
1411 this seems like the easiest way to handle the issue. */
1413 if (!info_ptr_updated
)
1414 info_ptr
= locate_pdi_sibling (&pdi
, info_ptr
, abfd
, cu
);
1421 add_partial_symbol (struct partial_die_info
*pdi
,
1422 struct dwarf2_cu
*cu
, const char *namespace)
1424 struct objfile
*objfile
= cu
->objfile
;
1426 const struct partial_symbol
*psym
= NULL
;
1430 case DW_TAG_subprogram
:
1431 if (pdi
->is_external
)
1433 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1434 mst_text, objfile); */
1435 psym
= add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1436 VAR_DOMAIN
, LOC_BLOCK
,
1437 &objfile
->global_psymbols
,
1438 0, pdi
->lowpc
+ baseaddr
,
1439 cu_language
, objfile
);
1443 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1444 mst_file_text, objfile); */
1445 psym
= add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1446 VAR_DOMAIN
, LOC_BLOCK
,
1447 &objfile
->static_psymbols
,
1448 0, pdi
->lowpc
+ baseaddr
,
1449 cu_language
, objfile
);
1452 case DW_TAG_variable
:
1453 if (pdi
->is_external
)
1456 Don't enter into the minimal symbol tables as there is
1457 a minimal symbol table entry from the ELF symbols already.
1458 Enter into partial symbol table if it has a location
1459 descriptor or a type.
1460 If the location descriptor is missing, new_symbol will create
1461 a LOC_UNRESOLVED symbol, the address of the variable will then
1462 be determined from the minimal symbol table whenever the variable
1464 The address for the partial symbol table entry is not
1465 used by GDB, but it comes in handy for debugging partial symbol
1469 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1470 if (pdi
->locdesc
|| pdi
->has_type
)
1471 psym
= add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1472 VAR_DOMAIN
, LOC_STATIC
,
1473 &objfile
->global_psymbols
,
1475 cu_language
, objfile
);
1479 /* Static Variable. Skip symbols without location descriptors. */
1480 if (pdi
->locdesc
== NULL
)
1482 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1483 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1484 mst_file_data, objfile); */
1485 psym
= add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1486 VAR_DOMAIN
, LOC_STATIC
,
1487 &objfile
->static_psymbols
,
1489 cu_language
, objfile
);
1492 case DW_TAG_typedef
:
1493 case DW_TAG_base_type
:
1494 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1495 VAR_DOMAIN
, LOC_TYPEDEF
,
1496 &objfile
->static_psymbols
,
1497 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1499 case DW_TAG_class_type
:
1500 case DW_TAG_structure_type
:
1501 case DW_TAG_union_type
:
1502 case DW_TAG_enumeration_type
:
1503 /* Skip aggregate types without children, these are external
1505 if (pdi
->has_children
== 0)
1507 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1508 STRUCT_DOMAIN
, LOC_TYPEDEF
,
1509 &objfile
->static_psymbols
,
1510 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1512 if (cu_language
== language_cplus
)
1514 /* For C++, these implicitly act as typedefs as well. */
1515 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1516 VAR_DOMAIN
, LOC_TYPEDEF
,
1517 &objfile
->static_psymbols
,
1518 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1521 case DW_TAG_enumerator
:
1522 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1523 VAR_DOMAIN
, LOC_CONST
,
1524 &objfile
->static_psymbols
,
1525 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1531 /* Check to see if we should scan the name for possible namespace
1532 info. Only do this if this is C++, if we don't have namespace
1533 debugging info in the file, if the psym is of an appropriate type
1534 (otherwise we'll have psym == NULL), and if we actually had a
1535 mangled name to begin with. */
1537 if (cu_language
== language_cplus
1538 && namespace == NULL
1540 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
1541 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
1545 /* Read a partial die corresponding to a namespace; also, add a symbol
1546 corresponding to that namespace to the symbol table. NAMESPACE is
1547 the name of the enclosing namespace. */
1550 add_partial_namespace (struct partial_die_info
*pdi
, char *info_ptr
,
1551 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1552 struct dwarf2_cu
*cu
, const char *namespace)
1554 struct objfile
*objfile
= cu
->objfile
;
1555 const char *new_name
= pdi
->name
;
1558 /* Calculate the full name of the namespace that we just entered. */
1560 if (new_name
== NULL
)
1561 new_name
= "(anonymous namespace)";
1562 full_name
= alloca (strlen (namespace) + 2 + strlen (new_name
) + 1);
1563 strcpy (full_name
, namespace);
1564 if (*namespace != '\0')
1565 strcat (full_name
, "::");
1566 strcat (full_name
, new_name
);
1568 /* FIXME: carlton/2003-06-27: Once we build qualified names for more
1569 symbols than just namespaces, we should replace this by a call to
1570 add_partial_symbol. */
1572 add_psymbol_to_list (full_name
, strlen (full_name
),
1573 VAR_DOMAIN
, LOC_TYPEDEF
,
1574 &objfile
->global_psymbols
,
1575 0, 0, cu_language
, objfile
);
1577 /* Now scan partial symbols in that namespace. */
1579 if (pdi
->has_children
)
1580 info_ptr
= scan_partial_symbols (info_ptr
, lowpc
, highpc
, cu
, full_name
);
1585 /* Read a partial die corresponding to an enumeration type. */
1588 add_partial_enumeration (struct partial_die_info
*enum_pdi
, char *info_ptr
,
1589 struct dwarf2_cu
*cu
, const char *namespace)
1591 struct objfile
*objfile
= cu
->objfile
;
1592 bfd
*abfd
= objfile
->obfd
;
1593 struct partial_die_info pdi
;
1595 if (enum_pdi
->name
!= NULL
)
1596 add_partial_symbol (enum_pdi
, cu
, namespace);
1600 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu
);
1603 if (pdi
.tag
!= DW_TAG_enumerator
|| pdi
.name
== NULL
)
1604 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
1606 add_partial_symbol (&pdi
, cu
, namespace);
1612 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the next DIE
1616 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, char *info_ptr
,
1617 bfd
*abfd
, struct dwarf2_cu
*cu
)
1619 /* Do we know the sibling already? */
1621 if (orig_pdi
->sibling
)
1622 return orig_pdi
->sibling
;
1624 /* Are there any children to deal with? */
1626 if (!orig_pdi
->has_children
)
1629 /* Okay, we don't know the sibling, but we have children that we
1630 want to skip. So read children until we run into one without a
1631 tag; return whatever follows it. */
1635 struct partial_die_info pdi
;
1637 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu
);
1642 info_ptr
= locate_pdi_sibling (&pdi
, info_ptr
, abfd
, cu
);
1646 /* Expand this partial symbol table into a full symbol table. */
1649 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1651 /* FIXME: This is barely more than a stub. */
1656 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1662 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1663 gdb_flush (gdb_stdout
);
1666 psymtab_to_symtab_1 (pst
);
1668 /* Finish up the debug error message. */
1670 printf_filtered ("done.\n");
1676 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1678 struct objfile
*objfile
= pst
->objfile
;
1679 bfd
*abfd
= objfile
->obfd
;
1680 struct dwarf2_cu cu
;
1681 struct die_info
*dies
;
1682 unsigned long offset
;
1683 CORE_ADDR lowpc
, highpc
;
1684 struct die_info
*child_die
;
1686 struct symtab
*symtab
;
1687 struct cleanup
*back_to
;
1688 struct attribute
*attr
;
1690 /* Set local variables from the partial symbol table info. */
1691 offset
= DWARF_INFO_OFFSET (pst
);
1692 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1693 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1694 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1695 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1696 dwarf_line_size
= DWARF_LINE_SIZE (pst
);
1697 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1698 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1699 dwarf_macinfo_buffer
= DWARF_MACINFO_BUFFER (pst
);
1700 dwarf_macinfo_size
= DWARF_MACINFO_SIZE (pst
);
1701 dwarf_ranges_buffer
= DWARF_RANGES_BUFFER (pst
);
1702 dwarf_ranges_size
= DWARF_RANGES_SIZE (pst
);
1703 dwarf_loc_buffer
= DWARF_LOC_BUFFER (pst
);
1704 dwarf_loc_size
= DWARF_LOC_SIZE (pst
);
1705 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1706 cu_header_offset
= offset
;
1707 info_ptr
= dwarf_info_buffer
+ offset
;
1709 obstack_init (&dwarf2_tmp_obstack
);
1710 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1713 make_cleanup (really_free_pendings
, NULL
);
1715 cu
.objfile
= objfile
;
1717 /* read in the comp_unit header */
1718 info_ptr
= read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1720 /* Read the abbrevs for this compilation unit */
1721 dwarf2_read_abbrevs (abfd
, &cu
);
1722 make_cleanup (dwarf2_empty_abbrev_table
, cu
.header
.dwarf2_abbrevs
);
1724 dies
= read_comp_unit (info_ptr
, abfd
, &cu
);
1726 make_cleanup_free_die_list (dies
);
1728 /* Find the base address of the compilation unit for range lists and
1729 location lists. It will normally be specified by DW_AT_low_pc.
1730 In DWARF-3 draft 4, the base address could be overridden by
1731 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1732 compilation units with discontinuous ranges. */
1734 cu
.header
.base_known
= 0;
1735 cu
.header
.base_address
= 0;
1737 attr
= dwarf_attr (dies
, DW_AT_entry_pc
);
1740 cu
.header
.base_address
= DW_ADDR (attr
);
1741 cu
.header
.base_known
= 1;
1745 attr
= dwarf_attr (dies
, DW_AT_low_pc
);
1748 cu
.header
.base_address
= DW_ADDR (attr
);
1749 cu
.header
.base_known
= 1;
1753 /* Do line number decoding in read_file_scope () */
1754 process_die (dies
, &cu
);
1756 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, &cu
))
1758 /* Some compilers don't define a DW_AT_high_pc attribute for
1759 the compilation unit. If the DW_AT_high_pc is missing,
1760 synthesize it, by scanning the DIE's below the compilation unit. */
1762 if (dies
->child
!= NULL
)
1764 child_die
= dies
->child
;
1765 while (child_die
&& child_die
->tag
)
1767 if (child_die
->tag
== DW_TAG_subprogram
)
1769 CORE_ADDR low
, high
;
1771 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, &cu
))
1773 highpc
= max (highpc
, high
);
1776 child_die
= sibling_die (child_die
);
1780 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1782 /* Set symtab language to language from DW_AT_language.
1783 If the compilation is from a C file generated by language preprocessors,
1784 do not set the language if it was already deduced by start_subfile. */
1786 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1788 symtab
->language
= cu_language
;
1790 pst
->symtab
= symtab
;
1793 do_cleanups (back_to
);
1796 /* Process a die and its children. */
1799 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
1803 case DW_TAG_padding
:
1805 case DW_TAG_compile_unit
:
1806 read_file_scope (die
, cu
);
1808 case DW_TAG_subprogram
:
1809 read_subroutine_type (die
, cu
);
1810 read_func_scope (die
, cu
);
1812 case DW_TAG_inlined_subroutine
:
1813 /* FIXME: These are ignored for now.
1814 They could be used to set breakpoints on all inlined instances
1815 of a function and make GDB `next' properly over inlined functions. */
1817 case DW_TAG_lexical_block
:
1818 case DW_TAG_try_block
:
1819 case DW_TAG_catch_block
:
1820 read_lexical_block_scope (die
, cu
);
1822 case DW_TAG_class_type
:
1823 case DW_TAG_structure_type
:
1824 case DW_TAG_union_type
:
1825 read_structure_scope (die
, cu
);
1827 case DW_TAG_enumeration_type
:
1828 read_enumeration (die
, cu
);
1830 case DW_TAG_subroutine_type
:
1831 read_subroutine_type (die
, cu
);
1833 case DW_TAG_array_type
:
1834 read_array_type (die
, cu
);
1836 case DW_TAG_pointer_type
:
1837 read_tag_pointer_type (die
, cu
);
1839 case DW_TAG_ptr_to_member_type
:
1840 read_tag_ptr_to_member_type (die
, cu
);
1842 case DW_TAG_reference_type
:
1843 read_tag_reference_type (die
, cu
);
1845 case DW_TAG_string_type
:
1846 read_tag_string_type (die
, cu
);
1848 case DW_TAG_base_type
:
1849 read_base_type (die
, cu
);
1850 if (dwarf_attr (die
, DW_AT_name
))
1852 /* Add a typedef symbol for the base type definition. */
1853 new_symbol (die
, die
->type
, cu
);
1856 case DW_TAG_common_block
:
1857 read_common_block (die
, cu
);
1859 case DW_TAG_common_inclusion
:
1861 case DW_TAG_namespace
:
1862 if (!processing_has_namespace_info
)
1864 processing_has_namespace_info
= 1;
1865 processing_current_namespace
= "";
1867 read_namespace (die
, cu
);
1869 case DW_TAG_imported_declaration
:
1870 case DW_TAG_imported_module
:
1871 /* FIXME: carlton/2002-10-16: Eventually, we should use the
1872 information contained in these. DW_TAG_imported_declaration
1873 dies shouldn't have children; DW_TAG_imported_module dies
1874 shouldn't in the C++ case, but conceivably could in the
1875 Fortran case, so we'll have to replace this gdb_assert if
1876 Fortran compilers start generating that info. */
1877 if (!processing_has_namespace_info
)
1879 processing_has_namespace_info
= 1;
1880 processing_current_namespace
= "";
1882 gdb_assert (die
->child
== NULL
);
1885 new_symbol (die
, NULL
, cu
);
1891 initialize_cu_func_list (void)
1893 cu_first_fn
= cu_last_fn
= cu_cached_fn
= NULL
;
1897 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
1899 struct objfile
*objfile
= cu
->objfile
;
1900 struct comp_unit_head
*cu_header
= &cu
->header
;
1901 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
1902 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1903 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1904 struct attribute
*attr
;
1905 char *name
= "<unknown>";
1906 char *comp_dir
= NULL
;
1907 struct die_info
*child_die
;
1908 bfd
*abfd
= objfile
->obfd
;
1909 struct line_header
*line_header
= 0;
1911 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
1913 if (die
->child
!= NULL
)
1915 child_die
= die
->child
;
1916 while (child_die
&& child_die
->tag
)
1918 if (child_die
->tag
== DW_TAG_subprogram
)
1920 CORE_ADDR low
, high
;
1922 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, cu
))
1924 lowpc
= min (lowpc
, low
);
1925 highpc
= max (highpc
, high
);
1928 child_die
= sibling_die (child_die
);
1933 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1934 from finish_block. */
1935 if (lowpc
== ((CORE_ADDR
) -1))
1940 attr
= dwarf_attr (die
, DW_AT_name
);
1943 name
= DW_STRING (attr
);
1945 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1948 comp_dir
= DW_STRING (attr
);
1951 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1952 directory, get rid of it. */
1953 char *cp
= strchr (comp_dir
, ':');
1955 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1960 if (objfile
->ei
.entry_point
>= lowpc
&&
1961 objfile
->ei
.entry_point
< highpc
)
1963 objfile
->ei
.deprecated_entry_file_lowpc
= lowpc
;
1964 objfile
->ei
.deprecated_entry_file_highpc
= highpc
;
1967 attr
= dwarf_attr (die
, DW_AT_language
);
1970 set_cu_language (DW_UNSND (attr
));
1973 /* We assume that we're processing GCC output. */
1974 processing_gcc_compilation
= 2;
1976 /* FIXME:Do something here. */
1977 if (dip
->at_producer
!= NULL
)
1979 handle_producer (dip
->at_producer
);
1983 /* The compilation unit may be in a different language or objfile,
1984 zero out all remembered fundamental types. */
1985 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1987 start_symtab (name
, comp_dir
, lowpc
);
1988 record_debugformat ("DWARF 2");
1990 initialize_cu_func_list ();
1992 /* Process all dies in compilation unit. */
1993 if (die
->child
!= NULL
)
1995 child_die
= die
->child
;
1996 while (child_die
&& child_die
->tag
)
1998 process_die (child_die
, cu
);
1999 child_die
= sibling_die (child_die
);
2003 /* Decode line number information if present. */
2004 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
2007 unsigned int line_offset
= DW_UNSND (attr
);
2008 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2011 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
2012 (void *) line_header
);
2013 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
);
2017 /* Decode macro information, if present. Dwarf 2 macro information
2018 refers to information in the line number info statement program
2019 header, so we can only read it if we've read the header
2021 attr
= dwarf_attr (die
, DW_AT_macro_info
);
2022 if (attr
&& line_header
)
2024 unsigned int macro_offset
= DW_UNSND (attr
);
2025 dwarf_decode_macros (line_header
, macro_offset
,
2026 comp_dir
, abfd
, cu
);
2028 do_cleanups (back_to
);
2032 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
)
2034 struct function_range
*thisfn
;
2036 thisfn
= (struct function_range
*)
2037 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct function_range
));
2038 thisfn
->name
= name
;
2039 thisfn
->lowpc
= lowpc
;
2040 thisfn
->highpc
= highpc
;
2041 thisfn
->seen_line
= 0;
2042 thisfn
->next
= NULL
;
2044 if (cu_last_fn
== NULL
)
2045 cu_first_fn
= thisfn
;
2047 cu_last_fn
->next
= thisfn
;
2049 cu_last_fn
= thisfn
;
2053 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2055 struct objfile
*objfile
= cu
->objfile
;
2056 struct context_stack
*new;
2059 struct die_info
*child_die
;
2060 struct attribute
*attr
;
2063 name
= dwarf2_linkage_name (die
);
2065 /* Ignore functions with missing or empty names and functions with
2066 missing or invalid low and high pc attributes. */
2067 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2073 /* Record the function range for dwarf_decode_lines. */
2074 add_to_cu_func_list (name
, lowpc
, highpc
);
2076 if (objfile
->ei
.entry_point
>= lowpc
&&
2077 objfile
->ei
.entry_point
< highpc
)
2079 objfile
->ei
.entry_func_lowpc
= lowpc
;
2080 objfile
->ei
.entry_func_highpc
= highpc
;
2083 new = push_context (0, lowpc
);
2084 new->name
= new_symbol (die
, die
->type
, cu
);
2086 /* If there is a location expression for DW_AT_frame_base, record
2088 attr
= dwarf_attr (die
, DW_AT_frame_base
);
2090 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
2092 list_in_scope
= &local_symbols
;
2094 if (die
->child
!= NULL
)
2096 child_die
= die
->child
;
2097 while (child_die
&& child_die
->tag
)
2099 process_die (child_die
, cu
);
2100 child_die
= sibling_die (child_die
);
2104 new = pop_context ();
2105 /* Make a block for the local symbols within. */
2106 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2107 lowpc
, highpc
, objfile
);
2109 /* In C++, we can have functions nested inside functions (e.g., when
2110 a function declares a class that has methods). This means that
2111 when we finish processing a function scope, we may need to go
2112 back to building a containing block's symbol lists. */
2113 local_symbols
= new->locals
;
2114 param_symbols
= new->params
;
2116 /* If we've finished processing a top-level function, subsequent
2117 symbols go in the file symbol list. */
2118 if (outermost_context_p ())
2119 list_in_scope
= &file_symbols
;
2122 /* Process all the DIES contained within a lexical block scope. Start
2123 a new scope, process the dies, and then close the scope. */
2126 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2128 struct objfile
*objfile
= cu
->objfile
;
2129 struct context_stack
*new;
2130 CORE_ADDR lowpc
, highpc
;
2131 struct die_info
*child_die
;
2133 /* Ignore blocks with missing or invalid low and high pc attributes. */
2134 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2135 as multiple lexical blocks? Handling children in a sane way would
2136 be nasty. Might be easier to properly extend generic blocks to
2138 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2143 push_context (0, lowpc
);
2144 if (die
->child
!= NULL
)
2146 child_die
= die
->child
;
2147 while (child_die
&& child_die
->tag
)
2149 process_die (child_die
, cu
);
2150 child_die
= sibling_die (child_die
);
2153 new = pop_context ();
2155 if (local_symbols
!= NULL
)
2157 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
2160 local_symbols
= new->locals
;
2163 /* Get low and high pc attributes from a die. Return 1 if the attributes
2164 are present and valid, otherwise, return 0. Return -1 if the range is
2165 discontinuous, i.e. derived from DW_AT_ranges information. */
2167 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
2168 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
2170 struct objfile
*objfile
= cu
->objfile
;
2171 struct comp_unit_head
*cu_header
= &cu
->header
;
2172 struct attribute
*attr
;
2173 bfd
*obfd
= objfile
->obfd
;
2178 attr
= dwarf_attr (die
, DW_AT_high_pc
);
2181 high
= DW_ADDR (attr
);
2182 attr
= dwarf_attr (die
, DW_AT_low_pc
);
2184 low
= DW_ADDR (attr
);
2186 /* Found high w/o low attribute. */
2189 /* Found consecutive range of addresses. */
2194 attr
= dwarf_attr (die
, DW_AT_ranges
);
2197 unsigned int addr_size
= cu_header
->addr_size
;
2198 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
2199 /* Value of the DW_AT_ranges attribute is the offset in the
2200 .debug_ranges section. */
2201 unsigned int offset
= DW_UNSND (attr
);
2202 /* Base address selection entry. */
2210 found_base
= cu_header
->base_known
;
2211 base
= cu_header
->base_address
;
2213 if (offset
>= dwarf_ranges_size
)
2215 complaint (&symfile_complaints
,
2216 "Offset %d out of bounds for DW_AT_ranges attribute",
2220 buffer
= dwarf_ranges_buffer
+ offset
;
2222 /* Read in the largest possible address. */
2223 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
2224 if ((marker
& mask
) == mask
)
2226 /* If we found the largest possible address, then
2227 read the base address. */
2228 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2229 buffer
+= 2 * addr_size
;
2230 offset
+= 2 * addr_size
;
2238 CORE_ADDR range_beginning
, range_end
;
2240 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
2241 buffer
+= addr_size
;
2242 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
2243 buffer
+= addr_size
;
2244 offset
+= 2 * addr_size
;
2246 /* An end of list marker is a pair of zero addresses. */
2247 if (range_beginning
== 0 && range_end
== 0)
2248 /* Found the end of list entry. */
2251 /* Each base address selection entry is a pair of 2 values.
2252 The first is the largest possible address, the second is
2253 the base address. Check for a base address here. */
2254 if ((range_beginning
& mask
) == mask
)
2256 /* If we found the largest possible address, then
2257 read the base address. */
2258 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2265 /* We have no valid base address for the ranges
2267 complaint (&symfile_complaints
,
2268 "Invalid .debug_ranges data (no base address)");
2272 range_beginning
+= base
;
2275 /* FIXME: This is recording everything as a low-high
2276 segment of consecutive addresses. We should have a
2277 data structure for discontiguous block ranges
2281 low
= range_beginning
;
2287 if (range_beginning
< low
)
2288 low
= range_beginning
;
2289 if (range_end
> high
)
2295 /* If the first entry is an end-of-list marker, the range
2296 describes an empty scope, i.e. no instructions. */
2306 /* When using the GNU linker, .gnu.linkonce. sections are used to
2307 eliminate duplicate copies of functions and vtables and such.
2308 The linker will arbitrarily choose one and discard the others.
2309 The AT_*_pc values for such functions refer to local labels in
2310 these sections. If the section from that file was discarded, the
2311 labels are not in the output, so the relocs get a value of 0.
2312 If this is a discarded function, mark the pc bounds as invalid,
2313 so that GDB will ignore it. */
2314 if (low
== 0 && (bfd_get_file_flags (obfd
) & HAS_RELOC
) == 0)
2322 /* Add an aggregate field to the field list. */
2325 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
2326 struct dwarf2_cu
*cu
)
2328 struct objfile
*objfile
= cu
->objfile
;
2329 struct nextfield
*new_field
;
2330 struct attribute
*attr
;
2332 char *fieldname
= "";
2334 /* Allocate a new field list entry and link it in. */
2335 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2336 make_cleanup (xfree
, new_field
);
2337 memset (new_field
, 0, sizeof (struct nextfield
));
2338 new_field
->next
= fip
->fields
;
2339 fip
->fields
= new_field
;
2342 /* Handle accessibility and virtuality of field.
2343 The default accessibility for members is public, the default
2344 accessibility for inheritance is private. */
2345 if (die
->tag
!= DW_TAG_inheritance
)
2346 new_field
->accessibility
= DW_ACCESS_public
;
2348 new_field
->accessibility
= DW_ACCESS_private
;
2349 new_field
->virtuality
= DW_VIRTUALITY_none
;
2351 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2353 new_field
->accessibility
= DW_UNSND (attr
);
2354 if (new_field
->accessibility
!= DW_ACCESS_public
)
2355 fip
->non_public_fields
= 1;
2356 attr
= dwarf_attr (die
, DW_AT_virtuality
);
2358 new_field
->virtuality
= DW_UNSND (attr
);
2360 fp
= &new_field
->field
;
2362 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
))
2364 /* Data member other than a C++ static data member. */
2366 /* Get type of field. */
2367 fp
->type
= die_type (die
, cu
);
2369 FIELD_STATIC_KIND (*fp
) = 0;
2371 /* Get bit size of field (zero if none). */
2372 attr
= dwarf_attr (die
, DW_AT_bit_size
);
2375 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
2379 FIELD_BITSIZE (*fp
) = 0;
2382 /* Get bit offset of field. */
2383 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2386 FIELD_BITPOS (*fp
) =
2387 decode_locdesc (DW_BLOCK (attr
), cu
) * bits_per_byte
;
2390 FIELD_BITPOS (*fp
) = 0;
2391 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
2394 if (BITS_BIG_ENDIAN
)
2396 /* For big endian bits, the DW_AT_bit_offset gives the
2397 additional bit offset from the MSB of the containing
2398 anonymous object to the MSB of the field. We don't
2399 have to do anything special since we don't need to
2400 know the size of the anonymous object. */
2401 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
2405 /* For little endian bits, compute the bit offset to the
2406 MSB of the anonymous object, subtract off the number of
2407 bits from the MSB of the field to the MSB of the
2408 object, and then subtract off the number of bits of
2409 the field itself. The result is the bit offset of
2410 the LSB of the field. */
2412 int bit_offset
= DW_UNSND (attr
);
2414 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2417 /* The size of the anonymous object containing
2418 the bit field is explicit, so use the
2419 indicated size (in bytes). */
2420 anonymous_size
= DW_UNSND (attr
);
2424 /* The size of the anonymous object containing
2425 the bit field must be inferred from the type
2426 attribute of the data member containing the
2428 anonymous_size
= TYPE_LENGTH (fp
->type
);
2430 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2431 - bit_offset
- FIELD_BITSIZE (*fp
);
2435 /* Get name of field. */
2436 attr
= dwarf_attr (die
, DW_AT_name
);
2437 if (attr
&& DW_STRING (attr
))
2438 fieldname
= DW_STRING (attr
);
2439 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
2440 &objfile
->type_obstack
);
2442 /* Change accessibility for artificial fields (e.g. virtual table
2443 pointer or virtual base class pointer) to private. */
2444 if (dwarf_attr (die
, DW_AT_artificial
))
2446 new_field
->accessibility
= DW_ACCESS_private
;
2447 fip
->non_public_fields
= 1;
2450 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
2452 /* C++ static member. */
2454 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2455 is a declaration, but all versions of G++ as of this writing
2456 (so through at least 3.2.1) incorrectly generate
2457 DW_TAG_variable tags. */
2461 /* Get name of field. */
2462 attr
= dwarf_attr (die
, DW_AT_name
);
2463 if (attr
&& DW_STRING (attr
))
2464 fieldname
= DW_STRING (attr
);
2468 /* Get physical name. */
2469 physname
= dwarf2_linkage_name (die
);
2471 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
2472 &objfile
->type_obstack
));
2473 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2474 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
2475 &objfile
->type_obstack
);
2477 else if (die
->tag
== DW_TAG_inheritance
)
2479 /* C++ base class field. */
2480 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2482 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
2484 FIELD_BITSIZE (*fp
) = 0;
2485 FIELD_STATIC_KIND (*fp
) = 0;
2486 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2487 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2488 fip
->nbaseclasses
++;
2492 /* Create the vector of fields, and attach it to the type. */
2495 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
2496 struct dwarf2_cu
*cu
)
2498 int nfields
= fip
->nfields
;
2500 /* Record the field count, allocate space for the array of fields,
2501 and create blank accessibility bitfields if necessary. */
2502 TYPE_NFIELDS (type
) = nfields
;
2503 TYPE_FIELDS (type
) = (struct field
*)
2504 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2505 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2507 if (fip
->non_public_fields
)
2509 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2511 TYPE_FIELD_PRIVATE_BITS (type
) =
2512 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2513 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2515 TYPE_FIELD_PROTECTED_BITS (type
) =
2516 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2517 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2519 TYPE_FIELD_IGNORE_BITS (type
) =
2520 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2521 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2524 /* If the type has baseclasses, allocate and clear a bit vector for
2525 TYPE_FIELD_VIRTUAL_BITS. */
2526 if (fip
->nbaseclasses
)
2528 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2531 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2532 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2533 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2534 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2535 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2538 /* Copy the saved-up fields into the field vector. Start from the head
2539 of the list, adding to the tail of the field array, so that they end
2540 up in the same order in the array in which they were added to the list. */
2541 while (nfields
-- > 0)
2543 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2544 switch (fip
->fields
->accessibility
)
2546 case DW_ACCESS_private
:
2547 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2550 case DW_ACCESS_protected
:
2551 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2554 case DW_ACCESS_public
:
2558 /* Unknown accessibility. Complain and treat it as public. */
2560 complaint (&symfile_complaints
, "unsupported accessibility %d",
2561 fip
->fields
->accessibility
);
2565 if (nfields
< fip
->nbaseclasses
)
2567 switch (fip
->fields
->virtuality
)
2569 case DW_VIRTUALITY_virtual
:
2570 case DW_VIRTUALITY_pure_virtual
:
2571 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2575 fip
->fields
= fip
->fields
->next
;
2579 /* Add a member function to the proper fieldlist. */
2582 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2583 struct type
*type
, struct dwarf2_cu
*cu
)
2585 struct objfile
*objfile
= cu
->objfile
;
2586 struct attribute
*attr
;
2587 struct fnfieldlist
*flp
;
2589 struct fn_field
*fnp
;
2592 struct nextfnfield
*new_fnfield
;
2594 /* Get name of member function. */
2595 attr
= dwarf_attr (die
, DW_AT_name
);
2596 if (attr
&& DW_STRING (attr
))
2597 fieldname
= DW_STRING (attr
);
2601 /* Get the mangled name. */
2602 physname
= dwarf2_linkage_name (die
);
2604 /* Look up member function name in fieldlist. */
2605 for (i
= 0; i
< fip
->nfnfields
; i
++)
2607 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
2611 /* Create new list element if necessary. */
2612 if (i
< fip
->nfnfields
)
2613 flp
= &fip
->fnfieldlists
[i
];
2616 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2618 fip
->fnfieldlists
= (struct fnfieldlist
*)
2619 xrealloc (fip
->fnfieldlists
,
2620 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2621 * sizeof (struct fnfieldlist
));
2622 if (fip
->nfnfields
== 0)
2623 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2625 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2626 flp
->name
= fieldname
;
2632 /* Create a new member function field and chain it to the field list
2634 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2635 make_cleanup (xfree
, new_fnfield
);
2636 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2637 new_fnfield
->next
= flp
->head
;
2638 flp
->head
= new_fnfield
;
2641 /* Fill in the member function field info. */
2642 fnp
= &new_fnfield
->fnfield
;
2643 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2644 &objfile
->type_obstack
);
2645 fnp
->type
= alloc_type (objfile
);
2646 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2648 int nparams
= TYPE_NFIELDS (die
->type
);
2650 /* TYPE is the domain of this method, and DIE->TYPE is the type
2651 of the method itself (TYPE_CODE_METHOD). */
2652 smash_to_method_type (fnp
->type
, type
,
2653 TYPE_TARGET_TYPE (die
->type
),
2654 TYPE_FIELDS (die
->type
),
2655 TYPE_NFIELDS (die
->type
),
2656 TYPE_VARARGS (die
->type
));
2658 /* Handle static member functions.
2659 Dwarf2 has no clean way to discern C++ static and non-static
2660 member functions. G++ helps GDB by marking the first
2661 parameter for non-static member functions (which is the
2662 this pointer) as artificial. We obtain this information
2663 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2664 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2665 fnp
->voffset
= VOFFSET_STATIC
;
2668 complaint (&symfile_complaints
, "member function type missing for '%s'",
2671 /* Get fcontext from DW_AT_containing_type if present. */
2672 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2673 fnp
->fcontext
= die_containing_type (die
, cu
);
2675 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2676 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2678 /* Get accessibility. */
2679 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2682 switch (DW_UNSND (attr
))
2684 case DW_ACCESS_private
:
2685 fnp
->is_private
= 1;
2687 case DW_ACCESS_protected
:
2688 fnp
->is_protected
= 1;
2693 /* Check for artificial methods. */
2694 attr
= dwarf_attr (die
, DW_AT_artificial
);
2695 if (attr
&& DW_UNSND (attr
) != 0)
2696 fnp
->is_artificial
= 1;
2698 /* Get index in virtual function table if it is a virtual member function. */
2699 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2702 /* Support the .debug_loc offsets */
2703 if (attr_form_is_block (attr
))
2705 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
2707 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
2709 dwarf2_complex_location_expr_complaint ();
2713 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
2719 /* Create the vector of member function fields, and attach it to the type. */
2722 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2723 struct dwarf2_cu
*cu
)
2725 struct fnfieldlist
*flp
;
2726 int total_length
= 0;
2729 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2730 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2731 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2733 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2735 struct nextfnfield
*nfp
= flp
->head
;
2736 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2739 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2740 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2741 fn_flp
->fn_fields
= (struct fn_field
*)
2742 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2743 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2744 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2746 total_length
+= flp
->length
;
2749 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2750 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2753 /* Called when we find the DIE that starts a structure or union scope
2754 (definition) to process all dies that define the members of the
2757 NOTE: we need to call struct_type regardless of whether or not the
2758 DIE has an at_name attribute, since it might be an anonymous
2759 structure or union. This gets the type entered into our set of
2762 However, if the structure is incomplete (an opaque struct/union)
2763 then suppress creating a symbol table entry for it since gdb only
2764 wants to find the one with the complete definition. Note that if
2765 it is complete, we just call new_symbol, which does it's own
2766 checking about whether the struct/union is anonymous or not (and
2767 suppresses creating a symbol table entry itself). */
2770 read_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2772 struct objfile
*objfile
= cu
->objfile
;
2774 struct attribute
*attr
;
2776 type
= alloc_type (objfile
);
2778 INIT_CPLUS_SPECIFIC (type
);
2779 attr
= dwarf_attr (die
, DW_AT_name
);
2780 if (attr
&& DW_STRING (attr
))
2782 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2783 strlen (DW_STRING (attr
)),
2784 &objfile
->type_obstack
);
2787 if (die
->tag
== DW_TAG_structure_type
)
2789 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2791 else if (die
->tag
== DW_TAG_union_type
)
2793 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2797 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2799 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2802 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2805 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2809 TYPE_LENGTH (type
) = 0;
2812 /* We need to add the type field to the die immediately so we don't
2813 infinitely recurse when dealing with pointers to the structure
2814 type within the structure itself. */
2817 if (die
->child
!= NULL
&& ! die_is_declaration (die
))
2819 struct field_info fi
;
2820 struct die_info
*child_die
;
2821 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2823 memset (&fi
, 0, sizeof (struct field_info
));
2825 child_die
= die
->child
;
2827 while (child_die
&& child_die
->tag
)
2829 if (child_die
->tag
== DW_TAG_member
2830 || child_die
->tag
== DW_TAG_variable
)
2832 /* NOTE: carlton/2002-11-05: A C++ static data member
2833 should be a DW_TAG_member that is a declaration, but
2834 all versions of G++ as of this writing (so through at
2835 least 3.2.1) incorrectly generate DW_TAG_variable
2836 tags for them instead. */
2837 dwarf2_add_field (&fi
, child_die
, cu
);
2839 else if (child_die
->tag
== DW_TAG_subprogram
)
2841 /* C++ member function. */
2842 process_die (child_die
, cu
);
2843 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
2845 else if (child_die
->tag
== DW_TAG_inheritance
)
2847 /* C++ base class field. */
2848 dwarf2_add_field (&fi
, child_die
, cu
);
2852 process_die (child_die
, cu
);
2854 child_die
= sibling_die (child_die
);
2857 /* Attach fields and member functions to the type. */
2859 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
2862 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
2864 /* Get the type which refers to the base class (possibly this
2865 class itself) which contains the vtable pointer for the current
2866 class from the DW_AT_containing_type attribute. */
2868 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2870 struct type
*t
= die_containing_type (die
, cu
);
2872 TYPE_VPTR_BASETYPE (type
) = t
;
2875 static const char vptr_name
[] =
2876 {'_', 'v', 'p', 't', 'r', '\0'};
2879 /* Our own class provides vtbl ptr. */
2880 for (i
= TYPE_NFIELDS (t
) - 1;
2881 i
>= TYPE_N_BASECLASSES (t
);
2884 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2886 if ((strncmp (fieldname
, vptr_name
,
2887 strlen (vptr_name
) - 1)
2889 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2891 TYPE_VPTR_FIELDNO (type
) = i
;
2896 /* Complain if virtual function table field not found. */
2897 if (i
< TYPE_N_BASECLASSES (t
))
2898 complaint (&symfile_complaints
,
2899 "virtual function table pointer not found when defining class '%s'",
2900 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
2905 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2910 new_symbol (die
, type
, cu
);
2912 do_cleanups (back_to
);
2916 /* No children, must be stub. */
2917 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2921 /* Given a pointer to a die which begins an enumeration, process all
2922 the dies that define the members of the enumeration.
2924 This will be much nicer in draft 6 of the DWARF spec when our
2925 members will be dies instead squished into the DW_AT_element_list
2928 NOTE: We reverse the order of the element list. */
2931 read_enumeration (struct die_info
*die
, struct dwarf2_cu
*cu
)
2933 struct objfile
*objfile
= cu
->objfile
;
2934 struct die_info
*child_die
;
2936 struct field
*fields
;
2937 struct attribute
*attr
;
2940 int unsigned_enum
= 1;
2942 type
= alloc_type (objfile
);
2944 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2945 attr
= dwarf_attr (die
, DW_AT_name
);
2946 if (attr
&& DW_STRING (attr
))
2948 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2949 strlen (DW_STRING (attr
)),
2950 &objfile
->type_obstack
);
2953 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2956 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2960 TYPE_LENGTH (type
) = 0;
2965 if (die
->child
!= NULL
)
2967 child_die
= die
->child
;
2968 while (child_die
&& child_die
->tag
)
2970 if (child_die
->tag
!= DW_TAG_enumerator
)
2972 process_die (child_die
, cu
);
2976 attr
= dwarf_attr (child_die
, DW_AT_name
);
2979 sym
= new_symbol (child_die
, type
, cu
);
2980 if (SYMBOL_VALUE (sym
) < 0)
2983 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2985 fields
= (struct field
*)
2987 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2988 * sizeof (struct field
));
2991 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
2992 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2993 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2994 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2995 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
3001 child_die
= sibling_die (child_die
);
3006 TYPE_NFIELDS (type
) = num_fields
;
3007 TYPE_FIELDS (type
) = (struct field
*)
3008 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
3009 memcpy (TYPE_FIELDS (type
), fields
,
3010 sizeof (struct field
) * num_fields
);
3014 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
3017 new_symbol (die
, type
, cu
);
3020 /* Extract all information from a DW_TAG_array_type DIE and put it in
3021 the DIE's type field. For now, this only handles one dimensional
3025 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3027 struct objfile
*objfile
= cu
->objfile
;
3028 struct die_info
*child_die
;
3029 struct type
*type
= NULL
;
3030 struct type
*element_type
, *range_type
, *index_type
;
3031 struct type
**range_types
= NULL
;
3032 struct attribute
*attr
;
3034 struct cleanup
*back_to
;
3036 /* Return if we've already decoded this type. */
3042 element_type
= die_type (die
, cu
);
3044 /* Irix 6.2 native cc creates array types without children for
3045 arrays with unspecified length. */
3046 if (die
->child
== NULL
)
3048 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
3049 range_type
= create_range_type (NULL
, index_type
, 0, -1);
3050 die
->type
= create_array_type (NULL
, element_type
, range_type
);
3054 back_to
= make_cleanup (null_cleanup
, NULL
);
3055 child_die
= die
->child
;
3056 while (child_die
&& child_die
->tag
)
3058 if (child_die
->tag
== DW_TAG_subrange_type
)
3060 unsigned int low
, high
;
3062 /* Default bounds to an array with unspecified length. */
3065 if (cu_language
== language_fortran
)
3067 /* FORTRAN implies a lower bound of 1, if not given. */
3071 index_type
= die_type (child_die
, cu
);
3072 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
3075 if (attr
->form
== DW_FORM_sdata
)
3077 low
= DW_SND (attr
);
3079 else if (attr
->form
== DW_FORM_udata
3080 || attr
->form
== DW_FORM_data1
3081 || attr
->form
== DW_FORM_data2
3082 || attr
->form
== DW_FORM_data4
3083 || attr
->form
== DW_FORM_data8
)
3085 low
= DW_UNSND (attr
);
3089 dwarf2_non_const_array_bound_ignored_complaint
3090 (dwarf_form_name (attr
->form
));
3092 die
->type
= lookup_pointer_type (element_type
);
3099 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
3102 if (attr
->form
== DW_FORM_sdata
)
3104 high
= DW_SND (attr
);
3106 else if (attr
->form
== DW_FORM_udata
3107 || attr
->form
== DW_FORM_data1
3108 || attr
->form
== DW_FORM_data2
3109 || attr
->form
== DW_FORM_data4
3110 || attr
->form
== DW_FORM_data8
)
3112 high
= DW_UNSND (attr
);
3114 else if (attr
->form
== DW_FORM_block1
)
3116 /* GCC encodes arrays with unspecified or dynamic length
3117 with a DW_FORM_block1 attribute.
3118 FIXME: GDB does not yet know how to handle dynamic
3119 arrays properly, treat them as arrays with unspecified
3122 FIXME: jimb/2003-09-22: GDB does not really know
3123 how to handle arrays of unspecified length
3124 either; we just represent them as zero-length
3125 arrays. Choose an appropriate upper bound given
3126 the lower bound we've computed above. */
3131 dwarf2_non_const_array_bound_ignored_complaint
3132 (dwarf_form_name (attr
->form
));
3134 die
->type
= lookup_pointer_type (element_type
);
3142 /* Create a range type and save it for array type creation. */
3143 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
3145 range_types
= (struct type
**)
3146 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
3147 * sizeof (struct type
*));
3149 make_cleanup (free_current_contents
, &range_types
);
3151 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
3153 child_die
= sibling_die (child_die
);
3156 /* Dwarf2 dimensions are output from left to right, create the
3157 necessary array types in backwards order. */
3158 type
= element_type
;
3160 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
3162 /* Understand Dwarf2 support for vector types (like they occur on
3163 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3164 array type. This is not part of the Dwarf2/3 standard yet, but a
3165 custom vendor extension. The main difference between a regular
3166 array and the vector variant is that vectors are passed by value
3168 attr
= dwarf_attr (die
, DW_AT_GNU_vector
);
3170 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
3172 do_cleanups (back_to
);
3174 /* Install the type in the die. */
3178 /* First cut: install each common block member as a global variable. */
3181 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
3183 struct die_info
*child_die
;
3184 struct attribute
*attr
;
3186 CORE_ADDR base
= (CORE_ADDR
) 0;
3188 attr
= dwarf_attr (die
, DW_AT_location
);
3191 /* Support the .debug_loc offsets */
3192 if (attr_form_is_block (attr
))
3194 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
3196 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3198 dwarf2_complex_location_expr_complaint ();
3202 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3203 "common block member");
3206 if (die
->child
!= NULL
)
3208 child_die
= die
->child
;
3209 while (child_die
&& child_die
->tag
)
3211 sym
= new_symbol (child_die
, NULL
, cu
);
3212 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
3215 SYMBOL_VALUE_ADDRESS (sym
) =
3216 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
3217 add_symbol_to_list (sym
, &global_symbols
);
3219 child_die
= sibling_die (child_die
);
3224 /* Read a C++ namespace. */
3227 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
3229 struct objfile
*objfile
= cu
->objfile
;
3230 const char *previous_namespace
= processing_current_namespace
;
3231 const char *name
= NULL
;
3233 struct die_info
*current_die
;
3235 /* Loop through the extensions until we find a name. */
3237 for (current_die
= die
;
3238 current_die
!= NULL
;
3239 current_die
= dwarf2_extension (die
))
3241 name
= dwarf2_name (current_die
);
3246 /* Is it an anonymous namespace? */
3248 is_anonymous
= (name
== NULL
);
3250 name
= "(anonymous namespace)";
3252 /* Now build the name of the current namespace. */
3254 if (previous_namespace
[0] == '\0')
3256 processing_current_namespace
= name
;
3260 /* We need temp_name around because processing_current_namespace
3261 is a const char *. */
3262 char *temp_name
= alloca (strlen (previous_namespace
)
3263 + 2 + strlen(name
) + 1);
3264 strcpy (temp_name
, previous_namespace
);
3265 strcat (temp_name
, "::");
3266 strcat (temp_name
, name
);
3268 processing_current_namespace
= temp_name
;
3271 /* Add a symbol associated to this if we haven't seen the namespace
3272 before. Also, add a using directive if it's an anonymous
3275 if (dwarf2_extension (die
) == NULL
)
3279 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
3280 this cast will hopefully become unnecessary. */
3281 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
3282 (char *) processing_current_namespace
,
3284 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
3286 new_symbol (die
, type
, cu
);
3289 cp_add_using_directive (processing_current_namespace
,
3290 strlen (previous_namespace
),
3291 strlen (processing_current_namespace
));
3294 if (die
->child
!= NULL
)
3296 struct die_info
*child_die
= die
->child
;
3298 while (child_die
&& child_die
->tag
)
3300 process_die (child_die
, cu
);
3301 child_die
= sibling_die (child_die
);
3305 processing_current_namespace
= previous_namespace
;
3308 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3309 the user defined type vector. */
3312 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3314 struct comp_unit_head
*cu_header
= &cu
->header
;
3316 struct attribute
*attr_byte_size
;
3317 struct attribute
*attr_address_class
;
3318 int byte_size
, addr_class
;
3325 type
= lookup_pointer_type (die_type (die
, cu
));
3327 attr_byte_size
= dwarf_attr (die
, DW_AT_byte_size
);
3329 byte_size
= DW_UNSND (attr_byte_size
);
3331 byte_size
= cu_header
->addr_size
;
3333 attr_address_class
= dwarf_attr (die
, DW_AT_address_class
);
3334 if (attr_address_class
)
3335 addr_class
= DW_UNSND (attr_address_class
);
3337 addr_class
= DW_ADDR_none
;
3339 /* If the pointer size or address class is different than the
3340 default, create a type variant marked as such and set the
3341 length accordingly. */
3342 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
3344 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3348 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
3349 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
3350 type
= make_type_with_address_space (type
, type_flags
);
3352 else if (TYPE_LENGTH (type
) != byte_size
)
3354 complaint (&symfile_complaints
, "invalid pointer size %d", byte_size
);
3357 /* Should we also complain about unhandled address classes? */
3361 TYPE_LENGTH (type
) = byte_size
;
3365 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3366 the user defined type vector. */
3369 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3371 struct objfile
*objfile
= cu
->objfile
;
3373 struct type
*to_type
;
3374 struct type
*domain
;
3381 type
= alloc_type (objfile
);
3382 to_type
= die_type (die
, cu
);
3383 domain
= die_containing_type (die
, cu
);
3384 smash_to_member_type (type
, domain
, to_type
);
3389 /* Extract all information from a DW_TAG_reference_type DIE and add to
3390 the user defined type vector. */
3393 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3395 struct comp_unit_head
*cu_header
= &cu
->header
;
3397 struct attribute
*attr
;
3404 type
= lookup_reference_type (die_type (die
, cu
));
3405 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3408 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3412 TYPE_LENGTH (type
) = cu_header
->addr_size
;
3418 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3420 struct type
*base_type
;
3427 base_type
= die_type (die
, cu
);
3428 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
3432 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3434 struct type
*base_type
;
3441 base_type
= die_type (die
, cu
);
3442 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
3445 /* Extract all information from a DW_TAG_string_type DIE and add to
3446 the user defined type vector. It isn't really a user defined type,
3447 but it behaves like one, with other DIE's using an AT_user_def_type
3448 attribute to reference it. */
3451 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3453 struct objfile
*objfile
= cu
->objfile
;
3454 struct type
*type
, *range_type
, *index_type
, *char_type
;
3455 struct attribute
*attr
;
3456 unsigned int length
;
3463 attr
= dwarf_attr (die
, DW_AT_string_length
);
3466 length
= DW_UNSND (attr
);
3470 /* check for the DW_AT_byte_size attribute */
3471 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3474 length
= DW_UNSND (attr
);
3481 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
3482 range_type
= create_range_type (NULL
, index_type
, 1, length
);
3483 if (cu_language
== language_fortran
)
3485 /* Need to create a unique string type for bounds
3487 type
= create_string_type (0, range_type
);
3491 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
3492 type
= create_string_type (char_type
, range_type
);
3497 /* Handle DIES due to C code like:
3501 int (*funcp)(int a, long l);
3505 ('funcp' generates a DW_TAG_subroutine_type DIE)
3509 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3511 struct type
*type
; /* Type that this function returns */
3512 struct type
*ftype
; /* Function that returns above type */
3513 struct attribute
*attr
;
3515 /* Decode the type that this subroutine returns */
3520 type
= die_type (die
, cu
);
3521 ftype
= lookup_function_type (type
);
3523 /* All functions in C++ have prototypes. */
3524 attr
= dwarf_attr (die
, DW_AT_prototyped
);
3525 if ((attr
&& (DW_UNSND (attr
) != 0))
3526 || cu_language
== language_cplus
)
3527 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
3529 if (die
->child
!= NULL
)
3531 struct die_info
*child_die
;
3535 /* Count the number of parameters.
3536 FIXME: GDB currently ignores vararg functions, but knows about
3537 vararg member functions. */
3538 child_die
= die
->child
;
3539 while (child_die
&& child_die
->tag
)
3541 if (child_die
->tag
== DW_TAG_formal_parameter
)
3543 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
3544 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
3545 child_die
= sibling_die (child_die
);
3548 /* Allocate storage for parameters and fill them in. */
3549 TYPE_NFIELDS (ftype
) = nparams
;
3550 TYPE_FIELDS (ftype
) = (struct field
*)
3551 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
3553 child_die
= die
->child
;
3554 while (child_die
&& child_die
->tag
)
3556 if (child_die
->tag
== DW_TAG_formal_parameter
)
3558 /* Dwarf2 has no clean way to discern C++ static and non-static
3559 member functions. G++ helps GDB by marking the first
3560 parameter for non-static member functions (which is the
3561 this pointer) as artificial. We pass this information
3562 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
3563 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
3565 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
3567 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
3568 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
3571 child_die
= sibling_die (child_die
);
3579 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
3581 struct objfile
*objfile
= cu
->objfile
;
3582 struct attribute
*attr
;
3587 attr
= dwarf_attr (die
, DW_AT_name
);
3588 if (attr
&& DW_STRING (attr
))
3590 name
= DW_STRING (attr
);
3592 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
3593 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, cu
);
3597 /* Find a representation of a given base type and install
3598 it in the TYPE field of the die. */
3601 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3603 struct objfile
*objfile
= cu
->objfile
;
3605 struct attribute
*attr
;
3606 int encoding
= 0, size
= 0;
3608 /* If we've already decoded this die, this is a no-op. */
3614 attr
= dwarf_attr (die
, DW_AT_encoding
);
3617 encoding
= DW_UNSND (attr
);
3619 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3622 size
= DW_UNSND (attr
);
3624 attr
= dwarf_attr (die
, DW_AT_name
);
3625 if (attr
&& DW_STRING (attr
))
3627 enum type_code code
= TYPE_CODE_INT
;
3632 case DW_ATE_address
:
3633 /* Turn DW_ATE_address into a void * pointer. */
3634 code
= TYPE_CODE_PTR
;
3635 type_flags
|= TYPE_FLAG_UNSIGNED
;
3637 case DW_ATE_boolean
:
3638 code
= TYPE_CODE_BOOL
;
3639 type_flags
|= TYPE_FLAG_UNSIGNED
;
3641 case DW_ATE_complex_float
:
3642 code
= TYPE_CODE_COMPLEX
;
3645 code
= TYPE_CODE_FLT
;
3648 case DW_ATE_signed_char
:
3650 case DW_ATE_unsigned
:
3651 case DW_ATE_unsigned_char
:
3652 type_flags
|= TYPE_FLAG_UNSIGNED
;
3655 complaint (&symfile_complaints
, "unsupported DW_AT_encoding: '%s'",
3656 dwarf_type_encoding_name (encoding
));
3659 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
3660 if (encoding
== DW_ATE_address
)
3661 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
3662 else if (encoding
== DW_ATE_complex_float
)
3665 TYPE_TARGET_TYPE (type
)
3666 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
3667 else if (size
== 16)
3668 TYPE_TARGET_TYPE (type
)
3669 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
3671 TYPE_TARGET_TYPE (type
)
3672 = dwarf2_fundamental_type (objfile
, FT_FLOAT
);
3677 type
= dwarf_base_type (encoding
, size
, cu
);
3682 /* Read a whole compilation unit into a linked list of dies. */
3684 static struct die_info
*
3685 read_comp_unit (char *info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
3687 /* Reset die reference table; we are
3688 building new ones now. */
3689 dwarf2_empty_hash_tables ();
3691 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
3694 /* Read a single die and all its descendents. Set the die's sibling
3695 field to NULL; set other fields in the die correctly, and set all
3696 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
3697 location of the info_ptr after reading all of those dies. PARENT
3698 is the parent of the die in question. */
3700 static struct die_info
*
3701 read_die_and_children (char *info_ptr
, bfd
*abfd
,
3702 struct dwarf2_cu
*cu
,
3703 char **new_info_ptr
,
3704 struct die_info
*parent
)
3706 struct die_info
*die
;
3710 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
3711 store_in_ref_table (die
->offset
, die
);
3715 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
3721 *new_info_ptr
= cur_ptr
;
3724 die
->sibling
= NULL
;
3725 die
->parent
= parent
;
3729 /* Read a die, all of its descendents, and all of its siblings; set
3730 all of the fields of all of the dies correctly. Arguments are as
3731 in read_die_and_children. */
3733 static struct die_info
*
3734 read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
3735 struct dwarf2_cu
*cu
,
3736 char **new_info_ptr
,
3737 struct die_info
*parent
)
3739 struct die_info
*first_die
, *last_sibling
;
3743 first_die
= last_sibling
= NULL
;
3747 struct die_info
*die
3748 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
3756 last_sibling
->sibling
= die
;
3761 *new_info_ptr
= cur_ptr
;
3771 /* Free a linked list of dies. */
3774 free_die_list (struct die_info
*dies
)
3776 struct die_info
*die
, *next
;
3781 if (die
->child
!= NULL
)
3782 free_die_list (die
->child
);
3783 next
= die
->sibling
;
3791 do_free_die_list_cleanup (void *dies
)
3793 free_die_list (dies
);
3796 static struct cleanup
*
3797 make_cleanup_free_die_list (struct die_info
*dies
)
3799 return make_cleanup (do_free_die_list_cleanup
, dies
);
3803 /* Read the contents of the section at OFFSET and of size SIZE from the
3804 object file specified by OBJFILE into the psymbol_obstack and return it. */
3807 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
3809 bfd
*abfd
= objfile
->obfd
;
3811 bfd_size_type size
= bfd_get_section_size_before_reloc (sectp
);
3816 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3818 = (char *) symfile_relocate_debug_section (abfd
, sectp
, (bfd_byte
*) buf
);
3822 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
3823 || bfd_bread (buf
, size
, abfd
) != size
)
3824 error ("Dwarf Error: Can't read DWARF data from '%s'",
3825 bfd_get_filename (abfd
));
3830 /* In DWARF version 2, the description of the debugging information is
3831 stored in a separate .debug_abbrev section. Before we read any
3832 dies from a section we read in all abbreviations and install them
3836 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
3838 struct comp_unit_head
*cu_header
= &cu
->header
;
3840 struct abbrev_info
*cur_abbrev
;
3841 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3842 unsigned int abbrev_form
, hash_number
;
3844 /* Initialize dwarf2 abbrevs */
3845 memset (cu_header
->dwarf2_abbrevs
, 0,
3846 ABBREV_HASH_SIZE
*sizeof (struct abbrev_info
*));
3848 abbrev_ptr
= dwarf_abbrev_buffer
+ cu_header
->abbrev_offset
;
3849 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3850 abbrev_ptr
+= bytes_read
;
3852 /* loop until we reach an abbrev number of 0 */
3853 while (abbrev_number
)
3855 cur_abbrev
= dwarf_alloc_abbrev ();
3857 /* read in abbrev header */
3858 cur_abbrev
->number
= abbrev_number
;
3859 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3860 abbrev_ptr
+= bytes_read
;
3861 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3864 /* now read in declarations */
3865 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3866 abbrev_ptr
+= bytes_read
;
3867 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3868 abbrev_ptr
+= bytes_read
;
3871 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3873 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3874 xrealloc (cur_abbrev
->attrs
,
3875 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3876 * sizeof (struct attr_abbrev
));
3878 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3879 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3880 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3881 abbrev_ptr
+= bytes_read
;
3882 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3883 abbrev_ptr
+= bytes_read
;
3886 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3887 cur_abbrev
->next
= cu_header
->dwarf2_abbrevs
[hash_number
];
3888 cu_header
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3890 /* Get next abbreviation.
3891 Under Irix6 the abbreviations for a compilation unit are not
3892 always properly terminated with an abbrev number of 0.
3893 Exit loop if we encounter an abbreviation which we have
3894 already read (which means we are about to read the abbreviations
3895 for the next compile unit) or if the end of the abbreviation
3896 table is reached. */
3897 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3898 >= dwarf_abbrev_size
)
3900 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3901 abbrev_ptr
+= bytes_read
;
3902 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
3907 /* Empty the abbrev table for a new compilation unit. */
3910 dwarf2_empty_abbrev_table (void *ptr_to_abbrevs_table
)
3913 struct abbrev_info
*abbrev
, *next
;
3914 struct abbrev_info
**abbrevs
;
3916 abbrevs
= (struct abbrev_info
**)ptr_to_abbrevs_table
;
3918 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3921 abbrev
= abbrevs
[i
];
3924 next
= abbrev
->next
;
3925 xfree (abbrev
->attrs
);
3933 /* Lookup an abbrev_info structure in the abbrev hash table. */
3935 static struct abbrev_info
*
3936 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
3938 struct comp_unit_head
*cu_header
= &cu
->header
;
3939 unsigned int hash_number
;
3940 struct abbrev_info
*abbrev
;
3942 hash_number
= number
% ABBREV_HASH_SIZE
;
3943 abbrev
= cu_header
->dwarf2_abbrevs
[hash_number
];
3947 if (abbrev
->number
== number
)
3950 abbrev
= abbrev
->next
;
3955 /* Read a minimal amount of information into the minimal die structure. */
3958 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3959 char *info_ptr
, struct dwarf2_cu
*cu
)
3961 unsigned int abbrev_number
, bytes_read
, i
;
3962 struct abbrev_info
*abbrev
;
3963 struct attribute attr
;
3964 struct attribute spec_attr
;
3965 int found_spec_attr
= 0;
3966 int has_low_pc_attr
= 0;
3967 int has_high_pc_attr
= 0;
3969 *part_die
= zeroed_partial_die
;
3970 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3971 info_ptr
+= bytes_read
;
3975 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
3978 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number
,
3979 bfd_get_filename (abfd
));
3981 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3982 part_die
->tag
= abbrev
->tag
;
3983 part_die
->has_children
= abbrev
->has_children
;
3984 part_die
->abbrev
= abbrev_number
;
3986 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3988 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
3990 /* Store the data if it is of an attribute we want to keep in a
3991 partial symbol table. */
3996 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3997 if (part_die
->name
== NULL
)
3998 part_die
->name
= DW_STRING (&attr
);
4000 case DW_AT_MIPS_linkage_name
:
4001 part_die
->name
= DW_STRING (&attr
);
4004 has_low_pc_attr
= 1;
4005 part_die
->lowpc
= DW_ADDR (&attr
);
4008 has_high_pc_attr
= 1;
4009 part_die
->highpc
= DW_ADDR (&attr
);
4011 case DW_AT_location
:
4012 /* Support the .debug_loc offsets */
4013 if (attr_form_is_block (&attr
))
4015 part_die
->locdesc
= DW_BLOCK (&attr
);
4017 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
4019 dwarf2_complex_location_expr_complaint ();
4023 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4024 "partial symbol information");
4027 case DW_AT_language
:
4028 part_die
->language
= DW_UNSND (&attr
);
4030 case DW_AT_external
:
4031 part_die
->is_external
= DW_UNSND (&attr
);
4033 case DW_AT_declaration
:
4034 part_die
->is_declaration
= DW_UNSND (&attr
);
4037 part_die
->has_type
= 1;
4039 case DW_AT_abstract_origin
:
4040 case DW_AT_specification
:
4041 found_spec_attr
= 1;
4045 /* Ignore absolute siblings, they might point outside of
4046 the current compile unit. */
4047 if (attr
.form
== DW_FORM_ref_addr
)
4048 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
4051 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
4058 /* If we found a reference attribute and the die has no name, try
4059 to find a name in the referred to die. */
4061 if (found_spec_attr
&& part_die
->name
== NULL
)
4063 struct partial_die_info spec_die
;
4066 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
4067 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu
);
4070 part_die
->name
= spec_die
.name
;
4072 /* Copy DW_AT_external attribute if it is set. */
4073 if (spec_die
.is_external
)
4074 part_die
->is_external
= spec_die
.is_external
;
4078 /* When using the GNU linker, .gnu.linkonce. sections are used to
4079 eliminate duplicate copies of functions and vtables and such.
4080 The linker will arbitrarily choose one and discard the others.
4081 The AT_*_pc values for such functions refer to local labels in
4082 these sections. If the section from that file was discarded, the
4083 labels are not in the output, so the relocs get a value of 0.
4084 If this is a discarded function, mark the pc bounds as invalid,
4085 so that GDB will ignore it. */
4086 if (has_low_pc_attr
&& has_high_pc_attr
4087 && part_die
->lowpc
< part_die
->highpc
4088 && (part_die
->lowpc
!= 0
4089 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
4090 part_die
->has_pc_info
= 1;
4094 /* Read the die from the .debug_info section buffer. Set DIEP to
4095 point to a newly allocated die with its information, except for its
4096 child, sibling, and parent fields. Set HAS_CHILDREN to tell
4097 whether the die has children or not. */
4100 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
4101 struct dwarf2_cu
*cu
, int *has_children
)
4103 unsigned int abbrev_number
, bytes_read
, i
, offset
;
4104 struct abbrev_info
*abbrev
;
4105 struct die_info
*die
;
4107 offset
= info_ptr
- dwarf_info_buffer
;
4108 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4109 info_ptr
+= bytes_read
;
4112 die
= dwarf_alloc_die ();
4114 die
->abbrev
= abbrev_number
;
4121 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4124 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
4126 bfd_get_filename (abfd
));
4128 die
= dwarf_alloc_die ();
4129 die
->offset
= offset
;
4130 die
->tag
= abbrev
->tag
;
4131 die
->abbrev
= abbrev_number
;
4134 die
->num_attrs
= abbrev
->num_attrs
;
4135 die
->attrs
= (struct attribute
*)
4136 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
4138 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4140 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
4141 abfd
, info_ptr
, cu
);
4145 *has_children
= abbrev
->has_children
;
4149 /* Read an attribute value described by an attribute form. */
4152 read_attribute_value (struct attribute
*attr
, unsigned form
,
4153 bfd
*abfd
, char *info_ptr
,
4154 struct dwarf2_cu
*cu
)
4156 struct comp_unit_head
*cu_header
= &cu
->header
;
4157 unsigned int bytes_read
;
4158 struct dwarf_block
*blk
;
4164 case DW_FORM_ref_addr
:
4165 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
4166 info_ptr
+= bytes_read
;
4168 case DW_FORM_block2
:
4169 blk
= dwarf_alloc_block ();
4170 blk
->size
= read_2_bytes (abfd
, info_ptr
);
4172 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4173 info_ptr
+= blk
->size
;
4174 DW_BLOCK (attr
) = blk
;
4176 case DW_FORM_block4
:
4177 blk
= dwarf_alloc_block ();
4178 blk
->size
= read_4_bytes (abfd
, info_ptr
);
4180 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4181 info_ptr
+= blk
->size
;
4182 DW_BLOCK (attr
) = blk
;
4185 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4189 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4193 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4196 case DW_FORM_string
:
4197 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
4198 info_ptr
+= bytes_read
;
4201 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
4203 info_ptr
+= bytes_read
;
4206 blk
= dwarf_alloc_block ();
4207 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4208 info_ptr
+= bytes_read
;
4209 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4210 info_ptr
+= blk
->size
;
4211 DW_BLOCK (attr
) = blk
;
4213 case DW_FORM_block1
:
4214 blk
= dwarf_alloc_block ();
4215 blk
->size
= read_1_byte (abfd
, info_ptr
);
4217 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4218 info_ptr
+= blk
->size
;
4219 DW_BLOCK (attr
) = blk
;
4222 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4226 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4230 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
4231 info_ptr
+= bytes_read
;
4234 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4235 info_ptr
+= bytes_read
;
4238 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4242 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4246 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4250 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4253 case DW_FORM_ref_udata
:
4254 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4255 info_ptr
+= bytes_read
;
4257 case DW_FORM_indirect
:
4258 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4259 info_ptr
+= bytes_read
;
4260 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
4263 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
4264 dwarf_form_name (form
),
4265 bfd_get_filename (abfd
));
4270 /* Read an attribute described by an abbreviated attribute. */
4273 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
4274 bfd
*abfd
, char *info_ptr
, struct dwarf2_cu
*cu
)
4276 attr
->name
= abbrev
->name
;
4277 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
4280 /* read dwarf information from a buffer */
4283 read_1_byte (bfd
*abfd
, char *buf
)
4285 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4289 read_1_signed_byte (bfd
*abfd
, char *buf
)
4291 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
4295 read_2_bytes (bfd
*abfd
, char *buf
)
4297 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4301 read_2_signed_bytes (bfd
*abfd
, char *buf
)
4303 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4307 read_4_bytes (bfd
*abfd
, char *buf
)
4309 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4313 read_4_signed_bytes (bfd
*abfd
, char *buf
)
4315 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4318 static unsigned long
4319 read_8_bytes (bfd
*abfd
, char *buf
)
4321 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4325 read_address (bfd
*abfd
, char *buf
, struct dwarf2_cu
*cu
, int *bytes_read
)
4327 struct comp_unit_head
*cu_header
= &cu
->header
;
4328 CORE_ADDR retval
= 0;
4330 if (cu_header
->signed_addr_p
)
4332 switch (cu_header
->addr_size
)
4335 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4338 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4341 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
4344 internal_error (__FILE__
, __LINE__
,
4345 "read_address: bad switch, signed [in module %s]",
4346 bfd_get_filename (abfd
));
4351 switch (cu_header
->addr_size
)
4354 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4357 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4360 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4363 internal_error (__FILE__
, __LINE__
,
4364 "read_address: bad switch, unsigned [in module %s]",
4365 bfd_get_filename (abfd
));
4369 *bytes_read
= cu_header
->addr_size
;
4373 /* Read the initial length from a section. The (draft) DWARF 3
4374 specification allows the initial length to take up either 4 bytes
4375 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
4376 bytes describe the length and all offsets will be 8 bytes in length
4379 An older, non-standard 64-bit format is also handled by this
4380 function. The older format in question stores the initial length
4381 as an 8-byte quantity without an escape value. Lengths greater
4382 than 2^32 aren't very common which means that the initial 4 bytes
4383 is almost always zero. Since a length value of zero doesn't make
4384 sense for the 32-bit format, this initial zero can be considered to
4385 be an escape value which indicates the presence of the older 64-bit
4386 format. As written, the code can't detect (old format) lengths
4387 greater than 4GB. If it becomes necessary to handle lengths somewhat
4388 larger than 4GB, we could allow other small values (such as the
4389 non-sensical values of 1, 2, and 3) to also be used as escape values
4390 indicating the presence of the old format.
4392 The value returned via bytes_read should be used to increment
4393 the relevant pointer after calling read_initial_length().
4395 As a side effect, this function sets the fields initial_length_size
4396 and offset_size in cu_header to the values appropriate for the
4397 length field. (The format of the initial length field determines
4398 the width of file offsets to be fetched later with fetch_offset().)
4400 [ Note: read_initial_length() and read_offset() are based on the
4401 document entitled "DWARF Debugging Information Format", revision
4402 3, draft 8, dated November 19, 2001. This document was obtained
4405 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
4407 This document is only a draft and is subject to change. (So beware.)
4409 Details regarding the older, non-standard 64-bit format were
4410 determined empirically by examining 64-bit ELF files produced
4411 by the SGI toolchain on an IRIX 6.5 machine.
4413 - Kevin, July 16, 2002
4417 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
4422 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4424 if (retval
== 0xffffffff)
4426 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
4428 if (cu_header
!= NULL
)
4430 cu_header
->initial_length_size
= 12;
4431 cu_header
->offset_size
= 8;
4434 else if (retval
== 0)
4436 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
4438 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4440 if (cu_header
!= NULL
)
4442 cu_header
->initial_length_size
= 8;
4443 cu_header
->offset_size
= 8;
4449 if (cu_header
!= NULL
)
4451 cu_header
->initial_length_size
= 4;
4452 cu_header
->offset_size
= 4;
4459 /* Read an offset from the data stream. The size of the offset is
4460 given by cu_header->offset_size. */
4463 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
4468 switch (cu_header
->offset_size
)
4471 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4475 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4479 internal_error (__FILE__
, __LINE__
,
4480 "read_offset: bad switch [in module %s]",
4481 bfd_get_filename (abfd
));
4488 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
4490 /* If the size of a host char is 8 bits, we can return a pointer
4491 to the buffer, otherwise we have to copy the data to a buffer
4492 allocated on the temporary obstack. */
4493 gdb_assert (HOST_CHAR_BIT
== 8);
4498 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4500 /* If the size of a host char is 8 bits, we can return a pointer
4501 to the string, otherwise we have to copy the string to a buffer
4502 allocated on the temporary obstack. */
4503 gdb_assert (HOST_CHAR_BIT
== 8);
4506 *bytes_read_ptr
= 1;
4509 *bytes_read_ptr
= strlen (buf
) + 1;
4514 read_indirect_string (bfd
*abfd
, char *buf
,
4515 const struct comp_unit_head
*cu_header
,
4516 unsigned int *bytes_read_ptr
)
4518 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
4519 (int *) bytes_read_ptr
);
4521 if (dwarf_str_buffer
== NULL
)
4523 error ("DW_FORM_strp used without .debug_str section [in module %s]",
4524 bfd_get_filename (abfd
));
4527 if (str_offset
>= dwarf_str_size
)
4529 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
4530 bfd_get_filename (abfd
));
4533 gdb_assert (HOST_CHAR_BIT
== 8);
4534 if (dwarf_str_buffer
[str_offset
] == '\0')
4536 return dwarf_str_buffer
+ str_offset
;
4539 static unsigned long
4540 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4542 unsigned long result
;
4543 unsigned int num_read
;
4553 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4556 result
|= ((unsigned long)(byte
& 127) << shift
);
4557 if ((byte
& 128) == 0)
4563 *bytes_read_ptr
= num_read
;
4568 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4571 int i
, shift
, size
, num_read
;
4581 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4584 result
|= ((long)(byte
& 127) << shift
);
4586 if ((byte
& 128) == 0)
4591 if ((shift
< size
) && (byte
& 0x40))
4593 result
|= -(1 << shift
);
4595 *bytes_read_ptr
= num_read
;
4600 set_cu_language (unsigned int lang
)
4606 cu_language
= language_c
;
4608 case DW_LANG_C_plus_plus
:
4609 cu_language
= language_cplus
;
4611 case DW_LANG_Fortran77
:
4612 case DW_LANG_Fortran90
:
4613 case DW_LANG_Fortran95
:
4614 cu_language
= language_fortran
;
4616 case DW_LANG_Mips_Assembler
:
4617 cu_language
= language_asm
;
4620 cu_language
= language_java
;
4624 case DW_LANG_Cobol74
:
4625 case DW_LANG_Cobol85
:
4626 case DW_LANG_Pascal83
:
4627 case DW_LANG_Modula2
:
4629 cu_language
= language_minimal
;
4632 cu_language_defn
= language_def (cu_language
);
4635 /* Return the named attribute or NULL if not there. */
4637 static struct attribute
*
4638 dwarf_attr (struct die_info
*die
, unsigned int name
)
4641 struct attribute
*spec
= NULL
;
4643 for (i
= 0; i
< die
->num_attrs
; ++i
)
4645 if (die
->attrs
[i
].name
== name
)
4647 return &die
->attrs
[i
];
4649 if (die
->attrs
[i
].name
== DW_AT_specification
4650 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
4651 spec
= &die
->attrs
[i
];
4655 struct die_info
*ref_die
=
4656 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
4659 return dwarf_attr (ref_die
, name
);
4666 die_is_declaration (struct die_info
*die
)
4668 return (dwarf_attr (die
, DW_AT_declaration
)
4669 && ! dwarf_attr (die
, DW_AT_specification
));
4673 /* Free the line_header structure *LH, and any arrays and strings it
4676 free_line_header (struct line_header
*lh
)
4678 if (lh
->standard_opcode_lengths
)
4679 xfree (lh
->standard_opcode_lengths
);
4681 /* Remember that all the lh->file_names[i].name pointers are
4682 pointers into debug_line_buffer, and don't need to be freed. */
4684 xfree (lh
->file_names
);
4686 /* Similarly for the include directory names. */
4687 if (lh
->include_dirs
)
4688 xfree (lh
->include_dirs
);
4694 /* Add an entry to LH's include directory table. */
4696 add_include_dir (struct line_header
*lh
, char *include_dir
)
4698 /* Grow the array if necessary. */
4699 if (lh
->include_dirs_size
== 0)
4701 lh
->include_dirs_size
= 1; /* for testing */
4702 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
4703 * sizeof (*lh
->include_dirs
));
4705 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
4707 lh
->include_dirs_size
*= 2;
4708 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
4709 (lh
->include_dirs_size
4710 * sizeof (*lh
->include_dirs
)));
4713 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
4717 /* Add an entry to LH's file name table. */
4719 add_file_name (struct line_header
*lh
,
4721 unsigned int dir_index
,
4722 unsigned int mod_time
,
4723 unsigned int length
)
4725 struct file_entry
*fe
;
4727 /* Grow the array if necessary. */
4728 if (lh
->file_names_size
== 0)
4730 lh
->file_names_size
= 1; /* for testing */
4731 lh
->file_names
= xmalloc (lh
->file_names_size
4732 * sizeof (*lh
->file_names
));
4734 else if (lh
->num_file_names
>= lh
->file_names_size
)
4736 lh
->file_names_size
*= 2;
4737 lh
->file_names
= xrealloc (lh
->file_names
,
4738 (lh
->file_names_size
4739 * sizeof (*lh
->file_names
)));
4742 fe
= &lh
->file_names
[lh
->num_file_names
++];
4744 fe
->dir_index
= dir_index
;
4745 fe
->mod_time
= mod_time
;
4746 fe
->length
= length
;
4750 /* Read the statement program header starting at OFFSET in
4751 dwarf_line_buffer, according to the endianness of ABFD. Return a
4752 pointer to a struct line_header, allocated using xmalloc.
4754 NOTE: the strings in the include directory and file name tables of
4755 the returned object point into debug_line_buffer, and must not be
4757 static struct line_header
*
4758 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
4759 struct dwarf2_cu
*cu
)
4761 struct cleanup
*back_to
;
4762 struct line_header
*lh
;
4766 char *cur_dir
, *cur_file
;
4768 if (dwarf_line_buffer
== NULL
)
4770 complaint (&symfile_complaints
, "missing .debug_line section");
4774 /* Make sure that at least there's room for the total_length field. That
4775 could be 12 bytes long, but we're just going to fudge that. */
4776 if (offset
+ 4 >= dwarf_line_size
)
4778 dwarf2_statement_list_fits_in_line_number_section_complaint ();
4782 lh
= xmalloc (sizeof (*lh
));
4783 memset (lh
, 0, sizeof (*lh
));
4784 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
4787 line_ptr
= dwarf_line_buffer
+ offset
;
4789 /* read in the header */
4790 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
4791 line_ptr
+= bytes_read
;
4792 if (line_ptr
+ lh
->total_length
> dwarf_line_buffer
+ dwarf_line_size
)
4794 dwarf2_statement_list_fits_in_line_number_section_complaint ();
4797 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
4798 lh
->version
= read_2_bytes (abfd
, line_ptr
);
4800 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
4801 line_ptr
+= bytes_read
;
4802 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
4804 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
4806 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
4808 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
4810 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
4812 lh
->standard_opcode_lengths
4813 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
4815 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
4816 for (i
= 1; i
< lh
->opcode_base
; ++i
)
4818 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
4822 /* Read directory table */
4823 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4825 line_ptr
+= bytes_read
;
4826 add_include_dir (lh
, cur_dir
);
4828 line_ptr
+= bytes_read
;
4830 /* Read file name table */
4831 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4833 unsigned int dir_index
, mod_time
, length
;
4835 line_ptr
+= bytes_read
;
4836 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4837 line_ptr
+= bytes_read
;
4838 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4839 line_ptr
+= bytes_read
;
4840 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4841 line_ptr
+= bytes_read
;
4843 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4845 line_ptr
+= bytes_read
;
4846 lh
->statement_program_start
= line_ptr
;
4848 if (line_ptr
> dwarf_line_buffer
+ dwarf_line_size
)
4849 complaint (&symfile_complaints
,
4850 "line number info header doesn't fit in `.debug_line' section");
4852 discard_cleanups (back_to
);
4856 /* This function exists to work around a bug in certain compilers
4857 (particularly GCC 2.95), in which the first line number marker of a
4858 function does not show up until after the prologue, right before
4859 the second line number marker. This function shifts ADDRESS down
4860 to the beginning of the function if necessary, and is called on
4861 addresses passed to record_line. */
4864 check_cu_functions (CORE_ADDR address
)
4866 struct function_range
*fn
;
4868 /* Find the function_range containing address. */
4873 cu_cached_fn
= cu_first_fn
;
4877 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4883 while (fn
&& fn
!= cu_cached_fn
)
4884 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4894 if (address
!= fn
->lowpc
)
4895 complaint (&symfile_complaints
,
4896 "misplaced first line number at 0x%lx for '%s'",
4897 (unsigned long) address
, fn
->name
);
4902 /* Decode the line number information for the compilation unit whose
4903 line number info is at OFFSET in the .debug_line section.
4904 The compilation directory of the file is passed in COMP_DIR. */
4907 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
4908 struct dwarf2_cu
*cu
)
4912 unsigned int bytes_read
;
4913 unsigned char op_code
, extended_op
, adj_opcode
;
4915 line_ptr
= lh
->statement_program_start
;
4916 line_end
= lh
->statement_program_end
;
4918 /* Read the statement sequences until there's nothing left. */
4919 while (line_ptr
< line_end
)
4921 /* state machine registers */
4922 CORE_ADDR address
= 0;
4923 unsigned int file
= 1;
4924 unsigned int line
= 1;
4925 unsigned int column
= 0;
4926 int is_stmt
= lh
->default_is_stmt
;
4927 int basic_block
= 0;
4928 int end_sequence
= 0;
4930 /* Start a subfile for the current file of the state machine. */
4931 if (lh
->num_file_names
>= file
)
4933 /* lh->include_dirs and lh->file_names are 0-based, but the
4934 directory and file name numbers in the statement program
4936 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
4939 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
4942 dwarf2_start_subfile (fe
->name
, dir
);
4945 /* Decode the table. */
4946 while (!end_sequence
)
4948 op_code
= read_1_byte (abfd
, line_ptr
);
4951 if (op_code
>= lh
->opcode_base
)
4952 { /* Special operand. */
4953 adj_opcode
= op_code
- lh
->opcode_base
;
4954 address
+= (adj_opcode
/ lh
->line_range
)
4955 * lh
->minimum_instruction_length
;
4956 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
4957 /* append row to matrix using current values */
4958 record_line (current_subfile
, line
,
4959 check_cu_functions (address
));
4962 else switch (op_code
)
4964 case DW_LNS_extended_op
:
4965 line_ptr
+= 1; /* ignore length */
4966 extended_op
= read_1_byte (abfd
, line_ptr
);
4968 switch (extended_op
)
4970 case DW_LNE_end_sequence
:
4972 record_line (current_subfile
, 0, address
);
4974 case DW_LNE_set_address
:
4975 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
4976 line_ptr
+= bytes_read
;
4977 address
+= baseaddr
;
4979 case DW_LNE_define_file
:
4982 unsigned int dir_index
, mod_time
, length
;
4984 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
4985 line_ptr
+= bytes_read
;
4987 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4988 line_ptr
+= bytes_read
;
4990 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4991 line_ptr
+= bytes_read
;
4993 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4994 line_ptr
+= bytes_read
;
4995 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4999 complaint (&symfile_complaints
,
5000 "mangled .debug_line section");
5005 record_line (current_subfile
, line
,
5006 check_cu_functions (address
));
5009 case DW_LNS_advance_pc
:
5010 address
+= lh
->minimum_instruction_length
5011 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5012 line_ptr
+= bytes_read
;
5014 case DW_LNS_advance_line
:
5015 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
5016 line_ptr
+= bytes_read
;
5018 case DW_LNS_set_file
:
5020 /* lh->include_dirs and lh->file_names are 0-based,
5021 but the directory and file name numbers in the
5022 statement program are 1-based. */
5023 struct file_entry
*fe
;
5025 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5026 line_ptr
+= bytes_read
;
5027 fe
= &lh
->file_names
[file
- 1];
5029 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
5032 dwarf2_start_subfile (fe
->name
, dir
);
5035 case DW_LNS_set_column
:
5036 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5037 line_ptr
+= bytes_read
;
5039 case DW_LNS_negate_stmt
:
5040 is_stmt
= (!is_stmt
);
5042 case DW_LNS_set_basic_block
:
5045 /* Add to the address register of the state machine the
5046 address increment value corresponding to special opcode
5047 255. Ie, this value is scaled by the minimum instruction
5048 length since special opcode 255 would have scaled the
5050 case DW_LNS_const_add_pc
:
5051 address
+= (lh
->minimum_instruction_length
5052 * ((255 - lh
->opcode_base
) / lh
->line_range
));
5054 case DW_LNS_fixed_advance_pc
:
5055 address
+= read_2_bytes (abfd
, line_ptr
);
5059 { /* Unknown standard opcode, ignore it. */
5061 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
5063 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5064 line_ptr
+= bytes_read
;
5072 /* Start a subfile for DWARF. FILENAME is the name of the file and
5073 DIRNAME the name of the source directory which contains FILENAME
5074 or NULL if not known.
5075 This routine tries to keep line numbers from identical absolute and
5076 relative file names in a common subfile.
5078 Using the `list' example from the GDB testsuite, which resides in
5079 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
5080 of /srcdir/list0.c yields the following debugging information for list0.c:
5082 DW_AT_name: /srcdir/list0.c
5083 DW_AT_comp_dir: /compdir
5084 files.files[0].name: list0.h
5085 files.files[0].dir: /srcdir
5086 files.files[1].name: list0.c
5087 files.files[1].dir: /srcdir
5089 The line number information for list0.c has to end up in a single
5090 subfile, so that `break /srcdir/list0.c:1' works as expected. */
5093 dwarf2_start_subfile (char *filename
, char *dirname
)
5095 /* If the filename isn't absolute, try to match an existing subfile
5096 with the full pathname. */
5098 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
5100 struct subfile
*subfile
;
5101 char *fullname
= concat (dirname
, "/", filename
, NULL
);
5103 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
5105 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
5107 current_subfile
= subfile
;
5114 start_subfile (filename
, dirname
);
5118 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
5119 struct dwarf2_cu
*cu
)
5121 struct objfile
*objfile
= cu
->objfile
;
5122 struct comp_unit_head
*cu_header
= &cu
->header
;
5124 /* NOTE drow/2003-01-30: There used to be a comment and some special
5125 code here to turn a symbol with DW_AT_external and a
5126 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
5127 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
5128 with some versions of binutils) where shared libraries could have
5129 relocations against symbols in their debug information - the
5130 minimal symbol would have the right address, but the debug info
5131 would not. It's no longer necessary, because we will explicitly
5132 apply relocations when we read in the debug information now. */
5134 /* A DW_AT_location attribute with no contents indicates that a
5135 variable has been optimized away. */
5136 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
5138 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
5142 /* Handle one degenerate form of location expression specially, to
5143 preserve GDB's previous behavior when section offsets are
5144 specified. If this is just a DW_OP_addr then mark this symbol
5147 if (attr_form_is_block (attr
)
5148 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
5149 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
5153 SYMBOL_VALUE_ADDRESS (sym
) =
5154 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
5155 fixup_symbol_section (sym
, objfile
);
5156 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
5157 SYMBOL_SECTION (sym
));
5158 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5162 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
5163 expression evaluator, and use LOC_COMPUTED only when necessary
5164 (i.e. when the value of a register or memory location is
5165 referenced, or a thread-local block, etc.). Then again, it might
5166 not be worthwhile. I'm assuming that it isn't unless performance
5167 or memory numbers show me otherwise. */
5169 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
5170 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
5173 /* Given a pointer to a DWARF information entry, figure out if we need
5174 to make a symbol table entry for it, and if so, create a new entry
5175 and return a pointer to it.
5176 If TYPE is NULL, determine symbol type from the die, otherwise
5177 used the passed type. */
5179 static struct symbol
*
5180 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
5182 struct objfile
*objfile
= cu
->objfile
;
5183 struct symbol
*sym
= NULL
;
5185 struct attribute
*attr
= NULL
;
5186 struct attribute
*attr2
= NULL
;
5188 if (die
->tag
!= DW_TAG_namespace
)
5189 name
= dwarf2_linkage_name (die
);
5191 name
= TYPE_NAME (type
);
5195 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
5196 sizeof (struct symbol
));
5197 OBJSTAT (objfile
, n_syms
++);
5198 memset (sym
, 0, sizeof (struct symbol
));
5200 /* Cache this symbol's name and the name's demangled form (if any). */
5201 SYMBOL_LANGUAGE (sym
) = cu_language
;
5202 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
5204 /* Default assumptions.
5205 Use the passed type or decode it from the die. */
5206 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5207 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5209 SYMBOL_TYPE (sym
) = type
;
5211 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
5212 attr
= dwarf_attr (die
, DW_AT_decl_line
);
5215 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
5220 attr
= dwarf_attr (die
, DW_AT_low_pc
);
5223 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
5225 SYMBOL_CLASS (sym
) = LOC_LABEL
;
5227 case DW_TAG_subprogram
:
5228 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
5230 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
5231 attr2
= dwarf_attr (die
, DW_AT_external
);
5232 if (attr2
&& (DW_UNSND (attr2
) != 0))
5234 add_symbol_to_list (sym
, &global_symbols
);
5238 add_symbol_to_list (sym
, list_in_scope
);
5241 case DW_TAG_variable
:
5242 /* Compilation with minimal debug info may result in variables
5243 with missing type entries. Change the misleading `void' type
5244 to something sensible. */
5245 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
5246 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
5247 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
5248 "<variable, no debug info>",
5250 attr
= dwarf_attr (die
, DW_AT_const_value
);
5253 dwarf2_const_value (attr
, sym
, cu
);
5254 attr2
= dwarf_attr (die
, DW_AT_external
);
5255 if (attr2
&& (DW_UNSND (attr2
) != 0))
5256 add_symbol_to_list (sym
, &global_symbols
);
5258 add_symbol_to_list (sym
, list_in_scope
);
5261 attr
= dwarf_attr (die
, DW_AT_location
);
5264 var_decode_location (attr
, sym
, cu
);
5265 attr2
= dwarf_attr (die
, DW_AT_external
);
5266 if (attr2
&& (DW_UNSND (attr2
) != 0))
5267 add_symbol_to_list (sym
, &global_symbols
);
5269 add_symbol_to_list (sym
, list_in_scope
);
5273 /* We do not know the address of this symbol.
5274 If it is an external symbol and we have type information
5275 for it, enter the symbol as a LOC_UNRESOLVED symbol.
5276 The address of the variable will then be determined from
5277 the minimal symbol table whenever the variable is
5279 attr2
= dwarf_attr (die
, DW_AT_external
);
5280 if (attr2
&& (DW_UNSND (attr2
) != 0)
5281 && dwarf_attr (die
, DW_AT_type
) != NULL
)
5283 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
5284 add_symbol_to_list (sym
, &global_symbols
);
5288 case DW_TAG_formal_parameter
:
5289 attr
= dwarf_attr (die
, DW_AT_location
);
5292 var_decode_location (attr
, sym
, cu
);
5293 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
5294 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
5295 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
5297 attr
= dwarf_attr (die
, DW_AT_const_value
);
5300 dwarf2_const_value (attr
, sym
, cu
);
5302 add_symbol_to_list (sym
, list_in_scope
);
5304 case DW_TAG_unspecified_parameters
:
5305 /* From varargs functions; gdb doesn't seem to have any
5306 interest in this information, so just ignore it for now.
5309 case DW_TAG_class_type
:
5310 case DW_TAG_structure_type
:
5311 case DW_TAG_union_type
:
5312 case DW_TAG_enumeration_type
:
5313 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5314 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
5315 add_symbol_to_list (sym
, list_in_scope
);
5317 /* The semantics of C++ state that "struct foo { ... }" also
5318 defines a typedef for "foo". Synthesize a typedef symbol so
5319 that "ptype foo" works as expected. */
5320 if (cu_language
== language_cplus
)
5322 struct symbol
*typedef_sym
= (struct symbol
*)
5323 obstack_alloc (&objfile
->symbol_obstack
,
5324 sizeof (struct symbol
));
5325 *typedef_sym
= *sym
;
5326 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
5327 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
5328 TYPE_NAME (SYMBOL_TYPE (sym
)) =
5329 obsavestring (DEPRECATED_SYMBOL_NAME (sym
),
5330 strlen (DEPRECATED_SYMBOL_NAME (sym
)),
5331 &objfile
->type_obstack
);
5332 add_symbol_to_list (typedef_sym
, list_in_scope
);
5335 case DW_TAG_typedef
:
5336 case DW_TAG_base_type
:
5337 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5338 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5339 add_symbol_to_list (sym
, list_in_scope
);
5341 case DW_TAG_enumerator
:
5342 attr
= dwarf_attr (die
, DW_AT_const_value
);
5345 dwarf2_const_value (attr
, sym
, cu
);
5347 add_symbol_to_list (sym
, list_in_scope
);
5349 case DW_TAG_namespace
:
5350 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5351 add_symbol_to_list (sym
, &global_symbols
);
5354 /* Not a tag we recognize. Hopefully we aren't processing
5355 trash data, but since we must specifically ignore things
5356 we don't recognize, there is nothing else we should do at
5358 complaint (&symfile_complaints
, "unsupported tag: '%s'",
5359 dwarf_tag_name (die
->tag
));
5366 /* Copy constant value from an attribute to a symbol. */
5369 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
5370 struct dwarf2_cu
*cu
)
5372 struct objfile
*objfile
= cu
->objfile
;
5373 struct comp_unit_head
*cu_header
= &cu
->header
;
5374 struct dwarf_block
*blk
;
5379 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
5380 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5381 cu_header
->addr_size
,
5382 TYPE_LENGTH (SYMBOL_TYPE
5384 SYMBOL_VALUE_BYTES (sym
) = (char *)
5385 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
5386 /* NOTE: cagney/2003-05-09: In-lined store_address call with
5387 it's body - store_unsigned_integer. */
5388 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
5390 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5392 case DW_FORM_block1
:
5393 case DW_FORM_block2
:
5394 case DW_FORM_block4
:
5396 blk
= DW_BLOCK (attr
);
5397 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
5398 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5400 TYPE_LENGTH (SYMBOL_TYPE
5402 SYMBOL_VALUE_BYTES (sym
) = (char *)
5403 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
5404 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
5405 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5408 /* The DW_AT_const_value attributes are supposed to carry the
5409 symbol's value "represented as it would be on the target
5410 architecture." By the time we get here, it's already been
5411 converted to host endianness, so we just need to sign- or
5412 zero-extend it as appropriate. */
5414 dwarf2_const_value_data (attr
, sym
, 8);
5417 dwarf2_const_value_data (attr
, sym
, 16);
5420 dwarf2_const_value_data (attr
, sym
, 32);
5423 dwarf2_const_value_data (attr
, sym
, 64);
5427 SYMBOL_VALUE (sym
) = DW_SND (attr
);
5428 SYMBOL_CLASS (sym
) = LOC_CONST
;
5432 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
5433 SYMBOL_CLASS (sym
) = LOC_CONST
;
5437 complaint (&symfile_complaints
,
5438 "unsupported const value attribute form: '%s'",
5439 dwarf_form_name (attr
->form
));
5440 SYMBOL_VALUE (sym
) = 0;
5441 SYMBOL_CLASS (sym
) = LOC_CONST
;
5447 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
5448 or zero-extend it as appropriate for the symbol's type. */
5450 dwarf2_const_value_data (struct attribute
*attr
,
5454 LONGEST l
= DW_UNSND (attr
);
5456 if (bits
< sizeof (l
) * 8)
5458 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
5459 l
&= ((LONGEST
) 1 << bits
) - 1;
5461 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
5464 SYMBOL_VALUE (sym
) = l
;
5465 SYMBOL_CLASS (sym
) = LOC_CONST
;
5469 /* Return the type of the die in question using its DW_AT_type attribute. */
5471 static struct type
*
5472 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5475 struct attribute
*type_attr
;
5476 struct die_info
*type_die
;
5479 type_attr
= dwarf_attr (die
, DW_AT_type
);
5482 /* A missing DW_AT_type represents a void type. */
5483 return dwarf2_fundamental_type (cu
->objfile
, FT_VOID
);
5487 ref
= dwarf2_get_ref_die_offset (type_attr
);
5488 type_die
= follow_die_ref (ref
);
5491 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
5492 ref
, cu
->objfile
->name
);
5496 type
= tag_type_to_type (type_die
, cu
);
5499 dump_die (type_die
);
5500 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
5506 /* Return the containing type of the die in question using its
5507 DW_AT_containing_type attribute. */
5509 static struct type
*
5510 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5512 struct type
*type
= NULL
;
5513 struct attribute
*type_attr
;
5514 struct die_info
*type_die
= NULL
;
5517 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
5520 ref
= dwarf2_get_ref_die_offset (type_attr
);
5521 type_die
= follow_die_ref (ref
);
5524 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref
,
5528 type
= tag_type_to_type (type_die
, cu
);
5533 dump_die (type_die
);
5534 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
5541 static struct type
*
5542 type_at_offset (unsigned int offset
, struct dwarf2_cu
*cu
)
5544 struct die_info
*die
;
5547 die
= follow_die_ref (offset
);
5550 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
5553 type
= tag_type_to_type (die
, cu
);
5558 static struct type
*
5559 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5567 read_type_die (die
, cu
);
5571 error ("Dwarf Error: Cannot find type of die [in module %s]",
5579 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
5583 case DW_TAG_class_type
:
5584 case DW_TAG_structure_type
:
5585 case DW_TAG_union_type
:
5586 read_structure_scope (die
, cu
);
5588 case DW_TAG_enumeration_type
:
5589 read_enumeration (die
, cu
);
5591 case DW_TAG_subprogram
:
5592 case DW_TAG_subroutine_type
:
5593 read_subroutine_type (die
, cu
);
5595 case DW_TAG_array_type
:
5596 read_array_type (die
, cu
);
5598 case DW_TAG_pointer_type
:
5599 read_tag_pointer_type (die
, cu
);
5601 case DW_TAG_ptr_to_member_type
:
5602 read_tag_ptr_to_member_type (die
, cu
);
5604 case DW_TAG_reference_type
:
5605 read_tag_reference_type (die
, cu
);
5607 case DW_TAG_const_type
:
5608 read_tag_const_type (die
, cu
);
5610 case DW_TAG_volatile_type
:
5611 read_tag_volatile_type (die
, cu
);
5613 case DW_TAG_string_type
:
5614 read_tag_string_type (die
, cu
);
5616 case DW_TAG_typedef
:
5617 read_typedef (die
, cu
);
5619 case DW_TAG_base_type
:
5620 read_base_type (die
, cu
);
5623 complaint (&symfile_complaints
, "unexepected tag in read_type_die: '%s'",
5624 dwarf_tag_name (die
->tag
));
5629 static struct type
*
5630 dwarf_base_type (int encoding
, int size
, struct dwarf2_cu
*cu
)
5632 struct objfile
*objfile
= cu
->objfile
;
5634 /* FIXME - this should not produce a new (struct type *)
5635 every time. It should cache base types. */
5639 case DW_ATE_address
:
5640 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
5642 case DW_ATE_boolean
:
5643 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
5645 case DW_ATE_complex_float
:
5648 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
5652 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
5658 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
5662 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
5669 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5672 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
5676 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5680 case DW_ATE_signed_char
:
5681 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5683 case DW_ATE_unsigned
:
5687 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5690 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
5694 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
5698 case DW_ATE_unsigned_char
:
5699 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5702 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5709 copy_die (struct die_info
*old_die
)
5711 struct die_info
*new_die
;
5714 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5715 memset (new_die
, 0, sizeof (struct die_info
));
5717 new_die
->tag
= old_die
->tag
;
5718 new_die
->has_children
= old_die
->has_children
;
5719 new_die
->abbrev
= old_die
->abbrev
;
5720 new_die
->offset
= old_die
->offset
;
5721 new_die
->type
= NULL
;
5723 num_attrs
= old_die
->num_attrs
;
5724 new_die
->num_attrs
= num_attrs
;
5725 new_die
->attrs
= (struct attribute
*)
5726 xmalloc (num_attrs
* sizeof (struct attribute
));
5728 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
5730 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
5731 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
5732 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
5735 new_die
->next
= NULL
;
5740 /* Return sibling of die, NULL if no sibling. */
5742 static struct die_info
*
5743 sibling_die (struct die_info
*die
)
5745 return die
->sibling
;
5748 /* Get linkage name of a die, return NULL if not found. */
5751 dwarf2_linkage_name (struct die_info
*die
)
5753 struct attribute
*attr
;
5755 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
5756 if (attr
&& DW_STRING (attr
))
5757 return DW_STRING (attr
);
5758 attr
= dwarf_attr (die
, DW_AT_name
);
5759 if (attr
&& DW_STRING (attr
))
5760 return DW_STRING (attr
);
5764 /* Get name of a die, return NULL if not found. */
5767 dwarf2_name (struct die_info
*die
)
5769 struct attribute
*attr
;
5771 attr
= dwarf_attr (die
, DW_AT_name
);
5772 if (attr
&& DW_STRING (attr
))
5773 return DW_STRING (attr
);
5777 /* Return the die that this die in an extension of, or NULL if there
5780 static struct die_info
*
5781 dwarf2_extension (struct die_info
*die
)
5783 struct attribute
*attr
;
5784 struct die_info
*extension_die
;
5787 attr
= dwarf_attr (die
, DW_AT_extension
);
5791 ref
= dwarf2_get_ref_die_offset (attr
);
5792 extension_die
= follow_die_ref (ref
);
5795 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
5798 return extension_die
;
5801 /* Convert a DIE tag into its string name. */
5804 dwarf_tag_name (unsigned tag
)
5808 case DW_TAG_padding
:
5809 return "DW_TAG_padding";
5810 case DW_TAG_array_type
:
5811 return "DW_TAG_array_type";
5812 case DW_TAG_class_type
:
5813 return "DW_TAG_class_type";
5814 case DW_TAG_entry_point
:
5815 return "DW_TAG_entry_point";
5816 case DW_TAG_enumeration_type
:
5817 return "DW_TAG_enumeration_type";
5818 case DW_TAG_formal_parameter
:
5819 return "DW_TAG_formal_parameter";
5820 case DW_TAG_imported_declaration
:
5821 return "DW_TAG_imported_declaration";
5823 return "DW_TAG_label";
5824 case DW_TAG_lexical_block
:
5825 return "DW_TAG_lexical_block";
5827 return "DW_TAG_member";
5828 case DW_TAG_pointer_type
:
5829 return "DW_TAG_pointer_type";
5830 case DW_TAG_reference_type
:
5831 return "DW_TAG_reference_type";
5832 case DW_TAG_compile_unit
:
5833 return "DW_TAG_compile_unit";
5834 case DW_TAG_string_type
:
5835 return "DW_TAG_string_type";
5836 case DW_TAG_structure_type
:
5837 return "DW_TAG_structure_type";
5838 case DW_TAG_subroutine_type
:
5839 return "DW_TAG_subroutine_type";
5840 case DW_TAG_typedef
:
5841 return "DW_TAG_typedef";
5842 case DW_TAG_union_type
:
5843 return "DW_TAG_union_type";
5844 case DW_TAG_unspecified_parameters
:
5845 return "DW_TAG_unspecified_parameters";
5846 case DW_TAG_variant
:
5847 return "DW_TAG_variant";
5848 case DW_TAG_common_block
:
5849 return "DW_TAG_common_block";
5850 case DW_TAG_common_inclusion
:
5851 return "DW_TAG_common_inclusion";
5852 case DW_TAG_inheritance
:
5853 return "DW_TAG_inheritance";
5854 case DW_TAG_inlined_subroutine
:
5855 return "DW_TAG_inlined_subroutine";
5857 return "DW_TAG_module";
5858 case DW_TAG_ptr_to_member_type
:
5859 return "DW_TAG_ptr_to_member_type";
5860 case DW_TAG_set_type
:
5861 return "DW_TAG_set_type";
5862 case DW_TAG_subrange_type
:
5863 return "DW_TAG_subrange_type";
5864 case DW_TAG_with_stmt
:
5865 return "DW_TAG_with_stmt";
5866 case DW_TAG_access_declaration
:
5867 return "DW_TAG_access_declaration";
5868 case DW_TAG_base_type
:
5869 return "DW_TAG_base_type";
5870 case DW_TAG_catch_block
:
5871 return "DW_TAG_catch_block";
5872 case DW_TAG_const_type
:
5873 return "DW_TAG_const_type";
5874 case DW_TAG_constant
:
5875 return "DW_TAG_constant";
5876 case DW_TAG_enumerator
:
5877 return "DW_TAG_enumerator";
5878 case DW_TAG_file_type
:
5879 return "DW_TAG_file_type";
5881 return "DW_TAG_friend";
5882 case DW_TAG_namelist
:
5883 return "DW_TAG_namelist";
5884 case DW_TAG_namelist_item
:
5885 return "DW_TAG_namelist_item";
5886 case DW_TAG_packed_type
:
5887 return "DW_TAG_packed_type";
5888 case DW_TAG_subprogram
:
5889 return "DW_TAG_subprogram";
5890 case DW_TAG_template_type_param
:
5891 return "DW_TAG_template_type_param";
5892 case DW_TAG_template_value_param
:
5893 return "DW_TAG_template_value_param";
5894 case DW_TAG_thrown_type
:
5895 return "DW_TAG_thrown_type";
5896 case DW_TAG_try_block
:
5897 return "DW_TAG_try_block";
5898 case DW_TAG_variant_part
:
5899 return "DW_TAG_variant_part";
5900 case DW_TAG_variable
:
5901 return "DW_TAG_variable";
5902 case DW_TAG_volatile_type
:
5903 return "DW_TAG_volatile_type";
5904 case DW_TAG_dwarf_procedure
:
5905 return "DW_TAG_dwarf_procedure";
5906 case DW_TAG_restrict_type
:
5907 return "DW_TAG_restrict_type";
5908 case DW_TAG_interface_type
:
5909 return "DW_TAG_interface_type";
5910 case DW_TAG_namespace
:
5911 return "DW_TAG_namespace";
5912 case DW_TAG_imported_module
:
5913 return "DW_TAG_imported_module";
5914 case DW_TAG_unspecified_type
:
5915 return "DW_TAG_unspecified_type";
5916 case DW_TAG_partial_unit
:
5917 return "DW_TAG_partial_unit";
5918 case DW_TAG_imported_unit
:
5919 return "DW_TAG_imported_unit";
5920 case DW_TAG_MIPS_loop
:
5921 return "DW_TAG_MIPS_loop";
5922 case DW_TAG_format_label
:
5923 return "DW_TAG_format_label";
5924 case DW_TAG_function_template
:
5925 return "DW_TAG_function_template";
5926 case DW_TAG_class_template
:
5927 return "DW_TAG_class_template";
5929 return "DW_TAG_<unknown>";
5933 /* Convert a DWARF attribute code into its string name. */
5936 dwarf_attr_name (unsigned attr
)
5941 return "DW_AT_sibling";
5942 case DW_AT_location
:
5943 return "DW_AT_location";
5945 return "DW_AT_name";
5946 case DW_AT_ordering
:
5947 return "DW_AT_ordering";
5948 case DW_AT_subscr_data
:
5949 return "DW_AT_subscr_data";
5950 case DW_AT_byte_size
:
5951 return "DW_AT_byte_size";
5952 case DW_AT_bit_offset
:
5953 return "DW_AT_bit_offset";
5954 case DW_AT_bit_size
:
5955 return "DW_AT_bit_size";
5956 case DW_AT_element_list
:
5957 return "DW_AT_element_list";
5958 case DW_AT_stmt_list
:
5959 return "DW_AT_stmt_list";
5961 return "DW_AT_low_pc";
5963 return "DW_AT_high_pc";
5964 case DW_AT_language
:
5965 return "DW_AT_language";
5967 return "DW_AT_member";
5969 return "DW_AT_discr";
5970 case DW_AT_discr_value
:
5971 return "DW_AT_discr_value";
5972 case DW_AT_visibility
:
5973 return "DW_AT_visibility";
5975 return "DW_AT_import";
5976 case DW_AT_string_length
:
5977 return "DW_AT_string_length";
5978 case DW_AT_common_reference
:
5979 return "DW_AT_common_reference";
5980 case DW_AT_comp_dir
:
5981 return "DW_AT_comp_dir";
5982 case DW_AT_const_value
:
5983 return "DW_AT_const_value";
5984 case DW_AT_containing_type
:
5985 return "DW_AT_containing_type";
5986 case DW_AT_default_value
:
5987 return "DW_AT_default_value";
5989 return "DW_AT_inline";
5990 case DW_AT_is_optional
:
5991 return "DW_AT_is_optional";
5992 case DW_AT_lower_bound
:
5993 return "DW_AT_lower_bound";
5994 case DW_AT_producer
:
5995 return "DW_AT_producer";
5996 case DW_AT_prototyped
:
5997 return "DW_AT_prototyped";
5998 case DW_AT_return_addr
:
5999 return "DW_AT_return_addr";
6000 case DW_AT_start_scope
:
6001 return "DW_AT_start_scope";
6002 case DW_AT_stride_size
:
6003 return "DW_AT_stride_size";
6004 case DW_AT_upper_bound
:
6005 return "DW_AT_upper_bound";
6006 case DW_AT_abstract_origin
:
6007 return "DW_AT_abstract_origin";
6008 case DW_AT_accessibility
:
6009 return "DW_AT_accessibility";
6010 case DW_AT_address_class
:
6011 return "DW_AT_address_class";
6012 case DW_AT_artificial
:
6013 return "DW_AT_artificial";
6014 case DW_AT_base_types
:
6015 return "DW_AT_base_types";
6016 case DW_AT_calling_convention
:
6017 return "DW_AT_calling_convention";
6019 return "DW_AT_count";
6020 case DW_AT_data_member_location
:
6021 return "DW_AT_data_member_location";
6022 case DW_AT_decl_column
:
6023 return "DW_AT_decl_column";
6024 case DW_AT_decl_file
:
6025 return "DW_AT_decl_file";
6026 case DW_AT_decl_line
:
6027 return "DW_AT_decl_line";
6028 case DW_AT_declaration
:
6029 return "DW_AT_declaration";
6030 case DW_AT_discr_list
:
6031 return "DW_AT_discr_list";
6032 case DW_AT_encoding
:
6033 return "DW_AT_encoding";
6034 case DW_AT_external
:
6035 return "DW_AT_external";
6036 case DW_AT_frame_base
:
6037 return "DW_AT_frame_base";
6039 return "DW_AT_friend";
6040 case DW_AT_identifier_case
:
6041 return "DW_AT_identifier_case";
6042 case DW_AT_macro_info
:
6043 return "DW_AT_macro_info";
6044 case DW_AT_namelist_items
:
6045 return "DW_AT_namelist_items";
6046 case DW_AT_priority
:
6047 return "DW_AT_priority";
6049 return "DW_AT_segment";
6050 case DW_AT_specification
:
6051 return "DW_AT_specification";
6052 case DW_AT_static_link
:
6053 return "DW_AT_static_link";
6055 return "DW_AT_type";
6056 case DW_AT_use_location
:
6057 return "DW_AT_use_location";
6058 case DW_AT_variable_parameter
:
6059 return "DW_AT_variable_parameter";
6060 case DW_AT_virtuality
:
6061 return "DW_AT_virtuality";
6062 case DW_AT_vtable_elem_location
:
6063 return "DW_AT_vtable_elem_location";
6064 case DW_AT_allocated
:
6065 return "DW_AT_allocated";
6066 case DW_AT_associated
:
6067 return "DW_AT_associated";
6068 case DW_AT_data_location
:
6069 return "DW_AT_data_location";
6071 return "DW_AT_stride";
6072 case DW_AT_entry_pc
:
6073 return "DW_AT_entry_pc";
6074 case DW_AT_use_UTF8
:
6075 return "DW_AT_use_UTF8";
6076 case DW_AT_extension
:
6077 return "DW_AT_extension";
6079 return "DW_AT_ranges";
6080 case DW_AT_trampoline
:
6081 return "DW_AT_trampoline";
6082 case DW_AT_call_column
:
6083 return "DW_AT_call_column";
6084 case DW_AT_call_file
:
6085 return "DW_AT_call_file";
6086 case DW_AT_call_line
:
6087 return "DW_AT_call_line";
6089 case DW_AT_MIPS_fde
:
6090 return "DW_AT_MIPS_fde";
6091 case DW_AT_MIPS_loop_begin
:
6092 return "DW_AT_MIPS_loop_begin";
6093 case DW_AT_MIPS_tail_loop_begin
:
6094 return "DW_AT_MIPS_tail_loop_begin";
6095 case DW_AT_MIPS_epilog_begin
:
6096 return "DW_AT_MIPS_epilog_begin";
6097 case DW_AT_MIPS_loop_unroll_factor
:
6098 return "DW_AT_MIPS_loop_unroll_factor";
6099 case DW_AT_MIPS_software_pipeline_depth
:
6100 return "DW_AT_MIPS_software_pipeline_depth";
6102 case DW_AT_MIPS_linkage_name
:
6103 return "DW_AT_MIPS_linkage_name";
6105 case DW_AT_sf_names
:
6106 return "DW_AT_sf_names";
6107 case DW_AT_src_info
:
6108 return "DW_AT_src_info";
6109 case DW_AT_mac_info
:
6110 return "DW_AT_mac_info";
6111 case DW_AT_src_coords
:
6112 return "DW_AT_src_coords";
6113 case DW_AT_body_begin
:
6114 return "DW_AT_body_begin";
6115 case DW_AT_body_end
:
6116 return "DW_AT_body_end";
6117 case DW_AT_GNU_vector
:
6118 return "DW_AT_GNU_vector";
6120 return "DW_AT_<unknown>";
6124 /* Convert a DWARF value form code into its string name. */
6127 dwarf_form_name (unsigned form
)
6132 return "DW_FORM_addr";
6133 case DW_FORM_block2
:
6134 return "DW_FORM_block2";
6135 case DW_FORM_block4
:
6136 return "DW_FORM_block4";
6138 return "DW_FORM_data2";
6140 return "DW_FORM_data4";
6142 return "DW_FORM_data8";
6143 case DW_FORM_string
:
6144 return "DW_FORM_string";
6146 return "DW_FORM_block";
6147 case DW_FORM_block1
:
6148 return "DW_FORM_block1";
6150 return "DW_FORM_data1";
6152 return "DW_FORM_flag";
6154 return "DW_FORM_sdata";
6156 return "DW_FORM_strp";
6158 return "DW_FORM_udata";
6159 case DW_FORM_ref_addr
:
6160 return "DW_FORM_ref_addr";
6162 return "DW_FORM_ref1";
6164 return "DW_FORM_ref2";
6166 return "DW_FORM_ref4";
6168 return "DW_FORM_ref8";
6169 case DW_FORM_ref_udata
:
6170 return "DW_FORM_ref_udata";
6171 case DW_FORM_indirect
:
6172 return "DW_FORM_indirect";
6174 return "DW_FORM_<unknown>";
6178 /* Convert a DWARF stack opcode into its string name. */
6181 dwarf_stack_op_name (unsigned op
)
6186 return "DW_OP_addr";
6188 return "DW_OP_deref";
6190 return "DW_OP_const1u";
6192 return "DW_OP_const1s";
6194 return "DW_OP_const2u";
6196 return "DW_OP_const2s";
6198 return "DW_OP_const4u";
6200 return "DW_OP_const4s";
6202 return "DW_OP_const8u";
6204 return "DW_OP_const8s";
6206 return "DW_OP_constu";
6208 return "DW_OP_consts";
6212 return "DW_OP_drop";
6214 return "DW_OP_over";
6216 return "DW_OP_pick";
6218 return "DW_OP_swap";
6222 return "DW_OP_xderef";
6230 return "DW_OP_minus";
6242 return "DW_OP_plus";
6243 case DW_OP_plus_uconst
:
6244 return "DW_OP_plus_uconst";
6250 return "DW_OP_shra";
6268 return "DW_OP_skip";
6270 return "DW_OP_lit0";
6272 return "DW_OP_lit1";
6274 return "DW_OP_lit2";
6276 return "DW_OP_lit3";
6278 return "DW_OP_lit4";
6280 return "DW_OP_lit5";
6282 return "DW_OP_lit6";
6284 return "DW_OP_lit7";
6286 return "DW_OP_lit8";
6288 return "DW_OP_lit9";
6290 return "DW_OP_lit10";
6292 return "DW_OP_lit11";
6294 return "DW_OP_lit12";
6296 return "DW_OP_lit13";
6298 return "DW_OP_lit14";
6300 return "DW_OP_lit15";
6302 return "DW_OP_lit16";
6304 return "DW_OP_lit17";
6306 return "DW_OP_lit18";
6308 return "DW_OP_lit19";
6310 return "DW_OP_lit20";
6312 return "DW_OP_lit21";
6314 return "DW_OP_lit22";
6316 return "DW_OP_lit23";
6318 return "DW_OP_lit24";
6320 return "DW_OP_lit25";
6322 return "DW_OP_lit26";
6324 return "DW_OP_lit27";
6326 return "DW_OP_lit28";
6328 return "DW_OP_lit29";
6330 return "DW_OP_lit30";
6332 return "DW_OP_lit31";
6334 return "DW_OP_reg0";
6336 return "DW_OP_reg1";
6338 return "DW_OP_reg2";
6340 return "DW_OP_reg3";
6342 return "DW_OP_reg4";
6344 return "DW_OP_reg5";
6346 return "DW_OP_reg6";
6348 return "DW_OP_reg7";
6350 return "DW_OP_reg8";
6352 return "DW_OP_reg9";
6354 return "DW_OP_reg10";
6356 return "DW_OP_reg11";
6358 return "DW_OP_reg12";
6360 return "DW_OP_reg13";
6362 return "DW_OP_reg14";
6364 return "DW_OP_reg15";
6366 return "DW_OP_reg16";
6368 return "DW_OP_reg17";
6370 return "DW_OP_reg18";
6372 return "DW_OP_reg19";
6374 return "DW_OP_reg20";
6376 return "DW_OP_reg21";
6378 return "DW_OP_reg22";
6380 return "DW_OP_reg23";
6382 return "DW_OP_reg24";
6384 return "DW_OP_reg25";
6386 return "DW_OP_reg26";
6388 return "DW_OP_reg27";
6390 return "DW_OP_reg28";
6392 return "DW_OP_reg29";
6394 return "DW_OP_reg30";
6396 return "DW_OP_reg31";
6398 return "DW_OP_breg0";
6400 return "DW_OP_breg1";
6402 return "DW_OP_breg2";
6404 return "DW_OP_breg3";
6406 return "DW_OP_breg4";
6408 return "DW_OP_breg5";
6410 return "DW_OP_breg6";
6412 return "DW_OP_breg7";
6414 return "DW_OP_breg8";
6416 return "DW_OP_breg9";
6418 return "DW_OP_breg10";
6420 return "DW_OP_breg11";
6422 return "DW_OP_breg12";
6424 return "DW_OP_breg13";
6426 return "DW_OP_breg14";
6428 return "DW_OP_breg15";
6430 return "DW_OP_breg16";
6432 return "DW_OP_breg17";
6434 return "DW_OP_breg18";
6436 return "DW_OP_breg19";
6438 return "DW_OP_breg20";
6440 return "DW_OP_breg21";
6442 return "DW_OP_breg22";
6444 return "DW_OP_breg23";
6446 return "DW_OP_breg24";
6448 return "DW_OP_breg25";
6450 return "DW_OP_breg26";
6452 return "DW_OP_breg27";
6454 return "DW_OP_breg28";
6456 return "DW_OP_breg29";
6458 return "DW_OP_breg30";
6460 return "DW_OP_breg31";
6462 return "DW_OP_regx";
6464 return "DW_OP_fbreg";
6466 return "DW_OP_bregx";
6468 return "DW_OP_piece";
6469 case DW_OP_deref_size
:
6470 return "DW_OP_deref_size";
6471 case DW_OP_xderef_size
:
6472 return "DW_OP_xderef_size";
6475 /* DWARF 3 extensions. */
6476 case DW_OP_push_object_address
:
6477 return "DW_OP_push_object_address";
6479 return "DW_OP_call2";
6481 return "DW_OP_call4";
6482 case DW_OP_call_ref
:
6483 return "DW_OP_call_ref";
6484 /* GNU extensions. */
6485 case DW_OP_GNU_push_tls_address
:
6486 return "DW_OP_GNU_push_tls_address";
6488 return "OP_<unknown>";
6493 dwarf_bool_name (unsigned mybool
)
6501 /* Convert a DWARF type code into its string name. */
6504 dwarf_type_encoding_name (unsigned enc
)
6508 case DW_ATE_address
:
6509 return "DW_ATE_address";
6510 case DW_ATE_boolean
:
6511 return "DW_ATE_boolean";
6512 case DW_ATE_complex_float
:
6513 return "DW_ATE_complex_float";
6515 return "DW_ATE_float";
6517 return "DW_ATE_signed";
6518 case DW_ATE_signed_char
:
6519 return "DW_ATE_signed_char";
6520 case DW_ATE_unsigned
:
6521 return "DW_ATE_unsigned";
6522 case DW_ATE_unsigned_char
:
6523 return "DW_ATE_unsigned_char";
6524 case DW_ATE_imaginary_float
:
6525 return "DW_ATE_imaginary_float";
6527 return "DW_ATE_<unknown>";
6531 /* Convert a DWARF call frame info operation to its string name. */
6535 dwarf_cfi_name (unsigned cfi_opc
)
6539 case DW_CFA_advance_loc
:
6540 return "DW_CFA_advance_loc";
6542 return "DW_CFA_offset";
6543 case DW_CFA_restore
:
6544 return "DW_CFA_restore";
6546 return "DW_CFA_nop";
6547 case DW_CFA_set_loc
:
6548 return "DW_CFA_set_loc";
6549 case DW_CFA_advance_loc1
:
6550 return "DW_CFA_advance_loc1";
6551 case DW_CFA_advance_loc2
:
6552 return "DW_CFA_advance_loc2";
6553 case DW_CFA_advance_loc4
:
6554 return "DW_CFA_advance_loc4";
6555 case DW_CFA_offset_extended
:
6556 return "DW_CFA_offset_extended";
6557 case DW_CFA_restore_extended
:
6558 return "DW_CFA_restore_extended";
6559 case DW_CFA_undefined
:
6560 return "DW_CFA_undefined";
6561 case DW_CFA_same_value
:
6562 return "DW_CFA_same_value";
6563 case DW_CFA_register
:
6564 return "DW_CFA_register";
6565 case DW_CFA_remember_state
:
6566 return "DW_CFA_remember_state";
6567 case DW_CFA_restore_state
:
6568 return "DW_CFA_restore_state";
6569 case DW_CFA_def_cfa
:
6570 return "DW_CFA_def_cfa";
6571 case DW_CFA_def_cfa_register
:
6572 return "DW_CFA_def_cfa_register";
6573 case DW_CFA_def_cfa_offset
:
6574 return "DW_CFA_def_cfa_offset";
6577 case DW_CFA_def_cfa_expression
:
6578 return "DW_CFA_def_cfa_expression";
6579 case DW_CFA_expression
:
6580 return "DW_CFA_expression";
6581 case DW_CFA_offset_extended_sf
:
6582 return "DW_CFA_offset_extended_sf";
6583 case DW_CFA_def_cfa_sf
:
6584 return "DW_CFA_def_cfa_sf";
6585 case DW_CFA_def_cfa_offset_sf
:
6586 return "DW_CFA_def_cfa_offset_sf";
6588 /* SGI/MIPS specific */
6589 case DW_CFA_MIPS_advance_loc8
:
6590 return "DW_CFA_MIPS_advance_loc8";
6592 /* GNU extensions */
6593 case DW_CFA_GNU_window_save
:
6594 return "DW_CFA_GNU_window_save";
6595 case DW_CFA_GNU_args_size
:
6596 return "DW_CFA_GNU_args_size";
6597 case DW_CFA_GNU_negative_offset_extended
:
6598 return "DW_CFA_GNU_negative_offset_extended";
6601 return "DW_CFA_<unknown>";
6607 dump_die (struct die_info
*die
)
6611 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
6612 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
6613 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
6614 dwarf_bool_name (die
->child
!= NULL
));
6616 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
6617 for (i
= 0; i
< die
->num_attrs
; ++i
)
6619 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
6620 dwarf_attr_name (die
->attrs
[i
].name
),
6621 dwarf_form_name (die
->attrs
[i
].form
));
6622 switch (die
->attrs
[i
].form
)
6624 case DW_FORM_ref_addr
:
6626 fprintf_unfiltered (gdb_stderr
, "address: ");
6627 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
6629 case DW_FORM_block2
:
6630 case DW_FORM_block4
:
6632 case DW_FORM_block1
:
6633 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
6644 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
6646 case DW_FORM_string
:
6648 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
6649 DW_STRING (&die
->attrs
[i
])
6650 ? DW_STRING (&die
->attrs
[i
]) : "");
6653 if (DW_UNSND (&die
->attrs
[i
]))
6654 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
6656 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
6658 case DW_FORM_indirect
:
6659 /* the reader will have reduced the indirect form to
6660 the "base form" so this form should not occur */
6661 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
6664 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
6665 die
->attrs
[i
].form
);
6667 fprintf_unfiltered (gdb_stderr
, "\n");
6672 dump_die_list (struct die_info
*die
)
6677 if (die
->child
!= NULL
)
6678 dump_die_list (die
->child
);
6679 if (die
->sibling
!= NULL
)
6680 dump_die_list (die
->sibling
);
6685 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
6688 struct die_info
*old
;
6690 h
= (offset
% REF_HASH_SIZE
);
6691 old
= die_ref_table
[h
];
6692 die
->next_ref
= old
;
6693 die_ref_table
[h
] = die
;
6698 dwarf2_empty_hash_tables (void)
6700 memset (die_ref_table
, 0, sizeof (die_ref_table
));
6704 dwarf2_get_ref_die_offset (struct attribute
*attr
)
6706 unsigned int result
= 0;
6710 case DW_FORM_ref_addr
:
6711 result
= DW_ADDR (attr
);
6717 case DW_FORM_ref_udata
:
6718 result
= cu_header_offset
+ DW_UNSND (attr
);
6721 complaint (&symfile_complaints
,
6722 "unsupported die ref attribute form: '%s'",
6723 dwarf_form_name (attr
->form
));
6728 static struct die_info
*
6729 follow_die_ref (unsigned int offset
)
6731 struct die_info
*die
;
6734 h
= (offset
% REF_HASH_SIZE
);
6735 die
= die_ref_table
[h
];
6738 if (die
->offset
== offset
)
6742 die
= die
->next_ref
;
6747 static struct type
*
6748 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
6750 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
6752 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
6753 typeid, objfile
->name
);
6756 /* Look for this particular type in the fundamental type vector. If
6757 one is not found, create and install one appropriate for the
6758 current language and the current target machine. */
6760 if (ftypes
[typeid] == NULL
)
6762 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
6765 return (ftypes
[typeid]);
6768 /* Decode simple location descriptions.
6769 Given a pointer to a dwarf block that defines a location, compute
6770 the location and return the value.
6772 NOTE drow/2003-11-18: This function is called in two situations
6773 now: for the address of static or global variables (partial symbols
6774 only) and for offsets into structures which are expected to be
6775 (more or less) constant. The partial symbol case should go away,
6776 and only the constant case should remain. That will let this
6777 function complain more accurately. A few special modes are allowed
6778 without complaint for global variables (for instance, global
6779 register values and thread-local values).
6781 A location description containing no operations indicates that the
6782 object is optimized out. The return value is 0 for that case.
6783 FIXME drow/2003-11-16: No callers check for this case any more; soon all
6784 callers will only want a very basic result and this can become a
6787 When the result is a register number, the global isreg flag is set,
6788 otherwise it is cleared.
6790 Note that stack[0] is unused except as a default error return.
6791 Note that stack overflow is not yet handled. */
6794 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
6796 struct objfile
*objfile
= cu
->objfile
;
6797 struct comp_unit_head
*cu_header
= &cu
->header
;
6799 int size
= blk
->size
;
6800 char *data
= blk
->data
;
6801 CORE_ADDR stack
[64];
6803 unsigned int bytes_read
, unsnd
;
6848 stack
[++stacki
] = op
- DW_OP_lit0
;
6884 stack
[++stacki
] = op
- DW_OP_reg0
;
6886 dwarf2_complex_location_expr_complaint ();
6891 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6893 stack
[++stacki
] = unsnd
;
6895 dwarf2_complex_location_expr_complaint ();
6899 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
6905 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
6910 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
6915 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
6920 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
6925 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
6930 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
6935 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
6941 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6946 stack
[stacki
+ 1] = stack
[stacki
];
6951 stack
[stacki
- 1] += stack
[stacki
];
6955 case DW_OP_plus_uconst
:
6956 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6961 stack
[stacki
- 1] -= stack
[stacki
];
6966 /* If we're not the last op, then we definitely can't encode
6967 this using GDB's address_class enum. This is valid for partial
6968 global symbols, although the variable's address will be bogus
6971 dwarf2_complex_location_expr_complaint ();
6974 case DW_OP_GNU_push_tls_address
:
6975 /* The top of the stack has the offset from the beginning
6976 of the thread control block at which the variable is located. */
6977 /* Nothing should follow this operator, so the top of stack would
6979 /* This is valid for partial global symbols, but the variable's
6980 address will be bogus in the psymtab. */
6982 dwarf2_complex_location_expr_complaint ();
6986 complaint (&symfile_complaints
, "unsupported stack op: '%s'",
6987 dwarf_stack_op_name (op
));
6988 return (stack
[stacki
]);
6991 return (stack
[stacki
]);
6994 /* memory allocation interface */
6997 dwarf2_free_tmp_obstack (void *ignore
)
6999 obstack_free (&dwarf2_tmp_obstack
, NULL
);
7002 static struct dwarf_block
*
7003 dwarf_alloc_block (void)
7005 struct dwarf_block
*blk
;
7007 blk
= (struct dwarf_block
*)
7008 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
7012 static struct abbrev_info
*
7013 dwarf_alloc_abbrev (void)
7015 struct abbrev_info
*abbrev
;
7017 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
7018 memset (abbrev
, 0, sizeof (struct abbrev_info
));
7022 static struct die_info
*
7023 dwarf_alloc_die (void)
7025 struct die_info
*die
;
7027 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
7028 memset (die
, 0, sizeof (struct die_info
));
7033 /* Macro support. */
7036 /* Return the full name of file number I in *LH's file name table.
7037 Use COMP_DIR as the name of the current directory of the
7038 compilation. The result is allocated using xmalloc; the caller is
7039 responsible for freeing it. */
7041 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
7043 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7045 if (IS_ABSOLUTE_PATH (fe
->name
))
7046 return xstrdup (fe
->name
);
7054 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7060 dir_len
= strlen (dir
);
7061 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
7062 strcpy (full_name
, dir
);
7063 full_name
[dir_len
] = '/';
7064 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
7068 return xstrdup (fe
->name
);
7073 static struct macro_source_file
*
7074 macro_start_file (int file
, int line
,
7075 struct macro_source_file
*current_file
,
7076 const char *comp_dir
,
7077 struct line_header
*lh
, struct objfile
*objfile
)
7079 /* The full name of this source file. */
7080 char *full_name
= file_full_name (file
, lh
, comp_dir
);
7082 /* We don't create a macro table for this compilation unit
7083 at all until we actually get a filename. */
7084 if (! pending_macros
)
7085 pending_macros
= new_macro_table (&objfile
->symbol_obstack
,
7086 objfile
->macro_cache
);
7089 /* If we have no current file, then this must be the start_file
7090 directive for the compilation unit's main source file. */
7091 current_file
= macro_set_main (pending_macros
, full_name
);
7093 current_file
= macro_include (current_file
, line
, full_name
);
7097 return current_file
;
7101 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
7102 followed by a null byte. */
7104 copy_string (const char *buf
, int len
)
7106 char *s
= xmalloc (len
+ 1);
7107 memcpy (s
, buf
, len
);
7115 consume_improper_spaces (const char *p
, const char *body
)
7119 complaint (&symfile_complaints
,
7120 "macro definition contains spaces in formal argument list:\n`%s'",
7132 parse_macro_definition (struct macro_source_file
*file
, int line
,
7137 /* The body string takes one of two forms. For object-like macro
7138 definitions, it should be:
7140 <macro name> " " <definition>
7142 For function-like macro definitions, it should be:
7144 <macro name> "() " <definition>
7146 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
7148 Spaces may appear only where explicitly indicated, and in the
7151 The Dwarf 2 spec says that an object-like macro's name is always
7152 followed by a space, but versions of GCC around March 2002 omit
7153 the space when the macro's definition is the empty string.
7155 The Dwarf 2 spec says that there should be no spaces between the
7156 formal arguments in a function-like macro's formal argument list,
7157 but versions of GCC around March 2002 include spaces after the
7161 /* Find the extent of the macro name. The macro name is terminated
7162 by either a space or null character (for an object-like macro) or
7163 an opening paren (for a function-like macro). */
7164 for (p
= body
; *p
; p
++)
7165 if (*p
== ' ' || *p
== '(')
7168 if (*p
== ' ' || *p
== '\0')
7170 /* It's an object-like macro. */
7171 int name_len
= p
- body
;
7172 char *name
= copy_string (body
, name_len
);
7173 const char *replacement
;
7176 replacement
= body
+ name_len
+ 1;
7179 dwarf2_macro_malformed_definition_complaint (body
);
7180 replacement
= body
+ name_len
;
7183 macro_define_object (file
, line
, name
, replacement
);
7189 /* It's a function-like macro. */
7190 char *name
= copy_string (body
, p
- body
);
7193 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
7197 p
= consume_improper_spaces (p
, body
);
7199 /* Parse the formal argument list. */
7200 while (*p
&& *p
!= ')')
7202 /* Find the extent of the current argument name. */
7203 const char *arg_start
= p
;
7205 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
7208 if (! *p
|| p
== arg_start
)
7209 dwarf2_macro_malformed_definition_complaint (body
);
7212 /* Make sure argv has room for the new argument. */
7213 if (argc
>= argv_size
)
7216 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
7219 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
7222 p
= consume_improper_spaces (p
, body
);
7224 /* Consume the comma, if present. */
7229 p
= consume_improper_spaces (p
, body
);
7238 /* Perfectly formed definition, no complaints. */
7239 macro_define_function (file
, line
, name
,
7240 argc
, (const char **) argv
,
7242 else if (*p
== '\0')
7244 /* Complain, but do define it. */
7245 dwarf2_macro_malformed_definition_complaint (body
);
7246 macro_define_function (file
, line
, name
,
7247 argc
, (const char **) argv
,
7251 /* Just complain. */
7252 dwarf2_macro_malformed_definition_complaint (body
);
7255 /* Just complain. */
7256 dwarf2_macro_malformed_definition_complaint (body
);
7262 for (i
= 0; i
< argc
; i
++)
7268 dwarf2_macro_malformed_definition_complaint (body
);
7273 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
7274 char *comp_dir
, bfd
*abfd
,
7275 struct dwarf2_cu
*cu
)
7277 char *mac_ptr
, *mac_end
;
7278 struct macro_source_file
*current_file
= 0;
7280 if (dwarf_macinfo_buffer
== NULL
)
7282 complaint (&symfile_complaints
, "missing .debug_macinfo section");
7286 mac_ptr
= dwarf_macinfo_buffer
+ offset
;
7287 mac_end
= dwarf_macinfo_buffer
+ dwarf_macinfo_size
;
7291 enum dwarf_macinfo_record_type macinfo_type
;
7293 /* Do we at least have room for a macinfo type byte? */
7294 if (mac_ptr
>= mac_end
)
7296 dwarf2_macros_too_long_complaint ();
7300 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
7303 switch (macinfo_type
)
7305 /* A zero macinfo type indicates the end of the macro
7310 case DW_MACINFO_define
:
7311 case DW_MACINFO_undef
:
7317 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7318 mac_ptr
+= bytes_read
;
7319 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
7320 mac_ptr
+= bytes_read
;
7323 complaint (&symfile_complaints
,
7324 "debug info gives macro %s outside of any file: %s",
7326 DW_MACINFO_define
? "definition" : macinfo_type
==
7327 DW_MACINFO_undef
? "undefinition" :
7328 "something-or-other", body
);
7331 if (macinfo_type
== DW_MACINFO_define
)
7332 parse_macro_definition (current_file
, line
, body
);
7333 else if (macinfo_type
== DW_MACINFO_undef
)
7334 macro_undef (current_file
, line
, body
);
7339 case DW_MACINFO_start_file
:
7344 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7345 mac_ptr
+= bytes_read
;
7346 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7347 mac_ptr
+= bytes_read
;
7349 current_file
= macro_start_file (file
, line
,
7350 current_file
, comp_dir
,
7355 case DW_MACINFO_end_file
:
7357 complaint (&symfile_complaints
,
7358 "macro debug info has an unmatched `close_file' directive");
7361 current_file
= current_file
->included_by
;
7364 enum dwarf_macinfo_record_type next_type
;
7366 /* GCC circa March 2002 doesn't produce the zero
7367 type byte marking the end of the compilation
7368 unit. Complain if it's not there, but exit no
7371 /* Do we at least have room for a macinfo type byte? */
7372 if (mac_ptr
>= mac_end
)
7374 dwarf2_macros_too_long_complaint ();
7378 /* We don't increment mac_ptr here, so this is just
7380 next_type
= read_1_byte (abfd
, mac_ptr
);
7382 complaint (&symfile_complaints
,
7383 "no terminating 0-type entry for macros in `.debug_macinfo' section");
7390 case DW_MACINFO_vendor_ext
:
7396 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7397 mac_ptr
+= bytes_read
;
7398 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
7399 mac_ptr
+= bytes_read
;
7401 /* We don't recognize any vendor extensions. */
7408 /* Check if the attribute's form is a DW_FORM_block*
7409 if so return true else false. */
7411 attr_form_is_block (struct attribute
*attr
)
7413 return (attr
== NULL
? 0 :
7414 attr
->form
== DW_FORM_block1
7415 || attr
->form
== DW_FORM_block2
7416 || attr
->form
== DW_FORM_block4
7417 || attr
->form
== DW_FORM_block
);
7421 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
7422 struct dwarf2_cu
*cu
)
7424 if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
7426 struct dwarf2_loclist_baton
*baton
;
7428 baton
= obstack_alloc (&cu
->objfile
->symbol_obstack
,
7429 sizeof (struct dwarf2_loclist_baton
));
7430 baton
->objfile
= cu
->objfile
;
7432 /* We don't know how long the location list is, but make sure we
7433 don't run off the edge of the section. */
7434 baton
->size
= dwarf_loc_size
- DW_UNSND (attr
);
7435 baton
->data
= dwarf_loc_buffer
+ DW_UNSND (attr
);
7436 baton
->base_address
= cu
->header
.base_address
;
7437 if (cu
->header
.base_known
== 0)
7438 complaint (&symfile_complaints
,
7439 "Location list used without specifying the CU base address.");
7441 SYMBOL_LOCATION_FUNCS (sym
) = &dwarf2_loclist_funcs
;
7442 SYMBOL_LOCATION_BATON (sym
) = baton
;
7446 struct dwarf2_locexpr_baton
*baton
;
7448 baton
= obstack_alloc (&cu
->objfile
->symbol_obstack
,
7449 sizeof (struct dwarf2_locexpr_baton
));
7450 baton
->objfile
= cu
->objfile
;
7452 if (attr_form_is_block (attr
))
7454 /* Note that we're just copying the block's data pointer
7455 here, not the actual data. We're still pointing into the
7456 dwarf_info_buffer for SYM's objfile; right now we never
7457 release that buffer, but when we do clean up properly
7458 this may need to change. */
7459 baton
->size
= DW_BLOCK (attr
)->size
;
7460 baton
->data
= DW_BLOCK (attr
)->data
;
7464 dwarf2_invalid_attrib_class_complaint ("location description",
7465 SYMBOL_NATURAL_NAME (sym
));
7470 SYMBOL_LOCATION_FUNCS (sym
) = &dwarf2_locexpr_funcs
;
7471 SYMBOL_LOCATION_BATON (sym
) = baton
;