1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
10 support in dwarfread.c
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or (at
17 your option) any later version.
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. */
35 #include "elf/dwarf2.h"
38 #include "expression.h"
39 #include "filenames.h" /* for DOSish file names */
43 #include "complaints.h"
46 #include "gdb_string.h"
47 #include "gdb_assert.h"
48 #include <sys/types.h>
50 #ifndef DWARF2_REG_TO_REGNUM
51 #define DWARF2_REG_TO_REGNUM(REG) (REG)
55 /* .debug_info header for a compilation unit
56 Because of alignment constraints, this structure has padding and cannot
57 be mapped directly onto the beginning of the .debug_info section. */
58 typedef struct comp_unit_header
60 unsigned int length
; /* length of the .debug_info
62 unsigned short version
; /* version number -- 2 for DWARF
64 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
65 unsigned char addr_size
; /* byte size of an address -- 4 */
68 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
71 /* .debug_pubnames header
72 Because of alignment constraints, this structure has padding and cannot
73 be mapped directly onto the beginning of the .debug_info section. */
74 typedef struct pubnames_header
76 unsigned int length
; /* length of the .debug_pubnames
78 unsigned char version
; /* version number -- 2 for DWARF
80 unsigned int info_offset
; /* offset into .debug_info section */
81 unsigned int info_size
; /* byte size of .debug_info section
85 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
87 /* .debug_pubnames header
88 Because of alignment constraints, this structure has padding and cannot
89 be mapped directly onto the beginning of the .debug_info section. */
90 typedef struct aranges_header
92 unsigned int length
; /* byte len of the .debug_aranges
94 unsigned short version
; /* version number -- 2 for DWARF
96 unsigned int info_offset
; /* offset into .debug_info section */
97 unsigned char addr_size
; /* byte size of an address */
98 unsigned char seg_size
; /* byte size of segment descriptor */
101 #define _ACTUAL_ARANGES_HEADER_SIZE 12
103 /* .debug_line statement program prologue
104 Because of alignment constraints, this structure has padding and cannot
105 be mapped directly onto the beginning of the .debug_info section. */
106 typedef struct statement_prologue
108 unsigned int total_length
; /* byte length of the statement
110 unsigned short version
; /* version number -- 2 for DWARF
112 unsigned int prologue_length
; /* # bytes between prologue &
114 unsigned char minimum_instruction_length
; /* byte size of
116 unsigned char default_is_stmt
; /* initial value of is_stmt
119 unsigned char line_range
;
120 unsigned char opcode_base
; /* number assigned to first special
122 unsigned char *standard_opcode_lengths
;
126 /* offsets and sizes of debugging sections */
128 static file_ptr dwarf_info_offset
;
129 static file_ptr dwarf_abbrev_offset
;
130 static file_ptr dwarf_line_offset
;
131 static file_ptr dwarf_pubnames_offset
;
132 static file_ptr dwarf_aranges_offset
;
133 static file_ptr dwarf_loc_offset
;
134 static file_ptr dwarf_macinfo_offset
;
135 static file_ptr dwarf_str_offset
;
136 file_ptr dwarf_frame_offset
;
137 file_ptr dwarf_eh_frame_offset
;
139 static unsigned int dwarf_info_size
;
140 static unsigned int dwarf_abbrev_size
;
141 static unsigned int dwarf_line_size
;
142 static unsigned int dwarf_pubnames_size
;
143 static unsigned int dwarf_aranges_size
;
144 static unsigned int dwarf_loc_size
;
145 static unsigned int dwarf_macinfo_size
;
146 static unsigned int dwarf_str_size
;
147 unsigned int dwarf_frame_size
;
148 unsigned int dwarf_eh_frame_size
;
150 /* names of the debugging sections */
152 #define INFO_SECTION ".debug_info"
153 #define ABBREV_SECTION ".debug_abbrev"
154 #define LINE_SECTION ".debug_line"
155 #define PUBNAMES_SECTION ".debug_pubnames"
156 #define ARANGES_SECTION ".debug_aranges"
157 #define LOC_SECTION ".debug_loc"
158 #define MACINFO_SECTION ".debug_macinfo"
159 #define STR_SECTION ".debug_str"
160 #define FRAME_SECTION ".debug_frame"
161 #define EH_FRAME_SECTION ".eh_frame"
163 /* local data types */
165 /* We hold several abbreviation tables in memory at the same time. */
166 #ifndef ABBREV_HASH_SIZE
167 #define ABBREV_HASH_SIZE 121
170 /* The data in a compilation unit header, after target2host
171 translation, looks like this. */
172 struct comp_unit_head
174 unsigned long length
;
176 unsigned int abbrev_offset
;
177 unsigned char addr_size
;
178 unsigned char signed_addr_p
;
179 unsigned int offset_size
; /* size of file offsets; either 4 or 8 */
180 unsigned int initial_length_size
; /* size of the length field; either
183 /* Offset to the first byte of this compilation unit header in the
184 * .debug_info section, for resolving relative reference dies. */
188 /* Pointer to this compilation unit header in the .debug_info
193 /* Pointer to the first die of this compilatio unit. This will
194 * be the first byte following the compilation unit header. */
198 /* Pointer to the next compilation unit header in the program. */
200 struct comp_unit_head
*next
;
202 /* DWARF abbreviation table associated with this compilation unit */
204 struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
207 /* The line number information for a compilation unit (found in the
208 .debug_line section) begins with a "statement program header",
209 which contains the following information. */
212 unsigned int total_length
;
213 unsigned short version
;
214 unsigned int header_length
;
215 unsigned char minimum_instruction_length
;
216 unsigned char default_is_stmt
;
218 unsigned char line_range
;
219 unsigned char opcode_base
;
221 /* standard_opcode_lengths[i] is the number of operands for the
222 standard opcode whose value is i. This means that
223 standard_opcode_lengths[0] is unused, and the last meaningful
224 element is standard_opcode_lengths[opcode_base - 1]. */
225 unsigned char *standard_opcode_lengths
;
227 /* The include_directories table. NOTE! These strings are not
228 allocated with xmalloc; instead, they are pointers into
229 debug_line_buffer. If you try to free them, `free' will get
231 unsigned int num_include_dirs
, include_dirs_size
;
234 /* The file_names table. NOTE! These strings are not allocated
235 with xmalloc; instead, they are pointers into debug_line_buffer.
236 Don't try to free them directly. */
237 unsigned int num_file_names
, file_names_size
;
241 unsigned int dir_index
;
242 unsigned int mod_time
;
246 /* The start and end of the statement program following this
247 header. These point into dwarf_line_buffer. */
248 char *statement_program_start
, *statement_program_end
;
251 /* When we construct a partial symbol table entry we only
252 need this much information. */
253 struct partial_die_info
256 unsigned char has_children
;
257 unsigned char is_external
;
258 unsigned char is_declaration
;
259 unsigned char has_type
;
266 struct dwarf_block
*locdesc
;
267 unsigned int language
;
271 /* This data structure holds the information of an abbrev. */
274 unsigned int number
; /* number identifying abbrev */
275 enum dwarf_tag tag
; /* dwarf tag */
276 int has_children
; /* boolean */
277 unsigned int num_attrs
; /* number of attributes */
278 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
279 struct abbrev_info
*next
; /* next in chain */
284 enum dwarf_attribute name
;
285 enum dwarf_form form
;
288 /* This data structure holds a complete die structure. */
291 enum dwarf_tag tag
; /* Tag indicating type of die */
292 unsigned short has_children
; /* Does the die have children */
293 unsigned int abbrev
; /* Abbrev number */
294 unsigned int offset
; /* Offset in .debug_info section */
295 unsigned int num_attrs
; /* Number of attributes */
296 struct attribute
*attrs
; /* An array of attributes */
297 struct die_info
*next_ref
; /* Next die in ref hash table */
298 struct die_info
*next
; /* Next die in linked list */
299 struct type
*type
; /* Cached type information */
302 /* Attributes have a name and a value */
305 enum dwarf_attribute name
;
306 enum dwarf_form form
;
310 struct dwarf_block
*blk
;
318 struct function_range
321 CORE_ADDR lowpc
, highpc
;
323 struct function_range
*next
;
326 static struct function_range
*cu_first_fn
, *cu_last_fn
, *cu_cached_fn
;
328 /* Get at parts of an attribute structure */
330 #define DW_STRING(attr) ((attr)->u.str)
331 #define DW_UNSND(attr) ((attr)->u.unsnd)
332 #define DW_BLOCK(attr) ((attr)->u.blk)
333 #define DW_SND(attr) ((attr)->u.snd)
334 #define DW_ADDR(attr) ((attr)->u.addr)
336 /* Blocks are a bunch of untyped bytes. */
343 #ifndef ATTR_ALLOC_CHUNK
344 #define ATTR_ALLOC_CHUNK 4
347 /* A hash table of die offsets for following references. */
348 #ifndef REF_HASH_SIZE
349 #define REF_HASH_SIZE 1021
352 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
354 /* Obstack for allocating temporary storage used during symbol reading. */
355 static struct obstack dwarf2_tmp_obstack
;
357 /* Offset to the first byte of the current compilation unit header,
358 for resolving relative reference dies. */
359 static unsigned int cu_header_offset
;
361 /* Allocate fields for structs, unions and enums in this size. */
362 #ifndef DW_FIELD_ALLOC_CHUNK
363 #define DW_FIELD_ALLOC_CHUNK 4
366 /* The language we are debugging. */
367 static enum language cu_language
;
368 static const struct language_defn
*cu_language_defn
;
370 /* Actually data from the sections. */
371 static char *dwarf_info_buffer
;
372 static char *dwarf_abbrev_buffer
;
373 static char *dwarf_line_buffer
;
374 static char *dwarf_str_buffer
;
375 static char *dwarf_macinfo_buffer
;
377 /* A zeroed version of a partial die for initialization purposes. */
378 static struct partial_die_info zeroed_partial_die
;
380 /* The generic symbol table building routines have separate lists for
381 file scope symbols and all all other scopes (local scopes). So
382 we need to select the right one to pass to add_symbol_to_list().
383 We do it by keeping a pointer to the correct list in list_in_scope.
385 FIXME: The original dwarf code just treated the file scope as the first
386 local scope, and all other local scopes as nested local scopes, and worked
387 fine. Check to see if we really need to distinguish these
389 static struct pending
**list_in_scope
= &file_symbols
;
391 /* FIXME: decode_locdesc sets these variables to describe the location
392 to the caller. These ought to be a structure or something. If
393 none of the flags are set, the object lives at the address returned
394 by decode_locdesc. */
396 static int optimized_out
; /* No ops in location in expression,
397 so object was optimized out. */
398 static int isreg
; /* Object lives in register.
399 decode_locdesc's return value is
400 the register number. */
401 static int offreg
; /* Object's address is the sum of the
402 register specified by basereg, plus
403 the offset returned. */
404 static int basereg
; /* See `offreg'. */
405 static int isderef
; /* Value described by flags above is
406 the address of a pointer to the object. */
407 static int islocal
; /* Variable is at the returned offset
408 from the frame start, but there's
409 no identified frame pointer for
410 this function, so we can't say
411 which register it's relative to;
413 static int is_thread_local
; /* Variable is at a constant offset in the
414 thread-local storage block for the
415 current thread and the dynamic linker
416 module containing this expression.
417 decode_locdesc returns the offset from
420 /* DW_AT_frame_base values for the current function.
421 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
422 contains the register number for the frame register.
423 frame_base_offset is the offset from the frame register to the
424 virtual stack frame. */
425 static int frame_base_reg
;
426 static CORE_ADDR frame_base_offset
;
428 /* This value is added to each symbol value. FIXME: Generalize to
429 the section_offsets structure used by dbxread (once this is done,
430 pass the appropriate section number to end_symtab). */
431 static CORE_ADDR baseaddr
; /* Add to each symbol value */
433 /* We put a pointer to this structure in the read_symtab_private field
435 The complete dwarf information for an objfile is kept in the
436 psymbol_obstack, so that absolute die references can be handled.
437 Most of the information in this structure is related to an entire
438 object file and could be passed via the sym_private field of the objfile.
439 It is however conceivable that dwarf2 might not be the only type
440 of symbols read from an object file. */
444 /* Pointer to start of dwarf info buffer for the objfile. */
446 char *dwarf_info_buffer
;
448 /* Offset in dwarf_info_buffer for this compilation unit. */
450 unsigned long dwarf_info_offset
;
452 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
454 char *dwarf_abbrev_buffer
;
456 /* Size of dwarf abbreviation section for the objfile. */
458 unsigned int dwarf_abbrev_size
;
460 /* Pointer to start of dwarf line buffer for the objfile. */
462 char *dwarf_line_buffer
;
464 /* Size of dwarf_line_buffer, in bytes. */
466 unsigned int dwarf_line_size
;
468 /* Pointer to start of dwarf string buffer for the objfile. */
470 char *dwarf_str_buffer
;
472 /* Size of dwarf string section for the objfile. */
474 unsigned int dwarf_str_size
;
476 /* Pointer to start of dwarf macro buffer for the objfile. */
478 char *dwarf_macinfo_buffer
;
480 /* Size of dwarf macinfo section for the objfile. */
482 unsigned int dwarf_macinfo_size
;
486 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
487 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
488 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
489 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
490 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
491 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
492 #define DWARF_LINE_SIZE(p) (PST_PRIVATE(p)->dwarf_line_size)
493 #define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer)
494 #define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size)
495 #define DWARF_MACINFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_macinfo_buffer)
496 #define DWARF_MACINFO_SIZE(p) (PST_PRIVATE(p)->dwarf_macinfo_size)
498 /* Maintain an array of referenced fundamental types for the current
499 compilation unit being read. For DWARF version 1, we have to construct
500 the fundamental types on the fly, since no information about the
501 fundamental types is supplied. Each such fundamental type is created by
502 calling a language dependent routine to create the type, and then a
503 pointer to that type is then placed in the array at the index specified
504 by it's FT_<TYPENAME> value. The array has a fixed size set by the
505 FT_NUM_MEMBERS compile time constant, which is the number of predefined
506 fundamental types gdb knows how to construct. */
507 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
509 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
510 but this would require a corresponding change in unpack_field_as_long
512 static int bits_per_byte
= 8;
514 /* The routines that read and process dies for a C struct or C++ class
515 pass lists of data member fields and lists of member function fields
516 in an instance of a field_info structure, as defined below. */
519 /* List of data member and baseclasses fields. */
522 struct nextfield
*next
;
529 /* Number of fields. */
532 /* Number of baseclasses. */
535 /* Set if the accesibility of one of the fields is not public. */
536 int non_public_fields
;
538 /* Member function fields array, entries are allocated in the order they
539 are encountered in the object file. */
542 struct nextfnfield
*next
;
543 struct fn_field fnfield
;
547 /* Member function fieldlist array, contains name of possibly overloaded
548 member function, number of overloaded member functions and a pointer
549 to the head of the member function field chain. */
554 struct nextfnfield
*head
;
558 /* Number of entries in the fnfieldlists array. */
562 /* Various complaints about symbol reading that don't abort the process */
564 static struct deprecated_complaint dwarf2_const_ignored
=
566 "type qualifier 'const' ignored", 0, 0
568 static struct deprecated_complaint dwarf2_volatile_ignored
=
570 "type qualifier 'volatile' ignored", 0, 0
572 static struct deprecated_complaint dwarf2_non_const_array_bound_ignored
=
574 "non-constant array bounds form '%s' ignored", 0, 0
576 static struct deprecated_complaint dwarf2_missing_line_number_section
=
578 "missing .debug_line section", 0, 0
580 static struct deprecated_complaint dwarf2_statement_list_fits_in_line_number_section
=
582 "statement list doesn't fit in .debug_line section", 0, 0
584 static struct deprecated_complaint dwarf2_mangled_line_number_section
=
586 "mangled .debug_line section", 0, 0
588 static struct deprecated_complaint dwarf2_unsupported_die_ref_attr
=
590 "unsupported die ref attribute form: '%s'", 0, 0
592 static struct deprecated_complaint dwarf2_unsupported_stack_op
=
594 "unsupported stack op: '%s'", 0, 0
596 static struct deprecated_complaint dwarf2_complex_location_expr
=
598 "location expression too complex", 0, 0
600 static struct deprecated_complaint dwarf2_unsupported_tag
=
602 "unsupported tag: '%s'", 0, 0
604 static struct deprecated_complaint dwarf2_unsupported_at_encoding
=
606 "unsupported DW_AT_encoding: '%s'", 0, 0
608 static struct deprecated_complaint dwarf2_unsupported_at_frame_base
=
610 "unsupported DW_AT_frame_base for function '%s'", 0, 0
612 static struct deprecated_complaint dwarf2_unexpected_tag
=
614 "unexepected tag in read_type_die: '%s'", 0, 0
616 static struct deprecated_complaint dwarf2_missing_at_frame_base
=
618 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
620 static struct deprecated_complaint dwarf2_bad_static_member_name
=
622 "unrecognized static data member name '%s'", 0, 0
624 static struct deprecated_complaint dwarf2_unsupported_accessibility
=
626 "unsupported accessibility %d", 0, 0
628 static struct deprecated_complaint dwarf2_bad_member_name_complaint
=
630 "cannot extract member name from '%s'", 0, 0
632 static struct deprecated_complaint dwarf2_missing_member_fn_type_complaint
=
634 "member function type missing for '%s'", 0, 0
636 static struct deprecated_complaint dwarf2_vtbl_not_found_complaint
=
638 "virtual function table pointer not found when defining class '%s'", 0, 0
640 static struct deprecated_complaint dwarf2_absolute_sibling_complaint
=
642 "ignoring absolute DW_AT_sibling", 0, 0
644 static struct deprecated_complaint dwarf2_const_value_length_mismatch
=
646 "const value length mismatch for '%s', got %d, expected %d", 0, 0
648 static struct deprecated_complaint dwarf2_unsupported_const_value_attr
=
650 "unsupported const value attribute form: '%s'", 0, 0
652 static struct deprecated_complaint dwarf2_misplaced_line_number
=
654 "misplaced first line number at 0x%lx for '%s'", 0, 0
656 static struct deprecated_complaint dwarf2_line_header_too_long
=
658 "line number info header doesn't fit in `.debug_line' section", 0, 0
660 static struct deprecated_complaint dwarf2_missing_macinfo_section
=
662 "missing .debug_macinfo section", 0, 0
664 static struct deprecated_complaint dwarf2_macros_too_long
=
666 "macro info runs off end of `.debug_macinfo' section", 0, 0
668 static struct deprecated_complaint dwarf2_macros_not_terminated
=
670 "no terminating 0-type entry for macros in `.debug_macinfo' section", 0, 0
672 static struct deprecated_complaint dwarf2_macro_outside_file
=
674 "debug info gives macro %s outside of any file: %s", 0, 0
676 static struct deprecated_complaint dwarf2_macro_unmatched_end_file
=
678 "macro debug info has an unmatched `close_file' directive", 0, 0
680 static struct deprecated_complaint dwarf2_macro_malformed_definition
=
682 "macro debug info contains a malformed macro definition:\n`%s'", 0, 0
684 static struct deprecated_complaint dwarf2_macro_spaces_in_definition
=
686 "macro definition contains spaces in formal argument list:\n`%s'", 0, 0
688 static struct deprecated_complaint dwarf2_invalid_attrib_class
=
690 "invalid attribute class or form for '%s' in '%s'", 0, 0
692 static struct deprecated_complaint dwarf2_invalid_pointer_size
=
694 "invalid pointer size %d", 0, 0
697 /* local function prototypes */
699 static void dwarf2_locate_sections (bfd
*, asection
*, PTR
);
702 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
705 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
707 static char *scan_partial_symbols (char *, struct objfile
*,
708 CORE_ADDR
*, CORE_ADDR
*,
709 const struct comp_unit_head
*);
711 static void add_partial_symbol (struct partial_die_info
*, struct objfile
*,
712 const struct comp_unit_head
*);
714 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
716 static void psymtab_to_symtab_1 (struct partial_symtab
*);
718 char *dwarf2_read_section (struct objfile
*, file_ptr
, unsigned int);
720 static void dwarf2_read_abbrevs (bfd
*abfd
, struct comp_unit_head
*cu_header
);
722 static void dwarf2_empty_abbrev_table (PTR
);
724 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
725 const struct comp_unit_head
*cu_header
);
727 static char *read_partial_die (struct partial_die_info
*,
729 const struct comp_unit_head
*);
731 static char *read_full_die (struct die_info
**, bfd
*, char *,
732 const struct comp_unit_head
*);
734 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
735 bfd
*, char *, const struct comp_unit_head
*);
737 static char *read_attribute_value (struct attribute
*, unsigned,
738 bfd
*, char *, const struct comp_unit_head
*);
740 static unsigned int read_1_byte (bfd
*, char *);
742 static int read_1_signed_byte (bfd
*, char *);
744 static unsigned int read_2_bytes (bfd
*, char *);
746 static unsigned int read_4_bytes (bfd
*, char *);
748 static unsigned long read_8_bytes (bfd
*, char *);
750 static CORE_ADDR
read_address (bfd
*, char *ptr
, const struct comp_unit_head
*,
753 static LONGEST
read_initial_length (bfd
*, char *,
754 struct comp_unit_head
*, int *bytes_read
);
756 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
759 static char *read_n_bytes (bfd
*, char *, unsigned int);
761 static char *read_string (bfd
*, char *, unsigned int *);
763 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
766 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
768 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
770 static void set_cu_language (unsigned int);
772 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
774 static int die_is_declaration (struct die_info
*);
776 static void free_line_header (struct line_header
*lh
);
778 static struct line_header
*(dwarf_decode_line_header
779 (unsigned int offset
,
781 const struct comp_unit_head
*cu_header
));
783 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
784 const struct comp_unit_head
*);
786 static void dwarf2_start_subfile (char *, char *);
788 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
789 struct objfile
*, const struct comp_unit_head
*);
791 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
792 struct objfile
*, const struct comp_unit_head
*);
794 static void dwarf2_const_value_data (struct attribute
*attr
,
798 static struct type
*die_type (struct die_info
*, struct objfile
*,
799 const struct comp_unit_head
*);
801 static struct type
*die_containing_type (struct die_info
*, struct objfile
*,
802 const struct comp_unit_head
*);
805 static struct type
*type_at_offset (unsigned int, struct objfile
*);
808 static struct type
*tag_type_to_type (struct die_info
*, struct objfile
*,
809 const struct comp_unit_head
*);
811 static void read_type_die (struct die_info
*, struct objfile
*,
812 const struct comp_unit_head
*);
814 static void read_typedef (struct die_info
*, struct objfile
*,
815 const struct comp_unit_head
*);
817 static void read_base_type (struct die_info
*, struct objfile
*);
819 static void read_file_scope (struct die_info
*, struct objfile
*,
820 const struct comp_unit_head
*);
822 static void read_func_scope (struct die_info
*, struct objfile
*,
823 const struct comp_unit_head
*);
825 static void read_lexical_block_scope (struct die_info
*, struct objfile
*,
826 const struct comp_unit_head
*);
828 static int dwarf2_get_pc_bounds (struct die_info
*,
829 CORE_ADDR
*, CORE_ADDR
*, struct objfile
*);
831 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
832 struct objfile
*, const struct comp_unit_head
*);
834 static void dwarf2_attach_fields_to_type (struct field_info
*,
835 struct type
*, struct objfile
*);
837 static void dwarf2_add_member_fn (struct field_info
*,
838 struct die_info
*, struct type
*,
839 struct objfile
*objfile
,
840 const struct comp_unit_head
*);
842 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
843 struct type
*, struct objfile
*);
845 static void read_structure_scope (struct die_info
*, struct objfile
*,
846 const struct comp_unit_head
*);
848 static void read_common_block (struct die_info
*, struct objfile
*,
849 const struct comp_unit_head
*);
851 static void read_namespace (struct die_info
*die
, struct objfile
*objfile
,
852 const struct comp_unit_head
*cu_header
);
854 static void read_enumeration (struct die_info
*, struct objfile
*,
855 const struct comp_unit_head
*);
857 static struct type
*dwarf_base_type (int, int, struct objfile
*);
859 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct objfile
*,
860 const struct comp_unit_head
*);
862 static void read_array_type (struct die_info
*, struct objfile
*,
863 const struct comp_unit_head
*);
865 static void read_tag_pointer_type (struct die_info
*, struct objfile
*,
866 const struct comp_unit_head
*);
868 static void read_tag_ptr_to_member_type (struct die_info
*, struct objfile
*,
869 const struct comp_unit_head
*);
871 static void read_tag_reference_type (struct die_info
*, struct objfile
*,
872 const struct comp_unit_head
*);
874 static void read_tag_const_type (struct die_info
*, struct objfile
*,
875 const struct comp_unit_head
*);
877 static void read_tag_volatile_type (struct die_info
*, struct objfile
*,
878 const struct comp_unit_head
*);
880 static void read_tag_string_type (struct die_info
*, struct objfile
*);
882 static void read_subroutine_type (struct die_info
*, struct objfile
*,
883 const struct comp_unit_head
*);
885 static struct die_info
*read_comp_unit (char *, bfd
*,
886 const struct comp_unit_head
*);
888 static void free_die_list (struct die_info
*);
890 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
892 static void process_die (struct die_info
*, struct objfile
*,
893 const struct comp_unit_head
*);
895 static char *dwarf2_linkage_name (struct die_info
*);
897 static char *dwarf_tag_name (unsigned int);
899 static char *dwarf_attr_name (unsigned int);
901 static char *dwarf_form_name (unsigned int);
903 static char *dwarf_stack_op_name (unsigned int);
905 static char *dwarf_bool_name (unsigned int);
907 static char *dwarf_type_encoding_name (unsigned int);
910 static char *dwarf_cfi_name (unsigned int);
912 struct die_info
*copy_die (struct die_info
*);
915 static struct die_info
*sibling_die (struct die_info
*);
917 static void dump_die (struct die_info
*);
919 static void dump_die_list (struct die_info
*);
921 static void store_in_ref_table (unsigned int, struct die_info
*);
923 static void dwarf2_empty_hash_tables (void);
925 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
927 static struct die_info
*follow_die_ref (unsigned int);
929 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
931 /* memory allocation interface */
933 static void dwarf2_free_tmp_obstack (PTR
);
935 static struct dwarf_block
*dwarf_alloc_block (void);
937 static struct abbrev_info
*dwarf_alloc_abbrev (void);
939 static struct die_info
*dwarf_alloc_die (void);
941 static void initialize_cu_func_list (void);
943 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
);
945 static void dwarf_decode_macros (struct line_header
*, unsigned int,
946 char *, bfd
*, const struct comp_unit_head
*,
949 static int attr_form_is_block (struct attribute
*);
951 /* Try to locate the sections we need for DWARF 2 debugging
952 information and return true if we have enough to do something. */
955 dwarf2_has_info (bfd
*abfd
)
957 dwarf_info_offset
= 0;
958 dwarf_abbrev_offset
= 0;
959 dwarf_line_offset
= 0;
960 dwarf_str_offset
= 0;
961 dwarf_macinfo_offset
= 0;
962 dwarf_frame_offset
= 0;
963 dwarf_eh_frame_offset
= 0;
964 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
965 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
975 /* This function is mapped across the sections and remembers the
976 offset and size of each of the debugging sections we are interested
980 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, PTR ignore_ptr
)
982 if (STREQ (sectp
->name
, INFO_SECTION
))
984 dwarf_info_offset
= sectp
->filepos
;
985 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
987 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
989 dwarf_abbrev_offset
= sectp
->filepos
;
990 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
992 else if (STREQ (sectp
->name
, LINE_SECTION
))
994 dwarf_line_offset
= sectp
->filepos
;
995 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
997 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
999 dwarf_pubnames_offset
= sectp
->filepos
;
1000 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
1002 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
1004 dwarf_aranges_offset
= sectp
->filepos
;
1005 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
1007 else if (STREQ (sectp
->name
, LOC_SECTION
))
1009 dwarf_loc_offset
= sectp
->filepos
;
1010 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
1012 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
1014 dwarf_macinfo_offset
= sectp
->filepos
;
1015 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
1017 else if (STREQ (sectp
->name
, STR_SECTION
))
1019 dwarf_str_offset
= sectp
->filepos
;
1020 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
1022 else if (STREQ (sectp
->name
, FRAME_SECTION
))
1024 dwarf_frame_offset
= sectp
->filepos
;
1025 dwarf_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1027 else if (STREQ (sectp
->name
, EH_FRAME_SECTION
))
1029 dwarf_eh_frame_offset
= sectp
->filepos
;
1030 dwarf_eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1034 /* Build a partial symbol table. */
1037 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1040 /* We definitely need the .debug_info and .debug_abbrev sections */
1042 dwarf_info_buffer
= dwarf2_read_section (objfile
,
1045 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
1046 dwarf_abbrev_offset
,
1049 if (dwarf_line_offset
)
1050 dwarf_line_buffer
= dwarf2_read_section (objfile
,
1054 dwarf_line_buffer
= NULL
;
1056 if (dwarf_str_offset
)
1057 dwarf_str_buffer
= dwarf2_read_section (objfile
,
1061 dwarf_str_buffer
= NULL
;
1063 if (dwarf_macinfo_offset
)
1064 dwarf_macinfo_buffer
= dwarf2_read_section (objfile
,
1065 dwarf_macinfo_offset
,
1066 dwarf_macinfo_size
);
1068 dwarf_macinfo_buffer
= NULL
;
1071 || (objfile
->global_psymbols
.size
== 0
1072 && objfile
->static_psymbols
.size
== 0))
1074 init_psymbol_list (objfile
, 1024);
1078 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1080 /* Things are significantly easier if we have .debug_aranges and
1081 .debug_pubnames sections */
1083 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1087 /* only test this case for now */
1089 /* In this case we have to work a bit harder */
1090 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1095 /* Build the partial symbol table from the information in the
1096 .debug_pubnames and .debug_aranges sections. */
1099 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1101 bfd
*abfd
= objfile
->obfd
;
1102 char *aranges_buffer
, *pubnames_buffer
;
1103 char *aranges_ptr
, *pubnames_ptr
;
1104 unsigned int entry_length
, version
, info_offset
, info_size
;
1106 pubnames_buffer
= dwarf2_read_section (objfile
,
1107 dwarf_pubnames_offset
,
1108 dwarf_pubnames_size
);
1109 pubnames_ptr
= pubnames_buffer
;
1110 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
1112 struct comp_unit_head cu_header
;
1115 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1117 pubnames_ptr
+= bytes_read
;
1118 version
= read_1_byte (abfd
, pubnames_ptr
);
1120 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1122 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1126 aranges_buffer
= dwarf2_read_section (objfile
,
1127 dwarf_aranges_offset
,
1128 dwarf_aranges_size
);
1133 /* Read in the comp unit header information from the debug_info at
1137 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1138 char *info_ptr
, bfd
*abfd
)
1142 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1144 info_ptr
+= bytes_read
;
1145 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1147 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1149 info_ptr
+= bytes_read
;
1150 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1152 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1153 if (signed_addr
< 0)
1154 internal_error (__FILE__
, __LINE__
,
1155 "read_comp_unit_head: dwarf from non elf file");
1156 cu_header
->signed_addr_p
= signed_addr
;
1160 /* Build the partial symbol table by doing a quick pass through the
1161 .debug_info and .debug_abbrev sections. */
1164 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1166 /* Instead of reading this into a big buffer, we should probably use
1167 mmap() on architectures that support it. (FIXME) */
1168 bfd
*abfd
= objfile
->obfd
;
1169 char *info_ptr
, *abbrev_ptr
;
1170 char *beg_of_comp_unit
;
1171 struct partial_die_info comp_unit_die
;
1172 struct partial_symtab
*pst
;
1173 struct cleanup
*back_to
;
1174 CORE_ADDR lowpc
, highpc
;
1176 info_ptr
= dwarf_info_buffer
;
1177 abbrev_ptr
= dwarf_abbrev_buffer
;
1179 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1180 the partial symbol scan, like attribute values.
1182 We could reduce our peak memory consumption during partial symbol
1183 table construction by freeing stuff from this obstack more often
1184 --- say, after processing each compilation unit, or each die ---
1185 but it turns out that this saves almost nothing. For an
1186 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1187 on dwarf2_tmp_obstack. Some investigation showed:
1189 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1190 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1191 all fixed-length values not requiring dynamic allocation.
1193 2) 30% of the attributes used the form DW_FORM_string. For
1194 DW_FORM_string, read_attribute simply hands back a pointer to
1195 the null-terminated string in dwarf_info_buffer, so no dynamic
1196 allocation is needed there either.
1198 3) The remaining 1% of the attributes all used DW_FORM_block1.
1199 75% of those were DW_AT_frame_base location lists for
1200 functions; the rest were DW_AT_location attributes, probably
1201 for the global variables.
1203 Anyway, what this all means is that the memory the dwarf2
1204 reader uses as temporary space reading partial symbols is about
1205 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1207 obstack_init (&dwarf2_tmp_obstack
);
1208 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1210 /* Since the objects we're extracting from dwarf_info_buffer vary in
1211 length, only the individual functions to extract them (like
1212 read_comp_unit_head and read_partial_die) can really know whether
1213 the buffer is large enough to hold another complete object.
1215 At the moment, they don't actually check that. If
1216 dwarf_info_buffer holds just one extra byte after the last
1217 compilation unit's dies, then read_comp_unit_head will happily
1218 read off the end of the buffer. read_partial_die is similarly
1219 casual. Those functions should be fixed.
1221 For this loop condition, simply checking whether there's any data
1222 left at all should be sufficient. */
1223 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1225 struct comp_unit_head cu_header
;
1226 beg_of_comp_unit
= info_ptr
;
1227 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1229 if (cu_header
.version
!= 2)
1231 error ("Dwarf Error: wrong version in compilation unit header.");
1234 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
1236 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
1237 (long) cu_header
.abbrev_offset
,
1238 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1241 if (beg_of_comp_unit
+ cu_header
.length
+ cu_header
.initial_length_size
1242 > dwarf_info_buffer
+ dwarf_info_size
)
1244 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
1245 (long) cu_header
.length
,
1246 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1249 /* Complete the cu_header */
1250 cu_header
.offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1251 cu_header
.first_die_ptr
= info_ptr
;
1252 cu_header
.cu_head_ptr
= beg_of_comp_unit
;
1254 /* Read the abbrevs for this compilation unit into a table */
1255 dwarf2_read_abbrevs (abfd
, &cu_header
);
1256 make_cleanup (dwarf2_empty_abbrev_table
, cu_header
.dwarf2_abbrevs
);
1258 /* Read the compilation unit die */
1259 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1262 /* Set the language we're debugging */
1263 set_cu_language (comp_unit_die
.language
);
1265 /* Allocate a new partial symbol table structure */
1266 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1267 comp_unit_die
.name
? comp_unit_die
.name
: "",
1268 comp_unit_die
.lowpc
,
1269 objfile
->global_psymbols
.next
,
1270 objfile
->static_psymbols
.next
);
1272 pst
->read_symtab_private
= (char *)
1273 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1274 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1275 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1276 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1277 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1278 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1279 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1280 DWARF_LINE_SIZE (pst
) = dwarf_line_size
;
1281 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1282 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1283 DWARF_MACINFO_BUFFER (pst
) = dwarf_macinfo_buffer
;
1284 DWARF_MACINFO_SIZE (pst
) = dwarf_macinfo_size
;
1285 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1287 /* Store the function that reads in the rest of the symbol table */
1288 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1290 /* Check if comp unit has_children.
1291 If so, read the rest of the partial symbols from this comp unit.
1292 If not, there's no more debug_info for this comp unit. */
1293 if (comp_unit_die
.has_children
)
1295 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
,
1298 /* If the compilation unit didn't have an explicit address range,
1299 then use the information extracted from its child dies. */
1300 if (! comp_unit_die
.has_pc_info
)
1302 comp_unit_die
.lowpc
= lowpc
;
1303 comp_unit_die
.highpc
= highpc
;
1306 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1307 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1309 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1310 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1311 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1312 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1313 sort_pst_symbols (pst
);
1315 /* If there is already a psymtab or symtab for a file of this
1316 name, remove it. (If there is a symtab, more drastic things
1317 also happen.) This happens in VxWorks. */
1318 free_named_symtabs (pst
->filename
);
1320 info_ptr
= beg_of_comp_unit
+ cu_header
.length
1321 + cu_header
.initial_length_size
;
1323 do_cleanups (back_to
);
1326 /* Read in all interesting dies to the end of the compilation unit. */
1329 scan_partial_symbols (char *info_ptr
, struct objfile
*objfile
,
1330 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1331 const struct comp_unit_head
*cu_header
)
1333 bfd
*abfd
= objfile
->obfd
;
1334 struct partial_die_info pdi
;
1336 /* This function is called after we've read in the comp_unit_die in
1337 order to read its children. We start the nesting level at 1 since
1338 we have pushed 1 level down in order to read the comp unit's children.
1339 The comp unit itself is at level 0, so we stop reading when we pop
1340 back to that level. */
1342 int nesting_level
= 1;
1344 /* We only want to read in symbols corresponding to variables or
1345 other similar objects that are global or static. Normally, these
1346 are all children of the DW_TAG_compile_unit die, so are all at
1347 level 1. But C++ namespaces give ries to DW_TAG_namespace dies
1348 whose children are global objects. So we keep track of what
1349 level we currently think of as referring to file scope; this
1350 should always equal 1 plus the number of namespaces that we are
1351 currently nested within. */
1353 int file_scope_level
= 1;
1355 *lowpc
= ((CORE_ADDR
) -1);
1356 *highpc
= ((CORE_ADDR
) 0);
1358 while (nesting_level
)
1360 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu_header
);
1366 case DW_TAG_subprogram
:
1367 if (pdi
.has_pc_info
)
1369 if (pdi
.lowpc
< *lowpc
)
1373 if (pdi
.highpc
> *highpc
)
1375 *highpc
= pdi
.highpc
;
1377 if ((pdi
.is_external
|| nesting_level
== file_scope_level
)
1378 && !pdi
.is_declaration
)
1380 add_partial_symbol (&pdi
, objfile
, cu_header
);
1384 case DW_TAG_variable
:
1385 case DW_TAG_typedef
:
1386 case DW_TAG_class_type
:
1387 case DW_TAG_structure_type
:
1388 case DW_TAG_union_type
:
1389 case DW_TAG_enumeration_type
:
1390 if ((pdi
.is_external
|| nesting_level
== file_scope_level
)
1391 && !pdi
.is_declaration
)
1393 add_partial_symbol (&pdi
, objfile
, cu_header
);
1396 case DW_TAG_enumerator
:
1397 /* File scope enumerators are added to the partial
1398 symbol table. They're children of the enumeration
1399 type die, so they occur at a level one higher than we
1400 normally look for. */
1401 if (nesting_level
== file_scope_level
+ 1)
1402 add_partial_symbol (&pdi
, objfile
, cu_header
);
1404 case DW_TAG_base_type
:
1405 /* File scope base type definitions are added to the partial
1407 if (nesting_level
== file_scope_level
)
1408 add_partial_symbol (&pdi
, objfile
, cu_header
);
1410 case DW_TAG_namespace
:
1411 /* FIXME: carlton/2002-10-16: we're not yet doing
1412 anything useful with this, but for now make sure that
1413 these tags at least don't cause us to miss any
1414 important symbols. */
1415 if (pdi
.has_children
)
1422 /* If the die has a sibling, skip to the sibling. Do not skip
1423 enumeration types, we want to record their enumerators. Do
1424 not skip namespaces, we want to record symbols inside
1427 && pdi
.tag
!= DW_TAG_enumeration_type
1428 && pdi
.tag
!= DW_TAG_namespace
)
1430 info_ptr
= pdi
.sibling
;
1432 else if (pdi
.has_children
)
1434 /* Die has children, but either the optional DW_AT_sibling
1435 attribute is missing or we want to look at them. */
1442 /* If this is the end of a DW_TAG_namespace entry, then
1443 decrease the file_scope_level, too. */
1444 if (nesting_level
< file_scope_level
)
1447 gdb_assert (nesting_level
== file_scope_level
);
1452 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1453 from `maint check'. */
1454 if (*lowpc
== ((CORE_ADDR
) -1))
1460 add_partial_symbol (struct partial_die_info
*pdi
, struct objfile
*objfile
,
1461 const struct comp_unit_head
*cu_header
)
1467 case DW_TAG_subprogram
:
1468 if (pdi
->is_external
)
1470 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1471 mst_text, objfile); */
1472 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1473 VAR_NAMESPACE
, LOC_BLOCK
,
1474 &objfile
->global_psymbols
,
1475 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1479 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1480 mst_file_text, objfile); */
1481 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1482 VAR_NAMESPACE
, LOC_BLOCK
,
1483 &objfile
->static_psymbols
,
1484 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1487 case DW_TAG_variable
:
1488 if (pdi
->is_external
)
1491 Don't enter into the minimal symbol tables as there is
1492 a minimal symbol table entry from the ELF symbols already.
1493 Enter into partial symbol table if it has a location
1494 descriptor or a type.
1495 If the location descriptor is missing, new_symbol will create
1496 a LOC_UNRESOLVED symbol, the address of the variable will then
1497 be determined from the minimal symbol table whenever the variable
1499 The address for the partial symbol table entry is not
1500 used by GDB, but it comes in handy for debugging partial symbol
1504 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1505 if (pdi
->locdesc
|| pdi
->has_type
)
1506 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1507 VAR_NAMESPACE
, LOC_STATIC
,
1508 &objfile
->global_psymbols
,
1509 0, addr
+ baseaddr
, cu_language
, objfile
);
1513 /* Static Variable. Skip symbols without location descriptors. */
1514 if (pdi
->locdesc
== NULL
)
1516 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1517 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1518 mst_file_data, objfile); */
1519 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1520 VAR_NAMESPACE
, LOC_STATIC
,
1521 &objfile
->static_psymbols
,
1522 0, addr
+ baseaddr
, cu_language
, objfile
);
1525 case DW_TAG_typedef
:
1526 case DW_TAG_base_type
:
1527 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1528 VAR_NAMESPACE
, LOC_TYPEDEF
,
1529 &objfile
->static_psymbols
,
1530 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1532 case DW_TAG_class_type
:
1533 case DW_TAG_structure_type
:
1534 case DW_TAG_union_type
:
1535 case DW_TAG_enumeration_type
:
1536 /* Skip aggregate types without children, these are external
1538 if (pdi
->has_children
== 0)
1540 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1541 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1542 &objfile
->static_psymbols
,
1543 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1545 if (cu_language
== language_cplus
)
1547 /* For C++, these implicitly act as typedefs as well. */
1548 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1549 VAR_NAMESPACE
, LOC_TYPEDEF
,
1550 &objfile
->static_psymbols
,
1551 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1554 case DW_TAG_enumerator
:
1555 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1556 VAR_NAMESPACE
, LOC_CONST
,
1557 &objfile
->static_psymbols
,
1558 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1565 /* Expand this partial symbol table into a full symbol table. */
1568 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1570 /* FIXME: This is barely more than a stub. */
1575 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1581 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1582 gdb_flush (gdb_stdout
);
1585 psymtab_to_symtab_1 (pst
);
1587 /* Finish up the debug error message. */
1589 printf_filtered ("done.\n");
1595 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1597 struct objfile
*objfile
= pst
->objfile
;
1598 bfd
*abfd
= objfile
->obfd
;
1599 struct comp_unit_head cu_header
;
1600 struct die_info
*dies
;
1601 unsigned long offset
;
1602 CORE_ADDR lowpc
, highpc
;
1603 struct die_info
*child_die
;
1605 struct symtab
*symtab
;
1606 struct cleanup
*back_to
;
1608 /* Set local variables from the partial symbol table info. */
1609 offset
= DWARF_INFO_OFFSET (pst
);
1610 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1611 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1612 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1613 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1614 dwarf_line_size
= DWARF_LINE_SIZE (pst
);
1615 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1616 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1617 dwarf_macinfo_buffer
= DWARF_MACINFO_BUFFER (pst
);
1618 dwarf_macinfo_size
= DWARF_MACINFO_SIZE (pst
);
1619 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1620 cu_header_offset
= offset
;
1621 info_ptr
= dwarf_info_buffer
+ offset
;
1623 obstack_init (&dwarf2_tmp_obstack
);
1624 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1627 make_cleanup (really_free_pendings
, NULL
);
1629 /* read in the comp_unit header */
1630 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1632 /* Read the abbrevs for this compilation unit */
1633 dwarf2_read_abbrevs (abfd
, &cu_header
);
1634 make_cleanup (dwarf2_empty_abbrev_table
, cu_header
.dwarf2_abbrevs
);
1636 dies
= read_comp_unit (info_ptr
, abfd
, &cu_header
);
1638 make_cleanup_free_die_list (dies
);
1640 /* Do line number decoding in read_file_scope () */
1641 process_die (dies
, objfile
, &cu_header
);
1643 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1645 /* Some compilers don't define a DW_AT_high_pc attribute for
1646 the compilation unit. If the DW_AT_high_pc is missing,
1647 synthesize it, by scanning the DIE's below the compilation unit. */
1649 if (dies
->has_children
)
1651 child_die
= dies
->next
;
1652 while (child_die
&& child_die
->tag
)
1654 if (child_die
->tag
== DW_TAG_subprogram
)
1656 CORE_ADDR low
, high
;
1658 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1660 highpc
= max (highpc
, high
);
1663 child_die
= sibling_die (child_die
);
1667 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1669 /* Set symtab language to language from DW_AT_language.
1670 If the compilation is from a C file generated by language preprocessors,
1671 do not set the language if it was already deduced by start_subfile. */
1673 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1675 symtab
->language
= cu_language
;
1677 pst
->symtab
= symtab
;
1679 sort_symtab_syms (pst
->symtab
);
1681 do_cleanups (back_to
);
1684 /* Process a die and its children. */
1687 process_die (struct die_info
*die
, struct objfile
*objfile
,
1688 const struct comp_unit_head
*cu_header
)
1692 case DW_TAG_padding
:
1694 case DW_TAG_compile_unit
:
1695 read_file_scope (die
, objfile
, cu_header
);
1697 case DW_TAG_subprogram
:
1698 read_subroutine_type (die
, objfile
, cu_header
);
1699 read_func_scope (die
, objfile
, cu_header
);
1701 case DW_TAG_inlined_subroutine
:
1702 /* FIXME: These are ignored for now.
1703 They could be used to set breakpoints on all inlined instances
1704 of a function and make GDB `next' properly over inlined functions. */
1706 case DW_TAG_lexical_block
:
1707 read_lexical_block_scope (die
, objfile
, cu_header
);
1709 case DW_TAG_class_type
:
1710 case DW_TAG_structure_type
:
1711 case DW_TAG_union_type
:
1712 read_structure_scope (die
, objfile
, cu_header
);
1714 case DW_TAG_enumeration_type
:
1715 read_enumeration (die
, objfile
, cu_header
);
1717 case DW_TAG_subroutine_type
:
1718 read_subroutine_type (die
, objfile
, cu_header
);
1720 case DW_TAG_array_type
:
1721 read_array_type (die
, objfile
, cu_header
);
1723 case DW_TAG_pointer_type
:
1724 read_tag_pointer_type (die
, objfile
, cu_header
);
1726 case DW_TAG_ptr_to_member_type
:
1727 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
1729 case DW_TAG_reference_type
:
1730 read_tag_reference_type (die
, objfile
, cu_header
);
1732 case DW_TAG_string_type
:
1733 read_tag_string_type (die
, objfile
);
1735 case DW_TAG_base_type
:
1736 read_base_type (die
, objfile
);
1737 if (dwarf_attr (die
, DW_AT_name
))
1739 /* Add a typedef symbol for the base type definition. */
1740 new_symbol (die
, die
->type
, objfile
, cu_header
);
1743 case DW_TAG_common_block
:
1744 read_common_block (die
, objfile
, cu_header
);
1746 case DW_TAG_common_inclusion
:
1748 case DW_TAG_namespace
:
1749 read_namespace (die
, objfile
, cu_header
);
1751 case DW_TAG_imported_declaration
:
1752 case DW_TAG_imported_module
:
1753 /* FIXME: carlton/2002-10-16: Eventually, we should use the
1754 information contained in these. DW_TAG_imported_declaration
1755 dies shouldn't have children; DW_TAG_imported_module dies
1756 shouldn't in the C++ case, but conceivably could in the
1757 Fortran case, so we'll have to replace this gdb_assert if
1758 Fortran compilers start generating that info. */
1759 gdb_assert (!die
->has_children
);
1762 new_symbol (die
, NULL
, objfile
, cu_header
);
1768 initialize_cu_func_list (void)
1770 cu_first_fn
= cu_last_fn
= cu_cached_fn
= NULL
;
1774 read_file_scope (struct die_info
*die
, struct objfile
*objfile
,
1775 const struct comp_unit_head
*cu_header
)
1777 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
1778 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1779 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1780 struct attribute
*attr
;
1781 char *name
= "<unknown>";
1782 char *comp_dir
= NULL
;
1783 struct die_info
*child_die
;
1784 bfd
*abfd
= objfile
->obfd
;
1785 struct line_header
*line_header
= 0;
1787 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1789 if (die
->has_children
)
1791 child_die
= die
->next
;
1792 while (child_die
&& child_die
->tag
)
1794 if (child_die
->tag
== DW_TAG_subprogram
)
1796 CORE_ADDR low
, high
;
1798 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1800 lowpc
= min (lowpc
, low
);
1801 highpc
= max (highpc
, high
);
1804 child_die
= sibling_die (child_die
);
1809 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1810 from finish_block. */
1811 if (lowpc
== ((CORE_ADDR
) -1))
1816 attr
= dwarf_attr (die
, DW_AT_name
);
1819 name
= DW_STRING (attr
);
1821 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1824 comp_dir
= DW_STRING (attr
);
1827 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1828 directory, get rid of it. */
1829 char *cp
= strchr (comp_dir
, ':');
1831 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1836 if (objfile
->ei
.entry_point
>= lowpc
&&
1837 objfile
->ei
.entry_point
< highpc
)
1839 objfile
->ei
.entry_file_lowpc
= lowpc
;
1840 objfile
->ei
.entry_file_highpc
= highpc
;
1843 attr
= dwarf_attr (die
, DW_AT_language
);
1846 set_cu_language (DW_UNSND (attr
));
1849 /* We assume that we're processing GCC output. */
1850 processing_gcc_compilation
= 2;
1852 /* FIXME:Do something here. */
1853 if (dip
->at_producer
!= NULL
)
1855 handle_producer (dip
->at_producer
);
1859 /* The compilation unit may be in a different language or objfile,
1860 zero out all remembered fundamental types. */
1861 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1863 start_symtab (name
, comp_dir
, lowpc
);
1864 record_debugformat ("DWARF 2");
1866 initialize_cu_func_list ();
1868 /* Process all dies in compilation unit. */
1869 if (die
->has_children
)
1871 child_die
= die
->next
;
1872 while (child_die
&& child_die
->tag
)
1874 process_die (child_die
, objfile
, cu_header
);
1875 child_die
= sibling_die (child_die
);
1879 /* Decode line number information if present. */
1880 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1883 unsigned int line_offset
= DW_UNSND (attr
);
1884 line_header
= dwarf_decode_line_header (line_offset
,
1888 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
1889 (void *) line_header
);
1890 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu_header
);
1894 /* Decode macro information, if present. Dwarf 2 macro information
1895 refers to information in the line number info statement program
1896 header, so we can only read it if we've read the header
1898 attr
= dwarf_attr (die
, DW_AT_macro_info
);
1899 if (attr
&& line_header
)
1901 unsigned int macro_offset
= DW_UNSND (attr
);
1902 dwarf_decode_macros (line_header
, macro_offset
,
1903 comp_dir
, abfd
, cu_header
, objfile
);
1905 do_cleanups (back_to
);
1909 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
)
1911 struct function_range
*thisfn
;
1913 thisfn
= (struct function_range
*)
1914 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct function_range
));
1915 thisfn
->name
= name
;
1916 thisfn
->lowpc
= lowpc
;
1917 thisfn
->highpc
= highpc
;
1918 thisfn
->seen_line
= 0;
1919 thisfn
->next
= NULL
;
1921 if (cu_last_fn
== NULL
)
1922 cu_first_fn
= thisfn
;
1924 cu_last_fn
->next
= thisfn
;
1926 cu_last_fn
= thisfn
;
1930 read_func_scope (struct die_info
*die
, struct objfile
*objfile
,
1931 const struct comp_unit_head
*cu_header
)
1933 register struct context_stack
*new;
1936 struct die_info
*child_die
;
1937 struct attribute
*attr
;
1940 name
= dwarf2_linkage_name (die
);
1942 /* Ignore functions with missing or empty names and functions with
1943 missing or invalid low and high pc attributes. */
1944 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1950 /* Record the function range for dwarf_decode_lines. */
1951 add_to_cu_func_list (name
, lowpc
, highpc
);
1953 if (objfile
->ei
.entry_point
>= lowpc
&&
1954 objfile
->ei
.entry_point
< highpc
)
1956 objfile
->ei
.entry_func_lowpc
= lowpc
;
1957 objfile
->ei
.entry_func_highpc
= highpc
;
1960 /* Decode DW_AT_frame_base location descriptor if present, keep result
1961 for DW_OP_fbreg operands in decode_locdesc. */
1962 frame_base_reg
= -1;
1963 frame_base_offset
= 0;
1964 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1969 /* Support the .debug_loc offsets */
1970 if (attr_form_is_block (attr
))
1972 addr
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
1974 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
1976 complain (&dwarf2_complex_location_expr
);
1981 complain (&dwarf2_invalid_attrib_class
, "DW_AT_frame_base", name
);
1986 complain (&dwarf2_unsupported_at_frame_base
, name
);
1988 frame_base_reg
= addr
;
1991 frame_base_reg
= basereg
;
1992 frame_base_offset
= addr
;
1995 complain (&dwarf2_unsupported_at_frame_base
, name
);
1998 new = push_context (0, lowpc
);
1999 new->name
= new_symbol (die
, die
->type
, objfile
, cu_header
);
2000 list_in_scope
= &local_symbols
;
2002 if (die
->has_children
)
2004 child_die
= die
->next
;
2005 while (child_die
&& child_die
->tag
)
2007 process_die (child_die
, objfile
, cu_header
);
2008 child_die
= sibling_die (child_die
);
2012 new = pop_context ();
2013 /* Make a block for the local symbols within. */
2014 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2015 lowpc
, highpc
, objfile
);
2016 list_in_scope
= &file_symbols
;
2019 /* Process all the DIES contained within a lexical block scope. Start
2020 a new scope, process the dies, and then close the scope. */
2023 read_lexical_block_scope (struct die_info
*die
, struct objfile
*objfile
,
2024 const struct comp_unit_head
*cu_header
)
2026 register struct context_stack
*new;
2027 CORE_ADDR lowpc
, highpc
;
2028 struct die_info
*child_die
;
2030 /* Ignore blocks with missing or invalid low and high pc attributes. */
2031 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
2036 push_context (0, lowpc
);
2037 if (die
->has_children
)
2039 child_die
= die
->next
;
2040 while (child_die
&& child_die
->tag
)
2042 process_die (child_die
, objfile
, cu_header
);
2043 child_die
= sibling_die (child_die
);
2046 new = pop_context ();
2048 if (local_symbols
!= NULL
)
2050 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
2053 local_symbols
= new->locals
;
2056 /* Get low and high pc attributes from a die.
2057 Return 1 if the attributes are present and valid, otherwise, return 0. */
2060 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2061 struct objfile
*objfile
)
2063 struct attribute
*attr
;
2067 attr
= dwarf_attr (die
, DW_AT_low_pc
);
2069 low
= DW_ADDR (attr
);
2072 attr
= dwarf_attr (die
, DW_AT_high_pc
);
2074 high
= DW_ADDR (attr
);
2081 /* When using the GNU linker, .gnu.linkonce. sections are used to
2082 eliminate duplicate copies of functions and vtables and such.
2083 The linker will arbitrarily choose one and discard the others.
2084 The AT_*_pc values for such functions refer to local labels in
2085 these sections. If the section from that file was discarded, the
2086 labels are not in the output, so the relocs get a value of 0.
2087 If this is a discarded function, mark the pc bounds as invalid,
2088 so that GDB will ignore it. */
2089 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
2097 /* Add an aggregate field to the field list. */
2100 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
2101 struct objfile
*objfile
,
2102 const struct comp_unit_head
*cu_header
)
2104 struct nextfield
*new_field
;
2105 struct attribute
*attr
;
2107 char *fieldname
= "";
2109 /* Allocate a new field list entry and link it in. */
2110 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2111 make_cleanup (xfree
, new_field
);
2112 memset (new_field
, 0, sizeof (struct nextfield
));
2113 new_field
->next
= fip
->fields
;
2114 fip
->fields
= new_field
;
2117 /* Handle accessibility and virtuality of field.
2118 The default accessibility for members is public, the default
2119 accessibility for inheritance is private. */
2120 if (die
->tag
!= DW_TAG_inheritance
)
2121 new_field
->accessibility
= DW_ACCESS_public
;
2123 new_field
->accessibility
= DW_ACCESS_private
;
2124 new_field
->virtuality
= DW_VIRTUALITY_none
;
2126 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2128 new_field
->accessibility
= DW_UNSND (attr
);
2129 if (new_field
->accessibility
!= DW_ACCESS_public
)
2130 fip
->non_public_fields
= 1;
2131 attr
= dwarf_attr (die
, DW_AT_virtuality
);
2133 new_field
->virtuality
= DW_UNSND (attr
);
2135 fp
= &new_field
->field
;
2136 if (die
->tag
== DW_TAG_member
)
2138 /* Get type of field. */
2139 fp
->type
= die_type (die
, objfile
, cu_header
);
2141 /* Get bit size of field (zero if none). */
2142 attr
= dwarf_attr (die
, DW_AT_bit_size
);
2145 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
2149 FIELD_BITSIZE (*fp
) = 0;
2152 /* Get bit offset of field. */
2153 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2156 FIELD_BITPOS (*fp
) =
2157 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) * bits_per_byte
;
2160 FIELD_BITPOS (*fp
) = 0;
2161 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
2164 if (BITS_BIG_ENDIAN
)
2166 /* For big endian bits, the DW_AT_bit_offset gives the
2167 additional bit offset from the MSB of the containing
2168 anonymous object to the MSB of the field. We don't
2169 have to do anything special since we don't need to
2170 know the size of the anonymous object. */
2171 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
2175 /* For little endian bits, compute the bit offset to the
2176 MSB of the anonymous object, subtract off the number of
2177 bits from the MSB of the field to the MSB of the
2178 object, and then subtract off the number of bits of
2179 the field itself. The result is the bit offset of
2180 the LSB of the field. */
2182 int bit_offset
= DW_UNSND (attr
);
2184 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2187 /* The size of the anonymous object containing
2188 the bit field is explicit, so use the
2189 indicated size (in bytes). */
2190 anonymous_size
= DW_UNSND (attr
);
2194 /* The size of the anonymous object containing
2195 the bit field must be inferred from the type
2196 attribute of the data member containing the
2198 anonymous_size
= TYPE_LENGTH (fp
->type
);
2200 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2201 - bit_offset
- FIELD_BITSIZE (*fp
);
2205 /* Get name of field. */
2206 attr
= dwarf_attr (die
, DW_AT_name
);
2207 if (attr
&& DW_STRING (attr
))
2208 fieldname
= DW_STRING (attr
);
2209 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
2210 &objfile
->type_obstack
);
2212 /* Change accessibility for artificial fields (e.g. virtual table
2213 pointer or virtual base class pointer) to private. */
2214 if (dwarf_attr (die
, DW_AT_artificial
))
2216 new_field
->accessibility
= DW_ACCESS_private
;
2217 fip
->non_public_fields
= 1;
2220 else if (die
->tag
== DW_TAG_variable
)
2224 /* C++ static member.
2225 Get name of field. */
2226 attr
= dwarf_attr (die
, DW_AT_name
);
2227 if (attr
&& DW_STRING (attr
))
2228 fieldname
= DW_STRING (attr
);
2232 /* Get physical name. */
2233 physname
= dwarf2_linkage_name (die
);
2235 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
2236 &objfile
->type_obstack
));
2237 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
2238 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
2239 &objfile
->type_obstack
);
2241 else if (die
->tag
== DW_TAG_inheritance
)
2243 /* C++ base class field. */
2244 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2246 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
)
2248 FIELD_BITSIZE (*fp
) = 0;
2249 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
2250 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2251 fip
->nbaseclasses
++;
2255 /* Create the vector of fields, and attach it to the type. */
2258 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
2259 struct objfile
*objfile
)
2261 int nfields
= fip
->nfields
;
2263 /* Record the field count, allocate space for the array of fields,
2264 and create blank accessibility bitfields if necessary. */
2265 TYPE_NFIELDS (type
) = nfields
;
2266 TYPE_FIELDS (type
) = (struct field
*)
2267 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2268 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2270 if (fip
->non_public_fields
)
2272 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2274 TYPE_FIELD_PRIVATE_BITS (type
) =
2275 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2276 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2278 TYPE_FIELD_PROTECTED_BITS (type
) =
2279 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2280 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2282 TYPE_FIELD_IGNORE_BITS (type
) =
2283 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2284 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2287 /* If the type has baseclasses, allocate and clear a bit vector for
2288 TYPE_FIELD_VIRTUAL_BITS. */
2289 if (fip
->nbaseclasses
)
2291 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2294 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2295 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2296 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2297 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2298 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2301 /* Copy the saved-up fields into the field vector. Start from the head
2302 of the list, adding to the tail of the field array, so that they end
2303 up in the same order in the array in which they were added to the list. */
2304 while (nfields
-- > 0)
2306 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2307 switch (fip
->fields
->accessibility
)
2309 case DW_ACCESS_private
:
2310 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2313 case DW_ACCESS_protected
:
2314 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2317 case DW_ACCESS_public
:
2321 /* Unknown accessibility. Complain and treat it as public. */
2323 complain (&dwarf2_unsupported_accessibility
,
2324 fip
->fields
->accessibility
);
2328 if (nfields
< fip
->nbaseclasses
)
2330 switch (fip
->fields
->virtuality
)
2332 case DW_VIRTUALITY_virtual
:
2333 case DW_VIRTUALITY_pure_virtual
:
2334 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2338 fip
->fields
= fip
->fields
->next
;
2342 /* Add a member function to the proper fieldlist. */
2345 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2346 struct type
*type
, struct objfile
*objfile
,
2347 const struct comp_unit_head
*cu_header
)
2349 struct attribute
*attr
;
2350 struct fnfieldlist
*flp
;
2352 struct fn_field
*fnp
;
2355 struct nextfnfield
*new_fnfield
;
2357 /* Get name of member function. */
2358 attr
= dwarf_attr (die
, DW_AT_name
);
2359 if (attr
&& DW_STRING (attr
))
2360 fieldname
= DW_STRING (attr
);
2364 /* Get the mangled name. */
2365 physname
= dwarf2_linkage_name (die
);
2367 /* Look up member function name in fieldlist. */
2368 for (i
= 0; i
< fip
->nfnfields
; i
++)
2370 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2374 /* Create new list element if necessary. */
2375 if (i
< fip
->nfnfields
)
2376 flp
= &fip
->fnfieldlists
[i
];
2379 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2381 fip
->fnfieldlists
= (struct fnfieldlist
*)
2382 xrealloc (fip
->fnfieldlists
,
2383 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2384 * sizeof (struct fnfieldlist
));
2385 if (fip
->nfnfields
== 0)
2386 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2388 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2389 flp
->name
= fieldname
;
2395 /* Create a new member function field and chain it to the field list
2397 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2398 make_cleanup (xfree
, new_fnfield
);
2399 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2400 new_fnfield
->next
= flp
->head
;
2401 flp
->head
= new_fnfield
;
2404 /* Fill in the member function field info. */
2405 fnp
= &new_fnfield
->fnfield
;
2406 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2407 &objfile
->type_obstack
);
2408 fnp
->type
= alloc_type (objfile
);
2409 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2411 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2412 int nparams
= TYPE_NFIELDS (die
->type
);
2414 /* TYPE is the domain of this method, and DIE->TYPE is the type
2415 of the method itself (TYPE_CODE_METHOD). */
2416 smash_to_method_type (fnp
->type
, type
,
2417 TYPE_TARGET_TYPE (die
->type
),
2418 TYPE_FIELDS (die
->type
),
2419 TYPE_NFIELDS (die
->type
),
2420 TYPE_VARARGS (die
->type
));
2422 /* Handle static member functions.
2423 Dwarf2 has no clean way to discern C++ static and non-static
2424 member functions. G++ helps GDB by marking the first
2425 parameter for non-static member functions (which is the
2426 this pointer) as artificial. We obtain this information
2427 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2428 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2429 fnp
->voffset
= VOFFSET_STATIC
;
2432 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2434 /* Get fcontext from DW_AT_containing_type if present. */
2435 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2436 fnp
->fcontext
= die_containing_type (die
, objfile
, cu_header
);
2438 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2439 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2441 /* Get accessibility. */
2442 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2445 switch (DW_UNSND (attr
))
2447 case DW_ACCESS_private
:
2448 fnp
->is_private
= 1;
2450 case DW_ACCESS_protected
:
2451 fnp
->is_protected
= 1;
2456 /* Check for artificial methods. */
2457 attr
= dwarf_attr (die
, DW_AT_artificial
);
2458 if (attr
&& DW_UNSND (attr
) != 0)
2459 fnp
->is_artificial
= 1;
2461 /* Get index in virtual function table if it is a virtual member function. */
2462 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2465 /* Support the .debug_loc offsets */
2466 if (attr_form_is_block (attr
))
2468 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) + 2;
2470 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
2472 complain (&dwarf2_complex_location_expr
);
2476 complain (&dwarf2_invalid_attrib_class
, "DW_AT_vtable_elem_location",
2482 /* Create the vector of member function fields, and attach it to the type. */
2485 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2486 struct objfile
*objfile
)
2488 struct fnfieldlist
*flp
;
2489 int total_length
= 0;
2492 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2493 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2494 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2496 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2498 struct nextfnfield
*nfp
= flp
->head
;
2499 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2502 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2503 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2504 fn_flp
->fn_fields
= (struct fn_field
*)
2505 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2506 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2507 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2509 total_length
+= flp
->length
;
2512 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2513 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2516 /* Called when we find the DIE that starts a structure or union scope
2517 (definition) to process all dies that define the members of the
2520 NOTE: we need to call struct_type regardless of whether or not the
2521 DIE has an at_name attribute, since it might be an anonymous
2522 structure or union. This gets the type entered into our set of
2525 However, if the structure is incomplete (an opaque struct/union)
2526 then suppress creating a symbol table entry for it since gdb only
2527 wants to find the one with the complete definition. Note that if
2528 it is complete, we just call new_symbol, which does it's own
2529 checking about whether the struct/union is anonymous or not (and
2530 suppresses creating a symbol table entry itself). */
2533 read_structure_scope (struct die_info
*die
, struct objfile
*objfile
,
2534 const struct comp_unit_head
*cu_header
)
2537 struct attribute
*attr
;
2539 type
= alloc_type (objfile
);
2541 INIT_CPLUS_SPECIFIC (type
);
2542 attr
= dwarf_attr (die
, DW_AT_name
);
2543 if (attr
&& DW_STRING (attr
))
2545 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2546 strlen (DW_STRING (attr
)),
2547 &objfile
->type_obstack
);
2550 if (die
->tag
== DW_TAG_structure_type
)
2552 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2554 else if (die
->tag
== DW_TAG_union_type
)
2556 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2560 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2562 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2565 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2568 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2572 TYPE_LENGTH (type
) = 0;
2575 /* We need to add the type field to the die immediately so we don't
2576 infinitely recurse when dealing with pointers to the structure
2577 type within the structure itself. */
2580 if (die
->has_children
&& ! die_is_declaration (die
))
2582 struct field_info fi
;
2583 struct die_info
*child_die
;
2584 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2586 memset (&fi
, 0, sizeof (struct field_info
));
2588 child_die
= die
->next
;
2590 while (child_die
&& child_die
->tag
)
2592 if (child_die
->tag
== DW_TAG_member
)
2594 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2596 else if (child_die
->tag
== DW_TAG_variable
)
2598 /* C++ static member. */
2599 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2601 else if (child_die
->tag
== DW_TAG_subprogram
)
2603 /* C++ member function. */
2604 process_die (child_die
, objfile
, cu_header
);
2605 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
, cu_header
);
2607 else if (child_die
->tag
== DW_TAG_inheritance
)
2609 /* C++ base class field. */
2610 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2614 process_die (child_die
, objfile
, cu_header
);
2616 child_die
= sibling_die (child_die
);
2619 /* Attach fields and member functions to the type. */
2621 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2624 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2626 /* Get the type which refers to the base class (possibly this
2627 class itself) which contains the vtable pointer for the current
2628 class from the DW_AT_containing_type attribute. */
2630 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2632 struct type
*t
= die_containing_type (die
, objfile
, cu_header
);
2634 TYPE_VPTR_BASETYPE (type
) = t
;
2637 static const char vptr_name
[] =
2638 {'_', 'v', 'p', 't', 'r', '\0'};
2641 /* Our own class provides vtbl ptr. */
2642 for (i
= TYPE_NFIELDS (t
) - 1;
2643 i
>= TYPE_N_BASECLASSES (t
);
2646 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2648 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2649 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2651 TYPE_VPTR_FIELDNO (type
) = i
;
2656 /* Complain if virtual function table field not found. */
2657 if (i
< TYPE_N_BASECLASSES (t
))
2658 complain (&dwarf2_vtbl_not_found_complaint
,
2659 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2663 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2668 new_symbol (die
, type
, objfile
, cu_header
);
2670 do_cleanups (back_to
);
2674 /* No children, must be stub. */
2675 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2679 /* Given a pointer to a die which begins an enumeration, process all
2680 the dies that define the members of the enumeration.
2682 This will be much nicer in draft 6 of the DWARF spec when our
2683 members will be dies instead squished into the DW_AT_element_list
2686 NOTE: We reverse the order of the element list. */
2689 read_enumeration (struct die_info
*die
, struct objfile
*objfile
,
2690 const struct comp_unit_head
*cu_header
)
2692 struct die_info
*child_die
;
2694 struct field
*fields
;
2695 struct attribute
*attr
;
2698 int unsigned_enum
= 1;
2700 type
= alloc_type (objfile
);
2702 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2703 attr
= dwarf_attr (die
, DW_AT_name
);
2704 if (attr
&& DW_STRING (attr
))
2706 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2707 strlen (DW_STRING (attr
)),
2708 &objfile
->type_obstack
);
2711 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2714 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2718 TYPE_LENGTH (type
) = 0;
2723 if (die
->has_children
)
2725 child_die
= die
->next
;
2726 while (child_die
&& child_die
->tag
)
2728 if (child_die
->tag
!= DW_TAG_enumerator
)
2730 process_die (child_die
, objfile
, cu_header
);
2734 attr
= dwarf_attr (child_die
, DW_AT_name
);
2737 sym
= new_symbol (child_die
, type
, objfile
, cu_header
);
2738 if (SYMBOL_VALUE (sym
) < 0)
2741 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2743 fields
= (struct field
*)
2745 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2746 * sizeof (struct field
));
2749 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2750 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2751 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2752 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2758 child_die
= sibling_die (child_die
);
2763 TYPE_NFIELDS (type
) = num_fields
;
2764 TYPE_FIELDS (type
) = (struct field
*)
2765 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2766 memcpy (TYPE_FIELDS (type
), fields
,
2767 sizeof (struct field
) * num_fields
);
2771 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2774 new_symbol (die
, type
, objfile
, cu_header
);
2777 /* Extract all information from a DW_TAG_array_type DIE and put it in
2778 the DIE's type field. For now, this only handles one dimensional
2782 read_array_type (struct die_info
*die
, struct objfile
*objfile
,
2783 const struct comp_unit_head
*cu_header
)
2785 struct die_info
*child_die
;
2786 struct type
*type
= NULL
;
2787 struct type
*element_type
, *range_type
, *index_type
;
2788 struct type
**range_types
= NULL
;
2789 struct attribute
*attr
;
2791 struct cleanup
*back_to
;
2793 /* Return if we've already decoded this type. */
2799 element_type
= die_type (die
, objfile
, cu_header
);
2801 /* Irix 6.2 native cc creates array types without children for
2802 arrays with unspecified length. */
2803 if (die
->has_children
== 0)
2805 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2806 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2807 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2811 back_to
= make_cleanup (null_cleanup
, NULL
);
2812 child_die
= die
->next
;
2813 while (child_die
&& child_die
->tag
)
2815 if (child_die
->tag
== DW_TAG_subrange_type
)
2817 unsigned int low
, high
;
2819 /* Default bounds to an array with unspecified length. */
2822 if (cu_language
== language_fortran
)
2824 /* FORTRAN implies a lower bound of 1, if not given. */
2828 index_type
= die_type (child_die
, objfile
, cu_header
);
2829 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2832 if (attr
->form
== DW_FORM_sdata
)
2834 low
= DW_SND (attr
);
2836 else if (attr
->form
== DW_FORM_udata
2837 || attr
->form
== DW_FORM_data1
2838 || attr
->form
== DW_FORM_data2
2839 || attr
->form
== DW_FORM_data4
2840 || attr
->form
== DW_FORM_data8
)
2842 low
= DW_UNSND (attr
);
2846 complain (&dwarf2_non_const_array_bound_ignored
,
2847 dwarf_form_name (attr
->form
));
2849 die
->type
= lookup_pointer_type (element_type
);
2856 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2859 if (attr
->form
== DW_FORM_sdata
)
2861 high
= DW_SND (attr
);
2863 else if (attr
->form
== DW_FORM_udata
2864 || attr
->form
== DW_FORM_data1
2865 || attr
->form
== DW_FORM_data2
2866 || attr
->form
== DW_FORM_data4
2867 || attr
->form
== DW_FORM_data8
)
2869 high
= DW_UNSND (attr
);
2871 else if (attr
->form
== DW_FORM_block1
)
2873 /* GCC encodes arrays with unspecified or dynamic length
2874 with a DW_FORM_block1 attribute.
2875 FIXME: GDB does not yet know how to handle dynamic
2876 arrays properly, treat them as arrays with unspecified
2882 complain (&dwarf2_non_const_array_bound_ignored
,
2883 dwarf_form_name (attr
->form
));
2885 die
->type
= lookup_pointer_type (element_type
);
2893 /* Create a range type and save it for array type creation. */
2894 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2896 range_types
= (struct type
**)
2897 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2898 * sizeof (struct type
*));
2900 make_cleanup (free_current_contents
, &range_types
);
2902 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2904 child_die
= sibling_die (child_die
);
2907 /* Dwarf2 dimensions are output from left to right, create the
2908 necessary array types in backwards order. */
2909 type
= element_type
;
2911 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2913 /* Understand Dwarf2 support for vector types (like they occur on
2914 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
2915 array type. This is not part of the Dwarf2/3 standard yet, but a
2916 custom vendor extension. The main difference between a regular
2917 array and the vector variant is that vectors are passed by value
2919 attr
= dwarf_attr (die
, DW_AT_GNU_vector
);
2921 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
2923 do_cleanups (back_to
);
2925 /* Install the type in the die. */
2929 /* First cut: install each common block member as a global variable. */
2932 read_common_block (struct die_info
*die
, struct objfile
*objfile
,
2933 const struct comp_unit_head
*cu_header
)
2935 struct die_info
*child_die
;
2936 struct attribute
*attr
;
2938 CORE_ADDR base
= (CORE_ADDR
) 0;
2940 attr
= dwarf_attr (die
, DW_AT_location
);
2943 /* Support the .debug_loc offsets */
2944 if (attr_form_is_block (attr
))
2946 base
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2948 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
2950 complain (&dwarf2_complex_location_expr
);
2954 complain (&dwarf2_invalid_attrib_class
, "DW_AT_location",
2955 "common block member");
2958 if (die
->has_children
)
2960 child_die
= die
->next
;
2961 while (child_die
&& child_die
->tag
)
2963 sym
= new_symbol (child_die
, NULL
, objfile
, cu_header
);
2964 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2967 SYMBOL_VALUE_ADDRESS (sym
) =
2968 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2969 add_symbol_to_list (sym
, &global_symbols
);
2971 child_die
= sibling_die (child_die
);
2976 /* Read a C++ namespace. */
2978 /* FIXME: carlton/2002-10-16: For now, we don't actually do anything
2979 useful with the namespace data: we just process its children. */
2982 read_namespace (struct die_info
*die
, struct objfile
*objfile
,
2983 const struct comp_unit_head
*cu_header
)
2985 if (die
->has_children
)
2987 struct die_info
*child_die
= die
->next
;
2989 while (child_die
&& child_die
->tag
)
2991 process_die (child_die
, objfile
, cu_header
);
2992 child_die
= sibling_die (child_die
);
2997 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2998 the user defined type vector. */
3001 read_tag_pointer_type (struct die_info
*die
, struct objfile
*objfile
,
3002 const struct comp_unit_head
*cu_header
)
3005 struct attribute
*attr_byte_size
;
3006 struct attribute
*attr_address_class
;
3007 int byte_size
, addr_class
;
3014 type
= lookup_pointer_type (die_type (die
, objfile
, cu_header
));
3016 attr_byte_size
= dwarf_attr (die
, DW_AT_byte_size
);
3018 byte_size
= DW_UNSND (attr_byte_size
);
3020 byte_size
= cu_header
->addr_size
;
3022 attr_address_class
= dwarf_attr (die
, DW_AT_address_class
);
3023 if (attr_address_class
)
3024 addr_class
= DW_UNSND (attr_address_class
);
3026 addr_class
= DW_ADDR_none
;
3028 /* If the pointer size or address class is different than the
3029 default, create a type variant marked as such and set the
3030 length accordingly. */
3031 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
3033 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3037 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
3038 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
3039 type
= make_type_with_address_space (type
, type_flags
);
3041 else if (TYPE_LENGTH (type
) != byte_size
)
3043 complain (&dwarf2_invalid_pointer_size
, byte_size
);
3046 /* Should we also complain about unhandled address classes? */
3050 TYPE_LENGTH (type
) = byte_size
;
3054 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3055 the user defined type vector. */
3058 read_tag_ptr_to_member_type (struct die_info
*die
, struct objfile
*objfile
,
3059 const struct comp_unit_head
*cu_header
)
3062 struct type
*to_type
;
3063 struct type
*domain
;
3070 type
= alloc_type (objfile
);
3071 to_type
= die_type (die
, objfile
, cu_header
);
3072 domain
= die_containing_type (die
, objfile
, cu_header
);
3073 smash_to_member_type (type
, domain
, to_type
);
3078 /* Extract all information from a DW_TAG_reference_type DIE and add to
3079 the user defined type vector. */
3082 read_tag_reference_type (struct die_info
*die
, struct objfile
*objfile
,
3083 const struct comp_unit_head
*cu_header
)
3086 struct attribute
*attr
;
3093 type
= lookup_reference_type (die_type (die
, objfile
, cu_header
));
3094 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3097 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3101 TYPE_LENGTH (type
) = cu_header
->addr_size
;
3107 read_tag_const_type (struct die_info
*die
, struct objfile
*objfile
,
3108 const struct comp_unit_head
*cu_header
)
3110 struct type
*base_type
;
3117 base_type
= die_type (die
, objfile
, cu_header
);
3118 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
3122 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
3123 const struct comp_unit_head
*cu_header
)
3125 struct type
*base_type
;
3132 base_type
= die_type (die
, objfile
, cu_header
);
3133 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
3136 /* Extract all information from a DW_TAG_string_type DIE and add to
3137 the user defined type vector. It isn't really a user defined type,
3138 but it behaves like one, with other DIE's using an AT_user_def_type
3139 attribute to reference it. */
3142 read_tag_string_type (struct die_info
*die
, struct objfile
*objfile
)
3144 struct type
*type
, *range_type
, *index_type
, *char_type
;
3145 struct attribute
*attr
;
3146 unsigned int length
;
3153 attr
= dwarf_attr (die
, DW_AT_string_length
);
3156 length
= DW_UNSND (attr
);
3160 /* check for the DW_AT_byte_size attribute */
3161 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3164 length
= DW_UNSND (attr
);
3171 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
3172 range_type
= create_range_type (NULL
, index_type
, 1, length
);
3173 if (cu_language
== language_fortran
)
3175 /* Need to create a unique string type for bounds
3177 type
= create_string_type (0, range_type
);
3181 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
3182 type
= create_string_type (char_type
, range_type
);
3187 /* Handle DIES due to C code like:
3191 int (*funcp)(int a, long l);
3195 ('funcp' generates a DW_TAG_subroutine_type DIE)
3199 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
3200 const struct comp_unit_head
*cu_header
)
3202 struct type
*type
; /* Type that this function returns */
3203 struct type
*ftype
; /* Function that returns above type */
3204 struct attribute
*attr
;
3206 /* Decode the type that this subroutine returns */
3211 type
= die_type (die
, objfile
, cu_header
);
3212 ftype
= lookup_function_type (type
);
3214 /* All functions in C++ have prototypes. */
3215 attr
= dwarf_attr (die
, DW_AT_prototyped
);
3216 if ((attr
&& (DW_UNSND (attr
) != 0))
3217 || cu_language
== language_cplus
)
3218 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
3220 if (die
->has_children
)
3222 struct die_info
*child_die
;
3226 /* Count the number of parameters.
3227 FIXME: GDB currently ignores vararg functions, but knows about
3228 vararg member functions. */
3229 child_die
= die
->next
;
3230 while (child_die
&& child_die
->tag
)
3232 if (child_die
->tag
== DW_TAG_formal_parameter
)
3234 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
3235 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
3236 child_die
= sibling_die (child_die
);
3239 /* Allocate storage for parameters and fill them in. */
3240 TYPE_NFIELDS (ftype
) = nparams
;
3241 TYPE_FIELDS (ftype
) = (struct field
*)
3242 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
3244 child_die
= die
->next
;
3245 while (child_die
&& child_die
->tag
)
3247 if (child_die
->tag
== DW_TAG_formal_parameter
)
3249 /* Dwarf2 has no clean way to discern C++ static and non-static
3250 member functions. G++ helps GDB by marking the first
3251 parameter for non-static member functions (which is the
3252 this pointer) as artificial. We pass this information
3253 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
3254 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
3256 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
3258 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
3259 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
3263 child_die
= sibling_die (child_die
);
3271 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
3272 const struct comp_unit_head
*cu_header
)
3274 struct attribute
*attr
;
3279 attr
= dwarf_attr (die
, DW_AT_name
);
3280 if (attr
&& DW_STRING (attr
))
3282 name
= DW_STRING (attr
);
3284 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
3285 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, objfile
, cu_header
);
3289 /* Find a representation of a given base type and install
3290 it in the TYPE field of the die. */
3293 read_base_type (struct die_info
*die
, struct objfile
*objfile
)
3296 struct attribute
*attr
;
3297 int encoding
= 0, size
= 0;
3299 /* If we've already decoded this die, this is a no-op. */
3305 attr
= dwarf_attr (die
, DW_AT_encoding
);
3308 encoding
= DW_UNSND (attr
);
3310 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3313 size
= DW_UNSND (attr
);
3315 attr
= dwarf_attr (die
, DW_AT_name
);
3316 if (attr
&& DW_STRING (attr
))
3318 enum type_code code
= TYPE_CODE_INT
;
3323 case DW_ATE_address
:
3324 /* Turn DW_ATE_address into a void * pointer. */
3325 code
= TYPE_CODE_PTR
;
3326 type_flags
|= TYPE_FLAG_UNSIGNED
;
3328 case DW_ATE_boolean
:
3329 code
= TYPE_CODE_BOOL
;
3330 type_flags
|= TYPE_FLAG_UNSIGNED
;
3332 case DW_ATE_complex_float
:
3333 code
= TYPE_CODE_COMPLEX
;
3336 code
= TYPE_CODE_FLT
;
3339 case DW_ATE_signed_char
:
3341 case DW_ATE_unsigned
:
3342 case DW_ATE_unsigned_char
:
3343 type_flags
|= TYPE_FLAG_UNSIGNED
;
3346 complain (&dwarf2_unsupported_at_encoding
,
3347 dwarf_type_encoding_name (encoding
));
3350 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
3351 if (encoding
== DW_ATE_address
)
3352 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
3353 else if (encoding
== DW_ATE_complex_float
)
3356 TYPE_TARGET_TYPE (type
)
3357 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
3358 else if (size
== 16)
3359 TYPE_TARGET_TYPE (type
)
3360 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
3362 TYPE_TARGET_TYPE (type
)
3363 = dwarf2_fundamental_type (objfile
, FT_FLOAT
);
3368 type
= dwarf_base_type (encoding
, size
, objfile
);
3373 /* Read a whole compilation unit into a linked list of dies. */
3375 static struct die_info
*
3376 read_comp_unit (char *info_ptr
, bfd
*abfd
,
3377 const struct comp_unit_head
*cu_header
)
3379 struct die_info
*first_die
, *last_die
, *die
;
3383 /* Reset die reference table; we are
3384 building new ones now. */
3385 dwarf2_empty_hash_tables ();
3389 first_die
= last_die
= NULL
;
3392 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
, cu_header
);
3393 if (die
->has_children
)
3404 /* Enter die in reference hash table */
3405 store_in_ref_table (die
->offset
, die
);
3409 first_die
= last_die
= die
;
3413 last_die
->next
= die
;
3417 while (nesting_level
> 0);
3421 /* Free a linked list of dies. */
3424 free_die_list (struct die_info
*dies
)
3426 struct die_info
*die
, *next
;
3439 do_free_die_list_cleanup (void *dies
)
3441 free_die_list (dies
);
3444 static struct cleanup
*
3445 make_cleanup_free_die_list (struct die_info
*dies
)
3447 return make_cleanup (do_free_die_list_cleanup
, dies
);
3451 /* Read the contents of the section at OFFSET and of size SIZE from the
3452 object file specified by OBJFILE into the psymbol_obstack and return it. */
3455 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
3458 bfd
*abfd
= objfile
->obfd
;
3464 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3465 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
3466 (bfd_bread (buf
, size
, abfd
) != size
))
3469 error ("Dwarf Error: Can't read DWARF data from '%s'",
3470 bfd_get_filename (abfd
));
3475 /* In DWARF version 2, the description of the debugging information is
3476 stored in a separate .debug_abbrev section. Before we read any
3477 dies from a section we read in all abbreviations and install them
3481 dwarf2_read_abbrevs (bfd
*abfd
, struct comp_unit_head
*cu_header
)
3484 struct abbrev_info
*cur_abbrev
;
3485 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3486 unsigned int abbrev_form
, hash_number
;
3488 /* Initialize dwarf2 abbrevs */
3489 memset (cu_header
->dwarf2_abbrevs
, 0,
3490 ABBREV_HASH_SIZE
*sizeof (struct abbrev_info
*));
3492 abbrev_ptr
= dwarf_abbrev_buffer
+ cu_header
->abbrev_offset
;
3493 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3494 abbrev_ptr
+= bytes_read
;
3496 /* loop until we reach an abbrev number of 0 */
3497 while (abbrev_number
)
3499 cur_abbrev
= dwarf_alloc_abbrev ();
3501 /* read in abbrev header */
3502 cur_abbrev
->number
= abbrev_number
;
3503 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3504 abbrev_ptr
+= bytes_read
;
3505 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3508 /* now read in declarations */
3509 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3510 abbrev_ptr
+= bytes_read
;
3511 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3512 abbrev_ptr
+= bytes_read
;
3515 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3517 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3518 xrealloc (cur_abbrev
->attrs
,
3519 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3520 * sizeof (struct attr_abbrev
));
3522 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3523 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3524 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3525 abbrev_ptr
+= bytes_read
;
3526 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3527 abbrev_ptr
+= bytes_read
;
3530 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3531 cur_abbrev
->next
= cu_header
->dwarf2_abbrevs
[hash_number
];
3532 cu_header
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3534 /* Get next abbreviation.
3535 Under Irix6 the abbreviations for a compilation unit are not
3536 always properly terminated with an abbrev number of 0.
3537 Exit loop if we encounter an abbreviation which we have
3538 already read (which means we are about to read the abbreviations
3539 for the next compile unit) or if the end of the abbreviation
3540 table is reached. */
3541 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3542 >= dwarf_abbrev_size
)
3544 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3545 abbrev_ptr
+= bytes_read
;
3546 if (dwarf2_lookup_abbrev (abbrev_number
, cu_header
) != NULL
)
3551 /* Empty the abbrev table for a new compilation unit. */
3555 dwarf2_empty_abbrev_table (PTR ptr_to_abbrevs_table
)
3558 struct abbrev_info
*abbrev
, *next
;
3559 struct abbrev_info
**abbrevs
;
3561 abbrevs
= (struct abbrev_info
**)ptr_to_abbrevs_table
;
3563 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3566 abbrev
= abbrevs
[i
];
3569 next
= abbrev
->next
;
3570 xfree (abbrev
->attrs
);
3578 /* Lookup an abbrev_info structure in the abbrev hash table. */
3580 static struct abbrev_info
*
3581 dwarf2_lookup_abbrev (unsigned int number
, const struct comp_unit_head
*cu_header
)
3583 unsigned int hash_number
;
3584 struct abbrev_info
*abbrev
;
3586 hash_number
= number
% ABBREV_HASH_SIZE
;
3587 abbrev
= cu_header
->dwarf2_abbrevs
[hash_number
];
3591 if (abbrev
->number
== number
)
3594 abbrev
= abbrev
->next
;
3599 /* Read a minimal amount of information into the minimal die structure. */
3602 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3603 char *info_ptr
, const struct comp_unit_head
*cu_header
)
3605 unsigned int abbrev_number
, bytes_read
, i
;
3606 struct abbrev_info
*abbrev
;
3607 struct attribute attr
;
3608 struct attribute spec_attr
;
3609 int found_spec_attr
= 0;
3610 int has_low_pc_attr
= 0;
3611 int has_high_pc_attr
= 0;
3613 *part_die
= zeroed_partial_die
;
3614 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3615 info_ptr
+= bytes_read
;
3619 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu_header
);
3622 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3624 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3625 part_die
->tag
= abbrev
->tag
;
3626 part_die
->has_children
= abbrev
->has_children
;
3627 part_die
->abbrev
= abbrev_number
;
3629 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3631 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
3632 info_ptr
, cu_header
);
3634 /* Store the data if it is of an attribute we want to keep in a
3635 partial symbol table. */
3640 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3641 if (part_die
->name
== NULL
)
3642 part_die
->name
= DW_STRING (&attr
);
3644 case DW_AT_MIPS_linkage_name
:
3645 part_die
->name
= DW_STRING (&attr
);
3648 has_low_pc_attr
= 1;
3649 part_die
->lowpc
= DW_ADDR (&attr
);
3652 has_high_pc_attr
= 1;
3653 part_die
->highpc
= DW_ADDR (&attr
);
3655 case DW_AT_location
:
3656 /* Support the .debug_loc offsets */
3657 if (attr_form_is_block (&attr
))
3659 part_die
->locdesc
= DW_BLOCK (&attr
);
3661 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
3663 complain (&dwarf2_complex_location_expr
);
3667 complain (&dwarf2_invalid_attrib_class
, "DW_AT_location",
3668 "partial symbol information");
3671 case DW_AT_language
:
3672 part_die
->language
= DW_UNSND (&attr
);
3674 case DW_AT_external
:
3675 part_die
->is_external
= DW_UNSND (&attr
);
3677 case DW_AT_declaration
:
3678 part_die
->is_declaration
= DW_UNSND (&attr
);
3681 part_die
->has_type
= 1;
3683 case DW_AT_abstract_origin
:
3684 case DW_AT_specification
:
3685 found_spec_attr
= 1;
3689 /* Ignore absolute siblings, they might point outside of
3690 the current compile unit. */
3691 if (attr
.form
== DW_FORM_ref_addr
)
3692 complain (&dwarf2_absolute_sibling_complaint
);
3695 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3702 /* If we found a reference attribute and the die has no name, try
3703 to find a name in the referred to die. */
3705 if (found_spec_attr
&& part_die
->name
== NULL
)
3707 struct partial_die_info spec_die
;
3711 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3712 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu_header
);
3715 part_die
->name
= spec_die
.name
;
3717 /* Copy DW_AT_external attribute if it is set. */
3718 if (spec_die
.is_external
)
3719 part_die
->is_external
= spec_die
.is_external
;
3723 /* When using the GNU linker, .gnu.linkonce. sections are used to
3724 eliminate duplicate copies of functions and vtables and such.
3725 The linker will arbitrarily choose one and discard the others.
3726 The AT_*_pc values for such functions refer to local labels in
3727 these sections. If the section from that file was discarded, the
3728 labels are not in the output, so the relocs get a value of 0.
3729 If this is a discarded function, mark the pc bounds as invalid,
3730 so that GDB will ignore it. */
3731 if (has_low_pc_attr
&& has_high_pc_attr
3732 && part_die
->lowpc
< part_die
->highpc
3733 && (part_die
->lowpc
!= 0
3734 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3735 part_die
->has_pc_info
= 1;
3739 /* Read the die from the .debug_info section buffer. And set diep to
3740 point to a newly allocated die with its information. */
3743 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
3744 const struct comp_unit_head
*cu_header
)
3746 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3747 struct abbrev_info
*abbrev
;
3748 struct die_info
*die
;
3750 offset
= info_ptr
- dwarf_info_buffer
;
3751 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3752 info_ptr
+= bytes_read
;
3755 die
= dwarf_alloc_die ();
3757 die
->abbrev
= abbrev_number
;
3763 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu_header
);
3766 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3768 die
= dwarf_alloc_die ();
3769 die
->offset
= offset
;
3770 die
->tag
= abbrev
->tag
;
3771 die
->has_children
= abbrev
->has_children
;
3772 die
->abbrev
= abbrev_number
;
3775 die
->num_attrs
= abbrev
->num_attrs
;
3776 die
->attrs
= (struct attribute
*)
3777 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3779 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3781 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3782 abfd
, info_ptr
, cu_header
);
3789 /* Read an attribute value described by an attribute form. */
3792 read_attribute_value (struct attribute
*attr
, unsigned form
,
3793 bfd
*abfd
, char *info_ptr
,
3794 const struct comp_unit_head
*cu_header
)
3796 unsigned int bytes_read
;
3797 struct dwarf_block
*blk
;
3803 case DW_FORM_ref_addr
:
3804 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
3805 info_ptr
+= bytes_read
;
3807 case DW_FORM_block2
:
3808 blk
= dwarf_alloc_block ();
3809 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3811 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3812 info_ptr
+= blk
->size
;
3813 DW_BLOCK (attr
) = blk
;
3815 case DW_FORM_block4
:
3816 blk
= dwarf_alloc_block ();
3817 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3819 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3820 info_ptr
+= blk
->size
;
3821 DW_BLOCK (attr
) = blk
;
3824 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3828 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3832 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3835 case DW_FORM_string
:
3836 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3837 info_ptr
+= bytes_read
;
3840 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
3842 info_ptr
+= bytes_read
;
3845 blk
= dwarf_alloc_block ();
3846 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3847 info_ptr
+= bytes_read
;
3848 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3849 info_ptr
+= blk
->size
;
3850 DW_BLOCK (attr
) = blk
;
3852 case DW_FORM_block1
:
3853 blk
= dwarf_alloc_block ();
3854 blk
->size
= read_1_byte (abfd
, info_ptr
);
3856 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3857 info_ptr
+= blk
->size
;
3858 DW_BLOCK (attr
) = blk
;
3861 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3865 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3869 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3870 info_ptr
+= bytes_read
;
3873 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3874 info_ptr
+= bytes_read
;
3877 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3881 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3885 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3889 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3892 case DW_FORM_ref_udata
:
3893 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3894 info_ptr
+= bytes_read
;
3896 case DW_FORM_indirect
:
3897 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3898 info_ptr
+= bytes_read
;
3899 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu_header
);
3902 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3903 dwarf_form_name (form
));
3908 /* Read an attribute described by an abbreviated attribute. */
3911 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
3912 bfd
*abfd
, char *info_ptr
,
3913 const struct comp_unit_head
*cu_header
)
3915 attr
->name
= abbrev
->name
;
3916 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu_header
);
3919 /* read dwarf information from a buffer */
3922 read_1_byte (bfd
*abfd
, char *buf
)
3924 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3928 read_1_signed_byte (bfd
*abfd
, char *buf
)
3930 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3934 read_2_bytes (bfd
*abfd
, char *buf
)
3936 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3940 read_2_signed_bytes (bfd
*abfd
, char *buf
)
3942 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3946 read_4_bytes (bfd
*abfd
, char *buf
)
3948 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3952 read_4_signed_bytes (bfd
*abfd
, char *buf
)
3954 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3957 static unsigned long
3958 read_8_bytes (bfd
*abfd
, char *buf
)
3960 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3964 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3967 CORE_ADDR retval
= 0;
3969 if (cu_header
->signed_addr_p
)
3971 switch (cu_header
->addr_size
)
3974 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3977 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3980 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
3983 internal_error (__FILE__
, __LINE__
,
3984 "read_address: bad switch, signed");
3989 switch (cu_header
->addr_size
)
3992 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3995 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3998 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4001 internal_error (__FILE__
, __LINE__
,
4002 "read_address: bad switch, unsigned");
4006 *bytes_read
= cu_header
->addr_size
;
4010 /* Read the initial length from a section. The (draft) DWARF 3
4011 specification allows the initial length to take up either 4 bytes
4012 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
4013 bytes describe the length and all offsets will be 8 bytes in length
4016 An older, non-standard 64-bit format is also handled by this
4017 function. The older format in question stores the initial length
4018 as an 8-byte quantity without an escape value. Lengths greater
4019 than 2^32 aren't very common which means that the initial 4 bytes
4020 is almost always zero. Since a length value of zero doesn't make
4021 sense for the 32-bit format, this initial zero can be considered to
4022 be an escape value which indicates the presence of the older 64-bit
4023 format. As written, the code can't detect (old format) lengths
4024 greater than 4GB. If it becomes necessary to handle lengths somewhat
4025 larger than 4GB, we could allow other small values (such as the
4026 non-sensical values of 1, 2, and 3) to also be used as escape values
4027 indicating the presence of the old format.
4029 The value returned via bytes_read should be used to increment
4030 the relevant pointer after calling read_initial_length().
4032 As a side effect, this function sets the fields initial_length_size
4033 and offset_size in cu_header to the values appropriate for the
4034 length field. (The format of the initial length field determines
4035 the width of file offsets to be fetched later with fetch_offset().)
4037 [ Note: read_initial_length() and read_offset() are based on the
4038 document entitled "DWARF Debugging Information Format", revision
4039 3, draft 8, dated November 19, 2001. This document was obtained
4042 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
4044 This document is only a draft and is subject to change. (So beware.)
4046 Details regarding the older, non-standard 64-bit format were
4047 determined empirically by examining 64-bit ELF files produced
4048 by the SGI toolchain on an IRIX 6.5 machine.
4050 - Kevin, July 16, 2002
4054 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
4059 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4061 if (retval
== 0xffffffff)
4063 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
4065 if (cu_header
!= NULL
)
4067 cu_header
->initial_length_size
= 12;
4068 cu_header
->offset_size
= 8;
4071 else if (retval
== 0)
4073 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
4075 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4077 if (cu_header
!= NULL
)
4079 cu_header
->initial_length_size
= 8;
4080 cu_header
->offset_size
= 8;
4086 if (cu_header
!= NULL
)
4088 cu_header
->initial_length_size
= 4;
4089 cu_header
->offset_size
= 4;
4096 /* Read an offset from the data stream. The size of the offset is
4097 given by cu_header->offset_size. */
4100 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
4105 switch (cu_header
->offset_size
)
4108 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4112 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4116 internal_error (__FILE__
, __LINE__
,
4117 "read_offset: bad switch");
4124 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
4126 /* If the size of a host char is 8 bits, we can return a pointer
4127 to the buffer, otherwise we have to copy the data to a buffer
4128 allocated on the temporary obstack. */
4129 gdb_assert (HOST_CHAR_BIT
== 8);
4134 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4136 /* If the size of a host char is 8 bits, we can return a pointer
4137 to the string, otherwise we have to copy the string to a buffer
4138 allocated on the temporary obstack. */
4139 gdb_assert (HOST_CHAR_BIT
== 8);
4142 *bytes_read_ptr
= 1;
4145 *bytes_read_ptr
= strlen (buf
) + 1;
4150 read_indirect_string (bfd
*abfd
, char *buf
,
4151 const struct comp_unit_head
*cu_header
,
4152 unsigned int *bytes_read_ptr
)
4154 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
4155 (int *) bytes_read_ptr
);
4157 if (dwarf_str_buffer
== NULL
)
4159 error ("DW_FORM_strp used without .debug_str section");
4162 if (str_offset
>= dwarf_str_size
)
4164 error ("DW_FORM_strp pointing outside of .debug_str section");
4167 gdb_assert (HOST_CHAR_BIT
== 8);
4168 if (dwarf_str_buffer
[str_offset
] == '\0')
4170 return dwarf_str_buffer
+ str_offset
;
4173 static unsigned long
4174 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4176 unsigned long result
;
4177 unsigned int num_read
;
4187 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4190 result
|= ((unsigned long)(byte
& 127) << shift
);
4191 if ((byte
& 128) == 0)
4197 *bytes_read_ptr
= num_read
;
4202 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4205 int i
, shift
, size
, num_read
;
4215 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4218 result
|= ((long)(byte
& 127) << shift
);
4220 if ((byte
& 128) == 0)
4225 if ((shift
< size
) && (byte
& 0x40))
4227 result
|= -(1 << shift
);
4229 *bytes_read_ptr
= num_read
;
4234 set_cu_language (unsigned int lang
)
4240 cu_language
= language_c
;
4242 case DW_LANG_C_plus_plus
:
4243 cu_language
= language_cplus
;
4245 case DW_LANG_Fortran77
:
4246 case DW_LANG_Fortran90
:
4247 case DW_LANG_Fortran95
:
4248 cu_language
= language_fortran
;
4250 case DW_LANG_Mips_Assembler
:
4251 cu_language
= language_asm
;
4254 cu_language
= language_java
;
4258 case DW_LANG_Cobol74
:
4259 case DW_LANG_Cobol85
:
4260 case DW_LANG_Pascal83
:
4261 case DW_LANG_Modula2
:
4263 cu_language
= language_unknown
;
4266 cu_language_defn
= language_def (cu_language
);
4269 /* Return the named attribute or NULL if not there. */
4271 static struct attribute
*
4272 dwarf_attr (struct die_info
*die
, unsigned int name
)
4275 struct attribute
*spec
= NULL
;
4277 for (i
= 0; i
< die
->num_attrs
; ++i
)
4279 if (die
->attrs
[i
].name
== name
)
4281 return &die
->attrs
[i
];
4283 if (die
->attrs
[i
].name
== DW_AT_specification
4284 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
4285 spec
= &die
->attrs
[i
];
4289 struct die_info
*ref_die
=
4290 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
4293 return dwarf_attr (ref_die
, name
);
4300 die_is_declaration (struct die_info
*die
)
4302 return (dwarf_attr (die
, DW_AT_declaration
)
4303 && ! dwarf_attr (die
, DW_AT_specification
));
4307 /* Free the line_header structure *LH, and any arrays and strings it
4310 free_line_header (struct line_header
*lh
)
4312 if (lh
->standard_opcode_lengths
)
4313 xfree (lh
->standard_opcode_lengths
);
4315 /* Remember that all the lh->file_names[i].name pointers are
4316 pointers into debug_line_buffer, and don't need to be freed. */
4318 xfree (lh
->file_names
);
4320 /* Similarly for the include directory names. */
4321 if (lh
->include_dirs
)
4322 xfree (lh
->include_dirs
);
4328 /* Add an entry to LH's include directory table. */
4330 add_include_dir (struct line_header
*lh
, char *include_dir
)
4332 /* Grow the array if necessary. */
4333 if (lh
->include_dirs_size
== 0)
4335 lh
->include_dirs_size
= 1; /* for testing */
4336 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
4337 * sizeof (*lh
->include_dirs
));
4339 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
4341 lh
->include_dirs_size
*= 2;
4342 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
4343 (lh
->include_dirs_size
4344 * sizeof (*lh
->include_dirs
)));
4347 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
4351 /* Add an entry to LH's file name table. */
4353 add_file_name (struct line_header
*lh
,
4355 unsigned int dir_index
,
4356 unsigned int mod_time
,
4357 unsigned int length
)
4359 struct file_entry
*fe
;
4361 /* Grow the array if necessary. */
4362 if (lh
->file_names_size
== 0)
4364 lh
->file_names_size
= 1; /* for testing */
4365 lh
->file_names
= xmalloc (lh
->file_names_size
4366 * sizeof (*lh
->file_names
));
4368 else if (lh
->num_file_names
>= lh
->file_names_size
)
4370 lh
->file_names_size
*= 2;
4371 lh
->file_names
= xrealloc (lh
->file_names
,
4372 (lh
->file_names_size
4373 * sizeof (*lh
->file_names
)));
4376 fe
= &lh
->file_names
[lh
->num_file_names
++];
4378 fe
->dir_index
= dir_index
;
4379 fe
->mod_time
= mod_time
;
4380 fe
->length
= length
;
4384 /* Read the statement program header starting at OFFSET in
4385 dwarf_line_buffer, according to the endianness of ABFD. Return a
4386 pointer to a struct line_header, allocated using xmalloc.
4388 NOTE: the strings in the include directory and file name tables of
4389 the returned object point into debug_line_buffer, and must not be
4391 static struct line_header
*
4392 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
4393 const struct comp_unit_head
*cu_header
)
4395 struct cleanup
*back_to
;
4396 struct line_header
*lh
;
4400 char *cur_dir
, *cur_file
;
4402 if (dwarf_line_buffer
== NULL
)
4404 complain (&dwarf2_missing_line_number_section
);
4408 /* Make sure that at least there's room for the total_length field. That
4409 could be 12 bytes long, but we're just going to fudge that. */
4410 if (offset
+ 4 >= dwarf_line_size
)
4412 complain (&dwarf2_statement_list_fits_in_line_number_section
);
4416 lh
= xmalloc (sizeof (*lh
));
4417 memset (lh
, 0, sizeof (*lh
));
4418 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
4421 line_ptr
= dwarf_line_buffer
+ offset
;
4423 /* read in the header */
4424 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
4425 line_ptr
+= bytes_read
;
4426 if (line_ptr
+ lh
->total_length
> dwarf_line_buffer
+ dwarf_line_size
)
4428 complain (&dwarf2_statement_list_fits_in_line_number_section
);
4431 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
4432 lh
->version
= read_2_bytes (abfd
, line_ptr
);
4434 lh
->header_length
= read_offset (abfd
, line_ptr
, cu_header
, &bytes_read
);
4435 line_ptr
+= bytes_read
;
4436 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
4438 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
4440 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
4442 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
4444 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
4446 lh
->standard_opcode_lengths
4447 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
4449 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
4450 for (i
= 1; i
< lh
->opcode_base
; ++i
)
4452 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
4456 /* Read directory table */
4457 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4459 line_ptr
+= bytes_read
;
4460 add_include_dir (lh
, cur_dir
);
4462 line_ptr
+= bytes_read
;
4464 /* Read file name table */
4465 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4467 unsigned int dir_index
, mod_time
, length
;
4469 line_ptr
+= bytes_read
;
4470 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4471 line_ptr
+= bytes_read
;
4472 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4473 line_ptr
+= bytes_read
;
4474 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4475 line_ptr
+= bytes_read
;
4477 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4479 line_ptr
+= bytes_read
;
4480 lh
->statement_program_start
= line_ptr
;
4482 if (line_ptr
> dwarf_line_buffer
+ dwarf_line_size
)
4483 complain (&dwarf2_line_header_too_long
);
4485 discard_cleanups (back_to
);
4489 /* This function exists to work around a bug in certain compilers
4490 (particularly GCC 2.95), in which the first line number marker of a
4491 function does not show up until after the prologue, right before
4492 the second line number marker. This function shifts ADDRESS down
4493 to the beginning of the function if necessary, and is called on
4494 addresses passed to record_line. */
4497 check_cu_functions (CORE_ADDR address
)
4499 struct function_range
*fn
;
4501 /* Find the function_range containing address. */
4506 cu_cached_fn
= cu_first_fn
;
4510 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4516 while (fn
&& fn
!= cu_cached_fn
)
4517 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4527 if (address
!= fn
->lowpc
)
4528 complain (&dwarf2_misplaced_line_number
,
4529 (unsigned long) address
, fn
->name
);
4534 /* Decode the line number information for the compilation unit whose
4535 line number info is at OFFSET in the .debug_line section.
4536 The compilation directory of the file is passed in COMP_DIR. */
4539 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
4540 const struct comp_unit_head
*cu_header
)
4544 unsigned int i
, bytes_read
;
4546 unsigned char op_code
, extended_op
, adj_opcode
;
4548 line_ptr
= lh
->statement_program_start
;
4549 line_end
= lh
->statement_program_end
;
4551 /* Read the statement sequences until there's nothing left. */
4552 while (line_ptr
< line_end
)
4554 /* state machine registers */
4555 CORE_ADDR address
= 0;
4556 unsigned int file
= 1;
4557 unsigned int line
= 1;
4558 unsigned int column
= 0;
4559 int is_stmt
= lh
->default_is_stmt
;
4560 int basic_block
= 0;
4561 int end_sequence
= 0;
4563 /* Start a subfile for the current file of the state machine. */
4564 if (lh
->num_file_names
>= file
)
4566 /* lh->include_dirs and lh->file_names are 0-based, but the
4567 directory and file name numbers in the statement program
4569 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
4572 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
4575 dwarf2_start_subfile (fe
->name
, dir
);
4578 /* Decode the table. */
4579 while (!end_sequence
)
4581 op_code
= read_1_byte (abfd
, line_ptr
);
4584 if (op_code
>= lh
->opcode_base
)
4585 { /* Special operand. */
4586 adj_opcode
= op_code
- lh
->opcode_base
;
4587 address
+= (adj_opcode
/ lh
->line_range
)
4588 * lh
->minimum_instruction_length
;
4589 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
4590 /* append row to matrix using current values */
4591 address
= check_cu_functions (address
);
4592 record_line (current_subfile
, line
, address
);
4595 else switch (op_code
)
4597 case DW_LNS_extended_op
:
4598 line_ptr
+= 1; /* ignore length */
4599 extended_op
= read_1_byte (abfd
, line_ptr
);
4601 switch (extended_op
)
4603 case DW_LNE_end_sequence
:
4605 record_line (current_subfile
, 0, address
);
4607 case DW_LNE_set_address
:
4608 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
4609 line_ptr
+= bytes_read
;
4610 address
+= baseaddr
;
4612 case DW_LNE_define_file
:
4615 unsigned int dir_index
, mod_time
, length
;
4617 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
4618 line_ptr
+= bytes_read
;
4620 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4621 line_ptr
+= bytes_read
;
4623 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4624 line_ptr
+= bytes_read
;
4626 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4627 line_ptr
+= bytes_read
;
4628 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4632 complain (&dwarf2_mangled_line_number_section
);
4637 address
= check_cu_functions (address
);
4638 record_line (current_subfile
, line
, address
);
4641 case DW_LNS_advance_pc
:
4642 address
+= lh
->minimum_instruction_length
4643 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4644 line_ptr
+= bytes_read
;
4646 case DW_LNS_advance_line
:
4647 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
4648 line_ptr
+= bytes_read
;
4650 case DW_LNS_set_file
:
4652 /* lh->include_dirs and lh->file_names are 0-based,
4653 but the directory and file name numbers in the
4654 statement program are 1-based. */
4655 struct file_entry
*fe
;
4657 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4658 line_ptr
+= bytes_read
;
4659 fe
= &lh
->file_names
[file
- 1];
4661 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
4664 dwarf2_start_subfile (fe
->name
, dir
);
4667 case DW_LNS_set_column
:
4668 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4669 line_ptr
+= bytes_read
;
4671 case DW_LNS_negate_stmt
:
4672 is_stmt
= (!is_stmt
);
4674 case DW_LNS_set_basic_block
:
4677 /* Add to the address register of the state machine the
4678 address increment value corresponding to special opcode
4679 255. Ie, this value is scaled by the minimum instruction
4680 length since special opcode 255 would have scaled the
4682 case DW_LNS_const_add_pc
:
4683 address
+= (lh
->minimum_instruction_length
4684 * ((255 - lh
->opcode_base
) / lh
->line_range
));
4686 case DW_LNS_fixed_advance_pc
:
4687 address
+= read_2_bytes (abfd
, line_ptr
);
4691 { /* Unknown standard opcode, ignore it. */
4693 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
4695 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4696 line_ptr
+= bytes_read
;
4704 /* Start a subfile for DWARF. FILENAME is the name of the file and
4705 DIRNAME the name of the source directory which contains FILENAME
4706 or NULL if not known.
4707 This routine tries to keep line numbers from identical absolute and
4708 relative file names in a common subfile.
4710 Using the `list' example from the GDB testsuite, which resides in
4711 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4712 of /srcdir/list0.c yields the following debugging information for list0.c:
4714 DW_AT_name: /srcdir/list0.c
4715 DW_AT_comp_dir: /compdir
4716 files.files[0].name: list0.h
4717 files.files[0].dir: /srcdir
4718 files.files[1].name: list0.c
4719 files.files[1].dir: /srcdir
4721 The line number information for list0.c has to end up in a single
4722 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4725 dwarf2_start_subfile (char *filename
, char *dirname
)
4727 /* If the filename isn't absolute, try to match an existing subfile
4728 with the full pathname. */
4730 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
4732 struct subfile
*subfile
;
4733 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4735 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4737 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
4739 current_subfile
= subfile
;
4746 start_subfile (filename
, dirname
);
4749 /* Given a pointer to a DWARF information entry, figure out if we need
4750 to make a symbol table entry for it, and if so, create a new entry
4751 and return a pointer to it.
4752 If TYPE is NULL, determine symbol type from the die, otherwise
4753 used the passed type. */
4755 static struct symbol
*
4756 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
4757 const struct comp_unit_head
*cu_header
)
4759 struct symbol
*sym
= NULL
;
4761 struct attribute
*attr
= NULL
;
4762 struct attribute
*attr2
= NULL
;
4765 name
= dwarf2_linkage_name (die
);
4768 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4769 sizeof (struct symbol
));
4770 OBJSTAT (objfile
, n_syms
++);
4771 memset (sym
, 0, sizeof (struct symbol
));
4772 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4773 &objfile
->symbol_obstack
);
4775 /* Default assumptions.
4776 Use the passed type or decode it from the die. */
4777 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4778 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4780 SYMBOL_TYPE (sym
) = type
;
4782 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
4783 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4786 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4789 /* If this symbol is from a C++ compilation, then attempt to
4790 cache the demangled form for future reference. This is a
4791 typical time versus space tradeoff, that was decided in favor
4792 of time because it sped up C++ symbol lookups by a factor of
4795 SYMBOL_LANGUAGE (sym
) = cu_language
;
4796 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4800 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4803 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4805 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4807 case DW_TAG_subprogram
:
4808 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4810 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4811 attr2
= dwarf_attr (die
, DW_AT_external
);
4812 if (attr2
&& (DW_UNSND (attr2
) != 0))
4814 add_symbol_to_list (sym
, &global_symbols
);
4818 add_symbol_to_list (sym
, list_in_scope
);
4821 case DW_TAG_variable
:
4822 /* Compilation with minimal debug info may result in variables
4823 with missing type entries. Change the misleading `void' type
4824 to something sensible. */
4825 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4826 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4827 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4828 "<variable, no debug info>",
4830 attr
= dwarf_attr (die
, DW_AT_const_value
);
4833 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4834 attr2
= dwarf_attr (die
, DW_AT_external
);
4835 if (attr2
&& (DW_UNSND (attr2
) != 0))
4836 add_symbol_to_list (sym
, &global_symbols
);
4838 add_symbol_to_list (sym
, list_in_scope
);
4841 attr
= dwarf_attr (die
, DW_AT_location
);
4844 attr2
= dwarf_attr (die
, DW_AT_external
);
4845 if (attr2
&& (DW_UNSND (attr2
) != 0))
4847 /* Support the .debug_loc offsets */
4848 if (attr_form_is_block (attr
))
4850 SYMBOL_VALUE_ADDRESS (sym
) =
4851 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4853 else if (attr
->form
== DW_FORM_data4
4854 || attr
->form
== DW_FORM_data8
)
4856 complain (&dwarf2_complex_location_expr
);
4860 complain (&dwarf2_invalid_attrib_class
, "DW_AT_location",
4861 "external variable");
4863 add_symbol_to_list (sym
, &global_symbols
);
4864 if (is_thread_local
)
4866 /* SYMBOL_VALUE_ADDRESS contains at this point the
4867 offset of the variable within the thread local
4869 SYMBOL_CLASS (sym
) = LOC_THREAD_LOCAL_STATIC
;
4870 SYMBOL_OBJFILE (sym
) = objfile
;
4873 /* In shared libraries the address of the variable
4874 in the location descriptor might still be relocatable,
4875 so its value could be zero.
4876 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4877 value is zero, the address of the variable will then
4878 be determined from the minimal symbol table whenever
4879 the variable is referenced. */
4880 else if (SYMBOL_VALUE_ADDRESS (sym
))
4882 fixup_symbol_section (sym
, objfile
);
4883 SYMBOL_VALUE_ADDRESS (sym
) +=
4884 ANOFFSET (objfile
->section_offsets
,
4885 SYMBOL_SECTION (sym
));
4886 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4889 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4893 /* Support the .debug_loc offsets */
4894 if (attr_form_is_block (attr
))
4896 SYMBOL_VALUE (sym
) = addr
=
4897 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4899 else if (attr
->form
== DW_FORM_data4
4900 || attr
->form
== DW_FORM_data8
)
4902 complain (&dwarf2_complex_location_expr
);
4906 complain (&dwarf2_invalid_attrib_class
, "DW_AT_location",
4907 "external variable");
4910 add_symbol_to_list (sym
, list_in_scope
);
4913 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4917 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4918 SYMBOL_VALUE (sym
) =
4919 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4923 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4924 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4928 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4930 else if (is_thread_local
)
4932 SYMBOL_CLASS (sym
) = LOC_THREAD_LOCAL_STATIC
;
4933 SYMBOL_OBJFILE (sym
) = objfile
;
4937 fixup_symbol_section (sym
, objfile
);
4938 SYMBOL_VALUE_ADDRESS (sym
) =
4939 addr
+ ANOFFSET (objfile
->section_offsets
,
4940 SYMBOL_SECTION (sym
));
4941 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4947 /* We do not know the address of this symbol.
4948 If it is an external symbol and we have type information
4949 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4950 The address of the variable will then be determined from
4951 the minimal symbol table whenever the variable is
4953 attr2
= dwarf_attr (die
, DW_AT_external
);
4954 if (attr2
&& (DW_UNSND (attr2
) != 0)
4955 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4957 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4958 add_symbol_to_list (sym
, &global_symbols
);
4962 case DW_TAG_formal_parameter
:
4963 attr
= dwarf_attr (die
, DW_AT_location
);
4966 SYMBOL_VALUE (sym
) =
4967 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4970 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4971 SYMBOL_VALUE (sym
) =
4972 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4978 if (basereg
!= frame_base_reg
)
4979 complain (&dwarf2_complex_location_expr
);
4980 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4984 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4985 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4990 SYMBOL_CLASS (sym
) = LOC_ARG
;
4993 attr
= dwarf_attr (die
, DW_AT_const_value
);
4996 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4998 add_symbol_to_list (sym
, list_in_scope
);
5000 case DW_TAG_unspecified_parameters
:
5001 /* From varargs functions; gdb doesn't seem to have any
5002 interest in this information, so just ignore it for now.
5005 case DW_TAG_class_type
:
5006 case DW_TAG_structure_type
:
5007 case DW_TAG_union_type
:
5008 case DW_TAG_enumeration_type
:
5009 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5010 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
5011 add_symbol_to_list (sym
, list_in_scope
);
5013 /* The semantics of C++ state that "struct foo { ... }" also
5014 defines a typedef for "foo". Synthesize a typedef symbol so
5015 that "ptype foo" works as expected. */
5016 if (cu_language
== language_cplus
)
5018 struct symbol
*typedef_sym
= (struct symbol
*)
5019 obstack_alloc (&objfile
->symbol_obstack
,
5020 sizeof (struct symbol
));
5021 *typedef_sym
= *sym
;
5022 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
5023 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
5024 TYPE_NAME (SYMBOL_TYPE (sym
)) =
5025 obsavestring (SYMBOL_NAME (sym
),
5026 strlen (SYMBOL_NAME (sym
)),
5027 &objfile
->type_obstack
);
5028 add_symbol_to_list (typedef_sym
, list_in_scope
);
5031 case DW_TAG_typedef
:
5032 case DW_TAG_base_type
:
5033 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5034 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
5035 add_symbol_to_list (sym
, list_in_scope
);
5037 case DW_TAG_enumerator
:
5038 attr
= dwarf_attr (die
, DW_AT_const_value
);
5041 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
5043 add_symbol_to_list (sym
, list_in_scope
);
5046 /* Not a tag we recognize. Hopefully we aren't processing
5047 trash data, but since we must specifically ignore things
5048 we don't recognize, there is nothing else we should do at
5050 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
5057 /* Copy constant value from an attribute to a symbol. */
5060 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
5061 struct objfile
*objfile
,
5062 const struct comp_unit_head
*cu_header
)
5064 struct dwarf_block
*blk
;
5069 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
5070 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
5071 cu_header
->addr_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
5072 SYMBOL_VALUE_BYTES (sym
) = (char *)
5073 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
5074 store_address (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
5076 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5078 case DW_FORM_block1
:
5079 case DW_FORM_block2
:
5080 case DW_FORM_block4
:
5082 blk
= DW_BLOCK (attr
);
5083 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
5084 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
5085 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
5086 SYMBOL_VALUE_BYTES (sym
) = (char *)
5087 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
5088 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
5089 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5092 /* The DW_AT_const_value attributes are supposed to carry the
5093 symbol's value "represented as it would be on the target
5094 architecture." By the time we get here, it's already been
5095 converted to host endianness, so we just need to sign- or
5096 zero-extend it as appropriate. */
5098 dwarf2_const_value_data (attr
, sym
, 8);
5101 dwarf2_const_value_data (attr
, sym
, 16);
5104 dwarf2_const_value_data (attr
, sym
, 32);
5107 dwarf2_const_value_data (attr
, sym
, 64);
5111 SYMBOL_VALUE (sym
) = DW_SND (attr
);
5112 SYMBOL_CLASS (sym
) = LOC_CONST
;
5116 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
5117 SYMBOL_CLASS (sym
) = LOC_CONST
;
5121 complain (&dwarf2_unsupported_const_value_attr
,
5122 dwarf_form_name (attr
->form
));
5123 SYMBOL_VALUE (sym
) = 0;
5124 SYMBOL_CLASS (sym
) = LOC_CONST
;
5130 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
5131 or zero-extend it as appropriate for the symbol's type. */
5133 dwarf2_const_value_data (struct attribute
*attr
,
5137 LONGEST l
= DW_UNSND (attr
);
5139 if (bits
< sizeof (l
) * 8)
5141 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
5142 l
&= ((LONGEST
) 1 << bits
) - 1;
5144 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
5147 SYMBOL_VALUE (sym
) = l
;
5148 SYMBOL_CLASS (sym
) = LOC_CONST
;
5152 /* Return the type of the die in question using its DW_AT_type attribute. */
5154 static struct type
*
5155 die_type (struct die_info
*die
, struct objfile
*objfile
,
5156 const struct comp_unit_head
*cu_header
)
5159 struct attribute
*type_attr
;
5160 struct die_info
*type_die
;
5163 type_attr
= dwarf_attr (die
, DW_AT_type
);
5166 /* A missing DW_AT_type represents a void type. */
5167 return dwarf2_fundamental_type (objfile
, FT_VOID
);
5171 ref
= dwarf2_get_ref_die_offset (type_attr
);
5172 type_die
= follow_die_ref (ref
);
5175 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
5179 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
5182 dump_die (type_die
);
5183 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
5188 /* Return the containing type of the die in question using its
5189 DW_AT_containing_type attribute. */
5191 static struct type
*
5192 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
5193 const struct comp_unit_head
*cu_header
)
5195 struct type
*type
= NULL
;
5196 struct attribute
*type_attr
;
5197 struct die_info
*type_die
= NULL
;
5200 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
5203 ref
= dwarf2_get_ref_die_offset (type_attr
);
5204 type_die
= follow_die_ref (ref
);
5207 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
5210 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
5215 dump_die (type_die
);
5216 error ("Dwarf Error: Problem turning containing type into gdb type.");
5222 static struct type
*
5223 type_at_offset (unsigned int offset
, struct objfile
*objfile
)
5225 struct die_info
*die
;
5228 die
= follow_die_ref (offset
);
5231 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
5234 type
= tag_type_to_type (die
, objfile
);
5239 static struct type
*
5240 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
5241 const struct comp_unit_head
*cu_header
)
5249 read_type_die (die
, objfile
, cu_header
);
5253 error ("Dwarf Error: Cannot find type of die.");
5260 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
5261 const struct comp_unit_head
*cu_header
)
5265 case DW_TAG_class_type
:
5266 case DW_TAG_structure_type
:
5267 case DW_TAG_union_type
:
5268 read_structure_scope (die
, objfile
, cu_header
);
5270 case DW_TAG_enumeration_type
:
5271 read_enumeration (die
, objfile
, cu_header
);
5273 case DW_TAG_subprogram
:
5274 case DW_TAG_subroutine_type
:
5275 read_subroutine_type (die
, objfile
, cu_header
);
5277 case DW_TAG_array_type
:
5278 read_array_type (die
, objfile
, cu_header
);
5280 case DW_TAG_pointer_type
:
5281 read_tag_pointer_type (die
, objfile
, cu_header
);
5283 case DW_TAG_ptr_to_member_type
:
5284 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
5286 case DW_TAG_reference_type
:
5287 read_tag_reference_type (die
, objfile
, cu_header
);
5289 case DW_TAG_const_type
:
5290 read_tag_const_type (die
, objfile
, cu_header
);
5292 case DW_TAG_volatile_type
:
5293 read_tag_volatile_type (die
, objfile
, cu_header
);
5295 case DW_TAG_string_type
:
5296 read_tag_string_type (die
, objfile
);
5298 case DW_TAG_typedef
:
5299 read_typedef (die
, objfile
, cu_header
);
5301 case DW_TAG_base_type
:
5302 read_base_type (die
, objfile
);
5305 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
5310 static struct type
*
5311 dwarf_base_type (int encoding
, int size
, struct objfile
*objfile
)
5313 /* FIXME - this should not produce a new (struct type *)
5314 every time. It should cache base types. */
5318 case DW_ATE_address
:
5319 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
5321 case DW_ATE_boolean
:
5322 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
5324 case DW_ATE_complex_float
:
5327 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
5331 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
5337 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
5341 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
5348 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5351 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
5355 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5359 case DW_ATE_signed_char
:
5360 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5362 case DW_ATE_unsigned
:
5366 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5369 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
5373 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
5377 case DW_ATE_unsigned_char
:
5378 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5381 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5388 copy_die (struct die_info
*old_die
)
5390 struct die_info
*new_die
;
5393 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5394 memset (new_die
, 0, sizeof (struct die_info
));
5396 new_die
->tag
= old_die
->tag
;
5397 new_die
->has_children
= old_die
->has_children
;
5398 new_die
->abbrev
= old_die
->abbrev
;
5399 new_die
->offset
= old_die
->offset
;
5400 new_die
->type
= NULL
;
5402 num_attrs
= old_die
->num_attrs
;
5403 new_die
->num_attrs
= num_attrs
;
5404 new_die
->attrs
= (struct attribute
*)
5405 xmalloc (num_attrs
* sizeof (struct attribute
));
5407 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
5409 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
5410 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
5411 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
5414 new_die
->next
= NULL
;
5419 /* Return sibling of die, NULL if no sibling. */
5421 static struct die_info
*
5422 sibling_die (struct die_info
*die
)
5424 int nesting_level
= 0;
5426 if (!die
->has_children
)
5428 if (die
->next
&& (die
->next
->tag
== 0))
5441 if (die
->has_children
)
5451 while (nesting_level
);
5452 if (die
&& (die
->tag
== 0))
5463 /* Get linkage name of a die, return NULL if not found. */
5466 dwarf2_linkage_name (struct die_info
*die
)
5468 struct attribute
*attr
;
5470 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
5471 if (attr
&& DW_STRING (attr
))
5472 return DW_STRING (attr
);
5473 attr
= dwarf_attr (die
, DW_AT_name
);
5474 if (attr
&& DW_STRING (attr
))
5475 return DW_STRING (attr
);
5479 /* Convert a DIE tag into its string name. */
5482 dwarf_tag_name (register unsigned tag
)
5486 case DW_TAG_padding
:
5487 return "DW_TAG_padding";
5488 case DW_TAG_array_type
:
5489 return "DW_TAG_array_type";
5490 case DW_TAG_class_type
:
5491 return "DW_TAG_class_type";
5492 case DW_TAG_entry_point
:
5493 return "DW_TAG_entry_point";
5494 case DW_TAG_enumeration_type
:
5495 return "DW_TAG_enumeration_type";
5496 case DW_TAG_formal_parameter
:
5497 return "DW_TAG_formal_parameter";
5498 case DW_TAG_imported_declaration
:
5499 return "DW_TAG_imported_declaration";
5501 return "DW_TAG_label";
5502 case DW_TAG_lexical_block
:
5503 return "DW_TAG_lexical_block";
5505 return "DW_TAG_member";
5506 case DW_TAG_pointer_type
:
5507 return "DW_TAG_pointer_type";
5508 case DW_TAG_reference_type
:
5509 return "DW_TAG_reference_type";
5510 case DW_TAG_compile_unit
:
5511 return "DW_TAG_compile_unit";
5512 case DW_TAG_string_type
:
5513 return "DW_TAG_string_type";
5514 case DW_TAG_structure_type
:
5515 return "DW_TAG_structure_type";
5516 case DW_TAG_subroutine_type
:
5517 return "DW_TAG_subroutine_type";
5518 case DW_TAG_typedef
:
5519 return "DW_TAG_typedef";
5520 case DW_TAG_union_type
:
5521 return "DW_TAG_union_type";
5522 case DW_TAG_unspecified_parameters
:
5523 return "DW_TAG_unspecified_parameters";
5524 case DW_TAG_variant
:
5525 return "DW_TAG_variant";
5526 case DW_TAG_common_block
:
5527 return "DW_TAG_common_block";
5528 case DW_TAG_common_inclusion
:
5529 return "DW_TAG_common_inclusion";
5530 case DW_TAG_inheritance
:
5531 return "DW_TAG_inheritance";
5532 case DW_TAG_inlined_subroutine
:
5533 return "DW_TAG_inlined_subroutine";
5535 return "DW_TAG_module";
5536 case DW_TAG_ptr_to_member_type
:
5537 return "DW_TAG_ptr_to_member_type";
5538 case DW_TAG_set_type
:
5539 return "DW_TAG_set_type";
5540 case DW_TAG_subrange_type
:
5541 return "DW_TAG_subrange_type";
5542 case DW_TAG_with_stmt
:
5543 return "DW_TAG_with_stmt";
5544 case DW_TAG_access_declaration
:
5545 return "DW_TAG_access_declaration";
5546 case DW_TAG_base_type
:
5547 return "DW_TAG_base_type";
5548 case DW_TAG_catch_block
:
5549 return "DW_TAG_catch_block";
5550 case DW_TAG_const_type
:
5551 return "DW_TAG_const_type";
5552 case DW_TAG_constant
:
5553 return "DW_TAG_constant";
5554 case DW_TAG_enumerator
:
5555 return "DW_TAG_enumerator";
5556 case DW_TAG_file_type
:
5557 return "DW_TAG_file_type";
5559 return "DW_TAG_friend";
5560 case DW_TAG_namelist
:
5561 return "DW_TAG_namelist";
5562 case DW_TAG_namelist_item
:
5563 return "DW_TAG_namelist_item";
5564 case DW_TAG_packed_type
:
5565 return "DW_TAG_packed_type";
5566 case DW_TAG_subprogram
:
5567 return "DW_TAG_subprogram";
5568 case DW_TAG_template_type_param
:
5569 return "DW_TAG_template_type_param";
5570 case DW_TAG_template_value_param
:
5571 return "DW_TAG_template_value_param";
5572 case DW_TAG_thrown_type
:
5573 return "DW_TAG_thrown_type";
5574 case DW_TAG_try_block
:
5575 return "DW_TAG_try_block";
5576 case DW_TAG_variant_part
:
5577 return "DW_TAG_variant_part";
5578 case DW_TAG_variable
:
5579 return "DW_TAG_variable";
5580 case DW_TAG_volatile_type
:
5581 return "DW_TAG_volatile_type";
5582 case DW_TAG_dwarf_procedure
:
5583 return "DW_TAG_dwarf_procedure";
5584 case DW_TAG_restrict_type
:
5585 return "DW_TAG_restrict_type";
5586 case DW_TAG_interface_type
:
5587 return "DW_TAG_interface_type";
5588 case DW_TAG_namespace
:
5589 return "DW_TAG_namespace";
5590 case DW_TAG_imported_module
:
5591 return "DW_TAG_imported_module";
5592 case DW_TAG_unspecified_type
:
5593 return "DW_TAG_unspecified_type";
5594 case DW_TAG_partial_unit
:
5595 return "DW_TAG_partial_unit";
5596 case DW_TAG_imported_unit
:
5597 return "DW_TAG_imported_unit";
5598 case DW_TAG_MIPS_loop
:
5599 return "DW_TAG_MIPS_loop";
5600 case DW_TAG_format_label
:
5601 return "DW_TAG_format_label";
5602 case DW_TAG_function_template
:
5603 return "DW_TAG_function_template";
5604 case DW_TAG_class_template
:
5605 return "DW_TAG_class_template";
5607 return "DW_TAG_<unknown>";
5611 /* Convert a DWARF attribute code into its string name. */
5614 dwarf_attr_name (register unsigned attr
)
5619 return "DW_AT_sibling";
5620 case DW_AT_location
:
5621 return "DW_AT_location";
5623 return "DW_AT_name";
5624 case DW_AT_ordering
:
5625 return "DW_AT_ordering";
5626 case DW_AT_subscr_data
:
5627 return "DW_AT_subscr_data";
5628 case DW_AT_byte_size
:
5629 return "DW_AT_byte_size";
5630 case DW_AT_bit_offset
:
5631 return "DW_AT_bit_offset";
5632 case DW_AT_bit_size
:
5633 return "DW_AT_bit_size";
5634 case DW_AT_element_list
:
5635 return "DW_AT_element_list";
5636 case DW_AT_stmt_list
:
5637 return "DW_AT_stmt_list";
5639 return "DW_AT_low_pc";
5641 return "DW_AT_high_pc";
5642 case DW_AT_language
:
5643 return "DW_AT_language";
5645 return "DW_AT_member";
5647 return "DW_AT_discr";
5648 case DW_AT_discr_value
:
5649 return "DW_AT_discr_value";
5650 case DW_AT_visibility
:
5651 return "DW_AT_visibility";
5653 return "DW_AT_import";
5654 case DW_AT_string_length
:
5655 return "DW_AT_string_length";
5656 case DW_AT_common_reference
:
5657 return "DW_AT_common_reference";
5658 case DW_AT_comp_dir
:
5659 return "DW_AT_comp_dir";
5660 case DW_AT_const_value
:
5661 return "DW_AT_const_value";
5662 case DW_AT_containing_type
:
5663 return "DW_AT_containing_type";
5664 case DW_AT_default_value
:
5665 return "DW_AT_default_value";
5667 return "DW_AT_inline";
5668 case DW_AT_is_optional
:
5669 return "DW_AT_is_optional";
5670 case DW_AT_lower_bound
:
5671 return "DW_AT_lower_bound";
5672 case DW_AT_producer
:
5673 return "DW_AT_producer";
5674 case DW_AT_prototyped
:
5675 return "DW_AT_prototyped";
5676 case DW_AT_return_addr
:
5677 return "DW_AT_return_addr";
5678 case DW_AT_start_scope
:
5679 return "DW_AT_start_scope";
5680 case DW_AT_stride_size
:
5681 return "DW_AT_stride_size";
5682 case DW_AT_upper_bound
:
5683 return "DW_AT_upper_bound";
5684 case DW_AT_abstract_origin
:
5685 return "DW_AT_abstract_origin";
5686 case DW_AT_accessibility
:
5687 return "DW_AT_accessibility";
5688 case DW_AT_address_class
:
5689 return "DW_AT_address_class";
5690 case DW_AT_artificial
:
5691 return "DW_AT_artificial";
5692 case DW_AT_base_types
:
5693 return "DW_AT_base_types";
5694 case DW_AT_calling_convention
:
5695 return "DW_AT_calling_convention";
5697 return "DW_AT_count";
5698 case DW_AT_data_member_location
:
5699 return "DW_AT_data_member_location";
5700 case DW_AT_decl_column
:
5701 return "DW_AT_decl_column";
5702 case DW_AT_decl_file
:
5703 return "DW_AT_decl_file";
5704 case DW_AT_decl_line
:
5705 return "DW_AT_decl_line";
5706 case DW_AT_declaration
:
5707 return "DW_AT_declaration";
5708 case DW_AT_discr_list
:
5709 return "DW_AT_discr_list";
5710 case DW_AT_encoding
:
5711 return "DW_AT_encoding";
5712 case DW_AT_external
:
5713 return "DW_AT_external";
5714 case DW_AT_frame_base
:
5715 return "DW_AT_frame_base";
5717 return "DW_AT_friend";
5718 case DW_AT_identifier_case
:
5719 return "DW_AT_identifier_case";
5720 case DW_AT_macro_info
:
5721 return "DW_AT_macro_info";
5722 case DW_AT_namelist_items
:
5723 return "DW_AT_namelist_items";
5724 case DW_AT_priority
:
5725 return "DW_AT_priority";
5727 return "DW_AT_segment";
5728 case DW_AT_specification
:
5729 return "DW_AT_specification";
5730 case DW_AT_static_link
:
5731 return "DW_AT_static_link";
5733 return "DW_AT_type";
5734 case DW_AT_use_location
:
5735 return "DW_AT_use_location";
5736 case DW_AT_variable_parameter
:
5737 return "DW_AT_variable_parameter";
5738 case DW_AT_virtuality
:
5739 return "DW_AT_virtuality";
5740 case DW_AT_vtable_elem_location
:
5741 return "DW_AT_vtable_elem_location";
5742 case DW_AT_allocated
:
5743 return "DW_AT_allocated";
5744 case DW_AT_associated
:
5745 return "DW_AT_associated";
5746 case DW_AT_data_location
:
5747 return "DW_AT_data_location";
5749 return "DW_AT_stride";
5750 case DW_AT_entry_pc
:
5751 return "DW_AT_entry_pc";
5752 case DW_AT_use_UTF8
:
5753 return "DW_AT_use_UTF8";
5754 case DW_AT_extension
:
5755 return "DW_AT_extension";
5757 return "DW_AT_ranges";
5758 case DW_AT_trampoline
:
5759 return "DW_AT_trampoline";
5760 case DW_AT_call_column
:
5761 return "DW_AT_call_column";
5762 case DW_AT_call_file
:
5763 return "DW_AT_call_file";
5764 case DW_AT_call_line
:
5765 return "DW_AT_call_line";
5767 case DW_AT_MIPS_fde
:
5768 return "DW_AT_MIPS_fde";
5769 case DW_AT_MIPS_loop_begin
:
5770 return "DW_AT_MIPS_loop_begin";
5771 case DW_AT_MIPS_tail_loop_begin
:
5772 return "DW_AT_MIPS_tail_loop_begin";
5773 case DW_AT_MIPS_epilog_begin
:
5774 return "DW_AT_MIPS_epilog_begin";
5775 case DW_AT_MIPS_loop_unroll_factor
:
5776 return "DW_AT_MIPS_loop_unroll_factor";
5777 case DW_AT_MIPS_software_pipeline_depth
:
5778 return "DW_AT_MIPS_software_pipeline_depth";
5779 case DW_AT_MIPS_linkage_name
:
5780 return "DW_AT_MIPS_linkage_name";
5783 case DW_AT_sf_names
:
5784 return "DW_AT_sf_names";
5785 case DW_AT_src_info
:
5786 return "DW_AT_src_info";
5787 case DW_AT_mac_info
:
5788 return "DW_AT_mac_info";
5789 case DW_AT_src_coords
:
5790 return "DW_AT_src_coords";
5791 case DW_AT_body_begin
:
5792 return "DW_AT_body_begin";
5793 case DW_AT_body_end
:
5794 return "DW_AT_body_end";
5795 case DW_AT_GNU_vector
:
5796 return "DW_AT_GNU_vector";
5798 return "DW_AT_<unknown>";
5802 /* Convert a DWARF value form code into its string name. */
5805 dwarf_form_name (register unsigned form
)
5810 return "DW_FORM_addr";
5811 case DW_FORM_block2
:
5812 return "DW_FORM_block2";
5813 case DW_FORM_block4
:
5814 return "DW_FORM_block4";
5816 return "DW_FORM_data2";
5818 return "DW_FORM_data4";
5820 return "DW_FORM_data8";
5821 case DW_FORM_string
:
5822 return "DW_FORM_string";
5824 return "DW_FORM_block";
5825 case DW_FORM_block1
:
5826 return "DW_FORM_block1";
5828 return "DW_FORM_data1";
5830 return "DW_FORM_flag";
5832 return "DW_FORM_sdata";
5834 return "DW_FORM_strp";
5836 return "DW_FORM_udata";
5837 case DW_FORM_ref_addr
:
5838 return "DW_FORM_ref_addr";
5840 return "DW_FORM_ref1";
5842 return "DW_FORM_ref2";
5844 return "DW_FORM_ref4";
5846 return "DW_FORM_ref8";
5847 case DW_FORM_ref_udata
:
5848 return "DW_FORM_ref_udata";
5849 case DW_FORM_indirect
:
5850 return "DW_FORM_indirect";
5852 return "DW_FORM_<unknown>";
5856 /* Convert a DWARF stack opcode into its string name. */
5859 dwarf_stack_op_name (register unsigned op
)
5864 return "DW_OP_addr";
5866 return "DW_OP_deref";
5868 return "DW_OP_const1u";
5870 return "DW_OP_const1s";
5872 return "DW_OP_const2u";
5874 return "DW_OP_const2s";
5876 return "DW_OP_const4u";
5878 return "DW_OP_const4s";
5880 return "DW_OP_const8u";
5882 return "DW_OP_const8s";
5884 return "DW_OP_constu";
5886 return "DW_OP_consts";
5890 return "DW_OP_drop";
5892 return "DW_OP_over";
5894 return "DW_OP_pick";
5896 return "DW_OP_swap";
5900 return "DW_OP_xderef";
5908 return "DW_OP_minus";
5920 return "DW_OP_plus";
5921 case DW_OP_plus_uconst
:
5922 return "DW_OP_plus_uconst";
5928 return "DW_OP_shra";
5946 return "DW_OP_skip";
5948 return "DW_OP_lit0";
5950 return "DW_OP_lit1";
5952 return "DW_OP_lit2";
5954 return "DW_OP_lit3";
5956 return "DW_OP_lit4";
5958 return "DW_OP_lit5";
5960 return "DW_OP_lit6";
5962 return "DW_OP_lit7";
5964 return "DW_OP_lit8";
5966 return "DW_OP_lit9";
5968 return "DW_OP_lit10";
5970 return "DW_OP_lit11";
5972 return "DW_OP_lit12";
5974 return "DW_OP_lit13";
5976 return "DW_OP_lit14";
5978 return "DW_OP_lit15";
5980 return "DW_OP_lit16";
5982 return "DW_OP_lit17";
5984 return "DW_OP_lit18";
5986 return "DW_OP_lit19";
5988 return "DW_OP_lit20";
5990 return "DW_OP_lit21";
5992 return "DW_OP_lit22";
5994 return "DW_OP_lit23";
5996 return "DW_OP_lit24";
5998 return "DW_OP_lit25";
6000 return "DW_OP_lit26";
6002 return "DW_OP_lit27";
6004 return "DW_OP_lit28";
6006 return "DW_OP_lit29";
6008 return "DW_OP_lit30";
6010 return "DW_OP_lit31";
6012 return "DW_OP_reg0";
6014 return "DW_OP_reg1";
6016 return "DW_OP_reg2";
6018 return "DW_OP_reg3";
6020 return "DW_OP_reg4";
6022 return "DW_OP_reg5";
6024 return "DW_OP_reg6";
6026 return "DW_OP_reg7";
6028 return "DW_OP_reg8";
6030 return "DW_OP_reg9";
6032 return "DW_OP_reg10";
6034 return "DW_OP_reg11";
6036 return "DW_OP_reg12";
6038 return "DW_OP_reg13";
6040 return "DW_OP_reg14";
6042 return "DW_OP_reg15";
6044 return "DW_OP_reg16";
6046 return "DW_OP_reg17";
6048 return "DW_OP_reg18";
6050 return "DW_OP_reg19";
6052 return "DW_OP_reg20";
6054 return "DW_OP_reg21";
6056 return "DW_OP_reg22";
6058 return "DW_OP_reg23";
6060 return "DW_OP_reg24";
6062 return "DW_OP_reg25";
6064 return "DW_OP_reg26";
6066 return "DW_OP_reg27";
6068 return "DW_OP_reg28";
6070 return "DW_OP_reg29";
6072 return "DW_OP_reg30";
6074 return "DW_OP_reg31";
6076 return "DW_OP_breg0";
6078 return "DW_OP_breg1";
6080 return "DW_OP_breg2";
6082 return "DW_OP_breg3";
6084 return "DW_OP_breg4";
6086 return "DW_OP_breg5";
6088 return "DW_OP_breg6";
6090 return "DW_OP_breg7";
6092 return "DW_OP_breg8";
6094 return "DW_OP_breg9";
6096 return "DW_OP_breg10";
6098 return "DW_OP_breg11";
6100 return "DW_OP_breg12";
6102 return "DW_OP_breg13";
6104 return "DW_OP_breg14";
6106 return "DW_OP_breg15";
6108 return "DW_OP_breg16";
6110 return "DW_OP_breg17";
6112 return "DW_OP_breg18";
6114 return "DW_OP_breg19";
6116 return "DW_OP_breg20";
6118 return "DW_OP_breg21";
6120 return "DW_OP_breg22";
6122 return "DW_OP_breg23";
6124 return "DW_OP_breg24";
6126 return "DW_OP_breg25";
6128 return "DW_OP_breg26";
6130 return "DW_OP_breg27";
6132 return "DW_OP_breg28";
6134 return "DW_OP_breg29";
6136 return "DW_OP_breg30";
6138 return "DW_OP_breg31";
6140 return "DW_OP_regx";
6142 return "DW_OP_fbreg";
6144 return "DW_OP_bregx";
6146 return "DW_OP_piece";
6147 case DW_OP_deref_size
:
6148 return "DW_OP_deref_size";
6149 case DW_OP_xderef_size
:
6150 return "DW_OP_xderef_size";
6153 /* DWARF 3 extensions. */
6154 case DW_OP_push_object_address
:
6155 return "DW_OP_push_object_address";
6157 return "DW_OP_call2";
6159 return "DW_OP_call4";
6160 case DW_OP_call_ref
:
6161 return "DW_OP_call_ref";
6162 /* GNU extensions. */
6163 case DW_OP_GNU_push_tls_address
:
6164 return "DW_OP_GNU_push_tls_address";
6166 return "OP_<unknown>";
6171 dwarf_bool_name (unsigned mybool
)
6179 /* Convert a DWARF type code into its string name. */
6182 dwarf_type_encoding_name (register unsigned enc
)
6186 case DW_ATE_address
:
6187 return "DW_ATE_address";
6188 case DW_ATE_boolean
:
6189 return "DW_ATE_boolean";
6190 case DW_ATE_complex_float
:
6191 return "DW_ATE_complex_float";
6193 return "DW_ATE_float";
6195 return "DW_ATE_signed";
6196 case DW_ATE_signed_char
:
6197 return "DW_ATE_signed_char";
6198 case DW_ATE_unsigned
:
6199 return "DW_ATE_unsigned";
6200 case DW_ATE_unsigned_char
:
6201 return "DW_ATE_unsigned_char";
6202 case DW_ATE_imaginary_float
:
6203 return "DW_ATE_imaginary_float";
6205 return "DW_ATE_<unknown>";
6209 /* Convert a DWARF call frame info operation to its string name. */
6213 dwarf_cfi_name (register unsigned cfi_opc
)
6217 case DW_CFA_advance_loc
:
6218 return "DW_CFA_advance_loc";
6220 return "DW_CFA_offset";
6221 case DW_CFA_restore
:
6222 return "DW_CFA_restore";
6224 return "DW_CFA_nop";
6225 case DW_CFA_set_loc
:
6226 return "DW_CFA_set_loc";
6227 case DW_CFA_advance_loc1
:
6228 return "DW_CFA_advance_loc1";
6229 case DW_CFA_advance_loc2
:
6230 return "DW_CFA_advance_loc2";
6231 case DW_CFA_advance_loc4
:
6232 return "DW_CFA_advance_loc4";
6233 case DW_CFA_offset_extended
:
6234 return "DW_CFA_offset_extended";
6235 case DW_CFA_restore_extended
:
6236 return "DW_CFA_restore_extended";
6237 case DW_CFA_undefined
:
6238 return "DW_CFA_undefined";
6239 case DW_CFA_same_value
:
6240 return "DW_CFA_same_value";
6241 case DW_CFA_register
:
6242 return "DW_CFA_register";
6243 case DW_CFA_remember_state
:
6244 return "DW_CFA_remember_state";
6245 case DW_CFA_restore_state
:
6246 return "DW_CFA_restore_state";
6247 case DW_CFA_def_cfa
:
6248 return "DW_CFA_def_cfa";
6249 case DW_CFA_def_cfa_register
:
6250 return "DW_CFA_def_cfa_register";
6251 case DW_CFA_def_cfa_offset
:
6252 return "DW_CFA_def_cfa_offset";
6255 case DW_CFA_def_cfa_expression
:
6256 return "DW_CFA_def_cfa_expression";
6257 case DW_CFA_expression
:
6258 return "DW_CFA_expression";
6259 case DW_CFA_offset_extended_sf
:
6260 return "DW_CFA_offset_extended_sf";
6261 case DW_CFA_def_cfa_sf
:
6262 return "DW_CFA_def_cfa_sf";
6263 case DW_CFA_def_cfa_offset_sf
:
6264 return "DW_CFA_def_cfa_offset_sf";
6266 /* SGI/MIPS specific */
6267 case DW_CFA_MIPS_advance_loc8
:
6268 return "DW_CFA_MIPS_advance_loc8";
6270 /* GNU extensions */
6271 case DW_CFA_GNU_window_save
:
6272 return "DW_CFA_GNU_window_save";
6273 case DW_CFA_GNU_args_size
:
6274 return "DW_CFA_GNU_args_size";
6275 case DW_CFA_GNU_negative_offset_extended
:
6276 return "DW_CFA_GNU_negative_offset_extended";
6279 return "DW_CFA_<unknown>";
6285 dump_die (struct die_info
*die
)
6289 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
6290 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
6291 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
6292 dwarf_bool_name (die
->has_children
));
6294 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
6295 for (i
= 0; i
< die
->num_attrs
; ++i
)
6297 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
6298 dwarf_attr_name (die
->attrs
[i
].name
),
6299 dwarf_form_name (die
->attrs
[i
].form
));
6300 switch (die
->attrs
[i
].form
)
6302 case DW_FORM_ref_addr
:
6304 fprintf_unfiltered (gdb_stderr
, "address: ");
6305 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
6307 case DW_FORM_block2
:
6308 case DW_FORM_block4
:
6310 case DW_FORM_block1
:
6311 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
6322 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
6324 case DW_FORM_string
:
6326 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
6327 DW_STRING (&die
->attrs
[i
])
6328 ? DW_STRING (&die
->attrs
[i
]) : "");
6331 if (DW_UNSND (&die
->attrs
[i
]))
6332 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
6334 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
6336 case DW_FORM_indirect
:
6337 /* the reader will have reduced the indirect form to
6338 the "base form" so this form should not occur */
6339 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
6342 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
6343 die
->attrs
[i
].form
);
6345 fprintf_unfiltered (gdb_stderr
, "\n");
6350 dump_die_list (struct die_info
*die
)
6360 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
6363 struct die_info
*old
;
6365 h
= (offset
% REF_HASH_SIZE
);
6366 old
= die_ref_table
[h
];
6367 die
->next_ref
= old
;
6368 die_ref_table
[h
] = die
;
6373 dwarf2_empty_hash_tables (void)
6375 memset (die_ref_table
, 0, sizeof (die_ref_table
));
6379 dwarf2_get_ref_die_offset (struct attribute
*attr
)
6381 unsigned int result
= 0;
6385 case DW_FORM_ref_addr
:
6386 result
= DW_ADDR (attr
);
6392 case DW_FORM_ref_udata
:
6393 result
= cu_header_offset
+ DW_UNSND (attr
);
6396 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
6401 static struct die_info
*
6402 follow_die_ref (unsigned int offset
)
6404 struct die_info
*die
;
6407 h
= (offset
% REF_HASH_SIZE
);
6408 die
= die_ref_table
[h
];
6411 if (die
->offset
== offset
)
6415 die
= die
->next_ref
;
6420 static struct type
*
6421 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
6423 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
6425 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
6429 /* Look for this particular type in the fundamental type vector. If
6430 one is not found, create and install one appropriate for the
6431 current language and the current target machine. */
6433 if (ftypes
[typeid] == NULL
)
6435 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
6438 return (ftypes
[typeid]);
6441 /* Decode simple location descriptions.
6442 Given a pointer to a dwarf block that defines a location, compute
6443 the location and return the value.
6445 FIXME: This is a kludge until we figure out a better
6446 way to handle the location descriptions.
6447 Gdb's design does not mesh well with the DWARF2 notion of a location
6448 computing interpreter, which is a shame because the flexibility goes unused.
6449 FIXME: Implement more operations as necessary.
6451 A location description containing no operations indicates that the
6452 object is optimized out. The global optimized_out flag is set for
6453 those, the return value is meaningless.
6455 When the result is a register number, the global isreg flag is set,
6456 otherwise it is cleared.
6458 When the result is a base register offset, the global offreg flag is set
6459 and the register number is returned in basereg, otherwise it is cleared.
6461 When the DW_OP_fbreg operation is encountered without a corresponding
6462 DW_AT_frame_base attribute, the global islocal flag is set.
6463 Hopefully the machine dependent code knows how to set up a virtual
6464 frame pointer for the local references.
6466 Note that stack[0] is unused except as a default error return.
6467 Note that stack overflow is not yet handled. */
6470 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
6471 const struct comp_unit_head
*cu_header
)
6474 int size
= blk
->size
;
6475 char *data
= blk
->data
;
6476 CORE_ADDR stack
[64];
6478 unsigned int bytes_read
, unsnd
;
6488 is_thread_local
= 0;
6529 stack
[++stacki
] = op
- DW_OP_lit0
;
6565 stack
[++stacki
] = op
- DW_OP_reg0
;
6570 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6572 stack
[++stacki
] = unsnd
;
6608 basereg
= op
- DW_OP_breg0
;
6609 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6615 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6617 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6622 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6624 if (frame_base_reg
>= 0)
6627 basereg
= frame_base_reg
;
6628 stack
[stacki
] += frame_base_offset
;
6632 complain (&dwarf2_missing_at_frame_base
);
6638 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
6639 cu_header
, &bytes_read
);
6644 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
6649 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
6654 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
6659 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
6664 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
6669 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
6674 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
6680 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6685 stack
[stacki
+ 1] = stack
[stacki
];
6690 stack
[stacki
- 1] += stack
[stacki
];
6694 case DW_OP_plus_uconst
:
6695 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6700 stack
[stacki
- 1] -= stack
[stacki
];
6706 /* If we're not the last op, then we definitely can't encode
6707 this using GDB's address_class enum. */
6709 complain (&dwarf2_complex_location_expr
);
6712 case DW_OP_GNU_push_tls_address
:
6713 is_thread_local
= 1;
6714 /* The top of the stack has the offset from the beginning
6715 of the thread control block at which the variable is located. */
6716 /* Nothing should follow this operator, so the top of stack would
6719 complain (&dwarf2_complex_location_expr
);
6723 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
6724 return (stack
[stacki
]);
6727 return (stack
[stacki
]);
6730 /* memory allocation interface */
6734 dwarf2_free_tmp_obstack (PTR ignore
)
6736 obstack_free (&dwarf2_tmp_obstack
, NULL
);
6739 static struct dwarf_block
*
6740 dwarf_alloc_block (void)
6742 struct dwarf_block
*blk
;
6744 blk
= (struct dwarf_block
*)
6745 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
6749 static struct abbrev_info
*
6750 dwarf_alloc_abbrev (void)
6752 struct abbrev_info
*abbrev
;
6754 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
6755 memset (abbrev
, 0, sizeof (struct abbrev_info
));
6759 static struct die_info
*
6760 dwarf_alloc_die (void)
6762 struct die_info
*die
;
6764 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6765 memset (die
, 0, sizeof (struct die_info
));
6770 /* Macro support. */
6773 /* Return the full name of file number I in *LH's file name table.
6774 Use COMP_DIR as the name of the current directory of the
6775 compilation. The result is allocated using xmalloc; the caller is
6776 responsible for freeing it. */
6778 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
6780 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
6782 if (IS_ABSOLUTE_PATH (fe
->name
))
6783 return xstrdup (fe
->name
);
6791 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6797 dir_len
= strlen (dir
);
6798 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
6799 strcpy (full_name
, dir
);
6800 full_name
[dir_len
] = '/';
6801 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
6805 return xstrdup (fe
->name
);
6810 static struct macro_source_file
*
6811 macro_start_file (int file
, int line
,
6812 struct macro_source_file
*current_file
,
6813 const char *comp_dir
,
6814 struct line_header
*lh
, struct objfile
*objfile
)
6816 /* The full name of this source file. */
6817 char *full_name
= file_full_name (file
, lh
, comp_dir
);
6819 /* We don't create a macro table for this compilation unit
6820 at all until we actually get a filename. */
6821 if (! pending_macros
)
6822 pending_macros
= new_macro_table (&objfile
->symbol_obstack
,
6823 objfile
->macro_cache
);
6826 /* If we have no current file, then this must be the start_file
6827 directive for the compilation unit's main source file. */
6828 current_file
= macro_set_main (pending_macros
, full_name
);
6830 current_file
= macro_include (current_file
, line
, full_name
);
6834 return current_file
;
6838 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
6839 followed by a null byte. */
6841 copy_string (const char *buf
, int len
)
6843 char *s
= xmalloc (len
+ 1);
6844 memcpy (s
, buf
, len
);
6852 consume_improper_spaces (const char *p
, const char *body
)
6856 complain (&dwarf2_macro_spaces_in_definition
, body
);
6867 parse_macro_definition (struct macro_source_file
*file
, int line
,
6872 /* The body string takes one of two forms. For object-like macro
6873 definitions, it should be:
6875 <macro name> " " <definition>
6877 For function-like macro definitions, it should be:
6879 <macro name> "() " <definition>
6881 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
6883 Spaces may appear only where explicitly indicated, and in the
6886 The Dwarf 2 spec says that an object-like macro's name is always
6887 followed by a space, but versions of GCC around March 2002 omit
6888 the space when the macro's definition is the empty string.
6890 The Dwarf 2 spec says that there should be no spaces between the
6891 formal arguments in a function-like macro's formal argument list,
6892 but versions of GCC around March 2002 include spaces after the
6896 /* Find the extent of the macro name. The macro name is terminated
6897 by either a space or null character (for an object-like macro) or
6898 an opening paren (for a function-like macro). */
6899 for (p
= body
; *p
; p
++)
6900 if (*p
== ' ' || *p
== '(')
6903 if (*p
== ' ' || *p
== '\0')
6905 /* It's an object-like macro. */
6906 int name_len
= p
- body
;
6907 char *name
= copy_string (body
, name_len
);
6908 const char *replacement
;
6911 replacement
= body
+ name_len
+ 1;
6914 complain (&dwarf2_macro_malformed_definition
, body
);
6915 replacement
= body
+ name_len
;
6918 macro_define_object (file
, line
, name
, replacement
);
6924 /* It's a function-like macro. */
6925 char *name
= copy_string (body
, p
- body
);
6928 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
6932 p
= consume_improper_spaces (p
, body
);
6934 /* Parse the formal argument list. */
6935 while (*p
&& *p
!= ')')
6937 /* Find the extent of the current argument name. */
6938 const char *arg_start
= p
;
6940 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
6943 if (! *p
|| p
== arg_start
)
6944 complain (&dwarf2_macro_malformed_definition
,
6948 /* Make sure argv has room for the new argument. */
6949 if (argc
>= argv_size
)
6952 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
6955 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
6958 p
= consume_improper_spaces (p
, body
);
6960 /* Consume the comma, if present. */
6965 p
= consume_improper_spaces (p
, body
);
6974 /* Perfectly formed definition, no complaints. */
6975 macro_define_function (file
, line
, name
,
6976 argc
, (const char **) argv
,
6978 else if (*p
== '\0')
6980 /* Complain, but do define it. */
6981 complain (&dwarf2_macro_malformed_definition
, body
);
6982 macro_define_function (file
, line
, name
,
6983 argc
, (const char **) argv
,
6987 /* Just complain. */
6988 complain (&dwarf2_macro_malformed_definition
, body
);
6991 /* Just complain. */
6992 complain (&dwarf2_macro_malformed_definition
, body
);
6998 for (i
= 0; i
< argc
; i
++)
7004 complain (&dwarf2_macro_malformed_definition
, body
);
7009 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
7010 char *comp_dir
, bfd
*abfd
,
7011 const struct comp_unit_head
*cu_header
,
7012 struct objfile
*objfile
)
7014 char *mac_ptr
, *mac_end
;
7015 struct macro_source_file
*current_file
= 0;
7017 if (dwarf_macinfo_buffer
== NULL
)
7019 complain (&dwarf2_missing_macinfo_section
);
7023 mac_ptr
= dwarf_macinfo_buffer
+ offset
;
7024 mac_end
= dwarf_macinfo_buffer
+ dwarf_macinfo_size
;
7028 enum dwarf_macinfo_record_type macinfo_type
;
7030 /* Do we at least have room for a macinfo type byte? */
7031 if (mac_ptr
>= mac_end
)
7033 complain (&dwarf2_macros_too_long
);
7037 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
7040 switch (macinfo_type
)
7042 /* A zero macinfo type indicates the end of the macro
7047 case DW_MACINFO_define
:
7048 case DW_MACINFO_undef
:
7054 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7055 mac_ptr
+= bytes_read
;
7056 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
7057 mac_ptr
+= bytes_read
;
7060 complain (&dwarf2_macro_outside_file
,
7061 macinfo_type
== DW_MACINFO_define
? "definition" :
7062 macinfo_type
== DW_MACINFO_undef
? "undefinition" :
7063 "something-or-other",
7067 if (macinfo_type
== DW_MACINFO_define
)
7068 parse_macro_definition (current_file
, line
, body
);
7069 else if (macinfo_type
== DW_MACINFO_undef
)
7070 macro_undef (current_file
, line
, body
);
7075 case DW_MACINFO_start_file
:
7080 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7081 mac_ptr
+= bytes_read
;
7082 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7083 mac_ptr
+= bytes_read
;
7085 current_file
= macro_start_file (file
, line
,
7086 current_file
, comp_dir
,
7091 case DW_MACINFO_end_file
:
7093 complain (&dwarf2_macro_unmatched_end_file
);
7096 current_file
= current_file
->included_by
;
7099 enum dwarf_macinfo_record_type next_type
;
7101 /* GCC circa March 2002 doesn't produce the zero
7102 type byte marking the end of the compilation
7103 unit. Complain if it's not there, but exit no
7106 /* Do we at least have room for a macinfo type byte? */
7107 if (mac_ptr
>= mac_end
)
7109 complain (&dwarf2_macros_too_long
);
7113 /* We don't increment mac_ptr here, so this is just
7115 next_type
= read_1_byte (abfd
, mac_ptr
);
7117 complain (&dwarf2_macros_not_terminated
);
7124 case DW_MACINFO_vendor_ext
:
7130 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7131 mac_ptr
+= bytes_read
;
7132 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
7133 mac_ptr
+= bytes_read
;
7135 /* We don't recognize any vendor extensions. */
7142 /* Check if the attribute's form is a DW_FORM_block*
7143 if so return true else false. */
7145 attr_form_is_block (struct attribute
*attr
)
7147 return (attr
== NULL
? 0 :
7148 attr
->form
== DW_FORM_block1
7149 || attr
->form
== DW_FORM_block2
7150 || attr
->form
== DW_FORM_block4
7151 || attr
->form
== DW_FORM_block
);