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. */
35 #include "elf/dwarf2.h"
38 #include "expression.h"
39 #include "filenames.h" /* for DOSish file names */
42 #include "complaints.h"
44 #include "dwarf2expr.h"
45 #include "dwarf2loc.h"
46 #include "cp-support.h"
49 #include "gdb_string.h"
50 #include "gdb_assert.h"
51 #include <sys/types.h>
53 /* A note on memory usage for this file.
55 At the present time, this code reads the debug info sections into
56 the objfile's objfile_obstack. A definite improvement for startup
57 time, on platforms which do not emit relocations for debug
58 sections, would be to use mmap instead. The object's complete
59 debug information is loaded into memory, partly to simplify
60 absolute DIE references.
62 Whether using obstacks or mmap, the sections should remain loaded
63 until the objfile is released, and pointers into the section data
64 can be used for any other data associated to the objfile (symbol
65 names, type names, location expressions to name a few). */
67 #ifndef DWARF2_REG_TO_REGNUM
68 #define DWARF2_REG_TO_REGNUM(REG) (REG)
72 /* .debug_info header for a compilation unit
73 Because of alignment constraints, this structure has padding and cannot
74 be mapped directly onto the beginning of the .debug_info section. */
75 typedef struct comp_unit_header
77 unsigned int length
; /* length of the .debug_info
79 unsigned short version
; /* version number -- 2 for DWARF
81 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
82 unsigned char addr_size
; /* byte size of an address -- 4 */
85 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
88 /* .debug_pubnames header
89 Because of alignment constraints, this structure has padding and cannot
90 be mapped directly onto the beginning of the .debug_info section. */
91 typedef struct pubnames_header
93 unsigned int length
; /* length of the .debug_pubnames
95 unsigned char version
; /* version number -- 2 for DWARF
97 unsigned int info_offset
; /* offset into .debug_info section */
98 unsigned int info_size
; /* byte size of .debug_info section
102 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
104 /* .debug_pubnames header
105 Because of alignment constraints, this structure has padding and cannot
106 be mapped directly onto the beginning of the .debug_info section. */
107 typedef struct aranges_header
109 unsigned int length
; /* byte len of the .debug_aranges
111 unsigned short version
; /* version number -- 2 for DWARF
113 unsigned int info_offset
; /* offset into .debug_info section */
114 unsigned char addr_size
; /* byte size of an address */
115 unsigned char seg_size
; /* byte size of segment descriptor */
118 #define _ACTUAL_ARANGES_HEADER_SIZE 12
120 /* .debug_line statement program prologue
121 Because of alignment constraints, this structure has padding and cannot
122 be mapped directly onto the beginning of the .debug_info section. */
123 typedef struct statement_prologue
125 unsigned int total_length
; /* byte length of the statement
127 unsigned short version
; /* version number -- 2 for DWARF
129 unsigned int prologue_length
; /* # bytes between prologue &
131 unsigned char minimum_instruction_length
; /* byte size of
133 unsigned char default_is_stmt
; /* initial value of is_stmt
136 unsigned char line_range
;
137 unsigned char opcode_base
; /* number assigned to first special
139 unsigned char *standard_opcode_lengths
;
143 /* offsets and sizes of debugging sections */
145 static unsigned int dwarf_info_size
;
146 static unsigned int dwarf_abbrev_size
;
147 static unsigned int dwarf_line_size
;
148 static unsigned int dwarf_pubnames_size
;
149 static unsigned int dwarf_aranges_size
;
150 static unsigned int dwarf_loc_size
;
151 static unsigned int dwarf_macinfo_size
;
152 static unsigned int dwarf_str_size
;
153 static unsigned int dwarf_ranges_size
;
154 unsigned int dwarf_frame_size
;
155 unsigned int dwarf_eh_frame_size
;
157 static asection
*dwarf_info_section
;
158 static asection
*dwarf_abbrev_section
;
159 static asection
*dwarf_line_section
;
160 static asection
*dwarf_pubnames_section
;
161 static asection
*dwarf_aranges_section
;
162 static asection
*dwarf_loc_section
;
163 static asection
*dwarf_macinfo_section
;
164 static asection
*dwarf_str_section
;
165 static asection
*dwarf_ranges_section
;
166 asection
*dwarf_frame_section
;
167 asection
*dwarf_eh_frame_section
;
169 /* names of the debugging sections */
171 #define INFO_SECTION ".debug_info"
172 #define ABBREV_SECTION ".debug_abbrev"
173 #define LINE_SECTION ".debug_line"
174 #define PUBNAMES_SECTION ".debug_pubnames"
175 #define ARANGES_SECTION ".debug_aranges"
176 #define LOC_SECTION ".debug_loc"
177 #define MACINFO_SECTION ".debug_macinfo"
178 #define STR_SECTION ".debug_str"
179 #define RANGES_SECTION ".debug_ranges"
180 #define FRAME_SECTION ".debug_frame"
181 #define EH_FRAME_SECTION ".eh_frame"
183 /* local data types */
185 /* We hold several abbreviation tables in memory at the same time. */
186 #ifndef ABBREV_HASH_SIZE
187 #define ABBREV_HASH_SIZE 121
190 /* The data in a compilation unit header, after target2host
191 translation, looks like this. */
192 struct comp_unit_head
194 unsigned long length
;
196 unsigned int abbrev_offset
;
197 unsigned char addr_size
;
198 unsigned char signed_addr_p
;
199 unsigned int offset_size
; /* size of file offsets; either 4 or 8 */
200 unsigned int initial_length_size
; /* size of the length field; either
203 /* Offset to the first byte of this compilation unit header in the
204 * .debug_info section, for resolving relative reference dies. */
208 /* Pointer to this compilation unit header in the .debug_info
213 /* Pointer to the first die of this compilatio unit. This will
214 * be the first byte following the compilation unit header. */
218 /* Pointer to the next compilation unit header in the program. */
220 struct comp_unit_head
*next
;
222 /* Base address of this compilation unit. */
224 CORE_ADDR base_address
;
226 /* Non-zero if base_address has been set. */
231 /* Internal state when decoding a particular compilation unit. */
234 /* The objfile containing this compilation unit. */
235 struct objfile
*objfile
;
237 /* The header of the compilation unit.
239 FIXME drow/2003-11-10: Some of the things from the comp_unit_head
240 should logically be moved to the dwarf2_cu structure. */
241 struct comp_unit_head header
;
243 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
245 /* The language we are debugging. */
246 enum language language
;
247 const struct language_defn
*language_defn
;
249 /* The generic symbol table building routines have separate lists for
250 file scope symbols and all all other scopes (local scopes). So
251 we need to select the right one to pass to add_symbol_to_list().
252 We do it by keeping a pointer to the correct list in list_in_scope.
254 FIXME: The original dwarf code just treated the file scope as the
255 first local scope, and all other local scopes as nested local
256 scopes, and worked fine. Check to see if we really need to
257 distinguish these in buildsym.c. */
258 struct pending
**list_in_scope
;
260 /* Maintain an array of referenced fundamental types for the current
261 compilation unit being read. For DWARF version 1, we have to construct
262 the fundamental types on the fly, since no information about the
263 fundamental types is supplied. Each such fundamental type is created by
264 calling a language dependent routine to create the type, and then a
265 pointer to that type is then placed in the array at the index specified
266 by it's FT_<TYPENAME> value. The array has a fixed size set by the
267 FT_NUM_MEMBERS compile time constant, which is the number of predefined
268 fundamental types gdb knows how to construct. */
269 struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
271 /* DWARF abbreviation table associated with this compilation unit. */
272 struct abbrev_info
**dwarf2_abbrevs
;
274 /* Storage for the abbrev table. */
275 struct obstack abbrev_obstack
;
278 /* The line number information for a compilation unit (found in the
279 .debug_line section) begins with a "statement program header",
280 which contains the following information. */
283 unsigned int total_length
;
284 unsigned short version
;
285 unsigned int header_length
;
286 unsigned char minimum_instruction_length
;
287 unsigned char default_is_stmt
;
289 unsigned char line_range
;
290 unsigned char opcode_base
;
292 /* standard_opcode_lengths[i] is the number of operands for the
293 standard opcode whose value is i. This means that
294 standard_opcode_lengths[0] is unused, and the last meaningful
295 element is standard_opcode_lengths[opcode_base - 1]. */
296 unsigned char *standard_opcode_lengths
;
298 /* The include_directories table. NOTE! These strings are not
299 allocated with xmalloc; instead, they are pointers into
300 debug_line_buffer. If you try to free them, `free' will get
302 unsigned int num_include_dirs
, include_dirs_size
;
305 /* The file_names table. NOTE! These strings are not allocated
306 with xmalloc; instead, they are pointers into debug_line_buffer.
307 Don't try to free them directly. */
308 unsigned int num_file_names
, file_names_size
;
312 unsigned int dir_index
;
313 unsigned int mod_time
;
317 /* The start and end of the statement program following this
318 header. These point into dwarf_line_buffer. */
319 char *statement_program_start
, *statement_program_end
;
322 /* When we construct a partial symbol table entry we only
323 need this much information. */
324 struct partial_die_info
327 unsigned char has_children
;
328 unsigned char is_external
;
329 unsigned char is_declaration
;
330 unsigned char has_type
;
337 struct dwarf_block
*locdesc
;
338 unsigned int language
;
342 /* This data structure holds the information of an abbrev. */
345 unsigned int number
; /* number identifying abbrev */
346 enum dwarf_tag tag
; /* dwarf tag */
347 unsigned short has_children
; /* boolean */
348 unsigned short num_attrs
; /* number of attributes */
349 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
350 struct abbrev_info
*next
; /* next in chain */
355 enum dwarf_attribute name
;
356 enum dwarf_form form
;
359 /* This data structure holds a complete die structure. */
362 enum dwarf_tag tag
; /* Tag indicating type of die */
363 unsigned int abbrev
; /* Abbrev number */
364 unsigned int offset
; /* Offset in .debug_info section */
365 unsigned int num_attrs
; /* Number of attributes */
366 struct attribute
*attrs
; /* An array of attributes */
367 struct die_info
*next_ref
; /* Next die in ref hash table */
369 /* The dies in a compilation unit form an n-ary tree. PARENT
370 points to this die's parent; CHILD points to the first child of
371 this node; and all the children of a given node are chained
372 together via their SIBLING fields, terminated by a die whose
374 struct die_info
*child
; /* Its first child, if any. */
375 struct die_info
*sibling
; /* Its next sibling, if any. */
376 struct die_info
*parent
; /* Its parent, if any. */
378 struct type
*type
; /* Cached type information */
381 /* Attributes have a name and a value */
384 enum dwarf_attribute name
;
385 enum dwarf_form form
;
389 struct dwarf_block
*blk
;
397 struct function_range
400 CORE_ADDR lowpc
, highpc
;
402 struct function_range
*next
;
405 /* Get at parts of an attribute structure */
407 #define DW_STRING(attr) ((attr)->u.str)
408 #define DW_UNSND(attr) ((attr)->u.unsnd)
409 #define DW_BLOCK(attr) ((attr)->u.blk)
410 #define DW_SND(attr) ((attr)->u.snd)
411 #define DW_ADDR(attr) ((attr)->u.addr)
413 /* Blocks are a bunch of untyped bytes. */
420 #ifndef ATTR_ALLOC_CHUNK
421 #define ATTR_ALLOC_CHUNK 4
424 /* A hash table of die offsets for following references. */
425 #ifndef REF_HASH_SIZE
426 #define REF_HASH_SIZE 1021
429 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
431 /* Obstack for allocating temporary storage used during symbol reading. */
432 static struct obstack dwarf2_tmp_obstack
;
434 /* Allocate fields for structs, unions and enums in this size. */
435 #ifndef DW_FIELD_ALLOC_CHUNK
436 #define DW_FIELD_ALLOC_CHUNK 4
439 /* Actually data from the sections. */
440 static char *dwarf_info_buffer
;
441 static char *dwarf_abbrev_buffer
;
442 static char *dwarf_line_buffer
;
443 static char *dwarf_str_buffer
;
444 static char *dwarf_macinfo_buffer
;
445 static char *dwarf_ranges_buffer
;
446 static char *dwarf_loc_buffer
;
448 /* A zeroed version of a partial die for initialization purposes. */
449 static struct partial_die_info zeroed_partial_die
;
451 /* FIXME: decode_locdesc sets these variables to describe the location
452 to the caller. These ought to be a structure or something. If
453 none of the flags are set, the object lives at the address returned
454 by decode_locdesc. */
456 static int isreg
; /* Object lives in register.
457 decode_locdesc's return value is
458 the register number. */
460 /* We put a pointer to this structure in the read_symtab_private field
463 Most of the information in this structure is related to an entire
464 object file and could be passed via the sym_private field of the
465 objfile. It is possible to have both dwarf2 and some other form
466 of debug symbols in one object file. */
470 /* Pointer to start of dwarf info buffer for the objfile. */
472 char *dwarf_info_buffer
;
474 /* Offset in dwarf_info_buffer for this compilation unit. */
476 unsigned long dwarf_info_offset
;
478 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
480 char *dwarf_abbrev_buffer
;
482 /* Size of dwarf abbreviation section for the objfile. */
484 unsigned int dwarf_abbrev_size
;
486 /* Pointer to start of dwarf line buffer for the objfile. */
488 char *dwarf_line_buffer
;
490 /* Size of dwarf_line_buffer, in bytes. */
492 unsigned int dwarf_line_size
;
494 /* Pointer to start of dwarf string buffer for the objfile. */
496 char *dwarf_str_buffer
;
498 /* Size of dwarf string section for the objfile. */
500 unsigned int dwarf_str_size
;
502 /* Pointer to start of dwarf macro buffer for the objfile. */
504 char *dwarf_macinfo_buffer
;
506 /* Size of dwarf macinfo section for the objfile. */
508 unsigned int dwarf_macinfo_size
;
510 /* Pointer to start of dwarf ranges buffer for the objfile. */
512 char *dwarf_ranges_buffer
;
514 /* Size of dwarf ranges buffer for the objfile. */
516 unsigned int dwarf_ranges_size
;
518 /* Pointer to start of dwarf locations buffer for the objfile. */
520 char *dwarf_loc_buffer
;
522 /* Size of dwarf locations buffer for the objfile. */
524 unsigned int dwarf_loc_size
;
527 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
528 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
529 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
530 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
531 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
532 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
533 #define DWARF_LINE_SIZE(p) (PST_PRIVATE(p)->dwarf_line_size)
534 #define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer)
535 #define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size)
536 #define DWARF_MACINFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_macinfo_buffer)
537 #define DWARF_MACINFO_SIZE(p) (PST_PRIVATE(p)->dwarf_macinfo_size)
538 #define DWARF_RANGES_BUFFER(p) (PST_PRIVATE(p)->dwarf_ranges_buffer)
539 #define DWARF_RANGES_SIZE(p) (PST_PRIVATE(p)->dwarf_ranges_size)
540 #define DWARF_LOC_BUFFER(p) (PST_PRIVATE(p)->dwarf_loc_buffer)
541 #define DWARF_LOC_SIZE(p) (PST_PRIVATE(p)->dwarf_loc_size)
543 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
544 but this would require a corresponding change in unpack_field_as_long
546 static int bits_per_byte
= 8;
548 /* The routines that read and process dies for a C struct or C++ class
549 pass lists of data member fields and lists of member function fields
550 in an instance of a field_info structure, as defined below. */
553 /* List of data member and baseclasses fields. */
556 struct nextfield
*next
;
563 /* Number of fields. */
566 /* Number of baseclasses. */
569 /* Set if the accesibility of one of the fields is not public. */
570 int non_public_fields
;
572 /* Member function fields array, entries are allocated in the order they
573 are encountered in the object file. */
576 struct nextfnfield
*next
;
577 struct fn_field fnfield
;
581 /* Member function fieldlist array, contains name of possibly overloaded
582 member function, number of overloaded member functions and a pointer
583 to the head of the member function field chain. */
588 struct nextfnfield
*head
;
592 /* Number of entries in the fnfieldlists array. */
596 /* Various complaints about symbol reading that don't abort the process */
599 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
601 complaint (&symfile_complaints
,
602 "statement list doesn't fit in .debug_line section");
606 dwarf2_complex_location_expr_complaint (void)
608 complaint (&symfile_complaints
, "location expression too complex");
612 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
615 complaint (&symfile_complaints
,
616 "const value length mismatch for '%s', got %d, expected %d", arg1
,
621 dwarf2_macros_too_long_complaint (void)
623 complaint (&symfile_complaints
,
624 "macro info runs off end of `.debug_macinfo' section");
628 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
630 complaint (&symfile_complaints
,
631 "macro debug info contains a malformed macro definition:\n`%s'",
636 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
638 complaint (&symfile_complaints
,
639 "invalid attribute class or form for '%s' in '%s'", arg1
, arg2
);
642 /* local function prototypes */
644 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
647 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
650 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
652 static char *scan_partial_symbols (char *, CORE_ADDR
*, CORE_ADDR
*,
654 const char *namespace);
656 static void add_partial_symbol (struct partial_die_info
*, struct dwarf2_cu
*,
657 const char *namespace);
659 static int pdi_needs_namespace (enum dwarf_tag tag
, const char *namespace);
661 static char *add_partial_namespace (struct partial_die_info
*pdi
,
663 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
664 struct dwarf2_cu
*cu
,
665 const char *namespace);
667 static char *add_partial_structure (struct partial_die_info
*struct_pdi
,
669 struct dwarf2_cu
*cu
,
670 const char *namespace);
672 static char *add_partial_enumeration (struct partial_die_info
*enum_pdi
,
674 struct dwarf2_cu
*cu
,
675 const char *namespace);
677 static char *locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
680 struct dwarf2_cu
*cu
);
682 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
684 static void psymtab_to_symtab_1 (struct partial_symtab
*);
686 char *dwarf2_read_section (struct objfile
*, asection
*);
688 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
690 static void dwarf2_free_abbrev_table (void *);
692 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
695 static char *read_partial_die (struct partial_die_info
*,
696 bfd
*, char *, struct dwarf2_cu
*);
698 static char *read_full_die (struct die_info
**, bfd
*, char *,
699 struct dwarf2_cu
*, int *);
701 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
702 bfd
*, char *, struct dwarf2_cu
*);
704 static char *read_attribute_value (struct attribute
*, unsigned,
705 bfd
*, char *, struct dwarf2_cu
*);
707 static unsigned int read_1_byte (bfd
*, char *);
709 static int read_1_signed_byte (bfd
*, char *);
711 static unsigned int read_2_bytes (bfd
*, char *);
713 static unsigned int read_4_bytes (bfd
*, char *);
715 static unsigned long read_8_bytes (bfd
*, char *);
717 static CORE_ADDR
read_address (bfd
*, char *ptr
, struct dwarf2_cu
*,
720 static LONGEST
read_initial_length (bfd
*, char *,
721 struct comp_unit_head
*, int *bytes_read
);
723 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
726 static char *read_n_bytes (bfd
*, char *, unsigned int);
728 static char *read_string (bfd
*, char *, unsigned int *);
730 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
733 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
735 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
737 static char *skip_leb128 (bfd
*, char *);
739 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
741 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
744 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
746 static struct die_info
*die_specification (struct die_info
*die
,
749 static void free_line_header (struct line_header
*lh
);
751 static struct line_header
*(dwarf_decode_line_header
752 (unsigned int offset
,
753 bfd
*abfd
, struct dwarf2_cu
*cu
));
755 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
758 static void dwarf2_start_subfile (char *, char *);
760 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
763 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
766 static void dwarf2_const_value_data (struct attribute
*attr
,
770 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
772 static struct type
*die_containing_type (struct die_info
*,
776 static struct type
*type_at_offset (unsigned int, struct objfile
*);
779 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
781 static void read_type_die (struct die_info
*, struct dwarf2_cu
*);
783 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
785 static char *typename_concat (const char *prefix
, const char *suffix
);
787 static void read_typedef (struct die_info
*, struct dwarf2_cu
*);
789 static void read_base_type (struct die_info
*, struct dwarf2_cu
*);
791 static void read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
793 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
795 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
797 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
799 static int dwarf2_get_pc_bounds (struct die_info
*,
800 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
802 static void get_scope_pc_bounds (struct die_info
*,
803 CORE_ADDR
*, CORE_ADDR
*,
806 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
809 static void dwarf2_attach_fields_to_type (struct field_info
*,
810 struct type
*, struct dwarf2_cu
*);
812 static void dwarf2_add_member_fn (struct field_info
*,
813 struct die_info
*, struct type
*,
816 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
817 struct type
*, struct dwarf2_cu
*);
819 static void read_structure_type (struct die_info
*, struct dwarf2_cu
*);
821 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
823 static char *determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
825 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
827 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
829 static const char *namespace_name (struct die_info
*die
,
830 int *is_anonymous
, struct dwarf2_cu
*);
832 static void read_enumeration_type (struct die_info
*, struct dwarf2_cu
*);
834 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
836 static struct type
*dwarf_base_type (int, int, struct dwarf2_cu
*);
838 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
840 static void read_array_type (struct die_info
*, struct dwarf2_cu
*);
842 static void read_tag_pointer_type (struct die_info
*, struct dwarf2_cu
*);
844 static void read_tag_ptr_to_member_type (struct die_info
*,
847 static void read_tag_reference_type (struct die_info
*, struct dwarf2_cu
*);
849 static void read_tag_const_type (struct die_info
*, struct dwarf2_cu
*);
851 static void read_tag_volatile_type (struct die_info
*, struct dwarf2_cu
*);
853 static void read_tag_string_type (struct die_info
*, struct dwarf2_cu
*);
855 static void read_subroutine_type (struct die_info
*, struct dwarf2_cu
*);
857 static struct die_info
*read_comp_unit (char *, bfd
*, struct dwarf2_cu
*);
859 static struct die_info
*read_die_and_children (char *info_ptr
, bfd
*abfd
,
862 struct die_info
*parent
);
864 static struct die_info
*read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
867 struct die_info
*parent
);
869 static void free_die_list (struct die_info
*);
871 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
873 static void process_die (struct die_info
*, struct dwarf2_cu
*);
875 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
877 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
879 static struct die_info
*dwarf2_extension (struct die_info
*die
,
882 static char *dwarf_tag_name (unsigned int);
884 static char *dwarf_attr_name (unsigned int);
886 static char *dwarf_form_name (unsigned int);
888 static char *dwarf_stack_op_name (unsigned int);
890 static char *dwarf_bool_name (unsigned int);
892 static char *dwarf_type_encoding_name (unsigned int);
895 static char *dwarf_cfi_name (unsigned int);
897 struct die_info
*copy_die (struct die_info
*);
900 static struct die_info
*sibling_die (struct die_info
*);
902 static void dump_die (struct die_info
*);
904 static void dump_die_list (struct die_info
*);
906 static void store_in_ref_table (unsigned int, struct die_info
*);
908 static void dwarf2_empty_hash_tables (void);
910 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*,
913 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
915 static struct die_info
*follow_die_ref (unsigned int);
917 static struct type
*dwarf2_fundamental_type (struct objfile
*, int,
920 /* memory allocation interface */
922 static void dwarf2_free_tmp_obstack (void *);
924 static struct dwarf_block
*dwarf_alloc_block (void);
926 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
928 static struct die_info
*dwarf_alloc_die (void);
930 static void initialize_cu_func_list (struct dwarf2_cu
*);
932 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
935 static void dwarf_decode_macros (struct line_header
*, unsigned int,
936 char *, bfd
*, struct dwarf2_cu
*);
938 static int attr_form_is_block (struct attribute
*);
941 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
942 struct dwarf2_cu
*cu
);
944 static char *skip_one_die (char *info_ptr
, struct abbrev_info
*abbrev
,
945 struct dwarf2_cu
*cu
);
947 /* Try to locate the sections we need for DWARF 2 debugging
948 information and return true if we have enough to do something. */
951 dwarf2_has_info (bfd
*abfd
)
953 dwarf_info_section
= 0;
954 dwarf_abbrev_section
= 0;
955 dwarf_line_section
= 0;
956 dwarf_str_section
= 0;
957 dwarf_macinfo_section
= 0;
958 dwarf_frame_section
= 0;
959 dwarf_eh_frame_section
= 0;
960 dwarf_ranges_section
= 0;
961 dwarf_loc_section
= 0;
963 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
964 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
967 /* This function is mapped across the sections and remembers the
968 offset and size of each of the debugging sections we are interested
972 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, void *ignore_ptr
)
974 if (strcmp (sectp
->name
, INFO_SECTION
) == 0)
976 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
977 dwarf_info_section
= sectp
;
979 else if (strcmp (sectp
->name
, ABBREV_SECTION
) == 0)
981 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
982 dwarf_abbrev_section
= sectp
;
984 else if (strcmp (sectp
->name
, LINE_SECTION
) == 0)
986 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
987 dwarf_line_section
= sectp
;
989 else if (strcmp (sectp
->name
, PUBNAMES_SECTION
) == 0)
991 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
992 dwarf_pubnames_section
= sectp
;
994 else if (strcmp (sectp
->name
, ARANGES_SECTION
) == 0)
996 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
997 dwarf_aranges_section
= sectp
;
999 else if (strcmp (sectp
->name
, LOC_SECTION
) == 0)
1001 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
1002 dwarf_loc_section
= sectp
;
1004 else if (strcmp (sectp
->name
, MACINFO_SECTION
) == 0)
1006 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
1007 dwarf_macinfo_section
= sectp
;
1009 else if (strcmp (sectp
->name
, STR_SECTION
) == 0)
1011 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
1012 dwarf_str_section
= sectp
;
1014 else if (strcmp (sectp
->name
, FRAME_SECTION
) == 0)
1016 dwarf_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1017 dwarf_frame_section
= sectp
;
1019 else if (strcmp (sectp
->name
, EH_FRAME_SECTION
) == 0)
1021 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1022 if (aflag
& SEC_HAS_CONTENTS
)
1024 dwarf_eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1025 dwarf_eh_frame_section
= sectp
;
1028 else if (strcmp (sectp
->name
, RANGES_SECTION
) == 0)
1030 dwarf_ranges_size
= bfd_get_section_size_before_reloc (sectp
);
1031 dwarf_ranges_section
= sectp
;
1035 /* Build a partial symbol table. */
1038 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1041 /* We definitely need the .debug_info and .debug_abbrev sections */
1043 dwarf_info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1044 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1046 if (dwarf_line_section
)
1047 dwarf_line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1049 dwarf_line_buffer
= NULL
;
1051 if (dwarf_str_section
)
1052 dwarf_str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1054 dwarf_str_buffer
= NULL
;
1056 if (dwarf_macinfo_section
)
1057 dwarf_macinfo_buffer
= dwarf2_read_section (objfile
,
1058 dwarf_macinfo_section
);
1060 dwarf_macinfo_buffer
= NULL
;
1062 if (dwarf_ranges_section
)
1063 dwarf_ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1065 dwarf_ranges_buffer
= NULL
;
1067 if (dwarf_loc_section
)
1068 dwarf_loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1070 dwarf_loc_buffer
= NULL
;
1073 || (objfile
->global_psymbols
.size
== 0
1074 && objfile
->static_psymbols
.size
== 0))
1076 init_psymbol_list (objfile
, 1024);
1080 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1082 /* Things are significantly easier if we have .debug_aranges and
1083 .debug_pubnames sections */
1085 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1089 /* only test this case for now */
1091 /* In this case we have to work a bit harder */
1092 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1097 /* Build the partial symbol table from the information in the
1098 .debug_pubnames and .debug_aranges sections. */
1101 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1103 bfd
*abfd
= objfile
->obfd
;
1104 char *aranges_buffer
, *pubnames_buffer
;
1105 char *aranges_ptr
, *pubnames_ptr
;
1106 unsigned int entry_length
, version
, info_offset
, info_size
;
1108 pubnames_buffer
= dwarf2_read_section (objfile
,
1109 dwarf_pubnames_section
);
1110 pubnames_ptr
= pubnames_buffer
;
1111 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
1113 struct comp_unit_head cu_header
;
1116 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1118 pubnames_ptr
+= bytes_read
;
1119 version
= read_1_byte (abfd
, pubnames_ptr
);
1121 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1123 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1127 aranges_buffer
= dwarf2_read_section (objfile
,
1128 dwarf_aranges_section
);
1133 /* Read in the comp unit header information from the debug_info at
1137 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1138 char *info_ptr
, bfd
*abfd
)
1142 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1144 info_ptr
+= bytes_read
;
1145 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1147 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1149 info_ptr
+= bytes_read
;
1150 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1152 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1153 if (signed_addr
< 0)
1154 internal_error (__FILE__
, __LINE__
,
1155 "read_comp_unit_head: dwarf from non elf file");
1156 cu_header
->signed_addr_p
= signed_addr
;
1160 /* Build the partial symbol table by doing a quick pass through the
1161 .debug_info and .debug_abbrev sections. */
1164 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1166 /* Instead of reading this into a big buffer, we should probably use
1167 mmap() on architectures that support it. (FIXME) */
1168 bfd
*abfd
= objfile
->obfd
;
1169 char *info_ptr
, *abbrev_ptr
;
1170 char *beg_of_comp_unit
;
1171 struct partial_die_info comp_unit_die
;
1172 struct partial_symtab
*pst
;
1173 struct cleanup
*back_to
;
1174 CORE_ADDR lowpc
, highpc
, baseaddr
;
1176 info_ptr
= dwarf_info_buffer
;
1177 abbrev_ptr
= dwarf_abbrev_buffer
;
1179 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1180 the partial symbol scan, like attribute values.
1182 We could reduce our peak memory consumption during partial symbol
1183 table construction by freeing stuff from this obstack more often
1184 --- say, after processing each compilation unit, or each die ---
1185 but it turns out that this saves almost nothing. For an
1186 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1187 on dwarf2_tmp_obstack. Some investigation showed:
1189 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1190 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1191 all fixed-length values not requiring dynamic allocation.
1193 2) 30% of the attributes used the form DW_FORM_string. For
1194 DW_FORM_string, read_attribute simply hands back a pointer to
1195 the null-terminated string in dwarf_info_buffer, so no dynamic
1196 allocation is needed there either.
1198 3) The remaining 1% of the attributes all used DW_FORM_block1.
1199 75% of those were DW_AT_frame_base location lists for
1200 functions; the rest were DW_AT_location attributes, probably
1201 for the global variables.
1203 Anyway, what this all means is that the memory the dwarf2
1204 reader uses as temporary space reading partial symbols is about
1205 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1207 obstack_init (&dwarf2_tmp_obstack
);
1208 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1210 /* Since the objects we're extracting from dwarf_info_buffer vary in
1211 length, only the individual functions to extract them (like
1212 read_comp_unit_head and read_partial_die) can really know whether
1213 the buffer is large enough to hold another complete object.
1215 At the moment, they don't actually check that. If
1216 dwarf_info_buffer holds just one extra byte after the last
1217 compilation unit's dies, then read_comp_unit_head will happily
1218 read off the end of the buffer. read_partial_die is similarly
1219 casual. Those functions should be fixed.
1221 For this loop condition, simply checking whether there's any data
1222 left at all should be sufficient. */
1223 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1225 struct cleanup
*back_to_inner
;
1226 struct dwarf2_cu cu
;
1227 beg_of_comp_unit
= info_ptr
;
1229 cu
.objfile
= objfile
;
1230 info_ptr
= read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1232 if (cu
.header
.version
!= 2)
1234 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
));
1237 if (cu
.header
.abbrev_offset
>= dwarf_abbrev_size
)
1239 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6) [in module %s]",
1240 (long) cu
.header
.abbrev_offset
,
1241 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1242 bfd_get_filename (abfd
));
1245 if (beg_of_comp_unit
+ cu
.header
.length
+ cu
.header
.initial_length_size
1246 > dwarf_info_buffer
+ dwarf_info_size
)
1248 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0) [in module %s]",
1249 (long) cu
.header
.length
,
1250 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1251 bfd_get_filename (abfd
));
1254 /* Complete the cu_header */
1255 cu
.header
.offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1256 cu
.header
.first_die_ptr
= info_ptr
;
1257 cu
.header
.cu_head_ptr
= beg_of_comp_unit
;
1259 cu
.list_in_scope
= &file_symbols
;
1261 /* Read the abbrevs for this compilation unit into a table */
1262 dwarf2_read_abbrevs (abfd
, &cu
);
1263 back_to_inner
= make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1265 /* Read the compilation unit die */
1266 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1269 /* Set the language we're debugging */
1270 set_cu_language (comp_unit_die
.language
, &cu
);
1272 /* Allocate a new partial symbol table structure */
1273 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1274 comp_unit_die
.name
? comp_unit_die
.name
: "",
1275 comp_unit_die
.lowpc
,
1276 objfile
->global_psymbols
.next
,
1277 objfile
->static_psymbols
.next
);
1279 pst
->read_symtab_private
= (char *)
1280 obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct dwarf2_pinfo
));
1281 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1282 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1283 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1284 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1285 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1286 DWARF_LINE_SIZE (pst
) = dwarf_line_size
;
1287 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1288 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1289 DWARF_MACINFO_BUFFER (pst
) = dwarf_macinfo_buffer
;
1290 DWARF_MACINFO_SIZE (pst
) = dwarf_macinfo_size
;
1291 DWARF_RANGES_BUFFER (pst
) = dwarf_ranges_buffer
;
1292 DWARF_RANGES_SIZE (pst
) = dwarf_ranges_size
;
1293 DWARF_LOC_BUFFER (pst
) = dwarf_loc_buffer
;
1294 DWARF_LOC_SIZE (pst
) = dwarf_loc_size
;
1295 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1297 /* Store the function that reads in the rest of the symbol table */
1298 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1300 /* Check if comp unit has_children.
1301 If so, read the rest of the partial symbols from this comp unit.
1302 If not, there's no more debug_info for this comp unit. */
1303 if (comp_unit_die
.has_children
)
1305 lowpc
= ((CORE_ADDR
) -1);
1306 highpc
= ((CORE_ADDR
) 0);
1308 info_ptr
= scan_partial_symbols (info_ptr
, &lowpc
, &highpc
,
1311 /* If we didn't find a lowpc, set it to highpc to avoid
1312 complaints from `maint check'. */
1313 if (lowpc
== ((CORE_ADDR
) -1))
1316 /* If the compilation unit didn't have an explicit address range,
1317 then use the information extracted from its child dies. */
1318 if (! comp_unit_die
.has_pc_info
)
1320 comp_unit_die
.lowpc
= lowpc
;
1321 comp_unit_die
.highpc
= highpc
;
1324 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1325 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1327 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1328 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1329 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1330 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1331 sort_pst_symbols (pst
);
1333 /* If there is already a psymtab or symtab for a file of this
1334 name, remove it. (If there is a symtab, more drastic things
1335 also happen.) This happens in VxWorks. */
1336 free_named_symtabs (pst
->filename
);
1338 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1339 + cu
.header
.initial_length_size
;
1341 do_cleanups (back_to_inner
);
1343 do_cleanups (back_to
);
1346 /* Read in all interesting dies to the end of the compilation unit or
1347 to the end of the current namespace. NAMESPACE is NULL if we
1348 haven't yet encountered any DW_TAG_namespace entries; otherwise,
1349 it's the name of the current namespace. In particular, it's the
1350 empty string if we're currently in the global namespace but have
1351 previously encountered a DW_TAG_namespace. */
1354 scan_partial_symbols (char *info_ptr
, CORE_ADDR
*lowpc
,
1355 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
1356 const char *namespace)
1358 struct objfile
*objfile
= cu
->objfile
;
1359 bfd
*abfd
= objfile
->obfd
;
1360 struct partial_die_info pdi
;
1362 /* Now, march along the PDI's, descending into ones which have
1363 interesting children but skipping the children of the other ones,
1364 until we reach the end of the compilation unit. */
1368 /* This flag tells whether or not info_ptr has gotten updated
1370 int info_ptr_updated
= 0;
1372 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu
);
1374 /* Anonymous namespaces have no name but have interesting
1375 children, so we need to look at them. Ditto for anonymous
1378 if (pdi
.name
!= NULL
|| pdi
.tag
== DW_TAG_namespace
1379 || pdi
.tag
== DW_TAG_enumeration_type
)
1383 case DW_TAG_subprogram
:
1384 if (pdi
.has_pc_info
)
1386 if (pdi
.lowpc
< *lowpc
)
1390 if (pdi
.highpc
> *highpc
)
1392 *highpc
= pdi
.highpc
;
1394 if (!pdi
.is_declaration
)
1396 add_partial_symbol (&pdi
, cu
, namespace);
1400 case DW_TAG_variable
:
1401 case DW_TAG_typedef
:
1402 case DW_TAG_union_type
:
1403 if (!pdi
.is_declaration
)
1405 add_partial_symbol (&pdi
, cu
, namespace);
1408 case DW_TAG_class_type
:
1409 case DW_TAG_structure_type
:
1410 if (!pdi
.is_declaration
)
1412 info_ptr
= add_partial_structure (&pdi
, info_ptr
, cu
,
1414 info_ptr_updated
= 1;
1417 case DW_TAG_enumeration_type
:
1418 if (!pdi
.is_declaration
)
1420 info_ptr
= add_partial_enumeration (&pdi
, info_ptr
, cu
,
1422 info_ptr_updated
= 1;
1425 case DW_TAG_base_type
:
1426 case DW_TAG_subrange_type
:
1427 /* File scope base type definitions are added to the partial
1429 add_partial_symbol (&pdi
, cu
, namespace);
1431 case DW_TAG_namespace
:
1432 /* We've hit a DW_TAG_namespace entry, so we know this
1433 file has been compiled using a compiler that
1434 generates them; update NAMESPACE to reflect that. */
1435 if (namespace == NULL
)
1437 info_ptr
= add_partial_namespace (&pdi
, info_ptr
, lowpc
, highpc
,
1439 info_ptr_updated
= 1;
1449 /* If the die has a sibling, skip to the sibling, unless another
1450 function has already updated info_ptr for us. */
1452 /* NOTE: carlton/2003-06-16: This is a bit hackish, but whether
1453 or not we want to update this depends on enough stuff (not
1454 only pdi.tag but also whether or not pdi.name is NULL) that
1455 this seems like the easiest way to handle the issue. */
1457 if (!info_ptr_updated
)
1458 info_ptr
= locate_pdi_sibling (&pdi
, info_ptr
, abfd
, cu
);
1465 add_partial_symbol (struct partial_die_info
*pdi
,
1466 struct dwarf2_cu
*cu
, const char *namespace)
1468 struct objfile
*objfile
= cu
->objfile
;
1470 char *actual_name
= pdi
->name
;
1471 const struct partial_symbol
*psym
= NULL
;
1474 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1476 /* If we're not in the global namespace and if the namespace name
1477 isn't encoded in a mangled actual_name, add it. */
1479 if (pdi_needs_namespace (pdi
->tag
, namespace))
1481 actual_name
= alloca (strlen (pdi
->name
) + 2 + strlen (namespace) + 1);
1482 strcpy (actual_name
, namespace);
1483 strcat (actual_name
, "::");
1484 strcat (actual_name
, pdi
->name
);
1489 case DW_TAG_subprogram
:
1490 if (pdi
->is_external
)
1492 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1493 mst_text, objfile); */
1494 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1495 VAR_DOMAIN
, LOC_BLOCK
,
1496 &objfile
->global_psymbols
,
1497 0, pdi
->lowpc
+ baseaddr
,
1498 cu
->language
, objfile
);
1502 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1503 mst_file_text, objfile); */
1504 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1505 VAR_DOMAIN
, LOC_BLOCK
,
1506 &objfile
->static_psymbols
,
1507 0, pdi
->lowpc
+ baseaddr
,
1508 cu
->language
, objfile
);
1511 case DW_TAG_variable
:
1512 if (pdi
->is_external
)
1515 Don't enter into the minimal symbol tables as there is
1516 a minimal symbol table entry from the ELF symbols already.
1517 Enter into partial symbol table if it has a location
1518 descriptor or a type.
1519 If the location descriptor is missing, new_symbol will create
1520 a LOC_UNRESOLVED symbol, the address of the variable will then
1521 be determined from the minimal symbol table whenever the variable
1523 The address for the partial symbol table entry is not
1524 used by GDB, but it comes in handy for debugging partial symbol
1528 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1529 if (pdi
->locdesc
|| pdi
->has_type
)
1530 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1531 VAR_DOMAIN
, LOC_STATIC
,
1532 &objfile
->global_psymbols
,
1534 cu
->language
, objfile
);
1538 /* Static Variable. Skip symbols without location descriptors. */
1539 if (pdi
->locdesc
== NULL
)
1541 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1542 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
1543 mst_file_data, objfile); */
1544 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1545 VAR_DOMAIN
, LOC_STATIC
,
1546 &objfile
->static_psymbols
,
1548 cu
->language
, objfile
);
1551 case DW_TAG_typedef
:
1552 case DW_TAG_base_type
:
1553 case DW_TAG_subrange_type
:
1554 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1555 VAR_DOMAIN
, LOC_TYPEDEF
,
1556 &objfile
->static_psymbols
,
1557 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1559 case DW_TAG_class_type
:
1560 case DW_TAG_structure_type
:
1561 case DW_TAG_union_type
:
1562 case DW_TAG_enumeration_type
:
1563 /* Skip aggregate types without children, these are external
1565 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
1566 static vs. global. */
1567 if (pdi
->has_children
== 0)
1569 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1570 STRUCT_DOMAIN
, LOC_TYPEDEF
,
1571 cu
->language
== language_cplus
1572 ? &objfile
->global_psymbols
1573 : &objfile
->static_psymbols
,
1574 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1576 if (cu
->language
== language_cplus
)
1578 /* For C++, these implicitly act as typedefs as well. */
1579 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1580 VAR_DOMAIN
, LOC_TYPEDEF
,
1581 &objfile
->global_psymbols
,
1582 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1585 case DW_TAG_enumerator
:
1586 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1587 VAR_DOMAIN
, LOC_CONST
,
1588 cu
->language
== language_cplus
1589 ? &objfile
->global_psymbols
1590 : &objfile
->static_psymbols
,
1591 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1597 /* Check to see if we should scan the name for possible namespace
1598 info. Only do this if this is C++, if we don't have namespace
1599 debugging info in the file, if the psym is of an appropriate type
1600 (otherwise we'll have psym == NULL), and if we actually had a
1601 mangled name to begin with. */
1603 if (cu
->language
== language_cplus
1604 && namespace == NULL
1606 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
1607 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
1611 /* Determine whether a die of type TAG living in the C++ namespace
1612 NAMESPACE needs to have the name of the namespace prepended to the
1613 name listed in the die. */
1616 pdi_needs_namespace (enum dwarf_tag tag
, const char *namespace)
1618 if (namespace == NULL
|| namespace[0] == '\0')
1623 case DW_TAG_typedef
:
1624 case DW_TAG_class_type
:
1625 case DW_TAG_structure_type
:
1626 case DW_TAG_union_type
:
1627 case DW_TAG_enumeration_type
:
1628 case DW_TAG_enumerator
:
1635 /* Read a partial die corresponding to a namespace; also, add a symbol
1636 corresponding to that namespace to the symbol table. NAMESPACE is
1637 the name of the enclosing namespace. */
1640 add_partial_namespace (struct partial_die_info
*pdi
, char *info_ptr
,
1641 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1642 struct dwarf2_cu
*cu
, const char *namespace)
1644 struct objfile
*objfile
= cu
->objfile
;
1645 const char *new_name
= pdi
->name
;
1648 /* Calculate the full name of the namespace that we just entered. */
1650 if (new_name
== NULL
)
1651 new_name
= "(anonymous namespace)";
1652 full_name
= alloca (strlen (namespace) + 2 + strlen (new_name
) + 1);
1653 strcpy (full_name
, namespace);
1654 if (*namespace != '\0')
1655 strcat (full_name
, "::");
1656 strcat (full_name
, new_name
);
1658 /* FIXME: carlton/2003-10-07: We can't just replace this by a call
1659 to add_partial_symbol, because we don't have a way to pass in the
1660 full name to that function; that might be a flaw in
1661 add_partial_symbol's interface. */
1663 add_psymbol_to_list (full_name
, strlen (full_name
),
1664 VAR_DOMAIN
, LOC_TYPEDEF
,
1665 &objfile
->global_psymbols
,
1666 0, 0, cu
->language
, objfile
);
1668 /* Now scan partial symbols in that namespace. */
1670 if (pdi
->has_children
)
1671 info_ptr
= scan_partial_symbols (info_ptr
, lowpc
, highpc
, cu
, full_name
);
1676 /* Read a partial die corresponding to a class or structure. */
1679 add_partial_structure (struct partial_die_info
*struct_pdi
, char *info_ptr
,
1680 struct dwarf2_cu
*cu
,
1681 const char *namespace)
1683 bfd
*abfd
= cu
->objfile
->obfd
;
1684 char *actual_class_name
= NULL
;
1686 if (cu
->language
== language_cplus
1687 && (namespace == NULL
|| namespace[0] == '\0')
1688 && struct_pdi
->name
!= NULL
1689 && struct_pdi
->has_children
)
1691 /* See if we can figure out if the class lives in a namespace
1692 (or is nested within another class.) We do this by looking
1693 for a member function; its demangled name will contain
1694 namespace info, if there is any. */
1696 /* NOTE: carlton/2003-10-07: Getting the info this way changes
1697 what template types look like, because the demangler
1698 frequently doesn't give the same name as the debug info. We
1699 could fix this by only using the demangled name to get the
1700 prefix (but see comment in read_structure_type). */
1702 /* FIXME: carlton/2004-01-23: If NAMESPACE equals "", we have
1703 the appropriate debug information, so it would be nice to be
1704 able to avoid this hack. But NAMESPACE may not be the
1705 namespace where this class was defined: NAMESPACE reflects
1706 where STRUCT_PDI occurs in the tree of dies, but because of
1707 DW_AT_specification, that may not actually tell us where the
1708 class is defined. (See the comment in read_func_scope for an
1709 example of how this could occur.)
1711 Unfortunately, our current partial symtab data structures are
1712 completely unable to deal with DW_AT_specification. So, for
1713 now, the best thing to do is to get nesting information from
1714 places other than the tree structure of dies if there's any
1715 chance that a DW_AT_specification is involved. :-( */
1717 char *next_child
= info_ptr
;
1721 struct partial_die_info child_pdi
;
1723 next_child
= read_partial_die (&child_pdi
, abfd
, next_child
,
1727 if (child_pdi
.tag
== DW_TAG_subprogram
)
1729 actual_class_name
= class_name_from_physname (child_pdi
.name
);
1730 if (actual_class_name
!= NULL
)
1731 struct_pdi
->name
= actual_class_name
;
1736 next_child
= locate_pdi_sibling (&child_pdi
, next_child
,
1742 add_partial_symbol (struct_pdi
, cu
, namespace);
1743 xfree (actual_class_name
);
1745 return locate_pdi_sibling (struct_pdi
, info_ptr
, abfd
, cu
);
1748 /* Read a partial die corresponding to an enumeration type. */
1751 add_partial_enumeration (struct partial_die_info
*enum_pdi
, char *info_ptr
,
1752 struct dwarf2_cu
*cu
, const char *namespace)
1754 struct objfile
*objfile
= cu
->objfile
;
1755 bfd
*abfd
= objfile
->obfd
;
1756 struct partial_die_info pdi
;
1758 if (enum_pdi
->name
!= NULL
)
1759 add_partial_symbol (enum_pdi
, cu
, namespace);
1763 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu
);
1766 if (pdi
.tag
!= DW_TAG_enumerator
|| pdi
.name
== NULL
)
1767 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
1769 add_partial_symbol (&pdi
, cu
, namespace);
1775 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
1776 Return the corresponding abbrev, or NULL if the number is zero (indicating
1777 an empty DIE). In either case *BYTES_READ will be set to the length of
1778 the initial number. */
1780 static struct abbrev_info
*
1781 peek_die_abbrev (char *info_ptr
, int *bytes_read
, struct dwarf2_cu
*cu
)
1783 bfd
*abfd
= cu
->objfile
->obfd
;
1784 unsigned int abbrev_number
;
1785 struct abbrev_info
*abbrev
;
1787 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
1789 if (abbrev_number
== 0)
1792 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
1795 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number
,
1796 bfd_get_filename (abfd
));
1802 /* Scan the debug information for CU starting at INFO_PTR. Returns a
1803 pointer to the end of a series of DIEs, terminated by an empty
1804 DIE. Any children of the skipped DIEs will also be skipped. */
1807 skip_children (char *info_ptr
, struct dwarf2_cu
*cu
)
1809 struct abbrev_info
*abbrev
;
1810 unsigned int bytes_read
;
1814 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1816 return info_ptr
+ bytes_read
;
1818 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
1822 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
1823 should point just after the initial uleb128 of a DIE, and the
1824 abbrev corresponding to that skipped uleb128 should be passed in
1825 ABBREV. Returns a pointer to this DIE's sibling, skipping any
1829 skip_one_die (char *info_ptr
, struct abbrev_info
*abbrev
,
1830 struct dwarf2_cu
*cu
)
1832 unsigned int bytes_read
;
1833 struct attribute attr
;
1834 bfd
*abfd
= cu
->objfile
->obfd
;
1835 unsigned int form
, i
;
1837 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
1839 /* The only abbrev we care about is DW_AT_sibling. */
1840 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
1842 read_attribute (&attr
, &abbrev
->attrs
[i
],
1843 abfd
, info_ptr
, cu
);
1844 if (attr
.form
== DW_FORM_ref_addr
)
1845 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
1847 return dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
, cu
);
1850 /* If it isn't DW_AT_sibling, skip this attribute. */
1851 form
= abbrev
->attrs
[i
].form
;
1856 case DW_FORM_ref_addr
:
1857 info_ptr
+= cu
->header
.addr_size
;
1876 case DW_FORM_string
:
1877 read_string (abfd
, info_ptr
, &bytes_read
);
1878 info_ptr
+= bytes_read
;
1881 info_ptr
+= cu
->header
.offset_size
;
1884 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
1885 info_ptr
+= bytes_read
;
1887 case DW_FORM_block1
:
1888 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
1890 case DW_FORM_block2
:
1891 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
1893 case DW_FORM_block4
:
1894 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
1898 case DW_FORM_ref_udata
:
1899 info_ptr
= skip_leb128 (abfd
, info_ptr
);
1901 case DW_FORM_indirect
:
1902 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
1903 info_ptr
+= bytes_read
;
1904 /* We need to continue parsing from here, so just go back to
1906 goto skip_attribute
;
1909 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
1910 dwarf_form_name (form
),
1911 bfd_get_filename (abfd
));
1915 if (abbrev
->has_children
)
1916 return skip_children (info_ptr
, cu
);
1921 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
1922 the next DIE after ORIG_PDI. */
1925 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, char *info_ptr
,
1926 bfd
*abfd
, struct dwarf2_cu
*cu
)
1928 /* Do we know the sibling already? */
1930 if (orig_pdi
->sibling
)
1931 return orig_pdi
->sibling
;
1933 /* Are there any children to deal with? */
1935 if (!orig_pdi
->has_children
)
1938 /* Skip the children the long way. */
1940 return skip_children (info_ptr
, cu
);
1943 /* Expand this partial symbol table into a full symbol table. */
1946 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1948 /* FIXME: This is barely more than a stub. */
1953 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1959 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1960 gdb_flush (gdb_stdout
);
1963 psymtab_to_symtab_1 (pst
);
1965 /* Finish up the debug error message. */
1967 printf_filtered ("done.\n");
1973 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1975 struct objfile
*objfile
= pst
->objfile
;
1976 bfd
*abfd
= objfile
->obfd
;
1977 struct dwarf2_cu cu
;
1978 struct die_info
*dies
;
1979 unsigned long offset
;
1980 CORE_ADDR lowpc
, highpc
;
1981 struct die_info
*child_die
;
1983 struct symtab
*symtab
;
1984 struct cleanup
*back_to
;
1985 struct attribute
*attr
;
1988 /* Set local variables from the partial symbol table info. */
1989 offset
= DWARF_INFO_OFFSET (pst
);
1990 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1991 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1992 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1993 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1994 dwarf_line_size
= DWARF_LINE_SIZE (pst
);
1995 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1996 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1997 dwarf_macinfo_buffer
= DWARF_MACINFO_BUFFER (pst
);
1998 dwarf_macinfo_size
= DWARF_MACINFO_SIZE (pst
);
1999 dwarf_ranges_buffer
= DWARF_RANGES_BUFFER (pst
);
2000 dwarf_ranges_size
= DWARF_RANGES_SIZE (pst
);
2001 dwarf_loc_buffer
= DWARF_LOC_BUFFER (pst
);
2002 dwarf_loc_size
= DWARF_LOC_SIZE (pst
);
2003 info_ptr
= dwarf_info_buffer
+ offset
;
2004 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2006 /* We're in the global namespace. */
2007 processing_current_prefix
= "";
2009 obstack_init (&dwarf2_tmp_obstack
);
2010 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
2013 make_cleanup (really_free_pendings
, NULL
);
2015 cu
.objfile
= objfile
;
2017 /* read in the comp_unit header */
2018 info_ptr
= read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
2020 /* Read the abbrevs for this compilation unit */
2021 dwarf2_read_abbrevs (abfd
, &cu
);
2022 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2024 cu
.header
.offset
= offset
;
2026 cu
.list_in_scope
= &file_symbols
;
2028 dies
= read_comp_unit (info_ptr
, abfd
, &cu
);
2030 make_cleanup_free_die_list (dies
);
2032 /* Find the base address of the compilation unit for range lists and
2033 location lists. It will normally be specified by DW_AT_low_pc.
2034 In DWARF-3 draft 4, the base address could be overridden by
2035 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2036 compilation units with discontinuous ranges. */
2038 cu
.header
.base_known
= 0;
2039 cu
.header
.base_address
= 0;
2041 attr
= dwarf2_attr (dies
, DW_AT_entry_pc
, &cu
);
2044 cu
.header
.base_address
= DW_ADDR (attr
);
2045 cu
.header
.base_known
= 1;
2049 attr
= dwarf2_attr (dies
, DW_AT_low_pc
, &cu
);
2052 cu
.header
.base_address
= DW_ADDR (attr
);
2053 cu
.header
.base_known
= 1;
2057 /* Do line number decoding in read_file_scope () */
2058 process_die (dies
, &cu
);
2060 /* Some compilers don't define a DW_AT_high_pc attribute for the
2061 compilation unit. If the DW_AT_high_pc is missing, synthesize
2062 it, by scanning the DIE's below the compilation unit. */
2063 get_scope_pc_bounds (dies
, &lowpc
, &highpc
, &cu
);
2065 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2067 /* Set symtab language to language from DW_AT_language.
2068 If the compilation is from a C file generated by language preprocessors,
2069 do not set the language if it was already deduced by start_subfile. */
2071 && !(cu
.language
== language_c
&& symtab
->language
!= language_c
))
2073 symtab
->language
= cu
.language
;
2075 pst
->symtab
= symtab
;
2078 do_cleanups (back_to
);
2081 /* Process a die and its children. */
2084 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2088 case DW_TAG_padding
:
2090 case DW_TAG_compile_unit
:
2091 read_file_scope (die
, cu
);
2093 case DW_TAG_subprogram
:
2094 read_subroutine_type (die
, cu
);
2095 read_func_scope (die
, cu
);
2097 case DW_TAG_inlined_subroutine
:
2098 /* FIXME: These are ignored for now.
2099 They could be used to set breakpoints on all inlined instances
2100 of a function and make GDB `next' properly over inlined functions. */
2102 case DW_TAG_lexical_block
:
2103 case DW_TAG_try_block
:
2104 case DW_TAG_catch_block
:
2105 read_lexical_block_scope (die
, cu
);
2107 case DW_TAG_class_type
:
2108 case DW_TAG_structure_type
:
2109 case DW_TAG_union_type
:
2110 read_structure_type (die
, cu
);
2111 process_structure_scope (die
, cu
);
2113 case DW_TAG_enumeration_type
:
2114 read_enumeration_type (die
, cu
);
2115 process_enumeration_scope (die
, cu
);
2118 /* FIXME drow/2004-03-14: These initialize die->type, but do not create
2119 a symbol or process any children. Therefore it doesn't do anything
2120 that won't be done on-demand by read_type_die. */
2121 case DW_TAG_subroutine_type
:
2122 read_subroutine_type (die
, cu
);
2124 case DW_TAG_array_type
:
2125 read_array_type (die
, cu
);
2127 case DW_TAG_pointer_type
:
2128 read_tag_pointer_type (die
, cu
);
2130 case DW_TAG_ptr_to_member_type
:
2131 read_tag_ptr_to_member_type (die
, cu
);
2133 case DW_TAG_reference_type
:
2134 read_tag_reference_type (die
, cu
);
2136 case DW_TAG_string_type
:
2137 read_tag_string_type (die
, cu
);
2141 case DW_TAG_base_type
:
2142 read_base_type (die
, cu
);
2143 /* Add a typedef symbol for the type definition, if it has a
2145 new_symbol (die
, die
->type
, cu
);
2147 case DW_TAG_subrange_type
:
2148 read_subrange_type (die
, cu
);
2149 /* Add a typedef symbol for the type definition, if it has a
2151 new_symbol (die
, die
->type
, cu
);
2153 case DW_TAG_common_block
:
2154 read_common_block (die
, cu
);
2156 case DW_TAG_common_inclusion
:
2158 case DW_TAG_namespace
:
2159 processing_has_namespace_info
= 1;
2160 read_namespace (die
, cu
);
2162 case DW_TAG_imported_declaration
:
2163 case DW_TAG_imported_module
:
2164 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2165 information contained in these. DW_TAG_imported_declaration
2166 dies shouldn't have children; DW_TAG_imported_module dies
2167 shouldn't in the C++ case, but conceivably could in the
2168 Fortran case, so we'll have to replace this gdb_assert if
2169 Fortran compilers start generating that info. */
2170 processing_has_namespace_info
= 1;
2171 gdb_assert (die
->child
== NULL
);
2174 new_symbol (die
, NULL
, cu
);
2180 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2182 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2186 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2188 struct objfile
*objfile
= cu
->objfile
;
2189 struct comp_unit_head
*cu_header
= &cu
->header
;
2190 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2191 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2192 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2193 struct attribute
*attr
;
2194 char *name
= "<unknown>";
2195 char *comp_dir
= NULL
;
2196 struct die_info
*child_die
;
2197 bfd
*abfd
= objfile
->obfd
;
2198 struct line_header
*line_header
= 0;
2201 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2203 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2205 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2206 from finish_block. */
2207 if (lowpc
== ((CORE_ADDR
) -1))
2212 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2215 name
= DW_STRING (attr
);
2217 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2220 comp_dir
= DW_STRING (attr
);
2223 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2224 directory, get rid of it. */
2225 char *cp
= strchr (comp_dir
, ':');
2227 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2232 if (objfile
->ei
.entry_point
>= lowpc
&&
2233 objfile
->ei
.entry_point
< highpc
)
2235 objfile
->ei
.deprecated_entry_file_lowpc
= lowpc
;
2236 objfile
->ei
.deprecated_entry_file_highpc
= highpc
;
2239 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2242 set_cu_language (DW_UNSND (attr
), cu
);
2245 /* We assume that we're processing GCC output. */
2246 processing_gcc_compilation
= 2;
2248 /* FIXME:Do something here. */
2249 if (dip
->at_producer
!= NULL
)
2251 handle_producer (dip
->at_producer
);
2255 /* The compilation unit may be in a different language or objfile,
2256 zero out all remembered fundamental types. */
2257 memset (cu
->ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
2259 start_symtab (name
, comp_dir
, lowpc
);
2260 record_debugformat ("DWARF 2");
2262 initialize_cu_func_list (cu
);
2264 /* Process all dies in compilation unit. */
2265 if (die
->child
!= NULL
)
2267 child_die
= die
->child
;
2268 while (child_die
&& child_die
->tag
)
2270 process_die (child_die
, cu
);
2271 child_die
= sibling_die (child_die
);
2275 /* Decode line number information if present. */
2276 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2279 unsigned int line_offset
= DW_UNSND (attr
);
2280 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2283 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
2284 (void *) line_header
);
2285 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
);
2289 /* Decode macro information, if present. Dwarf 2 macro information
2290 refers to information in the line number info statement program
2291 header, so we can only read it if we've read the header
2293 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2294 if (attr
&& line_header
)
2296 unsigned int macro_offset
= DW_UNSND (attr
);
2297 dwarf_decode_macros (line_header
, macro_offset
,
2298 comp_dir
, abfd
, cu
);
2300 do_cleanups (back_to
);
2304 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2305 struct dwarf2_cu
*cu
)
2307 struct function_range
*thisfn
;
2309 thisfn
= (struct function_range
*)
2310 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct function_range
));
2311 thisfn
->name
= name
;
2312 thisfn
->lowpc
= lowpc
;
2313 thisfn
->highpc
= highpc
;
2314 thisfn
->seen_line
= 0;
2315 thisfn
->next
= NULL
;
2317 if (cu
->last_fn
== NULL
)
2318 cu
->first_fn
= thisfn
;
2320 cu
->last_fn
->next
= thisfn
;
2322 cu
->last_fn
= thisfn
;
2326 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2328 struct objfile
*objfile
= cu
->objfile
;
2329 struct context_stack
*new;
2332 struct die_info
*child_die
;
2333 struct attribute
*attr
;
2335 const char *previous_prefix
= processing_current_prefix
;
2336 struct cleanup
*back_to
= NULL
;
2339 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2341 name
= dwarf2_linkage_name (die
, cu
);
2343 /* Ignore functions with missing or empty names and functions with
2344 missing or invalid low and high pc attributes. */
2345 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2348 if (cu
->language
== language_cplus
)
2350 struct die_info
*spec_die
= die_specification (die
, cu
);
2352 /* NOTE: carlton/2004-01-23: We have to be careful in the
2353 presence of DW_AT_specification. For example, with GCC 3.4,
2358 // Definition of N::foo.
2362 then we'll have a tree of DIEs like this:
2364 1: DW_TAG_compile_unit
2365 2: DW_TAG_namespace // N
2366 3: DW_TAG_subprogram // declaration of N::foo
2367 4: DW_TAG_subprogram // definition of N::foo
2368 DW_AT_specification // refers to die #3
2370 Thus, when processing die #4, we have to pretend that we're
2371 in the context of its DW_AT_specification, namely the contex
2374 if (spec_die
!= NULL
)
2376 char *specification_prefix
= determine_prefix (spec_die
, cu
);
2377 processing_current_prefix
= specification_prefix
;
2378 back_to
= make_cleanup (xfree
, specification_prefix
);
2385 /* Record the function range for dwarf_decode_lines. */
2386 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
2388 if (objfile
->ei
.entry_point
>= lowpc
&&
2389 objfile
->ei
.entry_point
< highpc
)
2391 objfile
->ei
.entry_func_lowpc
= lowpc
;
2392 objfile
->ei
.entry_func_highpc
= highpc
;
2395 new = push_context (0, lowpc
);
2396 new->name
= new_symbol (die
, die
->type
, cu
);
2398 /* If there is a location expression for DW_AT_frame_base, record
2400 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
2402 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
2403 expression is being recorded directly in the function's symbol
2404 and not in a separate frame-base object. I guess this hack is
2405 to avoid adding some sort of frame-base adjunct/annex to the
2406 function's symbol :-(. The problem with doing this is that it
2407 results in a function symbol with a location expression that
2408 has nothing to do with the location of the function, ouch! The
2409 relationship should be: a function's symbol has-a frame base; a
2410 frame-base has-a location expression. */
2411 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
2413 cu
->list_in_scope
= &local_symbols
;
2415 if (die
->child
!= NULL
)
2417 child_die
= die
->child
;
2418 while (child_die
&& child_die
->tag
)
2420 process_die (child_die
, cu
);
2421 child_die
= sibling_die (child_die
);
2425 new = pop_context ();
2426 /* Make a block for the local symbols within. */
2427 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2428 lowpc
, highpc
, objfile
);
2430 /* In C++, we can have functions nested inside functions (e.g., when
2431 a function declares a class that has methods). This means that
2432 when we finish processing a function scope, we may need to go
2433 back to building a containing block's symbol lists. */
2434 local_symbols
= new->locals
;
2435 param_symbols
= new->params
;
2437 /* If we've finished processing a top-level function, subsequent
2438 symbols go in the file symbol list. */
2439 if (outermost_context_p ())
2440 cu
->list_in_scope
= &file_symbols
;
2442 processing_current_prefix
= previous_prefix
;
2443 if (back_to
!= NULL
)
2444 do_cleanups (back_to
);
2447 /* Process all the DIES contained within a lexical block scope. Start
2448 a new scope, process the dies, and then close the scope. */
2451 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2453 struct objfile
*objfile
= cu
->objfile
;
2454 struct context_stack
*new;
2455 CORE_ADDR lowpc
, highpc
;
2456 struct die_info
*child_die
;
2459 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2461 /* Ignore blocks with missing or invalid low and high pc attributes. */
2462 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2463 as multiple lexical blocks? Handling children in a sane way would
2464 be nasty. Might be easier to properly extend generic blocks to
2466 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2471 push_context (0, lowpc
);
2472 if (die
->child
!= NULL
)
2474 child_die
= die
->child
;
2475 while (child_die
&& child_die
->tag
)
2477 process_die (child_die
, cu
);
2478 child_die
= sibling_die (child_die
);
2481 new = pop_context ();
2483 if (local_symbols
!= NULL
)
2485 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
2488 local_symbols
= new->locals
;
2491 /* Get low and high pc attributes from a die. Return 1 if the attributes
2492 are present and valid, otherwise, return 0. Return -1 if the range is
2493 discontinuous, i.e. derived from DW_AT_ranges information. */
2495 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
2496 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
2498 struct objfile
*objfile
= cu
->objfile
;
2499 struct comp_unit_head
*cu_header
= &cu
->header
;
2500 struct attribute
*attr
;
2501 bfd
*obfd
= objfile
->obfd
;
2506 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
2509 high
= DW_ADDR (attr
);
2510 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
2512 low
= DW_ADDR (attr
);
2514 /* Found high w/o low attribute. */
2517 /* Found consecutive range of addresses. */
2522 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
2525 unsigned int addr_size
= cu_header
->addr_size
;
2526 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
2527 /* Value of the DW_AT_ranges attribute is the offset in the
2528 .debug_ranges section. */
2529 unsigned int offset
= DW_UNSND (attr
);
2530 /* Base address selection entry. */
2538 found_base
= cu_header
->base_known
;
2539 base
= cu_header
->base_address
;
2541 if (offset
>= dwarf_ranges_size
)
2543 complaint (&symfile_complaints
,
2544 "Offset %d out of bounds for DW_AT_ranges attribute",
2548 buffer
= dwarf_ranges_buffer
+ offset
;
2550 /* Read in the largest possible address. */
2551 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
2552 if ((marker
& mask
) == mask
)
2554 /* If we found the largest possible address, then
2555 read the base address. */
2556 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2557 buffer
+= 2 * addr_size
;
2558 offset
+= 2 * addr_size
;
2566 CORE_ADDR range_beginning
, range_end
;
2568 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
2569 buffer
+= addr_size
;
2570 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
2571 buffer
+= addr_size
;
2572 offset
+= 2 * addr_size
;
2574 /* An end of list marker is a pair of zero addresses. */
2575 if (range_beginning
== 0 && range_end
== 0)
2576 /* Found the end of list entry. */
2579 /* Each base address selection entry is a pair of 2 values.
2580 The first is the largest possible address, the second is
2581 the base address. Check for a base address here. */
2582 if ((range_beginning
& mask
) == mask
)
2584 /* If we found the largest possible address, then
2585 read the base address. */
2586 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2593 /* We have no valid base address for the ranges
2595 complaint (&symfile_complaints
,
2596 "Invalid .debug_ranges data (no base address)");
2600 range_beginning
+= base
;
2603 /* FIXME: This is recording everything as a low-high
2604 segment of consecutive addresses. We should have a
2605 data structure for discontiguous block ranges
2609 low
= range_beginning
;
2615 if (range_beginning
< low
)
2616 low
= range_beginning
;
2617 if (range_end
> high
)
2623 /* If the first entry is an end-of-list marker, the range
2624 describes an empty scope, i.e. no instructions. */
2634 /* When using the GNU linker, .gnu.linkonce. sections are used to
2635 eliminate duplicate copies of functions and vtables and such.
2636 The linker will arbitrarily choose one and discard the others.
2637 The AT_*_pc values for such functions refer to local labels in
2638 these sections. If the section from that file was discarded, the
2639 labels are not in the output, so the relocs get a value of 0.
2640 If this is a discarded function, mark the pc bounds as invalid,
2641 so that GDB will ignore it. */
2642 if (low
== 0 && (bfd_get_file_flags (obfd
) & HAS_RELOC
) == 0)
2650 /* Get the low and high pc's represented by the scope DIE, and store
2651 them in *LOWPC and *HIGHPC. If the correct values can't be
2652 determined, set *LOWPC to -1 and *HIGHPC to 0. */
2655 get_scope_pc_bounds (struct die_info
*die
,
2656 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2657 struct dwarf2_cu
*cu
)
2659 CORE_ADDR best_low
= (CORE_ADDR
) -1;
2660 CORE_ADDR best_high
= (CORE_ADDR
) 0;
2661 CORE_ADDR current_low
, current_high
;
2663 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
2665 best_low
= current_low
;
2666 best_high
= current_high
;
2670 struct die_info
*child
= die
->child
;
2672 while (child
&& child
->tag
)
2674 switch (child
->tag
) {
2675 case DW_TAG_subprogram
:
2676 if (dwarf2_get_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
))
2678 best_low
= min (best_low
, current_low
);
2679 best_high
= max (best_high
, current_high
);
2682 case DW_TAG_namespace
:
2683 /* FIXME: carlton/2004-01-16: Should we do this for
2684 DW_TAG_class_type/DW_TAG_structure_type, too? I think
2685 that current GCC's always emit the DIEs corresponding
2686 to definitions of methods of classes as children of a
2687 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
2688 the DIEs giving the declarations, which could be
2689 anywhere). But I don't see any reason why the
2690 standards says that they have to be there. */
2691 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
2693 if (current_low
!= ((CORE_ADDR
) -1))
2695 best_low
= min (best_low
, current_low
);
2696 best_high
= max (best_high
, current_high
);
2704 child
= sibling_die (child
);
2709 *highpc
= best_high
;
2712 /* Add an aggregate field to the field list. */
2715 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
2716 struct dwarf2_cu
*cu
)
2718 struct objfile
*objfile
= cu
->objfile
;
2719 struct nextfield
*new_field
;
2720 struct attribute
*attr
;
2722 char *fieldname
= "";
2724 /* Allocate a new field list entry and link it in. */
2725 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2726 make_cleanup (xfree
, new_field
);
2727 memset (new_field
, 0, sizeof (struct nextfield
));
2728 new_field
->next
= fip
->fields
;
2729 fip
->fields
= new_field
;
2732 /* Handle accessibility and virtuality of field.
2733 The default accessibility for members is public, the default
2734 accessibility for inheritance is private. */
2735 if (die
->tag
!= DW_TAG_inheritance
)
2736 new_field
->accessibility
= DW_ACCESS_public
;
2738 new_field
->accessibility
= DW_ACCESS_private
;
2739 new_field
->virtuality
= DW_VIRTUALITY_none
;
2741 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
2743 new_field
->accessibility
= DW_UNSND (attr
);
2744 if (new_field
->accessibility
!= DW_ACCESS_public
)
2745 fip
->non_public_fields
= 1;
2746 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
2748 new_field
->virtuality
= DW_UNSND (attr
);
2750 fp
= &new_field
->field
;
2752 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
2754 /* Data member other than a C++ static data member. */
2756 /* Get type of field. */
2757 fp
->type
= die_type (die
, cu
);
2759 FIELD_STATIC_KIND (*fp
) = 0;
2761 /* Get bit size of field (zero if none). */
2762 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
2765 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
2769 FIELD_BITSIZE (*fp
) = 0;
2772 /* Get bit offset of field. */
2773 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
2776 FIELD_BITPOS (*fp
) =
2777 decode_locdesc (DW_BLOCK (attr
), cu
) * bits_per_byte
;
2780 FIELD_BITPOS (*fp
) = 0;
2781 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
2784 if (BITS_BIG_ENDIAN
)
2786 /* For big endian bits, the DW_AT_bit_offset gives the
2787 additional bit offset from the MSB of the containing
2788 anonymous object to the MSB of the field. We don't
2789 have to do anything special since we don't need to
2790 know the size of the anonymous object. */
2791 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
2795 /* For little endian bits, compute the bit offset to the
2796 MSB of the anonymous object, subtract off the number of
2797 bits from the MSB of the field to the MSB of the
2798 object, and then subtract off the number of bits of
2799 the field itself. The result is the bit offset of
2800 the LSB of the field. */
2802 int bit_offset
= DW_UNSND (attr
);
2804 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
2807 /* The size of the anonymous object containing
2808 the bit field is explicit, so use the
2809 indicated size (in bytes). */
2810 anonymous_size
= DW_UNSND (attr
);
2814 /* The size of the anonymous object containing
2815 the bit field must be inferred from the type
2816 attribute of the data member containing the
2818 anonymous_size
= TYPE_LENGTH (fp
->type
);
2820 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2821 - bit_offset
- FIELD_BITSIZE (*fp
);
2825 /* Get name of field. */
2826 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2827 if (attr
&& DW_STRING (attr
))
2828 fieldname
= DW_STRING (attr
);
2830 /* The name is already allocated along with this objfile, so we don't
2831 need to duplicate it for the type. */
2832 fp
->name
= fieldname
;
2834 /* Change accessibility for artificial fields (e.g. virtual table
2835 pointer or virtual base class pointer) to private. */
2836 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
2838 new_field
->accessibility
= DW_ACCESS_private
;
2839 fip
->non_public_fields
= 1;
2842 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
2844 /* C++ static member. */
2846 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2847 is a declaration, but all versions of G++ as of this writing
2848 (so through at least 3.2.1) incorrectly generate
2849 DW_TAG_variable tags. */
2853 /* Get name of field. */
2854 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2855 if (attr
&& DW_STRING (attr
))
2856 fieldname
= DW_STRING (attr
);
2860 /* Get physical name. */
2861 physname
= dwarf2_linkage_name (die
, cu
);
2863 /* The name is already allocated along with this objfile, so we don't
2864 need to duplicate it for the type. */
2865 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
2866 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2867 FIELD_NAME (*fp
) = fieldname
;
2869 else if (die
->tag
== DW_TAG_inheritance
)
2871 /* C++ base class field. */
2872 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
2874 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
2876 FIELD_BITSIZE (*fp
) = 0;
2877 FIELD_STATIC_KIND (*fp
) = 0;
2878 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2879 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2880 fip
->nbaseclasses
++;
2884 /* Create the vector of fields, and attach it to the type. */
2887 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
2888 struct dwarf2_cu
*cu
)
2890 int nfields
= fip
->nfields
;
2892 /* Record the field count, allocate space for the array of fields,
2893 and create blank accessibility bitfields if necessary. */
2894 TYPE_NFIELDS (type
) = nfields
;
2895 TYPE_FIELDS (type
) = (struct field
*)
2896 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2897 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2899 if (fip
->non_public_fields
)
2901 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2903 TYPE_FIELD_PRIVATE_BITS (type
) =
2904 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2905 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2907 TYPE_FIELD_PROTECTED_BITS (type
) =
2908 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2909 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2911 TYPE_FIELD_IGNORE_BITS (type
) =
2912 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2913 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2916 /* If the type has baseclasses, allocate and clear a bit vector for
2917 TYPE_FIELD_VIRTUAL_BITS. */
2918 if (fip
->nbaseclasses
)
2920 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2923 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2924 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2925 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2926 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2927 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2930 /* Copy the saved-up fields into the field vector. Start from the head
2931 of the list, adding to the tail of the field array, so that they end
2932 up in the same order in the array in which they were added to the list. */
2933 while (nfields
-- > 0)
2935 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2936 switch (fip
->fields
->accessibility
)
2938 case DW_ACCESS_private
:
2939 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2942 case DW_ACCESS_protected
:
2943 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2946 case DW_ACCESS_public
:
2950 /* Unknown accessibility. Complain and treat it as public. */
2952 complaint (&symfile_complaints
, "unsupported accessibility %d",
2953 fip
->fields
->accessibility
);
2957 if (nfields
< fip
->nbaseclasses
)
2959 switch (fip
->fields
->virtuality
)
2961 case DW_VIRTUALITY_virtual
:
2962 case DW_VIRTUALITY_pure_virtual
:
2963 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2967 fip
->fields
= fip
->fields
->next
;
2971 /* Add a member function to the proper fieldlist. */
2974 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2975 struct type
*type
, struct dwarf2_cu
*cu
)
2977 struct objfile
*objfile
= cu
->objfile
;
2978 struct attribute
*attr
;
2979 struct fnfieldlist
*flp
;
2981 struct fn_field
*fnp
;
2984 struct nextfnfield
*new_fnfield
;
2986 /* Get name of member function. */
2987 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2988 if (attr
&& DW_STRING (attr
))
2989 fieldname
= DW_STRING (attr
);
2993 /* Get the mangled name. */
2994 physname
= dwarf2_linkage_name (die
, cu
);
2996 /* Look up member function name in fieldlist. */
2997 for (i
= 0; i
< fip
->nfnfields
; i
++)
2999 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3003 /* Create new list element if necessary. */
3004 if (i
< fip
->nfnfields
)
3005 flp
= &fip
->fnfieldlists
[i
];
3008 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3010 fip
->fnfieldlists
= (struct fnfieldlist
*)
3011 xrealloc (fip
->fnfieldlists
,
3012 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3013 * sizeof (struct fnfieldlist
));
3014 if (fip
->nfnfields
== 0)
3015 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3017 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3018 flp
->name
= fieldname
;
3024 /* Create a new member function field and chain it to the field list
3026 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3027 make_cleanup (xfree
, new_fnfield
);
3028 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3029 new_fnfield
->next
= flp
->head
;
3030 flp
->head
= new_fnfield
;
3033 /* Fill in the member function field info. */
3034 fnp
= &new_fnfield
->fnfield
;
3035 /* The name is already allocated along with this objfile, so we don't
3036 need to duplicate it for the type. */
3037 fnp
->physname
= physname
? physname
: "";
3038 fnp
->type
= alloc_type (objfile
);
3039 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
3041 int nparams
= TYPE_NFIELDS (die
->type
);
3043 /* TYPE is the domain of this method, and DIE->TYPE is the type
3044 of the method itself (TYPE_CODE_METHOD). */
3045 smash_to_method_type (fnp
->type
, type
,
3046 TYPE_TARGET_TYPE (die
->type
),
3047 TYPE_FIELDS (die
->type
),
3048 TYPE_NFIELDS (die
->type
),
3049 TYPE_VARARGS (die
->type
));
3051 /* Handle static member functions.
3052 Dwarf2 has no clean way to discern C++ static and non-static
3053 member functions. G++ helps GDB by marking the first
3054 parameter for non-static member functions (which is the
3055 this pointer) as artificial. We obtain this information
3056 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3057 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
3058 fnp
->voffset
= VOFFSET_STATIC
;
3061 complaint (&symfile_complaints
, "member function type missing for '%s'",
3064 /* Get fcontext from DW_AT_containing_type if present. */
3065 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3066 fnp
->fcontext
= die_containing_type (die
, cu
);
3068 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3069 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3071 /* Get accessibility. */
3072 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3075 switch (DW_UNSND (attr
))
3077 case DW_ACCESS_private
:
3078 fnp
->is_private
= 1;
3080 case DW_ACCESS_protected
:
3081 fnp
->is_protected
= 1;
3086 /* Check for artificial methods. */
3087 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3088 if (attr
&& DW_UNSND (attr
) != 0)
3089 fnp
->is_artificial
= 1;
3091 /* Get index in virtual function table if it is a virtual member function. */
3092 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3095 /* Support the .debug_loc offsets */
3096 if (attr_form_is_block (attr
))
3098 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3100 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3102 dwarf2_complex_location_expr_complaint ();
3106 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3112 /* Create the vector of member function fields, and attach it to the type. */
3115 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3116 struct dwarf2_cu
*cu
)
3118 struct fnfieldlist
*flp
;
3119 int total_length
= 0;
3122 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3123 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3124 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3126 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3128 struct nextfnfield
*nfp
= flp
->head
;
3129 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3132 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3133 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3134 fn_flp
->fn_fields
= (struct fn_field
*)
3135 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3136 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3137 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3139 total_length
+= flp
->length
;
3142 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3143 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3146 /* Called when we find the DIE that starts a structure or union scope
3147 (definition) to process all dies that define the members of the
3150 NOTE: we need to call struct_type regardless of whether or not the
3151 DIE has an at_name attribute, since it might be an anonymous
3152 structure or union. This gets the type entered into our set of
3155 However, if the structure is incomplete (an opaque struct/union)
3156 then suppress creating a symbol table entry for it since gdb only
3157 wants to find the one with the complete definition. Note that if
3158 it is complete, we just call new_symbol, which does it's own
3159 checking about whether the struct/union is anonymous or not (and
3160 suppresses creating a symbol table entry itself). */
3163 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3165 struct objfile
*objfile
= cu
->objfile
;
3167 struct attribute
*attr
;
3168 const char *previous_prefix
= processing_current_prefix
;
3169 struct cleanup
*back_to
= NULL
;
3174 type
= alloc_type (objfile
);
3176 INIT_CPLUS_SPECIFIC (type
);
3177 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3178 if (attr
&& DW_STRING (attr
))
3180 if (cu
->language
== language_cplus
)
3182 char *new_prefix
= determine_class_name (die
, cu
);
3183 TYPE_TAG_NAME (type
) = obsavestring (new_prefix
,
3184 strlen (new_prefix
),
3185 &objfile
->objfile_obstack
);
3186 back_to
= make_cleanup (xfree
, new_prefix
);
3187 processing_current_prefix
= new_prefix
;
3191 /* The name is already allocated along with this objfile, so
3192 we don't need to duplicate it for the type. */
3193 TYPE_TAG_NAME (type
) = DW_STRING (attr
);
3197 if (die
->tag
== DW_TAG_structure_type
)
3199 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
3201 else if (die
->tag
== DW_TAG_union_type
)
3203 TYPE_CODE (type
) = TYPE_CODE_UNION
;
3207 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
3209 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
3212 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3215 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3219 TYPE_LENGTH (type
) = 0;
3222 /* We need to add the type field to the die immediately so we don't
3223 infinitely recurse when dealing with pointers to the structure
3224 type within the structure itself. */
3227 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
3229 struct field_info fi
;
3230 struct die_info
*child_die
;
3231 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
3233 memset (&fi
, 0, sizeof (struct field_info
));
3235 child_die
= die
->child
;
3237 while (child_die
&& child_die
->tag
)
3239 if (child_die
->tag
== DW_TAG_member
3240 || child_die
->tag
== DW_TAG_variable
)
3242 /* NOTE: carlton/2002-11-05: A C++ static data member
3243 should be a DW_TAG_member that is a declaration, but
3244 all versions of G++ as of this writing (so through at
3245 least 3.2.1) incorrectly generate DW_TAG_variable
3246 tags for them instead. */
3247 dwarf2_add_field (&fi
, child_die
, cu
);
3249 else if (child_die
->tag
== DW_TAG_subprogram
)
3251 /* C++ member function. */
3252 read_type_die (child_die
, cu
);
3253 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
3255 else if (child_die
->tag
== DW_TAG_inheritance
)
3257 /* C++ base class field. */
3258 dwarf2_add_field (&fi
, child_die
, cu
);
3260 child_die
= sibling_die (child_die
);
3263 /* Attach fields and member functions to the type. */
3265 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
3268 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
3270 /* Get the type which refers to the base class (possibly this
3271 class itself) which contains the vtable pointer for the current
3272 class from the DW_AT_containing_type attribute. */
3274 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3276 struct type
*t
= die_containing_type (die
, cu
);
3278 TYPE_VPTR_BASETYPE (type
) = t
;
3281 static const char vptr_name
[] =
3282 {'_', 'v', 'p', 't', 'r', '\0'};
3285 /* Our own class provides vtbl ptr. */
3286 for (i
= TYPE_NFIELDS (t
) - 1;
3287 i
>= TYPE_N_BASECLASSES (t
);
3290 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
3292 if ((strncmp (fieldname
, vptr_name
,
3293 strlen (vptr_name
) - 1)
3295 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
3297 TYPE_VPTR_FIELDNO (type
) = i
;
3302 /* Complain if virtual function table field not found. */
3303 if (i
< TYPE_N_BASECLASSES (t
))
3304 complaint (&symfile_complaints
,
3305 "virtual function table pointer not found when defining class '%s'",
3306 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
3311 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3316 do_cleanups (back_to
);
3320 /* No children, must be stub. */
3321 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
3324 processing_current_prefix
= previous_prefix
;
3325 if (back_to
!= NULL
)
3326 do_cleanups (back_to
);
3330 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3332 struct objfile
*objfile
= cu
->objfile
;
3333 const char *previous_prefix
= processing_current_prefix
;
3335 if (TYPE_TAG_NAME (die
->type
) != NULL
)
3336 processing_current_prefix
= TYPE_TAG_NAME (die
->type
);
3338 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
3340 struct die_info
*child_die
;
3342 child_die
= die
->child
;
3344 while (child_die
&& child_die
->tag
)
3346 if (child_die
->tag
== DW_TAG_member
3347 || child_die
->tag
== DW_TAG_variable
3348 || child_die
->tag
== DW_TAG_inheritance
)
3353 process_die (child_die
, cu
);
3355 child_die
= sibling_die (child_die
);
3358 new_symbol (die
, die
->type
, cu
);
3361 processing_current_prefix
= previous_prefix
;
3364 /* Given a DW_AT_enumeration_type die, set its type. We do not
3365 complete the type's fields yet, or create any symbols. */
3368 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3370 struct objfile
*objfile
= cu
->objfile
;
3372 struct attribute
*attr
;
3377 type
= alloc_type (objfile
);
3379 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
3380 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3381 if (attr
&& DW_STRING (attr
))
3383 char *name
= DW_STRING (attr
);
3385 if (processing_has_namespace_info
)
3387 TYPE_TAG_NAME (type
) = obconcat (&objfile
->objfile_obstack
,
3388 processing_current_prefix
,
3389 processing_current_prefix
[0] == '\0'
3395 /* The name is already allocated along with this objfile, so
3396 we don't need to duplicate it for the type. */
3397 TYPE_TAG_NAME (type
) = name
;
3401 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3404 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3408 TYPE_LENGTH (type
) = 0;
3414 /* Determine the name of the type represented by DIE, which should be
3415 a named C++ compound type. Return the name in question; the caller
3416 is responsible for xfree()'ing it. */
3419 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
3421 struct cleanup
*back_to
= NULL
;
3422 struct die_info
*spec_die
= die_specification (die
, cu
);
3423 char *new_prefix
= NULL
;
3425 /* If this is the definition of a class that is declared by another
3426 die, then processing_current_prefix may not be accurate; see
3427 read_func_scope for a similar example. */
3428 if (spec_die
!= NULL
)
3430 char *specification_prefix
= determine_prefix (spec_die
, cu
);
3431 processing_current_prefix
= specification_prefix
;
3432 back_to
= make_cleanup (xfree
, specification_prefix
);
3435 /* If we don't have namespace debug info, guess the name by trying
3436 to demangle the names of members, just like we did in
3437 add_partial_structure. */
3438 if (!processing_has_namespace_info
)
3440 struct die_info
*child
;
3442 for (child
= die
->child
;
3443 child
!= NULL
&& child
->tag
!= 0;
3444 child
= sibling_die (child
))
3446 if (child
->tag
== DW_TAG_subprogram
)
3448 new_prefix
= class_name_from_physname (dwarf2_linkage_name
3451 if (new_prefix
!= NULL
)
3457 if (new_prefix
== NULL
)
3459 const char *name
= dwarf2_name (die
, cu
);
3460 new_prefix
= typename_concat (processing_current_prefix
,
3461 name
? name
: "<<anonymous>>");
3464 if (back_to
!= NULL
)
3465 do_cleanups (back_to
);
3470 /* Given a pointer to a die which begins an enumeration, process all
3471 the dies that define the members of the enumeration, and create the
3472 symbol for the enumeration type.
3474 NOTE: We reverse the order of the element list. */
3477 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3479 struct objfile
*objfile
= cu
->objfile
;
3480 struct die_info
*child_die
;
3481 struct field
*fields
;
3482 struct attribute
*attr
;
3485 int unsigned_enum
= 1;
3489 if (die
->child
!= NULL
)
3491 child_die
= die
->child
;
3492 while (child_die
&& child_die
->tag
)
3494 if (child_die
->tag
!= DW_TAG_enumerator
)
3496 process_die (child_die
, cu
);
3500 attr
= dwarf2_attr (child_die
, DW_AT_name
, cu
);
3503 sym
= new_symbol (child_die
, die
->type
, cu
);
3504 if (SYMBOL_VALUE (sym
) < 0)
3507 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3509 fields
= (struct field
*)
3511 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
3512 * sizeof (struct field
));
3515 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
3516 FIELD_TYPE (fields
[num_fields
]) = NULL
;
3517 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
3518 FIELD_BITSIZE (fields
[num_fields
]) = 0;
3519 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
3525 child_die
= sibling_die (child_die
);
3530 TYPE_NFIELDS (die
->type
) = num_fields
;
3531 TYPE_FIELDS (die
->type
) = (struct field
*)
3532 TYPE_ALLOC (die
->type
, sizeof (struct field
) * num_fields
);
3533 memcpy (TYPE_FIELDS (die
->type
), fields
,
3534 sizeof (struct field
) * num_fields
);
3538 TYPE_FLAGS (die
->type
) |= TYPE_FLAG_UNSIGNED
;
3541 new_symbol (die
, die
->type
, cu
);
3544 /* Extract all information from a DW_TAG_array_type DIE and put it in
3545 the DIE's type field. For now, this only handles one dimensional
3549 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3551 struct objfile
*objfile
= cu
->objfile
;
3552 struct die_info
*child_die
;
3553 struct type
*type
= NULL
;
3554 struct type
*element_type
, *range_type
, *index_type
;
3555 struct type
**range_types
= NULL
;
3556 struct attribute
*attr
;
3558 struct cleanup
*back_to
;
3560 /* Return if we've already decoded this type. */
3566 element_type
= die_type (die
, cu
);
3568 /* Irix 6.2 native cc creates array types without children for
3569 arrays with unspecified length. */
3570 if (die
->child
== NULL
)
3572 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
3573 range_type
= create_range_type (NULL
, index_type
, 0, -1);
3574 die
->type
= create_array_type (NULL
, element_type
, range_type
);
3578 back_to
= make_cleanup (null_cleanup
, NULL
);
3579 child_die
= die
->child
;
3580 while (child_die
&& child_die
->tag
)
3582 if (child_die
->tag
== DW_TAG_subrange_type
)
3584 read_subrange_type (child_die
, cu
);
3586 if (child_die
->type
!= NULL
)
3588 /* The range type was succesfully read. Save it for
3589 the array type creation. */
3590 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
3592 range_types
= (struct type
**)
3593 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
3594 * sizeof (struct type
*));
3596 make_cleanup (free_current_contents
, &range_types
);
3598 range_types
[ndim
++] = child_die
->type
;
3601 child_die
= sibling_die (child_die
);
3604 /* Dwarf2 dimensions are output from left to right, create the
3605 necessary array types in backwards order. */
3606 type
= element_type
;
3608 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
3610 /* Understand Dwarf2 support for vector types (like they occur on
3611 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3612 array type. This is not part of the Dwarf2/3 standard yet, but a
3613 custom vendor extension. The main difference between a regular
3614 array and the vector variant is that vectors are passed by value
3616 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
3618 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
3620 do_cleanups (back_to
);
3622 /* Install the type in the die. */
3626 /* First cut: install each common block member as a global variable. */
3629 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
3631 struct die_info
*child_die
;
3632 struct attribute
*attr
;
3634 CORE_ADDR base
= (CORE_ADDR
) 0;
3636 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
3639 /* Support the .debug_loc offsets */
3640 if (attr_form_is_block (attr
))
3642 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
3644 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3646 dwarf2_complex_location_expr_complaint ();
3650 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3651 "common block member");
3654 if (die
->child
!= NULL
)
3656 child_die
= die
->child
;
3657 while (child_die
&& child_die
->tag
)
3659 sym
= new_symbol (child_die
, NULL
, cu
);
3660 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
3663 SYMBOL_VALUE_ADDRESS (sym
) =
3664 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
3665 add_symbol_to_list (sym
, &global_symbols
);
3667 child_die
= sibling_die (child_die
);
3672 /* Read a C++ namespace. */
3675 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
3677 struct objfile
*objfile
= cu
->objfile
;
3678 const char *previous_prefix
= processing_current_prefix
;
3681 struct die_info
*current_die
;
3683 name
= namespace_name (die
, &is_anonymous
, cu
);
3685 /* Now build the name of the current namespace. */
3687 if (previous_prefix
[0] == '\0')
3689 processing_current_prefix
= name
;
3693 /* We need temp_name around because processing_current_prefix
3694 is a const char *. */
3695 char *temp_name
= alloca (strlen (previous_prefix
)
3696 + 2 + strlen(name
) + 1);
3697 strcpy (temp_name
, previous_prefix
);
3698 strcat (temp_name
, "::");
3699 strcat (temp_name
, name
);
3701 processing_current_prefix
= temp_name
;
3704 /* Add a symbol associated to this if we haven't seen the namespace
3705 before. Also, add a using directive if it's an anonymous
3708 if (dwarf2_extension (die
, cu
) == NULL
)
3712 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
3713 this cast will hopefully become unnecessary. */
3714 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
3715 (char *) processing_current_prefix
,
3717 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
3719 new_symbol (die
, type
, cu
);
3723 cp_add_using_directive (processing_current_prefix
,
3724 strlen (previous_prefix
),
3725 strlen (processing_current_prefix
));
3728 if (die
->child
!= NULL
)
3730 struct die_info
*child_die
= die
->child
;
3732 while (child_die
&& child_die
->tag
)
3734 process_die (child_die
, cu
);
3735 child_die
= sibling_die (child_die
);
3739 processing_current_prefix
= previous_prefix
;
3742 /* Return the name of the namespace represented by DIE. Set
3743 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
3747 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
3749 struct die_info
*current_die
;
3750 const char *name
= NULL
;
3752 /* Loop through the extensions until we find a name. */
3754 for (current_die
= die
;
3755 current_die
!= NULL
;
3756 current_die
= dwarf2_extension (die
, cu
))
3758 name
= dwarf2_name (current_die
, cu
);
3763 /* Is it an anonymous namespace? */
3765 *is_anonymous
= (name
== NULL
);
3767 name
= "(anonymous namespace)";
3772 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3773 the user defined type vector. */
3776 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3778 struct comp_unit_head
*cu_header
= &cu
->header
;
3780 struct attribute
*attr_byte_size
;
3781 struct attribute
*attr_address_class
;
3782 int byte_size
, addr_class
;
3789 type
= lookup_pointer_type (die_type (die
, cu
));
3791 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3793 byte_size
= DW_UNSND (attr_byte_size
);
3795 byte_size
= cu_header
->addr_size
;
3797 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
3798 if (attr_address_class
)
3799 addr_class
= DW_UNSND (attr_address_class
);
3801 addr_class
= DW_ADDR_none
;
3803 /* If the pointer size or address class is different than the
3804 default, create a type variant marked as such and set the
3805 length accordingly. */
3806 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
3808 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3812 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
3813 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
3814 type
= make_type_with_address_space (type
, type_flags
);
3816 else if (TYPE_LENGTH (type
) != byte_size
)
3818 complaint (&symfile_complaints
, "invalid pointer size %d", byte_size
);
3821 /* Should we also complain about unhandled address classes? */
3825 TYPE_LENGTH (type
) = byte_size
;
3829 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3830 the user defined type vector. */
3833 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3835 struct objfile
*objfile
= cu
->objfile
;
3837 struct type
*to_type
;
3838 struct type
*domain
;
3845 type
= alloc_type (objfile
);
3846 to_type
= die_type (die
, cu
);
3847 domain
= die_containing_type (die
, cu
);
3848 smash_to_member_type (type
, domain
, to_type
);
3853 /* Extract all information from a DW_TAG_reference_type DIE and add to
3854 the user defined type vector. */
3857 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3859 struct comp_unit_head
*cu_header
= &cu
->header
;
3861 struct attribute
*attr
;
3868 type
= lookup_reference_type (die_type (die
, cu
));
3869 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3872 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3876 TYPE_LENGTH (type
) = cu_header
->addr_size
;
3882 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3884 struct type
*base_type
;
3891 base_type
= die_type (die
, cu
);
3892 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
3896 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3898 struct type
*base_type
;
3905 base_type
= die_type (die
, cu
);
3906 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
3909 /* Extract all information from a DW_TAG_string_type DIE and add to
3910 the user defined type vector. It isn't really a user defined type,
3911 but it behaves like one, with other DIE's using an AT_user_def_type
3912 attribute to reference it. */
3915 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3917 struct objfile
*objfile
= cu
->objfile
;
3918 struct type
*type
, *range_type
, *index_type
, *char_type
;
3919 struct attribute
*attr
;
3920 unsigned int length
;
3927 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
3930 length
= DW_UNSND (attr
);
3934 /* check for the DW_AT_byte_size attribute */
3935 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3938 length
= DW_UNSND (attr
);
3945 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
3946 range_type
= create_range_type (NULL
, index_type
, 1, length
);
3947 if (cu
->language
== language_fortran
)
3949 /* Need to create a unique string type for bounds
3951 type
= create_string_type (0, range_type
);
3955 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
, cu
);
3956 type
= create_string_type (char_type
, range_type
);
3961 /* Handle DIES due to C code like:
3965 int (*funcp)(int a, long l);
3969 ('funcp' generates a DW_TAG_subroutine_type DIE)
3973 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3975 struct type
*type
; /* Type that this function returns */
3976 struct type
*ftype
; /* Function that returns above type */
3977 struct attribute
*attr
;
3979 /* Decode the type that this subroutine returns */
3984 type
= die_type (die
, cu
);
3985 ftype
= lookup_function_type (type
);
3987 /* All functions in C++ have prototypes. */
3988 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
3989 if ((attr
&& (DW_UNSND (attr
) != 0))
3990 || cu
->language
== language_cplus
)
3991 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
3993 if (die
->child
!= NULL
)
3995 struct die_info
*child_die
;
3999 /* Count the number of parameters.
4000 FIXME: GDB currently ignores vararg functions, but knows about
4001 vararg member functions. */
4002 child_die
= die
->child
;
4003 while (child_die
&& child_die
->tag
)
4005 if (child_die
->tag
== DW_TAG_formal_parameter
)
4007 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4008 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
4009 child_die
= sibling_die (child_die
);
4012 /* Allocate storage for parameters and fill them in. */
4013 TYPE_NFIELDS (ftype
) = nparams
;
4014 TYPE_FIELDS (ftype
) = (struct field
*)
4015 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
4017 child_die
= die
->child
;
4018 while (child_die
&& child_die
->tag
)
4020 if (child_die
->tag
== DW_TAG_formal_parameter
)
4022 /* Dwarf2 has no clean way to discern C++ static and non-static
4023 member functions. G++ helps GDB by marking the first
4024 parameter for non-static member functions (which is the
4025 this pointer) as artificial. We pass this information
4026 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4027 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
4029 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
4031 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
4032 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
4035 child_die
= sibling_die (child_die
);
4043 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
4045 struct objfile
*objfile
= cu
->objfile
;
4046 struct attribute
*attr
;
4051 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4052 if (attr
&& DW_STRING (attr
))
4054 name
= DW_STRING (attr
);
4056 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
4057 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, cu
);
4061 /* Find a representation of a given base type and install
4062 it in the TYPE field of the die. */
4065 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4067 struct objfile
*objfile
= cu
->objfile
;
4069 struct attribute
*attr
;
4070 int encoding
= 0, size
= 0;
4072 /* If we've already decoded this die, this is a no-op. */
4078 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
4081 encoding
= DW_UNSND (attr
);
4083 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4086 size
= DW_UNSND (attr
);
4088 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4089 if (attr
&& DW_STRING (attr
))
4091 enum type_code code
= TYPE_CODE_INT
;
4096 case DW_ATE_address
:
4097 /* Turn DW_ATE_address into a void * pointer. */
4098 code
= TYPE_CODE_PTR
;
4099 type_flags
|= TYPE_FLAG_UNSIGNED
;
4101 case DW_ATE_boolean
:
4102 code
= TYPE_CODE_BOOL
;
4103 type_flags
|= TYPE_FLAG_UNSIGNED
;
4105 case DW_ATE_complex_float
:
4106 code
= TYPE_CODE_COMPLEX
;
4109 code
= TYPE_CODE_FLT
;
4112 case DW_ATE_signed_char
:
4114 case DW_ATE_unsigned
:
4115 case DW_ATE_unsigned_char
:
4116 type_flags
|= TYPE_FLAG_UNSIGNED
;
4119 complaint (&symfile_complaints
, "unsupported DW_AT_encoding: '%s'",
4120 dwarf_type_encoding_name (encoding
));
4123 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
4124 if (encoding
== DW_ATE_address
)
4125 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
,
4127 else if (encoding
== DW_ATE_complex_float
)
4130 TYPE_TARGET_TYPE (type
)
4131 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
, cu
);
4132 else if (size
== 16)
4133 TYPE_TARGET_TYPE (type
)
4134 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
4136 TYPE_TARGET_TYPE (type
)
4137 = dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
4142 type
= dwarf_base_type (encoding
, size
, cu
);
4147 /* Read the given DW_AT_subrange DIE. */
4150 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4152 struct type
*base_type
;
4153 struct type
*range_type
;
4154 struct attribute
*attr
;
4158 /* If we have already decoded this die, then nothing more to do. */
4162 base_type
= die_type (die
, cu
);
4163 if (base_type
== NULL
)
4165 complaint (&symfile_complaints
,
4166 "DW_AT_type missing from DW_TAG_subrange_type");
4170 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
4171 base_type
= alloc_type (NULL
);
4173 if (cu
->language
== language_fortran
)
4175 /* FORTRAN implies a lower bound of 1, if not given. */
4179 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
4181 low
= dwarf2_get_attr_constant_value (attr
, 0);
4183 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
4186 if (attr
->form
== DW_FORM_block1
)
4188 /* GCC encodes arrays with unspecified or dynamic length
4189 with a DW_FORM_block1 attribute.
4190 FIXME: GDB does not yet know how to handle dynamic
4191 arrays properly, treat them as arrays with unspecified
4194 FIXME: jimb/2003-09-22: GDB does not really know
4195 how to handle arrays of unspecified length
4196 either; we just represent them as zero-length
4197 arrays. Choose an appropriate upper bound given
4198 the lower bound we've computed above. */
4202 high
= dwarf2_get_attr_constant_value (attr
, 1);
4205 range_type
= create_range_type (NULL
, base_type
, low
, high
);
4207 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4208 if (attr
&& DW_STRING (attr
))
4209 TYPE_NAME (range_type
) = DW_STRING (attr
);
4211 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4213 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
4215 die
->type
= range_type
;
4219 /* Read a whole compilation unit into a linked list of dies. */
4221 static struct die_info
*
4222 read_comp_unit (char *info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
4224 /* Reset die reference table; we are
4225 building new ones now. */
4226 dwarf2_empty_hash_tables ();
4228 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
4231 /* Read a single die and all its descendents. Set the die's sibling
4232 field to NULL; set other fields in the die correctly, and set all
4233 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
4234 location of the info_ptr after reading all of those dies. PARENT
4235 is the parent of the die in question. */
4237 static struct die_info
*
4238 read_die_and_children (char *info_ptr
, bfd
*abfd
,
4239 struct dwarf2_cu
*cu
,
4240 char **new_info_ptr
,
4241 struct die_info
*parent
)
4243 struct die_info
*die
;
4247 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
4248 store_in_ref_table (die
->offset
, die
);
4252 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
4258 *new_info_ptr
= cur_ptr
;
4261 die
->sibling
= NULL
;
4262 die
->parent
= parent
;
4266 /* Read a die, all of its descendents, and all of its siblings; set
4267 all of the fields of all of the dies correctly. Arguments are as
4268 in read_die_and_children. */
4270 static struct die_info
*
4271 read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
4272 struct dwarf2_cu
*cu
,
4273 char **new_info_ptr
,
4274 struct die_info
*parent
)
4276 struct die_info
*first_die
, *last_sibling
;
4280 first_die
= last_sibling
= NULL
;
4284 struct die_info
*die
4285 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
4293 last_sibling
->sibling
= die
;
4298 *new_info_ptr
= cur_ptr
;
4308 /* Free a linked list of dies. */
4311 free_die_list (struct die_info
*dies
)
4313 struct die_info
*die
, *next
;
4318 if (die
->child
!= NULL
)
4319 free_die_list (die
->child
);
4320 next
= die
->sibling
;
4328 do_free_die_list_cleanup (void *dies
)
4330 free_die_list (dies
);
4333 static struct cleanup
*
4334 make_cleanup_free_die_list (struct die_info
*dies
)
4336 return make_cleanup (do_free_die_list_cleanup
, dies
);
4340 /* Read the contents of the section at OFFSET and of size SIZE from the
4341 object file specified by OBJFILE into the objfile_obstack and return it. */
4344 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
4346 bfd
*abfd
= objfile
->obfd
;
4348 bfd_size_type size
= bfd_get_section_size_before_reloc (sectp
);
4353 buf
= (char *) obstack_alloc (&objfile
->objfile_obstack
, size
);
4355 = (char *) symfile_relocate_debug_section (abfd
, sectp
, (bfd_byte
*) buf
);
4359 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
4360 || bfd_bread (buf
, size
, abfd
) != size
)
4361 error ("Dwarf Error: Can't read DWARF data from '%s'",
4362 bfd_get_filename (abfd
));
4367 /* In DWARF version 2, the description of the debugging information is
4368 stored in a separate .debug_abbrev section. Before we read any
4369 dies from a section we read in all abbreviations and install them
4373 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
4375 struct comp_unit_head
*cu_header
= &cu
->header
;
4377 struct abbrev_info
*cur_abbrev
;
4378 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
4379 unsigned int abbrev_form
, hash_number
;
4380 struct attr_abbrev
*cur_attrs
;
4381 unsigned int allocated_attrs
;
4383 /* Initialize dwarf2 abbrevs */
4384 obstack_init (&cu
->abbrev_obstack
);
4385 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
4387 * sizeof (struct abbrev_info
*)));
4388 memset (cu
->dwarf2_abbrevs
, 0,
4389 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
4391 abbrev_ptr
= dwarf_abbrev_buffer
+ cu_header
->abbrev_offset
;
4392 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4393 abbrev_ptr
+= bytes_read
;
4395 allocated_attrs
= ATTR_ALLOC_CHUNK
;
4396 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
4398 /* loop until we reach an abbrev number of 0 */
4399 while (abbrev_number
)
4401 cur_abbrev
= dwarf_alloc_abbrev (cu
);
4403 /* read in abbrev header */
4404 cur_abbrev
->number
= abbrev_number
;
4405 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4406 abbrev_ptr
+= bytes_read
;
4407 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
4410 /* now read in declarations */
4411 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4412 abbrev_ptr
+= bytes_read
;
4413 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4414 abbrev_ptr
+= bytes_read
;
4417 if (cur_abbrev
->num_attrs
== allocated_attrs
)
4419 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
4421 = xrealloc (cur_attrs
, (allocated_attrs
4422 * sizeof (struct attr_abbrev
)));
4424 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
4425 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
4426 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4427 abbrev_ptr
+= bytes_read
;
4428 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4429 abbrev_ptr
+= bytes_read
;
4432 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
4433 (cur_abbrev
->num_attrs
4434 * sizeof (struct attr_abbrev
)));
4435 memcpy (cur_abbrev
->attrs
, cur_attrs
,
4436 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
4438 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
4439 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
4440 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
4442 /* Get next abbreviation.
4443 Under Irix6 the abbreviations for a compilation unit are not
4444 always properly terminated with an abbrev number of 0.
4445 Exit loop if we encounter an abbreviation which we have
4446 already read (which means we are about to read the abbreviations
4447 for the next compile unit) or if the end of the abbreviation
4448 table is reached. */
4449 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
4450 >= dwarf_abbrev_size
)
4452 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4453 abbrev_ptr
+= bytes_read
;
4454 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
4461 /* Release the memory used by the abbrev table for a compilation unit. */
4464 dwarf2_free_abbrev_table (void *ptr_to_cu
)
4466 struct dwarf2_cu
*cu
= ptr_to_cu
;
4468 obstack_free (&cu
->abbrev_obstack
, NULL
);
4469 cu
->dwarf2_abbrevs
= NULL
;
4472 /* Lookup an abbrev_info structure in the abbrev hash table. */
4474 static struct abbrev_info
*
4475 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
4477 unsigned int hash_number
;
4478 struct abbrev_info
*abbrev
;
4480 hash_number
= number
% ABBREV_HASH_SIZE
;
4481 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
4485 if (abbrev
->number
== number
)
4488 abbrev
= abbrev
->next
;
4493 /* Read a minimal amount of information into the minimal die structure. */
4496 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
4497 char *info_ptr
, struct dwarf2_cu
*cu
)
4499 unsigned int abbrev_number
, bytes_read
, i
;
4500 struct abbrev_info
*abbrev
;
4501 struct attribute attr
;
4502 struct attribute spec_attr
;
4503 int found_spec_attr
= 0;
4504 int has_low_pc_attr
= 0;
4505 int has_high_pc_attr
= 0;
4507 *part_die
= zeroed_partial_die
;
4508 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4509 info_ptr
+= bytes_read
;
4513 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4516 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number
,
4517 bfd_get_filename (abfd
));
4519 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
4520 part_die
->tag
= abbrev
->tag
;
4521 part_die
->has_children
= abbrev
->has_children
;
4522 part_die
->abbrev
= abbrev_number
;
4524 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4526 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
4528 /* Store the data if it is of an attribute we want to keep in a
4529 partial symbol table. */
4534 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
4535 if (part_die
->name
== NULL
)
4536 part_die
->name
= DW_STRING (&attr
);
4538 case DW_AT_MIPS_linkage_name
:
4539 part_die
->name
= DW_STRING (&attr
);
4542 has_low_pc_attr
= 1;
4543 part_die
->lowpc
= DW_ADDR (&attr
);
4546 has_high_pc_attr
= 1;
4547 part_die
->highpc
= DW_ADDR (&attr
);
4549 case DW_AT_location
:
4550 /* Support the .debug_loc offsets */
4551 if (attr_form_is_block (&attr
))
4553 part_die
->locdesc
= DW_BLOCK (&attr
);
4555 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
4557 dwarf2_complex_location_expr_complaint ();
4561 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4562 "partial symbol information");
4565 case DW_AT_language
:
4566 part_die
->language
= DW_UNSND (&attr
);
4568 case DW_AT_external
:
4569 part_die
->is_external
= DW_UNSND (&attr
);
4571 case DW_AT_declaration
:
4572 part_die
->is_declaration
= DW_UNSND (&attr
);
4575 part_die
->has_type
= 1;
4577 case DW_AT_abstract_origin
:
4578 case DW_AT_specification
:
4579 found_spec_attr
= 1;
4583 /* Ignore absolute siblings, they might point outside of
4584 the current compile unit. */
4585 if (attr
.form
== DW_FORM_ref_addr
)
4586 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
4589 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
, cu
);
4596 /* If we found a reference attribute and the die has no name, try
4597 to find a name in the referred to die. */
4599 if (found_spec_attr
&& part_die
->name
== NULL
)
4601 struct partial_die_info spec_die
;
4604 spec_ptr
= dwarf_info_buffer
4605 + dwarf2_get_ref_die_offset (&spec_attr
, cu
);
4606 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu
);
4609 part_die
->name
= spec_die
.name
;
4611 /* Copy DW_AT_external attribute if it is set. */
4612 if (spec_die
.is_external
)
4613 part_die
->is_external
= spec_die
.is_external
;
4617 /* When using the GNU linker, .gnu.linkonce. sections are used to
4618 eliminate duplicate copies of functions and vtables and such.
4619 The linker will arbitrarily choose one and discard the others.
4620 The AT_*_pc values for such functions refer to local labels in
4621 these sections. If the section from that file was discarded, the
4622 labels are not in the output, so the relocs get a value of 0.
4623 If this is a discarded function, mark the pc bounds as invalid,
4624 so that GDB will ignore it. */
4625 if (has_low_pc_attr
&& has_high_pc_attr
4626 && part_die
->lowpc
< part_die
->highpc
4627 && (part_die
->lowpc
!= 0
4628 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
4629 part_die
->has_pc_info
= 1;
4633 /* Read the die from the .debug_info section buffer. Set DIEP to
4634 point to a newly allocated die with its information, except for its
4635 child, sibling, and parent fields. Set HAS_CHILDREN to tell
4636 whether the die has children or not. */
4639 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
4640 struct dwarf2_cu
*cu
, int *has_children
)
4642 unsigned int abbrev_number
, bytes_read
, i
, offset
;
4643 struct abbrev_info
*abbrev
;
4644 struct die_info
*die
;
4646 offset
= info_ptr
- dwarf_info_buffer
;
4647 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4648 info_ptr
+= bytes_read
;
4651 die
= dwarf_alloc_die ();
4653 die
->abbrev
= abbrev_number
;
4660 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4663 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
4665 bfd_get_filename (abfd
));
4667 die
= dwarf_alloc_die ();
4668 die
->offset
= offset
;
4669 die
->tag
= abbrev
->tag
;
4670 die
->abbrev
= abbrev_number
;
4673 die
->num_attrs
= abbrev
->num_attrs
;
4674 die
->attrs
= (struct attribute
*)
4675 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
4677 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4679 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
4680 abfd
, info_ptr
, cu
);
4684 *has_children
= abbrev
->has_children
;
4688 /* Read an attribute value described by an attribute form. */
4691 read_attribute_value (struct attribute
*attr
, unsigned form
,
4692 bfd
*abfd
, char *info_ptr
,
4693 struct dwarf2_cu
*cu
)
4695 struct comp_unit_head
*cu_header
= &cu
->header
;
4696 unsigned int bytes_read
;
4697 struct dwarf_block
*blk
;
4703 case DW_FORM_ref_addr
:
4704 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
4705 info_ptr
+= bytes_read
;
4707 case DW_FORM_block2
:
4708 blk
= dwarf_alloc_block ();
4709 blk
->size
= read_2_bytes (abfd
, info_ptr
);
4711 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4712 info_ptr
+= blk
->size
;
4713 DW_BLOCK (attr
) = blk
;
4715 case DW_FORM_block4
:
4716 blk
= dwarf_alloc_block ();
4717 blk
->size
= read_4_bytes (abfd
, info_ptr
);
4719 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4720 info_ptr
+= blk
->size
;
4721 DW_BLOCK (attr
) = blk
;
4724 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4728 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4732 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4735 case DW_FORM_string
:
4736 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
4737 info_ptr
+= bytes_read
;
4740 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
4742 info_ptr
+= bytes_read
;
4745 blk
= dwarf_alloc_block ();
4746 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4747 info_ptr
+= bytes_read
;
4748 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4749 info_ptr
+= blk
->size
;
4750 DW_BLOCK (attr
) = blk
;
4752 case DW_FORM_block1
:
4753 blk
= dwarf_alloc_block ();
4754 blk
->size
= read_1_byte (abfd
, info_ptr
);
4756 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4757 info_ptr
+= blk
->size
;
4758 DW_BLOCK (attr
) = blk
;
4761 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4765 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4769 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
4770 info_ptr
+= bytes_read
;
4773 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4774 info_ptr
+= bytes_read
;
4777 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4781 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4785 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4789 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4792 case DW_FORM_ref_udata
:
4793 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4794 info_ptr
+= bytes_read
;
4796 case DW_FORM_indirect
:
4797 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4798 info_ptr
+= bytes_read
;
4799 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
4802 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
4803 dwarf_form_name (form
),
4804 bfd_get_filename (abfd
));
4809 /* Read an attribute described by an abbreviated attribute. */
4812 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
4813 bfd
*abfd
, char *info_ptr
, struct dwarf2_cu
*cu
)
4815 attr
->name
= abbrev
->name
;
4816 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
4819 /* read dwarf information from a buffer */
4822 read_1_byte (bfd
*abfd
, char *buf
)
4824 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4828 read_1_signed_byte (bfd
*abfd
, char *buf
)
4830 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
4834 read_2_bytes (bfd
*abfd
, char *buf
)
4836 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4840 read_2_signed_bytes (bfd
*abfd
, char *buf
)
4842 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4846 read_4_bytes (bfd
*abfd
, char *buf
)
4848 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4852 read_4_signed_bytes (bfd
*abfd
, char *buf
)
4854 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4857 static unsigned long
4858 read_8_bytes (bfd
*abfd
, char *buf
)
4860 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4864 read_address (bfd
*abfd
, char *buf
, struct dwarf2_cu
*cu
, int *bytes_read
)
4866 struct comp_unit_head
*cu_header
= &cu
->header
;
4867 CORE_ADDR retval
= 0;
4869 if (cu_header
->signed_addr_p
)
4871 switch (cu_header
->addr_size
)
4874 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4877 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4880 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
4883 internal_error (__FILE__
, __LINE__
,
4884 "read_address: bad switch, signed [in module %s]",
4885 bfd_get_filename (abfd
));
4890 switch (cu_header
->addr_size
)
4893 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4896 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4899 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4902 internal_error (__FILE__
, __LINE__
,
4903 "read_address: bad switch, unsigned [in module %s]",
4904 bfd_get_filename (abfd
));
4908 *bytes_read
= cu_header
->addr_size
;
4912 /* Read the initial length from a section. The (draft) DWARF 3
4913 specification allows the initial length to take up either 4 bytes
4914 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
4915 bytes describe the length and all offsets will be 8 bytes in length
4918 An older, non-standard 64-bit format is also handled by this
4919 function. The older format in question stores the initial length
4920 as an 8-byte quantity without an escape value. Lengths greater
4921 than 2^32 aren't very common which means that the initial 4 bytes
4922 is almost always zero. Since a length value of zero doesn't make
4923 sense for the 32-bit format, this initial zero can be considered to
4924 be an escape value which indicates the presence of the older 64-bit
4925 format. As written, the code can't detect (old format) lengths
4926 greater than 4GB. If it becomes necessary to handle lengths somewhat
4927 larger than 4GB, we could allow other small values (such as the
4928 non-sensical values of 1, 2, and 3) to also be used as escape values
4929 indicating the presence of the old format.
4931 The value returned via bytes_read should be used to increment
4932 the relevant pointer after calling read_initial_length().
4934 As a side effect, this function sets the fields initial_length_size
4935 and offset_size in cu_header to the values appropriate for the
4936 length field. (The format of the initial length field determines
4937 the width of file offsets to be fetched later with fetch_offset().)
4939 [ Note: read_initial_length() and read_offset() are based on the
4940 document entitled "DWARF Debugging Information Format", revision
4941 3, draft 8, dated November 19, 2001. This document was obtained
4944 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
4946 This document is only a draft and is subject to change. (So beware.)
4948 Details regarding the older, non-standard 64-bit format were
4949 determined empirically by examining 64-bit ELF files produced
4950 by the SGI toolchain on an IRIX 6.5 machine.
4952 - Kevin, July 16, 2002
4956 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
4961 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4963 if (retval
== 0xffffffff)
4965 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
4967 if (cu_header
!= NULL
)
4969 cu_header
->initial_length_size
= 12;
4970 cu_header
->offset_size
= 8;
4973 else if (retval
== 0)
4975 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
4977 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4979 if (cu_header
!= NULL
)
4981 cu_header
->initial_length_size
= 8;
4982 cu_header
->offset_size
= 8;
4988 if (cu_header
!= NULL
)
4990 cu_header
->initial_length_size
= 4;
4991 cu_header
->offset_size
= 4;
4998 /* Read an offset from the data stream. The size of the offset is
4999 given by cu_header->offset_size. */
5002 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
5007 switch (cu_header
->offset_size
)
5010 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5014 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5018 internal_error (__FILE__
, __LINE__
,
5019 "read_offset: bad switch [in module %s]",
5020 bfd_get_filename (abfd
));
5027 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
5029 /* If the size of a host char is 8 bits, we can return a pointer
5030 to the buffer, otherwise we have to copy the data to a buffer
5031 allocated on the temporary obstack. */
5032 gdb_assert (HOST_CHAR_BIT
== 8);
5037 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5039 /* If the size of a host char is 8 bits, we can return a pointer
5040 to the string, otherwise we have to copy the string to a buffer
5041 allocated on the temporary obstack. */
5042 gdb_assert (HOST_CHAR_BIT
== 8);
5045 *bytes_read_ptr
= 1;
5048 *bytes_read_ptr
= strlen (buf
) + 1;
5053 read_indirect_string (bfd
*abfd
, char *buf
,
5054 const struct comp_unit_head
*cu_header
,
5055 unsigned int *bytes_read_ptr
)
5057 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
5058 (int *) bytes_read_ptr
);
5060 if (dwarf_str_buffer
== NULL
)
5062 error ("DW_FORM_strp used without .debug_str section [in module %s]",
5063 bfd_get_filename (abfd
));
5066 if (str_offset
>= dwarf_str_size
)
5068 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
5069 bfd_get_filename (abfd
));
5072 gdb_assert (HOST_CHAR_BIT
== 8);
5073 if (dwarf_str_buffer
[str_offset
] == '\0')
5075 return dwarf_str_buffer
+ str_offset
;
5078 static unsigned long
5079 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5081 unsigned long result
;
5082 unsigned int num_read
;
5092 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5095 result
|= ((unsigned long)(byte
& 127) << shift
);
5096 if ((byte
& 128) == 0)
5102 *bytes_read_ptr
= num_read
;
5107 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5110 int i
, shift
, size
, num_read
;
5120 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5123 result
|= ((long)(byte
& 127) << shift
);
5125 if ((byte
& 128) == 0)
5130 if ((shift
< size
) && (byte
& 0x40))
5132 result
|= -(1 << shift
);
5134 *bytes_read_ptr
= num_read
;
5138 /* Return a pointer to just past the end of an LEB128 number in BUF. */
5141 skip_leb128 (bfd
*abfd
, char *buf
)
5147 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5149 if ((byte
& 128) == 0)
5155 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
5161 cu
->language
= language_c
;
5163 case DW_LANG_C_plus_plus
:
5164 cu
->language
= language_cplus
;
5166 case DW_LANG_Fortran77
:
5167 case DW_LANG_Fortran90
:
5168 case DW_LANG_Fortran95
:
5169 cu
->language
= language_fortran
;
5171 case DW_LANG_Mips_Assembler
:
5172 cu
->language
= language_asm
;
5175 cu
->language
= language_java
;
5179 case DW_LANG_Cobol74
:
5180 case DW_LANG_Cobol85
:
5181 case DW_LANG_Pascal83
:
5182 case DW_LANG_Modula2
:
5184 cu
->language
= language_minimal
;
5187 cu
->language_defn
= language_def (cu
->language
);
5190 /* Return the named attribute or NULL if not there. */
5192 static struct attribute
*
5193 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
5196 struct attribute
*spec
= NULL
;
5198 for (i
= 0; i
< die
->num_attrs
; ++i
)
5200 if (die
->attrs
[i
].name
== name
)
5202 return &die
->attrs
[i
];
5204 if (die
->attrs
[i
].name
== DW_AT_specification
5205 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
5206 spec
= &die
->attrs
[i
];
5210 struct die_info
*ref_die
=
5211 follow_die_ref (dwarf2_get_ref_die_offset (spec
, cu
));
5214 return dwarf2_attr (ref_die
, name
, cu
);
5221 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
5223 return (dwarf2_attr (die
, DW_AT_declaration
, cu
)
5224 && ! dwarf2_attr (die
, DW_AT_specification
, cu
));
5227 /* Return the die giving the specification for DIE, if there is
5230 static struct die_info
*
5231 die_specification (struct die_info
*die
, struct dwarf2_cu
*cu
)
5233 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
, cu
);
5235 if (spec_attr
== NULL
)
5238 return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr
, cu
));
5241 /* Free the line_header structure *LH, and any arrays and strings it
5244 free_line_header (struct line_header
*lh
)
5246 if (lh
->standard_opcode_lengths
)
5247 xfree (lh
->standard_opcode_lengths
);
5249 /* Remember that all the lh->file_names[i].name pointers are
5250 pointers into debug_line_buffer, and don't need to be freed. */
5252 xfree (lh
->file_names
);
5254 /* Similarly for the include directory names. */
5255 if (lh
->include_dirs
)
5256 xfree (lh
->include_dirs
);
5262 /* Add an entry to LH's include directory table. */
5264 add_include_dir (struct line_header
*lh
, char *include_dir
)
5266 /* Grow the array if necessary. */
5267 if (lh
->include_dirs_size
== 0)
5269 lh
->include_dirs_size
= 1; /* for testing */
5270 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
5271 * sizeof (*lh
->include_dirs
));
5273 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
5275 lh
->include_dirs_size
*= 2;
5276 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
5277 (lh
->include_dirs_size
5278 * sizeof (*lh
->include_dirs
)));
5281 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
5285 /* Add an entry to LH's file name table. */
5287 add_file_name (struct line_header
*lh
,
5289 unsigned int dir_index
,
5290 unsigned int mod_time
,
5291 unsigned int length
)
5293 struct file_entry
*fe
;
5295 /* Grow the array if necessary. */
5296 if (lh
->file_names_size
== 0)
5298 lh
->file_names_size
= 1; /* for testing */
5299 lh
->file_names
= xmalloc (lh
->file_names_size
5300 * sizeof (*lh
->file_names
));
5302 else if (lh
->num_file_names
>= lh
->file_names_size
)
5304 lh
->file_names_size
*= 2;
5305 lh
->file_names
= xrealloc (lh
->file_names
,
5306 (lh
->file_names_size
5307 * sizeof (*lh
->file_names
)));
5310 fe
= &lh
->file_names
[lh
->num_file_names
++];
5312 fe
->dir_index
= dir_index
;
5313 fe
->mod_time
= mod_time
;
5314 fe
->length
= length
;
5318 /* Read the statement program header starting at OFFSET in
5319 dwarf_line_buffer, according to the endianness of ABFD. Return a
5320 pointer to a struct line_header, allocated using xmalloc.
5322 NOTE: the strings in the include directory and file name tables of
5323 the returned object point into debug_line_buffer, and must not be
5325 static struct line_header
*
5326 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
5327 struct dwarf2_cu
*cu
)
5329 struct cleanup
*back_to
;
5330 struct line_header
*lh
;
5334 char *cur_dir
, *cur_file
;
5336 if (dwarf_line_buffer
== NULL
)
5338 complaint (&symfile_complaints
, "missing .debug_line section");
5342 /* Make sure that at least there's room for the total_length field. That
5343 could be 12 bytes long, but we're just going to fudge that. */
5344 if (offset
+ 4 >= dwarf_line_size
)
5346 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5350 lh
= xmalloc (sizeof (*lh
));
5351 memset (lh
, 0, sizeof (*lh
));
5352 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
5355 line_ptr
= dwarf_line_buffer
+ offset
;
5357 /* read in the header */
5358 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
5359 line_ptr
+= bytes_read
;
5360 if (line_ptr
+ lh
->total_length
> dwarf_line_buffer
+ dwarf_line_size
)
5362 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5365 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
5366 lh
->version
= read_2_bytes (abfd
, line_ptr
);
5368 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
5369 line_ptr
+= bytes_read
;
5370 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
5372 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
5374 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
5376 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
5378 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
5380 lh
->standard_opcode_lengths
5381 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
5383 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
5384 for (i
= 1; i
< lh
->opcode_base
; ++i
)
5386 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
5390 /* Read directory table */
5391 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
5393 line_ptr
+= bytes_read
;
5394 add_include_dir (lh
, cur_dir
);
5396 line_ptr
+= bytes_read
;
5398 /* Read file name table */
5399 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
5401 unsigned int dir_index
, mod_time
, length
;
5403 line_ptr
+= bytes_read
;
5404 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5405 line_ptr
+= bytes_read
;
5406 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5407 line_ptr
+= bytes_read
;
5408 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5409 line_ptr
+= bytes_read
;
5411 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
5413 line_ptr
+= bytes_read
;
5414 lh
->statement_program_start
= line_ptr
;
5416 if (line_ptr
> dwarf_line_buffer
+ dwarf_line_size
)
5417 complaint (&symfile_complaints
,
5418 "line number info header doesn't fit in `.debug_line' section");
5420 discard_cleanups (back_to
);
5424 /* This function exists to work around a bug in certain compilers
5425 (particularly GCC 2.95), in which the first line number marker of a
5426 function does not show up until after the prologue, right before
5427 the second line number marker. This function shifts ADDRESS down
5428 to the beginning of the function if necessary, and is called on
5429 addresses passed to record_line. */
5432 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
5434 struct function_range
*fn
;
5436 /* Find the function_range containing address. */
5441 cu
->cached_fn
= cu
->first_fn
;
5445 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
5451 while (fn
&& fn
!= cu
->cached_fn
)
5452 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
5462 if (address
!= fn
->lowpc
)
5463 complaint (&symfile_complaints
,
5464 "misplaced first line number at 0x%lx for '%s'",
5465 (unsigned long) address
, fn
->name
);
5470 /* Decode the line number information for the compilation unit whose
5471 line number info is at OFFSET in the .debug_line section.
5472 The compilation directory of the file is passed in COMP_DIR. */
5475 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
5476 struct dwarf2_cu
*cu
)
5480 unsigned int bytes_read
;
5481 unsigned char op_code
, extended_op
, adj_opcode
;
5483 struct objfile
*objfile
= cu
->objfile
;
5485 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5487 line_ptr
= lh
->statement_program_start
;
5488 line_end
= lh
->statement_program_end
;
5490 /* Read the statement sequences until there's nothing left. */
5491 while (line_ptr
< line_end
)
5493 /* state machine registers */
5494 CORE_ADDR address
= 0;
5495 unsigned int file
= 1;
5496 unsigned int line
= 1;
5497 unsigned int column
= 0;
5498 int is_stmt
= lh
->default_is_stmt
;
5499 int basic_block
= 0;
5500 int end_sequence
= 0;
5502 /* Start a subfile for the current file of the state machine. */
5503 if (lh
->num_file_names
>= file
)
5505 /* lh->include_dirs and lh->file_names are 0-based, but the
5506 directory and file name numbers in the statement program
5508 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
5511 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
5514 dwarf2_start_subfile (fe
->name
, dir
);
5517 /* Decode the table. */
5518 while (!end_sequence
)
5520 op_code
= read_1_byte (abfd
, line_ptr
);
5523 if (op_code
>= lh
->opcode_base
)
5524 { /* Special operand. */
5525 adj_opcode
= op_code
- lh
->opcode_base
;
5526 address
+= (adj_opcode
/ lh
->line_range
)
5527 * lh
->minimum_instruction_length
;
5528 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
5529 /* append row to matrix using current values */
5530 record_line (current_subfile
, line
,
5531 check_cu_functions (address
, cu
));
5534 else switch (op_code
)
5536 case DW_LNS_extended_op
:
5537 line_ptr
+= 1; /* ignore length */
5538 extended_op
= read_1_byte (abfd
, line_ptr
);
5540 switch (extended_op
)
5542 case DW_LNE_end_sequence
:
5544 record_line (current_subfile
, 0, address
);
5546 case DW_LNE_set_address
:
5547 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
5548 line_ptr
+= bytes_read
;
5549 address
+= baseaddr
;
5551 case DW_LNE_define_file
:
5554 unsigned int dir_index
, mod_time
, length
;
5556 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
5557 line_ptr
+= bytes_read
;
5559 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5560 line_ptr
+= bytes_read
;
5562 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5563 line_ptr
+= bytes_read
;
5565 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5566 line_ptr
+= bytes_read
;
5567 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
5571 complaint (&symfile_complaints
,
5572 "mangled .debug_line section");
5577 record_line (current_subfile
, line
,
5578 check_cu_functions (address
, cu
));
5581 case DW_LNS_advance_pc
:
5582 address
+= lh
->minimum_instruction_length
5583 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5584 line_ptr
+= bytes_read
;
5586 case DW_LNS_advance_line
:
5587 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
5588 line_ptr
+= bytes_read
;
5590 case DW_LNS_set_file
:
5592 /* lh->include_dirs and lh->file_names are 0-based,
5593 but the directory and file name numbers in the
5594 statement program are 1-based. */
5595 struct file_entry
*fe
;
5597 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5598 line_ptr
+= bytes_read
;
5599 fe
= &lh
->file_names
[file
- 1];
5601 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
5604 dwarf2_start_subfile (fe
->name
, dir
);
5607 case DW_LNS_set_column
:
5608 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5609 line_ptr
+= bytes_read
;
5611 case DW_LNS_negate_stmt
:
5612 is_stmt
= (!is_stmt
);
5614 case DW_LNS_set_basic_block
:
5617 /* Add to the address register of the state machine the
5618 address increment value corresponding to special opcode
5619 255. Ie, this value is scaled by the minimum instruction
5620 length since special opcode 255 would have scaled the
5622 case DW_LNS_const_add_pc
:
5623 address
+= (lh
->minimum_instruction_length
5624 * ((255 - lh
->opcode_base
) / lh
->line_range
));
5626 case DW_LNS_fixed_advance_pc
:
5627 address
+= read_2_bytes (abfd
, line_ptr
);
5631 { /* Unknown standard opcode, ignore it. */
5633 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
5635 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5636 line_ptr
+= bytes_read
;
5644 /* Start a subfile for DWARF. FILENAME is the name of the file and
5645 DIRNAME the name of the source directory which contains FILENAME
5646 or NULL if not known.
5647 This routine tries to keep line numbers from identical absolute and
5648 relative file names in a common subfile.
5650 Using the `list' example from the GDB testsuite, which resides in
5651 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
5652 of /srcdir/list0.c yields the following debugging information for list0.c:
5654 DW_AT_name: /srcdir/list0.c
5655 DW_AT_comp_dir: /compdir
5656 files.files[0].name: list0.h
5657 files.files[0].dir: /srcdir
5658 files.files[1].name: list0.c
5659 files.files[1].dir: /srcdir
5661 The line number information for list0.c has to end up in a single
5662 subfile, so that `break /srcdir/list0.c:1' works as expected. */
5665 dwarf2_start_subfile (char *filename
, char *dirname
)
5667 /* If the filename isn't absolute, try to match an existing subfile
5668 with the full pathname. */
5670 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
5672 struct subfile
*subfile
;
5673 char *fullname
= concat (dirname
, "/", filename
, NULL
);
5675 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
5677 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
5679 current_subfile
= subfile
;
5686 start_subfile (filename
, dirname
);
5690 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
5691 struct dwarf2_cu
*cu
)
5693 struct objfile
*objfile
= cu
->objfile
;
5694 struct comp_unit_head
*cu_header
= &cu
->header
;
5696 /* NOTE drow/2003-01-30: There used to be a comment and some special
5697 code here to turn a symbol with DW_AT_external and a
5698 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
5699 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
5700 with some versions of binutils) where shared libraries could have
5701 relocations against symbols in their debug information - the
5702 minimal symbol would have the right address, but the debug info
5703 would not. It's no longer necessary, because we will explicitly
5704 apply relocations when we read in the debug information now. */
5706 /* A DW_AT_location attribute with no contents indicates that a
5707 variable has been optimized away. */
5708 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
5710 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
5714 /* Handle one degenerate form of location expression specially, to
5715 preserve GDB's previous behavior when section offsets are
5716 specified. If this is just a DW_OP_addr then mark this symbol
5719 if (attr_form_is_block (attr
)
5720 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
5721 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
5725 SYMBOL_VALUE_ADDRESS (sym
) =
5726 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
5727 fixup_symbol_section (sym
, objfile
);
5728 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
5729 SYMBOL_SECTION (sym
));
5730 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5734 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
5735 expression evaluator, and use LOC_COMPUTED only when necessary
5736 (i.e. when the value of a register or memory location is
5737 referenced, or a thread-local block, etc.). Then again, it might
5738 not be worthwhile. I'm assuming that it isn't unless performance
5739 or memory numbers show me otherwise. */
5741 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
5742 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
5745 /* Given a pointer to a DWARF information entry, figure out if we need
5746 to make a symbol table entry for it, and if so, create a new entry
5747 and return a pointer to it.
5748 If TYPE is NULL, determine symbol type from the die, otherwise
5749 used the passed type. */
5751 static struct symbol
*
5752 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
5754 struct objfile
*objfile
= cu
->objfile
;
5755 struct symbol
*sym
= NULL
;
5757 struct attribute
*attr
= NULL
;
5758 struct attribute
*attr2
= NULL
;
5761 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5763 if (die
->tag
!= DW_TAG_namespace
)
5764 name
= dwarf2_linkage_name (die
, cu
);
5766 name
= TYPE_NAME (type
);
5770 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
5771 sizeof (struct symbol
));
5772 OBJSTAT (objfile
, n_syms
++);
5773 memset (sym
, 0, sizeof (struct symbol
));
5775 /* Cache this symbol's name and the name's demangled form (if any). */
5776 SYMBOL_LANGUAGE (sym
) = cu
->language
;
5777 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
5779 /* Default assumptions.
5780 Use the passed type or decode it from the die. */
5781 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5782 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5784 SYMBOL_TYPE (sym
) = type
;
5786 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
5787 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
5790 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
5795 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5798 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
5800 SYMBOL_CLASS (sym
) = LOC_LABEL
;
5802 case DW_TAG_subprogram
:
5803 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
5805 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
5806 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
5807 if (attr2
&& (DW_UNSND (attr2
) != 0))
5809 add_symbol_to_list (sym
, &global_symbols
);
5813 add_symbol_to_list (sym
, cu
->list_in_scope
);
5816 case DW_TAG_variable
:
5817 /* Compilation with minimal debug info may result in variables
5818 with missing type entries. Change the misleading `void' type
5819 to something sensible. */
5820 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
5821 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
5822 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
5823 "<variable, no debug info>",
5825 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
5828 dwarf2_const_value (attr
, sym
, cu
);
5829 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
5830 if (attr2
&& (DW_UNSND (attr2
) != 0))
5831 add_symbol_to_list (sym
, &global_symbols
);
5833 add_symbol_to_list (sym
, cu
->list_in_scope
);
5836 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
5839 var_decode_location (attr
, sym
, cu
);
5840 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
5841 if (attr2
&& (DW_UNSND (attr2
) != 0))
5842 add_symbol_to_list (sym
, &global_symbols
);
5844 add_symbol_to_list (sym
, cu
->list_in_scope
);
5848 /* We do not know the address of this symbol.
5849 If it is an external symbol and we have type information
5850 for it, enter the symbol as a LOC_UNRESOLVED symbol.
5851 The address of the variable will then be determined from
5852 the minimal symbol table whenever the variable is
5854 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
5855 if (attr2
&& (DW_UNSND (attr2
) != 0)
5856 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
5858 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
5859 add_symbol_to_list (sym
, &global_symbols
);
5863 case DW_TAG_formal_parameter
:
5864 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
5867 var_decode_location (attr
, sym
, cu
);
5868 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
5869 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
5870 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
5872 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
5875 dwarf2_const_value (attr
, sym
, cu
);
5877 add_symbol_to_list (sym
, cu
->list_in_scope
);
5879 case DW_TAG_unspecified_parameters
:
5880 /* From varargs functions; gdb doesn't seem to have any
5881 interest in this information, so just ignore it for now.
5884 case DW_TAG_class_type
:
5885 case DW_TAG_structure_type
:
5886 case DW_TAG_union_type
:
5887 case DW_TAG_enumeration_type
:
5888 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5889 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
5891 /* Make sure that the symbol includes appropriate enclosing
5892 classes/namespaces in its name. These are calculated in
5893 read_structure_type, and the correct name is saved in
5896 if (cu
->language
== language_cplus
)
5898 struct type
*type
= SYMBOL_TYPE (sym
);
5900 if (TYPE_TAG_NAME (type
) != NULL
)
5902 /* FIXME: carlton/2003-11-10: Should this use
5903 SYMBOL_SET_NAMES instead? (The same problem also
5904 arises further down in this function.) */
5905 /* The type's name is already allocated along with
5906 this objfile, so we don't need to duplicate it
5908 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
5913 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
5914 really ever be static objects: otherwise, if you try
5915 to, say, break of a class's method and you're in a file
5916 which doesn't mention that class, it won't work unless
5917 the check for all static symbols in lookup_symbol_aux
5918 saves you. See the OtherFileClass tests in
5919 gdb.c++/namespace.exp. */
5921 struct pending
**list_to_add
;
5923 list_to_add
= (cu
->list_in_scope
== &file_symbols
5924 && cu
->language
== language_cplus
5925 ? &global_symbols
: cu
->list_in_scope
);
5927 add_symbol_to_list (sym
, list_to_add
);
5929 /* The semantics of C++ state that "struct foo { ... }" also
5930 defines a typedef for "foo". Synthesize a typedef symbol so
5931 that "ptype foo" works as expected. */
5932 if (cu
->language
== language_cplus
)
5934 struct symbol
*typedef_sym
= (struct symbol
*)
5935 obstack_alloc (&objfile
->objfile_obstack
,
5936 sizeof (struct symbol
));
5937 *typedef_sym
= *sym
;
5938 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
5939 /* The symbol's name is already allocated along with
5940 this objfile, so we don't need to duplicate it for
5942 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
5943 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NATURAL_NAME (sym
);
5944 add_symbol_to_list (typedef_sym
, list_to_add
);
5948 case DW_TAG_typedef
:
5949 if (processing_has_namespace_info
5950 && processing_current_prefix
[0] != '\0')
5952 SYMBOL_LINKAGE_NAME (sym
) = obconcat (&objfile
->objfile_obstack
,
5953 processing_current_prefix
,
5957 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5958 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5959 add_symbol_to_list (sym
, cu
->list_in_scope
);
5961 case DW_TAG_base_type
:
5962 case DW_TAG_subrange_type
:
5963 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5964 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5965 add_symbol_to_list (sym
, cu
->list_in_scope
);
5967 case DW_TAG_enumerator
:
5968 if (processing_has_namespace_info
5969 && processing_current_prefix
[0] != '\0')
5971 SYMBOL_LINKAGE_NAME (sym
) = obconcat (&objfile
->objfile_obstack
,
5972 processing_current_prefix
,
5976 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
5979 dwarf2_const_value (attr
, sym
, cu
);
5982 /* NOTE: carlton/2003-11-10: See comment above in the
5983 DW_TAG_class_type, etc. block. */
5985 struct pending
**list_to_add
;
5987 list_to_add
= (cu
->list_in_scope
== &file_symbols
5988 && cu
->language
== language_cplus
5989 ? &global_symbols
: cu
->list_in_scope
);
5991 add_symbol_to_list (sym
, list_to_add
);
5994 case DW_TAG_namespace
:
5995 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5996 add_symbol_to_list (sym
, &global_symbols
);
5999 /* Not a tag we recognize. Hopefully we aren't processing
6000 trash data, but since we must specifically ignore things
6001 we don't recognize, there is nothing else we should do at
6003 complaint (&symfile_complaints
, "unsupported tag: '%s'",
6004 dwarf_tag_name (die
->tag
));
6011 /* Copy constant value from an attribute to a symbol. */
6014 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
6015 struct dwarf2_cu
*cu
)
6017 struct objfile
*objfile
= cu
->objfile
;
6018 struct comp_unit_head
*cu_header
= &cu
->header
;
6019 struct dwarf_block
*blk
;
6024 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
6025 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
6026 cu_header
->addr_size
,
6027 TYPE_LENGTH (SYMBOL_TYPE
6029 SYMBOL_VALUE_BYTES (sym
) = (char *)
6030 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
6031 /* NOTE: cagney/2003-05-09: In-lined store_address call with
6032 it's body - store_unsigned_integer. */
6033 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
6035 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
6037 case DW_FORM_block1
:
6038 case DW_FORM_block2
:
6039 case DW_FORM_block4
:
6041 blk
= DW_BLOCK (attr
);
6042 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
6043 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
6045 TYPE_LENGTH (SYMBOL_TYPE
6047 SYMBOL_VALUE_BYTES (sym
) = (char *)
6048 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
6049 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
6050 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
6053 /* The DW_AT_const_value attributes are supposed to carry the
6054 symbol's value "represented as it would be on the target
6055 architecture." By the time we get here, it's already been
6056 converted to host endianness, so we just need to sign- or
6057 zero-extend it as appropriate. */
6059 dwarf2_const_value_data (attr
, sym
, 8);
6062 dwarf2_const_value_data (attr
, sym
, 16);
6065 dwarf2_const_value_data (attr
, sym
, 32);
6068 dwarf2_const_value_data (attr
, sym
, 64);
6072 SYMBOL_VALUE (sym
) = DW_SND (attr
);
6073 SYMBOL_CLASS (sym
) = LOC_CONST
;
6077 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
6078 SYMBOL_CLASS (sym
) = LOC_CONST
;
6082 complaint (&symfile_complaints
,
6083 "unsupported const value attribute form: '%s'",
6084 dwarf_form_name (attr
->form
));
6085 SYMBOL_VALUE (sym
) = 0;
6086 SYMBOL_CLASS (sym
) = LOC_CONST
;
6092 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
6093 or zero-extend it as appropriate for the symbol's type. */
6095 dwarf2_const_value_data (struct attribute
*attr
,
6099 LONGEST l
= DW_UNSND (attr
);
6101 if (bits
< sizeof (l
) * 8)
6103 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
6104 l
&= ((LONGEST
) 1 << bits
) - 1;
6106 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
6109 SYMBOL_VALUE (sym
) = l
;
6110 SYMBOL_CLASS (sym
) = LOC_CONST
;
6114 /* Return the type of the die in question using its DW_AT_type attribute. */
6116 static struct type
*
6117 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6120 struct attribute
*type_attr
;
6121 struct die_info
*type_die
;
6124 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
6127 /* A missing DW_AT_type represents a void type. */
6128 return dwarf2_fundamental_type (cu
->objfile
, FT_VOID
, cu
);
6132 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
6133 type_die
= follow_die_ref (ref
);
6136 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
6137 ref
, cu
->objfile
->name
);
6141 type
= tag_type_to_type (type_die
, cu
);
6144 dump_die (type_die
);
6145 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
6151 /* Return the containing type of the die in question using its
6152 DW_AT_containing_type attribute. */
6154 static struct type
*
6155 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6157 struct type
*type
= NULL
;
6158 struct attribute
*type_attr
;
6159 struct die_info
*type_die
= NULL
;
6162 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
6165 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
6166 type_die
= follow_die_ref (ref
);
6169 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref
,
6173 type
= tag_type_to_type (type_die
, cu
);
6178 dump_die (type_die
);
6179 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
6186 static struct type
*
6187 type_at_offset (unsigned int offset
, struct dwarf2_cu
*cu
)
6189 struct die_info
*die
;
6192 die
= follow_die_ref (offset
);
6195 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
6198 type
= tag_type_to_type (die
, cu
);
6203 static struct type
*
6204 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6212 read_type_die (die
, cu
);
6216 error ("Dwarf Error: Cannot find type of die [in module %s]",
6224 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
6226 char *prefix
= determine_prefix (die
, cu
);
6227 const char *old_prefix
= processing_current_prefix
;
6228 struct cleanup
*back_to
= make_cleanup (xfree
, prefix
);
6229 processing_current_prefix
= prefix
;
6233 case DW_TAG_class_type
:
6234 case DW_TAG_structure_type
:
6235 case DW_TAG_union_type
:
6236 read_structure_type (die
, cu
);
6238 case DW_TAG_enumeration_type
:
6239 read_enumeration_type (die
, cu
);
6241 case DW_TAG_subprogram
:
6242 case DW_TAG_subroutine_type
:
6243 read_subroutine_type (die
, cu
);
6245 case DW_TAG_array_type
:
6246 read_array_type (die
, cu
);
6248 case DW_TAG_pointer_type
:
6249 read_tag_pointer_type (die
, cu
);
6251 case DW_TAG_ptr_to_member_type
:
6252 read_tag_ptr_to_member_type (die
, cu
);
6254 case DW_TAG_reference_type
:
6255 read_tag_reference_type (die
, cu
);
6257 case DW_TAG_const_type
:
6258 read_tag_const_type (die
, cu
);
6260 case DW_TAG_volatile_type
:
6261 read_tag_volatile_type (die
, cu
);
6263 case DW_TAG_string_type
:
6264 read_tag_string_type (die
, cu
);
6266 case DW_TAG_typedef
:
6267 read_typedef (die
, cu
);
6269 case DW_TAG_subrange_type
:
6270 read_subrange_type (die
, cu
);
6272 case DW_TAG_base_type
:
6273 read_base_type (die
, cu
);
6276 complaint (&symfile_complaints
, "unexepected tag in read_type_die: '%s'",
6277 dwarf_tag_name (die
->tag
));
6281 processing_current_prefix
= old_prefix
;
6282 do_cleanups (back_to
);
6285 /* Return the name of the namespace/class that DIE is defined within,
6286 or "" if we can't tell. The caller should xfree the result. */
6288 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
6289 therein) for an example of how to use this function to deal with
6290 DW_AT_specification. */
6293 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
6295 struct die_info
*parent
;
6297 if (cu
->language
!= language_cplus
)
6300 parent
= die
->parent
;
6304 return xstrdup ("");
6308 switch (parent
->tag
) {
6309 case DW_TAG_namespace
:
6311 /* FIXME: carlton/2004-03-05: Should I follow extension dies
6312 before doing this check? */
6313 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
6315 return xstrdup (TYPE_TAG_NAME (parent
->type
));
6320 char *parent_prefix
= determine_prefix (parent
, cu
);
6321 char *retval
= typename_concat (parent_prefix
,
6322 namespace_name (parent
, &dummy
,
6324 xfree (parent_prefix
);
6329 case DW_TAG_class_type
:
6330 case DW_TAG_structure_type
:
6332 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
6334 return xstrdup (TYPE_TAG_NAME (parent
->type
));
6338 const char *old_prefix
= processing_current_prefix
;
6339 char *new_prefix
= determine_prefix (parent
, cu
);
6342 processing_current_prefix
= new_prefix
;
6343 retval
= determine_class_name (parent
, cu
);
6344 processing_current_prefix
= old_prefix
;
6351 return determine_prefix (parent
, cu
);
6356 /* Return a newly-allocated string formed by concatenating PREFIX,
6357 "::", and SUFFIX, except that if PREFIX is NULL or the empty
6358 string, just return a copy of SUFFIX. */
6361 typename_concat (const char *prefix
, const char *suffix
)
6363 if (prefix
== NULL
|| prefix
[0] == '\0')
6364 return xstrdup (suffix
);
6367 char *retval
= xmalloc (strlen (prefix
) + 2 + strlen (suffix
) + 1);
6369 strcpy (retval
, prefix
);
6370 strcat (retval
, "::");
6371 strcat (retval
, suffix
);
6377 static struct type
*
6378 dwarf_base_type (int encoding
, int size
, struct dwarf2_cu
*cu
)
6380 struct objfile
*objfile
= cu
->objfile
;
6382 /* FIXME - this should not produce a new (struct type *)
6383 every time. It should cache base types. */
6387 case DW_ATE_address
:
6388 type
= dwarf2_fundamental_type (objfile
, FT_VOID
, cu
);
6390 case DW_ATE_boolean
:
6391 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
, cu
);
6393 case DW_ATE_complex_float
:
6396 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
, cu
);
6400 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
, cu
);
6406 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
6410 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
6417 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
6420 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
, cu
);
6424 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
6428 case DW_ATE_signed_char
:
6429 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
6431 case DW_ATE_unsigned
:
6435 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
6438 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
, cu
);
6442 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
, cu
);
6446 case DW_ATE_unsigned_char
:
6447 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
6450 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
6457 copy_die (struct die_info
*old_die
)
6459 struct die_info
*new_die
;
6462 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6463 memset (new_die
, 0, sizeof (struct die_info
));
6465 new_die
->tag
= old_die
->tag
;
6466 new_die
->has_children
= old_die
->has_children
;
6467 new_die
->abbrev
= old_die
->abbrev
;
6468 new_die
->offset
= old_die
->offset
;
6469 new_die
->type
= NULL
;
6471 num_attrs
= old_die
->num_attrs
;
6472 new_die
->num_attrs
= num_attrs
;
6473 new_die
->attrs
= (struct attribute
*)
6474 xmalloc (num_attrs
* sizeof (struct attribute
));
6476 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
6478 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
6479 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
6480 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
6483 new_die
->next
= NULL
;
6488 /* Return sibling of die, NULL if no sibling. */
6490 static struct die_info
*
6491 sibling_die (struct die_info
*die
)
6493 return die
->sibling
;
6496 /* Get linkage name of a die, return NULL if not found. */
6499 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6501 struct attribute
*attr
;
6503 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6504 if (attr
&& DW_STRING (attr
))
6505 return DW_STRING (attr
);
6506 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6507 if (attr
&& DW_STRING (attr
))
6508 return DW_STRING (attr
);
6512 /* Get name of a die, return NULL if not found. */
6515 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6517 struct attribute
*attr
;
6519 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6520 if (attr
&& DW_STRING (attr
))
6521 return DW_STRING (attr
);
6525 /* Return the die that this die in an extension of, or NULL if there
6528 static struct die_info
*
6529 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
*cu
)
6531 struct attribute
*attr
;
6532 struct die_info
*extension_die
;
6535 attr
= dwarf2_attr (die
, DW_AT_extension
, cu
);
6539 ref
= dwarf2_get_ref_die_offset (attr
, cu
);
6540 extension_die
= follow_die_ref (ref
);
6543 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
6546 return extension_die
;
6549 /* Convert a DIE tag into its string name. */
6552 dwarf_tag_name (unsigned tag
)
6556 case DW_TAG_padding
:
6557 return "DW_TAG_padding";
6558 case DW_TAG_array_type
:
6559 return "DW_TAG_array_type";
6560 case DW_TAG_class_type
:
6561 return "DW_TAG_class_type";
6562 case DW_TAG_entry_point
:
6563 return "DW_TAG_entry_point";
6564 case DW_TAG_enumeration_type
:
6565 return "DW_TAG_enumeration_type";
6566 case DW_TAG_formal_parameter
:
6567 return "DW_TAG_formal_parameter";
6568 case DW_TAG_imported_declaration
:
6569 return "DW_TAG_imported_declaration";
6571 return "DW_TAG_label";
6572 case DW_TAG_lexical_block
:
6573 return "DW_TAG_lexical_block";
6575 return "DW_TAG_member";
6576 case DW_TAG_pointer_type
:
6577 return "DW_TAG_pointer_type";
6578 case DW_TAG_reference_type
:
6579 return "DW_TAG_reference_type";
6580 case DW_TAG_compile_unit
:
6581 return "DW_TAG_compile_unit";
6582 case DW_TAG_string_type
:
6583 return "DW_TAG_string_type";
6584 case DW_TAG_structure_type
:
6585 return "DW_TAG_structure_type";
6586 case DW_TAG_subroutine_type
:
6587 return "DW_TAG_subroutine_type";
6588 case DW_TAG_typedef
:
6589 return "DW_TAG_typedef";
6590 case DW_TAG_union_type
:
6591 return "DW_TAG_union_type";
6592 case DW_TAG_unspecified_parameters
:
6593 return "DW_TAG_unspecified_parameters";
6594 case DW_TAG_variant
:
6595 return "DW_TAG_variant";
6596 case DW_TAG_common_block
:
6597 return "DW_TAG_common_block";
6598 case DW_TAG_common_inclusion
:
6599 return "DW_TAG_common_inclusion";
6600 case DW_TAG_inheritance
:
6601 return "DW_TAG_inheritance";
6602 case DW_TAG_inlined_subroutine
:
6603 return "DW_TAG_inlined_subroutine";
6605 return "DW_TAG_module";
6606 case DW_TAG_ptr_to_member_type
:
6607 return "DW_TAG_ptr_to_member_type";
6608 case DW_TAG_set_type
:
6609 return "DW_TAG_set_type";
6610 case DW_TAG_subrange_type
:
6611 return "DW_TAG_subrange_type";
6612 case DW_TAG_with_stmt
:
6613 return "DW_TAG_with_stmt";
6614 case DW_TAG_access_declaration
:
6615 return "DW_TAG_access_declaration";
6616 case DW_TAG_base_type
:
6617 return "DW_TAG_base_type";
6618 case DW_TAG_catch_block
:
6619 return "DW_TAG_catch_block";
6620 case DW_TAG_const_type
:
6621 return "DW_TAG_const_type";
6622 case DW_TAG_constant
:
6623 return "DW_TAG_constant";
6624 case DW_TAG_enumerator
:
6625 return "DW_TAG_enumerator";
6626 case DW_TAG_file_type
:
6627 return "DW_TAG_file_type";
6629 return "DW_TAG_friend";
6630 case DW_TAG_namelist
:
6631 return "DW_TAG_namelist";
6632 case DW_TAG_namelist_item
:
6633 return "DW_TAG_namelist_item";
6634 case DW_TAG_packed_type
:
6635 return "DW_TAG_packed_type";
6636 case DW_TAG_subprogram
:
6637 return "DW_TAG_subprogram";
6638 case DW_TAG_template_type_param
:
6639 return "DW_TAG_template_type_param";
6640 case DW_TAG_template_value_param
:
6641 return "DW_TAG_template_value_param";
6642 case DW_TAG_thrown_type
:
6643 return "DW_TAG_thrown_type";
6644 case DW_TAG_try_block
:
6645 return "DW_TAG_try_block";
6646 case DW_TAG_variant_part
:
6647 return "DW_TAG_variant_part";
6648 case DW_TAG_variable
:
6649 return "DW_TAG_variable";
6650 case DW_TAG_volatile_type
:
6651 return "DW_TAG_volatile_type";
6652 case DW_TAG_dwarf_procedure
:
6653 return "DW_TAG_dwarf_procedure";
6654 case DW_TAG_restrict_type
:
6655 return "DW_TAG_restrict_type";
6656 case DW_TAG_interface_type
:
6657 return "DW_TAG_interface_type";
6658 case DW_TAG_namespace
:
6659 return "DW_TAG_namespace";
6660 case DW_TAG_imported_module
:
6661 return "DW_TAG_imported_module";
6662 case DW_TAG_unspecified_type
:
6663 return "DW_TAG_unspecified_type";
6664 case DW_TAG_partial_unit
:
6665 return "DW_TAG_partial_unit";
6666 case DW_TAG_imported_unit
:
6667 return "DW_TAG_imported_unit";
6668 case DW_TAG_MIPS_loop
:
6669 return "DW_TAG_MIPS_loop";
6670 case DW_TAG_format_label
:
6671 return "DW_TAG_format_label";
6672 case DW_TAG_function_template
:
6673 return "DW_TAG_function_template";
6674 case DW_TAG_class_template
:
6675 return "DW_TAG_class_template";
6677 return "DW_TAG_<unknown>";
6681 /* Convert a DWARF attribute code into its string name. */
6684 dwarf_attr_name (unsigned attr
)
6689 return "DW_AT_sibling";
6690 case DW_AT_location
:
6691 return "DW_AT_location";
6693 return "DW_AT_name";
6694 case DW_AT_ordering
:
6695 return "DW_AT_ordering";
6696 case DW_AT_subscr_data
:
6697 return "DW_AT_subscr_data";
6698 case DW_AT_byte_size
:
6699 return "DW_AT_byte_size";
6700 case DW_AT_bit_offset
:
6701 return "DW_AT_bit_offset";
6702 case DW_AT_bit_size
:
6703 return "DW_AT_bit_size";
6704 case DW_AT_element_list
:
6705 return "DW_AT_element_list";
6706 case DW_AT_stmt_list
:
6707 return "DW_AT_stmt_list";
6709 return "DW_AT_low_pc";
6711 return "DW_AT_high_pc";
6712 case DW_AT_language
:
6713 return "DW_AT_language";
6715 return "DW_AT_member";
6717 return "DW_AT_discr";
6718 case DW_AT_discr_value
:
6719 return "DW_AT_discr_value";
6720 case DW_AT_visibility
:
6721 return "DW_AT_visibility";
6723 return "DW_AT_import";
6724 case DW_AT_string_length
:
6725 return "DW_AT_string_length";
6726 case DW_AT_common_reference
:
6727 return "DW_AT_common_reference";
6728 case DW_AT_comp_dir
:
6729 return "DW_AT_comp_dir";
6730 case DW_AT_const_value
:
6731 return "DW_AT_const_value";
6732 case DW_AT_containing_type
:
6733 return "DW_AT_containing_type";
6734 case DW_AT_default_value
:
6735 return "DW_AT_default_value";
6737 return "DW_AT_inline";
6738 case DW_AT_is_optional
:
6739 return "DW_AT_is_optional";
6740 case DW_AT_lower_bound
:
6741 return "DW_AT_lower_bound";
6742 case DW_AT_producer
:
6743 return "DW_AT_producer";
6744 case DW_AT_prototyped
:
6745 return "DW_AT_prototyped";
6746 case DW_AT_return_addr
:
6747 return "DW_AT_return_addr";
6748 case DW_AT_start_scope
:
6749 return "DW_AT_start_scope";
6750 case DW_AT_stride_size
:
6751 return "DW_AT_stride_size";
6752 case DW_AT_upper_bound
:
6753 return "DW_AT_upper_bound";
6754 case DW_AT_abstract_origin
:
6755 return "DW_AT_abstract_origin";
6756 case DW_AT_accessibility
:
6757 return "DW_AT_accessibility";
6758 case DW_AT_address_class
:
6759 return "DW_AT_address_class";
6760 case DW_AT_artificial
:
6761 return "DW_AT_artificial";
6762 case DW_AT_base_types
:
6763 return "DW_AT_base_types";
6764 case DW_AT_calling_convention
:
6765 return "DW_AT_calling_convention";
6767 return "DW_AT_count";
6768 case DW_AT_data_member_location
:
6769 return "DW_AT_data_member_location";
6770 case DW_AT_decl_column
:
6771 return "DW_AT_decl_column";
6772 case DW_AT_decl_file
:
6773 return "DW_AT_decl_file";
6774 case DW_AT_decl_line
:
6775 return "DW_AT_decl_line";
6776 case DW_AT_declaration
:
6777 return "DW_AT_declaration";
6778 case DW_AT_discr_list
:
6779 return "DW_AT_discr_list";
6780 case DW_AT_encoding
:
6781 return "DW_AT_encoding";
6782 case DW_AT_external
:
6783 return "DW_AT_external";
6784 case DW_AT_frame_base
:
6785 return "DW_AT_frame_base";
6787 return "DW_AT_friend";
6788 case DW_AT_identifier_case
:
6789 return "DW_AT_identifier_case";
6790 case DW_AT_macro_info
:
6791 return "DW_AT_macro_info";
6792 case DW_AT_namelist_items
:
6793 return "DW_AT_namelist_items";
6794 case DW_AT_priority
:
6795 return "DW_AT_priority";
6797 return "DW_AT_segment";
6798 case DW_AT_specification
:
6799 return "DW_AT_specification";
6800 case DW_AT_static_link
:
6801 return "DW_AT_static_link";
6803 return "DW_AT_type";
6804 case DW_AT_use_location
:
6805 return "DW_AT_use_location";
6806 case DW_AT_variable_parameter
:
6807 return "DW_AT_variable_parameter";
6808 case DW_AT_virtuality
:
6809 return "DW_AT_virtuality";
6810 case DW_AT_vtable_elem_location
:
6811 return "DW_AT_vtable_elem_location";
6812 case DW_AT_allocated
:
6813 return "DW_AT_allocated";
6814 case DW_AT_associated
:
6815 return "DW_AT_associated";
6816 case DW_AT_data_location
:
6817 return "DW_AT_data_location";
6819 return "DW_AT_stride";
6820 case DW_AT_entry_pc
:
6821 return "DW_AT_entry_pc";
6822 case DW_AT_use_UTF8
:
6823 return "DW_AT_use_UTF8";
6824 case DW_AT_extension
:
6825 return "DW_AT_extension";
6827 return "DW_AT_ranges";
6828 case DW_AT_trampoline
:
6829 return "DW_AT_trampoline";
6830 case DW_AT_call_column
:
6831 return "DW_AT_call_column";
6832 case DW_AT_call_file
:
6833 return "DW_AT_call_file";
6834 case DW_AT_call_line
:
6835 return "DW_AT_call_line";
6837 case DW_AT_MIPS_fde
:
6838 return "DW_AT_MIPS_fde";
6839 case DW_AT_MIPS_loop_begin
:
6840 return "DW_AT_MIPS_loop_begin";
6841 case DW_AT_MIPS_tail_loop_begin
:
6842 return "DW_AT_MIPS_tail_loop_begin";
6843 case DW_AT_MIPS_epilog_begin
:
6844 return "DW_AT_MIPS_epilog_begin";
6845 case DW_AT_MIPS_loop_unroll_factor
:
6846 return "DW_AT_MIPS_loop_unroll_factor";
6847 case DW_AT_MIPS_software_pipeline_depth
:
6848 return "DW_AT_MIPS_software_pipeline_depth";
6850 case DW_AT_MIPS_linkage_name
:
6851 return "DW_AT_MIPS_linkage_name";
6853 case DW_AT_sf_names
:
6854 return "DW_AT_sf_names";
6855 case DW_AT_src_info
:
6856 return "DW_AT_src_info";
6857 case DW_AT_mac_info
:
6858 return "DW_AT_mac_info";
6859 case DW_AT_src_coords
:
6860 return "DW_AT_src_coords";
6861 case DW_AT_body_begin
:
6862 return "DW_AT_body_begin";
6863 case DW_AT_body_end
:
6864 return "DW_AT_body_end";
6865 case DW_AT_GNU_vector
:
6866 return "DW_AT_GNU_vector";
6868 return "DW_AT_<unknown>";
6872 /* Convert a DWARF value form code into its string name. */
6875 dwarf_form_name (unsigned form
)
6880 return "DW_FORM_addr";
6881 case DW_FORM_block2
:
6882 return "DW_FORM_block2";
6883 case DW_FORM_block4
:
6884 return "DW_FORM_block4";
6886 return "DW_FORM_data2";
6888 return "DW_FORM_data4";
6890 return "DW_FORM_data8";
6891 case DW_FORM_string
:
6892 return "DW_FORM_string";
6894 return "DW_FORM_block";
6895 case DW_FORM_block1
:
6896 return "DW_FORM_block1";
6898 return "DW_FORM_data1";
6900 return "DW_FORM_flag";
6902 return "DW_FORM_sdata";
6904 return "DW_FORM_strp";
6906 return "DW_FORM_udata";
6907 case DW_FORM_ref_addr
:
6908 return "DW_FORM_ref_addr";
6910 return "DW_FORM_ref1";
6912 return "DW_FORM_ref2";
6914 return "DW_FORM_ref4";
6916 return "DW_FORM_ref8";
6917 case DW_FORM_ref_udata
:
6918 return "DW_FORM_ref_udata";
6919 case DW_FORM_indirect
:
6920 return "DW_FORM_indirect";
6922 return "DW_FORM_<unknown>";
6926 /* Convert a DWARF stack opcode into its string name. */
6929 dwarf_stack_op_name (unsigned op
)
6934 return "DW_OP_addr";
6936 return "DW_OP_deref";
6938 return "DW_OP_const1u";
6940 return "DW_OP_const1s";
6942 return "DW_OP_const2u";
6944 return "DW_OP_const2s";
6946 return "DW_OP_const4u";
6948 return "DW_OP_const4s";
6950 return "DW_OP_const8u";
6952 return "DW_OP_const8s";
6954 return "DW_OP_constu";
6956 return "DW_OP_consts";
6960 return "DW_OP_drop";
6962 return "DW_OP_over";
6964 return "DW_OP_pick";
6966 return "DW_OP_swap";
6970 return "DW_OP_xderef";
6978 return "DW_OP_minus";
6990 return "DW_OP_plus";
6991 case DW_OP_plus_uconst
:
6992 return "DW_OP_plus_uconst";
6998 return "DW_OP_shra";
7016 return "DW_OP_skip";
7018 return "DW_OP_lit0";
7020 return "DW_OP_lit1";
7022 return "DW_OP_lit2";
7024 return "DW_OP_lit3";
7026 return "DW_OP_lit4";
7028 return "DW_OP_lit5";
7030 return "DW_OP_lit6";
7032 return "DW_OP_lit7";
7034 return "DW_OP_lit8";
7036 return "DW_OP_lit9";
7038 return "DW_OP_lit10";
7040 return "DW_OP_lit11";
7042 return "DW_OP_lit12";
7044 return "DW_OP_lit13";
7046 return "DW_OP_lit14";
7048 return "DW_OP_lit15";
7050 return "DW_OP_lit16";
7052 return "DW_OP_lit17";
7054 return "DW_OP_lit18";
7056 return "DW_OP_lit19";
7058 return "DW_OP_lit20";
7060 return "DW_OP_lit21";
7062 return "DW_OP_lit22";
7064 return "DW_OP_lit23";
7066 return "DW_OP_lit24";
7068 return "DW_OP_lit25";
7070 return "DW_OP_lit26";
7072 return "DW_OP_lit27";
7074 return "DW_OP_lit28";
7076 return "DW_OP_lit29";
7078 return "DW_OP_lit30";
7080 return "DW_OP_lit31";
7082 return "DW_OP_reg0";
7084 return "DW_OP_reg1";
7086 return "DW_OP_reg2";
7088 return "DW_OP_reg3";
7090 return "DW_OP_reg4";
7092 return "DW_OP_reg5";
7094 return "DW_OP_reg6";
7096 return "DW_OP_reg7";
7098 return "DW_OP_reg8";
7100 return "DW_OP_reg9";
7102 return "DW_OP_reg10";
7104 return "DW_OP_reg11";
7106 return "DW_OP_reg12";
7108 return "DW_OP_reg13";
7110 return "DW_OP_reg14";
7112 return "DW_OP_reg15";
7114 return "DW_OP_reg16";
7116 return "DW_OP_reg17";
7118 return "DW_OP_reg18";
7120 return "DW_OP_reg19";
7122 return "DW_OP_reg20";
7124 return "DW_OP_reg21";
7126 return "DW_OP_reg22";
7128 return "DW_OP_reg23";
7130 return "DW_OP_reg24";
7132 return "DW_OP_reg25";
7134 return "DW_OP_reg26";
7136 return "DW_OP_reg27";
7138 return "DW_OP_reg28";
7140 return "DW_OP_reg29";
7142 return "DW_OP_reg30";
7144 return "DW_OP_reg31";
7146 return "DW_OP_breg0";
7148 return "DW_OP_breg1";
7150 return "DW_OP_breg2";
7152 return "DW_OP_breg3";
7154 return "DW_OP_breg4";
7156 return "DW_OP_breg5";
7158 return "DW_OP_breg6";
7160 return "DW_OP_breg7";
7162 return "DW_OP_breg8";
7164 return "DW_OP_breg9";
7166 return "DW_OP_breg10";
7168 return "DW_OP_breg11";
7170 return "DW_OP_breg12";
7172 return "DW_OP_breg13";
7174 return "DW_OP_breg14";
7176 return "DW_OP_breg15";
7178 return "DW_OP_breg16";
7180 return "DW_OP_breg17";
7182 return "DW_OP_breg18";
7184 return "DW_OP_breg19";
7186 return "DW_OP_breg20";
7188 return "DW_OP_breg21";
7190 return "DW_OP_breg22";
7192 return "DW_OP_breg23";
7194 return "DW_OP_breg24";
7196 return "DW_OP_breg25";
7198 return "DW_OP_breg26";
7200 return "DW_OP_breg27";
7202 return "DW_OP_breg28";
7204 return "DW_OP_breg29";
7206 return "DW_OP_breg30";
7208 return "DW_OP_breg31";
7210 return "DW_OP_regx";
7212 return "DW_OP_fbreg";
7214 return "DW_OP_bregx";
7216 return "DW_OP_piece";
7217 case DW_OP_deref_size
:
7218 return "DW_OP_deref_size";
7219 case DW_OP_xderef_size
:
7220 return "DW_OP_xderef_size";
7223 /* DWARF 3 extensions. */
7224 case DW_OP_push_object_address
:
7225 return "DW_OP_push_object_address";
7227 return "DW_OP_call2";
7229 return "DW_OP_call4";
7230 case DW_OP_call_ref
:
7231 return "DW_OP_call_ref";
7232 /* GNU extensions. */
7233 case DW_OP_GNU_push_tls_address
:
7234 return "DW_OP_GNU_push_tls_address";
7236 return "OP_<unknown>";
7241 dwarf_bool_name (unsigned mybool
)
7249 /* Convert a DWARF type code into its string name. */
7252 dwarf_type_encoding_name (unsigned enc
)
7256 case DW_ATE_address
:
7257 return "DW_ATE_address";
7258 case DW_ATE_boolean
:
7259 return "DW_ATE_boolean";
7260 case DW_ATE_complex_float
:
7261 return "DW_ATE_complex_float";
7263 return "DW_ATE_float";
7265 return "DW_ATE_signed";
7266 case DW_ATE_signed_char
:
7267 return "DW_ATE_signed_char";
7268 case DW_ATE_unsigned
:
7269 return "DW_ATE_unsigned";
7270 case DW_ATE_unsigned_char
:
7271 return "DW_ATE_unsigned_char";
7272 case DW_ATE_imaginary_float
:
7273 return "DW_ATE_imaginary_float";
7275 return "DW_ATE_<unknown>";
7279 /* Convert a DWARF call frame info operation to its string name. */
7283 dwarf_cfi_name (unsigned cfi_opc
)
7287 case DW_CFA_advance_loc
:
7288 return "DW_CFA_advance_loc";
7290 return "DW_CFA_offset";
7291 case DW_CFA_restore
:
7292 return "DW_CFA_restore";
7294 return "DW_CFA_nop";
7295 case DW_CFA_set_loc
:
7296 return "DW_CFA_set_loc";
7297 case DW_CFA_advance_loc1
:
7298 return "DW_CFA_advance_loc1";
7299 case DW_CFA_advance_loc2
:
7300 return "DW_CFA_advance_loc2";
7301 case DW_CFA_advance_loc4
:
7302 return "DW_CFA_advance_loc4";
7303 case DW_CFA_offset_extended
:
7304 return "DW_CFA_offset_extended";
7305 case DW_CFA_restore_extended
:
7306 return "DW_CFA_restore_extended";
7307 case DW_CFA_undefined
:
7308 return "DW_CFA_undefined";
7309 case DW_CFA_same_value
:
7310 return "DW_CFA_same_value";
7311 case DW_CFA_register
:
7312 return "DW_CFA_register";
7313 case DW_CFA_remember_state
:
7314 return "DW_CFA_remember_state";
7315 case DW_CFA_restore_state
:
7316 return "DW_CFA_restore_state";
7317 case DW_CFA_def_cfa
:
7318 return "DW_CFA_def_cfa";
7319 case DW_CFA_def_cfa_register
:
7320 return "DW_CFA_def_cfa_register";
7321 case DW_CFA_def_cfa_offset
:
7322 return "DW_CFA_def_cfa_offset";
7325 case DW_CFA_def_cfa_expression
:
7326 return "DW_CFA_def_cfa_expression";
7327 case DW_CFA_expression
:
7328 return "DW_CFA_expression";
7329 case DW_CFA_offset_extended_sf
:
7330 return "DW_CFA_offset_extended_sf";
7331 case DW_CFA_def_cfa_sf
:
7332 return "DW_CFA_def_cfa_sf";
7333 case DW_CFA_def_cfa_offset_sf
:
7334 return "DW_CFA_def_cfa_offset_sf";
7336 /* SGI/MIPS specific */
7337 case DW_CFA_MIPS_advance_loc8
:
7338 return "DW_CFA_MIPS_advance_loc8";
7340 /* GNU extensions */
7341 case DW_CFA_GNU_window_save
:
7342 return "DW_CFA_GNU_window_save";
7343 case DW_CFA_GNU_args_size
:
7344 return "DW_CFA_GNU_args_size";
7345 case DW_CFA_GNU_negative_offset_extended
:
7346 return "DW_CFA_GNU_negative_offset_extended";
7349 return "DW_CFA_<unknown>";
7355 dump_die (struct die_info
*die
)
7359 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
7360 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
7361 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
7362 dwarf_bool_name (die
->child
!= NULL
));
7364 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
7365 for (i
= 0; i
< die
->num_attrs
; ++i
)
7367 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
7368 dwarf_attr_name (die
->attrs
[i
].name
),
7369 dwarf_form_name (die
->attrs
[i
].form
));
7370 switch (die
->attrs
[i
].form
)
7372 case DW_FORM_ref_addr
:
7374 fprintf_unfiltered (gdb_stderr
, "address: ");
7375 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
7377 case DW_FORM_block2
:
7378 case DW_FORM_block4
:
7380 case DW_FORM_block1
:
7381 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
7392 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
7394 case DW_FORM_string
:
7396 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
7397 DW_STRING (&die
->attrs
[i
])
7398 ? DW_STRING (&die
->attrs
[i
]) : "");
7401 if (DW_UNSND (&die
->attrs
[i
]))
7402 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
7404 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
7406 case DW_FORM_indirect
:
7407 /* the reader will have reduced the indirect form to
7408 the "base form" so this form should not occur */
7409 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
7412 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
7413 die
->attrs
[i
].form
);
7415 fprintf_unfiltered (gdb_stderr
, "\n");
7420 dump_die_list (struct die_info
*die
)
7425 if (die
->child
!= NULL
)
7426 dump_die_list (die
->child
);
7427 if (die
->sibling
!= NULL
)
7428 dump_die_list (die
->sibling
);
7433 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
7436 struct die_info
*old
;
7438 h
= (offset
% REF_HASH_SIZE
);
7439 old
= die_ref_table
[h
];
7440 die
->next_ref
= old
;
7441 die_ref_table
[h
] = die
;
7446 dwarf2_empty_hash_tables (void)
7448 memset (die_ref_table
, 0, sizeof (die_ref_table
));
7452 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
7454 unsigned int result
= 0;
7458 case DW_FORM_ref_addr
:
7459 result
= DW_ADDR (attr
);
7465 case DW_FORM_ref_udata
:
7466 result
= cu
->header
.offset
+ DW_UNSND (attr
);
7469 complaint (&symfile_complaints
,
7470 "unsupported die ref attribute form: '%s'",
7471 dwarf_form_name (attr
->form
));
7476 /* Return the constant value held by the given attribute. Return -1
7477 if the value held by the attribute is not constant. */
7480 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
7482 if (attr
->form
== DW_FORM_sdata
)
7483 return DW_SND (attr
);
7484 else if (attr
->form
== DW_FORM_udata
7485 || attr
->form
== DW_FORM_data1
7486 || attr
->form
== DW_FORM_data2
7487 || attr
->form
== DW_FORM_data4
7488 || attr
->form
== DW_FORM_data8
)
7489 return DW_UNSND (attr
);
7492 complaint (&symfile_complaints
, "Attribute value is not a constant (%s)",
7493 dwarf_form_name (attr
->form
));
7494 return default_value
;
7498 static struct die_info
*
7499 follow_die_ref (unsigned int offset
)
7501 struct die_info
*die
;
7504 h
= (offset
% REF_HASH_SIZE
);
7505 die
= die_ref_table
[h
];
7508 if (die
->offset
== offset
)
7512 die
= die
->next_ref
;
7517 static struct type
*
7518 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid,
7519 struct dwarf2_cu
*cu
)
7521 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
7523 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
7524 typeid, objfile
->name
);
7527 /* Look for this particular type in the fundamental type vector. If
7528 one is not found, create and install one appropriate for the
7529 current language and the current target machine. */
7531 if (cu
->ftypes
[typeid] == NULL
)
7533 cu
->ftypes
[typeid] = cu
->language_defn
->la_fund_type (objfile
, typeid);
7536 return (cu
->ftypes
[typeid]);
7539 /* Decode simple location descriptions.
7540 Given a pointer to a dwarf block that defines a location, compute
7541 the location and return the value.
7543 NOTE drow/2003-11-18: This function is called in two situations
7544 now: for the address of static or global variables (partial symbols
7545 only) and for offsets into structures which are expected to be
7546 (more or less) constant. The partial symbol case should go away,
7547 and only the constant case should remain. That will let this
7548 function complain more accurately. A few special modes are allowed
7549 without complaint for global variables (for instance, global
7550 register values and thread-local values).
7552 A location description containing no operations indicates that the
7553 object is optimized out. The return value is 0 for that case.
7554 FIXME drow/2003-11-16: No callers check for this case any more; soon all
7555 callers will only want a very basic result and this can become a
7558 When the result is a register number, the global isreg flag is set,
7559 otherwise it is cleared.
7561 Note that stack[0] is unused except as a default error return.
7562 Note that stack overflow is not yet handled. */
7565 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
7567 struct objfile
*objfile
= cu
->objfile
;
7568 struct comp_unit_head
*cu_header
= &cu
->header
;
7570 int size
= blk
->size
;
7571 char *data
= blk
->data
;
7572 CORE_ADDR stack
[64];
7574 unsigned int bytes_read
, unsnd
;
7619 stack
[++stacki
] = op
- DW_OP_lit0
;
7655 stack
[++stacki
] = op
- DW_OP_reg0
;
7657 dwarf2_complex_location_expr_complaint ();
7662 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
7664 stack
[++stacki
] = unsnd
;
7666 dwarf2_complex_location_expr_complaint ();
7670 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
7676 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
7681 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
7686 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
7691 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
7696 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
7701 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
7706 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
7712 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
7717 stack
[stacki
+ 1] = stack
[stacki
];
7722 stack
[stacki
- 1] += stack
[stacki
];
7726 case DW_OP_plus_uconst
:
7727 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
7732 stack
[stacki
- 1] -= stack
[stacki
];
7737 /* If we're not the last op, then we definitely can't encode
7738 this using GDB's address_class enum. This is valid for partial
7739 global symbols, although the variable's address will be bogus
7742 dwarf2_complex_location_expr_complaint ();
7745 case DW_OP_GNU_push_tls_address
:
7746 /* The top of the stack has the offset from the beginning
7747 of the thread control block at which the variable is located. */
7748 /* Nothing should follow this operator, so the top of stack would
7750 /* This is valid for partial global symbols, but the variable's
7751 address will be bogus in the psymtab. */
7753 dwarf2_complex_location_expr_complaint ();
7757 complaint (&symfile_complaints
, "unsupported stack op: '%s'",
7758 dwarf_stack_op_name (op
));
7759 return (stack
[stacki
]);
7762 return (stack
[stacki
]);
7765 /* memory allocation interface */
7768 dwarf2_free_tmp_obstack (void *ignore
)
7770 obstack_free (&dwarf2_tmp_obstack
, NULL
);
7773 static struct dwarf_block
*
7774 dwarf_alloc_block (void)
7776 struct dwarf_block
*blk
;
7778 blk
= (struct dwarf_block
*)
7779 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
7783 static struct abbrev_info
*
7784 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
7786 struct abbrev_info
*abbrev
;
7788 abbrev
= (struct abbrev_info
*)
7789 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
7790 memset (abbrev
, 0, sizeof (struct abbrev_info
));
7794 static struct die_info
*
7795 dwarf_alloc_die (void)
7797 struct die_info
*die
;
7799 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
7800 memset (die
, 0, sizeof (struct die_info
));
7805 /* Macro support. */
7808 /* Return the full name of file number I in *LH's file name table.
7809 Use COMP_DIR as the name of the current directory of the
7810 compilation. The result is allocated using xmalloc; the caller is
7811 responsible for freeing it. */
7813 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
7815 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7817 if (IS_ABSOLUTE_PATH (fe
->name
))
7818 return xstrdup (fe
->name
);
7826 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7832 dir_len
= strlen (dir
);
7833 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
7834 strcpy (full_name
, dir
);
7835 full_name
[dir_len
] = '/';
7836 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
7840 return xstrdup (fe
->name
);
7845 static struct macro_source_file
*
7846 macro_start_file (int file
, int line
,
7847 struct macro_source_file
*current_file
,
7848 const char *comp_dir
,
7849 struct line_header
*lh
, struct objfile
*objfile
)
7851 /* The full name of this source file. */
7852 char *full_name
= file_full_name (file
, lh
, comp_dir
);
7854 /* We don't create a macro table for this compilation unit
7855 at all until we actually get a filename. */
7856 if (! pending_macros
)
7857 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
7858 objfile
->macro_cache
);
7861 /* If we have no current file, then this must be the start_file
7862 directive for the compilation unit's main source file. */
7863 current_file
= macro_set_main (pending_macros
, full_name
);
7865 current_file
= macro_include (current_file
, line
, full_name
);
7869 return current_file
;
7873 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
7874 followed by a null byte. */
7876 copy_string (const char *buf
, int len
)
7878 char *s
= xmalloc (len
+ 1);
7879 memcpy (s
, buf
, len
);
7887 consume_improper_spaces (const char *p
, const char *body
)
7891 complaint (&symfile_complaints
,
7892 "macro definition contains spaces in formal argument list:\n`%s'",
7904 parse_macro_definition (struct macro_source_file
*file
, int line
,
7909 /* The body string takes one of two forms. For object-like macro
7910 definitions, it should be:
7912 <macro name> " " <definition>
7914 For function-like macro definitions, it should be:
7916 <macro name> "() " <definition>
7918 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
7920 Spaces may appear only where explicitly indicated, and in the
7923 The Dwarf 2 spec says that an object-like macro's name is always
7924 followed by a space, but versions of GCC around March 2002 omit
7925 the space when the macro's definition is the empty string.
7927 The Dwarf 2 spec says that there should be no spaces between the
7928 formal arguments in a function-like macro's formal argument list,
7929 but versions of GCC around March 2002 include spaces after the
7933 /* Find the extent of the macro name. The macro name is terminated
7934 by either a space or null character (for an object-like macro) or
7935 an opening paren (for a function-like macro). */
7936 for (p
= body
; *p
; p
++)
7937 if (*p
== ' ' || *p
== '(')
7940 if (*p
== ' ' || *p
== '\0')
7942 /* It's an object-like macro. */
7943 int name_len
= p
- body
;
7944 char *name
= copy_string (body
, name_len
);
7945 const char *replacement
;
7948 replacement
= body
+ name_len
+ 1;
7951 dwarf2_macro_malformed_definition_complaint (body
);
7952 replacement
= body
+ name_len
;
7955 macro_define_object (file
, line
, name
, replacement
);
7961 /* It's a function-like macro. */
7962 char *name
= copy_string (body
, p
- body
);
7965 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
7969 p
= consume_improper_spaces (p
, body
);
7971 /* Parse the formal argument list. */
7972 while (*p
&& *p
!= ')')
7974 /* Find the extent of the current argument name. */
7975 const char *arg_start
= p
;
7977 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
7980 if (! *p
|| p
== arg_start
)
7981 dwarf2_macro_malformed_definition_complaint (body
);
7984 /* Make sure argv has room for the new argument. */
7985 if (argc
>= argv_size
)
7988 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
7991 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
7994 p
= consume_improper_spaces (p
, body
);
7996 /* Consume the comma, if present. */
8001 p
= consume_improper_spaces (p
, body
);
8010 /* Perfectly formed definition, no complaints. */
8011 macro_define_function (file
, line
, name
,
8012 argc
, (const char **) argv
,
8014 else if (*p
== '\0')
8016 /* Complain, but do define it. */
8017 dwarf2_macro_malformed_definition_complaint (body
);
8018 macro_define_function (file
, line
, name
,
8019 argc
, (const char **) argv
,
8023 /* Just complain. */
8024 dwarf2_macro_malformed_definition_complaint (body
);
8027 /* Just complain. */
8028 dwarf2_macro_malformed_definition_complaint (body
);
8034 for (i
= 0; i
< argc
; i
++)
8040 dwarf2_macro_malformed_definition_complaint (body
);
8045 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
8046 char *comp_dir
, bfd
*abfd
,
8047 struct dwarf2_cu
*cu
)
8049 char *mac_ptr
, *mac_end
;
8050 struct macro_source_file
*current_file
= 0;
8052 if (dwarf_macinfo_buffer
== NULL
)
8054 complaint (&symfile_complaints
, "missing .debug_macinfo section");
8058 mac_ptr
= dwarf_macinfo_buffer
+ offset
;
8059 mac_end
= dwarf_macinfo_buffer
+ dwarf_macinfo_size
;
8063 enum dwarf_macinfo_record_type macinfo_type
;
8065 /* Do we at least have room for a macinfo type byte? */
8066 if (mac_ptr
>= mac_end
)
8068 dwarf2_macros_too_long_complaint ();
8072 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
8075 switch (macinfo_type
)
8077 /* A zero macinfo type indicates the end of the macro
8082 case DW_MACINFO_define
:
8083 case DW_MACINFO_undef
:
8089 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8090 mac_ptr
+= bytes_read
;
8091 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
8092 mac_ptr
+= bytes_read
;
8095 complaint (&symfile_complaints
,
8096 "debug info gives macro %s outside of any file: %s",
8098 DW_MACINFO_define
? "definition" : macinfo_type
==
8099 DW_MACINFO_undef
? "undefinition" :
8100 "something-or-other", body
);
8103 if (macinfo_type
== DW_MACINFO_define
)
8104 parse_macro_definition (current_file
, line
, body
);
8105 else if (macinfo_type
== DW_MACINFO_undef
)
8106 macro_undef (current_file
, line
, body
);
8111 case DW_MACINFO_start_file
:
8116 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8117 mac_ptr
+= bytes_read
;
8118 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8119 mac_ptr
+= bytes_read
;
8121 current_file
= macro_start_file (file
, line
,
8122 current_file
, comp_dir
,
8127 case DW_MACINFO_end_file
:
8129 complaint (&symfile_complaints
,
8130 "macro debug info has an unmatched `close_file' directive");
8133 current_file
= current_file
->included_by
;
8136 enum dwarf_macinfo_record_type next_type
;
8138 /* GCC circa March 2002 doesn't produce the zero
8139 type byte marking the end of the compilation
8140 unit. Complain if it's not there, but exit no
8143 /* Do we at least have room for a macinfo type byte? */
8144 if (mac_ptr
>= mac_end
)
8146 dwarf2_macros_too_long_complaint ();
8150 /* We don't increment mac_ptr here, so this is just
8152 next_type
= read_1_byte (abfd
, mac_ptr
);
8154 complaint (&symfile_complaints
,
8155 "no terminating 0-type entry for macros in `.debug_macinfo' section");
8162 case DW_MACINFO_vendor_ext
:
8168 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8169 mac_ptr
+= bytes_read
;
8170 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
8171 mac_ptr
+= bytes_read
;
8173 /* We don't recognize any vendor extensions. */
8180 /* Check if the attribute's form is a DW_FORM_block*
8181 if so return true else false. */
8183 attr_form_is_block (struct attribute
*attr
)
8185 return (attr
== NULL
? 0 :
8186 attr
->form
== DW_FORM_block1
8187 || attr
->form
== DW_FORM_block2
8188 || attr
->form
== DW_FORM_block4
8189 || attr
->form
== DW_FORM_block
);
8193 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
8194 struct dwarf2_cu
*cu
)
8196 if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
8198 struct dwarf2_loclist_baton
*baton
;
8200 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
8201 sizeof (struct dwarf2_loclist_baton
));
8202 baton
->objfile
= cu
->objfile
;
8204 /* We don't know how long the location list is, but make sure we
8205 don't run off the edge of the section. */
8206 baton
->size
= dwarf_loc_size
- DW_UNSND (attr
);
8207 baton
->data
= dwarf_loc_buffer
+ DW_UNSND (attr
);
8208 baton
->base_address
= cu
->header
.base_address
;
8209 if (cu
->header
.base_known
== 0)
8210 complaint (&symfile_complaints
,
8211 "Location list used without specifying the CU base address.");
8213 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
8214 SYMBOL_LOCATION_BATON (sym
) = baton
;
8218 struct dwarf2_locexpr_baton
*baton
;
8220 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
8221 sizeof (struct dwarf2_locexpr_baton
));
8222 baton
->objfile
= cu
->objfile
;
8224 if (attr_form_is_block (attr
))
8226 /* Note that we're just copying the block's data pointer
8227 here, not the actual data. We're still pointing into the
8228 dwarf_info_buffer for SYM's objfile; right now we never
8229 release that buffer, but when we do clean up properly
8230 this may need to change. */
8231 baton
->size
= DW_BLOCK (attr
)->size
;
8232 baton
->data
= DW_BLOCK (attr
)->data
;
8236 dwarf2_invalid_attrib_class_complaint ("location description",
8237 SYMBOL_NATURAL_NAME (sym
));
8242 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
8243 SYMBOL_LOCATION_BATON (sym
) = baton
;