1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
4 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
5 Inc. with support from Florida State University (under contract
6 with the Ada Joint Program Office), and Silicon Graphics, Inc.
7 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
8 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
11 This file is part of GDB.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or (at
16 your option) any later version.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. */
34 #include "elf/dwarf2.h"
37 #include "expression.h"
39 #include "complaints.h"
42 #include "gdb_string.h"
43 #include <sys/types.h>
45 /* .debug_info header for a compilation unit
46 Because of alignment constraints, this structure has padding and cannot
47 be mapped directly onto the beginning of the .debug_info section. */
48 typedef struct comp_unit_header
50 unsigned int length
; /* length of the .debug_info
52 unsigned short version
; /* version number -- 2 for DWARF
54 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
55 unsigned char addr_size
; /* byte size of an address -- 4 */
58 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
60 /* .debug_pubnames header
61 Because of alignment constraints, this structure has padding and cannot
62 be mapped directly onto the beginning of the .debug_info section. */
63 typedef struct pubnames_header
65 unsigned int length
; /* length of the .debug_pubnames
67 unsigned char version
; /* version number -- 2 for DWARF
69 unsigned int info_offset
; /* offset into .debug_info section */
70 unsigned int info_size
; /* byte size of .debug_info section
74 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
76 /* .debug_pubnames header
77 Because of alignment constraints, this structure has padding and cannot
78 be mapped directly onto the beginning of the .debug_info section. */
79 typedef struct aranges_header
81 unsigned int length
; /* byte len of the .debug_aranges
83 unsigned short version
; /* version number -- 2 for DWARF
85 unsigned int info_offset
; /* offset into .debug_info section */
86 unsigned char addr_size
; /* byte size of an address */
87 unsigned char seg_size
; /* byte size of segment descriptor */
90 #define _ACTUAL_ARANGES_HEADER_SIZE 12
92 /* .debug_line statement program prologue
93 Because of alignment constraints, this structure has padding and cannot
94 be mapped directly onto the beginning of the .debug_info section. */
95 typedef struct statement_prologue
97 unsigned int total_length
; /* byte length of the statement
99 unsigned short version
; /* version number -- 2 for DWARF
101 unsigned int prologue_length
; /* # bytes between prologue &
103 unsigned char minimum_instruction_length
; /* byte size of
105 unsigned char default_is_stmt
; /* initial value of is_stmt
108 unsigned char line_range
;
109 unsigned char opcode_base
; /* number assigned to first special
111 unsigned char *standard_opcode_lengths
;
115 /* offsets and sizes of debugging sections */
117 static file_ptr dwarf_info_offset
;
118 static file_ptr dwarf_abbrev_offset
;
119 static file_ptr dwarf_line_offset
;
120 static file_ptr dwarf_pubnames_offset
;
121 static file_ptr dwarf_aranges_offset
;
122 static file_ptr dwarf_loc_offset
;
123 static file_ptr dwarf_macinfo_offset
;
124 static file_ptr dwarf_str_offset
;
126 static unsigned int dwarf_info_size
;
127 static unsigned int dwarf_abbrev_size
;
128 static unsigned int dwarf_line_size
;
129 static unsigned int dwarf_pubnames_size
;
130 static unsigned int dwarf_aranges_size
;
131 static unsigned int dwarf_loc_size
;
132 static unsigned int dwarf_macinfo_size
;
133 static unsigned int dwarf_str_size
;
135 /* names of the debugging sections */
137 #define INFO_SECTION ".debug_info"
138 #define ABBREV_SECTION ".debug_abbrev"
139 #define LINE_SECTION ".debug_line"
140 #define PUBNAMES_SECTION ".debug_pubnames"
141 #define ARANGES_SECTION ".debug_aranges"
142 #define LOC_SECTION ".debug_loc"
143 #define MACINFO_SECTION ".debug_macinfo"
144 #define STR_SECTION ".debug_str"
146 /* local data types */
148 /* The data in a compilation unit header looks like this. */
149 struct comp_unit_head
153 unsigned int abbrev_offset
;
154 unsigned char addr_size
;
157 /* The data in the .debug_line statement prologue looks like this. */
160 unsigned int total_length
;
161 unsigned short version
;
162 unsigned int prologue_length
;
163 unsigned char minimum_instruction_length
;
164 unsigned char default_is_stmt
;
166 unsigned char line_range
;
167 unsigned char opcode_base
;
168 unsigned char *standard_opcode_lengths
;
171 /* When we construct a partial symbol table entry we only
172 need this much information. */
173 struct partial_die_info
176 unsigned char has_children
;
177 unsigned char is_external
;
178 unsigned char is_declaration
;
179 unsigned char has_type
;
185 struct dwarf_block
*locdesc
;
186 unsigned int language
;
190 /* This data structure holds the information of an abbrev. */
193 unsigned int number
; /* number identifying abbrev */
194 enum dwarf_tag tag
; /* dwarf tag */
195 int has_children
; /* boolean */
196 unsigned int num_attrs
; /* number of attributes */
197 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
198 struct abbrev_info
*next
; /* next in chain */
203 enum dwarf_attribute name
;
204 enum dwarf_form form
;
207 /* This data structure holds a complete die structure. */
210 enum dwarf_tag tag
; /* Tag indicating type of die */
211 unsigned short has_children
; /* Does the die have children */
212 unsigned int abbrev
; /* Abbrev number */
213 unsigned int offset
; /* Offset in .debug_info section */
214 unsigned int num_attrs
; /* Number of attributes */
215 struct attribute
*attrs
; /* An array of attributes */
216 struct die_info
*next_ref
; /* Next die in ref hash table */
217 struct die_info
*next
; /* Next die in linked list */
218 struct type
*type
; /* Cached type information */
221 /* Attributes have a name and a value */
224 enum dwarf_attribute name
;
225 enum dwarf_form form
;
229 struct dwarf_block
*blk
;
237 /* Get at parts of an attribute structure */
239 #define DW_STRING(attr) ((attr)->u.str)
240 #define DW_UNSND(attr) ((attr)->u.unsnd)
241 #define DW_BLOCK(attr) ((attr)->u.blk)
242 #define DW_SND(attr) ((attr)->u.snd)
243 #define DW_ADDR(attr) ((attr)->u.addr)
245 /* Blocks are a bunch of untyped bytes. */
252 /* We only hold one compilation unit's abbrevs in
253 memory at any one time. */
254 #ifndef ABBREV_HASH_SIZE
255 #define ABBREV_HASH_SIZE 121
257 #ifndef ATTR_ALLOC_CHUNK
258 #define ATTR_ALLOC_CHUNK 4
261 static struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
263 /* A hash table of die offsets for following references. */
264 #ifndef REF_HASH_SIZE
265 #define REF_HASH_SIZE 1021
268 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
270 /* Obstack for allocating temporary storage used during symbol reading. */
271 static struct obstack dwarf2_tmp_obstack
;
273 /* Offset to the first byte of the current compilation unit header,
274 for resolving relative reference dies. */
275 static unsigned int cu_header_offset
;
277 /* Allocate fields for structs, unions and enums in this size. */
278 #ifndef DW_FIELD_ALLOC_CHUNK
279 #define DW_FIELD_ALLOC_CHUNK 4
282 /* The language we are debugging. */
283 static enum language cu_language
;
284 static const struct language_defn
*cu_language_defn
;
286 /* Actually data from the sections. */
287 static char *dwarf_info_buffer
;
288 static char *dwarf_abbrev_buffer
;
289 static char *dwarf_line_buffer
;
291 /* A zeroed version of a partial die for initialization purposes. */
292 static struct partial_die_info zeroed_partial_die
;
294 /* The generic symbol table building routines have separate lists for
295 file scope symbols and all all other scopes (local scopes). So
296 we need to select the right one to pass to add_symbol_to_list().
297 We do it by keeping a pointer to the correct list in list_in_scope.
299 FIXME: The original dwarf code just treated the file scope as the first
300 local scope, and all other local scopes as nested local scopes, and worked
301 fine. Check to see if we really need to distinguish these
303 static struct pending
**list_in_scope
= &file_symbols
;
305 /* FIXME: decode_locdesc sets these variables to describe the location
306 to the caller. These ought to be a structure or something. If
307 none of the flags are set, the object lives at the address returned
308 by decode_locdesc. */
310 static int optimized_out
; /* No ops in location in expression,
311 so object was optimized out. */
312 static int isreg
; /* Object lives in register.
313 decode_locdesc's return value is
314 the register number. */
315 static int offreg
; /* Object's address is the sum of the
316 register specified by basereg, plus
317 the offset returned. */
318 static int basereg
; /* See `offreg'. */
319 static int isderef
; /* Value described by flags above is
320 the address of a pointer to the object. */
321 static int islocal
; /* Variable is at the returned offset
322 from the frame start, but there's
323 no identified frame pointer for
324 this function, so we can't say
325 which register it's relative to;
328 /* DW_AT_frame_base values for the current function.
329 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
330 contains the register number for the frame register.
331 frame_base_offset is the offset from the frame register to the
332 virtual stack frame. */
333 static int frame_base_reg
;
334 static CORE_ADDR frame_base_offset
;
336 /* This value is added to each symbol value. FIXME: Generalize to
337 the section_offsets structure used by dbxread (once this is done,
338 pass the appropriate section number to end_symtab). */
339 static CORE_ADDR baseaddr
; /* Add to each symbol value */
341 /* We put a pointer to this structure in the read_symtab_private field
343 The complete dwarf information for an objfile is kept in the
344 psymbol_obstack, so that absolute die references can be handled.
345 Most of the information in this structure is related to an entire
346 object file and could be passed via the sym_private field of the objfile.
347 It is however conceivable that dwarf2 might not be the only type
348 of symbols read from an object file. */
352 /* Pointer to start of dwarf info buffer for the objfile. */
354 char *dwarf_info_buffer
;
356 /* Offset in dwarf_info_buffer for this compilation unit. */
358 unsigned long dwarf_info_offset
;
360 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
362 char *dwarf_abbrev_buffer
;
364 /* Size of dwarf abbreviation section for the objfile. */
366 unsigned int dwarf_abbrev_size
;
368 /* Pointer to start of dwarf line buffer for the objfile. */
370 char *dwarf_line_buffer
;
373 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
374 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
375 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
376 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
377 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
378 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
380 /* Maintain an array of referenced fundamental types for the current
381 compilation unit being read. For DWARF version 1, we have to construct
382 the fundamental types on the fly, since no information about the
383 fundamental types is supplied. Each such fundamental type is created by
384 calling a language dependent routine to create the type, and then a
385 pointer to that type is then placed in the array at the index specified
386 by it's FT_<TYPENAME> value. The array has a fixed size set by the
387 FT_NUM_MEMBERS compile time constant, which is the number of predefined
388 fundamental types gdb knows how to construct. */
389 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
391 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
392 but this would require a corresponding change in unpack_field_as_long
394 static int bits_per_byte
= 8;
396 /* The routines that read and process dies for a C struct or C++ class
397 pass lists of data member fields and lists of member function fields
398 in an instance of a field_info structure, as defined below. */
401 /* List of data member and baseclasses fields. */
404 struct nextfield
*next
;
411 /* Number of fields. */
414 /* Number of baseclasses. */
417 /* Set if the accesibility of one of the fields is not public. */
418 int non_public_fields
;
420 /* Member function fields array, entries are allocated in the order they
421 are encountered in the object file. */
424 struct nextfnfield
*next
;
425 struct fn_field fnfield
;
429 /* Member function fieldlist array, contains name of possibly overloaded
430 member function, number of overloaded member functions and a pointer
431 to the head of the member function field chain. */
436 struct nextfnfield
*head
;
440 /* Number of entries in the fnfieldlists array. */
444 /* FIXME: Kludge to mark a varargs function type for C++ member function
445 argument processing. */
446 #define TYPE_FLAG_VARARGS (1 << 10)
448 /* Dwarf2 has no clean way to discern C++ static and non-static member
449 functions. G++ helps GDB by marking the first parameter for non-static
450 member functions (which is the this pointer) as artificial.
451 We pass this information between dwarf2_add_member_fn and
452 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
453 #define TYPE_FIELD_ARTIFICIAL TYPE_FIELD_BITPOS
455 /* Various complaints about symbol reading that don't abort the process */
457 static struct complaint dwarf2_const_ignored
=
459 "type qualifier 'const' ignored", 0, 0
461 static struct complaint dwarf2_volatile_ignored
=
463 "type qualifier 'volatile' ignored", 0, 0
465 static struct complaint dwarf2_non_const_array_bound_ignored
=
467 "non-constant array bounds form '%s' ignored", 0, 0
469 static struct complaint dwarf2_missing_line_number_section
=
471 "missing .debug_line section", 0, 0
473 static struct complaint dwarf2_mangled_line_number_section
=
475 "mangled .debug_line section", 0, 0
477 static struct complaint dwarf2_unsupported_die_ref_attr
=
479 "unsupported die ref attribute form: '%s'", 0, 0
481 static struct complaint dwarf2_unsupported_stack_op
=
483 "unsupported stack op: '%s'", 0, 0
485 static struct complaint dwarf2_complex_location_expr
=
487 "location expression too complex", 0, 0
489 static struct complaint dwarf2_unsupported_tag
=
491 "unsupported tag: '%s'", 0, 0
493 static struct complaint dwarf2_unsupported_at_encoding
=
495 "unsupported DW_AT_encoding: '%s'", 0, 0
497 static struct complaint dwarf2_unsupported_at_frame_base
=
499 "unsupported DW_AT_frame_base for function '%s'", 0, 0
501 static struct complaint dwarf2_unexpected_tag
=
503 "unexepected tag in read_type_die: '%s'", 0, 0
505 static struct complaint dwarf2_missing_at_frame_base
=
507 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
509 static struct complaint dwarf2_bad_static_member_name
=
511 "unrecognized static data member name '%s'", 0, 0
513 static struct complaint dwarf2_unsupported_accessibility
=
515 "unsupported accessibility %d", 0, 0
517 static struct complaint dwarf2_bad_member_name_complaint
=
519 "cannot extract member name from '%s'", 0, 0
521 static struct complaint dwarf2_missing_member_fn_type_complaint
=
523 "member function type missing for '%s'", 0, 0
525 static struct complaint dwarf2_vtbl_not_found_complaint
=
527 "virtual function table pointer not found when defining class '%s'", 0, 0
529 static struct complaint dwarf2_absolute_sibling_complaint
=
531 "ignoring absolute DW_AT_sibling", 0, 0
533 static struct complaint dwarf2_const_value_length_mismatch
=
535 "const value length mismatch for '%s', got %d, expected %d", 0, 0
537 static struct complaint dwarf2_unsupported_const_value_attr
=
539 "unsupported const value attribute form: '%s'", 0, 0
542 /* Remember the addr_size read from the dwarf.
543 If a target expects to link compilation units with differing address
544 sizes, gdb needs to be sure that the appropriate size is here for
545 whatever scope is currently getting read. */
546 static int address_size
;
548 /* Externals references. */
549 extern int info_verbose
; /* From main.c; nonzero => verbose */
551 /* local function prototypes */
553 static void dwarf2_locate_sections
PARAMS ((bfd
*, asection
*, PTR
));
556 static void dwarf2_build_psymtabs_easy
PARAMS ((struct objfile
*, int));
559 static void dwarf2_build_psymtabs_hard
PARAMS ((struct objfile
*, int));
561 static char *scan_partial_symbols
PARAMS ((char *, struct objfile
*,
562 CORE_ADDR
*, CORE_ADDR
*));
564 static void add_partial_symbol
PARAMS ((struct partial_die_info
*,
567 static void dwarf2_psymtab_to_symtab
PARAMS ((struct partial_symtab
*));
569 static void psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*));
571 static char *dwarf2_read_section
PARAMS ((struct objfile
*, file_ptr
,
574 static void dwarf2_read_abbrevs
PARAMS ((bfd
*, unsigned int));
576 static void dwarf2_empty_abbrev_table
PARAMS ((PTR
));
578 static struct abbrev_info
*dwarf2_lookup_abbrev
PARAMS ((unsigned int));
580 static char *read_partial_die
PARAMS ((struct partial_die_info
*,
581 bfd
*, char *, int *));
583 static char *read_full_die
PARAMS ((struct die_info
**, bfd
*, char *));
585 static char *read_attribute
PARAMS ((struct attribute
*, struct attr_abbrev
*,
588 static unsigned int read_1_byte
PARAMS ((bfd
*, char *));
590 static int read_1_signed_byte
PARAMS ((bfd
*, char *));
592 static unsigned int read_2_bytes
PARAMS ((bfd
*, char *));
594 static unsigned int read_4_bytes
PARAMS ((bfd
*, char *));
596 static unsigned int read_8_bytes
PARAMS ((bfd
*, char *));
598 static CORE_ADDR read_address
PARAMS ((bfd
*, char *));
600 static char *read_n_bytes
PARAMS ((bfd
*, char *, unsigned int));
602 static char *read_string
PARAMS ((bfd
*, char *, unsigned int *));
604 static unsigned int read_unsigned_leb128
PARAMS ((bfd
*, char *,
607 static int read_signed_leb128
PARAMS ((bfd
*, char *, unsigned int *));
609 static void set_cu_language
PARAMS ((unsigned int));
611 static struct attribute
*dwarf_attr
PARAMS ((struct die_info
*,
614 static int die_is_declaration (struct die_info
*);
616 static void dwarf_decode_lines
PARAMS ((unsigned int, char *, bfd
*));
618 static void dwarf2_start_subfile
PARAMS ((char *, char *));
620 static struct symbol
*new_symbol
PARAMS ((struct die_info
*, struct type
*,
623 static void dwarf2_const_value
PARAMS ((struct attribute
*, struct symbol
*,
626 static void dwarf2_const_value_data (struct attribute
*attr
,
630 static struct type
*die_type
PARAMS ((struct die_info
*, struct objfile
*));
632 static struct type
*die_containing_type
PARAMS ((struct die_info
*,
636 static struct type
*type_at_offset
PARAMS ((unsigned int, struct objfile
*));
639 static struct type
*tag_type_to_type
PARAMS ((struct die_info
*,
642 static void read_type_die
PARAMS ((struct die_info
*, struct objfile
*));
644 static void read_typedef
PARAMS ((struct die_info
*, struct objfile
*));
646 static void read_base_type
PARAMS ((struct die_info
*, struct objfile
*));
648 static void read_file_scope
PARAMS ((struct die_info
*, struct objfile
*));
650 static void read_func_scope
PARAMS ((struct die_info
*, struct objfile
*));
652 static void read_lexical_block_scope
PARAMS ((struct die_info
*,
655 static int dwarf2_get_pc_bounds
PARAMS ((struct die_info
*,
656 CORE_ADDR
*, CORE_ADDR
*,
659 static void dwarf2_add_field
PARAMS ((struct field_info
*, struct die_info
*,
662 static void dwarf2_attach_fields_to_type
PARAMS ((struct field_info
*,
666 static void dwarf2_add_member_fn
PARAMS ((struct field_info
*,
667 struct die_info
*, struct type
*,
668 struct objfile
* objfile
));
670 static void dwarf2_attach_fn_fields_to_type
PARAMS ((struct field_info
*,
674 static void read_structure_scope
PARAMS ((struct die_info
*, struct objfile
*));
676 static void read_common_block
PARAMS ((struct die_info
*, struct objfile
*));
678 static void read_enumeration
PARAMS ((struct die_info
*, struct objfile
*));
680 static struct type
*dwarf_base_type
PARAMS ((int, int, struct objfile
*));
682 static CORE_ADDR decode_locdesc
PARAMS ((struct dwarf_block
*,
685 static void read_array_type
PARAMS ((struct die_info
*, struct objfile
*));
687 static void read_tag_pointer_type
PARAMS ((struct die_info
*,
690 static void read_tag_ptr_to_member_type
PARAMS ((struct die_info
*,
693 static void read_tag_reference_type
PARAMS ((struct die_info
*,
696 static void read_tag_const_type
PARAMS ((struct die_info
*, struct objfile
*));
698 static void read_tag_volatile_type
PARAMS ((struct die_info
*,
701 static void read_tag_string_type
PARAMS ((struct die_info
*,
704 static void read_subroutine_type
PARAMS ((struct die_info
*,
707 struct die_info
*read_comp_unit
PARAMS ((char *, bfd
*));
709 static void free_die_list
PARAMS ((struct die_info
*));
711 static void process_die
PARAMS ((struct die_info
*, struct objfile
*));
713 static char *dwarf2_linkage_name
PARAMS ((struct die_info
*));
715 static char *dwarf_tag_name
PARAMS ((unsigned int));
717 static char *dwarf_attr_name
PARAMS ((unsigned int));
719 static char *dwarf_form_name
PARAMS ((unsigned int));
721 static char *dwarf_stack_op_name
PARAMS ((unsigned int));
723 static char *dwarf_bool_name
PARAMS ((unsigned int));
725 static char *dwarf_type_encoding_name
PARAMS ((unsigned int));
728 static char *dwarf_cfi_name
PARAMS ((unsigned int));
730 struct die_info
*copy_die
PARAMS ((struct die_info
*));
733 struct die_info
*sibling_die
PARAMS ((struct die_info
*));
735 void dump_die
PARAMS ((struct die_info
*));
737 void dump_die_list
PARAMS ((struct die_info
*));
739 void store_in_ref_table
PARAMS ((unsigned int, struct die_info
*));
741 static void dwarf2_empty_die_ref_table
PARAMS ((void));
743 static unsigned int dwarf2_get_ref_die_offset
PARAMS ((struct attribute
*));
745 struct die_info
*follow_die_ref
PARAMS ((unsigned int));
747 static struct type
*dwarf2_fundamental_type
PARAMS ((struct objfile
*, int));
749 /* memory allocation interface */
751 static void dwarf2_free_tmp_obstack
PARAMS ((PTR
));
753 static struct dwarf_block
*dwarf_alloc_block
PARAMS ((void));
755 static struct abbrev_info
*dwarf_alloc_abbrev
PARAMS ((void));
757 static struct die_info
*dwarf_alloc_die
PARAMS ((void));
759 /* Try to locate the sections we need for DWARF 2 debugging
760 information and return true if we have enough to do something. */
763 dwarf2_has_info (abfd
)
766 dwarf_info_offset
= dwarf_abbrev_offset
= dwarf_line_offset
= 0;
767 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
768 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
778 /* This function is mapped across the sections and remembers the
779 offset and size of each of the debugging sections we are interested
783 dwarf2_locate_sections (ignore_abfd
, sectp
, ignore_ptr
)
788 if (STREQ (sectp
->name
, INFO_SECTION
))
790 dwarf_info_offset
= sectp
->filepos
;
791 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
793 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
795 dwarf_abbrev_offset
= sectp
->filepos
;
796 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
798 else if (STREQ (sectp
->name
, LINE_SECTION
))
800 dwarf_line_offset
= sectp
->filepos
;
801 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
803 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
805 dwarf_pubnames_offset
= sectp
->filepos
;
806 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
808 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
810 dwarf_aranges_offset
= sectp
->filepos
;
811 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
813 else if (STREQ (sectp
->name
, LOC_SECTION
))
815 dwarf_loc_offset
= sectp
->filepos
;
816 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
818 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
820 dwarf_macinfo_offset
= sectp
->filepos
;
821 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
823 else if (STREQ (sectp
->name
, STR_SECTION
))
825 dwarf_str_offset
= sectp
->filepos
;
826 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
830 /* Build a partial symbol table. */
833 dwarf2_build_psymtabs (objfile
, mainline
)
834 struct objfile
*objfile
;
838 /* We definitely need the .debug_info and .debug_abbrev sections */
840 dwarf_info_buffer
= dwarf2_read_section (objfile
,
843 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
846 dwarf_line_buffer
= dwarf2_read_section (objfile
,
850 if (mainline
|| objfile
->global_psymbols
.size
== 0 ||
851 objfile
->static_psymbols
.size
== 0)
853 init_psymbol_list (objfile
, 1024);
857 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
859 /* Things are significantly easier if we have .debug_aranges and
860 .debug_pubnames sections */
862 dwarf2_build_psymtabs_easy (objfile
, mainline
);
866 /* only test this case for now */
868 /* In this case we have to work a bit harder */
869 dwarf2_build_psymtabs_hard (objfile
, mainline
);
874 /* Build the partial symbol table from the information in the
875 .debug_pubnames and .debug_aranges sections. */
878 dwarf2_build_psymtabs_easy (objfile
, mainline
)
879 struct objfile
*objfile
;
882 bfd
*abfd
= objfile
->obfd
;
883 char *aranges_buffer
, *pubnames_buffer
;
884 char *aranges_ptr
, *pubnames_ptr
;
885 unsigned int entry_length
, version
, info_offset
, info_size
;
887 pubnames_buffer
= dwarf2_read_section (objfile
,
888 dwarf_pubnames_offset
,
889 dwarf_pubnames_size
);
890 pubnames_ptr
= pubnames_buffer
;
891 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
893 entry_length
= read_4_bytes (abfd
, pubnames_ptr
);
895 version
= read_1_byte (abfd
, pubnames_ptr
);
897 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
899 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
903 aranges_buffer
= dwarf2_read_section (objfile
,
904 dwarf_aranges_offset
,
910 /* Build the partial symbol table by doing a quick pass through the
911 .debug_info and .debug_abbrev sections. */
914 dwarf2_build_psymtabs_hard (objfile
, mainline
)
915 struct objfile
*objfile
;
918 /* Instead of reading this into a big buffer, we should probably use
919 mmap() on architectures that support it. (FIXME) */
920 bfd
*abfd
= objfile
->obfd
;
921 char *info_ptr
, *abbrev_ptr
;
922 char *beg_of_comp_unit
;
923 struct comp_unit_head cu_header
;
924 struct partial_die_info comp_unit_die
;
925 struct partial_symtab
*pst
;
926 struct cleanup
*back_to
;
927 int comp_unit_has_pc_info
;
928 CORE_ADDR lowpc
, highpc
;
930 info_ptr
= dwarf_info_buffer
;
931 abbrev_ptr
= dwarf_abbrev_buffer
;
933 obstack_init (&dwarf2_tmp_obstack
);
934 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
936 while ((unsigned int) (info_ptr
- dwarf_info_buffer
)
937 + ((info_ptr
- dwarf_info_buffer
) % 4) < dwarf_info_size
)
939 beg_of_comp_unit
= info_ptr
;
940 cu_header
.length
= read_4_bytes (abfd
, info_ptr
);
942 cu_header
.version
= read_2_bytes (abfd
, info_ptr
);
944 cu_header
.abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
946 cu_header
.addr_size
= read_1_byte (abfd
, info_ptr
);
948 address_size
= cu_header
.addr_size
;
950 if (cu_header
.version
!= 2)
952 error ("Dwarf Error: wrong version in compilation unit header.");
955 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
957 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
958 (long) cu_header
.abbrev_offset
,
959 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
962 if (beg_of_comp_unit
+ cu_header
.length
+ 4
963 > dwarf_info_buffer
+ dwarf_info_size
)
965 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
966 (long) cu_header
.length
,
967 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
970 /* Read the abbrevs for this compilation unit into a table */
971 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
972 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
974 /* Read the compilation unit die */
975 info_ptr
= read_partial_die (&comp_unit_die
, abfd
,
976 info_ptr
, &comp_unit_has_pc_info
);
978 /* Set the language we're debugging */
979 set_cu_language (comp_unit_die
.language
);
981 /* Allocate a new partial symbol table structure */
982 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
983 comp_unit_die
.name
? comp_unit_die
.name
: "",
985 objfile
->global_psymbols
.next
,
986 objfile
->static_psymbols
.next
);
988 pst
->read_symtab_private
= (char *)
989 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
990 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
991 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
992 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
993 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
994 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
995 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
996 baseaddr
= ANOFFSET (objfile
->section_offsets
, 0);
998 /* Store the function that reads in the rest of the symbol table */
999 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1001 /* Check if comp unit has_children.
1002 If so, read the rest of the partial symbols from this comp unit.
1003 If not, there's no more debug_info for this comp unit. */
1004 if (comp_unit_die
.has_children
)
1006 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
);
1008 /* If the compilation unit didn't have an explicit address range,
1009 then use the information extracted from its child dies. */
1010 if (!comp_unit_has_pc_info
)
1012 comp_unit_die
.lowpc
= lowpc
;
1013 comp_unit_die
.highpc
= highpc
;
1016 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1017 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1019 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1020 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1021 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1022 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1023 sort_pst_symbols (pst
);
1025 /* If there is already a psymtab or symtab for a file of this
1026 name, remove it. (If there is a symtab, more drastic things
1027 also happen.) This happens in VxWorks. */
1028 free_named_symtabs (pst
->filename
);
1030 info_ptr
= beg_of_comp_unit
+ cu_header
.length
+ 4;
1032 do_cleanups (back_to
);
1035 /* Read in all interesting dies to the end of the compilation unit. */
1038 scan_partial_symbols (info_ptr
, objfile
, lowpc
, highpc
)
1040 struct objfile
*objfile
;
1044 bfd
*abfd
= objfile
->obfd
;
1045 struct partial_die_info pdi
;
1047 /* This function is called after we've read in the comp_unit_die in
1048 order to read its children. We start the nesting level at 1 since
1049 we have pushed 1 level down in order to read the comp unit's children.
1050 The comp unit itself is at level 0, so we stop reading when we pop
1051 back to that level. */
1053 int nesting_level
= 1;
1056 *lowpc
= ((CORE_ADDR
) -1);
1057 *highpc
= ((CORE_ADDR
) 0);
1059 while (nesting_level
)
1061 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, &has_pc_info
);
1067 case DW_TAG_subprogram
:
1070 if (pdi
.lowpc
< *lowpc
)
1074 if (pdi
.highpc
> *highpc
)
1076 *highpc
= pdi
.highpc
;
1078 if ((pdi
.is_external
|| nesting_level
== 1)
1079 && !pdi
.is_declaration
)
1081 add_partial_symbol (&pdi
, objfile
);
1085 case DW_TAG_variable
:
1086 case DW_TAG_typedef
:
1087 case DW_TAG_class_type
:
1088 case DW_TAG_structure_type
:
1089 case DW_TAG_union_type
:
1090 case DW_TAG_enumeration_type
:
1091 if ((pdi
.is_external
|| nesting_level
== 1)
1092 && !pdi
.is_declaration
)
1094 add_partial_symbol (&pdi
, objfile
);
1097 case DW_TAG_enumerator
:
1098 /* File scope enumerators are added to the partial symbol
1100 if (nesting_level
== 2)
1101 add_partial_symbol (&pdi
, objfile
);
1103 case DW_TAG_base_type
:
1104 /* File scope base type definitions are added to the partial
1106 if (nesting_level
== 1)
1107 add_partial_symbol (&pdi
, objfile
);
1114 /* If the die has a sibling, skip to the sibling.
1115 Do not skip enumeration types, we want to record their
1117 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1119 info_ptr
= pdi
.sibling
;
1121 else if (pdi
.has_children
)
1123 /* Die has children, but the optional DW_AT_sibling attribute
1134 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1135 from `maint check'. */
1136 if (*lowpc
== ((CORE_ADDR
) -1))
1142 add_partial_symbol (pdi
, objfile
)
1143 struct partial_die_info
*pdi
;
1144 struct objfile
*objfile
;
1150 case DW_TAG_subprogram
:
1151 if (pdi
->is_external
)
1153 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1154 mst_text, objfile); */
1155 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1156 VAR_NAMESPACE
, LOC_BLOCK
,
1157 &objfile
->global_psymbols
,
1158 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1162 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1163 mst_file_text, objfile); */
1164 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1165 VAR_NAMESPACE
, LOC_BLOCK
,
1166 &objfile
->static_psymbols
,
1167 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1170 case DW_TAG_variable
:
1171 if (pdi
->is_external
)
1174 Don't enter into the minimal symbol tables as there is
1175 a minimal symbol table entry from the ELF symbols already.
1176 Enter into partial symbol table if it has a location
1177 descriptor or a type.
1178 If the location descriptor is missing, new_symbol will create
1179 a LOC_UNRESOLVED symbol, the address of the variable will then
1180 be determined from the minimal symbol table whenever the variable
1182 The address for the partial symbol table entry is not
1183 used by GDB, but it comes in handy for debugging partial symbol
1187 addr
= decode_locdesc (pdi
->locdesc
, objfile
);
1188 if (pdi
->locdesc
|| pdi
->has_type
)
1189 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1190 VAR_NAMESPACE
, LOC_STATIC
,
1191 &objfile
->global_psymbols
,
1192 0, addr
+ baseaddr
, cu_language
, objfile
);
1196 /* Static Variable. Skip symbols without location descriptors. */
1197 if (pdi
->locdesc
== NULL
)
1199 addr
= decode_locdesc (pdi
->locdesc
, objfile
);
1200 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1201 mst_file_data, objfile); */
1202 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1203 VAR_NAMESPACE
, LOC_STATIC
,
1204 &objfile
->static_psymbols
,
1205 0, addr
+ baseaddr
, cu_language
, objfile
);
1208 case DW_TAG_typedef
:
1209 case DW_TAG_base_type
:
1210 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1211 VAR_NAMESPACE
, LOC_TYPEDEF
,
1212 &objfile
->static_psymbols
,
1213 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1215 case DW_TAG_class_type
:
1216 case DW_TAG_structure_type
:
1217 case DW_TAG_union_type
:
1218 case DW_TAG_enumeration_type
:
1219 /* Skip aggregate types without children, these are external
1221 if (pdi
->has_children
== 0)
1223 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1224 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1225 &objfile
->static_psymbols
,
1226 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1228 if (cu_language
== language_cplus
)
1230 /* For C++, these implicitly act as typedefs as well. */
1231 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1232 VAR_NAMESPACE
, LOC_TYPEDEF
,
1233 &objfile
->static_psymbols
,
1234 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1237 case DW_TAG_enumerator
:
1238 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1239 VAR_NAMESPACE
, LOC_CONST
,
1240 &objfile
->static_psymbols
,
1241 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1248 /* Expand this partial symbol table into a full symbol table. */
1251 dwarf2_psymtab_to_symtab (pst
)
1252 struct partial_symtab
*pst
;
1254 /* FIXME: This is barely more than a stub. */
1259 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1265 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1266 gdb_flush (gdb_stdout
);
1269 psymtab_to_symtab_1 (pst
);
1271 /* Finish up the debug error message. */
1273 printf_filtered ("done.\n");
1279 psymtab_to_symtab_1 (pst
)
1280 struct partial_symtab
*pst
;
1282 struct objfile
*objfile
= pst
->objfile
;
1283 bfd
*abfd
= objfile
->obfd
;
1284 struct comp_unit_head cu_header
;
1285 struct die_info
*dies
;
1286 unsigned long offset
;
1287 CORE_ADDR lowpc
, highpc
;
1288 struct die_info
*child_die
;
1290 struct symtab
*symtab
;
1291 struct cleanup
*back_to
;
1293 /* Set local variables from the partial symbol table info. */
1294 offset
= DWARF_INFO_OFFSET (pst
);
1295 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1296 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1297 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1298 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1299 baseaddr
= ANOFFSET (pst
->section_offsets
, 0);
1300 cu_header_offset
= offset
;
1301 info_ptr
= dwarf_info_buffer
+ offset
;
1303 obstack_init (&dwarf2_tmp_obstack
);
1304 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1307 make_cleanup (really_free_pendings
, NULL
);
1309 /* read in the comp_unit header */
1310 cu_header
.length
= read_4_bytes (abfd
, info_ptr
);
1312 cu_header
.version
= read_2_bytes (abfd
, info_ptr
);
1314 cu_header
.abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
1316 cu_header
.addr_size
= read_1_byte (abfd
, info_ptr
);
1319 /* Read the abbrevs for this compilation unit */
1320 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1321 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1323 dies
= read_comp_unit (info_ptr
, abfd
);
1325 make_cleanup ((make_cleanup_func
) free_die_list
, dies
);
1327 /* Do line number decoding in read_file_scope () */
1328 process_die (dies
, objfile
);
1330 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1332 /* Some compilers don't define a DW_AT_high_pc attribute for
1333 the compilation unit. If the DW_AT_high_pc is missing,
1334 synthesize it, by scanning the DIE's below the compilation unit. */
1336 if (dies
->has_children
)
1338 child_die
= dies
->next
;
1339 while (child_die
&& child_die
->tag
)
1341 if (child_die
->tag
== DW_TAG_subprogram
)
1343 CORE_ADDR low
, high
;
1345 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1347 highpc
= max (highpc
, high
);
1350 child_die
= sibling_die (child_die
);
1354 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, 0);
1356 /* Set symtab language to language from DW_AT_language.
1357 If the compilation is from a C file generated by language preprocessors,
1358 do not set the language if it was already deduced by start_subfile. */
1360 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1362 symtab
->language
= cu_language
;
1364 pst
->symtab
= symtab
;
1366 sort_symtab_syms (pst
->symtab
);
1368 do_cleanups (back_to
);
1371 /* Process a die and its children. */
1374 process_die (die
, objfile
)
1375 struct die_info
*die
;
1376 struct objfile
*objfile
;
1380 case DW_TAG_padding
:
1382 case DW_TAG_compile_unit
:
1383 read_file_scope (die
, objfile
);
1385 case DW_TAG_subprogram
:
1386 read_subroutine_type (die
, objfile
);
1387 read_func_scope (die
, objfile
);
1389 case DW_TAG_inlined_subroutine
:
1390 /* FIXME: These are ignored for now.
1391 They could be used to set breakpoints on all inlined instances
1392 of a function and make GDB `next' properly over inlined functions. */
1394 case DW_TAG_lexical_block
:
1395 read_lexical_block_scope (die
, objfile
);
1397 case DW_TAG_class_type
:
1398 case DW_TAG_structure_type
:
1399 case DW_TAG_union_type
:
1400 read_structure_scope (die
, objfile
);
1402 case DW_TAG_enumeration_type
:
1403 read_enumeration (die
, objfile
);
1405 case DW_TAG_subroutine_type
:
1406 read_subroutine_type (die
, objfile
);
1408 case DW_TAG_array_type
:
1409 read_array_type (die
, objfile
);
1411 case DW_TAG_pointer_type
:
1412 read_tag_pointer_type (die
, objfile
);
1414 case DW_TAG_ptr_to_member_type
:
1415 read_tag_ptr_to_member_type (die
, objfile
);
1417 case DW_TAG_reference_type
:
1418 read_tag_reference_type (die
, objfile
);
1420 case DW_TAG_string_type
:
1421 read_tag_string_type (die
, objfile
);
1423 case DW_TAG_base_type
:
1424 read_base_type (die
, objfile
);
1425 if (dwarf_attr (die
, DW_AT_name
))
1427 /* Add a typedef symbol for the base type definition. */
1428 new_symbol (die
, die
->type
, objfile
);
1431 case DW_TAG_common_block
:
1432 read_common_block (die
, objfile
);
1434 case DW_TAG_common_inclusion
:
1437 new_symbol (die
, NULL
, objfile
);
1443 read_file_scope (die
, objfile
)
1444 struct die_info
*die
;
1445 struct objfile
*objfile
;
1447 unsigned int line_offset
= 0;
1448 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1449 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1450 struct attribute
*attr
;
1451 char *name
= "<unknown>";
1452 char *comp_dir
= NULL
;
1453 struct die_info
*child_die
;
1454 bfd
*abfd
= objfile
->obfd
;
1456 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1458 if (die
->has_children
)
1460 child_die
= die
->next
;
1461 while (child_die
&& child_die
->tag
)
1463 if (child_die
->tag
== DW_TAG_subprogram
)
1465 CORE_ADDR low
, high
;
1467 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1469 lowpc
= min (lowpc
, low
);
1470 highpc
= max (highpc
, high
);
1473 child_die
= sibling_die (child_die
);
1478 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1479 from finish_block. */
1480 if (lowpc
== ((CORE_ADDR
) -1))
1485 attr
= dwarf_attr (die
, DW_AT_name
);
1488 name
= DW_STRING (attr
);
1490 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1493 comp_dir
= DW_STRING (attr
);
1496 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1497 directory, get rid of it. */
1498 char *cp
= strchr (comp_dir
, ':');
1500 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1505 if (objfile
->ei
.entry_point
>= lowpc
&&
1506 objfile
->ei
.entry_point
< highpc
)
1508 objfile
->ei
.entry_file_lowpc
= lowpc
;
1509 objfile
->ei
.entry_file_highpc
= highpc
;
1512 attr
= dwarf_attr (die
, DW_AT_language
);
1515 set_cu_language (DW_UNSND (attr
));
1518 /* We assume that we're processing GCC output. */
1519 processing_gcc_compilation
= 2;
1521 /* FIXME:Do something here. */
1522 if (dip
->at_producer
!= NULL
)
1524 handle_producer (dip
->at_producer
);
1528 /* The compilation unit may be in a different language or objfile,
1529 zero out all remembered fundamental types. */
1530 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1532 start_symtab (name
, comp_dir
, lowpc
);
1533 record_debugformat ("DWARF 2");
1535 /* Decode line number information if present. */
1536 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1539 line_offset
= DW_UNSND (attr
);
1540 dwarf_decode_lines (line_offset
, comp_dir
, abfd
);
1543 /* Process all dies in compilation unit. */
1544 if (die
->has_children
)
1546 child_die
= die
->next
;
1547 while (child_die
&& child_die
->tag
)
1549 process_die (child_die
, objfile
);
1550 child_die
= sibling_die (child_die
);
1556 read_func_scope (die
, objfile
)
1557 struct die_info
*die
;
1558 struct objfile
*objfile
;
1560 register struct context_stack
*new;
1563 struct die_info
*child_die
;
1564 struct attribute
*attr
;
1567 name
= dwarf2_linkage_name (die
);
1569 /* Ignore functions with missing or empty names and functions with
1570 missing or invalid low and high pc attributes. */
1571 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1577 if (objfile
->ei
.entry_point
>= lowpc
&&
1578 objfile
->ei
.entry_point
< highpc
)
1580 objfile
->ei
.entry_func_lowpc
= lowpc
;
1581 objfile
->ei
.entry_func_highpc
= highpc
;
1584 /* Decode DW_AT_frame_base location descriptor if present, keep result
1585 for DW_OP_fbreg operands in decode_locdesc. */
1586 frame_base_reg
= -1;
1587 frame_base_offset
= 0;
1588 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1591 CORE_ADDR addr
= decode_locdesc (DW_BLOCK (attr
), objfile
);
1593 complain (&dwarf2_unsupported_at_frame_base
, name
);
1595 frame_base_reg
= addr
;
1598 frame_base_reg
= basereg
;
1599 frame_base_offset
= addr
;
1602 complain (&dwarf2_unsupported_at_frame_base
, name
);
1605 new = push_context (0, lowpc
);
1606 new->name
= new_symbol (die
, die
->type
, objfile
);
1607 list_in_scope
= &local_symbols
;
1609 if (die
->has_children
)
1611 child_die
= die
->next
;
1612 while (child_die
&& child_die
->tag
)
1614 process_die (child_die
, objfile
);
1615 child_die
= sibling_die (child_die
);
1619 new = pop_context ();
1620 /* Make a block for the local symbols within. */
1621 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1622 lowpc
, highpc
, objfile
);
1623 list_in_scope
= &file_symbols
;
1626 /* Process all the DIES contained within a lexical block scope. Start
1627 a new scope, process the dies, and then close the scope. */
1630 read_lexical_block_scope (die
, objfile
)
1631 struct die_info
*die
;
1632 struct objfile
*objfile
;
1634 register struct context_stack
*new;
1635 CORE_ADDR lowpc
, highpc
;
1636 struct die_info
*child_die
;
1638 /* Ignore blocks with missing or invalid low and high pc attributes. */
1639 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1644 push_context (0, lowpc
);
1645 if (die
->has_children
)
1647 child_die
= die
->next
;
1648 while (child_die
&& child_die
->tag
)
1650 process_die (child_die
, objfile
);
1651 child_die
= sibling_die (child_die
);
1654 new = pop_context ();
1656 if (local_symbols
!= NULL
)
1658 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1661 local_symbols
= new->locals
;
1664 /* Get low and high pc attributes from a die.
1665 Return 1 if the attributes are present and valid, otherwise, return 0. */
1668 dwarf2_get_pc_bounds (die
, lowpc
, highpc
, objfile
)
1669 struct die_info
*die
;
1672 struct objfile
*objfile
;
1674 struct attribute
*attr
;
1678 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1680 low
= DW_ADDR (attr
);
1683 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1685 high
= DW_ADDR (attr
);
1692 /* When using the GNU linker, .gnu.linkonce. sections are used to
1693 eliminate duplicate copies of functions and vtables and such.
1694 The linker will arbitrarily choose one and discard the others.
1695 The AT_*_pc values for such functions refer to local labels in
1696 these sections. If the section from that file was discarded, the
1697 labels are not in the output, so the relocs get a value of 0.
1698 If this is a discarded function, mark the pc bounds as invalid,
1699 so that GDB will ignore it. */
1700 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
1708 /* Add an aggregate field to the field list. */
1711 dwarf2_add_field (fip
, die
, objfile
)
1712 struct field_info
*fip
;
1713 struct die_info
*die
;
1714 struct objfile
*objfile
;
1716 struct nextfield
*new_field
;
1717 struct attribute
*attr
;
1719 char *fieldname
= "";
1721 /* Allocate a new field list entry and link it in. */
1722 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1723 make_cleanup (free
, new_field
);
1724 memset (new_field
, 0, sizeof (struct nextfield
));
1725 new_field
->next
= fip
->fields
;
1726 fip
->fields
= new_field
;
1729 /* Handle accessibility and virtuality of field.
1730 The default accessibility for members is public, the default
1731 accessibility for inheritance is private. */
1732 if (die
->tag
!= DW_TAG_inheritance
)
1733 new_field
->accessibility
= DW_ACCESS_public
;
1735 new_field
->accessibility
= DW_ACCESS_private
;
1736 new_field
->virtuality
= DW_VIRTUALITY_none
;
1738 attr
= dwarf_attr (die
, DW_AT_accessibility
);
1740 new_field
->accessibility
= DW_UNSND (attr
);
1741 if (new_field
->accessibility
!= DW_ACCESS_public
)
1742 fip
->non_public_fields
= 1;
1743 attr
= dwarf_attr (die
, DW_AT_virtuality
);
1745 new_field
->virtuality
= DW_UNSND (attr
);
1747 fp
= &new_field
->field
;
1748 if (die
->tag
== DW_TAG_member
)
1750 /* Get type of field. */
1751 fp
->type
= die_type (die
, objfile
);
1753 /* Get bit size of field (zero if none). */
1754 attr
= dwarf_attr (die
, DW_AT_bit_size
);
1757 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
1761 FIELD_BITSIZE (*fp
) = 0;
1764 /* Get bit offset of field. */
1765 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1768 FIELD_BITPOS (*fp
) =
1769 decode_locdesc (DW_BLOCK (attr
), objfile
) * bits_per_byte
;
1772 FIELD_BITPOS (*fp
) = 0;
1773 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
1776 if (BITS_BIG_ENDIAN
)
1778 /* For big endian bits, the DW_AT_bit_offset gives the
1779 additional bit offset from the MSB of the containing
1780 anonymous object to the MSB of the field. We don't
1781 have to do anything special since we don't need to
1782 know the size of the anonymous object. */
1783 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
1787 /* For little endian bits, compute the bit offset to the
1788 MSB of the anonymous object, subtract off the number of
1789 bits from the MSB of the field to the MSB of the
1790 object, and then subtract off the number of bits of
1791 the field itself. The result is the bit offset of
1792 the LSB of the field. */
1794 int bit_offset
= DW_UNSND (attr
);
1796 attr
= dwarf_attr (die
, DW_AT_byte_size
);
1799 /* The size of the anonymous object containing
1800 the bit field is explicit, so use the
1801 indicated size (in bytes). */
1802 anonymous_size
= DW_UNSND (attr
);
1806 /* The size of the anonymous object containing
1807 the bit field must be inferred from the type
1808 attribute of the data member containing the
1810 anonymous_size
= TYPE_LENGTH (fp
->type
);
1812 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
1813 - bit_offset
- FIELD_BITSIZE (*fp
);
1817 /* Get name of field. */
1818 attr
= dwarf_attr (die
, DW_AT_name
);
1819 if (attr
&& DW_STRING (attr
))
1820 fieldname
= DW_STRING (attr
);
1821 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
1822 &objfile
->type_obstack
);
1824 /* Change accessibility for artificial fields (e.g. virtual table
1825 pointer or virtual base class pointer) to private. */
1826 if (dwarf_attr (die
, DW_AT_artificial
))
1828 new_field
->accessibility
= DW_ACCESS_private
;
1829 fip
->non_public_fields
= 1;
1832 else if (die
->tag
== DW_TAG_variable
)
1836 /* C++ static member.
1837 Get name of field. */
1838 attr
= dwarf_attr (die
, DW_AT_name
);
1839 if (attr
&& DW_STRING (attr
))
1840 fieldname
= DW_STRING (attr
);
1844 /* Get physical name. */
1845 physname
= dwarf2_linkage_name (die
);
1847 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
1848 &objfile
->type_obstack
));
1849 FIELD_TYPE (*fp
) = die_type (die
, objfile
);
1850 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
1851 &objfile
->type_obstack
);
1853 else if (die
->tag
== DW_TAG_inheritance
)
1855 /* C++ base class field. */
1856 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1858 FIELD_BITPOS (*fp
) = decode_locdesc (DW_BLOCK (attr
), objfile
) * bits_per_byte
;
1859 FIELD_BITSIZE (*fp
) = 0;
1860 FIELD_TYPE (*fp
) = die_type (die
, objfile
);
1861 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
1862 fip
->nbaseclasses
++;
1866 /* Create the vector of fields, and attach it to the type. */
1869 dwarf2_attach_fields_to_type (fip
, type
, objfile
)
1870 struct field_info
*fip
;
1872 struct objfile
*objfile
;
1874 int nfields
= fip
->nfields
;
1876 /* Record the field count, allocate space for the array of fields,
1877 and create blank accessibility bitfields if necessary. */
1878 TYPE_NFIELDS (type
) = nfields
;
1879 TYPE_FIELDS (type
) = (struct field
*)
1880 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
1881 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
1883 if (fip
->non_public_fields
)
1885 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1887 TYPE_FIELD_PRIVATE_BITS (type
) =
1888 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1889 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
1891 TYPE_FIELD_PROTECTED_BITS (type
) =
1892 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1893 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
1895 TYPE_FIELD_IGNORE_BITS (type
) =
1896 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1897 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
1900 /* If the type has baseclasses, allocate and clear a bit vector for
1901 TYPE_FIELD_VIRTUAL_BITS. */
1902 if (fip
->nbaseclasses
)
1904 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
1907 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1908 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
1909 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
1910 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
1911 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
1914 /* Copy the saved-up fields into the field vector. Start from the head
1915 of the list, adding to the tail of the field array, so that they end
1916 up in the same order in the array in which they were added to the list. */
1917 while (nfields
-- > 0)
1919 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
1920 switch (fip
->fields
->accessibility
)
1922 case DW_ACCESS_private
:
1923 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
1926 case DW_ACCESS_protected
:
1927 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
1930 case DW_ACCESS_public
:
1934 /* Unknown accessibility. Complain and treat it as public. */
1936 complain (&dwarf2_unsupported_accessibility
,
1937 fip
->fields
->accessibility
);
1941 if (nfields
< fip
->nbaseclasses
)
1943 switch (fip
->fields
->virtuality
)
1945 case DW_VIRTUALITY_virtual
:
1946 case DW_VIRTUALITY_pure_virtual
:
1947 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
1951 fip
->fields
= fip
->fields
->next
;
1955 /* Add a member function to the proper fieldlist. */
1958 dwarf2_add_member_fn (fip
, die
, type
, objfile
)
1959 struct field_info
*fip
;
1960 struct die_info
*die
;
1962 struct objfile
*objfile
;
1964 struct attribute
*attr
;
1965 struct fnfieldlist
*flp
;
1967 struct fn_field
*fnp
;
1970 struct nextfnfield
*new_fnfield
;
1972 /* Get name of member function. */
1973 attr
= dwarf_attr (die
, DW_AT_name
);
1974 if (attr
&& DW_STRING (attr
))
1975 fieldname
= DW_STRING (attr
);
1979 /* Get the mangled name. */
1980 physname
= dwarf2_linkage_name (die
);
1982 /* Look up member function name in fieldlist. */
1983 for (i
= 0; i
< fip
->nfnfields
; i
++)
1985 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
1989 /* Create new list element if necessary. */
1990 if (i
< fip
->nfnfields
)
1991 flp
= &fip
->fnfieldlists
[i
];
1994 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
1996 fip
->fnfieldlists
= (struct fnfieldlist
*)
1997 xrealloc (fip
->fnfieldlists
,
1998 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
1999 * sizeof (struct fnfieldlist
));
2000 if (fip
->nfnfields
== 0)
2001 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2003 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2004 flp
->name
= fieldname
;
2010 /* Create a new member function field and chain it to the field list
2012 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2013 make_cleanup (free
, new_fnfield
);
2014 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2015 new_fnfield
->next
= flp
->head
;
2016 flp
->head
= new_fnfield
;
2019 /* Fill in the member function field info. */
2020 fnp
= &new_fnfield
->fnfield
;
2021 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2022 &objfile
->type_obstack
);
2023 fnp
->type
= alloc_type (objfile
);
2024 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2026 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2027 struct type
**arg_types
;
2028 int nparams
= TYPE_NFIELDS (die
->type
);
2031 /* Copy argument types from the subroutine type. */
2032 arg_types
= (struct type
**)
2033 TYPE_ALLOC (fnp
->type
, (nparams
+ 1) * sizeof (struct type
*));
2034 for (iparams
= 0; iparams
< nparams
; iparams
++)
2035 arg_types
[iparams
] = TYPE_FIELD_TYPE (die
->type
, iparams
);
2037 /* Set last entry in argument type vector. */
2038 if (TYPE_FLAGS (die
->type
) & TYPE_FLAG_VARARGS
)
2039 arg_types
[nparams
] = NULL
;
2041 arg_types
[nparams
] = dwarf2_fundamental_type (objfile
, FT_VOID
);
2043 smash_to_method_type (fnp
->type
, type
, return_type
, arg_types
);
2045 /* Handle static member functions.
2046 Dwarf2 has no clean way to discern C++ static and non-static
2047 member functions. G++ helps GDB by marking the first
2048 parameter for non-static member functions (which is the
2049 this pointer) as artificial. We obtain this information
2050 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2051 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2052 fnp
->voffset
= VOFFSET_STATIC
;
2055 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2057 /* Get fcontext from DW_AT_containing_type if present. */
2058 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2059 fnp
->fcontext
= die_containing_type (die
, objfile
);
2061 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2062 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2064 /* Get accessibility. */
2065 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2068 switch (DW_UNSND (attr
))
2070 case DW_ACCESS_private
:
2071 fnp
->is_private
= 1;
2073 case DW_ACCESS_protected
:
2074 fnp
->is_protected
= 1;
2079 /* Get index in virtual function table if it is a virtual member function. */
2080 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2082 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
) + 2;
2085 /* Create the vector of member function fields, and attach it to the type. */
2088 dwarf2_attach_fn_fields_to_type (fip
, type
, objfile
)
2089 struct field_info
*fip
;
2091 struct objfile
*objfile
;
2093 struct fnfieldlist
*flp
;
2094 int total_length
= 0;
2097 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2098 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2099 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2101 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2103 struct nextfnfield
*nfp
= flp
->head
;
2104 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2107 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2108 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2109 fn_flp
->fn_fields
= (struct fn_field
*)
2110 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2111 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2112 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2114 total_length
+= flp
->length
;
2117 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2118 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2121 /* Called when we find the DIE that starts a structure or union scope
2122 (definition) to process all dies that define the members of the
2125 NOTE: we need to call struct_type regardless of whether or not the
2126 DIE has an at_name attribute, since it might be an anonymous
2127 structure or union. This gets the type entered into our set of
2130 However, if the structure is incomplete (an opaque struct/union)
2131 then suppress creating a symbol table entry for it since gdb only
2132 wants to find the one with the complete definition. Note that if
2133 it is complete, we just call new_symbol, which does it's own
2134 checking about whether the struct/union is anonymous or not (and
2135 suppresses creating a symbol table entry itself). */
2138 read_structure_scope (die
, objfile
)
2139 struct die_info
*die
;
2140 struct objfile
*objfile
;
2143 struct attribute
*attr
;
2145 type
= alloc_type (objfile
);
2147 INIT_CPLUS_SPECIFIC (type
);
2148 attr
= dwarf_attr (die
, DW_AT_name
);
2149 if (attr
&& DW_STRING (attr
))
2151 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2152 strlen (DW_STRING (attr
)),
2153 &objfile
->type_obstack
);
2156 if (die
->tag
== DW_TAG_structure_type
)
2158 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2160 else if (die
->tag
== DW_TAG_union_type
)
2162 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2166 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2168 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2171 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2174 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2178 TYPE_LENGTH (type
) = 0;
2181 /* We need to add the type field to the die immediately so we don't
2182 infinitely recurse when dealing with pointers to the structure
2183 type within the structure itself. */
2186 if (die
->has_children
&& ! die_is_declaration (die
))
2188 struct field_info fi
;
2189 struct die_info
*child_die
;
2190 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2192 memset (&fi
, 0, sizeof (struct field_info
));
2194 child_die
= die
->next
;
2196 while (child_die
&& child_die
->tag
)
2198 if (child_die
->tag
== DW_TAG_member
)
2200 dwarf2_add_field (&fi
, child_die
, objfile
);
2202 else if (child_die
->tag
== DW_TAG_variable
)
2204 /* C++ static member. */
2205 dwarf2_add_field (&fi
, child_die
, objfile
);
2207 else if (child_die
->tag
== DW_TAG_subprogram
)
2209 /* C++ member function. */
2210 process_die (child_die
, objfile
);
2211 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
);
2213 else if (child_die
->tag
== DW_TAG_inheritance
)
2215 /* C++ base class field. */
2216 dwarf2_add_field (&fi
, child_die
, objfile
);
2220 process_die (child_die
, objfile
);
2222 child_die
= sibling_die (child_die
);
2225 /* Attach fields and member functions to the type. */
2227 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2230 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2232 /* Get the type which refers to the base class (possibly this
2233 class itself) which contains the vtable pointer for the current
2234 class from the DW_AT_containing_type attribute. */
2236 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2238 struct type
*t
= die_containing_type (die
, objfile
);
2240 TYPE_VPTR_BASETYPE (type
) = t
;
2243 static const char vptr_name
[] =
2244 {'_', 'v', 'p', 't', 'r', '\0'};
2247 /* Our own class provides vtbl ptr. */
2248 for (i
= TYPE_NFIELDS (t
) - 1;
2249 i
>= TYPE_N_BASECLASSES (t
);
2252 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2254 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2255 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2257 TYPE_VPTR_FIELDNO (type
) = i
;
2262 /* Complain if virtual function table field not found. */
2263 if (i
< TYPE_N_BASECLASSES (t
))
2264 complain (&dwarf2_vtbl_not_found_complaint
,
2265 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2269 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2274 new_symbol (die
, type
, objfile
);
2276 do_cleanups (back_to
);
2280 /* No children, must be stub. */
2281 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2287 /* Given a pointer to a die which begins an enumeration, process all
2288 the dies that define the members of the enumeration.
2290 This will be much nicer in draft 6 of the DWARF spec when our
2291 members will be dies instead squished into the DW_AT_element_list
2294 NOTE: We reverse the order of the element list. */
2297 read_enumeration (die
, objfile
)
2298 struct die_info
*die
;
2299 struct objfile
*objfile
;
2301 struct die_info
*child_die
;
2303 struct field
*fields
;
2304 struct attribute
*attr
;
2307 int unsigned_enum
= 1;
2309 type
= alloc_type (objfile
);
2311 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2312 attr
= dwarf_attr (die
, DW_AT_name
);
2313 if (attr
&& DW_STRING (attr
))
2315 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2316 strlen (DW_STRING (attr
)),
2317 &objfile
->type_obstack
);
2320 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2323 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2327 TYPE_LENGTH (type
) = 0;
2332 if (die
->has_children
)
2334 child_die
= die
->next
;
2335 while (child_die
&& child_die
->tag
)
2337 if (child_die
->tag
!= DW_TAG_enumerator
)
2339 process_die (child_die
, objfile
);
2343 attr
= dwarf_attr (child_die
, DW_AT_name
);
2346 sym
= new_symbol (child_die
, type
, objfile
);
2347 if (SYMBOL_VALUE (sym
) < 0)
2350 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2352 fields
= (struct field
*)
2354 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2355 * sizeof (struct field
));
2358 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2359 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2360 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2361 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2367 child_die
= sibling_die (child_die
);
2372 TYPE_NFIELDS (type
) = num_fields
;
2373 TYPE_FIELDS (type
) = (struct field
*)
2374 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2375 memcpy (TYPE_FIELDS (type
), fields
,
2376 sizeof (struct field
) * num_fields
);
2380 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2383 new_symbol (die
, type
, objfile
);
2386 /* Extract all information from a DW_TAG_array_type DIE and put it in
2387 the DIE's type field. For now, this only handles one dimensional
2391 read_array_type (die
, objfile
)
2392 struct die_info
*die
;
2393 struct objfile
*objfile
;
2395 struct die_info
*child_die
;
2396 struct type
*type
= NULL
;
2397 struct type
*element_type
, *range_type
, *index_type
;
2398 struct type
**range_types
= NULL
;
2399 struct attribute
*attr
;
2401 struct cleanup
*back_to
;
2403 /* Return if we've already decoded this type. */
2409 element_type
= die_type (die
, objfile
);
2411 /* Irix 6.2 native cc creates array types without children for
2412 arrays with unspecified length. */
2413 if (die
->has_children
== 0)
2415 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2416 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2417 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2421 back_to
= make_cleanup (null_cleanup
, NULL
);
2422 child_die
= die
->next
;
2423 while (child_die
&& child_die
->tag
)
2425 if (child_die
->tag
== DW_TAG_subrange_type
)
2427 unsigned int low
, high
;
2429 /* Default bounds to an array with unspecified length. */
2432 if (cu_language
== language_fortran
)
2434 /* FORTRAN implies a lower bound of 1, if not given. */
2438 index_type
= die_type (child_die
, objfile
);
2439 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2442 if (attr
->form
== DW_FORM_sdata
)
2444 low
= DW_SND (attr
);
2446 else if (attr
->form
== DW_FORM_udata
2447 || attr
->form
== DW_FORM_data1
2448 || attr
->form
== DW_FORM_data2
2449 || attr
->form
== DW_FORM_data4
)
2451 low
= DW_UNSND (attr
);
2455 complain (&dwarf2_non_const_array_bound_ignored
,
2456 dwarf_form_name (attr
->form
));
2458 die
->type
= lookup_pointer_type (element_type
);
2465 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2468 if (attr
->form
== DW_FORM_sdata
)
2470 high
= DW_SND (attr
);
2472 else if (attr
->form
== DW_FORM_udata
2473 || attr
->form
== DW_FORM_data1
2474 || attr
->form
== DW_FORM_data2
2475 || attr
->form
== DW_FORM_data4
)
2477 high
= DW_UNSND (attr
);
2479 else if (attr
->form
== DW_FORM_block1
)
2481 /* GCC encodes arrays with unspecified or dynamic length
2482 with a DW_FORM_block1 attribute.
2483 FIXME: GDB does not yet know how to handle dynamic
2484 arrays properly, treat them as arrays with unspecified
2490 complain (&dwarf2_non_const_array_bound_ignored
,
2491 dwarf_form_name (attr
->form
));
2493 die
->type
= lookup_pointer_type (element_type
);
2501 /* Create a range type and save it for array type creation. */
2502 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2504 range_types
= (struct type
**)
2505 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2506 * sizeof (struct type
*));
2508 make_cleanup (free_current_contents
, &range_types
);
2510 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2512 child_die
= sibling_die (child_die
);
2515 /* Dwarf2 dimensions are output from left to right, create the
2516 necessary array types in backwards order. */
2517 type
= element_type
;
2519 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2521 do_cleanups (back_to
);
2523 /* Install the type in the die. */
2527 /* First cut: install each common block member as a global variable. */
2530 read_common_block (die
, objfile
)
2531 struct die_info
*die
;
2532 struct objfile
*objfile
;
2534 struct die_info
*child_die
;
2535 struct attribute
*attr
;
2537 CORE_ADDR base
= (CORE_ADDR
) 0;
2539 attr
= dwarf_attr (die
, DW_AT_location
);
2542 base
= decode_locdesc (DW_BLOCK (attr
), objfile
);
2544 if (die
->has_children
)
2546 child_die
= die
->next
;
2547 while (child_die
&& child_die
->tag
)
2549 sym
= new_symbol (child_die
, NULL
, objfile
);
2550 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2553 SYMBOL_VALUE_ADDRESS (sym
) =
2554 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
);
2555 add_symbol_to_list (sym
, &global_symbols
);
2557 child_die
= sibling_die (child_die
);
2562 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2563 the user defined type vector. */
2566 read_tag_pointer_type (die
, objfile
)
2567 struct die_info
*die
;
2568 struct objfile
*objfile
;
2571 struct attribute
*attr
;
2578 type
= lookup_pointer_type (die_type (die
, objfile
));
2579 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2582 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2586 TYPE_LENGTH (type
) = address_size
;
2591 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2592 the user defined type vector. */
2595 read_tag_ptr_to_member_type (die
, objfile
)
2596 struct die_info
*die
;
2597 struct objfile
*objfile
;
2600 struct type
*to_type
;
2601 struct type
*domain
;
2608 type
= alloc_type (objfile
);
2609 to_type
= die_type (die
, objfile
);
2610 domain
= die_containing_type (die
, objfile
);
2611 smash_to_member_type (type
, domain
, to_type
);
2616 /* Extract all information from a DW_TAG_reference_type DIE and add to
2617 the user defined type vector. */
2620 read_tag_reference_type (die
, objfile
)
2621 struct die_info
*die
;
2622 struct objfile
*objfile
;
2625 struct attribute
*attr
;
2632 type
= lookup_reference_type (die_type (die
, objfile
));
2633 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2636 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2640 TYPE_LENGTH (type
) = address_size
;
2646 read_tag_const_type (die
, objfile
)
2647 struct die_info
*die
;
2648 struct objfile
*objfile
;
2655 complain (&dwarf2_const_ignored
);
2656 die
->type
= die_type (die
, objfile
);
2660 read_tag_volatile_type (die
, objfile
)
2661 struct die_info
*die
;
2662 struct objfile
*objfile
;
2669 complain (&dwarf2_volatile_ignored
);
2670 die
->type
= die_type (die
, objfile
);
2673 /* Extract all information from a DW_TAG_string_type DIE and add to
2674 the user defined type vector. It isn't really a user defined type,
2675 but it behaves like one, with other DIE's using an AT_user_def_type
2676 attribute to reference it. */
2679 read_tag_string_type (die
, objfile
)
2680 struct die_info
*die
;
2681 struct objfile
*objfile
;
2683 struct type
*type
, *range_type
, *index_type
, *char_type
;
2684 struct attribute
*attr
;
2685 unsigned int length
;
2692 attr
= dwarf_attr (die
, DW_AT_string_length
);
2695 length
= DW_UNSND (attr
);
2701 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2702 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2703 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2704 type
= create_string_type (char_type
, range_type
);
2708 /* Handle DIES due to C code like:
2712 int (*funcp)(int a, long l);
2716 ('funcp' generates a DW_TAG_subroutine_type DIE)
2720 read_subroutine_type (die
, objfile
)
2721 struct die_info
*die
;
2722 struct objfile
*objfile
;
2724 struct type
*type
; /* Type that this function returns */
2725 struct type
*ftype
; /* Function that returns above type */
2726 struct attribute
*attr
;
2728 /* Decode the type that this subroutine returns */
2733 type
= die_type (die
, objfile
);
2734 ftype
= lookup_function_type (type
);
2736 /* All functions in C++ have prototypes. */
2737 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2738 if ((attr
&& (DW_UNSND (attr
) != 0))
2739 || cu_language
== language_cplus
)
2740 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2742 if (die
->has_children
)
2744 struct die_info
*child_die
;
2748 /* Count the number of parameters.
2749 FIXME: GDB currently ignores vararg functions, but knows about
2750 vararg member functions. */
2751 child_die
= die
->next
;
2752 while (child_die
&& child_die
->tag
)
2754 if (child_die
->tag
== DW_TAG_formal_parameter
)
2756 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2757 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2758 child_die
= sibling_die (child_die
);
2761 /* Allocate storage for parameters and fill them in. */
2762 TYPE_NFIELDS (ftype
) = nparams
;
2763 TYPE_FIELDS (ftype
) = (struct field
*)
2764 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2766 child_die
= die
->next
;
2767 while (child_die
&& child_die
->tag
)
2769 if (child_die
->tag
== DW_TAG_formal_parameter
)
2771 /* Dwarf2 has no clean way to discern C++ static and non-static
2772 member functions. G++ helps GDB by marking the first
2773 parameter for non-static member functions (which is the
2774 this pointer) as artificial. We pass this information
2775 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2776 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
2778 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
2780 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
2781 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
);
2784 child_die
= sibling_die (child_die
);
2792 read_typedef (die
, objfile
)
2793 struct die_info
*die
;
2794 struct objfile
*objfile
;
2800 struct attribute
*attr
;
2803 xtype
= die_type (die
, objfile
);
2805 type
= alloc_type (objfile
);
2806 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2807 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2808 TYPE_TARGET_TYPE (type
) = xtype
;
2809 attr
= dwarf_attr (die
, DW_AT_name
);
2810 if (attr
&& DW_STRING (attr
))
2811 TYPE_NAME (type
) = obsavestring (DW_STRING (attr
),
2812 strlen (DW_STRING (attr
)),
2813 &objfile
->type_obstack
);
2819 /* Find a representation of a given base type and install
2820 it in the TYPE field of the die. */
2823 read_base_type (die
, objfile
)
2824 struct die_info
*die
;
2825 struct objfile
*objfile
;
2828 struct attribute
*attr
;
2829 int encoding
= 0, size
= 0;
2831 /* If we've already decoded this die, this is a no-op. */
2837 attr
= dwarf_attr (die
, DW_AT_encoding
);
2840 encoding
= DW_UNSND (attr
);
2842 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2845 size
= DW_UNSND (attr
);
2847 attr
= dwarf_attr (die
, DW_AT_name
);
2848 if (attr
&& DW_STRING (attr
))
2850 enum type_code code
= TYPE_CODE_INT
;
2851 int is_unsigned
= 0;
2855 case DW_ATE_address
:
2856 /* Turn DW_ATE_address into a void * pointer. */
2857 code
= TYPE_CODE_PTR
;
2860 case DW_ATE_boolean
:
2861 code
= TYPE_CODE_BOOL
;
2864 case DW_ATE_complex_float
:
2865 code
= TYPE_CODE_COMPLEX
;
2868 code
= TYPE_CODE_FLT
;
2871 case DW_ATE_signed_char
:
2873 case DW_ATE_unsigned
:
2874 case DW_ATE_unsigned_char
:
2878 complain (&dwarf2_unsupported_at_encoding
,
2879 dwarf_type_encoding_name (encoding
));
2882 type
= init_type (code
, size
, is_unsigned
, DW_STRING (attr
), objfile
);
2883 if (encoding
== DW_ATE_address
)
2884 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
2888 type
= dwarf_base_type (encoding
, size
, objfile
);
2893 /* Read a whole compilation unit into a linked list of dies. */
2896 read_comp_unit (info_ptr
, abfd
)
2900 struct die_info
*first_die
, *last_die
, *die
;
2904 /* Reset die reference table, we are building a new one now. */
2905 dwarf2_empty_die_ref_table ();
2909 first_die
= last_die
= NULL
;
2912 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
);
2913 if (die
->has_children
)
2924 /* Enter die in reference hash table */
2925 store_in_ref_table (die
->offset
, die
);
2929 first_die
= last_die
= die
;
2933 last_die
->next
= die
;
2937 while (nesting_level
> 0);
2941 /* Free a linked list of dies. */
2944 free_die_list (dies
)
2945 struct die_info
*dies
;
2947 struct die_info
*die
, *next
;
2959 /* Read the contents of the section at OFFSET and of size SIZE from the
2960 object file specified by OBJFILE into the psymbol_obstack and return it. */
2963 dwarf2_read_section (objfile
, offset
, size
)
2964 struct objfile
*objfile
;
2968 bfd
*abfd
= objfile
->obfd
;
2974 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
2975 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
2976 (bfd_read (buf
, size
, 1, abfd
) != size
))
2979 error ("Dwarf Error: Can't read DWARF data from '%s'",
2980 bfd_get_filename (abfd
));
2985 /* In DWARF version 2, the description of the debugging information is
2986 stored in a separate .debug_abbrev section. Before we read any
2987 dies from a section we read in all abbreviations and install them
2991 dwarf2_read_abbrevs (abfd
, offset
)
2993 unsigned int offset
;
2996 struct abbrev_info
*cur_abbrev
;
2997 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
2998 unsigned int abbrev_form
, hash_number
;
3000 /* empty the table */
3001 dwarf2_empty_abbrev_table (NULL
);
3003 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3004 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3005 abbrev_ptr
+= bytes_read
;
3007 /* loop until we reach an abbrev number of 0 */
3008 while (abbrev_number
)
3010 cur_abbrev
= dwarf_alloc_abbrev ();
3012 /* read in abbrev header */
3013 cur_abbrev
->number
= abbrev_number
;
3014 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3015 abbrev_ptr
+= bytes_read
;
3016 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3019 /* now read in declarations */
3020 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3021 abbrev_ptr
+= bytes_read
;
3022 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3023 abbrev_ptr
+= bytes_read
;
3026 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3028 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3029 xrealloc (cur_abbrev
->attrs
,
3030 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3031 * sizeof (struct attr_abbrev
));
3033 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3034 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3035 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3036 abbrev_ptr
+= bytes_read
;
3037 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3038 abbrev_ptr
+= bytes_read
;
3041 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3042 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3043 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3045 /* Get next abbreviation.
3046 Under Irix6 the abbreviations for a compilation unit are not
3047 always properly terminated with an abbrev number of 0.
3048 Exit loop if we encounter an abbreviation which we have
3049 already read (which means we are about to read the abbreviations
3050 for the next compile unit) or if the end of the abbreviation
3051 table is reached. */
3052 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3053 >= dwarf_abbrev_size
)
3055 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3056 abbrev_ptr
+= bytes_read
;
3057 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3062 /* Empty the abbrev table for a new compilation unit. */
3066 dwarf2_empty_abbrev_table (ignore
)
3070 struct abbrev_info
*abbrev
, *next
;
3072 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3075 abbrev
= dwarf2_abbrevs
[i
];
3078 next
= abbrev
->next
;
3079 free (abbrev
->attrs
);
3083 dwarf2_abbrevs
[i
] = NULL
;
3087 /* Lookup an abbrev_info structure in the abbrev hash table. */
3089 static struct abbrev_info
*
3090 dwarf2_lookup_abbrev (number
)
3091 unsigned int number
;
3093 unsigned int hash_number
;
3094 struct abbrev_info
*abbrev
;
3096 hash_number
= number
% ABBREV_HASH_SIZE
;
3097 abbrev
= dwarf2_abbrevs
[hash_number
];
3101 if (abbrev
->number
== number
)
3104 abbrev
= abbrev
->next
;
3109 /* Read a minimal amount of information into the minimal die structure. */
3112 read_partial_die (part_die
, abfd
, info_ptr
, has_pc_info
)
3113 struct partial_die_info
*part_die
;
3118 unsigned int abbrev_number
, bytes_read
, i
;
3119 struct abbrev_info
*abbrev
;
3120 struct attribute attr
;
3121 struct attribute spec_attr
;
3122 int found_spec_attr
= 0;
3123 int has_low_pc_attr
= 0;
3124 int has_high_pc_attr
= 0;
3126 *part_die
= zeroed_partial_die
;
3128 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3129 info_ptr
+= bytes_read
;
3133 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3136 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3138 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3139 part_die
->tag
= abbrev
->tag
;
3140 part_die
->has_children
= abbrev
->has_children
;
3141 part_die
->abbrev
= abbrev_number
;
3143 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3145 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
);
3147 /* Store the data if it is of an attribute we want to keep in a
3148 partial symbol table. */
3153 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3154 if (part_die
->name
== NULL
)
3155 part_die
->name
= DW_STRING (&attr
);
3157 case DW_AT_MIPS_linkage_name
:
3158 part_die
->name
= DW_STRING (&attr
);
3161 has_low_pc_attr
= 1;
3162 part_die
->lowpc
= DW_ADDR (&attr
);
3165 has_high_pc_attr
= 1;
3166 part_die
->highpc
= DW_ADDR (&attr
);
3168 case DW_AT_location
:
3169 part_die
->locdesc
= DW_BLOCK (&attr
);
3171 case DW_AT_language
:
3172 part_die
->language
= DW_UNSND (&attr
);
3174 case DW_AT_external
:
3175 part_die
->is_external
= DW_UNSND (&attr
);
3177 case DW_AT_declaration
:
3178 part_die
->is_declaration
= DW_UNSND (&attr
);
3181 part_die
->has_type
= 1;
3183 case DW_AT_abstract_origin
:
3184 case DW_AT_specification
:
3185 found_spec_attr
= 1;
3189 /* Ignore absolute siblings, they might point outside of
3190 the current compile unit. */
3191 if (attr
.form
== DW_FORM_ref_addr
)
3192 complain (&dwarf2_absolute_sibling_complaint
);
3195 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3202 /* If we found a reference attribute and the die has no name, try
3203 to find a name in the referred to die. */
3205 if (found_spec_attr
&& part_die
->name
== NULL
)
3207 struct partial_die_info spec_die
;
3211 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3212 read_partial_die (&spec_die
, abfd
, spec_ptr
, &dummy
);
3215 part_die
->name
= spec_die
.name
;
3217 /* Copy DW_AT_external attribute if it is set. */
3218 if (spec_die
.is_external
)
3219 part_die
->is_external
= spec_die
.is_external
;
3223 /* When using the GNU linker, .gnu.linkonce. sections are used to
3224 eliminate duplicate copies of functions and vtables and such.
3225 The linker will arbitrarily choose one and discard the others.
3226 The AT_*_pc values for such functions refer to local labels in
3227 these sections. If the section from that file was discarded, the
3228 labels are not in the output, so the relocs get a value of 0.
3229 If this is a discarded function, mark the pc bounds as invalid,
3230 so that GDB will ignore it. */
3231 if (has_low_pc_attr
&& has_high_pc_attr
3232 && part_die
->lowpc
< part_die
->highpc
3233 && (part_die
->lowpc
!= 0
3234 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3239 /* Read the die from the .debug_info section buffer. And set diep to
3240 point to a newly allocated die with its information. */
3243 read_full_die (diep
, abfd
, info_ptr
)
3244 struct die_info
**diep
;
3248 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3249 struct abbrev_info
*abbrev
;
3250 struct die_info
*die
;
3252 offset
= info_ptr
- dwarf_info_buffer
;
3253 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3254 info_ptr
+= bytes_read
;
3257 die
= dwarf_alloc_die ();
3259 die
->abbrev
= abbrev_number
;
3265 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3268 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3270 die
= dwarf_alloc_die ();
3271 die
->offset
= offset
;
3272 die
->tag
= abbrev
->tag
;
3273 die
->has_children
= abbrev
->has_children
;
3274 die
->abbrev
= abbrev_number
;
3277 die
->num_attrs
= abbrev
->num_attrs
;
3278 die
->attrs
= (struct attribute
*)
3279 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3281 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3283 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3291 /* Read an attribute described by an abbreviated attribute. */
3294 read_attribute (attr
, abbrev
, abfd
, info_ptr
)
3295 struct attribute
*attr
;
3296 struct attr_abbrev
*abbrev
;
3300 unsigned int bytes_read
;
3301 struct dwarf_block
*blk
;
3303 attr
->name
= abbrev
->name
;
3304 attr
->form
= abbrev
->form
;
3305 switch (abbrev
->form
)
3308 case DW_FORM_ref_addr
:
3309 DW_ADDR (attr
) = read_address (abfd
, info_ptr
);
3310 info_ptr
+= address_size
;
3312 case DW_FORM_block2
:
3313 blk
= dwarf_alloc_block ();
3314 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3316 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3317 info_ptr
+= blk
->size
;
3318 DW_BLOCK (attr
) = blk
;
3320 case DW_FORM_block4
:
3321 blk
= dwarf_alloc_block ();
3322 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3324 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3325 info_ptr
+= blk
->size
;
3326 DW_BLOCK (attr
) = blk
;
3329 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3333 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3337 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3340 case DW_FORM_string
:
3341 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3342 info_ptr
+= bytes_read
;
3345 blk
= dwarf_alloc_block ();
3346 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3347 info_ptr
+= bytes_read
;
3348 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3349 info_ptr
+= blk
->size
;
3350 DW_BLOCK (attr
) = blk
;
3352 case DW_FORM_block1
:
3353 blk
= dwarf_alloc_block ();
3354 blk
->size
= read_1_byte (abfd
, info_ptr
);
3356 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3357 info_ptr
+= blk
->size
;
3358 DW_BLOCK (attr
) = blk
;
3361 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3365 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3369 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3370 info_ptr
+= bytes_read
;
3373 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3374 info_ptr
+= bytes_read
;
3377 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3381 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3385 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3388 case DW_FORM_ref_udata
:
3389 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3390 info_ptr
+= bytes_read
;
3393 case DW_FORM_indirect
:
3395 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3396 dwarf_form_name (abbrev
->form
));
3401 /* read dwarf information from a buffer */
3404 read_1_byte (abfd
, buf
)
3408 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3412 read_1_signed_byte (abfd
, buf
)
3416 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3420 read_2_bytes (abfd
, buf
)
3424 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3428 read_2_signed_bytes (abfd
, buf
)
3432 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3436 read_4_bytes (abfd
, buf
)
3440 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3444 read_4_signed_bytes (abfd
, buf
)
3448 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3452 read_8_bytes (abfd
, buf
)
3456 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3460 read_address (abfd
, buf
)
3464 CORE_ADDR retval
= 0;
3466 switch (address_size
)
3469 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3472 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3475 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3478 /* *THE* alternative is 8, right? */
3486 read_n_bytes (abfd
, buf
, size
)
3491 /* If the size of a host char is 8 bits, we can return a pointer
3492 to the buffer, otherwise we have to copy the data to a buffer
3493 allocated on the temporary obstack. */
3494 #if HOST_CHAR_BIT == 8
3500 ret
= obstack_alloc (&dwarf2_tmp_obstack
, size
);
3501 for (i
= 0; i
< size
; ++i
)
3503 ret
[i
] = bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3511 read_string (abfd
, buf
, bytes_read_ptr
)
3514 unsigned int *bytes_read_ptr
;
3516 /* If the size of a host char is 8 bits, we can return a pointer
3517 to the string, otherwise we have to copy the string to a buffer
3518 allocated on the temporary obstack. */
3519 #if HOST_CHAR_BIT == 8
3522 *bytes_read_ptr
= 1;
3525 *bytes_read_ptr
= strlen (buf
) + 1;
3531 while ((byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
)) != 0)
3533 obstack_1grow (&dwarf2_tmp_obstack
, byte
);
3539 *bytes_read_ptr
= 1;
3542 obstack_1grow (&dwarf2_tmp_obstack
, '\0');
3543 *bytes_read_ptr
= i
+ 1;
3544 return obstack_finish (&dwarf2_tmp_obstack
);
3549 read_unsigned_leb128 (abfd
, buf
, bytes_read_ptr
)
3552 unsigned int *bytes_read_ptr
;
3554 unsigned int result
, num_read
;
3564 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3567 result
|= ((byte
& 127) << shift
);
3568 if ((byte
& 128) == 0)
3574 *bytes_read_ptr
= num_read
;
3579 read_signed_leb128 (abfd
, buf
, bytes_read_ptr
)
3582 unsigned int *bytes_read_ptr
;
3585 int i
, shift
, size
, num_read
;
3595 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3598 result
|= ((byte
& 127) << shift
);
3600 if ((byte
& 128) == 0)
3605 if ((shift
< size
) && (byte
& 0x40))
3607 result
|= -(1 << shift
);
3609 *bytes_read_ptr
= num_read
;
3614 set_cu_language (lang
)
3621 cu_language
= language_c
;
3623 case DW_LANG_C_plus_plus
:
3624 cu_language
= language_cplus
;
3626 case DW_LANG_Fortran77
:
3627 case DW_LANG_Fortran90
:
3628 cu_language
= language_fortran
;
3630 case DW_LANG_Mips_Assembler
:
3631 cu_language
= language_asm
;
3634 case DW_LANG_Cobol74
:
3635 case DW_LANG_Cobol85
:
3636 case DW_LANG_Pascal83
:
3637 case DW_LANG_Modula2
:
3639 cu_language
= language_unknown
;
3642 cu_language_defn
= language_def (cu_language
);
3645 /* Return the named attribute or NULL if not there. */
3647 static struct attribute
*
3648 dwarf_attr (die
, name
)
3649 struct die_info
*die
;
3653 struct attribute
*spec
= NULL
;
3655 for (i
= 0; i
< die
->num_attrs
; ++i
)
3657 if (die
->attrs
[i
].name
== name
)
3659 return &die
->attrs
[i
];
3661 if (die
->attrs
[i
].name
== DW_AT_specification
3662 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3663 spec
= &die
->attrs
[i
];
3667 struct die_info
*ref_die
=
3668 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3671 return dwarf_attr (ref_die
, name
);
3678 die_is_declaration (struct die_info
*die
)
3680 return (dwarf_attr (die
, DW_AT_declaration
)
3681 && ! dwarf_attr (die
, DW_AT_specification
));
3684 /* Decode the line number information for the compilation unit whose
3685 line number info is at OFFSET in the .debug_line section.
3686 The compilation directory of the file is passed in COMP_DIR. */
3690 unsigned int num_files
;
3703 unsigned int num_dirs
;
3708 dwarf_decode_lines (offset
, comp_dir
, abfd
)
3709 unsigned int offset
;
3715 struct line_head lh
;
3716 struct cleanup
*back_to
;
3717 unsigned int i
, bytes_read
;
3718 char *cur_file
, *cur_dir
;
3719 unsigned char op_code
, extended_op
, adj_opcode
;
3721 #define FILE_ALLOC_CHUNK 5
3722 #define DIR_ALLOC_CHUNK 5
3724 struct filenames files
;
3725 struct directories dirs
;
3727 if (dwarf_line_buffer
== NULL
)
3729 complain (&dwarf2_missing_line_number_section
);
3733 files
.num_files
= 0;
3739 line_ptr
= dwarf_line_buffer
+ offset
;
3741 /* read in the prologue */
3742 lh
.total_length
= read_4_bytes (abfd
, line_ptr
);
3744 line_end
= line_ptr
+ lh
.total_length
;
3745 lh
.version
= read_2_bytes (abfd
, line_ptr
);
3747 lh
.prologue_length
= read_4_bytes (abfd
, line_ptr
);
3749 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
3751 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
3753 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
3755 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
3757 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
3759 lh
.standard_opcode_lengths
= (unsigned char *)
3760 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
3761 back_to
= make_cleanup (free_current_contents
, &lh
.standard_opcode_lengths
);
3763 lh
.standard_opcode_lengths
[0] = 1;
3764 for (i
= 1; i
< lh
.opcode_base
; ++i
)
3766 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
3770 /* Read directory table */
3771 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3773 line_ptr
+= bytes_read
;
3774 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
3776 dirs
.dirs
= (char **)
3777 xrealloc (dirs
.dirs
,
3778 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
3779 if (dirs
.num_dirs
== 0)
3780 make_cleanup (free_current_contents
, &dirs
.dirs
);
3782 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
3784 line_ptr
+= bytes_read
;
3786 /* Read file name table */
3787 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3789 line_ptr
+= bytes_read
;
3790 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3792 files
.files
= (struct fileinfo
*)
3793 xrealloc (files
.files
,
3794 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3795 * sizeof (struct fileinfo
));
3796 if (files
.num_files
== 0)
3797 make_cleanup (free_current_contents
, &files
.files
);
3799 files
.files
[files
.num_files
].name
= cur_file
;
3800 files
.files
[files
.num_files
].dir
=
3801 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3802 line_ptr
+= bytes_read
;
3803 files
.files
[files
.num_files
].time
=
3804 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3805 line_ptr
+= bytes_read
;
3806 files
.files
[files
.num_files
].size
=
3807 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3808 line_ptr
+= bytes_read
;
3811 line_ptr
+= bytes_read
;
3813 /* Read the statement sequences until there's nothing left. */
3814 while (line_ptr
< line_end
)
3816 /* state machine registers */
3817 CORE_ADDR address
= 0;
3818 unsigned int file
= 1;
3819 unsigned int line
= 1;
3820 unsigned int column
= 0;
3821 int is_stmt
= lh
.default_is_stmt
;
3822 int basic_block
= 0;
3823 int end_sequence
= 0;
3825 /* Start a subfile for the current file of the state machine. */
3826 if (files
.num_files
>= file
)
3828 /* The file and directory tables are 0 based, the references
3830 dwarf2_start_subfile (files
.files
[file
- 1].name
,
3831 (files
.files
[file
- 1].dir
3832 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3836 /* Decode the table. */
3837 while (!end_sequence
)
3839 op_code
= read_1_byte (abfd
, line_ptr
);
3843 case DW_LNS_extended_op
:
3844 line_ptr
+= 1; /* ignore length */
3845 extended_op
= read_1_byte (abfd
, line_ptr
);
3847 switch (extended_op
)
3849 case DW_LNE_end_sequence
:
3851 /* Don't call record_line here. The end_sequence
3852 instruction provides the address of the first byte
3853 *after* the last line in the sequence; it's not the
3854 address of any real source line. However, the GDB
3855 linetable structure only records the starts of lines,
3856 not the ends. This is a weakness of GDB. */
3858 case DW_LNE_set_address
:
3859 address
= read_address (abfd
, line_ptr
) + baseaddr
;
3860 line_ptr
+= address_size
;
3862 case DW_LNE_define_file
:
3863 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
3864 line_ptr
+= bytes_read
;
3865 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3867 files
.files
= (struct fileinfo
*)
3868 xrealloc (files
.files
,
3869 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3870 * sizeof (struct fileinfo
));
3871 if (files
.num_files
== 0)
3872 make_cleanup (free_current_contents
, &files
.files
);
3874 files
.files
[files
.num_files
].name
= cur_file
;
3875 files
.files
[files
.num_files
].dir
=
3876 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3877 line_ptr
+= bytes_read
;
3878 files
.files
[files
.num_files
].time
=
3879 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3880 line_ptr
+= bytes_read
;
3881 files
.files
[files
.num_files
].size
=
3882 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3883 line_ptr
+= bytes_read
;
3887 complain (&dwarf2_mangled_line_number_section
);
3892 record_line (current_subfile
, line
, address
);
3895 case DW_LNS_advance_pc
:
3896 address
+= lh
.minimum_instruction_length
3897 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3898 line_ptr
+= bytes_read
;
3900 case DW_LNS_advance_line
:
3901 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
3902 line_ptr
+= bytes_read
;
3904 case DW_LNS_set_file
:
3905 /* The file and directory tables are 0 based, the references
3907 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3908 line_ptr
+= bytes_read
;
3909 dwarf2_start_subfile
3910 (files
.files
[file
- 1].name
,
3911 (files
.files
[file
- 1].dir
3912 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3915 case DW_LNS_set_column
:
3916 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3917 line_ptr
+= bytes_read
;
3919 case DW_LNS_negate_stmt
:
3920 is_stmt
= (!is_stmt
);
3922 case DW_LNS_set_basic_block
:
3925 /* Add to the address register of the state machine the
3926 address increment value corresponding to special opcode
3927 255. Ie, this value is scaled by the minimum instruction
3928 length since special opcode 255 would have scaled the
3930 case DW_LNS_const_add_pc
:
3931 address
+= (lh
.minimum_instruction_length
3932 * ((255 - lh
.opcode_base
) / lh
.line_range
));
3934 case DW_LNS_fixed_advance_pc
:
3935 address
+= read_2_bytes (abfd
, line_ptr
);
3938 default: /* special operand */
3939 adj_opcode
= op_code
- lh
.opcode_base
;
3940 address
+= (adj_opcode
/ lh
.line_range
)
3941 * lh
.minimum_instruction_length
;
3942 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
3943 /* append row to matrix using current values */
3944 record_line (current_subfile
, line
, address
);
3950 do_cleanups (back_to
);
3953 /* Start a subfile for DWARF. FILENAME is the name of the file and
3954 DIRNAME the name of the source directory which contains FILENAME
3955 or NULL if not known.
3956 This routine tries to keep line numbers from identical absolute and
3957 relative file names in a common subfile.
3959 Using the `list' example from the GDB testsuite, which resides in
3960 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
3961 of /srcdir/list0.c yields the following debugging information for list0.c:
3963 DW_AT_name: /srcdir/list0.c
3964 DW_AT_comp_dir: /compdir
3965 files.files[0].name: list0.h
3966 files.files[0].dir: /srcdir
3967 files.files[1].name: list0.c
3968 files.files[1].dir: /srcdir
3970 The line number information for list0.c has to end up in a single
3971 subfile, so that `break /srcdir/list0.c:1' works as expected. */
3974 dwarf2_start_subfile (filename
, dirname
)
3978 /* If the filename isn't absolute, try to match an existing subfile
3979 with the full pathname. */
3981 if (*filename
!= '/' && dirname
!= NULL
)
3983 struct subfile
*subfile
;
3984 char *fullname
= concat (dirname
, "/", filename
, NULL
);
3986 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
3988 if (STREQ (subfile
->name
, fullname
))
3990 current_subfile
= subfile
;
3997 start_subfile (filename
, dirname
);
4000 /* Given a pointer to a DWARF information entry, figure out if we need
4001 to make a symbol table entry for it, and if so, create a new entry
4002 and return a pointer to it.
4003 If TYPE is NULL, determine symbol type from the die, otherwise
4004 used the passed type. */
4006 static struct symbol
*
4007 new_symbol (die
, type
, objfile
)
4008 struct die_info
*die
;
4010 struct objfile
*objfile
;
4012 struct symbol
*sym
= NULL
;
4014 struct attribute
*attr
= NULL
;
4015 struct attribute
*attr2
= NULL
;
4018 name
= dwarf2_linkage_name (die
);
4021 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4022 sizeof (struct symbol
));
4023 OBJSTAT (objfile
, n_syms
++);
4024 memset (sym
, 0, sizeof (struct symbol
));
4025 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4026 &objfile
->symbol_obstack
);
4028 /* Default assumptions.
4029 Use the passed type or decode it from the die. */
4030 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4031 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4033 SYMBOL_TYPE (sym
) = type
;
4035 SYMBOL_TYPE (sym
) = die_type (die
, objfile
);
4036 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4039 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4042 /* If this symbol is from a C++ compilation, then attempt to
4043 cache the demangled form for future reference. This is a
4044 typical time versus space tradeoff, that was decided in favor
4045 of time because it sped up C++ symbol lookups by a factor of
4048 SYMBOL_LANGUAGE (sym
) = cu_language
;
4049 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4053 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4056 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4058 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4060 case DW_TAG_subprogram
:
4061 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4063 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4064 attr2
= dwarf_attr (die
, DW_AT_external
);
4065 if (attr2
&& (DW_UNSND (attr2
) != 0))
4067 add_symbol_to_list (sym
, &global_symbols
);
4071 add_symbol_to_list (sym
, list_in_scope
);
4074 case DW_TAG_variable
:
4075 /* Compilation with minimal debug info may result in variables
4076 with missing type entries. Change the misleading `void' type
4077 to something sensible. */
4078 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4079 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4080 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4081 "<variable, no debug info>",
4083 attr
= dwarf_attr (die
, DW_AT_const_value
);
4086 dwarf2_const_value (attr
, sym
, objfile
);
4087 attr2
= dwarf_attr (die
, DW_AT_external
);
4088 if (attr2
&& (DW_UNSND (attr2
) != 0))
4089 add_symbol_to_list (sym
, &global_symbols
);
4091 add_symbol_to_list (sym
, list_in_scope
);
4094 attr
= dwarf_attr (die
, DW_AT_location
);
4097 attr2
= dwarf_attr (die
, DW_AT_external
);
4098 if (attr2
&& (DW_UNSND (attr2
) != 0))
4100 SYMBOL_VALUE_ADDRESS (sym
) =
4101 decode_locdesc (DW_BLOCK (attr
), objfile
);
4102 add_symbol_to_list (sym
, &global_symbols
);
4104 /* In shared libraries the address of the variable
4105 in the location descriptor might still be relocatable,
4106 so its value could be zero.
4107 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4108 value is zero, the address of the variable will then
4109 be determined from the minimal symbol table whenever
4110 the variable is referenced. */
4111 if (SYMBOL_VALUE_ADDRESS (sym
))
4113 SYMBOL_VALUE_ADDRESS (sym
) += baseaddr
;
4114 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4117 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4121 SYMBOL_VALUE (sym
) = addr
=
4122 decode_locdesc (DW_BLOCK (attr
), objfile
);
4123 add_symbol_to_list (sym
, list_in_scope
);
4126 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4130 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4134 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4135 SYMBOL_BASEREG (sym
) = basereg
;
4139 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4143 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4144 SYMBOL_VALUE_ADDRESS (sym
) = addr
+ baseaddr
;
4150 /* We do not know the address of this symbol.
4151 If it is an external symbol and we have type information
4152 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4153 The address of the variable will then be determined from
4154 the minimal symbol table whenever the variable is
4156 attr2
= dwarf_attr (die
, DW_AT_external
);
4157 if (attr2
&& (DW_UNSND (attr2
) != 0)
4158 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4160 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4161 add_symbol_to_list (sym
, &global_symbols
);
4165 case DW_TAG_formal_parameter
:
4166 attr
= dwarf_attr (die
, DW_AT_location
);
4169 SYMBOL_VALUE (sym
) = decode_locdesc (DW_BLOCK (attr
), objfile
);
4172 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4178 if (basereg
!= frame_base_reg
)
4179 complain (&dwarf2_complex_location_expr
);
4180 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4184 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4185 SYMBOL_BASEREG (sym
) = basereg
;
4190 SYMBOL_CLASS (sym
) = LOC_ARG
;
4193 attr
= dwarf_attr (die
, DW_AT_const_value
);
4196 dwarf2_const_value (attr
, sym
, objfile
);
4198 add_symbol_to_list (sym
, list_in_scope
);
4200 case DW_TAG_unspecified_parameters
:
4201 /* From varargs functions; gdb doesn't seem to have any
4202 interest in this information, so just ignore it for now.
4205 case DW_TAG_class_type
:
4206 case DW_TAG_structure_type
:
4207 case DW_TAG_union_type
:
4208 case DW_TAG_enumeration_type
:
4209 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4210 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4211 add_symbol_to_list (sym
, list_in_scope
);
4213 /* The semantics of C++ state that "struct foo { ... }" also
4214 defines a typedef for "foo". Synthesize a typedef symbol so
4215 that "ptype foo" works as expected. */
4216 if (cu_language
== language_cplus
)
4218 struct symbol
*typedef_sym
= (struct symbol
*)
4219 obstack_alloc (&objfile
->symbol_obstack
,
4220 sizeof (struct symbol
));
4221 *typedef_sym
= *sym
;
4222 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4223 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4224 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4225 obsavestring (SYMBOL_NAME (sym
),
4226 strlen (SYMBOL_NAME (sym
)),
4227 &objfile
->type_obstack
);
4228 add_symbol_to_list (typedef_sym
, list_in_scope
);
4231 case DW_TAG_typedef
:
4232 case DW_TAG_base_type
:
4233 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4234 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4235 add_symbol_to_list (sym
, list_in_scope
);
4237 case DW_TAG_enumerator
:
4238 attr
= dwarf_attr (die
, DW_AT_const_value
);
4241 dwarf2_const_value (attr
, sym
, objfile
);
4243 add_symbol_to_list (sym
, list_in_scope
);
4246 /* Not a tag we recognize. Hopefully we aren't processing
4247 trash data, but since we must specifically ignore things
4248 we don't recognize, there is nothing else we should do at
4250 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4257 /* Copy constant value from an attribute to a symbol. */
4260 dwarf2_const_value (attr
, sym
, objfile
)
4261 struct attribute
*attr
;
4263 struct objfile
*objfile
;
4265 struct dwarf_block
*blk
;
4270 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != (unsigned int) address_size
)
4271 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4272 address_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4273 SYMBOL_VALUE_BYTES (sym
) = (char *)
4274 obstack_alloc (&objfile
->symbol_obstack
, address_size
);
4275 store_address (SYMBOL_VALUE_BYTES (sym
), address_size
, DW_ADDR (attr
));
4276 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4278 case DW_FORM_block1
:
4279 case DW_FORM_block2
:
4280 case DW_FORM_block4
:
4282 blk
= DW_BLOCK (attr
);
4283 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4284 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4285 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4286 SYMBOL_VALUE_BYTES (sym
) = (char *)
4287 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4288 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4289 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4292 /* The DW_AT_const_value attributes are supposed to carry the
4293 symbol's value "represented as it would be on the target
4294 architecture." By the time we get here, it's already been
4295 converted to host endianness, so we just need to sign- or
4296 zero-extend it as appropriate. */
4298 dwarf2_const_value_data (attr
, sym
, 8);
4301 dwarf2_const_value_data (attr
, sym
, 16);
4304 dwarf2_const_value_data (attr
, sym
, 32);
4307 dwarf2_const_value_data (attr
, sym
, 64);
4311 SYMBOL_VALUE (sym
) = DW_SND (attr
);
4312 SYMBOL_CLASS (sym
) = LOC_CONST
;
4316 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4317 SYMBOL_CLASS (sym
) = LOC_CONST
;
4321 complain (&dwarf2_unsupported_const_value_attr
,
4322 dwarf_form_name (attr
->form
));
4323 SYMBOL_VALUE (sym
) = 0;
4324 SYMBOL_CLASS (sym
) = LOC_CONST
;
4330 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4331 or zero-extend it as appropriate for the symbol's type. */
4333 dwarf2_const_value_data (struct attribute
*attr
,
4337 LONGEST l
= DW_UNSND (attr
);
4339 if (bits
< sizeof (l
) * 8)
4341 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
4342 l
&= ((LONGEST
) 1 << bits
) - 1;
4344 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
4347 SYMBOL_VALUE (sym
) = l
;
4348 SYMBOL_CLASS (sym
) = LOC_CONST
;
4352 /* Return the type of the die in question using its DW_AT_type attribute. */
4354 static struct type
*
4355 die_type (die
, objfile
)
4356 struct die_info
*die
;
4357 struct objfile
*objfile
;
4360 struct attribute
*type_attr
;
4361 struct die_info
*type_die
;
4364 type_attr
= dwarf_attr (die
, DW_AT_type
);
4367 /* A missing DW_AT_type represents a void type. */
4368 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4372 ref
= dwarf2_get_ref_die_offset (type_attr
);
4373 type_die
= follow_die_ref (ref
);
4376 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4380 type
= tag_type_to_type (type_die
, objfile
);
4383 dump_die (type_die
);
4384 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4389 /* Return the containing type of the die in question using its
4390 DW_AT_containing_type attribute. */
4392 static struct type
*
4393 die_containing_type (die
, objfile
)
4394 struct die_info
*die
;
4395 struct objfile
*objfile
;
4397 struct type
*type
= NULL
;
4398 struct attribute
*type_attr
;
4399 struct die_info
*type_die
= NULL
;
4402 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4405 ref
= dwarf2_get_ref_die_offset (type_attr
);
4406 type_die
= follow_die_ref (ref
);
4409 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4412 type
= tag_type_to_type (type_die
, objfile
);
4417 dump_die (type_die
);
4418 error ("Dwarf Error: Problem turning containing type into gdb type.");
4424 static struct type
*
4425 type_at_offset (offset
, objfile
)
4426 unsigned int offset
;
4427 struct objfile
*objfile
;
4429 struct die_info
*die
;
4432 die
= follow_die_ref (offset
);
4435 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4438 type
= tag_type_to_type (die
, objfile
);
4443 static struct type
*
4444 tag_type_to_type (die
, objfile
)
4445 struct die_info
*die
;
4446 struct objfile
*objfile
;
4454 read_type_die (die
, objfile
);
4458 error ("Dwarf Error: Cannot find type of die.");
4465 read_type_die (die
, objfile
)
4466 struct die_info
*die
;
4467 struct objfile
*objfile
;
4471 case DW_TAG_class_type
:
4472 case DW_TAG_structure_type
:
4473 case DW_TAG_union_type
:
4474 read_structure_scope (die
, objfile
);
4476 case DW_TAG_enumeration_type
:
4477 read_enumeration (die
, objfile
);
4479 case DW_TAG_subprogram
:
4480 case DW_TAG_subroutine_type
:
4481 read_subroutine_type (die
, objfile
);
4483 case DW_TAG_array_type
:
4484 read_array_type (die
, objfile
);
4486 case DW_TAG_pointer_type
:
4487 read_tag_pointer_type (die
, objfile
);
4489 case DW_TAG_ptr_to_member_type
:
4490 read_tag_ptr_to_member_type (die
, objfile
);
4492 case DW_TAG_reference_type
:
4493 read_tag_reference_type (die
, objfile
);
4495 case DW_TAG_const_type
:
4496 read_tag_const_type (die
, objfile
);
4498 case DW_TAG_volatile_type
:
4499 read_tag_volatile_type (die
, objfile
);
4501 case DW_TAG_string_type
:
4502 read_tag_string_type (die
, objfile
);
4504 case DW_TAG_typedef
:
4505 read_typedef (die
, objfile
);
4507 case DW_TAG_base_type
:
4508 read_base_type (die
, objfile
);
4511 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4516 static struct type
*
4517 dwarf_base_type (encoding
, size
, objfile
)
4520 struct objfile
*objfile
;
4522 /* FIXME - this should not produce a new (struct type *)
4523 every time. It should cache base types. */
4527 case DW_ATE_address
:
4528 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4530 case DW_ATE_boolean
:
4531 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4533 case DW_ATE_complex_float
:
4536 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4540 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4546 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4550 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4557 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4560 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4564 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4568 case DW_ATE_signed_char
:
4569 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4571 case DW_ATE_unsigned
:
4575 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4578 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4582 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4586 case DW_ATE_unsigned_char
:
4587 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4590 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4598 struct die_info
*old_die
;
4600 struct die_info
*new_die
;
4603 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4604 memset (new_die
, 0, sizeof (struct die_info
));
4606 new_die
->tag
= old_die
->tag
;
4607 new_die
->has_children
= old_die
->has_children
;
4608 new_die
->abbrev
= old_die
->abbrev
;
4609 new_die
->offset
= old_die
->offset
;
4610 new_die
->type
= NULL
;
4612 num_attrs
= old_die
->num_attrs
;
4613 new_die
->num_attrs
= num_attrs
;
4614 new_die
->attrs
= (struct attribute
*)
4615 xmalloc (num_attrs
* sizeof (struct attribute
));
4617 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4619 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4620 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4621 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4624 new_die
->next
= NULL
;
4629 /* Return sibling of die, NULL if no sibling. */
4633 struct die_info
*die
;
4635 int nesting_level
= 0;
4637 if (!die
->has_children
)
4639 if (die
->next
&& (die
->next
->tag
== 0))
4652 if (die
->has_children
)
4662 while (nesting_level
);
4663 if (die
&& (die
->tag
== 0))
4674 /* Get linkage name of a die, return NULL if not found. */
4677 dwarf2_linkage_name (die
)
4678 struct die_info
*die
;
4680 struct attribute
*attr
;
4682 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4683 if (attr
&& DW_STRING (attr
))
4684 return DW_STRING (attr
);
4685 attr
= dwarf_attr (die
, DW_AT_name
);
4686 if (attr
&& DW_STRING (attr
))
4687 return DW_STRING (attr
);
4691 /* Convert a DIE tag into its string name. */
4694 dwarf_tag_name (tag
)
4695 register unsigned tag
;
4699 case DW_TAG_padding
:
4700 return "DW_TAG_padding";
4701 case DW_TAG_array_type
:
4702 return "DW_TAG_array_type";
4703 case DW_TAG_class_type
:
4704 return "DW_TAG_class_type";
4705 case DW_TAG_entry_point
:
4706 return "DW_TAG_entry_point";
4707 case DW_TAG_enumeration_type
:
4708 return "DW_TAG_enumeration_type";
4709 case DW_TAG_formal_parameter
:
4710 return "DW_TAG_formal_parameter";
4711 case DW_TAG_imported_declaration
:
4712 return "DW_TAG_imported_declaration";
4714 return "DW_TAG_label";
4715 case DW_TAG_lexical_block
:
4716 return "DW_TAG_lexical_block";
4718 return "DW_TAG_member";
4719 case DW_TAG_pointer_type
:
4720 return "DW_TAG_pointer_type";
4721 case DW_TAG_reference_type
:
4722 return "DW_TAG_reference_type";
4723 case DW_TAG_compile_unit
:
4724 return "DW_TAG_compile_unit";
4725 case DW_TAG_string_type
:
4726 return "DW_TAG_string_type";
4727 case DW_TAG_structure_type
:
4728 return "DW_TAG_structure_type";
4729 case DW_TAG_subroutine_type
:
4730 return "DW_TAG_subroutine_type";
4731 case DW_TAG_typedef
:
4732 return "DW_TAG_typedef";
4733 case DW_TAG_union_type
:
4734 return "DW_TAG_union_type";
4735 case DW_TAG_unspecified_parameters
:
4736 return "DW_TAG_unspecified_parameters";
4737 case DW_TAG_variant
:
4738 return "DW_TAG_variant";
4739 case DW_TAG_common_block
:
4740 return "DW_TAG_common_block";
4741 case DW_TAG_common_inclusion
:
4742 return "DW_TAG_common_inclusion";
4743 case DW_TAG_inheritance
:
4744 return "DW_TAG_inheritance";
4745 case DW_TAG_inlined_subroutine
:
4746 return "DW_TAG_inlined_subroutine";
4748 return "DW_TAG_module";
4749 case DW_TAG_ptr_to_member_type
:
4750 return "DW_TAG_ptr_to_member_type";
4751 case DW_TAG_set_type
:
4752 return "DW_TAG_set_type";
4753 case DW_TAG_subrange_type
:
4754 return "DW_TAG_subrange_type";
4755 case DW_TAG_with_stmt
:
4756 return "DW_TAG_with_stmt";
4757 case DW_TAG_access_declaration
:
4758 return "DW_TAG_access_declaration";
4759 case DW_TAG_base_type
:
4760 return "DW_TAG_base_type";
4761 case DW_TAG_catch_block
:
4762 return "DW_TAG_catch_block";
4763 case DW_TAG_const_type
:
4764 return "DW_TAG_const_type";
4765 case DW_TAG_constant
:
4766 return "DW_TAG_constant";
4767 case DW_TAG_enumerator
:
4768 return "DW_TAG_enumerator";
4769 case DW_TAG_file_type
:
4770 return "DW_TAG_file_type";
4772 return "DW_TAG_friend";
4773 case DW_TAG_namelist
:
4774 return "DW_TAG_namelist";
4775 case DW_TAG_namelist_item
:
4776 return "DW_TAG_namelist_item";
4777 case DW_TAG_packed_type
:
4778 return "DW_TAG_packed_type";
4779 case DW_TAG_subprogram
:
4780 return "DW_TAG_subprogram";
4781 case DW_TAG_template_type_param
:
4782 return "DW_TAG_template_type_param";
4783 case DW_TAG_template_value_param
:
4784 return "DW_TAG_template_value_param";
4785 case DW_TAG_thrown_type
:
4786 return "DW_TAG_thrown_type";
4787 case DW_TAG_try_block
:
4788 return "DW_TAG_try_block";
4789 case DW_TAG_variant_part
:
4790 return "DW_TAG_variant_part";
4791 case DW_TAG_variable
:
4792 return "DW_TAG_variable";
4793 case DW_TAG_volatile_type
:
4794 return "DW_TAG_volatile_type";
4795 case DW_TAG_MIPS_loop
:
4796 return "DW_TAG_MIPS_loop";
4797 case DW_TAG_format_label
:
4798 return "DW_TAG_format_label";
4799 case DW_TAG_function_template
:
4800 return "DW_TAG_function_template";
4801 case DW_TAG_class_template
:
4802 return "DW_TAG_class_template";
4804 return "DW_TAG_<unknown>";
4808 /* Convert a DWARF attribute code into its string name. */
4811 dwarf_attr_name (attr
)
4812 register unsigned attr
;
4817 return "DW_AT_sibling";
4818 case DW_AT_location
:
4819 return "DW_AT_location";
4821 return "DW_AT_name";
4822 case DW_AT_ordering
:
4823 return "DW_AT_ordering";
4824 case DW_AT_subscr_data
:
4825 return "DW_AT_subscr_data";
4826 case DW_AT_byte_size
:
4827 return "DW_AT_byte_size";
4828 case DW_AT_bit_offset
:
4829 return "DW_AT_bit_offset";
4830 case DW_AT_bit_size
:
4831 return "DW_AT_bit_size";
4832 case DW_AT_element_list
:
4833 return "DW_AT_element_list";
4834 case DW_AT_stmt_list
:
4835 return "DW_AT_stmt_list";
4837 return "DW_AT_low_pc";
4839 return "DW_AT_high_pc";
4840 case DW_AT_language
:
4841 return "DW_AT_language";
4843 return "DW_AT_member";
4845 return "DW_AT_discr";
4846 case DW_AT_discr_value
:
4847 return "DW_AT_discr_value";
4848 case DW_AT_visibility
:
4849 return "DW_AT_visibility";
4851 return "DW_AT_import";
4852 case DW_AT_string_length
:
4853 return "DW_AT_string_length";
4854 case DW_AT_common_reference
:
4855 return "DW_AT_common_reference";
4856 case DW_AT_comp_dir
:
4857 return "DW_AT_comp_dir";
4858 case DW_AT_const_value
:
4859 return "DW_AT_const_value";
4860 case DW_AT_containing_type
:
4861 return "DW_AT_containing_type";
4862 case DW_AT_default_value
:
4863 return "DW_AT_default_value";
4865 return "DW_AT_inline";
4866 case DW_AT_is_optional
:
4867 return "DW_AT_is_optional";
4868 case DW_AT_lower_bound
:
4869 return "DW_AT_lower_bound";
4870 case DW_AT_producer
:
4871 return "DW_AT_producer";
4872 case DW_AT_prototyped
:
4873 return "DW_AT_prototyped";
4874 case DW_AT_return_addr
:
4875 return "DW_AT_return_addr";
4876 case DW_AT_start_scope
:
4877 return "DW_AT_start_scope";
4878 case DW_AT_stride_size
:
4879 return "DW_AT_stride_size";
4880 case DW_AT_upper_bound
:
4881 return "DW_AT_upper_bound";
4882 case DW_AT_abstract_origin
:
4883 return "DW_AT_abstract_origin";
4884 case DW_AT_accessibility
:
4885 return "DW_AT_accessibility";
4886 case DW_AT_address_class
:
4887 return "DW_AT_address_class";
4888 case DW_AT_artificial
:
4889 return "DW_AT_artificial";
4890 case DW_AT_base_types
:
4891 return "DW_AT_base_types";
4892 case DW_AT_calling_convention
:
4893 return "DW_AT_calling_convention";
4895 return "DW_AT_count";
4896 case DW_AT_data_member_location
:
4897 return "DW_AT_data_member_location";
4898 case DW_AT_decl_column
:
4899 return "DW_AT_decl_column";
4900 case DW_AT_decl_file
:
4901 return "DW_AT_decl_file";
4902 case DW_AT_decl_line
:
4903 return "DW_AT_decl_line";
4904 case DW_AT_declaration
:
4905 return "DW_AT_declaration";
4906 case DW_AT_discr_list
:
4907 return "DW_AT_discr_list";
4908 case DW_AT_encoding
:
4909 return "DW_AT_encoding";
4910 case DW_AT_external
:
4911 return "DW_AT_external";
4912 case DW_AT_frame_base
:
4913 return "DW_AT_frame_base";
4915 return "DW_AT_friend";
4916 case DW_AT_identifier_case
:
4917 return "DW_AT_identifier_case";
4918 case DW_AT_macro_info
:
4919 return "DW_AT_macro_info";
4920 case DW_AT_namelist_items
:
4921 return "DW_AT_namelist_items";
4922 case DW_AT_priority
:
4923 return "DW_AT_priority";
4925 return "DW_AT_segment";
4926 case DW_AT_specification
:
4927 return "DW_AT_specification";
4928 case DW_AT_static_link
:
4929 return "DW_AT_static_link";
4931 return "DW_AT_type";
4932 case DW_AT_use_location
:
4933 return "DW_AT_use_location";
4934 case DW_AT_variable_parameter
:
4935 return "DW_AT_variable_parameter";
4936 case DW_AT_virtuality
:
4937 return "DW_AT_virtuality";
4938 case DW_AT_vtable_elem_location
:
4939 return "DW_AT_vtable_elem_location";
4942 case DW_AT_MIPS_fde
:
4943 return "DW_AT_MIPS_fde";
4944 case DW_AT_MIPS_loop_begin
:
4945 return "DW_AT_MIPS_loop_begin";
4946 case DW_AT_MIPS_tail_loop_begin
:
4947 return "DW_AT_MIPS_tail_loop_begin";
4948 case DW_AT_MIPS_epilog_begin
:
4949 return "DW_AT_MIPS_epilog_begin";
4950 case DW_AT_MIPS_loop_unroll_factor
:
4951 return "DW_AT_MIPS_loop_unroll_factor";
4952 case DW_AT_MIPS_software_pipeline_depth
:
4953 return "DW_AT_MIPS_software_pipeline_depth";
4954 case DW_AT_MIPS_linkage_name
:
4955 return "DW_AT_MIPS_linkage_name";
4958 case DW_AT_sf_names
:
4959 return "DW_AT_sf_names";
4960 case DW_AT_src_info
:
4961 return "DW_AT_src_info";
4962 case DW_AT_mac_info
:
4963 return "DW_AT_mac_info";
4964 case DW_AT_src_coords
:
4965 return "DW_AT_src_coords";
4966 case DW_AT_body_begin
:
4967 return "DW_AT_body_begin";
4968 case DW_AT_body_end
:
4969 return "DW_AT_body_end";
4971 return "DW_AT_<unknown>";
4975 /* Convert a DWARF value form code into its string name. */
4978 dwarf_form_name (form
)
4979 register unsigned form
;
4984 return "DW_FORM_addr";
4985 case DW_FORM_block2
:
4986 return "DW_FORM_block2";
4987 case DW_FORM_block4
:
4988 return "DW_FORM_block4";
4990 return "DW_FORM_data2";
4992 return "DW_FORM_data4";
4994 return "DW_FORM_data8";
4995 case DW_FORM_string
:
4996 return "DW_FORM_string";
4998 return "DW_FORM_block";
4999 case DW_FORM_block1
:
5000 return "DW_FORM_block1";
5002 return "DW_FORM_data1";
5004 return "DW_FORM_flag";
5006 return "DW_FORM_sdata";
5008 return "DW_FORM_strp";
5010 return "DW_FORM_udata";
5011 case DW_FORM_ref_addr
:
5012 return "DW_FORM_ref_addr";
5014 return "DW_FORM_ref1";
5016 return "DW_FORM_ref2";
5018 return "DW_FORM_ref4";
5020 return "DW_FORM_ref8";
5021 case DW_FORM_ref_udata
:
5022 return "DW_FORM_ref_udata";
5023 case DW_FORM_indirect
:
5024 return "DW_FORM_indirect";
5026 return "DW_FORM_<unknown>";
5030 /* Convert a DWARF stack opcode into its string name. */
5033 dwarf_stack_op_name (op
)
5034 register unsigned op
;
5039 return "DW_OP_addr";
5041 return "DW_OP_deref";
5043 return "DW_OP_const1u";
5045 return "DW_OP_const1s";
5047 return "DW_OP_const2u";
5049 return "DW_OP_const2s";
5051 return "DW_OP_const4u";
5053 return "DW_OP_const4s";
5055 return "DW_OP_const8u";
5057 return "DW_OP_const8s";
5059 return "DW_OP_constu";
5061 return "DW_OP_consts";
5065 return "DW_OP_drop";
5067 return "DW_OP_over";
5069 return "DW_OP_pick";
5071 return "DW_OP_swap";
5075 return "DW_OP_xderef";
5083 return "DW_OP_minus";
5095 return "DW_OP_plus";
5096 case DW_OP_plus_uconst
:
5097 return "DW_OP_plus_uconst";
5103 return "DW_OP_shra";
5121 return "DW_OP_skip";
5123 return "DW_OP_lit0";
5125 return "DW_OP_lit1";
5127 return "DW_OP_lit2";
5129 return "DW_OP_lit3";
5131 return "DW_OP_lit4";
5133 return "DW_OP_lit5";
5135 return "DW_OP_lit6";
5137 return "DW_OP_lit7";
5139 return "DW_OP_lit8";
5141 return "DW_OP_lit9";
5143 return "DW_OP_lit10";
5145 return "DW_OP_lit11";
5147 return "DW_OP_lit12";
5149 return "DW_OP_lit13";
5151 return "DW_OP_lit14";
5153 return "DW_OP_lit15";
5155 return "DW_OP_lit16";
5157 return "DW_OP_lit17";
5159 return "DW_OP_lit18";
5161 return "DW_OP_lit19";
5163 return "DW_OP_lit20";
5165 return "DW_OP_lit21";
5167 return "DW_OP_lit22";
5169 return "DW_OP_lit23";
5171 return "DW_OP_lit24";
5173 return "DW_OP_lit25";
5175 return "DW_OP_lit26";
5177 return "DW_OP_lit27";
5179 return "DW_OP_lit28";
5181 return "DW_OP_lit29";
5183 return "DW_OP_lit30";
5185 return "DW_OP_lit31";
5187 return "DW_OP_reg0";
5189 return "DW_OP_reg1";
5191 return "DW_OP_reg2";
5193 return "DW_OP_reg3";
5195 return "DW_OP_reg4";
5197 return "DW_OP_reg5";
5199 return "DW_OP_reg6";
5201 return "DW_OP_reg7";
5203 return "DW_OP_reg8";
5205 return "DW_OP_reg9";
5207 return "DW_OP_reg10";
5209 return "DW_OP_reg11";
5211 return "DW_OP_reg12";
5213 return "DW_OP_reg13";
5215 return "DW_OP_reg14";
5217 return "DW_OP_reg15";
5219 return "DW_OP_reg16";
5221 return "DW_OP_reg17";
5223 return "DW_OP_reg18";
5225 return "DW_OP_reg19";
5227 return "DW_OP_reg20";
5229 return "DW_OP_reg21";
5231 return "DW_OP_reg22";
5233 return "DW_OP_reg23";
5235 return "DW_OP_reg24";
5237 return "DW_OP_reg25";
5239 return "DW_OP_reg26";
5241 return "DW_OP_reg27";
5243 return "DW_OP_reg28";
5245 return "DW_OP_reg29";
5247 return "DW_OP_reg30";
5249 return "DW_OP_reg31";
5251 return "DW_OP_breg0";
5253 return "DW_OP_breg1";
5255 return "DW_OP_breg2";
5257 return "DW_OP_breg3";
5259 return "DW_OP_breg4";
5261 return "DW_OP_breg5";
5263 return "DW_OP_breg6";
5265 return "DW_OP_breg7";
5267 return "DW_OP_breg8";
5269 return "DW_OP_breg9";
5271 return "DW_OP_breg10";
5273 return "DW_OP_breg11";
5275 return "DW_OP_breg12";
5277 return "DW_OP_breg13";
5279 return "DW_OP_breg14";
5281 return "DW_OP_breg15";
5283 return "DW_OP_breg16";
5285 return "DW_OP_breg17";
5287 return "DW_OP_breg18";
5289 return "DW_OP_breg19";
5291 return "DW_OP_breg20";
5293 return "DW_OP_breg21";
5295 return "DW_OP_breg22";
5297 return "DW_OP_breg23";
5299 return "DW_OP_breg24";
5301 return "DW_OP_breg25";
5303 return "DW_OP_breg26";
5305 return "DW_OP_breg27";
5307 return "DW_OP_breg28";
5309 return "DW_OP_breg29";
5311 return "DW_OP_breg30";
5313 return "DW_OP_breg31";
5315 return "DW_OP_regx";
5317 return "DW_OP_fbreg";
5319 return "DW_OP_bregx";
5321 return "DW_OP_piece";
5322 case DW_OP_deref_size
:
5323 return "DW_OP_deref_size";
5324 case DW_OP_xderef_size
:
5325 return "DW_OP_xderef_size";
5329 return "OP_<unknown>";
5334 dwarf_bool_name (mybool
)
5343 /* Convert a DWARF type code into its string name. */
5346 dwarf_type_encoding_name (enc
)
5347 register unsigned enc
;
5351 case DW_ATE_address
:
5352 return "DW_ATE_address";
5353 case DW_ATE_boolean
:
5354 return "DW_ATE_boolean";
5355 case DW_ATE_complex_float
:
5356 return "DW_ATE_complex_float";
5358 return "DW_ATE_float";
5360 return "DW_ATE_signed";
5361 case DW_ATE_signed_char
:
5362 return "DW_ATE_signed_char";
5363 case DW_ATE_unsigned
:
5364 return "DW_ATE_unsigned";
5365 case DW_ATE_unsigned_char
:
5366 return "DW_ATE_unsigned_char";
5368 return "DW_ATE_<unknown>";
5372 /* Convert a DWARF call frame info operation to its string name. */
5376 dwarf_cfi_name (cfi_opc
)
5377 register unsigned cfi_opc
;
5381 case DW_CFA_advance_loc
:
5382 return "DW_CFA_advance_loc";
5384 return "DW_CFA_offset";
5385 case DW_CFA_restore
:
5386 return "DW_CFA_restore";
5388 return "DW_CFA_nop";
5389 case DW_CFA_set_loc
:
5390 return "DW_CFA_set_loc";
5391 case DW_CFA_advance_loc1
:
5392 return "DW_CFA_advance_loc1";
5393 case DW_CFA_advance_loc2
:
5394 return "DW_CFA_advance_loc2";
5395 case DW_CFA_advance_loc4
:
5396 return "DW_CFA_advance_loc4";
5397 case DW_CFA_offset_extended
:
5398 return "DW_CFA_offset_extended";
5399 case DW_CFA_restore_extended
:
5400 return "DW_CFA_restore_extended";
5401 case DW_CFA_undefined
:
5402 return "DW_CFA_undefined";
5403 case DW_CFA_same_value
:
5404 return "DW_CFA_same_value";
5405 case DW_CFA_register
:
5406 return "DW_CFA_register";
5407 case DW_CFA_remember_state
:
5408 return "DW_CFA_remember_state";
5409 case DW_CFA_restore_state
:
5410 return "DW_CFA_restore_state";
5411 case DW_CFA_def_cfa
:
5412 return "DW_CFA_def_cfa";
5413 case DW_CFA_def_cfa_register
:
5414 return "DW_CFA_def_cfa_register";
5415 case DW_CFA_def_cfa_offset
:
5416 return "DW_CFA_def_cfa_offset";
5417 /* SGI/MIPS specific */
5418 case DW_CFA_MIPS_advance_loc8
:
5419 return "DW_CFA_MIPS_advance_loc8";
5421 return "DW_CFA_<unknown>";
5428 struct die_info
*die
;
5432 fprintf (stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5433 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5434 fprintf (stderr
, "\thas children: %s\n",
5435 dwarf_bool_name (die
->has_children
));
5437 fprintf (stderr
, "\tattributes:\n");
5438 for (i
= 0; i
< die
->num_attrs
; ++i
)
5440 fprintf (stderr
, "\t\t%s (%s) ",
5441 dwarf_attr_name (die
->attrs
[i
].name
),
5442 dwarf_form_name (die
->attrs
[i
].form
));
5443 switch (die
->attrs
[i
].form
)
5445 case DW_FORM_ref_addr
:
5447 fprintf (stderr
, "address: ");
5448 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
5450 case DW_FORM_block2
:
5451 case DW_FORM_block4
:
5453 case DW_FORM_block1
:
5454 fprintf (stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5464 fprintf (stderr
, "constant: %d", DW_UNSND (&die
->attrs
[i
]));
5466 case DW_FORM_string
:
5467 fprintf (stderr
, "string: \"%s\"",
5468 DW_STRING (&die
->attrs
[i
])
5469 ? DW_STRING (&die
->attrs
[i
]) : "");
5472 if (DW_UNSND (&die
->attrs
[i
]))
5473 fprintf (stderr
, "flag: TRUE");
5475 fprintf (stderr
, "flag: FALSE");
5477 case DW_FORM_strp
: /* we do not support separate string
5479 case DW_FORM_indirect
: /* we do not handle indirect yet */
5480 case DW_FORM_data8
: /* we do not have 64 bit quantities */
5482 fprintf (stderr
, "unsupported attribute form: %d.",
5483 die
->attrs
[i
].form
);
5485 fprintf (stderr
, "\n");
5491 struct die_info
*die
;
5501 store_in_ref_table (offset
, die
)
5502 unsigned int offset
;
5503 struct die_info
*die
;
5506 struct die_info
*old
;
5508 h
= (offset
% REF_HASH_SIZE
);
5509 old
= die_ref_table
[h
];
5510 die
->next_ref
= old
;
5511 die_ref_table
[h
] = die
;
5516 dwarf2_empty_die_ref_table ()
5518 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5522 dwarf2_get_ref_die_offset (attr
)
5523 struct attribute
*attr
;
5525 unsigned int result
= 0;
5529 case DW_FORM_ref_addr
:
5530 result
= DW_ADDR (attr
);
5535 case DW_FORM_ref_udata
:
5536 result
= cu_header_offset
+ DW_UNSND (attr
);
5539 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5545 follow_die_ref (offset
)
5546 unsigned int offset
;
5548 struct die_info
*die
;
5551 h
= (offset
% REF_HASH_SIZE
);
5552 die
= die_ref_table
[h
];
5555 if (die
->offset
== offset
)
5559 die
= die
->next_ref
;
5564 static struct type
*
5565 dwarf2_fundamental_type (objfile
, typeid)
5566 struct objfile
*objfile
;
5569 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5571 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5575 /* Look for this particular type in the fundamental type vector. If
5576 one is not found, create and install one appropriate for the
5577 current language and the current target machine. */
5579 if (ftypes
[typeid] == NULL
)
5581 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5584 return (ftypes
[typeid]);
5587 /* Decode simple location descriptions.
5588 Given a pointer to a dwarf block that defines a location, compute
5589 the location and return the value.
5591 FIXME: This is a kludge until we figure out a better
5592 way to handle the location descriptions.
5593 Gdb's design does not mesh well with the DWARF2 notion of a location
5594 computing interpreter, which is a shame because the flexibility goes unused.
5595 FIXME: Implement more operations as necessary.
5597 A location description containing no operations indicates that the
5598 object is optimized out. The global optimized_out flag is set for
5599 those, the return value is meaningless.
5601 When the result is a register number, the global isreg flag is set,
5602 otherwise it is cleared.
5604 When the result is a base register offset, the global offreg flag is set
5605 and the register number is returned in basereg, otherwise it is cleared.
5607 When the DW_OP_fbreg operation is encountered without a corresponding
5608 DW_AT_frame_base attribute, the global islocal flag is set.
5609 Hopefully the machine dependent code knows how to set up a virtual
5610 frame pointer for the local references.
5612 Note that stack[0] is unused except as a default error return.
5613 Note that stack overflow is not yet handled. */
5616 decode_locdesc (blk
, objfile
)
5617 struct dwarf_block
*blk
;
5618 struct objfile
*objfile
;
5621 int size
= blk
->size
;
5622 char *data
= blk
->data
;
5623 CORE_ADDR stack
[64];
5625 unsigned int bytes_read
, unsnd
;
5676 stack
[++stacki
] = op
- DW_OP_reg0
;
5681 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5683 #if defined(HARRIS_TARGET) && defined(_M88K)
5684 /* The Harris 88110 gdb ports have long kept their special reg
5685 numbers between their gp-regs and their x-regs. This is
5686 not how our dwarf is generated. Punt. */
5689 stack
[++stacki
] = unsnd
;
5725 basereg
= op
- DW_OP_breg0
;
5726 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5732 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5734 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5739 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5741 if (frame_base_reg
>= 0)
5744 basereg
= frame_base_reg
;
5745 stack
[stacki
] += frame_base_offset
;
5749 complain (&dwarf2_missing_at_frame_base
);
5755 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
]);
5760 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
5765 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
5770 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
5775 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
5780 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
5785 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
5790 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
5796 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5801 stack
[stacki
- 1] += stack
[stacki
];
5805 case DW_OP_plus_uconst
:
5806 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5811 stack
[stacki
- 1] = stack
[stacki
] - stack
[stacki
- 1];
5817 /* If we're not the last op, then we definitely can't encode
5818 this using GDB's address_class enum. */
5820 complain (&dwarf2_complex_location_expr
);
5824 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
5825 return (stack
[stacki
]);
5828 return (stack
[stacki
]);
5831 /* memory allocation interface */
5835 dwarf2_free_tmp_obstack (ignore
)
5838 obstack_free (&dwarf2_tmp_obstack
, NULL
);
5841 static struct dwarf_block
*
5842 dwarf_alloc_block ()
5844 struct dwarf_block
*blk
;
5846 blk
= (struct dwarf_block
*)
5847 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
5851 static struct abbrev_info
*
5852 dwarf_alloc_abbrev ()
5854 struct abbrev_info
*abbrev
;
5856 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
5857 memset (abbrev
, 0, sizeof (struct abbrev_info
));
5861 static struct die_info
*
5864 struct die_info
*die
;
5866 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5867 memset (die
, 0, sizeof (struct die_info
));