1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
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 */
42 #include "complaints.h"
44 #include "dwarf2expr.h"
45 #include "dwarf2loc.h"
46 #include "cp-support.h"
49 #include "gdb_string.h"
50 #include "gdb_assert.h"
51 #include <sys/types.h>
53 #ifndef DWARF2_REG_TO_REGNUM
54 #define DWARF2_REG_TO_REGNUM(REG) (REG)
58 /* .debug_info header for a compilation unit
59 Because of alignment constraints, this structure has padding and cannot
60 be mapped directly onto the beginning of the .debug_info section. */
61 typedef struct comp_unit_header
63 unsigned int length
; /* length of the .debug_info
65 unsigned short version
; /* version number -- 2 for DWARF
67 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
68 unsigned char addr_size
; /* byte size of an address -- 4 */
71 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
74 /* .debug_pubnames header
75 Because of alignment constraints, this structure has padding and cannot
76 be mapped directly onto the beginning of the .debug_info section. */
77 typedef struct pubnames_header
79 unsigned int length
; /* length of the .debug_pubnames
81 unsigned char version
; /* version number -- 2 for DWARF
83 unsigned int info_offset
; /* offset into .debug_info section */
84 unsigned int info_size
; /* byte size of .debug_info section
88 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
90 /* .debug_pubnames header
91 Because of alignment constraints, this structure has padding and cannot
92 be mapped directly onto the beginning of the .debug_info section. */
93 typedef struct aranges_header
95 unsigned int length
; /* byte len of the .debug_aranges
97 unsigned short version
; /* version number -- 2 for DWARF
99 unsigned int info_offset
; /* offset into .debug_info section */
100 unsigned char addr_size
; /* byte size of an address */
101 unsigned char seg_size
; /* byte size of segment descriptor */
104 #define _ACTUAL_ARANGES_HEADER_SIZE 12
106 /* .debug_line statement program prologue
107 Because of alignment constraints, this structure has padding and cannot
108 be mapped directly onto the beginning of the .debug_info section. */
109 typedef struct statement_prologue
111 unsigned int total_length
; /* byte length of the statement
113 unsigned short version
; /* version number -- 2 for DWARF
115 unsigned int prologue_length
; /* # bytes between prologue &
117 unsigned char minimum_instruction_length
; /* byte size of
119 unsigned char default_is_stmt
; /* initial value of is_stmt
122 unsigned char line_range
;
123 unsigned char opcode_base
; /* number assigned to first special
125 unsigned char *standard_opcode_lengths
;
129 /* offsets and sizes of debugging sections */
131 static file_ptr dwarf_info_offset
;
132 static file_ptr dwarf_abbrev_offset
;
133 static file_ptr dwarf_line_offset
;
134 static file_ptr dwarf_pubnames_offset
;
135 static file_ptr dwarf_aranges_offset
;
136 static file_ptr dwarf_loc_offset
;
137 static file_ptr dwarf_macinfo_offset
;
138 static file_ptr dwarf_str_offset
;
139 static file_ptr dwarf_ranges_offset
;
140 file_ptr dwarf_frame_offset
;
141 file_ptr dwarf_eh_frame_offset
;
143 static unsigned int dwarf_info_size
;
144 static unsigned int dwarf_abbrev_size
;
145 static unsigned int dwarf_line_size
;
146 static unsigned int dwarf_pubnames_size
;
147 static unsigned int dwarf_aranges_size
;
148 static unsigned int dwarf_loc_size
;
149 static unsigned int dwarf_macinfo_size
;
150 static unsigned int dwarf_str_size
;
151 static unsigned int dwarf_ranges_size
;
152 unsigned int dwarf_frame_size
;
153 unsigned int dwarf_eh_frame_size
;
155 static asection
*dwarf_info_section
;
156 static asection
*dwarf_abbrev_section
;
157 static asection
*dwarf_line_section
;
158 static asection
*dwarf_pubnames_section
;
159 static asection
*dwarf_aranges_section
;
160 static asection
*dwarf_loc_section
;
161 static asection
*dwarf_macinfo_section
;
162 static asection
*dwarf_str_section
;
163 static asection
*dwarf_ranges_section
;
164 asection
*dwarf_frame_section
;
165 asection
*dwarf_eh_frame_section
;
167 /* names of the debugging sections */
169 #define INFO_SECTION ".debug_info"
170 #define ABBREV_SECTION ".debug_abbrev"
171 #define LINE_SECTION ".debug_line"
172 #define PUBNAMES_SECTION ".debug_pubnames"
173 #define ARANGES_SECTION ".debug_aranges"
174 #define LOC_SECTION ".debug_loc"
175 #define MACINFO_SECTION ".debug_macinfo"
176 #define STR_SECTION ".debug_str"
177 #define RANGES_SECTION ".debug_ranges"
178 #define FRAME_SECTION ".debug_frame"
179 #define EH_FRAME_SECTION ".eh_frame"
181 /* local data types */
183 /* We hold several abbreviation tables in memory at the same time. */
184 #ifndef ABBREV_HASH_SIZE
185 #define ABBREV_HASH_SIZE 121
188 /* The data in a compilation unit header, after target2host
189 translation, looks like this. */
190 struct comp_unit_head
192 unsigned long length
;
194 unsigned int abbrev_offset
;
195 unsigned char addr_size
;
196 unsigned char signed_addr_p
;
197 unsigned int offset_size
; /* size of file offsets; either 4 or 8 */
198 unsigned int initial_length_size
; /* size of the length field; either
201 /* Offset to the first byte of this compilation unit header in the
202 * .debug_info section, for resolving relative reference dies. */
206 /* Pointer to this compilation unit header in the .debug_info
211 /* Pointer to the first die of this compilatio unit. This will
212 * be the first byte following the compilation unit header. */
216 /* Pointer to the next compilation unit header in the program. */
218 struct comp_unit_head
*next
;
220 /* DWARF abbreviation table associated with this compilation unit */
222 struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
224 /* Base address of this compilation unit. */
226 CORE_ADDR base_address
;
228 /* Non-zero if base_address has been set. */
233 /* The line number information for a compilation unit (found in the
234 .debug_line section) begins with a "statement program header",
235 which contains the following information. */
238 unsigned int total_length
;
239 unsigned short version
;
240 unsigned int header_length
;
241 unsigned char minimum_instruction_length
;
242 unsigned char default_is_stmt
;
244 unsigned char line_range
;
245 unsigned char opcode_base
;
247 /* standard_opcode_lengths[i] is the number of operands for the
248 standard opcode whose value is i. This means that
249 standard_opcode_lengths[0] is unused, and the last meaningful
250 element is standard_opcode_lengths[opcode_base - 1]. */
251 unsigned char *standard_opcode_lengths
;
253 /* The include_directories table. NOTE! These strings are not
254 allocated with xmalloc; instead, they are pointers into
255 debug_line_buffer. If you try to free them, `free' will get
257 unsigned int num_include_dirs
, include_dirs_size
;
260 /* The file_names table. NOTE! These strings are not allocated
261 with xmalloc; instead, they are pointers into debug_line_buffer.
262 Don't try to free them directly. */
263 unsigned int num_file_names
, file_names_size
;
267 unsigned int dir_index
;
268 unsigned int mod_time
;
272 /* The start and end of the statement program following this
273 header. These point into dwarf_line_buffer. */
274 char *statement_program_start
, *statement_program_end
;
277 /* When we construct a partial symbol table entry we only
278 need this much information. */
279 struct partial_die_info
282 unsigned char has_children
;
283 unsigned char is_external
;
284 unsigned char is_declaration
;
285 unsigned char has_type
;
292 struct dwarf_block
*locdesc
;
293 unsigned int language
;
297 /* This data structure holds the information of an abbrev. */
300 unsigned int number
; /* number identifying abbrev */
301 enum dwarf_tag tag
; /* dwarf tag */
302 int has_children
; /* boolean */
303 unsigned int num_attrs
; /* number of attributes */
304 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
305 struct abbrev_info
*next
; /* next in chain */
310 enum dwarf_attribute name
;
311 enum dwarf_form form
;
314 /* This data structure holds a complete die structure. */
317 enum dwarf_tag tag
; /* Tag indicating type of die */
318 unsigned int abbrev
; /* Abbrev number */
319 unsigned int offset
; /* Offset in .debug_info section */
320 unsigned int num_attrs
; /* Number of attributes */
321 struct attribute
*attrs
; /* An array of attributes */
322 struct die_info
*next_ref
; /* Next die in ref hash table */
324 /* The dies in a compilation unit form an n-ary tree. PARENT
325 points to this die's parent; CHILD points to the first child of
326 this node; and all the children of a given node are chained
327 together via their SIBLING fields, terminated by a die whose
329 struct die_info
*child
; /* Its first child, if any. */
330 struct die_info
*sibling
; /* Its next sibling, if any. */
331 struct die_info
*parent
; /* Its parent, if any. */
333 struct type
*type
; /* Cached type information */
336 /* Attributes have a name and a value */
339 enum dwarf_attribute name
;
340 enum dwarf_form form
;
344 struct dwarf_block
*blk
;
352 struct function_range
355 CORE_ADDR lowpc
, highpc
;
357 struct function_range
*next
;
360 static struct function_range
*cu_first_fn
, *cu_last_fn
, *cu_cached_fn
;
362 /* Get at parts of an attribute structure */
364 #define DW_STRING(attr) ((attr)->u.str)
365 #define DW_UNSND(attr) ((attr)->u.unsnd)
366 #define DW_BLOCK(attr) ((attr)->u.blk)
367 #define DW_SND(attr) ((attr)->u.snd)
368 #define DW_ADDR(attr) ((attr)->u.addr)
370 /* Blocks are a bunch of untyped bytes. */
377 #ifndef ATTR_ALLOC_CHUNK
378 #define ATTR_ALLOC_CHUNK 4
381 /* A hash table of die offsets for following references. */
382 #ifndef REF_HASH_SIZE
383 #define REF_HASH_SIZE 1021
386 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
388 /* Obstack for allocating temporary storage used during symbol reading. */
389 static struct obstack dwarf2_tmp_obstack
;
391 /* Offset to the first byte of the current compilation unit header,
392 for resolving relative reference dies. */
393 static unsigned int cu_header_offset
;
395 /* Allocate fields for structs, unions and enums in this size. */
396 #ifndef DW_FIELD_ALLOC_CHUNK
397 #define DW_FIELD_ALLOC_CHUNK 4
400 /* The language we are debugging. */
401 static enum language cu_language
;
402 static const struct language_defn
*cu_language_defn
;
404 /* Actually data from the sections. */
405 static char *dwarf_info_buffer
;
406 static char *dwarf_abbrev_buffer
;
407 static char *dwarf_line_buffer
;
408 static char *dwarf_str_buffer
;
409 static char *dwarf_macinfo_buffer
;
410 static char *dwarf_ranges_buffer
;
411 static char *dwarf_loc_buffer
;
413 /* A zeroed version of a partial die for initialization purposes. */
414 static struct partial_die_info zeroed_partial_die
;
416 /* The generic symbol table building routines have separate lists for
417 file scope symbols and all all other scopes (local scopes). So
418 we need to select the right one to pass to add_symbol_to_list().
419 We do it by keeping a pointer to the correct list in list_in_scope.
421 FIXME: The original dwarf code just treated the file scope as the first
422 local scope, and all other local scopes as nested local scopes, and worked
423 fine. Check to see if we really need to distinguish these
425 static struct pending
**list_in_scope
= &file_symbols
;
427 /* FIXME: decode_locdesc sets these variables to describe the location
428 to the caller. These ought to be a structure or something. If
429 none of the flags are set, the object lives at the address returned
430 by decode_locdesc. */
432 static int optimized_out
; /* No ops in location in expression,
433 so object was optimized out. */
434 static int isreg
; /* Object lives in register.
435 decode_locdesc's return value is
436 the register number. */
437 static int offreg
; /* Object's address is the sum of the
438 register specified by basereg, plus
439 the offset returned. */
440 static int basereg
; /* See `offreg'. */
441 static int isderef
; /* Value described by flags above is
442 the address of a pointer to the object. */
443 static int islocal
; /* Variable is at the returned offset
444 from the frame start, but there's
445 no identified frame pointer for
446 this function, so we can't say
447 which register it's relative to;
450 /* DW_AT_frame_base values for the current function.
451 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
452 contains the register number for the frame register.
453 frame_base_offset is the offset from the frame register to the
454 virtual stack frame. */
455 static int frame_base_reg
;
456 static CORE_ADDR frame_base_offset
;
458 /* This value is added to each symbol value. FIXME: Generalize to
459 the section_offsets structure used by dbxread (once this is done,
460 pass the appropriate section number to end_symtab). */
461 static CORE_ADDR baseaddr
; /* Add to each symbol value */
463 /* We put a pointer to this structure in the read_symtab_private field
465 The complete dwarf information for an objfile is kept in the
466 psymbol_obstack, so that absolute die references can be handled.
467 Most of the information in this structure is related to an entire
468 object file and could be passed via the sym_private field of the objfile.
469 It is however conceivable that dwarf2 might not be the only type
470 of symbols read from an object file. */
474 /* Pointer to start of dwarf info buffer for the objfile. */
476 char *dwarf_info_buffer
;
478 /* Offset in dwarf_info_buffer for this compilation unit. */
480 unsigned long dwarf_info_offset
;
482 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
484 char *dwarf_abbrev_buffer
;
486 /* Size of dwarf abbreviation section for the objfile. */
488 unsigned int dwarf_abbrev_size
;
490 /* Pointer to start of dwarf line buffer for the objfile. */
492 char *dwarf_line_buffer
;
494 /* Size of dwarf_line_buffer, in bytes. */
496 unsigned int dwarf_line_size
;
498 /* Pointer to start of dwarf string buffer for the objfile. */
500 char *dwarf_str_buffer
;
502 /* Size of dwarf string section for the objfile. */
504 unsigned int dwarf_str_size
;
506 /* Pointer to start of dwarf macro buffer for the objfile. */
508 char *dwarf_macinfo_buffer
;
510 /* Size of dwarf macinfo section for the objfile. */
512 unsigned int dwarf_macinfo_size
;
514 /* Pointer to start of dwarf ranges buffer for the objfile. */
516 char *dwarf_ranges_buffer
;
518 /* Size of dwarf ranges buffer for the objfile. */
520 unsigned int dwarf_ranges_size
;
522 /* Pointer to start of dwarf locations buffer for the objfile. */
524 char *dwarf_loc_buffer
;
526 /* Size of dwarf locations buffer for the objfile. */
528 unsigned int dwarf_loc_size
;
531 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
532 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
533 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
534 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
535 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
536 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
537 #define DWARF_LINE_SIZE(p) (PST_PRIVATE(p)->dwarf_line_size)
538 #define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer)
539 #define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size)
540 #define DWARF_MACINFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_macinfo_buffer)
541 #define DWARF_MACINFO_SIZE(p) (PST_PRIVATE(p)->dwarf_macinfo_size)
542 #define DWARF_RANGES_BUFFER(p) (PST_PRIVATE(p)->dwarf_ranges_buffer)
543 #define DWARF_RANGES_SIZE(p) (PST_PRIVATE(p)->dwarf_ranges_size)
544 #define DWARF_LOC_BUFFER(p) (PST_PRIVATE(p)->dwarf_loc_buffer)
545 #define DWARF_LOC_SIZE(p) (PST_PRIVATE(p)->dwarf_loc_size)
547 /* Maintain an array of referenced fundamental types for the current
548 compilation unit being read. For DWARF version 1, we have to construct
549 the fundamental types on the fly, since no information about the
550 fundamental types is supplied. Each such fundamental type is created by
551 calling a language dependent routine to create the type, and then a
552 pointer to that type is then placed in the array at the index specified
553 by it's FT_<TYPENAME> value. The array has a fixed size set by the
554 FT_NUM_MEMBERS compile time constant, which is the number of predefined
555 fundamental types gdb knows how to construct. */
556 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
558 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
559 but this would require a corresponding change in unpack_field_as_long
561 static int bits_per_byte
= 8;
563 /* The routines that read and process dies for a C struct or C++ class
564 pass lists of data member fields and lists of member function fields
565 in an instance of a field_info structure, as defined below. */
568 /* List of data member and baseclasses fields. */
571 struct nextfield
*next
;
578 /* Number of fields. */
581 /* Number of baseclasses. */
584 /* Set if the accesibility of one of the fields is not public. */
585 int non_public_fields
;
587 /* Member function fields array, entries are allocated in the order they
588 are encountered in the object file. */
591 struct nextfnfield
*next
;
592 struct fn_field fnfield
;
596 /* Member function fieldlist array, contains name of possibly overloaded
597 member function, number of overloaded member functions and a pointer
598 to the head of the member function field chain. */
603 struct nextfnfield
*head
;
607 /* Number of entries in the fnfieldlists array. */
611 /* Various complaints about symbol reading that don't abort the process */
614 dwarf2_non_const_array_bound_ignored_complaint (const char *arg1
)
616 complaint (&symfile_complaints
, "non-constant array bounds form '%s' ignored",
621 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
623 complaint (&symfile_complaints
,
624 "statement list doesn't fit in .debug_line section");
628 dwarf2_complex_location_expr_complaint (void)
630 complaint (&symfile_complaints
, "location expression too complex");
634 dwarf2_unsupported_at_frame_base_complaint (const char *arg1
)
636 complaint (&symfile_complaints
,
637 "unsupported DW_AT_frame_base for function '%s'", arg1
);
641 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
644 complaint (&symfile_complaints
,
645 "const value length mismatch for '%s', got %d, expected %d", arg1
,
650 dwarf2_macros_too_long_complaint (void)
652 complaint (&symfile_complaints
,
653 "macro info runs off end of `.debug_macinfo' section");
657 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
659 complaint (&symfile_complaints
,
660 "macro debug info contains a malformed macro definition:\n`%s'",
665 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
667 complaint (&symfile_complaints
,
668 "invalid attribute class or form for '%s' in '%s'", arg1
, arg2
);
671 /* local function prototypes */
673 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
676 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
679 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
681 static char *scan_partial_symbols (char *, struct objfile
*,
682 CORE_ADDR
*, CORE_ADDR
*,
683 const struct comp_unit_head
*,
684 const char *namespace);
686 static void add_partial_symbol (struct partial_die_info
*, struct objfile
*,
687 const struct comp_unit_head
*,
688 const char *namespace);
690 static char *add_partial_namespace (struct partial_die_info
*pdi
,
692 struct objfile
*objfile
,
693 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
694 const struct comp_unit_head
*cu_header
,
695 const char *namespace);
697 static char *add_partial_enumeration (struct partial_die_info
*enum_pdi
,
699 struct objfile
*objfile
,
700 const struct comp_unit_head
*cu_header
,
701 const char *namespace);
703 static char *locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
706 const struct comp_unit_head
*cu_header
);
708 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
710 static void psymtab_to_symtab_1 (struct partial_symtab
*);
712 char *dwarf2_read_section (struct objfile
*, file_ptr
, unsigned int,
715 static void dwarf2_read_abbrevs (bfd
*abfd
, struct comp_unit_head
*cu_header
);
717 static void dwarf2_empty_abbrev_table (void *);
719 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
720 const struct comp_unit_head
*cu_header
);
722 static char *read_partial_die (struct partial_die_info
*,
724 const struct comp_unit_head
*);
726 static char *read_full_die (struct die_info
**, bfd
*, char *,
727 const struct comp_unit_head
*, int *);
729 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
730 bfd
*, char *, const struct comp_unit_head
*);
732 static char *read_attribute_value (struct attribute
*, unsigned,
733 bfd
*, char *, const struct comp_unit_head
*);
735 static unsigned int read_1_byte (bfd
*, char *);
737 static int read_1_signed_byte (bfd
*, char *);
739 static unsigned int read_2_bytes (bfd
*, char *);
741 static unsigned int read_4_bytes (bfd
*, char *);
743 static unsigned long read_8_bytes (bfd
*, char *);
745 static CORE_ADDR
read_address (bfd
*, char *ptr
, const struct comp_unit_head
*,
748 static LONGEST
read_initial_length (bfd
*, char *,
749 struct comp_unit_head
*, int *bytes_read
);
751 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
754 static char *read_n_bytes (bfd
*, char *, unsigned int);
756 static char *read_string (bfd
*, char *, unsigned int *);
758 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
761 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
763 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
765 static void set_cu_language (unsigned int);
767 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
769 static int die_is_declaration (struct die_info
*);
771 static void free_line_header (struct line_header
*lh
);
773 static struct line_header
*(dwarf_decode_line_header
774 (unsigned int offset
,
776 const struct comp_unit_head
*cu_header
));
778 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
779 const struct comp_unit_head
*);
781 static void dwarf2_start_subfile (char *, char *);
783 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
784 struct objfile
*, const struct comp_unit_head
*);
786 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
787 struct objfile
*, const struct comp_unit_head
*);
789 static void dwarf2_const_value_data (struct attribute
*attr
,
793 static struct type
*die_type (struct die_info
*, struct objfile
*,
794 const struct comp_unit_head
*);
796 static struct type
*die_containing_type (struct die_info
*, struct objfile
*,
797 const struct comp_unit_head
*);
800 static struct type
*type_at_offset (unsigned int, struct objfile
*);
803 static struct type
*tag_type_to_type (struct die_info
*, struct objfile
*,
804 const struct comp_unit_head
*);
806 static void read_type_die (struct die_info
*, struct objfile
*,
807 const struct comp_unit_head
*);
809 static void read_typedef (struct die_info
*, struct objfile
*,
810 const struct comp_unit_head
*);
812 static void read_base_type (struct die_info
*, struct objfile
*);
814 static void read_file_scope (struct die_info
*, struct objfile
*,
815 const struct comp_unit_head
*);
817 static void read_func_scope (struct die_info
*, struct objfile
*,
818 const struct comp_unit_head
*);
820 static void read_lexical_block_scope (struct die_info
*, struct objfile
*,
821 const struct comp_unit_head
*);
823 static int dwarf2_get_pc_bounds (struct die_info
*,
824 CORE_ADDR
*, CORE_ADDR
*, struct objfile
*,
825 const struct comp_unit_head
*);
827 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
828 struct objfile
*, const struct comp_unit_head
*);
830 static void dwarf2_attach_fields_to_type (struct field_info
*,
831 struct type
*, struct objfile
*);
833 static void dwarf2_add_member_fn (struct field_info
*,
834 struct die_info
*, struct type
*,
835 struct objfile
*objfile
,
836 const struct comp_unit_head
*);
838 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
839 struct type
*, struct objfile
*);
841 static void read_structure_scope (struct die_info
*, struct objfile
*,
842 const struct comp_unit_head
*);
844 static void read_common_block (struct die_info
*, struct objfile
*,
845 const struct comp_unit_head
*);
847 static void read_namespace (struct die_info
*die
, struct objfile
*objfile
,
848 const struct comp_unit_head
*cu_header
);
850 static void read_enumeration (struct die_info
*, struct objfile
*,
851 const struct comp_unit_head
*);
853 static struct type
*dwarf_base_type (int, int, struct objfile
*);
855 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct objfile
*,
856 const struct comp_unit_head
*);
858 static void read_array_type (struct die_info
*, struct objfile
*,
859 const struct comp_unit_head
*);
861 static void read_tag_pointer_type (struct die_info
*, struct objfile
*,
862 const struct comp_unit_head
*);
864 static void read_tag_ptr_to_member_type (struct die_info
*, struct objfile
*,
865 const struct comp_unit_head
*);
867 static void read_tag_reference_type (struct die_info
*, struct objfile
*,
868 const struct comp_unit_head
*);
870 static void read_tag_const_type (struct die_info
*, struct objfile
*,
871 const struct comp_unit_head
*);
873 static void read_tag_volatile_type (struct die_info
*, struct objfile
*,
874 const struct comp_unit_head
*);
876 static void read_tag_string_type (struct die_info
*, struct objfile
*);
878 static void read_subroutine_type (struct die_info
*, struct objfile
*,
879 const struct comp_unit_head
*);
881 static struct die_info
*read_comp_unit (char *, bfd
*,
882 const struct comp_unit_head
*);
884 static struct die_info
*read_die_and_children (char *info_ptr
, bfd
*abfd
,
885 const struct comp_unit_head
*,
887 struct die_info
*parent
);
889 static struct die_info
*read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
890 const struct comp_unit_head
*,
892 struct die_info
*parent
);
894 static void free_die_list (struct die_info
*);
896 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
898 static void process_die (struct die_info
*, struct objfile
*,
899 const struct comp_unit_head
*);
901 static char *dwarf2_linkage_name (struct die_info
*);
903 static char *dwarf2_name (struct die_info
*die
);
905 static struct die_info
*dwarf2_extension (struct die_info
*die
);
907 static char *dwarf_tag_name (unsigned int);
909 static char *dwarf_attr_name (unsigned int);
911 static char *dwarf_form_name (unsigned int);
913 static char *dwarf_stack_op_name (unsigned int);
915 static char *dwarf_bool_name (unsigned int);
917 static char *dwarf_type_encoding_name (unsigned int);
920 static char *dwarf_cfi_name (unsigned int);
922 struct die_info
*copy_die (struct die_info
*);
925 static struct die_info
*sibling_die (struct die_info
*);
927 static void dump_die (struct die_info
*);
929 static void dump_die_list (struct die_info
*);
931 static void store_in_ref_table (unsigned int, struct die_info
*);
933 static void dwarf2_empty_hash_tables (void);
935 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
937 static struct die_info
*follow_die_ref (unsigned int);
939 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
941 /* memory allocation interface */
943 static void dwarf2_free_tmp_obstack (void *);
945 static struct dwarf_block
*dwarf_alloc_block (void);
947 static struct abbrev_info
*dwarf_alloc_abbrev (void);
949 static struct die_info
*dwarf_alloc_die (void);
951 static void initialize_cu_func_list (void);
953 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
);
955 static void dwarf_decode_macros (struct line_header
*, unsigned int,
956 char *, bfd
*, const struct comp_unit_head
*,
959 static int attr_form_is_block (struct attribute
*);
962 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
963 const struct comp_unit_head
*,
964 struct objfile
*objfile
);
966 /* Try to locate the sections we need for DWARF 2 debugging
967 information and return true if we have enough to do something. */
970 dwarf2_has_info (bfd
*abfd
)
972 dwarf_info_offset
= 0;
973 dwarf_abbrev_offset
= 0;
974 dwarf_line_offset
= 0;
975 dwarf_str_offset
= 0;
976 dwarf_macinfo_offset
= 0;
977 dwarf_frame_offset
= 0;
978 dwarf_eh_frame_offset
= 0;
979 dwarf_ranges_offset
= 0;
980 dwarf_loc_offset
= 0;
982 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
983 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
993 /* This function is mapped across the sections and remembers the
994 offset and size of each of the debugging sections we are interested
998 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, void *ignore_ptr
)
1000 if (STREQ (sectp
->name
, INFO_SECTION
))
1002 dwarf_info_offset
= sectp
->filepos
;
1003 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
1004 dwarf_info_section
= sectp
;
1006 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
1008 dwarf_abbrev_offset
= sectp
->filepos
;
1009 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
1010 dwarf_abbrev_section
= sectp
;
1012 else if (STREQ (sectp
->name
, LINE_SECTION
))
1014 dwarf_line_offset
= sectp
->filepos
;
1015 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
1016 dwarf_line_section
= sectp
;
1018 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
1020 dwarf_pubnames_offset
= sectp
->filepos
;
1021 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
1022 dwarf_pubnames_section
= sectp
;
1024 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
1026 dwarf_aranges_offset
= sectp
->filepos
;
1027 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
1028 dwarf_aranges_section
= sectp
;
1030 else if (STREQ (sectp
->name
, LOC_SECTION
))
1032 dwarf_loc_offset
= sectp
->filepos
;
1033 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
1034 dwarf_loc_section
= sectp
;
1036 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
1038 dwarf_macinfo_offset
= sectp
->filepos
;
1039 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
1040 dwarf_macinfo_section
= sectp
;
1042 else if (STREQ (sectp
->name
, STR_SECTION
))
1044 dwarf_str_offset
= sectp
->filepos
;
1045 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
1046 dwarf_str_section
= sectp
;
1048 else if (STREQ (sectp
->name
, FRAME_SECTION
))
1050 dwarf_frame_offset
= sectp
->filepos
;
1051 dwarf_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1052 dwarf_frame_section
= sectp
;
1054 else if (STREQ (sectp
->name
, EH_FRAME_SECTION
))
1056 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1057 if (aflag
& SEC_HAS_CONTENTS
)
1059 dwarf_eh_frame_offset
= sectp
->filepos
;
1060 dwarf_eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1061 dwarf_eh_frame_section
= sectp
;
1064 else if (STREQ (sectp
->name
, RANGES_SECTION
))
1066 dwarf_ranges_offset
= sectp
->filepos
;
1067 dwarf_ranges_size
= bfd_get_section_size_before_reloc (sectp
);
1068 dwarf_ranges_section
= sectp
;
1072 /* Build a partial symbol table. */
1075 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1078 /* We definitely need the .debug_info and .debug_abbrev sections */
1080 dwarf_info_buffer
= dwarf2_read_section (objfile
,
1083 dwarf_info_section
);
1084 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
1085 dwarf_abbrev_offset
,
1087 dwarf_abbrev_section
);
1089 if (dwarf_line_offset
)
1090 dwarf_line_buffer
= dwarf2_read_section (objfile
,
1093 dwarf_line_section
);
1095 dwarf_line_buffer
= NULL
;
1097 if (dwarf_str_offset
)
1098 dwarf_str_buffer
= dwarf2_read_section (objfile
,
1103 dwarf_str_buffer
= NULL
;
1105 if (dwarf_macinfo_offset
)
1106 dwarf_macinfo_buffer
= dwarf2_read_section (objfile
,
1107 dwarf_macinfo_offset
,
1109 dwarf_macinfo_section
);
1111 dwarf_macinfo_buffer
= NULL
;
1113 if (dwarf_ranges_offset
)
1114 dwarf_ranges_buffer
= dwarf2_read_section (objfile
,
1115 dwarf_ranges_offset
,
1117 dwarf_ranges_section
);
1119 dwarf_ranges_buffer
= NULL
;
1121 if (dwarf_loc_offset
)
1122 dwarf_loc_buffer
= dwarf2_read_section (objfile
,
1127 dwarf_loc_buffer
= NULL
;
1130 || (objfile
->global_psymbols
.size
== 0
1131 && objfile
->static_psymbols
.size
== 0))
1133 init_psymbol_list (objfile
, 1024);
1137 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1139 /* Things are significantly easier if we have .debug_aranges and
1140 .debug_pubnames sections */
1142 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1146 /* only test this case for now */
1148 /* In this case we have to work a bit harder */
1149 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1154 /* Build the partial symbol table from the information in the
1155 .debug_pubnames and .debug_aranges sections. */
1158 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1160 bfd
*abfd
= objfile
->obfd
;
1161 char *aranges_buffer
, *pubnames_buffer
;
1162 char *aranges_ptr
, *pubnames_ptr
;
1163 unsigned int entry_length
, version
, info_offset
, info_size
;
1165 pubnames_buffer
= dwarf2_read_section (objfile
,
1166 dwarf_pubnames_offset
,
1167 dwarf_pubnames_size
,
1168 dwarf_pubnames_section
);
1169 pubnames_ptr
= pubnames_buffer
;
1170 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
1172 struct comp_unit_head cu_header
;
1175 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1177 pubnames_ptr
+= bytes_read
;
1178 version
= read_1_byte (abfd
, pubnames_ptr
);
1180 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1182 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1186 aranges_buffer
= dwarf2_read_section (objfile
,
1187 dwarf_aranges_offset
,
1189 dwarf_aranges_section
);
1194 /* Read in the comp unit header information from the debug_info at
1198 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1199 char *info_ptr
, bfd
*abfd
)
1203 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1205 info_ptr
+= bytes_read
;
1206 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1208 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1210 info_ptr
+= bytes_read
;
1211 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1213 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1214 if (signed_addr
< 0)
1215 internal_error (__FILE__
, __LINE__
,
1216 "read_comp_unit_head: dwarf from non elf file");
1217 cu_header
->signed_addr_p
= signed_addr
;
1221 /* Build the partial symbol table by doing a quick pass through the
1222 .debug_info and .debug_abbrev sections. */
1225 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1227 /* Instead of reading this into a big buffer, we should probably use
1228 mmap() on architectures that support it. (FIXME) */
1229 bfd
*abfd
= objfile
->obfd
;
1230 char *info_ptr
, *abbrev_ptr
;
1231 char *beg_of_comp_unit
;
1232 struct partial_die_info comp_unit_die
;
1233 struct partial_symtab
*pst
;
1234 struct cleanup
*back_to
;
1235 CORE_ADDR lowpc
, highpc
;
1237 info_ptr
= dwarf_info_buffer
;
1238 abbrev_ptr
= dwarf_abbrev_buffer
;
1240 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1241 the partial symbol scan, like attribute values.
1243 We could reduce our peak memory consumption during partial symbol
1244 table construction by freeing stuff from this obstack more often
1245 --- say, after processing each compilation unit, or each die ---
1246 but it turns out that this saves almost nothing. For an
1247 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1248 on dwarf2_tmp_obstack. Some investigation showed:
1250 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1251 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1252 all fixed-length values not requiring dynamic allocation.
1254 2) 30% of the attributes used the form DW_FORM_string. For
1255 DW_FORM_string, read_attribute simply hands back a pointer to
1256 the null-terminated string in dwarf_info_buffer, so no dynamic
1257 allocation is needed there either.
1259 3) The remaining 1% of the attributes all used DW_FORM_block1.
1260 75% of those were DW_AT_frame_base location lists for
1261 functions; the rest were DW_AT_location attributes, probably
1262 for the global variables.
1264 Anyway, what this all means is that the memory the dwarf2
1265 reader uses as temporary space reading partial symbols is about
1266 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1268 obstack_init (&dwarf2_tmp_obstack
);
1269 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1271 /* Since the objects we're extracting from dwarf_info_buffer vary in
1272 length, only the individual functions to extract them (like
1273 read_comp_unit_head and read_partial_die) can really know whether
1274 the buffer is large enough to hold another complete object.
1276 At the moment, they don't actually check that. If
1277 dwarf_info_buffer holds just one extra byte after the last
1278 compilation unit's dies, then read_comp_unit_head will happily
1279 read off the end of the buffer. read_partial_die is similarly
1280 casual. Those functions should be fixed.
1282 For this loop condition, simply checking whether there's any data
1283 left at all should be sufficient. */
1284 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1286 struct comp_unit_head cu_header
;
1287 beg_of_comp_unit
= info_ptr
;
1288 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1290 if (cu_header
.version
!= 2)
1292 error ("Dwarf Error: wrong version in compilation unit header (is %d, should be %d) [in module %s]", cu_header
.version
, 2, bfd_get_filename (abfd
));
1295 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
1297 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6) [in module %s]",
1298 (long) cu_header
.abbrev_offset
,
1299 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1300 bfd_get_filename (abfd
));
1303 if (beg_of_comp_unit
+ cu_header
.length
+ cu_header
.initial_length_size
1304 > dwarf_info_buffer
+ dwarf_info_size
)
1306 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0) [in module %s]",
1307 (long) cu_header
.length
,
1308 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1309 bfd_get_filename (abfd
));
1312 /* Complete the cu_header */
1313 cu_header
.offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1314 cu_header
.first_die_ptr
= info_ptr
;
1315 cu_header
.cu_head_ptr
= beg_of_comp_unit
;
1317 /* Read the abbrevs for this compilation unit into a table */
1318 dwarf2_read_abbrevs (abfd
, &cu_header
);
1319 make_cleanup (dwarf2_empty_abbrev_table
, cu_header
.dwarf2_abbrevs
);
1321 /* Read the compilation unit die */
1322 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1325 /* Set the language we're debugging */
1326 set_cu_language (comp_unit_die
.language
);
1328 /* Allocate a new partial symbol table structure */
1329 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1330 comp_unit_die
.name
? comp_unit_die
.name
: "",
1331 comp_unit_die
.lowpc
,
1332 objfile
->global_psymbols
.next
,
1333 objfile
->static_psymbols
.next
);
1335 pst
->read_symtab_private
= (char *)
1336 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1337 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1338 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1339 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1340 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1341 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1342 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1343 DWARF_LINE_SIZE (pst
) = dwarf_line_size
;
1344 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1345 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1346 DWARF_MACINFO_BUFFER (pst
) = dwarf_macinfo_buffer
;
1347 DWARF_MACINFO_SIZE (pst
) = dwarf_macinfo_size
;
1348 DWARF_RANGES_BUFFER (pst
) = dwarf_ranges_buffer
;
1349 DWARF_RANGES_SIZE (pst
) = dwarf_ranges_size
;
1350 DWARF_LOC_BUFFER (pst
) = dwarf_loc_buffer
;
1351 DWARF_LOC_SIZE (pst
) = dwarf_loc_size
;
1352 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1354 /* Store the function that reads in the rest of the symbol table */
1355 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1357 /* Check if comp unit has_children.
1358 If so, read the rest of the partial symbols from this comp unit.
1359 If not, there's no more debug_info for this comp unit. */
1360 if (comp_unit_die
.has_children
)
1362 lowpc
= ((CORE_ADDR
) -1);
1363 highpc
= ((CORE_ADDR
) 0);
1365 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
,
1368 /* If we didn't find a lowpc, set it to highpc to avoid
1369 complaints from `maint check'. */
1370 if (lowpc
== ((CORE_ADDR
) -1))
1373 /* If the compilation unit didn't have an explicit address range,
1374 then use the information extracted from its child dies. */
1375 if (! comp_unit_die
.has_pc_info
)
1377 comp_unit_die
.lowpc
= lowpc
;
1378 comp_unit_die
.highpc
= highpc
;
1381 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1382 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1384 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1385 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1386 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1387 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1388 sort_pst_symbols (pst
);
1390 /* If there is already a psymtab or symtab for a file of this
1391 name, remove it. (If there is a symtab, more drastic things
1392 also happen.) This happens in VxWorks. */
1393 free_named_symtabs (pst
->filename
);
1395 info_ptr
= beg_of_comp_unit
+ cu_header
.length
1396 + cu_header
.initial_length_size
;
1398 do_cleanups (back_to
);
1401 /* Read in all interesting dies to the end of the compilation unit or
1402 to the end of the current namespace. NAMESPACE is NULL if we
1403 haven't yet encountered any DW_TAG_namespace entries; otherwise,
1404 it's the name of the current namespace. In particular, it's the
1405 empty string if we're currently in the global namespace but have
1406 previously encountered a DW_TAG_namespace. */
1409 scan_partial_symbols (char *info_ptr
, struct objfile
*objfile
,
1410 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1411 const struct comp_unit_head
*cu_header
,
1412 const char *namespace)
1414 bfd
*abfd
= objfile
->obfd
;
1415 struct partial_die_info pdi
;
1417 /* Now, march along the PDI's, descending into ones which have
1418 interesting children but skipping the children of the other ones,
1419 until we reach the end of the compilation unit. */
1423 /* This flag tells whether or not info_ptr has gotten updated
1425 int info_ptr_updated
= 0;
1427 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu_header
);
1429 /* Anonymous namespaces have no name but have interesting
1430 children, so we need to look at them. Ditto for anonymous
1433 if (pdi
.name
!= NULL
|| pdi
.tag
== DW_TAG_namespace
1434 || pdi
.tag
== DW_TAG_enumeration_type
)
1438 case DW_TAG_subprogram
:
1439 if (pdi
.has_pc_info
)
1441 if (pdi
.lowpc
< *lowpc
)
1445 if (pdi
.highpc
> *highpc
)
1447 *highpc
= pdi
.highpc
;
1449 if (!pdi
.is_declaration
)
1451 add_partial_symbol (&pdi
, objfile
, cu_header
, namespace);
1455 case DW_TAG_variable
:
1456 case DW_TAG_typedef
:
1457 case DW_TAG_union_type
:
1458 case DW_TAG_class_type
:
1459 case DW_TAG_structure_type
:
1460 if (!pdi
.is_declaration
)
1462 add_partial_symbol (&pdi
, objfile
, cu_header
, namespace);
1465 case DW_TAG_enumeration_type
:
1466 if (!pdi
.is_declaration
)
1468 info_ptr
= add_partial_enumeration (&pdi
, info_ptr
,
1471 info_ptr_updated
= 1;
1474 case DW_TAG_base_type
:
1475 /* File scope base type definitions are added to the partial
1477 add_partial_symbol (&pdi
, objfile
, cu_header
, namespace);
1479 case DW_TAG_namespace
:
1480 /* We've hit a DW_TAG_namespace entry, so we know this
1481 file has been compiled using a compiler that
1482 generates them; update NAMESPACE to reflect that. */
1483 if (namespace == NULL
)
1485 info_ptr
= add_partial_namespace (&pdi
, info_ptr
, objfile
,
1486 lowpc
, highpc
, cu_header
,
1488 info_ptr_updated
= 1;
1498 /* If the die has a sibling, skip to the sibling, unless another
1499 function has already updated info_ptr for us. */
1501 /* NOTE: carlton/2003-06-16: This is a bit hackish, but whether
1502 or not we want to update this depends on enough stuff (not
1503 only pdi.tag but also whether or not pdi.name is NULL) that
1504 this seems like the easiest way to handle the issue. */
1506 if (!info_ptr_updated
)
1507 info_ptr
= locate_pdi_sibling (&pdi
, info_ptr
, abfd
, cu_header
);
1514 add_partial_symbol (struct partial_die_info
*pdi
, struct objfile
*objfile
,
1515 const struct comp_unit_head
*cu_header
,
1516 const char *namespace)
1519 const struct partial_symbol
*psym
= NULL
;
1523 case DW_TAG_subprogram
:
1524 if (pdi
->is_external
)
1526 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1527 mst_text, objfile); */
1528 psym
= add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1529 VAR_DOMAIN
, LOC_BLOCK
,
1530 &objfile
->global_psymbols
,
1531 0, pdi
->lowpc
+ baseaddr
,
1532 cu_language
, objfile
);
1536 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1537 mst_file_text, objfile); */
1538 psym
= add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1539 VAR_DOMAIN
, LOC_BLOCK
,
1540 &objfile
->static_psymbols
,
1541 0, pdi
->lowpc
+ baseaddr
,
1542 cu_language
, objfile
);
1545 case DW_TAG_variable
:
1546 if (pdi
->is_external
)
1549 Don't enter into the minimal symbol tables as there is
1550 a minimal symbol table entry from the ELF symbols already.
1551 Enter into partial symbol table if it has a location
1552 descriptor or a type.
1553 If the location descriptor is missing, new_symbol will create
1554 a LOC_UNRESOLVED symbol, the address of the variable will then
1555 be determined from the minimal symbol table whenever the variable
1557 The address for the partial symbol table entry is not
1558 used by GDB, but it comes in handy for debugging partial symbol
1562 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1563 if (pdi
->locdesc
|| pdi
->has_type
)
1564 psym
= add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1565 VAR_DOMAIN
, LOC_STATIC
,
1566 &objfile
->global_psymbols
,
1568 cu_language
, objfile
);
1572 /* Static Variable. Skip symbols without location descriptors. */
1573 if (pdi
->locdesc
== NULL
)
1575 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1576 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1577 mst_file_data, objfile); */
1578 psym
= add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1579 VAR_DOMAIN
, LOC_STATIC
,
1580 &objfile
->static_psymbols
,
1582 cu_language
, objfile
);
1585 case DW_TAG_typedef
:
1586 case DW_TAG_base_type
:
1587 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1588 VAR_DOMAIN
, LOC_TYPEDEF
,
1589 &objfile
->static_psymbols
,
1590 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1592 case DW_TAG_class_type
:
1593 case DW_TAG_structure_type
:
1594 case DW_TAG_union_type
:
1595 case DW_TAG_enumeration_type
:
1596 /* Skip aggregate types without children, these are external
1598 if (pdi
->has_children
== 0)
1600 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1601 STRUCT_DOMAIN
, LOC_TYPEDEF
,
1602 &objfile
->static_psymbols
,
1603 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1605 if (cu_language
== language_cplus
)
1607 /* For C++, these implicitly act as typedefs as well. */
1608 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1609 VAR_DOMAIN
, LOC_TYPEDEF
,
1610 &objfile
->static_psymbols
,
1611 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1614 case DW_TAG_enumerator
:
1615 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1616 VAR_DOMAIN
, LOC_CONST
,
1617 &objfile
->static_psymbols
,
1618 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1624 /* Check to see if we should scan the name for possible namespace
1625 info. Only do this if this is C++, if we don't have namespace
1626 debugging info in the file, if the psym is of an appropriate type
1627 (otherwise we'll have psym == NULL), and if we actually had a
1628 mangled name to begin with. */
1630 if (cu_language
== language_cplus
1631 && namespace == NULL
1633 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
1634 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
1638 /* Read a partial die corresponding to a namespace; also, add a symbol
1639 corresponding to that namespace to the symbol table. NAMESPACE is
1640 the name of the enclosing namespace. */
1643 add_partial_namespace (struct partial_die_info
*pdi
, char *info_ptr
,
1644 struct objfile
*objfile
,
1645 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1646 const struct comp_unit_head
*cu_header
,
1647 const char *namespace)
1649 /* Calculate the full name of the namespace that we just entered. */
1651 const char *new_name
= pdi
->name
;
1654 if (new_name
== NULL
)
1655 new_name
= "(anonymous namespace)";
1656 full_name
= alloca (strlen (namespace) + 2 + strlen (new_name
) + 1);
1657 strcpy (full_name
, namespace);
1658 if (*namespace != '\0')
1659 strcat (full_name
, "::");
1660 strcat (full_name
, new_name
);
1662 /* FIXME: carlton/2003-06-27: Once we build qualified names for more
1663 symbols than just namespaces, we should replace this by a call to
1664 add_partial_symbol. */
1666 add_psymbol_to_list (full_name
, strlen (full_name
),
1667 VAR_DOMAIN
, LOC_TYPEDEF
,
1668 &objfile
->global_psymbols
,
1669 0, 0, cu_language
, objfile
);
1671 /* Now scan partial symbols in that namespace. */
1673 if (pdi
->has_children
)
1674 info_ptr
= scan_partial_symbols (info_ptr
, objfile
,
1676 cu_header
, full_name
);
1681 /* Read a partial die corresponding to an enumeration type. */
1684 add_partial_enumeration (struct partial_die_info
*enum_pdi
, char *info_ptr
,
1685 struct objfile
*objfile
,
1686 const struct comp_unit_head
*cu_header
,
1687 const char *namespace)
1689 bfd
*abfd
= objfile
->obfd
;
1690 struct partial_die_info pdi
;
1692 if (enum_pdi
->name
!= NULL
)
1693 add_partial_symbol (enum_pdi
, objfile
, cu_header
, namespace);
1697 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu_header
);
1700 if (pdi
.tag
!= DW_TAG_enumerator
|| pdi
.name
== NULL
)
1701 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
1703 add_partial_symbol (&pdi
, objfile
, cu_header
, namespace);
1709 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the next DIE
1713 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, char *info_ptr
,
1714 bfd
*abfd
, const struct comp_unit_head
*cu_header
)
1716 /* Do we know the sibling already? */
1718 if (orig_pdi
->sibling
)
1719 return orig_pdi
->sibling
;
1721 /* Are there any children to deal with? */
1723 if (!orig_pdi
->has_children
)
1726 /* Okay, we don't know the sibling, but we have children that we
1727 want to skip. So read children until we run into one without a
1728 tag; return whatever follows it. */
1732 struct partial_die_info pdi
;
1734 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu_header
);
1739 info_ptr
= locate_pdi_sibling (&pdi
, info_ptr
, abfd
, cu_header
);
1743 /* Expand this partial symbol table into a full symbol table. */
1746 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1748 /* FIXME: This is barely more than a stub. */
1753 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1759 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1760 gdb_flush (gdb_stdout
);
1763 psymtab_to_symtab_1 (pst
);
1765 /* Finish up the debug error message. */
1767 printf_filtered ("done.\n");
1773 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1775 struct objfile
*objfile
= pst
->objfile
;
1776 bfd
*abfd
= objfile
->obfd
;
1777 struct comp_unit_head cu_header
;
1778 struct die_info
*dies
;
1779 unsigned long offset
;
1780 CORE_ADDR lowpc
, highpc
;
1781 struct die_info
*child_die
;
1783 struct symtab
*symtab
;
1784 struct cleanup
*back_to
;
1785 struct attribute
*attr
;
1787 /* Set local variables from the partial symbol table info. */
1788 offset
= DWARF_INFO_OFFSET (pst
);
1789 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1790 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1791 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1792 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1793 dwarf_line_size
= DWARF_LINE_SIZE (pst
);
1794 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1795 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1796 dwarf_macinfo_buffer
= DWARF_MACINFO_BUFFER (pst
);
1797 dwarf_macinfo_size
= DWARF_MACINFO_SIZE (pst
);
1798 dwarf_ranges_buffer
= DWARF_RANGES_BUFFER (pst
);
1799 dwarf_ranges_size
= DWARF_RANGES_SIZE (pst
);
1800 dwarf_loc_buffer
= DWARF_LOC_BUFFER (pst
);
1801 dwarf_loc_size
= DWARF_LOC_SIZE (pst
);
1802 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1803 cu_header_offset
= offset
;
1804 info_ptr
= dwarf_info_buffer
+ offset
;
1806 obstack_init (&dwarf2_tmp_obstack
);
1807 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1810 make_cleanup (really_free_pendings
, NULL
);
1812 /* read in the comp_unit header */
1813 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1815 /* Read the abbrevs for this compilation unit */
1816 dwarf2_read_abbrevs (abfd
, &cu_header
);
1817 make_cleanup (dwarf2_empty_abbrev_table
, cu_header
.dwarf2_abbrevs
);
1819 dies
= read_comp_unit (info_ptr
, abfd
, &cu_header
);
1821 make_cleanup_free_die_list (dies
);
1823 /* Find the base address of the compilation unit for range lists and
1824 location lists. It will normally be specified by DW_AT_low_pc.
1825 In DWARF-3 draft 4, the base address could be overridden by
1826 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1827 compilation units with discontinuous ranges. */
1829 cu_header
.base_known
= 0;
1830 cu_header
.base_address
= 0;
1832 attr
= dwarf_attr (dies
, DW_AT_entry_pc
);
1835 cu_header
.base_address
= DW_ADDR (attr
);
1836 cu_header
.base_known
= 1;
1840 attr
= dwarf_attr (dies
, DW_AT_low_pc
);
1843 cu_header
.base_address
= DW_ADDR (attr
);
1844 cu_header
.base_known
= 1;
1848 /* Do line number decoding in read_file_scope () */
1849 process_die (dies
, objfile
, &cu_header
);
1851 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
, &cu_header
))
1853 /* Some compilers don't define a DW_AT_high_pc attribute for
1854 the compilation unit. If the DW_AT_high_pc is missing,
1855 synthesize it, by scanning the DIE's below the compilation unit. */
1857 if (dies
->child
!= NULL
)
1859 child_die
= dies
->child
;
1860 while (child_die
&& child_die
->tag
)
1862 if (child_die
->tag
== DW_TAG_subprogram
)
1864 CORE_ADDR low
, high
;
1866 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
,
1867 objfile
, &cu_header
))
1869 highpc
= max (highpc
, high
);
1872 child_die
= sibling_die (child_die
);
1876 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1878 /* Set symtab language to language from DW_AT_language.
1879 If the compilation is from a C file generated by language preprocessors,
1880 do not set the language if it was already deduced by start_subfile. */
1882 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1884 symtab
->language
= cu_language
;
1886 pst
->symtab
= symtab
;
1889 do_cleanups (back_to
);
1892 /* Process a die and its children. */
1895 process_die (struct die_info
*die
, struct objfile
*objfile
,
1896 const struct comp_unit_head
*cu_header
)
1900 case DW_TAG_padding
:
1902 case DW_TAG_compile_unit
:
1903 read_file_scope (die
, objfile
, cu_header
);
1905 case DW_TAG_subprogram
:
1906 read_subroutine_type (die
, objfile
, cu_header
);
1907 read_func_scope (die
, objfile
, cu_header
);
1909 case DW_TAG_inlined_subroutine
:
1910 /* FIXME: These are ignored for now.
1911 They could be used to set breakpoints on all inlined instances
1912 of a function and make GDB `next' properly over inlined functions. */
1914 case DW_TAG_lexical_block
:
1915 case DW_TAG_try_block
:
1916 case DW_TAG_catch_block
:
1917 read_lexical_block_scope (die
, objfile
, cu_header
);
1919 case DW_TAG_class_type
:
1920 case DW_TAG_structure_type
:
1921 case DW_TAG_union_type
:
1922 read_structure_scope (die
, objfile
, cu_header
);
1924 case DW_TAG_enumeration_type
:
1925 read_enumeration (die
, objfile
, cu_header
);
1927 case DW_TAG_subroutine_type
:
1928 read_subroutine_type (die
, objfile
, cu_header
);
1930 case DW_TAG_array_type
:
1931 read_array_type (die
, objfile
, cu_header
);
1933 case DW_TAG_pointer_type
:
1934 read_tag_pointer_type (die
, objfile
, cu_header
);
1936 case DW_TAG_ptr_to_member_type
:
1937 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
1939 case DW_TAG_reference_type
:
1940 read_tag_reference_type (die
, objfile
, cu_header
);
1942 case DW_TAG_string_type
:
1943 read_tag_string_type (die
, objfile
);
1945 case DW_TAG_base_type
:
1946 read_base_type (die
, objfile
);
1947 if (dwarf_attr (die
, DW_AT_name
))
1949 /* Add a typedef symbol for the base type definition. */
1950 new_symbol (die
, die
->type
, objfile
, cu_header
);
1953 case DW_TAG_common_block
:
1954 read_common_block (die
, objfile
, cu_header
);
1956 case DW_TAG_common_inclusion
:
1958 case DW_TAG_namespace
:
1959 if (!processing_has_namespace_info
)
1961 processing_has_namespace_info
= 1;
1962 processing_current_namespace
= "";
1964 read_namespace (die
, objfile
, cu_header
);
1966 case DW_TAG_imported_declaration
:
1967 case DW_TAG_imported_module
:
1968 /* FIXME: carlton/2002-10-16: Eventually, we should use the
1969 information contained in these. DW_TAG_imported_declaration
1970 dies shouldn't have children; DW_TAG_imported_module dies
1971 shouldn't in the C++ case, but conceivably could in the
1972 Fortran case, so we'll have to replace this gdb_assert if
1973 Fortran compilers start generating that info. */
1974 if (!processing_has_namespace_info
)
1976 processing_has_namespace_info
= 1;
1977 processing_current_namespace
= "";
1979 gdb_assert (die
->child
== NULL
);
1982 new_symbol (die
, NULL
, objfile
, cu_header
);
1988 initialize_cu_func_list (void)
1990 cu_first_fn
= cu_last_fn
= cu_cached_fn
= NULL
;
1994 read_file_scope (struct die_info
*die
, struct objfile
*objfile
,
1995 const struct comp_unit_head
*cu_header
)
1997 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
1998 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1999 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2000 struct attribute
*attr
;
2001 char *name
= "<unknown>";
2002 char *comp_dir
= NULL
;
2003 struct die_info
*child_die
;
2004 bfd
*abfd
= objfile
->obfd
;
2005 struct line_header
*line_header
= 0;
2007 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
, cu_header
))
2009 if (die
->child
!= NULL
)
2011 child_die
= die
->child
;
2012 while (child_die
&& child_die
->tag
)
2014 if (child_die
->tag
== DW_TAG_subprogram
)
2016 CORE_ADDR low
, high
;
2018 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
,
2019 objfile
, cu_header
))
2021 lowpc
= min (lowpc
, low
);
2022 highpc
= max (highpc
, high
);
2025 child_die
= sibling_die (child_die
);
2030 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2031 from finish_block. */
2032 if (lowpc
== ((CORE_ADDR
) -1))
2037 attr
= dwarf_attr (die
, DW_AT_name
);
2040 name
= DW_STRING (attr
);
2042 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
2045 comp_dir
= DW_STRING (attr
);
2048 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2049 directory, get rid of it. */
2050 char *cp
= strchr (comp_dir
, ':');
2052 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2057 if (objfile
->ei
.entry_point
>= lowpc
&&
2058 objfile
->ei
.entry_point
< highpc
)
2060 objfile
->ei
.deprecated_entry_file_lowpc
= lowpc
;
2061 objfile
->ei
.deprecated_entry_file_highpc
= highpc
;
2064 attr
= dwarf_attr (die
, DW_AT_language
);
2067 set_cu_language (DW_UNSND (attr
));
2070 /* We assume that we're processing GCC output. */
2071 processing_gcc_compilation
= 2;
2073 /* FIXME:Do something here. */
2074 if (dip
->at_producer
!= NULL
)
2076 handle_producer (dip
->at_producer
);
2080 /* The compilation unit may be in a different language or objfile,
2081 zero out all remembered fundamental types. */
2082 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
2084 start_symtab (name
, comp_dir
, lowpc
);
2085 record_debugformat ("DWARF 2");
2087 initialize_cu_func_list ();
2089 /* Process all dies in compilation unit. */
2090 if (die
->child
!= NULL
)
2092 child_die
= die
->child
;
2093 while (child_die
&& child_die
->tag
)
2095 process_die (child_die
, objfile
, cu_header
);
2096 child_die
= sibling_die (child_die
);
2100 /* Decode line number information if present. */
2101 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
2104 unsigned int line_offset
= DW_UNSND (attr
);
2105 line_header
= dwarf_decode_line_header (line_offset
,
2109 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
2110 (void *) line_header
);
2111 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu_header
);
2115 /* Decode macro information, if present. Dwarf 2 macro information
2116 refers to information in the line number info statement program
2117 header, so we can only read it if we've read the header
2119 attr
= dwarf_attr (die
, DW_AT_macro_info
);
2120 if (attr
&& line_header
)
2122 unsigned int macro_offset
= DW_UNSND (attr
);
2123 dwarf_decode_macros (line_header
, macro_offset
,
2124 comp_dir
, abfd
, cu_header
, objfile
);
2126 do_cleanups (back_to
);
2130 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
)
2132 struct function_range
*thisfn
;
2134 thisfn
= (struct function_range
*)
2135 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct function_range
));
2136 thisfn
->name
= name
;
2137 thisfn
->lowpc
= lowpc
;
2138 thisfn
->highpc
= highpc
;
2139 thisfn
->seen_line
= 0;
2140 thisfn
->next
= NULL
;
2142 if (cu_last_fn
== NULL
)
2143 cu_first_fn
= thisfn
;
2145 cu_last_fn
->next
= thisfn
;
2147 cu_last_fn
= thisfn
;
2151 read_func_scope (struct die_info
*die
, struct objfile
*objfile
,
2152 const struct comp_unit_head
*cu_header
)
2154 struct context_stack
*new;
2157 struct die_info
*child_die
;
2158 struct attribute
*attr
;
2161 name
= dwarf2_linkage_name (die
);
2163 /* Ignore functions with missing or empty names and functions with
2164 missing or invalid low and high pc attributes. */
2165 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
, cu_header
))
2171 /* Record the function range for dwarf_decode_lines. */
2172 add_to_cu_func_list (name
, lowpc
, highpc
);
2174 if (objfile
->ei
.entry_point
>= lowpc
&&
2175 objfile
->ei
.entry_point
< highpc
)
2177 objfile
->ei
.entry_func_lowpc
= lowpc
;
2178 objfile
->ei
.entry_func_highpc
= highpc
;
2181 /* Decode DW_AT_frame_base location descriptor if present, keep result
2182 for DW_OP_fbreg operands in decode_locdesc. */
2183 frame_base_reg
= -1;
2184 frame_base_offset
= 0;
2185 attr
= dwarf_attr (die
, DW_AT_frame_base
);
2190 /* Support the .debug_loc offsets */
2191 if (attr_form_is_block (attr
))
2193 addr
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2195 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
2197 dwarf2_complex_location_expr_complaint ();
2202 dwarf2_invalid_attrib_class_complaint ("DW_AT_frame_base", name
);
2207 dwarf2_unsupported_at_frame_base_complaint (name
);
2209 frame_base_reg
= addr
;
2212 frame_base_reg
= basereg
;
2213 frame_base_offset
= addr
;
2216 dwarf2_unsupported_at_frame_base_complaint (name
);
2219 new = push_context (0, lowpc
);
2220 new->name
= new_symbol (die
, die
->type
, objfile
, cu_header
);
2222 /* If there was a location expression for DW_AT_frame_base above,
2223 record it. We still need to decode it above because not all
2224 symbols use location expressions exclusively. */
2226 dwarf2_symbol_mark_computed (attr
, new->name
, cu_header
, objfile
);
2228 list_in_scope
= &local_symbols
;
2230 if (die
->child
!= NULL
)
2232 child_die
= die
->child
;
2233 while (child_die
&& child_die
->tag
)
2235 process_die (child_die
, objfile
, cu_header
);
2236 child_die
= sibling_die (child_die
);
2240 new = pop_context ();
2241 /* Make a block for the local symbols within. */
2242 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2243 lowpc
, highpc
, objfile
);
2245 /* In C++, we can have functions nested inside functions (e.g., when
2246 a function declares a class that has methods). This means that
2247 when we finish processing a function scope, we may need to go
2248 back to building a containing block's symbol lists. */
2249 local_symbols
= new->locals
;
2250 param_symbols
= new->params
;
2252 /* If we've finished processing a top-level function, subsequent
2253 symbols go in the file symbol list. */
2254 if (outermost_context_p ())
2255 list_in_scope
= &file_symbols
;
2258 /* Process all the DIES contained within a lexical block scope. Start
2259 a new scope, process the dies, and then close the scope. */
2262 read_lexical_block_scope (struct die_info
*die
, struct objfile
*objfile
,
2263 const struct comp_unit_head
*cu_header
)
2265 struct context_stack
*new;
2266 CORE_ADDR lowpc
, highpc
;
2267 struct die_info
*child_die
;
2269 /* Ignore blocks with missing or invalid low and high pc attributes. */
2270 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2271 as multiple lexical blocks? Handling children in a sane way would
2272 be nasty. Might be easier to properly extend generic blocks to
2274 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
, cu_header
))
2279 push_context (0, lowpc
);
2280 if (die
->child
!= NULL
)
2282 child_die
= die
->child
;
2283 while (child_die
&& child_die
->tag
)
2285 process_die (child_die
, objfile
, cu_header
);
2286 child_die
= sibling_die (child_die
);
2289 new = pop_context ();
2291 if (local_symbols
!= NULL
)
2293 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
2296 local_symbols
= new->locals
;
2299 /* Get low and high pc attributes from a die. Return 1 if the attributes
2300 are present and valid, otherwise, return 0. Return -1 if the range is
2301 discontinuous, i.e. derived from DW_AT_ranges information. */
2303 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
2304 CORE_ADDR
*highpc
, struct objfile
*objfile
,
2305 const struct comp_unit_head
*cu_header
)
2307 struct attribute
*attr
;
2308 bfd
*obfd
= objfile
->obfd
;
2313 attr
= dwarf_attr (die
, DW_AT_high_pc
);
2316 high
= DW_ADDR (attr
);
2317 attr
= dwarf_attr (die
, DW_AT_low_pc
);
2319 low
= DW_ADDR (attr
);
2321 /* Found high w/o low attribute. */
2324 /* Found consecutive range of addresses. */
2329 attr
= dwarf_attr (die
, DW_AT_ranges
);
2332 unsigned int addr_size
= cu_header
->addr_size
;
2333 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
2334 /* Value of the DW_AT_ranges attribute is the offset in the
2335 .debug_ranges section. */
2336 unsigned int offset
= DW_UNSND (attr
);
2337 /* Base address selection entry. */
2346 found_base
= cu_header
->base_known
;
2347 base
= cu_header
->base_address
;
2349 if (offset
>= dwarf_ranges_size
)
2351 complaint (&symfile_complaints
,
2352 "Offset %d out of bounds for DW_AT_ranges attribute",
2356 buffer
= dwarf_ranges_buffer
+ offset
;
2358 /* Read in the largest possible address. */
2359 marker
= read_address (obfd
, buffer
, cu_header
, &dummy
);
2360 if ((marker
& mask
) == mask
)
2362 /* If we found the largest possible address, then
2363 read the base address. */
2364 base
= read_address (obfd
, buffer
+ addr_size
,
2366 buffer
+= 2 * addr_size
;
2367 offset
+= 2 * addr_size
;
2375 CORE_ADDR range_beginning
, range_end
;
2377 range_beginning
= read_address (obfd
, buffer
,
2379 buffer
+= addr_size
;
2380 range_end
= read_address (obfd
, buffer
, cu_header
, &dummy
);
2381 buffer
+= addr_size
;
2382 offset
+= 2 * addr_size
;
2384 /* An end of list marker is a pair of zero addresses. */
2385 if (range_beginning
== 0 && range_end
== 0)
2386 /* Found the end of list entry. */
2389 /* Each base address selection entry is a pair of 2 values.
2390 The first is the largest possible address, the second is
2391 the base address. Check for a base address here. */
2392 if ((range_beginning
& mask
) == mask
)
2394 /* If we found the largest possible address, then
2395 read the base address. */
2396 base
= read_address (obfd
, buffer
+ addr_size
,
2404 /* We have no valid base address for the ranges
2406 complaint (&symfile_complaints
,
2407 "Invalid .debug_ranges data (no base address)");
2411 range_beginning
+= base
;
2414 /* FIXME: This is recording everything as a low-high
2415 segment of consecutive addresses. We should have a
2416 data structure for discontiguous block ranges
2420 low
= range_beginning
;
2426 if (range_beginning
< low
)
2427 low
= range_beginning
;
2428 if (range_end
> high
)
2434 /* If the first entry is an end-of-list marker, the range
2435 describes an empty scope, i.e. no instructions. */
2445 /* When using the GNU linker, .gnu.linkonce. sections are used to
2446 eliminate duplicate copies of functions and vtables and such.
2447 The linker will arbitrarily choose one and discard the others.
2448 The AT_*_pc values for such functions refer to local labels in
2449 these sections. If the section from that file was discarded, the
2450 labels are not in the output, so the relocs get a value of 0.
2451 If this is a discarded function, mark the pc bounds as invalid,
2452 so that GDB will ignore it. */
2453 if (low
== 0 && (bfd_get_file_flags (obfd
) & HAS_RELOC
) == 0)
2461 /* Add an aggregate field to the field list. */
2464 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
2465 struct objfile
*objfile
,
2466 const struct comp_unit_head
*cu_header
)
2468 struct nextfield
*new_field
;
2469 struct attribute
*attr
;
2471 char *fieldname
= "";
2473 /* Allocate a new field list entry and link it in. */
2474 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2475 make_cleanup (xfree
, new_field
);
2476 memset (new_field
, 0, sizeof (struct nextfield
));
2477 new_field
->next
= fip
->fields
;
2478 fip
->fields
= new_field
;
2481 /* Handle accessibility and virtuality of field.
2482 The default accessibility for members is public, the default
2483 accessibility for inheritance is private. */
2484 if (die
->tag
!= DW_TAG_inheritance
)
2485 new_field
->accessibility
= DW_ACCESS_public
;
2487 new_field
->accessibility
= DW_ACCESS_private
;
2488 new_field
->virtuality
= DW_VIRTUALITY_none
;
2490 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2492 new_field
->accessibility
= DW_UNSND (attr
);
2493 if (new_field
->accessibility
!= DW_ACCESS_public
)
2494 fip
->non_public_fields
= 1;
2495 attr
= dwarf_attr (die
, DW_AT_virtuality
);
2497 new_field
->virtuality
= DW_UNSND (attr
);
2499 fp
= &new_field
->field
;
2501 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
))
2503 /* Data member other than a C++ static data member. */
2505 /* Get type of field. */
2506 fp
->type
= die_type (die
, objfile
, cu_header
);
2508 FIELD_STATIC_KIND (*fp
) = 0;
2510 /* Get bit size of field (zero if none). */
2511 attr
= dwarf_attr (die
, DW_AT_bit_size
);
2514 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
2518 FIELD_BITSIZE (*fp
) = 0;
2521 /* Get bit offset of field. */
2522 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2525 FIELD_BITPOS (*fp
) =
2526 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) * bits_per_byte
;
2529 FIELD_BITPOS (*fp
) = 0;
2530 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
2533 if (BITS_BIG_ENDIAN
)
2535 /* For big endian bits, the DW_AT_bit_offset gives the
2536 additional bit offset from the MSB of the containing
2537 anonymous object to the MSB of the field. We don't
2538 have to do anything special since we don't need to
2539 know the size of the anonymous object. */
2540 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
2544 /* For little endian bits, compute the bit offset to the
2545 MSB of the anonymous object, subtract off the number of
2546 bits from the MSB of the field to the MSB of the
2547 object, and then subtract off the number of bits of
2548 the field itself. The result is the bit offset of
2549 the LSB of the field. */
2551 int bit_offset
= DW_UNSND (attr
);
2553 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2556 /* The size of the anonymous object containing
2557 the bit field is explicit, so use the
2558 indicated size (in bytes). */
2559 anonymous_size
= DW_UNSND (attr
);
2563 /* The size of the anonymous object containing
2564 the bit field must be inferred from the type
2565 attribute of the data member containing the
2567 anonymous_size
= TYPE_LENGTH (fp
->type
);
2569 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2570 - bit_offset
- FIELD_BITSIZE (*fp
);
2574 /* Get name of field. */
2575 attr
= dwarf_attr (die
, DW_AT_name
);
2576 if (attr
&& DW_STRING (attr
))
2577 fieldname
= DW_STRING (attr
);
2578 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
2579 &objfile
->type_obstack
);
2581 /* Change accessibility for artificial fields (e.g. virtual table
2582 pointer or virtual base class pointer) to private. */
2583 if (dwarf_attr (die
, DW_AT_artificial
))
2585 new_field
->accessibility
= DW_ACCESS_private
;
2586 fip
->non_public_fields
= 1;
2589 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
2591 /* C++ static member. */
2593 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2594 is a declaration, but all versions of G++ as of this writing
2595 (so through at least 3.2.1) incorrectly generate
2596 DW_TAG_variable tags. */
2600 /* Get name of field. */
2601 attr
= dwarf_attr (die
, DW_AT_name
);
2602 if (attr
&& DW_STRING (attr
))
2603 fieldname
= DW_STRING (attr
);
2607 /* Get physical name. */
2608 physname
= dwarf2_linkage_name (die
);
2610 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
2611 &objfile
->type_obstack
));
2612 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
2613 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
2614 &objfile
->type_obstack
);
2616 else if (die
->tag
== DW_TAG_inheritance
)
2618 /* C++ base class field. */
2619 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2621 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
)
2623 FIELD_BITSIZE (*fp
) = 0;
2624 FIELD_STATIC_KIND (*fp
) = 0;
2625 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
2626 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2627 fip
->nbaseclasses
++;
2631 /* Create the vector of fields, and attach it to the type. */
2634 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
2635 struct objfile
*objfile
)
2637 int nfields
= fip
->nfields
;
2639 /* Record the field count, allocate space for the array of fields,
2640 and create blank accessibility bitfields if necessary. */
2641 TYPE_NFIELDS (type
) = nfields
;
2642 TYPE_FIELDS (type
) = (struct field
*)
2643 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2644 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2646 if (fip
->non_public_fields
)
2648 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2650 TYPE_FIELD_PRIVATE_BITS (type
) =
2651 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2652 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2654 TYPE_FIELD_PROTECTED_BITS (type
) =
2655 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2656 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2658 TYPE_FIELD_IGNORE_BITS (type
) =
2659 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2660 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2663 /* If the type has baseclasses, allocate and clear a bit vector for
2664 TYPE_FIELD_VIRTUAL_BITS. */
2665 if (fip
->nbaseclasses
)
2667 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2670 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2671 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2672 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2673 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2674 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2677 /* Copy the saved-up fields into the field vector. Start from the head
2678 of the list, adding to the tail of the field array, so that they end
2679 up in the same order in the array in which they were added to the list. */
2680 while (nfields
-- > 0)
2682 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2683 switch (fip
->fields
->accessibility
)
2685 case DW_ACCESS_private
:
2686 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2689 case DW_ACCESS_protected
:
2690 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2693 case DW_ACCESS_public
:
2697 /* Unknown accessibility. Complain and treat it as public. */
2699 complaint (&symfile_complaints
, "unsupported accessibility %d",
2700 fip
->fields
->accessibility
);
2704 if (nfields
< fip
->nbaseclasses
)
2706 switch (fip
->fields
->virtuality
)
2708 case DW_VIRTUALITY_virtual
:
2709 case DW_VIRTUALITY_pure_virtual
:
2710 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2714 fip
->fields
= fip
->fields
->next
;
2718 /* Add a member function to the proper fieldlist. */
2721 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2722 struct type
*type
, struct objfile
*objfile
,
2723 const struct comp_unit_head
*cu_header
)
2725 struct attribute
*attr
;
2726 struct fnfieldlist
*flp
;
2728 struct fn_field
*fnp
;
2731 struct nextfnfield
*new_fnfield
;
2733 /* Get name of member function. */
2734 attr
= dwarf_attr (die
, DW_AT_name
);
2735 if (attr
&& DW_STRING (attr
))
2736 fieldname
= DW_STRING (attr
);
2740 /* Get the mangled name. */
2741 physname
= dwarf2_linkage_name (die
);
2743 /* Look up member function name in fieldlist. */
2744 for (i
= 0; i
< fip
->nfnfields
; i
++)
2746 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2750 /* Create new list element if necessary. */
2751 if (i
< fip
->nfnfields
)
2752 flp
= &fip
->fnfieldlists
[i
];
2755 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2757 fip
->fnfieldlists
= (struct fnfieldlist
*)
2758 xrealloc (fip
->fnfieldlists
,
2759 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2760 * sizeof (struct fnfieldlist
));
2761 if (fip
->nfnfields
== 0)
2762 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2764 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2765 flp
->name
= fieldname
;
2771 /* Create a new member function field and chain it to the field list
2773 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2774 make_cleanup (xfree
, new_fnfield
);
2775 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2776 new_fnfield
->next
= flp
->head
;
2777 flp
->head
= new_fnfield
;
2780 /* Fill in the member function field info. */
2781 fnp
= &new_fnfield
->fnfield
;
2782 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2783 &objfile
->type_obstack
);
2784 fnp
->type
= alloc_type (objfile
);
2785 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2787 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2788 int nparams
= TYPE_NFIELDS (die
->type
);
2790 /* TYPE is the domain of this method, and DIE->TYPE is the type
2791 of the method itself (TYPE_CODE_METHOD). */
2792 smash_to_method_type (fnp
->type
, type
,
2793 TYPE_TARGET_TYPE (die
->type
),
2794 TYPE_FIELDS (die
->type
),
2795 TYPE_NFIELDS (die
->type
),
2796 TYPE_VARARGS (die
->type
));
2798 /* Handle static member functions.
2799 Dwarf2 has no clean way to discern C++ static and non-static
2800 member functions. G++ helps GDB by marking the first
2801 parameter for non-static member functions (which is the
2802 this pointer) as artificial. We obtain this information
2803 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2804 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2805 fnp
->voffset
= VOFFSET_STATIC
;
2808 complaint (&symfile_complaints
, "member function type missing for '%s'",
2811 /* Get fcontext from DW_AT_containing_type if present. */
2812 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2813 fnp
->fcontext
= die_containing_type (die
, objfile
, cu_header
);
2815 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2816 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2818 /* Get accessibility. */
2819 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2822 switch (DW_UNSND (attr
))
2824 case DW_ACCESS_private
:
2825 fnp
->is_private
= 1;
2827 case DW_ACCESS_protected
:
2828 fnp
->is_protected
= 1;
2833 /* Check for artificial methods. */
2834 attr
= dwarf_attr (die
, DW_AT_artificial
);
2835 if (attr
&& DW_UNSND (attr
) != 0)
2836 fnp
->is_artificial
= 1;
2838 /* Get index in virtual function table if it is a virtual member function. */
2839 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2842 /* Support the .debug_loc offsets */
2843 if (attr_form_is_block (attr
))
2845 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) + 2;
2847 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
2849 dwarf2_complex_location_expr_complaint ();
2853 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
2859 /* Create the vector of member function fields, and attach it to the type. */
2862 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2863 struct objfile
*objfile
)
2865 struct fnfieldlist
*flp
;
2866 int total_length
= 0;
2869 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2870 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2871 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2873 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2875 struct nextfnfield
*nfp
= flp
->head
;
2876 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2879 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2880 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2881 fn_flp
->fn_fields
= (struct fn_field
*)
2882 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2883 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2884 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2886 total_length
+= flp
->length
;
2889 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2890 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2893 /* Called when we find the DIE that starts a structure or union scope
2894 (definition) to process all dies that define the members of the
2897 NOTE: we need to call struct_type regardless of whether or not the
2898 DIE has an at_name attribute, since it might be an anonymous
2899 structure or union. This gets the type entered into our set of
2902 However, if the structure is incomplete (an opaque struct/union)
2903 then suppress creating a symbol table entry for it since gdb only
2904 wants to find the one with the complete definition. Note that if
2905 it is complete, we just call new_symbol, which does it's own
2906 checking about whether the struct/union is anonymous or not (and
2907 suppresses creating a symbol table entry itself). */
2910 read_structure_scope (struct die_info
*die
, struct objfile
*objfile
,
2911 const struct comp_unit_head
*cu_header
)
2914 struct attribute
*attr
;
2916 type
= alloc_type (objfile
);
2918 INIT_CPLUS_SPECIFIC (type
);
2919 attr
= dwarf_attr (die
, DW_AT_name
);
2920 if (attr
&& DW_STRING (attr
))
2922 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2923 strlen (DW_STRING (attr
)),
2924 &objfile
->type_obstack
);
2927 if (die
->tag
== DW_TAG_structure_type
)
2929 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2931 else if (die
->tag
== DW_TAG_union_type
)
2933 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2937 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2939 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2942 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2945 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2949 TYPE_LENGTH (type
) = 0;
2952 /* We need to add the type field to the die immediately so we don't
2953 infinitely recurse when dealing with pointers to the structure
2954 type within the structure itself. */
2957 if (die
->child
!= NULL
&& ! die_is_declaration (die
))
2959 struct field_info fi
;
2960 struct die_info
*child_die
;
2961 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2963 memset (&fi
, 0, sizeof (struct field_info
));
2965 child_die
= die
->child
;
2967 while (child_die
&& child_die
->tag
)
2969 if (child_die
->tag
== DW_TAG_member
2970 || child_die
->tag
== DW_TAG_variable
)
2972 /* NOTE: carlton/2002-11-05: A C++ static data member
2973 should be a DW_TAG_member that is a declaration, but
2974 all versions of G++ as of this writing (so through at
2975 least 3.2.1) incorrectly generate DW_TAG_variable
2976 tags for them instead. */
2977 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2979 else if (child_die
->tag
== DW_TAG_subprogram
)
2981 /* C++ member function. */
2982 process_die (child_die
, objfile
, cu_header
);
2983 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
, cu_header
);
2985 else if (child_die
->tag
== DW_TAG_inheritance
)
2987 /* C++ base class field. */
2988 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2992 process_die (child_die
, objfile
, cu_header
);
2994 child_die
= sibling_die (child_die
);
2997 /* Attach fields and member functions to the type. */
2999 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
3002 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
3004 /* Get the type which refers to the base class (possibly this
3005 class itself) which contains the vtable pointer for the current
3006 class from the DW_AT_containing_type attribute. */
3008 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
3010 struct type
*t
= die_containing_type (die
, objfile
, cu_header
);
3012 TYPE_VPTR_BASETYPE (type
) = t
;
3015 static const char vptr_name
[] =
3016 {'_', 'v', 'p', 't', 'r', '\0'};
3019 /* Our own class provides vtbl ptr. */
3020 for (i
= TYPE_NFIELDS (t
) - 1;
3021 i
>= TYPE_N_BASECLASSES (t
);
3024 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
3026 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
3027 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
3029 TYPE_VPTR_FIELDNO (type
) = i
;
3034 /* Complain if virtual function table field not found. */
3035 if (i
< TYPE_N_BASECLASSES (t
))
3036 complaint (&symfile_complaints
,
3037 "virtual function table pointer not found when defining class '%s'",
3038 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
3043 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3048 new_symbol (die
, type
, objfile
, cu_header
);
3050 do_cleanups (back_to
);
3054 /* No children, must be stub. */
3055 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
3059 /* Given a pointer to a die which begins an enumeration, process all
3060 the dies that define the members of the enumeration.
3062 This will be much nicer in draft 6 of the DWARF spec when our
3063 members will be dies instead squished into the DW_AT_element_list
3066 NOTE: We reverse the order of the element list. */
3069 read_enumeration (struct die_info
*die
, struct objfile
*objfile
,
3070 const struct comp_unit_head
*cu_header
)
3072 struct die_info
*child_die
;
3074 struct field
*fields
;
3075 struct attribute
*attr
;
3078 int unsigned_enum
= 1;
3080 type
= alloc_type (objfile
);
3082 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
3083 attr
= dwarf_attr (die
, DW_AT_name
);
3084 if (attr
&& DW_STRING (attr
))
3086 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
3087 strlen (DW_STRING (attr
)),
3088 &objfile
->type_obstack
);
3091 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3094 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3098 TYPE_LENGTH (type
) = 0;
3103 if (die
->child
!= NULL
)
3105 child_die
= die
->child
;
3106 while (child_die
&& child_die
->tag
)
3108 if (child_die
->tag
!= DW_TAG_enumerator
)
3110 process_die (child_die
, objfile
, cu_header
);
3114 attr
= dwarf_attr (child_die
, DW_AT_name
);
3117 sym
= new_symbol (child_die
, type
, objfile
, cu_header
);
3118 if (SYMBOL_VALUE (sym
) < 0)
3121 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3123 fields
= (struct field
*)
3125 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
3126 * sizeof (struct field
));
3129 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
3130 FIELD_TYPE (fields
[num_fields
]) = NULL
;
3131 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
3132 FIELD_BITSIZE (fields
[num_fields
]) = 0;
3133 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
3139 child_die
= sibling_die (child_die
);
3144 TYPE_NFIELDS (type
) = num_fields
;
3145 TYPE_FIELDS (type
) = (struct field
*)
3146 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
3147 memcpy (TYPE_FIELDS (type
), fields
,
3148 sizeof (struct field
) * num_fields
);
3152 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
3155 new_symbol (die
, type
, objfile
, cu_header
);
3158 /* Extract all information from a DW_TAG_array_type DIE and put it in
3159 the DIE's type field. For now, this only handles one dimensional
3163 read_array_type (struct die_info
*die
, struct objfile
*objfile
,
3164 const struct comp_unit_head
*cu_header
)
3166 struct die_info
*child_die
;
3167 struct type
*type
= NULL
;
3168 struct type
*element_type
, *range_type
, *index_type
;
3169 struct type
**range_types
= NULL
;
3170 struct attribute
*attr
;
3172 struct cleanup
*back_to
;
3174 /* Return if we've already decoded this type. */
3180 element_type
= die_type (die
, objfile
, cu_header
);
3182 /* Irix 6.2 native cc creates array types without children for
3183 arrays with unspecified length. */
3184 if (die
->child
== NULL
)
3186 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
3187 range_type
= create_range_type (NULL
, index_type
, 0, -1);
3188 die
->type
= create_array_type (NULL
, element_type
, range_type
);
3192 back_to
= make_cleanup (null_cleanup
, NULL
);
3193 child_die
= die
->child
;
3194 while (child_die
&& child_die
->tag
)
3196 if (child_die
->tag
== DW_TAG_subrange_type
)
3198 unsigned int low
, high
;
3200 /* Default bounds to an array with unspecified length. */
3203 if (cu_language
== language_fortran
)
3205 /* FORTRAN implies a lower bound of 1, if not given. */
3209 index_type
= die_type (child_die
, objfile
, cu_header
);
3210 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
3213 if (attr
->form
== DW_FORM_sdata
)
3215 low
= DW_SND (attr
);
3217 else if (attr
->form
== DW_FORM_udata
3218 || attr
->form
== DW_FORM_data1
3219 || attr
->form
== DW_FORM_data2
3220 || attr
->form
== DW_FORM_data4
3221 || attr
->form
== DW_FORM_data8
)
3223 low
= DW_UNSND (attr
);
3227 dwarf2_non_const_array_bound_ignored_complaint
3228 (dwarf_form_name (attr
->form
));
3230 die
->type
= lookup_pointer_type (element_type
);
3237 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
3240 if (attr
->form
== DW_FORM_sdata
)
3242 high
= DW_SND (attr
);
3244 else if (attr
->form
== DW_FORM_udata
3245 || attr
->form
== DW_FORM_data1
3246 || attr
->form
== DW_FORM_data2
3247 || attr
->form
== DW_FORM_data4
3248 || attr
->form
== DW_FORM_data8
)
3250 high
= DW_UNSND (attr
);
3252 else if (attr
->form
== DW_FORM_block1
)
3254 /* GCC encodes arrays with unspecified or dynamic length
3255 with a DW_FORM_block1 attribute.
3256 FIXME: GDB does not yet know how to handle dynamic
3257 arrays properly, treat them as arrays with unspecified
3260 FIXME: jimb/2003-09-22: GDB does not really know
3261 how to handle arrays of unspecified length
3262 either; we just represent them as zero-length
3263 arrays. Choose an appropriate upper bound given
3264 the lower bound we've computed above. */
3269 dwarf2_non_const_array_bound_ignored_complaint
3270 (dwarf_form_name (attr
->form
));
3272 die
->type
= lookup_pointer_type (element_type
);
3280 /* Create a range type and save it for array type creation. */
3281 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
3283 range_types
= (struct type
**)
3284 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
3285 * sizeof (struct type
*));
3287 make_cleanup (free_current_contents
, &range_types
);
3289 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
3291 child_die
= sibling_die (child_die
);
3294 /* Dwarf2 dimensions are output from left to right, create the
3295 necessary array types in backwards order. */
3296 type
= element_type
;
3298 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
3300 /* Understand Dwarf2 support for vector types (like they occur on
3301 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3302 array type. This is not part of the Dwarf2/3 standard yet, but a
3303 custom vendor extension. The main difference between a regular
3304 array and the vector variant is that vectors are passed by value
3306 attr
= dwarf_attr (die
, DW_AT_GNU_vector
);
3308 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
3310 do_cleanups (back_to
);
3312 /* Install the type in the die. */
3316 /* First cut: install each common block member as a global variable. */
3319 read_common_block (struct die_info
*die
, struct objfile
*objfile
,
3320 const struct comp_unit_head
*cu_header
)
3322 struct die_info
*child_die
;
3323 struct attribute
*attr
;
3325 CORE_ADDR base
= (CORE_ADDR
) 0;
3327 attr
= dwarf_attr (die
, DW_AT_location
);
3330 /* Support the .debug_loc offsets */
3331 if (attr_form_is_block (attr
))
3333 base
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
3335 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3337 dwarf2_complex_location_expr_complaint ();
3341 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3342 "common block member");
3345 if (die
->child
!= NULL
)
3347 child_die
= die
->child
;
3348 while (child_die
&& child_die
->tag
)
3350 sym
= new_symbol (child_die
, NULL
, objfile
, cu_header
);
3351 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
3354 SYMBOL_VALUE_ADDRESS (sym
) =
3355 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
3356 add_symbol_to_list (sym
, &global_symbols
);
3358 child_die
= sibling_die (child_die
);
3363 /* Read a C++ namespace. */
3366 read_namespace (struct die_info
*die
, struct objfile
*objfile
,
3367 const struct comp_unit_head
*cu_header
)
3369 const char *previous_namespace
= processing_current_namespace
;
3370 const char *name
= NULL
;
3372 struct die_info
*current_die
;
3374 /* Loop through the extensions until we find a name. */
3376 for (current_die
= die
;
3377 current_die
!= NULL
;
3378 current_die
= dwarf2_extension (die
))
3380 name
= dwarf2_name (current_die
);
3385 /* Is it an anonymous namespace? */
3387 is_anonymous
= (name
== NULL
);
3389 name
= "(anonymous namespace)";
3391 /* Now build the name of the current namespace. */
3393 if (previous_namespace
[0] == '\0')
3395 processing_current_namespace
= name
;
3399 /* We need temp_name around because processing_current_namespace
3400 is a const char *. */
3401 char *temp_name
= alloca (strlen (previous_namespace
)
3402 + 2 + strlen(name
) + 1);
3403 strcpy (temp_name
, previous_namespace
);
3404 strcat (temp_name
, "::");
3405 strcat (temp_name
, name
);
3407 processing_current_namespace
= temp_name
;
3410 /* Add a symbol associated to this if we haven't seen the namespace
3411 before. Also, add a using directive if it's an anonymous
3414 if (dwarf2_extension (die
) == NULL
)
3418 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
3419 this cast will hopefully become unnecessary. */
3420 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
3421 (char *) processing_current_namespace
,
3423 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
3425 new_symbol (die
, type
, objfile
, cu_header
);
3428 cp_add_using_directive (processing_current_namespace
,
3429 strlen (previous_namespace
),
3430 strlen (processing_current_namespace
));
3433 if (die
->child
!= NULL
)
3435 struct die_info
*child_die
= die
->child
;
3437 while (child_die
&& child_die
->tag
)
3439 process_die (child_die
, objfile
, cu_header
);
3440 child_die
= sibling_die (child_die
);
3444 processing_current_namespace
= previous_namespace
;
3447 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3448 the user defined type vector. */
3451 read_tag_pointer_type (struct die_info
*die
, struct objfile
*objfile
,
3452 const struct comp_unit_head
*cu_header
)
3455 struct attribute
*attr_byte_size
;
3456 struct attribute
*attr_address_class
;
3457 int byte_size
, addr_class
;
3464 type
= lookup_pointer_type (die_type (die
, objfile
, cu_header
));
3466 attr_byte_size
= dwarf_attr (die
, DW_AT_byte_size
);
3468 byte_size
= DW_UNSND (attr_byte_size
);
3470 byte_size
= cu_header
->addr_size
;
3472 attr_address_class
= dwarf_attr (die
, DW_AT_address_class
);
3473 if (attr_address_class
)
3474 addr_class
= DW_UNSND (attr_address_class
);
3476 addr_class
= DW_ADDR_none
;
3478 /* If the pointer size or address class is different than the
3479 default, create a type variant marked as such and set the
3480 length accordingly. */
3481 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
3483 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3487 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
3488 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
3489 type
= make_type_with_address_space (type
, type_flags
);
3491 else if (TYPE_LENGTH (type
) != byte_size
)
3493 complaint (&symfile_complaints
, "invalid pointer size %d", byte_size
);
3496 /* Should we also complain about unhandled address classes? */
3500 TYPE_LENGTH (type
) = byte_size
;
3504 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3505 the user defined type vector. */
3508 read_tag_ptr_to_member_type (struct die_info
*die
, struct objfile
*objfile
,
3509 const struct comp_unit_head
*cu_header
)
3512 struct type
*to_type
;
3513 struct type
*domain
;
3520 type
= alloc_type (objfile
);
3521 to_type
= die_type (die
, objfile
, cu_header
);
3522 domain
= die_containing_type (die
, objfile
, cu_header
);
3523 smash_to_member_type (type
, domain
, to_type
);
3528 /* Extract all information from a DW_TAG_reference_type DIE and add to
3529 the user defined type vector. */
3532 read_tag_reference_type (struct die_info
*die
, struct objfile
*objfile
,
3533 const struct comp_unit_head
*cu_header
)
3536 struct attribute
*attr
;
3543 type
= lookup_reference_type (die_type (die
, objfile
, cu_header
));
3544 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3547 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3551 TYPE_LENGTH (type
) = cu_header
->addr_size
;
3557 read_tag_const_type (struct die_info
*die
, struct objfile
*objfile
,
3558 const struct comp_unit_head
*cu_header
)
3560 struct type
*base_type
;
3567 base_type
= die_type (die
, objfile
, cu_header
);
3568 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
3572 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
3573 const struct comp_unit_head
*cu_header
)
3575 struct type
*base_type
;
3582 base_type
= die_type (die
, objfile
, cu_header
);
3583 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
3586 /* Extract all information from a DW_TAG_string_type DIE and add to
3587 the user defined type vector. It isn't really a user defined type,
3588 but it behaves like one, with other DIE's using an AT_user_def_type
3589 attribute to reference it. */
3592 read_tag_string_type (struct die_info
*die
, struct objfile
*objfile
)
3594 struct type
*type
, *range_type
, *index_type
, *char_type
;
3595 struct attribute
*attr
;
3596 unsigned int length
;
3603 attr
= dwarf_attr (die
, DW_AT_string_length
);
3606 length
= DW_UNSND (attr
);
3610 /* check for the DW_AT_byte_size attribute */
3611 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3614 length
= DW_UNSND (attr
);
3621 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
3622 range_type
= create_range_type (NULL
, index_type
, 1, length
);
3623 if (cu_language
== language_fortran
)
3625 /* Need to create a unique string type for bounds
3627 type
= create_string_type (0, range_type
);
3631 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
3632 type
= create_string_type (char_type
, range_type
);
3637 /* Handle DIES due to C code like:
3641 int (*funcp)(int a, long l);
3645 ('funcp' generates a DW_TAG_subroutine_type DIE)
3649 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
3650 const struct comp_unit_head
*cu_header
)
3652 struct type
*type
; /* Type that this function returns */
3653 struct type
*ftype
; /* Function that returns above type */
3654 struct attribute
*attr
;
3656 /* Decode the type that this subroutine returns */
3661 type
= die_type (die
, objfile
, cu_header
);
3662 ftype
= lookup_function_type (type
);
3664 /* All functions in C++ have prototypes. */
3665 attr
= dwarf_attr (die
, DW_AT_prototyped
);
3666 if ((attr
&& (DW_UNSND (attr
) != 0))
3667 || cu_language
== language_cplus
)
3668 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
3670 if (die
->child
!= NULL
)
3672 struct die_info
*child_die
;
3676 /* Count the number of parameters.
3677 FIXME: GDB currently ignores vararg functions, but knows about
3678 vararg member functions. */
3679 child_die
= die
->child
;
3680 while (child_die
&& child_die
->tag
)
3682 if (child_die
->tag
== DW_TAG_formal_parameter
)
3684 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
3685 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
3686 child_die
= sibling_die (child_die
);
3689 /* Allocate storage for parameters and fill them in. */
3690 TYPE_NFIELDS (ftype
) = nparams
;
3691 TYPE_FIELDS (ftype
) = (struct field
*)
3692 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
3694 child_die
= die
->child
;
3695 while (child_die
&& child_die
->tag
)
3697 if (child_die
->tag
== DW_TAG_formal_parameter
)
3699 /* Dwarf2 has no clean way to discern C++ static and non-static
3700 member functions. G++ helps GDB by marking the first
3701 parameter for non-static member functions (which is the
3702 this pointer) as artificial. We pass this information
3703 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
3704 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
3706 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
3708 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
3709 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
3713 child_die
= sibling_die (child_die
);
3721 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
3722 const struct comp_unit_head
*cu_header
)
3724 struct attribute
*attr
;
3729 attr
= dwarf_attr (die
, DW_AT_name
);
3730 if (attr
&& DW_STRING (attr
))
3732 name
= DW_STRING (attr
);
3734 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
3735 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, objfile
, cu_header
);
3739 /* Find a representation of a given base type and install
3740 it in the TYPE field of the die. */
3743 read_base_type (struct die_info
*die
, struct objfile
*objfile
)
3746 struct attribute
*attr
;
3747 int encoding
= 0, size
= 0;
3749 /* If we've already decoded this die, this is a no-op. */
3755 attr
= dwarf_attr (die
, DW_AT_encoding
);
3758 encoding
= DW_UNSND (attr
);
3760 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3763 size
= DW_UNSND (attr
);
3765 attr
= dwarf_attr (die
, DW_AT_name
);
3766 if (attr
&& DW_STRING (attr
))
3768 enum type_code code
= TYPE_CODE_INT
;
3773 case DW_ATE_address
:
3774 /* Turn DW_ATE_address into a void * pointer. */
3775 code
= TYPE_CODE_PTR
;
3776 type_flags
|= TYPE_FLAG_UNSIGNED
;
3778 case DW_ATE_boolean
:
3779 code
= TYPE_CODE_BOOL
;
3780 type_flags
|= TYPE_FLAG_UNSIGNED
;
3782 case DW_ATE_complex_float
:
3783 code
= TYPE_CODE_COMPLEX
;
3786 code
= TYPE_CODE_FLT
;
3789 case DW_ATE_signed_char
:
3791 case DW_ATE_unsigned
:
3792 case DW_ATE_unsigned_char
:
3793 type_flags
|= TYPE_FLAG_UNSIGNED
;
3796 complaint (&symfile_complaints
, "unsupported DW_AT_encoding: '%s'",
3797 dwarf_type_encoding_name (encoding
));
3800 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
3801 if (encoding
== DW_ATE_address
)
3802 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
3803 else if (encoding
== DW_ATE_complex_float
)
3806 TYPE_TARGET_TYPE (type
)
3807 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
3808 else if (size
== 16)
3809 TYPE_TARGET_TYPE (type
)
3810 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
3812 TYPE_TARGET_TYPE (type
)
3813 = dwarf2_fundamental_type (objfile
, FT_FLOAT
);
3818 type
= dwarf_base_type (encoding
, size
, objfile
);
3823 /* Read a whole compilation unit into a linked list of dies. */
3825 static struct die_info
*
3826 read_comp_unit (char *info_ptr
, bfd
*abfd
,
3827 const struct comp_unit_head
*cu_header
)
3829 /* Reset die reference table; we are
3830 building new ones now. */
3831 dwarf2_empty_hash_tables ();
3833 return read_die_and_children (info_ptr
, abfd
, cu_header
, &info_ptr
, NULL
);
3836 /* Read a single die and all its descendents. Set the die's sibling
3837 field to NULL; set other fields in the die correctly, and set all
3838 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
3839 location of the info_ptr after reading all of those dies. PARENT
3840 is the parent of the die in question. */
3842 static struct die_info
*
3843 read_die_and_children (char *info_ptr
, bfd
*abfd
,
3844 const struct comp_unit_head
*cu_header
,
3845 char **new_info_ptr
,
3846 struct die_info
*parent
)
3848 struct die_info
*die
;
3852 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu_header
, &has_children
);
3853 store_in_ref_table (die
->offset
, die
);
3857 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu_header
,
3863 *new_info_ptr
= cur_ptr
;
3866 die
->sibling
= NULL
;
3867 die
->parent
= parent
;
3871 /* Read a die, all of its descendents, and all of its siblings; set
3872 all of the fields of all of the dies correctly. Arguments are as
3873 in read_die_and_children. */
3875 static struct die_info
*
3876 read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
3877 const struct comp_unit_head
*cu_header
,
3878 char **new_info_ptr
,
3879 struct die_info
*parent
)
3881 struct die_info
*first_die
, *last_sibling
;
3885 first_die
= last_sibling
= NULL
;
3889 struct die_info
*die
3890 = read_die_and_children (cur_ptr
, abfd
, cu_header
,
3899 last_sibling
->sibling
= die
;
3904 *new_info_ptr
= cur_ptr
;
3914 /* Free a linked list of dies. */
3917 free_die_list (struct die_info
*dies
)
3919 struct die_info
*die
, *next
;
3924 if (die
->child
!= NULL
)
3925 free_die_list (die
->child
);
3926 next
= die
->sibling
;
3934 do_free_die_list_cleanup (void *dies
)
3936 free_die_list (dies
);
3939 static struct cleanup
*
3940 make_cleanup_free_die_list (struct die_info
*dies
)
3942 return make_cleanup (do_free_die_list_cleanup
, dies
);
3946 /* Read the contents of the section at OFFSET and of size SIZE from the
3947 object file specified by OBJFILE into the psymbol_obstack and return it. */
3950 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
3951 unsigned int size
, asection
*sectp
)
3953 bfd
*abfd
= objfile
->obfd
;
3959 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3961 = (char *) symfile_relocate_debug_section (abfd
, sectp
, (bfd_byte
*) buf
);
3965 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
3966 (bfd_bread (buf
, size
, abfd
) != size
))
3969 error ("Dwarf Error: Can't read DWARF data from '%s'",
3970 bfd_get_filename (abfd
));
3975 /* In DWARF version 2, the description of the debugging information is
3976 stored in a separate .debug_abbrev section. Before we read any
3977 dies from a section we read in all abbreviations and install them
3981 dwarf2_read_abbrevs (bfd
*abfd
, struct comp_unit_head
*cu_header
)
3984 struct abbrev_info
*cur_abbrev
;
3985 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3986 unsigned int abbrev_form
, hash_number
;
3988 /* Initialize dwarf2 abbrevs */
3989 memset (cu_header
->dwarf2_abbrevs
, 0,
3990 ABBREV_HASH_SIZE
*sizeof (struct abbrev_info
*));
3992 abbrev_ptr
= dwarf_abbrev_buffer
+ cu_header
->abbrev_offset
;
3993 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3994 abbrev_ptr
+= bytes_read
;
3996 /* loop until we reach an abbrev number of 0 */
3997 while (abbrev_number
)
3999 cur_abbrev
= dwarf_alloc_abbrev ();
4001 /* read in abbrev header */
4002 cur_abbrev
->number
= abbrev_number
;
4003 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4004 abbrev_ptr
+= bytes_read
;
4005 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
4008 /* now read in declarations */
4009 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4010 abbrev_ptr
+= bytes_read
;
4011 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4012 abbrev_ptr
+= bytes_read
;
4015 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
4017 cur_abbrev
->attrs
= (struct attr_abbrev
*)
4018 xrealloc (cur_abbrev
->attrs
,
4019 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
4020 * sizeof (struct attr_abbrev
));
4022 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
4023 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
4024 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4025 abbrev_ptr
+= bytes_read
;
4026 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4027 abbrev_ptr
+= bytes_read
;
4030 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
4031 cur_abbrev
->next
= cu_header
->dwarf2_abbrevs
[hash_number
];
4032 cu_header
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
4034 /* Get next abbreviation.
4035 Under Irix6 the abbreviations for a compilation unit are not
4036 always properly terminated with an abbrev number of 0.
4037 Exit loop if we encounter an abbreviation which we have
4038 already read (which means we are about to read the abbreviations
4039 for the next compile unit) or if the end of the abbreviation
4040 table is reached. */
4041 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
4042 >= dwarf_abbrev_size
)
4044 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4045 abbrev_ptr
+= bytes_read
;
4046 if (dwarf2_lookup_abbrev (abbrev_number
, cu_header
) != NULL
)
4051 /* Empty the abbrev table for a new compilation unit. */
4054 dwarf2_empty_abbrev_table (void *ptr_to_abbrevs_table
)
4057 struct abbrev_info
*abbrev
, *next
;
4058 struct abbrev_info
**abbrevs
;
4060 abbrevs
= (struct abbrev_info
**)ptr_to_abbrevs_table
;
4062 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
4065 abbrev
= abbrevs
[i
];
4068 next
= abbrev
->next
;
4069 xfree (abbrev
->attrs
);
4077 /* Lookup an abbrev_info structure in the abbrev hash table. */
4079 static struct abbrev_info
*
4080 dwarf2_lookup_abbrev (unsigned int number
, const struct comp_unit_head
*cu_header
)
4082 unsigned int hash_number
;
4083 struct abbrev_info
*abbrev
;
4085 hash_number
= number
% ABBREV_HASH_SIZE
;
4086 abbrev
= cu_header
->dwarf2_abbrevs
[hash_number
];
4090 if (abbrev
->number
== number
)
4093 abbrev
= abbrev
->next
;
4098 /* Read a minimal amount of information into the minimal die structure. */
4101 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
4102 char *info_ptr
, const struct comp_unit_head
*cu_header
)
4104 unsigned int abbrev_number
, bytes_read
, i
;
4105 struct abbrev_info
*abbrev
;
4106 struct attribute attr
;
4107 struct attribute spec_attr
;
4108 int found_spec_attr
= 0;
4109 int has_low_pc_attr
= 0;
4110 int has_high_pc_attr
= 0;
4112 *part_die
= zeroed_partial_die
;
4113 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4114 info_ptr
+= bytes_read
;
4118 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu_header
);
4121 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number
,
4122 bfd_get_filename (abfd
));
4124 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
4125 part_die
->tag
= abbrev
->tag
;
4126 part_die
->has_children
= abbrev
->has_children
;
4127 part_die
->abbrev
= abbrev_number
;
4129 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4131 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
4132 info_ptr
, cu_header
);
4134 /* Store the data if it is of an attribute we want to keep in a
4135 partial symbol table. */
4140 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
4141 if (part_die
->name
== NULL
)
4142 part_die
->name
= DW_STRING (&attr
);
4144 case DW_AT_MIPS_linkage_name
:
4145 part_die
->name
= DW_STRING (&attr
);
4148 has_low_pc_attr
= 1;
4149 part_die
->lowpc
= DW_ADDR (&attr
);
4152 has_high_pc_attr
= 1;
4153 part_die
->highpc
= DW_ADDR (&attr
);
4155 case DW_AT_location
:
4156 /* Support the .debug_loc offsets */
4157 if (attr_form_is_block (&attr
))
4159 part_die
->locdesc
= DW_BLOCK (&attr
);
4161 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
4163 dwarf2_complex_location_expr_complaint ();
4167 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4168 "partial symbol information");
4171 case DW_AT_language
:
4172 part_die
->language
= DW_UNSND (&attr
);
4174 case DW_AT_external
:
4175 part_die
->is_external
= DW_UNSND (&attr
);
4177 case DW_AT_declaration
:
4178 part_die
->is_declaration
= DW_UNSND (&attr
);
4181 part_die
->has_type
= 1;
4183 case DW_AT_abstract_origin
:
4184 case DW_AT_specification
:
4185 found_spec_attr
= 1;
4189 /* Ignore absolute siblings, they might point outside of
4190 the current compile unit. */
4191 if (attr
.form
== DW_FORM_ref_addr
)
4192 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
4195 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
4202 /* If we found a reference attribute and the die has no name, try
4203 to find a name in the referred to die. */
4205 if (found_spec_attr
&& part_die
->name
== NULL
)
4207 struct partial_die_info spec_die
;
4211 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
4212 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu_header
);
4215 part_die
->name
= spec_die
.name
;
4217 /* Copy DW_AT_external attribute if it is set. */
4218 if (spec_die
.is_external
)
4219 part_die
->is_external
= spec_die
.is_external
;
4223 /* When using the GNU linker, .gnu.linkonce. sections are used to
4224 eliminate duplicate copies of functions and vtables and such.
4225 The linker will arbitrarily choose one and discard the others.
4226 The AT_*_pc values for such functions refer to local labels in
4227 these sections. If the section from that file was discarded, the
4228 labels are not in the output, so the relocs get a value of 0.
4229 If this is a discarded function, mark the pc bounds as invalid,
4230 so that GDB will ignore it. */
4231 if (has_low_pc_attr
&& has_high_pc_attr
4232 && part_die
->lowpc
< part_die
->highpc
4233 && (part_die
->lowpc
!= 0
4234 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
4235 part_die
->has_pc_info
= 1;
4239 /* Read the die from the .debug_info section buffer. Set DIEP to
4240 point to a newly allocated die with its information, except for its
4241 child, sibling, and parent fields. Set HAS_CHILDREN to tell
4242 whether the die has children or not. */
4245 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
4246 const struct comp_unit_head
*cu_header
, int *has_children
)
4248 unsigned int abbrev_number
, bytes_read
, i
, offset
;
4249 struct abbrev_info
*abbrev
;
4250 struct die_info
*die
;
4252 offset
= info_ptr
- dwarf_info_buffer
;
4253 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4254 info_ptr
+= bytes_read
;
4257 die
= dwarf_alloc_die ();
4259 die
->abbrev
= abbrev_number
;
4266 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu_header
);
4269 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
4271 bfd_get_filename (abfd
));
4273 die
= dwarf_alloc_die ();
4274 die
->offset
= offset
;
4275 die
->tag
= abbrev
->tag
;
4276 die
->abbrev
= abbrev_number
;
4279 die
->num_attrs
= abbrev
->num_attrs
;
4280 die
->attrs
= (struct attribute
*)
4281 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
4283 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4285 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
4286 abfd
, info_ptr
, cu_header
);
4290 *has_children
= abbrev
->has_children
;
4294 /* Read an attribute value described by an attribute form. */
4297 read_attribute_value (struct attribute
*attr
, unsigned form
,
4298 bfd
*abfd
, char *info_ptr
,
4299 const struct comp_unit_head
*cu_header
)
4301 unsigned int bytes_read
;
4302 struct dwarf_block
*blk
;
4308 case DW_FORM_ref_addr
:
4309 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
4310 info_ptr
+= bytes_read
;
4312 case DW_FORM_block2
:
4313 blk
= dwarf_alloc_block ();
4314 blk
->size
= read_2_bytes (abfd
, info_ptr
);
4316 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4317 info_ptr
+= blk
->size
;
4318 DW_BLOCK (attr
) = blk
;
4320 case DW_FORM_block4
:
4321 blk
= dwarf_alloc_block ();
4322 blk
->size
= read_4_bytes (abfd
, info_ptr
);
4324 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4325 info_ptr
+= blk
->size
;
4326 DW_BLOCK (attr
) = blk
;
4329 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4333 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4337 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4340 case DW_FORM_string
:
4341 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
4342 info_ptr
+= bytes_read
;
4345 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
4347 info_ptr
+= bytes_read
;
4350 blk
= dwarf_alloc_block ();
4351 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4352 info_ptr
+= bytes_read
;
4353 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4354 info_ptr
+= blk
->size
;
4355 DW_BLOCK (attr
) = blk
;
4357 case DW_FORM_block1
:
4358 blk
= dwarf_alloc_block ();
4359 blk
->size
= read_1_byte (abfd
, info_ptr
);
4361 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4362 info_ptr
+= blk
->size
;
4363 DW_BLOCK (attr
) = blk
;
4366 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4370 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4374 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
4375 info_ptr
+= bytes_read
;
4378 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4379 info_ptr
+= bytes_read
;
4382 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4386 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4390 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4394 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4397 case DW_FORM_ref_udata
:
4398 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4399 info_ptr
+= bytes_read
;
4401 case DW_FORM_indirect
:
4402 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4403 info_ptr
+= bytes_read
;
4404 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu_header
);
4407 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
4408 dwarf_form_name (form
),
4409 bfd_get_filename (abfd
));
4414 /* Read an attribute described by an abbreviated attribute. */
4417 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
4418 bfd
*abfd
, char *info_ptr
,
4419 const struct comp_unit_head
*cu_header
)
4421 attr
->name
= abbrev
->name
;
4422 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu_header
);
4425 /* read dwarf information from a buffer */
4428 read_1_byte (bfd
*abfd
, char *buf
)
4430 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4434 read_1_signed_byte (bfd
*abfd
, char *buf
)
4436 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
4440 read_2_bytes (bfd
*abfd
, char *buf
)
4442 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4446 read_2_signed_bytes (bfd
*abfd
, char *buf
)
4448 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4452 read_4_bytes (bfd
*abfd
, char *buf
)
4454 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4458 read_4_signed_bytes (bfd
*abfd
, char *buf
)
4460 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4463 static unsigned long
4464 read_8_bytes (bfd
*abfd
, char *buf
)
4466 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4470 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
4473 CORE_ADDR retval
= 0;
4475 if (cu_header
->signed_addr_p
)
4477 switch (cu_header
->addr_size
)
4480 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4483 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4486 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
4489 internal_error (__FILE__
, __LINE__
,
4490 "read_address: bad switch, signed [in module %s]",
4491 bfd_get_filename (abfd
));
4496 switch (cu_header
->addr_size
)
4499 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4502 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4505 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4508 internal_error (__FILE__
, __LINE__
,
4509 "read_address: bad switch, unsigned [in module %s]",
4510 bfd_get_filename (abfd
));
4514 *bytes_read
= cu_header
->addr_size
;
4518 /* Read the initial length from a section. The (draft) DWARF 3
4519 specification allows the initial length to take up either 4 bytes
4520 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
4521 bytes describe the length and all offsets will be 8 bytes in length
4524 An older, non-standard 64-bit format is also handled by this
4525 function. The older format in question stores the initial length
4526 as an 8-byte quantity without an escape value. Lengths greater
4527 than 2^32 aren't very common which means that the initial 4 bytes
4528 is almost always zero. Since a length value of zero doesn't make
4529 sense for the 32-bit format, this initial zero can be considered to
4530 be an escape value which indicates the presence of the older 64-bit
4531 format. As written, the code can't detect (old format) lengths
4532 greater than 4GB. If it becomes necessary to handle lengths somewhat
4533 larger than 4GB, we could allow other small values (such as the
4534 non-sensical values of 1, 2, and 3) to also be used as escape values
4535 indicating the presence of the old format.
4537 The value returned via bytes_read should be used to increment
4538 the relevant pointer after calling read_initial_length().
4540 As a side effect, this function sets the fields initial_length_size
4541 and offset_size in cu_header to the values appropriate for the
4542 length field. (The format of the initial length field determines
4543 the width of file offsets to be fetched later with fetch_offset().)
4545 [ Note: read_initial_length() and read_offset() are based on the
4546 document entitled "DWARF Debugging Information Format", revision
4547 3, draft 8, dated November 19, 2001. This document was obtained
4550 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
4552 This document is only a draft and is subject to change. (So beware.)
4554 Details regarding the older, non-standard 64-bit format were
4555 determined empirically by examining 64-bit ELF files produced
4556 by the SGI toolchain on an IRIX 6.5 machine.
4558 - Kevin, July 16, 2002
4562 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
4567 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4569 if (retval
== 0xffffffff)
4571 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
4573 if (cu_header
!= NULL
)
4575 cu_header
->initial_length_size
= 12;
4576 cu_header
->offset_size
= 8;
4579 else if (retval
== 0)
4581 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
4583 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4585 if (cu_header
!= NULL
)
4587 cu_header
->initial_length_size
= 8;
4588 cu_header
->offset_size
= 8;
4594 if (cu_header
!= NULL
)
4596 cu_header
->initial_length_size
= 4;
4597 cu_header
->offset_size
= 4;
4604 /* Read an offset from the data stream. The size of the offset is
4605 given by cu_header->offset_size. */
4608 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
4613 switch (cu_header
->offset_size
)
4616 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4620 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4624 internal_error (__FILE__
, __LINE__
,
4625 "read_offset: bad switch [in module %s]",
4626 bfd_get_filename (abfd
));
4633 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
4635 /* If the size of a host char is 8 bits, we can return a pointer
4636 to the buffer, otherwise we have to copy the data to a buffer
4637 allocated on the temporary obstack. */
4638 gdb_assert (HOST_CHAR_BIT
== 8);
4643 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4645 /* If the size of a host char is 8 bits, we can return a pointer
4646 to the string, otherwise we have to copy the string to a buffer
4647 allocated on the temporary obstack. */
4648 gdb_assert (HOST_CHAR_BIT
== 8);
4651 *bytes_read_ptr
= 1;
4654 *bytes_read_ptr
= strlen (buf
) + 1;
4659 read_indirect_string (bfd
*abfd
, char *buf
,
4660 const struct comp_unit_head
*cu_header
,
4661 unsigned int *bytes_read_ptr
)
4663 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
4664 (int *) bytes_read_ptr
);
4666 if (dwarf_str_buffer
== NULL
)
4668 error ("DW_FORM_strp used without .debug_str section [in module %s]",
4669 bfd_get_filename (abfd
));
4672 if (str_offset
>= dwarf_str_size
)
4674 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
4675 bfd_get_filename (abfd
));
4678 gdb_assert (HOST_CHAR_BIT
== 8);
4679 if (dwarf_str_buffer
[str_offset
] == '\0')
4681 return dwarf_str_buffer
+ str_offset
;
4684 static unsigned long
4685 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4687 unsigned long result
;
4688 unsigned int num_read
;
4698 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4701 result
|= ((unsigned long)(byte
& 127) << shift
);
4702 if ((byte
& 128) == 0)
4708 *bytes_read_ptr
= num_read
;
4713 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4716 int i
, shift
, size
, num_read
;
4726 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4729 result
|= ((long)(byte
& 127) << shift
);
4731 if ((byte
& 128) == 0)
4736 if ((shift
< size
) && (byte
& 0x40))
4738 result
|= -(1 << shift
);
4740 *bytes_read_ptr
= num_read
;
4745 set_cu_language (unsigned int lang
)
4751 cu_language
= language_c
;
4753 case DW_LANG_C_plus_plus
:
4754 cu_language
= language_cplus
;
4756 case DW_LANG_Fortran77
:
4757 case DW_LANG_Fortran90
:
4758 case DW_LANG_Fortran95
:
4759 cu_language
= language_fortran
;
4761 case DW_LANG_Mips_Assembler
:
4762 cu_language
= language_asm
;
4765 cu_language
= language_java
;
4769 case DW_LANG_Cobol74
:
4770 case DW_LANG_Cobol85
:
4771 case DW_LANG_Pascal83
:
4772 case DW_LANG_Modula2
:
4774 cu_language
= language_minimal
;
4777 cu_language_defn
= language_def (cu_language
);
4780 /* Return the named attribute or NULL if not there. */
4782 static struct attribute
*
4783 dwarf_attr (struct die_info
*die
, unsigned int name
)
4786 struct attribute
*spec
= NULL
;
4788 for (i
= 0; i
< die
->num_attrs
; ++i
)
4790 if (die
->attrs
[i
].name
== name
)
4792 return &die
->attrs
[i
];
4794 if (die
->attrs
[i
].name
== DW_AT_specification
4795 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
4796 spec
= &die
->attrs
[i
];
4800 struct die_info
*ref_die
=
4801 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
4804 return dwarf_attr (ref_die
, name
);
4811 die_is_declaration (struct die_info
*die
)
4813 return (dwarf_attr (die
, DW_AT_declaration
)
4814 && ! dwarf_attr (die
, DW_AT_specification
));
4818 /* Free the line_header structure *LH, and any arrays and strings it
4821 free_line_header (struct line_header
*lh
)
4823 if (lh
->standard_opcode_lengths
)
4824 xfree (lh
->standard_opcode_lengths
);
4826 /* Remember that all the lh->file_names[i].name pointers are
4827 pointers into debug_line_buffer, and don't need to be freed. */
4829 xfree (lh
->file_names
);
4831 /* Similarly for the include directory names. */
4832 if (lh
->include_dirs
)
4833 xfree (lh
->include_dirs
);
4839 /* Add an entry to LH's include directory table. */
4841 add_include_dir (struct line_header
*lh
, char *include_dir
)
4843 /* Grow the array if necessary. */
4844 if (lh
->include_dirs_size
== 0)
4846 lh
->include_dirs_size
= 1; /* for testing */
4847 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
4848 * sizeof (*lh
->include_dirs
));
4850 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
4852 lh
->include_dirs_size
*= 2;
4853 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
4854 (lh
->include_dirs_size
4855 * sizeof (*lh
->include_dirs
)));
4858 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
4862 /* Add an entry to LH's file name table. */
4864 add_file_name (struct line_header
*lh
,
4866 unsigned int dir_index
,
4867 unsigned int mod_time
,
4868 unsigned int length
)
4870 struct file_entry
*fe
;
4872 /* Grow the array if necessary. */
4873 if (lh
->file_names_size
== 0)
4875 lh
->file_names_size
= 1; /* for testing */
4876 lh
->file_names
= xmalloc (lh
->file_names_size
4877 * sizeof (*lh
->file_names
));
4879 else if (lh
->num_file_names
>= lh
->file_names_size
)
4881 lh
->file_names_size
*= 2;
4882 lh
->file_names
= xrealloc (lh
->file_names
,
4883 (lh
->file_names_size
4884 * sizeof (*lh
->file_names
)));
4887 fe
= &lh
->file_names
[lh
->num_file_names
++];
4889 fe
->dir_index
= dir_index
;
4890 fe
->mod_time
= mod_time
;
4891 fe
->length
= length
;
4895 /* Read the statement program header starting at OFFSET in
4896 dwarf_line_buffer, according to the endianness of ABFD. Return a
4897 pointer to a struct line_header, allocated using xmalloc.
4899 NOTE: the strings in the include directory and file name tables of
4900 the returned object point into debug_line_buffer, and must not be
4902 static struct line_header
*
4903 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
4904 const struct comp_unit_head
*cu_header
)
4906 struct cleanup
*back_to
;
4907 struct line_header
*lh
;
4911 char *cur_dir
, *cur_file
;
4913 if (dwarf_line_buffer
== NULL
)
4915 complaint (&symfile_complaints
, "missing .debug_line section");
4919 /* Make sure that at least there's room for the total_length field. That
4920 could be 12 bytes long, but we're just going to fudge that. */
4921 if (offset
+ 4 >= dwarf_line_size
)
4923 dwarf2_statement_list_fits_in_line_number_section_complaint ();
4927 lh
= xmalloc (sizeof (*lh
));
4928 memset (lh
, 0, sizeof (*lh
));
4929 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
4932 line_ptr
= dwarf_line_buffer
+ offset
;
4934 /* read in the header */
4935 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
4936 line_ptr
+= bytes_read
;
4937 if (line_ptr
+ lh
->total_length
> dwarf_line_buffer
+ dwarf_line_size
)
4939 dwarf2_statement_list_fits_in_line_number_section_complaint ();
4942 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
4943 lh
->version
= read_2_bytes (abfd
, line_ptr
);
4945 lh
->header_length
= read_offset (abfd
, line_ptr
, cu_header
, &bytes_read
);
4946 line_ptr
+= bytes_read
;
4947 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
4949 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
4951 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
4953 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
4955 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
4957 lh
->standard_opcode_lengths
4958 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
4960 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
4961 for (i
= 1; i
< lh
->opcode_base
; ++i
)
4963 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
4967 /* Read directory table */
4968 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4970 line_ptr
+= bytes_read
;
4971 add_include_dir (lh
, cur_dir
);
4973 line_ptr
+= bytes_read
;
4975 /* Read file name table */
4976 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4978 unsigned int dir_index
, mod_time
, length
;
4980 line_ptr
+= bytes_read
;
4981 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4982 line_ptr
+= bytes_read
;
4983 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4984 line_ptr
+= bytes_read
;
4985 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4986 line_ptr
+= bytes_read
;
4988 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4990 line_ptr
+= bytes_read
;
4991 lh
->statement_program_start
= line_ptr
;
4993 if (line_ptr
> dwarf_line_buffer
+ dwarf_line_size
)
4994 complaint (&symfile_complaints
,
4995 "line number info header doesn't fit in `.debug_line' section");
4997 discard_cleanups (back_to
);
5001 /* This function exists to work around a bug in certain compilers
5002 (particularly GCC 2.95), in which the first line number marker of a
5003 function does not show up until after the prologue, right before
5004 the second line number marker. This function shifts ADDRESS down
5005 to the beginning of the function if necessary, and is called on
5006 addresses passed to record_line. */
5009 check_cu_functions (CORE_ADDR address
)
5011 struct function_range
*fn
;
5013 /* Find the function_range containing address. */
5018 cu_cached_fn
= cu_first_fn
;
5022 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
5028 while (fn
&& fn
!= cu_cached_fn
)
5029 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
5039 if (address
!= fn
->lowpc
)
5040 complaint (&symfile_complaints
,
5041 "misplaced first line number at 0x%lx for '%s'",
5042 (unsigned long) address
, fn
->name
);
5047 /* Decode the line number information for the compilation unit whose
5048 line number info is at OFFSET in the .debug_line section.
5049 The compilation directory of the file is passed in COMP_DIR. */
5052 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
5053 const struct comp_unit_head
*cu_header
)
5057 unsigned int i
, bytes_read
;
5059 unsigned char op_code
, extended_op
, adj_opcode
;
5061 line_ptr
= lh
->statement_program_start
;
5062 line_end
= lh
->statement_program_end
;
5064 /* Read the statement sequences until there's nothing left. */
5065 while (line_ptr
< line_end
)
5067 /* state machine registers */
5068 CORE_ADDR address
= 0;
5069 unsigned int file
= 1;
5070 unsigned int line
= 1;
5071 unsigned int column
= 0;
5072 int is_stmt
= lh
->default_is_stmt
;
5073 int basic_block
= 0;
5074 int end_sequence
= 0;
5076 /* Start a subfile for the current file of the state machine. */
5077 if (lh
->num_file_names
>= file
)
5079 /* lh->include_dirs and lh->file_names are 0-based, but the
5080 directory and file name numbers in the statement program
5082 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
5085 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
5088 dwarf2_start_subfile (fe
->name
, dir
);
5091 /* Decode the table. */
5092 while (!end_sequence
)
5094 op_code
= read_1_byte (abfd
, line_ptr
);
5097 if (op_code
>= lh
->opcode_base
)
5098 { /* Special operand. */
5099 adj_opcode
= op_code
- lh
->opcode_base
;
5100 address
+= (adj_opcode
/ lh
->line_range
)
5101 * lh
->minimum_instruction_length
;
5102 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
5103 /* append row to matrix using current values */
5104 record_line (current_subfile
, line
,
5105 check_cu_functions (address
));
5108 else switch (op_code
)
5110 case DW_LNS_extended_op
:
5111 line_ptr
+= 1; /* ignore length */
5112 extended_op
= read_1_byte (abfd
, line_ptr
);
5114 switch (extended_op
)
5116 case DW_LNE_end_sequence
:
5118 record_line (current_subfile
, 0, address
);
5120 case DW_LNE_set_address
:
5121 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
5122 line_ptr
+= bytes_read
;
5123 address
+= baseaddr
;
5125 case DW_LNE_define_file
:
5128 unsigned int dir_index
, mod_time
, length
;
5130 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
5131 line_ptr
+= bytes_read
;
5133 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5134 line_ptr
+= bytes_read
;
5136 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5137 line_ptr
+= bytes_read
;
5139 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5140 line_ptr
+= bytes_read
;
5141 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
5145 complaint (&symfile_complaints
,
5146 "mangled .debug_line section");
5151 record_line (current_subfile
, line
,
5152 check_cu_functions (address
));
5155 case DW_LNS_advance_pc
:
5156 address
+= lh
->minimum_instruction_length
5157 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5158 line_ptr
+= bytes_read
;
5160 case DW_LNS_advance_line
:
5161 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
5162 line_ptr
+= bytes_read
;
5164 case DW_LNS_set_file
:
5166 /* lh->include_dirs and lh->file_names are 0-based,
5167 but the directory and file name numbers in the
5168 statement program are 1-based. */
5169 struct file_entry
*fe
;
5171 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5172 line_ptr
+= bytes_read
;
5173 fe
= &lh
->file_names
[file
- 1];
5175 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
5178 dwarf2_start_subfile (fe
->name
, dir
);
5181 case DW_LNS_set_column
:
5182 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5183 line_ptr
+= bytes_read
;
5185 case DW_LNS_negate_stmt
:
5186 is_stmt
= (!is_stmt
);
5188 case DW_LNS_set_basic_block
:
5191 /* Add to the address register of the state machine the
5192 address increment value corresponding to special opcode
5193 255. Ie, this value is scaled by the minimum instruction
5194 length since special opcode 255 would have scaled the
5196 case DW_LNS_const_add_pc
:
5197 address
+= (lh
->minimum_instruction_length
5198 * ((255 - lh
->opcode_base
) / lh
->line_range
));
5200 case DW_LNS_fixed_advance_pc
:
5201 address
+= read_2_bytes (abfd
, line_ptr
);
5205 { /* Unknown standard opcode, ignore it. */
5207 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
5209 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5210 line_ptr
+= bytes_read
;
5218 /* Start a subfile for DWARF. FILENAME is the name of the file and
5219 DIRNAME the name of the source directory which contains FILENAME
5220 or NULL if not known.
5221 This routine tries to keep line numbers from identical absolute and
5222 relative file names in a common subfile.
5224 Using the `list' example from the GDB testsuite, which resides in
5225 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
5226 of /srcdir/list0.c yields the following debugging information for list0.c:
5228 DW_AT_name: /srcdir/list0.c
5229 DW_AT_comp_dir: /compdir
5230 files.files[0].name: list0.h
5231 files.files[0].dir: /srcdir
5232 files.files[1].name: list0.c
5233 files.files[1].dir: /srcdir
5235 The line number information for list0.c has to end up in a single
5236 subfile, so that `break /srcdir/list0.c:1' works as expected. */
5239 dwarf2_start_subfile (char *filename
, char *dirname
)
5241 /* If the filename isn't absolute, try to match an existing subfile
5242 with the full pathname. */
5244 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
5246 struct subfile
*subfile
;
5247 char *fullname
= concat (dirname
, "/", filename
, NULL
);
5249 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
5251 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
5253 current_subfile
= subfile
;
5260 start_subfile (filename
, dirname
);
5264 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
5265 struct objfile
*objfile
,
5266 const struct comp_unit_head
*cu_header
)
5268 /* NOTE drow/2003-01-30: There used to be a comment and some special
5269 code here to turn a symbol with DW_AT_external and a
5270 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
5271 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
5272 with some versions of binutils) where shared libraries could have
5273 relocations against symbols in their debug information - the
5274 minimal symbol would have the right address, but the debug info
5275 would not. It's no longer necessary, because we will explicitly
5276 apply relocations when we read in the debug information now. */
5278 /* A DW_AT_location attribute with no contents indicates that a
5279 variable has been optimized away. */
5280 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
5282 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
5286 /* Handle one degenerate form of location expression specially, to
5287 preserve GDB's previous behavior when section offsets are
5288 specified. If this is just a DW_OP_addr then mark this symbol
5291 if (attr_form_is_block (attr
)
5292 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
5293 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
5297 SYMBOL_VALUE_ADDRESS (sym
) =
5298 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu_header
,
5300 fixup_symbol_section (sym
, objfile
);
5301 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
5302 SYMBOL_SECTION (sym
));
5303 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5307 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
5308 expression evaluator, and use LOC_COMPUTED only when necessary
5309 (i.e. when the value of a register or memory location is
5310 referenced, or a thread-local block, etc.). Then again, it might
5311 not be worthwhile. I'm assuming that it isn't unless performance
5312 or memory numbers show me otherwise. */
5314 dwarf2_symbol_mark_computed (attr
, sym
, cu_header
, objfile
);
5315 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
5318 /* Given a pointer to a DWARF information entry, figure out if we need
5319 to make a symbol table entry for it, and if so, create a new entry
5320 and return a pointer to it.
5321 If TYPE is NULL, determine symbol type from the die, otherwise
5322 used the passed type. */
5324 static struct symbol
*
5325 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
5326 const struct comp_unit_head
*cu_header
)
5328 struct symbol
*sym
= NULL
;
5330 struct attribute
*attr
= NULL
;
5331 struct attribute
*attr2
= NULL
;
5334 if (die
->tag
!= DW_TAG_namespace
)
5335 name
= dwarf2_linkage_name (die
);
5337 name
= TYPE_NAME (type
);
5341 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
5342 sizeof (struct symbol
));
5343 OBJSTAT (objfile
, n_syms
++);
5344 memset (sym
, 0, sizeof (struct symbol
));
5346 /* Cache this symbol's name and the name's demangled form (if any). */
5347 SYMBOL_LANGUAGE (sym
) = cu_language
;
5348 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
5350 /* Default assumptions.
5351 Use the passed type or decode it from the die. */
5352 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5353 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5355 SYMBOL_TYPE (sym
) = type
;
5357 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
5358 attr
= dwarf_attr (die
, DW_AT_decl_line
);
5361 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
5366 attr
= dwarf_attr (die
, DW_AT_low_pc
);
5369 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
5371 SYMBOL_CLASS (sym
) = LOC_LABEL
;
5373 case DW_TAG_subprogram
:
5374 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
5376 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
5377 attr2
= dwarf_attr (die
, DW_AT_external
);
5378 if (attr2
&& (DW_UNSND (attr2
) != 0))
5380 add_symbol_to_list (sym
, &global_symbols
);
5384 add_symbol_to_list (sym
, list_in_scope
);
5387 case DW_TAG_variable
:
5388 /* Compilation with minimal debug info may result in variables
5389 with missing type entries. Change the misleading `void' type
5390 to something sensible. */
5391 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
5392 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
5393 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
5394 "<variable, no debug info>",
5396 attr
= dwarf_attr (die
, DW_AT_const_value
);
5399 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
5400 attr2
= dwarf_attr (die
, DW_AT_external
);
5401 if (attr2
&& (DW_UNSND (attr2
) != 0))
5402 add_symbol_to_list (sym
, &global_symbols
);
5404 add_symbol_to_list (sym
, list_in_scope
);
5407 attr
= dwarf_attr (die
, DW_AT_location
);
5410 var_decode_location (attr
, sym
, objfile
, cu_header
);
5411 attr2
= dwarf_attr (die
, DW_AT_external
);
5412 if (attr2
&& (DW_UNSND (attr2
) != 0))
5413 add_symbol_to_list (sym
, &global_symbols
);
5415 add_symbol_to_list (sym
, list_in_scope
);
5419 /* We do not know the address of this symbol.
5420 If it is an external symbol and we have type information
5421 for it, enter the symbol as a LOC_UNRESOLVED symbol.
5422 The address of the variable will then be determined from
5423 the minimal symbol table whenever the variable is
5425 attr2
= dwarf_attr (die
, DW_AT_external
);
5426 if (attr2
&& (DW_UNSND (attr2
) != 0)
5427 && dwarf_attr (die
, DW_AT_type
) != NULL
)
5429 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
5430 add_symbol_to_list (sym
, &global_symbols
);
5434 case DW_TAG_formal_parameter
:
5435 attr
= dwarf_attr (die
, DW_AT_location
);
5438 var_decode_location (attr
, sym
, objfile
, cu_header
);
5439 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
5440 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
5441 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
5443 attr
= dwarf_attr (die
, DW_AT_const_value
);
5446 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
5448 add_symbol_to_list (sym
, list_in_scope
);
5450 case DW_TAG_unspecified_parameters
:
5451 /* From varargs functions; gdb doesn't seem to have any
5452 interest in this information, so just ignore it for now.
5455 case DW_TAG_class_type
:
5456 case DW_TAG_structure_type
:
5457 case DW_TAG_union_type
:
5458 case DW_TAG_enumeration_type
:
5459 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5460 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
5461 add_symbol_to_list (sym
, list_in_scope
);
5463 /* The semantics of C++ state that "struct foo { ... }" also
5464 defines a typedef for "foo". Synthesize a typedef symbol so
5465 that "ptype foo" works as expected. */
5466 if (cu_language
== language_cplus
)
5468 struct symbol
*typedef_sym
= (struct symbol
*)
5469 obstack_alloc (&objfile
->symbol_obstack
,
5470 sizeof (struct symbol
));
5471 *typedef_sym
= *sym
;
5472 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
5473 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
5474 TYPE_NAME (SYMBOL_TYPE (sym
)) =
5475 obsavestring (DEPRECATED_SYMBOL_NAME (sym
),
5476 strlen (DEPRECATED_SYMBOL_NAME (sym
)),
5477 &objfile
->type_obstack
);
5478 add_symbol_to_list (typedef_sym
, list_in_scope
);
5481 case DW_TAG_typedef
:
5482 case DW_TAG_base_type
:
5483 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5484 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5485 add_symbol_to_list (sym
, list_in_scope
);
5487 case DW_TAG_enumerator
:
5488 attr
= dwarf_attr (die
, DW_AT_const_value
);
5491 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
5493 add_symbol_to_list (sym
, list_in_scope
);
5495 case DW_TAG_namespace
:
5496 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5497 add_symbol_to_list (sym
, &global_symbols
);
5500 /* Not a tag we recognize. Hopefully we aren't processing
5501 trash data, but since we must specifically ignore things
5502 we don't recognize, there is nothing else we should do at
5504 complaint (&symfile_complaints
, "unsupported tag: '%s'",
5505 dwarf_tag_name (die
->tag
));
5512 /* Copy constant value from an attribute to a symbol. */
5515 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
5516 struct objfile
*objfile
,
5517 const struct comp_unit_head
*cu_header
)
5519 struct dwarf_block
*blk
;
5524 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
5525 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5526 cu_header
->addr_size
,
5527 TYPE_LENGTH (SYMBOL_TYPE
5529 SYMBOL_VALUE_BYTES (sym
) = (char *)
5530 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
5531 /* NOTE: cagney/2003-05-09: In-lined store_address call with
5532 it's body - store_unsigned_integer. */
5533 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
5535 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5537 case DW_FORM_block1
:
5538 case DW_FORM_block2
:
5539 case DW_FORM_block4
:
5541 blk
= DW_BLOCK (attr
);
5542 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
5543 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5545 TYPE_LENGTH (SYMBOL_TYPE
5547 SYMBOL_VALUE_BYTES (sym
) = (char *)
5548 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
5549 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
5550 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5553 /* The DW_AT_const_value attributes are supposed to carry the
5554 symbol's value "represented as it would be on the target
5555 architecture." By the time we get here, it's already been
5556 converted to host endianness, so we just need to sign- or
5557 zero-extend it as appropriate. */
5559 dwarf2_const_value_data (attr
, sym
, 8);
5562 dwarf2_const_value_data (attr
, sym
, 16);
5565 dwarf2_const_value_data (attr
, sym
, 32);
5568 dwarf2_const_value_data (attr
, sym
, 64);
5572 SYMBOL_VALUE (sym
) = DW_SND (attr
);
5573 SYMBOL_CLASS (sym
) = LOC_CONST
;
5577 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
5578 SYMBOL_CLASS (sym
) = LOC_CONST
;
5582 complaint (&symfile_complaints
,
5583 "unsupported const value attribute form: '%s'",
5584 dwarf_form_name (attr
->form
));
5585 SYMBOL_VALUE (sym
) = 0;
5586 SYMBOL_CLASS (sym
) = LOC_CONST
;
5592 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
5593 or zero-extend it as appropriate for the symbol's type. */
5595 dwarf2_const_value_data (struct attribute
*attr
,
5599 LONGEST l
= DW_UNSND (attr
);
5601 if (bits
< sizeof (l
) * 8)
5603 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
5604 l
&= ((LONGEST
) 1 << bits
) - 1;
5606 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
5609 SYMBOL_VALUE (sym
) = l
;
5610 SYMBOL_CLASS (sym
) = LOC_CONST
;
5614 /* Return the type of the die in question using its DW_AT_type attribute. */
5616 static struct type
*
5617 die_type (struct die_info
*die
, struct objfile
*objfile
,
5618 const struct comp_unit_head
*cu_header
)
5621 struct attribute
*type_attr
;
5622 struct die_info
*type_die
;
5625 type_attr
= dwarf_attr (die
, DW_AT_type
);
5628 /* A missing DW_AT_type represents a void type. */
5629 return dwarf2_fundamental_type (objfile
, FT_VOID
);
5633 ref
= dwarf2_get_ref_die_offset (type_attr
);
5634 type_die
= follow_die_ref (ref
);
5637 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
5638 ref
, objfile
->name
);
5642 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
5645 dump_die (type_die
);
5646 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
5652 /* Return the containing type of the die in question using its
5653 DW_AT_containing_type attribute. */
5655 static struct type
*
5656 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
5657 const struct comp_unit_head
*cu_header
)
5659 struct type
*type
= NULL
;
5660 struct attribute
*type_attr
;
5661 struct die_info
*type_die
= NULL
;
5664 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
5667 ref
= dwarf2_get_ref_die_offset (type_attr
);
5668 type_die
= follow_die_ref (ref
);
5671 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref
,
5675 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
5680 dump_die (type_die
);
5681 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
5688 static struct type
*
5689 type_at_offset (unsigned int offset
, struct objfile
*objfile
)
5691 struct die_info
*die
;
5694 die
= follow_die_ref (offset
);
5697 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
5700 type
= tag_type_to_type (die
, objfile
);
5705 static struct type
*
5706 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
5707 const struct comp_unit_head
*cu_header
)
5715 read_type_die (die
, objfile
, cu_header
);
5719 error ("Dwarf Error: Cannot find type of die [in module %s]",
5727 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
5728 const struct comp_unit_head
*cu_header
)
5732 case DW_TAG_class_type
:
5733 case DW_TAG_structure_type
:
5734 case DW_TAG_union_type
:
5735 read_structure_scope (die
, objfile
, cu_header
);
5737 case DW_TAG_enumeration_type
:
5738 read_enumeration (die
, objfile
, cu_header
);
5740 case DW_TAG_subprogram
:
5741 case DW_TAG_subroutine_type
:
5742 read_subroutine_type (die
, objfile
, cu_header
);
5744 case DW_TAG_array_type
:
5745 read_array_type (die
, objfile
, cu_header
);
5747 case DW_TAG_pointer_type
:
5748 read_tag_pointer_type (die
, objfile
, cu_header
);
5750 case DW_TAG_ptr_to_member_type
:
5751 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
5753 case DW_TAG_reference_type
:
5754 read_tag_reference_type (die
, objfile
, cu_header
);
5756 case DW_TAG_const_type
:
5757 read_tag_const_type (die
, objfile
, cu_header
);
5759 case DW_TAG_volatile_type
:
5760 read_tag_volatile_type (die
, objfile
, cu_header
);
5762 case DW_TAG_string_type
:
5763 read_tag_string_type (die
, objfile
);
5765 case DW_TAG_typedef
:
5766 read_typedef (die
, objfile
, cu_header
);
5768 case DW_TAG_base_type
:
5769 read_base_type (die
, objfile
);
5772 complaint (&symfile_complaints
, "unexepected tag in read_type_die: '%s'",
5773 dwarf_tag_name (die
->tag
));
5778 static struct type
*
5779 dwarf_base_type (int encoding
, int size
, struct objfile
*objfile
)
5781 /* FIXME - this should not produce a new (struct type *)
5782 every time. It should cache base types. */
5786 case DW_ATE_address
:
5787 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
5789 case DW_ATE_boolean
:
5790 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
5792 case DW_ATE_complex_float
:
5795 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
5799 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
5805 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
5809 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
5816 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5819 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
5823 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5827 case DW_ATE_signed_char
:
5828 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5830 case DW_ATE_unsigned
:
5834 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5837 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
5841 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
5845 case DW_ATE_unsigned_char
:
5846 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5849 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5856 copy_die (struct die_info
*old_die
)
5858 struct die_info
*new_die
;
5861 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5862 memset (new_die
, 0, sizeof (struct die_info
));
5864 new_die
->tag
= old_die
->tag
;
5865 new_die
->has_children
= old_die
->has_children
;
5866 new_die
->abbrev
= old_die
->abbrev
;
5867 new_die
->offset
= old_die
->offset
;
5868 new_die
->type
= NULL
;
5870 num_attrs
= old_die
->num_attrs
;
5871 new_die
->num_attrs
= num_attrs
;
5872 new_die
->attrs
= (struct attribute
*)
5873 xmalloc (num_attrs
* sizeof (struct attribute
));
5875 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
5877 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
5878 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
5879 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
5882 new_die
->next
= NULL
;
5887 /* Return sibling of die, NULL if no sibling. */
5889 static struct die_info
*
5890 sibling_die (struct die_info
*die
)
5892 return die
->sibling
;
5895 /* Get linkage name of a die, return NULL if not found. */
5898 dwarf2_linkage_name (struct die_info
*die
)
5900 struct attribute
*attr
;
5902 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
5903 if (attr
&& DW_STRING (attr
))
5904 return DW_STRING (attr
);
5905 attr
= dwarf_attr (die
, DW_AT_name
);
5906 if (attr
&& DW_STRING (attr
))
5907 return DW_STRING (attr
);
5911 /* Get name of a die, return NULL if not found. */
5914 dwarf2_name (struct die_info
*die
)
5916 struct attribute
*attr
;
5918 attr
= dwarf_attr (die
, DW_AT_name
);
5919 if (attr
&& DW_STRING (attr
))
5920 return DW_STRING (attr
);
5924 /* Return the die that this die in an extension of, or NULL if there
5927 static struct die_info
*
5928 dwarf2_extension (struct die_info
*die
)
5930 struct attribute
*attr
;
5931 struct die_info
*extension_die
;
5934 attr
= dwarf_attr (die
, DW_AT_extension
);
5938 ref
= dwarf2_get_ref_die_offset (attr
);
5939 extension_die
= follow_die_ref (ref
);
5942 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
5945 return extension_die
;
5948 /* Convert a DIE tag into its string name. */
5951 dwarf_tag_name (unsigned tag
)
5955 case DW_TAG_padding
:
5956 return "DW_TAG_padding";
5957 case DW_TAG_array_type
:
5958 return "DW_TAG_array_type";
5959 case DW_TAG_class_type
:
5960 return "DW_TAG_class_type";
5961 case DW_TAG_entry_point
:
5962 return "DW_TAG_entry_point";
5963 case DW_TAG_enumeration_type
:
5964 return "DW_TAG_enumeration_type";
5965 case DW_TAG_formal_parameter
:
5966 return "DW_TAG_formal_parameter";
5967 case DW_TAG_imported_declaration
:
5968 return "DW_TAG_imported_declaration";
5970 return "DW_TAG_label";
5971 case DW_TAG_lexical_block
:
5972 return "DW_TAG_lexical_block";
5974 return "DW_TAG_member";
5975 case DW_TAG_pointer_type
:
5976 return "DW_TAG_pointer_type";
5977 case DW_TAG_reference_type
:
5978 return "DW_TAG_reference_type";
5979 case DW_TAG_compile_unit
:
5980 return "DW_TAG_compile_unit";
5981 case DW_TAG_string_type
:
5982 return "DW_TAG_string_type";
5983 case DW_TAG_structure_type
:
5984 return "DW_TAG_structure_type";
5985 case DW_TAG_subroutine_type
:
5986 return "DW_TAG_subroutine_type";
5987 case DW_TAG_typedef
:
5988 return "DW_TAG_typedef";
5989 case DW_TAG_union_type
:
5990 return "DW_TAG_union_type";
5991 case DW_TAG_unspecified_parameters
:
5992 return "DW_TAG_unspecified_parameters";
5993 case DW_TAG_variant
:
5994 return "DW_TAG_variant";
5995 case DW_TAG_common_block
:
5996 return "DW_TAG_common_block";
5997 case DW_TAG_common_inclusion
:
5998 return "DW_TAG_common_inclusion";
5999 case DW_TAG_inheritance
:
6000 return "DW_TAG_inheritance";
6001 case DW_TAG_inlined_subroutine
:
6002 return "DW_TAG_inlined_subroutine";
6004 return "DW_TAG_module";
6005 case DW_TAG_ptr_to_member_type
:
6006 return "DW_TAG_ptr_to_member_type";
6007 case DW_TAG_set_type
:
6008 return "DW_TAG_set_type";
6009 case DW_TAG_subrange_type
:
6010 return "DW_TAG_subrange_type";
6011 case DW_TAG_with_stmt
:
6012 return "DW_TAG_with_stmt";
6013 case DW_TAG_access_declaration
:
6014 return "DW_TAG_access_declaration";
6015 case DW_TAG_base_type
:
6016 return "DW_TAG_base_type";
6017 case DW_TAG_catch_block
:
6018 return "DW_TAG_catch_block";
6019 case DW_TAG_const_type
:
6020 return "DW_TAG_const_type";
6021 case DW_TAG_constant
:
6022 return "DW_TAG_constant";
6023 case DW_TAG_enumerator
:
6024 return "DW_TAG_enumerator";
6025 case DW_TAG_file_type
:
6026 return "DW_TAG_file_type";
6028 return "DW_TAG_friend";
6029 case DW_TAG_namelist
:
6030 return "DW_TAG_namelist";
6031 case DW_TAG_namelist_item
:
6032 return "DW_TAG_namelist_item";
6033 case DW_TAG_packed_type
:
6034 return "DW_TAG_packed_type";
6035 case DW_TAG_subprogram
:
6036 return "DW_TAG_subprogram";
6037 case DW_TAG_template_type_param
:
6038 return "DW_TAG_template_type_param";
6039 case DW_TAG_template_value_param
:
6040 return "DW_TAG_template_value_param";
6041 case DW_TAG_thrown_type
:
6042 return "DW_TAG_thrown_type";
6043 case DW_TAG_try_block
:
6044 return "DW_TAG_try_block";
6045 case DW_TAG_variant_part
:
6046 return "DW_TAG_variant_part";
6047 case DW_TAG_variable
:
6048 return "DW_TAG_variable";
6049 case DW_TAG_volatile_type
:
6050 return "DW_TAG_volatile_type";
6051 case DW_TAG_dwarf_procedure
:
6052 return "DW_TAG_dwarf_procedure";
6053 case DW_TAG_restrict_type
:
6054 return "DW_TAG_restrict_type";
6055 case DW_TAG_interface_type
:
6056 return "DW_TAG_interface_type";
6057 case DW_TAG_namespace
:
6058 return "DW_TAG_namespace";
6059 case DW_TAG_imported_module
:
6060 return "DW_TAG_imported_module";
6061 case DW_TAG_unspecified_type
:
6062 return "DW_TAG_unspecified_type";
6063 case DW_TAG_partial_unit
:
6064 return "DW_TAG_partial_unit";
6065 case DW_TAG_imported_unit
:
6066 return "DW_TAG_imported_unit";
6067 case DW_TAG_MIPS_loop
:
6068 return "DW_TAG_MIPS_loop";
6069 case DW_TAG_format_label
:
6070 return "DW_TAG_format_label";
6071 case DW_TAG_function_template
:
6072 return "DW_TAG_function_template";
6073 case DW_TAG_class_template
:
6074 return "DW_TAG_class_template";
6076 return "DW_TAG_<unknown>";
6080 /* Convert a DWARF attribute code into its string name. */
6083 dwarf_attr_name (unsigned attr
)
6088 return "DW_AT_sibling";
6089 case DW_AT_location
:
6090 return "DW_AT_location";
6092 return "DW_AT_name";
6093 case DW_AT_ordering
:
6094 return "DW_AT_ordering";
6095 case DW_AT_subscr_data
:
6096 return "DW_AT_subscr_data";
6097 case DW_AT_byte_size
:
6098 return "DW_AT_byte_size";
6099 case DW_AT_bit_offset
:
6100 return "DW_AT_bit_offset";
6101 case DW_AT_bit_size
:
6102 return "DW_AT_bit_size";
6103 case DW_AT_element_list
:
6104 return "DW_AT_element_list";
6105 case DW_AT_stmt_list
:
6106 return "DW_AT_stmt_list";
6108 return "DW_AT_low_pc";
6110 return "DW_AT_high_pc";
6111 case DW_AT_language
:
6112 return "DW_AT_language";
6114 return "DW_AT_member";
6116 return "DW_AT_discr";
6117 case DW_AT_discr_value
:
6118 return "DW_AT_discr_value";
6119 case DW_AT_visibility
:
6120 return "DW_AT_visibility";
6122 return "DW_AT_import";
6123 case DW_AT_string_length
:
6124 return "DW_AT_string_length";
6125 case DW_AT_common_reference
:
6126 return "DW_AT_common_reference";
6127 case DW_AT_comp_dir
:
6128 return "DW_AT_comp_dir";
6129 case DW_AT_const_value
:
6130 return "DW_AT_const_value";
6131 case DW_AT_containing_type
:
6132 return "DW_AT_containing_type";
6133 case DW_AT_default_value
:
6134 return "DW_AT_default_value";
6136 return "DW_AT_inline";
6137 case DW_AT_is_optional
:
6138 return "DW_AT_is_optional";
6139 case DW_AT_lower_bound
:
6140 return "DW_AT_lower_bound";
6141 case DW_AT_producer
:
6142 return "DW_AT_producer";
6143 case DW_AT_prototyped
:
6144 return "DW_AT_prototyped";
6145 case DW_AT_return_addr
:
6146 return "DW_AT_return_addr";
6147 case DW_AT_start_scope
:
6148 return "DW_AT_start_scope";
6149 case DW_AT_stride_size
:
6150 return "DW_AT_stride_size";
6151 case DW_AT_upper_bound
:
6152 return "DW_AT_upper_bound";
6153 case DW_AT_abstract_origin
:
6154 return "DW_AT_abstract_origin";
6155 case DW_AT_accessibility
:
6156 return "DW_AT_accessibility";
6157 case DW_AT_address_class
:
6158 return "DW_AT_address_class";
6159 case DW_AT_artificial
:
6160 return "DW_AT_artificial";
6161 case DW_AT_base_types
:
6162 return "DW_AT_base_types";
6163 case DW_AT_calling_convention
:
6164 return "DW_AT_calling_convention";
6166 return "DW_AT_count";
6167 case DW_AT_data_member_location
:
6168 return "DW_AT_data_member_location";
6169 case DW_AT_decl_column
:
6170 return "DW_AT_decl_column";
6171 case DW_AT_decl_file
:
6172 return "DW_AT_decl_file";
6173 case DW_AT_decl_line
:
6174 return "DW_AT_decl_line";
6175 case DW_AT_declaration
:
6176 return "DW_AT_declaration";
6177 case DW_AT_discr_list
:
6178 return "DW_AT_discr_list";
6179 case DW_AT_encoding
:
6180 return "DW_AT_encoding";
6181 case DW_AT_external
:
6182 return "DW_AT_external";
6183 case DW_AT_frame_base
:
6184 return "DW_AT_frame_base";
6186 return "DW_AT_friend";
6187 case DW_AT_identifier_case
:
6188 return "DW_AT_identifier_case";
6189 case DW_AT_macro_info
:
6190 return "DW_AT_macro_info";
6191 case DW_AT_namelist_items
:
6192 return "DW_AT_namelist_items";
6193 case DW_AT_priority
:
6194 return "DW_AT_priority";
6196 return "DW_AT_segment";
6197 case DW_AT_specification
:
6198 return "DW_AT_specification";
6199 case DW_AT_static_link
:
6200 return "DW_AT_static_link";
6202 return "DW_AT_type";
6203 case DW_AT_use_location
:
6204 return "DW_AT_use_location";
6205 case DW_AT_variable_parameter
:
6206 return "DW_AT_variable_parameter";
6207 case DW_AT_virtuality
:
6208 return "DW_AT_virtuality";
6209 case DW_AT_vtable_elem_location
:
6210 return "DW_AT_vtable_elem_location";
6211 case DW_AT_allocated
:
6212 return "DW_AT_allocated";
6213 case DW_AT_associated
:
6214 return "DW_AT_associated";
6215 case DW_AT_data_location
:
6216 return "DW_AT_data_location";
6218 return "DW_AT_stride";
6219 case DW_AT_entry_pc
:
6220 return "DW_AT_entry_pc";
6221 case DW_AT_use_UTF8
:
6222 return "DW_AT_use_UTF8";
6223 case DW_AT_extension
:
6224 return "DW_AT_extension";
6226 return "DW_AT_ranges";
6227 case DW_AT_trampoline
:
6228 return "DW_AT_trampoline";
6229 case DW_AT_call_column
:
6230 return "DW_AT_call_column";
6231 case DW_AT_call_file
:
6232 return "DW_AT_call_file";
6233 case DW_AT_call_line
:
6234 return "DW_AT_call_line";
6236 case DW_AT_MIPS_fde
:
6237 return "DW_AT_MIPS_fde";
6238 case DW_AT_MIPS_loop_begin
:
6239 return "DW_AT_MIPS_loop_begin";
6240 case DW_AT_MIPS_tail_loop_begin
:
6241 return "DW_AT_MIPS_tail_loop_begin";
6242 case DW_AT_MIPS_epilog_begin
:
6243 return "DW_AT_MIPS_epilog_begin";
6244 case DW_AT_MIPS_loop_unroll_factor
:
6245 return "DW_AT_MIPS_loop_unroll_factor";
6246 case DW_AT_MIPS_software_pipeline_depth
:
6247 return "DW_AT_MIPS_software_pipeline_depth";
6249 case DW_AT_MIPS_linkage_name
:
6250 return "DW_AT_MIPS_linkage_name";
6252 case DW_AT_sf_names
:
6253 return "DW_AT_sf_names";
6254 case DW_AT_src_info
:
6255 return "DW_AT_src_info";
6256 case DW_AT_mac_info
:
6257 return "DW_AT_mac_info";
6258 case DW_AT_src_coords
:
6259 return "DW_AT_src_coords";
6260 case DW_AT_body_begin
:
6261 return "DW_AT_body_begin";
6262 case DW_AT_body_end
:
6263 return "DW_AT_body_end";
6264 case DW_AT_GNU_vector
:
6265 return "DW_AT_GNU_vector";
6267 return "DW_AT_<unknown>";
6271 /* Convert a DWARF value form code into its string name. */
6274 dwarf_form_name (unsigned form
)
6279 return "DW_FORM_addr";
6280 case DW_FORM_block2
:
6281 return "DW_FORM_block2";
6282 case DW_FORM_block4
:
6283 return "DW_FORM_block4";
6285 return "DW_FORM_data2";
6287 return "DW_FORM_data4";
6289 return "DW_FORM_data8";
6290 case DW_FORM_string
:
6291 return "DW_FORM_string";
6293 return "DW_FORM_block";
6294 case DW_FORM_block1
:
6295 return "DW_FORM_block1";
6297 return "DW_FORM_data1";
6299 return "DW_FORM_flag";
6301 return "DW_FORM_sdata";
6303 return "DW_FORM_strp";
6305 return "DW_FORM_udata";
6306 case DW_FORM_ref_addr
:
6307 return "DW_FORM_ref_addr";
6309 return "DW_FORM_ref1";
6311 return "DW_FORM_ref2";
6313 return "DW_FORM_ref4";
6315 return "DW_FORM_ref8";
6316 case DW_FORM_ref_udata
:
6317 return "DW_FORM_ref_udata";
6318 case DW_FORM_indirect
:
6319 return "DW_FORM_indirect";
6321 return "DW_FORM_<unknown>";
6325 /* Convert a DWARF stack opcode into its string name. */
6328 dwarf_stack_op_name (unsigned op
)
6333 return "DW_OP_addr";
6335 return "DW_OP_deref";
6337 return "DW_OP_const1u";
6339 return "DW_OP_const1s";
6341 return "DW_OP_const2u";
6343 return "DW_OP_const2s";
6345 return "DW_OP_const4u";
6347 return "DW_OP_const4s";
6349 return "DW_OP_const8u";
6351 return "DW_OP_const8s";
6353 return "DW_OP_constu";
6355 return "DW_OP_consts";
6359 return "DW_OP_drop";
6361 return "DW_OP_over";
6363 return "DW_OP_pick";
6365 return "DW_OP_swap";
6369 return "DW_OP_xderef";
6377 return "DW_OP_minus";
6389 return "DW_OP_plus";
6390 case DW_OP_plus_uconst
:
6391 return "DW_OP_plus_uconst";
6397 return "DW_OP_shra";
6415 return "DW_OP_skip";
6417 return "DW_OP_lit0";
6419 return "DW_OP_lit1";
6421 return "DW_OP_lit2";
6423 return "DW_OP_lit3";
6425 return "DW_OP_lit4";
6427 return "DW_OP_lit5";
6429 return "DW_OP_lit6";
6431 return "DW_OP_lit7";
6433 return "DW_OP_lit8";
6435 return "DW_OP_lit9";
6437 return "DW_OP_lit10";
6439 return "DW_OP_lit11";
6441 return "DW_OP_lit12";
6443 return "DW_OP_lit13";
6445 return "DW_OP_lit14";
6447 return "DW_OP_lit15";
6449 return "DW_OP_lit16";
6451 return "DW_OP_lit17";
6453 return "DW_OP_lit18";
6455 return "DW_OP_lit19";
6457 return "DW_OP_lit20";
6459 return "DW_OP_lit21";
6461 return "DW_OP_lit22";
6463 return "DW_OP_lit23";
6465 return "DW_OP_lit24";
6467 return "DW_OP_lit25";
6469 return "DW_OP_lit26";
6471 return "DW_OP_lit27";
6473 return "DW_OP_lit28";
6475 return "DW_OP_lit29";
6477 return "DW_OP_lit30";
6479 return "DW_OP_lit31";
6481 return "DW_OP_reg0";
6483 return "DW_OP_reg1";
6485 return "DW_OP_reg2";
6487 return "DW_OP_reg3";
6489 return "DW_OP_reg4";
6491 return "DW_OP_reg5";
6493 return "DW_OP_reg6";
6495 return "DW_OP_reg7";
6497 return "DW_OP_reg8";
6499 return "DW_OP_reg9";
6501 return "DW_OP_reg10";
6503 return "DW_OP_reg11";
6505 return "DW_OP_reg12";
6507 return "DW_OP_reg13";
6509 return "DW_OP_reg14";
6511 return "DW_OP_reg15";
6513 return "DW_OP_reg16";
6515 return "DW_OP_reg17";
6517 return "DW_OP_reg18";
6519 return "DW_OP_reg19";
6521 return "DW_OP_reg20";
6523 return "DW_OP_reg21";
6525 return "DW_OP_reg22";
6527 return "DW_OP_reg23";
6529 return "DW_OP_reg24";
6531 return "DW_OP_reg25";
6533 return "DW_OP_reg26";
6535 return "DW_OP_reg27";
6537 return "DW_OP_reg28";
6539 return "DW_OP_reg29";
6541 return "DW_OP_reg30";
6543 return "DW_OP_reg31";
6545 return "DW_OP_breg0";
6547 return "DW_OP_breg1";
6549 return "DW_OP_breg2";
6551 return "DW_OP_breg3";
6553 return "DW_OP_breg4";
6555 return "DW_OP_breg5";
6557 return "DW_OP_breg6";
6559 return "DW_OP_breg7";
6561 return "DW_OP_breg8";
6563 return "DW_OP_breg9";
6565 return "DW_OP_breg10";
6567 return "DW_OP_breg11";
6569 return "DW_OP_breg12";
6571 return "DW_OP_breg13";
6573 return "DW_OP_breg14";
6575 return "DW_OP_breg15";
6577 return "DW_OP_breg16";
6579 return "DW_OP_breg17";
6581 return "DW_OP_breg18";
6583 return "DW_OP_breg19";
6585 return "DW_OP_breg20";
6587 return "DW_OP_breg21";
6589 return "DW_OP_breg22";
6591 return "DW_OP_breg23";
6593 return "DW_OP_breg24";
6595 return "DW_OP_breg25";
6597 return "DW_OP_breg26";
6599 return "DW_OP_breg27";
6601 return "DW_OP_breg28";
6603 return "DW_OP_breg29";
6605 return "DW_OP_breg30";
6607 return "DW_OP_breg31";
6609 return "DW_OP_regx";
6611 return "DW_OP_fbreg";
6613 return "DW_OP_bregx";
6615 return "DW_OP_piece";
6616 case DW_OP_deref_size
:
6617 return "DW_OP_deref_size";
6618 case DW_OP_xderef_size
:
6619 return "DW_OP_xderef_size";
6622 /* DWARF 3 extensions. */
6623 case DW_OP_push_object_address
:
6624 return "DW_OP_push_object_address";
6626 return "DW_OP_call2";
6628 return "DW_OP_call4";
6629 case DW_OP_call_ref
:
6630 return "DW_OP_call_ref";
6631 /* GNU extensions. */
6632 case DW_OP_GNU_push_tls_address
:
6633 return "DW_OP_GNU_push_tls_address";
6635 return "OP_<unknown>";
6640 dwarf_bool_name (unsigned mybool
)
6648 /* Convert a DWARF type code into its string name. */
6651 dwarf_type_encoding_name (unsigned enc
)
6655 case DW_ATE_address
:
6656 return "DW_ATE_address";
6657 case DW_ATE_boolean
:
6658 return "DW_ATE_boolean";
6659 case DW_ATE_complex_float
:
6660 return "DW_ATE_complex_float";
6662 return "DW_ATE_float";
6664 return "DW_ATE_signed";
6665 case DW_ATE_signed_char
:
6666 return "DW_ATE_signed_char";
6667 case DW_ATE_unsigned
:
6668 return "DW_ATE_unsigned";
6669 case DW_ATE_unsigned_char
:
6670 return "DW_ATE_unsigned_char";
6671 case DW_ATE_imaginary_float
:
6672 return "DW_ATE_imaginary_float";
6674 return "DW_ATE_<unknown>";
6678 /* Convert a DWARF call frame info operation to its string name. */
6682 dwarf_cfi_name (unsigned cfi_opc
)
6686 case DW_CFA_advance_loc
:
6687 return "DW_CFA_advance_loc";
6689 return "DW_CFA_offset";
6690 case DW_CFA_restore
:
6691 return "DW_CFA_restore";
6693 return "DW_CFA_nop";
6694 case DW_CFA_set_loc
:
6695 return "DW_CFA_set_loc";
6696 case DW_CFA_advance_loc1
:
6697 return "DW_CFA_advance_loc1";
6698 case DW_CFA_advance_loc2
:
6699 return "DW_CFA_advance_loc2";
6700 case DW_CFA_advance_loc4
:
6701 return "DW_CFA_advance_loc4";
6702 case DW_CFA_offset_extended
:
6703 return "DW_CFA_offset_extended";
6704 case DW_CFA_restore_extended
:
6705 return "DW_CFA_restore_extended";
6706 case DW_CFA_undefined
:
6707 return "DW_CFA_undefined";
6708 case DW_CFA_same_value
:
6709 return "DW_CFA_same_value";
6710 case DW_CFA_register
:
6711 return "DW_CFA_register";
6712 case DW_CFA_remember_state
:
6713 return "DW_CFA_remember_state";
6714 case DW_CFA_restore_state
:
6715 return "DW_CFA_restore_state";
6716 case DW_CFA_def_cfa
:
6717 return "DW_CFA_def_cfa";
6718 case DW_CFA_def_cfa_register
:
6719 return "DW_CFA_def_cfa_register";
6720 case DW_CFA_def_cfa_offset
:
6721 return "DW_CFA_def_cfa_offset";
6724 case DW_CFA_def_cfa_expression
:
6725 return "DW_CFA_def_cfa_expression";
6726 case DW_CFA_expression
:
6727 return "DW_CFA_expression";
6728 case DW_CFA_offset_extended_sf
:
6729 return "DW_CFA_offset_extended_sf";
6730 case DW_CFA_def_cfa_sf
:
6731 return "DW_CFA_def_cfa_sf";
6732 case DW_CFA_def_cfa_offset_sf
:
6733 return "DW_CFA_def_cfa_offset_sf";
6735 /* SGI/MIPS specific */
6736 case DW_CFA_MIPS_advance_loc8
:
6737 return "DW_CFA_MIPS_advance_loc8";
6739 /* GNU extensions */
6740 case DW_CFA_GNU_window_save
:
6741 return "DW_CFA_GNU_window_save";
6742 case DW_CFA_GNU_args_size
:
6743 return "DW_CFA_GNU_args_size";
6744 case DW_CFA_GNU_negative_offset_extended
:
6745 return "DW_CFA_GNU_negative_offset_extended";
6748 return "DW_CFA_<unknown>";
6754 dump_die (struct die_info
*die
)
6758 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
6759 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
6760 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
6761 dwarf_bool_name (die
->child
!= NULL
));
6763 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
6764 for (i
= 0; i
< die
->num_attrs
; ++i
)
6766 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
6767 dwarf_attr_name (die
->attrs
[i
].name
),
6768 dwarf_form_name (die
->attrs
[i
].form
));
6769 switch (die
->attrs
[i
].form
)
6771 case DW_FORM_ref_addr
:
6773 fprintf_unfiltered (gdb_stderr
, "address: ");
6774 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
6776 case DW_FORM_block2
:
6777 case DW_FORM_block4
:
6779 case DW_FORM_block1
:
6780 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
6791 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
6793 case DW_FORM_string
:
6795 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
6796 DW_STRING (&die
->attrs
[i
])
6797 ? DW_STRING (&die
->attrs
[i
]) : "");
6800 if (DW_UNSND (&die
->attrs
[i
]))
6801 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
6803 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
6805 case DW_FORM_indirect
:
6806 /* the reader will have reduced the indirect form to
6807 the "base form" so this form should not occur */
6808 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
6811 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
6812 die
->attrs
[i
].form
);
6814 fprintf_unfiltered (gdb_stderr
, "\n");
6819 dump_die_list (struct die_info
*die
)
6824 if (die
->child
!= NULL
)
6825 dump_die_list (die
->child
);
6826 if (die
->sibling
!= NULL
)
6827 dump_die_list (die
->sibling
);
6832 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
6835 struct die_info
*old
;
6837 h
= (offset
% REF_HASH_SIZE
);
6838 old
= die_ref_table
[h
];
6839 die
->next_ref
= old
;
6840 die_ref_table
[h
] = die
;
6845 dwarf2_empty_hash_tables (void)
6847 memset (die_ref_table
, 0, sizeof (die_ref_table
));
6851 dwarf2_get_ref_die_offset (struct attribute
*attr
)
6853 unsigned int result
= 0;
6857 case DW_FORM_ref_addr
:
6858 result
= DW_ADDR (attr
);
6864 case DW_FORM_ref_udata
:
6865 result
= cu_header_offset
+ DW_UNSND (attr
);
6868 complaint (&symfile_complaints
,
6869 "unsupported die ref attribute form: '%s'",
6870 dwarf_form_name (attr
->form
));
6875 static struct die_info
*
6876 follow_die_ref (unsigned int offset
)
6878 struct die_info
*die
;
6881 h
= (offset
% REF_HASH_SIZE
);
6882 die
= die_ref_table
[h
];
6885 if (die
->offset
== offset
)
6889 die
= die
->next_ref
;
6894 static struct type
*
6895 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
6897 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
6899 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
6900 typeid, objfile
->name
);
6903 /* Look for this particular type in the fundamental type vector. If
6904 one is not found, create and install one appropriate for the
6905 current language and the current target machine. */
6907 if (ftypes
[typeid] == NULL
)
6909 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
6912 return (ftypes
[typeid]);
6915 /* Decode simple location descriptions.
6916 Given a pointer to a dwarf block that defines a location, compute
6917 the location and return the value.
6919 FIXME: This is a kludge until we figure out a better
6920 way to handle the location descriptions.
6921 Gdb's design does not mesh well with the DWARF2 notion of a location
6922 computing interpreter, which is a shame because the flexibility goes unused.
6923 FIXME: Implement more operations as necessary.
6925 A location description containing no operations indicates that the
6926 object is optimized out. The global optimized_out flag is set for
6927 those, the return value is meaningless.
6929 When the result is a register number, the global isreg flag is set,
6930 otherwise it is cleared.
6932 When the result is a base register offset, the global offreg flag is set
6933 and the register number is returned in basereg, otherwise it is cleared.
6935 When the DW_OP_fbreg operation is encountered without a corresponding
6936 DW_AT_frame_base attribute, the global islocal flag is set.
6937 Hopefully the machine dependent code knows how to set up a virtual
6938 frame pointer for the local references.
6940 Note that stack[0] is unused except as a default error return.
6941 Note that stack overflow is not yet handled. */
6944 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
6945 const struct comp_unit_head
*cu_header
)
6948 int size
= blk
->size
;
6949 char *data
= blk
->data
;
6950 CORE_ADDR stack
[64];
6952 unsigned int bytes_read
, unsnd
;
7002 stack
[++stacki
] = op
- DW_OP_lit0
;
7038 stack
[++stacki
] = op
- DW_OP_reg0
;
7043 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
7045 stack
[++stacki
] = unsnd
;
7081 basereg
= op
- DW_OP_breg0
;
7082 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
7088 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
7090 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
7095 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
7097 if (frame_base_reg
>= 0)
7100 basereg
= frame_base_reg
;
7101 stack
[stacki
] += frame_base_offset
;
7105 complaint (&symfile_complaints
,
7106 "DW_AT_frame_base missing for DW_OP_fbreg");
7112 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
7113 cu_header
, &bytes_read
);
7118 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
7123 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
7128 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
7133 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
7138 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
7143 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
7148 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
7154 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
7159 stack
[stacki
+ 1] = stack
[stacki
];
7164 stack
[stacki
- 1] += stack
[stacki
];
7168 case DW_OP_plus_uconst
:
7169 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
7174 stack
[stacki
- 1] -= stack
[stacki
];
7180 /* If we're not the last op, then we definitely can't encode
7181 this using GDB's address_class enum. */
7183 dwarf2_complex_location_expr_complaint ();
7186 case DW_OP_GNU_push_tls_address
:
7187 /* The top of the stack has the offset from the beginning
7188 of the thread control block at which the variable is located. */
7189 /* Nothing should follow this operator, so the top of stack would
7192 dwarf2_complex_location_expr_complaint ();
7196 complaint (&symfile_complaints
, "unsupported stack op: '%s'",
7197 dwarf_stack_op_name (op
));
7198 return (stack
[stacki
]);
7201 return (stack
[stacki
]);
7204 /* memory allocation interface */
7207 dwarf2_free_tmp_obstack (void *ignore
)
7209 obstack_free (&dwarf2_tmp_obstack
, NULL
);
7212 static struct dwarf_block
*
7213 dwarf_alloc_block (void)
7215 struct dwarf_block
*blk
;
7217 blk
= (struct dwarf_block
*)
7218 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
7222 static struct abbrev_info
*
7223 dwarf_alloc_abbrev (void)
7225 struct abbrev_info
*abbrev
;
7227 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
7228 memset (abbrev
, 0, sizeof (struct abbrev_info
));
7232 static struct die_info
*
7233 dwarf_alloc_die (void)
7235 struct die_info
*die
;
7237 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
7238 memset (die
, 0, sizeof (struct die_info
));
7243 /* Macro support. */
7246 /* Return the full name of file number I in *LH's file name table.
7247 Use COMP_DIR as the name of the current directory of the
7248 compilation. The result is allocated using xmalloc; the caller is
7249 responsible for freeing it. */
7251 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
7253 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7255 if (IS_ABSOLUTE_PATH (fe
->name
))
7256 return xstrdup (fe
->name
);
7264 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7270 dir_len
= strlen (dir
);
7271 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
7272 strcpy (full_name
, dir
);
7273 full_name
[dir_len
] = '/';
7274 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
7278 return xstrdup (fe
->name
);
7283 static struct macro_source_file
*
7284 macro_start_file (int file
, int line
,
7285 struct macro_source_file
*current_file
,
7286 const char *comp_dir
,
7287 struct line_header
*lh
, struct objfile
*objfile
)
7289 /* The full name of this source file. */
7290 char *full_name
= file_full_name (file
, lh
, comp_dir
);
7292 /* We don't create a macro table for this compilation unit
7293 at all until we actually get a filename. */
7294 if (! pending_macros
)
7295 pending_macros
= new_macro_table (&objfile
->symbol_obstack
,
7296 objfile
->macro_cache
);
7299 /* If we have no current file, then this must be the start_file
7300 directive for the compilation unit's main source file. */
7301 current_file
= macro_set_main (pending_macros
, full_name
);
7303 current_file
= macro_include (current_file
, line
, full_name
);
7307 return current_file
;
7311 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
7312 followed by a null byte. */
7314 copy_string (const char *buf
, int len
)
7316 char *s
= xmalloc (len
+ 1);
7317 memcpy (s
, buf
, len
);
7325 consume_improper_spaces (const char *p
, const char *body
)
7329 complaint (&symfile_complaints
,
7330 "macro definition contains spaces in formal argument list:\n`%s'",
7342 parse_macro_definition (struct macro_source_file
*file
, int line
,
7347 /* The body string takes one of two forms. For object-like macro
7348 definitions, it should be:
7350 <macro name> " " <definition>
7352 For function-like macro definitions, it should be:
7354 <macro name> "() " <definition>
7356 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
7358 Spaces may appear only where explicitly indicated, and in the
7361 The Dwarf 2 spec says that an object-like macro's name is always
7362 followed by a space, but versions of GCC around March 2002 omit
7363 the space when the macro's definition is the empty string.
7365 The Dwarf 2 spec says that there should be no spaces between the
7366 formal arguments in a function-like macro's formal argument list,
7367 but versions of GCC around March 2002 include spaces after the
7371 /* Find the extent of the macro name. The macro name is terminated
7372 by either a space or null character (for an object-like macro) or
7373 an opening paren (for a function-like macro). */
7374 for (p
= body
; *p
; p
++)
7375 if (*p
== ' ' || *p
== '(')
7378 if (*p
== ' ' || *p
== '\0')
7380 /* It's an object-like macro. */
7381 int name_len
= p
- body
;
7382 char *name
= copy_string (body
, name_len
);
7383 const char *replacement
;
7386 replacement
= body
+ name_len
+ 1;
7389 dwarf2_macro_malformed_definition_complaint (body
);
7390 replacement
= body
+ name_len
;
7393 macro_define_object (file
, line
, name
, replacement
);
7399 /* It's a function-like macro. */
7400 char *name
= copy_string (body
, p
- body
);
7403 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
7407 p
= consume_improper_spaces (p
, body
);
7409 /* Parse the formal argument list. */
7410 while (*p
&& *p
!= ')')
7412 /* Find the extent of the current argument name. */
7413 const char *arg_start
= p
;
7415 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
7418 if (! *p
|| p
== arg_start
)
7419 dwarf2_macro_malformed_definition_complaint (body
);
7422 /* Make sure argv has room for the new argument. */
7423 if (argc
>= argv_size
)
7426 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
7429 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
7432 p
= consume_improper_spaces (p
, body
);
7434 /* Consume the comma, if present. */
7439 p
= consume_improper_spaces (p
, body
);
7448 /* Perfectly formed definition, no complaints. */
7449 macro_define_function (file
, line
, name
,
7450 argc
, (const char **) argv
,
7452 else if (*p
== '\0')
7454 /* Complain, but do define it. */
7455 dwarf2_macro_malformed_definition_complaint (body
);
7456 macro_define_function (file
, line
, name
,
7457 argc
, (const char **) argv
,
7461 /* Just complain. */
7462 dwarf2_macro_malformed_definition_complaint (body
);
7465 /* Just complain. */
7466 dwarf2_macro_malformed_definition_complaint (body
);
7472 for (i
= 0; i
< argc
; i
++)
7478 dwarf2_macro_malformed_definition_complaint (body
);
7483 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
7484 char *comp_dir
, bfd
*abfd
,
7485 const struct comp_unit_head
*cu_header
,
7486 struct objfile
*objfile
)
7488 char *mac_ptr
, *mac_end
;
7489 struct macro_source_file
*current_file
= 0;
7491 if (dwarf_macinfo_buffer
== NULL
)
7493 complaint (&symfile_complaints
, "missing .debug_macinfo section");
7497 mac_ptr
= dwarf_macinfo_buffer
+ offset
;
7498 mac_end
= dwarf_macinfo_buffer
+ dwarf_macinfo_size
;
7502 enum dwarf_macinfo_record_type macinfo_type
;
7504 /* Do we at least have room for a macinfo type byte? */
7505 if (mac_ptr
>= mac_end
)
7507 dwarf2_macros_too_long_complaint ();
7511 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
7514 switch (macinfo_type
)
7516 /* A zero macinfo type indicates the end of the macro
7521 case DW_MACINFO_define
:
7522 case DW_MACINFO_undef
:
7528 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7529 mac_ptr
+= bytes_read
;
7530 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
7531 mac_ptr
+= bytes_read
;
7534 complaint (&symfile_complaints
,
7535 "debug info gives macro %s outside of any file: %s",
7537 DW_MACINFO_define
? "definition" : macinfo_type
==
7538 DW_MACINFO_undef
? "undefinition" :
7539 "something-or-other", body
);
7542 if (macinfo_type
== DW_MACINFO_define
)
7543 parse_macro_definition (current_file
, line
, body
);
7544 else if (macinfo_type
== DW_MACINFO_undef
)
7545 macro_undef (current_file
, line
, body
);
7550 case DW_MACINFO_start_file
:
7555 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7556 mac_ptr
+= bytes_read
;
7557 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7558 mac_ptr
+= bytes_read
;
7560 current_file
= macro_start_file (file
, line
,
7561 current_file
, comp_dir
,
7566 case DW_MACINFO_end_file
:
7568 complaint (&symfile_complaints
,
7569 "macro debug info has an unmatched `close_file' directive");
7572 current_file
= current_file
->included_by
;
7575 enum dwarf_macinfo_record_type next_type
;
7577 /* GCC circa March 2002 doesn't produce the zero
7578 type byte marking the end of the compilation
7579 unit. Complain if it's not there, but exit no
7582 /* Do we at least have room for a macinfo type byte? */
7583 if (mac_ptr
>= mac_end
)
7585 dwarf2_macros_too_long_complaint ();
7589 /* We don't increment mac_ptr here, so this is just
7591 next_type
= read_1_byte (abfd
, mac_ptr
);
7593 complaint (&symfile_complaints
,
7594 "no terminating 0-type entry for macros in `.debug_macinfo' section");
7601 case DW_MACINFO_vendor_ext
:
7607 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7608 mac_ptr
+= bytes_read
;
7609 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
7610 mac_ptr
+= bytes_read
;
7612 /* We don't recognize any vendor extensions. */
7619 /* Check if the attribute's form is a DW_FORM_block*
7620 if so return true else false. */
7622 attr_form_is_block (struct attribute
*attr
)
7624 return (attr
== NULL
? 0 :
7625 attr
->form
== DW_FORM_block1
7626 || attr
->form
== DW_FORM_block2
7627 || attr
->form
== DW_FORM_block4
7628 || attr
->form
== DW_FORM_block
);
7632 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
7633 const struct comp_unit_head
*cu_header
,
7634 struct objfile
*objfile
)
7636 if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
7638 struct dwarf2_loclist_baton
*baton
;
7640 baton
= obstack_alloc (&objfile
->symbol_obstack
,
7641 sizeof (struct dwarf2_loclist_baton
));
7642 baton
->objfile
= objfile
;
7644 /* We don't know how long the location list is, but make sure we
7645 don't run off the edge of the section. */
7646 baton
->size
= dwarf_loc_size
- DW_UNSND (attr
);
7647 baton
->data
= dwarf_loc_buffer
+ DW_UNSND (attr
);
7648 baton
->base_address
= cu_header
->base_address
;
7649 if (cu_header
->base_known
== 0)
7650 complaint (&symfile_complaints
,
7651 "Location list used without specifying the CU base address.");
7653 SYMBOL_LOCATION_FUNCS (sym
) = &dwarf2_loclist_funcs
;
7654 SYMBOL_LOCATION_BATON (sym
) = baton
;
7658 struct dwarf2_locexpr_baton
*baton
;
7660 baton
= obstack_alloc (&objfile
->symbol_obstack
,
7661 sizeof (struct dwarf2_locexpr_baton
));
7662 baton
->objfile
= objfile
;
7664 if (attr_form_is_block (attr
))
7666 /* Note that we're just copying the block's data pointer
7667 here, not the actual data. We're still pointing into the
7668 dwarf_info_buffer for SYM's objfile; right now we never
7669 release that buffer, but when we do clean up properly
7670 this may need to change. */
7671 baton
->size
= DW_BLOCK (attr
)->size
;
7672 baton
->data
= DW_BLOCK (attr
)->data
;
7676 dwarf2_invalid_attrib_class_complaint ("location description",
7677 SYMBOL_NATURAL_NAME (sym
));
7682 SYMBOL_LOCATION_FUNCS (sym
) = &dwarf2_locexpr_funcs
;
7683 SYMBOL_LOCATION_BATON (sym
) = baton
;