1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 Free Software Foundation, Inc.
6 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
7 Inc. with support from Florida State University (under contract
8 with the Ada Joint Program Office), and Silicon Graphics, Inc.
9 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
10 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
11 support in dwarfread.c
13 This file is part of GDB.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or (at
18 your option) any later version.
20 This program is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. */
36 #include "elf/dwarf2.h"
39 #include "expression.h"
40 #include "filenames.h" /* for DOSish file names */
43 #include "complaints.h"
45 #include "dwarf2expr.h"
46 #include "dwarf2loc.h"
47 #include "cp-support.h"
50 #include "gdb_string.h"
51 #include "gdb_assert.h"
52 #include <sys/types.h>
54 #ifndef DWARF2_REG_TO_REGNUM
55 #define DWARF2_REG_TO_REGNUM(REG) (REG)
59 /* .debug_info header for a compilation unit
60 Because of alignment constraints, this structure has padding and cannot
61 be mapped directly onto the beginning of the .debug_info section. */
62 typedef struct comp_unit_header
64 unsigned int length
; /* length of the .debug_info
66 unsigned short version
; /* version number -- 2 for DWARF
68 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
69 unsigned char addr_size
; /* byte size of an address -- 4 */
72 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
75 /* .debug_pubnames header
76 Because of alignment constraints, this structure has padding and cannot
77 be mapped directly onto the beginning of the .debug_info section. */
78 typedef struct pubnames_header
80 unsigned int length
; /* length of the .debug_pubnames
82 unsigned char version
; /* version number -- 2 for DWARF
84 unsigned int info_offset
; /* offset into .debug_info section */
85 unsigned int info_size
; /* byte size of .debug_info section
89 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
91 /* .debug_pubnames header
92 Because of alignment constraints, this structure has padding and cannot
93 be mapped directly onto the beginning of the .debug_info section. */
94 typedef struct aranges_header
96 unsigned int length
; /* byte len of the .debug_aranges
98 unsigned short version
; /* version number -- 2 for DWARF
100 unsigned int info_offset
; /* offset into .debug_info section */
101 unsigned char addr_size
; /* byte size of an address */
102 unsigned char seg_size
; /* byte size of segment descriptor */
105 #define _ACTUAL_ARANGES_HEADER_SIZE 12
107 /* .debug_line statement program prologue
108 Because of alignment constraints, this structure has padding and cannot
109 be mapped directly onto the beginning of the .debug_info section. */
110 typedef struct statement_prologue
112 unsigned int total_length
; /* byte length of the statement
114 unsigned short version
; /* version number -- 2 for DWARF
116 unsigned int prologue_length
; /* # bytes between prologue &
118 unsigned char minimum_instruction_length
; /* byte size of
120 unsigned char default_is_stmt
; /* initial value of is_stmt
123 unsigned char line_range
;
124 unsigned char opcode_base
; /* number assigned to first special
126 unsigned char *standard_opcode_lengths
;
130 /* offsets and sizes of debugging sections */
132 static unsigned int dwarf_info_size
;
133 static unsigned int dwarf_abbrev_size
;
134 static unsigned int dwarf_line_size
;
135 static unsigned int dwarf_pubnames_size
;
136 static unsigned int dwarf_aranges_size
;
137 static unsigned int dwarf_loc_size
;
138 static unsigned int dwarf_macinfo_size
;
139 static unsigned int dwarf_str_size
;
140 static unsigned int dwarf_ranges_size
;
141 unsigned int dwarf_frame_size
;
142 unsigned int dwarf_eh_frame_size
;
144 static asection
*dwarf_info_section
;
145 static asection
*dwarf_abbrev_section
;
146 static asection
*dwarf_line_section
;
147 static asection
*dwarf_pubnames_section
;
148 static asection
*dwarf_aranges_section
;
149 static asection
*dwarf_loc_section
;
150 static asection
*dwarf_macinfo_section
;
151 static asection
*dwarf_str_section
;
152 static asection
*dwarf_ranges_section
;
153 asection
*dwarf_frame_section
;
154 asection
*dwarf_eh_frame_section
;
156 /* names of the debugging sections */
158 #define INFO_SECTION ".debug_info"
159 #define ABBREV_SECTION ".debug_abbrev"
160 #define LINE_SECTION ".debug_line"
161 #define PUBNAMES_SECTION ".debug_pubnames"
162 #define ARANGES_SECTION ".debug_aranges"
163 #define LOC_SECTION ".debug_loc"
164 #define MACINFO_SECTION ".debug_macinfo"
165 #define STR_SECTION ".debug_str"
166 #define RANGES_SECTION ".debug_ranges"
167 #define FRAME_SECTION ".debug_frame"
168 #define EH_FRAME_SECTION ".eh_frame"
170 /* local data types */
172 /* We hold several abbreviation tables in memory at the same time. */
173 #ifndef ABBREV_HASH_SIZE
174 #define ABBREV_HASH_SIZE 121
177 /* The data in a compilation unit header, after target2host
178 translation, looks like this. */
179 struct comp_unit_head
181 unsigned long length
;
183 unsigned int abbrev_offset
;
184 unsigned char addr_size
;
185 unsigned char signed_addr_p
;
186 unsigned int offset_size
; /* size of file offsets; either 4 or 8 */
187 unsigned int initial_length_size
; /* size of the length field; either
190 /* Offset to the first byte of this compilation unit header in the
191 * .debug_info section, for resolving relative reference dies. */
195 /* Pointer to this compilation unit header in the .debug_info
200 /* Pointer to the first die of this compilatio unit. This will
201 * be the first byte following the compilation unit header. */
205 /* Pointer to the next compilation unit header in the program. */
207 struct comp_unit_head
*next
;
209 /* DWARF abbreviation table associated with this compilation unit */
211 struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
213 /* Base address of this compilation unit. */
215 CORE_ADDR base_address
;
217 /* Non-zero if base_address has been set. */
222 /* Internal state when decoding a particular compilation unit. */
225 /* The objfile containing this compilation unit. */
226 struct objfile
*objfile
;
228 /* The header of the compilation unit.
230 FIXME drow/2003-11-10: Some of the things from the comp_unit_head
231 should be moved to the dwarf2_cu structure; for instance the abbrevs
233 struct comp_unit_head header
;
236 /* The line number information for a compilation unit (found in the
237 .debug_line section) begins with a "statement program header",
238 which contains the following information. */
241 unsigned int total_length
;
242 unsigned short version
;
243 unsigned int header_length
;
244 unsigned char minimum_instruction_length
;
245 unsigned char default_is_stmt
;
247 unsigned char line_range
;
248 unsigned char opcode_base
;
250 /* standard_opcode_lengths[i] is the number of operands for the
251 standard opcode whose value is i. This means that
252 standard_opcode_lengths[0] is unused, and the last meaningful
253 element is standard_opcode_lengths[opcode_base - 1]. */
254 unsigned char *standard_opcode_lengths
;
256 /* The include_directories table. NOTE! These strings are not
257 allocated with xmalloc; instead, they are pointers into
258 debug_line_buffer. If you try to free them, `free' will get
260 unsigned int num_include_dirs
, include_dirs_size
;
263 /* The file_names table. NOTE! These strings are not allocated
264 with xmalloc; instead, they are pointers into debug_line_buffer.
265 Don't try to free them directly. */
266 unsigned int num_file_names
, file_names_size
;
270 unsigned int dir_index
;
271 unsigned int mod_time
;
275 /* The start and end of the statement program following this
276 header. These point into dwarf_line_buffer. */
277 char *statement_program_start
, *statement_program_end
;
280 /* When we construct a partial symbol table entry we only
281 need this much information. */
282 struct partial_die_info
285 unsigned char has_children
;
286 unsigned char is_external
;
287 unsigned char is_declaration
;
288 unsigned char has_type
;
295 struct dwarf_block
*locdesc
;
296 unsigned int language
;
300 /* This data structure holds the information of an abbrev. */
303 unsigned int number
; /* number identifying abbrev */
304 enum dwarf_tag tag
; /* dwarf tag */
305 int has_children
; /* boolean */
306 unsigned int num_attrs
; /* number of attributes */
307 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
308 struct abbrev_info
*next
; /* next in chain */
313 enum dwarf_attribute name
;
314 enum dwarf_form form
;
317 /* This data structure holds a complete die structure. */
320 enum dwarf_tag tag
; /* Tag indicating type of die */
321 unsigned int abbrev
; /* Abbrev number */
322 unsigned int offset
; /* Offset in .debug_info section */
323 unsigned int num_attrs
; /* Number of attributes */
324 struct attribute
*attrs
; /* An array of attributes */
325 struct die_info
*next_ref
; /* Next die in ref hash table */
327 /* The dies in a compilation unit form an n-ary tree. PARENT
328 points to this die's parent; CHILD points to the first child of
329 this node; and all the children of a given node are chained
330 together via their SIBLING fields, terminated by a die whose
332 struct die_info
*child
; /* Its first child, if any. */
333 struct die_info
*sibling
; /* Its next sibling, if any. */
334 struct die_info
*parent
; /* Its parent, if any. */
336 struct type
*type
; /* Cached type information */
339 /* Attributes have a name and a value */
342 enum dwarf_attribute name
;
343 enum dwarf_form form
;
347 struct dwarf_block
*blk
;
355 struct function_range
358 CORE_ADDR lowpc
, highpc
;
360 struct function_range
*next
;
363 static struct function_range
*cu_first_fn
, *cu_last_fn
, *cu_cached_fn
;
365 /* Get at parts of an attribute structure */
367 #define DW_STRING(attr) ((attr)->u.str)
368 #define DW_UNSND(attr) ((attr)->u.unsnd)
369 #define DW_BLOCK(attr) ((attr)->u.blk)
370 #define DW_SND(attr) ((attr)->u.snd)
371 #define DW_ADDR(attr) ((attr)->u.addr)
373 /* Blocks are a bunch of untyped bytes. */
380 #ifndef ATTR_ALLOC_CHUNK
381 #define ATTR_ALLOC_CHUNK 4
384 /* A hash table of die offsets for following references. */
385 #ifndef REF_HASH_SIZE
386 #define REF_HASH_SIZE 1021
389 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
391 /* Obstack for allocating temporary storage used during symbol reading. */
392 static struct obstack dwarf2_tmp_obstack
;
394 /* Offset to the first byte of the current compilation unit header,
395 for resolving relative reference dies. */
396 static unsigned int cu_header_offset
;
398 /* Allocate fields for structs, unions and enums in this size. */
399 #ifndef DW_FIELD_ALLOC_CHUNK
400 #define DW_FIELD_ALLOC_CHUNK 4
403 /* The language we are debugging. */
404 static enum language cu_language
;
405 static const struct language_defn
*cu_language_defn
;
407 /* Actually data from the sections. */
408 static char *dwarf_info_buffer
;
409 static char *dwarf_abbrev_buffer
;
410 static char *dwarf_line_buffer
;
411 static char *dwarf_str_buffer
;
412 static char *dwarf_macinfo_buffer
;
413 static char *dwarf_ranges_buffer
;
414 static char *dwarf_loc_buffer
;
416 /* A zeroed version of a partial die for initialization purposes. */
417 static struct partial_die_info zeroed_partial_die
;
419 /* The generic symbol table building routines have separate lists for
420 file scope symbols and all all other scopes (local scopes). So
421 we need to select the right one to pass to add_symbol_to_list().
422 We do it by keeping a pointer to the correct list in list_in_scope.
424 FIXME: The original dwarf code just treated the file scope as the first
425 local scope, and all other local scopes as nested local scopes, and worked
426 fine. Check to see if we really need to distinguish these
428 static struct pending
**list_in_scope
= &file_symbols
;
430 /* FIXME: decode_locdesc sets these variables to describe the location
431 to the caller. These ought to be a structure or something. If
432 none of the flags are set, the object lives at the address returned
433 by decode_locdesc. */
435 static int isreg
; /* Object lives in register.
436 decode_locdesc's return value is
437 the register number. */
439 /* This value is added to each symbol value. FIXME: Generalize to
440 the section_offsets structure used by dbxread (once this is done,
441 pass the appropriate section number to end_symtab). */
442 static CORE_ADDR baseaddr
; /* Add to each symbol value */
444 /* We put a pointer to this structure in the read_symtab_private field
446 The complete dwarf information for an objfile is kept in the
447 psymbol_obstack, so that absolute die references can be handled.
448 Most of the information in this structure is related to an entire
449 object file and could be passed via the sym_private field of the objfile.
450 It is however conceivable that dwarf2 might not be the only type
451 of symbols read from an object file. */
455 /* Pointer to start of dwarf info buffer for the objfile. */
457 char *dwarf_info_buffer
;
459 /* Offset in dwarf_info_buffer for this compilation unit. */
461 unsigned long dwarf_info_offset
;
463 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
465 char *dwarf_abbrev_buffer
;
467 /* Size of dwarf abbreviation section for the objfile. */
469 unsigned int dwarf_abbrev_size
;
471 /* Pointer to start of dwarf line buffer for the objfile. */
473 char *dwarf_line_buffer
;
475 /* Size of dwarf_line_buffer, in bytes. */
477 unsigned int dwarf_line_size
;
479 /* Pointer to start of dwarf string buffer for the objfile. */
481 char *dwarf_str_buffer
;
483 /* Size of dwarf string section for the objfile. */
485 unsigned int dwarf_str_size
;
487 /* Pointer to start of dwarf macro buffer for the objfile. */
489 char *dwarf_macinfo_buffer
;
491 /* Size of dwarf macinfo section for the objfile. */
493 unsigned int dwarf_macinfo_size
;
495 /* Pointer to start of dwarf ranges buffer for the objfile. */
497 char *dwarf_ranges_buffer
;
499 /* Size of dwarf ranges buffer for the objfile. */
501 unsigned int dwarf_ranges_size
;
503 /* Pointer to start of dwarf locations buffer for the objfile. */
505 char *dwarf_loc_buffer
;
507 /* Size of dwarf locations buffer for the objfile. */
509 unsigned int dwarf_loc_size
;
512 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
513 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
514 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
515 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
516 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
517 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
518 #define DWARF_LINE_SIZE(p) (PST_PRIVATE(p)->dwarf_line_size)
519 #define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer)
520 #define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size)
521 #define DWARF_MACINFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_macinfo_buffer)
522 #define DWARF_MACINFO_SIZE(p) (PST_PRIVATE(p)->dwarf_macinfo_size)
523 #define DWARF_RANGES_BUFFER(p) (PST_PRIVATE(p)->dwarf_ranges_buffer)
524 #define DWARF_RANGES_SIZE(p) (PST_PRIVATE(p)->dwarf_ranges_size)
525 #define DWARF_LOC_BUFFER(p) (PST_PRIVATE(p)->dwarf_loc_buffer)
526 #define DWARF_LOC_SIZE(p) (PST_PRIVATE(p)->dwarf_loc_size)
528 /* Maintain an array of referenced fundamental types for the current
529 compilation unit being read. For DWARF version 1, we have to construct
530 the fundamental types on the fly, since no information about the
531 fundamental types is supplied. Each such fundamental type is created by
532 calling a language dependent routine to create the type, and then a
533 pointer to that type is then placed in the array at the index specified
534 by it's FT_<TYPENAME> value. The array has a fixed size set by the
535 FT_NUM_MEMBERS compile time constant, which is the number of predefined
536 fundamental types gdb knows how to construct. */
537 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
539 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
540 but this would require a corresponding change in unpack_field_as_long
542 static int bits_per_byte
= 8;
544 /* The routines that read and process dies for a C struct or C++ class
545 pass lists of data member fields and lists of member function fields
546 in an instance of a field_info structure, as defined below. */
549 /* List of data member and baseclasses fields. */
552 struct nextfield
*next
;
559 /* Number of fields. */
562 /* Number of baseclasses. */
565 /* Set if the accesibility of one of the fields is not public. */
566 int non_public_fields
;
568 /* Member function fields array, entries are allocated in the order they
569 are encountered in the object file. */
572 struct nextfnfield
*next
;
573 struct fn_field fnfield
;
577 /* Member function fieldlist array, contains name of possibly overloaded
578 member function, number of overloaded member functions and a pointer
579 to the head of the member function field chain. */
584 struct nextfnfield
*head
;
588 /* Number of entries in the fnfieldlists array. */
592 /* Various complaints about symbol reading that don't abort the process */
595 dwarf2_non_const_array_bound_ignored_complaint (const char *arg1
)
597 complaint (&symfile_complaints
, "non-constant array bounds form '%s' ignored",
602 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
604 complaint (&symfile_complaints
,
605 "statement list doesn't fit in .debug_line section");
609 dwarf2_complex_location_expr_complaint (void)
611 complaint (&symfile_complaints
, "location expression too complex");
615 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
618 complaint (&symfile_complaints
,
619 "const value length mismatch for '%s', got %d, expected %d", arg1
,
624 dwarf2_macros_too_long_complaint (void)
626 complaint (&symfile_complaints
,
627 "macro info runs off end of `.debug_macinfo' section");
631 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
633 complaint (&symfile_complaints
,
634 "macro debug info contains a malformed macro definition:\n`%s'",
639 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
641 complaint (&symfile_complaints
,
642 "invalid attribute class or form for '%s' in '%s'", arg1
, arg2
);
645 /* local function prototypes */
647 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
650 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
653 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
655 static char *scan_partial_symbols (char *, CORE_ADDR
*, CORE_ADDR
*,
657 const char *namespace);
659 static void add_partial_symbol (struct partial_die_info
*, struct dwarf2_cu
*,
660 const char *namespace);
662 static int pdi_needs_namespace (enum dwarf_tag tag
, const char *namespace);
664 static char *add_partial_namespace (struct partial_die_info
*pdi
,
666 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
667 struct dwarf2_cu
*cu
,
668 const char *namespace);
670 static char *add_partial_structure (struct partial_die_info
*struct_pdi
,
672 struct dwarf2_cu
*cu
,
673 const char *namespace);
675 static char *add_partial_enumeration (struct partial_die_info
*enum_pdi
,
677 struct dwarf2_cu
*cu
,
678 const char *namespace);
680 static char *locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
683 struct dwarf2_cu
*cu
);
685 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
687 static void psymtab_to_symtab_1 (struct partial_symtab
*);
689 char *dwarf2_read_section (struct objfile
*, asection
*);
691 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
693 static void dwarf2_empty_abbrev_table (void *);
695 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
698 static char *read_partial_die (struct partial_die_info
*,
699 bfd
*, char *, struct dwarf2_cu
*);
701 static char *read_full_die (struct die_info
**, bfd
*, char *,
702 struct dwarf2_cu
*, int *);
704 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
705 bfd
*, char *, struct dwarf2_cu
*);
707 static char *read_attribute_value (struct attribute
*, unsigned,
708 bfd
*, char *, struct dwarf2_cu
*);
710 static unsigned int read_1_byte (bfd
*, char *);
712 static int read_1_signed_byte (bfd
*, char *);
714 static unsigned int read_2_bytes (bfd
*, char *);
716 static unsigned int read_4_bytes (bfd
*, char *);
718 static unsigned long read_8_bytes (bfd
*, char *);
720 static CORE_ADDR
read_address (bfd
*, char *ptr
, struct dwarf2_cu
*,
723 static LONGEST
read_initial_length (bfd
*, char *,
724 struct comp_unit_head
*, int *bytes_read
);
726 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
729 static char *read_n_bytes (bfd
*, char *, unsigned int);
731 static char *read_string (bfd
*, char *, unsigned int *);
733 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
736 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
738 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
740 static void set_cu_language (unsigned int);
742 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
744 static int die_is_declaration (struct die_info
*);
746 static struct die_info
*die_specification (struct die_info
*die
);
748 static void free_line_header (struct line_header
*lh
);
750 static struct line_header
*(dwarf_decode_line_header
751 (unsigned int offset
,
752 bfd
*abfd
, struct dwarf2_cu
*cu
));
754 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
757 static void dwarf2_start_subfile (char *, char *);
759 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
762 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
765 static void dwarf2_const_value_data (struct attribute
*attr
,
769 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
771 static struct type
*die_containing_type (struct die_info
*,
775 static struct type
*type_at_offset (unsigned int, struct objfile
*);
778 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
780 static void read_type_die (struct die_info
*, struct dwarf2_cu
*);
782 static char *determine_prefix (struct die_info
*die
);
784 static char *typename_concat (const char *prefix
, const char *suffix
);
786 static char *class_name (struct die_info
*die
);
788 static void read_typedef (struct die_info
*, struct dwarf2_cu
*);
790 static void read_base_type (struct die_info
*, struct dwarf2_cu
*);
792 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
794 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
796 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
798 static int dwarf2_get_pc_bounds (struct die_info
*,
799 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
801 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
804 static void dwarf2_attach_fields_to_type (struct field_info
*,
805 struct type
*, struct dwarf2_cu
*);
807 static void dwarf2_add_member_fn (struct field_info
*,
808 struct die_info
*, struct type
*,
811 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
812 struct type
*, struct dwarf2_cu
*);
814 static void read_structure_scope (struct die_info
*, struct dwarf2_cu
*);
816 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
818 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
820 static const char *namespace_name (struct die_info
*die
,
823 static void read_enumeration (struct die_info
*, struct dwarf2_cu
*);
825 static struct type
*dwarf_base_type (int, int, struct dwarf2_cu
*);
827 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
829 static void read_array_type (struct die_info
*, struct dwarf2_cu
*);
831 static void read_tag_pointer_type (struct die_info
*, struct dwarf2_cu
*);
833 static void read_tag_ptr_to_member_type (struct die_info
*,
836 static void read_tag_reference_type (struct die_info
*, struct dwarf2_cu
*);
838 static void read_tag_const_type (struct die_info
*, struct dwarf2_cu
*);
840 static void read_tag_volatile_type (struct die_info
*, struct dwarf2_cu
*);
842 static void read_tag_string_type (struct die_info
*, struct dwarf2_cu
*);
844 static void read_subroutine_type (struct die_info
*, struct dwarf2_cu
*);
846 static struct die_info
*read_comp_unit (char *, bfd
*, struct dwarf2_cu
*);
848 static struct die_info
*read_die_and_children (char *info_ptr
, bfd
*abfd
,
851 struct die_info
*parent
);
853 static struct die_info
*read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
856 struct die_info
*parent
);
858 static void free_die_list (struct die_info
*);
860 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
862 static void process_die (struct die_info
*, struct dwarf2_cu
*);
864 static char *dwarf2_linkage_name (struct die_info
*);
866 static char *dwarf2_name (struct die_info
*die
);
868 static struct die_info
*dwarf2_extension (struct die_info
*die
);
870 static char *dwarf_tag_name (unsigned int);
872 static char *dwarf_attr_name (unsigned int);
874 static char *dwarf_form_name (unsigned int);
876 static char *dwarf_stack_op_name (unsigned int);
878 static char *dwarf_bool_name (unsigned int);
880 static char *dwarf_type_encoding_name (unsigned int);
883 static char *dwarf_cfi_name (unsigned int);
885 struct die_info
*copy_die (struct die_info
*);
888 static struct die_info
*sibling_die (struct die_info
*);
890 static void dump_die (struct die_info
*);
892 static void dump_die_list (struct die_info
*);
894 static void store_in_ref_table (unsigned int, struct die_info
*);
896 static void dwarf2_empty_hash_tables (void);
898 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
900 static struct die_info
*follow_die_ref (unsigned int);
902 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
904 /* memory allocation interface */
906 static void dwarf2_free_tmp_obstack (void *);
908 static struct dwarf_block
*dwarf_alloc_block (void);
910 static struct abbrev_info
*dwarf_alloc_abbrev (void);
912 static struct die_info
*dwarf_alloc_die (void);
914 static void initialize_cu_func_list (void);
916 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
);
918 static void dwarf_decode_macros (struct line_header
*, unsigned int,
919 char *, bfd
*, struct dwarf2_cu
*);
921 static int attr_form_is_block (struct attribute
*);
924 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
925 struct dwarf2_cu
*cu
);
927 /* Try to locate the sections we need for DWARF 2 debugging
928 information and return true if we have enough to do something. */
931 dwarf2_has_info (bfd
*abfd
)
933 dwarf_info_section
= 0;
934 dwarf_abbrev_section
= 0;
935 dwarf_line_section
= 0;
936 dwarf_str_section
= 0;
937 dwarf_macinfo_section
= 0;
938 dwarf_frame_section
= 0;
939 dwarf_eh_frame_section
= 0;
940 dwarf_ranges_section
= 0;
941 dwarf_loc_section
= 0;
943 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
944 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
947 /* This function is mapped across the sections and remembers the
948 offset and size of each of the debugging sections we are interested
952 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, void *ignore_ptr
)
954 if (strcmp (sectp
->name
, INFO_SECTION
) == 0)
956 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
957 dwarf_info_section
= sectp
;
959 else if (strcmp (sectp
->name
, ABBREV_SECTION
) == 0)
961 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
962 dwarf_abbrev_section
= sectp
;
964 else if (strcmp (sectp
->name
, LINE_SECTION
) == 0)
966 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
967 dwarf_line_section
= sectp
;
969 else if (strcmp (sectp
->name
, PUBNAMES_SECTION
) == 0)
971 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
972 dwarf_pubnames_section
= sectp
;
974 else if (strcmp (sectp
->name
, ARANGES_SECTION
) == 0)
976 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
977 dwarf_aranges_section
= sectp
;
979 else if (strcmp (sectp
->name
, LOC_SECTION
) == 0)
981 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
982 dwarf_loc_section
= sectp
;
984 else if (strcmp (sectp
->name
, MACINFO_SECTION
) == 0)
986 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
987 dwarf_macinfo_section
= sectp
;
989 else if (strcmp (sectp
->name
, STR_SECTION
) == 0)
991 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
992 dwarf_str_section
= sectp
;
994 else if (strcmp (sectp
->name
, FRAME_SECTION
) == 0)
996 dwarf_frame_size
= bfd_get_section_size_before_reloc (sectp
);
997 dwarf_frame_section
= sectp
;
999 else if (strcmp (sectp
->name
, EH_FRAME_SECTION
) == 0)
1001 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1002 if (aflag
& SEC_HAS_CONTENTS
)
1004 dwarf_eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1005 dwarf_eh_frame_section
= sectp
;
1008 else if (strcmp (sectp
->name
, RANGES_SECTION
) == 0)
1010 dwarf_ranges_size
= bfd_get_section_size_before_reloc (sectp
);
1011 dwarf_ranges_section
= sectp
;
1015 /* Build a partial symbol table. */
1018 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1021 /* We definitely need the .debug_info and .debug_abbrev sections */
1023 dwarf_info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1024 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1026 if (dwarf_line_section
)
1027 dwarf_line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1029 dwarf_line_buffer
= NULL
;
1031 if (dwarf_str_section
)
1032 dwarf_str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1034 dwarf_str_buffer
= NULL
;
1036 if (dwarf_macinfo_section
)
1037 dwarf_macinfo_buffer
= dwarf2_read_section (objfile
,
1038 dwarf_macinfo_section
);
1040 dwarf_macinfo_buffer
= NULL
;
1042 if (dwarf_ranges_section
)
1043 dwarf_ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1045 dwarf_ranges_buffer
= NULL
;
1047 if (dwarf_loc_section
)
1048 dwarf_loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1050 dwarf_loc_buffer
= NULL
;
1053 || (objfile
->global_psymbols
.size
== 0
1054 && objfile
->static_psymbols
.size
== 0))
1056 init_psymbol_list (objfile
, 1024);
1060 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1062 /* Things are significantly easier if we have .debug_aranges and
1063 .debug_pubnames sections */
1065 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1069 /* only test this case for now */
1071 /* In this case we have to work a bit harder */
1072 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1077 /* Build the partial symbol table from the information in the
1078 .debug_pubnames and .debug_aranges sections. */
1081 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1083 bfd
*abfd
= objfile
->obfd
;
1084 char *aranges_buffer
, *pubnames_buffer
;
1085 char *aranges_ptr
, *pubnames_ptr
;
1086 unsigned int entry_length
, version
, info_offset
, info_size
;
1088 pubnames_buffer
= dwarf2_read_section (objfile
,
1089 dwarf_pubnames_section
);
1090 pubnames_ptr
= pubnames_buffer
;
1091 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
1093 struct comp_unit_head cu_header
;
1096 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1098 pubnames_ptr
+= bytes_read
;
1099 version
= read_1_byte (abfd
, pubnames_ptr
);
1101 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1103 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1107 aranges_buffer
= dwarf2_read_section (objfile
,
1108 dwarf_aranges_section
);
1113 /* Read in the comp unit header information from the debug_info at
1117 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1118 char *info_ptr
, bfd
*abfd
)
1122 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1124 info_ptr
+= bytes_read
;
1125 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1127 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1129 info_ptr
+= bytes_read
;
1130 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1132 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1133 if (signed_addr
< 0)
1134 internal_error (__FILE__
, __LINE__
,
1135 "read_comp_unit_head: dwarf from non elf file");
1136 cu_header
->signed_addr_p
= signed_addr
;
1140 /* Build the partial symbol table by doing a quick pass through the
1141 .debug_info and .debug_abbrev sections. */
1144 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1146 /* Instead of reading this into a big buffer, we should probably use
1147 mmap() on architectures that support it. (FIXME) */
1148 bfd
*abfd
= objfile
->obfd
;
1149 char *info_ptr
, *abbrev_ptr
;
1150 char *beg_of_comp_unit
;
1151 struct partial_die_info comp_unit_die
;
1152 struct partial_symtab
*pst
;
1153 struct cleanup
*back_to
;
1154 CORE_ADDR lowpc
, highpc
;
1156 info_ptr
= dwarf_info_buffer
;
1157 abbrev_ptr
= dwarf_abbrev_buffer
;
1159 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1160 the partial symbol scan, like attribute values.
1162 We could reduce our peak memory consumption during partial symbol
1163 table construction by freeing stuff from this obstack more often
1164 --- say, after processing each compilation unit, or each die ---
1165 but it turns out that this saves almost nothing. For an
1166 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1167 on dwarf2_tmp_obstack. Some investigation showed:
1169 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1170 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1171 all fixed-length values not requiring dynamic allocation.
1173 2) 30% of the attributes used the form DW_FORM_string. For
1174 DW_FORM_string, read_attribute simply hands back a pointer to
1175 the null-terminated string in dwarf_info_buffer, so no dynamic
1176 allocation is needed there either.
1178 3) The remaining 1% of the attributes all used DW_FORM_block1.
1179 75% of those were DW_AT_frame_base location lists for
1180 functions; the rest were DW_AT_location attributes, probably
1181 for the global variables.
1183 Anyway, what this all means is that the memory the dwarf2
1184 reader uses as temporary space reading partial symbols is about
1185 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1187 obstack_init (&dwarf2_tmp_obstack
);
1188 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1190 /* Since the objects we're extracting from dwarf_info_buffer vary in
1191 length, only the individual functions to extract them (like
1192 read_comp_unit_head and read_partial_die) can really know whether
1193 the buffer is large enough to hold another complete object.
1195 At the moment, they don't actually check that. If
1196 dwarf_info_buffer holds just one extra byte after the last
1197 compilation unit's dies, then read_comp_unit_head will happily
1198 read off the end of the buffer. read_partial_die is similarly
1199 casual. Those functions should be fixed.
1201 For this loop condition, simply checking whether there's any data
1202 left at all should be sufficient. */
1203 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1205 struct dwarf2_cu cu
;
1206 beg_of_comp_unit
= info_ptr
;
1208 cu
.objfile
= objfile
;
1209 info_ptr
= read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1211 if (cu
.header
.version
!= 2)
1213 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
));
1216 if (cu
.header
.abbrev_offset
>= dwarf_abbrev_size
)
1218 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6) [in module %s]",
1219 (long) cu
.header
.abbrev_offset
,
1220 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1221 bfd_get_filename (abfd
));
1224 if (beg_of_comp_unit
+ cu
.header
.length
+ cu
.header
.initial_length_size
1225 > dwarf_info_buffer
+ dwarf_info_size
)
1227 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0) [in module %s]",
1228 (long) cu
.header
.length
,
1229 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1230 bfd_get_filename (abfd
));
1233 /* Complete the cu_header */
1234 cu
.header
.offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1235 cu
.header
.first_die_ptr
= info_ptr
;
1236 cu
.header
.cu_head_ptr
= beg_of_comp_unit
;
1238 /* Read the abbrevs for this compilation unit into a table */
1239 dwarf2_read_abbrevs (abfd
, &cu
);
1240 make_cleanup (dwarf2_empty_abbrev_table
, cu
.header
.dwarf2_abbrevs
);
1242 /* Read the compilation unit die */
1243 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1246 /* Set the language we're debugging */
1247 set_cu_language (comp_unit_die
.language
);
1249 /* Allocate a new partial symbol table structure */
1250 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1251 comp_unit_die
.name
? comp_unit_die
.name
: "",
1252 comp_unit_die
.lowpc
,
1253 objfile
->global_psymbols
.next
,
1254 objfile
->static_psymbols
.next
);
1256 pst
->read_symtab_private
= (char *)
1257 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1258 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1259 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1260 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1261 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1262 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1263 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1264 DWARF_LINE_SIZE (pst
) = dwarf_line_size
;
1265 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1266 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1267 DWARF_MACINFO_BUFFER (pst
) = dwarf_macinfo_buffer
;
1268 DWARF_MACINFO_SIZE (pst
) = dwarf_macinfo_size
;
1269 DWARF_RANGES_BUFFER (pst
) = dwarf_ranges_buffer
;
1270 DWARF_RANGES_SIZE (pst
) = dwarf_ranges_size
;
1271 DWARF_LOC_BUFFER (pst
) = dwarf_loc_buffer
;
1272 DWARF_LOC_SIZE (pst
) = dwarf_loc_size
;
1273 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1275 /* Store the function that reads in the rest of the symbol table */
1276 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1278 /* Check if comp unit has_children.
1279 If so, read the rest of the partial symbols from this comp unit.
1280 If not, there's no more debug_info for this comp unit. */
1281 if (comp_unit_die
.has_children
)
1283 lowpc
= ((CORE_ADDR
) -1);
1284 highpc
= ((CORE_ADDR
) 0);
1286 info_ptr
= scan_partial_symbols (info_ptr
, &lowpc
, &highpc
,
1289 /* If we didn't find a lowpc, set it to highpc to avoid
1290 complaints from `maint check'. */
1291 if (lowpc
== ((CORE_ADDR
) -1))
1294 /* If the compilation unit didn't have an explicit address range,
1295 then use the information extracted from its child dies. */
1296 if (! comp_unit_die
.has_pc_info
)
1298 comp_unit_die
.lowpc
= lowpc
;
1299 comp_unit_die
.highpc
= highpc
;
1302 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1303 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1305 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1306 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1307 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1308 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1309 sort_pst_symbols (pst
);
1311 /* If there is already a psymtab or symtab for a file of this
1312 name, remove it. (If there is a symtab, more drastic things
1313 also happen.) This happens in VxWorks. */
1314 free_named_symtabs (pst
->filename
);
1316 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1317 + cu
.header
.initial_length_size
;
1319 do_cleanups (back_to
);
1322 /* Read in all interesting dies to the end of the compilation unit or
1323 to the end of the current namespace. NAMESPACE is NULL if we
1324 haven't yet encountered any DW_TAG_namespace entries; otherwise,
1325 it's the name of the current namespace. In particular, it's the
1326 empty string if we're currently in the global namespace but have
1327 previously encountered a DW_TAG_namespace. */
1330 scan_partial_symbols (char *info_ptr
, CORE_ADDR
*lowpc
,
1331 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
1332 const char *namespace)
1334 struct objfile
*objfile
= cu
->objfile
;
1335 bfd
*abfd
= objfile
->obfd
;
1336 struct partial_die_info pdi
;
1338 /* Now, march along the PDI's, descending into ones which have
1339 interesting children but skipping the children of the other ones,
1340 until we reach the end of the compilation unit. */
1344 /* This flag tells whether or not info_ptr has gotten updated
1346 int info_ptr_updated
= 0;
1348 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu
);
1350 /* Anonymous namespaces have no name but have interesting
1351 children, so we need to look at them. Ditto for anonymous
1354 if (pdi
.name
!= NULL
|| pdi
.tag
== DW_TAG_namespace
1355 || pdi
.tag
== DW_TAG_enumeration_type
)
1359 case DW_TAG_subprogram
:
1360 if (pdi
.has_pc_info
)
1362 if (pdi
.lowpc
< *lowpc
)
1366 if (pdi
.highpc
> *highpc
)
1368 *highpc
= pdi
.highpc
;
1370 if (!pdi
.is_declaration
)
1372 add_partial_symbol (&pdi
, cu
, namespace);
1376 case DW_TAG_variable
:
1377 case DW_TAG_typedef
:
1378 case DW_TAG_union_type
:
1379 if (!pdi
.is_declaration
)
1381 add_partial_symbol (&pdi
, cu
, namespace);
1384 case DW_TAG_class_type
:
1385 case DW_TAG_structure_type
:
1386 if (!pdi
.is_declaration
)
1388 info_ptr
= add_partial_structure (&pdi
, info_ptr
, cu
,
1390 info_ptr_updated
= 1;
1393 case DW_TAG_enumeration_type
:
1394 if (!pdi
.is_declaration
)
1396 info_ptr
= add_partial_enumeration (&pdi
, info_ptr
, cu
,
1398 info_ptr_updated
= 1;
1401 case DW_TAG_base_type
:
1402 /* File scope base type definitions are added to the partial
1404 add_partial_symbol (&pdi
, cu
, namespace);
1406 case DW_TAG_namespace
:
1407 /* We've hit a DW_TAG_namespace entry, so we know this
1408 file has been compiled using a compiler that
1409 generates them; update NAMESPACE to reflect that. */
1410 if (namespace == NULL
)
1412 info_ptr
= add_partial_namespace (&pdi
, info_ptr
, lowpc
, highpc
,
1414 info_ptr_updated
= 1;
1424 /* If the die has a sibling, skip to the sibling, unless another
1425 function has already updated info_ptr for us. */
1427 /* NOTE: carlton/2003-06-16: This is a bit hackish, but whether
1428 or not we want to update this depends on enough stuff (not
1429 only pdi.tag but also whether or not pdi.name is NULL) that
1430 this seems like the easiest way to handle the issue. */
1432 if (!info_ptr_updated
)
1433 info_ptr
= locate_pdi_sibling (&pdi
, info_ptr
, abfd
, cu
);
1440 add_partial_symbol (struct partial_die_info
*pdi
,
1441 struct dwarf2_cu
*cu
, const char *namespace)
1443 struct objfile
*objfile
= cu
->objfile
;
1445 char *actual_name
= pdi
->name
;
1446 const struct partial_symbol
*psym
= NULL
;
1448 /* If we're not in the global namespace and if the namespace name
1449 isn't encoded in a mangled actual_name, add it. */
1451 if (pdi_needs_namespace (pdi
->tag
, namespace))
1453 actual_name
= alloca (strlen (pdi
->name
) + 2 + strlen (namespace) + 1);
1454 strcpy (actual_name
, namespace);
1455 strcat (actual_name
, "::");
1456 strcat (actual_name
, pdi
->name
);
1461 case DW_TAG_subprogram
:
1462 if (pdi
->is_external
)
1464 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1465 mst_text, objfile); */
1466 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1467 VAR_DOMAIN
, LOC_BLOCK
,
1468 &objfile
->global_psymbols
,
1469 0, pdi
->lowpc
+ baseaddr
,
1470 cu_language
, objfile
);
1474 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1475 mst_file_text, objfile); */
1476 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1477 VAR_DOMAIN
, LOC_BLOCK
,
1478 &objfile
->static_psymbols
,
1479 0, pdi
->lowpc
+ baseaddr
,
1480 cu_language
, objfile
);
1483 case DW_TAG_variable
:
1484 if (pdi
->is_external
)
1487 Don't enter into the minimal symbol tables as there is
1488 a minimal symbol table entry from the ELF symbols already.
1489 Enter into partial symbol table if it has a location
1490 descriptor or a type.
1491 If the location descriptor is missing, new_symbol will create
1492 a LOC_UNRESOLVED symbol, the address of the variable will then
1493 be determined from the minimal symbol table whenever the variable
1495 The address for the partial symbol table entry is not
1496 used by GDB, but it comes in handy for debugging partial symbol
1500 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1501 if (pdi
->locdesc
|| pdi
->has_type
)
1502 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1503 VAR_DOMAIN
, LOC_STATIC
,
1504 &objfile
->global_psymbols
,
1506 cu_language
, objfile
);
1510 /* Static Variable. Skip symbols without location descriptors. */
1511 if (pdi
->locdesc
== NULL
)
1513 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1514 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
1515 mst_file_data, objfile); */
1516 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1517 VAR_DOMAIN
, LOC_STATIC
,
1518 &objfile
->static_psymbols
,
1520 cu_language
, objfile
);
1523 case DW_TAG_typedef
:
1524 case DW_TAG_base_type
:
1525 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1526 VAR_DOMAIN
, LOC_TYPEDEF
,
1527 &objfile
->static_psymbols
,
1528 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1530 case DW_TAG_class_type
:
1531 case DW_TAG_structure_type
:
1532 case DW_TAG_union_type
:
1533 case DW_TAG_enumeration_type
:
1534 /* Skip aggregate types without children, these are external
1536 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
1537 static vs. global. */
1538 if (pdi
->has_children
== 0)
1540 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1541 STRUCT_DOMAIN
, LOC_TYPEDEF
,
1542 cu_language
== language_cplus
1543 ? &objfile
->global_psymbols
1544 : &objfile
->static_psymbols
,
1545 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1547 if (cu_language
== language_cplus
)
1549 /* For C++, these implicitly act as typedefs as well. */
1550 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1551 VAR_DOMAIN
, LOC_TYPEDEF
,
1552 &objfile
->global_psymbols
,
1553 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1556 case DW_TAG_enumerator
:
1557 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1558 VAR_DOMAIN
, LOC_CONST
,
1559 cu_language
== language_cplus
1560 ? &objfile
->static_psymbols
1561 : &objfile
->global_psymbols
,
1562 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1568 /* Check to see if we should scan the name for possible namespace
1569 info. Only do this if this is C++, if we don't have namespace
1570 debugging info in the file, if the psym is of an appropriate type
1571 (otherwise we'll have psym == NULL), and if we actually had a
1572 mangled name to begin with. */
1574 if (cu_language
== language_cplus
1575 && namespace == NULL
1577 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
1578 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
1582 /* Determine whether a die of type TAG living in the C++ namespace
1583 NAMESPACE needs to have the name of the namespace prepended to the
1584 name listed in the die. */
1587 pdi_needs_namespace (enum dwarf_tag tag
, const char *namespace)
1589 if (namespace == NULL
|| namespace[0] == '\0')
1594 case DW_TAG_typedef
:
1595 case DW_TAG_class_type
:
1596 case DW_TAG_structure_type
:
1597 case DW_TAG_union_type
:
1598 case DW_TAG_enumeration_type
:
1599 case DW_TAG_enumerator
:
1606 /* Read a partial die corresponding to a namespace; also, add a symbol
1607 corresponding to that namespace to the symbol table. NAMESPACE is
1608 the name of the enclosing namespace. */
1611 add_partial_namespace (struct partial_die_info
*pdi
, char *info_ptr
,
1612 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1613 struct dwarf2_cu
*cu
, const char *namespace)
1615 struct objfile
*objfile
= cu
->objfile
;
1616 const char *new_name
= pdi
->name
;
1619 /* Calculate the full name of the namespace that we just entered. */
1621 if (new_name
== NULL
)
1622 new_name
= "(anonymous namespace)";
1623 full_name
= alloca (strlen (namespace) + 2 + strlen (new_name
) + 1);
1624 strcpy (full_name
, namespace);
1625 if (*namespace != '\0')
1626 strcat (full_name
, "::");
1627 strcat (full_name
, new_name
);
1629 /* FIXME: carlton/2003-10-07: We can't just replace this by a call
1630 to add_partial_symbol, because we don't have a way to pass in the
1631 full name to that function; that might be a flaw in
1632 add_partial_symbol's interface. */
1634 add_psymbol_to_list (full_name
, strlen (full_name
),
1635 VAR_DOMAIN
, LOC_TYPEDEF
,
1636 &objfile
->global_psymbols
,
1637 0, 0, cu_language
, objfile
);
1639 /* Now scan partial symbols in that namespace. */
1641 if (pdi
->has_children
)
1642 info_ptr
= scan_partial_symbols (info_ptr
, lowpc
, highpc
, cu
, full_name
);
1647 /* Read a partial die corresponding to a class or structure. */
1650 add_partial_structure (struct partial_die_info
*struct_pdi
, char *info_ptr
,
1651 struct dwarf2_cu
*cu
,
1652 const char *namespace)
1654 bfd
*abfd
= cu
->objfile
->obfd
;
1655 char *actual_class_name
= NULL
;
1657 if (cu_language
== language_cplus
1658 && namespace == NULL
1659 && struct_pdi
->name
!= NULL
1660 && struct_pdi
->has_children
)
1662 /* We don't have namespace debugging information, so see if we
1663 can figure out if this structure lives in a namespace. Look
1664 for a member function; its demangled name will contain
1665 namespace info, if there is any. */
1667 /* NOTE: carlton/2003-10-07: Getting the info this way changes
1668 what template types look like, because the demangler
1669 frequently doesn't give the same name as the debug info. We
1670 could fix this by only using the demangled name to get the
1671 prefix (but see comment in read_structure_scope). */
1673 char *next_child
= info_ptr
;
1677 struct partial_die_info child_pdi
;
1679 next_child
= read_partial_die (&child_pdi
, abfd
, next_child
,
1683 if (child_pdi
.tag
== DW_TAG_subprogram
)
1685 actual_class_name
= class_name_from_physname (child_pdi
.name
);
1686 if (actual_class_name
!= NULL
)
1687 struct_pdi
->name
= actual_class_name
;
1692 next_child
= locate_pdi_sibling (&child_pdi
, next_child
,
1698 add_partial_symbol (struct_pdi
, cu
, namespace);
1699 xfree(actual_class_name
);
1701 return locate_pdi_sibling (struct_pdi
, info_ptr
, abfd
, cu
);
1704 /* Read a partial die corresponding to an enumeration type. */
1707 add_partial_enumeration (struct partial_die_info
*enum_pdi
, char *info_ptr
,
1708 struct dwarf2_cu
*cu
, const char *namespace)
1710 struct objfile
*objfile
= cu
->objfile
;
1711 bfd
*abfd
= objfile
->obfd
;
1712 struct partial_die_info pdi
;
1714 if (enum_pdi
->name
!= NULL
)
1715 add_partial_symbol (enum_pdi
, cu
, namespace);
1719 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu
);
1722 if (pdi
.tag
!= DW_TAG_enumerator
|| pdi
.name
== NULL
)
1723 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
1725 add_partial_symbol (&pdi
, cu
, namespace);
1731 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the next DIE
1735 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, char *info_ptr
,
1736 bfd
*abfd
, struct dwarf2_cu
*cu
)
1738 /* Do we know the sibling already? */
1740 if (orig_pdi
->sibling
)
1741 return orig_pdi
->sibling
;
1743 /* Are there any children to deal with? */
1745 if (!orig_pdi
->has_children
)
1748 /* Okay, we don't know the sibling, but we have children that we
1749 want to skip. So read children until we run into one without a
1750 tag; return whatever follows it. */
1754 struct partial_die_info pdi
;
1756 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu
);
1761 info_ptr
= locate_pdi_sibling (&pdi
, info_ptr
, abfd
, cu
);
1765 /* Expand this partial symbol table into a full symbol table. */
1768 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1770 /* FIXME: This is barely more than a stub. */
1775 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1781 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1782 gdb_flush (gdb_stdout
);
1785 psymtab_to_symtab_1 (pst
);
1787 /* Finish up the debug error message. */
1789 printf_filtered ("done.\n");
1795 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1797 struct objfile
*objfile
= pst
->objfile
;
1798 bfd
*abfd
= objfile
->obfd
;
1799 struct dwarf2_cu cu
;
1800 struct die_info
*dies
;
1801 unsigned long offset
;
1802 CORE_ADDR lowpc
, highpc
;
1803 struct die_info
*child_die
;
1805 struct symtab
*symtab
;
1806 struct cleanup
*back_to
;
1807 struct attribute
*attr
;
1809 /* Set local variables from the partial symbol table info. */
1810 offset
= DWARF_INFO_OFFSET (pst
);
1811 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1812 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1813 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1814 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1815 dwarf_line_size
= DWARF_LINE_SIZE (pst
);
1816 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1817 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1818 dwarf_macinfo_buffer
= DWARF_MACINFO_BUFFER (pst
);
1819 dwarf_macinfo_size
= DWARF_MACINFO_SIZE (pst
);
1820 dwarf_ranges_buffer
= DWARF_RANGES_BUFFER (pst
);
1821 dwarf_ranges_size
= DWARF_RANGES_SIZE (pst
);
1822 dwarf_loc_buffer
= DWARF_LOC_BUFFER (pst
);
1823 dwarf_loc_size
= DWARF_LOC_SIZE (pst
);
1824 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1825 cu_header_offset
= offset
;
1826 info_ptr
= dwarf_info_buffer
+ offset
;
1828 /* We're in the global namespace. */
1829 processing_current_prefix
= "";
1831 obstack_init (&dwarf2_tmp_obstack
);
1832 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1835 make_cleanup (really_free_pendings
, NULL
);
1837 cu
.objfile
= objfile
;
1839 /* read in the comp_unit header */
1840 info_ptr
= read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1842 /* Read the abbrevs for this compilation unit */
1843 dwarf2_read_abbrevs (abfd
, &cu
);
1844 make_cleanup (dwarf2_empty_abbrev_table
, cu
.header
.dwarf2_abbrevs
);
1846 dies
= read_comp_unit (info_ptr
, abfd
, &cu
);
1848 make_cleanup_free_die_list (dies
);
1850 /* Find the base address of the compilation unit for range lists and
1851 location lists. It will normally be specified by DW_AT_low_pc.
1852 In DWARF-3 draft 4, the base address could be overridden by
1853 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1854 compilation units with discontinuous ranges. */
1856 cu
.header
.base_known
= 0;
1857 cu
.header
.base_address
= 0;
1859 attr
= dwarf_attr (dies
, DW_AT_entry_pc
);
1862 cu
.header
.base_address
= DW_ADDR (attr
);
1863 cu
.header
.base_known
= 1;
1867 attr
= dwarf_attr (dies
, DW_AT_low_pc
);
1870 cu
.header
.base_address
= DW_ADDR (attr
);
1871 cu
.header
.base_known
= 1;
1875 /* Do line number decoding in read_file_scope () */
1876 process_die (dies
, &cu
);
1878 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, &cu
))
1880 /* Some compilers don't define a DW_AT_high_pc attribute for
1881 the compilation unit. If the DW_AT_high_pc is missing,
1882 synthesize it, by scanning the DIE's below the compilation unit. */
1884 if (dies
->child
!= NULL
)
1886 child_die
= dies
->child
;
1887 while (child_die
&& child_die
->tag
)
1889 if (child_die
->tag
== DW_TAG_subprogram
)
1891 CORE_ADDR low
, high
;
1893 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, &cu
))
1895 highpc
= max (highpc
, high
);
1898 child_die
= sibling_die (child_die
);
1902 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1904 /* Set symtab language to language from DW_AT_language.
1905 If the compilation is from a C file generated by language preprocessors,
1906 do not set the language if it was already deduced by start_subfile. */
1908 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1910 symtab
->language
= cu_language
;
1912 pst
->symtab
= symtab
;
1915 do_cleanups (back_to
);
1918 /* Process a die and its children. */
1921 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
1925 case DW_TAG_padding
:
1927 case DW_TAG_compile_unit
:
1928 read_file_scope (die
, cu
);
1930 case DW_TAG_subprogram
:
1931 read_subroutine_type (die
, cu
);
1932 read_func_scope (die
, cu
);
1934 case DW_TAG_inlined_subroutine
:
1935 /* FIXME: These are ignored for now.
1936 They could be used to set breakpoints on all inlined instances
1937 of a function and make GDB `next' properly over inlined functions. */
1939 case DW_TAG_lexical_block
:
1940 case DW_TAG_try_block
:
1941 case DW_TAG_catch_block
:
1942 read_lexical_block_scope (die
, cu
);
1944 case DW_TAG_class_type
:
1945 case DW_TAG_structure_type
:
1946 case DW_TAG_union_type
:
1947 read_structure_scope (die
, cu
);
1949 case DW_TAG_enumeration_type
:
1950 read_enumeration (die
, cu
);
1952 case DW_TAG_subroutine_type
:
1953 read_subroutine_type (die
, cu
);
1955 case DW_TAG_array_type
:
1956 read_array_type (die
, cu
);
1958 case DW_TAG_pointer_type
:
1959 read_tag_pointer_type (die
, cu
);
1961 case DW_TAG_ptr_to_member_type
:
1962 read_tag_ptr_to_member_type (die
, cu
);
1964 case DW_TAG_reference_type
:
1965 read_tag_reference_type (die
, cu
);
1967 case DW_TAG_string_type
:
1968 read_tag_string_type (die
, cu
);
1970 case DW_TAG_base_type
:
1971 read_base_type (die
, cu
);
1972 if (dwarf_attr (die
, DW_AT_name
))
1974 /* Add a typedef symbol for the base type definition. */
1975 new_symbol (die
, die
->type
, cu
);
1978 case DW_TAG_common_block
:
1979 read_common_block (die
, cu
);
1981 case DW_TAG_common_inclusion
:
1983 case DW_TAG_namespace
:
1984 processing_has_namespace_info
= 1;
1985 read_namespace (die
, cu
);
1987 case DW_TAG_imported_declaration
:
1988 case DW_TAG_imported_module
:
1989 /* FIXME: carlton/2002-10-16: Eventually, we should use the
1990 information contained in these. DW_TAG_imported_declaration
1991 dies shouldn't have children; DW_TAG_imported_module dies
1992 shouldn't in the C++ case, but conceivably could in the
1993 Fortran case, so we'll have to replace this gdb_assert if
1994 Fortran compilers start generating that info. */
1995 processing_has_namespace_info
= 1;
1996 gdb_assert (die
->child
== NULL
);
1999 new_symbol (die
, NULL
, cu
);
2005 initialize_cu_func_list (void)
2007 cu_first_fn
= cu_last_fn
= cu_cached_fn
= NULL
;
2011 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2013 struct objfile
*objfile
= cu
->objfile
;
2014 struct comp_unit_head
*cu_header
= &cu
->header
;
2015 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2016 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2017 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2018 struct attribute
*attr
;
2019 char *name
= "<unknown>";
2020 char *comp_dir
= NULL
;
2021 struct die_info
*child_die
;
2022 bfd
*abfd
= objfile
->obfd
;
2023 struct line_header
*line_header
= 0;
2025 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2027 if (die
->child
!= NULL
)
2029 child_die
= die
->child
;
2030 while (child_die
&& child_die
->tag
)
2032 if (child_die
->tag
== DW_TAG_subprogram
)
2034 CORE_ADDR low
, high
;
2036 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, cu
))
2038 lowpc
= min (lowpc
, low
);
2039 highpc
= max (highpc
, high
);
2042 child_die
= sibling_die (child_die
);
2047 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2048 from finish_block. */
2049 if (lowpc
== ((CORE_ADDR
) -1))
2054 attr
= dwarf_attr (die
, DW_AT_name
);
2057 name
= DW_STRING (attr
);
2059 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
2062 comp_dir
= DW_STRING (attr
);
2065 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2066 directory, get rid of it. */
2067 char *cp
= strchr (comp_dir
, ':');
2069 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2074 if (objfile
->ei
.entry_point
>= lowpc
&&
2075 objfile
->ei
.entry_point
< highpc
)
2077 objfile
->ei
.deprecated_entry_file_lowpc
= lowpc
;
2078 objfile
->ei
.deprecated_entry_file_highpc
= highpc
;
2081 attr
= dwarf_attr (die
, DW_AT_language
);
2084 set_cu_language (DW_UNSND (attr
));
2087 /* We assume that we're processing GCC output. */
2088 processing_gcc_compilation
= 2;
2090 /* FIXME:Do something here. */
2091 if (dip
->at_producer
!= NULL
)
2093 handle_producer (dip
->at_producer
);
2097 /* The compilation unit may be in a different language or objfile,
2098 zero out all remembered fundamental types. */
2099 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
2101 start_symtab (name
, comp_dir
, lowpc
);
2102 record_debugformat ("DWARF 2");
2104 initialize_cu_func_list ();
2106 /* Process all dies in compilation unit. */
2107 if (die
->child
!= NULL
)
2109 child_die
= die
->child
;
2110 while (child_die
&& child_die
->tag
)
2112 process_die (child_die
, cu
);
2113 child_die
= sibling_die (child_die
);
2117 /* Decode line number information if present. */
2118 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
2121 unsigned int line_offset
= DW_UNSND (attr
);
2122 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2125 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
2126 (void *) line_header
);
2127 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
);
2131 /* Decode macro information, if present. Dwarf 2 macro information
2132 refers to information in the line number info statement program
2133 header, so we can only read it if we've read the header
2135 attr
= dwarf_attr (die
, DW_AT_macro_info
);
2136 if (attr
&& line_header
)
2138 unsigned int macro_offset
= DW_UNSND (attr
);
2139 dwarf_decode_macros (line_header
, macro_offset
,
2140 comp_dir
, abfd
, cu
);
2142 do_cleanups (back_to
);
2146 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
)
2148 struct function_range
*thisfn
;
2150 thisfn
= (struct function_range
*)
2151 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct function_range
));
2152 thisfn
->name
= name
;
2153 thisfn
->lowpc
= lowpc
;
2154 thisfn
->highpc
= highpc
;
2155 thisfn
->seen_line
= 0;
2156 thisfn
->next
= NULL
;
2158 if (cu_last_fn
== NULL
)
2159 cu_first_fn
= thisfn
;
2161 cu_last_fn
->next
= thisfn
;
2163 cu_last_fn
= thisfn
;
2167 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2169 struct objfile
*objfile
= cu
->objfile
;
2170 struct context_stack
*new;
2173 struct die_info
*child_die
;
2174 struct attribute
*attr
;
2177 name
= dwarf2_linkage_name (die
);
2179 /* Ignore functions with missing or empty names and functions with
2180 missing or invalid low and high pc attributes. */
2181 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2187 /* Record the function range for dwarf_decode_lines. */
2188 add_to_cu_func_list (name
, lowpc
, highpc
);
2190 if (objfile
->ei
.entry_point
>= lowpc
&&
2191 objfile
->ei
.entry_point
< highpc
)
2193 objfile
->ei
.entry_func_lowpc
= lowpc
;
2194 objfile
->ei
.entry_func_highpc
= highpc
;
2197 new = push_context (0, lowpc
);
2198 new->name
= new_symbol (die
, die
->type
, cu
);
2200 /* If there is a location expression for DW_AT_frame_base, record
2202 attr
= dwarf_attr (die
, DW_AT_frame_base
);
2204 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
2206 list_in_scope
= &local_symbols
;
2208 if (die
->child
!= NULL
)
2210 child_die
= die
->child
;
2211 while (child_die
&& child_die
->tag
)
2213 process_die (child_die
, cu
);
2214 child_die
= sibling_die (child_die
);
2218 new = pop_context ();
2219 /* Make a block for the local symbols within. */
2220 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2221 lowpc
, highpc
, objfile
);
2223 /* In C++, we can have functions nested inside functions (e.g., when
2224 a function declares a class that has methods). This means that
2225 when we finish processing a function scope, we may need to go
2226 back to building a containing block's symbol lists. */
2227 local_symbols
= new->locals
;
2228 param_symbols
= new->params
;
2230 /* If we've finished processing a top-level function, subsequent
2231 symbols go in the file symbol list. */
2232 if (outermost_context_p ())
2233 list_in_scope
= &file_symbols
;
2236 /* Process all the DIES contained within a lexical block scope. Start
2237 a new scope, process the dies, and then close the scope. */
2240 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2242 struct objfile
*objfile
= cu
->objfile
;
2243 struct context_stack
*new;
2244 CORE_ADDR lowpc
, highpc
;
2245 struct die_info
*child_die
;
2247 /* Ignore blocks with missing or invalid low and high pc attributes. */
2248 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2249 as multiple lexical blocks? Handling children in a sane way would
2250 be nasty. Might be easier to properly extend generic blocks to
2252 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2257 push_context (0, lowpc
);
2258 if (die
->child
!= NULL
)
2260 child_die
= die
->child
;
2261 while (child_die
&& child_die
->tag
)
2263 process_die (child_die
, cu
);
2264 child_die
= sibling_die (child_die
);
2267 new = pop_context ();
2269 if (local_symbols
!= NULL
)
2271 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
2274 local_symbols
= new->locals
;
2277 /* Get low and high pc attributes from a die. Return 1 if the attributes
2278 are present and valid, otherwise, return 0. Return -1 if the range is
2279 discontinuous, i.e. derived from DW_AT_ranges information. */
2281 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
2282 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
2284 struct objfile
*objfile
= cu
->objfile
;
2285 struct comp_unit_head
*cu_header
= &cu
->header
;
2286 struct attribute
*attr
;
2287 bfd
*obfd
= objfile
->obfd
;
2292 attr
= dwarf_attr (die
, DW_AT_high_pc
);
2295 high
= DW_ADDR (attr
);
2296 attr
= dwarf_attr (die
, DW_AT_low_pc
);
2298 low
= DW_ADDR (attr
);
2300 /* Found high w/o low attribute. */
2303 /* Found consecutive range of addresses. */
2308 attr
= dwarf_attr (die
, DW_AT_ranges
);
2311 unsigned int addr_size
= cu_header
->addr_size
;
2312 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
2313 /* Value of the DW_AT_ranges attribute is the offset in the
2314 .debug_ranges section. */
2315 unsigned int offset
= DW_UNSND (attr
);
2316 /* Base address selection entry. */
2324 found_base
= cu_header
->base_known
;
2325 base
= cu_header
->base_address
;
2327 if (offset
>= dwarf_ranges_size
)
2329 complaint (&symfile_complaints
,
2330 "Offset %d out of bounds for DW_AT_ranges attribute",
2334 buffer
= dwarf_ranges_buffer
+ offset
;
2336 /* Read in the largest possible address. */
2337 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
2338 if ((marker
& mask
) == mask
)
2340 /* If we found the largest possible address, then
2341 read the base address. */
2342 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2343 buffer
+= 2 * addr_size
;
2344 offset
+= 2 * addr_size
;
2352 CORE_ADDR range_beginning
, range_end
;
2354 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
2355 buffer
+= addr_size
;
2356 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
2357 buffer
+= addr_size
;
2358 offset
+= 2 * addr_size
;
2360 /* An end of list marker is a pair of zero addresses. */
2361 if (range_beginning
== 0 && range_end
== 0)
2362 /* Found the end of list entry. */
2365 /* Each base address selection entry is a pair of 2 values.
2366 The first is the largest possible address, the second is
2367 the base address. Check for a base address here. */
2368 if ((range_beginning
& mask
) == mask
)
2370 /* If we found the largest possible address, then
2371 read the base address. */
2372 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2379 /* We have no valid base address for the ranges
2381 complaint (&symfile_complaints
,
2382 "Invalid .debug_ranges data (no base address)");
2386 range_beginning
+= base
;
2389 /* FIXME: This is recording everything as a low-high
2390 segment of consecutive addresses. We should have a
2391 data structure for discontiguous block ranges
2395 low
= range_beginning
;
2401 if (range_beginning
< low
)
2402 low
= range_beginning
;
2403 if (range_end
> high
)
2409 /* If the first entry is an end-of-list marker, the range
2410 describes an empty scope, i.e. no instructions. */
2420 /* When using the GNU linker, .gnu.linkonce. sections are used to
2421 eliminate duplicate copies of functions and vtables and such.
2422 The linker will arbitrarily choose one and discard the others.
2423 The AT_*_pc values for such functions refer to local labels in
2424 these sections. If the section from that file was discarded, the
2425 labels are not in the output, so the relocs get a value of 0.
2426 If this is a discarded function, mark the pc bounds as invalid,
2427 so that GDB will ignore it. */
2428 if (low
== 0 && (bfd_get_file_flags (obfd
) & HAS_RELOC
) == 0)
2436 /* Add an aggregate field to the field list. */
2439 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
2440 struct dwarf2_cu
*cu
)
2442 struct objfile
*objfile
= cu
->objfile
;
2443 struct nextfield
*new_field
;
2444 struct attribute
*attr
;
2446 char *fieldname
= "";
2448 /* Allocate a new field list entry and link it in. */
2449 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2450 make_cleanup (xfree
, new_field
);
2451 memset (new_field
, 0, sizeof (struct nextfield
));
2452 new_field
->next
= fip
->fields
;
2453 fip
->fields
= new_field
;
2456 /* Handle accessibility and virtuality of field.
2457 The default accessibility for members is public, the default
2458 accessibility for inheritance is private. */
2459 if (die
->tag
!= DW_TAG_inheritance
)
2460 new_field
->accessibility
= DW_ACCESS_public
;
2462 new_field
->accessibility
= DW_ACCESS_private
;
2463 new_field
->virtuality
= DW_VIRTUALITY_none
;
2465 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2467 new_field
->accessibility
= DW_UNSND (attr
);
2468 if (new_field
->accessibility
!= DW_ACCESS_public
)
2469 fip
->non_public_fields
= 1;
2470 attr
= dwarf_attr (die
, DW_AT_virtuality
);
2472 new_field
->virtuality
= DW_UNSND (attr
);
2474 fp
= &new_field
->field
;
2476 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
))
2478 /* Data member other than a C++ static data member. */
2480 /* Get type of field. */
2481 fp
->type
= die_type (die
, cu
);
2483 FIELD_STATIC_KIND (*fp
) = 0;
2485 /* Get bit size of field (zero if none). */
2486 attr
= dwarf_attr (die
, DW_AT_bit_size
);
2489 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
2493 FIELD_BITSIZE (*fp
) = 0;
2496 /* Get bit offset of field. */
2497 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2500 FIELD_BITPOS (*fp
) =
2501 decode_locdesc (DW_BLOCK (attr
), cu
) * bits_per_byte
;
2504 FIELD_BITPOS (*fp
) = 0;
2505 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
2508 if (BITS_BIG_ENDIAN
)
2510 /* For big endian bits, the DW_AT_bit_offset gives the
2511 additional bit offset from the MSB of the containing
2512 anonymous object to the MSB of the field. We don't
2513 have to do anything special since we don't need to
2514 know the size of the anonymous object. */
2515 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
2519 /* For little endian bits, compute the bit offset to the
2520 MSB of the anonymous object, subtract off the number of
2521 bits from the MSB of the field to the MSB of the
2522 object, and then subtract off the number of bits of
2523 the field itself. The result is the bit offset of
2524 the LSB of the field. */
2526 int bit_offset
= DW_UNSND (attr
);
2528 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2531 /* The size of the anonymous object containing
2532 the bit field is explicit, so use the
2533 indicated size (in bytes). */
2534 anonymous_size
= DW_UNSND (attr
);
2538 /* The size of the anonymous object containing
2539 the bit field must be inferred from the type
2540 attribute of the data member containing the
2542 anonymous_size
= TYPE_LENGTH (fp
->type
);
2544 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2545 - bit_offset
- FIELD_BITSIZE (*fp
);
2549 /* Get name of field. */
2550 attr
= dwarf_attr (die
, DW_AT_name
);
2551 if (attr
&& DW_STRING (attr
))
2552 fieldname
= DW_STRING (attr
);
2553 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
2554 &objfile
->type_obstack
);
2556 /* Change accessibility for artificial fields (e.g. virtual table
2557 pointer or virtual base class pointer) to private. */
2558 if (dwarf_attr (die
, DW_AT_artificial
))
2560 new_field
->accessibility
= DW_ACCESS_private
;
2561 fip
->non_public_fields
= 1;
2564 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
2566 /* C++ static member. */
2568 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2569 is a declaration, but all versions of G++ as of this writing
2570 (so through at least 3.2.1) incorrectly generate
2571 DW_TAG_variable tags. */
2575 /* Get name of field. */
2576 attr
= dwarf_attr (die
, DW_AT_name
);
2577 if (attr
&& DW_STRING (attr
))
2578 fieldname
= DW_STRING (attr
);
2582 /* Get physical name. */
2583 physname
= dwarf2_linkage_name (die
);
2585 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
2586 &objfile
->type_obstack
));
2587 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2588 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
2589 &objfile
->type_obstack
);
2591 else if (die
->tag
== DW_TAG_inheritance
)
2593 /* C++ base class field. */
2594 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2596 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
2598 FIELD_BITSIZE (*fp
) = 0;
2599 FIELD_STATIC_KIND (*fp
) = 0;
2600 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2601 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2602 fip
->nbaseclasses
++;
2606 /* Create the vector of fields, and attach it to the type. */
2609 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
2610 struct dwarf2_cu
*cu
)
2612 int nfields
= fip
->nfields
;
2614 /* Record the field count, allocate space for the array of fields,
2615 and create blank accessibility bitfields if necessary. */
2616 TYPE_NFIELDS (type
) = nfields
;
2617 TYPE_FIELDS (type
) = (struct field
*)
2618 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2619 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2621 if (fip
->non_public_fields
)
2623 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2625 TYPE_FIELD_PRIVATE_BITS (type
) =
2626 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2627 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2629 TYPE_FIELD_PROTECTED_BITS (type
) =
2630 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2631 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2633 TYPE_FIELD_IGNORE_BITS (type
) =
2634 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2635 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2638 /* If the type has baseclasses, allocate and clear a bit vector for
2639 TYPE_FIELD_VIRTUAL_BITS. */
2640 if (fip
->nbaseclasses
)
2642 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2645 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2646 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2647 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2648 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2649 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2652 /* Copy the saved-up fields into the field vector. Start from the head
2653 of the list, adding to the tail of the field array, so that they end
2654 up in the same order in the array in which they were added to the list. */
2655 while (nfields
-- > 0)
2657 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2658 switch (fip
->fields
->accessibility
)
2660 case DW_ACCESS_private
:
2661 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2664 case DW_ACCESS_protected
:
2665 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2668 case DW_ACCESS_public
:
2672 /* Unknown accessibility. Complain and treat it as public. */
2674 complaint (&symfile_complaints
, "unsupported accessibility %d",
2675 fip
->fields
->accessibility
);
2679 if (nfields
< fip
->nbaseclasses
)
2681 switch (fip
->fields
->virtuality
)
2683 case DW_VIRTUALITY_virtual
:
2684 case DW_VIRTUALITY_pure_virtual
:
2685 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2689 fip
->fields
= fip
->fields
->next
;
2693 /* Add a member function to the proper fieldlist. */
2696 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2697 struct type
*type
, struct dwarf2_cu
*cu
)
2699 struct objfile
*objfile
= cu
->objfile
;
2700 struct attribute
*attr
;
2701 struct fnfieldlist
*flp
;
2703 struct fn_field
*fnp
;
2706 struct nextfnfield
*new_fnfield
;
2708 /* Get name of member function. */
2709 attr
= dwarf_attr (die
, DW_AT_name
);
2710 if (attr
&& DW_STRING (attr
))
2711 fieldname
= DW_STRING (attr
);
2715 /* Get the mangled name. */
2716 physname
= dwarf2_linkage_name (die
);
2718 /* Look up member function name in fieldlist. */
2719 for (i
= 0; i
< fip
->nfnfields
; i
++)
2721 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
2725 /* Create new list element if necessary. */
2726 if (i
< fip
->nfnfields
)
2727 flp
= &fip
->fnfieldlists
[i
];
2730 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2732 fip
->fnfieldlists
= (struct fnfieldlist
*)
2733 xrealloc (fip
->fnfieldlists
,
2734 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2735 * sizeof (struct fnfieldlist
));
2736 if (fip
->nfnfields
== 0)
2737 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2739 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2740 flp
->name
= fieldname
;
2746 /* Create a new member function field and chain it to the field list
2748 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2749 make_cleanup (xfree
, new_fnfield
);
2750 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2751 new_fnfield
->next
= flp
->head
;
2752 flp
->head
= new_fnfield
;
2755 /* Fill in the member function field info. */
2756 fnp
= &new_fnfield
->fnfield
;
2757 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2758 &objfile
->type_obstack
);
2759 fnp
->type
= alloc_type (objfile
);
2760 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2762 int nparams
= TYPE_NFIELDS (die
->type
);
2764 /* TYPE is the domain of this method, and DIE->TYPE is the type
2765 of the method itself (TYPE_CODE_METHOD). */
2766 smash_to_method_type (fnp
->type
, type
,
2767 TYPE_TARGET_TYPE (die
->type
),
2768 TYPE_FIELDS (die
->type
),
2769 TYPE_NFIELDS (die
->type
),
2770 TYPE_VARARGS (die
->type
));
2772 /* Handle static member functions.
2773 Dwarf2 has no clean way to discern C++ static and non-static
2774 member functions. G++ helps GDB by marking the first
2775 parameter for non-static member functions (which is the
2776 this pointer) as artificial. We obtain this information
2777 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2778 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2779 fnp
->voffset
= VOFFSET_STATIC
;
2782 complaint (&symfile_complaints
, "member function type missing for '%s'",
2785 /* Get fcontext from DW_AT_containing_type if present. */
2786 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2787 fnp
->fcontext
= die_containing_type (die
, cu
);
2789 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2790 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2792 /* Get accessibility. */
2793 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2796 switch (DW_UNSND (attr
))
2798 case DW_ACCESS_private
:
2799 fnp
->is_private
= 1;
2801 case DW_ACCESS_protected
:
2802 fnp
->is_protected
= 1;
2807 /* Check for artificial methods. */
2808 attr
= dwarf_attr (die
, DW_AT_artificial
);
2809 if (attr
&& DW_UNSND (attr
) != 0)
2810 fnp
->is_artificial
= 1;
2812 /* Get index in virtual function table if it is a virtual member function. */
2813 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2816 /* Support the .debug_loc offsets */
2817 if (attr_form_is_block (attr
))
2819 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
2821 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
2823 dwarf2_complex_location_expr_complaint ();
2827 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
2833 /* Create the vector of member function fields, and attach it to the type. */
2836 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2837 struct dwarf2_cu
*cu
)
2839 struct fnfieldlist
*flp
;
2840 int total_length
= 0;
2843 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2844 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2845 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2847 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2849 struct nextfnfield
*nfp
= flp
->head
;
2850 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2853 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2854 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2855 fn_flp
->fn_fields
= (struct fn_field
*)
2856 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2857 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2858 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2860 total_length
+= flp
->length
;
2863 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2864 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2867 /* Called when we find the DIE that starts a structure or union scope
2868 (definition) to process all dies that define the members of the
2871 NOTE: we need to call struct_type regardless of whether or not the
2872 DIE has an at_name attribute, since it might be an anonymous
2873 structure or union. This gets the type entered into our set of
2876 However, if the structure is incomplete (an opaque struct/union)
2877 then suppress creating a symbol table entry for it since gdb only
2878 wants to find the one with the complete definition. Note that if
2879 it is complete, we just call new_symbol, which does it's own
2880 checking about whether the struct/union is anonymous or not (and
2881 suppresses creating a symbol table entry itself). */
2884 read_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2886 struct objfile
*objfile
= cu
->objfile
;
2888 struct attribute
*attr
;
2889 const char *name
= NULL
;
2890 const char *previous_prefix
= processing_current_prefix
;
2891 struct cleanup
*back_to
= NULL
;
2892 /* This says whether or not we want to try to update the structure's
2893 name to include enclosing namespace/class information, if
2895 int need_to_update_name
= 0;
2897 type
= alloc_type (objfile
);
2899 INIT_CPLUS_SPECIFIC (type
);
2900 attr
= dwarf_attr (die
, DW_AT_name
);
2901 if (attr
&& DW_STRING (attr
))
2903 name
= DW_STRING (attr
);
2905 if (cu_language
== language_cplus
)
2907 struct die_info
*spec_die
= die_specification (die
);
2909 if (spec_die
!= NULL
)
2911 char *specification_prefix
= determine_prefix (spec_die
);
2912 processing_current_prefix
= specification_prefix
;
2913 back_to
= make_cleanup (xfree
, specification_prefix
);
2917 if (processing_has_namespace_info
)
2919 /* FIXME: carlton/2003-11-10: This variable exists only for
2920 const-correctness reasons. When I tried to change
2921 TYPE_TAG_NAME to be a const char *, I ran into a cascade
2922 of changes which would have forced decode_line_1 to take
2924 char *new_prefix
= obconcat (&objfile
->type_obstack
,
2925 processing_current_prefix
,
2926 processing_current_prefix
[0] == '\0'
2929 TYPE_TAG_NAME (type
) = new_prefix
;
2930 processing_current_prefix
= new_prefix
;
2934 TYPE_TAG_NAME (type
) = obsavestring (name
, strlen (name
),
2935 &objfile
->type_obstack
);
2936 need_to_update_name
= (cu_language
== language_cplus
);
2940 if (die
->tag
== DW_TAG_structure_type
)
2942 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2944 else if (die
->tag
== DW_TAG_union_type
)
2946 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2950 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2952 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2955 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2958 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2962 TYPE_LENGTH (type
) = 0;
2965 /* We need to add the type field to the die immediately so we don't
2966 infinitely recurse when dealing with pointers to the structure
2967 type within the structure itself. */
2970 if (die
->child
!= NULL
&& ! die_is_declaration (die
))
2972 struct field_info fi
;
2973 struct die_info
*child_die
;
2974 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2976 memset (&fi
, 0, sizeof (struct field_info
));
2978 child_die
= die
->child
;
2980 while (child_die
&& child_die
->tag
)
2982 if (child_die
->tag
== DW_TAG_member
2983 || child_die
->tag
== DW_TAG_variable
)
2985 /* NOTE: carlton/2002-11-05: A C++ static data member
2986 should be a DW_TAG_member that is a declaration, but
2987 all versions of G++ as of this writing (so through at
2988 least 3.2.1) incorrectly generate DW_TAG_variable
2989 tags for them instead. */
2990 dwarf2_add_field (&fi
, child_die
, cu
);
2992 else if (child_die
->tag
== DW_TAG_subprogram
)
2994 /* C++ member function. */
2995 process_die (child_die
, cu
);
2996 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
2997 if (need_to_update_name
)
2999 /* The demangled names of member functions contain
3000 information about enclosing namespaces/classes,
3003 /* FIXME: carlton/2003-11-10: The excessive
3004 demangling here is a bit wasteful, as is the
3005 memory usage for names. */
3007 /* NOTE: carlton/2003-11-10: As commented in
3008 add_partial_structure, the demangler sometimes
3009 prints the type info in a different form from the
3010 debug info. We could solve this by using the
3011 demangled name to get the prefix; if doing so,
3012 however, we'd need to be careful when reading a
3013 class that's nested inside a template class.
3014 That would also cause problems when trying to
3015 determine RTTI information, since we use the
3016 demangler to determine the appropriate class
3018 char *actual_class_name
3019 = class_name_from_physname (dwarf2_linkage_name
3021 if (actual_class_name
!= NULL
3022 && strcmp (actual_class_name
, name
) != 0)
3024 TYPE_TAG_NAME (type
)
3025 = obsavestring (actual_class_name
,
3026 strlen (actual_class_name
),
3027 &objfile
->type_obstack
);
3029 xfree (actual_class_name
);
3030 need_to_update_name
= 0;
3033 else if (child_die
->tag
== DW_TAG_inheritance
)
3035 /* C++ base class field. */
3036 dwarf2_add_field (&fi
, child_die
, cu
);
3040 process_die (child_die
, cu
);
3042 child_die
= sibling_die (child_die
);
3045 /* Attach fields and member functions to the type. */
3047 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
3050 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
3052 /* Get the type which refers to the base class (possibly this
3053 class itself) which contains the vtable pointer for the current
3054 class from the DW_AT_containing_type attribute. */
3056 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
3058 struct type
*t
= die_containing_type (die
, cu
);
3060 TYPE_VPTR_BASETYPE (type
) = t
;
3063 static const char vptr_name
[] =
3064 {'_', 'v', 'p', 't', 'r', '\0'};
3067 /* Our own class provides vtbl ptr. */
3068 for (i
= TYPE_NFIELDS (t
) - 1;
3069 i
>= TYPE_N_BASECLASSES (t
);
3072 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
3074 if ((strncmp (fieldname
, vptr_name
,
3075 strlen (vptr_name
) - 1)
3077 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
3079 TYPE_VPTR_FIELDNO (type
) = i
;
3084 /* Complain if virtual function table field not found. */
3085 if (i
< TYPE_N_BASECLASSES (t
))
3086 complaint (&symfile_complaints
,
3087 "virtual function table pointer not found when defining class '%s'",
3088 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
3093 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3098 new_symbol (die
, type
, cu
);
3100 do_cleanups (back_to
);
3104 /* No children, must be stub. */
3105 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
3108 processing_current_prefix
= previous_prefix
;
3109 if (back_to
!= NULL
)
3110 do_cleanups (back_to
);
3113 /* Given a pointer to a die which begins an enumeration, process all
3114 the dies that define the members of the enumeration.
3116 This will be much nicer in draft 6 of the DWARF spec when our
3117 members will be dies instead squished into the DW_AT_element_list
3120 NOTE: We reverse the order of the element list. */
3123 read_enumeration (struct die_info
*die
, struct dwarf2_cu
*cu
)
3125 struct objfile
*objfile
= cu
->objfile
;
3126 struct die_info
*child_die
;
3128 struct field
*fields
;
3129 struct attribute
*attr
;
3132 int unsigned_enum
= 1;
3134 type
= alloc_type (objfile
);
3136 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
3137 attr
= dwarf_attr (die
, DW_AT_name
);
3138 if (attr
&& DW_STRING (attr
))
3140 const char *name
= DW_STRING (attr
);
3142 if (processing_has_namespace_info
)
3144 TYPE_TAG_NAME (type
) = obconcat (&objfile
->type_obstack
,
3145 processing_current_prefix
,
3146 processing_current_prefix
[0] == '\0'
3152 TYPE_TAG_NAME (type
) = obsavestring (name
, strlen (name
),
3153 &objfile
->type_obstack
);
3157 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3160 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3164 TYPE_LENGTH (type
) = 0;
3169 if (die
->child
!= NULL
)
3171 child_die
= die
->child
;
3172 while (child_die
&& child_die
->tag
)
3174 if (child_die
->tag
!= DW_TAG_enumerator
)
3176 process_die (child_die
, cu
);
3180 attr
= dwarf_attr (child_die
, DW_AT_name
);
3183 sym
= new_symbol (child_die
, type
, cu
);
3184 if (SYMBOL_VALUE (sym
) < 0)
3187 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3189 fields
= (struct field
*)
3191 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
3192 * sizeof (struct field
));
3195 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
3196 FIELD_TYPE (fields
[num_fields
]) = NULL
;
3197 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
3198 FIELD_BITSIZE (fields
[num_fields
]) = 0;
3199 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
3205 child_die
= sibling_die (child_die
);
3210 TYPE_NFIELDS (type
) = num_fields
;
3211 TYPE_FIELDS (type
) = (struct field
*)
3212 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
3213 memcpy (TYPE_FIELDS (type
), fields
,
3214 sizeof (struct field
) * num_fields
);
3218 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
3221 new_symbol (die
, type
, cu
);
3224 /* Extract all information from a DW_TAG_array_type DIE and put it in
3225 the DIE's type field. For now, this only handles one dimensional
3229 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3231 struct objfile
*objfile
= cu
->objfile
;
3232 struct die_info
*child_die
;
3233 struct type
*type
= NULL
;
3234 struct type
*element_type
, *range_type
, *index_type
;
3235 struct type
**range_types
= NULL
;
3236 struct attribute
*attr
;
3238 struct cleanup
*back_to
;
3240 /* Return if we've already decoded this type. */
3246 element_type
= die_type (die
, cu
);
3248 /* Irix 6.2 native cc creates array types without children for
3249 arrays with unspecified length. */
3250 if (die
->child
== NULL
)
3252 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
3253 range_type
= create_range_type (NULL
, index_type
, 0, -1);
3254 die
->type
= create_array_type (NULL
, element_type
, range_type
);
3258 back_to
= make_cleanup (null_cleanup
, NULL
);
3259 child_die
= die
->child
;
3260 while (child_die
&& child_die
->tag
)
3262 if (child_die
->tag
== DW_TAG_subrange_type
)
3264 unsigned int low
, high
;
3266 /* Default bounds to an array with unspecified length. */
3269 if (cu_language
== language_fortran
)
3271 /* FORTRAN implies a lower bound of 1, if not given. */
3275 index_type
= die_type (child_die
, cu
);
3276 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
3279 if (attr
->form
== DW_FORM_sdata
)
3281 low
= DW_SND (attr
);
3283 else if (attr
->form
== DW_FORM_udata
3284 || attr
->form
== DW_FORM_data1
3285 || attr
->form
== DW_FORM_data2
3286 || attr
->form
== DW_FORM_data4
3287 || attr
->form
== DW_FORM_data8
)
3289 low
= DW_UNSND (attr
);
3293 dwarf2_non_const_array_bound_ignored_complaint
3294 (dwarf_form_name (attr
->form
));
3298 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
3301 if (attr
->form
== DW_FORM_sdata
)
3303 high
= DW_SND (attr
);
3305 else if (attr
->form
== DW_FORM_udata
3306 || attr
->form
== DW_FORM_data1
3307 || attr
->form
== DW_FORM_data2
3308 || attr
->form
== DW_FORM_data4
3309 || attr
->form
== DW_FORM_data8
)
3311 high
= DW_UNSND (attr
);
3313 else if (attr
->form
== DW_FORM_block1
)
3315 /* GCC encodes arrays with unspecified or dynamic length
3316 with a DW_FORM_block1 attribute.
3317 FIXME: GDB does not yet know how to handle dynamic
3318 arrays properly, treat them as arrays with unspecified
3321 FIXME: jimb/2003-09-22: GDB does not really know
3322 how to handle arrays of unspecified length
3323 either; we just represent them as zero-length
3324 arrays. Choose an appropriate upper bound given
3325 the lower bound we've computed above. */
3330 dwarf2_non_const_array_bound_ignored_complaint
3331 (dwarf_form_name (attr
->form
));
3336 /* Create a range type and save it for array type creation. */
3337 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
3339 range_types
= (struct type
**)
3340 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
3341 * sizeof (struct type
*));
3343 make_cleanup (free_current_contents
, &range_types
);
3345 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
3347 child_die
= sibling_die (child_die
);
3350 /* Dwarf2 dimensions are output from left to right, create the
3351 necessary array types in backwards order. */
3352 type
= element_type
;
3354 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
3356 /* Understand Dwarf2 support for vector types (like they occur on
3357 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3358 array type. This is not part of the Dwarf2/3 standard yet, but a
3359 custom vendor extension. The main difference between a regular
3360 array and the vector variant is that vectors are passed by value
3362 attr
= dwarf_attr (die
, DW_AT_GNU_vector
);
3364 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
3366 do_cleanups (back_to
);
3368 /* Install the type in the die. */
3372 /* First cut: install each common block member as a global variable. */
3375 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
3377 struct die_info
*child_die
;
3378 struct attribute
*attr
;
3380 CORE_ADDR base
= (CORE_ADDR
) 0;
3382 attr
= dwarf_attr (die
, DW_AT_location
);
3385 /* Support the .debug_loc offsets */
3386 if (attr_form_is_block (attr
))
3388 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
3390 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3392 dwarf2_complex_location_expr_complaint ();
3396 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3397 "common block member");
3400 if (die
->child
!= NULL
)
3402 child_die
= die
->child
;
3403 while (child_die
&& child_die
->tag
)
3405 sym
= new_symbol (child_die
, NULL
, cu
);
3406 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
3409 SYMBOL_VALUE_ADDRESS (sym
) =
3410 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
3411 add_symbol_to_list (sym
, &global_symbols
);
3413 child_die
= sibling_die (child_die
);
3418 /* Read a C++ namespace. */
3421 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
3423 struct objfile
*objfile
= cu
->objfile
;
3424 const char *previous_prefix
= processing_current_prefix
;
3427 struct die_info
*current_die
;
3429 name
= namespace_name (die
, &is_anonymous
);
3431 /* Now build the name of the current namespace. */
3433 if (previous_prefix
[0] == '\0')
3435 processing_current_prefix
= name
;
3439 /* We need temp_name around because processing_current_prefix
3440 is a const char *. */
3441 char *temp_name
= alloca (strlen (previous_prefix
)
3442 + 2 + strlen(name
) + 1);
3443 strcpy (temp_name
, previous_prefix
);
3444 strcat (temp_name
, "::");
3445 strcat (temp_name
, name
);
3447 processing_current_prefix
= temp_name
;
3450 /* Add a symbol associated to this if we haven't seen the namespace
3451 before. Also, add a using directive if it's an anonymous
3454 if (dwarf2_extension (die
) == NULL
)
3458 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
3459 this cast will hopefully become unnecessary. */
3460 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
3461 (char *) processing_current_prefix
,
3463 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
3465 new_symbol (die
, type
, cu
);
3468 cp_add_using_directive (processing_current_prefix
,
3469 strlen (previous_prefix
),
3470 strlen (processing_current_prefix
));
3473 if (die
->child
!= NULL
)
3475 struct die_info
*child_die
= die
->child
;
3477 while (child_die
&& child_die
->tag
)
3479 process_die (child_die
, cu
);
3480 child_die
= sibling_die (child_die
);
3484 processing_current_prefix
= previous_prefix
;
3487 /* Return the name of the namespace represented by DIE. Set
3488 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
3492 namespace_name (struct die_info
*die
, int *is_anonymous
)
3494 struct die_info
*current_die
;
3495 const char *name
= NULL
;
3497 /* Loop through the extensions until we find a name. */
3499 for (current_die
= die
;
3500 current_die
!= NULL
;
3501 current_die
= dwarf2_extension (die
))
3503 name
= dwarf2_name (current_die
);
3508 /* Is it an anonymous namespace? */
3510 *is_anonymous
= (name
== NULL
);
3512 name
= "(anonymous namespace)";
3517 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3518 the user defined type vector. */
3521 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3523 struct comp_unit_head
*cu_header
= &cu
->header
;
3525 struct attribute
*attr_byte_size
;
3526 struct attribute
*attr_address_class
;
3527 int byte_size
, addr_class
;
3534 type
= lookup_pointer_type (die_type (die
, cu
));
3536 attr_byte_size
= dwarf_attr (die
, DW_AT_byte_size
);
3538 byte_size
= DW_UNSND (attr_byte_size
);
3540 byte_size
= cu_header
->addr_size
;
3542 attr_address_class
= dwarf_attr (die
, DW_AT_address_class
);
3543 if (attr_address_class
)
3544 addr_class
= DW_UNSND (attr_address_class
);
3546 addr_class
= DW_ADDR_none
;
3548 /* If the pointer size or address class is different than the
3549 default, create a type variant marked as such and set the
3550 length accordingly. */
3551 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
3553 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3557 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
3558 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
3559 type
= make_type_with_address_space (type
, type_flags
);
3561 else if (TYPE_LENGTH (type
) != byte_size
)
3563 complaint (&symfile_complaints
, "invalid pointer size %d", byte_size
);
3566 /* Should we also complain about unhandled address classes? */
3570 TYPE_LENGTH (type
) = byte_size
;
3574 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3575 the user defined type vector. */
3578 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3580 struct objfile
*objfile
= cu
->objfile
;
3582 struct type
*to_type
;
3583 struct type
*domain
;
3590 type
= alloc_type (objfile
);
3591 to_type
= die_type (die
, cu
);
3592 domain
= die_containing_type (die
, cu
);
3593 smash_to_member_type (type
, domain
, to_type
);
3598 /* Extract all information from a DW_TAG_reference_type DIE and add to
3599 the user defined type vector. */
3602 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3604 struct comp_unit_head
*cu_header
= &cu
->header
;
3606 struct attribute
*attr
;
3613 type
= lookup_reference_type (die_type (die
, cu
));
3614 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3617 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3621 TYPE_LENGTH (type
) = cu_header
->addr_size
;
3627 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3629 struct type
*base_type
;
3636 base_type
= die_type (die
, cu
);
3637 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
3641 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3643 struct type
*base_type
;
3650 base_type
= die_type (die
, cu
);
3651 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
3654 /* Extract all information from a DW_TAG_string_type DIE and add to
3655 the user defined type vector. It isn't really a user defined type,
3656 but it behaves like one, with other DIE's using an AT_user_def_type
3657 attribute to reference it. */
3660 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3662 struct objfile
*objfile
= cu
->objfile
;
3663 struct type
*type
, *range_type
, *index_type
, *char_type
;
3664 struct attribute
*attr
;
3665 unsigned int length
;
3672 attr
= dwarf_attr (die
, DW_AT_string_length
);
3675 length
= DW_UNSND (attr
);
3679 /* check for the DW_AT_byte_size attribute */
3680 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3683 length
= DW_UNSND (attr
);
3690 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
3691 range_type
= create_range_type (NULL
, index_type
, 1, length
);
3692 if (cu_language
== language_fortran
)
3694 /* Need to create a unique string type for bounds
3696 type
= create_string_type (0, range_type
);
3700 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
3701 type
= create_string_type (char_type
, range_type
);
3706 /* Handle DIES due to C code like:
3710 int (*funcp)(int a, long l);
3714 ('funcp' generates a DW_TAG_subroutine_type DIE)
3718 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3720 struct type
*type
; /* Type that this function returns */
3721 struct type
*ftype
; /* Function that returns above type */
3722 struct attribute
*attr
;
3724 /* Decode the type that this subroutine returns */
3729 type
= die_type (die
, cu
);
3730 ftype
= lookup_function_type (type
);
3732 /* All functions in C++ have prototypes. */
3733 attr
= dwarf_attr (die
, DW_AT_prototyped
);
3734 if ((attr
&& (DW_UNSND (attr
) != 0))
3735 || cu_language
== language_cplus
)
3736 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
3738 if (die
->child
!= NULL
)
3740 struct die_info
*child_die
;
3744 /* Count the number of parameters.
3745 FIXME: GDB currently ignores vararg functions, but knows about
3746 vararg member functions. */
3747 child_die
= die
->child
;
3748 while (child_die
&& child_die
->tag
)
3750 if (child_die
->tag
== DW_TAG_formal_parameter
)
3752 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
3753 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
3754 child_die
= sibling_die (child_die
);
3757 /* Allocate storage for parameters and fill them in. */
3758 TYPE_NFIELDS (ftype
) = nparams
;
3759 TYPE_FIELDS (ftype
) = (struct field
*)
3760 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
3762 child_die
= die
->child
;
3763 while (child_die
&& child_die
->tag
)
3765 if (child_die
->tag
== DW_TAG_formal_parameter
)
3767 /* Dwarf2 has no clean way to discern C++ static and non-static
3768 member functions. G++ helps GDB by marking the first
3769 parameter for non-static member functions (which is the
3770 this pointer) as artificial. We pass this information
3771 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
3772 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
3774 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
3776 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
3777 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
3780 child_die
= sibling_die (child_die
);
3788 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
3790 struct objfile
*objfile
= cu
->objfile
;
3791 struct attribute
*attr
;
3796 attr
= dwarf_attr (die
, DW_AT_name
);
3797 if (attr
&& DW_STRING (attr
))
3799 name
= DW_STRING (attr
);
3801 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
3802 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, cu
);
3806 /* Find a representation of a given base type and install
3807 it in the TYPE field of the die. */
3810 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3812 struct objfile
*objfile
= cu
->objfile
;
3814 struct attribute
*attr
;
3815 int encoding
= 0, size
= 0;
3817 /* If we've already decoded this die, this is a no-op. */
3823 attr
= dwarf_attr (die
, DW_AT_encoding
);
3826 encoding
= DW_UNSND (attr
);
3828 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3831 size
= DW_UNSND (attr
);
3833 attr
= dwarf_attr (die
, DW_AT_name
);
3834 if (attr
&& DW_STRING (attr
))
3836 enum type_code code
= TYPE_CODE_INT
;
3841 case DW_ATE_address
:
3842 /* Turn DW_ATE_address into a void * pointer. */
3843 code
= TYPE_CODE_PTR
;
3844 type_flags
|= TYPE_FLAG_UNSIGNED
;
3846 case DW_ATE_boolean
:
3847 code
= TYPE_CODE_BOOL
;
3848 type_flags
|= TYPE_FLAG_UNSIGNED
;
3850 case DW_ATE_complex_float
:
3851 code
= TYPE_CODE_COMPLEX
;
3854 code
= TYPE_CODE_FLT
;
3857 case DW_ATE_signed_char
:
3859 case DW_ATE_unsigned
:
3860 case DW_ATE_unsigned_char
:
3861 type_flags
|= TYPE_FLAG_UNSIGNED
;
3864 complaint (&symfile_complaints
, "unsupported DW_AT_encoding: '%s'",
3865 dwarf_type_encoding_name (encoding
));
3868 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
3869 if (encoding
== DW_ATE_address
)
3870 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
3871 else if (encoding
== DW_ATE_complex_float
)
3874 TYPE_TARGET_TYPE (type
)
3875 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
3876 else if (size
== 16)
3877 TYPE_TARGET_TYPE (type
)
3878 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
3880 TYPE_TARGET_TYPE (type
)
3881 = dwarf2_fundamental_type (objfile
, FT_FLOAT
);
3886 type
= dwarf_base_type (encoding
, size
, cu
);
3891 /* Read a whole compilation unit into a linked list of dies. */
3893 static struct die_info
*
3894 read_comp_unit (char *info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
3896 /* Reset die reference table; we are
3897 building new ones now. */
3898 dwarf2_empty_hash_tables ();
3900 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
3903 /* Read a single die and all its descendents. Set the die's sibling
3904 field to NULL; set other fields in the die correctly, and set all
3905 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
3906 location of the info_ptr after reading all of those dies. PARENT
3907 is the parent of the die in question. */
3909 static struct die_info
*
3910 read_die_and_children (char *info_ptr
, bfd
*abfd
,
3911 struct dwarf2_cu
*cu
,
3912 char **new_info_ptr
,
3913 struct die_info
*parent
)
3915 struct die_info
*die
;
3919 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
3920 store_in_ref_table (die
->offset
, die
);
3924 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
3930 *new_info_ptr
= cur_ptr
;
3933 die
->sibling
= NULL
;
3934 die
->parent
= parent
;
3938 /* Read a die, all of its descendents, and all of its siblings; set
3939 all of the fields of all of the dies correctly. Arguments are as
3940 in read_die_and_children. */
3942 static struct die_info
*
3943 read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
3944 struct dwarf2_cu
*cu
,
3945 char **new_info_ptr
,
3946 struct die_info
*parent
)
3948 struct die_info
*first_die
, *last_sibling
;
3952 first_die
= last_sibling
= NULL
;
3956 struct die_info
*die
3957 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
3965 last_sibling
->sibling
= die
;
3970 *new_info_ptr
= cur_ptr
;
3980 /* Free a linked list of dies. */
3983 free_die_list (struct die_info
*dies
)
3985 struct die_info
*die
, *next
;
3990 if (die
->child
!= NULL
)
3991 free_die_list (die
->child
);
3992 next
= die
->sibling
;
4000 do_free_die_list_cleanup (void *dies
)
4002 free_die_list (dies
);
4005 static struct cleanup
*
4006 make_cleanup_free_die_list (struct die_info
*dies
)
4008 return make_cleanup (do_free_die_list_cleanup
, dies
);
4012 /* Read the contents of the section at OFFSET and of size SIZE from the
4013 object file specified by OBJFILE into the psymbol_obstack and return it. */
4016 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
4018 bfd
*abfd
= objfile
->obfd
;
4020 bfd_size_type size
= bfd_get_section_size_before_reloc (sectp
);
4025 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
4027 = (char *) symfile_relocate_debug_section (abfd
, sectp
, (bfd_byte
*) buf
);
4031 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
4032 || bfd_bread (buf
, size
, abfd
) != size
)
4033 error ("Dwarf Error: Can't read DWARF data from '%s'",
4034 bfd_get_filename (abfd
));
4039 /* In DWARF version 2, the description of the debugging information is
4040 stored in a separate .debug_abbrev section. Before we read any
4041 dies from a section we read in all abbreviations and install them
4045 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
4047 struct comp_unit_head
*cu_header
= &cu
->header
;
4049 struct abbrev_info
*cur_abbrev
;
4050 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
4051 unsigned int abbrev_form
, hash_number
;
4053 /* Initialize dwarf2 abbrevs */
4054 memset (cu_header
->dwarf2_abbrevs
, 0,
4055 ABBREV_HASH_SIZE
*sizeof (struct abbrev_info
*));
4057 abbrev_ptr
= dwarf_abbrev_buffer
+ cu_header
->abbrev_offset
;
4058 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4059 abbrev_ptr
+= bytes_read
;
4061 /* loop until we reach an abbrev number of 0 */
4062 while (abbrev_number
)
4064 cur_abbrev
= dwarf_alloc_abbrev ();
4066 /* read in abbrev header */
4067 cur_abbrev
->number
= abbrev_number
;
4068 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4069 abbrev_ptr
+= bytes_read
;
4070 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
4073 /* now read in declarations */
4074 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4075 abbrev_ptr
+= bytes_read
;
4076 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4077 abbrev_ptr
+= bytes_read
;
4080 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
4082 cur_abbrev
->attrs
= (struct attr_abbrev
*)
4083 xrealloc (cur_abbrev
->attrs
,
4084 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
4085 * sizeof (struct attr_abbrev
));
4087 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
4088 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
4089 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4090 abbrev_ptr
+= bytes_read
;
4091 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4092 abbrev_ptr
+= bytes_read
;
4095 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
4096 cur_abbrev
->next
= cu_header
->dwarf2_abbrevs
[hash_number
];
4097 cu_header
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
4099 /* Get next abbreviation.
4100 Under Irix6 the abbreviations for a compilation unit are not
4101 always properly terminated with an abbrev number of 0.
4102 Exit loop if we encounter an abbreviation which we have
4103 already read (which means we are about to read the abbreviations
4104 for the next compile unit) or if the end of the abbreviation
4105 table is reached. */
4106 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
4107 >= dwarf_abbrev_size
)
4109 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4110 abbrev_ptr
+= bytes_read
;
4111 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
4116 /* Empty the abbrev table for a new compilation unit. */
4119 dwarf2_empty_abbrev_table (void *ptr_to_abbrevs_table
)
4122 struct abbrev_info
*abbrev
, *next
;
4123 struct abbrev_info
**abbrevs
;
4125 abbrevs
= (struct abbrev_info
**)ptr_to_abbrevs_table
;
4127 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
4130 abbrev
= abbrevs
[i
];
4133 next
= abbrev
->next
;
4134 xfree (abbrev
->attrs
);
4142 /* Lookup an abbrev_info structure in the abbrev hash table. */
4144 static struct abbrev_info
*
4145 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
4147 struct comp_unit_head
*cu_header
= &cu
->header
;
4148 unsigned int hash_number
;
4149 struct abbrev_info
*abbrev
;
4151 hash_number
= number
% ABBREV_HASH_SIZE
;
4152 abbrev
= cu_header
->dwarf2_abbrevs
[hash_number
];
4156 if (abbrev
->number
== number
)
4159 abbrev
= abbrev
->next
;
4164 /* Read a minimal amount of information into the minimal die structure. */
4167 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
4168 char *info_ptr
, struct dwarf2_cu
*cu
)
4170 unsigned int abbrev_number
, bytes_read
, i
;
4171 struct abbrev_info
*abbrev
;
4172 struct attribute attr
;
4173 struct attribute spec_attr
;
4174 int found_spec_attr
= 0;
4175 int has_low_pc_attr
= 0;
4176 int has_high_pc_attr
= 0;
4178 *part_die
= zeroed_partial_die
;
4179 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4180 info_ptr
+= bytes_read
;
4184 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4187 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number
,
4188 bfd_get_filename (abfd
));
4190 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
4191 part_die
->tag
= abbrev
->tag
;
4192 part_die
->has_children
= abbrev
->has_children
;
4193 part_die
->abbrev
= abbrev_number
;
4195 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4197 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
4199 /* Store the data if it is of an attribute we want to keep in a
4200 partial symbol table. */
4205 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
4206 if (part_die
->name
== NULL
)
4207 part_die
->name
= DW_STRING (&attr
);
4209 case DW_AT_MIPS_linkage_name
:
4210 part_die
->name
= DW_STRING (&attr
);
4213 has_low_pc_attr
= 1;
4214 part_die
->lowpc
= DW_ADDR (&attr
);
4217 has_high_pc_attr
= 1;
4218 part_die
->highpc
= DW_ADDR (&attr
);
4220 case DW_AT_location
:
4221 /* Support the .debug_loc offsets */
4222 if (attr_form_is_block (&attr
))
4224 part_die
->locdesc
= DW_BLOCK (&attr
);
4226 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
4228 dwarf2_complex_location_expr_complaint ();
4232 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4233 "partial symbol information");
4236 case DW_AT_language
:
4237 part_die
->language
= DW_UNSND (&attr
);
4239 case DW_AT_external
:
4240 part_die
->is_external
= DW_UNSND (&attr
);
4242 case DW_AT_declaration
:
4243 part_die
->is_declaration
= DW_UNSND (&attr
);
4246 part_die
->has_type
= 1;
4248 case DW_AT_abstract_origin
:
4249 case DW_AT_specification
:
4250 found_spec_attr
= 1;
4254 /* Ignore absolute siblings, they might point outside of
4255 the current compile unit. */
4256 if (attr
.form
== DW_FORM_ref_addr
)
4257 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
4260 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
4267 /* If we found a reference attribute and the die has no name, try
4268 to find a name in the referred to die. */
4270 if (found_spec_attr
&& part_die
->name
== NULL
)
4272 struct partial_die_info spec_die
;
4275 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
4276 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu
);
4279 part_die
->name
= spec_die
.name
;
4281 /* Copy DW_AT_external attribute if it is set. */
4282 if (spec_die
.is_external
)
4283 part_die
->is_external
= spec_die
.is_external
;
4287 /* When using the GNU linker, .gnu.linkonce. sections are used to
4288 eliminate duplicate copies of functions and vtables and such.
4289 The linker will arbitrarily choose one and discard the others.
4290 The AT_*_pc values for such functions refer to local labels in
4291 these sections. If the section from that file was discarded, the
4292 labels are not in the output, so the relocs get a value of 0.
4293 If this is a discarded function, mark the pc bounds as invalid,
4294 so that GDB will ignore it. */
4295 if (has_low_pc_attr
&& has_high_pc_attr
4296 && part_die
->lowpc
< part_die
->highpc
4297 && (part_die
->lowpc
!= 0
4298 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
4299 part_die
->has_pc_info
= 1;
4303 /* Read the die from the .debug_info section buffer. Set DIEP to
4304 point to a newly allocated die with its information, except for its
4305 child, sibling, and parent fields. Set HAS_CHILDREN to tell
4306 whether the die has children or not. */
4309 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
4310 struct dwarf2_cu
*cu
, int *has_children
)
4312 unsigned int abbrev_number
, bytes_read
, i
, offset
;
4313 struct abbrev_info
*abbrev
;
4314 struct die_info
*die
;
4316 offset
= info_ptr
- dwarf_info_buffer
;
4317 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4318 info_ptr
+= bytes_read
;
4321 die
= dwarf_alloc_die ();
4323 die
->abbrev
= abbrev_number
;
4330 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4333 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
4335 bfd_get_filename (abfd
));
4337 die
= dwarf_alloc_die ();
4338 die
->offset
= offset
;
4339 die
->tag
= abbrev
->tag
;
4340 die
->abbrev
= abbrev_number
;
4343 die
->num_attrs
= abbrev
->num_attrs
;
4344 die
->attrs
= (struct attribute
*)
4345 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
4347 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4349 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
4350 abfd
, info_ptr
, cu
);
4354 *has_children
= abbrev
->has_children
;
4358 /* Read an attribute value described by an attribute form. */
4361 read_attribute_value (struct attribute
*attr
, unsigned form
,
4362 bfd
*abfd
, char *info_ptr
,
4363 struct dwarf2_cu
*cu
)
4365 struct comp_unit_head
*cu_header
= &cu
->header
;
4366 unsigned int bytes_read
;
4367 struct dwarf_block
*blk
;
4373 case DW_FORM_ref_addr
:
4374 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
4375 info_ptr
+= bytes_read
;
4377 case DW_FORM_block2
:
4378 blk
= dwarf_alloc_block ();
4379 blk
->size
= read_2_bytes (abfd
, info_ptr
);
4381 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4382 info_ptr
+= blk
->size
;
4383 DW_BLOCK (attr
) = blk
;
4385 case DW_FORM_block4
:
4386 blk
= dwarf_alloc_block ();
4387 blk
->size
= read_4_bytes (abfd
, info_ptr
);
4389 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4390 info_ptr
+= blk
->size
;
4391 DW_BLOCK (attr
) = blk
;
4394 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4398 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4402 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4405 case DW_FORM_string
:
4406 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
4407 info_ptr
+= bytes_read
;
4410 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
4412 info_ptr
+= bytes_read
;
4415 blk
= dwarf_alloc_block ();
4416 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4417 info_ptr
+= bytes_read
;
4418 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4419 info_ptr
+= blk
->size
;
4420 DW_BLOCK (attr
) = blk
;
4422 case DW_FORM_block1
:
4423 blk
= dwarf_alloc_block ();
4424 blk
->size
= read_1_byte (abfd
, info_ptr
);
4426 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4427 info_ptr
+= blk
->size
;
4428 DW_BLOCK (attr
) = blk
;
4431 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4435 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4439 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
4440 info_ptr
+= bytes_read
;
4443 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4444 info_ptr
+= bytes_read
;
4447 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4451 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4455 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4459 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4462 case DW_FORM_ref_udata
:
4463 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4464 info_ptr
+= bytes_read
;
4466 case DW_FORM_indirect
:
4467 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4468 info_ptr
+= bytes_read
;
4469 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
4472 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
4473 dwarf_form_name (form
),
4474 bfd_get_filename (abfd
));
4479 /* Read an attribute described by an abbreviated attribute. */
4482 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
4483 bfd
*abfd
, char *info_ptr
, struct dwarf2_cu
*cu
)
4485 attr
->name
= abbrev
->name
;
4486 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
4489 /* read dwarf information from a buffer */
4492 read_1_byte (bfd
*abfd
, char *buf
)
4494 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4498 read_1_signed_byte (bfd
*abfd
, char *buf
)
4500 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
4504 read_2_bytes (bfd
*abfd
, char *buf
)
4506 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4510 read_2_signed_bytes (bfd
*abfd
, char *buf
)
4512 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4516 read_4_bytes (bfd
*abfd
, char *buf
)
4518 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4522 read_4_signed_bytes (bfd
*abfd
, char *buf
)
4524 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4527 static unsigned long
4528 read_8_bytes (bfd
*abfd
, char *buf
)
4530 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4534 read_address (bfd
*abfd
, char *buf
, struct dwarf2_cu
*cu
, int *bytes_read
)
4536 struct comp_unit_head
*cu_header
= &cu
->header
;
4537 CORE_ADDR retval
= 0;
4539 if (cu_header
->signed_addr_p
)
4541 switch (cu_header
->addr_size
)
4544 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4547 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4550 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
4553 internal_error (__FILE__
, __LINE__
,
4554 "read_address: bad switch, signed [in module %s]",
4555 bfd_get_filename (abfd
));
4560 switch (cu_header
->addr_size
)
4563 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4566 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4569 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4572 internal_error (__FILE__
, __LINE__
,
4573 "read_address: bad switch, unsigned [in module %s]",
4574 bfd_get_filename (abfd
));
4578 *bytes_read
= cu_header
->addr_size
;
4582 /* Read the initial length from a section. The (draft) DWARF 3
4583 specification allows the initial length to take up either 4 bytes
4584 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
4585 bytes describe the length and all offsets will be 8 bytes in length
4588 An older, non-standard 64-bit format is also handled by this
4589 function. The older format in question stores the initial length
4590 as an 8-byte quantity without an escape value. Lengths greater
4591 than 2^32 aren't very common which means that the initial 4 bytes
4592 is almost always zero. Since a length value of zero doesn't make
4593 sense for the 32-bit format, this initial zero can be considered to
4594 be an escape value which indicates the presence of the older 64-bit
4595 format. As written, the code can't detect (old format) lengths
4596 greater than 4GB. If it becomes necessary to handle lengths somewhat
4597 larger than 4GB, we could allow other small values (such as the
4598 non-sensical values of 1, 2, and 3) to also be used as escape values
4599 indicating the presence of the old format.
4601 The value returned via bytes_read should be used to increment
4602 the relevant pointer after calling read_initial_length().
4604 As a side effect, this function sets the fields initial_length_size
4605 and offset_size in cu_header to the values appropriate for the
4606 length field. (The format of the initial length field determines
4607 the width of file offsets to be fetched later with fetch_offset().)
4609 [ Note: read_initial_length() and read_offset() are based on the
4610 document entitled "DWARF Debugging Information Format", revision
4611 3, draft 8, dated November 19, 2001. This document was obtained
4614 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
4616 This document is only a draft and is subject to change. (So beware.)
4618 Details regarding the older, non-standard 64-bit format were
4619 determined empirically by examining 64-bit ELF files produced
4620 by the SGI toolchain on an IRIX 6.5 machine.
4622 - Kevin, July 16, 2002
4626 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
4631 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4633 if (retval
== 0xffffffff)
4635 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
4637 if (cu_header
!= NULL
)
4639 cu_header
->initial_length_size
= 12;
4640 cu_header
->offset_size
= 8;
4643 else if (retval
== 0)
4645 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
4647 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4649 if (cu_header
!= NULL
)
4651 cu_header
->initial_length_size
= 8;
4652 cu_header
->offset_size
= 8;
4658 if (cu_header
!= NULL
)
4660 cu_header
->initial_length_size
= 4;
4661 cu_header
->offset_size
= 4;
4668 /* Read an offset from the data stream. The size of the offset is
4669 given by cu_header->offset_size. */
4672 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
4677 switch (cu_header
->offset_size
)
4680 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4684 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4688 internal_error (__FILE__
, __LINE__
,
4689 "read_offset: bad switch [in module %s]",
4690 bfd_get_filename (abfd
));
4697 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
4699 /* If the size of a host char is 8 bits, we can return a pointer
4700 to the buffer, otherwise we have to copy the data to a buffer
4701 allocated on the temporary obstack. */
4702 gdb_assert (HOST_CHAR_BIT
== 8);
4707 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4709 /* If the size of a host char is 8 bits, we can return a pointer
4710 to the string, otherwise we have to copy the string to a buffer
4711 allocated on the temporary obstack. */
4712 gdb_assert (HOST_CHAR_BIT
== 8);
4715 *bytes_read_ptr
= 1;
4718 *bytes_read_ptr
= strlen (buf
) + 1;
4723 read_indirect_string (bfd
*abfd
, char *buf
,
4724 const struct comp_unit_head
*cu_header
,
4725 unsigned int *bytes_read_ptr
)
4727 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
4728 (int *) bytes_read_ptr
);
4730 if (dwarf_str_buffer
== NULL
)
4732 error ("DW_FORM_strp used without .debug_str section [in module %s]",
4733 bfd_get_filename (abfd
));
4736 if (str_offset
>= dwarf_str_size
)
4738 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
4739 bfd_get_filename (abfd
));
4742 gdb_assert (HOST_CHAR_BIT
== 8);
4743 if (dwarf_str_buffer
[str_offset
] == '\0')
4745 return dwarf_str_buffer
+ str_offset
;
4748 static unsigned long
4749 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4751 unsigned long result
;
4752 unsigned int num_read
;
4762 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4765 result
|= ((unsigned long)(byte
& 127) << shift
);
4766 if ((byte
& 128) == 0)
4772 *bytes_read_ptr
= num_read
;
4777 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4780 int i
, shift
, size
, num_read
;
4790 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4793 result
|= ((long)(byte
& 127) << shift
);
4795 if ((byte
& 128) == 0)
4800 if ((shift
< size
) && (byte
& 0x40))
4802 result
|= -(1 << shift
);
4804 *bytes_read_ptr
= num_read
;
4809 set_cu_language (unsigned int lang
)
4815 cu_language
= language_c
;
4817 case DW_LANG_C_plus_plus
:
4818 cu_language
= language_cplus
;
4820 case DW_LANG_Fortran77
:
4821 case DW_LANG_Fortran90
:
4822 case DW_LANG_Fortran95
:
4823 cu_language
= language_fortran
;
4825 case DW_LANG_Mips_Assembler
:
4826 cu_language
= language_asm
;
4829 cu_language
= language_java
;
4833 case DW_LANG_Cobol74
:
4834 case DW_LANG_Cobol85
:
4835 case DW_LANG_Pascal83
:
4836 case DW_LANG_Modula2
:
4838 cu_language
= language_minimal
;
4841 cu_language_defn
= language_def (cu_language
);
4844 /* Return the named attribute or NULL if not there. */
4846 static struct attribute
*
4847 dwarf_attr (struct die_info
*die
, unsigned int name
)
4850 struct attribute
*spec
= NULL
;
4852 for (i
= 0; i
< die
->num_attrs
; ++i
)
4854 if (die
->attrs
[i
].name
== name
)
4856 return &die
->attrs
[i
];
4858 if (die
->attrs
[i
].name
== DW_AT_specification
4859 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
4860 spec
= &die
->attrs
[i
];
4864 struct die_info
*ref_die
=
4865 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
4868 return dwarf_attr (ref_die
, name
);
4875 die_is_declaration (struct die_info
*die
)
4877 return (dwarf_attr (die
, DW_AT_declaration
)
4878 && ! dwarf_attr (die
, DW_AT_specification
));
4881 /* Return the die giving the specification for DIE, if there is
4884 static struct die_info
*
4885 die_specification (struct die_info
*die
)
4887 struct attribute
*spec_attr
= dwarf_attr (die
, DW_AT_specification
);
4889 if (spec_attr
== NULL
)
4892 return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr
));
4895 /* Free the line_header structure *LH, and any arrays and strings it
4898 free_line_header (struct line_header
*lh
)
4900 if (lh
->standard_opcode_lengths
)
4901 xfree (lh
->standard_opcode_lengths
);
4903 /* Remember that all the lh->file_names[i].name pointers are
4904 pointers into debug_line_buffer, and don't need to be freed. */
4906 xfree (lh
->file_names
);
4908 /* Similarly for the include directory names. */
4909 if (lh
->include_dirs
)
4910 xfree (lh
->include_dirs
);
4916 /* Add an entry to LH's include directory table. */
4918 add_include_dir (struct line_header
*lh
, char *include_dir
)
4920 /* Grow the array if necessary. */
4921 if (lh
->include_dirs_size
== 0)
4923 lh
->include_dirs_size
= 1; /* for testing */
4924 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
4925 * sizeof (*lh
->include_dirs
));
4927 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
4929 lh
->include_dirs_size
*= 2;
4930 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
4931 (lh
->include_dirs_size
4932 * sizeof (*lh
->include_dirs
)));
4935 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
4939 /* Add an entry to LH's file name table. */
4941 add_file_name (struct line_header
*lh
,
4943 unsigned int dir_index
,
4944 unsigned int mod_time
,
4945 unsigned int length
)
4947 struct file_entry
*fe
;
4949 /* Grow the array if necessary. */
4950 if (lh
->file_names_size
== 0)
4952 lh
->file_names_size
= 1; /* for testing */
4953 lh
->file_names
= xmalloc (lh
->file_names_size
4954 * sizeof (*lh
->file_names
));
4956 else if (lh
->num_file_names
>= lh
->file_names_size
)
4958 lh
->file_names_size
*= 2;
4959 lh
->file_names
= xrealloc (lh
->file_names
,
4960 (lh
->file_names_size
4961 * sizeof (*lh
->file_names
)));
4964 fe
= &lh
->file_names
[lh
->num_file_names
++];
4966 fe
->dir_index
= dir_index
;
4967 fe
->mod_time
= mod_time
;
4968 fe
->length
= length
;
4972 /* Read the statement program header starting at OFFSET in
4973 dwarf_line_buffer, according to the endianness of ABFD. Return a
4974 pointer to a struct line_header, allocated using xmalloc.
4976 NOTE: the strings in the include directory and file name tables of
4977 the returned object point into debug_line_buffer, and must not be
4979 static struct line_header
*
4980 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
4981 struct dwarf2_cu
*cu
)
4983 struct cleanup
*back_to
;
4984 struct line_header
*lh
;
4988 char *cur_dir
, *cur_file
;
4990 if (dwarf_line_buffer
== NULL
)
4992 complaint (&symfile_complaints
, "missing .debug_line section");
4996 /* Make sure that at least there's room for the total_length field. That
4997 could be 12 bytes long, but we're just going to fudge that. */
4998 if (offset
+ 4 >= dwarf_line_size
)
5000 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5004 lh
= xmalloc (sizeof (*lh
));
5005 memset (lh
, 0, sizeof (*lh
));
5006 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
5009 line_ptr
= dwarf_line_buffer
+ offset
;
5011 /* read in the header */
5012 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
5013 line_ptr
+= bytes_read
;
5014 if (line_ptr
+ lh
->total_length
> dwarf_line_buffer
+ dwarf_line_size
)
5016 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5019 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
5020 lh
->version
= read_2_bytes (abfd
, line_ptr
);
5022 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
5023 line_ptr
+= bytes_read
;
5024 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
5026 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
5028 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
5030 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
5032 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
5034 lh
->standard_opcode_lengths
5035 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
5037 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
5038 for (i
= 1; i
< lh
->opcode_base
; ++i
)
5040 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
5044 /* Read directory table */
5045 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
5047 line_ptr
+= bytes_read
;
5048 add_include_dir (lh
, cur_dir
);
5050 line_ptr
+= bytes_read
;
5052 /* Read file name table */
5053 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
5055 unsigned int dir_index
, mod_time
, length
;
5057 line_ptr
+= bytes_read
;
5058 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5059 line_ptr
+= bytes_read
;
5060 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5061 line_ptr
+= bytes_read
;
5062 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5063 line_ptr
+= bytes_read
;
5065 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
5067 line_ptr
+= bytes_read
;
5068 lh
->statement_program_start
= line_ptr
;
5070 if (line_ptr
> dwarf_line_buffer
+ dwarf_line_size
)
5071 complaint (&symfile_complaints
,
5072 "line number info header doesn't fit in `.debug_line' section");
5074 discard_cleanups (back_to
);
5078 /* This function exists to work around a bug in certain compilers
5079 (particularly GCC 2.95), in which the first line number marker of a
5080 function does not show up until after the prologue, right before
5081 the second line number marker. This function shifts ADDRESS down
5082 to the beginning of the function if necessary, and is called on
5083 addresses passed to record_line. */
5086 check_cu_functions (CORE_ADDR address
)
5088 struct function_range
*fn
;
5090 /* Find the function_range containing address. */
5095 cu_cached_fn
= cu_first_fn
;
5099 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
5105 while (fn
&& fn
!= cu_cached_fn
)
5106 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
5116 if (address
!= fn
->lowpc
)
5117 complaint (&symfile_complaints
,
5118 "misplaced first line number at 0x%lx for '%s'",
5119 (unsigned long) address
, fn
->name
);
5124 /* Decode the line number information for the compilation unit whose
5125 line number info is at OFFSET in the .debug_line section.
5126 The compilation directory of the file is passed in COMP_DIR. */
5129 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
5130 struct dwarf2_cu
*cu
)
5134 unsigned int bytes_read
;
5135 unsigned char op_code
, extended_op
, adj_opcode
;
5137 line_ptr
= lh
->statement_program_start
;
5138 line_end
= lh
->statement_program_end
;
5140 /* Read the statement sequences until there's nothing left. */
5141 while (line_ptr
< line_end
)
5143 /* state machine registers */
5144 CORE_ADDR address
= 0;
5145 unsigned int file
= 1;
5146 unsigned int line
= 1;
5147 unsigned int column
= 0;
5148 int is_stmt
= lh
->default_is_stmt
;
5149 int basic_block
= 0;
5150 int end_sequence
= 0;
5152 /* Start a subfile for the current file of the state machine. */
5153 if (lh
->num_file_names
>= file
)
5155 /* lh->include_dirs and lh->file_names are 0-based, but the
5156 directory and file name numbers in the statement program
5158 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
5161 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
5164 dwarf2_start_subfile (fe
->name
, dir
);
5167 /* Decode the table. */
5168 while (!end_sequence
)
5170 op_code
= read_1_byte (abfd
, line_ptr
);
5173 if (op_code
>= lh
->opcode_base
)
5174 { /* Special operand. */
5175 adj_opcode
= op_code
- lh
->opcode_base
;
5176 address
+= (adj_opcode
/ lh
->line_range
)
5177 * lh
->minimum_instruction_length
;
5178 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
5179 /* append row to matrix using current values */
5180 record_line (current_subfile
, line
,
5181 check_cu_functions (address
));
5184 else switch (op_code
)
5186 case DW_LNS_extended_op
:
5187 line_ptr
+= 1; /* ignore length */
5188 extended_op
= read_1_byte (abfd
, line_ptr
);
5190 switch (extended_op
)
5192 case DW_LNE_end_sequence
:
5194 record_line (current_subfile
, 0, address
);
5196 case DW_LNE_set_address
:
5197 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
5198 line_ptr
+= bytes_read
;
5199 address
+= baseaddr
;
5201 case DW_LNE_define_file
:
5204 unsigned int dir_index
, mod_time
, length
;
5206 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
5207 line_ptr
+= bytes_read
;
5209 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5210 line_ptr
+= bytes_read
;
5212 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5213 line_ptr
+= bytes_read
;
5215 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5216 line_ptr
+= bytes_read
;
5217 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
5221 complaint (&symfile_complaints
,
5222 "mangled .debug_line section");
5227 record_line (current_subfile
, line
,
5228 check_cu_functions (address
));
5231 case DW_LNS_advance_pc
:
5232 address
+= lh
->minimum_instruction_length
5233 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5234 line_ptr
+= bytes_read
;
5236 case DW_LNS_advance_line
:
5237 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
5238 line_ptr
+= bytes_read
;
5240 case DW_LNS_set_file
:
5242 /* lh->include_dirs and lh->file_names are 0-based,
5243 but the directory and file name numbers in the
5244 statement program are 1-based. */
5245 struct file_entry
*fe
;
5247 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5248 line_ptr
+= bytes_read
;
5249 fe
= &lh
->file_names
[file
- 1];
5251 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
5254 dwarf2_start_subfile (fe
->name
, dir
);
5257 case DW_LNS_set_column
:
5258 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5259 line_ptr
+= bytes_read
;
5261 case DW_LNS_negate_stmt
:
5262 is_stmt
= (!is_stmt
);
5264 case DW_LNS_set_basic_block
:
5267 /* Add to the address register of the state machine the
5268 address increment value corresponding to special opcode
5269 255. Ie, this value is scaled by the minimum instruction
5270 length since special opcode 255 would have scaled the
5272 case DW_LNS_const_add_pc
:
5273 address
+= (lh
->minimum_instruction_length
5274 * ((255 - lh
->opcode_base
) / lh
->line_range
));
5276 case DW_LNS_fixed_advance_pc
:
5277 address
+= read_2_bytes (abfd
, line_ptr
);
5281 { /* Unknown standard opcode, ignore it. */
5283 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
5285 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5286 line_ptr
+= bytes_read
;
5294 /* Start a subfile for DWARF. FILENAME is the name of the file and
5295 DIRNAME the name of the source directory which contains FILENAME
5296 or NULL if not known.
5297 This routine tries to keep line numbers from identical absolute and
5298 relative file names in a common subfile.
5300 Using the `list' example from the GDB testsuite, which resides in
5301 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
5302 of /srcdir/list0.c yields the following debugging information for list0.c:
5304 DW_AT_name: /srcdir/list0.c
5305 DW_AT_comp_dir: /compdir
5306 files.files[0].name: list0.h
5307 files.files[0].dir: /srcdir
5308 files.files[1].name: list0.c
5309 files.files[1].dir: /srcdir
5311 The line number information for list0.c has to end up in a single
5312 subfile, so that `break /srcdir/list0.c:1' works as expected. */
5315 dwarf2_start_subfile (char *filename
, char *dirname
)
5317 /* If the filename isn't absolute, try to match an existing subfile
5318 with the full pathname. */
5320 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
5322 struct subfile
*subfile
;
5323 char *fullname
= concat (dirname
, "/", filename
, NULL
);
5325 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
5327 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
5329 current_subfile
= subfile
;
5336 start_subfile (filename
, dirname
);
5340 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
5341 struct dwarf2_cu
*cu
)
5343 struct objfile
*objfile
= cu
->objfile
;
5344 struct comp_unit_head
*cu_header
= &cu
->header
;
5346 /* NOTE drow/2003-01-30: There used to be a comment and some special
5347 code here to turn a symbol with DW_AT_external and a
5348 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
5349 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
5350 with some versions of binutils) where shared libraries could have
5351 relocations against symbols in their debug information - the
5352 minimal symbol would have the right address, but the debug info
5353 would not. It's no longer necessary, because we will explicitly
5354 apply relocations when we read in the debug information now. */
5356 /* A DW_AT_location attribute with no contents indicates that a
5357 variable has been optimized away. */
5358 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
5360 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
5364 /* Handle one degenerate form of location expression specially, to
5365 preserve GDB's previous behavior when section offsets are
5366 specified. If this is just a DW_OP_addr then mark this symbol
5369 if (attr_form_is_block (attr
)
5370 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
5371 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
5375 SYMBOL_VALUE_ADDRESS (sym
) =
5376 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
5377 fixup_symbol_section (sym
, objfile
);
5378 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
5379 SYMBOL_SECTION (sym
));
5380 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5384 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
5385 expression evaluator, and use LOC_COMPUTED only when necessary
5386 (i.e. when the value of a register or memory location is
5387 referenced, or a thread-local block, etc.). Then again, it might
5388 not be worthwhile. I'm assuming that it isn't unless performance
5389 or memory numbers show me otherwise. */
5391 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
5392 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
5395 /* Given a pointer to a DWARF information entry, figure out if we need
5396 to make a symbol table entry for it, and if so, create a new entry
5397 and return a pointer to it.
5398 If TYPE is NULL, determine symbol type from the die, otherwise
5399 used the passed type. */
5401 static struct symbol
*
5402 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
5404 struct objfile
*objfile
= cu
->objfile
;
5405 struct symbol
*sym
= NULL
;
5407 struct attribute
*attr
= NULL
;
5408 struct attribute
*attr2
= NULL
;
5410 if (die
->tag
!= DW_TAG_namespace
)
5411 name
= dwarf2_linkage_name (die
);
5413 name
= TYPE_NAME (type
);
5417 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
5418 sizeof (struct symbol
));
5419 OBJSTAT (objfile
, n_syms
++);
5420 memset (sym
, 0, sizeof (struct symbol
));
5422 /* Cache this symbol's name and the name's demangled form (if any). */
5423 SYMBOL_LANGUAGE (sym
) = cu_language
;
5424 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
5426 /* Default assumptions.
5427 Use the passed type or decode it from the die. */
5428 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5429 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5431 SYMBOL_TYPE (sym
) = type
;
5433 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
5434 attr
= dwarf_attr (die
, DW_AT_decl_line
);
5437 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
5442 attr
= dwarf_attr (die
, DW_AT_low_pc
);
5445 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
5447 SYMBOL_CLASS (sym
) = LOC_LABEL
;
5449 case DW_TAG_subprogram
:
5450 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
5452 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
5453 attr2
= dwarf_attr (die
, DW_AT_external
);
5454 if (attr2
&& (DW_UNSND (attr2
) != 0))
5456 add_symbol_to_list (sym
, &global_symbols
);
5460 add_symbol_to_list (sym
, list_in_scope
);
5463 case DW_TAG_variable
:
5464 /* Compilation with minimal debug info may result in variables
5465 with missing type entries. Change the misleading `void' type
5466 to something sensible. */
5467 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
5468 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
5469 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
5470 "<variable, no debug info>",
5472 attr
= dwarf_attr (die
, DW_AT_const_value
);
5475 dwarf2_const_value (attr
, sym
, cu
);
5476 attr2
= dwarf_attr (die
, DW_AT_external
);
5477 if (attr2
&& (DW_UNSND (attr2
) != 0))
5478 add_symbol_to_list (sym
, &global_symbols
);
5480 add_symbol_to_list (sym
, list_in_scope
);
5483 attr
= dwarf_attr (die
, DW_AT_location
);
5486 var_decode_location (attr
, sym
, cu
);
5487 attr2
= dwarf_attr (die
, DW_AT_external
);
5488 if (attr2
&& (DW_UNSND (attr2
) != 0))
5489 add_symbol_to_list (sym
, &global_symbols
);
5491 add_symbol_to_list (sym
, list_in_scope
);
5495 /* We do not know the address of this symbol.
5496 If it is an external symbol and we have type information
5497 for it, enter the symbol as a LOC_UNRESOLVED symbol.
5498 The address of the variable will then be determined from
5499 the minimal symbol table whenever the variable is
5501 attr2
= dwarf_attr (die
, DW_AT_external
);
5502 if (attr2
&& (DW_UNSND (attr2
) != 0)
5503 && dwarf_attr (die
, DW_AT_type
) != NULL
)
5505 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
5506 add_symbol_to_list (sym
, &global_symbols
);
5510 case DW_TAG_formal_parameter
:
5511 attr
= dwarf_attr (die
, DW_AT_location
);
5514 var_decode_location (attr
, sym
, cu
);
5515 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
5516 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
5517 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
5519 attr
= dwarf_attr (die
, DW_AT_const_value
);
5522 dwarf2_const_value (attr
, sym
, cu
);
5524 add_symbol_to_list (sym
, list_in_scope
);
5526 case DW_TAG_unspecified_parameters
:
5527 /* From varargs functions; gdb doesn't seem to have any
5528 interest in this information, so just ignore it for now.
5531 case DW_TAG_class_type
:
5532 case DW_TAG_structure_type
:
5533 case DW_TAG_union_type
:
5534 case DW_TAG_enumeration_type
:
5535 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5536 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
5538 /* Make sure that the symbol includes appropriate enclosing
5539 classes/namespaces in its name. These are calculated in
5540 read_structure_scope, and the correct name is saved in
5543 if (cu_language
== language_cplus
)
5545 struct type
*type
= SYMBOL_TYPE (sym
);
5547 if (TYPE_TAG_NAME (type
) != NULL
)
5549 /* FIXME: carlton/2003-11-10: Should this use
5550 SYMBOL_SET_NAMES instead? (The same problem also
5551 arises a further down in the function.) */
5552 SYMBOL_LINKAGE_NAME (sym
)
5553 = obsavestring (TYPE_TAG_NAME (type
),
5554 strlen (TYPE_TAG_NAME (type
)),
5555 &objfile
->symbol_obstack
);
5560 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
5561 really ever be static objects: otherwise, if you try
5562 to, say, break of a class's method and you're in a file
5563 which doesn't mention that class, it won't work unless
5564 the check for all static symbols in lookup_symbol_aux
5565 saves you. See the OtherFileClass tests in
5566 gdb.c++/namespace.exp. */
5568 struct pending
**list_to_add
;
5570 list_to_add
= (list_in_scope
== &file_symbols
5571 && cu_language
== language_cplus
5572 ? &global_symbols
: list_in_scope
);
5574 add_symbol_to_list (sym
, list_to_add
);
5576 /* The semantics of C++ state that "struct foo { ... }" also
5577 defines a typedef for "foo". Synthesize a typedef symbol so
5578 that "ptype foo" works as expected. */
5579 if (cu_language
== language_cplus
)
5581 struct symbol
*typedef_sym
= (struct symbol
*)
5582 obstack_alloc (&objfile
->symbol_obstack
,
5583 sizeof (struct symbol
));
5584 *typedef_sym
= *sym
;
5585 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
5586 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
5587 TYPE_NAME (SYMBOL_TYPE (sym
)) =
5588 obsavestring (SYMBOL_NATURAL_NAME (sym
),
5589 strlen (SYMBOL_NATURAL_NAME (sym
)),
5590 &objfile
->type_obstack
);
5591 add_symbol_to_list (typedef_sym
, list_to_add
);
5595 case DW_TAG_typedef
:
5596 if (processing_has_namespace_info
5597 && processing_current_prefix
[0] != '\0')
5599 SYMBOL_LINKAGE_NAME (sym
) = obconcat (&objfile
->symbol_obstack
,
5600 processing_current_prefix
,
5604 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5605 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5606 add_symbol_to_list (sym
, list_in_scope
);
5608 case DW_TAG_base_type
:
5609 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5610 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5611 add_symbol_to_list (sym
, list_in_scope
);
5613 case DW_TAG_enumerator
:
5614 if (processing_has_namespace_info
5615 && processing_current_prefix
[0] != '\0')
5617 SYMBOL_LINKAGE_NAME (sym
) = obconcat (&objfile
->symbol_obstack
,
5618 processing_current_prefix
,
5622 attr
= dwarf_attr (die
, DW_AT_const_value
);
5625 dwarf2_const_value (attr
, sym
, cu
);
5628 /* NOTE: carlton/2003-11-10: See comment above in the
5629 DW_TAG_class_type, etc. block. */
5631 struct pending
**list_to_add
;
5633 list_to_add
= (list_in_scope
== &file_symbols
5634 && cu_language
== language_cplus
5635 ? &global_symbols
: list_in_scope
);
5637 add_symbol_to_list (sym
, list_to_add
);
5640 case DW_TAG_namespace
:
5641 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5642 add_symbol_to_list (sym
, &global_symbols
);
5645 /* Not a tag we recognize. Hopefully we aren't processing
5646 trash data, but since we must specifically ignore things
5647 we don't recognize, there is nothing else we should do at
5649 complaint (&symfile_complaints
, "unsupported tag: '%s'",
5650 dwarf_tag_name (die
->tag
));
5657 /* Copy constant value from an attribute to a symbol. */
5660 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
5661 struct dwarf2_cu
*cu
)
5663 struct objfile
*objfile
= cu
->objfile
;
5664 struct comp_unit_head
*cu_header
= &cu
->header
;
5665 struct dwarf_block
*blk
;
5670 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
5671 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5672 cu_header
->addr_size
,
5673 TYPE_LENGTH (SYMBOL_TYPE
5675 SYMBOL_VALUE_BYTES (sym
) = (char *)
5676 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
5677 /* NOTE: cagney/2003-05-09: In-lined store_address call with
5678 it's body - store_unsigned_integer. */
5679 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
5681 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5683 case DW_FORM_block1
:
5684 case DW_FORM_block2
:
5685 case DW_FORM_block4
:
5687 blk
= DW_BLOCK (attr
);
5688 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
5689 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5691 TYPE_LENGTH (SYMBOL_TYPE
5693 SYMBOL_VALUE_BYTES (sym
) = (char *)
5694 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
5695 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
5696 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5699 /* The DW_AT_const_value attributes are supposed to carry the
5700 symbol's value "represented as it would be on the target
5701 architecture." By the time we get here, it's already been
5702 converted to host endianness, so we just need to sign- or
5703 zero-extend it as appropriate. */
5705 dwarf2_const_value_data (attr
, sym
, 8);
5708 dwarf2_const_value_data (attr
, sym
, 16);
5711 dwarf2_const_value_data (attr
, sym
, 32);
5714 dwarf2_const_value_data (attr
, sym
, 64);
5718 SYMBOL_VALUE (sym
) = DW_SND (attr
);
5719 SYMBOL_CLASS (sym
) = LOC_CONST
;
5723 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
5724 SYMBOL_CLASS (sym
) = LOC_CONST
;
5728 complaint (&symfile_complaints
,
5729 "unsupported const value attribute form: '%s'",
5730 dwarf_form_name (attr
->form
));
5731 SYMBOL_VALUE (sym
) = 0;
5732 SYMBOL_CLASS (sym
) = LOC_CONST
;
5738 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
5739 or zero-extend it as appropriate for the symbol's type. */
5741 dwarf2_const_value_data (struct attribute
*attr
,
5745 LONGEST l
= DW_UNSND (attr
);
5747 if (bits
< sizeof (l
) * 8)
5749 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
5750 l
&= ((LONGEST
) 1 << bits
) - 1;
5752 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
5755 SYMBOL_VALUE (sym
) = l
;
5756 SYMBOL_CLASS (sym
) = LOC_CONST
;
5760 /* Return the type of the die in question using its DW_AT_type attribute. */
5762 static struct type
*
5763 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5766 struct attribute
*type_attr
;
5767 struct die_info
*type_die
;
5770 type_attr
= dwarf_attr (die
, DW_AT_type
);
5773 /* A missing DW_AT_type represents a void type. */
5774 return dwarf2_fundamental_type (cu
->objfile
, FT_VOID
);
5778 ref
= dwarf2_get_ref_die_offset (type_attr
);
5779 type_die
= follow_die_ref (ref
);
5782 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
5783 ref
, cu
->objfile
->name
);
5787 type
= tag_type_to_type (type_die
, cu
);
5790 dump_die (type_die
);
5791 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
5797 /* Return the containing type of the die in question using its
5798 DW_AT_containing_type attribute. */
5800 static struct type
*
5801 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5803 struct type
*type
= NULL
;
5804 struct attribute
*type_attr
;
5805 struct die_info
*type_die
= NULL
;
5808 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
5811 ref
= dwarf2_get_ref_die_offset (type_attr
);
5812 type_die
= follow_die_ref (ref
);
5815 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref
,
5819 type
= tag_type_to_type (type_die
, cu
);
5824 dump_die (type_die
);
5825 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
5832 static struct type
*
5833 type_at_offset (unsigned int offset
, struct dwarf2_cu
*cu
)
5835 struct die_info
*die
;
5838 die
= follow_die_ref (offset
);
5841 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
5844 type
= tag_type_to_type (die
, cu
);
5849 static struct type
*
5850 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5858 read_type_die (die
, cu
);
5862 error ("Dwarf Error: Cannot find type of die [in module %s]",
5870 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
5872 char *prefix
= determine_prefix (die
);
5873 const char *old_prefix
= processing_current_prefix
;
5874 struct cleanup
*back_to
= make_cleanup (xfree
, prefix
);
5875 processing_current_prefix
= prefix
;
5879 case DW_TAG_class_type
:
5880 case DW_TAG_structure_type
:
5881 case DW_TAG_union_type
:
5882 read_structure_scope (die
, cu
);
5884 case DW_TAG_enumeration_type
:
5885 read_enumeration (die
, cu
);
5887 case DW_TAG_subprogram
:
5888 case DW_TAG_subroutine_type
:
5889 read_subroutine_type (die
, cu
);
5891 case DW_TAG_array_type
:
5892 read_array_type (die
, cu
);
5894 case DW_TAG_pointer_type
:
5895 read_tag_pointer_type (die
, cu
);
5897 case DW_TAG_ptr_to_member_type
:
5898 read_tag_ptr_to_member_type (die
, cu
);
5900 case DW_TAG_reference_type
:
5901 read_tag_reference_type (die
, cu
);
5903 case DW_TAG_const_type
:
5904 read_tag_const_type (die
, cu
);
5906 case DW_TAG_volatile_type
:
5907 read_tag_volatile_type (die
, cu
);
5909 case DW_TAG_string_type
:
5910 read_tag_string_type (die
, cu
);
5912 case DW_TAG_typedef
:
5913 read_typedef (die
, cu
);
5915 case DW_TAG_base_type
:
5916 read_base_type (die
, cu
);
5919 complaint (&symfile_complaints
, "unexepected tag in read_type_die: '%s'",
5920 dwarf_tag_name (die
->tag
));
5924 processing_current_prefix
= old_prefix
;
5925 do_cleanups (back_to
);
5928 /* Return the name of the namespace/class that DIE is defined
5929 within, or NULL if we can't tell. The caller should xfree the
5933 determine_prefix (struct die_info
*die
)
5935 struct die_info
*parent
;
5937 if (cu_language
!= language_cplus
)
5940 parent
= die
->parent
;
5944 return (processing_has_namespace_info
? xstrdup ("") : NULL
);
5948 char *parent_prefix
= determine_prefix (parent
);
5951 switch (parent
->tag
) {
5952 case DW_TAG_namespace
:
5956 retval
= typename_concat (parent_prefix
,
5957 namespace_name (parent
, &dummy
));
5960 case DW_TAG_class_type
:
5961 case DW_TAG_structure_type
:
5963 if (parent_prefix
!= NULL
)
5965 const char *parent_name
= dwarf2_name (parent
);
5967 if (parent_name
!= NULL
)
5968 retval
= typename_concat (parent_prefix
, dwarf2_name (parent
));
5970 /* FIXME: carlton/2003-11-10: I'm not sure what the
5971 best thing to do here is. */
5972 retval
= typename_concat (parent_prefix
,
5973 "<<anonymous class>>");
5976 retval
= class_name (parent
);
5980 retval
= parent_prefix
;
5984 if (retval
!= parent_prefix
)
5985 xfree (parent_prefix
);
5990 /* Return a newly-allocated string formed by concatenating PREFIX,
5991 "::", and SUFFIX, except that if PREFIX is NULL or the empty
5992 string, just return a copy of SUFFIX. */
5995 typename_concat (const char *prefix
, const char *suffix
)
5997 if (prefix
== NULL
|| prefix
[0] == '\0')
5998 return xstrdup (suffix
);
6001 char *retval
= xmalloc (strlen (prefix
) + 2 + strlen (suffix
) + 1);
6003 strcpy (retval
, prefix
);
6004 strcat (retval
, "::");
6005 strcat (retval
, suffix
);
6011 /* Return a newly-allocated string giving the name of the class given
6015 class_name (struct die_info
*die
)
6017 struct die_info
*child
;
6020 for (child
= die
->child
; child
!= NULL
; child
= sibling_die (child
))
6022 if (child
->tag
== DW_TAG_subprogram
)
6023 return class_name_from_physname (dwarf2_linkage_name (child
));
6026 name
= dwarf2_name (die
);
6028 return xstrdup (name
);
6030 return xstrdup ("");
6033 static struct type
*
6034 dwarf_base_type (int encoding
, int size
, struct dwarf2_cu
*cu
)
6036 struct objfile
*objfile
= cu
->objfile
;
6038 /* FIXME - this should not produce a new (struct type *)
6039 every time. It should cache base types. */
6043 case DW_ATE_address
:
6044 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
6046 case DW_ATE_boolean
:
6047 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
6049 case DW_ATE_complex_float
:
6052 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
6056 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
6062 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
6066 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
6073 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
6076 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
6080 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
6084 case DW_ATE_signed_char
:
6085 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
6087 case DW_ATE_unsigned
:
6091 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
6094 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
6098 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
6102 case DW_ATE_unsigned_char
:
6103 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
6106 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
6113 copy_die (struct die_info
*old_die
)
6115 struct die_info
*new_die
;
6118 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6119 memset (new_die
, 0, sizeof (struct die_info
));
6121 new_die
->tag
= old_die
->tag
;
6122 new_die
->has_children
= old_die
->has_children
;
6123 new_die
->abbrev
= old_die
->abbrev
;
6124 new_die
->offset
= old_die
->offset
;
6125 new_die
->type
= NULL
;
6127 num_attrs
= old_die
->num_attrs
;
6128 new_die
->num_attrs
= num_attrs
;
6129 new_die
->attrs
= (struct attribute
*)
6130 xmalloc (num_attrs
* sizeof (struct attribute
));
6132 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
6134 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
6135 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
6136 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
6139 new_die
->next
= NULL
;
6144 /* Return sibling of die, NULL if no sibling. */
6146 static struct die_info
*
6147 sibling_die (struct die_info
*die
)
6149 return die
->sibling
;
6152 /* Get linkage name of a die, return NULL if not found. */
6155 dwarf2_linkage_name (struct die_info
*die
)
6157 struct attribute
*attr
;
6159 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
6160 if (attr
&& DW_STRING (attr
))
6161 return DW_STRING (attr
);
6162 attr
= dwarf_attr (die
, DW_AT_name
);
6163 if (attr
&& DW_STRING (attr
))
6164 return DW_STRING (attr
);
6168 /* Get name of a die, return NULL if not found. */
6171 dwarf2_name (struct die_info
*die
)
6173 struct attribute
*attr
;
6175 attr
= dwarf_attr (die
, DW_AT_name
);
6176 if (attr
&& DW_STRING (attr
))
6177 return DW_STRING (attr
);
6181 /* Return the die that this die in an extension of, or NULL if there
6184 static struct die_info
*
6185 dwarf2_extension (struct die_info
*die
)
6187 struct attribute
*attr
;
6188 struct die_info
*extension_die
;
6191 attr
= dwarf_attr (die
, DW_AT_extension
);
6195 ref
= dwarf2_get_ref_die_offset (attr
);
6196 extension_die
= follow_die_ref (ref
);
6199 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
6202 return extension_die
;
6205 /* Convert a DIE tag into its string name. */
6208 dwarf_tag_name (unsigned tag
)
6212 case DW_TAG_padding
:
6213 return "DW_TAG_padding";
6214 case DW_TAG_array_type
:
6215 return "DW_TAG_array_type";
6216 case DW_TAG_class_type
:
6217 return "DW_TAG_class_type";
6218 case DW_TAG_entry_point
:
6219 return "DW_TAG_entry_point";
6220 case DW_TAG_enumeration_type
:
6221 return "DW_TAG_enumeration_type";
6222 case DW_TAG_formal_parameter
:
6223 return "DW_TAG_formal_parameter";
6224 case DW_TAG_imported_declaration
:
6225 return "DW_TAG_imported_declaration";
6227 return "DW_TAG_label";
6228 case DW_TAG_lexical_block
:
6229 return "DW_TAG_lexical_block";
6231 return "DW_TAG_member";
6232 case DW_TAG_pointer_type
:
6233 return "DW_TAG_pointer_type";
6234 case DW_TAG_reference_type
:
6235 return "DW_TAG_reference_type";
6236 case DW_TAG_compile_unit
:
6237 return "DW_TAG_compile_unit";
6238 case DW_TAG_string_type
:
6239 return "DW_TAG_string_type";
6240 case DW_TAG_structure_type
:
6241 return "DW_TAG_structure_type";
6242 case DW_TAG_subroutine_type
:
6243 return "DW_TAG_subroutine_type";
6244 case DW_TAG_typedef
:
6245 return "DW_TAG_typedef";
6246 case DW_TAG_union_type
:
6247 return "DW_TAG_union_type";
6248 case DW_TAG_unspecified_parameters
:
6249 return "DW_TAG_unspecified_parameters";
6250 case DW_TAG_variant
:
6251 return "DW_TAG_variant";
6252 case DW_TAG_common_block
:
6253 return "DW_TAG_common_block";
6254 case DW_TAG_common_inclusion
:
6255 return "DW_TAG_common_inclusion";
6256 case DW_TAG_inheritance
:
6257 return "DW_TAG_inheritance";
6258 case DW_TAG_inlined_subroutine
:
6259 return "DW_TAG_inlined_subroutine";
6261 return "DW_TAG_module";
6262 case DW_TAG_ptr_to_member_type
:
6263 return "DW_TAG_ptr_to_member_type";
6264 case DW_TAG_set_type
:
6265 return "DW_TAG_set_type";
6266 case DW_TAG_subrange_type
:
6267 return "DW_TAG_subrange_type";
6268 case DW_TAG_with_stmt
:
6269 return "DW_TAG_with_stmt";
6270 case DW_TAG_access_declaration
:
6271 return "DW_TAG_access_declaration";
6272 case DW_TAG_base_type
:
6273 return "DW_TAG_base_type";
6274 case DW_TAG_catch_block
:
6275 return "DW_TAG_catch_block";
6276 case DW_TAG_const_type
:
6277 return "DW_TAG_const_type";
6278 case DW_TAG_constant
:
6279 return "DW_TAG_constant";
6280 case DW_TAG_enumerator
:
6281 return "DW_TAG_enumerator";
6282 case DW_TAG_file_type
:
6283 return "DW_TAG_file_type";
6285 return "DW_TAG_friend";
6286 case DW_TAG_namelist
:
6287 return "DW_TAG_namelist";
6288 case DW_TAG_namelist_item
:
6289 return "DW_TAG_namelist_item";
6290 case DW_TAG_packed_type
:
6291 return "DW_TAG_packed_type";
6292 case DW_TAG_subprogram
:
6293 return "DW_TAG_subprogram";
6294 case DW_TAG_template_type_param
:
6295 return "DW_TAG_template_type_param";
6296 case DW_TAG_template_value_param
:
6297 return "DW_TAG_template_value_param";
6298 case DW_TAG_thrown_type
:
6299 return "DW_TAG_thrown_type";
6300 case DW_TAG_try_block
:
6301 return "DW_TAG_try_block";
6302 case DW_TAG_variant_part
:
6303 return "DW_TAG_variant_part";
6304 case DW_TAG_variable
:
6305 return "DW_TAG_variable";
6306 case DW_TAG_volatile_type
:
6307 return "DW_TAG_volatile_type";
6308 case DW_TAG_dwarf_procedure
:
6309 return "DW_TAG_dwarf_procedure";
6310 case DW_TAG_restrict_type
:
6311 return "DW_TAG_restrict_type";
6312 case DW_TAG_interface_type
:
6313 return "DW_TAG_interface_type";
6314 case DW_TAG_namespace
:
6315 return "DW_TAG_namespace";
6316 case DW_TAG_imported_module
:
6317 return "DW_TAG_imported_module";
6318 case DW_TAG_unspecified_type
:
6319 return "DW_TAG_unspecified_type";
6320 case DW_TAG_partial_unit
:
6321 return "DW_TAG_partial_unit";
6322 case DW_TAG_imported_unit
:
6323 return "DW_TAG_imported_unit";
6324 case DW_TAG_MIPS_loop
:
6325 return "DW_TAG_MIPS_loop";
6326 case DW_TAG_format_label
:
6327 return "DW_TAG_format_label";
6328 case DW_TAG_function_template
:
6329 return "DW_TAG_function_template";
6330 case DW_TAG_class_template
:
6331 return "DW_TAG_class_template";
6333 return "DW_TAG_<unknown>";
6337 /* Convert a DWARF attribute code into its string name. */
6340 dwarf_attr_name (unsigned attr
)
6345 return "DW_AT_sibling";
6346 case DW_AT_location
:
6347 return "DW_AT_location";
6349 return "DW_AT_name";
6350 case DW_AT_ordering
:
6351 return "DW_AT_ordering";
6352 case DW_AT_subscr_data
:
6353 return "DW_AT_subscr_data";
6354 case DW_AT_byte_size
:
6355 return "DW_AT_byte_size";
6356 case DW_AT_bit_offset
:
6357 return "DW_AT_bit_offset";
6358 case DW_AT_bit_size
:
6359 return "DW_AT_bit_size";
6360 case DW_AT_element_list
:
6361 return "DW_AT_element_list";
6362 case DW_AT_stmt_list
:
6363 return "DW_AT_stmt_list";
6365 return "DW_AT_low_pc";
6367 return "DW_AT_high_pc";
6368 case DW_AT_language
:
6369 return "DW_AT_language";
6371 return "DW_AT_member";
6373 return "DW_AT_discr";
6374 case DW_AT_discr_value
:
6375 return "DW_AT_discr_value";
6376 case DW_AT_visibility
:
6377 return "DW_AT_visibility";
6379 return "DW_AT_import";
6380 case DW_AT_string_length
:
6381 return "DW_AT_string_length";
6382 case DW_AT_common_reference
:
6383 return "DW_AT_common_reference";
6384 case DW_AT_comp_dir
:
6385 return "DW_AT_comp_dir";
6386 case DW_AT_const_value
:
6387 return "DW_AT_const_value";
6388 case DW_AT_containing_type
:
6389 return "DW_AT_containing_type";
6390 case DW_AT_default_value
:
6391 return "DW_AT_default_value";
6393 return "DW_AT_inline";
6394 case DW_AT_is_optional
:
6395 return "DW_AT_is_optional";
6396 case DW_AT_lower_bound
:
6397 return "DW_AT_lower_bound";
6398 case DW_AT_producer
:
6399 return "DW_AT_producer";
6400 case DW_AT_prototyped
:
6401 return "DW_AT_prototyped";
6402 case DW_AT_return_addr
:
6403 return "DW_AT_return_addr";
6404 case DW_AT_start_scope
:
6405 return "DW_AT_start_scope";
6406 case DW_AT_stride_size
:
6407 return "DW_AT_stride_size";
6408 case DW_AT_upper_bound
:
6409 return "DW_AT_upper_bound";
6410 case DW_AT_abstract_origin
:
6411 return "DW_AT_abstract_origin";
6412 case DW_AT_accessibility
:
6413 return "DW_AT_accessibility";
6414 case DW_AT_address_class
:
6415 return "DW_AT_address_class";
6416 case DW_AT_artificial
:
6417 return "DW_AT_artificial";
6418 case DW_AT_base_types
:
6419 return "DW_AT_base_types";
6420 case DW_AT_calling_convention
:
6421 return "DW_AT_calling_convention";
6423 return "DW_AT_count";
6424 case DW_AT_data_member_location
:
6425 return "DW_AT_data_member_location";
6426 case DW_AT_decl_column
:
6427 return "DW_AT_decl_column";
6428 case DW_AT_decl_file
:
6429 return "DW_AT_decl_file";
6430 case DW_AT_decl_line
:
6431 return "DW_AT_decl_line";
6432 case DW_AT_declaration
:
6433 return "DW_AT_declaration";
6434 case DW_AT_discr_list
:
6435 return "DW_AT_discr_list";
6436 case DW_AT_encoding
:
6437 return "DW_AT_encoding";
6438 case DW_AT_external
:
6439 return "DW_AT_external";
6440 case DW_AT_frame_base
:
6441 return "DW_AT_frame_base";
6443 return "DW_AT_friend";
6444 case DW_AT_identifier_case
:
6445 return "DW_AT_identifier_case";
6446 case DW_AT_macro_info
:
6447 return "DW_AT_macro_info";
6448 case DW_AT_namelist_items
:
6449 return "DW_AT_namelist_items";
6450 case DW_AT_priority
:
6451 return "DW_AT_priority";
6453 return "DW_AT_segment";
6454 case DW_AT_specification
:
6455 return "DW_AT_specification";
6456 case DW_AT_static_link
:
6457 return "DW_AT_static_link";
6459 return "DW_AT_type";
6460 case DW_AT_use_location
:
6461 return "DW_AT_use_location";
6462 case DW_AT_variable_parameter
:
6463 return "DW_AT_variable_parameter";
6464 case DW_AT_virtuality
:
6465 return "DW_AT_virtuality";
6466 case DW_AT_vtable_elem_location
:
6467 return "DW_AT_vtable_elem_location";
6468 case DW_AT_allocated
:
6469 return "DW_AT_allocated";
6470 case DW_AT_associated
:
6471 return "DW_AT_associated";
6472 case DW_AT_data_location
:
6473 return "DW_AT_data_location";
6475 return "DW_AT_stride";
6476 case DW_AT_entry_pc
:
6477 return "DW_AT_entry_pc";
6478 case DW_AT_use_UTF8
:
6479 return "DW_AT_use_UTF8";
6480 case DW_AT_extension
:
6481 return "DW_AT_extension";
6483 return "DW_AT_ranges";
6484 case DW_AT_trampoline
:
6485 return "DW_AT_trampoline";
6486 case DW_AT_call_column
:
6487 return "DW_AT_call_column";
6488 case DW_AT_call_file
:
6489 return "DW_AT_call_file";
6490 case DW_AT_call_line
:
6491 return "DW_AT_call_line";
6493 case DW_AT_MIPS_fde
:
6494 return "DW_AT_MIPS_fde";
6495 case DW_AT_MIPS_loop_begin
:
6496 return "DW_AT_MIPS_loop_begin";
6497 case DW_AT_MIPS_tail_loop_begin
:
6498 return "DW_AT_MIPS_tail_loop_begin";
6499 case DW_AT_MIPS_epilog_begin
:
6500 return "DW_AT_MIPS_epilog_begin";
6501 case DW_AT_MIPS_loop_unroll_factor
:
6502 return "DW_AT_MIPS_loop_unroll_factor";
6503 case DW_AT_MIPS_software_pipeline_depth
:
6504 return "DW_AT_MIPS_software_pipeline_depth";
6506 case DW_AT_MIPS_linkage_name
:
6507 return "DW_AT_MIPS_linkage_name";
6509 case DW_AT_sf_names
:
6510 return "DW_AT_sf_names";
6511 case DW_AT_src_info
:
6512 return "DW_AT_src_info";
6513 case DW_AT_mac_info
:
6514 return "DW_AT_mac_info";
6515 case DW_AT_src_coords
:
6516 return "DW_AT_src_coords";
6517 case DW_AT_body_begin
:
6518 return "DW_AT_body_begin";
6519 case DW_AT_body_end
:
6520 return "DW_AT_body_end";
6521 case DW_AT_GNU_vector
:
6522 return "DW_AT_GNU_vector";
6524 return "DW_AT_<unknown>";
6528 /* Convert a DWARF value form code into its string name. */
6531 dwarf_form_name (unsigned form
)
6536 return "DW_FORM_addr";
6537 case DW_FORM_block2
:
6538 return "DW_FORM_block2";
6539 case DW_FORM_block4
:
6540 return "DW_FORM_block4";
6542 return "DW_FORM_data2";
6544 return "DW_FORM_data4";
6546 return "DW_FORM_data8";
6547 case DW_FORM_string
:
6548 return "DW_FORM_string";
6550 return "DW_FORM_block";
6551 case DW_FORM_block1
:
6552 return "DW_FORM_block1";
6554 return "DW_FORM_data1";
6556 return "DW_FORM_flag";
6558 return "DW_FORM_sdata";
6560 return "DW_FORM_strp";
6562 return "DW_FORM_udata";
6563 case DW_FORM_ref_addr
:
6564 return "DW_FORM_ref_addr";
6566 return "DW_FORM_ref1";
6568 return "DW_FORM_ref2";
6570 return "DW_FORM_ref4";
6572 return "DW_FORM_ref8";
6573 case DW_FORM_ref_udata
:
6574 return "DW_FORM_ref_udata";
6575 case DW_FORM_indirect
:
6576 return "DW_FORM_indirect";
6578 return "DW_FORM_<unknown>";
6582 /* Convert a DWARF stack opcode into its string name. */
6585 dwarf_stack_op_name (unsigned op
)
6590 return "DW_OP_addr";
6592 return "DW_OP_deref";
6594 return "DW_OP_const1u";
6596 return "DW_OP_const1s";
6598 return "DW_OP_const2u";
6600 return "DW_OP_const2s";
6602 return "DW_OP_const4u";
6604 return "DW_OP_const4s";
6606 return "DW_OP_const8u";
6608 return "DW_OP_const8s";
6610 return "DW_OP_constu";
6612 return "DW_OP_consts";
6616 return "DW_OP_drop";
6618 return "DW_OP_over";
6620 return "DW_OP_pick";
6622 return "DW_OP_swap";
6626 return "DW_OP_xderef";
6634 return "DW_OP_minus";
6646 return "DW_OP_plus";
6647 case DW_OP_plus_uconst
:
6648 return "DW_OP_plus_uconst";
6654 return "DW_OP_shra";
6672 return "DW_OP_skip";
6674 return "DW_OP_lit0";
6676 return "DW_OP_lit1";
6678 return "DW_OP_lit2";
6680 return "DW_OP_lit3";
6682 return "DW_OP_lit4";
6684 return "DW_OP_lit5";
6686 return "DW_OP_lit6";
6688 return "DW_OP_lit7";
6690 return "DW_OP_lit8";
6692 return "DW_OP_lit9";
6694 return "DW_OP_lit10";
6696 return "DW_OP_lit11";
6698 return "DW_OP_lit12";
6700 return "DW_OP_lit13";
6702 return "DW_OP_lit14";
6704 return "DW_OP_lit15";
6706 return "DW_OP_lit16";
6708 return "DW_OP_lit17";
6710 return "DW_OP_lit18";
6712 return "DW_OP_lit19";
6714 return "DW_OP_lit20";
6716 return "DW_OP_lit21";
6718 return "DW_OP_lit22";
6720 return "DW_OP_lit23";
6722 return "DW_OP_lit24";
6724 return "DW_OP_lit25";
6726 return "DW_OP_lit26";
6728 return "DW_OP_lit27";
6730 return "DW_OP_lit28";
6732 return "DW_OP_lit29";
6734 return "DW_OP_lit30";
6736 return "DW_OP_lit31";
6738 return "DW_OP_reg0";
6740 return "DW_OP_reg1";
6742 return "DW_OP_reg2";
6744 return "DW_OP_reg3";
6746 return "DW_OP_reg4";
6748 return "DW_OP_reg5";
6750 return "DW_OP_reg6";
6752 return "DW_OP_reg7";
6754 return "DW_OP_reg8";
6756 return "DW_OP_reg9";
6758 return "DW_OP_reg10";
6760 return "DW_OP_reg11";
6762 return "DW_OP_reg12";
6764 return "DW_OP_reg13";
6766 return "DW_OP_reg14";
6768 return "DW_OP_reg15";
6770 return "DW_OP_reg16";
6772 return "DW_OP_reg17";
6774 return "DW_OP_reg18";
6776 return "DW_OP_reg19";
6778 return "DW_OP_reg20";
6780 return "DW_OP_reg21";
6782 return "DW_OP_reg22";
6784 return "DW_OP_reg23";
6786 return "DW_OP_reg24";
6788 return "DW_OP_reg25";
6790 return "DW_OP_reg26";
6792 return "DW_OP_reg27";
6794 return "DW_OP_reg28";
6796 return "DW_OP_reg29";
6798 return "DW_OP_reg30";
6800 return "DW_OP_reg31";
6802 return "DW_OP_breg0";
6804 return "DW_OP_breg1";
6806 return "DW_OP_breg2";
6808 return "DW_OP_breg3";
6810 return "DW_OP_breg4";
6812 return "DW_OP_breg5";
6814 return "DW_OP_breg6";
6816 return "DW_OP_breg7";
6818 return "DW_OP_breg8";
6820 return "DW_OP_breg9";
6822 return "DW_OP_breg10";
6824 return "DW_OP_breg11";
6826 return "DW_OP_breg12";
6828 return "DW_OP_breg13";
6830 return "DW_OP_breg14";
6832 return "DW_OP_breg15";
6834 return "DW_OP_breg16";
6836 return "DW_OP_breg17";
6838 return "DW_OP_breg18";
6840 return "DW_OP_breg19";
6842 return "DW_OP_breg20";
6844 return "DW_OP_breg21";
6846 return "DW_OP_breg22";
6848 return "DW_OP_breg23";
6850 return "DW_OP_breg24";
6852 return "DW_OP_breg25";
6854 return "DW_OP_breg26";
6856 return "DW_OP_breg27";
6858 return "DW_OP_breg28";
6860 return "DW_OP_breg29";
6862 return "DW_OP_breg30";
6864 return "DW_OP_breg31";
6866 return "DW_OP_regx";
6868 return "DW_OP_fbreg";
6870 return "DW_OP_bregx";
6872 return "DW_OP_piece";
6873 case DW_OP_deref_size
:
6874 return "DW_OP_deref_size";
6875 case DW_OP_xderef_size
:
6876 return "DW_OP_xderef_size";
6879 /* DWARF 3 extensions. */
6880 case DW_OP_push_object_address
:
6881 return "DW_OP_push_object_address";
6883 return "DW_OP_call2";
6885 return "DW_OP_call4";
6886 case DW_OP_call_ref
:
6887 return "DW_OP_call_ref";
6888 /* GNU extensions. */
6889 case DW_OP_GNU_push_tls_address
:
6890 return "DW_OP_GNU_push_tls_address";
6892 return "OP_<unknown>";
6897 dwarf_bool_name (unsigned mybool
)
6905 /* Convert a DWARF type code into its string name. */
6908 dwarf_type_encoding_name (unsigned enc
)
6912 case DW_ATE_address
:
6913 return "DW_ATE_address";
6914 case DW_ATE_boolean
:
6915 return "DW_ATE_boolean";
6916 case DW_ATE_complex_float
:
6917 return "DW_ATE_complex_float";
6919 return "DW_ATE_float";
6921 return "DW_ATE_signed";
6922 case DW_ATE_signed_char
:
6923 return "DW_ATE_signed_char";
6924 case DW_ATE_unsigned
:
6925 return "DW_ATE_unsigned";
6926 case DW_ATE_unsigned_char
:
6927 return "DW_ATE_unsigned_char";
6928 case DW_ATE_imaginary_float
:
6929 return "DW_ATE_imaginary_float";
6931 return "DW_ATE_<unknown>";
6935 /* Convert a DWARF call frame info operation to its string name. */
6939 dwarf_cfi_name (unsigned cfi_opc
)
6943 case DW_CFA_advance_loc
:
6944 return "DW_CFA_advance_loc";
6946 return "DW_CFA_offset";
6947 case DW_CFA_restore
:
6948 return "DW_CFA_restore";
6950 return "DW_CFA_nop";
6951 case DW_CFA_set_loc
:
6952 return "DW_CFA_set_loc";
6953 case DW_CFA_advance_loc1
:
6954 return "DW_CFA_advance_loc1";
6955 case DW_CFA_advance_loc2
:
6956 return "DW_CFA_advance_loc2";
6957 case DW_CFA_advance_loc4
:
6958 return "DW_CFA_advance_loc4";
6959 case DW_CFA_offset_extended
:
6960 return "DW_CFA_offset_extended";
6961 case DW_CFA_restore_extended
:
6962 return "DW_CFA_restore_extended";
6963 case DW_CFA_undefined
:
6964 return "DW_CFA_undefined";
6965 case DW_CFA_same_value
:
6966 return "DW_CFA_same_value";
6967 case DW_CFA_register
:
6968 return "DW_CFA_register";
6969 case DW_CFA_remember_state
:
6970 return "DW_CFA_remember_state";
6971 case DW_CFA_restore_state
:
6972 return "DW_CFA_restore_state";
6973 case DW_CFA_def_cfa
:
6974 return "DW_CFA_def_cfa";
6975 case DW_CFA_def_cfa_register
:
6976 return "DW_CFA_def_cfa_register";
6977 case DW_CFA_def_cfa_offset
:
6978 return "DW_CFA_def_cfa_offset";
6981 case DW_CFA_def_cfa_expression
:
6982 return "DW_CFA_def_cfa_expression";
6983 case DW_CFA_expression
:
6984 return "DW_CFA_expression";
6985 case DW_CFA_offset_extended_sf
:
6986 return "DW_CFA_offset_extended_sf";
6987 case DW_CFA_def_cfa_sf
:
6988 return "DW_CFA_def_cfa_sf";
6989 case DW_CFA_def_cfa_offset_sf
:
6990 return "DW_CFA_def_cfa_offset_sf";
6992 /* SGI/MIPS specific */
6993 case DW_CFA_MIPS_advance_loc8
:
6994 return "DW_CFA_MIPS_advance_loc8";
6996 /* GNU extensions */
6997 case DW_CFA_GNU_window_save
:
6998 return "DW_CFA_GNU_window_save";
6999 case DW_CFA_GNU_args_size
:
7000 return "DW_CFA_GNU_args_size";
7001 case DW_CFA_GNU_negative_offset_extended
:
7002 return "DW_CFA_GNU_negative_offset_extended";
7005 return "DW_CFA_<unknown>";
7011 dump_die (struct die_info
*die
)
7015 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
7016 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
7017 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
7018 dwarf_bool_name (die
->child
!= NULL
));
7020 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
7021 for (i
= 0; i
< die
->num_attrs
; ++i
)
7023 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
7024 dwarf_attr_name (die
->attrs
[i
].name
),
7025 dwarf_form_name (die
->attrs
[i
].form
));
7026 switch (die
->attrs
[i
].form
)
7028 case DW_FORM_ref_addr
:
7030 fprintf_unfiltered (gdb_stderr
, "address: ");
7031 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
7033 case DW_FORM_block2
:
7034 case DW_FORM_block4
:
7036 case DW_FORM_block1
:
7037 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
7048 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
7050 case DW_FORM_string
:
7052 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
7053 DW_STRING (&die
->attrs
[i
])
7054 ? DW_STRING (&die
->attrs
[i
]) : "");
7057 if (DW_UNSND (&die
->attrs
[i
]))
7058 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
7060 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
7062 case DW_FORM_indirect
:
7063 /* the reader will have reduced the indirect form to
7064 the "base form" so this form should not occur */
7065 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
7068 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
7069 die
->attrs
[i
].form
);
7071 fprintf_unfiltered (gdb_stderr
, "\n");
7076 dump_die_list (struct die_info
*die
)
7081 if (die
->child
!= NULL
)
7082 dump_die_list (die
->child
);
7083 if (die
->sibling
!= NULL
)
7084 dump_die_list (die
->sibling
);
7089 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
7092 struct die_info
*old
;
7094 h
= (offset
% REF_HASH_SIZE
);
7095 old
= die_ref_table
[h
];
7096 die
->next_ref
= old
;
7097 die_ref_table
[h
] = die
;
7102 dwarf2_empty_hash_tables (void)
7104 memset (die_ref_table
, 0, sizeof (die_ref_table
));
7108 dwarf2_get_ref_die_offset (struct attribute
*attr
)
7110 unsigned int result
= 0;
7114 case DW_FORM_ref_addr
:
7115 result
= DW_ADDR (attr
);
7121 case DW_FORM_ref_udata
:
7122 result
= cu_header_offset
+ DW_UNSND (attr
);
7125 complaint (&symfile_complaints
,
7126 "unsupported die ref attribute form: '%s'",
7127 dwarf_form_name (attr
->form
));
7132 static struct die_info
*
7133 follow_die_ref (unsigned int offset
)
7135 struct die_info
*die
;
7138 h
= (offset
% REF_HASH_SIZE
);
7139 die
= die_ref_table
[h
];
7142 if (die
->offset
== offset
)
7146 die
= die
->next_ref
;
7151 static struct type
*
7152 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
7154 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
7156 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
7157 typeid, objfile
->name
);
7160 /* Look for this particular type in the fundamental type vector. If
7161 one is not found, create and install one appropriate for the
7162 current language and the current target machine. */
7164 if (ftypes
[typeid] == NULL
)
7166 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
7169 return (ftypes
[typeid]);
7172 /* Decode simple location descriptions.
7173 Given a pointer to a dwarf block that defines a location, compute
7174 the location and return the value.
7176 NOTE drow/2003-11-18: This function is called in two situations
7177 now: for the address of static or global variables (partial symbols
7178 only) and for offsets into structures which are expected to be
7179 (more or less) constant. The partial symbol case should go away,
7180 and only the constant case should remain. That will let this
7181 function complain more accurately. A few special modes are allowed
7182 without complaint for global variables (for instance, global
7183 register values and thread-local values).
7185 A location description containing no operations indicates that the
7186 object is optimized out. The return value is 0 for that case.
7187 FIXME drow/2003-11-16: No callers check for this case any more; soon all
7188 callers will only want a very basic result and this can become a
7191 When the result is a register number, the global isreg flag is set,
7192 otherwise it is cleared.
7194 Note that stack[0] is unused except as a default error return.
7195 Note that stack overflow is not yet handled. */
7198 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
7200 struct objfile
*objfile
= cu
->objfile
;
7201 struct comp_unit_head
*cu_header
= &cu
->header
;
7203 int size
= blk
->size
;
7204 char *data
= blk
->data
;
7205 CORE_ADDR stack
[64];
7207 unsigned int bytes_read
, unsnd
;
7252 stack
[++stacki
] = op
- DW_OP_lit0
;
7288 stack
[++stacki
] = op
- DW_OP_reg0
;
7290 dwarf2_complex_location_expr_complaint ();
7295 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
7297 stack
[++stacki
] = unsnd
;
7299 dwarf2_complex_location_expr_complaint ();
7303 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
7309 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
7314 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
7319 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
7324 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
7329 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
7334 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
7339 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
7345 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
7350 stack
[stacki
+ 1] = stack
[stacki
];
7355 stack
[stacki
- 1] += stack
[stacki
];
7359 case DW_OP_plus_uconst
:
7360 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
7365 stack
[stacki
- 1] -= stack
[stacki
];
7370 /* If we're not the last op, then we definitely can't encode
7371 this using GDB's address_class enum. This is valid for partial
7372 global symbols, although the variable's address will be bogus
7375 dwarf2_complex_location_expr_complaint ();
7378 case DW_OP_GNU_push_tls_address
:
7379 /* The top of the stack has the offset from the beginning
7380 of the thread control block at which the variable is located. */
7381 /* Nothing should follow this operator, so the top of stack would
7383 /* This is valid for partial global symbols, but the variable's
7384 address will be bogus in the psymtab. */
7386 dwarf2_complex_location_expr_complaint ();
7390 complaint (&symfile_complaints
, "unsupported stack op: '%s'",
7391 dwarf_stack_op_name (op
));
7392 return (stack
[stacki
]);
7395 return (stack
[stacki
]);
7398 /* memory allocation interface */
7401 dwarf2_free_tmp_obstack (void *ignore
)
7403 obstack_free (&dwarf2_tmp_obstack
, NULL
);
7406 static struct dwarf_block
*
7407 dwarf_alloc_block (void)
7409 struct dwarf_block
*blk
;
7411 blk
= (struct dwarf_block
*)
7412 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
7416 static struct abbrev_info
*
7417 dwarf_alloc_abbrev (void)
7419 struct abbrev_info
*abbrev
;
7421 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
7422 memset (abbrev
, 0, sizeof (struct abbrev_info
));
7426 static struct die_info
*
7427 dwarf_alloc_die (void)
7429 struct die_info
*die
;
7431 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
7432 memset (die
, 0, sizeof (struct die_info
));
7437 /* Macro support. */
7440 /* Return the full name of file number I in *LH's file name table.
7441 Use COMP_DIR as the name of the current directory of the
7442 compilation. The result is allocated using xmalloc; the caller is
7443 responsible for freeing it. */
7445 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
7447 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7449 if (IS_ABSOLUTE_PATH (fe
->name
))
7450 return xstrdup (fe
->name
);
7458 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7464 dir_len
= strlen (dir
);
7465 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
7466 strcpy (full_name
, dir
);
7467 full_name
[dir_len
] = '/';
7468 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
7472 return xstrdup (fe
->name
);
7477 static struct macro_source_file
*
7478 macro_start_file (int file
, int line
,
7479 struct macro_source_file
*current_file
,
7480 const char *comp_dir
,
7481 struct line_header
*lh
, struct objfile
*objfile
)
7483 /* The full name of this source file. */
7484 char *full_name
= file_full_name (file
, lh
, comp_dir
);
7486 /* We don't create a macro table for this compilation unit
7487 at all until we actually get a filename. */
7488 if (! pending_macros
)
7489 pending_macros
= new_macro_table (&objfile
->symbol_obstack
,
7490 objfile
->macro_cache
);
7493 /* If we have no current file, then this must be the start_file
7494 directive for the compilation unit's main source file. */
7495 current_file
= macro_set_main (pending_macros
, full_name
);
7497 current_file
= macro_include (current_file
, line
, full_name
);
7501 return current_file
;
7505 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
7506 followed by a null byte. */
7508 copy_string (const char *buf
, int len
)
7510 char *s
= xmalloc (len
+ 1);
7511 memcpy (s
, buf
, len
);
7519 consume_improper_spaces (const char *p
, const char *body
)
7523 complaint (&symfile_complaints
,
7524 "macro definition contains spaces in formal argument list:\n`%s'",
7536 parse_macro_definition (struct macro_source_file
*file
, int line
,
7541 /* The body string takes one of two forms. For object-like macro
7542 definitions, it should be:
7544 <macro name> " " <definition>
7546 For function-like macro definitions, it should be:
7548 <macro name> "() " <definition>
7550 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
7552 Spaces may appear only where explicitly indicated, and in the
7555 The Dwarf 2 spec says that an object-like macro's name is always
7556 followed by a space, but versions of GCC around March 2002 omit
7557 the space when the macro's definition is the empty string.
7559 The Dwarf 2 spec says that there should be no spaces between the
7560 formal arguments in a function-like macro's formal argument list,
7561 but versions of GCC around March 2002 include spaces after the
7565 /* Find the extent of the macro name. The macro name is terminated
7566 by either a space or null character (for an object-like macro) or
7567 an opening paren (for a function-like macro). */
7568 for (p
= body
; *p
; p
++)
7569 if (*p
== ' ' || *p
== '(')
7572 if (*p
== ' ' || *p
== '\0')
7574 /* It's an object-like macro. */
7575 int name_len
= p
- body
;
7576 char *name
= copy_string (body
, name_len
);
7577 const char *replacement
;
7580 replacement
= body
+ name_len
+ 1;
7583 dwarf2_macro_malformed_definition_complaint (body
);
7584 replacement
= body
+ name_len
;
7587 macro_define_object (file
, line
, name
, replacement
);
7593 /* It's a function-like macro. */
7594 char *name
= copy_string (body
, p
- body
);
7597 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
7601 p
= consume_improper_spaces (p
, body
);
7603 /* Parse the formal argument list. */
7604 while (*p
&& *p
!= ')')
7606 /* Find the extent of the current argument name. */
7607 const char *arg_start
= p
;
7609 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
7612 if (! *p
|| p
== arg_start
)
7613 dwarf2_macro_malformed_definition_complaint (body
);
7616 /* Make sure argv has room for the new argument. */
7617 if (argc
>= argv_size
)
7620 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
7623 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
7626 p
= consume_improper_spaces (p
, body
);
7628 /* Consume the comma, if present. */
7633 p
= consume_improper_spaces (p
, body
);
7642 /* Perfectly formed definition, no complaints. */
7643 macro_define_function (file
, line
, name
,
7644 argc
, (const char **) argv
,
7646 else if (*p
== '\0')
7648 /* Complain, but do define it. */
7649 dwarf2_macro_malformed_definition_complaint (body
);
7650 macro_define_function (file
, line
, name
,
7651 argc
, (const char **) argv
,
7655 /* Just complain. */
7656 dwarf2_macro_malformed_definition_complaint (body
);
7659 /* Just complain. */
7660 dwarf2_macro_malformed_definition_complaint (body
);
7666 for (i
= 0; i
< argc
; i
++)
7672 dwarf2_macro_malformed_definition_complaint (body
);
7677 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
7678 char *comp_dir
, bfd
*abfd
,
7679 struct dwarf2_cu
*cu
)
7681 char *mac_ptr
, *mac_end
;
7682 struct macro_source_file
*current_file
= 0;
7684 if (dwarf_macinfo_buffer
== NULL
)
7686 complaint (&symfile_complaints
, "missing .debug_macinfo section");
7690 mac_ptr
= dwarf_macinfo_buffer
+ offset
;
7691 mac_end
= dwarf_macinfo_buffer
+ dwarf_macinfo_size
;
7695 enum dwarf_macinfo_record_type macinfo_type
;
7697 /* Do we at least have room for a macinfo type byte? */
7698 if (mac_ptr
>= mac_end
)
7700 dwarf2_macros_too_long_complaint ();
7704 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
7707 switch (macinfo_type
)
7709 /* A zero macinfo type indicates the end of the macro
7714 case DW_MACINFO_define
:
7715 case DW_MACINFO_undef
:
7721 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7722 mac_ptr
+= bytes_read
;
7723 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
7724 mac_ptr
+= bytes_read
;
7727 complaint (&symfile_complaints
,
7728 "debug info gives macro %s outside of any file: %s",
7730 DW_MACINFO_define
? "definition" : macinfo_type
==
7731 DW_MACINFO_undef
? "undefinition" :
7732 "something-or-other", body
);
7735 if (macinfo_type
== DW_MACINFO_define
)
7736 parse_macro_definition (current_file
, line
, body
);
7737 else if (macinfo_type
== DW_MACINFO_undef
)
7738 macro_undef (current_file
, line
, body
);
7743 case DW_MACINFO_start_file
:
7748 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7749 mac_ptr
+= bytes_read
;
7750 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7751 mac_ptr
+= bytes_read
;
7753 current_file
= macro_start_file (file
, line
,
7754 current_file
, comp_dir
,
7759 case DW_MACINFO_end_file
:
7761 complaint (&symfile_complaints
,
7762 "macro debug info has an unmatched `close_file' directive");
7765 current_file
= current_file
->included_by
;
7768 enum dwarf_macinfo_record_type next_type
;
7770 /* GCC circa March 2002 doesn't produce the zero
7771 type byte marking the end of the compilation
7772 unit. Complain if it's not there, but exit no
7775 /* Do we at least have room for a macinfo type byte? */
7776 if (mac_ptr
>= mac_end
)
7778 dwarf2_macros_too_long_complaint ();
7782 /* We don't increment mac_ptr here, so this is just
7784 next_type
= read_1_byte (abfd
, mac_ptr
);
7786 complaint (&symfile_complaints
,
7787 "no terminating 0-type entry for macros in `.debug_macinfo' section");
7794 case DW_MACINFO_vendor_ext
:
7800 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7801 mac_ptr
+= bytes_read
;
7802 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
7803 mac_ptr
+= bytes_read
;
7805 /* We don't recognize any vendor extensions. */
7812 /* Check if the attribute's form is a DW_FORM_block*
7813 if so return true else false. */
7815 attr_form_is_block (struct attribute
*attr
)
7817 return (attr
== NULL
? 0 :
7818 attr
->form
== DW_FORM_block1
7819 || attr
->form
== DW_FORM_block2
7820 || attr
->form
== DW_FORM_block4
7821 || attr
->form
== DW_FORM_block
);
7825 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
7826 struct dwarf2_cu
*cu
)
7828 if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
7830 struct dwarf2_loclist_baton
*baton
;
7832 baton
= obstack_alloc (&cu
->objfile
->symbol_obstack
,
7833 sizeof (struct dwarf2_loclist_baton
));
7834 baton
->objfile
= cu
->objfile
;
7836 /* We don't know how long the location list is, but make sure we
7837 don't run off the edge of the section. */
7838 baton
->size
= dwarf_loc_size
- DW_UNSND (attr
);
7839 baton
->data
= dwarf_loc_buffer
+ DW_UNSND (attr
);
7840 baton
->base_address
= cu
->header
.base_address
;
7841 if (cu
->header
.base_known
== 0)
7842 complaint (&symfile_complaints
,
7843 "Location list used without specifying the CU base address.");
7845 SYMBOL_LOCATION_FUNCS (sym
) = &dwarf2_loclist_funcs
;
7846 SYMBOL_LOCATION_BATON (sym
) = baton
;
7850 struct dwarf2_locexpr_baton
*baton
;
7852 baton
= obstack_alloc (&cu
->objfile
->symbol_obstack
,
7853 sizeof (struct dwarf2_locexpr_baton
));
7854 baton
->objfile
= cu
->objfile
;
7856 if (attr_form_is_block (attr
))
7858 /* Note that we're just copying the block's data pointer
7859 here, not the actual data. We're still pointing into the
7860 dwarf_info_buffer for SYM's objfile; right now we never
7861 release that buffer, but when we do clean up properly
7862 this may need to change. */
7863 baton
->size
= DW_BLOCK (attr
)->size
;
7864 baton
->data
= DW_BLOCK (attr
)->data
;
7868 dwarf2_invalid_attrib_class_complaint ("location description",
7869 SYMBOL_NATURAL_NAME (sym
));
7874 SYMBOL_LOCATION_FUNCS (sym
) = &dwarf2_locexpr_funcs
;
7875 SYMBOL_LOCATION_BATON (sym
) = baton
;