1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
4 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
5 Inc. with support from Florida State University (under contract
6 with the Ada Joint Program Office), and Silicon Graphics, Inc.
7 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
8 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
11 This file is part of GDB.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or (at
16 your option) any later version.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. */
34 #include "elf/dwarf2.h"
37 #include "expression.h"
39 #include "complaints.h"
42 #include "gdb_string.h"
43 #include <sys/types.h>
45 /* .debug_info header for a compilation unit
46 Because of alignment constraints, this structure has padding and cannot
47 be mapped directly onto the beginning of the .debug_info section. */
48 typedef struct comp_unit_header
50 unsigned int length
; /* length of the .debug_info
52 unsigned short version
; /* version number -- 2 for DWARF
54 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
55 unsigned char addr_size
; /* byte size of an address -- 4 */
58 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
60 /* .debug_pubnames header
61 Because of alignment constraints, this structure has padding and cannot
62 be mapped directly onto the beginning of the .debug_info section. */
63 typedef struct pubnames_header
65 unsigned int length
; /* length of the .debug_pubnames
67 unsigned char version
; /* version number -- 2 for DWARF
69 unsigned int info_offset
; /* offset into .debug_info section */
70 unsigned int info_size
; /* byte size of .debug_info section
74 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
76 /* .debug_pubnames header
77 Because of alignment constraints, this structure has padding and cannot
78 be mapped directly onto the beginning of the .debug_info section. */
79 typedef struct aranges_header
81 unsigned int length
; /* byte len of the .debug_aranges
83 unsigned short version
; /* version number -- 2 for DWARF
85 unsigned int info_offset
; /* offset into .debug_info section */
86 unsigned char addr_size
; /* byte size of an address */
87 unsigned char seg_size
; /* byte size of segment descriptor */
90 #define _ACTUAL_ARANGES_HEADER_SIZE 12
92 /* .debug_line statement program prologue
93 Because of alignment constraints, this structure has padding and cannot
94 be mapped directly onto the beginning of the .debug_info section. */
95 typedef struct statement_prologue
97 unsigned int total_length
; /* byte length of the statement
99 unsigned short version
; /* version number -- 2 for DWARF
101 unsigned int prologue_length
; /* # bytes between prologue &
103 unsigned char minimum_instruction_length
; /* byte size of
105 unsigned char default_is_stmt
; /* initial value of is_stmt
108 unsigned char line_range
;
109 unsigned char opcode_base
; /* number assigned to first special
111 unsigned char *standard_opcode_lengths
;
115 /* offsets and sizes of debugging sections */
117 static file_ptr dwarf_info_offset
;
118 static file_ptr dwarf_abbrev_offset
;
119 static file_ptr dwarf_line_offset
;
120 static file_ptr dwarf_pubnames_offset
;
121 static file_ptr dwarf_aranges_offset
;
122 static file_ptr dwarf_loc_offset
;
123 static file_ptr dwarf_macinfo_offset
;
124 static file_ptr dwarf_str_offset
;
126 static unsigned int dwarf_info_size
;
127 static unsigned int dwarf_abbrev_size
;
128 static unsigned int dwarf_line_size
;
129 static unsigned int dwarf_pubnames_size
;
130 static unsigned int dwarf_aranges_size
;
131 static unsigned int dwarf_loc_size
;
132 static unsigned int dwarf_macinfo_size
;
133 static unsigned int dwarf_str_size
;
135 /* names of the debugging sections */
137 #define INFO_SECTION ".debug_info"
138 #define ABBREV_SECTION ".debug_abbrev"
139 #define LINE_SECTION ".debug_line"
140 #define PUBNAMES_SECTION ".debug_pubnames"
141 #define ARANGES_SECTION ".debug_aranges"
142 #define LOC_SECTION ".debug_loc"
143 #define MACINFO_SECTION ".debug_macinfo"
144 #define STR_SECTION ".debug_str"
146 /* local data types */
148 /* The data in a compilation unit header looks like this. */
149 struct comp_unit_head
153 unsigned int abbrev_offset
;
154 unsigned char addr_size
;
157 /* The data in the .debug_line statement prologue looks like this. */
160 unsigned int total_length
;
161 unsigned short version
;
162 unsigned int prologue_length
;
163 unsigned char minimum_instruction_length
;
164 unsigned char default_is_stmt
;
166 unsigned char line_range
;
167 unsigned char opcode_base
;
168 unsigned char *standard_opcode_lengths
;
171 /* When we construct a partial symbol table entry we only
172 need this much information. */
173 struct partial_die_info
176 unsigned char has_children
;
177 unsigned char is_external
;
178 unsigned char is_declaration
;
179 unsigned char has_type
;
185 struct dwarf_block
*locdesc
;
186 unsigned int language
;
190 /* This data structure holds the information of an abbrev. */
193 unsigned int number
; /* number identifying abbrev */
194 enum dwarf_tag tag
; /* dwarf tag */
195 int has_children
; /* boolean */
196 unsigned int num_attrs
; /* number of attributes */
197 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
198 struct abbrev_info
*next
; /* next in chain */
203 enum dwarf_attribute name
;
204 enum dwarf_form form
;
207 /* This data structure holds a complete die structure. */
210 enum dwarf_tag tag
; /* Tag indicating type of die */
211 unsigned short has_children
; /* Does the die have children */
212 unsigned int abbrev
; /* Abbrev number */
213 unsigned int offset
; /* Offset in .debug_info section */
214 unsigned int num_attrs
; /* Number of attributes */
215 struct attribute
*attrs
; /* An array of attributes */
216 struct die_info
*next_ref
; /* Next die in ref hash table */
217 struct die_info
*next
; /* Next die in linked list */
218 struct type
*type
; /* Cached type information */
221 /* Attributes have a name and a value */
224 enum dwarf_attribute name
;
225 enum dwarf_form form
;
229 struct dwarf_block
*blk
;
237 /* Get at parts of an attribute structure */
239 #define DW_STRING(attr) ((attr)->u.str)
240 #define DW_UNSND(attr) ((attr)->u.unsnd)
241 #define DW_BLOCK(attr) ((attr)->u.blk)
242 #define DW_SND(attr) ((attr)->u.snd)
243 #define DW_ADDR(attr) ((attr)->u.addr)
245 /* Blocks are a bunch of untyped bytes. */
252 /* We only hold one compilation unit's abbrevs in
253 memory at any one time. */
254 #ifndef ABBREV_HASH_SIZE
255 #define ABBREV_HASH_SIZE 121
257 #ifndef ATTR_ALLOC_CHUNK
258 #define ATTR_ALLOC_CHUNK 4
261 static struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
263 /* A hash table of die offsets for following references. */
264 #ifndef REF_HASH_SIZE
265 #define REF_HASH_SIZE 1021
268 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
270 /* Obstack for allocating temporary storage used during symbol reading. */
271 static struct obstack dwarf2_tmp_obstack
;
273 /* Offset to the first byte of the current compilation unit header,
274 for resolving relative reference dies. */
275 static unsigned int cu_header_offset
;
277 /* Allocate fields for structs, unions and enums in this size. */
278 #ifndef DW_FIELD_ALLOC_CHUNK
279 #define DW_FIELD_ALLOC_CHUNK 4
282 /* The language we are debugging. */
283 static enum language cu_language
;
284 static const struct language_defn
*cu_language_defn
;
286 /* Actually data from the sections. */
287 static char *dwarf_info_buffer
;
288 static char *dwarf_abbrev_buffer
;
289 static char *dwarf_line_buffer
;
291 /* A zeroed version of a partial die for initialization purposes. */
292 static struct partial_die_info zeroed_partial_die
;
294 /* The generic symbol table building routines have separate lists for
295 file scope symbols and all all other scopes (local scopes). So
296 we need to select the right one to pass to add_symbol_to_list().
297 We do it by keeping a pointer to the correct list in list_in_scope.
299 FIXME: The original dwarf code just treated the file scope as the first
300 local scope, and all other local scopes as nested local scopes, and worked
301 fine. Check to see if we really need to distinguish these
303 static struct pending
**list_in_scope
= &file_symbols
;
305 /* FIXME: decode_locdesc sets these variables to describe the location
306 to the caller. These ought to be a structure or something. If
307 none of the flags are set, the object lives at the address returned
308 by decode_locdesc. */
310 static int optimized_out
; /* No ops in location in expression,
311 so object was optimized out. */
312 static int isreg
; /* Object lives in register.
313 decode_locdesc's return value is
314 the register number. */
315 static int offreg
; /* Object's address is the sum of the
316 register specified by basereg, plus
317 the offset returned. */
318 static int basereg
; /* See `offreg'. */
319 static int isderef
; /* Value described by flags above is
320 the address of a pointer to the object. */
321 static int islocal
; /* Variable is at the returned offset
322 from the frame start, but there's
323 no identified frame pointer for
324 this function, so we can't say
325 which register it's relative to;
328 /* DW_AT_frame_base values for the current function.
329 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
330 contains the register number for the frame register.
331 frame_base_offset is the offset from the frame register to the
332 virtual stack frame. */
333 static int frame_base_reg
;
334 static CORE_ADDR frame_base_offset
;
336 /* This value is added to each symbol value. FIXME: Generalize to
337 the section_offsets structure used by dbxread (once this is done,
338 pass the appropriate section number to end_symtab). */
339 static CORE_ADDR baseaddr
; /* Add to each symbol value */
341 /* We put a pointer to this structure in the read_symtab_private field
343 The complete dwarf information for an objfile is kept in the
344 psymbol_obstack, so that absolute die references can be handled.
345 Most of the information in this structure is related to an entire
346 object file and could be passed via the sym_private field of the objfile.
347 It is however conceivable that dwarf2 might not be the only type
348 of symbols read from an object file. */
352 /* Pointer to start of dwarf info buffer for the objfile. */
354 char *dwarf_info_buffer
;
356 /* Offset in dwarf_info_buffer for this compilation unit. */
358 unsigned long dwarf_info_offset
;
360 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
362 char *dwarf_abbrev_buffer
;
364 /* Size of dwarf abbreviation section for the objfile. */
366 unsigned int dwarf_abbrev_size
;
368 /* Pointer to start of dwarf line buffer for the objfile. */
370 char *dwarf_line_buffer
;
373 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
374 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
375 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
376 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
377 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
378 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
380 /* Maintain an array of referenced fundamental types for the current
381 compilation unit being read. For DWARF version 1, we have to construct
382 the fundamental types on the fly, since no information about the
383 fundamental types is supplied. Each such fundamental type is created by
384 calling a language dependent routine to create the type, and then a
385 pointer to that type is then placed in the array at the index specified
386 by it's FT_<TYPENAME> value. The array has a fixed size set by the
387 FT_NUM_MEMBERS compile time constant, which is the number of predefined
388 fundamental types gdb knows how to construct. */
389 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
391 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
392 but this would require a corresponding change in unpack_field_as_long
394 static int bits_per_byte
= 8;
396 /* The routines that read and process dies for a C struct or C++ class
397 pass lists of data member fields and lists of member function fields
398 in an instance of a field_info structure, as defined below. */
401 /* List of data member and baseclasses fields. */
404 struct nextfield
*next
;
411 /* Number of fields. */
414 /* Number of baseclasses. */
417 /* Set if the accesibility of one of the fields is not public. */
418 int non_public_fields
;
420 /* Member function fields array, entries are allocated in the order they
421 are encountered in the object file. */
424 struct nextfnfield
*next
;
425 struct fn_field fnfield
;
429 /* Member function fieldlist array, contains name of possibly overloaded
430 member function, number of overloaded member functions and a pointer
431 to the head of the member function field chain. */
436 struct nextfnfield
*head
;
440 /* Number of entries in the fnfieldlists array. */
444 /* FIXME: Kludge to mark a varargs function type for C++ member function
445 argument processing. */
446 #define TYPE_FLAG_VARARGS (1 << 10)
448 /* Dwarf2 has no clean way to discern C++ static and non-static member
449 functions. G++ helps GDB by marking the first parameter for non-static
450 member functions (which is the this pointer) as artificial.
451 We pass this information between dwarf2_add_member_fn and
452 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
453 #define TYPE_FIELD_ARTIFICIAL TYPE_FIELD_BITPOS
455 /* Various complaints about symbol reading that don't abort the process */
457 static struct complaint dwarf2_const_ignored
=
459 "type qualifier 'const' ignored", 0, 0
461 static struct complaint dwarf2_volatile_ignored
=
463 "type qualifier 'volatile' ignored", 0, 0
465 static struct complaint dwarf2_non_const_array_bound_ignored
=
467 "non-constant array bounds form '%s' ignored", 0, 0
469 static struct complaint dwarf2_missing_line_number_section
=
471 "missing .debug_line section", 0, 0
473 static struct complaint dwarf2_mangled_line_number_section
=
475 "mangled .debug_line section", 0, 0
477 static struct complaint dwarf2_unsupported_die_ref_attr
=
479 "unsupported die ref attribute form: '%s'", 0, 0
481 static struct complaint dwarf2_unsupported_stack_op
=
483 "unsupported stack op: '%s'", 0, 0
485 static struct complaint dwarf2_complex_location_expr
=
487 "location expression too complex", 0, 0
489 static struct complaint dwarf2_unsupported_tag
=
491 "unsupported tag: '%s'", 0, 0
493 static struct complaint dwarf2_unsupported_at_encoding
=
495 "unsupported DW_AT_encoding: '%s'", 0, 0
497 static struct complaint dwarf2_unsupported_at_frame_base
=
499 "unsupported DW_AT_frame_base for function '%s'", 0, 0
501 static struct complaint dwarf2_unexpected_tag
=
503 "unexepected tag in read_type_die: '%s'", 0, 0
505 static struct complaint dwarf2_missing_at_frame_base
=
507 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
509 static struct complaint dwarf2_bad_static_member_name
=
511 "unrecognized static data member name '%s'", 0, 0
513 static struct complaint dwarf2_unsupported_accessibility
=
515 "unsupported accessibility %d", 0, 0
517 static struct complaint dwarf2_bad_member_name_complaint
=
519 "cannot extract member name from '%s'", 0, 0
521 static struct complaint dwarf2_missing_member_fn_type_complaint
=
523 "member function type missing for '%s'", 0, 0
525 static struct complaint dwarf2_vtbl_not_found_complaint
=
527 "virtual function table pointer not found when defining class '%s'", 0, 0
529 static struct complaint dwarf2_absolute_sibling_complaint
=
531 "ignoring absolute DW_AT_sibling", 0, 0
533 static struct complaint dwarf2_const_value_length_mismatch
=
535 "const value length mismatch for '%s', got %d, expected %d", 0, 0
537 static struct complaint dwarf2_unsupported_const_value_attr
=
539 "unsupported const value attribute form: '%s'", 0, 0
542 /* Remember the addr_size read from the dwarf.
543 If a target expects to link compilation units with differing address
544 sizes, gdb needs to be sure that the appropriate size is here for
545 whatever scope is currently getting read. */
546 static int address_size
;
548 /* Externals references. */
549 extern int info_verbose
; /* From main.c; nonzero => verbose */
551 /* local function prototypes */
553 static void dwarf2_locate_sections
PARAMS ((bfd
*, asection
*, PTR
));
556 static void dwarf2_build_psymtabs_easy
PARAMS ((struct objfile
*, int));
559 static void dwarf2_build_psymtabs_hard
PARAMS ((struct objfile
*, int));
561 static char *scan_partial_symbols
PARAMS ((char *, struct objfile
*,
562 CORE_ADDR
*, CORE_ADDR
*));
564 static void add_partial_symbol
PARAMS ((struct partial_die_info
*,
567 static void dwarf2_psymtab_to_symtab
PARAMS ((struct partial_symtab
*));
569 static void psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*));
571 static char *dwarf2_read_section
PARAMS ((struct objfile
*, file_ptr
,
574 static void dwarf2_read_abbrevs
PARAMS ((bfd
*, unsigned int));
576 static void dwarf2_empty_abbrev_table
PARAMS ((PTR
));
578 static struct abbrev_info
*dwarf2_lookup_abbrev
PARAMS ((unsigned int));
580 static char *read_partial_die
PARAMS ((struct partial_die_info
*,
581 bfd
*, char *, int *));
583 static char *read_full_die
PARAMS ((struct die_info
**, bfd
*, char *));
585 static char *read_attribute
PARAMS ((struct attribute
*, struct attr_abbrev
*,
588 static unsigned int read_1_byte
PARAMS ((bfd
*, char *));
590 static int read_1_signed_byte
PARAMS ((bfd
*, char *));
592 static unsigned int read_2_bytes
PARAMS ((bfd
*, char *));
594 static unsigned int read_4_bytes
PARAMS ((bfd
*, char *));
596 static unsigned int read_8_bytes
PARAMS ((bfd
*, char *));
598 static CORE_ADDR read_address
PARAMS ((bfd
*, char *));
600 static char *read_n_bytes
PARAMS ((bfd
*, char *, unsigned int));
602 static char *read_string
PARAMS ((bfd
*, char *, unsigned int *));
604 static unsigned int read_unsigned_leb128
PARAMS ((bfd
*, char *,
607 static int read_signed_leb128
PARAMS ((bfd
*, char *, unsigned int *));
609 static void set_cu_language
PARAMS ((unsigned int));
611 static struct attribute
*dwarf_attr
PARAMS ((struct die_info
*,
614 static int die_is_declaration (struct die_info
*);
616 static void dwarf_decode_lines
PARAMS ((unsigned int, char *, bfd
*));
618 static void dwarf2_start_subfile
PARAMS ((char *, char *));
620 static struct symbol
*new_symbol
PARAMS ((struct die_info
*, struct type
*,
623 static void dwarf2_const_value
PARAMS ((struct attribute
*, struct symbol
*,
626 static void dwarf2_const_value_data (struct attribute
*attr
,
630 static struct type
*die_type
PARAMS ((struct die_info
*, struct objfile
*));
632 static struct type
*die_containing_type
PARAMS ((struct die_info
*,
636 static struct type
*type_at_offset
PARAMS ((unsigned int, struct objfile
*));
639 static struct type
*tag_type_to_type
PARAMS ((struct die_info
*,
642 static void read_type_die
PARAMS ((struct die_info
*, struct objfile
*));
644 static void read_typedef
PARAMS ((struct die_info
*, struct objfile
*));
646 static void read_base_type
PARAMS ((struct die_info
*, struct objfile
*));
648 static void read_file_scope
PARAMS ((struct die_info
*, struct objfile
*));
650 static void read_func_scope
PARAMS ((struct die_info
*, struct objfile
*));
652 static void read_lexical_block_scope
PARAMS ((struct die_info
*,
655 static int dwarf2_get_pc_bounds
PARAMS ((struct die_info
*,
656 CORE_ADDR
*, CORE_ADDR
*,
659 static void dwarf2_add_field
PARAMS ((struct field_info
*, struct die_info
*,
662 static void dwarf2_attach_fields_to_type
PARAMS ((struct field_info
*,
666 static void dwarf2_add_member_fn
PARAMS ((struct field_info
*,
667 struct die_info
*, struct type
*,
668 struct objfile
* objfile
));
670 static void dwarf2_attach_fn_fields_to_type
PARAMS ((struct field_info
*,
674 static void read_structure_scope
PARAMS ((struct die_info
*, struct objfile
*));
676 static void read_common_block
PARAMS ((struct die_info
*, struct objfile
*));
678 static void read_enumeration
PARAMS ((struct die_info
*, struct objfile
*));
680 static struct type
*dwarf_base_type
PARAMS ((int, int, struct objfile
*));
682 static CORE_ADDR decode_locdesc
PARAMS ((struct dwarf_block
*,
685 static void read_array_type
PARAMS ((struct die_info
*, struct objfile
*));
687 static void read_tag_pointer_type
PARAMS ((struct die_info
*,
690 static void read_tag_ptr_to_member_type
PARAMS ((struct die_info
*,
693 static void read_tag_reference_type
PARAMS ((struct die_info
*,
696 static void read_tag_const_type
PARAMS ((struct die_info
*, struct objfile
*));
698 static void read_tag_volatile_type
PARAMS ((struct die_info
*,
701 static void read_tag_string_type
PARAMS ((struct die_info
*,
704 static void read_subroutine_type
PARAMS ((struct die_info
*,
707 struct die_info
*read_comp_unit
PARAMS ((char *, bfd
*));
709 static void free_die_list
PARAMS ((struct die_info
*));
711 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
713 static void process_die
PARAMS ((struct die_info
*, struct objfile
*));
715 static char *dwarf2_linkage_name
PARAMS ((struct die_info
*));
717 static char *dwarf_tag_name
PARAMS ((unsigned int));
719 static char *dwarf_attr_name
PARAMS ((unsigned int));
721 static char *dwarf_form_name
PARAMS ((unsigned int));
723 static char *dwarf_stack_op_name
PARAMS ((unsigned int));
725 static char *dwarf_bool_name
PARAMS ((unsigned int));
727 static char *dwarf_type_encoding_name
PARAMS ((unsigned int));
730 static char *dwarf_cfi_name
PARAMS ((unsigned int));
732 struct die_info
*copy_die
PARAMS ((struct die_info
*));
735 struct die_info
*sibling_die
PARAMS ((struct die_info
*));
737 void dump_die
PARAMS ((struct die_info
*));
739 void dump_die_list
PARAMS ((struct die_info
*));
741 void store_in_ref_table
PARAMS ((unsigned int, struct die_info
*));
743 static void dwarf2_empty_die_ref_table
PARAMS ((void));
745 static unsigned int dwarf2_get_ref_die_offset
PARAMS ((struct attribute
*));
747 struct die_info
*follow_die_ref
PARAMS ((unsigned int));
749 static struct type
*dwarf2_fundamental_type
PARAMS ((struct objfile
*, int));
751 /* memory allocation interface */
753 static void dwarf2_free_tmp_obstack
PARAMS ((PTR
));
755 static struct dwarf_block
*dwarf_alloc_block
PARAMS ((void));
757 static struct abbrev_info
*dwarf_alloc_abbrev
PARAMS ((void));
759 static struct die_info
*dwarf_alloc_die
PARAMS ((void));
761 /* Try to locate the sections we need for DWARF 2 debugging
762 information and return true if we have enough to do something. */
765 dwarf2_has_info (abfd
)
768 dwarf_info_offset
= dwarf_abbrev_offset
= dwarf_line_offset
= 0;
769 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
770 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
780 /* This function is mapped across the sections and remembers the
781 offset and size of each of the debugging sections we are interested
785 dwarf2_locate_sections (ignore_abfd
, sectp
, ignore_ptr
)
790 if (STREQ (sectp
->name
, INFO_SECTION
))
792 dwarf_info_offset
= sectp
->filepos
;
793 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
795 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
797 dwarf_abbrev_offset
= sectp
->filepos
;
798 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
800 else if (STREQ (sectp
->name
, LINE_SECTION
))
802 dwarf_line_offset
= sectp
->filepos
;
803 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
805 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
807 dwarf_pubnames_offset
= sectp
->filepos
;
808 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
810 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
812 dwarf_aranges_offset
= sectp
->filepos
;
813 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
815 else if (STREQ (sectp
->name
, LOC_SECTION
))
817 dwarf_loc_offset
= sectp
->filepos
;
818 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
820 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
822 dwarf_macinfo_offset
= sectp
->filepos
;
823 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
825 else if (STREQ (sectp
->name
, STR_SECTION
))
827 dwarf_str_offset
= sectp
->filepos
;
828 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
832 /* Build a partial symbol table. */
835 dwarf2_build_psymtabs (objfile
, mainline
)
836 struct objfile
*objfile
;
840 /* We definitely need the .debug_info and .debug_abbrev sections */
842 dwarf_info_buffer
= dwarf2_read_section (objfile
,
845 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
848 dwarf_line_buffer
= dwarf2_read_section (objfile
,
852 if (mainline
|| objfile
->global_psymbols
.size
== 0 ||
853 objfile
->static_psymbols
.size
== 0)
855 init_psymbol_list (objfile
, 1024);
859 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
861 /* Things are significantly easier if we have .debug_aranges and
862 .debug_pubnames sections */
864 dwarf2_build_psymtabs_easy (objfile
, mainline
);
868 /* only test this case for now */
870 /* In this case we have to work a bit harder */
871 dwarf2_build_psymtabs_hard (objfile
, mainline
);
876 /* Build the partial symbol table from the information in the
877 .debug_pubnames and .debug_aranges sections. */
880 dwarf2_build_psymtabs_easy (objfile
, mainline
)
881 struct objfile
*objfile
;
884 bfd
*abfd
= objfile
->obfd
;
885 char *aranges_buffer
, *pubnames_buffer
;
886 char *aranges_ptr
, *pubnames_ptr
;
887 unsigned int entry_length
, version
, info_offset
, info_size
;
889 pubnames_buffer
= dwarf2_read_section (objfile
,
890 dwarf_pubnames_offset
,
891 dwarf_pubnames_size
);
892 pubnames_ptr
= pubnames_buffer
;
893 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
895 entry_length
= read_4_bytes (abfd
, pubnames_ptr
);
897 version
= read_1_byte (abfd
, pubnames_ptr
);
899 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
901 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
905 aranges_buffer
= dwarf2_read_section (objfile
,
906 dwarf_aranges_offset
,
912 /* Build the partial symbol table by doing a quick pass through the
913 .debug_info and .debug_abbrev sections. */
916 dwarf2_build_psymtabs_hard (objfile
, mainline
)
917 struct objfile
*objfile
;
920 /* Instead of reading this into a big buffer, we should probably use
921 mmap() on architectures that support it. (FIXME) */
922 bfd
*abfd
= objfile
->obfd
;
923 char *info_ptr
, *abbrev_ptr
;
924 char *beg_of_comp_unit
;
925 struct comp_unit_head cu_header
;
926 struct partial_die_info comp_unit_die
;
927 struct partial_symtab
*pst
;
928 struct cleanup
*back_to
;
929 int comp_unit_has_pc_info
;
930 CORE_ADDR lowpc
, highpc
;
932 info_ptr
= dwarf_info_buffer
;
933 abbrev_ptr
= dwarf_abbrev_buffer
;
935 obstack_init (&dwarf2_tmp_obstack
);
936 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
938 while ((unsigned int) (info_ptr
- dwarf_info_buffer
)
939 + ((info_ptr
- dwarf_info_buffer
) % 4) < dwarf_info_size
)
941 beg_of_comp_unit
= info_ptr
;
942 cu_header
.length
= read_4_bytes (abfd
, info_ptr
);
944 cu_header
.version
= read_2_bytes (abfd
, info_ptr
);
946 cu_header
.abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
948 cu_header
.addr_size
= read_1_byte (abfd
, info_ptr
);
950 address_size
= cu_header
.addr_size
;
952 if (cu_header
.version
!= 2)
954 error ("Dwarf Error: wrong version in compilation unit header.");
957 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
959 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
960 (long) cu_header
.abbrev_offset
,
961 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
964 if (beg_of_comp_unit
+ cu_header
.length
+ 4
965 > dwarf_info_buffer
+ dwarf_info_size
)
967 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
968 (long) cu_header
.length
,
969 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
972 /* Read the abbrevs for this compilation unit into a table */
973 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
974 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
976 /* Read the compilation unit die */
977 info_ptr
= read_partial_die (&comp_unit_die
, abfd
,
978 info_ptr
, &comp_unit_has_pc_info
);
980 /* Set the language we're debugging */
981 set_cu_language (comp_unit_die
.language
);
983 /* Allocate a new partial symbol table structure */
984 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
985 comp_unit_die
.name
? comp_unit_die
.name
: "",
987 objfile
->global_psymbols
.next
,
988 objfile
->static_psymbols
.next
);
990 pst
->read_symtab_private
= (char *)
991 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
992 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
993 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
994 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
995 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
996 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
997 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
998 baseaddr
= ANOFFSET (objfile
->section_offsets
, 0);
1000 /* Store the function that reads in the rest of the symbol table */
1001 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1003 /* Check if comp unit has_children.
1004 If so, read the rest of the partial symbols from this comp unit.
1005 If not, there's no more debug_info for this comp unit. */
1006 if (comp_unit_die
.has_children
)
1008 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
);
1010 /* If the compilation unit didn't have an explicit address range,
1011 then use the information extracted from its child dies. */
1012 if (!comp_unit_has_pc_info
)
1014 comp_unit_die
.lowpc
= lowpc
;
1015 comp_unit_die
.highpc
= highpc
;
1018 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1019 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1021 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1022 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1023 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1024 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1025 sort_pst_symbols (pst
);
1027 /* If there is already a psymtab or symtab for a file of this
1028 name, remove it. (If there is a symtab, more drastic things
1029 also happen.) This happens in VxWorks. */
1030 free_named_symtabs (pst
->filename
);
1032 info_ptr
= beg_of_comp_unit
+ cu_header
.length
+ 4;
1034 do_cleanups (back_to
);
1037 /* Read in all interesting dies to the end of the compilation unit. */
1040 scan_partial_symbols (info_ptr
, objfile
, lowpc
, highpc
)
1042 struct objfile
*objfile
;
1046 bfd
*abfd
= objfile
->obfd
;
1047 struct partial_die_info pdi
;
1049 /* This function is called after we've read in the comp_unit_die in
1050 order to read its children. We start the nesting level at 1 since
1051 we have pushed 1 level down in order to read the comp unit's children.
1052 The comp unit itself is at level 0, so we stop reading when we pop
1053 back to that level. */
1055 int nesting_level
= 1;
1058 *lowpc
= ((CORE_ADDR
) -1);
1059 *highpc
= ((CORE_ADDR
) 0);
1061 while (nesting_level
)
1063 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, &has_pc_info
);
1069 case DW_TAG_subprogram
:
1072 if (pdi
.lowpc
< *lowpc
)
1076 if (pdi
.highpc
> *highpc
)
1078 *highpc
= pdi
.highpc
;
1080 if ((pdi
.is_external
|| nesting_level
== 1)
1081 && !pdi
.is_declaration
)
1083 add_partial_symbol (&pdi
, objfile
);
1087 case DW_TAG_variable
:
1088 case DW_TAG_typedef
:
1089 case DW_TAG_class_type
:
1090 case DW_TAG_structure_type
:
1091 case DW_TAG_union_type
:
1092 case DW_TAG_enumeration_type
:
1093 if ((pdi
.is_external
|| nesting_level
== 1)
1094 && !pdi
.is_declaration
)
1096 add_partial_symbol (&pdi
, objfile
);
1099 case DW_TAG_enumerator
:
1100 /* File scope enumerators are added to the partial symbol
1102 if (nesting_level
== 2)
1103 add_partial_symbol (&pdi
, objfile
);
1105 case DW_TAG_base_type
:
1106 /* File scope base type definitions are added to the partial
1108 if (nesting_level
== 1)
1109 add_partial_symbol (&pdi
, objfile
);
1116 /* If the die has a sibling, skip to the sibling.
1117 Do not skip enumeration types, we want to record their
1119 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1121 info_ptr
= pdi
.sibling
;
1123 else if (pdi
.has_children
)
1125 /* Die has children, but the optional DW_AT_sibling attribute
1136 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1137 from `maint check'. */
1138 if (*lowpc
== ((CORE_ADDR
) -1))
1144 add_partial_symbol (pdi
, objfile
)
1145 struct partial_die_info
*pdi
;
1146 struct objfile
*objfile
;
1152 case DW_TAG_subprogram
:
1153 if (pdi
->is_external
)
1155 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1156 mst_text, objfile); */
1157 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1158 VAR_NAMESPACE
, LOC_BLOCK
,
1159 &objfile
->global_psymbols
,
1160 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1164 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1165 mst_file_text, objfile); */
1166 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1167 VAR_NAMESPACE
, LOC_BLOCK
,
1168 &objfile
->static_psymbols
,
1169 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1172 case DW_TAG_variable
:
1173 if (pdi
->is_external
)
1176 Don't enter into the minimal symbol tables as there is
1177 a minimal symbol table entry from the ELF symbols already.
1178 Enter into partial symbol table if it has a location
1179 descriptor or a type.
1180 If the location descriptor is missing, new_symbol will create
1181 a LOC_UNRESOLVED symbol, the address of the variable will then
1182 be determined from the minimal symbol table whenever the variable
1184 The address for the partial symbol table entry is not
1185 used by GDB, but it comes in handy for debugging partial symbol
1189 addr
= decode_locdesc (pdi
->locdesc
, objfile
);
1190 if (pdi
->locdesc
|| pdi
->has_type
)
1191 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1192 VAR_NAMESPACE
, LOC_STATIC
,
1193 &objfile
->global_psymbols
,
1194 0, addr
+ baseaddr
, cu_language
, objfile
);
1198 /* Static Variable. Skip symbols without location descriptors. */
1199 if (pdi
->locdesc
== NULL
)
1201 addr
= decode_locdesc (pdi
->locdesc
, objfile
);
1202 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1203 mst_file_data, objfile); */
1204 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1205 VAR_NAMESPACE
, LOC_STATIC
,
1206 &objfile
->static_psymbols
,
1207 0, addr
+ baseaddr
, cu_language
, objfile
);
1210 case DW_TAG_typedef
:
1211 case DW_TAG_base_type
:
1212 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1213 VAR_NAMESPACE
, LOC_TYPEDEF
,
1214 &objfile
->static_psymbols
,
1215 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1217 case DW_TAG_class_type
:
1218 case DW_TAG_structure_type
:
1219 case DW_TAG_union_type
:
1220 case DW_TAG_enumeration_type
:
1221 /* Skip aggregate types without children, these are external
1223 if (pdi
->has_children
== 0)
1225 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1226 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1227 &objfile
->static_psymbols
,
1228 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1230 if (cu_language
== language_cplus
)
1232 /* For C++, these implicitly act as typedefs as well. */
1233 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1234 VAR_NAMESPACE
, LOC_TYPEDEF
,
1235 &objfile
->static_psymbols
,
1236 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1239 case DW_TAG_enumerator
:
1240 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1241 VAR_NAMESPACE
, LOC_CONST
,
1242 &objfile
->static_psymbols
,
1243 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1250 /* Expand this partial symbol table into a full symbol table. */
1253 dwarf2_psymtab_to_symtab (pst
)
1254 struct partial_symtab
*pst
;
1256 /* FIXME: This is barely more than a stub. */
1261 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1267 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1268 gdb_flush (gdb_stdout
);
1271 psymtab_to_symtab_1 (pst
);
1273 /* Finish up the debug error message. */
1275 printf_filtered ("done.\n");
1281 psymtab_to_symtab_1 (pst
)
1282 struct partial_symtab
*pst
;
1284 struct objfile
*objfile
= pst
->objfile
;
1285 bfd
*abfd
= objfile
->obfd
;
1286 struct comp_unit_head cu_header
;
1287 struct die_info
*dies
;
1288 unsigned long offset
;
1289 CORE_ADDR lowpc
, highpc
;
1290 struct die_info
*child_die
;
1292 struct symtab
*symtab
;
1293 struct cleanup
*back_to
;
1295 /* Set local variables from the partial symbol table info. */
1296 offset
= DWARF_INFO_OFFSET (pst
);
1297 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1298 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1299 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1300 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1301 baseaddr
= ANOFFSET (pst
->section_offsets
, 0);
1302 cu_header_offset
= offset
;
1303 info_ptr
= dwarf_info_buffer
+ offset
;
1305 obstack_init (&dwarf2_tmp_obstack
);
1306 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1309 make_cleanup (really_free_pendings
, NULL
);
1311 /* read in the comp_unit header */
1312 cu_header
.length
= read_4_bytes (abfd
, info_ptr
);
1314 cu_header
.version
= read_2_bytes (abfd
, info_ptr
);
1316 cu_header
.abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
1318 cu_header
.addr_size
= read_1_byte (abfd
, info_ptr
);
1321 /* Read the abbrevs for this compilation unit */
1322 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1323 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1325 dies
= read_comp_unit (info_ptr
, abfd
);
1327 make_cleanup_free_die_list (dies
);
1329 /* Do line number decoding in read_file_scope () */
1330 process_die (dies
, objfile
);
1332 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1334 /* Some compilers don't define a DW_AT_high_pc attribute for
1335 the compilation unit. If the DW_AT_high_pc is missing,
1336 synthesize it, by scanning the DIE's below the compilation unit. */
1338 if (dies
->has_children
)
1340 child_die
= dies
->next
;
1341 while (child_die
&& child_die
->tag
)
1343 if (child_die
->tag
== DW_TAG_subprogram
)
1345 CORE_ADDR low
, high
;
1347 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1349 highpc
= max (highpc
, high
);
1352 child_die
= sibling_die (child_die
);
1356 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, 0);
1358 /* Set symtab language to language from DW_AT_language.
1359 If the compilation is from a C file generated by language preprocessors,
1360 do not set the language if it was already deduced by start_subfile. */
1362 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1364 symtab
->language
= cu_language
;
1366 pst
->symtab
= symtab
;
1368 sort_symtab_syms (pst
->symtab
);
1370 do_cleanups (back_to
);
1373 /* Process a die and its children. */
1376 process_die (die
, objfile
)
1377 struct die_info
*die
;
1378 struct objfile
*objfile
;
1382 case DW_TAG_padding
:
1384 case DW_TAG_compile_unit
:
1385 read_file_scope (die
, objfile
);
1387 case DW_TAG_subprogram
:
1388 read_subroutine_type (die
, objfile
);
1389 read_func_scope (die
, objfile
);
1391 case DW_TAG_inlined_subroutine
:
1392 /* FIXME: These are ignored for now.
1393 They could be used to set breakpoints on all inlined instances
1394 of a function and make GDB `next' properly over inlined functions. */
1396 case DW_TAG_lexical_block
:
1397 read_lexical_block_scope (die
, objfile
);
1399 case DW_TAG_class_type
:
1400 case DW_TAG_structure_type
:
1401 case DW_TAG_union_type
:
1402 read_structure_scope (die
, objfile
);
1404 case DW_TAG_enumeration_type
:
1405 read_enumeration (die
, objfile
);
1407 case DW_TAG_subroutine_type
:
1408 read_subroutine_type (die
, objfile
);
1410 case DW_TAG_array_type
:
1411 read_array_type (die
, objfile
);
1413 case DW_TAG_pointer_type
:
1414 read_tag_pointer_type (die
, objfile
);
1416 case DW_TAG_ptr_to_member_type
:
1417 read_tag_ptr_to_member_type (die
, objfile
);
1419 case DW_TAG_reference_type
:
1420 read_tag_reference_type (die
, objfile
);
1422 case DW_TAG_string_type
:
1423 read_tag_string_type (die
, objfile
);
1425 case DW_TAG_base_type
:
1426 read_base_type (die
, objfile
);
1427 if (dwarf_attr (die
, DW_AT_name
))
1429 /* Add a typedef symbol for the base type definition. */
1430 new_symbol (die
, die
->type
, objfile
);
1433 case DW_TAG_common_block
:
1434 read_common_block (die
, objfile
);
1436 case DW_TAG_common_inclusion
:
1439 new_symbol (die
, NULL
, objfile
);
1445 read_file_scope (die
, objfile
)
1446 struct die_info
*die
;
1447 struct objfile
*objfile
;
1449 unsigned int line_offset
= 0;
1450 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1451 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1452 struct attribute
*attr
;
1453 char *name
= "<unknown>";
1454 char *comp_dir
= NULL
;
1455 struct die_info
*child_die
;
1456 bfd
*abfd
= objfile
->obfd
;
1458 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1460 if (die
->has_children
)
1462 child_die
= die
->next
;
1463 while (child_die
&& child_die
->tag
)
1465 if (child_die
->tag
== DW_TAG_subprogram
)
1467 CORE_ADDR low
, high
;
1469 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1471 lowpc
= min (lowpc
, low
);
1472 highpc
= max (highpc
, high
);
1475 child_die
= sibling_die (child_die
);
1480 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1481 from finish_block. */
1482 if (lowpc
== ((CORE_ADDR
) -1))
1487 attr
= dwarf_attr (die
, DW_AT_name
);
1490 name
= DW_STRING (attr
);
1492 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1495 comp_dir
= DW_STRING (attr
);
1498 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1499 directory, get rid of it. */
1500 char *cp
= strchr (comp_dir
, ':');
1502 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1507 if (objfile
->ei
.entry_point
>= lowpc
&&
1508 objfile
->ei
.entry_point
< highpc
)
1510 objfile
->ei
.entry_file_lowpc
= lowpc
;
1511 objfile
->ei
.entry_file_highpc
= highpc
;
1514 attr
= dwarf_attr (die
, DW_AT_language
);
1517 set_cu_language (DW_UNSND (attr
));
1520 /* We assume that we're processing GCC output. */
1521 processing_gcc_compilation
= 2;
1523 /* FIXME:Do something here. */
1524 if (dip
->at_producer
!= NULL
)
1526 handle_producer (dip
->at_producer
);
1530 /* The compilation unit may be in a different language or objfile,
1531 zero out all remembered fundamental types. */
1532 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1534 start_symtab (name
, comp_dir
, lowpc
);
1535 record_debugformat ("DWARF 2");
1537 /* Decode line number information if present. */
1538 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1541 line_offset
= DW_UNSND (attr
);
1542 dwarf_decode_lines (line_offset
, comp_dir
, abfd
);
1545 /* Process all dies in compilation unit. */
1546 if (die
->has_children
)
1548 child_die
= die
->next
;
1549 while (child_die
&& child_die
->tag
)
1551 process_die (child_die
, objfile
);
1552 child_die
= sibling_die (child_die
);
1558 read_func_scope (die
, objfile
)
1559 struct die_info
*die
;
1560 struct objfile
*objfile
;
1562 register struct context_stack
*new;
1565 struct die_info
*child_die
;
1566 struct attribute
*attr
;
1569 name
= dwarf2_linkage_name (die
);
1571 /* Ignore functions with missing or empty names and functions with
1572 missing or invalid low and high pc attributes. */
1573 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1579 if (objfile
->ei
.entry_point
>= lowpc
&&
1580 objfile
->ei
.entry_point
< highpc
)
1582 objfile
->ei
.entry_func_lowpc
= lowpc
;
1583 objfile
->ei
.entry_func_highpc
= highpc
;
1586 /* Decode DW_AT_frame_base location descriptor if present, keep result
1587 for DW_OP_fbreg operands in decode_locdesc. */
1588 frame_base_reg
= -1;
1589 frame_base_offset
= 0;
1590 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1593 CORE_ADDR addr
= decode_locdesc (DW_BLOCK (attr
), objfile
);
1595 complain (&dwarf2_unsupported_at_frame_base
, name
);
1597 frame_base_reg
= addr
;
1600 frame_base_reg
= basereg
;
1601 frame_base_offset
= addr
;
1604 complain (&dwarf2_unsupported_at_frame_base
, name
);
1607 new = push_context (0, lowpc
);
1608 new->name
= new_symbol (die
, die
->type
, objfile
);
1609 list_in_scope
= &local_symbols
;
1611 if (die
->has_children
)
1613 child_die
= die
->next
;
1614 while (child_die
&& child_die
->tag
)
1616 process_die (child_die
, objfile
);
1617 child_die
= sibling_die (child_die
);
1621 new = pop_context ();
1622 /* Make a block for the local symbols within. */
1623 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1624 lowpc
, highpc
, objfile
);
1625 list_in_scope
= &file_symbols
;
1628 /* Process all the DIES contained within a lexical block scope. Start
1629 a new scope, process the dies, and then close the scope. */
1632 read_lexical_block_scope (die
, objfile
)
1633 struct die_info
*die
;
1634 struct objfile
*objfile
;
1636 register struct context_stack
*new;
1637 CORE_ADDR lowpc
, highpc
;
1638 struct die_info
*child_die
;
1640 /* Ignore blocks with missing or invalid low and high pc attributes. */
1641 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1646 push_context (0, lowpc
);
1647 if (die
->has_children
)
1649 child_die
= die
->next
;
1650 while (child_die
&& child_die
->tag
)
1652 process_die (child_die
, objfile
);
1653 child_die
= sibling_die (child_die
);
1656 new = pop_context ();
1658 if (local_symbols
!= NULL
)
1660 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1663 local_symbols
= new->locals
;
1666 /* Get low and high pc attributes from a die.
1667 Return 1 if the attributes are present and valid, otherwise, return 0. */
1670 dwarf2_get_pc_bounds (die
, lowpc
, highpc
, objfile
)
1671 struct die_info
*die
;
1674 struct objfile
*objfile
;
1676 struct attribute
*attr
;
1680 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1682 low
= DW_ADDR (attr
);
1685 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1687 high
= DW_ADDR (attr
);
1694 /* When using the GNU linker, .gnu.linkonce. sections are used to
1695 eliminate duplicate copies of functions and vtables and such.
1696 The linker will arbitrarily choose one and discard the others.
1697 The AT_*_pc values for such functions refer to local labels in
1698 these sections. If the section from that file was discarded, the
1699 labels are not in the output, so the relocs get a value of 0.
1700 If this is a discarded function, mark the pc bounds as invalid,
1701 so that GDB will ignore it. */
1702 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
1710 /* Add an aggregate field to the field list. */
1713 dwarf2_add_field (fip
, die
, objfile
)
1714 struct field_info
*fip
;
1715 struct die_info
*die
;
1716 struct objfile
*objfile
;
1718 struct nextfield
*new_field
;
1719 struct attribute
*attr
;
1721 char *fieldname
= "";
1723 /* Allocate a new field list entry and link it in. */
1724 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1725 make_cleanup (free
, new_field
);
1726 memset (new_field
, 0, sizeof (struct nextfield
));
1727 new_field
->next
= fip
->fields
;
1728 fip
->fields
= new_field
;
1731 /* Handle accessibility and virtuality of field.
1732 The default accessibility for members is public, the default
1733 accessibility for inheritance is private. */
1734 if (die
->tag
!= DW_TAG_inheritance
)
1735 new_field
->accessibility
= DW_ACCESS_public
;
1737 new_field
->accessibility
= DW_ACCESS_private
;
1738 new_field
->virtuality
= DW_VIRTUALITY_none
;
1740 attr
= dwarf_attr (die
, DW_AT_accessibility
);
1742 new_field
->accessibility
= DW_UNSND (attr
);
1743 if (new_field
->accessibility
!= DW_ACCESS_public
)
1744 fip
->non_public_fields
= 1;
1745 attr
= dwarf_attr (die
, DW_AT_virtuality
);
1747 new_field
->virtuality
= DW_UNSND (attr
);
1749 fp
= &new_field
->field
;
1750 if (die
->tag
== DW_TAG_member
)
1752 /* Get type of field. */
1753 fp
->type
= die_type (die
, objfile
);
1755 /* Get bit size of field (zero if none). */
1756 attr
= dwarf_attr (die
, DW_AT_bit_size
);
1759 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
1763 FIELD_BITSIZE (*fp
) = 0;
1766 /* Get bit offset of field. */
1767 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1770 FIELD_BITPOS (*fp
) =
1771 decode_locdesc (DW_BLOCK (attr
), objfile
) * bits_per_byte
;
1774 FIELD_BITPOS (*fp
) = 0;
1775 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
1778 if (BITS_BIG_ENDIAN
)
1780 /* For big endian bits, the DW_AT_bit_offset gives the
1781 additional bit offset from the MSB of the containing
1782 anonymous object to the MSB of the field. We don't
1783 have to do anything special since we don't need to
1784 know the size of the anonymous object. */
1785 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
1789 /* For little endian bits, compute the bit offset to the
1790 MSB of the anonymous object, subtract off the number of
1791 bits from the MSB of the field to the MSB of the
1792 object, and then subtract off the number of bits of
1793 the field itself. The result is the bit offset of
1794 the LSB of the field. */
1796 int bit_offset
= DW_UNSND (attr
);
1798 attr
= dwarf_attr (die
, DW_AT_byte_size
);
1801 /* The size of the anonymous object containing
1802 the bit field is explicit, so use the
1803 indicated size (in bytes). */
1804 anonymous_size
= DW_UNSND (attr
);
1808 /* The size of the anonymous object containing
1809 the bit field must be inferred from the type
1810 attribute of the data member containing the
1812 anonymous_size
= TYPE_LENGTH (fp
->type
);
1814 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
1815 - bit_offset
- FIELD_BITSIZE (*fp
);
1819 /* Get name of field. */
1820 attr
= dwarf_attr (die
, DW_AT_name
);
1821 if (attr
&& DW_STRING (attr
))
1822 fieldname
= DW_STRING (attr
);
1823 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
1824 &objfile
->type_obstack
);
1826 /* Change accessibility for artificial fields (e.g. virtual table
1827 pointer or virtual base class pointer) to private. */
1828 if (dwarf_attr (die
, DW_AT_artificial
))
1830 new_field
->accessibility
= DW_ACCESS_private
;
1831 fip
->non_public_fields
= 1;
1834 else if (die
->tag
== DW_TAG_variable
)
1838 /* C++ static member.
1839 Get name of field. */
1840 attr
= dwarf_attr (die
, DW_AT_name
);
1841 if (attr
&& DW_STRING (attr
))
1842 fieldname
= DW_STRING (attr
);
1846 /* Get physical name. */
1847 physname
= dwarf2_linkage_name (die
);
1849 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
1850 &objfile
->type_obstack
));
1851 FIELD_TYPE (*fp
) = die_type (die
, objfile
);
1852 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
1853 &objfile
->type_obstack
);
1855 else if (die
->tag
== DW_TAG_inheritance
)
1857 /* C++ base class field. */
1858 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1860 FIELD_BITPOS (*fp
) = decode_locdesc (DW_BLOCK (attr
), objfile
) * bits_per_byte
;
1861 FIELD_BITSIZE (*fp
) = 0;
1862 FIELD_TYPE (*fp
) = die_type (die
, objfile
);
1863 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
1864 fip
->nbaseclasses
++;
1868 /* Create the vector of fields, and attach it to the type. */
1871 dwarf2_attach_fields_to_type (fip
, type
, objfile
)
1872 struct field_info
*fip
;
1874 struct objfile
*objfile
;
1876 int nfields
= fip
->nfields
;
1878 /* Record the field count, allocate space for the array of fields,
1879 and create blank accessibility bitfields if necessary. */
1880 TYPE_NFIELDS (type
) = nfields
;
1881 TYPE_FIELDS (type
) = (struct field
*)
1882 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
1883 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
1885 if (fip
->non_public_fields
)
1887 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1889 TYPE_FIELD_PRIVATE_BITS (type
) =
1890 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1891 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
1893 TYPE_FIELD_PROTECTED_BITS (type
) =
1894 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1895 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
1897 TYPE_FIELD_IGNORE_BITS (type
) =
1898 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1899 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
1902 /* If the type has baseclasses, allocate and clear a bit vector for
1903 TYPE_FIELD_VIRTUAL_BITS. */
1904 if (fip
->nbaseclasses
)
1906 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
1909 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1910 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
1911 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
1912 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
1913 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
1916 /* Copy the saved-up fields into the field vector. Start from the head
1917 of the list, adding to the tail of the field array, so that they end
1918 up in the same order in the array in which they were added to the list. */
1919 while (nfields
-- > 0)
1921 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
1922 switch (fip
->fields
->accessibility
)
1924 case DW_ACCESS_private
:
1925 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
1928 case DW_ACCESS_protected
:
1929 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
1932 case DW_ACCESS_public
:
1936 /* Unknown accessibility. Complain and treat it as public. */
1938 complain (&dwarf2_unsupported_accessibility
,
1939 fip
->fields
->accessibility
);
1943 if (nfields
< fip
->nbaseclasses
)
1945 switch (fip
->fields
->virtuality
)
1947 case DW_VIRTUALITY_virtual
:
1948 case DW_VIRTUALITY_pure_virtual
:
1949 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
1953 fip
->fields
= fip
->fields
->next
;
1957 /* Add a member function to the proper fieldlist. */
1960 dwarf2_add_member_fn (fip
, die
, type
, objfile
)
1961 struct field_info
*fip
;
1962 struct die_info
*die
;
1964 struct objfile
*objfile
;
1966 struct attribute
*attr
;
1967 struct fnfieldlist
*flp
;
1969 struct fn_field
*fnp
;
1972 struct nextfnfield
*new_fnfield
;
1974 /* Get name of member function. */
1975 attr
= dwarf_attr (die
, DW_AT_name
);
1976 if (attr
&& DW_STRING (attr
))
1977 fieldname
= DW_STRING (attr
);
1981 /* Get the mangled name. */
1982 physname
= dwarf2_linkage_name (die
);
1984 /* Look up member function name in fieldlist. */
1985 for (i
= 0; i
< fip
->nfnfields
; i
++)
1987 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
1991 /* Create new list element if necessary. */
1992 if (i
< fip
->nfnfields
)
1993 flp
= &fip
->fnfieldlists
[i
];
1996 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
1998 fip
->fnfieldlists
= (struct fnfieldlist
*)
1999 xrealloc (fip
->fnfieldlists
,
2000 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2001 * sizeof (struct fnfieldlist
));
2002 if (fip
->nfnfields
== 0)
2003 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2005 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2006 flp
->name
= fieldname
;
2012 /* Create a new member function field and chain it to the field list
2014 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2015 make_cleanup (free
, new_fnfield
);
2016 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2017 new_fnfield
->next
= flp
->head
;
2018 flp
->head
= new_fnfield
;
2021 /* Fill in the member function field info. */
2022 fnp
= &new_fnfield
->fnfield
;
2023 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2024 &objfile
->type_obstack
);
2025 fnp
->type
= alloc_type (objfile
);
2026 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2028 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2029 struct type
**arg_types
;
2030 int nparams
= TYPE_NFIELDS (die
->type
);
2033 /* Copy argument types from the subroutine type. */
2034 arg_types
= (struct type
**)
2035 TYPE_ALLOC (fnp
->type
, (nparams
+ 1) * sizeof (struct type
*));
2036 for (iparams
= 0; iparams
< nparams
; iparams
++)
2037 arg_types
[iparams
] = TYPE_FIELD_TYPE (die
->type
, iparams
);
2039 /* Set last entry in argument type vector. */
2040 if (TYPE_FLAGS (die
->type
) & TYPE_FLAG_VARARGS
)
2041 arg_types
[nparams
] = NULL
;
2043 arg_types
[nparams
] = dwarf2_fundamental_type (objfile
, FT_VOID
);
2045 smash_to_method_type (fnp
->type
, type
, return_type
, arg_types
);
2047 /* Handle static member functions.
2048 Dwarf2 has no clean way to discern C++ static and non-static
2049 member functions. G++ helps GDB by marking the first
2050 parameter for non-static member functions (which is the
2051 this pointer) as artificial. We obtain this information
2052 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2053 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2054 fnp
->voffset
= VOFFSET_STATIC
;
2057 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2059 /* Get fcontext from DW_AT_containing_type if present. */
2060 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2061 fnp
->fcontext
= die_containing_type (die
, objfile
);
2063 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2064 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2066 /* Get accessibility. */
2067 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2070 switch (DW_UNSND (attr
))
2072 case DW_ACCESS_private
:
2073 fnp
->is_private
= 1;
2075 case DW_ACCESS_protected
:
2076 fnp
->is_protected
= 1;
2081 /* Get index in virtual function table if it is a virtual member function. */
2082 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2084 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
) + 2;
2087 /* Create the vector of member function fields, and attach it to the type. */
2090 dwarf2_attach_fn_fields_to_type (fip
, type
, objfile
)
2091 struct field_info
*fip
;
2093 struct objfile
*objfile
;
2095 struct fnfieldlist
*flp
;
2096 int total_length
= 0;
2099 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2100 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2101 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2103 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2105 struct nextfnfield
*nfp
= flp
->head
;
2106 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2109 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2110 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2111 fn_flp
->fn_fields
= (struct fn_field
*)
2112 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2113 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2114 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2116 total_length
+= flp
->length
;
2119 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2120 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2123 /* Called when we find the DIE that starts a structure or union scope
2124 (definition) to process all dies that define the members of the
2127 NOTE: we need to call struct_type regardless of whether or not the
2128 DIE has an at_name attribute, since it might be an anonymous
2129 structure or union. This gets the type entered into our set of
2132 However, if the structure is incomplete (an opaque struct/union)
2133 then suppress creating a symbol table entry for it since gdb only
2134 wants to find the one with the complete definition. Note that if
2135 it is complete, we just call new_symbol, which does it's own
2136 checking about whether the struct/union is anonymous or not (and
2137 suppresses creating a symbol table entry itself). */
2140 read_structure_scope (die
, objfile
)
2141 struct die_info
*die
;
2142 struct objfile
*objfile
;
2145 struct attribute
*attr
;
2147 type
= alloc_type (objfile
);
2149 INIT_CPLUS_SPECIFIC (type
);
2150 attr
= dwarf_attr (die
, DW_AT_name
);
2151 if (attr
&& DW_STRING (attr
))
2153 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2154 strlen (DW_STRING (attr
)),
2155 &objfile
->type_obstack
);
2158 if (die
->tag
== DW_TAG_structure_type
)
2160 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2162 else if (die
->tag
== DW_TAG_union_type
)
2164 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2168 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2170 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2173 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2176 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2180 TYPE_LENGTH (type
) = 0;
2183 /* We need to add the type field to the die immediately so we don't
2184 infinitely recurse when dealing with pointers to the structure
2185 type within the structure itself. */
2188 if (die
->has_children
&& ! die_is_declaration (die
))
2190 struct field_info fi
;
2191 struct die_info
*child_die
;
2192 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2194 memset (&fi
, 0, sizeof (struct field_info
));
2196 child_die
= die
->next
;
2198 while (child_die
&& child_die
->tag
)
2200 if (child_die
->tag
== DW_TAG_member
)
2202 dwarf2_add_field (&fi
, child_die
, objfile
);
2204 else if (child_die
->tag
== DW_TAG_variable
)
2206 /* C++ static member. */
2207 dwarf2_add_field (&fi
, child_die
, objfile
);
2209 else if (child_die
->tag
== DW_TAG_subprogram
)
2211 /* C++ member function. */
2212 process_die (child_die
, objfile
);
2213 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
);
2215 else if (child_die
->tag
== DW_TAG_inheritance
)
2217 /* C++ base class field. */
2218 dwarf2_add_field (&fi
, child_die
, objfile
);
2222 process_die (child_die
, objfile
);
2224 child_die
= sibling_die (child_die
);
2227 /* Attach fields and member functions to the type. */
2229 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2232 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2234 /* Get the type which refers to the base class (possibly this
2235 class itself) which contains the vtable pointer for the current
2236 class from the DW_AT_containing_type attribute. */
2238 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2240 struct type
*t
= die_containing_type (die
, objfile
);
2242 TYPE_VPTR_BASETYPE (type
) = t
;
2245 static const char vptr_name
[] =
2246 {'_', 'v', 'p', 't', 'r', '\0'};
2249 /* Our own class provides vtbl ptr. */
2250 for (i
= TYPE_NFIELDS (t
) - 1;
2251 i
>= TYPE_N_BASECLASSES (t
);
2254 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2256 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2257 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2259 TYPE_VPTR_FIELDNO (type
) = i
;
2264 /* Complain if virtual function table field not found. */
2265 if (i
< TYPE_N_BASECLASSES (t
))
2266 complain (&dwarf2_vtbl_not_found_complaint
,
2267 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2271 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2276 new_symbol (die
, type
, objfile
);
2278 do_cleanups (back_to
);
2282 /* No children, must be stub. */
2283 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2289 /* Given a pointer to a die which begins an enumeration, process all
2290 the dies that define the members of the enumeration.
2292 This will be much nicer in draft 6 of the DWARF spec when our
2293 members will be dies instead squished into the DW_AT_element_list
2296 NOTE: We reverse the order of the element list. */
2299 read_enumeration (die
, objfile
)
2300 struct die_info
*die
;
2301 struct objfile
*objfile
;
2303 struct die_info
*child_die
;
2305 struct field
*fields
;
2306 struct attribute
*attr
;
2309 int unsigned_enum
= 1;
2311 type
= alloc_type (objfile
);
2313 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2314 attr
= dwarf_attr (die
, DW_AT_name
);
2315 if (attr
&& DW_STRING (attr
))
2317 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2318 strlen (DW_STRING (attr
)),
2319 &objfile
->type_obstack
);
2322 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2325 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2329 TYPE_LENGTH (type
) = 0;
2334 if (die
->has_children
)
2336 child_die
= die
->next
;
2337 while (child_die
&& child_die
->tag
)
2339 if (child_die
->tag
!= DW_TAG_enumerator
)
2341 process_die (child_die
, objfile
);
2345 attr
= dwarf_attr (child_die
, DW_AT_name
);
2348 sym
= new_symbol (child_die
, type
, objfile
);
2349 if (SYMBOL_VALUE (sym
) < 0)
2352 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2354 fields
= (struct field
*)
2356 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2357 * sizeof (struct field
));
2360 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2361 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2362 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2363 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2369 child_die
= sibling_die (child_die
);
2374 TYPE_NFIELDS (type
) = num_fields
;
2375 TYPE_FIELDS (type
) = (struct field
*)
2376 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2377 memcpy (TYPE_FIELDS (type
), fields
,
2378 sizeof (struct field
) * num_fields
);
2382 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2385 new_symbol (die
, type
, objfile
);
2388 /* Extract all information from a DW_TAG_array_type DIE and put it in
2389 the DIE's type field. For now, this only handles one dimensional
2393 read_array_type (die
, objfile
)
2394 struct die_info
*die
;
2395 struct objfile
*objfile
;
2397 struct die_info
*child_die
;
2398 struct type
*type
= NULL
;
2399 struct type
*element_type
, *range_type
, *index_type
;
2400 struct type
**range_types
= NULL
;
2401 struct attribute
*attr
;
2403 struct cleanup
*back_to
;
2405 /* Return if we've already decoded this type. */
2411 element_type
= die_type (die
, objfile
);
2413 /* Irix 6.2 native cc creates array types without children for
2414 arrays with unspecified length. */
2415 if (die
->has_children
== 0)
2417 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2418 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2419 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2423 back_to
= make_cleanup (null_cleanup
, NULL
);
2424 child_die
= die
->next
;
2425 while (child_die
&& child_die
->tag
)
2427 if (child_die
->tag
== DW_TAG_subrange_type
)
2429 unsigned int low
, high
;
2431 /* Default bounds to an array with unspecified length. */
2434 if (cu_language
== language_fortran
)
2436 /* FORTRAN implies a lower bound of 1, if not given. */
2440 index_type
= die_type (child_die
, objfile
);
2441 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2444 if (attr
->form
== DW_FORM_sdata
)
2446 low
= DW_SND (attr
);
2448 else if (attr
->form
== DW_FORM_udata
2449 || attr
->form
== DW_FORM_data1
2450 || attr
->form
== DW_FORM_data2
2451 || attr
->form
== DW_FORM_data4
)
2453 low
= DW_UNSND (attr
);
2457 complain (&dwarf2_non_const_array_bound_ignored
,
2458 dwarf_form_name (attr
->form
));
2460 die
->type
= lookup_pointer_type (element_type
);
2467 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2470 if (attr
->form
== DW_FORM_sdata
)
2472 high
= DW_SND (attr
);
2474 else if (attr
->form
== DW_FORM_udata
2475 || attr
->form
== DW_FORM_data1
2476 || attr
->form
== DW_FORM_data2
2477 || attr
->form
== DW_FORM_data4
)
2479 high
= DW_UNSND (attr
);
2481 else if (attr
->form
== DW_FORM_block1
)
2483 /* GCC encodes arrays with unspecified or dynamic length
2484 with a DW_FORM_block1 attribute.
2485 FIXME: GDB does not yet know how to handle dynamic
2486 arrays properly, treat them as arrays with unspecified
2492 complain (&dwarf2_non_const_array_bound_ignored
,
2493 dwarf_form_name (attr
->form
));
2495 die
->type
= lookup_pointer_type (element_type
);
2503 /* Create a range type and save it for array type creation. */
2504 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2506 range_types
= (struct type
**)
2507 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2508 * sizeof (struct type
*));
2510 make_cleanup (free_current_contents
, &range_types
);
2512 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2514 child_die
= sibling_die (child_die
);
2517 /* Dwarf2 dimensions are output from left to right, create the
2518 necessary array types in backwards order. */
2519 type
= element_type
;
2521 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2523 do_cleanups (back_to
);
2525 /* Install the type in the die. */
2529 /* First cut: install each common block member as a global variable. */
2532 read_common_block (die
, objfile
)
2533 struct die_info
*die
;
2534 struct objfile
*objfile
;
2536 struct die_info
*child_die
;
2537 struct attribute
*attr
;
2539 CORE_ADDR base
= (CORE_ADDR
) 0;
2541 attr
= dwarf_attr (die
, DW_AT_location
);
2544 base
= decode_locdesc (DW_BLOCK (attr
), objfile
);
2546 if (die
->has_children
)
2548 child_die
= die
->next
;
2549 while (child_die
&& child_die
->tag
)
2551 sym
= new_symbol (child_die
, NULL
, objfile
);
2552 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2555 SYMBOL_VALUE_ADDRESS (sym
) =
2556 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
);
2557 add_symbol_to_list (sym
, &global_symbols
);
2559 child_die
= sibling_die (child_die
);
2564 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2565 the user defined type vector. */
2568 read_tag_pointer_type (die
, objfile
)
2569 struct die_info
*die
;
2570 struct objfile
*objfile
;
2573 struct attribute
*attr
;
2580 type
= lookup_pointer_type (die_type (die
, objfile
));
2581 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2584 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2588 TYPE_LENGTH (type
) = address_size
;
2593 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2594 the user defined type vector. */
2597 read_tag_ptr_to_member_type (die
, objfile
)
2598 struct die_info
*die
;
2599 struct objfile
*objfile
;
2602 struct type
*to_type
;
2603 struct type
*domain
;
2610 type
= alloc_type (objfile
);
2611 to_type
= die_type (die
, objfile
);
2612 domain
= die_containing_type (die
, objfile
);
2613 smash_to_member_type (type
, domain
, to_type
);
2618 /* Extract all information from a DW_TAG_reference_type DIE and add to
2619 the user defined type vector. */
2622 read_tag_reference_type (die
, objfile
)
2623 struct die_info
*die
;
2624 struct objfile
*objfile
;
2627 struct attribute
*attr
;
2634 type
= lookup_reference_type (die_type (die
, objfile
));
2635 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2638 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2642 TYPE_LENGTH (type
) = address_size
;
2648 read_tag_const_type (die
, objfile
)
2649 struct die_info
*die
;
2650 struct objfile
*objfile
;
2657 complain (&dwarf2_const_ignored
);
2658 die
->type
= die_type (die
, objfile
);
2662 read_tag_volatile_type (die
, objfile
)
2663 struct die_info
*die
;
2664 struct objfile
*objfile
;
2671 complain (&dwarf2_volatile_ignored
);
2672 die
->type
= die_type (die
, objfile
);
2675 /* Extract all information from a DW_TAG_string_type DIE and add to
2676 the user defined type vector. It isn't really a user defined type,
2677 but it behaves like one, with other DIE's using an AT_user_def_type
2678 attribute to reference it. */
2681 read_tag_string_type (die
, objfile
)
2682 struct die_info
*die
;
2683 struct objfile
*objfile
;
2685 struct type
*type
, *range_type
, *index_type
, *char_type
;
2686 struct attribute
*attr
;
2687 unsigned int length
;
2694 attr
= dwarf_attr (die
, DW_AT_string_length
);
2697 length
= DW_UNSND (attr
);
2703 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2704 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2705 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2706 type
= create_string_type (char_type
, range_type
);
2710 /* Handle DIES due to C code like:
2714 int (*funcp)(int a, long l);
2718 ('funcp' generates a DW_TAG_subroutine_type DIE)
2722 read_subroutine_type (die
, objfile
)
2723 struct die_info
*die
;
2724 struct objfile
*objfile
;
2726 struct type
*type
; /* Type that this function returns */
2727 struct type
*ftype
; /* Function that returns above type */
2728 struct attribute
*attr
;
2730 /* Decode the type that this subroutine returns */
2735 type
= die_type (die
, objfile
);
2736 ftype
= lookup_function_type (type
);
2738 /* All functions in C++ have prototypes. */
2739 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2740 if ((attr
&& (DW_UNSND (attr
) != 0))
2741 || cu_language
== language_cplus
)
2742 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2744 if (die
->has_children
)
2746 struct die_info
*child_die
;
2750 /* Count the number of parameters.
2751 FIXME: GDB currently ignores vararg functions, but knows about
2752 vararg member functions. */
2753 child_die
= die
->next
;
2754 while (child_die
&& child_die
->tag
)
2756 if (child_die
->tag
== DW_TAG_formal_parameter
)
2758 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2759 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2760 child_die
= sibling_die (child_die
);
2763 /* Allocate storage for parameters and fill them in. */
2764 TYPE_NFIELDS (ftype
) = nparams
;
2765 TYPE_FIELDS (ftype
) = (struct field
*)
2766 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2768 child_die
= die
->next
;
2769 while (child_die
&& child_die
->tag
)
2771 if (child_die
->tag
== DW_TAG_formal_parameter
)
2773 /* Dwarf2 has no clean way to discern C++ static and non-static
2774 member functions. G++ helps GDB by marking the first
2775 parameter for non-static member functions (which is the
2776 this pointer) as artificial. We pass this information
2777 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2778 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
2780 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
2782 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
2783 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
);
2786 child_die
= sibling_die (child_die
);
2794 read_typedef (die
, objfile
)
2795 struct die_info
*die
;
2796 struct objfile
*objfile
;
2802 struct attribute
*attr
;
2805 xtype
= die_type (die
, objfile
);
2807 type
= alloc_type (objfile
);
2808 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2809 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2810 TYPE_TARGET_TYPE (type
) = xtype
;
2811 attr
= dwarf_attr (die
, DW_AT_name
);
2812 if (attr
&& DW_STRING (attr
))
2813 TYPE_NAME (type
) = obsavestring (DW_STRING (attr
),
2814 strlen (DW_STRING (attr
)),
2815 &objfile
->type_obstack
);
2821 /* Find a representation of a given base type and install
2822 it in the TYPE field of the die. */
2825 read_base_type (die
, objfile
)
2826 struct die_info
*die
;
2827 struct objfile
*objfile
;
2830 struct attribute
*attr
;
2831 int encoding
= 0, size
= 0;
2833 /* If we've already decoded this die, this is a no-op. */
2839 attr
= dwarf_attr (die
, DW_AT_encoding
);
2842 encoding
= DW_UNSND (attr
);
2844 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2847 size
= DW_UNSND (attr
);
2849 attr
= dwarf_attr (die
, DW_AT_name
);
2850 if (attr
&& DW_STRING (attr
))
2852 enum type_code code
= TYPE_CODE_INT
;
2853 int is_unsigned
= 0;
2857 case DW_ATE_address
:
2858 /* Turn DW_ATE_address into a void * pointer. */
2859 code
= TYPE_CODE_PTR
;
2862 case DW_ATE_boolean
:
2863 code
= TYPE_CODE_BOOL
;
2866 case DW_ATE_complex_float
:
2867 code
= TYPE_CODE_COMPLEX
;
2870 code
= TYPE_CODE_FLT
;
2873 case DW_ATE_signed_char
:
2875 case DW_ATE_unsigned
:
2876 case DW_ATE_unsigned_char
:
2880 complain (&dwarf2_unsupported_at_encoding
,
2881 dwarf_type_encoding_name (encoding
));
2884 type
= init_type (code
, size
, is_unsigned
, DW_STRING (attr
), objfile
);
2885 if (encoding
== DW_ATE_address
)
2886 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
2890 type
= dwarf_base_type (encoding
, size
, objfile
);
2895 /* Read a whole compilation unit into a linked list of dies. */
2898 read_comp_unit (info_ptr
, abfd
)
2902 struct die_info
*first_die
, *last_die
, *die
;
2906 /* Reset die reference table, we are building a new one now. */
2907 dwarf2_empty_die_ref_table ();
2911 first_die
= last_die
= NULL
;
2914 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
);
2915 if (die
->has_children
)
2926 /* Enter die in reference hash table */
2927 store_in_ref_table (die
->offset
, die
);
2931 first_die
= last_die
= die
;
2935 last_die
->next
= die
;
2939 while (nesting_level
> 0);
2943 /* Free a linked list of dies. */
2946 free_die_list (dies
)
2947 struct die_info
*dies
;
2949 struct die_info
*die
, *next
;
2962 do_free_die_list_cleanup (void *dies
)
2964 free_die_list (dies
);
2967 static struct cleanup
*
2968 make_cleanup_free_die_list (struct die_info
*dies
)
2970 return make_cleanup (do_free_die_list_cleanup
, dies
);
2974 /* Read the contents of the section at OFFSET and of size SIZE from the
2975 object file specified by OBJFILE into the psymbol_obstack and return it. */
2978 dwarf2_read_section (objfile
, offset
, size
)
2979 struct objfile
*objfile
;
2983 bfd
*abfd
= objfile
->obfd
;
2989 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
2990 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
2991 (bfd_read (buf
, size
, 1, abfd
) != size
))
2994 error ("Dwarf Error: Can't read DWARF data from '%s'",
2995 bfd_get_filename (abfd
));
3000 /* In DWARF version 2, the description of the debugging information is
3001 stored in a separate .debug_abbrev section. Before we read any
3002 dies from a section we read in all abbreviations and install them
3006 dwarf2_read_abbrevs (abfd
, offset
)
3008 unsigned int offset
;
3011 struct abbrev_info
*cur_abbrev
;
3012 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3013 unsigned int abbrev_form
, hash_number
;
3015 /* empty the table */
3016 dwarf2_empty_abbrev_table (NULL
);
3018 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3019 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3020 abbrev_ptr
+= bytes_read
;
3022 /* loop until we reach an abbrev number of 0 */
3023 while (abbrev_number
)
3025 cur_abbrev
= dwarf_alloc_abbrev ();
3027 /* read in abbrev header */
3028 cur_abbrev
->number
= abbrev_number
;
3029 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3030 abbrev_ptr
+= bytes_read
;
3031 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3034 /* now read in declarations */
3035 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3036 abbrev_ptr
+= bytes_read
;
3037 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3038 abbrev_ptr
+= bytes_read
;
3041 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3043 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3044 xrealloc (cur_abbrev
->attrs
,
3045 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3046 * sizeof (struct attr_abbrev
));
3048 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3049 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3050 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3051 abbrev_ptr
+= bytes_read
;
3052 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3053 abbrev_ptr
+= bytes_read
;
3056 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3057 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3058 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3060 /* Get next abbreviation.
3061 Under Irix6 the abbreviations for a compilation unit are not
3062 always properly terminated with an abbrev number of 0.
3063 Exit loop if we encounter an abbreviation which we have
3064 already read (which means we are about to read the abbreviations
3065 for the next compile unit) or if the end of the abbreviation
3066 table is reached. */
3067 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3068 >= dwarf_abbrev_size
)
3070 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3071 abbrev_ptr
+= bytes_read
;
3072 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3077 /* Empty the abbrev table for a new compilation unit. */
3081 dwarf2_empty_abbrev_table (ignore
)
3085 struct abbrev_info
*abbrev
, *next
;
3087 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3090 abbrev
= dwarf2_abbrevs
[i
];
3093 next
= abbrev
->next
;
3094 free (abbrev
->attrs
);
3098 dwarf2_abbrevs
[i
] = NULL
;
3102 /* Lookup an abbrev_info structure in the abbrev hash table. */
3104 static struct abbrev_info
*
3105 dwarf2_lookup_abbrev (number
)
3106 unsigned int number
;
3108 unsigned int hash_number
;
3109 struct abbrev_info
*abbrev
;
3111 hash_number
= number
% ABBREV_HASH_SIZE
;
3112 abbrev
= dwarf2_abbrevs
[hash_number
];
3116 if (abbrev
->number
== number
)
3119 abbrev
= abbrev
->next
;
3124 /* Read a minimal amount of information into the minimal die structure. */
3127 read_partial_die (part_die
, abfd
, info_ptr
, has_pc_info
)
3128 struct partial_die_info
*part_die
;
3133 unsigned int abbrev_number
, bytes_read
, i
;
3134 struct abbrev_info
*abbrev
;
3135 struct attribute attr
;
3136 struct attribute spec_attr
;
3137 int found_spec_attr
= 0;
3138 int has_low_pc_attr
= 0;
3139 int has_high_pc_attr
= 0;
3141 *part_die
= zeroed_partial_die
;
3143 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3144 info_ptr
+= bytes_read
;
3148 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3151 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3153 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3154 part_die
->tag
= abbrev
->tag
;
3155 part_die
->has_children
= abbrev
->has_children
;
3156 part_die
->abbrev
= abbrev_number
;
3158 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3160 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
);
3162 /* Store the data if it is of an attribute we want to keep in a
3163 partial symbol table. */
3168 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3169 if (part_die
->name
== NULL
)
3170 part_die
->name
= DW_STRING (&attr
);
3172 case DW_AT_MIPS_linkage_name
:
3173 part_die
->name
= DW_STRING (&attr
);
3176 has_low_pc_attr
= 1;
3177 part_die
->lowpc
= DW_ADDR (&attr
);
3180 has_high_pc_attr
= 1;
3181 part_die
->highpc
= DW_ADDR (&attr
);
3183 case DW_AT_location
:
3184 part_die
->locdesc
= DW_BLOCK (&attr
);
3186 case DW_AT_language
:
3187 part_die
->language
= DW_UNSND (&attr
);
3189 case DW_AT_external
:
3190 part_die
->is_external
= DW_UNSND (&attr
);
3192 case DW_AT_declaration
:
3193 part_die
->is_declaration
= DW_UNSND (&attr
);
3196 part_die
->has_type
= 1;
3198 case DW_AT_abstract_origin
:
3199 case DW_AT_specification
:
3200 found_spec_attr
= 1;
3204 /* Ignore absolute siblings, they might point outside of
3205 the current compile unit. */
3206 if (attr
.form
== DW_FORM_ref_addr
)
3207 complain (&dwarf2_absolute_sibling_complaint
);
3210 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3217 /* If we found a reference attribute and the die has no name, try
3218 to find a name in the referred to die. */
3220 if (found_spec_attr
&& part_die
->name
== NULL
)
3222 struct partial_die_info spec_die
;
3226 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3227 read_partial_die (&spec_die
, abfd
, spec_ptr
, &dummy
);
3230 part_die
->name
= spec_die
.name
;
3232 /* Copy DW_AT_external attribute if it is set. */
3233 if (spec_die
.is_external
)
3234 part_die
->is_external
= spec_die
.is_external
;
3238 /* When using the GNU linker, .gnu.linkonce. sections are used to
3239 eliminate duplicate copies of functions and vtables and such.
3240 The linker will arbitrarily choose one and discard the others.
3241 The AT_*_pc values for such functions refer to local labels in
3242 these sections. If the section from that file was discarded, the
3243 labels are not in the output, so the relocs get a value of 0.
3244 If this is a discarded function, mark the pc bounds as invalid,
3245 so that GDB will ignore it. */
3246 if (has_low_pc_attr
&& has_high_pc_attr
3247 && part_die
->lowpc
< part_die
->highpc
3248 && (part_die
->lowpc
!= 0
3249 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3254 /* Read the die from the .debug_info section buffer. And set diep to
3255 point to a newly allocated die with its information. */
3258 read_full_die (diep
, abfd
, info_ptr
)
3259 struct die_info
**diep
;
3263 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3264 struct abbrev_info
*abbrev
;
3265 struct die_info
*die
;
3267 offset
= info_ptr
- dwarf_info_buffer
;
3268 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3269 info_ptr
+= bytes_read
;
3272 die
= dwarf_alloc_die ();
3274 die
->abbrev
= abbrev_number
;
3280 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3283 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3285 die
= dwarf_alloc_die ();
3286 die
->offset
= offset
;
3287 die
->tag
= abbrev
->tag
;
3288 die
->has_children
= abbrev
->has_children
;
3289 die
->abbrev
= abbrev_number
;
3292 die
->num_attrs
= abbrev
->num_attrs
;
3293 die
->attrs
= (struct attribute
*)
3294 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3296 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3298 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3306 /* Read an attribute described by an abbreviated attribute. */
3309 read_attribute (attr
, abbrev
, abfd
, info_ptr
)
3310 struct attribute
*attr
;
3311 struct attr_abbrev
*abbrev
;
3315 unsigned int bytes_read
;
3316 struct dwarf_block
*blk
;
3318 attr
->name
= abbrev
->name
;
3319 attr
->form
= abbrev
->form
;
3320 switch (abbrev
->form
)
3323 case DW_FORM_ref_addr
:
3324 DW_ADDR (attr
) = read_address (abfd
, info_ptr
);
3325 info_ptr
+= address_size
;
3327 case DW_FORM_block2
:
3328 blk
= dwarf_alloc_block ();
3329 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3331 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3332 info_ptr
+= blk
->size
;
3333 DW_BLOCK (attr
) = blk
;
3335 case DW_FORM_block4
:
3336 blk
= dwarf_alloc_block ();
3337 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3339 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3340 info_ptr
+= blk
->size
;
3341 DW_BLOCK (attr
) = blk
;
3344 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3348 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3352 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3355 case DW_FORM_string
:
3356 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3357 info_ptr
+= bytes_read
;
3360 blk
= dwarf_alloc_block ();
3361 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3362 info_ptr
+= bytes_read
;
3363 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3364 info_ptr
+= blk
->size
;
3365 DW_BLOCK (attr
) = blk
;
3367 case DW_FORM_block1
:
3368 blk
= dwarf_alloc_block ();
3369 blk
->size
= read_1_byte (abfd
, info_ptr
);
3371 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3372 info_ptr
+= blk
->size
;
3373 DW_BLOCK (attr
) = blk
;
3376 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3380 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3384 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3385 info_ptr
+= bytes_read
;
3388 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3389 info_ptr
+= bytes_read
;
3392 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3396 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3400 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3403 case DW_FORM_ref_udata
:
3404 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3405 info_ptr
+= bytes_read
;
3408 case DW_FORM_indirect
:
3410 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3411 dwarf_form_name (abbrev
->form
));
3416 /* read dwarf information from a buffer */
3419 read_1_byte (abfd
, buf
)
3423 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3427 read_1_signed_byte (abfd
, buf
)
3431 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3435 read_2_bytes (abfd
, buf
)
3439 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3443 read_2_signed_bytes (abfd
, buf
)
3447 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3451 read_4_bytes (abfd
, buf
)
3455 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3459 read_4_signed_bytes (abfd
, buf
)
3463 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3467 read_8_bytes (abfd
, buf
)
3471 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3475 read_address (abfd
, buf
)
3479 CORE_ADDR retval
= 0;
3481 switch (address_size
)
3484 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3487 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3490 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3493 /* *THE* alternative is 8, right? */
3501 read_n_bytes (abfd
, buf
, size
)
3506 /* If the size of a host char is 8 bits, we can return a pointer
3507 to the buffer, otherwise we have to copy the data to a buffer
3508 allocated on the temporary obstack. */
3509 #if HOST_CHAR_BIT == 8
3515 ret
= obstack_alloc (&dwarf2_tmp_obstack
, size
);
3516 for (i
= 0; i
< size
; ++i
)
3518 ret
[i
] = bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3526 read_string (abfd
, buf
, bytes_read_ptr
)
3529 unsigned int *bytes_read_ptr
;
3531 /* If the size of a host char is 8 bits, we can return a pointer
3532 to the string, otherwise we have to copy the string to a buffer
3533 allocated on the temporary obstack. */
3534 #if HOST_CHAR_BIT == 8
3537 *bytes_read_ptr
= 1;
3540 *bytes_read_ptr
= strlen (buf
) + 1;
3546 while ((byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
)) != 0)
3548 obstack_1grow (&dwarf2_tmp_obstack
, byte
);
3554 *bytes_read_ptr
= 1;
3557 obstack_1grow (&dwarf2_tmp_obstack
, '\0');
3558 *bytes_read_ptr
= i
+ 1;
3559 return obstack_finish (&dwarf2_tmp_obstack
);
3564 read_unsigned_leb128 (abfd
, buf
, bytes_read_ptr
)
3567 unsigned int *bytes_read_ptr
;
3569 unsigned int result
, num_read
;
3579 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3582 result
|= ((byte
& 127) << shift
);
3583 if ((byte
& 128) == 0)
3589 *bytes_read_ptr
= num_read
;
3594 read_signed_leb128 (abfd
, buf
, bytes_read_ptr
)
3597 unsigned int *bytes_read_ptr
;
3600 int i
, shift
, size
, num_read
;
3610 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3613 result
|= ((byte
& 127) << shift
);
3615 if ((byte
& 128) == 0)
3620 if ((shift
< size
) && (byte
& 0x40))
3622 result
|= -(1 << shift
);
3624 *bytes_read_ptr
= num_read
;
3629 set_cu_language (lang
)
3636 cu_language
= language_c
;
3638 case DW_LANG_C_plus_plus
:
3639 cu_language
= language_cplus
;
3641 case DW_LANG_Fortran77
:
3642 case DW_LANG_Fortran90
:
3643 cu_language
= language_fortran
;
3645 case DW_LANG_Mips_Assembler
:
3646 cu_language
= language_asm
;
3649 case DW_LANG_Cobol74
:
3650 case DW_LANG_Cobol85
:
3651 case DW_LANG_Pascal83
:
3652 case DW_LANG_Modula2
:
3654 cu_language
= language_unknown
;
3657 cu_language_defn
= language_def (cu_language
);
3660 /* Return the named attribute or NULL if not there. */
3662 static struct attribute
*
3663 dwarf_attr (die
, name
)
3664 struct die_info
*die
;
3668 struct attribute
*spec
= NULL
;
3670 for (i
= 0; i
< die
->num_attrs
; ++i
)
3672 if (die
->attrs
[i
].name
== name
)
3674 return &die
->attrs
[i
];
3676 if (die
->attrs
[i
].name
== DW_AT_specification
3677 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3678 spec
= &die
->attrs
[i
];
3682 struct die_info
*ref_die
=
3683 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3686 return dwarf_attr (ref_die
, name
);
3693 die_is_declaration (struct die_info
*die
)
3695 return (dwarf_attr (die
, DW_AT_declaration
)
3696 && ! dwarf_attr (die
, DW_AT_specification
));
3699 /* Decode the line number information for the compilation unit whose
3700 line number info is at OFFSET in the .debug_line section.
3701 The compilation directory of the file is passed in COMP_DIR. */
3705 unsigned int num_files
;
3718 unsigned int num_dirs
;
3723 dwarf_decode_lines (offset
, comp_dir
, abfd
)
3724 unsigned int offset
;
3730 struct line_head lh
;
3731 struct cleanup
*back_to
;
3732 unsigned int i
, bytes_read
;
3733 char *cur_file
, *cur_dir
;
3734 unsigned char op_code
, extended_op
, adj_opcode
;
3736 #define FILE_ALLOC_CHUNK 5
3737 #define DIR_ALLOC_CHUNK 5
3739 struct filenames files
;
3740 struct directories dirs
;
3742 if (dwarf_line_buffer
== NULL
)
3744 complain (&dwarf2_missing_line_number_section
);
3748 files
.num_files
= 0;
3754 line_ptr
= dwarf_line_buffer
+ offset
;
3756 /* read in the prologue */
3757 lh
.total_length
= read_4_bytes (abfd
, line_ptr
);
3759 line_end
= line_ptr
+ lh
.total_length
;
3760 lh
.version
= read_2_bytes (abfd
, line_ptr
);
3762 lh
.prologue_length
= read_4_bytes (abfd
, line_ptr
);
3764 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
3766 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
3768 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
3770 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
3772 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
3774 lh
.standard_opcode_lengths
= (unsigned char *)
3775 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
3776 back_to
= make_cleanup (free_current_contents
, &lh
.standard_opcode_lengths
);
3778 lh
.standard_opcode_lengths
[0] = 1;
3779 for (i
= 1; i
< lh
.opcode_base
; ++i
)
3781 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
3785 /* Read directory table */
3786 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3788 line_ptr
+= bytes_read
;
3789 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
3791 dirs
.dirs
= (char **)
3792 xrealloc (dirs
.dirs
,
3793 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
3794 if (dirs
.num_dirs
== 0)
3795 make_cleanup (free_current_contents
, &dirs
.dirs
);
3797 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
3799 line_ptr
+= bytes_read
;
3801 /* Read file name table */
3802 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3804 line_ptr
+= bytes_read
;
3805 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3807 files
.files
= (struct fileinfo
*)
3808 xrealloc (files
.files
,
3809 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3810 * sizeof (struct fileinfo
));
3811 if (files
.num_files
== 0)
3812 make_cleanup (free_current_contents
, &files
.files
);
3814 files
.files
[files
.num_files
].name
= cur_file
;
3815 files
.files
[files
.num_files
].dir
=
3816 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3817 line_ptr
+= bytes_read
;
3818 files
.files
[files
.num_files
].time
=
3819 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3820 line_ptr
+= bytes_read
;
3821 files
.files
[files
.num_files
].size
=
3822 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3823 line_ptr
+= bytes_read
;
3826 line_ptr
+= bytes_read
;
3828 /* Read the statement sequences until there's nothing left. */
3829 while (line_ptr
< line_end
)
3831 /* state machine registers */
3832 CORE_ADDR address
= 0;
3833 unsigned int file
= 1;
3834 unsigned int line
= 1;
3835 unsigned int column
= 0;
3836 int is_stmt
= lh
.default_is_stmt
;
3837 int basic_block
= 0;
3838 int end_sequence
= 0;
3840 /* Start a subfile for the current file of the state machine. */
3841 if (files
.num_files
>= file
)
3843 /* The file and directory tables are 0 based, the references
3845 dwarf2_start_subfile (files
.files
[file
- 1].name
,
3846 (files
.files
[file
- 1].dir
3847 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3851 /* Decode the table. */
3852 while (!end_sequence
)
3854 op_code
= read_1_byte (abfd
, line_ptr
);
3858 case DW_LNS_extended_op
:
3859 line_ptr
+= 1; /* ignore length */
3860 extended_op
= read_1_byte (abfd
, line_ptr
);
3862 switch (extended_op
)
3864 case DW_LNE_end_sequence
:
3866 /* Don't call record_line here. The end_sequence
3867 instruction provides the address of the first byte
3868 *after* the last line in the sequence; it's not the
3869 address of any real source line. However, the GDB
3870 linetable structure only records the starts of lines,
3871 not the ends. This is a weakness of GDB. */
3873 case DW_LNE_set_address
:
3874 address
= read_address (abfd
, line_ptr
) + baseaddr
;
3875 line_ptr
+= address_size
;
3877 case DW_LNE_define_file
:
3878 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
3879 line_ptr
+= bytes_read
;
3880 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3882 files
.files
= (struct fileinfo
*)
3883 xrealloc (files
.files
,
3884 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3885 * sizeof (struct fileinfo
));
3886 if (files
.num_files
== 0)
3887 make_cleanup (free_current_contents
, &files
.files
);
3889 files
.files
[files
.num_files
].name
= cur_file
;
3890 files
.files
[files
.num_files
].dir
=
3891 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3892 line_ptr
+= bytes_read
;
3893 files
.files
[files
.num_files
].time
=
3894 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3895 line_ptr
+= bytes_read
;
3896 files
.files
[files
.num_files
].size
=
3897 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3898 line_ptr
+= bytes_read
;
3902 complain (&dwarf2_mangled_line_number_section
);
3907 record_line (current_subfile
, line
, address
);
3910 case DW_LNS_advance_pc
:
3911 address
+= lh
.minimum_instruction_length
3912 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3913 line_ptr
+= bytes_read
;
3915 case DW_LNS_advance_line
:
3916 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
3917 line_ptr
+= bytes_read
;
3919 case DW_LNS_set_file
:
3920 /* The file and directory tables are 0 based, the references
3922 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3923 line_ptr
+= bytes_read
;
3924 dwarf2_start_subfile
3925 (files
.files
[file
- 1].name
,
3926 (files
.files
[file
- 1].dir
3927 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3930 case DW_LNS_set_column
:
3931 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3932 line_ptr
+= bytes_read
;
3934 case DW_LNS_negate_stmt
:
3935 is_stmt
= (!is_stmt
);
3937 case DW_LNS_set_basic_block
:
3940 /* Add to the address register of the state machine the
3941 address increment value corresponding to special opcode
3942 255. Ie, this value is scaled by the minimum instruction
3943 length since special opcode 255 would have scaled the
3945 case DW_LNS_const_add_pc
:
3946 address
+= (lh
.minimum_instruction_length
3947 * ((255 - lh
.opcode_base
) / lh
.line_range
));
3949 case DW_LNS_fixed_advance_pc
:
3950 address
+= read_2_bytes (abfd
, line_ptr
);
3953 default: /* special operand */
3954 adj_opcode
= op_code
- lh
.opcode_base
;
3955 address
+= (adj_opcode
/ lh
.line_range
)
3956 * lh
.minimum_instruction_length
;
3957 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
3958 /* append row to matrix using current values */
3959 record_line (current_subfile
, line
, address
);
3965 do_cleanups (back_to
);
3968 /* Start a subfile for DWARF. FILENAME is the name of the file and
3969 DIRNAME the name of the source directory which contains FILENAME
3970 or NULL if not known.
3971 This routine tries to keep line numbers from identical absolute and
3972 relative file names in a common subfile.
3974 Using the `list' example from the GDB testsuite, which resides in
3975 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
3976 of /srcdir/list0.c yields the following debugging information for list0.c:
3978 DW_AT_name: /srcdir/list0.c
3979 DW_AT_comp_dir: /compdir
3980 files.files[0].name: list0.h
3981 files.files[0].dir: /srcdir
3982 files.files[1].name: list0.c
3983 files.files[1].dir: /srcdir
3985 The line number information for list0.c has to end up in a single
3986 subfile, so that `break /srcdir/list0.c:1' works as expected. */
3989 dwarf2_start_subfile (filename
, dirname
)
3993 /* If the filename isn't absolute, try to match an existing subfile
3994 with the full pathname. */
3996 if (*filename
!= '/' && dirname
!= NULL
)
3998 struct subfile
*subfile
;
3999 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4001 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4003 if (STREQ (subfile
->name
, fullname
))
4005 current_subfile
= subfile
;
4012 start_subfile (filename
, dirname
);
4015 /* Given a pointer to a DWARF information entry, figure out if we need
4016 to make a symbol table entry for it, and if so, create a new entry
4017 and return a pointer to it.
4018 If TYPE is NULL, determine symbol type from the die, otherwise
4019 used the passed type. */
4021 static struct symbol
*
4022 new_symbol (die
, type
, objfile
)
4023 struct die_info
*die
;
4025 struct objfile
*objfile
;
4027 struct symbol
*sym
= NULL
;
4029 struct attribute
*attr
= NULL
;
4030 struct attribute
*attr2
= NULL
;
4033 name
= dwarf2_linkage_name (die
);
4036 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4037 sizeof (struct symbol
));
4038 OBJSTAT (objfile
, n_syms
++);
4039 memset (sym
, 0, sizeof (struct symbol
));
4040 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4041 &objfile
->symbol_obstack
);
4043 /* Default assumptions.
4044 Use the passed type or decode it from the die. */
4045 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4046 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4048 SYMBOL_TYPE (sym
) = type
;
4050 SYMBOL_TYPE (sym
) = die_type (die
, objfile
);
4051 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4054 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4057 /* If this symbol is from a C++ compilation, then attempt to
4058 cache the demangled form for future reference. This is a
4059 typical time versus space tradeoff, that was decided in favor
4060 of time because it sped up C++ symbol lookups by a factor of
4063 SYMBOL_LANGUAGE (sym
) = cu_language
;
4064 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4068 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4071 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4073 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4075 case DW_TAG_subprogram
:
4076 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4078 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4079 attr2
= dwarf_attr (die
, DW_AT_external
);
4080 if (attr2
&& (DW_UNSND (attr2
) != 0))
4082 add_symbol_to_list (sym
, &global_symbols
);
4086 add_symbol_to_list (sym
, list_in_scope
);
4089 case DW_TAG_variable
:
4090 /* Compilation with minimal debug info may result in variables
4091 with missing type entries. Change the misleading `void' type
4092 to something sensible. */
4093 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4094 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4095 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4096 "<variable, no debug info>",
4098 attr
= dwarf_attr (die
, DW_AT_const_value
);
4101 dwarf2_const_value (attr
, sym
, objfile
);
4102 attr2
= dwarf_attr (die
, DW_AT_external
);
4103 if (attr2
&& (DW_UNSND (attr2
) != 0))
4104 add_symbol_to_list (sym
, &global_symbols
);
4106 add_symbol_to_list (sym
, list_in_scope
);
4109 attr
= dwarf_attr (die
, DW_AT_location
);
4112 attr2
= dwarf_attr (die
, DW_AT_external
);
4113 if (attr2
&& (DW_UNSND (attr2
) != 0))
4115 SYMBOL_VALUE_ADDRESS (sym
) =
4116 decode_locdesc (DW_BLOCK (attr
), objfile
);
4117 add_symbol_to_list (sym
, &global_symbols
);
4119 /* In shared libraries the address of the variable
4120 in the location descriptor might still be relocatable,
4121 so its value could be zero.
4122 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4123 value is zero, the address of the variable will then
4124 be determined from the minimal symbol table whenever
4125 the variable is referenced. */
4126 if (SYMBOL_VALUE_ADDRESS (sym
))
4128 SYMBOL_VALUE_ADDRESS (sym
) += baseaddr
;
4129 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4132 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4136 SYMBOL_VALUE (sym
) = addr
=
4137 decode_locdesc (DW_BLOCK (attr
), objfile
);
4138 add_symbol_to_list (sym
, list_in_scope
);
4141 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4145 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4149 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4150 SYMBOL_BASEREG (sym
) = basereg
;
4154 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4158 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4159 SYMBOL_VALUE_ADDRESS (sym
) = addr
+ baseaddr
;
4165 /* We do not know the address of this symbol.
4166 If it is an external symbol and we have type information
4167 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4168 The address of the variable will then be determined from
4169 the minimal symbol table whenever the variable is
4171 attr2
= dwarf_attr (die
, DW_AT_external
);
4172 if (attr2
&& (DW_UNSND (attr2
) != 0)
4173 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4175 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4176 add_symbol_to_list (sym
, &global_symbols
);
4180 case DW_TAG_formal_parameter
:
4181 attr
= dwarf_attr (die
, DW_AT_location
);
4184 SYMBOL_VALUE (sym
) = decode_locdesc (DW_BLOCK (attr
), objfile
);
4187 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4193 if (basereg
!= frame_base_reg
)
4194 complain (&dwarf2_complex_location_expr
);
4195 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4199 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4200 SYMBOL_BASEREG (sym
) = basereg
;
4205 SYMBOL_CLASS (sym
) = LOC_ARG
;
4208 attr
= dwarf_attr (die
, DW_AT_const_value
);
4211 dwarf2_const_value (attr
, sym
, objfile
);
4213 add_symbol_to_list (sym
, list_in_scope
);
4215 case DW_TAG_unspecified_parameters
:
4216 /* From varargs functions; gdb doesn't seem to have any
4217 interest in this information, so just ignore it for now.
4220 case DW_TAG_class_type
:
4221 case DW_TAG_structure_type
:
4222 case DW_TAG_union_type
:
4223 case DW_TAG_enumeration_type
:
4224 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4225 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4226 add_symbol_to_list (sym
, list_in_scope
);
4228 /* The semantics of C++ state that "struct foo { ... }" also
4229 defines a typedef for "foo". Synthesize a typedef symbol so
4230 that "ptype foo" works as expected. */
4231 if (cu_language
== language_cplus
)
4233 struct symbol
*typedef_sym
= (struct symbol
*)
4234 obstack_alloc (&objfile
->symbol_obstack
,
4235 sizeof (struct symbol
));
4236 *typedef_sym
= *sym
;
4237 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4238 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4239 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4240 obsavestring (SYMBOL_NAME (sym
),
4241 strlen (SYMBOL_NAME (sym
)),
4242 &objfile
->type_obstack
);
4243 add_symbol_to_list (typedef_sym
, list_in_scope
);
4246 case DW_TAG_typedef
:
4247 case DW_TAG_base_type
:
4248 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4249 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4250 add_symbol_to_list (sym
, list_in_scope
);
4252 case DW_TAG_enumerator
:
4253 attr
= dwarf_attr (die
, DW_AT_const_value
);
4256 dwarf2_const_value (attr
, sym
, objfile
);
4258 add_symbol_to_list (sym
, list_in_scope
);
4261 /* Not a tag we recognize. Hopefully we aren't processing
4262 trash data, but since we must specifically ignore things
4263 we don't recognize, there is nothing else we should do at
4265 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4272 /* Copy constant value from an attribute to a symbol. */
4275 dwarf2_const_value (attr
, sym
, objfile
)
4276 struct attribute
*attr
;
4278 struct objfile
*objfile
;
4280 struct dwarf_block
*blk
;
4285 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != (unsigned int) address_size
)
4286 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4287 address_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4288 SYMBOL_VALUE_BYTES (sym
) = (char *)
4289 obstack_alloc (&objfile
->symbol_obstack
, address_size
);
4290 store_address (SYMBOL_VALUE_BYTES (sym
), address_size
, DW_ADDR (attr
));
4291 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4293 case DW_FORM_block1
:
4294 case DW_FORM_block2
:
4295 case DW_FORM_block4
:
4297 blk
= DW_BLOCK (attr
);
4298 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4299 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4300 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4301 SYMBOL_VALUE_BYTES (sym
) = (char *)
4302 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4303 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4304 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4307 /* The DW_AT_const_value attributes are supposed to carry the
4308 symbol's value "represented as it would be on the target
4309 architecture." By the time we get here, it's already been
4310 converted to host endianness, so we just need to sign- or
4311 zero-extend it as appropriate. */
4313 dwarf2_const_value_data (attr
, sym
, 8);
4316 dwarf2_const_value_data (attr
, sym
, 16);
4319 dwarf2_const_value_data (attr
, sym
, 32);
4322 dwarf2_const_value_data (attr
, sym
, 64);
4326 SYMBOL_VALUE (sym
) = DW_SND (attr
);
4327 SYMBOL_CLASS (sym
) = LOC_CONST
;
4331 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4332 SYMBOL_CLASS (sym
) = LOC_CONST
;
4336 complain (&dwarf2_unsupported_const_value_attr
,
4337 dwarf_form_name (attr
->form
));
4338 SYMBOL_VALUE (sym
) = 0;
4339 SYMBOL_CLASS (sym
) = LOC_CONST
;
4345 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4346 or zero-extend it as appropriate for the symbol's type. */
4348 dwarf2_const_value_data (struct attribute
*attr
,
4352 LONGEST l
= DW_UNSND (attr
);
4354 if (bits
< sizeof (l
) * 8)
4356 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
4357 l
&= ((LONGEST
) 1 << bits
) - 1;
4359 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
4362 SYMBOL_VALUE (sym
) = l
;
4363 SYMBOL_CLASS (sym
) = LOC_CONST
;
4367 /* Return the type of the die in question using its DW_AT_type attribute. */
4369 static struct type
*
4370 die_type (die
, objfile
)
4371 struct die_info
*die
;
4372 struct objfile
*objfile
;
4375 struct attribute
*type_attr
;
4376 struct die_info
*type_die
;
4379 type_attr
= dwarf_attr (die
, DW_AT_type
);
4382 /* A missing DW_AT_type represents a void type. */
4383 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4387 ref
= dwarf2_get_ref_die_offset (type_attr
);
4388 type_die
= follow_die_ref (ref
);
4391 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4395 type
= tag_type_to_type (type_die
, objfile
);
4398 dump_die (type_die
);
4399 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4404 /* Return the containing type of the die in question using its
4405 DW_AT_containing_type attribute. */
4407 static struct type
*
4408 die_containing_type (die
, objfile
)
4409 struct die_info
*die
;
4410 struct objfile
*objfile
;
4412 struct type
*type
= NULL
;
4413 struct attribute
*type_attr
;
4414 struct die_info
*type_die
= NULL
;
4417 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4420 ref
= dwarf2_get_ref_die_offset (type_attr
);
4421 type_die
= follow_die_ref (ref
);
4424 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4427 type
= tag_type_to_type (type_die
, objfile
);
4432 dump_die (type_die
);
4433 error ("Dwarf Error: Problem turning containing type into gdb type.");
4439 static struct type
*
4440 type_at_offset (offset
, objfile
)
4441 unsigned int offset
;
4442 struct objfile
*objfile
;
4444 struct die_info
*die
;
4447 die
= follow_die_ref (offset
);
4450 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4453 type
= tag_type_to_type (die
, objfile
);
4458 static struct type
*
4459 tag_type_to_type (die
, objfile
)
4460 struct die_info
*die
;
4461 struct objfile
*objfile
;
4469 read_type_die (die
, objfile
);
4473 error ("Dwarf Error: Cannot find type of die.");
4480 read_type_die (die
, objfile
)
4481 struct die_info
*die
;
4482 struct objfile
*objfile
;
4486 case DW_TAG_class_type
:
4487 case DW_TAG_structure_type
:
4488 case DW_TAG_union_type
:
4489 read_structure_scope (die
, objfile
);
4491 case DW_TAG_enumeration_type
:
4492 read_enumeration (die
, objfile
);
4494 case DW_TAG_subprogram
:
4495 case DW_TAG_subroutine_type
:
4496 read_subroutine_type (die
, objfile
);
4498 case DW_TAG_array_type
:
4499 read_array_type (die
, objfile
);
4501 case DW_TAG_pointer_type
:
4502 read_tag_pointer_type (die
, objfile
);
4504 case DW_TAG_ptr_to_member_type
:
4505 read_tag_ptr_to_member_type (die
, objfile
);
4507 case DW_TAG_reference_type
:
4508 read_tag_reference_type (die
, objfile
);
4510 case DW_TAG_const_type
:
4511 read_tag_const_type (die
, objfile
);
4513 case DW_TAG_volatile_type
:
4514 read_tag_volatile_type (die
, objfile
);
4516 case DW_TAG_string_type
:
4517 read_tag_string_type (die
, objfile
);
4519 case DW_TAG_typedef
:
4520 read_typedef (die
, objfile
);
4522 case DW_TAG_base_type
:
4523 read_base_type (die
, objfile
);
4526 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4531 static struct type
*
4532 dwarf_base_type (encoding
, size
, objfile
)
4535 struct objfile
*objfile
;
4537 /* FIXME - this should not produce a new (struct type *)
4538 every time. It should cache base types. */
4542 case DW_ATE_address
:
4543 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4545 case DW_ATE_boolean
:
4546 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4548 case DW_ATE_complex_float
:
4551 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4555 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4561 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4565 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4572 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4575 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4579 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4583 case DW_ATE_signed_char
:
4584 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4586 case DW_ATE_unsigned
:
4590 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4593 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4597 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4601 case DW_ATE_unsigned_char
:
4602 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4605 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4613 struct die_info
*old_die
;
4615 struct die_info
*new_die
;
4618 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4619 memset (new_die
, 0, sizeof (struct die_info
));
4621 new_die
->tag
= old_die
->tag
;
4622 new_die
->has_children
= old_die
->has_children
;
4623 new_die
->abbrev
= old_die
->abbrev
;
4624 new_die
->offset
= old_die
->offset
;
4625 new_die
->type
= NULL
;
4627 num_attrs
= old_die
->num_attrs
;
4628 new_die
->num_attrs
= num_attrs
;
4629 new_die
->attrs
= (struct attribute
*)
4630 xmalloc (num_attrs
* sizeof (struct attribute
));
4632 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4634 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4635 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4636 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4639 new_die
->next
= NULL
;
4644 /* Return sibling of die, NULL if no sibling. */
4648 struct die_info
*die
;
4650 int nesting_level
= 0;
4652 if (!die
->has_children
)
4654 if (die
->next
&& (die
->next
->tag
== 0))
4667 if (die
->has_children
)
4677 while (nesting_level
);
4678 if (die
&& (die
->tag
== 0))
4689 /* Get linkage name of a die, return NULL if not found. */
4692 dwarf2_linkage_name (die
)
4693 struct die_info
*die
;
4695 struct attribute
*attr
;
4697 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4698 if (attr
&& DW_STRING (attr
))
4699 return DW_STRING (attr
);
4700 attr
= dwarf_attr (die
, DW_AT_name
);
4701 if (attr
&& DW_STRING (attr
))
4702 return DW_STRING (attr
);
4706 /* Convert a DIE tag into its string name. */
4709 dwarf_tag_name (tag
)
4710 register unsigned tag
;
4714 case DW_TAG_padding
:
4715 return "DW_TAG_padding";
4716 case DW_TAG_array_type
:
4717 return "DW_TAG_array_type";
4718 case DW_TAG_class_type
:
4719 return "DW_TAG_class_type";
4720 case DW_TAG_entry_point
:
4721 return "DW_TAG_entry_point";
4722 case DW_TAG_enumeration_type
:
4723 return "DW_TAG_enumeration_type";
4724 case DW_TAG_formal_parameter
:
4725 return "DW_TAG_formal_parameter";
4726 case DW_TAG_imported_declaration
:
4727 return "DW_TAG_imported_declaration";
4729 return "DW_TAG_label";
4730 case DW_TAG_lexical_block
:
4731 return "DW_TAG_lexical_block";
4733 return "DW_TAG_member";
4734 case DW_TAG_pointer_type
:
4735 return "DW_TAG_pointer_type";
4736 case DW_TAG_reference_type
:
4737 return "DW_TAG_reference_type";
4738 case DW_TAG_compile_unit
:
4739 return "DW_TAG_compile_unit";
4740 case DW_TAG_string_type
:
4741 return "DW_TAG_string_type";
4742 case DW_TAG_structure_type
:
4743 return "DW_TAG_structure_type";
4744 case DW_TAG_subroutine_type
:
4745 return "DW_TAG_subroutine_type";
4746 case DW_TAG_typedef
:
4747 return "DW_TAG_typedef";
4748 case DW_TAG_union_type
:
4749 return "DW_TAG_union_type";
4750 case DW_TAG_unspecified_parameters
:
4751 return "DW_TAG_unspecified_parameters";
4752 case DW_TAG_variant
:
4753 return "DW_TAG_variant";
4754 case DW_TAG_common_block
:
4755 return "DW_TAG_common_block";
4756 case DW_TAG_common_inclusion
:
4757 return "DW_TAG_common_inclusion";
4758 case DW_TAG_inheritance
:
4759 return "DW_TAG_inheritance";
4760 case DW_TAG_inlined_subroutine
:
4761 return "DW_TAG_inlined_subroutine";
4763 return "DW_TAG_module";
4764 case DW_TAG_ptr_to_member_type
:
4765 return "DW_TAG_ptr_to_member_type";
4766 case DW_TAG_set_type
:
4767 return "DW_TAG_set_type";
4768 case DW_TAG_subrange_type
:
4769 return "DW_TAG_subrange_type";
4770 case DW_TAG_with_stmt
:
4771 return "DW_TAG_with_stmt";
4772 case DW_TAG_access_declaration
:
4773 return "DW_TAG_access_declaration";
4774 case DW_TAG_base_type
:
4775 return "DW_TAG_base_type";
4776 case DW_TAG_catch_block
:
4777 return "DW_TAG_catch_block";
4778 case DW_TAG_const_type
:
4779 return "DW_TAG_const_type";
4780 case DW_TAG_constant
:
4781 return "DW_TAG_constant";
4782 case DW_TAG_enumerator
:
4783 return "DW_TAG_enumerator";
4784 case DW_TAG_file_type
:
4785 return "DW_TAG_file_type";
4787 return "DW_TAG_friend";
4788 case DW_TAG_namelist
:
4789 return "DW_TAG_namelist";
4790 case DW_TAG_namelist_item
:
4791 return "DW_TAG_namelist_item";
4792 case DW_TAG_packed_type
:
4793 return "DW_TAG_packed_type";
4794 case DW_TAG_subprogram
:
4795 return "DW_TAG_subprogram";
4796 case DW_TAG_template_type_param
:
4797 return "DW_TAG_template_type_param";
4798 case DW_TAG_template_value_param
:
4799 return "DW_TAG_template_value_param";
4800 case DW_TAG_thrown_type
:
4801 return "DW_TAG_thrown_type";
4802 case DW_TAG_try_block
:
4803 return "DW_TAG_try_block";
4804 case DW_TAG_variant_part
:
4805 return "DW_TAG_variant_part";
4806 case DW_TAG_variable
:
4807 return "DW_TAG_variable";
4808 case DW_TAG_volatile_type
:
4809 return "DW_TAG_volatile_type";
4810 case DW_TAG_MIPS_loop
:
4811 return "DW_TAG_MIPS_loop";
4812 case DW_TAG_format_label
:
4813 return "DW_TAG_format_label";
4814 case DW_TAG_function_template
:
4815 return "DW_TAG_function_template";
4816 case DW_TAG_class_template
:
4817 return "DW_TAG_class_template";
4819 return "DW_TAG_<unknown>";
4823 /* Convert a DWARF attribute code into its string name. */
4826 dwarf_attr_name (attr
)
4827 register unsigned attr
;
4832 return "DW_AT_sibling";
4833 case DW_AT_location
:
4834 return "DW_AT_location";
4836 return "DW_AT_name";
4837 case DW_AT_ordering
:
4838 return "DW_AT_ordering";
4839 case DW_AT_subscr_data
:
4840 return "DW_AT_subscr_data";
4841 case DW_AT_byte_size
:
4842 return "DW_AT_byte_size";
4843 case DW_AT_bit_offset
:
4844 return "DW_AT_bit_offset";
4845 case DW_AT_bit_size
:
4846 return "DW_AT_bit_size";
4847 case DW_AT_element_list
:
4848 return "DW_AT_element_list";
4849 case DW_AT_stmt_list
:
4850 return "DW_AT_stmt_list";
4852 return "DW_AT_low_pc";
4854 return "DW_AT_high_pc";
4855 case DW_AT_language
:
4856 return "DW_AT_language";
4858 return "DW_AT_member";
4860 return "DW_AT_discr";
4861 case DW_AT_discr_value
:
4862 return "DW_AT_discr_value";
4863 case DW_AT_visibility
:
4864 return "DW_AT_visibility";
4866 return "DW_AT_import";
4867 case DW_AT_string_length
:
4868 return "DW_AT_string_length";
4869 case DW_AT_common_reference
:
4870 return "DW_AT_common_reference";
4871 case DW_AT_comp_dir
:
4872 return "DW_AT_comp_dir";
4873 case DW_AT_const_value
:
4874 return "DW_AT_const_value";
4875 case DW_AT_containing_type
:
4876 return "DW_AT_containing_type";
4877 case DW_AT_default_value
:
4878 return "DW_AT_default_value";
4880 return "DW_AT_inline";
4881 case DW_AT_is_optional
:
4882 return "DW_AT_is_optional";
4883 case DW_AT_lower_bound
:
4884 return "DW_AT_lower_bound";
4885 case DW_AT_producer
:
4886 return "DW_AT_producer";
4887 case DW_AT_prototyped
:
4888 return "DW_AT_prototyped";
4889 case DW_AT_return_addr
:
4890 return "DW_AT_return_addr";
4891 case DW_AT_start_scope
:
4892 return "DW_AT_start_scope";
4893 case DW_AT_stride_size
:
4894 return "DW_AT_stride_size";
4895 case DW_AT_upper_bound
:
4896 return "DW_AT_upper_bound";
4897 case DW_AT_abstract_origin
:
4898 return "DW_AT_abstract_origin";
4899 case DW_AT_accessibility
:
4900 return "DW_AT_accessibility";
4901 case DW_AT_address_class
:
4902 return "DW_AT_address_class";
4903 case DW_AT_artificial
:
4904 return "DW_AT_artificial";
4905 case DW_AT_base_types
:
4906 return "DW_AT_base_types";
4907 case DW_AT_calling_convention
:
4908 return "DW_AT_calling_convention";
4910 return "DW_AT_count";
4911 case DW_AT_data_member_location
:
4912 return "DW_AT_data_member_location";
4913 case DW_AT_decl_column
:
4914 return "DW_AT_decl_column";
4915 case DW_AT_decl_file
:
4916 return "DW_AT_decl_file";
4917 case DW_AT_decl_line
:
4918 return "DW_AT_decl_line";
4919 case DW_AT_declaration
:
4920 return "DW_AT_declaration";
4921 case DW_AT_discr_list
:
4922 return "DW_AT_discr_list";
4923 case DW_AT_encoding
:
4924 return "DW_AT_encoding";
4925 case DW_AT_external
:
4926 return "DW_AT_external";
4927 case DW_AT_frame_base
:
4928 return "DW_AT_frame_base";
4930 return "DW_AT_friend";
4931 case DW_AT_identifier_case
:
4932 return "DW_AT_identifier_case";
4933 case DW_AT_macro_info
:
4934 return "DW_AT_macro_info";
4935 case DW_AT_namelist_items
:
4936 return "DW_AT_namelist_items";
4937 case DW_AT_priority
:
4938 return "DW_AT_priority";
4940 return "DW_AT_segment";
4941 case DW_AT_specification
:
4942 return "DW_AT_specification";
4943 case DW_AT_static_link
:
4944 return "DW_AT_static_link";
4946 return "DW_AT_type";
4947 case DW_AT_use_location
:
4948 return "DW_AT_use_location";
4949 case DW_AT_variable_parameter
:
4950 return "DW_AT_variable_parameter";
4951 case DW_AT_virtuality
:
4952 return "DW_AT_virtuality";
4953 case DW_AT_vtable_elem_location
:
4954 return "DW_AT_vtable_elem_location";
4957 case DW_AT_MIPS_fde
:
4958 return "DW_AT_MIPS_fde";
4959 case DW_AT_MIPS_loop_begin
:
4960 return "DW_AT_MIPS_loop_begin";
4961 case DW_AT_MIPS_tail_loop_begin
:
4962 return "DW_AT_MIPS_tail_loop_begin";
4963 case DW_AT_MIPS_epilog_begin
:
4964 return "DW_AT_MIPS_epilog_begin";
4965 case DW_AT_MIPS_loop_unroll_factor
:
4966 return "DW_AT_MIPS_loop_unroll_factor";
4967 case DW_AT_MIPS_software_pipeline_depth
:
4968 return "DW_AT_MIPS_software_pipeline_depth";
4969 case DW_AT_MIPS_linkage_name
:
4970 return "DW_AT_MIPS_linkage_name";
4973 case DW_AT_sf_names
:
4974 return "DW_AT_sf_names";
4975 case DW_AT_src_info
:
4976 return "DW_AT_src_info";
4977 case DW_AT_mac_info
:
4978 return "DW_AT_mac_info";
4979 case DW_AT_src_coords
:
4980 return "DW_AT_src_coords";
4981 case DW_AT_body_begin
:
4982 return "DW_AT_body_begin";
4983 case DW_AT_body_end
:
4984 return "DW_AT_body_end";
4986 return "DW_AT_<unknown>";
4990 /* Convert a DWARF value form code into its string name. */
4993 dwarf_form_name (form
)
4994 register unsigned form
;
4999 return "DW_FORM_addr";
5000 case DW_FORM_block2
:
5001 return "DW_FORM_block2";
5002 case DW_FORM_block4
:
5003 return "DW_FORM_block4";
5005 return "DW_FORM_data2";
5007 return "DW_FORM_data4";
5009 return "DW_FORM_data8";
5010 case DW_FORM_string
:
5011 return "DW_FORM_string";
5013 return "DW_FORM_block";
5014 case DW_FORM_block1
:
5015 return "DW_FORM_block1";
5017 return "DW_FORM_data1";
5019 return "DW_FORM_flag";
5021 return "DW_FORM_sdata";
5023 return "DW_FORM_strp";
5025 return "DW_FORM_udata";
5026 case DW_FORM_ref_addr
:
5027 return "DW_FORM_ref_addr";
5029 return "DW_FORM_ref1";
5031 return "DW_FORM_ref2";
5033 return "DW_FORM_ref4";
5035 return "DW_FORM_ref8";
5036 case DW_FORM_ref_udata
:
5037 return "DW_FORM_ref_udata";
5038 case DW_FORM_indirect
:
5039 return "DW_FORM_indirect";
5041 return "DW_FORM_<unknown>";
5045 /* Convert a DWARF stack opcode into its string name. */
5048 dwarf_stack_op_name (op
)
5049 register unsigned op
;
5054 return "DW_OP_addr";
5056 return "DW_OP_deref";
5058 return "DW_OP_const1u";
5060 return "DW_OP_const1s";
5062 return "DW_OP_const2u";
5064 return "DW_OP_const2s";
5066 return "DW_OP_const4u";
5068 return "DW_OP_const4s";
5070 return "DW_OP_const8u";
5072 return "DW_OP_const8s";
5074 return "DW_OP_constu";
5076 return "DW_OP_consts";
5080 return "DW_OP_drop";
5082 return "DW_OP_over";
5084 return "DW_OP_pick";
5086 return "DW_OP_swap";
5090 return "DW_OP_xderef";
5098 return "DW_OP_minus";
5110 return "DW_OP_plus";
5111 case DW_OP_plus_uconst
:
5112 return "DW_OP_plus_uconst";
5118 return "DW_OP_shra";
5136 return "DW_OP_skip";
5138 return "DW_OP_lit0";
5140 return "DW_OP_lit1";
5142 return "DW_OP_lit2";
5144 return "DW_OP_lit3";
5146 return "DW_OP_lit4";
5148 return "DW_OP_lit5";
5150 return "DW_OP_lit6";
5152 return "DW_OP_lit7";
5154 return "DW_OP_lit8";
5156 return "DW_OP_lit9";
5158 return "DW_OP_lit10";
5160 return "DW_OP_lit11";
5162 return "DW_OP_lit12";
5164 return "DW_OP_lit13";
5166 return "DW_OP_lit14";
5168 return "DW_OP_lit15";
5170 return "DW_OP_lit16";
5172 return "DW_OP_lit17";
5174 return "DW_OP_lit18";
5176 return "DW_OP_lit19";
5178 return "DW_OP_lit20";
5180 return "DW_OP_lit21";
5182 return "DW_OP_lit22";
5184 return "DW_OP_lit23";
5186 return "DW_OP_lit24";
5188 return "DW_OP_lit25";
5190 return "DW_OP_lit26";
5192 return "DW_OP_lit27";
5194 return "DW_OP_lit28";
5196 return "DW_OP_lit29";
5198 return "DW_OP_lit30";
5200 return "DW_OP_lit31";
5202 return "DW_OP_reg0";
5204 return "DW_OP_reg1";
5206 return "DW_OP_reg2";
5208 return "DW_OP_reg3";
5210 return "DW_OP_reg4";
5212 return "DW_OP_reg5";
5214 return "DW_OP_reg6";
5216 return "DW_OP_reg7";
5218 return "DW_OP_reg8";
5220 return "DW_OP_reg9";
5222 return "DW_OP_reg10";
5224 return "DW_OP_reg11";
5226 return "DW_OP_reg12";
5228 return "DW_OP_reg13";
5230 return "DW_OP_reg14";
5232 return "DW_OP_reg15";
5234 return "DW_OP_reg16";
5236 return "DW_OP_reg17";
5238 return "DW_OP_reg18";
5240 return "DW_OP_reg19";
5242 return "DW_OP_reg20";
5244 return "DW_OP_reg21";
5246 return "DW_OP_reg22";
5248 return "DW_OP_reg23";
5250 return "DW_OP_reg24";
5252 return "DW_OP_reg25";
5254 return "DW_OP_reg26";
5256 return "DW_OP_reg27";
5258 return "DW_OP_reg28";
5260 return "DW_OP_reg29";
5262 return "DW_OP_reg30";
5264 return "DW_OP_reg31";
5266 return "DW_OP_breg0";
5268 return "DW_OP_breg1";
5270 return "DW_OP_breg2";
5272 return "DW_OP_breg3";
5274 return "DW_OP_breg4";
5276 return "DW_OP_breg5";
5278 return "DW_OP_breg6";
5280 return "DW_OP_breg7";
5282 return "DW_OP_breg8";
5284 return "DW_OP_breg9";
5286 return "DW_OP_breg10";
5288 return "DW_OP_breg11";
5290 return "DW_OP_breg12";
5292 return "DW_OP_breg13";
5294 return "DW_OP_breg14";
5296 return "DW_OP_breg15";
5298 return "DW_OP_breg16";
5300 return "DW_OP_breg17";
5302 return "DW_OP_breg18";
5304 return "DW_OP_breg19";
5306 return "DW_OP_breg20";
5308 return "DW_OP_breg21";
5310 return "DW_OP_breg22";
5312 return "DW_OP_breg23";
5314 return "DW_OP_breg24";
5316 return "DW_OP_breg25";
5318 return "DW_OP_breg26";
5320 return "DW_OP_breg27";
5322 return "DW_OP_breg28";
5324 return "DW_OP_breg29";
5326 return "DW_OP_breg30";
5328 return "DW_OP_breg31";
5330 return "DW_OP_regx";
5332 return "DW_OP_fbreg";
5334 return "DW_OP_bregx";
5336 return "DW_OP_piece";
5337 case DW_OP_deref_size
:
5338 return "DW_OP_deref_size";
5339 case DW_OP_xderef_size
:
5340 return "DW_OP_xderef_size";
5344 return "OP_<unknown>";
5349 dwarf_bool_name (mybool
)
5358 /* Convert a DWARF type code into its string name. */
5361 dwarf_type_encoding_name (enc
)
5362 register unsigned enc
;
5366 case DW_ATE_address
:
5367 return "DW_ATE_address";
5368 case DW_ATE_boolean
:
5369 return "DW_ATE_boolean";
5370 case DW_ATE_complex_float
:
5371 return "DW_ATE_complex_float";
5373 return "DW_ATE_float";
5375 return "DW_ATE_signed";
5376 case DW_ATE_signed_char
:
5377 return "DW_ATE_signed_char";
5378 case DW_ATE_unsigned
:
5379 return "DW_ATE_unsigned";
5380 case DW_ATE_unsigned_char
:
5381 return "DW_ATE_unsigned_char";
5383 return "DW_ATE_<unknown>";
5387 /* Convert a DWARF call frame info operation to its string name. */
5391 dwarf_cfi_name (cfi_opc
)
5392 register unsigned cfi_opc
;
5396 case DW_CFA_advance_loc
:
5397 return "DW_CFA_advance_loc";
5399 return "DW_CFA_offset";
5400 case DW_CFA_restore
:
5401 return "DW_CFA_restore";
5403 return "DW_CFA_nop";
5404 case DW_CFA_set_loc
:
5405 return "DW_CFA_set_loc";
5406 case DW_CFA_advance_loc1
:
5407 return "DW_CFA_advance_loc1";
5408 case DW_CFA_advance_loc2
:
5409 return "DW_CFA_advance_loc2";
5410 case DW_CFA_advance_loc4
:
5411 return "DW_CFA_advance_loc4";
5412 case DW_CFA_offset_extended
:
5413 return "DW_CFA_offset_extended";
5414 case DW_CFA_restore_extended
:
5415 return "DW_CFA_restore_extended";
5416 case DW_CFA_undefined
:
5417 return "DW_CFA_undefined";
5418 case DW_CFA_same_value
:
5419 return "DW_CFA_same_value";
5420 case DW_CFA_register
:
5421 return "DW_CFA_register";
5422 case DW_CFA_remember_state
:
5423 return "DW_CFA_remember_state";
5424 case DW_CFA_restore_state
:
5425 return "DW_CFA_restore_state";
5426 case DW_CFA_def_cfa
:
5427 return "DW_CFA_def_cfa";
5428 case DW_CFA_def_cfa_register
:
5429 return "DW_CFA_def_cfa_register";
5430 case DW_CFA_def_cfa_offset
:
5431 return "DW_CFA_def_cfa_offset";
5432 /* SGI/MIPS specific */
5433 case DW_CFA_MIPS_advance_loc8
:
5434 return "DW_CFA_MIPS_advance_loc8";
5436 return "DW_CFA_<unknown>";
5443 struct die_info
*die
;
5447 fprintf (stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5448 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5449 fprintf (stderr
, "\thas children: %s\n",
5450 dwarf_bool_name (die
->has_children
));
5452 fprintf (stderr
, "\tattributes:\n");
5453 for (i
= 0; i
< die
->num_attrs
; ++i
)
5455 fprintf (stderr
, "\t\t%s (%s) ",
5456 dwarf_attr_name (die
->attrs
[i
].name
),
5457 dwarf_form_name (die
->attrs
[i
].form
));
5458 switch (die
->attrs
[i
].form
)
5460 case DW_FORM_ref_addr
:
5462 fprintf (stderr
, "address: ");
5463 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
5465 case DW_FORM_block2
:
5466 case DW_FORM_block4
:
5468 case DW_FORM_block1
:
5469 fprintf (stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5479 fprintf (stderr
, "constant: %d", DW_UNSND (&die
->attrs
[i
]));
5481 case DW_FORM_string
:
5482 fprintf (stderr
, "string: \"%s\"",
5483 DW_STRING (&die
->attrs
[i
])
5484 ? DW_STRING (&die
->attrs
[i
]) : "");
5487 if (DW_UNSND (&die
->attrs
[i
]))
5488 fprintf (stderr
, "flag: TRUE");
5490 fprintf (stderr
, "flag: FALSE");
5492 case DW_FORM_strp
: /* we do not support separate string
5494 case DW_FORM_indirect
: /* we do not handle indirect yet */
5495 case DW_FORM_data8
: /* we do not have 64 bit quantities */
5497 fprintf (stderr
, "unsupported attribute form: %d.",
5498 die
->attrs
[i
].form
);
5500 fprintf (stderr
, "\n");
5506 struct die_info
*die
;
5516 store_in_ref_table (offset
, die
)
5517 unsigned int offset
;
5518 struct die_info
*die
;
5521 struct die_info
*old
;
5523 h
= (offset
% REF_HASH_SIZE
);
5524 old
= die_ref_table
[h
];
5525 die
->next_ref
= old
;
5526 die_ref_table
[h
] = die
;
5531 dwarf2_empty_die_ref_table ()
5533 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5537 dwarf2_get_ref_die_offset (attr
)
5538 struct attribute
*attr
;
5540 unsigned int result
= 0;
5544 case DW_FORM_ref_addr
:
5545 result
= DW_ADDR (attr
);
5550 case DW_FORM_ref_udata
:
5551 result
= cu_header_offset
+ DW_UNSND (attr
);
5554 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5560 follow_die_ref (offset
)
5561 unsigned int offset
;
5563 struct die_info
*die
;
5566 h
= (offset
% REF_HASH_SIZE
);
5567 die
= die_ref_table
[h
];
5570 if (die
->offset
== offset
)
5574 die
= die
->next_ref
;
5579 static struct type
*
5580 dwarf2_fundamental_type (objfile
, typeid)
5581 struct objfile
*objfile
;
5584 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5586 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5590 /* Look for this particular type in the fundamental type vector. If
5591 one is not found, create and install one appropriate for the
5592 current language and the current target machine. */
5594 if (ftypes
[typeid] == NULL
)
5596 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5599 return (ftypes
[typeid]);
5602 /* Decode simple location descriptions.
5603 Given a pointer to a dwarf block that defines a location, compute
5604 the location and return the value.
5606 FIXME: This is a kludge until we figure out a better
5607 way to handle the location descriptions.
5608 Gdb's design does not mesh well with the DWARF2 notion of a location
5609 computing interpreter, which is a shame because the flexibility goes unused.
5610 FIXME: Implement more operations as necessary.
5612 A location description containing no operations indicates that the
5613 object is optimized out. The global optimized_out flag is set for
5614 those, the return value is meaningless.
5616 When the result is a register number, the global isreg flag is set,
5617 otherwise it is cleared.
5619 When the result is a base register offset, the global offreg flag is set
5620 and the register number is returned in basereg, otherwise it is cleared.
5622 When the DW_OP_fbreg operation is encountered without a corresponding
5623 DW_AT_frame_base attribute, the global islocal flag is set.
5624 Hopefully the machine dependent code knows how to set up a virtual
5625 frame pointer for the local references.
5627 Note that stack[0] is unused except as a default error return.
5628 Note that stack overflow is not yet handled. */
5631 decode_locdesc (blk
, objfile
)
5632 struct dwarf_block
*blk
;
5633 struct objfile
*objfile
;
5636 int size
= blk
->size
;
5637 char *data
= blk
->data
;
5638 CORE_ADDR stack
[64];
5640 unsigned int bytes_read
, unsnd
;
5691 stack
[++stacki
] = op
- DW_OP_reg0
;
5696 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5698 #if defined(HARRIS_TARGET) && defined(_M88K)
5699 /* The Harris 88110 gdb ports have long kept their special reg
5700 numbers between their gp-regs and their x-regs. This is
5701 not how our dwarf is generated. Punt. */
5704 stack
[++stacki
] = unsnd
;
5740 basereg
= op
- DW_OP_breg0
;
5741 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5747 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5749 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5754 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5756 if (frame_base_reg
>= 0)
5759 basereg
= frame_base_reg
;
5760 stack
[stacki
] += frame_base_offset
;
5764 complain (&dwarf2_missing_at_frame_base
);
5770 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
]);
5775 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
5780 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
5785 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
5790 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
5795 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
5800 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
5805 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
5811 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5816 stack
[stacki
- 1] += stack
[stacki
];
5820 case DW_OP_plus_uconst
:
5821 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5826 stack
[stacki
- 1] = stack
[stacki
] - stack
[stacki
- 1];
5832 /* If we're not the last op, then we definitely can't encode
5833 this using GDB's address_class enum. */
5835 complain (&dwarf2_complex_location_expr
);
5839 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
5840 return (stack
[stacki
]);
5843 return (stack
[stacki
]);
5846 /* memory allocation interface */
5850 dwarf2_free_tmp_obstack (ignore
)
5853 obstack_free (&dwarf2_tmp_obstack
, NULL
);
5856 static struct dwarf_block
*
5857 dwarf_alloc_block ()
5859 struct dwarf_block
*blk
;
5861 blk
= (struct dwarf_block
*)
5862 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
5866 static struct abbrev_info
*
5867 dwarf_alloc_abbrev ()
5869 struct abbrev_info
*abbrev
;
5871 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
5872 memset (abbrev
, 0, sizeof (struct abbrev_info
));
5876 static struct die_info
*
5879 struct die_info
*die
;
5881 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5882 memset (die
, 0, sizeof (struct die_info
));