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 file_ptr dwarf_info_offset
;
132 static file_ptr dwarf_abbrev_offset
;
133 static file_ptr dwarf_line_offset
;
134 static file_ptr dwarf_pubnames_offset
;
135 static file_ptr dwarf_aranges_offset
;
136 static file_ptr dwarf_loc_offset
;
137 static file_ptr dwarf_macinfo_offset
;
138 static file_ptr dwarf_str_offset
;
139 static file_ptr dwarf_ranges_offset
;
140 file_ptr dwarf_frame_offset
;
141 file_ptr dwarf_eh_frame_offset
;
143 static unsigned int dwarf_info_size
;
144 static unsigned int dwarf_abbrev_size
;
145 static unsigned int dwarf_line_size
;
146 static unsigned int dwarf_pubnames_size
;
147 static unsigned int dwarf_aranges_size
;
148 static unsigned int dwarf_loc_size
;
149 static unsigned int dwarf_macinfo_size
;
150 static unsigned int dwarf_str_size
;
151 static unsigned int dwarf_ranges_size
;
152 unsigned int dwarf_frame_size
;
153 unsigned int dwarf_eh_frame_size
;
155 static asection
*dwarf_info_section
;
156 static asection
*dwarf_abbrev_section
;
157 static asection
*dwarf_line_section
;
158 static asection
*dwarf_pubnames_section
;
159 static asection
*dwarf_aranges_section
;
160 static asection
*dwarf_loc_section
;
161 static asection
*dwarf_macinfo_section
;
162 static asection
*dwarf_str_section
;
163 static asection
*dwarf_ranges_section
;
164 asection
*dwarf_frame_section
;
165 asection
*dwarf_eh_frame_section
;
167 /* names of the debugging sections */
169 #define INFO_SECTION ".debug_info"
170 #define ABBREV_SECTION ".debug_abbrev"
171 #define LINE_SECTION ".debug_line"
172 #define PUBNAMES_SECTION ".debug_pubnames"
173 #define ARANGES_SECTION ".debug_aranges"
174 #define LOC_SECTION ".debug_loc"
175 #define MACINFO_SECTION ".debug_macinfo"
176 #define STR_SECTION ".debug_str"
177 #define RANGES_SECTION ".debug_ranges"
178 #define FRAME_SECTION ".debug_frame"
179 #define EH_FRAME_SECTION ".eh_frame"
181 /* local data types */
183 /* We hold several abbreviation tables in memory at the same time. */
184 #ifndef ABBREV_HASH_SIZE
185 #define ABBREV_HASH_SIZE 121
188 /* The data in a compilation unit header, after target2host
189 translation, looks like this. */
190 struct comp_unit_head
192 unsigned long length
;
194 unsigned int abbrev_offset
;
195 unsigned char addr_size
;
196 unsigned char signed_addr_p
;
197 unsigned int offset_size
; /* size of file offsets; either 4 or 8 */
198 unsigned int initial_length_size
; /* size of the length field; either
201 /* Offset to the first byte of this compilation unit header in the
202 * .debug_info section, for resolving relative reference dies. */
206 /* Pointer to this compilation unit header in the .debug_info
211 /* Pointer to the first die of this compilatio unit. This will
212 * be the first byte following the compilation unit header. */
216 /* Pointer to the next compilation unit header in the program. */
218 struct comp_unit_head
*next
;
220 /* DWARF abbreviation table associated with this compilation unit */
222 struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
224 /* Base address of this compilation unit. */
226 CORE_ADDR base_address
;
228 /* Non-zero if base_address has been set. */
233 /* Internal state when decoding a particular compilation unit. */
236 /* The objfile containing this compilation unit. */
237 struct objfile
*objfile
;
239 /* The header of the compilation unit.
241 FIXME drow/2003-11-10: Some of the things from the comp_unit_head
242 should be moved to the dwarf2_cu structure; for instance the abbrevs
244 struct comp_unit_head header
;
247 /* The line number information for a compilation unit (found in the
248 .debug_line section) begins with a "statement program header",
249 which contains the following information. */
252 unsigned int total_length
;
253 unsigned short version
;
254 unsigned int header_length
;
255 unsigned char minimum_instruction_length
;
256 unsigned char default_is_stmt
;
258 unsigned char line_range
;
259 unsigned char opcode_base
;
261 /* standard_opcode_lengths[i] is the number of operands for the
262 standard opcode whose value is i. This means that
263 standard_opcode_lengths[0] is unused, and the last meaningful
264 element is standard_opcode_lengths[opcode_base - 1]. */
265 unsigned char *standard_opcode_lengths
;
267 /* The include_directories table. NOTE! These strings are not
268 allocated with xmalloc; instead, they are pointers into
269 debug_line_buffer. If you try to free them, `free' will get
271 unsigned int num_include_dirs
, include_dirs_size
;
274 /* The file_names table. NOTE! These strings are not allocated
275 with xmalloc; instead, they are pointers into debug_line_buffer.
276 Don't try to free them directly. */
277 unsigned int num_file_names
, file_names_size
;
281 unsigned int dir_index
;
282 unsigned int mod_time
;
286 /* The start and end of the statement program following this
287 header. These point into dwarf_line_buffer. */
288 char *statement_program_start
, *statement_program_end
;
291 /* When we construct a partial symbol table entry we only
292 need this much information. */
293 struct partial_die_info
296 unsigned char has_children
;
297 unsigned char is_external
;
298 unsigned char is_declaration
;
299 unsigned char has_type
;
306 struct dwarf_block
*locdesc
;
307 unsigned int language
;
311 /* This data structure holds the information of an abbrev. */
314 unsigned int number
; /* number identifying abbrev */
315 enum dwarf_tag tag
; /* dwarf tag */
316 int has_children
; /* boolean */
317 unsigned int num_attrs
; /* number of attributes */
318 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
319 struct abbrev_info
*next
; /* next in chain */
324 enum dwarf_attribute name
;
325 enum dwarf_form form
;
328 /* This data structure holds a complete die structure. */
331 enum dwarf_tag tag
; /* Tag indicating type of die */
332 unsigned int abbrev
; /* Abbrev number */
333 unsigned int offset
; /* Offset in .debug_info section */
334 unsigned int num_attrs
; /* Number of attributes */
335 struct attribute
*attrs
; /* An array of attributes */
336 struct die_info
*next_ref
; /* Next die in ref hash table */
338 /* The dies in a compilation unit form an n-ary tree. PARENT
339 points to this die's parent; CHILD points to the first child of
340 this node; and all the children of a given node are chained
341 together via their SIBLING fields, terminated by a die whose
343 struct die_info
*child
; /* Its first child, if any. */
344 struct die_info
*sibling
; /* Its next sibling, if any. */
345 struct die_info
*parent
; /* Its parent, if any. */
347 struct type
*type
; /* Cached type information */
350 /* Attributes have a name and a value */
353 enum dwarf_attribute name
;
354 enum dwarf_form form
;
358 struct dwarf_block
*blk
;
366 struct function_range
369 CORE_ADDR lowpc
, highpc
;
371 struct function_range
*next
;
374 static struct function_range
*cu_first_fn
, *cu_last_fn
, *cu_cached_fn
;
376 /* Get at parts of an attribute structure */
378 #define DW_STRING(attr) ((attr)->u.str)
379 #define DW_UNSND(attr) ((attr)->u.unsnd)
380 #define DW_BLOCK(attr) ((attr)->u.blk)
381 #define DW_SND(attr) ((attr)->u.snd)
382 #define DW_ADDR(attr) ((attr)->u.addr)
384 /* Blocks are a bunch of untyped bytes. */
391 #ifndef ATTR_ALLOC_CHUNK
392 #define ATTR_ALLOC_CHUNK 4
395 /* A hash table of die offsets for following references. */
396 #ifndef REF_HASH_SIZE
397 #define REF_HASH_SIZE 1021
400 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
402 /* Obstack for allocating temporary storage used during symbol reading. */
403 static struct obstack dwarf2_tmp_obstack
;
405 /* Offset to the first byte of the current compilation unit header,
406 for resolving relative reference dies. */
407 static unsigned int cu_header_offset
;
409 /* Allocate fields for structs, unions and enums in this size. */
410 #ifndef DW_FIELD_ALLOC_CHUNK
411 #define DW_FIELD_ALLOC_CHUNK 4
414 /* The language we are debugging. */
415 static enum language cu_language
;
416 static const struct language_defn
*cu_language_defn
;
418 /* Actually data from the sections. */
419 static char *dwarf_info_buffer
;
420 static char *dwarf_abbrev_buffer
;
421 static char *dwarf_line_buffer
;
422 static char *dwarf_str_buffer
;
423 static char *dwarf_macinfo_buffer
;
424 static char *dwarf_ranges_buffer
;
425 static char *dwarf_loc_buffer
;
427 /* A zeroed version of a partial die for initialization purposes. */
428 static struct partial_die_info zeroed_partial_die
;
430 /* The generic symbol table building routines have separate lists for
431 file scope symbols and all all other scopes (local scopes). So
432 we need to select the right one to pass to add_symbol_to_list().
433 We do it by keeping a pointer to the correct list in list_in_scope.
435 FIXME: The original dwarf code just treated the file scope as the first
436 local scope, and all other local scopes as nested local scopes, and worked
437 fine. Check to see if we really need to distinguish these
439 static struct pending
**list_in_scope
= &file_symbols
;
441 /* FIXME: decode_locdesc sets these variables to describe the location
442 to the caller. These ought to be a structure or something. If
443 none of the flags are set, the object lives at the address returned
444 by decode_locdesc. */
446 static int isreg
; /* Object lives in register.
447 decode_locdesc's return value is
448 the register number. */
450 /* This value is added to each symbol value. FIXME: Generalize to
451 the section_offsets structure used by dbxread (once this is done,
452 pass the appropriate section number to end_symtab). */
453 static CORE_ADDR baseaddr
; /* Add to each symbol value */
455 /* We put a pointer to this structure in the read_symtab_private field
457 The complete dwarf information for an objfile is kept in the
458 psymbol_obstack, so that absolute die references can be handled.
459 Most of the information in this structure is related to an entire
460 object file and could be passed via the sym_private field of the objfile.
461 It is however conceivable that dwarf2 might not be the only type
462 of symbols read from an object file. */
466 /* Pointer to start of dwarf info buffer for the objfile. */
468 char *dwarf_info_buffer
;
470 /* Offset in dwarf_info_buffer for this compilation unit. */
472 unsigned long dwarf_info_offset
;
474 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
476 char *dwarf_abbrev_buffer
;
478 /* Size of dwarf abbreviation section for the objfile. */
480 unsigned int dwarf_abbrev_size
;
482 /* Pointer to start of dwarf line buffer for the objfile. */
484 char *dwarf_line_buffer
;
486 /* Size of dwarf_line_buffer, in bytes. */
488 unsigned int dwarf_line_size
;
490 /* Pointer to start of dwarf string buffer for the objfile. */
492 char *dwarf_str_buffer
;
494 /* Size of dwarf string section for the objfile. */
496 unsigned int dwarf_str_size
;
498 /* Pointer to start of dwarf macro buffer for the objfile. */
500 char *dwarf_macinfo_buffer
;
502 /* Size of dwarf macinfo section for the objfile. */
504 unsigned int dwarf_macinfo_size
;
506 /* Pointer to start of dwarf ranges buffer for the objfile. */
508 char *dwarf_ranges_buffer
;
510 /* Size of dwarf ranges buffer for the objfile. */
512 unsigned int dwarf_ranges_size
;
514 /* Pointer to start of dwarf locations buffer for the objfile. */
516 char *dwarf_loc_buffer
;
518 /* Size of dwarf locations buffer for the objfile. */
520 unsigned int dwarf_loc_size
;
523 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
524 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
525 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
526 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
527 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
528 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
529 #define DWARF_LINE_SIZE(p) (PST_PRIVATE(p)->dwarf_line_size)
530 #define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer)
531 #define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size)
532 #define DWARF_MACINFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_macinfo_buffer)
533 #define DWARF_MACINFO_SIZE(p) (PST_PRIVATE(p)->dwarf_macinfo_size)
534 #define DWARF_RANGES_BUFFER(p) (PST_PRIVATE(p)->dwarf_ranges_buffer)
535 #define DWARF_RANGES_SIZE(p) (PST_PRIVATE(p)->dwarf_ranges_size)
536 #define DWARF_LOC_BUFFER(p) (PST_PRIVATE(p)->dwarf_loc_buffer)
537 #define DWARF_LOC_SIZE(p) (PST_PRIVATE(p)->dwarf_loc_size)
539 /* Maintain an array of referenced fundamental types for the current
540 compilation unit being read. For DWARF version 1, we have to construct
541 the fundamental types on the fly, since no information about the
542 fundamental types is supplied. Each such fundamental type is created by
543 calling a language dependent routine to create the type, and then a
544 pointer to that type is then placed in the array at the index specified
545 by it's FT_<TYPENAME> value. The array has a fixed size set by the
546 FT_NUM_MEMBERS compile time constant, which is the number of predefined
547 fundamental types gdb knows how to construct. */
548 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
550 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
551 but this would require a corresponding change in unpack_field_as_long
553 static int bits_per_byte
= 8;
555 /* The routines that read and process dies for a C struct or C++ class
556 pass lists of data member fields and lists of member function fields
557 in an instance of a field_info structure, as defined below. */
560 /* List of data member and baseclasses fields. */
563 struct nextfield
*next
;
570 /* Number of fields. */
573 /* Number of baseclasses. */
576 /* Set if the accesibility of one of the fields is not public. */
577 int non_public_fields
;
579 /* Member function fields array, entries are allocated in the order they
580 are encountered in the object file. */
583 struct nextfnfield
*next
;
584 struct fn_field fnfield
;
588 /* Member function fieldlist array, contains name of possibly overloaded
589 member function, number of overloaded member functions and a pointer
590 to the head of the member function field chain. */
595 struct nextfnfield
*head
;
599 /* Number of entries in the fnfieldlists array. */
603 /* Various complaints about symbol reading that don't abort the process */
606 dwarf2_non_const_array_bound_ignored_complaint (const char *arg1
)
608 complaint (&symfile_complaints
, "non-constant array bounds form '%s' ignored",
613 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
615 complaint (&symfile_complaints
,
616 "statement list doesn't fit in .debug_line section");
620 dwarf2_complex_location_expr_complaint (void)
622 complaint (&symfile_complaints
, "location expression too complex");
626 dwarf2_unsupported_at_frame_base_complaint (const char *arg1
)
628 complaint (&symfile_complaints
,
629 "unsupported DW_AT_frame_base for function '%s'", arg1
);
633 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
636 complaint (&symfile_complaints
,
637 "const value length mismatch for '%s', got %d, expected %d", arg1
,
642 dwarf2_macros_too_long_complaint (void)
644 complaint (&symfile_complaints
,
645 "macro info runs off end of `.debug_macinfo' section");
649 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
651 complaint (&symfile_complaints
,
652 "macro debug info contains a malformed macro definition:\n`%s'",
657 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
659 complaint (&symfile_complaints
,
660 "invalid attribute class or form for '%s' in '%s'", arg1
, arg2
);
663 /* local function prototypes */
665 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
668 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
671 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
673 static char *scan_partial_symbols (char *, CORE_ADDR
*, CORE_ADDR
*,
675 const char *namespace);
677 static void add_partial_symbol (struct partial_die_info
*, struct dwarf2_cu
*,
678 const char *namespace);
680 static char *add_partial_namespace (struct partial_die_info
*pdi
,
682 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
683 struct dwarf2_cu
*cu
,
684 const char *namespace);
686 static char *add_partial_enumeration (struct partial_die_info
*enum_pdi
,
688 struct dwarf2_cu
*cu
,
689 const char *namespace);
691 static char *locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
694 struct dwarf2_cu
*cu
);
696 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
698 static void psymtab_to_symtab_1 (struct partial_symtab
*);
700 char *dwarf2_read_section (struct objfile
*, file_ptr
, unsigned int,
703 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
705 static void dwarf2_empty_abbrev_table (void *);
707 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
710 static char *read_partial_die (struct partial_die_info
*,
711 bfd
*, char *, struct dwarf2_cu
*);
713 static char *read_full_die (struct die_info
**, bfd
*, char *,
714 struct dwarf2_cu
*, int *);
716 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
717 bfd
*, char *, struct dwarf2_cu
*);
719 static char *read_attribute_value (struct attribute
*, unsigned,
720 bfd
*, char *, struct dwarf2_cu
*);
722 static unsigned int read_1_byte (bfd
*, char *);
724 static int read_1_signed_byte (bfd
*, char *);
726 static unsigned int read_2_bytes (bfd
*, char *);
728 static unsigned int read_4_bytes (bfd
*, char *);
730 static unsigned long read_8_bytes (bfd
*, char *);
732 static CORE_ADDR
read_address (bfd
*, char *ptr
, struct dwarf2_cu
*,
735 static LONGEST
read_initial_length (bfd
*, char *,
736 struct comp_unit_head
*, int *bytes_read
);
738 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
741 static char *read_n_bytes (bfd
*, char *, unsigned int);
743 static char *read_string (bfd
*, char *, unsigned int *);
745 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
748 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
750 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
752 static void set_cu_language (unsigned int);
754 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
756 static int die_is_declaration (struct die_info
*);
758 static void free_line_header (struct line_header
*lh
);
760 static struct line_header
*(dwarf_decode_line_header
761 (unsigned int offset
,
762 bfd
*abfd
, struct dwarf2_cu
*cu
));
764 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
767 static void dwarf2_start_subfile (char *, char *);
769 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
772 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
775 static void dwarf2_const_value_data (struct attribute
*attr
,
779 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
781 static struct type
*die_containing_type (struct die_info
*,
785 static struct type
*type_at_offset (unsigned int, struct objfile
*);
788 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
790 static void read_type_die (struct die_info
*, struct dwarf2_cu
*);
792 static void read_typedef (struct die_info
*, struct dwarf2_cu
*);
794 static void read_base_type (struct die_info
*, struct dwarf2_cu
*);
796 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
798 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
800 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
802 static int dwarf2_get_pc_bounds (struct die_info
*,
803 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
805 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
808 static void dwarf2_attach_fields_to_type (struct field_info
*,
809 struct type
*, struct dwarf2_cu
*);
811 static void dwarf2_add_member_fn (struct field_info
*,
812 struct die_info
*, struct type
*,
815 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
816 struct type
*, struct dwarf2_cu
*);
818 static void read_structure_scope (struct die_info
*, struct dwarf2_cu
*);
820 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
822 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
824 static void read_enumeration (struct die_info
*, struct dwarf2_cu
*);
826 static struct type
*dwarf_base_type (int, int, struct dwarf2_cu
*);
828 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
830 static void read_array_type (struct die_info
*, struct dwarf2_cu
*);
832 static void read_tag_pointer_type (struct die_info
*, struct dwarf2_cu
*);
834 static void read_tag_ptr_to_member_type (struct die_info
*,
837 static void read_tag_reference_type (struct die_info
*, struct dwarf2_cu
*);
839 static void read_tag_const_type (struct die_info
*, struct dwarf2_cu
*);
841 static void read_tag_volatile_type (struct die_info
*, struct dwarf2_cu
*);
843 static void read_tag_string_type (struct die_info
*, struct dwarf2_cu
*);
845 static void read_subroutine_type (struct die_info
*, struct dwarf2_cu
*);
847 static struct die_info
*read_comp_unit (char *, bfd
*, struct dwarf2_cu
*);
849 static struct die_info
*read_die_and_children (char *info_ptr
, bfd
*abfd
,
852 struct die_info
*parent
);
854 static struct die_info
*read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
857 struct die_info
*parent
);
859 static void free_die_list (struct die_info
*);
861 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
863 static void process_die (struct die_info
*, struct dwarf2_cu
*);
865 static char *dwarf2_linkage_name (struct die_info
*);
867 static char *dwarf2_name (struct die_info
*die
);
869 static struct die_info
*dwarf2_extension (struct die_info
*die
);
871 static char *dwarf_tag_name (unsigned int);
873 static char *dwarf_attr_name (unsigned int);
875 static char *dwarf_form_name (unsigned int);
877 static char *dwarf_stack_op_name (unsigned int);
879 static char *dwarf_bool_name (unsigned int);
881 static char *dwarf_type_encoding_name (unsigned int);
884 static char *dwarf_cfi_name (unsigned int);
886 struct die_info
*copy_die (struct die_info
*);
889 static struct die_info
*sibling_die (struct die_info
*);
891 static void dump_die (struct die_info
*);
893 static void dump_die_list (struct die_info
*);
895 static void store_in_ref_table (unsigned int, struct die_info
*);
897 static void dwarf2_empty_hash_tables (void);
899 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
901 static struct die_info
*follow_die_ref (unsigned int);
903 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
905 /* memory allocation interface */
907 static void dwarf2_free_tmp_obstack (void *);
909 static struct dwarf_block
*dwarf_alloc_block (void);
911 static struct abbrev_info
*dwarf_alloc_abbrev (void);
913 static struct die_info
*dwarf_alloc_die (void);
915 static void initialize_cu_func_list (void);
917 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
);
919 static void dwarf_decode_macros (struct line_header
*, unsigned int,
920 char *, bfd
*, struct dwarf2_cu
*);
922 static int attr_form_is_block (struct attribute
*);
925 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
926 struct dwarf2_cu
*cu
);
928 /* Try to locate the sections we need for DWARF 2 debugging
929 information and return true if we have enough to do something. */
932 dwarf2_has_info (bfd
*abfd
)
934 dwarf_info_offset
= 0;
935 dwarf_abbrev_offset
= 0;
936 dwarf_line_offset
= 0;
937 dwarf_str_offset
= 0;
938 dwarf_macinfo_offset
= 0;
939 dwarf_frame_offset
= 0;
940 dwarf_eh_frame_offset
= 0;
941 dwarf_ranges_offset
= 0;
942 dwarf_loc_offset
= 0;
944 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
945 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
955 /* This function is mapped across the sections and remembers the
956 offset and size of each of the debugging sections we are interested
960 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, void *ignore_ptr
)
962 if (strcmp (sectp
->name
, INFO_SECTION
) == 0)
964 dwarf_info_offset
= sectp
->filepos
;
965 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
966 dwarf_info_section
= sectp
;
968 else if (strcmp (sectp
->name
, ABBREV_SECTION
) == 0)
970 dwarf_abbrev_offset
= sectp
->filepos
;
971 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
972 dwarf_abbrev_section
= sectp
;
974 else if (strcmp (sectp
->name
, LINE_SECTION
) == 0)
976 dwarf_line_offset
= sectp
->filepos
;
977 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
978 dwarf_line_section
= sectp
;
980 else if (strcmp (sectp
->name
, PUBNAMES_SECTION
) == 0)
982 dwarf_pubnames_offset
= sectp
->filepos
;
983 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
984 dwarf_pubnames_section
= sectp
;
986 else if (strcmp (sectp
->name
, ARANGES_SECTION
) == 0)
988 dwarf_aranges_offset
= sectp
->filepos
;
989 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
990 dwarf_aranges_section
= sectp
;
992 else if (strcmp (sectp
->name
, LOC_SECTION
) == 0)
994 dwarf_loc_offset
= sectp
->filepos
;
995 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
996 dwarf_loc_section
= sectp
;
998 else if (strcmp (sectp
->name
, MACINFO_SECTION
) == 0)
1000 dwarf_macinfo_offset
= sectp
->filepos
;
1001 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
1002 dwarf_macinfo_section
= sectp
;
1004 else if (strcmp (sectp
->name
, STR_SECTION
) == 0)
1006 dwarf_str_offset
= sectp
->filepos
;
1007 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
1008 dwarf_str_section
= sectp
;
1010 else if (strcmp (sectp
->name
, FRAME_SECTION
) == 0)
1012 dwarf_frame_offset
= sectp
->filepos
;
1013 dwarf_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1014 dwarf_frame_section
= sectp
;
1016 else if (strcmp (sectp
->name
, EH_FRAME_SECTION
) == 0)
1018 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1019 if (aflag
& SEC_HAS_CONTENTS
)
1021 dwarf_eh_frame_offset
= sectp
->filepos
;
1022 dwarf_eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1023 dwarf_eh_frame_section
= sectp
;
1026 else if (strcmp (sectp
->name
, RANGES_SECTION
) == 0)
1028 dwarf_ranges_offset
= sectp
->filepos
;
1029 dwarf_ranges_size
= bfd_get_section_size_before_reloc (sectp
);
1030 dwarf_ranges_section
= sectp
;
1034 /* Build a partial symbol table. */
1037 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1040 /* We definitely need the .debug_info and .debug_abbrev sections */
1042 dwarf_info_buffer
= dwarf2_read_section (objfile
,
1045 dwarf_info_section
);
1046 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
1047 dwarf_abbrev_offset
,
1049 dwarf_abbrev_section
);
1051 if (dwarf_line_offset
)
1052 dwarf_line_buffer
= dwarf2_read_section (objfile
,
1055 dwarf_line_section
);
1057 dwarf_line_buffer
= NULL
;
1059 if (dwarf_str_offset
)
1060 dwarf_str_buffer
= dwarf2_read_section (objfile
,
1065 dwarf_str_buffer
= NULL
;
1067 if (dwarf_macinfo_offset
)
1068 dwarf_macinfo_buffer
= dwarf2_read_section (objfile
,
1069 dwarf_macinfo_offset
,
1071 dwarf_macinfo_section
);
1073 dwarf_macinfo_buffer
= NULL
;
1075 if (dwarf_ranges_offset
)
1076 dwarf_ranges_buffer
= dwarf2_read_section (objfile
,
1077 dwarf_ranges_offset
,
1079 dwarf_ranges_section
);
1081 dwarf_ranges_buffer
= NULL
;
1083 if (dwarf_loc_offset
)
1084 dwarf_loc_buffer
= dwarf2_read_section (objfile
,
1089 dwarf_loc_buffer
= NULL
;
1092 || (objfile
->global_psymbols
.size
== 0
1093 && objfile
->static_psymbols
.size
== 0))
1095 init_psymbol_list (objfile
, 1024);
1099 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1101 /* Things are significantly easier if we have .debug_aranges and
1102 .debug_pubnames sections */
1104 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1108 /* only test this case for now */
1110 /* In this case we have to work a bit harder */
1111 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1116 /* Build the partial symbol table from the information in the
1117 .debug_pubnames and .debug_aranges sections. */
1120 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1122 bfd
*abfd
= objfile
->obfd
;
1123 char *aranges_buffer
, *pubnames_buffer
;
1124 char *aranges_ptr
, *pubnames_ptr
;
1125 unsigned int entry_length
, version
, info_offset
, info_size
;
1127 pubnames_buffer
= dwarf2_read_section (objfile
,
1128 dwarf_pubnames_offset
,
1129 dwarf_pubnames_size
,
1130 dwarf_pubnames_section
);
1131 pubnames_ptr
= pubnames_buffer
;
1132 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
1134 struct comp_unit_head cu_header
;
1137 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1139 pubnames_ptr
+= bytes_read
;
1140 version
= read_1_byte (abfd
, pubnames_ptr
);
1142 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1144 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1148 aranges_buffer
= dwarf2_read_section (objfile
,
1149 dwarf_aranges_offset
,
1151 dwarf_aranges_section
);
1156 /* Read in the comp unit header information from the debug_info at
1160 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1161 char *info_ptr
, bfd
*abfd
)
1165 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1167 info_ptr
+= bytes_read
;
1168 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1170 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1172 info_ptr
+= bytes_read
;
1173 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1175 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1176 if (signed_addr
< 0)
1177 internal_error (__FILE__
, __LINE__
,
1178 "read_comp_unit_head: dwarf from non elf file");
1179 cu_header
->signed_addr_p
= signed_addr
;
1183 /* Build the partial symbol table by doing a quick pass through the
1184 .debug_info and .debug_abbrev sections. */
1187 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1189 /* Instead of reading this into a big buffer, we should probably use
1190 mmap() on architectures that support it. (FIXME) */
1191 bfd
*abfd
= objfile
->obfd
;
1192 char *info_ptr
, *abbrev_ptr
;
1193 char *beg_of_comp_unit
;
1194 struct partial_die_info comp_unit_die
;
1195 struct partial_symtab
*pst
;
1196 struct cleanup
*back_to
;
1197 CORE_ADDR lowpc
, highpc
;
1199 info_ptr
= dwarf_info_buffer
;
1200 abbrev_ptr
= dwarf_abbrev_buffer
;
1202 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1203 the partial symbol scan, like attribute values.
1205 We could reduce our peak memory consumption during partial symbol
1206 table construction by freeing stuff from this obstack more often
1207 --- say, after processing each compilation unit, or each die ---
1208 but it turns out that this saves almost nothing. For an
1209 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1210 on dwarf2_tmp_obstack. Some investigation showed:
1212 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1213 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1214 all fixed-length values not requiring dynamic allocation.
1216 2) 30% of the attributes used the form DW_FORM_string. For
1217 DW_FORM_string, read_attribute simply hands back a pointer to
1218 the null-terminated string in dwarf_info_buffer, so no dynamic
1219 allocation is needed there either.
1221 3) The remaining 1% of the attributes all used DW_FORM_block1.
1222 75% of those were DW_AT_frame_base location lists for
1223 functions; the rest were DW_AT_location attributes, probably
1224 for the global variables.
1226 Anyway, what this all means is that the memory the dwarf2
1227 reader uses as temporary space reading partial symbols is about
1228 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1230 obstack_init (&dwarf2_tmp_obstack
);
1231 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1233 /* Since the objects we're extracting from dwarf_info_buffer vary in
1234 length, only the individual functions to extract them (like
1235 read_comp_unit_head and read_partial_die) can really know whether
1236 the buffer is large enough to hold another complete object.
1238 At the moment, they don't actually check that. If
1239 dwarf_info_buffer holds just one extra byte after the last
1240 compilation unit's dies, then read_comp_unit_head will happily
1241 read off the end of the buffer. read_partial_die is similarly
1242 casual. Those functions should be fixed.
1244 For this loop condition, simply checking whether there's any data
1245 left at all should be sufficient. */
1246 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1248 struct dwarf2_cu cu
;
1249 beg_of_comp_unit
= info_ptr
;
1251 cu
.objfile
= objfile
;
1252 info_ptr
= read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1254 if (cu
.header
.version
!= 2)
1256 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
));
1259 if (cu
.header
.abbrev_offset
>= dwarf_abbrev_size
)
1261 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6) [in module %s]",
1262 (long) cu
.header
.abbrev_offset
,
1263 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1264 bfd_get_filename (abfd
));
1267 if (beg_of_comp_unit
+ cu
.header
.length
+ cu
.header
.initial_length_size
1268 > dwarf_info_buffer
+ dwarf_info_size
)
1270 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0) [in module %s]",
1271 (long) cu
.header
.length
,
1272 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1273 bfd_get_filename (abfd
));
1276 /* Complete the cu_header */
1277 cu
.header
.offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1278 cu
.header
.first_die_ptr
= info_ptr
;
1279 cu
.header
.cu_head_ptr
= beg_of_comp_unit
;
1281 /* Read the abbrevs for this compilation unit into a table */
1282 dwarf2_read_abbrevs (abfd
, &cu
);
1283 make_cleanup (dwarf2_empty_abbrev_table
, cu
.header
.dwarf2_abbrevs
);
1285 /* Read the compilation unit die */
1286 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1289 /* Set the language we're debugging */
1290 set_cu_language (comp_unit_die
.language
);
1292 /* Allocate a new partial symbol table structure */
1293 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1294 comp_unit_die
.name
? comp_unit_die
.name
: "",
1295 comp_unit_die
.lowpc
,
1296 objfile
->global_psymbols
.next
,
1297 objfile
->static_psymbols
.next
);
1299 pst
->read_symtab_private
= (char *)
1300 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1301 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1302 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1303 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1304 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1305 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1306 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1307 DWARF_LINE_SIZE (pst
) = dwarf_line_size
;
1308 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1309 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1310 DWARF_MACINFO_BUFFER (pst
) = dwarf_macinfo_buffer
;
1311 DWARF_MACINFO_SIZE (pst
) = dwarf_macinfo_size
;
1312 DWARF_RANGES_BUFFER (pst
) = dwarf_ranges_buffer
;
1313 DWARF_RANGES_SIZE (pst
) = dwarf_ranges_size
;
1314 DWARF_LOC_BUFFER (pst
) = dwarf_loc_buffer
;
1315 DWARF_LOC_SIZE (pst
) = dwarf_loc_size
;
1316 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1318 /* Store the function that reads in the rest of the symbol table */
1319 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1321 /* Check if comp unit has_children.
1322 If so, read the rest of the partial symbols from this comp unit.
1323 If not, there's no more debug_info for this comp unit. */
1324 if (comp_unit_die
.has_children
)
1326 lowpc
= ((CORE_ADDR
) -1);
1327 highpc
= ((CORE_ADDR
) 0);
1329 info_ptr
= scan_partial_symbols (info_ptr
, &lowpc
, &highpc
,
1332 /* If we didn't find a lowpc, set it to highpc to avoid
1333 complaints from `maint check'. */
1334 if (lowpc
== ((CORE_ADDR
) -1))
1337 /* If the compilation unit didn't have an explicit address range,
1338 then use the information extracted from its child dies. */
1339 if (! comp_unit_die
.has_pc_info
)
1341 comp_unit_die
.lowpc
= lowpc
;
1342 comp_unit_die
.highpc
= highpc
;
1345 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1346 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1348 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1349 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1350 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1351 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1352 sort_pst_symbols (pst
);
1354 /* If there is already a psymtab or symtab for a file of this
1355 name, remove it. (If there is a symtab, more drastic things
1356 also happen.) This happens in VxWorks. */
1357 free_named_symtabs (pst
->filename
);
1359 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1360 + cu
.header
.initial_length_size
;
1362 do_cleanups (back_to
);
1365 /* Read in all interesting dies to the end of the compilation unit or
1366 to the end of the current namespace. NAMESPACE is NULL if we
1367 haven't yet encountered any DW_TAG_namespace entries; otherwise,
1368 it's the name of the current namespace. In particular, it's the
1369 empty string if we're currently in the global namespace but have
1370 previously encountered a DW_TAG_namespace. */
1373 scan_partial_symbols (char *info_ptr
, CORE_ADDR
*lowpc
,
1374 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
1375 const char *namespace)
1377 struct objfile
*objfile
= cu
->objfile
;
1378 bfd
*abfd
= objfile
->obfd
;
1379 struct partial_die_info pdi
;
1381 /* Now, march along the PDI's, descending into ones which have
1382 interesting children but skipping the children of the other ones,
1383 until we reach the end of the compilation unit. */
1387 /* This flag tells whether or not info_ptr has gotten updated
1389 int info_ptr_updated
= 0;
1391 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu
);
1393 /* Anonymous namespaces have no name but have interesting
1394 children, so we need to look at them. Ditto for anonymous
1397 if (pdi
.name
!= NULL
|| pdi
.tag
== DW_TAG_namespace
1398 || pdi
.tag
== DW_TAG_enumeration_type
)
1402 case DW_TAG_subprogram
:
1403 if (pdi
.has_pc_info
)
1405 if (pdi
.lowpc
< *lowpc
)
1409 if (pdi
.highpc
> *highpc
)
1411 *highpc
= pdi
.highpc
;
1413 if (!pdi
.is_declaration
)
1415 add_partial_symbol (&pdi
, cu
, namespace);
1419 case DW_TAG_variable
:
1420 case DW_TAG_typedef
:
1421 case DW_TAG_union_type
:
1422 case DW_TAG_class_type
:
1423 case DW_TAG_structure_type
:
1424 if (!pdi
.is_declaration
)
1426 add_partial_symbol (&pdi
, cu
, namespace);
1429 case DW_TAG_enumeration_type
:
1430 if (!pdi
.is_declaration
)
1432 info_ptr
= add_partial_enumeration (&pdi
, info_ptr
, cu
,
1434 info_ptr_updated
= 1;
1437 case DW_TAG_base_type
:
1438 /* File scope base type definitions are added to the partial
1440 add_partial_symbol (&pdi
, cu
, namespace);
1442 case DW_TAG_namespace
:
1443 /* We've hit a DW_TAG_namespace entry, so we know this
1444 file has been compiled using a compiler that
1445 generates them; update NAMESPACE to reflect that. */
1446 if (namespace == NULL
)
1448 info_ptr
= add_partial_namespace (&pdi
, info_ptr
, lowpc
, highpc
,
1450 info_ptr_updated
= 1;
1460 /* If the die has a sibling, skip to the sibling, unless another
1461 function has already updated info_ptr for us. */
1463 /* NOTE: carlton/2003-06-16: This is a bit hackish, but whether
1464 or not we want to update this depends on enough stuff (not
1465 only pdi.tag but also whether or not pdi.name is NULL) that
1466 this seems like the easiest way to handle the issue. */
1468 if (!info_ptr_updated
)
1469 info_ptr
= locate_pdi_sibling (&pdi
, info_ptr
, abfd
, cu
);
1476 add_partial_symbol (struct partial_die_info
*pdi
,
1477 struct dwarf2_cu
*cu
, const char *namespace)
1479 struct objfile
*objfile
= cu
->objfile
;
1481 const struct partial_symbol
*psym
= NULL
;
1485 case DW_TAG_subprogram
:
1486 if (pdi
->is_external
)
1488 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1489 mst_text, objfile); */
1490 psym
= add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1491 VAR_DOMAIN
, LOC_BLOCK
,
1492 &objfile
->global_psymbols
,
1493 0, pdi
->lowpc
+ baseaddr
,
1494 cu_language
, objfile
);
1498 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1499 mst_file_text, objfile); */
1500 psym
= add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1501 VAR_DOMAIN
, LOC_BLOCK
,
1502 &objfile
->static_psymbols
,
1503 0, pdi
->lowpc
+ baseaddr
,
1504 cu_language
, objfile
);
1507 case DW_TAG_variable
:
1508 if (pdi
->is_external
)
1511 Don't enter into the minimal symbol tables as there is
1512 a minimal symbol table entry from the ELF symbols already.
1513 Enter into partial symbol table if it has a location
1514 descriptor or a type.
1515 If the location descriptor is missing, new_symbol will create
1516 a LOC_UNRESOLVED symbol, the address of the variable will then
1517 be determined from the minimal symbol table whenever the variable
1519 The address for the partial symbol table entry is not
1520 used by GDB, but it comes in handy for debugging partial symbol
1524 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1525 if (pdi
->locdesc
|| pdi
->has_type
)
1526 psym
= add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1527 VAR_DOMAIN
, LOC_STATIC
,
1528 &objfile
->global_psymbols
,
1530 cu_language
, objfile
);
1534 /* Static Variable. Skip symbols without location descriptors. */
1535 if (pdi
->locdesc
== NULL
)
1537 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1538 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1539 mst_file_data, objfile); */
1540 psym
= add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1541 VAR_DOMAIN
, LOC_STATIC
,
1542 &objfile
->static_psymbols
,
1544 cu_language
, objfile
);
1547 case DW_TAG_typedef
:
1548 case DW_TAG_base_type
:
1549 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1550 VAR_DOMAIN
, LOC_TYPEDEF
,
1551 &objfile
->static_psymbols
,
1552 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1554 case DW_TAG_class_type
:
1555 case DW_TAG_structure_type
:
1556 case DW_TAG_union_type
:
1557 case DW_TAG_enumeration_type
:
1558 /* Skip aggregate types without children, these are external
1560 if (pdi
->has_children
== 0)
1562 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1563 STRUCT_DOMAIN
, LOC_TYPEDEF
,
1564 &objfile
->static_psymbols
,
1565 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1567 if (cu_language
== language_cplus
)
1569 /* For C++, these implicitly act as typedefs as well. */
1570 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1571 VAR_DOMAIN
, LOC_TYPEDEF
,
1572 &objfile
->static_psymbols
,
1573 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1576 case DW_TAG_enumerator
:
1577 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1578 VAR_DOMAIN
, LOC_CONST
,
1579 &objfile
->static_psymbols
,
1580 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1586 /* Check to see if we should scan the name for possible namespace
1587 info. Only do this if this is C++, if we don't have namespace
1588 debugging info in the file, if the psym is of an appropriate type
1589 (otherwise we'll have psym == NULL), and if we actually had a
1590 mangled name to begin with. */
1592 if (cu_language
== language_cplus
1593 && namespace == NULL
1595 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
1596 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
1600 /* Read a partial die corresponding to a namespace; also, add a symbol
1601 corresponding to that namespace to the symbol table. NAMESPACE is
1602 the name of the enclosing namespace. */
1605 add_partial_namespace (struct partial_die_info
*pdi
, char *info_ptr
,
1606 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1607 struct dwarf2_cu
*cu
, const char *namespace)
1609 struct objfile
*objfile
= cu
->objfile
;
1610 const char *new_name
= pdi
->name
;
1613 /* Calculate the full name of the namespace that we just entered. */
1615 if (new_name
== NULL
)
1616 new_name
= "(anonymous namespace)";
1617 full_name
= alloca (strlen (namespace) + 2 + strlen (new_name
) + 1);
1618 strcpy (full_name
, namespace);
1619 if (*namespace != '\0')
1620 strcat (full_name
, "::");
1621 strcat (full_name
, new_name
);
1623 /* FIXME: carlton/2003-06-27: Once we build qualified names for more
1624 symbols than just namespaces, we should replace this by a call to
1625 add_partial_symbol. */
1627 add_psymbol_to_list (full_name
, strlen (full_name
),
1628 VAR_DOMAIN
, LOC_TYPEDEF
,
1629 &objfile
->global_psymbols
,
1630 0, 0, cu_language
, objfile
);
1632 /* Now scan partial symbols in that namespace. */
1634 if (pdi
->has_children
)
1635 info_ptr
= scan_partial_symbols (info_ptr
, lowpc
, highpc
, cu
, full_name
);
1640 /* Read a partial die corresponding to an enumeration type. */
1643 add_partial_enumeration (struct partial_die_info
*enum_pdi
, char *info_ptr
,
1644 struct dwarf2_cu
*cu
, const char *namespace)
1646 struct objfile
*objfile
= cu
->objfile
;
1647 bfd
*abfd
= objfile
->obfd
;
1648 struct partial_die_info pdi
;
1650 if (enum_pdi
->name
!= NULL
)
1651 add_partial_symbol (enum_pdi
, cu
, namespace);
1655 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu
);
1658 if (pdi
.tag
!= DW_TAG_enumerator
|| pdi
.name
== NULL
)
1659 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
1661 add_partial_symbol (&pdi
, cu
, namespace);
1667 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the next DIE
1671 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, char *info_ptr
,
1672 bfd
*abfd
, struct dwarf2_cu
*cu
)
1674 /* Do we know the sibling already? */
1676 if (orig_pdi
->sibling
)
1677 return orig_pdi
->sibling
;
1679 /* Are there any children to deal with? */
1681 if (!orig_pdi
->has_children
)
1684 /* Okay, we don't know the sibling, but we have children that we
1685 want to skip. So read children until we run into one without a
1686 tag; return whatever follows it. */
1690 struct partial_die_info pdi
;
1692 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu
);
1697 info_ptr
= locate_pdi_sibling (&pdi
, info_ptr
, abfd
, cu
);
1701 /* Expand this partial symbol table into a full symbol table. */
1704 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1706 /* FIXME: This is barely more than a stub. */
1711 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1717 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1718 gdb_flush (gdb_stdout
);
1721 psymtab_to_symtab_1 (pst
);
1723 /* Finish up the debug error message. */
1725 printf_filtered ("done.\n");
1731 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1733 struct objfile
*objfile
= pst
->objfile
;
1734 bfd
*abfd
= objfile
->obfd
;
1735 struct dwarf2_cu cu
;
1736 struct die_info
*dies
;
1737 unsigned long offset
;
1738 CORE_ADDR lowpc
, highpc
;
1739 struct die_info
*child_die
;
1741 struct symtab
*symtab
;
1742 struct cleanup
*back_to
;
1743 struct attribute
*attr
;
1745 /* Set local variables from the partial symbol table info. */
1746 offset
= DWARF_INFO_OFFSET (pst
);
1747 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1748 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1749 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1750 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1751 dwarf_line_size
= DWARF_LINE_SIZE (pst
);
1752 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1753 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1754 dwarf_macinfo_buffer
= DWARF_MACINFO_BUFFER (pst
);
1755 dwarf_macinfo_size
= DWARF_MACINFO_SIZE (pst
);
1756 dwarf_ranges_buffer
= DWARF_RANGES_BUFFER (pst
);
1757 dwarf_ranges_size
= DWARF_RANGES_SIZE (pst
);
1758 dwarf_loc_buffer
= DWARF_LOC_BUFFER (pst
);
1759 dwarf_loc_size
= DWARF_LOC_SIZE (pst
);
1760 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1761 cu_header_offset
= offset
;
1762 info_ptr
= dwarf_info_buffer
+ offset
;
1764 obstack_init (&dwarf2_tmp_obstack
);
1765 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1768 make_cleanup (really_free_pendings
, NULL
);
1770 cu
.objfile
= objfile
;
1772 /* read in the comp_unit header */
1773 info_ptr
= read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1775 /* Read the abbrevs for this compilation unit */
1776 dwarf2_read_abbrevs (abfd
, &cu
);
1777 make_cleanup (dwarf2_empty_abbrev_table
, cu
.header
.dwarf2_abbrevs
);
1779 dies
= read_comp_unit (info_ptr
, abfd
, &cu
);
1781 make_cleanup_free_die_list (dies
);
1783 /* Find the base address of the compilation unit for range lists and
1784 location lists. It will normally be specified by DW_AT_low_pc.
1785 In DWARF-3 draft 4, the base address could be overridden by
1786 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1787 compilation units with discontinuous ranges. */
1789 cu
.header
.base_known
= 0;
1790 cu
.header
.base_address
= 0;
1792 attr
= dwarf_attr (dies
, DW_AT_entry_pc
);
1795 cu
.header
.base_address
= DW_ADDR (attr
);
1796 cu
.header
.base_known
= 1;
1800 attr
= dwarf_attr (dies
, DW_AT_low_pc
);
1803 cu
.header
.base_address
= DW_ADDR (attr
);
1804 cu
.header
.base_known
= 1;
1808 /* Do line number decoding in read_file_scope () */
1809 process_die (dies
, &cu
);
1811 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, &cu
))
1813 /* Some compilers don't define a DW_AT_high_pc attribute for
1814 the compilation unit. If the DW_AT_high_pc is missing,
1815 synthesize it, by scanning the DIE's below the compilation unit. */
1817 if (dies
->child
!= NULL
)
1819 child_die
= dies
->child
;
1820 while (child_die
&& child_die
->tag
)
1822 if (child_die
->tag
== DW_TAG_subprogram
)
1824 CORE_ADDR low
, high
;
1826 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, &cu
))
1828 highpc
= max (highpc
, high
);
1831 child_die
= sibling_die (child_die
);
1835 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1837 /* Set symtab language to language from DW_AT_language.
1838 If the compilation is from a C file generated by language preprocessors,
1839 do not set the language if it was already deduced by start_subfile. */
1841 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1843 symtab
->language
= cu_language
;
1845 pst
->symtab
= symtab
;
1848 do_cleanups (back_to
);
1851 /* Process a die and its children. */
1854 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
1858 case DW_TAG_padding
:
1860 case DW_TAG_compile_unit
:
1861 read_file_scope (die
, cu
);
1863 case DW_TAG_subprogram
:
1864 read_subroutine_type (die
, cu
);
1865 read_func_scope (die
, cu
);
1867 case DW_TAG_inlined_subroutine
:
1868 /* FIXME: These are ignored for now.
1869 They could be used to set breakpoints on all inlined instances
1870 of a function and make GDB `next' properly over inlined functions. */
1872 case DW_TAG_lexical_block
:
1873 case DW_TAG_try_block
:
1874 case DW_TAG_catch_block
:
1875 read_lexical_block_scope (die
, cu
);
1877 case DW_TAG_class_type
:
1878 case DW_TAG_structure_type
:
1879 case DW_TAG_union_type
:
1880 read_structure_scope (die
, cu
);
1882 case DW_TAG_enumeration_type
:
1883 read_enumeration (die
, cu
);
1885 case DW_TAG_subroutine_type
:
1886 read_subroutine_type (die
, cu
);
1888 case DW_TAG_array_type
:
1889 read_array_type (die
, cu
);
1891 case DW_TAG_pointer_type
:
1892 read_tag_pointer_type (die
, cu
);
1894 case DW_TAG_ptr_to_member_type
:
1895 read_tag_ptr_to_member_type (die
, cu
);
1897 case DW_TAG_reference_type
:
1898 read_tag_reference_type (die
, cu
);
1900 case DW_TAG_string_type
:
1901 read_tag_string_type (die
, cu
);
1903 case DW_TAG_base_type
:
1904 read_base_type (die
, cu
);
1905 if (dwarf_attr (die
, DW_AT_name
))
1907 /* Add a typedef symbol for the base type definition. */
1908 new_symbol (die
, die
->type
, cu
);
1911 case DW_TAG_common_block
:
1912 read_common_block (die
, cu
);
1914 case DW_TAG_common_inclusion
:
1916 case DW_TAG_namespace
:
1917 if (!processing_has_namespace_info
)
1919 processing_has_namespace_info
= 1;
1920 processing_current_namespace
= "";
1922 read_namespace (die
, cu
);
1924 case DW_TAG_imported_declaration
:
1925 case DW_TAG_imported_module
:
1926 /* FIXME: carlton/2002-10-16: Eventually, we should use the
1927 information contained in these. DW_TAG_imported_declaration
1928 dies shouldn't have children; DW_TAG_imported_module dies
1929 shouldn't in the C++ case, but conceivably could in the
1930 Fortran case, so we'll have to replace this gdb_assert if
1931 Fortran compilers start generating that info. */
1932 if (!processing_has_namespace_info
)
1934 processing_has_namespace_info
= 1;
1935 processing_current_namespace
= "";
1937 gdb_assert (die
->child
== NULL
);
1940 new_symbol (die
, NULL
, cu
);
1946 initialize_cu_func_list (void)
1948 cu_first_fn
= cu_last_fn
= cu_cached_fn
= NULL
;
1952 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
1954 struct objfile
*objfile
= cu
->objfile
;
1955 struct comp_unit_head
*cu_header
= &cu
->header
;
1956 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
1957 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1958 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1959 struct attribute
*attr
;
1960 char *name
= "<unknown>";
1961 char *comp_dir
= NULL
;
1962 struct die_info
*child_die
;
1963 bfd
*abfd
= objfile
->obfd
;
1964 struct line_header
*line_header
= 0;
1966 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
1968 if (die
->child
!= NULL
)
1970 child_die
= die
->child
;
1971 while (child_die
&& child_die
->tag
)
1973 if (child_die
->tag
== DW_TAG_subprogram
)
1975 CORE_ADDR low
, high
;
1977 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, cu
))
1979 lowpc
= min (lowpc
, low
);
1980 highpc
= max (highpc
, high
);
1983 child_die
= sibling_die (child_die
);
1988 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1989 from finish_block. */
1990 if (lowpc
== ((CORE_ADDR
) -1))
1995 attr
= dwarf_attr (die
, DW_AT_name
);
1998 name
= DW_STRING (attr
);
2000 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
2003 comp_dir
= DW_STRING (attr
);
2006 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2007 directory, get rid of it. */
2008 char *cp
= strchr (comp_dir
, ':');
2010 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2015 if (objfile
->ei
.entry_point
>= lowpc
&&
2016 objfile
->ei
.entry_point
< highpc
)
2018 objfile
->ei
.deprecated_entry_file_lowpc
= lowpc
;
2019 objfile
->ei
.deprecated_entry_file_highpc
= highpc
;
2022 attr
= dwarf_attr (die
, DW_AT_language
);
2025 set_cu_language (DW_UNSND (attr
));
2028 /* We assume that we're processing GCC output. */
2029 processing_gcc_compilation
= 2;
2031 /* FIXME:Do something here. */
2032 if (dip
->at_producer
!= NULL
)
2034 handle_producer (dip
->at_producer
);
2038 /* The compilation unit may be in a different language or objfile,
2039 zero out all remembered fundamental types. */
2040 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
2042 start_symtab (name
, comp_dir
, lowpc
);
2043 record_debugformat ("DWARF 2");
2045 initialize_cu_func_list ();
2047 /* Process all dies in compilation unit. */
2048 if (die
->child
!= NULL
)
2050 child_die
= die
->child
;
2051 while (child_die
&& child_die
->tag
)
2053 process_die (child_die
, cu
);
2054 child_die
= sibling_die (child_die
);
2058 /* Decode line number information if present. */
2059 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
2062 unsigned int line_offset
= DW_UNSND (attr
);
2063 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2066 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
2067 (void *) line_header
);
2068 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
);
2072 /* Decode macro information, if present. Dwarf 2 macro information
2073 refers to information in the line number info statement program
2074 header, so we can only read it if we've read the header
2076 attr
= dwarf_attr (die
, DW_AT_macro_info
);
2077 if (attr
&& line_header
)
2079 unsigned int macro_offset
= DW_UNSND (attr
);
2080 dwarf_decode_macros (line_header
, macro_offset
,
2081 comp_dir
, abfd
, cu
);
2083 do_cleanups (back_to
);
2087 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
)
2089 struct function_range
*thisfn
;
2091 thisfn
= (struct function_range
*)
2092 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct function_range
));
2093 thisfn
->name
= name
;
2094 thisfn
->lowpc
= lowpc
;
2095 thisfn
->highpc
= highpc
;
2096 thisfn
->seen_line
= 0;
2097 thisfn
->next
= NULL
;
2099 if (cu_last_fn
== NULL
)
2100 cu_first_fn
= thisfn
;
2102 cu_last_fn
->next
= thisfn
;
2104 cu_last_fn
= thisfn
;
2108 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2110 struct objfile
*objfile
= cu
->objfile
;
2111 struct context_stack
*new;
2114 struct die_info
*child_die
;
2115 struct attribute
*attr
;
2118 name
= dwarf2_linkage_name (die
);
2120 /* Ignore functions with missing or empty names and functions with
2121 missing or invalid low and high pc attributes. */
2122 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2128 /* Record the function range for dwarf_decode_lines. */
2129 add_to_cu_func_list (name
, lowpc
, highpc
);
2131 if (objfile
->ei
.entry_point
>= lowpc
&&
2132 objfile
->ei
.entry_point
< highpc
)
2134 objfile
->ei
.entry_func_lowpc
= lowpc
;
2135 objfile
->ei
.entry_func_highpc
= highpc
;
2138 new = push_context (0, lowpc
);
2139 new->name
= new_symbol (die
, die
->type
, cu
);
2141 /* If there is a location expression for DW_AT_frame_base, record
2143 attr
= dwarf_attr (die
, DW_AT_frame_base
);
2145 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
2147 list_in_scope
= &local_symbols
;
2149 if (die
->child
!= NULL
)
2151 child_die
= die
->child
;
2152 while (child_die
&& child_die
->tag
)
2154 process_die (child_die
, cu
);
2155 child_die
= sibling_die (child_die
);
2159 new = pop_context ();
2160 /* Make a block for the local symbols within. */
2161 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2162 lowpc
, highpc
, objfile
);
2164 /* In C++, we can have functions nested inside functions (e.g., when
2165 a function declares a class that has methods). This means that
2166 when we finish processing a function scope, we may need to go
2167 back to building a containing block's symbol lists. */
2168 local_symbols
= new->locals
;
2169 param_symbols
= new->params
;
2171 /* If we've finished processing a top-level function, subsequent
2172 symbols go in the file symbol list. */
2173 if (outermost_context_p ())
2174 list_in_scope
= &file_symbols
;
2177 /* Process all the DIES contained within a lexical block scope. Start
2178 a new scope, process the dies, and then close the scope. */
2181 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2183 struct objfile
*objfile
= cu
->objfile
;
2184 struct context_stack
*new;
2185 CORE_ADDR lowpc
, highpc
;
2186 struct die_info
*child_die
;
2188 /* Ignore blocks with missing or invalid low and high pc attributes. */
2189 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2190 as multiple lexical blocks? Handling children in a sane way would
2191 be nasty. Might be easier to properly extend generic blocks to
2193 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2198 push_context (0, lowpc
);
2199 if (die
->child
!= NULL
)
2201 child_die
= die
->child
;
2202 while (child_die
&& child_die
->tag
)
2204 process_die (child_die
, cu
);
2205 child_die
= sibling_die (child_die
);
2208 new = pop_context ();
2210 if (local_symbols
!= NULL
)
2212 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
2215 local_symbols
= new->locals
;
2218 /* Get low and high pc attributes from a die. Return 1 if the attributes
2219 are present and valid, otherwise, return 0. Return -1 if the range is
2220 discontinuous, i.e. derived from DW_AT_ranges information. */
2222 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
2223 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
2225 struct objfile
*objfile
= cu
->objfile
;
2226 struct comp_unit_head
*cu_header
= &cu
->header
;
2227 struct attribute
*attr
;
2228 bfd
*obfd
= objfile
->obfd
;
2233 attr
= dwarf_attr (die
, DW_AT_high_pc
);
2236 high
= DW_ADDR (attr
);
2237 attr
= dwarf_attr (die
, DW_AT_low_pc
);
2239 low
= DW_ADDR (attr
);
2241 /* Found high w/o low attribute. */
2244 /* Found consecutive range of addresses. */
2249 attr
= dwarf_attr (die
, DW_AT_ranges
);
2252 unsigned int addr_size
= cu_header
->addr_size
;
2253 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
2254 /* Value of the DW_AT_ranges attribute is the offset in the
2255 .debug_ranges section. */
2256 unsigned int offset
= DW_UNSND (attr
);
2257 /* Base address selection entry. */
2265 found_base
= cu_header
->base_known
;
2266 base
= cu_header
->base_address
;
2268 if (offset
>= dwarf_ranges_size
)
2270 complaint (&symfile_complaints
,
2271 "Offset %d out of bounds for DW_AT_ranges attribute",
2275 buffer
= dwarf_ranges_buffer
+ offset
;
2277 /* Read in the largest possible address. */
2278 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
2279 if ((marker
& mask
) == mask
)
2281 /* If we found the largest possible address, then
2282 read the base address. */
2283 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2284 buffer
+= 2 * addr_size
;
2285 offset
+= 2 * addr_size
;
2293 CORE_ADDR range_beginning
, range_end
;
2295 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
2296 buffer
+= addr_size
;
2297 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
2298 buffer
+= addr_size
;
2299 offset
+= 2 * addr_size
;
2301 /* An end of list marker is a pair of zero addresses. */
2302 if (range_beginning
== 0 && range_end
== 0)
2303 /* Found the end of list entry. */
2306 /* Each base address selection entry is a pair of 2 values.
2307 The first is the largest possible address, the second is
2308 the base address. Check for a base address here. */
2309 if ((range_beginning
& mask
) == mask
)
2311 /* If we found the largest possible address, then
2312 read the base address. */
2313 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2320 /* We have no valid base address for the ranges
2322 complaint (&symfile_complaints
,
2323 "Invalid .debug_ranges data (no base address)");
2327 range_beginning
+= base
;
2330 /* FIXME: This is recording everything as a low-high
2331 segment of consecutive addresses. We should have a
2332 data structure for discontiguous block ranges
2336 low
= range_beginning
;
2342 if (range_beginning
< low
)
2343 low
= range_beginning
;
2344 if (range_end
> high
)
2350 /* If the first entry is an end-of-list marker, the range
2351 describes an empty scope, i.e. no instructions. */
2361 /* When using the GNU linker, .gnu.linkonce. sections are used to
2362 eliminate duplicate copies of functions and vtables and such.
2363 The linker will arbitrarily choose one and discard the others.
2364 The AT_*_pc values for such functions refer to local labels in
2365 these sections. If the section from that file was discarded, the
2366 labels are not in the output, so the relocs get a value of 0.
2367 If this is a discarded function, mark the pc bounds as invalid,
2368 so that GDB will ignore it. */
2369 if (low
== 0 && (bfd_get_file_flags (obfd
) & HAS_RELOC
) == 0)
2377 /* Add an aggregate field to the field list. */
2380 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
2381 struct dwarf2_cu
*cu
)
2383 struct objfile
*objfile
= cu
->objfile
;
2384 struct nextfield
*new_field
;
2385 struct attribute
*attr
;
2387 char *fieldname
= "";
2389 /* Allocate a new field list entry and link it in. */
2390 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2391 make_cleanup (xfree
, new_field
);
2392 memset (new_field
, 0, sizeof (struct nextfield
));
2393 new_field
->next
= fip
->fields
;
2394 fip
->fields
= new_field
;
2397 /* Handle accessibility and virtuality of field.
2398 The default accessibility for members is public, the default
2399 accessibility for inheritance is private. */
2400 if (die
->tag
!= DW_TAG_inheritance
)
2401 new_field
->accessibility
= DW_ACCESS_public
;
2403 new_field
->accessibility
= DW_ACCESS_private
;
2404 new_field
->virtuality
= DW_VIRTUALITY_none
;
2406 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2408 new_field
->accessibility
= DW_UNSND (attr
);
2409 if (new_field
->accessibility
!= DW_ACCESS_public
)
2410 fip
->non_public_fields
= 1;
2411 attr
= dwarf_attr (die
, DW_AT_virtuality
);
2413 new_field
->virtuality
= DW_UNSND (attr
);
2415 fp
= &new_field
->field
;
2417 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
))
2419 /* Data member other than a C++ static data member. */
2421 /* Get type of field. */
2422 fp
->type
= die_type (die
, cu
);
2424 FIELD_STATIC_KIND (*fp
) = 0;
2426 /* Get bit size of field (zero if none). */
2427 attr
= dwarf_attr (die
, DW_AT_bit_size
);
2430 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
2434 FIELD_BITSIZE (*fp
) = 0;
2437 /* Get bit offset of field. */
2438 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2441 FIELD_BITPOS (*fp
) =
2442 decode_locdesc (DW_BLOCK (attr
), cu
) * bits_per_byte
;
2445 FIELD_BITPOS (*fp
) = 0;
2446 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
2449 if (BITS_BIG_ENDIAN
)
2451 /* For big endian bits, the DW_AT_bit_offset gives the
2452 additional bit offset from the MSB of the containing
2453 anonymous object to the MSB of the field. We don't
2454 have to do anything special since we don't need to
2455 know the size of the anonymous object. */
2456 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
2460 /* For little endian bits, compute the bit offset to the
2461 MSB of the anonymous object, subtract off the number of
2462 bits from the MSB of the field to the MSB of the
2463 object, and then subtract off the number of bits of
2464 the field itself. The result is the bit offset of
2465 the LSB of the field. */
2467 int bit_offset
= DW_UNSND (attr
);
2469 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2472 /* The size of the anonymous object containing
2473 the bit field is explicit, so use the
2474 indicated size (in bytes). */
2475 anonymous_size
= DW_UNSND (attr
);
2479 /* The size of the anonymous object containing
2480 the bit field must be inferred from the type
2481 attribute of the data member containing the
2483 anonymous_size
= TYPE_LENGTH (fp
->type
);
2485 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2486 - bit_offset
- FIELD_BITSIZE (*fp
);
2490 /* Get name of field. */
2491 attr
= dwarf_attr (die
, DW_AT_name
);
2492 if (attr
&& DW_STRING (attr
))
2493 fieldname
= DW_STRING (attr
);
2494 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
2495 &objfile
->type_obstack
);
2497 /* Change accessibility for artificial fields (e.g. virtual table
2498 pointer or virtual base class pointer) to private. */
2499 if (dwarf_attr (die
, DW_AT_artificial
))
2501 new_field
->accessibility
= DW_ACCESS_private
;
2502 fip
->non_public_fields
= 1;
2505 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
2507 /* C++ static member. */
2509 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2510 is a declaration, but all versions of G++ as of this writing
2511 (so through at least 3.2.1) incorrectly generate
2512 DW_TAG_variable tags. */
2516 /* Get name of field. */
2517 attr
= dwarf_attr (die
, DW_AT_name
);
2518 if (attr
&& DW_STRING (attr
))
2519 fieldname
= DW_STRING (attr
);
2523 /* Get physical name. */
2524 physname
= dwarf2_linkage_name (die
);
2526 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
2527 &objfile
->type_obstack
));
2528 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2529 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
2530 &objfile
->type_obstack
);
2532 else if (die
->tag
== DW_TAG_inheritance
)
2534 /* C++ base class field. */
2535 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2537 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
2539 FIELD_BITSIZE (*fp
) = 0;
2540 FIELD_STATIC_KIND (*fp
) = 0;
2541 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2542 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2543 fip
->nbaseclasses
++;
2547 /* Create the vector of fields, and attach it to the type. */
2550 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
2551 struct dwarf2_cu
*cu
)
2553 int nfields
= fip
->nfields
;
2555 /* Record the field count, allocate space for the array of fields,
2556 and create blank accessibility bitfields if necessary. */
2557 TYPE_NFIELDS (type
) = nfields
;
2558 TYPE_FIELDS (type
) = (struct field
*)
2559 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2560 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2562 if (fip
->non_public_fields
)
2564 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2566 TYPE_FIELD_PRIVATE_BITS (type
) =
2567 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2568 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2570 TYPE_FIELD_PROTECTED_BITS (type
) =
2571 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2572 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2574 TYPE_FIELD_IGNORE_BITS (type
) =
2575 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2576 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2579 /* If the type has baseclasses, allocate and clear a bit vector for
2580 TYPE_FIELD_VIRTUAL_BITS. */
2581 if (fip
->nbaseclasses
)
2583 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2586 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2587 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2588 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2589 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2590 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2593 /* Copy the saved-up fields into the field vector. Start from the head
2594 of the list, adding to the tail of the field array, so that they end
2595 up in the same order in the array in which they were added to the list. */
2596 while (nfields
-- > 0)
2598 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2599 switch (fip
->fields
->accessibility
)
2601 case DW_ACCESS_private
:
2602 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2605 case DW_ACCESS_protected
:
2606 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2609 case DW_ACCESS_public
:
2613 /* Unknown accessibility. Complain and treat it as public. */
2615 complaint (&symfile_complaints
, "unsupported accessibility %d",
2616 fip
->fields
->accessibility
);
2620 if (nfields
< fip
->nbaseclasses
)
2622 switch (fip
->fields
->virtuality
)
2624 case DW_VIRTUALITY_virtual
:
2625 case DW_VIRTUALITY_pure_virtual
:
2626 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2630 fip
->fields
= fip
->fields
->next
;
2634 /* Add a member function to the proper fieldlist. */
2637 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2638 struct type
*type
, struct dwarf2_cu
*cu
)
2640 struct objfile
*objfile
= cu
->objfile
;
2641 struct attribute
*attr
;
2642 struct fnfieldlist
*flp
;
2644 struct fn_field
*fnp
;
2647 struct nextfnfield
*new_fnfield
;
2649 /* Get name of member function. */
2650 attr
= dwarf_attr (die
, DW_AT_name
);
2651 if (attr
&& DW_STRING (attr
))
2652 fieldname
= DW_STRING (attr
);
2656 /* Get the mangled name. */
2657 physname
= dwarf2_linkage_name (die
);
2659 /* Look up member function name in fieldlist. */
2660 for (i
= 0; i
< fip
->nfnfields
; i
++)
2662 if (DEPRECATED_STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2666 /* Create new list element if necessary. */
2667 if (i
< fip
->nfnfields
)
2668 flp
= &fip
->fnfieldlists
[i
];
2671 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2673 fip
->fnfieldlists
= (struct fnfieldlist
*)
2674 xrealloc (fip
->fnfieldlists
,
2675 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2676 * sizeof (struct fnfieldlist
));
2677 if (fip
->nfnfields
== 0)
2678 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2680 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2681 flp
->name
= fieldname
;
2687 /* Create a new member function field and chain it to the field list
2689 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2690 make_cleanup (xfree
, new_fnfield
);
2691 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2692 new_fnfield
->next
= flp
->head
;
2693 flp
->head
= new_fnfield
;
2696 /* Fill in the member function field info. */
2697 fnp
= &new_fnfield
->fnfield
;
2698 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2699 &objfile
->type_obstack
);
2700 fnp
->type
= alloc_type (objfile
);
2701 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2703 int nparams
= TYPE_NFIELDS (die
->type
);
2705 /* TYPE is the domain of this method, and DIE->TYPE is the type
2706 of the method itself (TYPE_CODE_METHOD). */
2707 smash_to_method_type (fnp
->type
, type
,
2708 TYPE_TARGET_TYPE (die
->type
),
2709 TYPE_FIELDS (die
->type
),
2710 TYPE_NFIELDS (die
->type
),
2711 TYPE_VARARGS (die
->type
));
2713 /* Handle static member functions.
2714 Dwarf2 has no clean way to discern C++ static and non-static
2715 member functions. G++ helps GDB by marking the first
2716 parameter for non-static member functions (which is the
2717 this pointer) as artificial. We obtain this information
2718 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2719 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2720 fnp
->voffset
= VOFFSET_STATIC
;
2723 complaint (&symfile_complaints
, "member function type missing for '%s'",
2726 /* Get fcontext from DW_AT_containing_type if present. */
2727 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2728 fnp
->fcontext
= die_containing_type (die
, cu
);
2730 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2731 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2733 /* Get accessibility. */
2734 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2737 switch (DW_UNSND (attr
))
2739 case DW_ACCESS_private
:
2740 fnp
->is_private
= 1;
2742 case DW_ACCESS_protected
:
2743 fnp
->is_protected
= 1;
2748 /* Check for artificial methods. */
2749 attr
= dwarf_attr (die
, DW_AT_artificial
);
2750 if (attr
&& DW_UNSND (attr
) != 0)
2751 fnp
->is_artificial
= 1;
2753 /* Get index in virtual function table if it is a virtual member function. */
2754 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2757 /* Support the .debug_loc offsets */
2758 if (attr_form_is_block (attr
))
2760 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
2762 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
2764 dwarf2_complex_location_expr_complaint ();
2768 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
2774 /* Create the vector of member function fields, and attach it to the type. */
2777 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2778 struct dwarf2_cu
*cu
)
2780 struct fnfieldlist
*flp
;
2781 int total_length
= 0;
2784 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2785 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2786 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2788 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2790 struct nextfnfield
*nfp
= flp
->head
;
2791 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2794 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2795 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2796 fn_flp
->fn_fields
= (struct fn_field
*)
2797 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2798 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2799 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2801 total_length
+= flp
->length
;
2804 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2805 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2808 /* Called when we find the DIE that starts a structure or union scope
2809 (definition) to process all dies that define the members of the
2812 NOTE: we need to call struct_type regardless of whether or not the
2813 DIE has an at_name attribute, since it might be an anonymous
2814 structure or union. This gets the type entered into our set of
2817 However, if the structure is incomplete (an opaque struct/union)
2818 then suppress creating a symbol table entry for it since gdb only
2819 wants to find the one with the complete definition. Note that if
2820 it is complete, we just call new_symbol, which does it's own
2821 checking about whether the struct/union is anonymous or not (and
2822 suppresses creating a symbol table entry itself). */
2825 read_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2827 struct objfile
*objfile
= cu
->objfile
;
2829 struct attribute
*attr
;
2831 type
= alloc_type (objfile
);
2833 INIT_CPLUS_SPECIFIC (type
);
2834 attr
= dwarf_attr (die
, DW_AT_name
);
2835 if (attr
&& DW_STRING (attr
))
2837 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2838 strlen (DW_STRING (attr
)),
2839 &objfile
->type_obstack
);
2842 if (die
->tag
== DW_TAG_structure_type
)
2844 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2846 else if (die
->tag
== DW_TAG_union_type
)
2848 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2852 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2854 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2857 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2860 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2864 TYPE_LENGTH (type
) = 0;
2867 /* We need to add the type field to the die immediately so we don't
2868 infinitely recurse when dealing with pointers to the structure
2869 type within the structure itself. */
2872 if (die
->child
!= NULL
&& ! die_is_declaration (die
))
2874 struct field_info fi
;
2875 struct die_info
*child_die
;
2876 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2878 memset (&fi
, 0, sizeof (struct field_info
));
2880 child_die
= die
->child
;
2882 while (child_die
&& child_die
->tag
)
2884 if (child_die
->tag
== DW_TAG_member
2885 || child_die
->tag
== DW_TAG_variable
)
2887 /* NOTE: carlton/2002-11-05: A C++ static data member
2888 should be a DW_TAG_member that is a declaration, but
2889 all versions of G++ as of this writing (so through at
2890 least 3.2.1) incorrectly generate DW_TAG_variable
2891 tags for them instead. */
2892 dwarf2_add_field (&fi
, child_die
, cu
);
2894 else if (child_die
->tag
== DW_TAG_subprogram
)
2896 /* C++ member function. */
2897 process_die (child_die
, cu
);
2898 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
2900 else if (child_die
->tag
== DW_TAG_inheritance
)
2902 /* C++ base class field. */
2903 dwarf2_add_field (&fi
, child_die
, cu
);
2907 process_die (child_die
, cu
);
2909 child_die
= sibling_die (child_die
);
2912 /* Attach fields and member functions to the type. */
2914 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
2917 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
2919 /* Get the type which refers to the base class (possibly this
2920 class itself) which contains the vtable pointer for the current
2921 class from the DW_AT_containing_type attribute. */
2923 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2925 struct type
*t
= die_containing_type (die
, cu
);
2927 TYPE_VPTR_BASETYPE (type
) = t
;
2930 static const char vptr_name
[] =
2931 {'_', 'v', 'p', 't', 'r', '\0'};
2934 /* Our own class provides vtbl ptr. */
2935 for (i
= TYPE_NFIELDS (t
) - 1;
2936 i
>= TYPE_N_BASECLASSES (t
);
2939 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2941 if (DEPRECATED_STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2942 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2944 TYPE_VPTR_FIELDNO (type
) = i
;
2949 /* Complain if virtual function table field not found. */
2950 if (i
< TYPE_N_BASECLASSES (t
))
2951 complaint (&symfile_complaints
,
2952 "virtual function table pointer not found when defining class '%s'",
2953 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
2958 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2963 new_symbol (die
, type
, cu
);
2965 do_cleanups (back_to
);
2969 /* No children, must be stub. */
2970 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2974 /* Given a pointer to a die which begins an enumeration, process all
2975 the dies that define the members of the enumeration.
2977 This will be much nicer in draft 6 of the DWARF spec when our
2978 members will be dies instead squished into the DW_AT_element_list
2981 NOTE: We reverse the order of the element list. */
2984 read_enumeration (struct die_info
*die
, struct dwarf2_cu
*cu
)
2986 struct objfile
*objfile
= cu
->objfile
;
2987 struct die_info
*child_die
;
2989 struct field
*fields
;
2990 struct attribute
*attr
;
2993 int unsigned_enum
= 1;
2995 type
= alloc_type (objfile
);
2997 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2998 attr
= dwarf_attr (die
, DW_AT_name
);
2999 if (attr
&& DW_STRING (attr
))
3001 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
3002 strlen (DW_STRING (attr
)),
3003 &objfile
->type_obstack
);
3006 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3009 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3013 TYPE_LENGTH (type
) = 0;
3018 if (die
->child
!= NULL
)
3020 child_die
= die
->child
;
3021 while (child_die
&& child_die
->tag
)
3023 if (child_die
->tag
!= DW_TAG_enumerator
)
3025 process_die (child_die
, cu
);
3029 attr
= dwarf_attr (child_die
, DW_AT_name
);
3032 sym
= new_symbol (child_die
, type
, cu
);
3033 if (SYMBOL_VALUE (sym
) < 0)
3036 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3038 fields
= (struct field
*)
3040 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
3041 * sizeof (struct field
));
3044 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
3045 FIELD_TYPE (fields
[num_fields
]) = NULL
;
3046 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
3047 FIELD_BITSIZE (fields
[num_fields
]) = 0;
3048 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
3054 child_die
= sibling_die (child_die
);
3059 TYPE_NFIELDS (type
) = num_fields
;
3060 TYPE_FIELDS (type
) = (struct field
*)
3061 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
3062 memcpy (TYPE_FIELDS (type
), fields
,
3063 sizeof (struct field
) * num_fields
);
3067 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
3070 new_symbol (die
, type
, cu
);
3073 /* Extract all information from a DW_TAG_array_type DIE and put it in
3074 the DIE's type field. For now, this only handles one dimensional
3078 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3080 struct objfile
*objfile
= cu
->objfile
;
3081 struct die_info
*child_die
;
3082 struct type
*type
= NULL
;
3083 struct type
*element_type
, *range_type
, *index_type
;
3084 struct type
**range_types
= NULL
;
3085 struct attribute
*attr
;
3087 struct cleanup
*back_to
;
3089 /* Return if we've already decoded this type. */
3095 element_type
= die_type (die
, cu
);
3097 /* Irix 6.2 native cc creates array types without children for
3098 arrays with unspecified length. */
3099 if (die
->child
== NULL
)
3101 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
3102 range_type
= create_range_type (NULL
, index_type
, 0, -1);
3103 die
->type
= create_array_type (NULL
, element_type
, range_type
);
3107 back_to
= make_cleanup (null_cleanup
, NULL
);
3108 child_die
= die
->child
;
3109 while (child_die
&& child_die
->tag
)
3111 if (child_die
->tag
== DW_TAG_subrange_type
)
3113 unsigned int low
, high
;
3115 /* Default bounds to an array with unspecified length. */
3118 if (cu_language
== language_fortran
)
3120 /* FORTRAN implies a lower bound of 1, if not given. */
3124 index_type
= die_type (child_die
, cu
);
3125 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
3128 if (attr
->form
== DW_FORM_sdata
)
3130 low
= DW_SND (attr
);
3132 else if (attr
->form
== DW_FORM_udata
3133 || attr
->form
== DW_FORM_data1
3134 || attr
->form
== DW_FORM_data2
3135 || attr
->form
== DW_FORM_data4
3136 || attr
->form
== DW_FORM_data8
)
3138 low
= DW_UNSND (attr
);
3142 dwarf2_non_const_array_bound_ignored_complaint
3143 (dwarf_form_name (attr
->form
));
3145 die
->type
= lookup_pointer_type (element_type
);
3152 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
3155 if (attr
->form
== DW_FORM_sdata
)
3157 high
= DW_SND (attr
);
3159 else if (attr
->form
== DW_FORM_udata
3160 || attr
->form
== DW_FORM_data1
3161 || attr
->form
== DW_FORM_data2
3162 || attr
->form
== DW_FORM_data4
3163 || attr
->form
== DW_FORM_data8
)
3165 high
= DW_UNSND (attr
);
3167 else if (attr
->form
== DW_FORM_block1
)
3169 /* GCC encodes arrays with unspecified or dynamic length
3170 with a DW_FORM_block1 attribute.
3171 FIXME: GDB does not yet know how to handle dynamic
3172 arrays properly, treat them as arrays with unspecified
3175 FIXME: jimb/2003-09-22: GDB does not really know
3176 how to handle arrays of unspecified length
3177 either; we just represent them as zero-length
3178 arrays. Choose an appropriate upper bound given
3179 the lower bound we've computed above. */
3184 dwarf2_non_const_array_bound_ignored_complaint
3185 (dwarf_form_name (attr
->form
));
3187 die
->type
= lookup_pointer_type (element_type
);
3195 /* Create a range type and save it for array type creation. */
3196 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
3198 range_types
= (struct type
**)
3199 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
3200 * sizeof (struct type
*));
3202 make_cleanup (free_current_contents
, &range_types
);
3204 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
3206 child_die
= sibling_die (child_die
);
3209 /* Dwarf2 dimensions are output from left to right, create the
3210 necessary array types in backwards order. */
3211 type
= element_type
;
3213 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
3215 /* Understand Dwarf2 support for vector types (like they occur on
3216 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3217 array type. This is not part of the Dwarf2/3 standard yet, but a
3218 custom vendor extension. The main difference between a regular
3219 array and the vector variant is that vectors are passed by value
3221 attr
= dwarf_attr (die
, DW_AT_GNU_vector
);
3223 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
3225 do_cleanups (back_to
);
3227 /* Install the type in the die. */
3231 /* First cut: install each common block member as a global variable. */
3234 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
3236 struct die_info
*child_die
;
3237 struct attribute
*attr
;
3239 CORE_ADDR base
= (CORE_ADDR
) 0;
3241 attr
= dwarf_attr (die
, DW_AT_location
);
3244 /* Support the .debug_loc offsets */
3245 if (attr_form_is_block (attr
))
3247 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
3249 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3251 dwarf2_complex_location_expr_complaint ();
3255 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3256 "common block member");
3259 if (die
->child
!= NULL
)
3261 child_die
= die
->child
;
3262 while (child_die
&& child_die
->tag
)
3264 sym
= new_symbol (child_die
, NULL
, cu
);
3265 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
3268 SYMBOL_VALUE_ADDRESS (sym
) =
3269 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
3270 add_symbol_to_list (sym
, &global_symbols
);
3272 child_die
= sibling_die (child_die
);
3277 /* Read a C++ namespace. */
3280 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
3282 struct objfile
*objfile
= cu
->objfile
;
3283 const char *previous_namespace
= processing_current_namespace
;
3284 const char *name
= NULL
;
3286 struct die_info
*current_die
;
3288 /* Loop through the extensions until we find a name. */
3290 for (current_die
= die
;
3291 current_die
!= NULL
;
3292 current_die
= dwarf2_extension (die
))
3294 name
= dwarf2_name (current_die
);
3299 /* Is it an anonymous namespace? */
3301 is_anonymous
= (name
== NULL
);
3303 name
= "(anonymous namespace)";
3305 /* Now build the name of the current namespace. */
3307 if (previous_namespace
[0] == '\0')
3309 processing_current_namespace
= name
;
3313 /* We need temp_name around because processing_current_namespace
3314 is a const char *. */
3315 char *temp_name
= alloca (strlen (previous_namespace
)
3316 + 2 + strlen(name
) + 1);
3317 strcpy (temp_name
, previous_namespace
);
3318 strcat (temp_name
, "::");
3319 strcat (temp_name
, name
);
3321 processing_current_namespace
= temp_name
;
3324 /* Add a symbol associated to this if we haven't seen the namespace
3325 before. Also, add a using directive if it's an anonymous
3328 if (dwarf2_extension (die
) == NULL
)
3332 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
3333 this cast will hopefully become unnecessary. */
3334 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
3335 (char *) processing_current_namespace
,
3337 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
3339 new_symbol (die
, type
, cu
);
3342 cp_add_using_directive (processing_current_namespace
,
3343 strlen (previous_namespace
),
3344 strlen (processing_current_namespace
));
3347 if (die
->child
!= NULL
)
3349 struct die_info
*child_die
= die
->child
;
3351 while (child_die
&& child_die
->tag
)
3353 process_die (child_die
, cu
);
3354 child_die
= sibling_die (child_die
);
3358 processing_current_namespace
= previous_namespace
;
3361 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3362 the user defined type vector. */
3365 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3367 struct comp_unit_head
*cu_header
= &cu
->header
;
3369 struct attribute
*attr_byte_size
;
3370 struct attribute
*attr_address_class
;
3371 int byte_size
, addr_class
;
3378 type
= lookup_pointer_type (die_type (die
, cu
));
3380 attr_byte_size
= dwarf_attr (die
, DW_AT_byte_size
);
3382 byte_size
= DW_UNSND (attr_byte_size
);
3384 byte_size
= cu_header
->addr_size
;
3386 attr_address_class
= dwarf_attr (die
, DW_AT_address_class
);
3387 if (attr_address_class
)
3388 addr_class
= DW_UNSND (attr_address_class
);
3390 addr_class
= DW_ADDR_none
;
3392 /* If the pointer size or address class is different than the
3393 default, create a type variant marked as such and set the
3394 length accordingly. */
3395 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
3397 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3401 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
3402 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
3403 type
= make_type_with_address_space (type
, type_flags
);
3405 else if (TYPE_LENGTH (type
) != byte_size
)
3407 complaint (&symfile_complaints
, "invalid pointer size %d", byte_size
);
3410 /* Should we also complain about unhandled address classes? */
3414 TYPE_LENGTH (type
) = byte_size
;
3418 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3419 the user defined type vector. */
3422 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3424 struct objfile
*objfile
= cu
->objfile
;
3426 struct type
*to_type
;
3427 struct type
*domain
;
3434 type
= alloc_type (objfile
);
3435 to_type
= die_type (die
, cu
);
3436 domain
= die_containing_type (die
, cu
);
3437 smash_to_member_type (type
, domain
, to_type
);
3442 /* Extract all information from a DW_TAG_reference_type DIE and add to
3443 the user defined type vector. */
3446 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3448 struct comp_unit_head
*cu_header
= &cu
->header
;
3450 struct attribute
*attr
;
3457 type
= lookup_reference_type (die_type (die
, cu
));
3458 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3461 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3465 TYPE_LENGTH (type
) = cu_header
->addr_size
;
3471 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3473 struct type
*base_type
;
3480 base_type
= die_type (die
, cu
);
3481 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
3485 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3487 struct type
*base_type
;
3494 base_type
= die_type (die
, cu
);
3495 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
3498 /* Extract all information from a DW_TAG_string_type DIE and add to
3499 the user defined type vector. It isn't really a user defined type,
3500 but it behaves like one, with other DIE's using an AT_user_def_type
3501 attribute to reference it. */
3504 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3506 struct objfile
*objfile
= cu
->objfile
;
3507 struct type
*type
, *range_type
, *index_type
, *char_type
;
3508 struct attribute
*attr
;
3509 unsigned int length
;
3516 attr
= dwarf_attr (die
, DW_AT_string_length
);
3519 length
= DW_UNSND (attr
);
3523 /* check for the DW_AT_byte_size attribute */
3524 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3527 length
= DW_UNSND (attr
);
3534 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
3535 range_type
= create_range_type (NULL
, index_type
, 1, length
);
3536 if (cu_language
== language_fortran
)
3538 /* Need to create a unique string type for bounds
3540 type
= create_string_type (0, range_type
);
3544 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
3545 type
= create_string_type (char_type
, range_type
);
3550 /* Handle DIES due to C code like:
3554 int (*funcp)(int a, long l);
3558 ('funcp' generates a DW_TAG_subroutine_type DIE)
3562 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3564 struct type
*type
; /* Type that this function returns */
3565 struct type
*ftype
; /* Function that returns above type */
3566 struct attribute
*attr
;
3568 /* Decode the type that this subroutine returns */
3573 type
= die_type (die
, cu
);
3574 ftype
= lookup_function_type (type
);
3576 /* All functions in C++ have prototypes. */
3577 attr
= dwarf_attr (die
, DW_AT_prototyped
);
3578 if ((attr
&& (DW_UNSND (attr
) != 0))
3579 || cu_language
== language_cplus
)
3580 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
3582 if (die
->child
!= NULL
)
3584 struct die_info
*child_die
;
3588 /* Count the number of parameters.
3589 FIXME: GDB currently ignores vararg functions, but knows about
3590 vararg member functions. */
3591 child_die
= die
->child
;
3592 while (child_die
&& child_die
->tag
)
3594 if (child_die
->tag
== DW_TAG_formal_parameter
)
3596 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
3597 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
3598 child_die
= sibling_die (child_die
);
3601 /* Allocate storage for parameters and fill them in. */
3602 TYPE_NFIELDS (ftype
) = nparams
;
3603 TYPE_FIELDS (ftype
) = (struct field
*)
3604 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
3606 child_die
= die
->child
;
3607 while (child_die
&& child_die
->tag
)
3609 if (child_die
->tag
== DW_TAG_formal_parameter
)
3611 /* Dwarf2 has no clean way to discern C++ static and non-static
3612 member functions. G++ helps GDB by marking the first
3613 parameter for non-static member functions (which is the
3614 this pointer) as artificial. We pass this information
3615 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
3616 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
3618 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
3620 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
3621 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
3624 child_die
= sibling_die (child_die
);
3632 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
3634 struct objfile
*objfile
= cu
->objfile
;
3635 struct attribute
*attr
;
3640 attr
= dwarf_attr (die
, DW_AT_name
);
3641 if (attr
&& DW_STRING (attr
))
3643 name
= DW_STRING (attr
);
3645 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
3646 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, cu
);
3650 /* Find a representation of a given base type and install
3651 it in the TYPE field of the die. */
3654 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3656 struct objfile
*objfile
= cu
->objfile
;
3658 struct attribute
*attr
;
3659 int encoding
= 0, size
= 0;
3661 /* If we've already decoded this die, this is a no-op. */
3667 attr
= dwarf_attr (die
, DW_AT_encoding
);
3670 encoding
= DW_UNSND (attr
);
3672 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3675 size
= DW_UNSND (attr
);
3677 attr
= dwarf_attr (die
, DW_AT_name
);
3678 if (attr
&& DW_STRING (attr
))
3680 enum type_code code
= TYPE_CODE_INT
;
3685 case DW_ATE_address
:
3686 /* Turn DW_ATE_address into a void * pointer. */
3687 code
= TYPE_CODE_PTR
;
3688 type_flags
|= TYPE_FLAG_UNSIGNED
;
3690 case DW_ATE_boolean
:
3691 code
= TYPE_CODE_BOOL
;
3692 type_flags
|= TYPE_FLAG_UNSIGNED
;
3694 case DW_ATE_complex_float
:
3695 code
= TYPE_CODE_COMPLEX
;
3698 code
= TYPE_CODE_FLT
;
3701 case DW_ATE_signed_char
:
3703 case DW_ATE_unsigned
:
3704 case DW_ATE_unsigned_char
:
3705 type_flags
|= TYPE_FLAG_UNSIGNED
;
3708 complaint (&symfile_complaints
, "unsupported DW_AT_encoding: '%s'",
3709 dwarf_type_encoding_name (encoding
));
3712 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
3713 if (encoding
== DW_ATE_address
)
3714 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
3715 else if (encoding
== DW_ATE_complex_float
)
3718 TYPE_TARGET_TYPE (type
)
3719 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
3720 else if (size
== 16)
3721 TYPE_TARGET_TYPE (type
)
3722 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
3724 TYPE_TARGET_TYPE (type
)
3725 = dwarf2_fundamental_type (objfile
, FT_FLOAT
);
3730 type
= dwarf_base_type (encoding
, size
, cu
);
3735 /* Read a whole compilation unit into a linked list of dies. */
3737 static struct die_info
*
3738 read_comp_unit (char *info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
3740 /* Reset die reference table; we are
3741 building new ones now. */
3742 dwarf2_empty_hash_tables ();
3744 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
3747 /* Read a single die and all its descendents. Set the die's sibling
3748 field to NULL; set other fields in the die correctly, and set all
3749 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
3750 location of the info_ptr after reading all of those dies. PARENT
3751 is the parent of the die in question. */
3753 static struct die_info
*
3754 read_die_and_children (char *info_ptr
, bfd
*abfd
,
3755 struct dwarf2_cu
*cu
,
3756 char **new_info_ptr
,
3757 struct die_info
*parent
)
3759 struct die_info
*die
;
3763 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
3764 store_in_ref_table (die
->offset
, die
);
3768 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
3774 *new_info_ptr
= cur_ptr
;
3777 die
->sibling
= NULL
;
3778 die
->parent
= parent
;
3782 /* Read a die, all of its descendents, and all of its siblings; set
3783 all of the fields of all of the dies correctly. Arguments are as
3784 in read_die_and_children. */
3786 static struct die_info
*
3787 read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
3788 struct dwarf2_cu
*cu
,
3789 char **new_info_ptr
,
3790 struct die_info
*parent
)
3792 struct die_info
*first_die
, *last_sibling
;
3796 first_die
= last_sibling
= NULL
;
3800 struct die_info
*die
3801 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
3809 last_sibling
->sibling
= die
;
3814 *new_info_ptr
= cur_ptr
;
3824 /* Free a linked list of dies. */
3827 free_die_list (struct die_info
*dies
)
3829 struct die_info
*die
, *next
;
3834 if (die
->child
!= NULL
)
3835 free_die_list (die
->child
);
3836 next
= die
->sibling
;
3844 do_free_die_list_cleanup (void *dies
)
3846 free_die_list (dies
);
3849 static struct cleanup
*
3850 make_cleanup_free_die_list (struct die_info
*dies
)
3852 return make_cleanup (do_free_die_list_cleanup
, dies
);
3856 /* Read the contents of the section at OFFSET and of size SIZE from the
3857 object file specified by OBJFILE into the psymbol_obstack and return it. */
3860 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
3861 unsigned int size
, asection
*sectp
)
3863 bfd
*abfd
= objfile
->obfd
;
3869 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3871 = (char *) symfile_relocate_debug_section (abfd
, sectp
, (bfd_byte
*) buf
);
3875 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
3876 (bfd_bread (buf
, size
, abfd
) != size
))
3879 error ("Dwarf Error: Can't read DWARF data from '%s'",
3880 bfd_get_filename (abfd
));
3885 /* In DWARF version 2, the description of the debugging information is
3886 stored in a separate .debug_abbrev section. Before we read any
3887 dies from a section we read in all abbreviations and install them
3891 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
3893 struct comp_unit_head
*cu_header
= &cu
->header
;
3895 struct abbrev_info
*cur_abbrev
;
3896 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3897 unsigned int abbrev_form
, hash_number
;
3899 /* Initialize dwarf2 abbrevs */
3900 memset (cu_header
->dwarf2_abbrevs
, 0,
3901 ABBREV_HASH_SIZE
*sizeof (struct abbrev_info
*));
3903 abbrev_ptr
= dwarf_abbrev_buffer
+ cu_header
->abbrev_offset
;
3904 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3905 abbrev_ptr
+= bytes_read
;
3907 /* loop until we reach an abbrev number of 0 */
3908 while (abbrev_number
)
3910 cur_abbrev
= dwarf_alloc_abbrev ();
3912 /* read in abbrev header */
3913 cur_abbrev
->number
= abbrev_number
;
3914 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3915 abbrev_ptr
+= bytes_read
;
3916 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3919 /* now read in declarations */
3920 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3921 abbrev_ptr
+= bytes_read
;
3922 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3923 abbrev_ptr
+= bytes_read
;
3926 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3928 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3929 xrealloc (cur_abbrev
->attrs
,
3930 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3931 * sizeof (struct attr_abbrev
));
3933 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3934 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3935 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3936 abbrev_ptr
+= bytes_read
;
3937 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3938 abbrev_ptr
+= bytes_read
;
3941 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3942 cur_abbrev
->next
= cu_header
->dwarf2_abbrevs
[hash_number
];
3943 cu_header
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3945 /* Get next abbreviation.
3946 Under Irix6 the abbreviations for a compilation unit are not
3947 always properly terminated with an abbrev number of 0.
3948 Exit loop if we encounter an abbreviation which we have
3949 already read (which means we are about to read the abbreviations
3950 for the next compile unit) or if the end of the abbreviation
3951 table is reached. */
3952 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3953 >= dwarf_abbrev_size
)
3955 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3956 abbrev_ptr
+= bytes_read
;
3957 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
3962 /* Empty the abbrev table for a new compilation unit. */
3965 dwarf2_empty_abbrev_table (void *ptr_to_abbrevs_table
)
3968 struct abbrev_info
*abbrev
, *next
;
3969 struct abbrev_info
**abbrevs
;
3971 abbrevs
= (struct abbrev_info
**)ptr_to_abbrevs_table
;
3973 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3976 abbrev
= abbrevs
[i
];
3979 next
= abbrev
->next
;
3980 xfree (abbrev
->attrs
);
3988 /* Lookup an abbrev_info structure in the abbrev hash table. */
3990 static struct abbrev_info
*
3991 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
3993 struct comp_unit_head
*cu_header
= &cu
->header
;
3994 unsigned int hash_number
;
3995 struct abbrev_info
*abbrev
;
3997 hash_number
= number
% ABBREV_HASH_SIZE
;
3998 abbrev
= cu_header
->dwarf2_abbrevs
[hash_number
];
4002 if (abbrev
->number
== number
)
4005 abbrev
= abbrev
->next
;
4010 /* Read a minimal amount of information into the minimal die structure. */
4013 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
4014 char *info_ptr
, struct dwarf2_cu
*cu
)
4016 unsigned int abbrev_number
, bytes_read
, i
;
4017 struct abbrev_info
*abbrev
;
4018 struct attribute attr
;
4019 struct attribute spec_attr
;
4020 int found_spec_attr
= 0;
4021 int has_low_pc_attr
= 0;
4022 int has_high_pc_attr
= 0;
4024 *part_die
= zeroed_partial_die
;
4025 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4026 info_ptr
+= bytes_read
;
4030 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4033 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number
,
4034 bfd_get_filename (abfd
));
4036 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
4037 part_die
->tag
= abbrev
->tag
;
4038 part_die
->has_children
= abbrev
->has_children
;
4039 part_die
->abbrev
= abbrev_number
;
4041 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4043 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
4045 /* Store the data if it is of an attribute we want to keep in a
4046 partial symbol table. */
4051 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
4052 if (part_die
->name
== NULL
)
4053 part_die
->name
= DW_STRING (&attr
);
4055 case DW_AT_MIPS_linkage_name
:
4056 part_die
->name
= DW_STRING (&attr
);
4059 has_low_pc_attr
= 1;
4060 part_die
->lowpc
= DW_ADDR (&attr
);
4063 has_high_pc_attr
= 1;
4064 part_die
->highpc
= DW_ADDR (&attr
);
4066 case DW_AT_location
:
4067 /* Support the .debug_loc offsets */
4068 if (attr_form_is_block (&attr
))
4070 part_die
->locdesc
= DW_BLOCK (&attr
);
4072 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
4074 dwarf2_complex_location_expr_complaint ();
4078 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4079 "partial symbol information");
4082 case DW_AT_language
:
4083 part_die
->language
= DW_UNSND (&attr
);
4085 case DW_AT_external
:
4086 part_die
->is_external
= DW_UNSND (&attr
);
4088 case DW_AT_declaration
:
4089 part_die
->is_declaration
= DW_UNSND (&attr
);
4092 part_die
->has_type
= 1;
4094 case DW_AT_abstract_origin
:
4095 case DW_AT_specification
:
4096 found_spec_attr
= 1;
4100 /* Ignore absolute siblings, they might point outside of
4101 the current compile unit. */
4102 if (attr
.form
== DW_FORM_ref_addr
)
4103 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
4106 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
4113 /* If we found a reference attribute and the die has no name, try
4114 to find a name in the referred to die. */
4116 if (found_spec_attr
&& part_die
->name
== NULL
)
4118 struct partial_die_info spec_die
;
4121 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
4122 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu
);
4125 part_die
->name
= spec_die
.name
;
4127 /* Copy DW_AT_external attribute if it is set. */
4128 if (spec_die
.is_external
)
4129 part_die
->is_external
= spec_die
.is_external
;
4133 /* When using the GNU linker, .gnu.linkonce. sections are used to
4134 eliminate duplicate copies of functions and vtables and such.
4135 The linker will arbitrarily choose one and discard the others.
4136 The AT_*_pc values for such functions refer to local labels in
4137 these sections. If the section from that file was discarded, the
4138 labels are not in the output, so the relocs get a value of 0.
4139 If this is a discarded function, mark the pc bounds as invalid,
4140 so that GDB will ignore it. */
4141 if (has_low_pc_attr
&& has_high_pc_attr
4142 && part_die
->lowpc
< part_die
->highpc
4143 && (part_die
->lowpc
!= 0
4144 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
4145 part_die
->has_pc_info
= 1;
4149 /* Read the die from the .debug_info section buffer. Set DIEP to
4150 point to a newly allocated die with its information, except for its
4151 child, sibling, and parent fields. Set HAS_CHILDREN to tell
4152 whether the die has children or not. */
4155 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
4156 struct dwarf2_cu
*cu
, int *has_children
)
4158 unsigned int abbrev_number
, bytes_read
, i
, offset
;
4159 struct abbrev_info
*abbrev
;
4160 struct die_info
*die
;
4162 offset
= info_ptr
- dwarf_info_buffer
;
4163 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4164 info_ptr
+= bytes_read
;
4167 die
= dwarf_alloc_die ();
4169 die
->abbrev
= abbrev_number
;
4176 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4179 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
4181 bfd_get_filename (abfd
));
4183 die
= dwarf_alloc_die ();
4184 die
->offset
= offset
;
4185 die
->tag
= abbrev
->tag
;
4186 die
->abbrev
= abbrev_number
;
4189 die
->num_attrs
= abbrev
->num_attrs
;
4190 die
->attrs
= (struct attribute
*)
4191 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
4193 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4195 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
4196 abfd
, info_ptr
, cu
);
4200 *has_children
= abbrev
->has_children
;
4204 /* Read an attribute value described by an attribute form. */
4207 read_attribute_value (struct attribute
*attr
, unsigned form
,
4208 bfd
*abfd
, char *info_ptr
,
4209 struct dwarf2_cu
*cu
)
4211 struct comp_unit_head
*cu_header
= &cu
->header
;
4212 unsigned int bytes_read
;
4213 struct dwarf_block
*blk
;
4219 case DW_FORM_ref_addr
:
4220 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
4221 info_ptr
+= bytes_read
;
4223 case DW_FORM_block2
:
4224 blk
= dwarf_alloc_block ();
4225 blk
->size
= read_2_bytes (abfd
, info_ptr
);
4227 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4228 info_ptr
+= blk
->size
;
4229 DW_BLOCK (attr
) = blk
;
4231 case DW_FORM_block4
:
4232 blk
= dwarf_alloc_block ();
4233 blk
->size
= read_4_bytes (abfd
, info_ptr
);
4235 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4236 info_ptr
+= blk
->size
;
4237 DW_BLOCK (attr
) = blk
;
4240 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4244 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4248 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4251 case DW_FORM_string
:
4252 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
4253 info_ptr
+= bytes_read
;
4256 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
4258 info_ptr
+= bytes_read
;
4261 blk
= dwarf_alloc_block ();
4262 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4263 info_ptr
+= bytes_read
;
4264 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4265 info_ptr
+= blk
->size
;
4266 DW_BLOCK (attr
) = blk
;
4268 case DW_FORM_block1
:
4269 blk
= dwarf_alloc_block ();
4270 blk
->size
= read_1_byte (abfd
, info_ptr
);
4272 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4273 info_ptr
+= blk
->size
;
4274 DW_BLOCK (attr
) = blk
;
4277 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4281 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4285 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
4286 info_ptr
+= bytes_read
;
4289 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4290 info_ptr
+= bytes_read
;
4293 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4297 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4301 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4305 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4308 case DW_FORM_ref_udata
:
4309 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4310 info_ptr
+= bytes_read
;
4312 case DW_FORM_indirect
:
4313 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4314 info_ptr
+= bytes_read
;
4315 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
4318 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
4319 dwarf_form_name (form
),
4320 bfd_get_filename (abfd
));
4325 /* Read an attribute described by an abbreviated attribute. */
4328 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
4329 bfd
*abfd
, char *info_ptr
, struct dwarf2_cu
*cu
)
4331 attr
->name
= abbrev
->name
;
4332 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
4335 /* read dwarf information from a buffer */
4338 read_1_byte (bfd
*abfd
, char *buf
)
4340 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4344 read_1_signed_byte (bfd
*abfd
, char *buf
)
4346 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
4350 read_2_bytes (bfd
*abfd
, char *buf
)
4352 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4356 read_2_signed_bytes (bfd
*abfd
, char *buf
)
4358 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4362 read_4_bytes (bfd
*abfd
, char *buf
)
4364 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4368 read_4_signed_bytes (bfd
*abfd
, char *buf
)
4370 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4373 static unsigned long
4374 read_8_bytes (bfd
*abfd
, char *buf
)
4376 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4380 read_address (bfd
*abfd
, char *buf
, struct dwarf2_cu
*cu
, int *bytes_read
)
4382 struct comp_unit_head
*cu_header
= &cu
->header
;
4383 CORE_ADDR retval
= 0;
4385 if (cu_header
->signed_addr_p
)
4387 switch (cu_header
->addr_size
)
4390 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4393 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4396 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
4399 internal_error (__FILE__
, __LINE__
,
4400 "read_address: bad switch, signed [in module %s]",
4401 bfd_get_filename (abfd
));
4406 switch (cu_header
->addr_size
)
4409 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4412 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4415 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4418 internal_error (__FILE__
, __LINE__
,
4419 "read_address: bad switch, unsigned [in module %s]",
4420 bfd_get_filename (abfd
));
4424 *bytes_read
= cu_header
->addr_size
;
4428 /* Read the initial length from a section. The (draft) DWARF 3
4429 specification allows the initial length to take up either 4 bytes
4430 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
4431 bytes describe the length and all offsets will be 8 bytes in length
4434 An older, non-standard 64-bit format is also handled by this
4435 function. The older format in question stores the initial length
4436 as an 8-byte quantity without an escape value. Lengths greater
4437 than 2^32 aren't very common which means that the initial 4 bytes
4438 is almost always zero. Since a length value of zero doesn't make
4439 sense for the 32-bit format, this initial zero can be considered to
4440 be an escape value which indicates the presence of the older 64-bit
4441 format. As written, the code can't detect (old format) lengths
4442 greater than 4GB. If it becomes necessary to handle lengths somewhat
4443 larger than 4GB, we could allow other small values (such as the
4444 non-sensical values of 1, 2, and 3) to also be used as escape values
4445 indicating the presence of the old format.
4447 The value returned via bytes_read should be used to increment
4448 the relevant pointer after calling read_initial_length().
4450 As a side effect, this function sets the fields initial_length_size
4451 and offset_size in cu_header to the values appropriate for the
4452 length field. (The format of the initial length field determines
4453 the width of file offsets to be fetched later with fetch_offset().)
4455 [ Note: read_initial_length() and read_offset() are based on the
4456 document entitled "DWARF Debugging Information Format", revision
4457 3, draft 8, dated November 19, 2001. This document was obtained
4460 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
4462 This document is only a draft and is subject to change. (So beware.)
4464 Details regarding the older, non-standard 64-bit format were
4465 determined empirically by examining 64-bit ELF files produced
4466 by the SGI toolchain on an IRIX 6.5 machine.
4468 - Kevin, July 16, 2002
4472 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
4477 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4479 if (retval
== 0xffffffff)
4481 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
4483 if (cu_header
!= NULL
)
4485 cu_header
->initial_length_size
= 12;
4486 cu_header
->offset_size
= 8;
4489 else if (retval
== 0)
4491 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
4493 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4495 if (cu_header
!= NULL
)
4497 cu_header
->initial_length_size
= 8;
4498 cu_header
->offset_size
= 8;
4504 if (cu_header
!= NULL
)
4506 cu_header
->initial_length_size
= 4;
4507 cu_header
->offset_size
= 4;
4514 /* Read an offset from the data stream. The size of the offset is
4515 given by cu_header->offset_size. */
4518 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
4523 switch (cu_header
->offset_size
)
4526 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4530 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4534 internal_error (__FILE__
, __LINE__
,
4535 "read_offset: bad switch [in module %s]",
4536 bfd_get_filename (abfd
));
4543 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
4545 /* If the size of a host char is 8 bits, we can return a pointer
4546 to the buffer, otherwise we have to copy the data to a buffer
4547 allocated on the temporary obstack. */
4548 gdb_assert (HOST_CHAR_BIT
== 8);
4553 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4555 /* If the size of a host char is 8 bits, we can return a pointer
4556 to the string, otherwise we have to copy the string to a buffer
4557 allocated on the temporary obstack. */
4558 gdb_assert (HOST_CHAR_BIT
== 8);
4561 *bytes_read_ptr
= 1;
4564 *bytes_read_ptr
= strlen (buf
) + 1;
4569 read_indirect_string (bfd
*abfd
, char *buf
,
4570 const struct comp_unit_head
*cu_header
,
4571 unsigned int *bytes_read_ptr
)
4573 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
4574 (int *) bytes_read_ptr
);
4576 if (dwarf_str_buffer
== NULL
)
4578 error ("DW_FORM_strp used without .debug_str section [in module %s]",
4579 bfd_get_filename (abfd
));
4582 if (str_offset
>= dwarf_str_size
)
4584 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
4585 bfd_get_filename (abfd
));
4588 gdb_assert (HOST_CHAR_BIT
== 8);
4589 if (dwarf_str_buffer
[str_offset
] == '\0')
4591 return dwarf_str_buffer
+ str_offset
;
4594 static unsigned long
4595 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4597 unsigned long result
;
4598 unsigned int num_read
;
4608 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4611 result
|= ((unsigned long)(byte
& 127) << shift
);
4612 if ((byte
& 128) == 0)
4618 *bytes_read_ptr
= num_read
;
4623 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4626 int i
, shift
, size
, num_read
;
4636 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4639 result
|= ((long)(byte
& 127) << shift
);
4641 if ((byte
& 128) == 0)
4646 if ((shift
< size
) && (byte
& 0x40))
4648 result
|= -(1 << shift
);
4650 *bytes_read_ptr
= num_read
;
4655 set_cu_language (unsigned int lang
)
4661 cu_language
= language_c
;
4663 case DW_LANG_C_plus_plus
:
4664 cu_language
= language_cplus
;
4666 case DW_LANG_Fortran77
:
4667 case DW_LANG_Fortran90
:
4668 case DW_LANG_Fortran95
:
4669 cu_language
= language_fortran
;
4671 case DW_LANG_Mips_Assembler
:
4672 cu_language
= language_asm
;
4675 cu_language
= language_java
;
4679 case DW_LANG_Cobol74
:
4680 case DW_LANG_Cobol85
:
4681 case DW_LANG_Pascal83
:
4682 case DW_LANG_Modula2
:
4684 cu_language
= language_minimal
;
4687 cu_language_defn
= language_def (cu_language
);
4690 /* Return the named attribute or NULL if not there. */
4692 static struct attribute
*
4693 dwarf_attr (struct die_info
*die
, unsigned int name
)
4696 struct attribute
*spec
= NULL
;
4698 for (i
= 0; i
< die
->num_attrs
; ++i
)
4700 if (die
->attrs
[i
].name
== name
)
4702 return &die
->attrs
[i
];
4704 if (die
->attrs
[i
].name
== DW_AT_specification
4705 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
4706 spec
= &die
->attrs
[i
];
4710 struct die_info
*ref_die
=
4711 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
4714 return dwarf_attr (ref_die
, name
);
4721 die_is_declaration (struct die_info
*die
)
4723 return (dwarf_attr (die
, DW_AT_declaration
)
4724 && ! dwarf_attr (die
, DW_AT_specification
));
4728 /* Free the line_header structure *LH, and any arrays and strings it
4731 free_line_header (struct line_header
*lh
)
4733 if (lh
->standard_opcode_lengths
)
4734 xfree (lh
->standard_opcode_lengths
);
4736 /* Remember that all the lh->file_names[i].name pointers are
4737 pointers into debug_line_buffer, and don't need to be freed. */
4739 xfree (lh
->file_names
);
4741 /* Similarly for the include directory names. */
4742 if (lh
->include_dirs
)
4743 xfree (lh
->include_dirs
);
4749 /* Add an entry to LH's include directory table. */
4751 add_include_dir (struct line_header
*lh
, char *include_dir
)
4753 /* Grow the array if necessary. */
4754 if (lh
->include_dirs_size
== 0)
4756 lh
->include_dirs_size
= 1; /* for testing */
4757 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
4758 * sizeof (*lh
->include_dirs
));
4760 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
4762 lh
->include_dirs_size
*= 2;
4763 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
4764 (lh
->include_dirs_size
4765 * sizeof (*lh
->include_dirs
)));
4768 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
4772 /* Add an entry to LH's file name table. */
4774 add_file_name (struct line_header
*lh
,
4776 unsigned int dir_index
,
4777 unsigned int mod_time
,
4778 unsigned int length
)
4780 struct file_entry
*fe
;
4782 /* Grow the array if necessary. */
4783 if (lh
->file_names_size
== 0)
4785 lh
->file_names_size
= 1; /* for testing */
4786 lh
->file_names
= xmalloc (lh
->file_names_size
4787 * sizeof (*lh
->file_names
));
4789 else if (lh
->num_file_names
>= lh
->file_names_size
)
4791 lh
->file_names_size
*= 2;
4792 lh
->file_names
= xrealloc (lh
->file_names
,
4793 (lh
->file_names_size
4794 * sizeof (*lh
->file_names
)));
4797 fe
= &lh
->file_names
[lh
->num_file_names
++];
4799 fe
->dir_index
= dir_index
;
4800 fe
->mod_time
= mod_time
;
4801 fe
->length
= length
;
4805 /* Read the statement program header starting at OFFSET in
4806 dwarf_line_buffer, according to the endianness of ABFD. Return a
4807 pointer to a struct line_header, allocated using xmalloc.
4809 NOTE: the strings in the include directory and file name tables of
4810 the returned object point into debug_line_buffer, and must not be
4812 static struct line_header
*
4813 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
4814 struct dwarf2_cu
*cu
)
4816 struct cleanup
*back_to
;
4817 struct line_header
*lh
;
4821 char *cur_dir
, *cur_file
;
4823 if (dwarf_line_buffer
== NULL
)
4825 complaint (&symfile_complaints
, "missing .debug_line section");
4829 /* Make sure that at least there's room for the total_length field. That
4830 could be 12 bytes long, but we're just going to fudge that. */
4831 if (offset
+ 4 >= dwarf_line_size
)
4833 dwarf2_statement_list_fits_in_line_number_section_complaint ();
4837 lh
= xmalloc (sizeof (*lh
));
4838 memset (lh
, 0, sizeof (*lh
));
4839 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
4842 line_ptr
= dwarf_line_buffer
+ offset
;
4844 /* read in the header */
4845 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
4846 line_ptr
+= bytes_read
;
4847 if (line_ptr
+ lh
->total_length
> dwarf_line_buffer
+ dwarf_line_size
)
4849 dwarf2_statement_list_fits_in_line_number_section_complaint ();
4852 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
4853 lh
->version
= read_2_bytes (abfd
, line_ptr
);
4855 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
4856 line_ptr
+= bytes_read
;
4857 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
4859 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
4861 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
4863 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
4865 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
4867 lh
->standard_opcode_lengths
4868 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
4870 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
4871 for (i
= 1; i
< lh
->opcode_base
; ++i
)
4873 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
4877 /* Read directory table */
4878 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4880 line_ptr
+= bytes_read
;
4881 add_include_dir (lh
, cur_dir
);
4883 line_ptr
+= bytes_read
;
4885 /* Read file name table */
4886 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4888 unsigned int dir_index
, mod_time
, length
;
4890 line_ptr
+= bytes_read
;
4891 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4892 line_ptr
+= bytes_read
;
4893 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4894 line_ptr
+= bytes_read
;
4895 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4896 line_ptr
+= bytes_read
;
4898 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4900 line_ptr
+= bytes_read
;
4901 lh
->statement_program_start
= line_ptr
;
4903 if (line_ptr
> dwarf_line_buffer
+ dwarf_line_size
)
4904 complaint (&symfile_complaints
,
4905 "line number info header doesn't fit in `.debug_line' section");
4907 discard_cleanups (back_to
);
4911 /* This function exists to work around a bug in certain compilers
4912 (particularly GCC 2.95), in which the first line number marker of a
4913 function does not show up until after the prologue, right before
4914 the second line number marker. This function shifts ADDRESS down
4915 to the beginning of the function if necessary, and is called on
4916 addresses passed to record_line. */
4919 check_cu_functions (CORE_ADDR address
)
4921 struct function_range
*fn
;
4923 /* Find the function_range containing address. */
4928 cu_cached_fn
= cu_first_fn
;
4932 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4938 while (fn
&& fn
!= cu_cached_fn
)
4939 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4949 if (address
!= fn
->lowpc
)
4950 complaint (&symfile_complaints
,
4951 "misplaced first line number at 0x%lx for '%s'",
4952 (unsigned long) address
, fn
->name
);
4957 /* Decode the line number information for the compilation unit whose
4958 line number info is at OFFSET in the .debug_line section.
4959 The compilation directory of the file is passed in COMP_DIR. */
4962 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
4963 struct dwarf2_cu
*cu
)
4967 unsigned int bytes_read
;
4968 unsigned char op_code
, extended_op
, adj_opcode
;
4970 line_ptr
= lh
->statement_program_start
;
4971 line_end
= lh
->statement_program_end
;
4973 /* Read the statement sequences until there's nothing left. */
4974 while (line_ptr
< line_end
)
4976 /* state machine registers */
4977 CORE_ADDR address
= 0;
4978 unsigned int file
= 1;
4979 unsigned int line
= 1;
4980 unsigned int column
= 0;
4981 int is_stmt
= lh
->default_is_stmt
;
4982 int basic_block
= 0;
4983 int end_sequence
= 0;
4985 /* Start a subfile for the current file of the state machine. */
4986 if (lh
->num_file_names
>= file
)
4988 /* lh->include_dirs and lh->file_names are 0-based, but the
4989 directory and file name numbers in the statement program
4991 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
4994 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
4997 dwarf2_start_subfile (fe
->name
, dir
);
5000 /* Decode the table. */
5001 while (!end_sequence
)
5003 op_code
= read_1_byte (abfd
, line_ptr
);
5006 if (op_code
>= lh
->opcode_base
)
5007 { /* Special operand. */
5008 adj_opcode
= op_code
- lh
->opcode_base
;
5009 address
+= (adj_opcode
/ lh
->line_range
)
5010 * lh
->minimum_instruction_length
;
5011 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
5012 /* append row to matrix using current values */
5013 record_line (current_subfile
, line
,
5014 check_cu_functions (address
));
5017 else switch (op_code
)
5019 case DW_LNS_extended_op
:
5020 line_ptr
+= 1; /* ignore length */
5021 extended_op
= read_1_byte (abfd
, line_ptr
);
5023 switch (extended_op
)
5025 case DW_LNE_end_sequence
:
5027 record_line (current_subfile
, 0, address
);
5029 case DW_LNE_set_address
:
5030 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
5031 line_ptr
+= bytes_read
;
5032 address
+= baseaddr
;
5034 case DW_LNE_define_file
:
5037 unsigned int dir_index
, mod_time
, length
;
5039 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
5040 line_ptr
+= bytes_read
;
5042 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5043 line_ptr
+= bytes_read
;
5045 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5046 line_ptr
+= bytes_read
;
5048 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5049 line_ptr
+= bytes_read
;
5050 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
5054 complaint (&symfile_complaints
,
5055 "mangled .debug_line section");
5060 record_line (current_subfile
, line
,
5061 check_cu_functions (address
));
5064 case DW_LNS_advance_pc
:
5065 address
+= lh
->minimum_instruction_length
5066 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5067 line_ptr
+= bytes_read
;
5069 case DW_LNS_advance_line
:
5070 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
5071 line_ptr
+= bytes_read
;
5073 case DW_LNS_set_file
:
5075 /* lh->include_dirs and lh->file_names are 0-based,
5076 but the directory and file name numbers in the
5077 statement program are 1-based. */
5078 struct file_entry
*fe
;
5080 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5081 line_ptr
+= bytes_read
;
5082 fe
= &lh
->file_names
[file
- 1];
5084 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
5087 dwarf2_start_subfile (fe
->name
, dir
);
5090 case DW_LNS_set_column
:
5091 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5092 line_ptr
+= bytes_read
;
5094 case DW_LNS_negate_stmt
:
5095 is_stmt
= (!is_stmt
);
5097 case DW_LNS_set_basic_block
:
5100 /* Add to the address register of the state machine the
5101 address increment value corresponding to special opcode
5102 255. Ie, this value is scaled by the minimum instruction
5103 length since special opcode 255 would have scaled the
5105 case DW_LNS_const_add_pc
:
5106 address
+= (lh
->minimum_instruction_length
5107 * ((255 - lh
->opcode_base
) / lh
->line_range
));
5109 case DW_LNS_fixed_advance_pc
:
5110 address
+= read_2_bytes (abfd
, line_ptr
);
5114 { /* Unknown standard opcode, ignore it. */
5116 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
5118 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5119 line_ptr
+= bytes_read
;
5127 /* Start a subfile for DWARF. FILENAME is the name of the file and
5128 DIRNAME the name of the source directory which contains FILENAME
5129 or NULL if not known.
5130 This routine tries to keep line numbers from identical absolute and
5131 relative file names in a common subfile.
5133 Using the `list' example from the GDB testsuite, which resides in
5134 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
5135 of /srcdir/list0.c yields the following debugging information for list0.c:
5137 DW_AT_name: /srcdir/list0.c
5138 DW_AT_comp_dir: /compdir
5139 files.files[0].name: list0.h
5140 files.files[0].dir: /srcdir
5141 files.files[1].name: list0.c
5142 files.files[1].dir: /srcdir
5144 The line number information for list0.c has to end up in a single
5145 subfile, so that `break /srcdir/list0.c:1' works as expected. */
5148 dwarf2_start_subfile (char *filename
, char *dirname
)
5150 /* If the filename isn't absolute, try to match an existing subfile
5151 with the full pathname. */
5153 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
5155 struct subfile
*subfile
;
5156 char *fullname
= concat (dirname
, "/", filename
, NULL
);
5158 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
5160 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
5162 current_subfile
= subfile
;
5169 start_subfile (filename
, dirname
);
5173 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
5174 struct dwarf2_cu
*cu
)
5176 struct objfile
*objfile
= cu
->objfile
;
5177 struct comp_unit_head
*cu_header
= &cu
->header
;
5179 /* NOTE drow/2003-01-30: There used to be a comment and some special
5180 code here to turn a symbol with DW_AT_external and a
5181 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
5182 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
5183 with some versions of binutils) where shared libraries could have
5184 relocations against symbols in their debug information - the
5185 minimal symbol would have the right address, but the debug info
5186 would not. It's no longer necessary, because we will explicitly
5187 apply relocations when we read in the debug information now. */
5189 /* A DW_AT_location attribute with no contents indicates that a
5190 variable has been optimized away. */
5191 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
5193 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
5197 /* Handle one degenerate form of location expression specially, to
5198 preserve GDB's previous behavior when section offsets are
5199 specified. If this is just a DW_OP_addr then mark this symbol
5202 if (attr_form_is_block (attr
)
5203 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
5204 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
5208 SYMBOL_VALUE_ADDRESS (sym
) =
5209 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
5210 fixup_symbol_section (sym
, objfile
);
5211 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
5212 SYMBOL_SECTION (sym
));
5213 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5217 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
5218 expression evaluator, and use LOC_COMPUTED only when necessary
5219 (i.e. when the value of a register or memory location is
5220 referenced, or a thread-local block, etc.). Then again, it might
5221 not be worthwhile. I'm assuming that it isn't unless performance
5222 or memory numbers show me otherwise. */
5224 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
5225 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
5228 /* Given a pointer to a DWARF information entry, figure out if we need
5229 to make a symbol table entry for it, and if so, create a new entry
5230 and return a pointer to it.
5231 If TYPE is NULL, determine symbol type from the die, otherwise
5232 used the passed type. */
5234 static struct symbol
*
5235 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
5237 struct objfile
*objfile
= cu
->objfile
;
5238 struct symbol
*sym
= NULL
;
5240 struct attribute
*attr
= NULL
;
5241 struct attribute
*attr2
= NULL
;
5243 if (die
->tag
!= DW_TAG_namespace
)
5244 name
= dwarf2_linkage_name (die
);
5246 name
= TYPE_NAME (type
);
5250 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
5251 sizeof (struct symbol
));
5252 OBJSTAT (objfile
, n_syms
++);
5253 memset (sym
, 0, sizeof (struct symbol
));
5255 /* Cache this symbol's name and the name's demangled form (if any). */
5256 SYMBOL_LANGUAGE (sym
) = cu_language
;
5257 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
5259 /* Default assumptions.
5260 Use the passed type or decode it from the die. */
5261 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5262 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5264 SYMBOL_TYPE (sym
) = type
;
5266 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
5267 attr
= dwarf_attr (die
, DW_AT_decl_line
);
5270 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
5275 attr
= dwarf_attr (die
, DW_AT_low_pc
);
5278 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
5280 SYMBOL_CLASS (sym
) = LOC_LABEL
;
5282 case DW_TAG_subprogram
:
5283 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
5285 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
5286 attr2
= dwarf_attr (die
, DW_AT_external
);
5287 if (attr2
&& (DW_UNSND (attr2
) != 0))
5289 add_symbol_to_list (sym
, &global_symbols
);
5293 add_symbol_to_list (sym
, list_in_scope
);
5296 case DW_TAG_variable
:
5297 /* Compilation with minimal debug info may result in variables
5298 with missing type entries. Change the misleading `void' type
5299 to something sensible. */
5300 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
5301 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
5302 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
5303 "<variable, no debug info>",
5305 attr
= dwarf_attr (die
, DW_AT_const_value
);
5308 dwarf2_const_value (attr
, sym
, cu
);
5309 attr2
= dwarf_attr (die
, DW_AT_external
);
5310 if (attr2
&& (DW_UNSND (attr2
) != 0))
5311 add_symbol_to_list (sym
, &global_symbols
);
5313 add_symbol_to_list (sym
, list_in_scope
);
5316 attr
= dwarf_attr (die
, DW_AT_location
);
5319 var_decode_location (attr
, sym
, cu
);
5320 attr2
= dwarf_attr (die
, DW_AT_external
);
5321 if (attr2
&& (DW_UNSND (attr2
) != 0))
5322 add_symbol_to_list (sym
, &global_symbols
);
5324 add_symbol_to_list (sym
, list_in_scope
);
5328 /* We do not know the address of this symbol.
5329 If it is an external symbol and we have type information
5330 for it, enter the symbol as a LOC_UNRESOLVED symbol.
5331 The address of the variable will then be determined from
5332 the minimal symbol table whenever the variable is
5334 attr2
= dwarf_attr (die
, DW_AT_external
);
5335 if (attr2
&& (DW_UNSND (attr2
) != 0)
5336 && dwarf_attr (die
, DW_AT_type
) != NULL
)
5338 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
5339 add_symbol_to_list (sym
, &global_symbols
);
5343 case DW_TAG_formal_parameter
:
5344 attr
= dwarf_attr (die
, DW_AT_location
);
5347 var_decode_location (attr
, sym
, cu
);
5348 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
5349 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
5350 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
5352 attr
= dwarf_attr (die
, DW_AT_const_value
);
5355 dwarf2_const_value (attr
, sym
, cu
);
5357 add_symbol_to_list (sym
, list_in_scope
);
5359 case DW_TAG_unspecified_parameters
:
5360 /* From varargs functions; gdb doesn't seem to have any
5361 interest in this information, so just ignore it for now.
5364 case DW_TAG_class_type
:
5365 case DW_TAG_structure_type
:
5366 case DW_TAG_union_type
:
5367 case DW_TAG_enumeration_type
:
5368 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5369 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
5370 add_symbol_to_list (sym
, list_in_scope
);
5372 /* The semantics of C++ state that "struct foo { ... }" also
5373 defines a typedef for "foo". Synthesize a typedef symbol so
5374 that "ptype foo" works as expected. */
5375 if (cu_language
== language_cplus
)
5377 struct symbol
*typedef_sym
= (struct symbol
*)
5378 obstack_alloc (&objfile
->symbol_obstack
,
5379 sizeof (struct symbol
));
5380 *typedef_sym
= *sym
;
5381 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
5382 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
5383 TYPE_NAME (SYMBOL_TYPE (sym
)) =
5384 obsavestring (DEPRECATED_SYMBOL_NAME (sym
),
5385 strlen (DEPRECATED_SYMBOL_NAME (sym
)),
5386 &objfile
->type_obstack
);
5387 add_symbol_to_list (typedef_sym
, list_in_scope
);
5390 case DW_TAG_typedef
:
5391 case DW_TAG_base_type
:
5392 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5393 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5394 add_symbol_to_list (sym
, list_in_scope
);
5396 case DW_TAG_enumerator
:
5397 attr
= dwarf_attr (die
, DW_AT_const_value
);
5400 dwarf2_const_value (attr
, sym
, cu
);
5402 add_symbol_to_list (sym
, list_in_scope
);
5404 case DW_TAG_namespace
:
5405 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5406 add_symbol_to_list (sym
, &global_symbols
);
5409 /* Not a tag we recognize. Hopefully we aren't processing
5410 trash data, but since we must specifically ignore things
5411 we don't recognize, there is nothing else we should do at
5413 complaint (&symfile_complaints
, "unsupported tag: '%s'",
5414 dwarf_tag_name (die
->tag
));
5421 /* Copy constant value from an attribute to a symbol. */
5424 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
5425 struct dwarf2_cu
*cu
)
5427 struct objfile
*objfile
= cu
->objfile
;
5428 struct comp_unit_head
*cu_header
= &cu
->header
;
5429 struct dwarf_block
*blk
;
5434 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
5435 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5436 cu_header
->addr_size
,
5437 TYPE_LENGTH (SYMBOL_TYPE
5439 SYMBOL_VALUE_BYTES (sym
) = (char *)
5440 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
5441 /* NOTE: cagney/2003-05-09: In-lined store_address call with
5442 it's body - store_unsigned_integer. */
5443 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
5445 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5447 case DW_FORM_block1
:
5448 case DW_FORM_block2
:
5449 case DW_FORM_block4
:
5451 blk
= DW_BLOCK (attr
);
5452 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
5453 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5455 TYPE_LENGTH (SYMBOL_TYPE
5457 SYMBOL_VALUE_BYTES (sym
) = (char *)
5458 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
5459 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
5460 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5463 /* The DW_AT_const_value attributes are supposed to carry the
5464 symbol's value "represented as it would be on the target
5465 architecture." By the time we get here, it's already been
5466 converted to host endianness, so we just need to sign- or
5467 zero-extend it as appropriate. */
5469 dwarf2_const_value_data (attr
, sym
, 8);
5472 dwarf2_const_value_data (attr
, sym
, 16);
5475 dwarf2_const_value_data (attr
, sym
, 32);
5478 dwarf2_const_value_data (attr
, sym
, 64);
5482 SYMBOL_VALUE (sym
) = DW_SND (attr
);
5483 SYMBOL_CLASS (sym
) = LOC_CONST
;
5487 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
5488 SYMBOL_CLASS (sym
) = LOC_CONST
;
5492 complaint (&symfile_complaints
,
5493 "unsupported const value attribute form: '%s'",
5494 dwarf_form_name (attr
->form
));
5495 SYMBOL_VALUE (sym
) = 0;
5496 SYMBOL_CLASS (sym
) = LOC_CONST
;
5502 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
5503 or zero-extend it as appropriate for the symbol's type. */
5505 dwarf2_const_value_data (struct attribute
*attr
,
5509 LONGEST l
= DW_UNSND (attr
);
5511 if (bits
< sizeof (l
) * 8)
5513 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
5514 l
&= ((LONGEST
) 1 << bits
) - 1;
5516 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
5519 SYMBOL_VALUE (sym
) = l
;
5520 SYMBOL_CLASS (sym
) = LOC_CONST
;
5524 /* Return the type of the die in question using its DW_AT_type attribute. */
5526 static struct type
*
5527 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5530 struct attribute
*type_attr
;
5531 struct die_info
*type_die
;
5534 type_attr
= dwarf_attr (die
, DW_AT_type
);
5537 /* A missing DW_AT_type represents a void type. */
5538 return dwarf2_fundamental_type (cu
->objfile
, FT_VOID
);
5542 ref
= dwarf2_get_ref_die_offset (type_attr
);
5543 type_die
= follow_die_ref (ref
);
5546 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
5547 ref
, cu
->objfile
->name
);
5551 type
= tag_type_to_type (type_die
, cu
);
5554 dump_die (type_die
);
5555 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
5561 /* Return the containing type of the die in question using its
5562 DW_AT_containing_type attribute. */
5564 static struct type
*
5565 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5567 struct type
*type
= NULL
;
5568 struct attribute
*type_attr
;
5569 struct die_info
*type_die
= NULL
;
5572 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
5575 ref
= dwarf2_get_ref_die_offset (type_attr
);
5576 type_die
= follow_die_ref (ref
);
5579 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref
,
5583 type
= tag_type_to_type (type_die
, cu
);
5588 dump_die (type_die
);
5589 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
5596 static struct type
*
5597 type_at_offset (unsigned int offset
, struct dwarf2_cu
*cu
)
5599 struct die_info
*die
;
5602 die
= follow_die_ref (offset
);
5605 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
5608 type
= tag_type_to_type (die
, cu
);
5613 static struct type
*
5614 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5622 read_type_die (die
, cu
);
5626 error ("Dwarf Error: Cannot find type of die [in module %s]",
5634 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
5638 case DW_TAG_class_type
:
5639 case DW_TAG_structure_type
:
5640 case DW_TAG_union_type
:
5641 read_structure_scope (die
, cu
);
5643 case DW_TAG_enumeration_type
:
5644 read_enumeration (die
, cu
);
5646 case DW_TAG_subprogram
:
5647 case DW_TAG_subroutine_type
:
5648 read_subroutine_type (die
, cu
);
5650 case DW_TAG_array_type
:
5651 read_array_type (die
, cu
);
5653 case DW_TAG_pointer_type
:
5654 read_tag_pointer_type (die
, cu
);
5656 case DW_TAG_ptr_to_member_type
:
5657 read_tag_ptr_to_member_type (die
, cu
);
5659 case DW_TAG_reference_type
:
5660 read_tag_reference_type (die
, cu
);
5662 case DW_TAG_const_type
:
5663 read_tag_const_type (die
, cu
);
5665 case DW_TAG_volatile_type
:
5666 read_tag_volatile_type (die
, cu
);
5668 case DW_TAG_string_type
:
5669 read_tag_string_type (die
, cu
);
5671 case DW_TAG_typedef
:
5672 read_typedef (die
, cu
);
5674 case DW_TAG_base_type
:
5675 read_base_type (die
, cu
);
5678 complaint (&symfile_complaints
, "unexepected tag in read_type_die: '%s'",
5679 dwarf_tag_name (die
->tag
));
5684 static struct type
*
5685 dwarf_base_type (int encoding
, int size
, struct dwarf2_cu
*cu
)
5687 struct objfile
*objfile
= cu
->objfile
;
5689 /* FIXME - this should not produce a new (struct type *)
5690 every time. It should cache base types. */
5694 case DW_ATE_address
:
5695 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
5697 case DW_ATE_boolean
:
5698 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
5700 case DW_ATE_complex_float
:
5703 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
5707 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
5713 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
5717 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
5724 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5727 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
5731 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5735 case DW_ATE_signed_char
:
5736 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5738 case DW_ATE_unsigned
:
5742 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5745 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
5749 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
5753 case DW_ATE_unsigned_char
:
5754 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5757 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5764 copy_die (struct die_info
*old_die
)
5766 struct die_info
*new_die
;
5769 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5770 memset (new_die
, 0, sizeof (struct die_info
));
5772 new_die
->tag
= old_die
->tag
;
5773 new_die
->has_children
= old_die
->has_children
;
5774 new_die
->abbrev
= old_die
->abbrev
;
5775 new_die
->offset
= old_die
->offset
;
5776 new_die
->type
= NULL
;
5778 num_attrs
= old_die
->num_attrs
;
5779 new_die
->num_attrs
= num_attrs
;
5780 new_die
->attrs
= (struct attribute
*)
5781 xmalloc (num_attrs
* sizeof (struct attribute
));
5783 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
5785 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
5786 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
5787 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
5790 new_die
->next
= NULL
;
5795 /* Return sibling of die, NULL if no sibling. */
5797 static struct die_info
*
5798 sibling_die (struct die_info
*die
)
5800 return die
->sibling
;
5803 /* Get linkage name of a die, return NULL if not found. */
5806 dwarf2_linkage_name (struct die_info
*die
)
5808 struct attribute
*attr
;
5810 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
5811 if (attr
&& DW_STRING (attr
))
5812 return DW_STRING (attr
);
5813 attr
= dwarf_attr (die
, DW_AT_name
);
5814 if (attr
&& DW_STRING (attr
))
5815 return DW_STRING (attr
);
5819 /* Get name of a die, return NULL if not found. */
5822 dwarf2_name (struct die_info
*die
)
5824 struct attribute
*attr
;
5826 attr
= dwarf_attr (die
, DW_AT_name
);
5827 if (attr
&& DW_STRING (attr
))
5828 return DW_STRING (attr
);
5832 /* Return the die that this die in an extension of, or NULL if there
5835 static struct die_info
*
5836 dwarf2_extension (struct die_info
*die
)
5838 struct attribute
*attr
;
5839 struct die_info
*extension_die
;
5842 attr
= dwarf_attr (die
, DW_AT_extension
);
5846 ref
= dwarf2_get_ref_die_offset (attr
);
5847 extension_die
= follow_die_ref (ref
);
5850 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
5853 return extension_die
;
5856 /* Convert a DIE tag into its string name. */
5859 dwarf_tag_name (unsigned tag
)
5863 case DW_TAG_padding
:
5864 return "DW_TAG_padding";
5865 case DW_TAG_array_type
:
5866 return "DW_TAG_array_type";
5867 case DW_TAG_class_type
:
5868 return "DW_TAG_class_type";
5869 case DW_TAG_entry_point
:
5870 return "DW_TAG_entry_point";
5871 case DW_TAG_enumeration_type
:
5872 return "DW_TAG_enumeration_type";
5873 case DW_TAG_formal_parameter
:
5874 return "DW_TAG_formal_parameter";
5875 case DW_TAG_imported_declaration
:
5876 return "DW_TAG_imported_declaration";
5878 return "DW_TAG_label";
5879 case DW_TAG_lexical_block
:
5880 return "DW_TAG_lexical_block";
5882 return "DW_TAG_member";
5883 case DW_TAG_pointer_type
:
5884 return "DW_TAG_pointer_type";
5885 case DW_TAG_reference_type
:
5886 return "DW_TAG_reference_type";
5887 case DW_TAG_compile_unit
:
5888 return "DW_TAG_compile_unit";
5889 case DW_TAG_string_type
:
5890 return "DW_TAG_string_type";
5891 case DW_TAG_structure_type
:
5892 return "DW_TAG_structure_type";
5893 case DW_TAG_subroutine_type
:
5894 return "DW_TAG_subroutine_type";
5895 case DW_TAG_typedef
:
5896 return "DW_TAG_typedef";
5897 case DW_TAG_union_type
:
5898 return "DW_TAG_union_type";
5899 case DW_TAG_unspecified_parameters
:
5900 return "DW_TAG_unspecified_parameters";
5901 case DW_TAG_variant
:
5902 return "DW_TAG_variant";
5903 case DW_TAG_common_block
:
5904 return "DW_TAG_common_block";
5905 case DW_TAG_common_inclusion
:
5906 return "DW_TAG_common_inclusion";
5907 case DW_TAG_inheritance
:
5908 return "DW_TAG_inheritance";
5909 case DW_TAG_inlined_subroutine
:
5910 return "DW_TAG_inlined_subroutine";
5912 return "DW_TAG_module";
5913 case DW_TAG_ptr_to_member_type
:
5914 return "DW_TAG_ptr_to_member_type";
5915 case DW_TAG_set_type
:
5916 return "DW_TAG_set_type";
5917 case DW_TAG_subrange_type
:
5918 return "DW_TAG_subrange_type";
5919 case DW_TAG_with_stmt
:
5920 return "DW_TAG_with_stmt";
5921 case DW_TAG_access_declaration
:
5922 return "DW_TAG_access_declaration";
5923 case DW_TAG_base_type
:
5924 return "DW_TAG_base_type";
5925 case DW_TAG_catch_block
:
5926 return "DW_TAG_catch_block";
5927 case DW_TAG_const_type
:
5928 return "DW_TAG_const_type";
5929 case DW_TAG_constant
:
5930 return "DW_TAG_constant";
5931 case DW_TAG_enumerator
:
5932 return "DW_TAG_enumerator";
5933 case DW_TAG_file_type
:
5934 return "DW_TAG_file_type";
5936 return "DW_TAG_friend";
5937 case DW_TAG_namelist
:
5938 return "DW_TAG_namelist";
5939 case DW_TAG_namelist_item
:
5940 return "DW_TAG_namelist_item";
5941 case DW_TAG_packed_type
:
5942 return "DW_TAG_packed_type";
5943 case DW_TAG_subprogram
:
5944 return "DW_TAG_subprogram";
5945 case DW_TAG_template_type_param
:
5946 return "DW_TAG_template_type_param";
5947 case DW_TAG_template_value_param
:
5948 return "DW_TAG_template_value_param";
5949 case DW_TAG_thrown_type
:
5950 return "DW_TAG_thrown_type";
5951 case DW_TAG_try_block
:
5952 return "DW_TAG_try_block";
5953 case DW_TAG_variant_part
:
5954 return "DW_TAG_variant_part";
5955 case DW_TAG_variable
:
5956 return "DW_TAG_variable";
5957 case DW_TAG_volatile_type
:
5958 return "DW_TAG_volatile_type";
5959 case DW_TAG_dwarf_procedure
:
5960 return "DW_TAG_dwarf_procedure";
5961 case DW_TAG_restrict_type
:
5962 return "DW_TAG_restrict_type";
5963 case DW_TAG_interface_type
:
5964 return "DW_TAG_interface_type";
5965 case DW_TAG_namespace
:
5966 return "DW_TAG_namespace";
5967 case DW_TAG_imported_module
:
5968 return "DW_TAG_imported_module";
5969 case DW_TAG_unspecified_type
:
5970 return "DW_TAG_unspecified_type";
5971 case DW_TAG_partial_unit
:
5972 return "DW_TAG_partial_unit";
5973 case DW_TAG_imported_unit
:
5974 return "DW_TAG_imported_unit";
5975 case DW_TAG_MIPS_loop
:
5976 return "DW_TAG_MIPS_loop";
5977 case DW_TAG_format_label
:
5978 return "DW_TAG_format_label";
5979 case DW_TAG_function_template
:
5980 return "DW_TAG_function_template";
5981 case DW_TAG_class_template
:
5982 return "DW_TAG_class_template";
5984 return "DW_TAG_<unknown>";
5988 /* Convert a DWARF attribute code into its string name. */
5991 dwarf_attr_name (unsigned attr
)
5996 return "DW_AT_sibling";
5997 case DW_AT_location
:
5998 return "DW_AT_location";
6000 return "DW_AT_name";
6001 case DW_AT_ordering
:
6002 return "DW_AT_ordering";
6003 case DW_AT_subscr_data
:
6004 return "DW_AT_subscr_data";
6005 case DW_AT_byte_size
:
6006 return "DW_AT_byte_size";
6007 case DW_AT_bit_offset
:
6008 return "DW_AT_bit_offset";
6009 case DW_AT_bit_size
:
6010 return "DW_AT_bit_size";
6011 case DW_AT_element_list
:
6012 return "DW_AT_element_list";
6013 case DW_AT_stmt_list
:
6014 return "DW_AT_stmt_list";
6016 return "DW_AT_low_pc";
6018 return "DW_AT_high_pc";
6019 case DW_AT_language
:
6020 return "DW_AT_language";
6022 return "DW_AT_member";
6024 return "DW_AT_discr";
6025 case DW_AT_discr_value
:
6026 return "DW_AT_discr_value";
6027 case DW_AT_visibility
:
6028 return "DW_AT_visibility";
6030 return "DW_AT_import";
6031 case DW_AT_string_length
:
6032 return "DW_AT_string_length";
6033 case DW_AT_common_reference
:
6034 return "DW_AT_common_reference";
6035 case DW_AT_comp_dir
:
6036 return "DW_AT_comp_dir";
6037 case DW_AT_const_value
:
6038 return "DW_AT_const_value";
6039 case DW_AT_containing_type
:
6040 return "DW_AT_containing_type";
6041 case DW_AT_default_value
:
6042 return "DW_AT_default_value";
6044 return "DW_AT_inline";
6045 case DW_AT_is_optional
:
6046 return "DW_AT_is_optional";
6047 case DW_AT_lower_bound
:
6048 return "DW_AT_lower_bound";
6049 case DW_AT_producer
:
6050 return "DW_AT_producer";
6051 case DW_AT_prototyped
:
6052 return "DW_AT_prototyped";
6053 case DW_AT_return_addr
:
6054 return "DW_AT_return_addr";
6055 case DW_AT_start_scope
:
6056 return "DW_AT_start_scope";
6057 case DW_AT_stride_size
:
6058 return "DW_AT_stride_size";
6059 case DW_AT_upper_bound
:
6060 return "DW_AT_upper_bound";
6061 case DW_AT_abstract_origin
:
6062 return "DW_AT_abstract_origin";
6063 case DW_AT_accessibility
:
6064 return "DW_AT_accessibility";
6065 case DW_AT_address_class
:
6066 return "DW_AT_address_class";
6067 case DW_AT_artificial
:
6068 return "DW_AT_artificial";
6069 case DW_AT_base_types
:
6070 return "DW_AT_base_types";
6071 case DW_AT_calling_convention
:
6072 return "DW_AT_calling_convention";
6074 return "DW_AT_count";
6075 case DW_AT_data_member_location
:
6076 return "DW_AT_data_member_location";
6077 case DW_AT_decl_column
:
6078 return "DW_AT_decl_column";
6079 case DW_AT_decl_file
:
6080 return "DW_AT_decl_file";
6081 case DW_AT_decl_line
:
6082 return "DW_AT_decl_line";
6083 case DW_AT_declaration
:
6084 return "DW_AT_declaration";
6085 case DW_AT_discr_list
:
6086 return "DW_AT_discr_list";
6087 case DW_AT_encoding
:
6088 return "DW_AT_encoding";
6089 case DW_AT_external
:
6090 return "DW_AT_external";
6091 case DW_AT_frame_base
:
6092 return "DW_AT_frame_base";
6094 return "DW_AT_friend";
6095 case DW_AT_identifier_case
:
6096 return "DW_AT_identifier_case";
6097 case DW_AT_macro_info
:
6098 return "DW_AT_macro_info";
6099 case DW_AT_namelist_items
:
6100 return "DW_AT_namelist_items";
6101 case DW_AT_priority
:
6102 return "DW_AT_priority";
6104 return "DW_AT_segment";
6105 case DW_AT_specification
:
6106 return "DW_AT_specification";
6107 case DW_AT_static_link
:
6108 return "DW_AT_static_link";
6110 return "DW_AT_type";
6111 case DW_AT_use_location
:
6112 return "DW_AT_use_location";
6113 case DW_AT_variable_parameter
:
6114 return "DW_AT_variable_parameter";
6115 case DW_AT_virtuality
:
6116 return "DW_AT_virtuality";
6117 case DW_AT_vtable_elem_location
:
6118 return "DW_AT_vtable_elem_location";
6119 case DW_AT_allocated
:
6120 return "DW_AT_allocated";
6121 case DW_AT_associated
:
6122 return "DW_AT_associated";
6123 case DW_AT_data_location
:
6124 return "DW_AT_data_location";
6126 return "DW_AT_stride";
6127 case DW_AT_entry_pc
:
6128 return "DW_AT_entry_pc";
6129 case DW_AT_use_UTF8
:
6130 return "DW_AT_use_UTF8";
6131 case DW_AT_extension
:
6132 return "DW_AT_extension";
6134 return "DW_AT_ranges";
6135 case DW_AT_trampoline
:
6136 return "DW_AT_trampoline";
6137 case DW_AT_call_column
:
6138 return "DW_AT_call_column";
6139 case DW_AT_call_file
:
6140 return "DW_AT_call_file";
6141 case DW_AT_call_line
:
6142 return "DW_AT_call_line";
6144 case DW_AT_MIPS_fde
:
6145 return "DW_AT_MIPS_fde";
6146 case DW_AT_MIPS_loop_begin
:
6147 return "DW_AT_MIPS_loop_begin";
6148 case DW_AT_MIPS_tail_loop_begin
:
6149 return "DW_AT_MIPS_tail_loop_begin";
6150 case DW_AT_MIPS_epilog_begin
:
6151 return "DW_AT_MIPS_epilog_begin";
6152 case DW_AT_MIPS_loop_unroll_factor
:
6153 return "DW_AT_MIPS_loop_unroll_factor";
6154 case DW_AT_MIPS_software_pipeline_depth
:
6155 return "DW_AT_MIPS_software_pipeline_depth";
6157 case DW_AT_MIPS_linkage_name
:
6158 return "DW_AT_MIPS_linkage_name";
6160 case DW_AT_sf_names
:
6161 return "DW_AT_sf_names";
6162 case DW_AT_src_info
:
6163 return "DW_AT_src_info";
6164 case DW_AT_mac_info
:
6165 return "DW_AT_mac_info";
6166 case DW_AT_src_coords
:
6167 return "DW_AT_src_coords";
6168 case DW_AT_body_begin
:
6169 return "DW_AT_body_begin";
6170 case DW_AT_body_end
:
6171 return "DW_AT_body_end";
6172 case DW_AT_GNU_vector
:
6173 return "DW_AT_GNU_vector";
6175 return "DW_AT_<unknown>";
6179 /* Convert a DWARF value form code into its string name. */
6182 dwarf_form_name (unsigned form
)
6187 return "DW_FORM_addr";
6188 case DW_FORM_block2
:
6189 return "DW_FORM_block2";
6190 case DW_FORM_block4
:
6191 return "DW_FORM_block4";
6193 return "DW_FORM_data2";
6195 return "DW_FORM_data4";
6197 return "DW_FORM_data8";
6198 case DW_FORM_string
:
6199 return "DW_FORM_string";
6201 return "DW_FORM_block";
6202 case DW_FORM_block1
:
6203 return "DW_FORM_block1";
6205 return "DW_FORM_data1";
6207 return "DW_FORM_flag";
6209 return "DW_FORM_sdata";
6211 return "DW_FORM_strp";
6213 return "DW_FORM_udata";
6214 case DW_FORM_ref_addr
:
6215 return "DW_FORM_ref_addr";
6217 return "DW_FORM_ref1";
6219 return "DW_FORM_ref2";
6221 return "DW_FORM_ref4";
6223 return "DW_FORM_ref8";
6224 case DW_FORM_ref_udata
:
6225 return "DW_FORM_ref_udata";
6226 case DW_FORM_indirect
:
6227 return "DW_FORM_indirect";
6229 return "DW_FORM_<unknown>";
6233 /* Convert a DWARF stack opcode into its string name. */
6236 dwarf_stack_op_name (unsigned op
)
6241 return "DW_OP_addr";
6243 return "DW_OP_deref";
6245 return "DW_OP_const1u";
6247 return "DW_OP_const1s";
6249 return "DW_OP_const2u";
6251 return "DW_OP_const2s";
6253 return "DW_OP_const4u";
6255 return "DW_OP_const4s";
6257 return "DW_OP_const8u";
6259 return "DW_OP_const8s";
6261 return "DW_OP_constu";
6263 return "DW_OP_consts";
6267 return "DW_OP_drop";
6269 return "DW_OP_over";
6271 return "DW_OP_pick";
6273 return "DW_OP_swap";
6277 return "DW_OP_xderef";
6285 return "DW_OP_minus";
6297 return "DW_OP_plus";
6298 case DW_OP_plus_uconst
:
6299 return "DW_OP_plus_uconst";
6305 return "DW_OP_shra";
6323 return "DW_OP_skip";
6325 return "DW_OP_lit0";
6327 return "DW_OP_lit1";
6329 return "DW_OP_lit2";
6331 return "DW_OP_lit3";
6333 return "DW_OP_lit4";
6335 return "DW_OP_lit5";
6337 return "DW_OP_lit6";
6339 return "DW_OP_lit7";
6341 return "DW_OP_lit8";
6343 return "DW_OP_lit9";
6345 return "DW_OP_lit10";
6347 return "DW_OP_lit11";
6349 return "DW_OP_lit12";
6351 return "DW_OP_lit13";
6353 return "DW_OP_lit14";
6355 return "DW_OP_lit15";
6357 return "DW_OP_lit16";
6359 return "DW_OP_lit17";
6361 return "DW_OP_lit18";
6363 return "DW_OP_lit19";
6365 return "DW_OP_lit20";
6367 return "DW_OP_lit21";
6369 return "DW_OP_lit22";
6371 return "DW_OP_lit23";
6373 return "DW_OP_lit24";
6375 return "DW_OP_lit25";
6377 return "DW_OP_lit26";
6379 return "DW_OP_lit27";
6381 return "DW_OP_lit28";
6383 return "DW_OP_lit29";
6385 return "DW_OP_lit30";
6387 return "DW_OP_lit31";
6389 return "DW_OP_reg0";
6391 return "DW_OP_reg1";
6393 return "DW_OP_reg2";
6395 return "DW_OP_reg3";
6397 return "DW_OP_reg4";
6399 return "DW_OP_reg5";
6401 return "DW_OP_reg6";
6403 return "DW_OP_reg7";
6405 return "DW_OP_reg8";
6407 return "DW_OP_reg9";
6409 return "DW_OP_reg10";
6411 return "DW_OP_reg11";
6413 return "DW_OP_reg12";
6415 return "DW_OP_reg13";
6417 return "DW_OP_reg14";
6419 return "DW_OP_reg15";
6421 return "DW_OP_reg16";
6423 return "DW_OP_reg17";
6425 return "DW_OP_reg18";
6427 return "DW_OP_reg19";
6429 return "DW_OP_reg20";
6431 return "DW_OP_reg21";
6433 return "DW_OP_reg22";
6435 return "DW_OP_reg23";
6437 return "DW_OP_reg24";
6439 return "DW_OP_reg25";
6441 return "DW_OP_reg26";
6443 return "DW_OP_reg27";
6445 return "DW_OP_reg28";
6447 return "DW_OP_reg29";
6449 return "DW_OP_reg30";
6451 return "DW_OP_reg31";
6453 return "DW_OP_breg0";
6455 return "DW_OP_breg1";
6457 return "DW_OP_breg2";
6459 return "DW_OP_breg3";
6461 return "DW_OP_breg4";
6463 return "DW_OP_breg5";
6465 return "DW_OP_breg6";
6467 return "DW_OP_breg7";
6469 return "DW_OP_breg8";
6471 return "DW_OP_breg9";
6473 return "DW_OP_breg10";
6475 return "DW_OP_breg11";
6477 return "DW_OP_breg12";
6479 return "DW_OP_breg13";
6481 return "DW_OP_breg14";
6483 return "DW_OP_breg15";
6485 return "DW_OP_breg16";
6487 return "DW_OP_breg17";
6489 return "DW_OP_breg18";
6491 return "DW_OP_breg19";
6493 return "DW_OP_breg20";
6495 return "DW_OP_breg21";
6497 return "DW_OP_breg22";
6499 return "DW_OP_breg23";
6501 return "DW_OP_breg24";
6503 return "DW_OP_breg25";
6505 return "DW_OP_breg26";
6507 return "DW_OP_breg27";
6509 return "DW_OP_breg28";
6511 return "DW_OP_breg29";
6513 return "DW_OP_breg30";
6515 return "DW_OP_breg31";
6517 return "DW_OP_regx";
6519 return "DW_OP_fbreg";
6521 return "DW_OP_bregx";
6523 return "DW_OP_piece";
6524 case DW_OP_deref_size
:
6525 return "DW_OP_deref_size";
6526 case DW_OP_xderef_size
:
6527 return "DW_OP_xderef_size";
6530 /* DWARF 3 extensions. */
6531 case DW_OP_push_object_address
:
6532 return "DW_OP_push_object_address";
6534 return "DW_OP_call2";
6536 return "DW_OP_call4";
6537 case DW_OP_call_ref
:
6538 return "DW_OP_call_ref";
6539 /* GNU extensions. */
6540 case DW_OP_GNU_push_tls_address
:
6541 return "DW_OP_GNU_push_tls_address";
6543 return "OP_<unknown>";
6548 dwarf_bool_name (unsigned mybool
)
6556 /* Convert a DWARF type code into its string name. */
6559 dwarf_type_encoding_name (unsigned enc
)
6563 case DW_ATE_address
:
6564 return "DW_ATE_address";
6565 case DW_ATE_boolean
:
6566 return "DW_ATE_boolean";
6567 case DW_ATE_complex_float
:
6568 return "DW_ATE_complex_float";
6570 return "DW_ATE_float";
6572 return "DW_ATE_signed";
6573 case DW_ATE_signed_char
:
6574 return "DW_ATE_signed_char";
6575 case DW_ATE_unsigned
:
6576 return "DW_ATE_unsigned";
6577 case DW_ATE_unsigned_char
:
6578 return "DW_ATE_unsigned_char";
6579 case DW_ATE_imaginary_float
:
6580 return "DW_ATE_imaginary_float";
6582 return "DW_ATE_<unknown>";
6586 /* Convert a DWARF call frame info operation to its string name. */
6590 dwarf_cfi_name (unsigned cfi_opc
)
6594 case DW_CFA_advance_loc
:
6595 return "DW_CFA_advance_loc";
6597 return "DW_CFA_offset";
6598 case DW_CFA_restore
:
6599 return "DW_CFA_restore";
6601 return "DW_CFA_nop";
6602 case DW_CFA_set_loc
:
6603 return "DW_CFA_set_loc";
6604 case DW_CFA_advance_loc1
:
6605 return "DW_CFA_advance_loc1";
6606 case DW_CFA_advance_loc2
:
6607 return "DW_CFA_advance_loc2";
6608 case DW_CFA_advance_loc4
:
6609 return "DW_CFA_advance_loc4";
6610 case DW_CFA_offset_extended
:
6611 return "DW_CFA_offset_extended";
6612 case DW_CFA_restore_extended
:
6613 return "DW_CFA_restore_extended";
6614 case DW_CFA_undefined
:
6615 return "DW_CFA_undefined";
6616 case DW_CFA_same_value
:
6617 return "DW_CFA_same_value";
6618 case DW_CFA_register
:
6619 return "DW_CFA_register";
6620 case DW_CFA_remember_state
:
6621 return "DW_CFA_remember_state";
6622 case DW_CFA_restore_state
:
6623 return "DW_CFA_restore_state";
6624 case DW_CFA_def_cfa
:
6625 return "DW_CFA_def_cfa";
6626 case DW_CFA_def_cfa_register
:
6627 return "DW_CFA_def_cfa_register";
6628 case DW_CFA_def_cfa_offset
:
6629 return "DW_CFA_def_cfa_offset";
6632 case DW_CFA_def_cfa_expression
:
6633 return "DW_CFA_def_cfa_expression";
6634 case DW_CFA_expression
:
6635 return "DW_CFA_expression";
6636 case DW_CFA_offset_extended_sf
:
6637 return "DW_CFA_offset_extended_sf";
6638 case DW_CFA_def_cfa_sf
:
6639 return "DW_CFA_def_cfa_sf";
6640 case DW_CFA_def_cfa_offset_sf
:
6641 return "DW_CFA_def_cfa_offset_sf";
6643 /* SGI/MIPS specific */
6644 case DW_CFA_MIPS_advance_loc8
:
6645 return "DW_CFA_MIPS_advance_loc8";
6647 /* GNU extensions */
6648 case DW_CFA_GNU_window_save
:
6649 return "DW_CFA_GNU_window_save";
6650 case DW_CFA_GNU_args_size
:
6651 return "DW_CFA_GNU_args_size";
6652 case DW_CFA_GNU_negative_offset_extended
:
6653 return "DW_CFA_GNU_negative_offset_extended";
6656 return "DW_CFA_<unknown>";
6662 dump_die (struct die_info
*die
)
6666 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
6667 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
6668 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
6669 dwarf_bool_name (die
->child
!= NULL
));
6671 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
6672 for (i
= 0; i
< die
->num_attrs
; ++i
)
6674 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
6675 dwarf_attr_name (die
->attrs
[i
].name
),
6676 dwarf_form_name (die
->attrs
[i
].form
));
6677 switch (die
->attrs
[i
].form
)
6679 case DW_FORM_ref_addr
:
6681 fprintf_unfiltered (gdb_stderr
, "address: ");
6682 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
6684 case DW_FORM_block2
:
6685 case DW_FORM_block4
:
6687 case DW_FORM_block1
:
6688 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
6699 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
6701 case DW_FORM_string
:
6703 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
6704 DW_STRING (&die
->attrs
[i
])
6705 ? DW_STRING (&die
->attrs
[i
]) : "");
6708 if (DW_UNSND (&die
->attrs
[i
]))
6709 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
6711 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
6713 case DW_FORM_indirect
:
6714 /* the reader will have reduced the indirect form to
6715 the "base form" so this form should not occur */
6716 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
6719 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
6720 die
->attrs
[i
].form
);
6722 fprintf_unfiltered (gdb_stderr
, "\n");
6727 dump_die_list (struct die_info
*die
)
6732 if (die
->child
!= NULL
)
6733 dump_die_list (die
->child
);
6734 if (die
->sibling
!= NULL
)
6735 dump_die_list (die
->sibling
);
6740 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
6743 struct die_info
*old
;
6745 h
= (offset
% REF_HASH_SIZE
);
6746 old
= die_ref_table
[h
];
6747 die
->next_ref
= old
;
6748 die_ref_table
[h
] = die
;
6753 dwarf2_empty_hash_tables (void)
6755 memset (die_ref_table
, 0, sizeof (die_ref_table
));
6759 dwarf2_get_ref_die_offset (struct attribute
*attr
)
6761 unsigned int result
= 0;
6765 case DW_FORM_ref_addr
:
6766 result
= DW_ADDR (attr
);
6772 case DW_FORM_ref_udata
:
6773 result
= cu_header_offset
+ DW_UNSND (attr
);
6776 complaint (&symfile_complaints
,
6777 "unsupported die ref attribute form: '%s'",
6778 dwarf_form_name (attr
->form
));
6783 static struct die_info
*
6784 follow_die_ref (unsigned int offset
)
6786 struct die_info
*die
;
6789 h
= (offset
% REF_HASH_SIZE
);
6790 die
= die_ref_table
[h
];
6793 if (die
->offset
== offset
)
6797 die
= die
->next_ref
;
6802 static struct type
*
6803 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
6805 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
6807 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
6808 typeid, objfile
->name
);
6811 /* Look for this particular type in the fundamental type vector. If
6812 one is not found, create and install one appropriate for the
6813 current language and the current target machine. */
6815 if (ftypes
[typeid] == NULL
)
6817 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
6820 return (ftypes
[typeid]);
6823 /* Decode simple location descriptions.
6824 Given a pointer to a dwarf block that defines a location, compute
6825 the location and return the value.
6827 NOTE drow/2003-11-18: This function is called in two situations
6828 now: for the address of static or global variables (partial symbols
6829 only) and for offsets into structures which are expected to be
6830 (more or less) constant. The partial symbol case should go away,
6831 and only the constant case should remain. That will let this
6832 function complain more accurately. A few special modes are allowed
6833 without complaint for global variables (for instance, global
6834 register values and thread-local values).
6836 A location description containing no operations indicates that the
6837 object is optimized out. The return value is 0 for that case.
6838 FIXME drow/2003-11-16: No callers check for this case any more; soon all
6839 callers will only want a very basic result and this can become a
6842 When the result is a register number, the global isreg flag is set,
6843 otherwise it is cleared.
6845 Note that stack[0] is unused except as a default error return.
6846 Note that stack overflow is not yet handled. */
6849 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
6851 struct objfile
*objfile
= cu
->objfile
;
6852 struct comp_unit_head
*cu_header
= &cu
->header
;
6854 int size
= blk
->size
;
6855 char *data
= blk
->data
;
6856 CORE_ADDR stack
[64];
6858 unsigned int bytes_read
, unsnd
;
6903 stack
[++stacki
] = op
- DW_OP_lit0
;
6939 stack
[++stacki
] = op
- DW_OP_reg0
;
6941 dwarf2_complex_location_expr_complaint ();
6946 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6948 stack
[++stacki
] = unsnd
;
6950 dwarf2_complex_location_expr_complaint ();
6954 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
6960 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
6965 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
6970 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
6975 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
6980 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
6985 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
6990 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
6996 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
7001 stack
[stacki
+ 1] = stack
[stacki
];
7006 stack
[stacki
- 1] += stack
[stacki
];
7010 case DW_OP_plus_uconst
:
7011 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
7016 stack
[stacki
- 1] -= stack
[stacki
];
7021 /* If we're not the last op, then we definitely can't encode
7022 this using GDB's address_class enum. This is valid for partial
7023 global symbols, although the variable's address will be bogus
7026 dwarf2_complex_location_expr_complaint ();
7029 case DW_OP_GNU_push_tls_address
:
7030 /* The top of the stack has the offset from the beginning
7031 of the thread control block at which the variable is located. */
7032 /* Nothing should follow this operator, so the top of stack would
7034 /* This is valid for partial global symbols, but the variable's
7035 address will be bogus in the psymtab. */
7037 dwarf2_complex_location_expr_complaint ();
7041 complaint (&symfile_complaints
, "unsupported stack op: '%s'",
7042 dwarf_stack_op_name (op
));
7043 return (stack
[stacki
]);
7046 return (stack
[stacki
]);
7049 /* memory allocation interface */
7052 dwarf2_free_tmp_obstack (void *ignore
)
7054 obstack_free (&dwarf2_tmp_obstack
, NULL
);
7057 static struct dwarf_block
*
7058 dwarf_alloc_block (void)
7060 struct dwarf_block
*blk
;
7062 blk
= (struct dwarf_block
*)
7063 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
7067 static struct abbrev_info
*
7068 dwarf_alloc_abbrev (void)
7070 struct abbrev_info
*abbrev
;
7072 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
7073 memset (abbrev
, 0, sizeof (struct abbrev_info
));
7077 static struct die_info
*
7078 dwarf_alloc_die (void)
7080 struct die_info
*die
;
7082 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
7083 memset (die
, 0, sizeof (struct die_info
));
7088 /* Macro support. */
7091 /* Return the full name of file number I in *LH's file name table.
7092 Use COMP_DIR as the name of the current directory of the
7093 compilation. The result is allocated using xmalloc; the caller is
7094 responsible for freeing it. */
7096 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
7098 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7100 if (IS_ABSOLUTE_PATH (fe
->name
))
7101 return xstrdup (fe
->name
);
7109 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7115 dir_len
= strlen (dir
);
7116 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
7117 strcpy (full_name
, dir
);
7118 full_name
[dir_len
] = '/';
7119 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
7123 return xstrdup (fe
->name
);
7128 static struct macro_source_file
*
7129 macro_start_file (int file
, int line
,
7130 struct macro_source_file
*current_file
,
7131 const char *comp_dir
,
7132 struct line_header
*lh
, struct objfile
*objfile
)
7134 /* The full name of this source file. */
7135 char *full_name
= file_full_name (file
, lh
, comp_dir
);
7137 /* We don't create a macro table for this compilation unit
7138 at all until we actually get a filename. */
7139 if (! pending_macros
)
7140 pending_macros
= new_macro_table (&objfile
->symbol_obstack
,
7141 objfile
->macro_cache
);
7144 /* If we have no current file, then this must be the start_file
7145 directive for the compilation unit's main source file. */
7146 current_file
= macro_set_main (pending_macros
, full_name
);
7148 current_file
= macro_include (current_file
, line
, full_name
);
7152 return current_file
;
7156 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
7157 followed by a null byte. */
7159 copy_string (const char *buf
, int len
)
7161 char *s
= xmalloc (len
+ 1);
7162 memcpy (s
, buf
, len
);
7170 consume_improper_spaces (const char *p
, const char *body
)
7174 complaint (&symfile_complaints
,
7175 "macro definition contains spaces in formal argument list:\n`%s'",
7187 parse_macro_definition (struct macro_source_file
*file
, int line
,
7192 /* The body string takes one of two forms. For object-like macro
7193 definitions, it should be:
7195 <macro name> " " <definition>
7197 For function-like macro definitions, it should be:
7199 <macro name> "() " <definition>
7201 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
7203 Spaces may appear only where explicitly indicated, and in the
7206 The Dwarf 2 spec says that an object-like macro's name is always
7207 followed by a space, but versions of GCC around March 2002 omit
7208 the space when the macro's definition is the empty string.
7210 The Dwarf 2 spec says that there should be no spaces between the
7211 formal arguments in a function-like macro's formal argument list,
7212 but versions of GCC around March 2002 include spaces after the
7216 /* Find the extent of the macro name. The macro name is terminated
7217 by either a space or null character (for an object-like macro) or
7218 an opening paren (for a function-like macro). */
7219 for (p
= body
; *p
; p
++)
7220 if (*p
== ' ' || *p
== '(')
7223 if (*p
== ' ' || *p
== '\0')
7225 /* It's an object-like macro. */
7226 int name_len
= p
- body
;
7227 char *name
= copy_string (body
, name_len
);
7228 const char *replacement
;
7231 replacement
= body
+ name_len
+ 1;
7234 dwarf2_macro_malformed_definition_complaint (body
);
7235 replacement
= body
+ name_len
;
7238 macro_define_object (file
, line
, name
, replacement
);
7244 /* It's a function-like macro. */
7245 char *name
= copy_string (body
, p
- body
);
7248 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
7252 p
= consume_improper_spaces (p
, body
);
7254 /* Parse the formal argument list. */
7255 while (*p
&& *p
!= ')')
7257 /* Find the extent of the current argument name. */
7258 const char *arg_start
= p
;
7260 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
7263 if (! *p
|| p
== arg_start
)
7264 dwarf2_macro_malformed_definition_complaint (body
);
7267 /* Make sure argv has room for the new argument. */
7268 if (argc
>= argv_size
)
7271 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
7274 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
7277 p
= consume_improper_spaces (p
, body
);
7279 /* Consume the comma, if present. */
7284 p
= consume_improper_spaces (p
, body
);
7293 /* Perfectly formed definition, no complaints. */
7294 macro_define_function (file
, line
, name
,
7295 argc
, (const char **) argv
,
7297 else if (*p
== '\0')
7299 /* Complain, but do define it. */
7300 dwarf2_macro_malformed_definition_complaint (body
);
7301 macro_define_function (file
, line
, name
,
7302 argc
, (const char **) argv
,
7306 /* Just complain. */
7307 dwarf2_macro_malformed_definition_complaint (body
);
7310 /* Just complain. */
7311 dwarf2_macro_malformed_definition_complaint (body
);
7317 for (i
= 0; i
< argc
; i
++)
7323 dwarf2_macro_malformed_definition_complaint (body
);
7328 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
7329 char *comp_dir
, bfd
*abfd
,
7330 struct dwarf2_cu
*cu
)
7332 char *mac_ptr
, *mac_end
;
7333 struct macro_source_file
*current_file
= 0;
7335 if (dwarf_macinfo_buffer
== NULL
)
7337 complaint (&symfile_complaints
, "missing .debug_macinfo section");
7341 mac_ptr
= dwarf_macinfo_buffer
+ offset
;
7342 mac_end
= dwarf_macinfo_buffer
+ dwarf_macinfo_size
;
7346 enum dwarf_macinfo_record_type macinfo_type
;
7348 /* Do we at least have room for a macinfo type byte? */
7349 if (mac_ptr
>= mac_end
)
7351 dwarf2_macros_too_long_complaint ();
7355 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
7358 switch (macinfo_type
)
7360 /* A zero macinfo type indicates the end of the macro
7365 case DW_MACINFO_define
:
7366 case DW_MACINFO_undef
:
7372 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7373 mac_ptr
+= bytes_read
;
7374 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
7375 mac_ptr
+= bytes_read
;
7378 complaint (&symfile_complaints
,
7379 "debug info gives macro %s outside of any file: %s",
7381 DW_MACINFO_define
? "definition" : macinfo_type
==
7382 DW_MACINFO_undef
? "undefinition" :
7383 "something-or-other", body
);
7386 if (macinfo_type
== DW_MACINFO_define
)
7387 parse_macro_definition (current_file
, line
, body
);
7388 else if (macinfo_type
== DW_MACINFO_undef
)
7389 macro_undef (current_file
, line
, body
);
7394 case DW_MACINFO_start_file
:
7399 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7400 mac_ptr
+= bytes_read
;
7401 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7402 mac_ptr
+= bytes_read
;
7404 current_file
= macro_start_file (file
, line
,
7405 current_file
, comp_dir
,
7410 case DW_MACINFO_end_file
:
7412 complaint (&symfile_complaints
,
7413 "macro debug info has an unmatched `close_file' directive");
7416 current_file
= current_file
->included_by
;
7419 enum dwarf_macinfo_record_type next_type
;
7421 /* GCC circa March 2002 doesn't produce the zero
7422 type byte marking the end of the compilation
7423 unit. Complain if it's not there, but exit no
7426 /* Do we at least have room for a macinfo type byte? */
7427 if (mac_ptr
>= mac_end
)
7429 dwarf2_macros_too_long_complaint ();
7433 /* We don't increment mac_ptr here, so this is just
7435 next_type
= read_1_byte (abfd
, mac_ptr
);
7437 complaint (&symfile_complaints
,
7438 "no terminating 0-type entry for macros in `.debug_macinfo' section");
7445 case DW_MACINFO_vendor_ext
:
7451 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7452 mac_ptr
+= bytes_read
;
7453 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
7454 mac_ptr
+= bytes_read
;
7456 /* We don't recognize any vendor extensions. */
7463 /* Check if the attribute's form is a DW_FORM_block*
7464 if so return true else false. */
7466 attr_form_is_block (struct attribute
*attr
)
7468 return (attr
== NULL
? 0 :
7469 attr
->form
== DW_FORM_block1
7470 || attr
->form
== DW_FORM_block2
7471 || attr
->form
== DW_FORM_block4
7472 || attr
->form
== DW_FORM_block
);
7476 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
7477 struct dwarf2_cu
*cu
)
7479 if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
7481 struct dwarf2_loclist_baton
*baton
;
7483 baton
= obstack_alloc (&cu
->objfile
->symbol_obstack
,
7484 sizeof (struct dwarf2_loclist_baton
));
7485 baton
->objfile
= cu
->objfile
;
7487 /* We don't know how long the location list is, but make sure we
7488 don't run off the edge of the section. */
7489 baton
->size
= dwarf_loc_size
- DW_UNSND (attr
);
7490 baton
->data
= dwarf_loc_buffer
+ DW_UNSND (attr
);
7491 baton
->base_address
= cu
->header
.base_address
;
7492 if (cu
->header
.base_known
== 0)
7493 complaint (&symfile_complaints
,
7494 "Location list used without specifying the CU base address.");
7496 SYMBOL_LOCATION_FUNCS (sym
) = &dwarf2_loclist_funcs
;
7497 SYMBOL_LOCATION_BATON (sym
) = baton
;
7501 struct dwarf2_locexpr_baton
*baton
;
7503 baton
= obstack_alloc (&cu
->objfile
->symbol_obstack
,
7504 sizeof (struct dwarf2_locexpr_baton
));
7505 baton
->objfile
= cu
->objfile
;
7507 if (attr_form_is_block (attr
))
7509 /* Note that we're just copying the block's data pointer
7510 here, not the actual data. We're still pointing into the
7511 dwarf_info_buffer for SYM's objfile; right now we never
7512 release that buffer, but when we do clean up properly
7513 this may need to change. */
7514 baton
->size
= DW_BLOCK (attr
)->size
;
7515 baton
->data
= DW_BLOCK (attr
)->data
;
7519 dwarf2_invalid_attrib_class_complaint ("location description",
7520 SYMBOL_NATURAL_NAME (sym
));
7525 SYMBOL_LOCATION_FUNCS (sym
) = &dwarf2_locexpr_funcs
;
7526 SYMBOL_LOCATION_BATON (sym
) = baton
;