1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997 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, 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: The following variables pass additional information from
306 decode_locdesc to the caller. */
307 static int optimized_out
; /* Kludge to identify optimized out variables */
308 static int isreg
; /* Kludge to identify register variables */
309 static int offreg
; /* Kludge to identify basereg references */
310 static int basereg
; /* Which base register is it relative to? */
311 static int islocal
; /* Kludge to identify local variables */
313 /* DW_AT_frame_base values for the current function.
314 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
315 contains the register number for the frame register.
316 frame_base_offset is the offset from the frame register to the
317 virtual stack frame. */
318 static int frame_base_reg
;
319 static CORE_ADDR frame_base_offset
;
321 /* This value is added to each symbol value. FIXME: Generalize to
322 the section_offsets structure used by dbxread (once this is done,
323 pass the appropriate section number to end_symtab). */
324 static CORE_ADDR baseaddr
; /* Add to each symbol value */
326 /* We put a pointer to this structure in the read_symtab_private field
328 The complete dwarf information for an objfile is kept in the
329 psymbol_obstack, so that absolute die references can be handled.
330 Most of the information in this structure is related to an entire
331 object file and could be passed via the sym_private field of the objfile.
332 It is however conceivable that dwarf2 might not be the only type
333 of symbols read from an object file. */
337 /* Pointer to start of dwarf info buffer for the objfile. */
339 char *dwarf_info_buffer
;
341 /* Offset in dwarf_info_buffer for this compilation unit. */
343 unsigned long dwarf_info_offset
;
345 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
347 char *dwarf_abbrev_buffer
;
349 /* Size of dwarf abbreviation section for the objfile. */
351 unsigned int dwarf_abbrev_size
;
353 /* Pointer to start of dwarf line buffer for the objfile. */
355 char *dwarf_line_buffer
;
358 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
359 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
360 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
361 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
362 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
363 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
365 /* Maintain an array of referenced fundamental types for the current
366 compilation unit being read. For DWARF version 1, we have to construct
367 the fundamental types on the fly, since no information about the
368 fundamental types is supplied. Each such fundamental type is created by
369 calling a language dependent routine to create the type, and then a
370 pointer to that type is then placed in the array at the index specified
371 by it's FT_<TYPENAME> value. The array has a fixed size set by the
372 FT_NUM_MEMBERS compile time constant, which is the number of predefined
373 fundamental types gdb knows how to construct. */
374 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
376 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
377 but this would require a corresponding change in unpack_field_as_long
379 static int bits_per_byte
= 8;
381 /* The routines that read and process dies for a C struct or C++ class
382 pass lists of data member fields and lists of member function fields
383 in an instance of a field_info structure, as defined below. */
386 /* List of data member and baseclasses fields. */
389 struct nextfield
*next
;
395 /* Number of fields. */
398 /* Number of baseclasses. */
401 /* Set if the accesibility of one of the fields is not public. */
402 int non_public_fields
;
404 /* Member function fields array, entries are allocated in the order they
405 are encountered in the object file. */
408 struct nextfnfield
*next
;
409 struct fn_field fnfield
;
412 /* Member function fieldlist array, contains name of possibly overloaded
413 member function, number of overloaded member functions and a pointer
414 to the head of the member function field chain. */
419 struct nextfnfield
*head
;
422 /* Number of entries in the fnfieldlists array. */
426 /* FIXME: Kludge to mark a varargs function type for C++ member function
427 argument processing. */
428 #define TYPE_FLAG_VARARGS (1 << 10)
430 /* Dwarf2 has no clean way to discern C++ static and non-static member
431 functions. G++ helps GDB by marking the first parameter for non-static
432 member functions (which is the this pointer) as artificial.
433 We pass this information between dwarf2_add_member_fn and
434 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
435 #define TYPE_FIELD_ARTIFICIAL TYPE_FIELD_BITPOS
437 /* Various complaints about symbol reading that don't abort the process */
439 static struct complaint dwarf2_const_ignored
=
441 "type qualifier 'const' ignored", 0, 0
443 static struct complaint dwarf2_volatile_ignored
=
445 "type qualifier 'volatile' ignored", 0, 0
447 static struct complaint dwarf2_non_const_array_bound_ignored
=
449 "non-constant array bounds form '%s' ignored", 0, 0
451 static struct complaint dwarf2_missing_line_number_section
=
453 "missing .debug_line section", 0, 0
455 static struct complaint dwarf2_mangled_line_number_section
=
457 "mangled .debug_line section", 0, 0
459 static struct complaint dwarf2_unsupported_die_ref_attr
=
461 "unsupported die ref attribute form: '%s'", 0, 0
463 static struct complaint dwarf2_unsupported_stack_op
=
465 "unsupported stack op: '%s'", 0, 0
467 static struct complaint dwarf2_unsupported_tag
=
469 "unsupported tag: '%s'", 0, 0
471 static struct complaint dwarf2_unsupported_at_encoding
=
473 "unsupported DW_AT_encoding: '%s'", 0, 0
475 static struct complaint dwarf2_unsupported_at_frame_base
=
477 "unsupported DW_AT_frame_base for function '%s'", 0, 0
479 static struct complaint dwarf2_unexpected_tag
=
481 "unexepected tag in read_type_die: '%s'", 0, 0
483 static struct complaint dwarf2_missing_at_frame_base
=
485 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
487 static struct complaint dwarf2_bad_static_member_name
=
489 "unrecognized static data member name '%s'", 0, 0
491 static struct complaint dwarf2_unsupported_accessibility
=
493 "unsupported accessibility %d", 0, 0
495 static struct complaint dwarf2_bad_member_name_complaint
=
497 "cannot extract member name from '%s'", 0, 0
499 static struct complaint dwarf2_missing_member_fn_type_complaint
=
501 "member function type missing for '%s'", 0, 0
503 static struct complaint dwarf2_vtbl_not_found_complaint
=
505 "virtual function table pointer not found when defining class '%s'", 0, 0
507 static struct complaint dwarf2_absolute_sibling_complaint
=
509 "ignoring absolute DW_AT_sibling", 0, 0
511 static struct complaint dwarf2_const_value_length_mismatch
=
513 "const value length mismatch for '%s', got %d, expected %d", 0, 0
515 static struct complaint dwarf2_unsupported_const_value_attr
=
517 "unsupported const value attribute form: '%s'", 0, 0
520 /* Remember the addr_size read from the dwarf.
521 If a target expects to link compilation units with differing address
522 sizes, gdb needs to be sure that the appropriate size is here for
523 whatever scope is currently getting read. */
524 static int address_size
;
526 /* Some elf32 object file formats while linked for a 32 bit address
527 space contain debug information that has assumed 64 bit
528 addresses. Eg 64 bit MIPS target produced by GCC/GAS/LD where the
529 symbol table contains 32bit address values while its .debug_info
530 section contains 64 bit address values.
531 ADDRESS_SIGNIFICANT_SIZE specifies the number significant bits in
532 the ADDRESS_SIZE bytes read from the file */
533 static int address_significant_size
;
535 /* Externals references. */
536 extern int info_verbose
; /* From main.c; nonzero => verbose */
538 /* local function prototypes */
540 static void dwarf2_locate_sections
PARAMS ((bfd
*, asection
*, PTR
));
543 static void dwarf2_build_psymtabs_easy
PARAMS ((struct objfile
*,
544 struct section_offsets
*,
548 static void dwarf2_build_psymtabs_hard
PARAMS ((struct objfile
*,
549 struct section_offsets
*,
552 static char *scan_partial_symbols
PARAMS ((char *, struct objfile
*,
553 CORE_ADDR
*, CORE_ADDR
*));
555 static void add_partial_symbol
PARAMS ((struct partial_die_info
*,
558 static void dwarf2_psymtab_to_symtab
PARAMS ((struct partial_symtab
*));
560 static void psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*));
562 static char *dwarf2_read_section
PARAMS ((struct objfile
*, file_ptr
,
565 static void dwarf2_read_abbrevs
PARAMS ((bfd
*, unsigned int));
567 static void dwarf2_empty_abbrev_table
PARAMS ((PTR
));
569 static struct abbrev_info
*dwarf2_lookup_abbrev
PARAMS ((unsigned int));
571 static char *read_partial_die
PARAMS ((struct partial_die_info
*,
572 bfd
*, char *, int *));
574 static char *read_full_die
PARAMS ((struct die_info
**, bfd
*, char *));
576 static char *read_attribute
PARAMS ((struct attribute
*, struct attr_abbrev
*,
579 static unsigned int read_1_byte
PARAMS ((bfd
*, char *));
581 static int read_1_signed_byte
PARAMS ((bfd
*, char *));
583 static unsigned int read_2_bytes
PARAMS ((bfd
*, char *));
585 static unsigned int read_4_bytes
PARAMS ((bfd
*, char *));
587 static unsigned int read_8_bytes
PARAMS ((bfd
*, char *));
589 static CORE_ADDR read_address
PARAMS ((bfd
*, char *));
591 static char *read_n_bytes
PARAMS ((bfd
*, char *, unsigned int));
593 static char *read_string
PARAMS ((bfd
*, char *, unsigned int *));
595 static unsigned int read_unsigned_leb128
PARAMS ((bfd
*, char *,
598 static int read_signed_leb128
PARAMS ((bfd
*, char *, unsigned int *));
600 static void set_cu_language
PARAMS ((unsigned int));
602 static struct attribute
*dwarf_attr
PARAMS ((struct die_info
*,
605 static void dwarf_decode_lines
PARAMS ((unsigned int, char *, bfd
*));
607 static void dwarf2_start_subfile
PARAMS ((char *, char *));
609 static struct symbol
*new_symbol
PARAMS ((struct die_info
*, struct type
*,
612 static void dwarf2_const_value
PARAMS ((struct attribute
*, struct symbol
*,
615 static struct type
*die_type
PARAMS ((struct die_info
*, struct objfile
*));
617 static struct type
*die_containing_type
PARAMS ((struct die_info
*,
621 static struct type
*type_at_offset
PARAMS ((unsigned int, struct objfile
*));
624 static struct type
*tag_type_to_type
PARAMS ((struct die_info
*,
627 static void read_type_die
PARAMS ((struct die_info
*, struct objfile
*));
629 static void read_typedef
PARAMS ((struct die_info
*, struct objfile
*));
631 static void read_base_type
PARAMS ((struct die_info
*, struct objfile
*));
633 static void read_file_scope
PARAMS ((struct die_info
*, struct objfile
*));
635 static void read_func_scope
PARAMS ((struct die_info
*, struct objfile
*));
637 static void read_lexical_block_scope
PARAMS ((struct die_info
*,
640 static int dwarf2_get_pc_bounds
PARAMS ((struct die_info
*,
641 CORE_ADDR
*, CORE_ADDR
*,
644 static void dwarf2_add_field
PARAMS ((struct field_info
*, struct die_info
*,
647 static void dwarf2_attach_fields_to_type
PARAMS ((struct field_info
*,
651 static char *skip_member_fn_name
PARAMS ((char *));
653 static void dwarf2_add_member_fn
PARAMS ((struct field_info
*,
654 struct die_info
*, struct type
*,
655 struct objfile
*objfile
));
657 static void dwarf2_attach_fn_fields_to_type
PARAMS ((struct field_info
*,
661 static void read_structure_scope
PARAMS ((struct die_info
*, struct objfile
*));
663 static void read_common_block
PARAMS ((struct die_info
*, struct objfile
*));
665 static void read_enumeration
PARAMS ((struct die_info
*, struct objfile
*));
667 static struct type
*dwarf_base_type
PARAMS ((int, int, struct objfile
*));
669 static CORE_ADDR decode_locdesc
PARAMS ((struct dwarf_block
*,
672 static void read_array_type
PARAMS ((struct die_info
*, struct objfile
*));
674 static void read_tag_pointer_type
PARAMS ((struct die_info
*,
677 static void read_tag_ptr_to_member_type
PARAMS ((struct die_info
*,
680 static void read_tag_reference_type
PARAMS ((struct die_info
*,
683 static void read_tag_const_type
PARAMS ((struct die_info
*, struct objfile
*));
685 static void read_tag_volatile_type
PARAMS ((struct die_info
*,
688 static void read_tag_string_type
PARAMS ((struct die_info
*,
691 static void read_subroutine_type
PARAMS ((struct die_info
*,
694 struct die_info
*read_comp_unit
PARAMS ((char *, bfd
*));
696 static void free_die_list
PARAMS ((struct die_info
*));
698 static void process_die
PARAMS ((struct die_info
*, struct objfile
*));
700 static char *dwarf2_linkage_name
PARAMS ((struct die_info
*));
702 static char *dwarf_tag_name
PARAMS ((unsigned int));
704 static char *dwarf_attr_name
PARAMS ((unsigned int));
706 static char *dwarf_form_name
PARAMS ((unsigned int));
708 static char *dwarf_stack_op_name
PARAMS ((unsigned int));
710 static char *dwarf_bool_name
PARAMS ((unsigned int));
712 static char *dwarf_type_encoding_name
PARAMS ((unsigned int));
715 static char *dwarf_cfi_name
PARAMS ((unsigned int));
717 struct die_info
*copy_die
PARAMS ((struct die_info
*));
720 struct die_info
*sibling_die
PARAMS ((struct die_info
*));
722 void dump_die
PARAMS ((struct die_info
*));
724 void dump_die_list
PARAMS ((struct die_info
*));
726 void store_in_ref_table
PARAMS ((unsigned int, struct die_info
*));
728 static void dwarf2_empty_die_ref_table
PARAMS ((void));
730 static unsigned int dwarf2_get_ref_die_offset
PARAMS ((struct attribute
*));
732 struct die_info
*follow_die_ref
PARAMS ((unsigned int));
734 static struct type
*dwarf2_fundamental_type
PARAMS ((struct objfile
*, int));
736 /* memory allocation interface */
738 static void dwarf2_free_tmp_obstack
PARAMS ((PTR
));
740 static struct dwarf_block
*dwarf_alloc_block
PARAMS ((void));
742 static struct abbrev_info
*dwarf_alloc_abbrev
PARAMS ((void));
744 static struct die_info
*dwarf_alloc_die
PARAMS ((void));
746 /* Try to locate the sections we need for DWARF 2 debugging
747 information and return true if we have enough to do something. */
750 dwarf2_has_info (abfd
)
753 dwarf_info_offset
= dwarf_abbrev_offset
= dwarf_line_offset
= 0;
754 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
755 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
765 /* This function is mapped across the sections and remembers the
766 offset and size of each of the debugging sections we are interested
770 dwarf2_locate_sections (ignore_abfd
, sectp
, ignore_ptr
)
775 if (STREQ (sectp
->name
, INFO_SECTION
))
777 dwarf_info_offset
= sectp
->filepos
;
778 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
780 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
782 dwarf_abbrev_offset
= sectp
->filepos
;
783 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
785 else if (STREQ (sectp
->name
, LINE_SECTION
))
787 dwarf_line_offset
= sectp
->filepos
;
788 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
790 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
792 dwarf_pubnames_offset
= sectp
->filepos
;
793 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
795 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
797 dwarf_aranges_offset
= sectp
->filepos
;
798 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
800 else if (STREQ (sectp
->name
, LOC_SECTION
))
802 dwarf_loc_offset
= sectp
->filepos
;
803 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
805 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
807 dwarf_macinfo_offset
= sectp
->filepos
;
808 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
810 else if (STREQ (sectp
->name
, STR_SECTION
))
812 dwarf_str_offset
= sectp
->filepos
;
813 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
817 /* Build a partial symbol table. */
820 dwarf2_build_psymtabs (objfile
, section_offsets
, mainline
)
821 struct objfile
*objfile
;
822 struct section_offsets
*section_offsets
;
826 /* We definitely need the .debug_info and .debug_abbrev sections */
828 dwarf_info_buffer
= dwarf2_read_section (objfile
,
831 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
834 dwarf_line_buffer
= dwarf2_read_section (objfile
,
838 if (mainline
|| objfile
->global_psymbols
.size
== 0 ||
839 objfile
->static_psymbols
.size
== 0)
841 init_psymbol_list (objfile
, 1024);
845 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
847 /* Things are significanlty easier if we have .debug_aranges and
848 .debug_pubnames sections */
850 dwarf2_build_psymtabs_easy (objfile
, section_offsets
, mainline
);
854 /* only test this case for now */
856 /* In this case we have to work a bit harder */
857 dwarf2_build_psymtabs_hard (objfile
, section_offsets
, mainline
);
862 /* Build the partial symbol table from the information in the
863 .debug_pubnames and .debug_aranges sections. */
866 dwarf2_build_psymtabs_easy (objfile
, section_offsets
, mainline
)
867 struct objfile
*objfile
;
868 struct section_offsets
*section_offsets
;
871 bfd
*abfd
= objfile
->obfd
;
872 char *aranges_buffer
, *pubnames_buffer
;
873 char *aranges_ptr
, *pubnames_ptr
;
874 unsigned int entry_length
, version
, info_offset
, info_size
;
876 pubnames_buffer
= dwarf2_read_section (objfile
,
877 dwarf_pubnames_offset
,
878 dwarf_pubnames_size
);
879 pubnames_ptr
= pubnames_buffer
;
880 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
882 entry_length
= read_4_bytes (abfd
, pubnames_ptr
);
884 version
= read_1_byte (abfd
, pubnames_ptr
);
886 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
888 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
892 aranges_buffer
= dwarf2_read_section (objfile
,
893 dwarf_aranges_offset
,
899 /* Build the partial symbol table by doing a quick pass through the
900 .debug_info and .debug_abbrev sections. */
903 dwarf2_build_psymtabs_hard (objfile
, section_offsets
, mainline
)
904 struct objfile
*objfile
;
905 struct section_offsets
*section_offsets
;
908 /* Instead of reading this into a big buffer, we should probably use
909 mmap() on architectures that support it. (FIXME) */
910 bfd
*abfd
= objfile
->obfd
;
911 char *info_ptr
, *abbrev_ptr
;
912 char *beg_of_comp_unit
;
913 struct comp_unit_head cu_header
;
914 struct partial_die_info comp_unit_die
;
915 struct partial_symtab
*pst
;
916 struct cleanup
*back_to
;
917 int comp_unit_has_pc_info
;
918 CORE_ADDR lowpc
, highpc
;
920 /* Number of bytes of any addresses that are signficant */
921 address_significant_size
= get_elf_backend_data (abfd
)->s
->arch_size
/ 8;
923 info_ptr
= dwarf_info_buffer
;
924 abbrev_ptr
= dwarf_abbrev_buffer
;
926 obstack_init (&dwarf2_tmp_obstack
);
927 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
929 while ((unsigned int) (info_ptr
- dwarf_info_buffer
)
930 + ((info_ptr
- dwarf_info_buffer
) % 4) < dwarf_info_size
)
932 beg_of_comp_unit
= info_ptr
;
933 cu_header
.length
= read_4_bytes (abfd
, info_ptr
);
935 cu_header
.version
= read_2_bytes (abfd
, info_ptr
);
937 cu_header
.abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
939 cu_header
.addr_size
= read_1_byte (abfd
, info_ptr
);
941 address_size
= cu_header
.addr_size
;
943 if (cu_header
.version
!= 2)
945 error ("Dwarf Error: wrong version in compilation unit header.");
948 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
950 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
951 (long) cu_header
.abbrev_offset
,
952 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
955 if (beg_of_comp_unit
+ cu_header
.length
+ 4
956 > dwarf_info_buffer
+ dwarf_info_size
)
958 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
959 (long) cu_header
.length
,
960 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
963 if (address_size
< address_significant_size
)
965 error ("Dwarf Error: bad address size (%ld) in compilation unit header (offset 0x%lx + 11).",
966 (long) cu_header
.addr_size
,
967 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
970 /* Read the abbrevs for this compilation unit into a table */
971 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
972 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
974 /* Read the compilation unit die */
975 info_ptr
= read_partial_die (&comp_unit_die
, abfd
,
976 info_ptr
, &comp_unit_has_pc_info
);
978 /* Set the language we're debugging */
979 set_cu_language (comp_unit_die
.language
);
981 /* Allocate a new partial symbol table structure */
982 pst
= start_psymtab_common (objfile
, section_offsets
,
983 comp_unit_die
.name
? comp_unit_die
.name
: "",
985 objfile
->global_psymbols
.next
,
986 objfile
->static_psymbols
.next
);
988 pst
->read_symtab_private
= (char *)
989 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
990 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
991 DWARF_INFO_BUFFER(pst
) = dwarf_info_buffer
;
992 DWARF_INFO_OFFSET(pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
993 DWARF_ABBREV_BUFFER(pst
) = dwarf_abbrev_buffer
;
994 DWARF_ABBREV_SIZE(pst
) = dwarf_abbrev_size
;
995 DWARF_LINE_BUFFER(pst
) = dwarf_line_buffer
;
996 baseaddr
= ANOFFSET (section_offsets
, 0);
998 /* Store the function that reads in the rest of the symbol table */
999 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1001 /* Check if comp unit has_children.
1002 If so, read the rest of the partial symbols from this comp unit.
1003 If not, there's no more debug_info for this comp unit. */
1004 if (comp_unit_die
.has_children
)
1005 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
);
1007 /* If the compilation unit didn't have an explicit address range,
1008 then use the information extracted from its child dies. */
1009 if (!comp_unit_has_pc_info
)
1011 comp_unit_die
.lowpc
= lowpc
;
1012 comp_unit_die
.highpc
= highpc
;
1014 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1015 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1017 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1018 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1019 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1020 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1021 sort_pst_symbols (pst
);
1023 /* If there is already a psymtab or symtab for a file of this
1024 name, remove it. (If there is a symtab, more drastic things
1025 also happen.) This happens in VxWorks. */
1026 free_named_symtabs (pst
->filename
);
1028 info_ptr
= beg_of_comp_unit
+ cu_header
.length
+ 4;
1030 do_cleanups (back_to
);
1033 /* Read in all interesting dies to the end of the compilation unit. */
1036 scan_partial_symbols (info_ptr
, objfile
, lowpc
, highpc
)
1038 struct objfile
*objfile
;
1042 bfd
*abfd
= objfile
->obfd
;
1043 struct partial_die_info pdi
;
1045 /* This function is called after we've read in the comp_unit_die in
1046 order to read its children. We start the nesting level at 1 since
1047 we have pushed 1 level down in order to read the comp unit's children.
1048 The comp unit itself is at level 0, so we stop reading when we pop
1049 back to that level. */
1051 int nesting_level
= 1;
1054 *lowpc
= ((CORE_ADDR
) -1);
1055 *highpc
= ((CORE_ADDR
) 0);
1057 while (nesting_level
)
1059 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, &has_pc_info
);
1065 case DW_TAG_subprogram
:
1068 if (pdi
.lowpc
< *lowpc
)
1072 if (pdi
.highpc
> *highpc
)
1074 *highpc
= pdi
.highpc
;
1076 if ((pdi
.is_external
|| nesting_level
== 1)
1077 && !pdi
.is_declaration
)
1079 add_partial_symbol (&pdi
, objfile
);
1083 case DW_TAG_variable
:
1084 case DW_TAG_typedef
:
1085 case DW_TAG_class_type
:
1086 case DW_TAG_structure_type
:
1087 case DW_TAG_union_type
:
1088 case DW_TAG_enumeration_type
:
1089 if ((pdi
.is_external
|| nesting_level
== 1)
1090 && !pdi
.is_declaration
)
1092 add_partial_symbol (&pdi
, objfile
);
1095 case DW_TAG_enumerator
:
1096 /* File scope enumerators are added to the partial symbol
1098 if (nesting_level
== 2)
1099 add_partial_symbol (&pdi
, objfile
);
1101 case DW_TAG_base_type
:
1102 /* File scope base type definitions are added to the partial
1104 if (nesting_level
== 1)
1105 add_partial_symbol (&pdi
, objfile
);
1112 /* If the die has a sibling, skip to the sibling.
1113 Do not skip enumeration types, we want to record their
1115 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1117 info_ptr
= pdi
.sibling
;
1119 else if (pdi
.has_children
)
1121 /* Die has children, but the optional DW_AT_sibling attribute
1132 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1133 from `maint check'. */
1134 if (*lowpc
== ((CORE_ADDR
) -1))
1140 add_partial_symbol (pdi
, objfile
)
1141 struct partial_die_info
*pdi
;
1142 struct objfile
*objfile
;
1148 case DW_TAG_subprogram
:
1149 if (pdi
->is_external
)
1151 prim_record_minimal_symbol (pdi
->name
, pdi
->lowpc
+ baseaddr
,
1153 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1154 VAR_NAMESPACE
, LOC_BLOCK
,
1155 &objfile
->global_psymbols
,
1156 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1160 prim_record_minimal_symbol (pdi
->name
, pdi
->lowpc
+ baseaddr
,
1161 mst_file_text
, objfile
);
1162 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1163 VAR_NAMESPACE
, LOC_BLOCK
,
1164 &objfile
->static_psymbols
,
1165 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1168 case DW_TAG_variable
:
1169 if (pdi
->is_external
)
1172 Don't enter into the minimal symbol tables as there is
1173 a minimal symbol table entry from the ELF symbols already.
1174 Enter into partial symbol table if it has a location
1175 descriptor or a type.
1176 If the location descriptor is missing, new_symbol will create
1177 a LOC_UNRESOLVED symbol, the address of the variable will then
1178 be determined from the minimal symbol table whenever the variable
1180 The address for the partial symbol table entry is not
1181 used by GDB, but it comes in handy for debugging partial symbol
1185 addr
= decode_locdesc (pdi
->locdesc
, objfile
);
1186 if (pdi
->locdesc
|| pdi
->has_type
)
1187 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1188 VAR_NAMESPACE
, LOC_STATIC
,
1189 &objfile
->global_psymbols
,
1190 0, addr
+ baseaddr
, cu_language
, objfile
);
1194 /* Static Variable. Skip symbols without location descriptors. */
1195 if (pdi
->locdesc
== NULL
)
1197 addr
= decode_locdesc (pdi
->locdesc
, objfile
);
1198 prim_record_minimal_symbol (pdi
->name
, addr
+ baseaddr
,
1199 mst_file_data
, objfile
);
1200 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1201 VAR_NAMESPACE
, LOC_STATIC
,
1202 &objfile
->static_psymbols
,
1203 0, addr
+ baseaddr
, cu_language
, objfile
);
1206 case DW_TAG_typedef
:
1207 case DW_TAG_base_type
:
1208 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1209 VAR_NAMESPACE
, LOC_TYPEDEF
,
1210 &objfile
->static_psymbols
,
1211 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1213 case DW_TAG_class_type
:
1214 case DW_TAG_structure_type
:
1215 case DW_TAG_union_type
:
1216 case DW_TAG_enumeration_type
:
1217 /* Skip aggregate types without children, these are external
1219 if (pdi
->has_children
== 0)
1221 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1222 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1223 &objfile
->static_psymbols
,
1224 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1226 if (cu_language
== language_cplus
)
1228 /* For C++, these implicitly act as typedefs as well. */
1229 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1230 VAR_NAMESPACE
, LOC_TYPEDEF
,
1231 &objfile
->static_psymbols
,
1232 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1235 case DW_TAG_enumerator
:
1236 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1237 VAR_NAMESPACE
, LOC_CONST
,
1238 &objfile
->static_psymbols
,
1239 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1246 /* Expand this partial symbol table into a full symbol table. */
1249 dwarf2_psymtab_to_symtab (pst
)
1250 struct partial_symtab
*pst
;
1252 /* FIXME: This is barely more than a stub. */
1257 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1263 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1264 gdb_flush (gdb_stdout
);
1267 psymtab_to_symtab_1 (pst
);
1269 /* Finish up the debug error message. */
1271 printf_filtered ("done.\n");
1277 psymtab_to_symtab_1 (pst
)
1278 struct partial_symtab
*pst
;
1280 struct objfile
*objfile
= pst
->objfile
;
1281 bfd
*abfd
= objfile
->obfd
;
1282 struct comp_unit_head cu_header
;
1283 struct die_info
*dies
;
1284 unsigned long offset
;
1285 CORE_ADDR lowpc
, highpc
;
1286 struct die_info
*child_die
;
1288 struct symtab
*symtab
;
1289 struct cleanup
*back_to
;
1291 /* Set local variables from the partial symbol table info. */
1292 offset
= DWARF_INFO_OFFSET(pst
);
1293 dwarf_info_buffer
= DWARF_INFO_BUFFER(pst
);
1294 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER(pst
);
1295 dwarf_abbrev_size
= DWARF_ABBREV_SIZE(pst
);
1296 dwarf_line_buffer
= DWARF_LINE_BUFFER(pst
);
1297 baseaddr
= ANOFFSET (pst
->section_offsets
, 0);
1298 cu_header_offset
= offset
;
1299 info_ptr
= dwarf_info_buffer
+ offset
;
1301 obstack_init (&dwarf2_tmp_obstack
);
1302 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1305 make_cleanup (really_free_pendings
, NULL
);
1307 /* read in the comp_unit header */
1308 cu_header
.length
= read_4_bytes (abfd
, info_ptr
);
1310 cu_header
.version
= read_2_bytes (abfd
, info_ptr
);
1312 cu_header
.abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
1314 cu_header
.addr_size
= read_1_byte (abfd
, info_ptr
);
1317 /* Read the abbrevs for this compilation unit */
1318 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1319 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1321 dies
= read_comp_unit (info_ptr
, abfd
);
1323 make_cleanup (free_die_list
, dies
);
1325 /* Do line number decoding in read_file_scope () */
1326 process_die (dies
, objfile
);
1328 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1330 /* Some compilers don't define a DW_AT_high_pc attribute for
1331 the compilation unit. If the DW_AT_high_pc is missing,
1332 synthesize it, by scanning the DIE's below the compilation unit. */
1334 if (dies
->has_children
)
1336 child_die
= dies
->next
;
1337 while (child_die
&& child_die
->tag
)
1339 if (child_die
->tag
== DW_TAG_subprogram
)
1341 CORE_ADDR low
, high
;
1343 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1345 highpc
= max (highpc
, high
);
1348 child_die
= sibling_die (child_die
);
1352 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, 0);
1354 /* Set symtab language to language from DW_AT_language.
1355 If the compilation is from a C file generated by language preprocessors,
1356 do not set the language if it was already deduced by start_subfile. */
1358 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1360 symtab
->language
= cu_language
;
1362 pst
->symtab
= symtab
;
1364 sort_symtab_syms (pst
->symtab
);
1366 do_cleanups (back_to
);
1369 /* Process a die and its children. */
1372 process_die (die
, objfile
)
1373 struct die_info
*die
;
1374 struct objfile
*objfile
;
1378 case DW_TAG_padding
:
1380 case DW_TAG_compile_unit
:
1381 read_file_scope (die
, objfile
);
1383 case DW_TAG_subprogram
:
1384 read_subroutine_type (die
, objfile
);
1385 read_func_scope (die
, objfile
);
1387 case DW_TAG_inlined_subroutine
:
1388 /* FIXME: These are ignored for now.
1389 They could be used to set breakpoints on all inlined instances
1390 of a function and make GDB `next' properly over inlined functions. */
1392 case DW_TAG_lexical_block
:
1393 read_lexical_block_scope (die
, objfile
);
1395 case DW_TAG_class_type
:
1396 case DW_TAG_structure_type
:
1397 case DW_TAG_union_type
:
1398 read_structure_scope (die
, objfile
);
1400 case DW_TAG_enumeration_type
:
1401 read_enumeration (die
, objfile
);
1403 case DW_TAG_subroutine_type
:
1404 read_subroutine_type (die
, objfile
);
1406 case DW_TAG_array_type
:
1407 read_array_type (die
, objfile
);
1409 case DW_TAG_pointer_type
:
1410 read_tag_pointer_type (die
, objfile
);
1412 case DW_TAG_ptr_to_member_type
:
1413 read_tag_ptr_to_member_type (die
, objfile
);
1415 case DW_TAG_reference_type
:
1416 read_tag_reference_type (die
, objfile
);
1418 case DW_TAG_string_type
:
1419 read_tag_string_type (die
, objfile
);
1421 case DW_TAG_base_type
:
1422 read_base_type (die
, objfile
);
1423 if (dwarf_attr (die
, DW_AT_name
))
1425 /* Add a typedef symbol for the base type definition. */
1426 new_symbol (die
, die
->type
, objfile
);
1429 case DW_TAG_common_block
:
1430 read_common_block (die
, objfile
);
1432 case DW_TAG_common_inclusion
:
1435 new_symbol (die
, NULL
, objfile
);
1441 read_file_scope (die
, objfile
)
1442 struct die_info
*die
;
1443 struct objfile
*objfile
;
1445 unsigned int line_offset
= 0;
1446 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1447 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1448 struct attribute
*attr
;
1449 char *name
= "<unknown>";
1450 char *comp_dir
= NULL
;
1451 struct die_info
*child_die
;
1452 bfd
*abfd
= objfile
->obfd
;
1454 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1456 if (die
->has_children
)
1458 child_die
= die
->next
;
1459 while (child_die
&& child_die
->tag
)
1461 if (child_die
->tag
== DW_TAG_subprogram
)
1463 CORE_ADDR low
, high
;
1465 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1467 lowpc
= min (lowpc
, low
);
1468 highpc
= max (highpc
, high
);
1471 child_die
= sibling_die (child_die
);
1476 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1477 from finish_block. */
1478 if (lowpc
== ((CORE_ADDR
) -1))
1483 attr
= dwarf_attr (die
, DW_AT_name
);
1486 name
= DW_STRING (attr
);
1488 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1491 comp_dir
= DW_STRING (attr
);
1494 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1495 directory, get rid of it. */
1496 char *cp
= strchr (comp_dir
, ':');
1498 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1503 if (objfile
->ei
.entry_point
>= lowpc
&&
1504 objfile
->ei
.entry_point
< highpc
)
1506 objfile
->ei
.entry_file_lowpc
= lowpc
;
1507 objfile
->ei
.entry_file_highpc
= highpc
;
1510 attr
= dwarf_attr (die
, DW_AT_language
);
1513 set_cu_language (DW_UNSND (attr
));
1516 /* We assume that we're processing GCC output. */
1517 processing_gcc_compilation
= 2;
1519 /* FIXME:Do something here. */
1520 if (dip
->at_producer
!= NULL
)
1522 handle_producer (dip
->at_producer
);
1526 /* The compilation unit may be in a different language or objfile,
1527 zero out all remembered fundamental types. */
1528 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1530 start_symtab (name
, comp_dir
, lowpc
);
1531 record_debugformat ("DWARF 2");
1533 /* Decode line number information if present. */
1534 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1537 line_offset
= DW_UNSND (attr
);
1538 dwarf_decode_lines (line_offset
, comp_dir
, abfd
);
1541 /* Process all dies in compilation unit. */
1542 if (die
->has_children
)
1544 child_die
= die
->next
;
1545 while (child_die
&& child_die
->tag
)
1547 process_die (child_die
, objfile
);
1548 child_die
= sibling_die (child_die
);
1554 read_func_scope (die
, objfile
)
1555 struct die_info
*die
;
1556 struct objfile
*objfile
;
1558 register struct context_stack
*new;
1561 struct die_info
*child_die
;
1562 struct attribute
*attr
;
1565 name
= dwarf2_linkage_name (die
);
1567 /* Ignore functions with missing or empty names and functions with
1568 missing or invalid low and high pc attributes. */
1569 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1575 if (objfile
->ei
.entry_point
>= lowpc
&&
1576 objfile
->ei
.entry_point
< highpc
)
1578 objfile
->ei
.entry_func_lowpc
= lowpc
;
1579 objfile
->ei
.entry_func_highpc
= highpc
;
1582 if (STREQ (name
, "main")) /* FIXME: hardwired name */
1584 objfile
->ei
.main_func_lowpc
= lowpc
;
1585 objfile
->ei
.main_func_highpc
= highpc
;
1588 /* Decode DW_AT_frame_base location descriptor if present, keep result
1589 for DW_OP_fbreg operands in decode_locdesc. */
1590 frame_base_reg
= -1;
1591 frame_base_offset
= 0;
1592 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1595 CORE_ADDR addr
= decode_locdesc (DW_BLOCK (attr
), objfile
);
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
)
1839 /* C++ static member.
1840 Get physical name, extract field name from physical name. */
1841 physname
= dwarf2_linkage_name (die
);
1842 if (physname
== NULL
)
1846 while (*cp
&& !is_cplus_marker (*cp
))
1850 if (*fieldname
== '\0')
1852 complain (&dwarf2_bad_static_member_name
, physname
);
1855 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
1856 &objfile
->type_obstack
));
1857 FIELD_TYPE (*fp
) = die_type (die
, objfile
);
1858 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
1859 &objfile
->type_obstack
);
1861 else if (die
->tag
== DW_TAG_inheritance
)
1863 /* C++ base class field. */
1864 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1866 FIELD_BITPOS (*fp
) = decode_locdesc (DW_BLOCK (attr
), objfile
) * bits_per_byte
;
1867 FIELD_BITSIZE (*fp
) = 0;
1868 FIELD_TYPE (*fp
) = die_type (die
, objfile
);
1869 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
1870 fip
->nbaseclasses
++;
1874 /* Create the vector of fields, and attach it to the type. */
1877 dwarf2_attach_fields_to_type (fip
, type
, objfile
)
1878 struct field_info
*fip
;
1880 struct objfile
*objfile
;
1882 int nfields
= fip
->nfields
;
1884 /* Record the field count, allocate space for the array of fields,
1885 and create blank accessibility bitfields if necessary. */
1886 TYPE_NFIELDS (type
) = nfields
;
1887 TYPE_FIELDS (type
) = (struct field
*)
1888 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
1889 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
1891 if (fip
->non_public_fields
)
1893 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1895 TYPE_FIELD_PRIVATE_BITS (type
) =
1896 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1897 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
1899 TYPE_FIELD_PROTECTED_BITS (type
) =
1900 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1901 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
1903 TYPE_FIELD_IGNORE_BITS (type
) =
1904 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1905 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
1908 /* If the type has baseclasses, allocate and clear a bit vector for
1909 TYPE_FIELD_VIRTUAL_BITS. */
1910 if (fip
->nbaseclasses
)
1912 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
1915 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1916 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
1917 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
1918 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
1919 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
1922 /* Copy the saved-up fields into the field vector. Start from the head
1923 of the list, adding to the tail of the field array, so that they end
1924 up in the same order in the array in which they were added to the list. */
1925 while (nfields
-- > 0)
1927 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
1928 switch (fip
->fields
->accessibility
)
1930 case DW_ACCESS_private
:
1931 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
1934 case DW_ACCESS_protected
:
1935 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
1938 case DW_ACCESS_public
:
1942 /* Unknown accessibility. Complain and treat it as public. */
1944 complain (&dwarf2_unsupported_accessibility
,
1945 fip
->fields
->accessibility
);
1949 if (nfields
< fip
->nbaseclasses
)
1951 switch (fip
->fields
->virtuality
)
1953 case DW_VIRTUALITY_virtual
:
1954 case DW_VIRTUALITY_pure_virtual
:
1955 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
1959 fip
->fields
= fip
->fields
->next
;
1963 /* Skip to the end of a member function name in a mangled name. */
1966 skip_member_fn_name (physname
)
1969 char *endname
= physname
;
1971 /* Skip over leading underscores. */
1972 while (*endname
== '_')
1975 /* Find two succesive underscores. */
1977 endname
= strchr (endname
, '_');
1978 while (endname
!= NULL
&& *++endname
!= '_');
1980 if (endname
== NULL
)
1982 complain (&dwarf2_bad_member_name_complaint
, physname
);
1987 /* Take care of trailing underscores. */
1988 if (endname
[1] != '_')
1994 /* Add a member function to the proper fieldlist. */
1997 dwarf2_add_member_fn (fip
, die
, type
, objfile
)
1998 struct field_info
*fip
;
1999 struct die_info
*die
;
2001 struct objfile
*objfile
;
2003 struct attribute
*attr
;
2004 struct fnfieldlist
*flp
;
2006 struct fn_field
*fnp
;
2009 struct nextfnfield
*new_fnfield
;
2011 /* Extract member function name from mangled name. */
2012 physname
= dwarf2_linkage_name (die
);
2013 if (physname
== NULL
)
2015 if ((physname
[0] == '_' && physname
[1] == '_'
2016 && strchr ("0123456789Qt", physname
[2]))
2017 || DESTRUCTOR_PREFIX_P (physname
))
2019 /* Constructor and destructor field names are set to the name
2020 of the class, but without template parameter lists.
2021 The name might be missing for anonymous aggregates. */
2022 if (TYPE_TAG_NAME (type
))
2024 char *p
= strchr (TYPE_TAG_NAME (type
), '<');
2027 fieldname
= TYPE_TAG_NAME (type
);
2029 fieldname
= obsavestring (TYPE_TAG_NAME (type
),
2030 p
- TYPE_TAG_NAME (type
),
2031 &objfile
->type_obstack
);
2035 char *anon_name
= "";
2036 fieldname
= obsavestring (anon_name
, strlen (anon_name
),
2037 &objfile
->type_obstack
);
2042 char *endname
= skip_member_fn_name (physname
);
2044 /* Ignore member function if we were unable not extract the member
2046 if (endname
== physname
)
2048 fieldname
= obsavestring (physname
, endname
- physname
,
2049 &objfile
->type_obstack
);
2052 /* Look up member function name in fieldlist. */
2053 for (i
= 0; i
< fip
->nfnfields
; i
++)
2055 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2059 /* Create new list element if necessary. */
2060 if (i
< fip
->nfnfields
)
2061 flp
= &fip
->fnfieldlists
[i
];
2064 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2066 fip
->fnfieldlists
= (struct fnfieldlist
*)
2067 xrealloc (fip
->fnfieldlists
,
2068 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2069 * sizeof (struct fnfieldlist
));
2070 if (fip
->nfnfields
== 0)
2071 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2073 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2074 flp
->name
= fieldname
;
2080 /* Create a new member function field and chain it to the field list
2082 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2083 make_cleanup (free
, new_fnfield
);
2084 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2085 new_fnfield
->next
= flp
->head
;
2086 flp
->head
= new_fnfield
;
2089 /* Fill in the member function field info. */
2090 fnp
= &new_fnfield
->fnfield
;
2091 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2092 &objfile
->type_obstack
);
2093 fnp
->type
= alloc_type (objfile
);
2094 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2096 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2097 struct type
**arg_types
;
2098 int nparams
= TYPE_NFIELDS (die
->type
);
2101 /* Copy argument types from the subroutine type. */
2102 arg_types
= (struct type
**)
2103 TYPE_ALLOC (fnp
->type
, (nparams
+ 1) * sizeof (struct type
*));
2104 for (iparams
= 0; iparams
< nparams
; iparams
++)
2105 arg_types
[iparams
] = TYPE_FIELD_TYPE (die
->type
, iparams
);
2107 /* Set last entry in argument type vector. */
2108 if (TYPE_FLAGS (die
->type
) & TYPE_FLAG_VARARGS
)
2109 arg_types
[nparams
] = NULL
;
2111 arg_types
[nparams
] = dwarf2_fundamental_type (objfile
, FT_VOID
);
2113 smash_to_method_type (fnp
->type
, type
, return_type
, arg_types
);
2115 /* Handle static member functions.
2116 Dwarf2 has no clean way to discern C++ static and non-static
2117 member functions. G++ helps GDB by marking the first
2118 parameter for non-static member functions (which is the
2119 this pointer) as artificial. We obtain this information
2120 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2121 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2122 fnp
->voffset
= VOFFSET_STATIC
;
2125 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2127 /* Get fcontext from DW_AT_containing_type if present. */
2128 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2129 fnp
->fcontext
= die_containing_type (die
, objfile
);
2131 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2132 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2134 /* Get accessibility. */
2135 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2138 switch (DW_UNSND (attr
))
2140 case DW_ACCESS_private
:
2141 fnp
->is_private
= 1;
2143 case DW_ACCESS_protected
:
2144 fnp
->is_protected
= 1;
2149 /* Get index in virtual function table if it is a virtual member function. */
2150 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2152 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
) + 2;
2155 /* Create the vector of member function fields, and attach it to the type. */
2158 dwarf2_attach_fn_fields_to_type (fip
, type
, objfile
)
2159 struct field_info
*fip
;
2161 struct objfile
*objfile
;
2163 struct fnfieldlist
*flp
;
2164 int total_length
= 0;
2167 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2168 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2169 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2171 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2173 struct nextfnfield
*nfp
= flp
->head
;
2174 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2177 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2178 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2179 fn_flp
->fn_fields
= (struct fn_field
*)
2180 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2181 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2182 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2184 total_length
+= flp
->length
;
2187 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2188 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2191 /* Called when we find the DIE that starts a structure or union scope
2192 (definition) to process all dies that define the members of the
2195 NOTE: we need to call struct_type regardless of whether or not the
2196 DIE has an at_name attribute, since it might be an anonymous
2197 structure or union. This gets the type entered into our set of
2200 However, if the structure is incomplete (an opaque struct/union)
2201 then suppress creating a symbol table entry for it since gdb only
2202 wants to find the one with the complete definition. Note that if
2203 it is complete, we just call new_symbol, which does it's own
2204 checking about whether the struct/union is anonymous or not (and
2205 suppresses creating a symbol table entry itself). */
2208 read_structure_scope (die
, objfile
)
2209 struct die_info
*die
;
2210 struct objfile
*objfile
;
2213 struct attribute
*attr
;
2215 type
= alloc_type (objfile
);
2217 INIT_CPLUS_SPECIFIC (type
);
2218 attr
= dwarf_attr (die
, DW_AT_name
);
2219 if (attr
&& DW_STRING (attr
))
2221 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2222 strlen (DW_STRING (attr
)),
2223 &objfile
->type_obstack
);
2226 if (die
->tag
== DW_TAG_structure_type
)
2228 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2230 else if (die
->tag
== DW_TAG_union_type
)
2232 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2236 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2238 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2241 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2244 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2248 TYPE_LENGTH (type
) = 0;
2251 /* We need to add the type field to the die immediately so we don't
2252 infinitely recurse when dealing with pointers to the structure
2253 type within the structure itself. */
2256 if (die
->has_children
)
2258 struct field_info fi
;
2259 struct die_info
*child_die
;
2260 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2262 memset (&fi
, 0, sizeof (struct field_info
));
2264 child_die
= die
->next
;
2266 while (child_die
&& child_die
->tag
)
2268 if (child_die
->tag
== DW_TAG_member
)
2270 dwarf2_add_field (&fi
, child_die
, objfile
);
2272 else if (child_die
->tag
== DW_TAG_variable
)
2274 /* C++ static member. */
2275 dwarf2_add_field (&fi
, child_die
, objfile
);
2277 else if (child_die
->tag
== DW_TAG_subprogram
)
2279 /* C++ member function. */
2280 process_die (child_die
, objfile
);
2281 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
);
2283 else if (child_die
->tag
== DW_TAG_inheritance
)
2285 /* C++ base class field. */
2286 dwarf2_add_field (&fi
, child_die
, objfile
);
2290 process_die (child_die
, objfile
);
2292 child_die
= sibling_die (child_die
);
2295 /* Attach fields and member functions to the type. */
2297 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2300 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2302 /* Get the type which refers to the base class (possibly this
2303 class itself) which contains the vtable pointer for the current
2304 class from the DW_AT_containing_type attribute. */
2306 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2308 struct type
*t
= die_containing_type (die
, objfile
);
2310 TYPE_VPTR_BASETYPE (type
) = t
;
2313 static const char vptr_name
[] = { '_','v','p','t','r','\0' };
2316 /* Our own class provides vtbl ptr. */
2317 for (i
= TYPE_NFIELDS (t
) - 1;
2318 i
>= TYPE_N_BASECLASSES (t
);
2321 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2323 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2324 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2326 TYPE_VPTR_FIELDNO (type
) = i
;
2331 /* Complain if virtual function table field not found. */
2332 if (i
< TYPE_N_BASECLASSES (t
))
2333 complain (&dwarf2_vtbl_not_found_complaint
,
2334 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2338 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2343 new_symbol (die
, type
, objfile
);
2345 do_cleanups (back_to
);
2349 /* No children, must be stub. */
2350 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2356 /* Given a pointer to a die which begins an enumeration, process all
2357 the dies that define the members of the enumeration.
2359 This will be much nicer in draft 6 of the DWARF spec when our
2360 members will be dies instead squished into the DW_AT_element_list
2363 NOTE: We reverse the order of the element list. */
2366 read_enumeration (die
, objfile
)
2367 struct die_info
*die
;
2368 struct objfile
*objfile
;
2370 struct die_info
*child_die
;
2372 struct field
*fields
;
2373 struct attribute
*attr
;
2376 int unsigned_enum
= 1;
2378 type
= alloc_type (objfile
);
2380 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2381 attr
= dwarf_attr (die
, DW_AT_name
);
2382 if (attr
&& DW_STRING (attr
))
2384 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2385 strlen (DW_STRING (attr
)),
2386 &objfile
->type_obstack
);
2389 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2392 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2396 TYPE_LENGTH (type
) = 0;
2401 if (die
->has_children
)
2403 child_die
= die
->next
;
2404 while (child_die
&& child_die
->tag
)
2406 if (child_die
->tag
!= DW_TAG_enumerator
)
2408 process_die (child_die
, objfile
);
2412 attr
= dwarf_attr (child_die
, DW_AT_name
);
2415 sym
= new_symbol (child_die
, type
, objfile
);
2416 if (SYMBOL_VALUE (sym
) < 0)
2419 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2421 fields
= (struct field
*)
2423 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2424 * sizeof (struct field
));
2427 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2428 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2429 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2430 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2436 child_die
= sibling_die (child_die
);
2441 TYPE_NFIELDS (type
) = num_fields
;
2442 TYPE_FIELDS (type
) = (struct field
*)
2443 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2444 memcpy (TYPE_FIELDS (type
), fields
,
2445 sizeof (struct field
) * num_fields
);
2449 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2452 new_symbol (die
, type
, objfile
);
2455 /* Extract all information from a DW_TAG_array_type DIE and put it in
2456 the DIE's type field. For now, this only handles one dimensional
2460 read_array_type (die
, objfile
)
2461 struct die_info
*die
;
2462 struct objfile
*objfile
;
2464 struct die_info
*child_die
;
2465 struct type
*type
= NULL
;
2466 struct type
*element_type
, *range_type
, *index_type
;
2467 struct type
**range_types
= NULL
;
2468 struct attribute
*attr
;
2470 struct cleanup
*back_to
;
2472 /* Return if we've already decoded this type. */
2478 element_type
= die_type (die
, objfile
);
2480 /* Irix 6.2 native cc creates array types without children for
2481 arrays with unspecified length. */
2482 if (die
->has_children
== 0)
2484 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2485 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2486 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2490 back_to
= make_cleanup (null_cleanup
, NULL
);
2491 child_die
= die
->next
;
2492 while (child_die
&& child_die
->tag
)
2494 if (child_die
->tag
== DW_TAG_subrange_type
)
2496 unsigned int low
, high
;
2498 /* Default bounds to an array with unspecified length. */
2501 if (cu_language
== language_fortran
)
2503 /* FORTRAN implies a lower bound of 1, if not given. */
2507 index_type
= die_type (child_die
, objfile
);
2508 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2511 if (attr
->form
== DW_FORM_sdata
)
2513 low
= DW_SND (attr
);
2515 else if (attr
->form
== DW_FORM_udata
2516 || attr
->form
== DW_FORM_data1
2517 || attr
->form
== DW_FORM_data2
2518 || attr
->form
== DW_FORM_data4
)
2520 low
= DW_UNSND (attr
);
2524 complain (&dwarf2_non_const_array_bound_ignored
,
2525 dwarf_form_name (attr
->form
));
2527 die
->type
= lookup_pointer_type (element_type
);
2534 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2537 if (attr
->form
== DW_FORM_sdata
)
2539 high
= DW_SND (attr
);
2541 else if (attr
->form
== DW_FORM_udata
2542 || attr
->form
== DW_FORM_data1
2543 || attr
->form
== DW_FORM_data2
2544 || attr
->form
== DW_FORM_data4
)
2546 high
= DW_UNSND (attr
);
2548 else if (attr
->form
== DW_FORM_block1
)
2550 /* GCC encodes arrays with unspecified or dynamic length
2551 with a DW_FORM_block1 attribute.
2552 FIXME: GDB does not yet know how to handle dynamic
2553 arrays properly, treat them as arrays with unspecified
2559 complain (&dwarf2_non_const_array_bound_ignored
,
2560 dwarf_form_name (attr
->form
));
2562 die
->type
= lookup_pointer_type (element_type
);
2570 /* Create a range type and save it for array type creation. */
2571 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2573 range_types
= (struct type
**)
2574 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2575 * sizeof (struct type
*));
2577 make_cleanup (free_current_contents
, &range_types
);
2579 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2581 child_die
= sibling_die (child_die
);
2584 /* Dwarf2 dimensions are output from left to right, create the
2585 necessary array types in backwards order. */
2586 type
= element_type
;
2588 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2590 do_cleanups (back_to
);
2592 /* Install the type in the die. */
2596 /* First cut: install each common block member as a global variable. */
2599 read_common_block (die
, objfile
)
2600 struct die_info
*die
;
2601 struct objfile
*objfile
;
2603 struct die_info
*child_die
;
2604 struct attribute
*attr
;
2606 CORE_ADDR base
= (CORE_ADDR
) 0;
2608 attr
= dwarf_attr (die
, DW_AT_location
);
2611 base
= decode_locdesc (DW_BLOCK (attr
), objfile
);
2613 if (die
->has_children
)
2615 child_die
= die
->next
;
2616 while (child_die
&& child_die
->tag
)
2618 sym
= new_symbol (child_die
, NULL
, objfile
);
2619 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2622 SYMBOL_VALUE_ADDRESS (sym
) =
2623 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
);
2624 add_symbol_to_list (sym
, &global_symbols
);
2626 child_die
= sibling_die (child_die
);
2631 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2632 the user defined type vector. */
2635 read_tag_pointer_type (die
, objfile
)
2636 struct die_info
*die
;
2637 struct objfile
*objfile
;
2640 struct attribute
*attr
;
2647 type
= lookup_pointer_type (die_type (die
, objfile
));
2648 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2651 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2655 TYPE_LENGTH (type
) = address_size
;
2660 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2661 the user defined type vector. */
2664 read_tag_ptr_to_member_type (die
, objfile
)
2665 struct die_info
*die
;
2666 struct objfile
*objfile
;
2669 struct type
*to_type
;
2670 struct type
*domain
;
2677 type
= alloc_type (objfile
);
2678 to_type
= die_type (die
, objfile
);
2679 domain
= die_containing_type (die
, objfile
);
2680 smash_to_member_type (type
, domain
, to_type
);
2685 /* Extract all information from a DW_TAG_reference_type DIE and add to
2686 the user defined type vector. */
2689 read_tag_reference_type (die
, objfile
)
2690 struct die_info
*die
;
2691 struct objfile
*objfile
;
2694 struct attribute
*attr
;
2701 type
= lookup_reference_type (die_type (die
, objfile
));
2702 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2705 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2709 TYPE_LENGTH (type
) = address_size
;
2715 read_tag_const_type (die
, objfile
)
2716 struct die_info
*die
;
2717 struct objfile
*objfile
;
2724 complain (&dwarf2_const_ignored
);
2725 die
->type
= die_type (die
, objfile
);
2729 read_tag_volatile_type (die
, objfile
)
2730 struct die_info
*die
;
2731 struct objfile
*objfile
;
2738 complain (&dwarf2_volatile_ignored
);
2739 die
->type
= die_type (die
, objfile
);
2742 /* Extract all information from a DW_TAG_string_type DIE and add to
2743 the user defined type vector. It isn't really a user defined type,
2744 but it behaves like one, with other DIE's using an AT_user_def_type
2745 attribute to reference it. */
2748 read_tag_string_type (die
, objfile
)
2749 struct die_info
*die
;
2750 struct objfile
*objfile
;
2752 struct type
*type
, *range_type
, *index_type
, *char_type
;
2753 struct attribute
*attr
;
2754 unsigned int length
;
2761 attr
= dwarf_attr (die
, DW_AT_string_length
);
2764 length
= DW_UNSND (attr
);
2770 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2771 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2772 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2773 type
= create_string_type (char_type
, range_type
);
2777 /* Handle DIES due to C code like:
2781 int (*funcp)(int a, long l);
2785 ('funcp' generates a DW_TAG_subroutine_type DIE)
2789 read_subroutine_type (die
, objfile
)
2790 struct die_info
*die
;
2791 struct objfile
*objfile
;
2793 struct type
*type
; /* Type that this function returns */
2794 struct type
*ftype
; /* Function that returns above type */
2795 struct attribute
*attr
;
2797 /* Decode the type that this subroutine returns */
2802 type
= die_type (die
, objfile
);
2803 ftype
= lookup_function_type (type
);
2804 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2805 if (attr
&& (DW_UNSND (attr
) != 0))
2806 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2808 if (die
->has_children
)
2810 struct die_info
*child_die
;
2814 /* Count the number of parameters.
2815 FIXME: GDB currently ignores vararg functions, but knows about
2816 vararg member functions. */
2817 child_die
= die
->next
;
2818 while (child_die
&& child_die
->tag
)
2820 if (child_die
->tag
== DW_TAG_formal_parameter
)
2822 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2823 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2824 child_die
= sibling_die (child_die
);
2827 /* Allocate storage for parameters and fill them in. */
2828 TYPE_NFIELDS (ftype
) = nparams
;
2829 TYPE_FIELDS (ftype
) = (struct field
*)
2830 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2832 child_die
= die
->next
;
2833 while (child_die
&& child_die
->tag
)
2835 if (child_die
->tag
== DW_TAG_formal_parameter
)
2837 /* Dwarf2 has no clean way to discern C++ static and non-static
2838 member functions. G++ helps GDB by marking the first
2839 parameter for non-static member functions (which is the
2840 this pointer) as artificial. We pass this information
2841 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2842 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
2844 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
2846 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
2847 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
);
2850 child_die
= sibling_die (child_die
);
2858 read_typedef (die
, objfile
)
2859 struct die_info
*die
;
2860 struct objfile
*objfile
;
2866 struct attribute
*attr
;
2869 xtype
= die_type (die
, objfile
);
2871 type
= alloc_type (objfile
);
2872 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2873 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2874 TYPE_TARGET_TYPE (type
) = xtype
;
2875 attr
= dwarf_attr (die
, DW_AT_name
);
2876 if (attr
&& DW_STRING (attr
))
2877 TYPE_NAME (type
) = obsavestring (DW_STRING (attr
),
2878 strlen (DW_STRING (attr
)),
2879 &objfile
->type_obstack
);
2885 /* Find a representation of a given base type and install
2886 it in the TYPE field of the die. */
2889 read_base_type (die
, objfile
)
2890 struct die_info
*die
;
2891 struct objfile
*objfile
;
2894 struct attribute
*attr
;
2895 int encoding
= 0, size
= 0;
2897 /* If we've already decoded this die, this is a no-op. */
2903 attr
= dwarf_attr (die
, DW_AT_encoding
);
2906 encoding
= DW_UNSND (attr
);
2908 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2911 size
= DW_UNSND (attr
);
2913 attr
= dwarf_attr (die
, DW_AT_name
);
2914 if (attr
&& DW_STRING (attr
))
2916 enum type_code code
= TYPE_CODE_INT
;
2917 int is_unsigned
= 0;
2921 case DW_ATE_address
:
2922 /* Turn DW_ATE_address into a void * pointer. */
2923 code
= TYPE_CODE_PTR
;
2926 case DW_ATE_boolean
:
2927 code
= TYPE_CODE_BOOL
;
2930 case DW_ATE_complex_float
:
2931 code
= TYPE_CODE_COMPLEX
;
2934 code
= TYPE_CODE_FLT
;
2937 case DW_ATE_signed_char
:
2939 case DW_ATE_unsigned
:
2940 case DW_ATE_unsigned_char
:
2944 complain (&dwarf2_unsupported_at_encoding
,
2945 dwarf_type_encoding_name (encoding
));
2948 type
= init_type (code
, size
, is_unsigned
, DW_STRING (attr
), objfile
);
2949 if (encoding
== DW_ATE_address
)
2950 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
2954 type
= dwarf_base_type (encoding
, size
, objfile
);
2959 /* Read a whole compilation unit into a linked list of dies. */
2962 read_comp_unit (info_ptr
, abfd
)
2966 struct die_info
*first_die
, *last_die
, *die
;
2970 /* Reset die reference table, we are building a new one now. */
2971 dwarf2_empty_die_ref_table ();
2975 first_die
= last_die
= NULL
;
2978 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
);
2979 if (die
->has_children
)
2990 /* Enter die in reference hash table */
2991 store_in_ref_table (die
->offset
, die
);
2995 first_die
= last_die
= die
;
2999 last_die
->next
= die
;
3003 while (nesting_level
> 0);
3007 /* Free a linked list of dies. */
3010 free_die_list (dies
)
3011 struct die_info
*dies
;
3013 struct die_info
*die
, *next
;
3025 /* Read the contents of the section at OFFSET and of size SIZE from the
3026 object file specified by OBJFILE into the psymbol_obstack and return it. */
3029 dwarf2_read_section (objfile
, offset
, size
)
3030 struct objfile
*objfile
;
3034 bfd
*abfd
= objfile
->obfd
;
3040 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3041 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
3042 (bfd_read (buf
, size
, 1, abfd
) != size
))
3045 error ("Dwarf Error: Can't read DWARF data from '%s'",
3046 bfd_get_filename (abfd
));
3051 /* In DWARF version 2, the description of the debugging information is
3052 stored in a separate .debug_abbrev section. Before we read any
3053 dies from a section we read in all abbreviations and install them
3057 dwarf2_read_abbrevs (abfd
, offset
)
3059 unsigned int offset
;
3062 struct abbrev_info
*cur_abbrev
;
3063 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3064 unsigned int abbrev_form
, hash_number
;
3066 /* empty the table */
3067 dwarf2_empty_abbrev_table (NULL
);
3069 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3070 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3071 abbrev_ptr
+= bytes_read
;
3073 /* loop until we reach an abbrev number of 0 */
3074 while (abbrev_number
)
3076 cur_abbrev
= dwarf_alloc_abbrev ();
3078 /* read in abbrev header */
3079 cur_abbrev
->number
= abbrev_number
;
3080 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3081 abbrev_ptr
+= bytes_read
;
3082 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3085 /* now read in declarations */
3086 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3087 abbrev_ptr
+= bytes_read
;
3088 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3089 abbrev_ptr
+= bytes_read
;
3092 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3094 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3095 xrealloc (cur_abbrev
->attrs
,
3096 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3097 * sizeof (struct attr_abbrev
));
3099 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3100 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3101 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3102 abbrev_ptr
+= bytes_read
;
3103 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3104 abbrev_ptr
+= bytes_read
;
3107 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3108 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3109 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3111 /* Get next abbreviation.
3112 Under Irix6 the abbreviations for a compilation unit are not
3113 always properly terminated with an abbrev number of 0.
3114 Exit loop if we encounter an abbreviation which we have
3115 already read (which means we are about to read the abbreviations
3116 for the next compile unit) or if the end of the abbreviation
3117 table is reached. */
3118 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3119 >= dwarf_abbrev_size
)
3121 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3122 abbrev_ptr
+= bytes_read
;
3123 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3128 /* Empty the abbrev table for a new compilation unit. */
3132 dwarf2_empty_abbrev_table (ignore
)
3136 struct abbrev_info
*abbrev
, *next
;
3138 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3141 abbrev
= dwarf2_abbrevs
[i
];
3144 next
= abbrev
->next
;
3145 free (abbrev
->attrs
);
3149 dwarf2_abbrevs
[i
] = NULL
;
3153 /* Lookup an abbrev_info structure in the abbrev hash table. */
3155 static struct abbrev_info
*
3156 dwarf2_lookup_abbrev (number
)
3157 unsigned int number
;
3159 unsigned int hash_number
;
3160 struct abbrev_info
*abbrev
;
3162 hash_number
= number
% ABBREV_HASH_SIZE
;
3163 abbrev
= dwarf2_abbrevs
[hash_number
];
3167 if (abbrev
->number
== number
)
3170 abbrev
= abbrev
->next
;
3175 /* Read a minimal amount of information into the minimal die structure. */
3178 read_partial_die (part_die
, abfd
, info_ptr
, has_pc_info
)
3179 struct partial_die_info
*part_die
;
3184 unsigned int abbrev_number
, bytes_read
, i
;
3185 struct abbrev_info
*abbrev
;
3186 struct attribute attr
;
3187 struct attribute spec_attr
;
3188 int found_spec_attr
= 0;
3189 int has_low_pc_attr
= 0;
3190 int has_high_pc_attr
= 0;
3192 *part_die
= zeroed_partial_die
;
3194 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3195 info_ptr
+= bytes_read
;
3199 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3202 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3204 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3205 part_die
->tag
= abbrev
->tag
;
3206 part_die
->has_children
= abbrev
->has_children
;
3207 part_die
->abbrev
= abbrev_number
;
3209 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3211 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
);
3213 /* Store the data if it is of an attribute we want to keep in a
3214 partial symbol table. */
3219 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3220 if (part_die
->name
== NULL
)
3221 part_die
->name
= DW_STRING (&attr
);
3223 case DW_AT_MIPS_linkage_name
:
3224 part_die
->name
= DW_STRING (&attr
);
3227 has_low_pc_attr
= 1;
3228 part_die
->lowpc
= DW_ADDR (&attr
);
3231 has_high_pc_attr
= 1;
3232 part_die
->highpc
= DW_ADDR (&attr
);
3234 case DW_AT_location
:
3235 part_die
->locdesc
= DW_BLOCK (&attr
);
3237 case DW_AT_language
:
3238 part_die
->language
= DW_UNSND (&attr
);
3240 case DW_AT_external
:
3241 part_die
->is_external
= DW_UNSND (&attr
);
3243 case DW_AT_declaration
:
3244 part_die
->is_declaration
= DW_UNSND (&attr
);
3247 part_die
->has_type
= 1;
3249 case DW_AT_abstract_origin
:
3250 case DW_AT_specification
:
3251 found_spec_attr
= 1;
3255 /* Ignore absolute siblings, they might point outside of
3256 the current compile unit. */
3257 if (attr
.form
== DW_FORM_ref_addr
)
3258 complain(&dwarf2_absolute_sibling_complaint
);
3261 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3268 /* If we found a reference attribute and the die has no name, try
3269 to find a name in the referred to die. */
3271 if (found_spec_attr
&& part_die
->name
== NULL
)
3273 struct partial_die_info spec_die
;
3277 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3278 read_partial_die (&spec_die
, abfd
, spec_ptr
, &dummy
);
3281 part_die
->name
= spec_die
.name
;
3283 /* Copy DW_AT_external attribute if it is set. */
3284 if (spec_die
.is_external
)
3285 part_die
->is_external
= spec_die
.is_external
;
3289 /* When using the GNU linker, .gnu.linkonce. sections are used to
3290 eliminate duplicate copies of functions and vtables and such.
3291 The linker will arbitrarily choose one and discard the others.
3292 The AT_*_pc values for such functions refer to local labels in
3293 these sections. If the section from that file was discarded, the
3294 labels are not in the output, so the relocs get a value of 0.
3295 If this is a discarded function, mark the pc bounds as invalid,
3296 so that GDB will ignore it. */
3297 if (has_low_pc_attr
&& has_high_pc_attr
3298 && part_die
->lowpc
< part_die
->highpc
3299 && (part_die
->lowpc
!= 0
3300 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3305 /* Read the die from the .debug_info section buffer. And set diep to
3306 point to a newly allocated die with its information. */
3309 read_full_die (diep
, abfd
, info_ptr
)
3310 struct die_info
**diep
;
3314 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3315 struct abbrev_info
*abbrev
;
3316 struct die_info
*die
;
3318 offset
= info_ptr
- dwarf_info_buffer
;
3319 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3320 info_ptr
+= bytes_read
;
3323 die
= dwarf_alloc_die ();
3325 die
->abbrev
= abbrev_number
;
3331 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3334 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3336 die
= dwarf_alloc_die ();
3337 die
->offset
= offset
;
3338 die
->tag
= abbrev
->tag
;
3339 die
->has_children
= abbrev
->has_children
;
3340 die
->abbrev
= abbrev_number
;
3343 die
->num_attrs
= abbrev
->num_attrs
;
3344 die
->attrs
= (struct attribute
*)
3345 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3347 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3349 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3357 /* Read an attribute described by an abbreviated attribute. */
3360 read_attribute (attr
, abbrev
, abfd
, info_ptr
)
3361 struct attribute
*attr
;
3362 struct attr_abbrev
*abbrev
;
3366 unsigned int bytes_read
;
3367 struct dwarf_block
*blk
;
3369 attr
->name
= abbrev
->name
;
3370 attr
->form
= abbrev
->form
;
3371 switch (abbrev
->form
)
3374 case DW_FORM_ref_addr
:
3375 DW_ADDR (attr
) = read_address (abfd
, info_ptr
);
3376 info_ptr
+= address_size
;
3378 case DW_FORM_block2
:
3379 blk
= dwarf_alloc_block ();
3380 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3382 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3383 info_ptr
+= blk
->size
;
3384 DW_BLOCK (attr
) = blk
;
3386 case DW_FORM_block4
:
3387 blk
= dwarf_alloc_block ();
3388 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3390 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3391 info_ptr
+= blk
->size
;
3392 DW_BLOCK (attr
) = blk
;
3395 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3399 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3403 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3406 case DW_FORM_string
:
3407 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3408 info_ptr
+= bytes_read
;
3411 blk
= dwarf_alloc_block ();
3412 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3413 info_ptr
+= bytes_read
;
3414 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3415 info_ptr
+= blk
->size
;
3416 DW_BLOCK (attr
) = blk
;
3418 case DW_FORM_block1
:
3419 blk
= dwarf_alloc_block ();
3420 blk
->size
= read_1_byte (abfd
, info_ptr
);
3422 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3423 info_ptr
+= blk
->size
;
3424 DW_BLOCK (attr
) = blk
;
3427 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3431 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3435 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3436 info_ptr
+= bytes_read
;
3439 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3440 info_ptr
+= bytes_read
;
3443 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3447 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3451 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3454 case DW_FORM_ref_udata
:
3455 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3456 info_ptr
+= bytes_read
;
3459 case DW_FORM_indirect
:
3461 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3462 dwarf_form_name (abbrev
->form
));
3467 /* read dwarf information from a buffer */
3470 read_1_byte (abfd
, buf
)
3474 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3478 read_1_signed_byte (abfd
, buf
)
3482 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3486 read_2_bytes (abfd
, buf
)
3490 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3494 read_2_signed_bytes (abfd
, buf
)
3498 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3502 read_4_bytes (abfd
, buf
)
3506 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3510 read_4_signed_bytes (abfd
, buf
)
3514 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3518 read_8_bytes (abfd
, buf
)
3522 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3526 read_address (abfd
, buf
)
3530 CORE_ADDR retval
= 0;
3532 switch (address_size
)
3535 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3538 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3541 /* *THE* alternative is 8, right? */
3544 /* If the address being read is larger than the address that is
3545 applicable for the object file format then mask it down to the
3546 correct size. Take care to avoid unnecessary shift or shift
3548 if (address_size
> address_significant_size
3549 && address_significant_size
< sizeof (CORE_ADDR
))
3551 CORE_ADDR mask
= ((CORE_ADDR
) 0) - 1;
3552 retval
&= ~(mask
<< (address_significant_size
* 8));
3558 read_n_bytes (abfd
, buf
, size
)
3563 /* If the size of a host char is 8 bits, we can return a pointer
3564 to the buffer, otherwise we have to copy the data to a buffer
3565 allocated on the temporary obstack. */
3566 #if HOST_CHAR_BIT == 8
3572 ret
= obstack_alloc (&dwarf2_tmp_obstack
, size
);
3573 for (i
= 0; i
< size
; ++i
)
3575 ret
[i
] = bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3583 read_string (abfd
, buf
, bytes_read_ptr
)
3586 unsigned int *bytes_read_ptr
;
3588 /* If the size of a host char is 8 bits, we can return a pointer
3589 to the string, otherwise we have to copy the string to a buffer
3590 allocated on the temporary obstack. */
3591 #if HOST_CHAR_BIT == 8
3594 *bytes_read_ptr
= 1;
3597 *bytes_read_ptr
= strlen (buf
) + 1;
3603 while ((byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
)) != 0)
3605 obstack_1grow (&dwarf2_tmp_obstack
, byte
);
3611 *bytes_read_ptr
= 1;
3614 obstack_1grow (&dwarf2_tmp_obstack
, '\0');
3615 *bytes_read_ptr
= i
+ 1;
3616 return obstack_finish (&dwarf2_tmp_obstack
);
3621 read_unsigned_leb128 (abfd
, buf
, bytes_read_ptr
)
3624 unsigned int *bytes_read_ptr
;
3626 unsigned int result
, num_read
;
3636 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3639 result
|= ((byte
& 127) << shift
);
3640 if ((byte
& 128) == 0)
3646 *bytes_read_ptr
= num_read
;
3651 read_signed_leb128 (abfd
, buf
, bytes_read_ptr
)
3654 unsigned int *bytes_read_ptr
;
3657 int i
, shift
, size
, num_read
;
3667 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3670 result
|= ((byte
& 127) << shift
);
3672 if ((byte
& 128) == 0)
3677 if ((shift
< size
) && (byte
& 0x40))
3679 result
|= -(1 << shift
);
3681 *bytes_read_ptr
= num_read
;
3686 set_cu_language (lang
)
3693 cu_language
= language_c
;
3695 case DW_LANG_C_plus_plus
:
3696 cu_language
= language_cplus
;
3698 case DW_LANG_Fortran77
:
3699 case DW_LANG_Fortran90
:
3700 cu_language
= language_fortran
;
3702 case DW_LANG_Mips_Assembler
:
3703 cu_language
= language_asm
;
3706 case DW_LANG_Cobol74
:
3707 case DW_LANG_Cobol85
:
3708 case DW_LANG_Pascal83
:
3709 case DW_LANG_Modula2
:
3711 cu_language
= language_unknown
;
3714 cu_language_defn
= language_def (cu_language
);
3717 /* Return the named attribute or NULL if not there. */
3719 static struct attribute
*
3720 dwarf_attr (die
, name
)
3721 struct die_info
*die
;
3725 struct attribute
*spec
= NULL
;
3727 for (i
= 0; i
< die
->num_attrs
; ++i
)
3729 if (die
->attrs
[i
].name
== name
)
3731 return &die
->attrs
[i
];
3733 if (die
->attrs
[i
].name
== DW_AT_specification
3734 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3735 spec
= &die
->attrs
[i
];
3739 struct die_info
*ref_die
=
3740 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3743 return dwarf_attr (ref_die
, name
);
3749 /* Decode the line number information for the compilation unit whose
3750 line number info is at OFFSET in the .debug_line section.
3751 The compilation directory of the file is passed in COMP_DIR. */
3755 unsigned int num_files
;
3768 unsigned int num_dirs
;
3773 dwarf_decode_lines (offset
, comp_dir
, abfd
)
3774 unsigned int offset
;
3780 struct line_head lh
;
3781 struct cleanup
*back_to
;
3782 unsigned int i
, bytes_read
;
3783 char *cur_file
, *cur_dir
;
3784 unsigned char op_code
, extended_op
, adj_opcode
;
3786 #define FILE_ALLOC_CHUNK 5
3787 #define DIR_ALLOC_CHUNK 5
3789 struct filenames files
;
3790 struct directories dirs
;
3792 if (dwarf_line_buffer
== NULL
)
3794 complain (&dwarf2_missing_line_number_section
);
3798 files
.num_files
= 0;
3804 line_ptr
= dwarf_line_buffer
+ offset
;
3806 /* read in the prologue */
3807 lh
.total_length
= read_4_bytes (abfd
, line_ptr
);
3809 line_end
= line_ptr
+ lh
.total_length
;
3810 lh
.version
= read_2_bytes (abfd
, line_ptr
);
3812 lh
.prologue_length
= read_4_bytes (abfd
, line_ptr
);
3814 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
3816 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
3818 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
3820 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
3822 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
3824 lh
.standard_opcode_lengths
= (unsigned char *)
3825 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
3826 back_to
= make_cleanup (free_current_contents
, &lh
.standard_opcode_lengths
);
3828 lh
.standard_opcode_lengths
[0] = 1;
3829 for (i
= 1; i
< lh
.opcode_base
; ++i
)
3831 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
3835 /* Read directory table */
3836 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3838 line_ptr
+= bytes_read
;
3839 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
3841 dirs
.dirs
= (char **)
3842 xrealloc (dirs
.dirs
,
3843 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
3844 if (dirs
.num_dirs
== 0)
3845 make_cleanup (free_current_contents
, &dirs
.dirs
);
3847 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
3849 line_ptr
+= bytes_read
;
3851 /* Read file name table */
3852 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3854 line_ptr
+= bytes_read
;
3855 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3857 files
.files
= (struct fileinfo
*)
3858 xrealloc (files
.files
,
3859 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3860 * sizeof (struct fileinfo
));
3861 if (files
.num_files
== 0)
3862 make_cleanup (free_current_contents
, &files
.files
);
3864 files
.files
[files
.num_files
].name
= cur_file
;
3865 files
.files
[files
.num_files
].dir
=
3866 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3867 line_ptr
+= bytes_read
;
3868 files
.files
[files
.num_files
].time
=
3869 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3870 line_ptr
+= bytes_read
;
3871 files
.files
[files
.num_files
].size
=
3872 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3873 line_ptr
+= bytes_read
;
3876 line_ptr
+= bytes_read
;
3878 /* Read the statement sequences until there's nothing left. */
3879 while (line_ptr
< line_end
)
3881 /* state machine registers */
3882 CORE_ADDR address
= 0;
3883 unsigned int file
= 1;
3884 unsigned int line
= 1;
3885 unsigned int column
= 0;
3886 int is_stmt
= lh
.default_is_stmt
;
3887 int basic_block
= 0;
3888 int end_sequence
= 0;
3890 /* Start a subfile for the current file of the state machine. */
3891 if (files
.num_files
>= file
)
3893 /* The file and directory tables are 0 based, the references
3895 dwarf2_start_subfile (files
.files
[file
- 1].name
,
3896 (files
.files
[file
- 1].dir
3897 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3901 /* Decode the table. */
3902 while (! end_sequence
)
3904 op_code
= read_1_byte (abfd
, line_ptr
);
3908 case DW_LNS_extended_op
:
3909 line_ptr
+= 1; /* ignore length */
3910 extended_op
= read_1_byte (abfd
, line_ptr
);
3912 switch (extended_op
)
3914 case DW_LNE_end_sequence
:
3916 record_line (current_subfile
, line
, address
);
3918 case DW_LNE_set_address
:
3919 address
= read_address (abfd
, line_ptr
) + baseaddr
;
3920 line_ptr
+= address_size
;
3922 case DW_LNE_define_file
:
3923 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
3924 line_ptr
+= bytes_read
;
3925 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3927 files
.files
= (struct fileinfo
*)
3928 xrealloc (files
.files
,
3929 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3930 * sizeof (struct fileinfo
));
3931 if (files
.num_files
== 0)
3932 make_cleanup (free_current_contents
, &files
.files
);
3934 files
.files
[files
.num_files
].name
= cur_file
;
3935 files
.files
[files
.num_files
].dir
=
3936 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3937 line_ptr
+= bytes_read
;
3938 files
.files
[files
.num_files
].time
=
3939 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3940 line_ptr
+= bytes_read
;
3941 files
.files
[files
.num_files
].size
=
3942 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3943 line_ptr
+= bytes_read
;
3947 complain (&dwarf2_mangled_line_number_section
);
3952 record_line (current_subfile
, line
, address
);
3955 case DW_LNS_advance_pc
:
3956 address
+= lh
.minimum_instruction_length
3957 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3958 line_ptr
+= bytes_read
;
3960 case DW_LNS_advance_line
:
3961 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
3962 line_ptr
+= bytes_read
;
3964 case DW_LNS_set_file
:
3965 /* The file and directory tables are 0 based, the references
3967 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3968 line_ptr
+= bytes_read
;
3969 dwarf2_start_subfile
3970 (files
.files
[file
- 1].name
,
3971 (files
.files
[file
- 1].dir
3972 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3975 case DW_LNS_set_column
:
3976 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3977 line_ptr
+= bytes_read
;
3979 case DW_LNS_negate_stmt
:
3980 is_stmt
= (!is_stmt
);
3982 case DW_LNS_set_basic_block
:
3985 case DW_LNS_const_add_pc
:
3986 address
+= (255 - lh
.opcode_base
) / lh
.line_range
;
3988 case DW_LNS_fixed_advance_pc
:
3989 address
+= read_2_bytes (abfd
, line_ptr
);
3992 default: /* special operand */
3993 adj_opcode
= op_code
- lh
.opcode_base
;
3994 address
+= (adj_opcode
/ lh
.line_range
)
3995 * lh
.minimum_instruction_length
;
3996 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
3997 /* append row to matrix using current values */
3998 record_line (current_subfile
, line
, address
);
4004 do_cleanups (back_to
);
4007 /* Start a subfile for DWARF. FILENAME is the name of the file and
4008 DIRNAME the name of the source directory which contains FILENAME
4009 or NULL if not known.
4010 This routine tries to keep line numbers from identical absolute and
4011 relative file names in a common subfile.
4013 Using the `list' example from the GDB testsuite, which resides in
4014 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4015 of /srcdir/list0.c yields the following debugging information for list0.c:
4017 DW_AT_name: /srcdir/list0.c
4018 DW_AT_comp_dir: /compdir
4019 files.files[0].name: list0.h
4020 files.files[0].dir: /srcdir
4021 files.files[1].name: list0.c
4022 files.files[1].dir: /srcdir
4024 The line number information for list0.c has to end up in a single
4025 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4028 dwarf2_start_subfile (filename
, dirname
)
4032 /* If the filename isn't absolute, try to match an existing subfile
4033 with the full pathname. */
4035 if (*filename
!= '/' && dirname
!= NULL
)
4037 struct subfile
*subfile
;
4038 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4040 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4042 if (STREQ (subfile
->name
, fullname
))
4044 current_subfile
= subfile
;
4051 start_subfile (filename
, dirname
);
4054 /* Given a pointer to a DWARF information entry, figure out if we need
4055 to make a symbol table entry for it, and if so, create a new entry
4056 and return a pointer to it.
4057 If TYPE is NULL, determine symbol type from the die, otherwise
4058 used the passed type.
4061 static struct symbol
*
4062 new_symbol (die
, type
, objfile
)
4063 struct die_info
*die
;
4065 struct objfile
*objfile
;
4067 struct symbol
*sym
= NULL
;
4069 struct attribute
*attr
= NULL
;
4070 struct attribute
*attr2
= NULL
;
4073 name
= dwarf2_linkage_name (die
);
4076 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4077 sizeof (struct symbol
));
4078 OBJSTAT (objfile
, n_syms
++);
4079 memset (sym
, 0, sizeof (struct symbol
));
4080 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4081 &objfile
->symbol_obstack
);
4083 /* Default assumptions.
4084 Use the passed type or decode it from the die. */
4085 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4086 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4088 SYMBOL_TYPE (sym
) = type
;
4090 SYMBOL_TYPE (sym
) = die_type (die
, objfile
);
4091 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4094 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4097 /* If this symbol is from a C++ compilation, then attempt to
4098 cache the demangled form for future reference. This is a
4099 typical time versus space tradeoff, that was decided in favor
4100 of time because it sped up C++ symbol lookups by a factor of
4103 SYMBOL_LANGUAGE (sym
) = cu_language
;
4104 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4108 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4111 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4113 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4115 case DW_TAG_subprogram
:
4116 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4118 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4119 attr2
= dwarf_attr (die
, DW_AT_external
);
4120 if (attr2
&& (DW_UNSND (attr2
) != 0))
4122 add_symbol_to_list (sym
, &global_symbols
);
4126 add_symbol_to_list (sym
, list_in_scope
);
4129 case DW_TAG_variable
:
4130 /* Compilation with minimal debug info may result in variables
4131 with missing type entries. Change the misleading `void' type
4132 to something sensible. */
4133 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4134 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4135 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4136 "<variable, no debug info>",
4138 attr
= dwarf_attr (die
, DW_AT_const_value
);
4141 dwarf2_const_value (attr
, sym
, objfile
);
4142 attr2
= dwarf_attr (die
, DW_AT_external
);
4143 if (attr2
&& (DW_UNSND (attr2
) != 0))
4144 add_symbol_to_list (sym
, &global_symbols
);
4146 add_symbol_to_list (sym
, list_in_scope
);
4149 attr
= dwarf_attr (die
, DW_AT_location
);
4152 attr2
= dwarf_attr (die
, DW_AT_external
);
4153 if (attr2
&& (DW_UNSND (attr2
) != 0))
4155 SYMBOL_VALUE_ADDRESS (sym
) =
4156 decode_locdesc (DW_BLOCK (attr
), objfile
);
4157 add_symbol_to_list (sym
, &global_symbols
);
4159 /* In shared libraries the address of the variable
4160 in the location descriptor might still be relocatable,
4161 so its value could be zero.
4162 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4163 value is zero, the address of the variable will then
4164 be determined from the minimal symbol table whenever
4165 the variable is referenced. */
4166 if (SYMBOL_VALUE_ADDRESS (sym
))
4168 SYMBOL_VALUE_ADDRESS (sym
) += baseaddr
;
4169 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4172 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4176 SYMBOL_VALUE (sym
) = addr
=
4177 decode_locdesc (DW_BLOCK (attr
), objfile
);
4178 add_symbol_to_list (sym
, list_in_scope
);
4181 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4185 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4189 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4190 SYMBOL_BASEREG (sym
) = basereg
;
4194 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4198 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4199 SYMBOL_VALUE_ADDRESS (sym
) = addr
+ baseaddr
;
4205 /* We do not know the address of this symbol.
4206 If it is an external symbol and we have type information
4207 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4208 The address of the variable will then be determined from
4209 the minimal symbol table whenever the variable is
4211 attr2
= dwarf_attr (die
, DW_AT_external
);
4212 if (attr2
&& (DW_UNSND (attr2
) != 0)
4213 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4215 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4216 add_symbol_to_list (sym
, &global_symbols
);
4220 case DW_TAG_formal_parameter
:
4221 attr
= dwarf_attr (die
, DW_AT_location
);
4224 SYMBOL_VALUE (sym
) = decode_locdesc (DW_BLOCK (attr
), objfile
);
4227 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4231 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4232 SYMBOL_BASEREG (sym
) = basereg
;
4236 SYMBOL_CLASS (sym
) = LOC_ARG
;
4239 attr
= dwarf_attr (die
, DW_AT_const_value
);
4242 dwarf2_const_value (attr
, sym
, objfile
);
4244 add_symbol_to_list (sym
, list_in_scope
);
4246 case DW_TAG_unspecified_parameters
:
4247 /* From varargs functions; gdb doesn't seem to have any
4248 interest in this information, so just ignore it for now.
4251 case DW_TAG_class_type
:
4252 case DW_TAG_structure_type
:
4253 case DW_TAG_union_type
:
4254 case DW_TAG_enumeration_type
:
4255 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4256 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4257 add_symbol_to_list (sym
, list_in_scope
);
4259 /* The semantics of C++ state that "struct foo { ... }" also
4260 defines a typedef for "foo". Synthesize a typedef symbol so
4261 that "ptype foo" works as expected. */
4262 if (cu_language
== language_cplus
)
4264 struct symbol
*typedef_sym
= (struct symbol
*)
4265 obstack_alloc (&objfile
->symbol_obstack
,
4266 sizeof (struct symbol
));
4267 *typedef_sym
= *sym
;
4268 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4269 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4270 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4271 obsavestring (SYMBOL_NAME (sym
),
4272 strlen (SYMBOL_NAME (sym
)),
4273 &objfile
->type_obstack
);
4274 add_symbol_to_list (typedef_sym
, list_in_scope
);
4277 case DW_TAG_typedef
:
4278 case DW_TAG_base_type
:
4279 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4280 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4281 add_symbol_to_list (sym
, list_in_scope
);
4283 case DW_TAG_enumerator
:
4284 attr
= dwarf_attr (die
, DW_AT_const_value
);
4287 dwarf2_const_value (attr
, sym
, objfile
);
4289 add_symbol_to_list (sym
, list_in_scope
);
4292 /* Not a tag we recognize. Hopefully we aren't processing
4293 trash data, but since we must specifically ignore things
4294 we don't recognize, there is nothing else we should do at
4296 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4303 /* Copy constant value from an attribute to a symbol. */
4306 dwarf2_const_value (attr
, sym
, objfile
)
4307 struct attribute
*attr
;
4309 struct objfile
*objfile
;
4311 struct dwarf_block
*blk
;
4316 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != (unsigned int) address_size
)
4317 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4318 address_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4319 SYMBOL_VALUE_BYTES (sym
) = (char *)
4320 obstack_alloc (&objfile
->symbol_obstack
, address_size
);
4321 store_address (SYMBOL_VALUE_BYTES (sym
), address_size
, DW_ADDR (attr
));
4322 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4324 case DW_FORM_block1
:
4325 case DW_FORM_block2
:
4326 case DW_FORM_block4
:
4328 blk
= DW_BLOCK (attr
);
4329 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4330 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4331 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4332 SYMBOL_VALUE_BYTES (sym
) = (char *)
4333 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4334 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4335 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4343 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4344 SYMBOL_CLASS (sym
) = LOC_CONST
;
4347 complain (&dwarf2_unsupported_const_value_attr
,
4348 dwarf_form_name (attr
->form
));
4349 SYMBOL_VALUE (sym
) = 0;
4350 SYMBOL_CLASS (sym
) = LOC_CONST
;
4355 /* Return the type of the die in question using its DW_AT_type attribute. */
4357 static struct type
*
4358 die_type (die
, objfile
)
4359 struct die_info
*die
;
4360 struct objfile
*objfile
;
4363 struct attribute
*type_attr
;
4364 struct die_info
*type_die
;
4367 type_attr
= dwarf_attr (die
, DW_AT_type
);
4370 /* A missing DW_AT_type represents a void type. */
4371 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4375 ref
= dwarf2_get_ref_die_offset (type_attr
);
4376 type_die
= follow_die_ref (ref
);
4379 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4383 type
= tag_type_to_type (type_die
, objfile
);
4386 dump_die (type_die
);
4387 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4392 /* Return the containing type of the die in question using its
4393 DW_AT_containing_type attribute. */
4395 static struct type
*
4396 die_containing_type (die
, objfile
)
4397 struct die_info
*die
;
4398 struct objfile
*objfile
;
4400 struct type
*type
= NULL
;
4401 struct attribute
*type_attr
;
4402 struct die_info
*type_die
= NULL
;
4405 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4408 ref
= dwarf2_get_ref_die_offset (type_attr
);
4409 type_die
= follow_die_ref (ref
);
4412 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4415 type
= tag_type_to_type (type_die
, objfile
);
4420 dump_die (type_die
);
4421 error ("Dwarf Error: Problem turning containing type into gdb type.");
4427 static struct type
*
4428 type_at_offset (offset
, objfile
)
4429 unsigned int offset
;
4430 struct objfile
*objfile
;
4432 struct die_info
*die
;
4435 die
= follow_die_ref (offset
);
4438 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4441 type
= tag_type_to_type (die
, objfile
);
4446 static struct type
*
4447 tag_type_to_type (die
, objfile
)
4448 struct die_info
*die
;
4449 struct objfile
*objfile
;
4457 read_type_die (die
, objfile
);
4461 error ("Dwarf Error: Cannot find type of die.");
4468 read_type_die (die
, objfile
)
4469 struct die_info
*die
;
4470 struct objfile
*objfile
;
4474 case DW_TAG_class_type
:
4475 case DW_TAG_structure_type
:
4476 case DW_TAG_union_type
:
4477 read_structure_scope (die
, objfile
);
4479 case DW_TAG_enumeration_type
:
4480 read_enumeration (die
, objfile
);
4482 case DW_TAG_subprogram
:
4483 case DW_TAG_subroutine_type
:
4484 read_subroutine_type (die
, objfile
);
4486 case DW_TAG_array_type
:
4487 read_array_type (die
, objfile
);
4489 case DW_TAG_pointer_type
:
4490 read_tag_pointer_type (die
, objfile
);
4492 case DW_TAG_ptr_to_member_type
:
4493 read_tag_ptr_to_member_type (die
, objfile
);
4495 case DW_TAG_reference_type
:
4496 read_tag_reference_type (die
, objfile
);
4498 case DW_TAG_const_type
:
4499 read_tag_const_type (die
, objfile
);
4501 case DW_TAG_volatile_type
:
4502 read_tag_volatile_type (die
, objfile
);
4504 case DW_TAG_string_type
:
4505 read_tag_string_type (die
, objfile
);
4507 case DW_TAG_typedef
:
4508 read_typedef (die
, objfile
);
4510 case DW_TAG_base_type
:
4511 read_base_type (die
, objfile
);
4514 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4519 static struct type
*
4520 dwarf_base_type (encoding
, size
, objfile
)
4523 struct objfile
*objfile
;
4525 /* FIXME - this should not produce a new (struct type *)
4526 every time. It should cache base types. */
4530 case DW_ATE_address
:
4531 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4533 case DW_ATE_boolean
:
4534 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4536 case DW_ATE_complex_float
:
4539 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4543 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4549 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4553 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4560 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4563 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4567 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4571 case DW_ATE_signed_char
:
4572 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4574 case DW_ATE_unsigned
:
4578 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4581 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4585 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4589 case DW_ATE_unsigned_char
:
4590 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4593 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4601 struct die_info
*old_die
;
4603 struct die_info
*new_die
;
4606 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4607 memset (new_die
, 0, sizeof (struct die_info
));
4609 new_die
->tag
= old_die
->tag
;
4610 new_die
->has_children
= old_die
->has_children
;
4611 new_die
->abbrev
= old_die
->abbrev
;
4612 new_die
->offset
= old_die
->offset
;
4613 new_die
->type
= NULL
;
4615 num_attrs
= old_die
->num_attrs
;
4616 new_die
->num_attrs
= num_attrs
;
4617 new_die
->attrs
= (struct attribute
*)
4618 xmalloc (num_attrs
* sizeof (struct attribute
));
4620 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4622 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4623 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4624 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4627 new_die
->next
= NULL
;
4632 /* Return sibling of die, NULL if no sibling. */
4636 struct die_info
*die
;
4638 int nesting_level
= 0;
4640 if (!die
->has_children
)
4642 if (die
->next
&& (die
->next
->tag
== 0))
4655 if (die
->has_children
)
4665 while (nesting_level
);
4666 if (die
&& (die
->tag
== 0))
4677 /* Get linkage name of a die, return NULL if not found. */
4680 dwarf2_linkage_name (die
)
4681 struct die_info
*die
;
4683 struct attribute
*attr
;
4685 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4686 if (attr
&& DW_STRING (attr
))
4687 return DW_STRING (attr
);
4688 attr
= dwarf_attr (die
, DW_AT_name
);
4689 if (attr
&& DW_STRING (attr
))
4690 return DW_STRING (attr
);
4694 /* Convert a DIE tag into its string name. */
4697 dwarf_tag_name (tag
)
4698 register unsigned tag
;
4702 case DW_TAG_padding
:
4703 return "DW_TAG_padding";
4704 case DW_TAG_array_type
:
4705 return "DW_TAG_array_type";
4706 case DW_TAG_class_type
:
4707 return "DW_TAG_class_type";
4708 case DW_TAG_entry_point
:
4709 return "DW_TAG_entry_point";
4710 case DW_TAG_enumeration_type
:
4711 return "DW_TAG_enumeration_type";
4712 case DW_TAG_formal_parameter
:
4713 return "DW_TAG_formal_parameter";
4714 case DW_TAG_imported_declaration
:
4715 return "DW_TAG_imported_declaration";
4717 return "DW_TAG_label";
4718 case DW_TAG_lexical_block
:
4719 return "DW_TAG_lexical_block";
4721 return "DW_TAG_member";
4722 case DW_TAG_pointer_type
:
4723 return "DW_TAG_pointer_type";
4724 case DW_TAG_reference_type
:
4725 return "DW_TAG_reference_type";
4726 case DW_TAG_compile_unit
:
4727 return "DW_TAG_compile_unit";
4728 case DW_TAG_string_type
:
4729 return "DW_TAG_string_type";
4730 case DW_TAG_structure_type
:
4731 return "DW_TAG_structure_type";
4732 case DW_TAG_subroutine_type
:
4733 return "DW_TAG_subroutine_type";
4734 case DW_TAG_typedef
:
4735 return "DW_TAG_typedef";
4736 case DW_TAG_union_type
:
4737 return "DW_TAG_union_type";
4738 case DW_TAG_unspecified_parameters
:
4739 return "DW_TAG_unspecified_parameters";
4740 case DW_TAG_variant
:
4741 return "DW_TAG_variant";
4742 case DW_TAG_common_block
:
4743 return "DW_TAG_common_block";
4744 case DW_TAG_common_inclusion
:
4745 return "DW_TAG_common_inclusion";
4746 case DW_TAG_inheritance
:
4747 return "DW_TAG_inheritance";
4748 case DW_TAG_inlined_subroutine
:
4749 return "DW_TAG_inlined_subroutine";
4751 return "DW_TAG_module";
4752 case DW_TAG_ptr_to_member_type
:
4753 return "DW_TAG_ptr_to_member_type";
4754 case DW_TAG_set_type
:
4755 return "DW_TAG_set_type";
4756 case DW_TAG_subrange_type
:
4757 return "DW_TAG_subrange_type";
4758 case DW_TAG_with_stmt
:
4759 return "DW_TAG_with_stmt";
4760 case DW_TAG_access_declaration
:
4761 return "DW_TAG_access_declaration";
4762 case DW_TAG_base_type
:
4763 return "DW_TAG_base_type";
4764 case DW_TAG_catch_block
:
4765 return "DW_TAG_catch_block";
4766 case DW_TAG_const_type
:
4767 return "DW_TAG_const_type";
4768 case DW_TAG_constant
:
4769 return "DW_TAG_constant";
4770 case DW_TAG_enumerator
:
4771 return "DW_TAG_enumerator";
4772 case DW_TAG_file_type
:
4773 return "DW_TAG_file_type";
4775 return "DW_TAG_friend";
4776 case DW_TAG_namelist
:
4777 return "DW_TAG_namelist";
4778 case DW_TAG_namelist_item
:
4779 return "DW_TAG_namelist_item";
4780 case DW_TAG_packed_type
:
4781 return "DW_TAG_packed_type";
4782 case DW_TAG_subprogram
:
4783 return "DW_TAG_subprogram";
4784 case DW_TAG_template_type_param
:
4785 return "DW_TAG_template_type_param";
4786 case DW_TAG_template_value_param
:
4787 return "DW_TAG_template_value_param";
4788 case DW_TAG_thrown_type
:
4789 return "DW_TAG_thrown_type";
4790 case DW_TAG_try_block
:
4791 return "DW_TAG_try_block";
4792 case DW_TAG_variant_part
:
4793 return "DW_TAG_variant_part";
4794 case DW_TAG_variable
:
4795 return "DW_TAG_variable";
4796 case DW_TAG_volatile_type
:
4797 return "DW_TAG_volatile_type";
4798 case DW_TAG_MIPS_loop
:
4799 return "DW_TAG_MIPS_loop";
4800 case DW_TAG_format_label
:
4801 return "DW_TAG_format_label";
4802 case DW_TAG_function_template
:
4803 return "DW_TAG_function_template";
4804 case DW_TAG_class_template
:
4805 return "DW_TAG_class_template";
4807 return "DW_TAG_<unknown>";
4811 /* Convert a DWARF attribute code into its string name. */
4814 dwarf_attr_name (attr
)
4815 register unsigned attr
;
4820 return "DW_AT_sibling";
4821 case DW_AT_location
:
4822 return "DW_AT_location";
4824 return "DW_AT_name";
4825 case DW_AT_ordering
:
4826 return "DW_AT_ordering";
4827 case DW_AT_subscr_data
:
4828 return "DW_AT_subscr_data";
4829 case DW_AT_byte_size
:
4830 return "DW_AT_byte_size";
4831 case DW_AT_bit_offset
:
4832 return "DW_AT_bit_offset";
4833 case DW_AT_bit_size
:
4834 return "DW_AT_bit_size";
4835 case DW_AT_element_list
:
4836 return "DW_AT_element_list";
4837 case DW_AT_stmt_list
:
4838 return "DW_AT_stmt_list";
4840 return "DW_AT_low_pc";
4842 return "DW_AT_high_pc";
4843 case DW_AT_language
:
4844 return "DW_AT_language";
4846 return "DW_AT_member";
4848 return "DW_AT_discr";
4849 case DW_AT_discr_value
:
4850 return "DW_AT_discr_value";
4851 case DW_AT_visibility
:
4852 return "DW_AT_visibility";
4854 return "DW_AT_import";
4855 case DW_AT_string_length
:
4856 return "DW_AT_string_length";
4857 case DW_AT_common_reference
:
4858 return "DW_AT_common_reference";
4859 case DW_AT_comp_dir
:
4860 return "DW_AT_comp_dir";
4861 case DW_AT_const_value
:
4862 return "DW_AT_const_value";
4863 case DW_AT_containing_type
:
4864 return "DW_AT_containing_type";
4865 case DW_AT_default_value
:
4866 return "DW_AT_default_value";
4868 return "DW_AT_inline";
4869 case DW_AT_is_optional
:
4870 return "DW_AT_is_optional";
4871 case DW_AT_lower_bound
:
4872 return "DW_AT_lower_bound";
4873 case DW_AT_producer
:
4874 return "DW_AT_producer";
4875 case DW_AT_prototyped
:
4876 return "DW_AT_prototyped";
4877 case DW_AT_return_addr
:
4878 return "DW_AT_return_addr";
4879 case DW_AT_start_scope
:
4880 return "DW_AT_start_scope";
4881 case DW_AT_stride_size
:
4882 return "DW_AT_stride_size";
4883 case DW_AT_upper_bound
:
4884 return "DW_AT_upper_bound";
4885 case DW_AT_abstract_origin
:
4886 return "DW_AT_abstract_origin";
4887 case DW_AT_accessibility
:
4888 return "DW_AT_accessibility";
4889 case DW_AT_address_class
:
4890 return "DW_AT_address_class";
4891 case DW_AT_artificial
:
4892 return "DW_AT_artificial";
4893 case DW_AT_base_types
:
4894 return "DW_AT_base_types";
4895 case DW_AT_calling_convention
:
4896 return "DW_AT_calling_convention";
4898 return "DW_AT_count";
4899 case DW_AT_data_member_location
:
4900 return "DW_AT_data_member_location";
4901 case DW_AT_decl_column
:
4902 return "DW_AT_decl_column";
4903 case DW_AT_decl_file
:
4904 return "DW_AT_decl_file";
4905 case DW_AT_decl_line
:
4906 return "DW_AT_decl_line";
4907 case DW_AT_declaration
:
4908 return "DW_AT_declaration";
4909 case DW_AT_discr_list
:
4910 return "DW_AT_discr_list";
4911 case DW_AT_encoding
:
4912 return "DW_AT_encoding";
4913 case DW_AT_external
:
4914 return "DW_AT_external";
4915 case DW_AT_frame_base
:
4916 return "DW_AT_frame_base";
4918 return "DW_AT_friend";
4919 case DW_AT_identifier_case
:
4920 return "DW_AT_identifier_case";
4921 case DW_AT_macro_info
:
4922 return "DW_AT_macro_info";
4923 case DW_AT_namelist_items
:
4924 return "DW_AT_namelist_items";
4925 case DW_AT_priority
:
4926 return "DW_AT_priority";
4928 return "DW_AT_segment";
4929 case DW_AT_specification
:
4930 return "DW_AT_specification";
4931 case DW_AT_static_link
:
4932 return "DW_AT_static_link";
4934 return "DW_AT_type";
4935 case DW_AT_use_location
:
4936 return "DW_AT_use_location";
4937 case DW_AT_variable_parameter
:
4938 return "DW_AT_variable_parameter";
4939 case DW_AT_virtuality
:
4940 return "DW_AT_virtuality";
4941 case DW_AT_vtable_elem_location
:
4942 return "DW_AT_vtable_elem_location";
4945 case DW_AT_MIPS_fde
:
4946 return "DW_AT_MIPS_fde";
4947 case DW_AT_MIPS_loop_begin
:
4948 return "DW_AT_MIPS_loop_begin";
4949 case DW_AT_MIPS_tail_loop_begin
:
4950 return "DW_AT_MIPS_tail_loop_begin";
4951 case DW_AT_MIPS_epilog_begin
:
4952 return "DW_AT_MIPS_epilog_begin";
4953 case DW_AT_MIPS_loop_unroll_factor
:
4954 return "DW_AT_MIPS_loop_unroll_factor";
4955 case DW_AT_MIPS_software_pipeline_depth
:
4956 return "DW_AT_MIPS_software_pipeline_depth";
4957 case DW_AT_MIPS_linkage_name
:
4958 return "DW_AT_MIPS_linkage_name";
4961 case DW_AT_sf_names
:
4962 return "DW_AT_sf_names";
4963 case DW_AT_src_info
:
4964 return "DW_AT_src_info";
4965 case DW_AT_mac_info
:
4966 return "DW_AT_mac_info";
4967 case DW_AT_src_coords
:
4968 return "DW_AT_src_coords";
4969 case DW_AT_body_begin
:
4970 return "DW_AT_body_begin";
4971 case DW_AT_body_end
:
4972 return "DW_AT_body_end";
4974 return "DW_AT_<unknown>";
4978 /* Convert a DWARF value form code into its string name. */
4981 dwarf_form_name (form
)
4982 register unsigned form
;
4987 return "DW_FORM_addr";
4988 case DW_FORM_block2
:
4989 return "DW_FORM_block2";
4990 case DW_FORM_block4
:
4991 return "DW_FORM_block4";
4993 return "DW_FORM_data2";
4995 return "DW_FORM_data4";
4997 return "DW_FORM_data8";
4998 case DW_FORM_string
:
4999 return "DW_FORM_string";
5001 return "DW_FORM_block";
5002 case DW_FORM_block1
:
5003 return "DW_FORM_block1";
5005 return "DW_FORM_data1";
5007 return "DW_FORM_flag";
5009 return "DW_FORM_sdata";
5011 return "DW_FORM_strp";
5013 return "DW_FORM_udata";
5014 case DW_FORM_ref_addr
:
5015 return "DW_FORM_ref_addr";
5017 return "DW_FORM_ref1";
5019 return "DW_FORM_ref2";
5021 return "DW_FORM_ref4";
5023 return "DW_FORM_ref8";
5024 case DW_FORM_ref_udata
:
5025 return "DW_FORM_ref_udata";
5026 case DW_FORM_indirect
:
5027 return "DW_FORM_indirect";
5029 return "DW_FORM_<unknown>";
5033 /* Convert a DWARF stack opcode into its string name. */
5036 dwarf_stack_op_name (op
)
5037 register unsigned op
;
5042 return "DW_OP_addr";
5044 return "DW_OP_deref";
5046 return "DW_OP_const1u";
5048 return "DW_OP_const1s";
5050 return "DW_OP_const2u";
5052 return "DW_OP_const2s";
5054 return "DW_OP_const4u";
5056 return "DW_OP_const4s";
5058 return "DW_OP_const8u";
5060 return "DW_OP_const8s";
5062 return "DW_OP_constu";
5064 return "DW_OP_consts";
5068 return "DW_OP_drop";
5070 return "DW_OP_over";
5072 return "DW_OP_pick";
5074 return "DW_OP_swap";
5078 return "DW_OP_xderef";
5086 return "DW_OP_minus";
5098 return "DW_OP_plus";
5099 case DW_OP_plus_uconst
:
5100 return "DW_OP_plus_uconst";
5106 return "DW_OP_shra";
5124 return "DW_OP_skip";
5126 return "DW_OP_lit0";
5128 return "DW_OP_lit1";
5130 return "DW_OP_lit2";
5132 return "DW_OP_lit3";
5134 return "DW_OP_lit4";
5136 return "DW_OP_lit5";
5138 return "DW_OP_lit6";
5140 return "DW_OP_lit7";
5142 return "DW_OP_lit8";
5144 return "DW_OP_lit9";
5146 return "DW_OP_lit10";
5148 return "DW_OP_lit11";
5150 return "DW_OP_lit12";
5152 return "DW_OP_lit13";
5154 return "DW_OP_lit14";
5156 return "DW_OP_lit15";
5158 return "DW_OP_lit16";
5160 return "DW_OP_lit17";
5162 return "DW_OP_lit18";
5164 return "DW_OP_lit19";
5166 return "DW_OP_lit20";
5168 return "DW_OP_lit21";
5170 return "DW_OP_lit22";
5172 return "DW_OP_lit23";
5174 return "DW_OP_lit24";
5176 return "DW_OP_lit25";
5178 return "DW_OP_lit26";
5180 return "DW_OP_lit27";
5182 return "DW_OP_lit28";
5184 return "DW_OP_lit29";
5186 return "DW_OP_lit30";
5188 return "DW_OP_lit31";
5190 return "DW_OP_reg0";
5192 return "DW_OP_reg1";
5194 return "DW_OP_reg2";
5196 return "DW_OP_reg3";
5198 return "DW_OP_reg4";
5200 return "DW_OP_reg5";
5202 return "DW_OP_reg6";
5204 return "DW_OP_reg7";
5206 return "DW_OP_reg8";
5208 return "DW_OP_reg9";
5210 return "DW_OP_reg10";
5212 return "DW_OP_reg11";
5214 return "DW_OP_reg12";
5216 return "DW_OP_reg13";
5218 return "DW_OP_reg14";
5220 return "DW_OP_reg15";
5222 return "DW_OP_reg16";
5224 return "DW_OP_reg17";
5226 return "DW_OP_reg18";
5228 return "DW_OP_reg19";
5230 return "DW_OP_reg20";
5232 return "DW_OP_reg21";
5234 return "DW_OP_reg22";
5236 return "DW_OP_reg23";
5238 return "DW_OP_reg24";
5240 return "DW_OP_reg25";
5242 return "DW_OP_reg26";
5244 return "DW_OP_reg27";
5246 return "DW_OP_reg28";
5248 return "DW_OP_reg29";
5250 return "DW_OP_reg30";
5252 return "DW_OP_reg31";
5254 return "DW_OP_breg0";
5256 return "DW_OP_breg1";
5258 return "DW_OP_breg2";
5260 return "DW_OP_breg3";
5262 return "DW_OP_breg4";
5264 return "DW_OP_breg5";
5266 return "DW_OP_breg6";
5268 return "DW_OP_breg7";
5270 return "DW_OP_breg8";
5272 return "DW_OP_breg9";
5274 return "DW_OP_breg10";
5276 return "DW_OP_breg11";
5278 return "DW_OP_breg12";
5280 return "DW_OP_breg13";
5282 return "DW_OP_breg14";
5284 return "DW_OP_breg15";
5286 return "DW_OP_breg16";
5288 return "DW_OP_breg17";
5290 return "DW_OP_breg18";
5292 return "DW_OP_breg19";
5294 return "DW_OP_breg20";
5296 return "DW_OP_breg21";
5298 return "DW_OP_breg22";
5300 return "DW_OP_breg23";
5302 return "DW_OP_breg24";
5304 return "DW_OP_breg25";
5306 return "DW_OP_breg26";
5308 return "DW_OP_breg27";
5310 return "DW_OP_breg28";
5312 return "DW_OP_breg29";
5314 return "DW_OP_breg30";
5316 return "DW_OP_breg31";
5318 return "DW_OP_regx";
5320 return "DW_OP_fbreg";
5322 return "DW_OP_bregx";
5324 return "DW_OP_piece";
5325 case DW_OP_deref_size
:
5326 return "DW_OP_deref_size";
5327 case DW_OP_xderef_size
:
5328 return "DW_OP_xderef_size";
5332 return "OP_<unknown>";
5337 dwarf_bool_name (bool)
5346 /* Convert a DWARF type code into its string name. */
5349 dwarf_type_encoding_name (enc
)
5350 register unsigned enc
;
5354 case DW_ATE_address
:
5355 return "DW_ATE_address";
5356 case DW_ATE_boolean
:
5357 return "DW_ATE_boolean";
5358 case DW_ATE_complex_float
:
5359 return "DW_ATE_complex_float";
5361 return "DW_ATE_float";
5363 return "DW_ATE_signed";
5364 case DW_ATE_signed_char
:
5365 return "DW_ATE_signed_char";
5366 case DW_ATE_unsigned
:
5367 return "DW_ATE_unsigned";
5368 case DW_ATE_unsigned_char
:
5369 return "DW_ATE_unsigned_char";
5371 return "DW_ATE_<unknown>";
5375 /* Convert a DWARF call frame info operation to its string name. */
5379 dwarf_cfi_name (cfi_opc
)
5380 register unsigned cfi_opc
;
5384 case DW_CFA_advance_loc
:
5385 return "DW_CFA_advance_loc";
5387 return "DW_CFA_offset";
5388 case DW_CFA_restore
:
5389 return "DW_CFA_restore";
5391 return "DW_CFA_nop";
5392 case DW_CFA_set_loc
:
5393 return "DW_CFA_set_loc";
5394 case DW_CFA_advance_loc1
:
5395 return "DW_CFA_advance_loc1";
5396 case DW_CFA_advance_loc2
:
5397 return "DW_CFA_advance_loc2";
5398 case DW_CFA_advance_loc4
:
5399 return "DW_CFA_advance_loc4";
5400 case DW_CFA_offset_extended
:
5401 return "DW_CFA_offset_extended";
5402 case DW_CFA_restore_extended
:
5403 return "DW_CFA_restore_extended";
5404 case DW_CFA_undefined
:
5405 return "DW_CFA_undefined";
5406 case DW_CFA_same_value
:
5407 return "DW_CFA_same_value";
5408 case DW_CFA_register
:
5409 return "DW_CFA_register";
5410 case DW_CFA_remember_state
:
5411 return "DW_CFA_remember_state";
5412 case DW_CFA_restore_state
:
5413 return "DW_CFA_restore_state";
5414 case DW_CFA_def_cfa
:
5415 return "DW_CFA_def_cfa";
5416 case DW_CFA_def_cfa_register
:
5417 return "DW_CFA_def_cfa_register";
5418 case DW_CFA_def_cfa_offset
:
5419 return "DW_CFA_def_cfa_offset";
5420 /* SGI/MIPS specific */
5421 case DW_CFA_MIPS_advance_loc8
:
5422 return "DW_CFA_MIPS_advance_loc8";
5424 return "DW_CFA_<unknown>";
5431 struct die_info
*die
;
5435 fprintf (stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5436 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5437 fprintf (stderr
, "\thas children: %s\n",
5438 dwarf_bool_name (die
->has_children
));
5440 fprintf (stderr
, "\tattributes:\n");
5441 for (i
= 0; i
< die
->num_attrs
; ++i
)
5443 fprintf (stderr
, "\t\t%s (%s) ",
5444 dwarf_attr_name (die
->attrs
[i
].name
),
5445 dwarf_form_name (die
->attrs
[i
].form
));
5446 switch (die
->attrs
[i
].form
)
5448 case DW_FORM_ref_addr
:
5450 fprintf (stderr
, "address: ");
5451 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, stderr
);
5453 case DW_FORM_block2
:
5454 case DW_FORM_block4
:
5456 case DW_FORM_block1
:
5457 fprintf (stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5467 fprintf (stderr
, "constant: %d", DW_UNSND (&die
->attrs
[i
]));
5469 case DW_FORM_string
:
5470 fprintf (stderr
, "string: \"%s\"",
5471 DW_STRING (&die
->attrs
[i
])
5472 ? DW_STRING (&die
->attrs
[i
]) : "");
5475 if (DW_UNSND (&die
->attrs
[i
]))
5476 fprintf (stderr
, "flag: TRUE");
5478 fprintf (stderr
, "flag: FALSE");
5480 case DW_FORM_strp
: /* we do not support separate string
5482 case DW_FORM_indirect
: /* we do not handle indirect yet */
5483 case DW_FORM_data8
: /* we do not have 64 bit quantities */
5485 fprintf (stderr
, "unsupported attribute form: %d.",
5486 die
->attrs
[i
].form
);
5488 fprintf (stderr
, "\n");
5494 struct die_info
*die
;
5504 store_in_ref_table (offset
, die
)
5505 unsigned int offset
;
5506 struct die_info
*die
;
5509 struct die_info
*old
;
5511 h
= (offset
% REF_HASH_SIZE
);
5512 old
= die_ref_table
[h
];
5513 die
->next_ref
= old
;
5514 die_ref_table
[h
] = die
;
5519 dwarf2_empty_die_ref_table ()
5521 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5525 dwarf2_get_ref_die_offset (attr
)
5526 struct attribute
*attr
;
5528 unsigned int result
= 0;
5532 case DW_FORM_ref_addr
:
5533 result
= DW_ADDR (attr
);
5538 case DW_FORM_ref_udata
:
5539 result
= cu_header_offset
+ DW_UNSND (attr
);
5542 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5548 follow_die_ref (offset
)
5549 unsigned int offset
;
5551 struct die_info
*die
;
5554 h
= (offset
% REF_HASH_SIZE
);
5555 die
= die_ref_table
[h
];
5558 if (die
->offset
== offset
)
5562 die
= die
->next_ref
;
5567 static struct type
*
5568 dwarf2_fundamental_type (objfile
, typeid)
5569 struct objfile
*objfile
;
5572 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5574 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5578 /* Look for this particular type in the fundamental type vector. If
5579 one is not found, create and install one appropriate for the
5580 current language and the current target machine. */
5582 if (ftypes
[typeid] == NULL
)
5584 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5587 return (ftypes
[typeid]);
5590 /* Decode simple location descriptions.
5591 Given a pointer to a dwarf block that defines a location, compute
5592 the location and return the value.
5594 FIXME: This is a kludge until we figure out a better
5595 way to handle the location descriptions.
5596 Gdb's design does not mesh well with the DWARF2 notion of a location
5597 computing interpreter, which is a shame because the flexibility goes unused.
5598 FIXME: Implement more operations as necessary.
5600 A location description containing no operations indicates that the
5601 object is optimized out. The global optimized_out flag is set for
5602 those, the return value is meaningless.
5604 When the result is a register number, the global isreg flag is set,
5605 otherwise it is cleared.
5607 When the result is a base register offset, the global offreg flag is set
5608 and the register number is returned in basereg, otherwise it is cleared.
5610 When the DW_OP_fbreg operation is encountered without a corresponding
5611 DW_AT_frame_base attribute, the global islocal flag is set.
5612 Hopefully the machine dependent code knows how to set up a virtual
5613 frame pointer for the local references.
5615 Note that stack[0] is unused except as a default error return.
5616 Note that stack overflow is not yet handled. */
5619 decode_locdesc (blk
, objfile
)
5620 struct dwarf_block
*blk
;
5621 struct objfile
*objfile
;
5624 int size
= blk
->size
;
5625 char *data
= blk
->data
;
5626 CORE_ADDR stack
[64];
5628 unsigned int bytes_read
, unsnd
;
5678 stack
[++stacki
] = op
- DW_OP_reg0
;
5683 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5685 #if defined(HARRIS_TARGET) && defined(_M88K)
5686 /* The Harris 88110 gdb ports have long kept their special reg
5687 numbers between their gp-regs and their x-regs. This is
5688 not how our dwarf is generated. Punt. */
5691 stack
[++stacki
] = unsnd
;
5727 basereg
= op
- DW_OP_breg0
;
5728 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5733 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5735 if (frame_base_reg
>= 0)
5738 basereg
= frame_base_reg
;
5739 stack
[stacki
] += frame_base_offset
;
5743 complain (&dwarf2_missing_at_frame_base
);
5749 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
]);
5754 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
5759 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
5764 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
5769 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
5774 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
5779 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
5784 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
5790 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5795 stack
[stacki
- 1] += stack
[stacki
];
5799 case DW_OP_plus_uconst
:
5800 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5805 stack
[stacki
- 1] = stack
[stacki
] - stack
[stacki
- 1];
5810 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name(op
));
5811 return (stack
[stacki
]);
5814 return (stack
[stacki
]);
5817 /* memory allocation interface */
5821 dwarf2_free_tmp_obstack (ignore
)
5824 obstack_free (&dwarf2_tmp_obstack
, NULL
);
5827 static struct dwarf_block
*
5828 dwarf_alloc_block ()
5830 struct dwarf_block
*blk
;
5832 blk
= (struct dwarf_block
*)
5833 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
5837 static struct abbrev_info
*
5838 dwarf_alloc_abbrev ()
5840 struct abbrev_info
*abbrev
;
5842 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
5843 memset (abbrev
, 0, sizeof (struct abbrev_info
));
5847 static struct die_info
*
5850 struct die_info
*die
;
5852 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5853 memset (die
, 0, sizeof (struct die_info
));