1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
4 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
5 Inc. with support from Florida State University (under contract
6 with the Ada Joint Program Office), and Silicon Graphics, Inc.
7 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
8 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
11 This file is part of GDB.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or (at
16 your option) any later version.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. */
34 #include "elf/dwarf2.h"
37 #include "expression.h"
40 #include "complaints.h"
43 #include "gdb_string.h"
44 #include <sys/types.h>
47 /* .debug_info header for a compilation unit
48 Because of alignment constraints, this structure has padding and cannot
49 be mapped directly onto the beginning of the .debug_info section. */
50 typedef struct comp_unit_header
52 unsigned int length
; /* length of the .debug_info
54 unsigned short version
; /* version number -- 2 for DWARF
56 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
57 unsigned char addr_size
; /* byte size of an address -- 4 */
60 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
63 /* .debug_pubnames header
64 Because of alignment constraints, this structure has padding and cannot
65 be mapped directly onto the beginning of the .debug_info section. */
66 typedef struct pubnames_header
68 unsigned int length
; /* length of the .debug_pubnames
70 unsigned char version
; /* version number -- 2 for DWARF
72 unsigned int info_offset
; /* offset into .debug_info section */
73 unsigned int info_size
; /* byte size of .debug_info section
77 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
79 /* .debug_pubnames header
80 Because of alignment constraints, this structure has padding and cannot
81 be mapped directly onto the beginning of the .debug_info section. */
82 typedef struct aranges_header
84 unsigned int length
; /* byte len of the .debug_aranges
86 unsigned short version
; /* version number -- 2 for DWARF
88 unsigned int info_offset
; /* offset into .debug_info section */
89 unsigned char addr_size
; /* byte size of an address */
90 unsigned char seg_size
; /* byte size of segment descriptor */
93 #define _ACTUAL_ARANGES_HEADER_SIZE 12
95 /* .debug_line statement program prologue
96 Because of alignment constraints, this structure has padding and cannot
97 be mapped directly onto the beginning of the .debug_info section. */
98 typedef struct statement_prologue
100 unsigned int total_length
; /* byte length of the statement
102 unsigned short version
; /* version number -- 2 for DWARF
104 unsigned int prologue_length
; /* # bytes between prologue &
106 unsigned char minimum_instruction_length
; /* byte size of
108 unsigned char default_is_stmt
; /* initial value of is_stmt
111 unsigned char line_range
;
112 unsigned char opcode_base
; /* number assigned to first special
114 unsigned char *standard_opcode_lengths
;
118 /* offsets and sizes of debugging sections */
120 static file_ptr dwarf_info_offset
;
121 static file_ptr dwarf_abbrev_offset
;
122 static file_ptr dwarf_line_offset
;
123 static file_ptr dwarf_pubnames_offset
;
124 static file_ptr dwarf_aranges_offset
;
125 static file_ptr dwarf_loc_offset
;
126 static file_ptr dwarf_macinfo_offset
;
127 static file_ptr dwarf_str_offset
;
129 static unsigned int dwarf_info_size
;
130 static unsigned int dwarf_abbrev_size
;
131 static unsigned int dwarf_line_size
;
132 static unsigned int dwarf_pubnames_size
;
133 static unsigned int dwarf_aranges_size
;
134 static unsigned int dwarf_loc_size
;
135 static unsigned int dwarf_macinfo_size
;
136 static unsigned int dwarf_str_size
;
138 /* names of the debugging sections */
140 #define INFO_SECTION ".debug_info"
141 #define ABBREV_SECTION ".debug_abbrev"
142 #define LINE_SECTION ".debug_line"
143 #define PUBNAMES_SECTION ".debug_pubnames"
144 #define ARANGES_SECTION ".debug_aranges"
145 #define LOC_SECTION ".debug_loc"
146 #define MACINFO_SECTION ".debug_macinfo"
147 #define STR_SECTION ".debug_str"
149 /* local data types */
151 /* The data in a compilation unit header, after target2host
152 translation, looks like this. */
153 struct comp_unit_head
155 unsigned long length
;
157 unsigned int abbrev_offset
;
158 unsigned char addr_size
;
159 unsigned char signed_addr_p
;
160 unsigned int offset_size
; /* size of file offsets; either 4 or 8 */
161 unsigned int initial_length_size
; /* size of the length field; either
165 /* The data in the .debug_line statement prologue looks like this. */
168 unsigned int total_length
;
169 unsigned short version
;
170 unsigned int prologue_length
;
171 unsigned char minimum_instruction_length
;
172 unsigned char default_is_stmt
;
174 unsigned char line_range
;
175 unsigned char opcode_base
;
176 unsigned char *standard_opcode_lengths
;
179 /* When we construct a partial symbol table entry we only
180 need this much information. */
181 struct partial_die_info
184 unsigned char has_children
;
185 unsigned char is_external
;
186 unsigned char is_declaration
;
187 unsigned char has_type
;
193 struct dwarf_block
*locdesc
;
194 unsigned int language
;
198 /* This data structure holds the information of an abbrev. */
201 unsigned int number
; /* number identifying abbrev */
202 enum dwarf_tag tag
; /* dwarf tag */
203 int has_children
; /* boolean */
204 unsigned int num_attrs
; /* number of attributes */
205 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
206 struct abbrev_info
*next
; /* next in chain */
211 enum dwarf_attribute name
;
212 enum dwarf_form form
;
215 /* This data structure holds a complete die structure. */
218 enum dwarf_tag tag
; /* Tag indicating type of die */
219 unsigned short has_children
; /* Does the die have children */
220 unsigned int abbrev
; /* Abbrev number */
221 unsigned int offset
; /* Offset in .debug_info section */
222 unsigned int num_attrs
; /* Number of attributes */
223 struct attribute
*attrs
; /* An array of attributes */
224 struct die_info
*next_ref
; /* Next die in ref hash table */
225 struct die_info
*next
; /* Next die in linked list */
226 struct type
*type
; /* Cached type information */
229 /* Attributes have a name and a value */
232 enum dwarf_attribute name
;
233 enum dwarf_form form
;
237 struct dwarf_block
*blk
;
245 /* Get at parts of an attribute structure */
247 #define DW_STRING(attr) ((attr)->u.str)
248 #define DW_UNSND(attr) ((attr)->u.unsnd)
249 #define DW_BLOCK(attr) ((attr)->u.blk)
250 #define DW_SND(attr) ((attr)->u.snd)
251 #define DW_ADDR(attr) ((attr)->u.addr)
253 /* Blocks are a bunch of untyped bytes. */
260 /* We only hold one compilation unit's abbrevs in
261 memory at any one time. */
262 #ifndef ABBREV_HASH_SIZE
263 #define ABBREV_HASH_SIZE 121
265 #ifndef ATTR_ALLOC_CHUNK
266 #define ATTR_ALLOC_CHUNK 4
269 static struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
271 /* A hash table of die offsets for following references. */
272 #ifndef REF_HASH_SIZE
273 #define REF_HASH_SIZE 1021
276 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
278 /* Obstack for allocating temporary storage used during symbol reading. */
279 static struct obstack dwarf2_tmp_obstack
;
281 /* Offset to the first byte of the current compilation unit header,
282 for resolving relative reference dies. */
283 static unsigned int cu_header_offset
;
285 /* Allocate fields for structs, unions and enums in this size. */
286 #ifndef DW_FIELD_ALLOC_CHUNK
287 #define DW_FIELD_ALLOC_CHUNK 4
290 /* The language we are debugging. */
291 static enum language cu_language
;
292 static const struct language_defn
*cu_language_defn
;
294 /* Actually data from the sections. */
295 static char *dwarf_info_buffer
;
296 static char *dwarf_abbrev_buffer
;
297 static char *dwarf_line_buffer
;
299 /* A zeroed version of a partial die for initialization purposes. */
300 static struct partial_die_info zeroed_partial_die
;
302 /* The generic symbol table building routines have separate lists for
303 file scope symbols and all all other scopes (local scopes). So
304 we need to select the right one to pass to add_symbol_to_list().
305 We do it by keeping a pointer to the correct list in list_in_scope.
307 FIXME: The original dwarf code just treated the file scope as the first
308 local scope, and all other local scopes as nested local scopes, and worked
309 fine. Check to see if we really need to distinguish these
311 static struct pending
**list_in_scope
= &file_symbols
;
313 /* FIXME: decode_locdesc sets these variables to describe the location
314 to the caller. These ought to be a structure or something. If
315 none of the flags are set, the object lives at the address returned
316 by decode_locdesc. */
318 static int optimized_out
; /* No ops in location in expression,
319 so object was optimized out. */
320 static int isreg
; /* Object lives in register.
321 decode_locdesc's return value is
322 the register number. */
323 static int offreg
; /* Object's address is the sum of the
324 register specified by basereg, plus
325 the offset returned. */
326 static int basereg
; /* See `offreg'. */
327 static int isderef
; /* Value described by flags above is
328 the address of a pointer to the object. */
329 static int islocal
; /* Variable is at the returned offset
330 from the frame start, but there's
331 no identified frame pointer for
332 this function, so we can't say
333 which register it's relative to;
336 /* DW_AT_frame_base values for the current function.
337 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
338 contains the register number for the frame register.
339 frame_base_offset is the offset from the frame register to the
340 virtual stack frame. */
341 static int frame_base_reg
;
342 static CORE_ADDR frame_base_offset
;
344 /* This value is added to each symbol value. FIXME: Generalize to
345 the section_offsets structure used by dbxread (once this is done,
346 pass the appropriate section number to end_symtab). */
347 static CORE_ADDR baseaddr
; /* Add to each symbol value */
349 /* We put a pointer to this structure in the read_symtab_private field
351 The complete dwarf information for an objfile is kept in the
352 psymbol_obstack, so that absolute die references can be handled.
353 Most of the information in this structure is related to an entire
354 object file and could be passed via the sym_private field of the objfile.
355 It is however conceivable that dwarf2 might not be the only type
356 of symbols read from an object file. */
360 /* Pointer to start of dwarf info buffer for the objfile. */
362 char *dwarf_info_buffer
;
364 /* Offset in dwarf_info_buffer for this compilation unit. */
366 unsigned long dwarf_info_offset
;
368 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
370 char *dwarf_abbrev_buffer
;
372 /* Size of dwarf abbreviation section for the objfile. */
374 unsigned int dwarf_abbrev_size
;
376 /* Pointer to start of dwarf line buffer for the objfile. */
378 char *dwarf_line_buffer
;
381 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
382 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
383 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
384 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
385 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
386 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
388 /* Maintain an array of referenced fundamental types for the current
389 compilation unit being read. For DWARF version 1, we have to construct
390 the fundamental types on the fly, since no information about the
391 fundamental types is supplied. Each such fundamental type is created by
392 calling a language dependent routine to create the type, and then a
393 pointer to that type is then placed in the array at the index specified
394 by it's FT_<TYPENAME> value. The array has a fixed size set by the
395 FT_NUM_MEMBERS compile time constant, which is the number of predefined
396 fundamental types gdb knows how to construct. */
397 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
399 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
400 but this would require a corresponding change in unpack_field_as_long
402 static int bits_per_byte
= 8;
404 /* The routines that read and process dies for a C struct or C++ class
405 pass lists of data member fields and lists of member function fields
406 in an instance of a field_info structure, as defined below. */
409 /* List of data member and baseclasses fields. */
412 struct nextfield
*next
;
419 /* Number of fields. */
422 /* Number of baseclasses. */
425 /* Set if the accesibility of one of the fields is not public. */
426 int non_public_fields
;
428 /* Member function fields array, entries are allocated in the order they
429 are encountered in the object file. */
432 struct nextfnfield
*next
;
433 struct fn_field fnfield
;
437 /* Member function fieldlist array, contains name of possibly overloaded
438 member function, number of overloaded member functions and a pointer
439 to the head of the member function field chain. */
444 struct nextfnfield
*head
;
448 /* Number of entries in the fnfieldlists array. */
452 /* FIXME: Kludge to mark a varargs function type for C++ member function
453 argument processing. */
454 #define TYPE_FLAG_VARARGS (1 << 10)
456 /* Dwarf2 has no clean way to discern C++ static and non-static member
457 functions. G++ helps GDB by marking the first parameter for non-static
458 member functions (which is the this pointer) as artificial.
459 We pass this information between dwarf2_add_member_fn and
460 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
461 #define TYPE_FIELD_ARTIFICIAL TYPE_FIELD_BITPOS
463 /* Various complaints about symbol reading that don't abort the process */
465 static struct complaint dwarf2_const_ignored
=
467 "type qualifier 'const' ignored", 0, 0
469 static struct complaint dwarf2_volatile_ignored
=
471 "type qualifier 'volatile' ignored", 0, 0
473 static struct complaint dwarf2_non_const_array_bound_ignored
=
475 "non-constant array bounds form '%s' ignored", 0, 0
477 static struct complaint dwarf2_missing_line_number_section
=
479 "missing .debug_line section", 0, 0
481 static struct complaint dwarf2_mangled_line_number_section
=
483 "mangled .debug_line section", 0, 0
485 static struct complaint dwarf2_unsupported_die_ref_attr
=
487 "unsupported die ref attribute form: '%s'", 0, 0
489 static struct complaint dwarf2_unsupported_stack_op
=
491 "unsupported stack op: '%s'", 0, 0
493 static struct complaint dwarf2_complex_location_expr
=
495 "location expression too complex", 0, 0
497 static struct complaint dwarf2_unsupported_tag
=
499 "unsupported tag: '%s'", 0, 0
501 static struct complaint dwarf2_unsupported_at_encoding
=
503 "unsupported DW_AT_encoding: '%s'", 0, 0
505 static struct complaint dwarf2_unsupported_at_frame_base
=
507 "unsupported DW_AT_frame_base for function '%s'", 0, 0
509 static struct complaint dwarf2_unexpected_tag
=
511 "unexepected tag in read_type_die: '%s'", 0, 0
513 static struct complaint dwarf2_missing_at_frame_base
=
515 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
517 static struct complaint dwarf2_bad_static_member_name
=
519 "unrecognized static data member name '%s'", 0, 0
521 static struct complaint dwarf2_unsupported_accessibility
=
523 "unsupported accessibility %d", 0, 0
525 static struct complaint dwarf2_bad_member_name_complaint
=
527 "cannot extract member name from '%s'", 0, 0
529 static struct complaint dwarf2_missing_member_fn_type_complaint
=
531 "member function type missing for '%s'", 0, 0
533 static struct complaint dwarf2_vtbl_not_found_complaint
=
535 "virtual function table pointer not found when defining class '%s'", 0, 0
537 static struct complaint dwarf2_absolute_sibling_complaint
=
539 "ignoring absolute DW_AT_sibling", 0, 0
541 static struct complaint dwarf2_const_value_length_mismatch
=
543 "const value length mismatch for '%s', got %d, expected %d", 0, 0
545 static struct complaint dwarf2_unsupported_const_value_attr
=
547 "unsupported const value attribute form: '%s'", 0, 0
550 /* Externals references. */
551 extern int info_verbose
; /* From main.c; nonzero => verbose */
553 /* local function prototypes */
555 static void dwarf2_locate_sections (bfd
*, asection
*, PTR
);
558 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
561 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
563 static char *scan_partial_symbols (char *, struct objfile
*,
564 CORE_ADDR
*, CORE_ADDR
*,
565 const struct comp_unit_head
*);
567 static void add_partial_symbol (struct partial_die_info
*, struct objfile
*,
568 const struct comp_unit_head
*);
570 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
572 static void psymtab_to_symtab_1 (struct partial_symtab
*);
574 static char *dwarf2_read_section (struct objfile
*, file_ptr
, unsigned int);
576 static void dwarf2_read_abbrevs (bfd
*, unsigned int);
578 static void dwarf2_empty_abbrev_table (PTR
);
580 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int);
582 static char *read_partial_die (struct partial_die_info
*,
583 bfd
*, char *, int *,
584 const struct comp_unit_head
*);
586 static char *read_full_die (struct die_info
**, bfd
*, char *,
587 const struct comp_unit_head
*);
589 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
590 bfd
*, char *, const struct comp_unit_head
*);
592 static unsigned int read_1_byte (bfd
*, char *);
594 static int read_1_signed_byte (bfd
*, char *);
596 static unsigned int read_2_bytes (bfd
*, char *);
598 static unsigned int read_4_bytes (bfd
*, char *);
600 static unsigned long read_8_bytes (bfd
*, char *);
602 static CORE_ADDR
read_address (bfd
*, char *ptr
, const struct comp_unit_head
*,
605 static LONGEST
read_initial_length (bfd
*, char *,
606 struct comp_unit_head
*, int *bytes_read
);
608 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
611 static char *read_n_bytes (bfd
*, char *, unsigned int);
613 static char *read_string (bfd
*, char *, unsigned int *);
615 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
617 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
619 static void set_cu_language (unsigned int);
621 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
623 static int die_is_declaration (struct die_info
*);
625 static void dwarf_decode_lines (unsigned int, char *, bfd
*,
626 const struct comp_unit_head
*);
628 static void dwarf2_start_subfile (char *, char *);
630 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
631 struct objfile
*, const struct comp_unit_head
*);
633 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
634 struct objfile
*, const struct comp_unit_head
*);
636 static void dwarf2_const_value_data (struct attribute
*attr
,
640 static struct type
*die_type (struct die_info
*, struct objfile
*,
641 const struct comp_unit_head
*);
643 static struct type
*die_containing_type (struct die_info
*, struct objfile
*,
644 const struct comp_unit_head
*);
647 static struct type
*type_at_offset (unsigned int, struct objfile
*);
650 static struct type
*tag_type_to_type (struct die_info
*, struct objfile
*,
651 const struct comp_unit_head
*);
653 static void read_type_die (struct die_info
*, struct objfile
*,
654 const struct comp_unit_head
*);
656 static void read_typedef (struct die_info
*, struct objfile
*,
657 const struct comp_unit_head
*);
659 static void read_base_type (struct die_info
*, struct objfile
*);
661 static void read_file_scope (struct die_info
*, struct objfile
*,
662 const struct comp_unit_head
*);
664 static void read_func_scope (struct die_info
*, struct objfile
*,
665 const struct comp_unit_head
*);
667 static void read_lexical_block_scope (struct die_info
*, struct objfile
*,
668 const struct comp_unit_head
*);
670 static int dwarf2_get_pc_bounds (struct die_info
*,
671 CORE_ADDR
*, CORE_ADDR
*, struct objfile
*);
673 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
674 struct objfile
*, const struct comp_unit_head
*);
676 static void dwarf2_attach_fields_to_type (struct field_info
*,
677 struct type
*, struct objfile
*);
679 static void dwarf2_add_member_fn (struct field_info
*,
680 struct die_info
*, struct type
*,
681 struct objfile
*objfile
,
682 const struct comp_unit_head
*);
684 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
685 struct type
*, struct objfile
*);
687 static void read_structure_scope (struct die_info
*, struct objfile
*,
688 const struct comp_unit_head
*);
690 static void read_common_block (struct die_info
*, struct objfile
*,
691 const struct comp_unit_head
*);
693 static void read_enumeration (struct die_info
*, struct objfile
*,
694 const struct comp_unit_head
*);
696 static struct type
*dwarf_base_type (int, int, struct objfile
*);
698 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct objfile
*,
699 const struct comp_unit_head
*);
701 static void read_array_type (struct die_info
*, struct objfile
*,
702 const struct comp_unit_head
*);
704 static void read_tag_pointer_type (struct die_info
*, struct objfile
*,
705 const struct comp_unit_head
*);
707 static void read_tag_ptr_to_member_type (struct die_info
*, struct objfile
*,
708 const struct comp_unit_head
*);
710 static void read_tag_reference_type (struct die_info
*, struct objfile
*,
711 const struct comp_unit_head
*);
713 static void read_tag_const_type (struct die_info
*, struct objfile
*,
714 const struct comp_unit_head
*);
716 static void read_tag_volatile_type (struct die_info
*, struct objfile
*,
717 const struct comp_unit_head
*);
719 static void read_tag_string_type (struct die_info
*, struct objfile
*);
721 static void read_subroutine_type (struct die_info
*, struct objfile
*,
722 const struct comp_unit_head
*);
724 struct die_info
*read_comp_unit (char *, bfd
*, const struct comp_unit_head
*);
726 static void free_die_list (struct die_info
*);
728 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
730 static void process_die (struct die_info
*, struct objfile
*,
731 const struct comp_unit_head
*);
733 static char *dwarf2_linkage_name (struct die_info
*);
735 static char *dwarf_tag_name (unsigned int);
737 static char *dwarf_attr_name (unsigned int);
739 static char *dwarf_form_name (unsigned int);
741 static char *dwarf_stack_op_name (unsigned int);
743 static char *dwarf_bool_name (unsigned int);
745 static char *dwarf_type_encoding_name (unsigned int);
748 static char *dwarf_cfi_name (unsigned int);
750 struct die_info
*copy_die (struct die_info
*);
753 struct die_info
*sibling_die (struct die_info
*);
755 void dump_die (struct die_info
*);
757 void dump_die_list (struct die_info
*);
759 void store_in_ref_table (unsigned int, struct die_info
*);
761 static void dwarf2_empty_hash_tables (void);
763 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
765 struct die_info
*follow_die_ref (unsigned int);
767 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
769 /* memory allocation interface */
771 static void dwarf2_free_tmp_obstack (PTR
);
773 static struct dwarf_block
*dwarf_alloc_block (void);
775 static struct abbrev_info
*dwarf_alloc_abbrev (void);
777 static struct die_info
*dwarf_alloc_die (void);
779 /* Try to locate the sections we need for DWARF 2 debugging
780 information and return true if we have enough to do something. */
783 dwarf2_has_info (bfd
*abfd
)
785 dwarf_info_offset
= dwarf_abbrev_offset
= dwarf_line_offset
= 0;
786 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
787 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
797 /* This function is mapped across the sections and remembers the
798 offset and size of each of the debugging sections we are interested
802 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, PTR ignore_ptr
)
804 if (STREQ (sectp
->name
, INFO_SECTION
))
806 dwarf_info_offset
= sectp
->filepos
;
807 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
809 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
811 dwarf_abbrev_offset
= sectp
->filepos
;
812 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
814 else if (STREQ (sectp
->name
, LINE_SECTION
))
816 dwarf_line_offset
= sectp
->filepos
;
817 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
819 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
821 dwarf_pubnames_offset
= sectp
->filepos
;
822 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
824 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
826 dwarf_aranges_offset
= sectp
->filepos
;
827 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
829 else if (STREQ (sectp
->name
, LOC_SECTION
))
831 dwarf_loc_offset
= sectp
->filepos
;
832 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
834 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
836 dwarf_macinfo_offset
= sectp
->filepos
;
837 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
839 else if (STREQ (sectp
->name
, STR_SECTION
))
841 dwarf_str_offset
= sectp
->filepos
;
842 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
846 /* Build a partial symbol table. */
849 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
852 /* We definitely need the .debug_info and .debug_abbrev sections */
854 dwarf_info_buffer
= dwarf2_read_section (objfile
,
857 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
860 dwarf_line_buffer
= dwarf2_read_section (objfile
,
864 if (mainline
|| objfile
->global_psymbols
.size
== 0 ||
865 objfile
->static_psymbols
.size
== 0)
867 init_psymbol_list (objfile
, 1024);
871 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
873 /* Things are significantly easier if we have .debug_aranges and
874 .debug_pubnames sections */
876 dwarf2_build_psymtabs_easy (objfile
, mainline
);
880 /* only test this case for now */
882 /* In this case we have to work a bit harder */
883 dwarf2_build_psymtabs_hard (objfile
, mainline
);
888 /* Build the partial symbol table from the information in the
889 .debug_pubnames and .debug_aranges sections. */
892 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
894 bfd
*abfd
= objfile
->obfd
;
895 char *aranges_buffer
, *pubnames_buffer
;
896 char *aranges_ptr
, *pubnames_ptr
;
897 unsigned int entry_length
, version
, info_offset
, info_size
;
899 pubnames_buffer
= dwarf2_read_section (objfile
,
900 dwarf_pubnames_offset
,
901 dwarf_pubnames_size
);
902 pubnames_ptr
= pubnames_buffer
;
903 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
905 struct comp_unit_head cu_header
;
908 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
910 pubnames_ptr
+= bytes_read
;
911 version
= read_1_byte (abfd
, pubnames_ptr
);
913 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
915 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
919 aranges_buffer
= dwarf2_read_section (objfile
,
920 dwarf_aranges_offset
,
926 /* Read in the comp unit header information from the debug_info at
930 read_comp_unit_head (struct comp_unit_head
*cu_header
,
931 char *info_ptr
, bfd
*abfd
)
935 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
937 info_ptr
+= bytes_read
;
938 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
940 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
942 info_ptr
+= bytes_read
;
943 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
945 signed_addr
= bfd_get_sign_extend_vma (abfd
);
947 internal_error ("read_comp_unit_head: dwarf from non elf file");
948 cu_header
->signed_addr_p
= signed_addr
;
952 /* Build the partial symbol table by doing a quick pass through the
953 .debug_info and .debug_abbrev sections. */
956 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
958 /* Instead of reading this into a big buffer, we should probably use
959 mmap() on architectures that support it. (FIXME) */
960 bfd
*abfd
= objfile
->obfd
;
961 char *info_ptr
, *abbrev_ptr
;
962 char *beg_of_comp_unit
;
963 struct partial_die_info comp_unit_die
;
964 struct partial_symtab
*pst
;
965 struct cleanup
*back_to
;
966 int comp_unit_has_pc_info
;
967 CORE_ADDR lowpc
, highpc
;
969 info_ptr
= dwarf_info_buffer
;
970 abbrev_ptr
= dwarf_abbrev_buffer
;
972 obstack_init (&dwarf2_tmp_obstack
);
973 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
975 while ((unsigned int) (info_ptr
- dwarf_info_buffer
)
976 + ((info_ptr
- dwarf_info_buffer
) % 4) < dwarf_info_size
)
978 struct comp_unit_head cu_header
;
979 beg_of_comp_unit
= info_ptr
;
980 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
982 if (cu_header
.version
!= 2)
984 error ("Dwarf Error: wrong version in compilation unit header.");
987 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
989 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
990 (long) cu_header
.abbrev_offset
,
991 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
994 if (beg_of_comp_unit
+ cu_header
.length
+ cu_header
.initial_length_size
995 > dwarf_info_buffer
+ dwarf_info_size
)
997 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
998 (long) cu_header
.length
,
999 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1002 /* Read the abbrevs for this compilation unit into a table */
1003 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1004 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1006 /* Read the compilation unit die */
1007 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1008 &comp_unit_has_pc_info
, &cu_header
);
1010 /* Set the language we're debugging */
1011 set_cu_language (comp_unit_die
.language
);
1013 /* Allocate a new partial symbol table structure */
1014 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1015 comp_unit_die
.name
? comp_unit_die
.name
: "",
1016 comp_unit_die
.lowpc
,
1017 objfile
->global_psymbols
.next
,
1018 objfile
->static_psymbols
.next
);
1020 pst
->read_symtab_private
= (char *)
1021 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1022 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1023 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1024 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1025 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1026 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1027 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1028 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1030 /* Store the function that reads in the rest of the symbol table */
1031 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1033 /* Check if comp unit has_children.
1034 If so, read the rest of the partial symbols from this comp unit.
1035 If not, there's no more debug_info for this comp unit. */
1036 if (comp_unit_die
.has_children
)
1038 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
,
1041 /* If the compilation unit didn't have an explicit address range,
1042 then use the information extracted from its child dies. */
1043 if (!comp_unit_has_pc_info
)
1045 comp_unit_die
.lowpc
= lowpc
;
1046 comp_unit_die
.highpc
= highpc
;
1049 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1050 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1052 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1053 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1054 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1055 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1056 sort_pst_symbols (pst
);
1058 /* If there is already a psymtab or symtab for a file of this
1059 name, remove it. (If there is a symtab, more drastic things
1060 also happen.) This happens in VxWorks. */
1061 free_named_symtabs (pst
->filename
);
1063 info_ptr
= beg_of_comp_unit
+ cu_header
.length
1064 + cu_header
.initial_length_size
;
1066 do_cleanups (back_to
);
1069 /* Read in all interesting dies to the end of the compilation unit. */
1072 scan_partial_symbols (char *info_ptr
, struct objfile
*objfile
,
1073 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1074 const struct comp_unit_head
*cu_header
)
1076 bfd
*abfd
= objfile
->obfd
;
1077 struct partial_die_info pdi
;
1079 /* This function is called after we've read in the comp_unit_die in
1080 order to read its children. We start the nesting level at 1 since
1081 we have pushed 1 level down in order to read the comp unit's children.
1082 The comp unit itself is at level 0, so we stop reading when we pop
1083 back to that level. */
1085 int nesting_level
= 1;
1088 *lowpc
= ((CORE_ADDR
) -1);
1089 *highpc
= ((CORE_ADDR
) 0);
1091 while (nesting_level
)
1093 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
,
1094 &has_pc_info
, cu_header
);
1100 case DW_TAG_subprogram
:
1103 if (pdi
.lowpc
< *lowpc
)
1107 if (pdi
.highpc
> *highpc
)
1109 *highpc
= pdi
.highpc
;
1111 if ((pdi
.is_external
|| nesting_level
== 1)
1112 && !pdi
.is_declaration
)
1114 add_partial_symbol (&pdi
, objfile
, cu_header
);
1118 case DW_TAG_variable
:
1119 case DW_TAG_typedef
:
1120 case DW_TAG_class_type
:
1121 case DW_TAG_structure_type
:
1122 case DW_TAG_union_type
:
1123 case DW_TAG_enumeration_type
:
1124 if ((pdi
.is_external
|| nesting_level
== 1)
1125 && !pdi
.is_declaration
)
1127 add_partial_symbol (&pdi
, objfile
, cu_header
);
1130 case DW_TAG_enumerator
:
1131 /* File scope enumerators are added to the partial symbol
1133 if (nesting_level
== 2)
1134 add_partial_symbol (&pdi
, objfile
, cu_header
);
1136 case DW_TAG_base_type
:
1137 /* File scope base type definitions are added to the partial
1139 if (nesting_level
== 1)
1140 add_partial_symbol (&pdi
, objfile
, cu_header
);
1147 /* If the die has a sibling, skip to the sibling.
1148 Do not skip enumeration types, we want to record their
1150 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1152 info_ptr
= pdi
.sibling
;
1154 else if (pdi
.has_children
)
1156 /* Die has children, but the optional DW_AT_sibling attribute
1167 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1168 from `maint check'. */
1169 if (*lowpc
== ((CORE_ADDR
) -1))
1175 add_partial_symbol (struct partial_die_info
*pdi
, struct objfile
*objfile
,
1176 const struct comp_unit_head
*cu_header
)
1182 case DW_TAG_subprogram
:
1183 if (pdi
->is_external
)
1185 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1186 mst_text, objfile); */
1187 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1188 VAR_NAMESPACE
, LOC_BLOCK
,
1189 &objfile
->global_psymbols
,
1190 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1194 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1195 mst_file_text, objfile); */
1196 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1197 VAR_NAMESPACE
, LOC_BLOCK
,
1198 &objfile
->static_psymbols
,
1199 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1202 case DW_TAG_variable
:
1203 if (pdi
->is_external
)
1206 Don't enter into the minimal symbol tables as there is
1207 a minimal symbol table entry from the ELF symbols already.
1208 Enter into partial symbol table if it has a location
1209 descriptor or a type.
1210 If the location descriptor is missing, new_symbol will create
1211 a LOC_UNRESOLVED symbol, the address of the variable will then
1212 be determined from the minimal symbol table whenever the variable
1214 The address for the partial symbol table entry is not
1215 used by GDB, but it comes in handy for debugging partial symbol
1219 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1220 if (pdi
->locdesc
|| pdi
->has_type
)
1221 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1222 VAR_NAMESPACE
, LOC_STATIC
,
1223 &objfile
->global_psymbols
,
1224 0, addr
+ baseaddr
, cu_language
, objfile
);
1228 /* Static Variable. Skip symbols without location descriptors. */
1229 if (pdi
->locdesc
== NULL
)
1231 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1232 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1233 mst_file_data, objfile); */
1234 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1235 VAR_NAMESPACE
, LOC_STATIC
,
1236 &objfile
->static_psymbols
,
1237 0, addr
+ baseaddr
, cu_language
, objfile
);
1240 case DW_TAG_typedef
:
1241 case DW_TAG_base_type
:
1242 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1243 VAR_NAMESPACE
, LOC_TYPEDEF
,
1244 &objfile
->static_psymbols
,
1245 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1247 case DW_TAG_class_type
:
1248 case DW_TAG_structure_type
:
1249 case DW_TAG_union_type
:
1250 case DW_TAG_enumeration_type
:
1251 /* Skip aggregate types without children, these are external
1253 if (pdi
->has_children
== 0)
1255 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1256 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1257 &objfile
->static_psymbols
,
1258 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1260 if (cu_language
== language_cplus
)
1262 /* For C++, these implicitly act as typedefs as well. */
1263 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1264 VAR_NAMESPACE
, LOC_TYPEDEF
,
1265 &objfile
->static_psymbols
,
1266 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1269 case DW_TAG_enumerator
:
1270 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1271 VAR_NAMESPACE
, LOC_CONST
,
1272 &objfile
->static_psymbols
,
1273 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1280 /* Expand this partial symbol table into a full symbol table. */
1283 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1285 /* FIXME: This is barely more than a stub. */
1290 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1296 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1297 gdb_flush (gdb_stdout
);
1300 psymtab_to_symtab_1 (pst
);
1302 /* Finish up the debug error message. */
1304 printf_filtered ("done.\n");
1310 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1312 struct objfile
*objfile
= pst
->objfile
;
1313 bfd
*abfd
= objfile
->obfd
;
1314 struct comp_unit_head cu_header
;
1315 struct die_info
*dies
;
1316 unsigned long offset
;
1317 CORE_ADDR lowpc
, highpc
;
1318 struct die_info
*child_die
;
1320 struct symtab
*symtab
;
1321 struct cleanup
*back_to
;
1323 /* Set local variables from the partial symbol table info. */
1324 offset
= DWARF_INFO_OFFSET (pst
);
1325 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1326 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1327 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1328 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1329 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1330 cu_header_offset
= offset
;
1331 info_ptr
= dwarf_info_buffer
+ offset
;
1333 obstack_init (&dwarf2_tmp_obstack
);
1334 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1337 make_cleanup (really_free_pendings
, NULL
);
1339 /* read in the comp_unit header */
1340 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1342 /* Read the abbrevs for this compilation unit */
1343 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1344 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1346 dies
= read_comp_unit (info_ptr
, abfd
, &cu_header
);
1348 make_cleanup_free_die_list (dies
);
1350 /* Do line number decoding in read_file_scope () */
1351 process_die (dies
, objfile
, &cu_header
);
1353 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1355 /* Some compilers don't define a DW_AT_high_pc attribute for
1356 the compilation unit. If the DW_AT_high_pc is missing,
1357 synthesize it, by scanning the DIE's below the compilation unit. */
1359 if (dies
->has_children
)
1361 child_die
= dies
->next
;
1362 while (child_die
&& child_die
->tag
)
1364 if (child_die
->tag
== DW_TAG_subprogram
)
1366 CORE_ADDR low
, high
;
1368 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1370 highpc
= max (highpc
, high
);
1373 child_die
= sibling_die (child_die
);
1377 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1379 /* Set symtab language to language from DW_AT_language.
1380 If the compilation is from a C file generated by language preprocessors,
1381 do not set the language if it was already deduced by start_subfile. */
1383 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1385 symtab
->language
= cu_language
;
1387 pst
->symtab
= symtab
;
1389 sort_symtab_syms (pst
->symtab
);
1391 do_cleanups (back_to
);
1394 /* Process a die and its children. */
1397 process_die (struct die_info
*die
, struct objfile
*objfile
,
1398 const struct comp_unit_head
*cu_header
)
1402 case DW_TAG_padding
:
1404 case DW_TAG_compile_unit
:
1405 read_file_scope (die
, objfile
, cu_header
);
1407 case DW_TAG_subprogram
:
1408 read_subroutine_type (die
, objfile
, cu_header
);
1409 read_func_scope (die
, objfile
, cu_header
);
1411 case DW_TAG_inlined_subroutine
:
1412 /* FIXME: These are ignored for now.
1413 They could be used to set breakpoints on all inlined instances
1414 of a function and make GDB `next' properly over inlined functions. */
1416 case DW_TAG_lexical_block
:
1417 read_lexical_block_scope (die
, objfile
, cu_header
);
1419 case DW_TAG_class_type
:
1420 case DW_TAG_structure_type
:
1421 case DW_TAG_union_type
:
1422 read_structure_scope (die
, objfile
, cu_header
);
1424 case DW_TAG_enumeration_type
:
1425 read_enumeration (die
, objfile
, cu_header
);
1427 case DW_TAG_subroutine_type
:
1428 read_subroutine_type (die
, objfile
, cu_header
);
1430 case DW_TAG_array_type
:
1431 read_array_type (die
, objfile
, cu_header
);
1433 case DW_TAG_pointer_type
:
1434 read_tag_pointer_type (die
, objfile
, cu_header
);
1436 case DW_TAG_ptr_to_member_type
:
1437 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
1439 case DW_TAG_reference_type
:
1440 read_tag_reference_type (die
, objfile
, cu_header
);
1442 case DW_TAG_string_type
:
1443 read_tag_string_type (die
, objfile
);
1445 case DW_TAG_base_type
:
1446 read_base_type (die
, objfile
);
1447 if (dwarf_attr (die
, DW_AT_name
))
1449 /* Add a typedef symbol for the base type definition. */
1450 new_symbol (die
, die
->type
, objfile
, cu_header
);
1453 case DW_TAG_common_block
:
1454 read_common_block (die
, objfile
, cu_header
);
1456 case DW_TAG_common_inclusion
:
1459 new_symbol (die
, NULL
, objfile
, cu_header
);
1465 read_file_scope (struct die_info
*die
, struct objfile
*objfile
,
1466 const struct comp_unit_head
*cu_header
)
1468 unsigned int line_offset
= 0;
1469 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1470 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1471 struct attribute
*attr
;
1472 char *name
= "<unknown>";
1473 char *comp_dir
= NULL
;
1474 struct die_info
*child_die
;
1475 bfd
*abfd
= objfile
->obfd
;
1477 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1479 if (die
->has_children
)
1481 child_die
= die
->next
;
1482 while (child_die
&& child_die
->tag
)
1484 if (child_die
->tag
== DW_TAG_subprogram
)
1486 CORE_ADDR low
, high
;
1488 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1490 lowpc
= min (lowpc
, low
);
1491 highpc
= max (highpc
, high
);
1494 child_die
= sibling_die (child_die
);
1499 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1500 from finish_block. */
1501 if (lowpc
== ((CORE_ADDR
) -1))
1506 attr
= dwarf_attr (die
, DW_AT_name
);
1509 name
= DW_STRING (attr
);
1511 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1514 comp_dir
= DW_STRING (attr
);
1517 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1518 directory, get rid of it. */
1519 char *cp
= strchr (comp_dir
, ':');
1521 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1526 if (objfile
->ei
.entry_point
>= lowpc
&&
1527 objfile
->ei
.entry_point
< highpc
)
1529 objfile
->ei
.entry_file_lowpc
= lowpc
;
1530 objfile
->ei
.entry_file_highpc
= highpc
;
1533 attr
= dwarf_attr (die
, DW_AT_language
);
1536 set_cu_language (DW_UNSND (attr
));
1539 /* We assume that we're processing GCC output. */
1540 processing_gcc_compilation
= 2;
1542 /* FIXME:Do something here. */
1543 if (dip
->at_producer
!= NULL
)
1545 handle_producer (dip
->at_producer
);
1549 /* The compilation unit may be in a different language or objfile,
1550 zero out all remembered fundamental types. */
1551 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1553 start_symtab (name
, comp_dir
, lowpc
);
1554 record_debugformat ("DWARF 2");
1556 /* Decode line number information if present. */
1557 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1560 line_offset
= DW_UNSND (attr
);
1561 dwarf_decode_lines (line_offset
, comp_dir
, abfd
, cu_header
);
1564 /* Process all dies in compilation unit. */
1565 if (die
->has_children
)
1567 child_die
= die
->next
;
1568 while (child_die
&& child_die
->tag
)
1570 process_die (child_die
, objfile
, cu_header
);
1571 child_die
= sibling_die (child_die
);
1577 read_func_scope (struct die_info
*die
, struct objfile
*objfile
,
1578 const struct comp_unit_head
*cu_header
)
1580 register struct context_stack
*new;
1583 struct die_info
*child_die
;
1584 struct attribute
*attr
;
1587 name
= dwarf2_linkage_name (die
);
1589 /* Ignore functions with missing or empty names and functions with
1590 missing or invalid low and high pc attributes. */
1591 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1597 if (objfile
->ei
.entry_point
>= lowpc
&&
1598 objfile
->ei
.entry_point
< highpc
)
1600 objfile
->ei
.entry_func_lowpc
= lowpc
;
1601 objfile
->ei
.entry_func_highpc
= highpc
;
1604 /* Decode DW_AT_frame_base location descriptor if present, keep result
1605 for DW_OP_fbreg operands in decode_locdesc. */
1606 frame_base_reg
= -1;
1607 frame_base_offset
= 0;
1608 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1611 CORE_ADDR addr
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
1613 complain (&dwarf2_unsupported_at_frame_base
, name
);
1615 frame_base_reg
= addr
;
1618 frame_base_reg
= basereg
;
1619 frame_base_offset
= addr
;
1622 complain (&dwarf2_unsupported_at_frame_base
, name
);
1625 new = push_context (0, lowpc
);
1626 new->name
= new_symbol (die
, die
->type
, objfile
, cu_header
);
1627 list_in_scope
= &local_symbols
;
1629 if (die
->has_children
)
1631 child_die
= die
->next
;
1632 while (child_die
&& child_die
->tag
)
1634 process_die (child_die
, objfile
, cu_header
);
1635 child_die
= sibling_die (child_die
);
1639 new = pop_context ();
1640 /* Make a block for the local symbols within. */
1641 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1642 lowpc
, highpc
, objfile
);
1643 list_in_scope
= &file_symbols
;
1646 /* Process all the DIES contained within a lexical block scope. Start
1647 a new scope, process the dies, and then close the scope. */
1650 read_lexical_block_scope (struct die_info
*die
, struct objfile
*objfile
,
1651 const struct comp_unit_head
*cu_header
)
1653 register struct context_stack
*new;
1654 CORE_ADDR lowpc
, highpc
;
1655 struct die_info
*child_die
;
1657 /* Ignore blocks with missing or invalid low and high pc attributes. */
1658 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1663 push_context (0, lowpc
);
1664 if (die
->has_children
)
1666 child_die
= die
->next
;
1667 while (child_die
&& child_die
->tag
)
1669 process_die (child_die
, objfile
, cu_header
);
1670 child_die
= sibling_die (child_die
);
1673 new = pop_context ();
1675 if (local_symbols
!= NULL
)
1677 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1680 local_symbols
= new->locals
;
1683 /* Get low and high pc attributes from a die.
1684 Return 1 if the attributes are present and valid, otherwise, return 0. */
1687 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1688 struct objfile
*objfile
)
1690 struct attribute
*attr
;
1694 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1696 low
= DW_ADDR (attr
);
1699 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1701 high
= DW_ADDR (attr
);
1708 /* When using the GNU linker, .gnu.linkonce. sections are used to
1709 eliminate duplicate copies of functions and vtables and such.
1710 The linker will arbitrarily choose one and discard the others.
1711 The AT_*_pc values for such functions refer to local labels in
1712 these sections. If the section from that file was discarded, the
1713 labels are not in the output, so the relocs get a value of 0.
1714 If this is a discarded function, mark the pc bounds as invalid,
1715 so that GDB will ignore it. */
1716 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
1724 /* Add an aggregate field to the field list. */
1727 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
1728 struct objfile
*objfile
,
1729 const struct comp_unit_head
*cu_header
)
1731 struct nextfield
*new_field
;
1732 struct attribute
*attr
;
1734 char *fieldname
= "";
1736 /* Allocate a new field list entry and link it in. */
1737 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1738 make_cleanup (free
, new_field
);
1739 memset (new_field
, 0, sizeof (struct nextfield
));
1740 new_field
->next
= fip
->fields
;
1741 fip
->fields
= new_field
;
1744 /* Handle accessibility and virtuality of field.
1745 The default accessibility for members is public, the default
1746 accessibility for inheritance is private. */
1747 if (die
->tag
!= DW_TAG_inheritance
)
1748 new_field
->accessibility
= DW_ACCESS_public
;
1750 new_field
->accessibility
= DW_ACCESS_private
;
1751 new_field
->virtuality
= DW_VIRTUALITY_none
;
1753 attr
= dwarf_attr (die
, DW_AT_accessibility
);
1755 new_field
->accessibility
= DW_UNSND (attr
);
1756 if (new_field
->accessibility
!= DW_ACCESS_public
)
1757 fip
->non_public_fields
= 1;
1758 attr
= dwarf_attr (die
, DW_AT_virtuality
);
1760 new_field
->virtuality
= DW_UNSND (attr
);
1762 fp
= &new_field
->field
;
1763 if (die
->tag
== DW_TAG_member
)
1765 /* Get type of field. */
1766 fp
->type
= die_type (die
, objfile
, cu_header
);
1768 /* Get bit size of field (zero if none). */
1769 attr
= dwarf_attr (die
, DW_AT_bit_size
);
1772 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
1776 FIELD_BITSIZE (*fp
) = 0;
1779 /* Get bit offset of field. */
1780 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1783 FIELD_BITPOS (*fp
) =
1784 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) * bits_per_byte
;
1787 FIELD_BITPOS (*fp
) = 0;
1788 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
1791 if (BITS_BIG_ENDIAN
)
1793 /* For big endian bits, the DW_AT_bit_offset gives the
1794 additional bit offset from the MSB of the containing
1795 anonymous object to the MSB of the field. We don't
1796 have to do anything special since we don't need to
1797 know the size of the anonymous object. */
1798 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
1802 /* For little endian bits, compute the bit offset to the
1803 MSB of the anonymous object, subtract off the number of
1804 bits from the MSB of the field to the MSB of the
1805 object, and then subtract off the number of bits of
1806 the field itself. The result is the bit offset of
1807 the LSB of the field. */
1809 int bit_offset
= DW_UNSND (attr
);
1811 attr
= dwarf_attr (die
, DW_AT_byte_size
);
1814 /* The size of the anonymous object containing
1815 the bit field is explicit, so use the
1816 indicated size (in bytes). */
1817 anonymous_size
= DW_UNSND (attr
);
1821 /* The size of the anonymous object containing
1822 the bit field must be inferred from the type
1823 attribute of the data member containing the
1825 anonymous_size
= TYPE_LENGTH (fp
->type
);
1827 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
1828 - bit_offset
- FIELD_BITSIZE (*fp
);
1832 /* Get name of field. */
1833 attr
= dwarf_attr (die
, DW_AT_name
);
1834 if (attr
&& DW_STRING (attr
))
1835 fieldname
= DW_STRING (attr
);
1836 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
1837 &objfile
->type_obstack
);
1839 /* Change accessibility for artificial fields (e.g. virtual table
1840 pointer or virtual base class pointer) to private. */
1841 if (dwarf_attr (die
, DW_AT_artificial
))
1843 new_field
->accessibility
= DW_ACCESS_private
;
1844 fip
->non_public_fields
= 1;
1847 else if (die
->tag
== DW_TAG_variable
)
1851 /* C++ static member.
1852 Get name of field. */
1853 attr
= dwarf_attr (die
, DW_AT_name
);
1854 if (attr
&& DW_STRING (attr
))
1855 fieldname
= DW_STRING (attr
);
1859 /* Get physical name. */
1860 physname
= dwarf2_linkage_name (die
);
1862 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
1863 &objfile
->type_obstack
));
1864 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
1865 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
1866 &objfile
->type_obstack
);
1868 else if (die
->tag
== DW_TAG_inheritance
)
1870 /* C++ base class field. */
1871 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1873 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
)
1875 FIELD_BITSIZE (*fp
) = 0;
1876 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
1877 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
1878 fip
->nbaseclasses
++;
1882 /* Create the vector of fields, and attach it to the type. */
1885 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
1886 struct objfile
*objfile
)
1888 int nfields
= fip
->nfields
;
1890 /* Record the field count, allocate space for the array of fields,
1891 and create blank accessibility bitfields if necessary. */
1892 TYPE_NFIELDS (type
) = nfields
;
1893 TYPE_FIELDS (type
) = (struct field
*)
1894 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
1895 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
1897 if (fip
->non_public_fields
)
1899 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1901 TYPE_FIELD_PRIVATE_BITS (type
) =
1902 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1903 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
1905 TYPE_FIELD_PROTECTED_BITS (type
) =
1906 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1907 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
1909 TYPE_FIELD_IGNORE_BITS (type
) =
1910 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1911 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
1914 /* If the type has baseclasses, allocate and clear a bit vector for
1915 TYPE_FIELD_VIRTUAL_BITS. */
1916 if (fip
->nbaseclasses
)
1918 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
1921 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1922 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
1923 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
1924 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
1925 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
1928 /* Copy the saved-up fields into the field vector. Start from the head
1929 of the list, adding to the tail of the field array, so that they end
1930 up in the same order in the array in which they were added to the list. */
1931 while (nfields
-- > 0)
1933 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
1934 switch (fip
->fields
->accessibility
)
1936 case DW_ACCESS_private
:
1937 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
1940 case DW_ACCESS_protected
:
1941 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
1944 case DW_ACCESS_public
:
1948 /* Unknown accessibility. Complain and treat it as public. */
1950 complain (&dwarf2_unsupported_accessibility
,
1951 fip
->fields
->accessibility
);
1955 if (nfields
< fip
->nbaseclasses
)
1957 switch (fip
->fields
->virtuality
)
1959 case DW_VIRTUALITY_virtual
:
1960 case DW_VIRTUALITY_pure_virtual
:
1961 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
1965 fip
->fields
= fip
->fields
->next
;
1969 /* Add a member function to the proper fieldlist. */
1972 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
1973 struct type
*type
, struct objfile
*objfile
,
1974 const struct comp_unit_head
*cu_header
)
1976 struct attribute
*attr
;
1977 struct fnfieldlist
*flp
;
1979 struct fn_field
*fnp
;
1982 struct nextfnfield
*new_fnfield
;
1984 /* Get name of member function. */
1985 attr
= dwarf_attr (die
, DW_AT_name
);
1986 if (attr
&& DW_STRING (attr
))
1987 fieldname
= DW_STRING (attr
);
1991 /* Get the mangled name. */
1992 physname
= dwarf2_linkage_name (die
);
1994 /* Look up member function name in fieldlist. */
1995 for (i
= 0; i
< fip
->nfnfields
; i
++)
1997 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2001 /* Create new list element if necessary. */
2002 if (i
< fip
->nfnfields
)
2003 flp
= &fip
->fnfieldlists
[i
];
2006 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2008 fip
->fnfieldlists
= (struct fnfieldlist
*)
2009 xrealloc (fip
->fnfieldlists
,
2010 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2011 * sizeof (struct fnfieldlist
));
2012 if (fip
->nfnfields
== 0)
2013 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2015 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2016 flp
->name
= fieldname
;
2022 /* Create a new member function field and chain it to the field list
2024 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2025 make_cleanup (free
, new_fnfield
);
2026 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2027 new_fnfield
->next
= flp
->head
;
2028 flp
->head
= new_fnfield
;
2031 /* Fill in the member function field info. */
2032 fnp
= &new_fnfield
->fnfield
;
2033 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2034 &objfile
->type_obstack
);
2035 fnp
->type
= alloc_type (objfile
);
2036 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2038 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2039 struct type
**arg_types
;
2040 int nparams
= TYPE_NFIELDS (die
->type
);
2043 /* Copy argument types from the subroutine type. */
2044 arg_types
= (struct type
**)
2045 TYPE_ALLOC (fnp
->type
, (nparams
+ 1) * sizeof (struct type
*));
2046 for (iparams
= 0; iparams
< nparams
; iparams
++)
2047 arg_types
[iparams
] = TYPE_FIELD_TYPE (die
->type
, iparams
);
2049 /* Set last entry in argument type vector. */
2050 if (TYPE_FLAGS (die
->type
) & TYPE_FLAG_VARARGS
)
2051 arg_types
[nparams
] = NULL
;
2053 arg_types
[nparams
] = dwarf2_fundamental_type (objfile
, FT_VOID
);
2055 smash_to_method_type (fnp
->type
, type
, return_type
, arg_types
);
2057 /* Handle static member functions.
2058 Dwarf2 has no clean way to discern C++ static and non-static
2059 member functions. G++ helps GDB by marking the first
2060 parameter for non-static member functions (which is the
2061 this pointer) as artificial. We obtain this information
2062 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2063 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2064 fnp
->voffset
= VOFFSET_STATIC
;
2067 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2069 /* Get fcontext from DW_AT_containing_type if present. */
2070 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2071 fnp
->fcontext
= die_containing_type (die
, objfile
, cu_header
);
2073 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2074 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2076 /* Get accessibility. */
2077 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2080 switch (DW_UNSND (attr
))
2082 case DW_ACCESS_private
:
2083 fnp
->is_private
= 1;
2085 case DW_ACCESS_protected
:
2086 fnp
->is_protected
= 1;
2091 /* Get index in virtual function table if it is a virtual member function. */
2092 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2094 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) + 2;
2097 /* Create the vector of member function fields, and attach it to the type. */
2100 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2101 struct objfile
*objfile
)
2103 struct fnfieldlist
*flp
;
2104 int total_length
= 0;
2107 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2108 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2109 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2111 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2113 struct nextfnfield
*nfp
= flp
->head
;
2114 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2117 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2118 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2119 fn_flp
->fn_fields
= (struct fn_field
*)
2120 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2121 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2122 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2124 total_length
+= flp
->length
;
2127 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2128 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2131 /* Called when we find the DIE that starts a structure or union scope
2132 (definition) to process all dies that define the members of the
2135 NOTE: we need to call struct_type regardless of whether or not the
2136 DIE has an at_name attribute, since it might be an anonymous
2137 structure or union. This gets the type entered into our set of
2140 However, if the structure is incomplete (an opaque struct/union)
2141 then suppress creating a symbol table entry for it since gdb only
2142 wants to find the one with the complete definition. Note that if
2143 it is complete, we just call new_symbol, which does it's own
2144 checking about whether the struct/union is anonymous or not (and
2145 suppresses creating a symbol table entry itself). */
2148 read_structure_scope (struct die_info
*die
, struct objfile
*objfile
,
2149 const struct comp_unit_head
*cu_header
)
2152 struct attribute
*attr
;
2154 type
= alloc_type (objfile
);
2156 INIT_CPLUS_SPECIFIC (type
);
2157 attr
= dwarf_attr (die
, DW_AT_name
);
2158 if (attr
&& DW_STRING (attr
))
2160 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2161 strlen (DW_STRING (attr
)),
2162 &objfile
->type_obstack
);
2165 if (die
->tag
== DW_TAG_structure_type
)
2167 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2169 else if (die
->tag
== DW_TAG_union_type
)
2171 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2175 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2177 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2180 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2183 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2187 TYPE_LENGTH (type
) = 0;
2190 /* We need to add the type field to the die immediately so we don't
2191 infinitely recurse when dealing with pointers to the structure
2192 type within the structure itself. */
2195 if (die
->has_children
&& ! die_is_declaration (die
))
2197 struct field_info fi
;
2198 struct die_info
*child_die
;
2199 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2201 memset (&fi
, 0, sizeof (struct field_info
));
2203 child_die
= die
->next
;
2205 while (child_die
&& child_die
->tag
)
2207 if (child_die
->tag
== DW_TAG_member
)
2209 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2211 else if (child_die
->tag
== DW_TAG_variable
)
2213 /* C++ static member. */
2214 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2216 else if (child_die
->tag
== DW_TAG_subprogram
)
2218 /* C++ member function. */
2219 process_die (child_die
, objfile
, cu_header
);
2220 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
, cu_header
);
2222 else if (child_die
->tag
== DW_TAG_inheritance
)
2224 /* C++ base class field. */
2225 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2229 process_die (child_die
, objfile
, cu_header
);
2231 child_die
= sibling_die (child_die
);
2234 /* Attach fields and member functions to the type. */
2236 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2239 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2241 /* Get the type which refers to the base class (possibly this
2242 class itself) which contains the vtable pointer for the current
2243 class from the DW_AT_containing_type attribute. */
2245 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2247 struct type
*t
= die_containing_type (die
, objfile
, cu_header
);
2249 TYPE_VPTR_BASETYPE (type
) = t
;
2252 static const char vptr_name
[] =
2253 {'_', 'v', 'p', 't', 'r', '\0'};
2256 /* Our own class provides vtbl ptr. */
2257 for (i
= TYPE_NFIELDS (t
) - 1;
2258 i
>= TYPE_N_BASECLASSES (t
);
2261 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2263 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2264 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2266 TYPE_VPTR_FIELDNO (type
) = i
;
2271 /* Complain if virtual function table field not found. */
2272 if (i
< TYPE_N_BASECLASSES (t
))
2273 complain (&dwarf2_vtbl_not_found_complaint
,
2274 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2278 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2283 new_symbol (die
, type
, objfile
, cu_header
);
2285 do_cleanups (back_to
);
2289 /* No children, must be stub. */
2290 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2296 /* Given a pointer to a die which begins an enumeration, process all
2297 the dies that define the members of the enumeration.
2299 This will be much nicer in draft 6 of the DWARF spec when our
2300 members will be dies instead squished into the DW_AT_element_list
2303 NOTE: We reverse the order of the element list. */
2306 read_enumeration (struct die_info
*die
, struct objfile
*objfile
,
2307 const struct comp_unit_head
*cu_header
)
2309 struct die_info
*child_die
;
2311 struct field
*fields
;
2312 struct attribute
*attr
;
2315 int unsigned_enum
= 1;
2317 type
= alloc_type (objfile
);
2319 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2320 attr
= dwarf_attr (die
, DW_AT_name
);
2321 if (attr
&& DW_STRING (attr
))
2323 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2324 strlen (DW_STRING (attr
)),
2325 &objfile
->type_obstack
);
2328 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2331 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2335 TYPE_LENGTH (type
) = 0;
2340 if (die
->has_children
)
2342 child_die
= die
->next
;
2343 while (child_die
&& child_die
->tag
)
2345 if (child_die
->tag
!= DW_TAG_enumerator
)
2347 process_die (child_die
, objfile
, cu_header
);
2351 attr
= dwarf_attr (child_die
, DW_AT_name
);
2354 sym
= new_symbol (child_die
, type
, objfile
, cu_header
);
2355 if (SYMBOL_VALUE (sym
) < 0)
2358 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2360 fields
= (struct field
*)
2362 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2363 * sizeof (struct field
));
2366 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2367 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2368 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2369 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2375 child_die
= sibling_die (child_die
);
2380 TYPE_NFIELDS (type
) = num_fields
;
2381 TYPE_FIELDS (type
) = (struct field
*)
2382 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2383 memcpy (TYPE_FIELDS (type
), fields
,
2384 sizeof (struct field
) * num_fields
);
2388 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2391 new_symbol (die
, type
, objfile
, cu_header
);
2394 /* Extract all information from a DW_TAG_array_type DIE and put it in
2395 the DIE's type field. For now, this only handles one dimensional
2399 read_array_type (struct die_info
*die
, struct objfile
*objfile
,
2400 const struct comp_unit_head
*cu_header
)
2402 struct die_info
*child_die
;
2403 struct type
*type
= NULL
;
2404 struct type
*element_type
, *range_type
, *index_type
;
2405 struct type
**range_types
= NULL
;
2406 struct attribute
*attr
;
2408 struct cleanup
*back_to
;
2410 /* Return if we've already decoded this type. */
2416 element_type
= die_type (die
, objfile
, cu_header
);
2418 /* Irix 6.2 native cc creates array types without children for
2419 arrays with unspecified length. */
2420 if (die
->has_children
== 0)
2422 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2423 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2424 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2428 back_to
= make_cleanup (null_cleanup
, NULL
);
2429 child_die
= die
->next
;
2430 while (child_die
&& child_die
->tag
)
2432 if (child_die
->tag
== DW_TAG_subrange_type
)
2434 unsigned int low
, high
;
2436 /* Default bounds to an array with unspecified length. */
2439 if (cu_language
== language_fortran
)
2441 /* FORTRAN implies a lower bound of 1, if not given. */
2445 index_type
= die_type (child_die
, objfile
, cu_header
);
2446 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2449 if (attr
->form
== DW_FORM_sdata
)
2451 low
= DW_SND (attr
);
2453 else if (attr
->form
== DW_FORM_udata
2454 || attr
->form
== DW_FORM_data1
2455 || attr
->form
== DW_FORM_data2
2456 || attr
->form
== DW_FORM_data4
)
2458 low
= DW_UNSND (attr
);
2462 complain (&dwarf2_non_const_array_bound_ignored
,
2463 dwarf_form_name (attr
->form
));
2465 die
->type
= lookup_pointer_type (element_type
);
2472 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2475 if (attr
->form
== DW_FORM_sdata
)
2477 high
= DW_SND (attr
);
2479 else if (attr
->form
== DW_FORM_udata
2480 || attr
->form
== DW_FORM_data1
2481 || attr
->form
== DW_FORM_data2
2482 || attr
->form
== DW_FORM_data4
)
2484 high
= DW_UNSND (attr
);
2486 else if (attr
->form
== DW_FORM_block1
)
2488 /* GCC encodes arrays with unspecified or dynamic length
2489 with a DW_FORM_block1 attribute.
2490 FIXME: GDB does not yet know how to handle dynamic
2491 arrays properly, treat them as arrays with unspecified
2497 complain (&dwarf2_non_const_array_bound_ignored
,
2498 dwarf_form_name (attr
->form
));
2500 die
->type
= lookup_pointer_type (element_type
);
2508 /* Create a range type and save it for array type creation. */
2509 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2511 range_types
= (struct type
**)
2512 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2513 * sizeof (struct type
*));
2515 make_cleanup (free_current_contents
, &range_types
);
2517 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2519 child_die
= sibling_die (child_die
);
2522 /* Dwarf2 dimensions are output from left to right, create the
2523 necessary array types in backwards order. */
2524 type
= element_type
;
2526 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2528 do_cleanups (back_to
);
2530 /* Install the type in the die. */
2534 /* First cut: install each common block member as a global variable. */
2537 read_common_block (struct die_info
*die
, struct objfile
*objfile
,
2538 const struct comp_unit_head
*cu_header
)
2540 struct die_info
*child_die
;
2541 struct attribute
*attr
;
2543 CORE_ADDR base
= (CORE_ADDR
) 0;
2545 attr
= dwarf_attr (die
, DW_AT_location
);
2548 base
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2550 if (die
->has_children
)
2552 child_die
= die
->next
;
2553 while (child_die
&& child_die
->tag
)
2555 sym
= new_symbol (child_die
, NULL
, objfile
, cu_header
);
2556 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2559 SYMBOL_VALUE_ADDRESS (sym
) =
2560 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2561 add_symbol_to_list (sym
, &global_symbols
);
2563 child_die
= sibling_die (child_die
);
2568 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2569 the user defined type vector. */
2572 read_tag_pointer_type (struct die_info
*die
, struct objfile
*objfile
,
2573 const struct comp_unit_head
*cu_header
)
2576 struct attribute
*attr
;
2583 type
= lookup_pointer_type (die_type (die
, objfile
, cu_header
));
2584 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2587 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2591 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2596 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2597 the user defined type vector. */
2600 read_tag_ptr_to_member_type (struct die_info
*die
, struct objfile
*objfile
,
2601 const struct comp_unit_head
*cu_header
)
2604 struct type
*to_type
;
2605 struct type
*domain
;
2612 type
= alloc_type (objfile
);
2613 to_type
= die_type (die
, objfile
, cu_header
);
2614 domain
= die_containing_type (die
, objfile
, cu_header
);
2615 smash_to_member_type (type
, domain
, to_type
);
2620 /* Extract all information from a DW_TAG_reference_type DIE and add to
2621 the user defined type vector. */
2624 read_tag_reference_type (struct die_info
*die
, struct objfile
*objfile
,
2625 const struct comp_unit_head
*cu_header
)
2628 struct attribute
*attr
;
2635 type
= lookup_reference_type (die_type (die
, objfile
, cu_header
));
2636 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2639 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2643 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2649 read_tag_const_type (struct die_info
*die
, struct objfile
*objfile
,
2650 const struct comp_unit_head
*cu_header
)
2657 complain (&dwarf2_const_ignored
);
2658 die
->type
= die_type (die
, objfile
, cu_header
);
2662 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
2663 const struct comp_unit_head
*cu_header
)
2670 complain (&dwarf2_volatile_ignored
);
2671 die
->type
= die_type (die
, objfile
, cu_header
);
2674 /* Extract all information from a DW_TAG_string_type DIE and add to
2675 the user defined type vector. It isn't really a user defined type,
2676 but it behaves like one, with other DIE's using an AT_user_def_type
2677 attribute to reference it. */
2680 read_tag_string_type (struct die_info
*die
, struct objfile
*objfile
)
2682 struct type
*type
, *range_type
, *index_type
, *char_type
;
2683 struct attribute
*attr
;
2684 unsigned int length
;
2691 attr
= dwarf_attr (die
, DW_AT_string_length
);
2694 length
= DW_UNSND (attr
);
2700 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2701 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2702 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2703 type
= create_string_type (char_type
, range_type
);
2707 /* Handle DIES due to C code like:
2711 int (*funcp)(int a, long l);
2715 ('funcp' generates a DW_TAG_subroutine_type DIE)
2719 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
2720 const struct comp_unit_head
*cu_header
)
2722 struct type
*type
; /* Type that this function returns */
2723 struct type
*ftype
; /* Function that returns above type */
2724 struct attribute
*attr
;
2726 /* Decode the type that this subroutine returns */
2731 type
= die_type (die
, objfile
, cu_header
);
2732 ftype
= lookup_function_type (type
);
2734 /* All functions in C++ have prototypes. */
2735 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2736 if ((attr
&& (DW_UNSND (attr
) != 0))
2737 || cu_language
== language_cplus
)
2738 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2740 if (die
->has_children
)
2742 struct die_info
*child_die
;
2746 /* Count the number of parameters.
2747 FIXME: GDB currently ignores vararg functions, but knows about
2748 vararg member functions. */
2749 child_die
= die
->next
;
2750 while (child_die
&& child_die
->tag
)
2752 if (child_die
->tag
== DW_TAG_formal_parameter
)
2754 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2755 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2756 child_die
= sibling_die (child_die
);
2759 /* Allocate storage for parameters and fill them in. */
2760 TYPE_NFIELDS (ftype
) = nparams
;
2761 TYPE_FIELDS (ftype
) = (struct field
*)
2762 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2764 child_die
= die
->next
;
2765 while (child_die
&& child_die
->tag
)
2767 if (child_die
->tag
== DW_TAG_formal_parameter
)
2769 /* Dwarf2 has no clean way to discern C++ static and non-static
2770 member functions. G++ helps GDB by marking the first
2771 parameter for non-static member functions (which is the
2772 this pointer) as artificial. We pass this information
2773 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2774 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
2776 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
2778 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
2779 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
2783 child_die
= sibling_die (child_die
);
2791 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
2792 const struct comp_unit_head
*cu_header
)
2798 struct attribute
*attr
;
2801 xtype
= die_type (die
, objfile
, cu_header
);
2803 type
= alloc_type (objfile
);
2804 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2805 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2806 TYPE_TARGET_TYPE (type
) = xtype
;
2807 attr
= dwarf_attr (die
, DW_AT_name
);
2808 if (attr
&& DW_STRING (attr
))
2809 TYPE_NAME (type
) = obsavestring (DW_STRING (attr
),
2810 strlen (DW_STRING (attr
)),
2811 &objfile
->type_obstack
);
2817 /* Find a representation of a given base type and install
2818 it in the TYPE field of the die. */
2821 read_base_type (struct die_info
*die
, struct objfile
*objfile
)
2824 struct attribute
*attr
;
2825 int encoding
= 0, size
= 0;
2827 /* If we've already decoded this die, this is a no-op. */
2833 attr
= dwarf_attr (die
, DW_AT_encoding
);
2836 encoding
= DW_UNSND (attr
);
2838 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2841 size
= DW_UNSND (attr
);
2843 attr
= dwarf_attr (die
, DW_AT_name
);
2844 if (attr
&& DW_STRING (attr
))
2846 enum type_code code
= TYPE_CODE_INT
;
2847 int is_unsigned
= 0;
2851 case DW_ATE_address
:
2852 /* Turn DW_ATE_address into a void * pointer. */
2853 code
= TYPE_CODE_PTR
;
2856 case DW_ATE_boolean
:
2857 code
= TYPE_CODE_BOOL
;
2860 case DW_ATE_complex_float
:
2861 code
= TYPE_CODE_COMPLEX
;
2864 code
= TYPE_CODE_FLT
;
2867 case DW_ATE_signed_char
:
2869 case DW_ATE_unsigned
:
2870 case DW_ATE_unsigned_char
:
2874 complain (&dwarf2_unsupported_at_encoding
,
2875 dwarf_type_encoding_name (encoding
));
2878 type
= init_type (code
, size
, is_unsigned
, DW_STRING (attr
), objfile
);
2879 if (encoding
== DW_ATE_address
)
2880 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
2884 type
= dwarf_base_type (encoding
, size
, objfile
);
2889 /* Read a whole compilation unit into a linked list of dies. */
2892 read_comp_unit (char *info_ptr
, bfd
*abfd
,
2893 const struct comp_unit_head
*cu_header
)
2895 struct die_info
*first_die
, *last_die
, *die
;
2899 /* Reset die reference table; we are
2900 building new ones now. */
2901 dwarf2_empty_hash_tables ();
2905 first_die
= last_die
= NULL
;
2908 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
, cu_header
);
2909 if (die
->has_children
)
2920 /* Enter die in reference hash table */
2921 store_in_ref_table (die
->offset
, die
);
2925 first_die
= last_die
= die
;
2929 last_die
->next
= die
;
2933 while (nesting_level
> 0);
2937 /* Free a linked list of dies. */
2940 free_die_list (struct die_info
*dies
)
2942 struct die_info
*die
, *next
;
2955 do_free_die_list_cleanup (void *dies
)
2957 free_die_list (dies
);
2960 static struct cleanup
*
2961 make_cleanup_free_die_list (struct die_info
*dies
)
2963 return make_cleanup (do_free_die_list_cleanup
, dies
);
2967 /* Read the contents of the section at OFFSET and of size SIZE from the
2968 object file specified by OBJFILE into the psymbol_obstack and return it. */
2971 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
2974 bfd
*abfd
= objfile
->obfd
;
2980 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
2981 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
2982 (bfd_read (buf
, size
, 1, abfd
) != size
))
2985 error ("Dwarf Error: Can't read DWARF data from '%s'",
2986 bfd_get_filename (abfd
));
2991 /* In DWARF version 2, the description of the debugging information is
2992 stored in a separate .debug_abbrev section. Before we read any
2993 dies from a section we read in all abbreviations and install them
2997 dwarf2_read_abbrevs (bfd
*abfd
, unsigned int offset
)
3000 struct abbrev_info
*cur_abbrev
;
3001 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3002 unsigned int abbrev_form
, hash_number
;
3004 /* empty the table */
3005 dwarf2_empty_abbrev_table (NULL
);
3007 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3008 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3009 abbrev_ptr
+= bytes_read
;
3011 /* loop until we reach an abbrev number of 0 */
3012 while (abbrev_number
)
3014 cur_abbrev
= dwarf_alloc_abbrev ();
3016 /* read in abbrev header */
3017 cur_abbrev
->number
= abbrev_number
;
3018 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3019 abbrev_ptr
+= bytes_read
;
3020 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3023 /* now read in declarations */
3024 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3025 abbrev_ptr
+= bytes_read
;
3026 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3027 abbrev_ptr
+= bytes_read
;
3030 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3032 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3033 xrealloc (cur_abbrev
->attrs
,
3034 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3035 * sizeof (struct attr_abbrev
));
3037 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3038 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3039 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3040 abbrev_ptr
+= bytes_read
;
3041 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3042 abbrev_ptr
+= bytes_read
;
3045 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3046 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3047 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3049 /* Get next abbreviation.
3050 Under Irix6 the abbreviations for a compilation unit are not
3051 always properly terminated with an abbrev number of 0.
3052 Exit loop if we encounter an abbreviation which we have
3053 already read (which means we are about to read the abbreviations
3054 for the next compile unit) or if the end of the abbreviation
3055 table is reached. */
3056 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3057 >= dwarf_abbrev_size
)
3059 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3060 abbrev_ptr
+= bytes_read
;
3061 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3066 /* Empty the abbrev table for a new compilation unit. */
3070 dwarf2_empty_abbrev_table (PTR ignore
)
3073 struct abbrev_info
*abbrev
, *next
;
3075 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3078 abbrev
= dwarf2_abbrevs
[i
];
3081 next
= abbrev
->next
;
3082 free (abbrev
->attrs
);
3086 dwarf2_abbrevs
[i
] = NULL
;
3090 /* Lookup an abbrev_info structure in the abbrev hash table. */
3092 static struct abbrev_info
*
3093 dwarf2_lookup_abbrev (unsigned int number
)
3095 unsigned int hash_number
;
3096 struct abbrev_info
*abbrev
;
3098 hash_number
= number
% ABBREV_HASH_SIZE
;
3099 abbrev
= dwarf2_abbrevs
[hash_number
];
3103 if (abbrev
->number
== number
)
3106 abbrev
= abbrev
->next
;
3111 /* Read a minimal amount of information into the minimal die structure. */
3114 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3115 char *info_ptr
, int *has_pc_info
,
3116 const struct comp_unit_head
*cu_header
)
3118 unsigned int abbrev_number
, bytes_read
, i
;
3119 struct abbrev_info
*abbrev
;
3120 struct attribute attr
;
3121 struct attribute spec_attr
;
3122 int found_spec_attr
= 0;
3123 int has_low_pc_attr
= 0;
3124 int has_high_pc_attr
= 0;
3126 *part_die
= zeroed_partial_die
;
3128 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3129 info_ptr
+= bytes_read
;
3133 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3136 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3138 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3139 part_die
->tag
= abbrev
->tag
;
3140 part_die
->has_children
= abbrev
->has_children
;
3141 part_die
->abbrev
= abbrev_number
;
3143 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3145 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
3146 info_ptr
, cu_header
);
3148 /* Store the data if it is of an attribute we want to keep in a
3149 partial symbol table. */
3154 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3155 if (part_die
->name
== NULL
)
3156 part_die
->name
= DW_STRING (&attr
);
3158 case DW_AT_MIPS_linkage_name
:
3159 part_die
->name
= DW_STRING (&attr
);
3162 has_low_pc_attr
= 1;
3163 part_die
->lowpc
= DW_ADDR (&attr
);
3166 has_high_pc_attr
= 1;
3167 part_die
->highpc
= DW_ADDR (&attr
);
3169 case DW_AT_location
:
3170 part_die
->locdesc
= DW_BLOCK (&attr
);
3172 case DW_AT_language
:
3173 part_die
->language
= DW_UNSND (&attr
);
3175 case DW_AT_external
:
3176 part_die
->is_external
= DW_UNSND (&attr
);
3178 case DW_AT_declaration
:
3179 part_die
->is_declaration
= DW_UNSND (&attr
);
3182 part_die
->has_type
= 1;
3184 case DW_AT_abstract_origin
:
3185 case DW_AT_specification
:
3186 found_spec_attr
= 1;
3190 /* Ignore absolute siblings, they might point outside of
3191 the current compile unit. */
3192 if (attr
.form
== DW_FORM_ref_addr
)
3193 complain (&dwarf2_absolute_sibling_complaint
);
3196 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3203 /* If we found a reference attribute and the die has no name, try
3204 to find a name in the referred to die. */
3206 if (found_spec_attr
&& part_die
->name
== NULL
)
3208 struct partial_die_info spec_die
;
3212 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3213 read_partial_die (&spec_die
, abfd
, spec_ptr
, &dummy
, cu_header
);
3216 part_die
->name
= spec_die
.name
;
3218 /* Copy DW_AT_external attribute if it is set. */
3219 if (spec_die
.is_external
)
3220 part_die
->is_external
= spec_die
.is_external
;
3224 /* When using the GNU linker, .gnu.linkonce. sections are used to
3225 eliminate duplicate copies of functions and vtables and such.
3226 The linker will arbitrarily choose one and discard the others.
3227 The AT_*_pc values for such functions refer to local labels in
3228 these sections. If the section from that file was discarded, the
3229 labels are not in the output, so the relocs get a value of 0.
3230 If this is a discarded function, mark the pc bounds as invalid,
3231 so that GDB will ignore it. */
3232 if (has_low_pc_attr
&& has_high_pc_attr
3233 && part_die
->lowpc
< part_die
->highpc
3234 && (part_die
->lowpc
!= 0
3235 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3240 /* Read the die from the .debug_info section buffer. And set diep to
3241 point to a newly allocated die with its information. */
3244 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
3245 const struct comp_unit_head
*cu_header
)
3247 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3248 struct abbrev_info
*abbrev
;
3249 struct die_info
*die
;
3251 offset
= info_ptr
- dwarf_info_buffer
;
3252 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3253 info_ptr
+= bytes_read
;
3256 die
= dwarf_alloc_die ();
3258 die
->abbrev
= abbrev_number
;
3264 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3267 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3269 die
= dwarf_alloc_die ();
3270 die
->offset
= offset
;
3271 die
->tag
= abbrev
->tag
;
3272 die
->has_children
= abbrev
->has_children
;
3273 die
->abbrev
= abbrev_number
;
3276 die
->num_attrs
= abbrev
->num_attrs
;
3277 die
->attrs
= (struct attribute
*)
3278 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3280 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3282 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3283 abfd
, info_ptr
, cu_header
);
3290 /* Read an attribute described by an abbreviated attribute. */
3293 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
3294 bfd
*abfd
, char *info_ptr
,
3295 const struct comp_unit_head
*cu_header
)
3297 unsigned int bytes_read
;
3298 struct dwarf_block
*blk
;
3300 attr
->name
= abbrev
->name
;
3301 attr
->form
= abbrev
->form
;
3302 switch (abbrev
->form
)
3305 case DW_FORM_ref_addr
:
3306 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
3307 info_ptr
+= bytes_read
;
3309 case DW_FORM_block2
:
3310 blk
= dwarf_alloc_block ();
3311 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3313 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3314 info_ptr
+= blk
->size
;
3315 DW_BLOCK (attr
) = blk
;
3317 case DW_FORM_block4
:
3318 blk
= dwarf_alloc_block ();
3319 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3321 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3322 info_ptr
+= blk
->size
;
3323 DW_BLOCK (attr
) = blk
;
3326 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3330 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3334 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3337 case DW_FORM_string
:
3338 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3339 info_ptr
+= bytes_read
;
3342 blk
= dwarf_alloc_block ();
3343 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3344 info_ptr
+= bytes_read
;
3345 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3346 info_ptr
+= blk
->size
;
3347 DW_BLOCK (attr
) = blk
;
3349 case DW_FORM_block1
:
3350 blk
= dwarf_alloc_block ();
3351 blk
->size
= read_1_byte (abfd
, info_ptr
);
3353 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3354 info_ptr
+= blk
->size
;
3355 DW_BLOCK (attr
) = blk
;
3358 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3362 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3366 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3367 info_ptr
+= bytes_read
;
3370 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3371 info_ptr
+= bytes_read
;
3374 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3378 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3382 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3386 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3389 case DW_FORM_ref_udata
:
3390 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3391 info_ptr
+= bytes_read
;
3394 case DW_FORM_indirect
:
3396 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3397 dwarf_form_name (abbrev
->form
));
3402 /* read dwarf information from a buffer */
3405 read_1_byte (bfd
*abfd
, char *buf
)
3407 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3411 read_1_signed_byte (bfd
*abfd
, char *buf
)
3413 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3417 read_2_bytes (bfd
*abfd
, char *buf
)
3419 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3423 read_2_signed_bytes (bfd
*abfd
, char *buf
)
3425 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3429 read_4_bytes (bfd
*abfd
, char *buf
)
3431 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3435 read_4_signed_bytes (bfd
*abfd
, char *buf
)
3437 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3440 static unsigned long
3441 read_8_bytes (bfd
*abfd
, char *buf
)
3443 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3447 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3450 CORE_ADDR retval
= 0;
3452 if (cu_header
->signed_addr_p
)
3454 switch (cu_header
->addr_size
)
3457 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3460 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3463 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
3466 internal_error ("read_address: bad switch, signed");
3471 switch (cu_header
->addr_size
)
3474 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3477 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3480 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3483 internal_error ("read_address: bad switch, unsigned");
3487 *bytes_read
= cu_header
->addr_size
;
3491 /* Reads the initial length from a section. The (draft) DWARF 2.1
3492 specification allows the initial length to take up either 4 bytes
3493 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
3494 bytes describe the length and all offsets will be 8 bytes in length
3497 The value returned via bytes_read should be used to increment
3498 the relevant pointer after calling read_initial_length().
3500 As a side effect, this function sets the fields initial_length_size
3501 and offset_size in cu_header to the values appropriate for the
3502 length field. (The format of the initial length field determines
3503 the width of file offsets to be fetched later with fetch_offset().)
3505 [ Note: read_initial_length() and read_offset() are based on the
3506 document entitled "DWARF Debugging Information Format", revision
3507 2.1, draft 4, dated July 20, 2000. This document was obtained
3510 http://reality.sgi.com/dehnert_engr/dwarf/dwarf2p1-draft4-000720.pdf
3512 This document is only a draft and is subject to change. (So beware.)
3514 - Kevin, Aug 4, 2000
3518 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
3523 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3525 if (retval
== 0xffffffff)
3527 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
3529 if (cu_header
!= NULL
)
3531 cu_header
->initial_length_size
= 12;
3532 cu_header
->offset_size
= 8;
3538 if (cu_header
!= NULL
)
3540 cu_header
->initial_length_size
= 4;
3541 cu_header
->offset_size
= 4;
3548 /* Read an offset from the data stream. The size of the offset is
3549 given by cu_header->offset_size. */
3552 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3557 switch (cu_header
->offset_size
)
3560 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3564 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3568 internal_error ("read_offset: bad switch");
3575 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
3577 /* If the size of a host char is 8 bits, we can return a pointer
3578 to the buffer, otherwise we have to copy the data to a buffer
3579 allocated on the temporary obstack. */
3580 #if HOST_CHAR_BIT == 8
3586 ret
= obstack_alloc (&dwarf2_tmp_obstack
, size
);
3587 for (i
= 0; i
< size
; ++i
)
3589 ret
[i
] = bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3597 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3599 /* If the size of a host char is 8 bits, we can return a pointer
3600 to the string, otherwise we have to copy the string to a buffer
3601 allocated on the temporary obstack. */
3602 #if HOST_CHAR_BIT == 8
3605 *bytes_read_ptr
= 1;
3608 *bytes_read_ptr
= strlen (buf
) + 1;
3614 while ((byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
)) != 0)
3616 obstack_1grow (&dwarf2_tmp_obstack
, byte
);
3622 *bytes_read_ptr
= 1;
3625 obstack_1grow (&dwarf2_tmp_obstack
, '\0');
3626 *bytes_read_ptr
= i
+ 1;
3627 return obstack_finish (&dwarf2_tmp_obstack
);
3631 static unsigned long
3632 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3634 unsigned long result
;
3635 unsigned int num_read
;
3645 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3648 result
|= ((unsigned long)(byte
& 127) << shift
);
3649 if ((byte
& 128) == 0)
3655 *bytes_read_ptr
= num_read
;
3660 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3663 int i
, shift
, size
, num_read
;
3673 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3676 result
|= ((long)(byte
& 127) << shift
);
3678 if ((byte
& 128) == 0)
3683 if ((shift
< size
) && (byte
& 0x40))
3685 result
|= -(1 << shift
);
3687 *bytes_read_ptr
= num_read
;
3692 set_cu_language (unsigned int lang
)
3698 cu_language
= language_c
;
3700 case DW_LANG_C_plus_plus
:
3701 cu_language
= language_cplus
;
3703 case DW_LANG_Fortran77
:
3704 case DW_LANG_Fortran90
:
3705 cu_language
= language_fortran
;
3707 case DW_LANG_Mips_Assembler
:
3708 cu_language
= language_asm
;
3711 case DW_LANG_Cobol74
:
3712 case DW_LANG_Cobol85
:
3713 case DW_LANG_Pascal83
:
3714 case DW_LANG_Modula2
:
3716 cu_language
= language_unknown
;
3719 cu_language_defn
= language_def (cu_language
);
3722 /* Return the named attribute or NULL if not there. */
3724 static struct attribute
*
3725 dwarf_attr (struct die_info
*die
, unsigned int name
)
3728 struct attribute
*spec
= NULL
;
3730 for (i
= 0; i
< die
->num_attrs
; ++i
)
3732 if (die
->attrs
[i
].name
== name
)
3734 return &die
->attrs
[i
];
3736 if (die
->attrs
[i
].name
== DW_AT_specification
3737 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3738 spec
= &die
->attrs
[i
];
3742 struct die_info
*ref_die
=
3743 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3746 return dwarf_attr (ref_die
, name
);
3753 die_is_declaration (struct die_info
*die
)
3755 return (dwarf_attr (die
, DW_AT_declaration
)
3756 && ! dwarf_attr (die
, DW_AT_specification
));
3759 /* Decode the line number information for the compilation unit whose
3760 line number info is at OFFSET in the .debug_line section.
3761 The compilation directory of the file is passed in COMP_DIR. */
3765 unsigned int num_files
;
3778 unsigned int num_dirs
;
3783 dwarf_decode_lines (unsigned int offset
, char *comp_dir
, bfd
*abfd
,
3784 const struct comp_unit_head
*cu_header
)
3788 struct line_head lh
;
3789 struct cleanup
*back_to
;
3790 unsigned int i
, bytes_read
;
3791 char *cur_file
, *cur_dir
;
3792 unsigned char op_code
, extended_op
, adj_opcode
;
3794 #define FILE_ALLOC_CHUNK 5
3795 #define DIR_ALLOC_CHUNK 5
3797 struct filenames files
;
3798 struct directories dirs
;
3800 if (dwarf_line_buffer
== NULL
)
3802 complain (&dwarf2_missing_line_number_section
);
3806 files
.num_files
= 0;
3812 line_ptr
= dwarf_line_buffer
+ offset
;
3814 /* read in the prologue */
3815 lh
.total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
3816 line_ptr
+= bytes_read
;
3817 line_end
= line_ptr
+ lh
.total_length
;
3818 lh
.version
= read_2_bytes (abfd
, line_ptr
);
3820 lh
.prologue_length
= read_offset (abfd
, line_ptr
, cu_header
, &bytes_read
);
3821 line_ptr
+= bytes_read
;
3822 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
3824 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
3826 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
3828 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
3830 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
3832 lh
.standard_opcode_lengths
= (unsigned char *)
3833 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
3834 back_to
= make_cleanup (free_current_contents
, &lh
.standard_opcode_lengths
);
3836 lh
.standard_opcode_lengths
[0] = 1;
3837 for (i
= 1; i
< lh
.opcode_base
; ++i
)
3839 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
3843 /* Read directory table */
3844 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3846 line_ptr
+= bytes_read
;
3847 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
3849 dirs
.dirs
= (char **)
3850 xrealloc (dirs
.dirs
,
3851 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
3852 if (dirs
.num_dirs
== 0)
3853 make_cleanup (free_current_contents
, &dirs
.dirs
);
3855 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
3857 line_ptr
+= bytes_read
;
3859 /* Read file name table */
3860 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3862 line_ptr
+= bytes_read
;
3863 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3865 files
.files
= (struct fileinfo
*)
3866 xrealloc (files
.files
,
3867 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3868 * sizeof (struct fileinfo
));
3869 if (files
.num_files
== 0)
3870 make_cleanup (free_current_contents
, &files
.files
);
3872 files
.files
[files
.num_files
].name
= cur_file
;
3873 files
.files
[files
.num_files
].dir
=
3874 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3875 line_ptr
+= bytes_read
;
3876 files
.files
[files
.num_files
].time
=
3877 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3878 line_ptr
+= bytes_read
;
3879 files
.files
[files
.num_files
].size
=
3880 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3881 line_ptr
+= bytes_read
;
3884 line_ptr
+= bytes_read
;
3886 /* Read the statement sequences until there's nothing left. */
3887 while (line_ptr
< line_end
)
3889 /* state machine registers */
3890 CORE_ADDR address
= 0;
3891 unsigned int file
= 1;
3892 unsigned int line
= 1;
3893 unsigned int column
= 0;
3894 int is_stmt
= lh
.default_is_stmt
;
3895 int basic_block
= 0;
3896 int end_sequence
= 0;
3898 /* Start a subfile for the current file of the state machine. */
3899 if (files
.num_files
>= file
)
3901 /* The file and directory tables are 0 based, the references
3903 dwarf2_start_subfile (files
.files
[file
- 1].name
,
3904 (files
.files
[file
- 1].dir
3905 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3909 /* Decode the table. */
3910 while (!end_sequence
)
3912 op_code
= read_1_byte (abfd
, line_ptr
);
3916 case DW_LNS_extended_op
:
3917 line_ptr
+= 1; /* ignore length */
3918 extended_op
= read_1_byte (abfd
, line_ptr
);
3920 switch (extended_op
)
3922 case DW_LNE_end_sequence
:
3924 /* Don't call record_line here. The end_sequence
3925 instruction provides the address of the first byte
3926 *after* the last line in the sequence; it's not the
3927 address of any real source line. However, the GDB
3928 linetable structure only records the starts of lines,
3929 not the ends. This is a weakness of GDB. */
3931 case DW_LNE_set_address
:
3932 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
3933 line_ptr
+= bytes_read
;
3934 address
+= baseaddr
;
3936 case DW_LNE_define_file
:
3937 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
3938 line_ptr
+= bytes_read
;
3939 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3941 files
.files
= (struct fileinfo
*)
3942 xrealloc (files
.files
,
3943 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3944 * sizeof (struct fileinfo
));
3945 if (files
.num_files
== 0)
3946 make_cleanup (free_current_contents
, &files
.files
);
3948 files
.files
[files
.num_files
].name
= cur_file
;
3949 files
.files
[files
.num_files
].dir
=
3950 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3951 line_ptr
+= bytes_read
;
3952 files
.files
[files
.num_files
].time
=
3953 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3954 line_ptr
+= bytes_read
;
3955 files
.files
[files
.num_files
].size
=
3956 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3957 line_ptr
+= bytes_read
;
3961 complain (&dwarf2_mangled_line_number_section
);
3966 record_line (current_subfile
, line
, address
);
3969 case DW_LNS_advance_pc
:
3970 address
+= lh
.minimum_instruction_length
3971 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3972 line_ptr
+= bytes_read
;
3974 case DW_LNS_advance_line
:
3975 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
3976 line_ptr
+= bytes_read
;
3978 case DW_LNS_set_file
:
3979 /* The file and directory tables are 0 based, the references
3981 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3982 line_ptr
+= bytes_read
;
3983 dwarf2_start_subfile
3984 (files
.files
[file
- 1].name
,
3985 (files
.files
[file
- 1].dir
3986 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3989 case DW_LNS_set_column
:
3990 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3991 line_ptr
+= bytes_read
;
3993 case DW_LNS_negate_stmt
:
3994 is_stmt
= (!is_stmt
);
3996 case DW_LNS_set_basic_block
:
3999 /* Add to the address register of the state machine the
4000 address increment value corresponding to special opcode
4001 255. Ie, this value is scaled by the minimum instruction
4002 length since special opcode 255 would have scaled the
4004 case DW_LNS_const_add_pc
:
4005 address
+= (lh
.minimum_instruction_length
4006 * ((255 - lh
.opcode_base
) / lh
.line_range
));
4008 case DW_LNS_fixed_advance_pc
:
4009 address
+= read_2_bytes (abfd
, line_ptr
);
4012 default: /* special operand */
4013 adj_opcode
= op_code
- lh
.opcode_base
;
4014 address
+= (adj_opcode
/ lh
.line_range
)
4015 * lh
.minimum_instruction_length
;
4016 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
4017 /* append row to matrix using current values */
4018 record_line (current_subfile
, line
, address
);
4024 do_cleanups (back_to
);
4027 /* Start a subfile for DWARF. FILENAME is the name of the file and
4028 DIRNAME the name of the source directory which contains FILENAME
4029 or NULL if not known.
4030 This routine tries to keep line numbers from identical absolute and
4031 relative file names in a common subfile.
4033 Using the `list' example from the GDB testsuite, which resides in
4034 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4035 of /srcdir/list0.c yields the following debugging information for list0.c:
4037 DW_AT_name: /srcdir/list0.c
4038 DW_AT_comp_dir: /compdir
4039 files.files[0].name: list0.h
4040 files.files[0].dir: /srcdir
4041 files.files[1].name: list0.c
4042 files.files[1].dir: /srcdir
4044 The line number information for list0.c has to end up in a single
4045 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4048 dwarf2_start_subfile (char *filename
, char *dirname
)
4050 /* If the filename isn't absolute, try to match an existing subfile
4051 with the full pathname. */
4053 if (*filename
!= '/' && dirname
!= NULL
)
4055 struct subfile
*subfile
;
4056 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4058 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4060 if (STREQ (subfile
->name
, fullname
))
4062 current_subfile
= subfile
;
4069 start_subfile (filename
, dirname
);
4072 /* Given a pointer to a DWARF information entry, figure out if we need
4073 to make a symbol table entry for it, and if so, create a new entry
4074 and return a pointer to it.
4075 If TYPE is NULL, determine symbol type from the die, otherwise
4076 used the passed type. */
4078 static struct symbol
*
4079 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
4080 const struct comp_unit_head
*cu_header
)
4082 struct symbol
*sym
= NULL
;
4084 struct attribute
*attr
= NULL
;
4085 struct attribute
*attr2
= NULL
;
4088 name
= dwarf2_linkage_name (die
);
4091 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4092 sizeof (struct symbol
));
4093 OBJSTAT (objfile
, n_syms
++);
4094 memset (sym
, 0, sizeof (struct symbol
));
4095 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4096 &objfile
->symbol_obstack
);
4098 /* Default assumptions.
4099 Use the passed type or decode it from the die. */
4100 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4101 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4103 SYMBOL_TYPE (sym
) = type
;
4105 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
4106 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4109 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4112 /* If this symbol is from a C++ compilation, then attempt to
4113 cache the demangled form for future reference. This is a
4114 typical time versus space tradeoff, that was decided in favor
4115 of time because it sped up C++ symbol lookups by a factor of
4118 SYMBOL_LANGUAGE (sym
) = cu_language
;
4119 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4123 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4126 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4128 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4130 case DW_TAG_subprogram
:
4131 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4133 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4134 attr2
= dwarf_attr (die
, DW_AT_external
);
4135 if (attr2
&& (DW_UNSND (attr2
) != 0))
4137 add_symbol_to_list (sym
, &global_symbols
);
4141 add_symbol_to_list (sym
, list_in_scope
);
4144 case DW_TAG_variable
:
4145 /* Compilation with minimal debug info may result in variables
4146 with missing type entries. Change the misleading `void' type
4147 to something sensible. */
4148 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4149 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4150 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4151 "<variable, no debug info>",
4153 attr
= dwarf_attr (die
, DW_AT_const_value
);
4156 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4157 attr2
= dwarf_attr (die
, DW_AT_external
);
4158 if (attr2
&& (DW_UNSND (attr2
) != 0))
4159 add_symbol_to_list (sym
, &global_symbols
);
4161 add_symbol_to_list (sym
, list_in_scope
);
4164 attr
= dwarf_attr (die
, DW_AT_location
);
4167 attr2
= dwarf_attr (die
, DW_AT_external
);
4168 if (attr2
&& (DW_UNSND (attr2
) != 0))
4170 SYMBOL_VALUE_ADDRESS (sym
) =
4171 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4172 add_symbol_to_list (sym
, &global_symbols
);
4174 /* In shared libraries the address of the variable
4175 in the location descriptor might still be relocatable,
4176 so its value could be zero.
4177 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4178 value is zero, the address of the variable will then
4179 be determined from the minimal symbol table whenever
4180 the variable is referenced. */
4181 if (SYMBOL_VALUE_ADDRESS (sym
))
4183 fixup_symbol_section (sym
, objfile
);
4184 SYMBOL_VALUE_ADDRESS (sym
) +=
4185 ANOFFSET (objfile
->section_offsets
,
4186 SYMBOL_SECTION (sym
));
4187 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4190 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4194 SYMBOL_VALUE (sym
) = addr
=
4195 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4196 add_symbol_to_list (sym
, list_in_scope
);
4199 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4203 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4207 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4208 SYMBOL_BASEREG (sym
) = basereg
;
4212 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4216 fixup_symbol_section (sym
, objfile
);
4217 SYMBOL_VALUE_ADDRESS (sym
) =
4218 addr
+ ANOFFSET (objfile
->section_offsets
,
4219 SYMBOL_SECTION (sym
));
4220 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4226 /* We do not know the address of this symbol.
4227 If it is an external symbol and we have type information
4228 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4229 The address of the variable will then be determined from
4230 the minimal symbol table whenever the variable is
4232 attr2
= dwarf_attr (die
, DW_AT_external
);
4233 if (attr2
&& (DW_UNSND (attr2
) != 0)
4234 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4236 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4237 add_symbol_to_list (sym
, &global_symbols
);
4241 case DW_TAG_formal_parameter
:
4242 attr
= dwarf_attr (die
, DW_AT_location
);
4245 SYMBOL_VALUE (sym
) =
4246 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4249 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4255 if (basereg
!= frame_base_reg
)
4256 complain (&dwarf2_complex_location_expr
);
4257 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4261 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4262 SYMBOL_BASEREG (sym
) = basereg
;
4267 SYMBOL_CLASS (sym
) = LOC_ARG
;
4270 attr
= dwarf_attr (die
, DW_AT_const_value
);
4273 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4275 add_symbol_to_list (sym
, list_in_scope
);
4277 case DW_TAG_unspecified_parameters
:
4278 /* From varargs functions; gdb doesn't seem to have any
4279 interest in this information, so just ignore it for now.
4282 case DW_TAG_class_type
:
4283 case DW_TAG_structure_type
:
4284 case DW_TAG_union_type
:
4285 case DW_TAG_enumeration_type
:
4286 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4287 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4288 add_symbol_to_list (sym
, list_in_scope
);
4290 /* The semantics of C++ state that "struct foo { ... }" also
4291 defines a typedef for "foo". Synthesize a typedef symbol so
4292 that "ptype foo" works as expected. */
4293 if (cu_language
== language_cplus
)
4295 struct symbol
*typedef_sym
= (struct symbol
*)
4296 obstack_alloc (&objfile
->symbol_obstack
,
4297 sizeof (struct symbol
));
4298 *typedef_sym
= *sym
;
4299 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4300 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4301 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4302 obsavestring (SYMBOL_NAME (sym
),
4303 strlen (SYMBOL_NAME (sym
)),
4304 &objfile
->type_obstack
);
4305 add_symbol_to_list (typedef_sym
, list_in_scope
);
4308 case DW_TAG_typedef
:
4309 case DW_TAG_base_type
:
4310 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4311 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4312 add_symbol_to_list (sym
, list_in_scope
);
4314 case DW_TAG_enumerator
:
4315 attr
= dwarf_attr (die
, DW_AT_const_value
);
4318 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4320 add_symbol_to_list (sym
, list_in_scope
);
4323 /* Not a tag we recognize. Hopefully we aren't processing
4324 trash data, but since we must specifically ignore things
4325 we don't recognize, there is nothing else we should do at
4327 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4334 /* Copy constant value from an attribute to a symbol. */
4337 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
4338 struct objfile
*objfile
,
4339 const struct comp_unit_head
*cu_header
)
4341 struct dwarf_block
*blk
;
4346 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
4347 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4348 cu_header
->addr_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4349 SYMBOL_VALUE_BYTES (sym
) = (char *)
4350 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
4351 store_address (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
4353 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4355 case DW_FORM_block1
:
4356 case DW_FORM_block2
:
4357 case DW_FORM_block4
:
4359 blk
= DW_BLOCK (attr
);
4360 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4361 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4362 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4363 SYMBOL_VALUE_BYTES (sym
) = (char *)
4364 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4365 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4366 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4369 /* The DW_AT_const_value attributes are supposed to carry the
4370 symbol's value "represented as it would be on the target
4371 architecture." By the time we get here, it's already been
4372 converted to host endianness, so we just need to sign- or
4373 zero-extend it as appropriate. */
4375 dwarf2_const_value_data (attr
, sym
, 8);
4378 dwarf2_const_value_data (attr
, sym
, 16);
4381 dwarf2_const_value_data (attr
, sym
, 32);
4384 dwarf2_const_value_data (attr
, sym
, 64);
4388 SYMBOL_VALUE (sym
) = DW_SND (attr
);
4389 SYMBOL_CLASS (sym
) = LOC_CONST
;
4393 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4394 SYMBOL_CLASS (sym
) = LOC_CONST
;
4398 complain (&dwarf2_unsupported_const_value_attr
,
4399 dwarf_form_name (attr
->form
));
4400 SYMBOL_VALUE (sym
) = 0;
4401 SYMBOL_CLASS (sym
) = LOC_CONST
;
4407 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4408 or zero-extend it as appropriate for the symbol's type. */
4410 dwarf2_const_value_data (struct attribute
*attr
,
4414 LONGEST l
= DW_UNSND (attr
);
4416 if (bits
< sizeof (l
) * 8)
4418 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
4419 l
&= ((LONGEST
) 1 << bits
) - 1;
4421 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
4424 SYMBOL_VALUE (sym
) = l
;
4425 SYMBOL_CLASS (sym
) = LOC_CONST
;
4429 /* Return the type of the die in question using its DW_AT_type attribute. */
4431 static struct type
*
4432 die_type (struct die_info
*die
, struct objfile
*objfile
,
4433 const struct comp_unit_head
*cu_header
)
4436 struct attribute
*type_attr
;
4437 struct die_info
*type_die
;
4440 type_attr
= dwarf_attr (die
, DW_AT_type
);
4443 /* A missing DW_AT_type represents a void type. */
4444 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4448 ref
= dwarf2_get_ref_die_offset (type_attr
);
4449 type_die
= follow_die_ref (ref
);
4452 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4456 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4459 dump_die (type_die
);
4460 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4465 /* Return the containing type of the die in question using its
4466 DW_AT_containing_type attribute. */
4468 static struct type
*
4469 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
4470 const struct comp_unit_head
*cu_header
)
4472 struct type
*type
= NULL
;
4473 struct attribute
*type_attr
;
4474 struct die_info
*type_die
= NULL
;
4477 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4480 ref
= dwarf2_get_ref_die_offset (type_attr
);
4481 type_die
= follow_die_ref (ref
);
4484 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4487 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4492 dump_die (type_die
);
4493 error ("Dwarf Error: Problem turning containing type into gdb type.");
4499 static struct type
*
4500 type_at_offset (unsigned int offset
, struct objfile
*objfile
)
4502 struct die_info
*die
;
4505 die
= follow_die_ref (offset
);
4508 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4511 type
= tag_type_to_type (die
, objfile
);
4516 static struct type
*
4517 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
4518 const struct comp_unit_head
*cu_header
)
4526 read_type_die (die
, objfile
, cu_header
);
4530 error ("Dwarf Error: Cannot find type of die.");
4537 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
4538 const struct comp_unit_head
*cu_header
)
4542 case DW_TAG_class_type
:
4543 case DW_TAG_structure_type
:
4544 case DW_TAG_union_type
:
4545 read_structure_scope (die
, objfile
, cu_header
);
4547 case DW_TAG_enumeration_type
:
4548 read_enumeration (die
, objfile
, cu_header
);
4550 case DW_TAG_subprogram
:
4551 case DW_TAG_subroutine_type
:
4552 read_subroutine_type (die
, objfile
, cu_header
);
4554 case DW_TAG_array_type
:
4555 read_array_type (die
, objfile
, cu_header
);
4557 case DW_TAG_pointer_type
:
4558 read_tag_pointer_type (die
, objfile
, cu_header
);
4560 case DW_TAG_ptr_to_member_type
:
4561 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
4563 case DW_TAG_reference_type
:
4564 read_tag_reference_type (die
, objfile
, cu_header
);
4566 case DW_TAG_const_type
:
4567 read_tag_const_type (die
, objfile
, cu_header
);
4569 case DW_TAG_volatile_type
:
4570 read_tag_volatile_type (die
, objfile
, cu_header
);
4572 case DW_TAG_string_type
:
4573 read_tag_string_type (die
, objfile
);
4575 case DW_TAG_typedef
:
4576 read_typedef (die
, objfile
, cu_header
);
4578 case DW_TAG_base_type
:
4579 read_base_type (die
, objfile
);
4582 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4587 static struct type
*
4588 dwarf_base_type (int encoding
, int size
, struct objfile
*objfile
)
4590 /* FIXME - this should not produce a new (struct type *)
4591 every time. It should cache base types. */
4595 case DW_ATE_address
:
4596 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4598 case DW_ATE_boolean
:
4599 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4601 case DW_ATE_complex_float
:
4604 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4608 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4614 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4618 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4625 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4628 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4632 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4636 case DW_ATE_signed_char
:
4637 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4639 case DW_ATE_unsigned
:
4643 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4646 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4650 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4654 case DW_ATE_unsigned_char
:
4655 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4658 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4665 copy_die (struct die_info
*old_die
)
4667 struct die_info
*new_die
;
4670 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4671 memset (new_die
, 0, sizeof (struct die_info
));
4673 new_die
->tag
= old_die
->tag
;
4674 new_die
->has_children
= old_die
->has_children
;
4675 new_die
->abbrev
= old_die
->abbrev
;
4676 new_die
->offset
= old_die
->offset
;
4677 new_die
->type
= NULL
;
4679 num_attrs
= old_die
->num_attrs
;
4680 new_die
->num_attrs
= num_attrs
;
4681 new_die
->attrs
= (struct attribute
*)
4682 xmalloc (num_attrs
* sizeof (struct attribute
));
4684 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4686 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4687 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4688 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4691 new_die
->next
= NULL
;
4696 /* Return sibling of die, NULL if no sibling. */
4699 sibling_die (struct die_info
*die
)
4701 int nesting_level
= 0;
4703 if (!die
->has_children
)
4705 if (die
->next
&& (die
->next
->tag
== 0))
4718 if (die
->has_children
)
4728 while (nesting_level
);
4729 if (die
&& (die
->tag
== 0))
4740 /* Get linkage name of a die, return NULL if not found. */
4743 dwarf2_linkage_name (struct die_info
*die
)
4745 struct attribute
*attr
;
4747 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4748 if (attr
&& DW_STRING (attr
))
4749 return DW_STRING (attr
);
4750 attr
= dwarf_attr (die
, DW_AT_name
);
4751 if (attr
&& DW_STRING (attr
))
4752 return DW_STRING (attr
);
4756 /* Convert a DIE tag into its string name. */
4759 dwarf_tag_name (register unsigned tag
)
4763 case DW_TAG_padding
:
4764 return "DW_TAG_padding";
4765 case DW_TAG_array_type
:
4766 return "DW_TAG_array_type";
4767 case DW_TAG_class_type
:
4768 return "DW_TAG_class_type";
4769 case DW_TAG_entry_point
:
4770 return "DW_TAG_entry_point";
4771 case DW_TAG_enumeration_type
:
4772 return "DW_TAG_enumeration_type";
4773 case DW_TAG_formal_parameter
:
4774 return "DW_TAG_formal_parameter";
4775 case DW_TAG_imported_declaration
:
4776 return "DW_TAG_imported_declaration";
4778 return "DW_TAG_label";
4779 case DW_TAG_lexical_block
:
4780 return "DW_TAG_lexical_block";
4782 return "DW_TAG_member";
4783 case DW_TAG_pointer_type
:
4784 return "DW_TAG_pointer_type";
4785 case DW_TAG_reference_type
:
4786 return "DW_TAG_reference_type";
4787 case DW_TAG_compile_unit
:
4788 return "DW_TAG_compile_unit";
4789 case DW_TAG_string_type
:
4790 return "DW_TAG_string_type";
4791 case DW_TAG_structure_type
:
4792 return "DW_TAG_structure_type";
4793 case DW_TAG_subroutine_type
:
4794 return "DW_TAG_subroutine_type";
4795 case DW_TAG_typedef
:
4796 return "DW_TAG_typedef";
4797 case DW_TAG_union_type
:
4798 return "DW_TAG_union_type";
4799 case DW_TAG_unspecified_parameters
:
4800 return "DW_TAG_unspecified_parameters";
4801 case DW_TAG_variant
:
4802 return "DW_TAG_variant";
4803 case DW_TAG_common_block
:
4804 return "DW_TAG_common_block";
4805 case DW_TAG_common_inclusion
:
4806 return "DW_TAG_common_inclusion";
4807 case DW_TAG_inheritance
:
4808 return "DW_TAG_inheritance";
4809 case DW_TAG_inlined_subroutine
:
4810 return "DW_TAG_inlined_subroutine";
4812 return "DW_TAG_module";
4813 case DW_TAG_ptr_to_member_type
:
4814 return "DW_TAG_ptr_to_member_type";
4815 case DW_TAG_set_type
:
4816 return "DW_TAG_set_type";
4817 case DW_TAG_subrange_type
:
4818 return "DW_TAG_subrange_type";
4819 case DW_TAG_with_stmt
:
4820 return "DW_TAG_with_stmt";
4821 case DW_TAG_access_declaration
:
4822 return "DW_TAG_access_declaration";
4823 case DW_TAG_base_type
:
4824 return "DW_TAG_base_type";
4825 case DW_TAG_catch_block
:
4826 return "DW_TAG_catch_block";
4827 case DW_TAG_const_type
:
4828 return "DW_TAG_const_type";
4829 case DW_TAG_constant
:
4830 return "DW_TAG_constant";
4831 case DW_TAG_enumerator
:
4832 return "DW_TAG_enumerator";
4833 case DW_TAG_file_type
:
4834 return "DW_TAG_file_type";
4836 return "DW_TAG_friend";
4837 case DW_TAG_namelist
:
4838 return "DW_TAG_namelist";
4839 case DW_TAG_namelist_item
:
4840 return "DW_TAG_namelist_item";
4841 case DW_TAG_packed_type
:
4842 return "DW_TAG_packed_type";
4843 case DW_TAG_subprogram
:
4844 return "DW_TAG_subprogram";
4845 case DW_TAG_template_type_param
:
4846 return "DW_TAG_template_type_param";
4847 case DW_TAG_template_value_param
:
4848 return "DW_TAG_template_value_param";
4849 case DW_TAG_thrown_type
:
4850 return "DW_TAG_thrown_type";
4851 case DW_TAG_try_block
:
4852 return "DW_TAG_try_block";
4853 case DW_TAG_variant_part
:
4854 return "DW_TAG_variant_part";
4855 case DW_TAG_variable
:
4856 return "DW_TAG_variable";
4857 case DW_TAG_volatile_type
:
4858 return "DW_TAG_volatile_type";
4859 case DW_TAG_MIPS_loop
:
4860 return "DW_TAG_MIPS_loop";
4861 case DW_TAG_format_label
:
4862 return "DW_TAG_format_label";
4863 case DW_TAG_function_template
:
4864 return "DW_TAG_function_template";
4865 case DW_TAG_class_template
:
4866 return "DW_TAG_class_template";
4868 return "DW_TAG_<unknown>";
4872 /* Convert a DWARF attribute code into its string name. */
4875 dwarf_attr_name (register unsigned attr
)
4880 return "DW_AT_sibling";
4881 case DW_AT_location
:
4882 return "DW_AT_location";
4884 return "DW_AT_name";
4885 case DW_AT_ordering
:
4886 return "DW_AT_ordering";
4887 case DW_AT_subscr_data
:
4888 return "DW_AT_subscr_data";
4889 case DW_AT_byte_size
:
4890 return "DW_AT_byte_size";
4891 case DW_AT_bit_offset
:
4892 return "DW_AT_bit_offset";
4893 case DW_AT_bit_size
:
4894 return "DW_AT_bit_size";
4895 case DW_AT_element_list
:
4896 return "DW_AT_element_list";
4897 case DW_AT_stmt_list
:
4898 return "DW_AT_stmt_list";
4900 return "DW_AT_low_pc";
4902 return "DW_AT_high_pc";
4903 case DW_AT_language
:
4904 return "DW_AT_language";
4906 return "DW_AT_member";
4908 return "DW_AT_discr";
4909 case DW_AT_discr_value
:
4910 return "DW_AT_discr_value";
4911 case DW_AT_visibility
:
4912 return "DW_AT_visibility";
4914 return "DW_AT_import";
4915 case DW_AT_string_length
:
4916 return "DW_AT_string_length";
4917 case DW_AT_common_reference
:
4918 return "DW_AT_common_reference";
4919 case DW_AT_comp_dir
:
4920 return "DW_AT_comp_dir";
4921 case DW_AT_const_value
:
4922 return "DW_AT_const_value";
4923 case DW_AT_containing_type
:
4924 return "DW_AT_containing_type";
4925 case DW_AT_default_value
:
4926 return "DW_AT_default_value";
4928 return "DW_AT_inline";
4929 case DW_AT_is_optional
:
4930 return "DW_AT_is_optional";
4931 case DW_AT_lower_bound
:
4932 return "DW_AT_lower_bound";
4933 case DW_AT_producer
:
4934 return "DW_AT_producer";
4935 case DW_AT_prototyped
:
4936 return "DW_AT_prototyped";
4937 case DW_AT_return_addr
:
4938 return "DW_AT_return_addr";
4939 case DW_AT_start_scope
:
4940 return "DW_AT_start_scope";
4941 case DW_AT_stride_size
:
4942 return "DW_AT_stride_size";
4943 case DW_AT_upper_bound
:
4944 return "DW_AT_upper_bound";
4945 case DW_AT_abstract_origin
:
4946 return "DW_AT_abstract_origin";
4947 case DW_AT_accessibility
:
4948 return "DW_AT_accessibility";
4949 case DW_AT_address_class
:
4950 return "DW_AT_address_class";
4951 case DW_AT_artificial
:
4952 return "DW_AT_artificial";
4953 case DW_AT_base_types
:
4954 return "DW_AT_base_types";
4955 case DW_AT_calling_convention
:
4956 return "DW_AT_calling_convention";
4958 return "DW_AT_count";
4959 case DW_AT_data_member_location
:
4960 return "DW_AT_data_member_location";
4961 case DW_AT_decl_column
:
4962 return "DW_AT_decl_column";
4963 case DW_AT_decl_file
:
4964 return "DW_AT_decl_file";
4965 case DW_AT_decl_line
:
4966 return "DW_AT_decl_line";
4967 case DW_AT_declaration
:
4968 return "DW_AT_declaration";
4969 case DW_AT_discr_list
:
4970 return "DW_AT_discr_list";
4971 case DW_AT_encoding
:
4972 return "DW_AT_encoding";
4973 case DW_AT_external
:
4974 return "DW_AT_external";
4975 case DW_AT_frame_base
:
4976 return "DW_AT_frame_base";
4978 return "DW_AT_friend";
4979 case DW_AT_identifier_case
:
4980 return "DW_AT_identifier_case";
4981 case DW_AT_macro_info
:
4982 return "DW_AT_macro_info";
4983 case DW_AT_namelist_items
:
4984 return "DW_AT_namelist_items";
4985 case DW_AT_priority
:
4986 return "DW_AT_priority";
4988 return "DW_AT_segment";
4989 case DW_AT_specification
:
4990 return "DW_AT_specification";
4991 case DW_AT_static_link
:
4992 return "DW_AT_static_link";
4994 return "DW_AT_type";
4995 case DW_AT_use_location
:
4996 return "DW_AT_use_location";
4997 case DW_AT_variable_parameter
:
4998 return "DW_AT_variable_parameter";
4999 case DW_AT_virtuality
:
5000 return "DW_AT_virtuality";
5001 case DW_AT_vtable_elem_location
:
5002 return "DW_AT_vtable_elem_location";
5005 case DW_AT_MIPS_fde
:
5006 return "DW_AT_MIPS_fde";
5007 case DW_AT_MIPS_loop_begin
:
5008 return "DW_AT_MIPS_loop_begin";
5009 case DW_AT_MIPS_tail_loop_begin
:
5010 return "DW_AT_MIPS_tail_loop_begin";
5011 case DW_AT_MIPS_epilog_begin
:
5012 return "DW_AT_MIPS_epilog_begin";
5013 case DW_AT_MIPS_loop_unroll_factor
:
5014 return "DW_AT_MIPS_loop_unroll_factor";
5015 case DW_AT_MIPS_software_pipeline_depth
:
5016 return "DW_AT_MIPS_software_pipeline_depth";
5017 case DW_AT_MIPS_linkage_name
:
5018 return "DW_AT_MIPS_linkage_name";
5021 case DW_AT_sf_names
:
5022 return "DW_AT_sf_names";
5023 case DW_AT_src_info
:
5024 return "DW_AT_src_info";
5025 case DW_AT_mac_info
:
5026 return "DW_AT_mac_info";
5027 case DW_AT_src_coords
:
5028 return "DW_AT_src_coords";
5029 case DW_AT_body_begin
:
5030 return "DW_AT_body_begin";
5031 case DW_AT_body_end
:
5032 return "DW_AT_body_end";
5034 return "DW_AT_<unknown>";
5038 /* Convert a DWARF value form code into its string name. */
5041 dwarf_form_name (register unsigned form
)
5046 return "DW_FORM_addr";
5047 case DW_FORM_block2
:
5048 return "DW_FORM_block2";
5049 case DW_FORM_block4
:
5050 return "DW_FORM_block4";
5052 return "DW_FORM_data2";
5054 return "DW_FORM_data4";
5056 return "DW_FORM_data8";
5057 case DW_FORM_string
:
5058 return "DW_FORM_string";
5060 return "DW_FORM_block";
5061 case DW_FORM_block1
:
5062 return "DW_FORM_block1";
5064 return "DW_FORM_data1";
5066 return "DW_FORM_flag";
5068 return "DW_FORM_sdata";
5070 return "DW_FORM_strp";
5072 return "DW_FORM_udata";
5073 case DW_FORM_ref_addr
:
5074 return "DW_FORM_ref_addr";
5076 return "DW_FORM_ref1";
5078 return "DW_FORM_ref2";
5080 return "DW_FORM_ref4";
5082 return "DW_FORM_ref8";
5083 case DW_FORM_ref_udata
:
5084 return "DW_FORM_ref_udata";
5085 case DW_FORM_indirect
:
5086 return "DW_FORM_indirect";
5088 return "DW_FORM_<unknown>";
5092 /* Convert a DWARF stack opcode into its string name. */
5095 dwarf_stack_op_name (register unsigned op
)
5100 return "DW_OP_addr";
5102 return "DW_OP_deref";
5104 return "DW_OP_const1u";
5106 return "DW_OP_const1s";
5108 return "DW_OP_const2u";
5110 return "DW_OP_const2s";
5112 return "DW_OP_const4u";
5114 return "DW_OP_const4s";
5116 return "DW_OP_const8u";
5118 return "DW_OP_const8s";
5120 return "DW_OP_constu";
5122 return "DW_OP_consts";
5126 return "DW_OP_drop";
5128 return "DW_OP_over";
5130 return "DW_OP_pick";
5132 return "DW_OP_swap";
5136 return "DW_OP_xderef";
5144 return "DW_OP_minus";
5156 return "DW_OP_plus";
5157 case DW_OP_plus_uconst
:
5158 return "DW_OP_plus_uconst";
5164 return "DW_OP_shra";
5182 return "DW_OP_skip";
5184 return "DW_OP_lit0";
5186 return "DW_OP_lit1";
5188 return "DW_OP_lit2";
5190 return "DW_OP_lit3";
5192 return "DW_OP_lit4";
5194 return "DW_OP_lit5";
5196 return "DW_OP_lit6";
5198 return "DW_OP_lit7";
5200 return "DW_OP_lit8";
5202 return "DW_OP_lit9";
5204 return "DW_OP_lit10";
5206 return "DW_OP_lit11";
5208 return "DW_OP_lit12";
5210 return "DW_OP_lit13";
5212 return "DW_OP_lit14";
5214 return "DW_OP_lit15";
5216 return "DW_OP_lit16";
5218 return "DW_OP_lit17";
5220 return "DW_OP_lit18";
5222 return "DW_OP_lit19";
5224 return "DW_OP_lit20";
5226 return "DW_OP_lit21";
5228 return "DW_OP_lit22";
5230 return "DW_OP_lit23";
5232 return "DW_OP_lit24";
5234 return "DW_OP_lit25";
5236 return "DW_OP_lit26";
5238 return "DW_OP_lit27";
5240 return "DW_OP_lit28";
5242 return "DW_OP_lit29";
5244 return "DW_OP_lit30";
5246 return "DW_OP_lit31";
5248 return "DW_OP_reg0";
5250 return "DW_OP_reg1";
5252 return "DW_OP_reg2";
5254 return "DW_OP_reg3";
5256 return "DW_OP_reg4";
5258 return "DW_OP_reg5";
5260 return "DW_OP_reg6";
5262 return "DW_OP_reg7";
5264 return "DW_OP_reg8";
5266 return "DW_OP_reg9";
5268 return "DW_OP_reg10";
5270 return "DW_OP_reg11";
5272 return "DW_OP_reg12";
5274 return "DW_OP_reg13";
5276 return "DW_OP_reg14";
5278 return "DW_OP_reg15";
5280 return "DW_OP_reg16";
5282 return "DW_OP_reg17";
5284 return "DW_OP_reg18";
5286 return "DW_OP_reg19";
5288 return "DW_OP_reg20";
5290 return "DW_OP_reg21";
5292 return "DW_OP_reg22";
5294 return "DW_OP_reg23";
5296 return "DW_OP_reg24";
5298 return "DW_OP_reg25";
5300 return "DW_OP_reg26";
5302 return "DW_OP_reg27";
5304 return "DW_OP_reg28";
5306 return "DW_OP_reg29";
5308 return "DW_OP_reg30";
5310 return "DW_OP_reg31";
5312 return "DW_OP_breg0";
5314 return "DW_OP_breg1";
5316 return "DW_OP_breg2";
5318 return "DW_OP_breg3";
5320 return "DW_OP_breg4";
5322 return "DW_OP_breg5";
5324 return "DW_OP_breg6";
5326 return "DW_OP_breg7";
5328 return "DW_OP_breg8";
5330 return "DW_OP_breg9";
5332 return "DW_OP_breg10";
5334 return "DW_OP_breg11";
5336 return "DW_OP_breg12";
5338 return "DW_OP_breg13";
5340 return "DW_OP_breg14";
5342 return "DW_OP_breg15";
5344 return "DW_OP_breg16";
5346 return "DW_OP_breg17";
5348 return "DW_OP_breg18";
5350 return "DW_OP_breg19";
5352 return "DW_OP_breg20";
5354 return "DW_OP_breg21";
5356 return "DW_OP_breg22";
5358 return "DW_OP_breg23";
5360 return "DW_OP_breg24";
5362 return "DW_OP_breg25";
5364 return "DW_OP_breg26";
5366 return "DW_OP_breg27";
5368 return "DW_OP_breg28";
5370 return "DW_OP_breg29";
5372 return "DW_OP_breg30";
5374 return "DW_OP_breg31";
5376 return "DW_OP_regx";
5378 return "DW_OP_fbreg";
5380 return "DW_OP_bregx";
5382 return "DW_OP_piece";
5383 case DW_OP_deref_size
:
5384 return "DW_OP_deref_size";
5385 case DW_OP_xderef_size
:
5386 return "DW_OP_xderef_size";
5390 return "OP_<unknown>";
5395 dwarf_bool_name (unsigned mybool
)
5403 /* Convert a DWARF type code into its string name. */
5406 dwarf_type_encoding_name (register unsigned enc
)
5410 case DW_ATE_address
:
5411 return "DW_ATE_address";
5412 case DW_ATE_boolean
:
5413 return "DW_ATE_boolean";
5414 case DW_ATE_complex_float
:
5415 return "DW_ATE_complex_float";
5417 return "DW_ATE_float";
5419 return "DW_ATE_signed";
5420 case DW_ATE_signed_char
:
5421 return "DW_ATE_signed_char";
5422 case DW_ATE_unsigned
:
5423 return "DW_ATE_unsigned";
5424 case DW_ATE_unsigned_char
:
5425 return "DW_ATE_unsigned_char";
5427 return "DW_ATE_<unknown>";
5431 /* Convert a DWARF call frame info operation to its string name. */
5435 dwarf_cfi_name (register unsigned cfi_opc
)
5439 case DW_CFA_advance_loc
:
5440 return "DW_CFA_advance_loc";
5442 return "DW_CFA_offset";
5443 case DW_CFA_restore
:
5444 return "DW_CFA_restore";
5446 return "DW_CFA_nop";
5447 case DW_CFA_set_loc
:
5448 return "DW_CFA_set_loc";
5449 case DW_CFA_advance_loc1
:
5450 return "DW_CFA_advance_loc1";
5451 case DW_CFA_advance_loc2
:
5452 return "DW_CFA_advance_loc2";
5453 case DW_CFA_advance_loc4
:
5454 return "DW_CFA_advance_loc4";
5455 case DW_CFA_offset_extended
:
5456 return "DW_CFA_offset_extended";
5457 case DW_CFA_restore_extended
:
5458 return "DW_CFA_restore_extended";
5459 case DW_CFA_undefined
:
5460 return "DW_CFA_undefined";
5461 case DW_CFA_same_value
:
5462 return "DW_CFA_same_value";
5463 case DW_CFA_register
:
5464 return "DW_CFA_register";
5465 case DW_CFA_remember_state
:
5466 return "DW_CFA_remember_state";
5467 case DW_CFA_restore_state
:
5468 return "DW_CFA_restore_state";
5469 case DW_CFA_def_cfa
:
5470 return "DW_CFA_def_cfa";
5471 case DW_CFA_def_cfa_register
:
5472 return "DW_CFA_def_cfa_register";
5473 case DW_CFA_def_cfa_offset
:
5474 return "DW_CFA_def_cfa_offset";
5475 /* SGI/MIPS specific */
5476 case DW_CFA_MIPS_advance_loc8
:
5477 return "DW_CFA_MIPS_advance_loc8";
5479 return "DW_CFA_<unknown>";
5485 dump_die (struct die_info
*die
)
5489 fprintf (stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5490 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5491 fprintf (stderr
, "\thas children: %s\n",
5492 dwarf_bool_name (die
->has_children
));
5494 fprintf (stderr
, "\tattributes:\n");
5495 for (i
= 0; i
< die
->num_attrs
; ++i
)
5497 fprintf (stderr
, "\t\t%s (%s) ",
5498 dwarf_attr_name (die
->attrs
[i
].name
),
5499 dwarf_form_name (die
->attrs
[i
].form
));
5500 switch (die
->attrs
[i
].form
)
5502 case DW_FORM_ref_addr
:
5504 fprintf (stderr
, "address: ");
5505 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
5507 case DW_FORM_block2
:
5508 case DW_FORM_block4
:
5510 case DW_FORM_block1
:
5511 fprintf (stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5522 fprintf (stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
5524 case DW_FORM_string
:
5525 fprintf (stderr
, "string: \"%s\"",
5526 DW_STRING (&die
->attrs
[i
])
5527 ? DW_STRING (&die
->attrs
[i
]) : "");
5530 if (DW_UNSND (&die
->attrs
[i
]))
5531 fprintf (stderr
, "flag: TRUE");
5533 fprintf (stderr
, "flag: FALSE");
5535 case DW_FORM_strp
: /* we do not support separate string
5537 case DW_FORM_indirect
: /* we do not handle indirect yet */
5539 fprintf (stderr
, "unsupported attribute form: %d.",
5540 die
->attrs
[i
].form
);
5542 fprintf (stderr
, "\n");
5547 dump_die_list (struct die_info
*die
)
5557 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
5560 struct die_info
*old
;
5562 h
= (offset
% REF_HASH_SIZE
);
5563 old
= die_ref_table
[h
];
5564 die
->next_ref
= old
;
5565 die_ref_table
[h
] = die
;
5570 dwarf2_empty_hash_tables (void)
5572 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5576 dwarf2_get_ref_die_offset (struct attribute
*attr
)
5578 unsigned int result
= 0;
5582 case DW_FORM_ref_addr
:
5583 result
= DW_ADDR (attr
);
5589 case DW_FORM_ref_udata
:
5590 result
= cu_header_offset
+ DW_UNSND (attr
);
5593 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5599 follow_die_ref (unsigned int offset
)
5601 struct die_info
*die
;
5604 h
= (offset
% REF_HASH_SIZE
);
5605 die
= die_ref_table
[h
];
5608 if (die
->offset
== offset
)
5612 die
= die
->next_ref
;
5617 static struct type
*
5618 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
5620 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5622 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5626 /* Look for this particular type in the fundamental type vector. If
5627 one is not found, create and install one appropriate for the
5628 current language and the current target machine. */
5630 if (ftypes
[typeid] == NULL
)
5632 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5635 return (ftypes
[typeid]);
5638 /* Decode simple location descriptions.
5639 Given a pointer to a dwarf block that defines a location, compute
5640 the location and return the value.
5642 FIXME: This is a kludge until we figure out a better
5643 way to handle the location descriptions.
5644 Gdb's design does not mesh well with the DWARF2 notion of a location
5645 computing interpreter, which is a shame because the flexibility goes unused.
5646 FIXME: Implement more operations as necessary.
5648 A location description containing no operations indicates that the
5649 object is optimized out. The global optimized_out flag is set for
5650 those, the return value is meaningless.
5652 When the result is a register number, the global isreg flag is set,
5653 otherwise it is cleared.
5655 When the result is a base register offset, the global offreg flag is set
5656 and the register number is returned in basereg, otherwise it is cleared.
5658 When the DW_OP_fbreg operation is encountered without a corresponding
5659 DW_AT_frame_base attribute, the global islocal flag is set.
5660 Hopefully the machine dependent code knows how to set up a virtual
5661 frame pointer for the local references.
5663 Note that stack[0] is unused except as a default error return.
5664 Note that stack overflow is not yet handled. */
5667 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
5668 const struct comp_unit_head
*cu_header
)
5671 int size
= blk
->size
;
5672 char *data
= blk
->data
;
5673 CORE_ADDR stack
[64];
5675 unsigned int bytes_read
, unsnd
;
5726 stack
[++stacki
] = op
- DW_OP_reg0
;
5731 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5733 #if defined(HARRIS_TARGET) && defined(_M88K)
5734 /* The Harris 88110 gdb ports have long kept their special reg
5735 numbers between their gp-regs and their x-regs. This is
5736 not how our dwarf is generated. Punt. */
5739 stack
[++stacki
] = unsnd
;
5775 basereg
= op
- DW_OP_breg0
;
5776 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5782 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5784 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5789 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5791 if (frame_base_reg
>= 0)
5794 basereg
= frame_base_reg
;
5795 stack
[stacki
] += frame_base_offset
;
5799 complain (&dwarf2_missing_at_frame_base
);
5805 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
5806 cu_header
, &bytes_read
);
5811 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
5816 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
5821 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
5826 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
5831 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
5836 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
5841 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
5847 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5852 stack
[stacki
- 1] += stack
[stacki
];
5856 case DW_OP_plus_uconst
:
5857 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5862 stack
[stacki
- 1] = stack
[stacki
] - stack
[stacki
- 1];
5868 /* If we're not the last op, then we definitely can't encode
5869 this using GDB's address_class enum. */
5871 complain (&dwarf2_complex_location_expr
);
5875 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
5876 return (stack
[stacki
]);
5879 return (stack
[stacki
]);
5882 /* memory allocation interface */
5886 dwarf2_free_tmp_obstack (PTR ignore
)
5888 obstack_free (&dwarf2_tmp_obstack
, NULL
);
5891 static struct dwarf_block
*
5892 dwarf_alloc_block (void)
5894 struct dwarf_block
*blk
;
5896 blk
= (struct dwarf_block
*)
5897 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
5901 static struct abbrev_info
*
5902 dwarf_alloc_abbrev (void)
5904 struct abbrev_info
*abbrev
;
5906 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
5907 memset (abbrev
, 0, sizeof (struct abbrev_info
));
5911 static struct die_info
*
5912 dwarf_alloc_die (void)
5914 struct die_info
*die
;
5916 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5917 memset (die
, 0, sizeof (struct die_info
));