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 (bfd
*, asection
*, PTR
);
556 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
559 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
561 static char *scan_partial_symbols (char *, struct objfile
*,
562 CORE_ADDR
*, CORE_ADDR
*);
564 static void add_partial_symbol (struct partial_die_info
*, struct objfile
*);
566 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
568 static void psymtab_to_symtab_1 (struct partial_symtab
*);
570 static char *dwarf2_read_section (struct objfile
*, file_ptr
, unsigned int);
572 static void dwarf2_read_abbrevs (bfd
*, unsigned int);
574 static void dwarf2_empty_abbrev_table (PTR
);
576 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int);
578 static char *read_partial_die (struct partial_die_info
*,
579 bfd
*, char *, int *);
581 static char *read_full_die (struct die_info
**, bfd
*, char *);
583 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
586 static unsigned int read_1_byte (bfd
*, char *);
588 static int read_1_signed_byte (bfd
*, char *);
590 static unsigned int read_2_bytes (bfd
*, char *);
592 static unsigned int read_4_bytes (bfd
*, char *);
594 static unsigned int read_8_bytes (bfd
*, char *);
596 static CORE_ADDR
read_address (bfd
*, char *);
598 static char *read_n_bytes (bfd
*, char *, unsigned int);
600 static char *read_string (bfd
*, char *, unsigned int *);
602 static unsigned int read_unsigned_leb128 (bfd
*, char *, unsigned int *);
604 static int read_signed_leb128 (bfd
*, char *, unsigned int *);
606 static void set_cu_language (unsigned int);
608 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
610 static int die_is_declaration (struct die_info
*);
612 static void dwarf_decode_lines (unsigned int, char *, bfd
*);
614 static void dwarf2_start_subfile (char *, char *);
616 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
619 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
622 static void dwarf2_const_value_data (struct attribute
*attr
,
626 static struct type
*die_type (struct die_info
*, struct objfile
*);
628 static struct type
*die_containing_type (struct die_info
*, struct objfile
*);
631 static struct type
*type_at_offset (unsigned int, struct objfile
*);
634 static struct type
*tag_type_to_type (struct die_info
*, struct objfile
*);
636 static void read_type_die (struct die_info
*, struct objfile
*);
638 static void read_typedef (struct die_info
*, struct objfile
*);
640 static void read_base_type (struct die_info
*, struct objfile
*);
642 static void read_file_scope (struct die_info
*, struct objfile
*);
644 static void read_func_scope (struct die_info
*, struct objfile
*);
646 static void read_lexical_block_scope (struct die_info
*, struct objfile
*);
648 static int dwarf2_get_pc_bounds (struct die_info
*,
649 CORE_ADDR
*, CORE_ADDR
*, struct objfile
*);
651 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
654 static void dwarf2_attach_fields_to_type (struct field_info
*,
655 struct type
*, struct objfile
*);
657 static void dwarf2_add_member_fn (struct field_info
*,
658 struct die_info
*, struct type
*,
659 struct objfile
*objfile
);
661 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
662 struct type
*, struct objfile
*);
664 static void read_structure_scope (struct die_info
*, struct objfile
*);
666 static void read_common_block (struct die_info
*, struct objfile
*);
668 static void read_enumeration (struct die_info
*, struct objfile
*);
670 static struct type
*dwarf_base_type (int, int, struct objfile
*);
672 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct objfile
*);
674 static void read_array_type (struct die_info
*, struct objfile
*);
676 static void read_tag_pointer_type (struct die_info
*, struct objfile
*);
678 static void read_tag_ptr_to_member_type (struct die_info
*, struct objfile
*);
680 static void read_tag_reference_type (struct die_info
*, struct objfile
*);
682 static void read_tag_const_type (struct die_info
*, struct objfile
*);
684 static void read_tag_volatile_type (struct die_info
*, struct objfile
*);
686 static void read_tag_string_type (struct die_info
*, struct objfile
*);
688 static void read_subroutine_type (struct die_info
*, struct objfile
*);
690 struct die_info
*read_comp_unit (char *, bfd
*);
692 static void free_die_list (struct die_info
*);
694 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
696 static void process_die (struct die_info
*, struct objfile
*);
698 static char *dwarf2_linkage_name (struct die_info
*);
700 static char *dwarf_tag_name (unsigned int);
702 static char *dwarf_attr_name (unsigned int);
704 static char *dwarf_form_name (unsigned int);
706 static char *dwarf_stack_op_name (unsigned int);
708 static char *dwarf_bool_name (unsigned int);
710 static char *dwarf_type_encoding_name (unsigned int);
713 static char *dwarf_cfi_name (unsigned int);
715 struct die_info
*copy_die (struct die_info
*);
718 struct die_info
*sibling_die (struct die_info
*);
720 void dump_die (struct die_info
*);
722 void dump_die_list (struct die_info
*);
724 void store_in_ref_table (unsigned int, struct die_info
*);
726 static void dwarf2_empty_die_ref_table (void);
728 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
730 struct die_info
*follow_die_ref (unsigned int);
732 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
734 /* memory allocation interface */
736 static void dwarf2_free_tmp_obstack (PTR
);
738 static struct dwarf_block
*dwarf_alloc_block (void);
740 static struct abbrev_info
*dwarf_alloc_abbrev (void);
742 static struct die_info
*dwarf_alloc_die (void);
744 /* Try to locate the sections we need for DWARF 2 debugging
745 information and return true if we have enough to do something. */
748 dwarf2_has_info (abfd
)
751 dwarf_info_offset
= dwarf_abbrev_offset
= dwarf_line_offset
= 0;
752 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
753 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
763 /* This function is mapped across the sections and remembers the
764 offset and size of each of the debugging sections we are interested
768 dwarf2_locate_sections (ignore_abfd
, sectp
, ignore_ptr
)
773 if (STREQ (sectp
->name
, INFO_SECTION
))
775 dwarf_info_offset
= sectp
->filepos
;
776 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
778 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
780 dwarf_abbrev_offset
= sectp
->filepos
;
781 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
783 else if (STREQ (sectp
->name
, LINE_SECTION
))
785 dwarf_line_offset
= sectp
->filepos
;
786 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
788 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
790 dwarf_pubnames_offset
= sectp
->filepos
;
791 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
793 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
795 dwarf_aranges_offset
= sectp
->filepos
;
796 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
798 else if (STREQ (sectp
->name
, LOC_SECTION
))
800 dwarf_loc_offset
= sectp
->filepos
;
801 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
803 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
805 dwarf_macinfo_offset
= sectp
->filepos
;
806 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
808 else if (STREQ (sectp
->name
, STR_SECTION
))
810 dwarf_str_offset
= sectp
->filepos
;
811 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
815 /* Build a partial symbol table. */
818 dwarf2_build_psymtabs (objfile
, mainline
)
819 struct objfile
*objfile
;
823 /* We definitely need the .debug_info and .debug_abbrev sections */
825 dwarf_info_buffer
= dwarf2_read_section (objfile
,
828 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
831 dwarf_line_buffer
= dwarf2_read_section (objfile
,
835 if (mainline
|| objfile
->global_psymbols
.size
== 0 ||
836 objfile
->static_psymbols
.size
== 0)
838 init_psymbol_list (objfile
, 1024);
842 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
844 /* Things are significantly easier if we have .debug_aranges and
845 .debug_pubnames sections */
847 dwarf2_build_psymtabs_easy (objfile
, mainline
);
851 /* only test this case for now */
853 /* In this case we have to work a bit harder */
854 dwarf2_build_psymtabs_hard (objfile
, mainline
);
859 /* Build the partial symbol table from the information in the
860 .debug_pubnames and .debug_aranges sections. */
863 dwarf2_build_psymtabs_easy (objfile
, mainline
)
864 struct objfile
*objfile
;
867 bfd
*abfd
= objfile
->obfd
;
868 char *aranges_buffer
, *pubnames_buffer
;
869 char *aranges_ptr
, *pubnames_ptr
;
870 unsigned int entry_length
, version
, info_offset
, info_size
;
872 pubnames_buffer
= dwarf2_read_section (objfile
,
873 dwarf_pubnames_offset
,
874 dwarf_pubnames_size
);
875 pubnames_ptr
= pubnames_buffer
;
876 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
878 entry_length
= read_4_bytes (abfd
, pubnames_ptr
);
880 version
= read_1_byte (abfd
, pubnames_ptr
);
882 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
884 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
888 aranges_buffer
= dwarf2_read_section (objfile
,
889 dwarf_aranges_offset
,
895 /* Build the partial symbol table by doing a quick pass through the
896 .debug_info and .debug_abbrev sections. */
899 dwarf2_build_psymtabs_hard (objfile
, mainline
)
900 struct objfile
*objfile
;
903 /* Instead of reading this into a big buffer, we should probably use
904 mmap() on architectures that support it. (FIXME) */
905 bfd
*abfd
= objfile
->obfd
;
906 char *info_ptr
, *abbrev_ptr
;
907 char *beg_of_comp_unit
;
908 struct comp_unit_head cu_header
;
909 struct partial_die_info comp_unit_die
;
910 struct partial_symtab
*pst
;
911 struct cleanup
*back_to
;
912 int comp_unit_has_pc_info
;
913 CORE_ADDR lowpc
, highpc
;
915 info_ptr
= dwarf_info_buffer
;
916 abbrev_ptr
= dwarf_abbrev_buffer
;
918 obstack_init (&dwarf2_tmp_obstack
);
919 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
921 while ((unsigned int) (info_ptr
- dwarf_info_buffer
)
922 + ((info_ptr
- dwarf_info_buffer
) % 4) < dwarf_info_size
)
924 beg_of_comp_unit
= info_ptr
;
925 cu_header
.length
= read_4_bytes (abfd
, info_ptr
);
927 cu_header
.version
= read_2_bytes (abfd
, info_ptr
);
929 cu_header
.abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
931 cu_header
.addr_size
= read_1_byte (abfd
, info_ptr
);
933 address_size
= cu_header
.addr_size
;
935 if (cu_header
.version
!= 2)
937 error ("Dwarf Error: wrong version in compilation unit header.");
940 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
942 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
943 (long) cu_header
.abbrev_offset
,
944 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
947 if (beg_of_comp_unit
+ cu_header
.length
+ 4
948 > dwarf_info_buffer
+ dwarf_info_size
)
950 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
951 (long) cu_header
.length
,
952 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
955 /* Read the abbrevs for this compilation unit into a table */
956 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
957 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
959 /* Read the compilation unit die */
960 info_ptr
= read_partial_die (&comp_unit_die
, abfd
,
961 info_ptr
, &comp_unit_has_pc_info
);
963 /* Set the language we're debugging */
964 set_cu_language (comp_unit_die
.language
);
966 /* Allocate a new partial symbol table structure */
967 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
968 comp_unit_die
.name
? comp_unit_die
.name
: "",
970 objfile
->global_psymbols
.next
,
971 objfile
->static_psymbols
.next
);
973 pst
->read_symtab_private
= (char *)
974 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
975 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
976 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
977 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
978 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
979 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
980 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
981 baseaddr
= ANOFFSET (objfile
->section_offsets
, 0);
983 /* Store the function that reads in the rest of the symbol table */
984 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
986 /* Check if comp unit has_children.
987 If so, read the rest of the partial symbols from this comp unit.
988 If not, there's no more debug_info for this comp unit. */
989 if (comp_unit_die
.has_children
)
991 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
);
993 /* If the compilation unit didn't have an explicit address range,
994 then use the information extracted from its child dies. */
995 if (!comp_unit_has_pc_info
)
997 comp_unit_die
.lowpc
= lowpc
;
998 comp_unit_die
.highpc
= highpc
;
1001 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1002 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1004 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1005 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1006 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1007 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1008 sort_pst_symbols (pst
);
1010 /* If there is already a psymtab or symtab for a file of this
1011 name, remove it. (If there is a symtab, more drastic things
1012 also happen.) This happens in VxWorks. */
1013 free_named_symtabs (pst
->filename
);
1015 info_ptr
= beg_of_comp_unit
+ cu_header
.length
+ 4;
1017 do_cleanups (back_to
);
1020 /* Read in all interesting dies to the end of the compilation unit. */
1023 scan_partial_symbols (info_ptr
, objfile
, lowpc
, highpc
)
1025 struct objfile
*objfile
;
1029 bfd
*abfd
= objfile
->obfd
;
1030 struct partial_die_info pdi
;
1032 /* This function is called after we've read in the comp_unit_die in
1033 order to read its children. We start the nesting level at 1 since
1034 we have pushed 1 level down in order to read the comp unit's children.
1035 The comp unit itself is at level 0, so we stop reading when we pop
1036 back to that level. */
1038 int nesting_level
= 1;
1041 *lowpc
= ((CORE_ADDR
) -1);
1042 *highpc
= ((CORE_ADDR
) 0);
1044 while (nesting_level
)
1046 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, &has_pc_info
);
1052 case DW_TAG_subprogram
:
1055 if (pdi
.lowpc
< *lowpc
)
1059 if (pdi
.highpc
> *highpc
)
1061 *highpc
= pdi
.highpc
;
1063 if ((pdi
.is_external
|| nesting_level
== 1)
1064 && !pdi
.is_declaration
)
1066 add_partial_symbol (&pdi
, objfile
);
1070 case DW_TAG_variable
:
1071 case DW_TAG_typedef
:
1072 case DW_TAG_class_type
:
1073 case DW_TAG_structure_type
:
1074 case DW_TAG_union_type
:
1075 case DW_TAG_enumeration_type
:
1076 if ((pdi
.is_external
|| nesting_level
== 1)
1077 && !pdi
.is_declaration
)
1079 add_partial_symbol (&pdi
, objfile
);
1082 case DW_TAG_enumerator
:
1083 /* File scope enumerators are added to the partial symbol
1085 if (nesting_level
== 2)
1086 add_partial_symbol (&pdi
, objfile
);
1088 case DW_TAG_base_type
:
1089 /* File scope base type definitions are added to the partial
1091 if (nesting_level
== 1)
1092 add_partial_symbol (&pdi
, objfile
);
1099 /* If the die has a sibling, skip to the sibling.
1100 Do not skip enumeration types, we want to record their
1102 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1104 info_ptr
= pdi
.sibling
;
1106 else if (pdi
.has_children
)
1108 /* Die has children, but the optional DW_AT_sibling attribute
1119 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1120 from `maint check'. */
1121 if (*lowpc
== ((CORE_ADDR
) -1))
1127 add_partial_symbol (pdi
, objfile
)
1128 struct partial_die_info
*pdi
;
1129 struct objfile
*objfile
;
1135 case DW_TAG_subprogram
:
1136 if (pdi
->is_external
)
1138 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1139 mst_text, objfile); */
1140 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1141 VAR_NAMESPACE
, LOC_BLOCK
,
1142 &objfile
->global_psymbols
,
1143 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1147 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1148 mst_file_text, objfile); */
1149 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1150 VAR_NAMESPACE
, LOC_BLOCK
,
1151 &objfile
->static_psymbols
,
1152 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1155 case DW_TAG_variable
:
1156 if (pdi
->is_external
)
1159 Don't enter into the minimal symbol tables as there is
1160 a minimal symbol table entry from the ELF symbols already.
1161 Enter into partial symbol table if it has a location
1162 descriptor or a type.
1163 If the location descriptor is missing, new_symbol will create
1164 a LOC_UNRESOLVED symbol, the address of the variable will then
1165 be determined from the minimal symbol table whenever the variable
1167 The address for the partial symbol table entry is not
1168 used by GDB, but it comes in handy for debugging partial symbol
1172 addr
= decode_locdesc (pdi
->locdesc
, objfile
);
1173 if (pdi
->locdesc
|| pdi
->has_type
)
1174 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1175 VAR_NAMESPACE
, LOC_STATIC
,
1176 &objfile
->global_psymbols
,
1177 0, addr
+ baseaddr
, cu_language
, objfile
);
1181 /* Static Variable. Skip symbols without location descriptors. */
1182 if (pdi
->locdesc
== NULL
)
1184 addr
= decode_locdesc (pdi
->locdesc
, objfile
);
1185 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1186 mst_file_data, objfile); */
1187 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1188 VAR_NAMESPACE
, LOC_STATIC
,
1189 &objfile
->static_psymbols
,
1190 0, addr
+ baseaddr
, cu_language
, objfile
);
1193 case DW_TAG_typedef
:
1194 case DW_TAG_base_type
:
1195 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1196 VAR_NAMESPACE
, LOC_TYPEDEF
,
1197 &objfile
->static_psymbols
,
1198 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1200 case DW_TAG_class_type
:
1201 case DW_TAG_structure_type
:
1202 case DW_TAG_union_type
:
1203 case DW_TAG_enumeration_type
:
1204 /* Skip aggregate types without children, these are external
1206 if (pdi
->has_children
== 0)
1208 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1209 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1210 &objfile
->static_psymbols
,
1211 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1213 if (cu_language
== language_cplus
)
1215 /* For C++, these implicitly act as typedefs as well. */
1216 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1217 VAR_NAMESPACE
, LOC_TYPEDEF
,
1218 &objfile
->static_psymbols
,
1219 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1222 case DW_TAG_enumerator
:
1223 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1224 VAR_NAMESPACE
, LOC_CONST
,
1225 &objfile
->static_psymbols
,
1226 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1233 /* Expand this partial symbol table into a full symbol table. */
1236 dwarf2_psymtab_to_symtab (pst
)
1237 struct partial_symtab
*pst
;
1239 /* FIXME: This is barely more than a stub. */
1244 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1250 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1251 gdb_flush (gdb_stdout
);
1254 psymtab_to_symtab_1 (pst
);
1256 /* Finish up the debug error message. */
1258 printf_filtered ("done.\n");
1264 psymtab_to_symtab_1 (pst
)
1265 struct partial_symtab
*pst
;
1267 struct objfile
*objfile
= pst
->objfile
;
1268 bfd
*abfd
= objfile
->obfd
;
1269 struct comp_unit_head cu_header
;
1270 struct die_info
*dies
;
1271 unsigned long offset
;
1272 CORE_ADDR lowpc
, highpc
;
1273 struct die_info
*child_die
;
1275 struct symtab
*symtab
;
1276 struct cleanup
*back_to
;
1278 /* Set local variables from the partial symbol table info. */
1279 offset
= DWARF_INFO_OFFSET (pst
);
1280 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1281 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1282 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1283 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1284 baseaddr
= ANOFFSET (pst
->section_offsets
, 0);
1285 cu_header_offset
= offset
;
1286 info_ptr
= dwarf_info_buffer
+ offset
;
1288 obstack_init (&dwarf2_tmp_obstack
);
1289 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1292 make_cleanup (really_free_pendings
, NULL
);
1294 /* read in the comp_unit header */
1295 cu_header
.length
= read_4_bytes (abfd
, info_ptr
);
1297 cu_header
.version
= read_2_bytes (abfd
, info_ptr
);
1299 cu_header
.abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
1301 cu_header
.addr_size
= read_1_byte (abfd
, info_ptr
);
1304 /* Read the abbrevs for this compilation unit */
1305 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1306 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1308 dies
= read_comp_unit (info_ptr
, abfd
);
1310 make_cleanup_free_die_list (dies
);
1312 /* Do line number decoding in read_file_scope () */
1313 process_die (dies
, objfile
);
1315 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1317 /* Some compilers don't define a DW_AT_high_pc attribute for
1318 the compilation unit. If the DW_AT_high_pc is missing,
1319 synthesize it, by scanning the DIE's below the compilation unit. */
1321 if (dies
->has_children
)
1323 child_die
= dies
->next
;
1324 while (child_die
&& child_die
->tag
)
1326 if (child_die
->tag
== DW_TAG_subprogram
)
1328 CORE_ADDR low
, high
;
1330 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1332 highpc
= max (highpc
, high
);
1335 child_die
= sibling_die (child_die
);
1339 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, 0);
1341 /* Set symtab language to language from DW_AT_language.
1342 If the compilation is from a C file generated by language preprocessors,
1343 do not set the language if it was already deduced by start_subfile. */
1345 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1347 symtab
->language
= cu_language
;
1349 pst
->symtab
= symtab
;
1351 sort_symtab_syms (pst
->symtab
);
1353 do_cleanups (back_to
);
1356 /* Process a die and its children. */
1359 process_die (die
, objfile
)
1360 struct die_info
*die
;
1361 struct objfile
*objfile
;
1365 case DW_TAG_padding
:
1367 case DW_TAG_compile_unit
:
1368 read_file_scope (die
, objfile
);
1370 case DW_TAG_subprogram
:
1371 read_subroutine_type (die
, objfile
);
1372 read_func_scope (die
, objfile
);
1374 case DW_TAG_inlined_subroutine
:
1375 /* FIXME: These are ignored for now.
1376 They could be used to set breakpoints on all inlined instances
1377 of a function and make GDB `next' properly over inlined functions. */
1379 case DW_TAG_lexical_block
:
1380 read_lexical_block_scope (die
, objfile
);
1382 case DW_TAG_class_type
:
1383 case DW_TAG_structure_type
:
1384 case DW_TAG_union_type
:
1385 read_structure_scope (die
, objfile
);
1387 case DW_TAG_enumeration_type
:
1388 read_enumeration (die
, objfile
);
1390 case DW_TAG_subroutine_type
:
1391 read_subroutine_type (die
, objfile
);
1393 case DW_TAG_array_type
:
1394 read_array_type (die
, objfile
);
1396 case DW_TAG_pointer_type
:
1397 read_tag_pointer_type (die
, objfile
);
1399 case DW_TAG_ptr_to_member_type
:
1400 read_tag_ptr_to_member_type (die
, objfile
);
1402 case DW_TAG_reference_type
:
1403 read_tag_reference_type (die
, objfile
);
1405 case DW_TAG_string_type
:
1406 read_tag_string_type (die
, objfile
);
1408 case DW_TAG_base_type
:
1409 read_base_type (die
, objfile
);
1410 if (dwarf_attr (die
, DW_AT_name
))
1412 /* Add a typedef symbol for the base type definition. */
1413 new_symbol (die
, die
->type
, objfile
);
1416 case DW_TAG_common_block
:
1417 read_common_block (die
, objfile
);
1419 case DW_TAG_common_inclusion
:
1422 new_symbol (die
, NULL
, objfile
);
1428 read_file_scope (die
, objfile
)
1429 struct die_info
*die
;
1430 struct objfile
*objfile
;
1432 unsigned int line_offset
= 0;
1433 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1434 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1435 struct attribute
*attr
;
1436 char *name
= "<unknown>";
1437 char *comp_dir
= NULL
;
1438 struct die_info
*child_die
;
1439 bfd
*abfd
= objfile
->obfd
;
1441 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1443 if (die
->has_children
)
1445 child_die
= die
->next
;
1446 while (child_die
&& child_die
->tag
)
1448 if (child_die
->tag
== DW_TAG_subprogram
)
1450 CORE_ADDR low
, high
;
1452 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1454 lowpc
= min (lowpc
, low
);
1455 highpc
= max (highpc
, high
);
1458 child_die
= sibling_die (child_die
);
1463 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1464 from finish_block. */
1465 if (lowpc
== ((CORE_ADDR
) -1))
1470 attr
= dwarf_attr (die
, DW_AT_name
);
1473 name
= DW_STRING (attr
);
1475 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1478 comp_dir
= DW_STRING (attr
);
1481 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1482 directory, get rid of it. */
1483 char *cp
= strchr (comp_dir
, ':');
1485 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1490 if (objfile
->ei
.entry_point
>= lowpc
&&
1491 objfile
->ei
.entry_point
< highpc
)
1493 objfile
->ei
.entry_file_lowpc
= lowpc
;
1494 objfile
->ei
.entry_file_highpc
= highpc
;
1497 attr
= dwarf_attr (die
, DW_AT_language
);
1500 set_cu_language (DW_UNSND (attr
));
1503 /* We assume that we're processing GCC output. */
1504 processing_gcc_compilation
= 2;
1506 /* FIXME:Do something here. */
1507 if (dip
->at_producer
!= NULL
)
1509 handle_producer (dip
->at_producer
);
1513 /* The compilation unit may be in a different language or objfile,
1514 zero out all remembered fundamental types. */
1515 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1517 start_symtab (name
, comp_dir
, lowpc
);
1518 record_debugformat ("DWARF 2");
1520 /* Decode line number information if present. */
1521 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1524 line_offset
= DW_UNSND (attr
);
1525 dwarf_decode_lines (line_offset
, comp_dir
, abfd
);
1528 /* Process all dies in compilation unit. */
1529 if (die
->has_children
)
1531 child_die
= die
->next
;
1532 while (child_die
&& child_die
->tag
)
1534 process_die (child_die
, objfile
);
1535 child_die
= sibling_die (child_die
);
1541 read_func_scope (die
, objfile
)
1542 struct die_info
*die
;
1543 struct objfile
*objfile
;
1545 register struct context_stack
*new;
1548 struct die_info
*child_die
;
1549 struct attribute
*attr
;
1552 name
= dwarf2_linkage_name (die
);
1554 /* Ignore functions with missing or empty names and functions with
1555 missing or invalid low and high pc attributes. */
1556 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1562 if (objfile
->ei
.entry_point
>= lowpc
&&
1563 objfile
->ei
.entry_point
< highpc
)
1565 objfile
->ei
.entry_func_lowpc
= lowpc
;
1566 objfile
->ei
.entry_func_highpc
= highpc
;
1569 /* Decode DW_AT_frame_base location descriptor if present, keep result
1570 for DW_OP_fbreg operands in decode_locdesc. */
1571 frame_base_reg
= -1;
1572 frame_base_offset
= 0;
1573 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1576 CORE_ADDR addr
= decode_locdesc (DW_BLOCK (attr
), objfile
);
1578 complain (&dwarf2_unsupported_at_frame_base
, name
);
1580 frame_base_reg
= addr
;
1583 frame_base_reg
= basereg
;
1584 frame_base_offset
= addr
;
1587 complain (&dwarf2_unsupported_at_frame_base
, name
);
1590 new = push_context (0, lowpc
);
1591 new->name
= new_symbol (die
, die
->type
, objfile
);
1592 list_in_scope
= &local_symbols
;
1594 if (die
->has_children
)
1596 child_die
= die
->next
;
1597 while (child_die
&& child_die
->tag
)
1599 process_die (child_die
, objfile
);
1600 child_die
= sibling_die (child_die
);
1604 new = pop_context ();
1605 /* Make a block for the local symbols within. */
1606 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1607 lowpc
, highpc
, objfile
);
1608 list_in_scope
= &file_symbols
;
1611 /* Process all the DIES contained within a lexical block scope. Start
1612 a new scope, process the dies, and then close the scope. */
1615 read_lexical_block_scope (die
, objfile
)
1616 struct die_info
*die
;
1617 struct objfile
*objfile
;
1619 register struct context_stack
*new;
1620 CORE_ADDR lowpc
, highpc
;
1621 struct die_info
*child_die
;
1623 /* Ignore blocks with missing or invalid low and high pc attributes. */
1624 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1629 push_context (0, lowpc
);
1630 if (die
->has_children
)
1632 child_die
= die
->next
;
1633 while (child_die
&& child_die
->tag
)
1635 process_die (child_die
, objfile
);
1636 child_die
= sibling_die (child_die
);
1639 new = pop_context ();
1641 if (local_symbols
!= NULL
)
1643 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1646 local_symbols
= new->locals
;
1649 /* Get low and high pc attributes from a die.
1650 Return 1 if the attributes are present and valid, otherwise, return 0. */
1653 dwarf2_get_pc_bounds (die
, lowpc
, highpc
, objfile
)
1654 struct die_info
*die
;
1657 struct objfile
*objfile
;
1659 struct attribute
*attr
;
1663 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1665 low
= DW_ADDR (attr
);
1668 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1670 high
= DW_ADDR (attr
);
1677 /* When using the GNU linker, .gnu.linkonce. sections are used to
1678 eliminate duplicate copies of functions and vtables and such.
1679 The linker will arbitrarily choose one and discard the others.
1680 The AT_*_pc values for such functions refer to local labels in
1681 these sections. If the section from that file was discarded, the
1682 labels are not in the output, so the relocs get a value of 0.
1683 If this is a discarded function, mark the pc bounds as invalid,
1684 so that GDB will ignore it. */
1685 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
1693 /* Add an aggregate field to the field list. */
1696 dwarf2_add_field (fip
, die
, objfile
)
1697 struct field_info
*fip
;
1698 struct die_info
*die
;
1699 struct objfile
*objfile
;
1701 struct nextfield
*new_field
;
1702 struct attribute
*attr
;
1704 char *fieldname
= "";
1706 /* Allocate a new field list entry and link it in. */
1707 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1708 make_cleanup (free
, new_field
);
1709 memset (new_field
, 0, sizeof (struct nextfield
));
1710 new_field
->next
= fip
->fields
;
1711 fip
->fields
= new_field
;
1714 /* Handle accessibility and virtuality of field.
1715 The default accessibility for members is public, the default
1716 accessibility for inheritance is private. */
1717 if (die
->tag
!= DW_TAG_inheritance
)
1718 new_field
->accessibility
= DW_ACCESS_public
;
1720 new_field
->accessibility
= DW_ACCESS_private
;
1721 new_field
->virtuality
= DW_VIRTUALITY_none
;
1723 attr
= dwarf_attr (die
, DW_AT_accessibility
);
1725 new_field
->accessibility
= DW_UNSND (attr
);
1726 if (new_field
->accessibility
!= DW_ACCESS_public
)
1727 fip
->non_public_fields
= 1;
1728 attr
= dwarf_attr (die
, DW_AT_virtuality
);
1730 new_field
->virtuality
= DW_UNSND (attr
);
1732 fp
= &new_field
->field
;
1733 if (die
->tag
== DW_TAG_member
)
1735 /* Get type of field. */
1736 fp
->type
= die_type (die
, objfile
);
1738 /* Get bit size of field (zero if none). */
1739 attr
= dwarf_attr (die
, DW_AT_bit_size
);
1742 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
1746 FIELD_BITSIZE (*fp
) = 0;
1749 /* Get bit offset of field. */
1750 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1753 FIELD_BITPOS (*fp
) =
1754 decode_locdesc (DW_BLOCK (attr
), objfile
) * bits_per_byte
;
1757 FIELD_BITPOS (*fp
) = 0;
1758 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
1761 if (BITS_BIG_ENDIAN
)
1763 /* For big endian bits, the DW_AT_bit_offset gives the
1764 additional bit offset from the MSB of the containing
1765 anonymous object to the MSB of the field. We don't
1766 have to do anything special since we don't need to
1767 know the size of the anonymous object. */
1768 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
1772 /* For little endian bits, compute the bit offset to the
1773 MSB of the anonymous object, subtract off the number of
1774 bits from the MSB of the field to the MSB of the
1775 object, and then subtract off the number of bits of
1776 the field itself. The result is the bit offset of
1777 the LSB of the field. */
1779 int bit_offset
= DW_UNSND (attr
);
1781 attr
= dwarf_attr (die
, DW_AT_byte_size
);
1784 /* The size of the anonymous object containing
1785 the bit field is explicit, so use the
1786 indicated size (in bytes). */
1787 anonymous_size
= DW_UNSND (attr
);
1791 /* The size of the anonymous object containing
1792 the bit field must be inferred from the type
1793 attribute of the data member containing the
1795 anonymous_size
= TYPE_LENGTH (fp
->type
);
1797 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
1798 - bit_offset
- FIELD_BITSIZE (*fp
);
1802 /* Get name of field. */
1803 attr
= dwarf_attr (die
, DW_AT_name
);
1804 if (attr
&& DW_STRING (attr
))
1805 fieldname
= DW_STRING (attr
);
1806 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
1807 &objfile
->type_obstack
);
1809 /* Change accessibility for artificial fields (e.g. virtual table
1810 pointer or virtual base class pointer) to private. */
1811 if (dwarf_attr (die
, DW_AT_artificial
))
1813 new_field
->accessibility
= DW_ACCESS_private
;
1814 fip
->non_public_fields
= 1;
1817 else if (die
->tag
== DW_TAG_variable
)
1821 /* C++ static member.
1822 Get name of field. */
1823 attr
= dwarf_attr (die
, DW_AT_name
);
1824 if (attr
&& DW_STRING (attr
))
1825 fieldname
= DW_STRING (attr
);
1829 /* Get physical name. */
1830 physname
= dwarf2_linkage_name (die
);
1832 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
1833 &objfile
->type_obstack
));
1834 FIELD_TYPE (*fp
) = die_type (die
, objfile
);
1835 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
1836 &objfile
->type_obstack
);
1838 else if (die
->tag
== DW_TAG_inheritance
)
1840 /* C++ base class field. */
1841 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1843 FIELD_BITPOS (*fp
) = decode_locdesc (DW_BLOCK (attr
), objfile
) * bits_per_byte
;
1844 FIELD_BITSIZE (*fp
) = 0;
1845 FIELD_TYPE (*fp
) = die_type (die
, objfile
);
1846 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
1847 fip
->nbaseclasses
++;
1851 /* Create the vector of fields, and attach it to the type. */
1854 dwarf2_attach_fields_to_type (fip
, type
, objfile
)
1855 struct field_info
*fip
;
1857 struct objfile
*objfile
;
1859 int nfields
= fip
->nfields
;
1861 /* Record the field count, allocate space for the array of fields,
1862 and create blank accessibility bitfields if necessary. */
1863 TYPE_NFIELDS (type
) = nfields
;
1864 TYPE_FIELDS (type
) = (struct field
*)
1865 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
1866 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
1868 if (fip
->non_public_fields
)
1870 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1872 TYPE_FIELD_PRIVATE_BITS (type
) =
1873 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1874 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
1876 TYPE_FIELD_PROTECTED_BITS (type
) =
1877 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1878 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
1880 TYPE_FIELD_IGNORE_BITS (type
) =
1881 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1882 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
1885 /* If the type has baseclasses, allocate and clear a bit vector for
1886 TYPE_FIELD_VIRTUAL_BITS. */
1887 if (fip
->nbaseclasses
)
1889 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
1892 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1893 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
1894 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
1895 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
1896 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
1899 /* Copy the saved-up fields into the field vector. Start from the head
1900 of the list, adding to the tail of the field array, so that they end
1901 up in the same order in the array in which they were added to the list. */
1902 while (nfields
-- > 0)
1904 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
1905 switch (fip
->fields
->accessibility
)
1907 case DW_ACCESS_private
:
1908 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
1911 case DW_ACCESS_protected
:
1912 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
1915 case DW_ACCESS_public
:
1919 /* Unknown accessibility. Complain and treat it as public. */
1921 complain (&dwarf2_unsupported_accessibility
,
1922 fip
->fields
->accessibility
);
1926 if (nfields
< fip
->nbaseclasses
)
1928 switch (fip
->fields
->virtuality
)
1930 case DW_VIRTUALITY_virtual
:
1931 case DW_VIRTUALITY_pure_virtual
:
1932 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
1936 fip
->fields
= fip
->fields
->next
;
1940 /* Add a member function to the proper fieldlist. */
1943 dwarf2_add_member_fn (fip
, die
, type
, objfile
)
1944 struct field_info
*fip
;
1945 struct die_info
*die
;
1947 struct objfile
*objfile
;
1949 struct attribute
*attr
;
1950 struct fnfieldlist
*flp
;
1952 struct fn_field
*fnp
;
1955 struct nextfnfield
*new_fnfield
;
1957 /* Get name of member function. */
1958 attr
= dwarf_attr (die
, DW_AT_name
);
1959 if (attr
&& DW_STRING (attr
))
1960 fieldname
= DW_STRING (attr
);
1964 /* Get the mangled name. */
1965 physname
= dwarf2_linkage_name (die
);
1967 /* Look up member function name in fieldlist. */
1968 for (i
= 0; i
< fip
->nfnfields
; i
++)
1970 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
1974 /* Create new list element if necessary. */
1975 if (i
< fip
->nfnfields
)
1976 flp
= &fip
->fnfieldlists
[i
];
1979 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
1981 fip
->fnfieldlists
= (struct fnfieldlist
*)
1982 xrealloc (fip
->fnfieldlists
,
1983 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
1984 * sizeof (struct fnfieldlist
));
1985 if (fip
->nfnfields
== 0)
1986 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
1988 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
1989 flp
->name
= fieldname
;
1995 /* Create a new member function field and chain it to the field list
1997 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
1998 make_cleanup (free
, new_fnfield
);
1999 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2000 new_fnfield
->next
= flp
->head
;
2001 flp
->head
= new_fnfield
;
2004 /* Fill in the member function field info. */
2005 fnp
= &new_fnfield
->fnfield
;
2006 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2007 &objfile
->type_obstack
);
2008 fnp
->type
= alloc_type (objfile
);
2009 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2011 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2012 struct type
**arg_types
;
2013 int nparams
= TYPE_NFIELDS (die
->type
);
2016 /* Copy argument types from the subroutine type. */
2017 arg_types
= (struct type
**)
2018 TYPE_ALLOC (fnp
->type
, (nparams
+ 1) * sizeof (struct type
*));
2019 for (iparams
= 0; iparams
< nparams
; iparams
++)
2020 arg_types
[iparams
] = TYPE_FIELD_TYPE (die
->type
, iparams
);
2022 /* Set last entry in argument type vector. */
2023 if (TYPE_FLAGS (die
->type
) & TYPE_FLAG_VARARGS
)
2024 arg_types
[nparams
] = NULL
;
2026 arg_types
[nparams
] = dwarf2_fundamental_type (objfile
, FT_VOID
);
2028 smash_to_method_type (fnp
->type
, type
, return_type
, arg_types
);
2030 /* Handle static member functions.
2031 Dwarf2 has no clean way to discern C++ static and non-static
2032 member functions. G++ helps GDB by marking the first
2033 parameter for non-static member functions (which is the
2034 this pointer) as artificial. We obtain this information
2035 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2036 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2037 fnp
->voffset
= VOFFSET_STATIC
;
2040 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2042 /* Get fcontext from DW_AT_containing_type if present. */
2043 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2044 fnp
->fcontext
= die_containing_type (die
, objfile
);
2046 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2047 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2049 /* Get accessibility. */
2050 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2053 switch (DW_UNSND (attr
))
2055 case DW_ACCESS_private
:
2056 fnp
->is_private
= 1;
2058 case DW_ACCESS_protected
:
2059 fnp
->is_protected
= 1;
2064 /* Get index in virtual function table if it is a virtual member function. */
2065 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2067 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
) + 2;
2070 /* Create the vector of member function fields, and attach it to the type. */
2073 dwarf2_attach_fn_fields_to_type (fip
, type
, objfile
)
2074 struct field_info
*fip
;
2076 struct objfile
*objfile
;
2078 struct fnfieldlist
*flp
;
2079 int total_length
= 0;
2082 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2083 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2084 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2086 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2088 struct nextfnfield
*nfp
= flp
->head
;
2089 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2092 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2093 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2094 fn_flp
->fn_fields
= (struct fn_field
*)
2095 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2096 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2097 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2099 total_length
+= flp
->length
;
2102 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2103 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2106 /* Called when we find the DIE that starts a structure or union scope
2107 (definition) to process all dies that define the members of the
2110 NOTE: we need to call struct_type regardless of whether or not the
2111 DIE has an at_name attribute, since it might be an anonymous
2112 structure or union. This gets the type entered into our set of
2115 However, if the structure is incomplete (an opaque struct/union)
2116 then suppress creating a symbol table entry for it since gdb only
2117 wants to find the one with the complete definition. Note that if
2118 it is complete, we just call new_symbol, which does it's own
2119 checking about whether the struct/union is anonymous or not (and
2120 suppresses creating a symbol table entry itself). */
2123 read_structure_scope (die
, objfile
)
2124 struct die_info
*die
;
2125 struct objfile
*objfile
;
2128 struct attribute
*attr
;
2130 type
= alloc_type (objfile
);
2132 INIT_CPLUS_SPECIFIC (type
);
2133 attr
= dwarf_attr (die
, DW_AT_name
);
2134 if (attr
&& DW_STRING (attr
))
2136 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2137 strlen (DW_STRING (attr
)),
2138 &objfile
->type_obstack
);
2141 if (die
->tag
== DW_TAG_structure_type
)
2143 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2145 else if (die
->tag
== DW_TAG_union_type
)
2147 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2151 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2153 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2156 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2159 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2163 TYPE_LENGTH (type
) = 0;
2166 /* We need to add the type field to the die immediately so we don't
2167 infinitely recurse when dealing with pointers to the structure
2168 type within the structure itself. */
2171 if (die
->has_children
&& ! die_is_declaration (die
))
2173 struct field_info fi
;
2174 struct die_info
*child_die
;
2175 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2177 memset (&fi
, 0, sizeof (struct field_info
));
2179 child_die
= die
->next
;
2181 while (child_die
&& child_die
->tag
)
2183 if (child_die
->tag
== DW_TAG_member
)
2185 dwarf2_add_field (&fi
, child_die
, objfile
);
2187 else if (child_die
->tag
== DW_TAG_variable
)
2189 /* C++ static member. */
2190 dwarf2_add_field (&fi
, child_die
, objfile
);
2192 else if (child_die
->tag
== DW_TAG_subprogram
)
2194 /* C++ member function. */
2195 process_die (child_die
, objfile
);
2196 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
);
2198 else if (child_die
->tag
== DW_TAG_inheritance
)
2200 /* C++ base class field. */
2201 dwarf2_add_field (&fi
, child_die
, objfile
);
2205 process_die (child_die
, objfile
);
2207 child_die
= sibling_die (child_die
);
2210 /* Attach fields and member functions to the type. */
2212 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2215 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2217 /* Get the type which refers to the base class (possibly this
2218 class itself) which contains the vtable pointer for the current
2219 class from the DW_AT_containing_type attribute. */
2221 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2223 struct type
*t
= die_containing_type (die
, objfile
);
2225 TYPE_VPTR_BASETYPE (type
) = t
;
2228 static const char vptr_name
[] =
2229 {'_', 'v', 'p', 't', 'r', '\0'};
2232 /* Our own class provides vtbl ptr. */
2233 for (i
= TYPE_NFIELDS (t
) - 1;
2234 i
>= TYPE_N_BASECLASSES (t
);
2237 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2239 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2240 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2242 TYPE_VPTR_FIELDNO (type
) = i
;
2247 /* Complain if virtual function table field not found. */
2248 if (i
< TYPE_N_BASECLASSES (t
))
2249 complain (&dwarf2_vtbl_not_found_complaint
,
2250 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2254 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2259 new_symbol (die
, type
, objfile
);
2261 do_cleanups (back_to
);
2265 /* No children, must be stub. */
2266 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2272 /* Given a pointer to a die which begins an enumeration, process all
2273 the dies that define the members of the enumeration.
2275 This will be much nicer in draft 6 of the DWARF spec when our
2276 members will be dies instead squished into the DW_AT_element_list
2279 NOTE: We reverse the order of the element list. */
2282 read_enumeration (die
, objfile
)
2283 struct die_info
*die
;
2284 struct objfile
*objfile
;
2286 struct die_info
*child_die
;
2288 struct field
*fields
;
2289 struct attribute
*attr
;
2292 int unsigned_enum
= 1;
2294 type
= alloc_type (objfile
);
2296 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2297 attr
= dwarf_attr (die
, DW_AT_name
);
2298 if (attr
&& DW_STRING (attr
))
2300 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2301 strlen (DW_STRING (attr
)),
2302 &objfile
->type_obstack
);
2305 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2308 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2312 TYPE_LENGTH (type
) = 0;
2317 if (die
->has_children
)
2319 child_die
= die
->next
;
2320 while (child_die
&& child_die
->tag
)
2322 if (child_die
->tag
!= DW_TAG_enumerator
)
2324 process_die (child_die
, objfile
);
2328 attr
= dwarf_attr (child_die
, DW_AT_name
);
2331 sym
= new_symbol (child_die
, type
, objfile
);
2332 if (SYMBOL_VALUE (sym
) < 0)
2335 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2337 fields
= (struct field
*)
2339 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2340 * sizeof (struct field
));
2343 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2344 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2345 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2346 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2352 child_die
= sibling_die (child_die
);
2357 TYPE_NFIELDS (type
) = num_fields
;
2358 TYPE_FIELDS (type
) = (struct field
*)
2359 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2360 memcpy (TYPE_FIELDS (type
), fields
,
2361 sizeof (struct field
) * num_fields
);
2365 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2368 new_symbol (die
, type
, objfile
);
2371 /* Extract all information from a DW_TAG_array_type DIE and put it in
2372 the DIE's type field. For now, this only handles one dimensional
2376 read_array_type (die
, objfile
)
2377 struct die_info
*die
;
2378 struct objfile
*objfile
;
2380 struct die_info
*child_die
;
2381 struct type
*type
= NULL
;
2382 struct type
*element_type
, *range_type
, *index_type
;
2383 struct type
**range_types
= NULL
;
2384 struct attribute
*attr
;
2386 struct cleanup
*back_to
;
2388 /* Return if we've already decoded this type. */
2394 element_type
= die_type (die
, objfile
);
2396 /* Irix 6.2 native cc creates array types without children for
2397 arrays with unspecified length. */
2398 if (die
->has_children
== 0)
2400 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2401 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2402 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2406 back_to
= make_cleanup (null_cleanup
, NULL
);
2407 child_die
= die
->next
;
2408 while (child_die
&& child_die
->tag
)
2410 if (child_die
->tag
== DW_TAG_subrange_type
)
2412 unsigned int low
, high
;
2414 /* Default bounds to an array with unspecified length. */
2417 if (cu_language
== language_fortran
)
2419 /* FORTRAN implies a lower bound of 1, if not given. */
2423 index_type
= die_type (child_die
, objfile
);
2424 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2427 if (attr
->form
== DW_FORM_sdata
)
2429 low
= DW_SND (attr
);
2431 else if (attr
->form
== DW_FORM_udata
2432 || attr
->form
== DW_FORM_data1
2433 || attr
->form
== DW_FORM_data2
2434 || attr
->form
== DW_FORM_data4
)
2436 low
= DW_UNSND (attr
);
2440 complain (&dwarf2_non_const_array_bound_ignored
,
2441 dwarf_form_name (attr
->form
));
2443 die
->type
= lookup_pointer_type (element_type
);
2450 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2453 if (attr
->form
== DW_FORM_sdata
)
2455 high
= DW_SND (attr
);
2457 else if (attr
->form
== DW_FORM_udata
2458 || attr
->form
== DW_FORM_data1
2459 || attr
->form
== DW_FORM_data2
2460 || attr
->form
== DW_FORM_data4
)
2462 high
= DW_UNSND (attr
);
2464 else if (attr
->form
== DW_FORM_block1
)
2466 /* GCC encodes arrays with unspecified or dynamic length
2467 with a DW_FORM_block1 attribute.
2468 FIXME: GDB does not yet know how to handle dynamic
2469 arrays properly, treat them as arrays with unspecified
2475 complain (&dwarf2_non_const_array_bound_ignored
,
2476 dwarf_form_name (attr
->form
));
2478 die
->type
= lookup_pointer_type (element_type
);
2486 /* Create a range type and save it for array type creation. */
2487 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2489 range_types
= (struct type
**)
2490 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2491 * sizeof (struct type
*));
2493 make_cleanup (free_current_contents
, &range_types
);
2495 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2497 child_die
= sibling_die (child_die
);
2500 /* Dwarf2 dimensions are output from left to right, create the
2501 necessary array types in backwards order. */
2502 type
= element_type
;
2504 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2506 do_cleanups (back_to
);
2508 /* Install the type in the die. */
2512 /* First cut: install each common block member as a global variable. */
2515 read_common_block (die
, objfile
)
2516 struct die_info
*die
;
2517 struct objfile
*objfile
;
2519 struct die_info
*child_die
;
2520 struct attribute
*attr
;
2522 CORE_ADDR base
= (CORE_ADDR
) 0;
2524 attr
= dwarf_attr (die
, DW_AT_location
);
2527 base
= decode_locdesc (DW_BLOCK (attr
), objfile
);
2529 if (die
->has_children
)
2531 child_die
= die
->next
;
2532 while (child_die
&& child_die
->tag
)
2534 sym
= new_symbol (child_die
, NULL
, objfile
);
2535 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2538 SYMBOL_VALUE_ADDRESS (sym
) =
2539 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
);
2540 add_symbol_to_list (sym
, &global_symbols
);
2542 child_die
= sibling_die (child_die
);
2547 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2548 the user defined type vector. */
2551 read_tag_pointer_type (die
, objfile
)
2552 struct die_info
*die
;
2553 struct objfile
*objfile
;
2556 struct attribute
*attr
;
2563 type
= lookup_pointer_type (die_type (die
, objfile
));
2564 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2567 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2571 TYPE_LENGTH (type
) = address_size
;
2576 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2577 the user defined type vector. */
2580 read_tag_ptr_to_member_type (die
, objfile
)
2581 struct die_info
*die
;
2582 struct objfile
*objfile
;
2585 struct type
*to_type
;
2586 struct type
*domain
;
2593 type
= alloc_type (objfile
);
2594 to_type
= die_type (die
, objfile
);
2595 domain
= die_containing_type (die
, objfile
);
2596 smash_to_member_type (type
, domain
, to_type
);
2601 /* Extract all information from a DW_TAG_reference_type DIE and add to
2602 the user defined type vector. */
2605 read_tag_reference_type (die
, objfile
)
2606 struct die_info
*die
;
2607 struct objfile
*objfile
;
2610 struct attribute
*attr
;
2617 type
= lookup_reference_type (die_type (die
, objfile
));
2618 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2621 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2625 TYPE_LENGTH (type
) = address_size
;
2631 read_tag_const_type (die
, objfile
)
2632 struct die_info
*die
;
2633 struct objfile
*objfile
;
2640 complain (&dwarf2_const_ignored
);
2641 die
->type
= die_type (die
, objfile
);
2645 read_tag_volatile_type (die
, objfile
)
2646 struct die_info
*die
;
2647 struct objfile
*objfile
;
2654 complain (&dwarf2_volatile_ignored
);
2655 die
->type
= die_type (die
, objfile
);
2658 /* Extract all information from a DW_TAG_string_type DIE and add to
2659 the user defined type vector. It isn't really a user defined type,
2660 but it behaves like one, with other DIE's using an AT_user_def_type
2661 attribute to reference it. */
2664 read_tag_string_type (die
, objfile
)
2665 struct die_info
*die
;
2666 struct objfile
*objfile
;
2668 struct type
*type
, *range_type
, *index_type
, *char_type
;
2669 struct attribute
*attr
;
2670 unsigned int length
;
2677 attr
= dwarf_attr (die
, DW_AT_string_length
);
2680 length
= DW_UNSND (attr
);
2686 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2687 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2688 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2689 type
= create_string_type (char_type
, range_type
);
2693 /* Handle DIES due to C code like:
2697 int (*funcp)(int a, long l);
2701 ('funcp' generates a DW_TAG_subroutine_type DIE)
2705 read_subroutine_type (die
, objfile
)
2706 struct die_info
*die
;
2707 struct objfile
*objfile
;
2709 struct type
*type
; /* Type that this function returns */
2710 struct type
*ftype
; /* Function that returns above type */
2711 struct attribute
*attr
;
2713 /* Decode the type that this subroutine returns */
2718 type
= die_type (die
, objfile
);
2719 ftype
= lookup_function_type (type
);
2721 /* All functions in C++ have prototypes. */
2722 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2723 if ((attr
&& (DW_UNSND (attr
) != 0))
2724 || cu_language
== language_cplus
)
2725 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2727 if (die
->has_children
)
2729 struct die_info
*child_die
;
2733 /* Count the number of parameters.
2734 FIXME: GDB currently ignores vararg functions, but knows about
2735 vararg member functions. */
2736 child_die
= die
->next
;
2737 while (child_die
&& child_die
->tag
)
2739 if (child_die
->tag
== DW_TAG_formal_parameter
)
2741 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2742 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2743 child_die
= sibling_die (child_die
);
2746 /* Allocate storage for parameters and fill them in. */
2747 TYPE_NFIELDS (ftype
) = nparams
;
2748 TYPE_FIELDS (ftype
) = (struct field
*)
2749 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2751 child_die
= die
->next
;
2752 while (child_die
&& child_die
->tag
)
2754 if (child_die
->tag
== DW_TAG_formal_parameter
)
2756 /* Dwarf2 has no clean way to discern C++ static and non-static
2757 member functions. G++ helps GDB by marking the first
2758 parameter for non-static member functions (which is the
2759 this pointer) as artificial. We pass this information
2760 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2761 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
2763 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
2765 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
2766 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
);
2769 child_die
= sibling_die (child_die
);
2777 read_typedef (die
, objfile
)
2778 struct die_info
*die
;
2779 struct objfile
*objfile
;
2785 struct attribute
*attr
;
2788 xtype
= die_type (die
, objfile
);
2790 type
= alloc_type (objfile
);
2791 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2792 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2793 TYPE_TARGET_TYPE (type
) = xtype
;
2794 attr
= dwarf_attr (die
, DW_AT_name
);
2795 if (attr
&& DW_STRING (attr
))
2796 TYPE_NAME (type
) = obsavestring (DW_STRING (attr
),
2797 strlen (DW_STRING (attr
)),
2798 &objfile
->type_obstack
);
2804 /* Find a representation of a given base type and install
2805 it in the TYPE field of the die. */
2808 read_base_type (die
, objfile
)
2809 struct die_info
*die
;
2810 struct objfile
*objfile
;
2813 struct attribute
*attr
;
2814 int encoding
= 0, size
= 0;
2816 /* If we've already decoded this die, this is a no-op. */
2822 attr
= dwarf_attr (die
, DW_AT_encoding
);
2825 encoding
= DW_UNSND (attr
);
2827 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2830 size
= DW_UNSND (attr
);
2832 attr
= dwarf_attr (die
, DW_AT_name
);
2833 if (attr
&& DW_STRING (attr
))
2835 enum type_code code
= TYPE_CODE_INT
;
2836 int is_unsigned
= 0;
2840 case DW_ATE_address
:
2841 /* Turn DW_ATE_address into a void * pointer. */
2842 code
= TYPE_CODE_PTR
;
2845 case DW_ATE_boolean
:
2846 code
= TYPE_CODE_BOOL
;
2849 case DW_ATE_complex_float
:
2850 code
= TYPE_CODE_COMPLEX
;
2853 code
= TYPE_CODE_FLT
;
2856 case DW_ATE_signed_char
:
2858 case DW_ATE_unsigned
:
2859 case DW_ATE_unsigned_char
:
2863 complain (&dwarf2_unsupported_at_encoding
,
2864 dwarf_type_encoding_name (encoding
));
2867 type
= init_type (code
, size
, is_unsigned
, DW_STRING (attr
), objfile
);
2868 if (encoding
== DW_ATE_address
)
2869 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
2873 type
= dwarf_base_type (encoding
, size
, objfile
);
2878 /* Read a whole compilation unit into a linked list of dies. */
2881 read_comp_unit (info_ptr
, abfd
)
2885 struct die_info
*first_die
, *last_die
, *die
;
2889 /* Reset die reference table, we are building a new one now. */
2890 dwarf2_empty_die_ref_table ();
2894 first_die
= last_die
= NULL
;
2897 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
);
2898 if (die
->has_children
)
2909 /* Enter die in reference hash table */
2910 store_in_ref_table (die
->offset
, die
);
2914 first_die
= last_die
= die
;
2918 last_die
->next
= die
;
2922 while (nesting_level
> 0);
2926 /* Free a linked list of dies. */
2929 free_die_list (dies
)
2930 struct die_info
*dies
;
2932 struct die_info
*die
, *next
;
2945 do_free_die_list_cleanup (void *dies
)
2947 free_die_list (dies
);
2950 static struct cleanup
*
2951 make_cleanup_free_die_list (struct die_info
*dies
)
2953 return make_cleanup (do_free_die_list_cleanup
, dies
);
2957 /* Read the contents of the section at OFFSET and of size SIZE from the
2958 object file specified by OBJFILE into the psymbol_obstack and return it. */
2961 dwarf2_read_section (objfile
, offset
, size
)
2962 struct objfile
*objfile
;
2966 bfd
*abfd
= objfile
->obfd
;
2972 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
2973 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
2974 (bfd_read (buf
, size
, 1, abfd
) != size
))
2977 error ("Dwarf Error: Can't read DWARF data from '%s'",
2978 bfd_get_filename (abfd
));
2983 /* In DWARF version 2, the description of the debugging information is
2984 stored in a separate .debug_abbrev section. Before we read any
2985 dies from a section we read in all abbreviations and install them
2989 dwarf2_read_abbrevs (abfd
, offset
)
2991 unsigned int offset
;
2994 struct abbrev_info
*cur_abbrev
;
2995 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
2996 unsigned int abbrev_form
, hash_number
;
2998 /* empty the table */
2999 dwarf2_empty_abbrev_table (NULL
);
3001 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3002 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3003 abbrev_ptr
+= bytes_read
;
3005 /* loop until we reach an abbrev number of 0 */
3006 while (abbrev_number
)
3008 cur_abbrev
= dwarf_alloc_abbrev ();
3010 /* read in abbrev header */
3011 cur_abbrev
->number
= abbrev_number
;
3012 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3013 abbrev_ptr
+= bytes_read
;
3014 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3017 /* now read in declarations */
3018 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3019 abbrev_ptr
+= bytes_read
;
3020 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3021 abbrev_ptr
+= bytes_read
;
3024 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3026 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3027 xrealloc (cur_abbrev
->attrs
,
3028 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3029 * sizeof (struct attr_abbrev
));
3031 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3032 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3033 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3034 abbrev_ptr
+= bytes_read
;
3035 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3036 abbrev_ptr
+= bytes_read
;
3039 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3040 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3041 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3043 /* Get next abbreviation.
3044 Under Irix6 the abbreviations for a compilation unit are not
3045 always properly terminated with an abbrev number of 0.
3046 Exit loop if we encounter an abbreviation which we have
3047 already read (which means we are about to read the abbreviations
3048 for the next compile unit) or if the end of the abbreviation
3049 table is reached. */
3050 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3051 >= dwarf_abbrev_size
)
3053 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3054 abbrev_ptr
+= bytes_read
;
3055 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3060 /* Empty the abbrev table for a new compilation unit. */
3064 dwarf2_empty_abbrev_table (ignore
)
3068 struct abbrev_info
*abbrev
, *next
;
3070 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3073 abbrev
= dwarf2_abbrevs
[i
];
3076 next
= abbrev
->next
;
3077 free (abbrev
->attrs
);
3081 dwarf2_abbrevs
[i
] = NULL
;
3085 /* Lookup an abbrev_info structure in the abbrev hash table. */
3087 static struct abbrev_info
*
3088 dwarf2_lookup_abbrev (number
)
3089 unsigned int number
;
3091 unsigned int hash_number
;
3092 struct abbrev_info
*abbrev
;
3094 hash_number
= number
% ABBREV_HASH_SIZE
;
3095 abbrev
= dwarf2_abbrevs
[hash_number
];
3099 if (abbrev
->number
== number
)
3102 abbrev
= abbrev
->next
;
3107 /* Read a minimal amount of information into the minimal die structure. */
3110 read_partial_die (part_die
, abfd
, info_ptr
, has_pc_info
)
3111 struct partial_die_info
*part_die
;
3116 unsigned int abbrev_number
, bytes_read
, i
;
3117 struct abbrev_info
*abbrev
;
3118 struct attribute attr
;
3119 struct attribute spec_attr
;
3120 int found_spec_attr
= 0;
3121 int has_low_pc_attr
= 0;
3122 int has_high_pc_attr
= 0;
3124 *part_die
= zeroed_partial_die
;
3126 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3127 info_ptr
+= bytes_read
;
3131 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3134 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3136 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3137 part_die
->tag
= abbrev
->tag
;
3138 part_die
->has_children
= abbrev
->has_children
;
3139 part_die
->abbrev
= abbrev_number
;
3141 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3143 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
);
3145 /* Store the data if it is of an attribute we want to keep in a
3146 partial symbol table. */
3151 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3152 if (part_die
->name
== NULL
)
3153 part_die
->name
= DW_STRING (&attr
);
3155 case DW_AT_MIPS_linkage_name
:
3156 part_die
->name
= DW_STRING (&attr
);
3159 has_low_pc_attr
= 1;
3160 part_die
->lowpc
= DW_ADDR (&attr
);
3163 has_high_pc_attr
= 1;
3164 part_die
->highpc
= DW_ADDR (&attr
);
3166 case DW_AT_location
:
3167 part_die
->locdesc
= DW_BLOCK (&attr
);
3169 case DW_AT_language
:
3170 part_die
->language
= DW_UNSND (&attr
);
3172 case DW_AT_external
:
3173 part_die
->is_external
= DW_UNSND (&attr
);
3175 case DW_AT_declaration
:
3176 part_die
->is_declaration
= DW_UNSND (&attr
);
3179 part_die
->has_type
= 1;
3181 case DW_AT_abstract_origin
:
3182 case DW_AT_specification
:
3183 found_spec_attr
= 1;
3187 /* Ignore absolute siblings, they might point outside of
3188 the current compile unit. */
3189 if (attr
.form
== DW_FORM_ref_addr
)
3190 complain (&dwarf2_absolute_sibling_complaint
);
3193 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3200 /* If we found a reference attribute and the die has no name, try
3201 to find a name in the referred to die. */
3203 if (found_spec_attr
&& part_die
->name
== NULL
)
3205 struct partial_die_info spec_die
;
3209 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3210 read_partial_die (&spec_die
, abfd
, spec_ptr
, &dummy
);
3213 part_die
->name
= spec_die
.name
;
3215 /* Copy DW_AT_external attribute if it is set. */
3216 if (spec_die
.is_external
)
3217 part_die
->is_external
= spec_die
.is_external
;
3221 /* When using the GNU linker, .gnu.linkonce. sections are used to
3222 eliminate duplicate copies of functions and vtables and such.
3223 The linker will arbitrarily choose one and discard the others.
3224 The AT_*_pc values for such functions refer to local labels in
3225 these sections. If the section from that file was discarded, the
3226 labels are not in the output, so the relocs get a value of 0.
3227 If this is a discarded function, mark the pc bounds as invalid,
3228 so that GDB will ignore it. */
3229 if (has_low_pc_attr
&& has_high_pc_attr
3230 && part_die
->lowpc
< part_die
->highpc
3231 && (part_die
->lowpc
!= 0
3232 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3237 /* Read the die from the .debug_info section buffer. And set diep to
3238 point to a newly allocated die with its information. */
3241 read_full_die (diep
, abfd
, info_ptr
)
3242 struct die_info
**diep
;
3246 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3247 struct abbrev_info
*abbrev
;
3248 struct die_info
*die
;
3250 offset
= info_ptr
- dwarf_info_buffer
;
3251 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3252 info_ptr
+= bytes_read
;
3255 die
= dwarf_alloc_die ();
3257 die
->abbrev
= abbrev_number
;
3263 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3266 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3268 die
= dwarf_alloc_die ();
3269 die
->offset
= offset
;
3270 die
->tag
= abbrev
->tag
;
3271 die
->has_children
= abbrev
->has_children
;
3272 die
->abbrev
= abbrev_number
;
3275 die
->num_attrs
= abbrev
->num_attrs
;
3276 die
->attrs
= (struct attribute
*)
3277 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3279 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3281 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3289 /* Read an attribute described by an abbreviated attribute. */
3292 read_attribute (attr
, abbrev
, abfd
, info_ptr
)
3293 struct attribute
*attr
;
3294 struct attr_abbrev
*abbrev
;
3298 unsigned int bytes_read
;
3299 struct dwarf_block
*blk
;
3301 attr
->name
= abbrev
->name
;
3302 attr
->form
= abbrev
->form
;
3303 switch (abbrev
->form
)
3306 case DW_FORM_ref_addr
:
3307 DW_ADDR (attr
) = read_address (abfd
, info_ptr
);
3308 info_ptr
+= address_size
;
3310 case DW_FORM_block2
:
3311 blk
= dwarf_alloc_block ();
3312 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3314 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3315 info_ptr
+= blk
->size
;
3316 DW_BLOCK (attr
) = blk
;
3318 case DW_FORM_block4
:
3319 blk
= dwarf_alloc_block ();
3320 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3322 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3323 info_ptr
+= blk
->size
;
3324 DW_BLOCK (attr
) = blk
;
3327 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3331 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3335 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3338 case DW_FORM_string
:
3339 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3340 info_ptr
+= bytes_read
;
3343 blk
= dwarf_alloc_block ();
3344 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3345 info_ptr
+= bytes_read
;
3346 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3347 info_ptr
+= blk
->size
;
3348 DW_BLOCK (attr
) = blk
;
3350 case DW_FORM_block1
:
3351 blk
= dwarf_alloc_block ();
3352 blk
->size
= read_1_byte (abfd
, info_ptr
);
3354 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3355 info_ptr
+= blk
->size
;
3356 DW_BLOCK (attr
) = blk
;
3359 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3363 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3367 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3368 info_ptr
+= bytes_read
;
3371 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3372 info_ptr
+= bytes_read
;
3375 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3379 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3383 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3386 case DW_FORM_ref_udata
:
3387 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3388 info_ptr
+= bytes_read
;
3391 case DW_FORM_indirect
:
3393 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3394 dwarf_form_name (abbrev
->form
));
3399 /* read dwarf information from a buffer */
3402 read_1_byte (abfd
, buf
)
3406 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3410 read_1_signed_byte (abfd
, buf
)
3414 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3418 read_2_bytes (abfd
, buf
)
3422 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3426 read_2_signed_bytes (abfd
, buf
)
3430 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3434 read_4_bytes (abfd
, buf
)
3438 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3442 read_4_signed_bytes (abfd
, buf
)
3446 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3450 read_8_bytes (abfd
, buf
)
3454 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3458 read_address (abfd
, buf
)
3462 CORE_ADDR retval
= 0;
3464 switch (address_size
)
3467 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3470 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3473 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3476 /* *THE* alternative is 8, right? */
3484 read_n_bytes (abfd
, buf
, size
)
3489 /* If the size of a host char is 8 bits, we can return a pointer
3490 to the buffer, otherwise we have to copy the data to a buffer
3491 allocated on the temporary obstack. */
3492 #if HOST_CHAR_BIT == 8
3498 ret
= obstack_alloc (&dwarf2_tmp_obstack
, size
);
3499 for (i
= 0; i
< size
; ++i
)
3501 ret
[i
] = bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3509 read_string (abfd
, buf
, bytes_read_ptr
)
3512 unsigned int *bytes_read_ptr
;
3514 /* If the size of a host char is 8 bits, we can return a pointer
3515 to the string, otherwise we have to copy the string to a buffer
3516 allocated on the temporary obstack. */
3517 #if HOST_CHAR_BIT == 8
3520 *bytes_read_ptr
= 1;
3523 *bytes_read_ptr
= strlen (buf
) + 1;
3529 while ((byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
)) != 0)
3531 obstack_1grow (&dwarf2_tmp_obstack
, byte
);
3537 *bytes_read_ptr
= 1;
3540 obstack_1grow (&dwarf2_tmp_obstack
, '\0');
3541 *bytes_read_ptr
= i
+ 1;
3542 return obstack_finish (&dwarf2_tmp_obstack
);
3547 read_unsigned_leb128 (abfd
, buf
, bytes_read_ptr
)
3550 unsigned int *bytes_read_ptr
;
3552 unsigned int result
, num_read
;
3562 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3565 result
|= ((byte
& 127) << shift
);
3566 if ((byte
& 128) == 0)
3572 *bytes_read_ptr
= num_read
;
3577 read_signed_leb128 (abfd
, buf
, bytes_read_ptr
)
3580 unsigned int *bytes_read_ptr
;
3583 int i
, shift
, size
, num_read
;
3593 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3596 result
|= ((byte
& 127) << shift
);
3598 if ((byte
& 128) == 0)
3603 if ((shift
< size
) && (byte
& 0x40))
3605 result
|= -(1 << shift
);
3607 *bytes_read_ptr
= num_read
;
3612 set_cu_language (lang
)
3619 cu_language
= language_c
;
3621 case DW_LANG_C_plus_plus
:
3622 cu_language
= language_cplus
;
3624 case DW_LANG_Fortran77
:
3625 case DW_LANG_Fortran90
:
3626 cu_language
= language_fortran
;
3628 case DW_LANG_Mips_Assembler
:
3629 cu_language
= language_asm
;
3632 case DW_LANG_Cobol74
:
3633 case DW_LANG_Cobol85
:
3634 case DW_LANG_Pascal83
:
3635 case DW_LANG_Modula2
:
3637 cu_language
= language_unknown
;
3640 cu_language_defn
= language_def (cu_language
);
3643 /* Return the named attribute or NULL if not there. */
3645 static struct attribute
*
3646 dwarf_attr (die
, name
)
3647 struct die_info
*die
;
3651 struct attribute
*spec
= NULL
;
3653 for (i
= 0; i
< die
->num_attrs
; ++i
)
3655 if (die
->attrs
[i
].name
== name
)
3657 return &die
->attrs
[i
];
3659 if (die
->attrs
[i
].name
== DW_AT_specification
3660 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3661 spec
= &die
->attrs
[i
];
3665 struct die_info
*ref_die
=
3666 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3669 return dwarf_attr (ref_die
, name
);
3676 die_is_declaration (struct die_info
*die
)
3678 return (dwarf_attr (die
, DW_AT_declaration
)
3679 && ! dwarf_attr (die
, DW_AT_specification
));
3682 /* Decode the line number information for the compilation unit whose
3683 line number info is at OFFSET in the .debug_line section.
3684 The compilation directory of the file is passed in COMP_DIR. */
3688 unsigned int num_files
;
3701 unsigned int num_dirs
;
3706 dwarf_decode_lines (offset
, comp_dir
, abfd
)
3707 unsigned int offset
;
3713 struct line_head lh
;
3714 struct cleanup
*back_to
;
3715 unsigned int i
, bytes_read
;
3716 char *cur_file
, *cur_dir
;
3717 unsigned char op_code
, extended_op
, adj_opcode
;
3719 #define FILE_ALLOC_CHUNK 5
3720 #define DIR_ALLOC_CHUNK 5
3722 struct filenames files
;
3723 struct directories dirs
;
3725 if (dwarf_line_buffer
== NULL
)
3727 complain (&dwarf2_missing_line_number_section
);
3731 files
.num_files
= 0;
3737 line_ptr
= dwarf_line_buffer
+ offset
;
3739 /* read in the prologue */
3740 lh
.total_length
= read_4_bytes (abfd
, line_ptr
);
3742 line_end
= line_ptr
+ lh
.total_length
;
3743 lh
.version
= read_2_bytes (abfd
, line_ptr
);
3745 lh
.prologue_length
= read_4_bytes (abfd
, line_ptr
);
3747 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
3749 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
3751 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
3753 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
3755 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
3757 lh
.standard_opcode_lengths
= (unsigned char *)
3758 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
3759 back_to
= make_cleanup (free_current_contents
, &lh
.standard_opcode_lengths
);
3761 lh
.standard_opcode_lengths
[0] = 1;
3762 for (i
= 1; i
< lh
.opcode_base
; ++i
)
3764 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
3768 /* Read directory table */
3769 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3771 line_ptr
+= bytes_read
;
3772 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
3774 dirs
.dirs
= (char **)
3775 xrealloc (dirs
.dirs
,
3776 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
3777 if (dirs
.num_dirs
== 0)
3778 make_cleanup (free_current_contents
, &dirs
.dirs
);
3780 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
3782 line_ptr
+= bytes_read
;
3784 /* Read file name table */
3785 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3787 line_ptr
+= bytes_read
;
3788 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3790 files
.files
= (struct fileinfo
*)
3791 xrealloc (files
.files
,
3792 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3793 * sizeof (struct fileinfo
));
3794 if (files
.num_files
== 0)
3795 make_cleanup (free_current_contents
, &files
.files
);
3797 files
.files
[files
.num_files
].name
= cur_file
;
3798 files
.files
[files
.num_files
].dir
=
3799 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3800 line_ptr
+= bytes_read
;
3801 files
.files
[files
.num_files
].time
=
3802 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3803 line_ptr
+= bytes_read
;
3804 files
.files
[files
.num_files
].size
=
3805 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3806 line_ptr
+= bytes_read
;
3809 line_ptr
+= bytes_read
;
3811 /* Read the statement sequences until there's nothing left. */
3812 while (line_ptr
< line_end
)
3814 /* state machine registers */
3815 CORE_ADDR address
= 0;
3816 unsigned int file
= 1;
3817 unsigned int line
= 1;
3818 unsigned int column
= 0;
3819 int is_stmt
= lh
.default_is_stmt
;
3820 int basic_block
= 0;
3821 int end_sequence
= 0;
3823 /* Start a subfile for the current file of the state machine. */
3824 if (files
.num_files
>= file
)
3826 /* The file and directory tables are 0 based, the references
3828 dwarf2_start_subfile (files
.files
[file
- 1].name
,
3829 (files
.files
[file
- 1].dir
3830 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3834 /* Decode the table. */
3835 while (!end_sequence
)
3837 op_code
= read_1_byte (abfd
, line_ptr
);
3841 case DW_LNS_extended_op
:
3842 line_ptr
+= 1; /* ignore length */
3843 extended_op
= read_1_byte (abfd
, line_ptr
);
3845 switch (extended_op
)
3847 case DW_LNE_end_sequence
:
3849 /* Don't call record_line here. The end_sequence
3850 instruction provides the address of the first byte
3851 *after* the last line in the sequence; it's not the
3852 address of any real source line. However, the GDB
3853 linetable structure only records the starts of lines,
3854 not the ends. This is a weakness of GDB. */
3856 case DW_LNE_set_address
:
3857 address
= read_address (abfd
, line_ptr
) + baseaddr
;
3858 line_ptr
+= address_size
;
3860 case DW_LNE_define_file
:
3861 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
3862 line_ptr
+= bytes_read
;
3863 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3865 files
.files
= (struct fileinfo
*)
3866 xrealloc (files
.files
,
3867 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3868 * sizeof (struct fileinfo
));
3869 if (files
.num_files
== 0)
3870 make_cleanup (free_current_contents
, &files
.files
);
3872 files
.files
[files
.num_files
].name
= cur_file
;
3873 files
.files
[files
.num_files
].dir
=
3874 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3875 line_ptr
+= bytes_read
;
3876 files
.files
[files
.num_files
].time
=
3877 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3878 line_ptr
+= bytes_read
;
3879 files
.files
[files
.num_files
].size
=
3880 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3881 line_ptr
+= bytes_read
;
3885 complain (&dwarf2_mangled_line_number_section
);
3890 record_line (current_subfile
, line
, address
);
3893 case DW_LNS_advance_pc
:
3894 address
+= lh
.minimum_instruction_length
3895 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3896 line_ptr
+= bytes_read
;
3898 case DW_LNS_advance_line
:
3899 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
3900 line_ptr
+= bytes_read
;
3902 case DW_LNS_set_file
:
3903 /* The file and directory tables are 0 based, the references
3905 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3906 line_ptr
+= bytes_read
;
3907 dwarf2_start_subfile
3908 (files
.files
[file
- 1].name
,
3909 (files
.files
[file
- 1].dir
3910 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3913 case DW_LNS_set_column
:
3914 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3915 line_ptr
+= bytes_read
;
3917 case DW_LNS_negate_stmt
:
3918 is_stmt
= (!is_stmt
);
3920 case DW_LNS_set_basic_block
:
3923 /* Add to the address register of the state machine the
3924 address increment value corresponding to special opcode
3925 255. Ie, this value is scaled by the minimum instruction
3926 length since special opcode 255 would have scaled the
3928 case DW_LNS_const_add_pc
:
3929 address
+= (lh
.minimum_instruction_length
3930 * ((255 - lh
.opcode_base
) / lh
.line_range
));
3932 case DW_LNS_fixed_advance_pc
:
3933 address
+= read_2_bytes (abfd
, line_ptr
);
3936 default: /* special operand */
3937 adj_opcode
= op_code
- lh
.opcode_base
;
3938 address
+= (adj_opcode
/ lh
.line_range
)
3939 * lh
.minimum_instruction_length
;
3940 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
3941 /* append row to matrix using current values */
3942 record_line (current_subfile
, line
, address
);
3948 do_cleanups (back_to
);
3951 /* Start a subfile for DWARF. FILENAME is the name of the file and
3952 DIRNAME the name of the source directory which contains FILENAME
3953 or NULL if not known.
3954 This routine tries to keep line numbers from identical absolute and
3955 relative file names in a common subfile.
3957 Using the `list' example from the GDB testsuite, which resides in
3958 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
3959 of /srcdir/list0.c yields the following debugging information for list0.c:
3961 DW_AT_name: /srcdir/list0.c
3962 DW_AT_comp_dir: /compdir
3963 files.files[0].name: list0.h
3964 files.files[0].dir: /srcdir
3965 files.files[1].name: list0.c
3966 files.files[1].dir: /srcdir
3968 The line number information for list0.c has to end up in a single
3969 subfile, so that `break /srcdir/list0.c:1' works as expected. */
3972 dwarf2_start_subfile (filename
, dirname
)
3976 /* If the filename isn't absolute, try to match an existing subfile
3977 with the full pathname. */
3979 if (*filename
!= '/' && dirname
!= NULL
)
3981 struct subfile
*subfile
;
3982 char *fullname
= concat (dirname
, "/", filename
, NULL
);
3984 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
3986 if (STREQ (subfile
->name
, fullname
))
3988 current_subfile
= subfile
;
3995 start_subfile (filename
, dirname
);
3998 /* Given a pointer to a DWARF information entry, figure out if we need
3999 to make a symbol table entry for it, and if so, create a new entry
4000 and return a pointer to it.
4001 If TYPE is NULL, determine symbol type from the die, otherwise
4002 used the passed type. */
4004 static struct symbol
*
4005 new_symbol (die
, type
, objfile
)
4006 struct die_info
*die
;
4008 struct objfile
*objfile
;
4010 struct symbol
*sym
= NULL
;
4012 struct attribute
*attr
= NULL
;
4013 struct attribute
*attr2
= NULL
;
4016 name
= dwarf2_linkage_name (die
);
4019 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4020 sizeof (struct symbol
));
4021 OBJSTAT (objfile
, n_syms
++);
4022 memset (sym
, 0, sizeof (struct symbol
));
4023 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4024 &objfile
->symbol_obstack
);
4026 /* Default assumptions.
4027 Use the passed type or decode it from the die. */
4028 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4029 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4031 SYMBOL_TYPE (sym
) = type
;
4033 SYMBOL_TYPE (sym
) = die_type (die
, objfile
);
4034 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4037 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4040 /* If this symbol is from a C++ compilation, then attempt to
4041 cache the demangled form for future reference. This is a
4042 typical time versus space tradeoff, that was decided in favor
4043 of time because it sped up C++ symbol lookups by a factor of
4046 SYMBOL_LANGUAGE (sym
) = cu_language
;
4047 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4051 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4054 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4056 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4058 case DW_TAG_subprogram
:
4059 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4061 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4062 attr2
= dwarf_attr (die
, DW_AT_external
);
4063 if (attr2
&& (DW_UNSND (attr2
) != 0))
4065 add_symbol_to_list (sym
, &global_symbols
);
4069 add_symbol_to_list (sym
, list_in_scope
);
4072 case DW_TAG_variable
:
4073 /* Compilation with minimal debug info may result in variables
4074 with missing type entries. Change the misleading `void' type
4075 to something sensible. */
4076 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4077 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4078 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4079 "<variable, no debug info>",
4081 attr
= dwarf_attr (die
, DW_AT_const_value
);
4084 dwarf2_const_value (attr
, sym
, objfile
);
4085 attr2
= dwarf_attr (die
, DW_AT_external
);
4086 if (attr2
&& (DW_UNSND (attr2
) != 0))
4087 add_symbol_to_list (sym
, &global_symbols
);
4089 add_symbol_to_list (sym
, list_in_scope
);
4092 attr
= dwarf_attr (die
, DW_AT_location
);
4095 attr2
= dwarf_attr (die
, DW_AT_external
);
4096 if (attr2
&& (DW_UNSND (attr2
) != 0))
4098 SYMBOL_VALUE_ADDRESS (sym
) =
4099 decode_locdesc (DW_BLOCK (attr
), objfile
);
4100 add_symbol_to_list (sym
, &global_symbols
);
4102 /* In shared libraries the address of the variable
4103 in the location descriptor might still be relocatable,
4104 so its value could be zero.
4105 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4106 value is zero, the address of the variable will then
4107 be determined from the minimal symbol table whenever
4108 the variable is referenced. */
4109 if (SYMBOL_VALUE_ADDRESS (sym
))
4111 SYMBOL_VALUE_ADDRESS (sym
) += baseaddr
;
4112 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4115 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4119 SYMBOL_VALUE (sym
) = addr
=
4120 decode_locdesc (DW_BLOCK (attr
), objfile
);
4121 add_symbol_to_list (sym
, list_in_scope
);
4124 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4128 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4132 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4133 SYMBOL_BASEREG (sym
) = basereg
;
4137 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4141 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4142 SYMBOL_VALUE_ADDRESS (sym
) = addr
+ baseaddr
;
4148 /* We do not know the address of this symbol.
4149 If it is an external symbol and we have type information
4150 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4151 The address of the variable will then be determined from
4152 the minimal symbol table whenever the variable is
4154 attr2
= dwarf_attr (die
, DW_AT_external
);
4155 if (attr2
&& (DW_UNSND (attr2
) != 0)
4156 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4158 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4159 add_symbol_to_list (sym
, &global_symbols
);
4163 case DW_TAG_formal_parameter
:
4164 attr
= dwarf_attr (die
, DW_AT_location
);
4167 SYMBOL_VALUE (sym
) = decode_locdesc (DW_BLOCK (attr
), objfile
);
4170 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4176 if (basereg
!= frame_base_reg
)
4177 complain (&dwarf2_complex_location_expr
);
4178 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4182 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4183 SYMBOL_BASEREG (sym
) = basereg
;
4188 SYMBOL_CLASS (sym
) = LOC_ARG
;
4191 attr
= dwarf_attr (die
, DW_AT_const_value
);
4194 dwarf2_const_value (attr
, sym
, objfile
);
4196 add_symbol_to_list (sym
, list_in_scope
);
4198 case DW_TAG_unspecified_parameters
:
4199 /* From varargs functions; gdb doesn't seem to have any
4200 interest in this information, so just ignore it for now.
4203 case DW_TAG_class_type
:
4204 case DW_TAG_structure_type
:
4205 case DW_TAG_union_type
:
4206 case DW_TAG_enumeration_type
:
4207 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4208 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4209 add_symbol_to_list (sym
, list_in_scope
);
4211 /* The semantics of C++ state that "struct foo { ... }" also
4212 defines a typedef for "foo". Synthesize a typedef symbol so
4213 that "ptype foo" works as expected. */
4214 if (cu_language
== language_cplus
)
4216 struct symbol
*typedef_sym
= (struct symbol
*)
4217 obstack_alloc (&objfile
->symbol_obstack
,
4218 sizeof (struct symbol
));
4219 *typedef_sym
= *sym
;
4220 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4221 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4222 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4223 obsavestring (SYMBOL_NAME (sym
),
4224 strlen (SYMBOL_NAME (sym
)),
4225 &objfile
->type_obstack
);
4226 add_symbol_to_list (typedef_sym
, list_in_scope
);
4229 case DW_TAG_typedef
:
4230 case DW_TAG_base_type
:
4231 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4232 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4233 add_symbol_to_list (sym
, list_in_scope
);
4235 case DW_TAG_enumerator
:
4236 attr
= dwarf_attr (die
, DW_AT_const_value
);
4239 dwarf2_const_value (attr
, sym
, objfile
);
4241 add_symbol_to_list (sym
, list_in_scope
);
4244 /* Not a tag we recognize. Hopefully we aren't processing
4245 trash data, but since we must specifically ignore things
4246 we don't recognize, there is nothing else we should do at
4248 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4255 /* Copy constant value from an attribute to a symbol. */
4258 dwarf2_const_value (attr
, sym
, objfile
)
4259 struct attribute
*attr
;
4261 struct objfile
*objfile
;
4263 struct dwarf_block
*blk
;
4268 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != (unsigned int) address_size
)
4269 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4270 address_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4271 SYMBOL_VALUE_BYTES (sym
) = (char *)
4272 obstack_alloc (&objfile
->symbol_obstack
, address_size
);
4273 store_address (SYMBOL_VALUE_BYTES (sym
), address_size
, DW_ADDR (attr
));
4274 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4276 case DW_FORM_block1
:
4277 case DW_FORM_block2
:
4278 case DW_FORM_block4
:
4280 blk
= DW_BLOCK (attr
);
4281 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4282 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4283 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4284 SYMBOL_VALUE_BYTES (sym
) = (char *)
4285 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4286 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4287 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4290 /* The DW_AT_const_value attributes are supposed to carry the
4291 symbol's value "represented as it would be on the target
4292 architecture." By the time we get here, it's already been
4293 converted to host endianness, so we just need to sign- or
4294 zero-extend it as appropriate. */
4296 dwarf2_const_value_data (attr
, sym
, 8);
4299 dwarf2_const_value_data (attr
, sym
, 16);
4302 dwarf2_const_value_data (attr
, sym
, 32);
4305 dwarf2_const_value_data (attr
, sym
, 64);
4309 SYMBOL_VALUE (sym
) = DW_SND (attr
);
4310 SYMBOL_CLASS (sym
) = LOC_CONST
;
4314 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4315 SYMBOL_CLASS (sym
) = LOC_CONST
;
4319 complain (&dwarf2_unsupported_const_value_attr
,
4320 dwarf_form_name (attr
->form
));
4321 SYMBOL_VALUE (sym
) = 0;
4322 SYMBOL_CLASS (sym
) = LOC_CONST
;
4328 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4329 or zero-extend it as appropriate for the symbol's type. */
4331 dwarf2_const_value_data (struct attribute
*attr
,
4335 LONGEST l
= DW_UNSND (attr
);
4337 if (bits
< sizeof (l
) * 8)
4339 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
4340 l
&= ((LONGEST
) 1 << bits
) - 1;
4342 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
4345 SYMBOL_VALUE (sym
) = l
;
4346 SYMBOL_CLASS (sym
) = LOC_CONST
;
4350 /* Return the type of the die in question using its DW_AT_type attribute. */
4352 static struct type
*
4353 die_type (die
, objfile
)
4354 struct die_info
*die
;
4355 struct objfile
*objfile
;
4358 struct attribute
*type_attr
;
4359 struct die_info
*type_die
;
4362 type_attr
= dwarf_attr (die
, DW_AT_type
);
4365 /* A missing DW_AT_type represents a void type. */
4366 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4370 ref
= dwarf2_get_ref_die_offset (type_attr
);
4371 type_die
= follow_die_ref (ref
);
4374 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4378 type
= tag_type_to_type (type_die
, objfile
);
4381 dump_die (type_die
);
4382 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4387 /* Return the containing type of the die in question using its
4388 DW_AT_containing_type attribute. */
4390 static struct type
*
4391 die_containing_type (die
, objfile
)
4392 struct die_info
*die
;
4393 struct objfile
*objfile
;
4395 struct type
*type
= NULL
;
4396 struct attribute
*type_attr
;
4397 struct die_info
*type_die
= NULL
;
4400 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4403 ref
= dwarf2_get_ref_die_offset (type_attr
);
4404 type_die
= follow_die_ref (ref
);
4407 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4410 type
= tag_type_to_type (type_die
, objfile
);
4415 dump_die (type_die
);
4416 error ("Dwarf Error: Problem turning containing type into gdb type.");
4422 static struct type
*
4423 type_at_offset (offset
, objfile
)
4424 unsigned int offset
;
4425 struct objfile
*objfile
;
4427 struct die_info
*die
;
4430 die
= follow_die_ref (offset
);
4433 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4436 type
= tag_type_to_type (die
, objfile
);
4441 static struct type
*
4442 tag_type_to_type (die
, objfile
)
4443 struct die_info
*die
;
4444 struct objfile
*objfile
;
4452 read_type_die (die
, objfile
);
4456 error ("Dwarf Error: Cannot find type of die.");
4463 read_type_die (die
, objfile
)
4464 struct die_info
*die
;
4465 struct objfile
*objfile
;
4469 case DW_TAG_class_type
:
4470 case DW_TAG_structure_type
:
4471 case DW_TAG_union_type
:
4472 read_structure_scope (die
, objfile
);
4474 case DW_TAG_enumeration_type
:
4475 read_enumeration (die
, objfile
);
4477 case DW_TAG_subprogram
:
4478 case DW_TAG_subroutine_type
:
4479 read_subroutine_type (die
, objfile
);
4481 case DW_TAG_array_type
:
4482 read_array_type (die
, objfile
);
4484 case DW_TAG_pointer_type
:
4485 read_tag_pointer_type (die
, objfile
);
4487 case DW_TAG_ptr_to_member_type
:
4488 read_tag_ptr_to_member_type (die
, objfile
);
4490 case DW_TAG_reference_type
:
4491 read_tag_reference_type (die
, objfile
);
4493 case DW_TAG_const_type
:
4494 read_tag_const_type (die
, objfile
);
4496 case DW_TAG_volatile_type
:
4497 read_tag_volatile_type (die
, objfile
);
4499 case DW_TAG_string_type
:
4500 read_tag_string_type (die
, objfile
);
4502 case DW_TAG_typedef
:
4503 read_typedef (die
, objfile
);
4505 case DW_TAG_base_type
:
4506 read_base_type (die
, objfile
);
4509 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4514 static struct type
*
4515 dwarf_base_type (encoding
, size
, objfile
)
4518 struct objfile
*objfile
;
4520 /* FIXME - this should not produce a new (struct type *)
4521 every time. It should cache base types. */
4525 case DW_ATE_address
:
4526 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4528 case DW_ATE_boolean
:
4529 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4531 case DW_ATE_complex_float
:
4534 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4538 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4544 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4548 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4555 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4558 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4562 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4566 case DW_ATE_signed_char
:
4567 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4569 case DW_ATE_unsigned
:
4573 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4576 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4580 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4584 case DW_ATE_unsigned_char
:
4585 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4588 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4596 struct die_info
*old_die
;
4598 struct die_info
*new_die
;
4601 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4602 memset (new_die
, 0, sizeof (struct die_info
));
4604 new_die
->tag
= old_die
->tag
;
4605 new_die
->has_children
= old_die
->has_children
;
4606 new_die
->abbrev
= old_die
->abbrev
;
4607 new_die
->offset
= old_die
->offset
;
4608 new_die
->type
= NULL
;
4610 num_attrs
= old_die
->num_attrs
;
4611 new_die
->num_attrs
= num_attrs
;
4612 new_die
->attrs
= (struct attribute
*)
4613 xmalloc (num_attrs
* sizeof (struct attribute
));
4615 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4617 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4618 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4619 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4622 new_die
->next
= NULL
;
4627 /* Return sibling of die, NULL if no sibling. */
4631 struct die_info
*die
;
4633 int nesting_level
= 0;
4635 if (!die
->has_children
)
4637 if (die
->next
&& (die
->next
->tag
== 0))
4650 if (die
->has_children
)
4660 while (nesting_level
);
4661 if (die
&& (die
->tag
== 0))
4672 /* Get linkage name of a die, return NULL if not found. */
4675 dwarf2_linkage_name (die
)
4676 struct die_info
*die
;
4678 struct attribute
*attr
;
4680 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4681 if (attr
&& DW_STRING (attr
))
4682 return DW_STRING (attr
);
4683 attr
= dwarf_attr (die
, DW_AT_name
);
4684 if (attr
&& DW_STRING (attr
))
4685 return DW_STRING (attr
);
4689 /* Convert a DIE tag into its string name. */
4692 dwarf_tag_name (tag
)
4693 register unsigned tag
;
4697 case DW_TAG_padding
:
4698 return "DW_TAG_padding";
4699 case DW_TAG_array_type
:
4700 return "DW_TAG_array_type";
4701 case DW_TAG_class_type
:
4702 return "DW_TAG_class_type";
4703 case DW_TAG_entry_point
:
4704 return "DW_TAG_entry_point";
4705 case DW_TAG_enumeration_type
:
4706 return "DW_TAG_enumeration_type";
4707 case DW_TAG_formal_parameter
:
4708 return "DW_TAG_formal_parameter";
4709 case DW_TAG_imported_declaration
:
4710 return "DW_TAG_imported_declaration";
4712 return "DW_TAG_label";
4713 case DW_TAG_lexical_block
:
4714 return "DW_TAG_lexical_block";
4716 return "DW_TAG_member";
4717 case DW_TAG_pointer_type
:
4718 return "DW_TAG_pointer_type";
4719 case DW_TAG_reference_type
:
4720 return "DW_TAG_reference_type";
4721 case DW_TAG_compile_unit
:
4722 return "DW_TAG_compile_unit";
4723 case DW_TAG_string_type
:
4724 return "DW_TAG_string_type";
4725 case DW_TAG_structure_type
:
4726 return "DW_TAG_structure_type";
4727 case DW_TAG_subroutine_type
:
4728 return "DW_TAG_subroutine_type";
4729 case DW_TAG_typedef
:
4730 return "DW_TAG_typedef";
4731 case DW_TAG_union_type
:
4732 return "DW_TAG_union_type";
4733 case DW_TAG_unspecified_parameters
:
4734 return "DW_TAG_unspecified_parameters";
4735 case DW_TAG_variant
:
4736 return "DW_TAG_variant";
4737 case DW_TAG_common_block
:
4738 return "DW_TAG_common_block";
4739 case DW_TAG_common_inclusion
:
4740 return "DW_TAG_common_inclusion";
4741 case DW_TAG_inheritance
:
4742 return "DW_TAG_inheritance";
4743 case DW_TAG_inlined_subroutine
:
4744 return "DW_TAG_inlined_subroutine";
4746 return "DW_TAG_module";
4747 case DW_TAG_ptr_to_member_type
:
4748 return "DW_TAG_ptr_to_member_type";
4749 case DW_TAG_set_type
:
4750 return "DW_TAG_set_type";
4751 case DW_TAG_subrange_type
:
4752 return "DW_TAG_subrange_type";
4753 case DW_TAG_with_stmt
:
4754 return "DW_TAG_with_stmt";
4755 case DW_TAG_access_declaration
:
4756 return "DW_TAG_access_declaration";
4757 case DW_TAG_base_type
:
4758 return "DW_TAG_base_type";
4759 case DW_TAG_catch_block
:
4760 return "DW_TAG_catch_block";
4761 case DW_TAG_const_type
:
4762 return "DW_TAG_const_type";
4763 case DW_TAG_constant
:
4764 return "DW_TAG_constant";
4765 case DW_TAG_enumerator
:
4766 return "DW_TAG_enumerator";
4767 case DW_TAG_file_type
:
4768 return "DW_TAG_file_type";
4770 return "DW_TAG_friend";
4771 case DW_TAG_namelist
:
4772 return "DW_TAG_namelist";
4773 case DW_TAG_namelist_item
:
4774 return "DW_TAG_namelist_item";
4775 case DW_TAG_packed_type
:
4776 return "DW_TAG_packed_type";
4777 case DW_TAG_subprogram
:
4778 return "DW_TAG_subprogram";
4779 case DW_TAG_template_type_param
:
4780 return "DW_TAG_template_type_param";
4781 case DW_TAG_template_value_param
:
4782 return "DW_TAG_template_value_param";
4783 case DW_TAG_thrown_type
:
4784 return "DW_TAG_thrown_type";
4785 case DW_TAG_try_block
:
4786 return "DW_TAG_try_block";
4787 case DW_TAG_variant_part
:
4788 return "DW_TAG_variant_part";
4789 case DW_TAG_variable
:
4790 return "DW_TAG_variable";
4791 case DW_TAG_volatile_type
:
4792 return "DW_TAG_volatile_type";
4793 case DW_TAG_MIPS_loop
:
4794 return "DW_TAG_MIPS_loop";
4795 case DW_TAG_format_label
:
4796 return "DW_TAG_format_label";
4797 case DW_TAG_function_template
:
4798 return "DW_TAG_function_template";
4799 case DW_TAG_class_template
:
4800 return "DW_TAG_class_template";
4802 return "DW_TAG_<unknown>";
4806 /* Convert a DWARF attribute code into its string name. */
4809 dwarf_attr_name (attr
)
4810 register unsigned attr
;
4815 return "DW_AT_sibling";
4816 case DW_AT_location
:
4817 return "DW_AT_location";
4819 return "DW_AT_name";
4820 case DW_AT_ordering
:
4821 return "DW_AT_ordering";
4822 case DW_AT_subscr_data
:
4823 return "DW_AT_subscr_data";
4824 case DW_AT_byte_size
:
4825 return "DW_AT_byte_size";
4826 case DW_AT_bit_offset
:
4827 return "DW_AT_bit_offset";
4828 case DW_AT_bit_size
:
4829 return "DW_AT_bit_size";
4830 case DW_AT_element_list
:
4831 return "DW_AT_element_list";
4832 case DW_AT_stmt_list
:
4833 return "DW_AT_stmt_list";
4835 return "DW_AT_low_pc";
4837 return "DW_AT_high_pc";
4838 case DW_AT_language
:
4839 return "DW_AT_language";
4841 return "DW_AT_member";
4843 return "DW_AT_discr";
4844 case DW_AT_discr_value
:
4845 return "DW_AT_discr_value";
4846 case DW_AT_visibility
:
4847 return "DW_AT_visibility";
4849 return "DW_AT_import";
4850 case DW_AT_string_length
:
4851 return "DW_AT_string_length";
4852 case DW_AT_common_reference
:
4853 return "DW_AT_common_reference";
4854 case DW_AT_comp_dir
:
4855 return "DW_AT_comp_dir";
4856 case DW_AT_const_value
:
4857 return "DW_AT_const_value";
4858 case DW_AT_containing_type
:
4859 return "DW_AT_containing_type";
4860 case DW_AT_default_value
:
4861 return "DW_AT_default_value";
4863 return "DW_AT_inline";
4864 case DW_AT_is_optional
:
4865 return "DW_AT_is_optional";
4866 case DW_AT_lower_bound
:
4867 return "DW_AT_lower_bound";
4868 case DW_AT_producer
:
4869 return "DW_AT_producer";
4870 case DW_AT_prototyped
:
4871 return "DW_AT_prototyped";
4872 case DW_AT_return_addr
:
4873 return "DW_AT_return_addr";
4874 case DW_AT_start_scope
:
4875 return "DW_AT_start_scope";
4876 case DW_AT_stride_size
:
4877 return "DW_AT_stride_size";
4878 case DW_AT_upper_bound
:
4879 return "DW_AT_upper_bound";
4880 case DW_AT_abstract_origin
:
4881 return "DW_AT_abstract_origin";
4882 case DW_AT_accessibility
:
4883 return "DW_AT_accessibility";
4884 case DW_AT_address_class
:
4885 return "DW_AT_address_class";
4886 case DW_AT_artificial
:
4887 return "DW_AT_artificial";
4888 case DW_AT_base_types
:
4889 return "DW_AT_base_types";
4890 case DW_AT_calling_convention
:
4891 return "DW_AT_calling_convention";
4893 return "DW_AT_count";
4894 case DW_AT_data_member_location
:
4895 return "DW_AT_data_member_location";
4896 case DW_AT_decl_column
:
4897 return "DW_AT_decl_column";
4898 case DW_AT_decl_file
:
4899 return "DW_AT_decl_file";
4900 case DW_AT_decl_line
:
4901 return "DW_AT_decl_line";
4902 case DW_AT_declaration
:
4903 return "DW_AT_declaration";
4904 case DW_AT_discr_list
:
4905 return "DW_AT_discr_list";
4906 case DW_AT_encoding
:
4907 return "DW_AT_encoding";
4908 case DW_AT_external
:
4909 return "DW_AT_external";
4910 case DW_AT_frame_base
:
4911 return "DW_AT_frame_base";
4913 return "DW_AT_friend";
4914 case DW_AT_identifier_case
:
4915 return "DW_AT_identifier_case";
4916 case DW_AT_macro_info
:
4917 return "DW_AT_macro_info";
4918 case DW_AT_namelist_items
:
4919 return "DW_AT_namelist_items";
4920 case DW_AT_priority
:
4921 return "DW_AT_priority";
4923 return "DW_AT_segment";
4924 case DW_AT_specification
:
4925 return "DW_AT_specification";
4926 case DW_AT_static_link
:
4927 return "DW_AT_static_link";
4929 return "DW_AT_type";
4930 case DW_AT_use_location
:
4931 return "DW_AT_use_location";
4932 case DW_AT_variable_parameter
:
4933 return "DW_AT_variable_parameter";
4934 case DW_AT_virtuality
:
4935 return "DW_AT_virtuality";
4936 case DW_AT_vtable_elem_location
:
4937 return "DW_AT_vtable_elem_location";
4940 case DW_AT_MIPS_fde
:
4941 return "DW_AT_MIPS_fde";
4942 case DW_AT_MIPS_loop_begin
:
4943 return "DW_AT_MIPS_loop_begin";
4944 case DW_AT_MIPS_tail_loop_begin
:
4945 return "DW_AT_MIPS_tail_loop_begin";
4946 case DW_AT_MIPS_epilog_begin
:
4947 return "DW_AT_MIPS_epilog_begin";
4948 case DW_AT_MIPS_loop_unroll_factor
:
4949 return "DW_AT_MIPS_loop_unroll_factor";
4950 case DW_AT_MIPS_software_pipeline_depth
:
4951 return "DW_AT_MIPS_software_pipeline_depth";
4952 case DW_AT_MIPS_linkage_name
:
4953 return "DW_AT_MIPS_linkage_name";
4956 case DW_AT_sf_names
:
4957 return "DW_AT_sf_names";
4958 case DW_AT_src_info
:
4959 return "DW_AT_src_info";
4960 case DW_AT_mac_info
:
4961 return "DW_AT_mac_info";
4962 case DW_AT_src_coords
:
4963 return "DW_AT_src_coords";
4964 case DW_AT_body_begin
:
4965 return "DW_AT_body_begin";
4966 case DW_AT_body_end
:
4967 return "DW_AT_body_end";
4969 return "DW_AT_<unknown>";
4973 /* Convert a DWARF value form code into its string name. */
4976 dwarf_form_name (form
)
4977 register unsigned form
;
4982 return "DW_FORM_addr";
4983 case DW_FORM_block2
:
4984 return "DW_FORM_block2";
4985 case DW_FORM_block4
:
4986 return "DW_FORM_block4";
4988 return "DW_FORM_data2";
4990 return "DW_FORM_data4";
4992 return "DW_FORM_data8";
4993 case DW_FORM_string
:
4994 return "DW_FORM_string";
4996 return "DW_FORM_block";
4997 case DW_FORM_block1
:
4998 return "DW_FORM_block1";
5000 return "DW_FORM_data1";
5002 return "DW_FORM_flag";
5004 return "DW_FORM_sdata";
5006 return "DW_FORM_strp";
5008 return "DW_FORM_udata";
5009 case DW_FORM_ref_addr
:
5010 return "DW_FORM_ref_addr";
5012 return "DW_FORM_ref1";
5014 return "DW_FORM_ref2";
5016 return "DW_FORM_ref4";
5018 return "DW_FORM_ref8";
5019 case DW_FORM_ref_udata
:
5020 return "DW_FORM_ref_udata";
5021 case DW_FORM_indirect
:
5022 return "DW_FORM_indirect";
5024 return "DW_FORM_<unknown>";
5028 /* Convert a DWARF stack opcode into its string name. */
5031 dwarf_stack_op_name (op
)
5032 register unsigned op
;
5037 return "DW_OP_addr";
5039 return "DW_OP_deref";
5041 return "DW_OP_const1u";
5043 return "DW_OP_const1s";
5045 return "DW_OP_const2u";
5047 return "DW_OP_const2s";
5049 return "DW_OP_const4u";
5051 return "DW_OP_const4s";
5053 return "DW_OP_const8u";
5055 return "DW_OP_const8s";
5057 return "DW_OP_constu";
5059 return "DW_OP_consts";
5063 return "DW_OP_drop";
5065 return "DW_OP_over";
5067 return "DW_OP_pick";
5069 return "DW_OP_swap";
5073 return "DW_OP_xderef";
5081 return "DW_OP_minus";
5093 return "DW_OP_plus";
5094 case DW_OP_plus_uconst
:
5095 return "DW_OP_plus_uconst";
5101 return "DW_OP_shra";
5119 return "DW_OP_skip";
5121 return "DW_OP_lit0";
5123 return "DW_OP_lit1";
5125 return "DW_OP_lit2";
5127 return "DW_OP_lit3";
5129 return "DW_OP_lit4";
5131 return "DW_OP_lit5";
5133 return "DW_OP_lit6";
5135 return "DW_OP_lit7";
5137 return "DW_OP_lit8";
5139 return "DW_OP_lit9";
5141 return "DW_OP_lit10";
5143 return "DW_OP_lit11";
5145 return "DW_OP_lit12";
5147 return "DW_OP_lit13";
5149 return "DW_OP_lit14";
5151 return "DW_OP_lit15";
5153 return "DW_OP_lit16";
5155 return "DW_OP_lit17";
5157 return "DW_OP_lit18";
5159 return "DW_OP_lit19";
5161 return "DW_OP_lit20";
5163 return "DW_OP_lit21";
5165 return "DW_OP_lit22";
5167 return "DW_OP_lit23";
5169 return "DW_OP_lit24";
5171 return "DW_OP_lit25";
5173 return "DW_OP_lit26";
5175 return "DW_OP_lit27";
5177 return "DW_OP_lit28";
5179 return "DW_OP_lit29";
5181 return "DW_OP_lit30";
5183 return "DW_OP_lit31";
5185 return "DW_OP_reg0";
5187 return "DW_OP_reg1";
5189 return "DW_OP_reg2";
5191 return "DW_OP_reg3";
5193 return "DW_OP_reg4";
5195 return "DW_OP_reg5";
5197 return "DW_OP_reg6";
5199 return "DW_OP_reg7";
5201 return "DW_OP_reg8";
5203 return "DW_OP_reg9";
5205 return "DW_OP_reg10";
5207 return "DW_OP_reg11";
5209 return "DW_OP_reg12";
5211 return "DW_OP_reg13";
5213 return "DW_OP_reg14";
5215 return "DW_OP_reg15";
5217 return "DW_OP_reg16";
5219 return "DW_OP_reg17";
5221 return "DW_OP_reg18";
5223 return "DW_OP_reg19";
5225 return "DW_OP_reg20";
5227 return "DW_OP_reg21";
5229 return "DW_OP_reg22";
5231 return "DW_OP_reg23";
5233 return "DW_OP_reg24";
5235 return "DW_OP_reg25";
5237 return "DW_OP_reg26";
5239 return "DW_OP_reg27";
5241 return "DW_OP_reg28";
5243 return "DW_OP_reg29";
5245 return "DW_OP_reg30";
5247 return "DW_OP_reg31";
5249 return "DW_OP_breg0";
5251 return "DW_OP_breg1";
5253 return "DW_OP_breg2";
5255 return "DW_OP_breg3";
5257 return "DW_OP_breg4";
5259 return "DW_OP_breg5";
5261 return "DW_OP_breg6";
5263 return "DW_OP_breg7";
5265 return "DW_OP_breg8";
5267 return "DW_OP_breg9";
5269 return "DW_OP_breg10";
5271 return "DW_OP_breg11";
5273 return "DW_OP_breg12";
5275 return "DW_OP_breg13";
5277 return "DW_OP_breg14";
5279 return "DW_OP_breg15";
5281 return "DW_OP_breg16";
5283 return "DW_OP_breg17";
5285 return "DW_OP_breg18";
5287 return "DW_OP_breg19";
5289 return "DW_OP_breg20";
5291 return "DW_OP_breg21";
5293 return "DW_OP_breg22";
5295 return "DW_OP_breg23";
5297 return "DW_OP_breg24";
5299 return "DW_OP_breg25";
5301 return "DW_OP_breg26";
5303 return "DW_OP_breg27";
5305 return "DW_OP_breg28";
5307 return "DW_OP_breg29";
5309 return "DW_OP_breg30";
5311 return "DW_OP_breg31";
5313 return "DW_OP_regx";
5315 return "DW_OP_fbreg";
5317 return "DW_OP_bregx";
5319 return "DW_OP_piece";
5320 case DW_OP_deref_size
:
5321 return "DW_OP_deref_size";
5322 case DW_OP_xderef_size
:
5323 return "DW_OP_xderef_size";
5327 return "OP_<unknown>";
5332 dwarf_bool_name (mybool
)
5341 /* Convert a DWARF type code into its string name. */
5344 dwarf_type_encoding_name (enc
)
5345 register unsigned enc
;
5349 case DW_ATE_address
:
5350 return "DW_ATE_address";
5351 case DW_ATE_boolean
:
5352 return "DW_ATE_boolean";
5353 case DW_ATE_complex_float
:
5354 return "DW_ATE_complex_float";
5356 return "DW_ATE_float";
5358 return "DW_ATE_signed";
5359 case DW_ATE_signed_char
:
5360 return "DW_ATE_signed_char";
5361 case DW_ATE_unsigned
:
5362 return "DW_ATE_unsigned";
5363 case DW_ATE_unsigned_char
:
5364 return "DW_ATE_unsigned_char";
5366 return "DW_ATE_<unknown>";
5370 /* Convert a DWARF call frame info operation to its string name. */
5374 dwarf_cfi_name (cfi_opc
)
5375 register unsigned cfi_opc
;
5379 case DW_CFA_advance_loc
:
5380 return "DW_CFA_advance_loc";
5382 return "DW_CFA_offset";
5383 case DW_CFA_restore
:
5384 return "DW_CFA_restore";
5386 return "DW_CFA_nop";
5387 case DW_CFA_set_loc
:
5388 return "DW_CFA_set_loc";
5389 case DW_CFA_advance_loc1
:
5390 return "DW_CFA_advance_loc1";
5391 case DW_CFA_advance_loc2
:
5392 return "DW_CFA_advance_loc2";
5393 case DW_CFA_advance_loc4
:
5394 return "DW_CFA_advance_loc4";
5395 case DW_CFA_offset_extended
:
5396 return "DW_CFA_offset_extended";
5397 case DW_CFA_restore_extended
:
5398 return "DW_CFA_restore_extended";
5399 case DW_CFA_undefined
:
5400 return "DW_CFA_undefined";
5401 case DW_CFA_same_value
:
5402 return "DW_CFA_same_value";
5403 case DW_CFA_register
:
5404 return "DW_CFA_register";
5405 case DW_CFA_remember_state
:
5406 return "DW_CFA_remember_state";
5407 case DW_CFA_restore_state
:
5408 return "DW_CFA_restore_state";
5409 case DW_CFA_def_cfa
:
5410 return "DW_CFA_def_cfa";
5411 case DW_CFA_def_cfa_register
:
5412 return "DW_CFA_def_cfa_register";
5413 case DW_CFA_def_cfa_offset
:
5414 return "DW_CFA_def_cfa_offset";
5415 /* SGI/MIPS specific */
5416 case DW_CFA_MIPS_advance_loc8
:
5417 return "DW_CFA_MIPS_advance_loc8";
5419 return "DW_CFA_<unknown>";
5426 struct die_info
*die
;
5430 fprintf (stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5431 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5432 fprintf (stderr
, "\thas children: %s\n",
5433 dwarf_bool_name (die
->has_children
));
5435 fprintf (stderr
, "\tattributes:\n");
5436 for (i
= 0; i
< die
->num_attrs
; ++i
)
5438 fprintf (stderr
, "\t\t%s (%s) ",
5439 dwarf_attr_name (die
->attrs
[i
].name
),
5440 dwarf_form_name (die
->attrs
[i
].form
));
5441 switch (die
->attrs
[i
].form
)
5443 case DW_FORM_ref_addr
:
5445 fprintf (stderr
, "address: ");
5446 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
5448 case DW_FORM_block2
:
5449 case DW_FORM_block4
:
5451 case DW_FORM_block1
:
5452 fprintf (stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5462 fprintf (stderr
, "constant: %d", DW_UNSND (&die
->attrs
[i
]));
5464 case DW_FORM_string
:
5465 fprintf (stderr
, "string: \"%s\"",
5466 DW_STRING (&die
->attrs
[i
])
5467 ? DW_STRING (&die
->attrs
[i
]) : "");
5470 if (DW_UNSND (&die
->attrs
[i
]))
5471 fprintf (stderr
, "flag: TRUE");
5473 fprintf (stderr
, "flag: FALSE");
5475 case DW_FORM_strp
: /* we do not support separate string
5477 case DW_FORM_indirect
: /* we do not handle indirect yet */
5478 case DW_FORM_data8
: /* we do not have 64 bit quantities */
5480 fprintf (stderr
, "unsupported attribute form: %d.",
5481 die
->attrs
[i
].form
);
5483 fprintf (stderr
, "\n");
5489 struct die_info
*die
;
5499 store_in_ref_table (offset
, die
)
5500 unsigned int offset
;
5501 struct die_info
*die
;
5504 struct die_info
*old
;
5506 h
= (offset
% REF_HASH_SIZE
);
5507 old
= die_ref_table
[h
];
5508 die
->next_ref
= old
;
5509 die_ref_table
[h
] = die
;
5514 dwarf2_empty_die_ref_table ()
5516 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5520 dwarf2_get_ref_die_offset (attr
)
5521 struct attribute
*attr
;
5523 unsigned int result
= 0;
5527 case DW_FORM_ref_addr
:
5528 result
= DW_ADDR (attr
);
5533 case DW_FORM_ref_udata
:
5534 result
= cu_header_offset
+ DW_UNSND (attr
);
5537 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5543 follow_die_ref (offset
)
5544 unsigned int offset
;
5546 struct die_info
*die
;
5549 h
= (offset
% REF_HASH_SIZE
);
5550 die
= die_ref_table
[h
];
5553 if (die
->offset
== offset
)
5557 die
= die
->next_ref
;
5562 static struct type
*
5563 dwarf2_fundamental_type (objfile
, typeid)
5564 struct objfile
*objfile
;
5567 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5569 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5573 /* Look for this particular type in the fundamental type vector. If
5574 one is not found, create and install one appropriate for the
5575 current language and the current target machine. */
5577 if (ftypes
[typeid] == NULL
)
5579 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5582 return (ftypes
[typeid]);
5585 /* Decode simple location descriptions.
5586 Given a pointer to a dwarf block that defines a location, compute
5587 the location and return the value.
5589 FIXME: This is a kludge until we figure out a better
5590 way to handle the location descriptions.
5591 Gdb's design does not mesh well with the DWARF2 notion of a location
5592 computing interpreter, which is a shame because the flexibility goes unused.
5593 FIXME: Implement more operations as necessary.
5595 A location description containing no operations indicates that the
5596 object is optimized out. The global optimized_out flag is set for
5597 those, the return value is meaningless.
5599 When the result is a register number, the global isreg flag is set,
5600 otherwise it is cleared.
5602 When the result is a base register offset, the global offreg flag is set
5603 and the register number is returned in basereg, otherwise it is cleared.
5605 When the DW_OP_fbreg operation is encountered without a corresponding
5606 DW_AT_frame_base attribute, the global islocal flag is set.
5607 Hopefully the machine dependent code knows how to set up a virtual
5608 frame pointer for the local references.
5610 Note that stack[0] is unused except as a default error return.
5611 Note that stack overflow is not yet handled. */
5614 decode_locdesc (blk
, objfile
)
5615 struct dwarf_block
*blk
;
5616 struct objfile
*objfile
;
5619 int size
= blk
->size
;
5620 char *data
= blk
->data
;
5621 CORE_ADDR stack
[64];
5623 unsigned int bytes_read
, unsnd
;
5674 stack
[++stacki
] = op
- DW_OP_reg0
;
5679 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5681 #if defined(HARRIS_TARGET) && defined(_M88K)
5682 /* The Harris 88110 gdb ports have long kept their special reg
5683 numbers between their gp-regs and their x-regs. This is
5684 not how our dwarf is generated. Punt. */
5687 stack
[++stacki
] = unsnd
;
5723 basereg
= op
- DW_OP_breg0
;
5724 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5730 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5732 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5737 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5739 if (frame_base_reg
>= 0)
5742 basereg
= frame_base_reg
;
5743 stack
[stacki
] += frame_base_offset
;
5747 complain (&dwarf2_missing_at_frame_base
);
5753 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
]);
5758 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
5763 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
5768 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
5773 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
5778 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
5783 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
5788 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
5794 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5799 stack
[stacki
- 1] += stack
[stacki
];
5803 case DW_OP_plus_uconst
:
5804 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5809 stack
[stacki
- 1] = stack
[stacki
] - stack
[stacki
- 1];
5815 /* If we're not the last op, then we definitely can't encode
5816 this using GDB's address_class enum. */
5818 complain (&dwarf2_complex_location_expr
);
5822 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
5823 return (stack
[stacki
]);
5826 return (stack
[stacki
]);
5829 /* memory allocation interface */
5833 dwarf2_free_tmp_obstack (ignore
)
5836 obstack_free (&dwarf2_tmp_obstack
, NULL
);
5839 static struct dwarf_block
*
5840 dwarf_alloc_block ()
5842 struct dwarf_block
*blk
;
5844 blk
= (struct dwarf_block
*)
5845 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
5849 static struct abbrev_info
*
5850 dwarf_alloc_abbrev ()
5852 struct abbrev_info
*abbrev
;
5854 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
5855 memset (abbrev
, 0, sizeof (struct abbrev_info
));
5859 static struct die_info
*
5862 struct die_info
*die
;
5864 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5865 memset (die
, 0, sizeof (struct die_info
));