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 *determine_prefix_aux (struct die_info
*die
, struct dwarf2_cu
*);
787 static char *typename_concat (const char *prefix
, const char *suffix
);
789 static char *class_name (struct die_info
*die
, struct dwarf2_cu
*);
791 static void read_typedef (struct die_info
*, struct dwarf2_cu
*);
793 static void read_base_type (struct die_info
*, struct dwarf2_cu
*);
795 static void read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
797 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
799 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
801 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
803 static int dwarf2_get_pc_bounds (struct die_info
*,
804 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
806 static void get_scope_pc_bounds (struct die_info
*,
807 CORE_ADDR
*, CORE_ADDR
*,
810 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
813 static void dwarf2_attach_fields_to_type (struct field_info
*,
814 struct type
*, struct dwarf2_cu
*);
816 static void dwarf2_add_member_fn (struct field_info
*,
817 struct die_info
*, struct type
*,
820 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
821 struct type
*, struct dwarf2_cu
*);
823 static void read_structure_scope (struct die_info
*, struct dwarf2_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 (struct die_info
*, struct dwarf2_cu
*);
834 static struct type
*dwarf_base_type (int, int, struct dwarf2_cu
*);
836 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
838 static void read_array_type (struct die_info
*, struct dwarf2_cu
*);
840 static void read_tag_pointer_type (struct die_info
*, struct dwarf2_cu
*);
842 static void read_tag_ptr_to_member_type (struct die_info
*,
845 static void read_tag_reference_type (struct die_info
*, struct dwarf2_cu
*);
847 static void read_tag_const_type (struct die_info
*, struct dwarf2_cu
*);
849 static void read_tag_volatile_type (struct die_info
*, struct dwarf2_cu
*);
851 static void read_tag_string_type (struct die_info
*, struct dwarf2_cu
*);
853 static void read_subroutine_type (struct die_info
*, struct dwarf2_cu
*);
855 static struct die_info
*read_comp_unit (char *, bfd
*, struct dwarf2_cu
*);
857 static struct die_info
*read_die_and_children (char *info_ptr
, bfd
*abfd
,
860 struct die_info
*parent
);
862 static struct die_info
*read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
865 struct die_info
*parent
);
867 static void free_die_list (struct die_info
*);
869 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
871 static void process_die (struct die_info
*, struct dwarf2_cu
*);
873 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
875 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
877 static struct die_info
*dwarf2_extension (struct die_info
*die
,
880 static char *dwarf_tag_name (unsigned int);
882 static char *dwarf_attr_name (unsigned int);
884 static char *dwarf_form_name (unsigned int);
886 static char *dwarf_stack_op_name (unsigned int);
888 static char *dwarf_bool_name (unsigned int);
890 static char *dwarf_type_encoding_name (unsigned int);
893 static char *dwarf_cfi_name (unsigned int);
895 struct die_info
*copy_die (struct die_info
*);
898 static struct die_info
*sibling_die (struct die_info
*);
900 static void dump_die (struct die_info
*);
902 static void dump_die_list (struct die_info
*);
904 static void store_in_ref_table (unsigned int, struct die_info
*);
906 static void dwarf2_empty_hash_tables (void);
908 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*,
911 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
913 static struct die_info
*follow_die_ref (unsigned int);
915 static struct type
*dwarf2_fundamental_type (struct objfile
*, int,
918 /* memory allocation interface */
920 static void dwarf2_free_tmp_obstack (void *);
922 static struct dwarf_block
*dwarf_alloc_block (void);
924 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
926 static struct die_info
*dwarf_alloc_die (void);
928 static void initialize_cu_func_list (struct dwarf2_cu
*);
930 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
933 static void dwarf_decode_macros (struct line_header
*, unsigned int,
934 char *, bfd
*, struct dwarf2_cu
*);
936 static int attr_form_is_block (struct attribute
*);
939 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
940 struct dwarf2_cu
*cu
);
942 static char *skip_one_die (char *info_ptr
, struct abbrev_info
*abbrev
,
943 struct dwarf2_cu
*cu
);
945 /* Try to locate the sections we need for DWARF 2 debugging
946 information and return true if we have enough to do something. */
949 dwarf2_has_info (bfd
*abfd
)
951 dwarf_info_section
= 0;
952 dwarf_abbrev_section
= 0;
953 dwarf_line_section
= 0;
954 dwarf_str_section
= 0;
955 dwarf_macinfo_section
= 0;
956 dwarf_frame_section
= 0;
957 dwarf_eh_frame_section
= 0;
958 dwarf_ranges_section
= 0;
959 dwarf_loc_section
= 0;
961 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
962 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
965 /* This function is mapped across the sections and remembers the
966 offset and size of each of the debugging sections we are interested
970 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, void *ignore_ptr
)
972 if (strcmp (sectp
->name
, INFO_SECTION
) == 0)
974 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
975 dwarf_info_section
= sectp
;
977 else if (strcmp (sectp
->name
, ABBREV_SECTION
) == 0)
979 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
980 dwarf_abbrev_section
= sectp
;
982 else if (strcmp (sectp
->name
, LINE_SECTION
) == 0)
984 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
985 dwarf_line_section
= sectp
;
987 else if (strcmp (sectp
->name
, PUBNAMES_SECTION
) == 0)
989 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
990 dwarf_pubnames_section
= sectp
;
992 else if (strcmp (sectp
->name
, ARANGES_SECTION
) == 0)
994 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
995 dwarf_aranges_section
= sectp
;
997 else if (strcmp (sectp
->name
, LOC_SECTION
) == 0)
999 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
1000 dwarf_loc_section
= sectp
;
1002 else if (strcmp (sectp
->name
, MACINFO_SECTION
) == 0)
1004 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
1005 dwarf_macinfo_section
= sectp
;
1007 else if (strcmp (sectp
->name
, STR_SECTION
) == 0)
1009 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
1010 dwarf_str_section
= sectp
;
1012 else if (strcmp (sectp
->name
, FRAME_SECTION
) == 0)
1014 dwarf_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1015 dwarf_frame_section
= sectp
;
1017 else if (strcmp (sectp
->name
, EH_FRAME_SECTION
) == 0)
1019 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1020 if (aflag
& SEC_HAS_CONTENTS
)
1022 dwarf_eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1023 dwarf_eh_frame_section
= sectp
;
1026 else if (strcmp (sectp
->name
, RANGES_SECTION
) == 0)
1028 dwarf_ranges_size
= bfd_get_section_size_before_reloc (sectp
);
1029 dwarf_ranges_section
= sectp
;
1033 /* Build a partial symbol table. */
1036 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1039 /* We definitely need the .debug_info and .debug_abbrev sections */
1041 dwarf_info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1042 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1044 if (dwarf_line_section
)
1045 dwarf_line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1047 dwarf_line_buffer
= NULL
;
1049 if (dwarf_str_section
)
1050 dwarf_str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1052 dwarf_str_buffer
= NULL
;
1054 if (dwarf_macinfo_section
)
1055 dwarf_macinfo_buffer
= dwarf2_read_section (objfile
,
1056 dwarf_macinfo_section
);
1058 dwarf_macinfo_buffer
= NULL
;
1060 if (dwarf_ranges_section
)
1061 dwarf_ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1063 dwarf_ranges_buffer
= NULL
;
1065 if (dwarf_loc_section
)
1066 dwarf_loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1068 dwarf_loc_buffer
= NULL
;
1071 || (objfile
->global_psymbols
.size
== 0
1072 && objfile
->static_psymbols
.size
== 0))
1074 init_psymbol_list (objfile
, 1024);
1078 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1080 /* Things are significantly easier if we have .debug_aranges and
1081 .debug_pubnames sections */
1083 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1087 /* only test this case for now */
1089 /* In this case we have to work a bit harder */
1090 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1095 /* Build the partial symbol table from the information in the
1096 .debug_pubnames and .debug_aranges sections. */
1099 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1101 bfd
*abfd
= objfile
->obfd
;
1102 char *aranges_buffer
, *pubnames_buffer
;
1103 char *aranges_ptr
, *pubnames_ptr
;
1104 unsigned int entry_length
, version
, info_offset
, info_size
;
1106 pubnames_buffer
= dwarf2_read_section (objfile
,
1107 dwarf_pubnames_section
);
1108 pubnames_ptr
= pubnames_buffer
;
1109 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
1111 struct comp_unit_head cu_header
;
1114 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1116 pubnames_ptr
+= bytes_read
;
1117 version
= read_1_byte (abfd
, pubnames_ptr
);
1119 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1121 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1125 aranges_buffer
= dwarf2_read_section (objfile
,
1126 dwarf_aranges_section
);
1131 /* Read in the comp unit header information from the debug_info at
1135 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1136 char *info_ptr
, bfd
*abfd
)
1140 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1142 info_ptr
+= bytes_read
;
1143 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1145 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1147 info_ptr
+= bytes_read
;
1148 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1150 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1151 if (signed_addr
< 0)
1152 internal_error (__FILE__
, __LINE__
,
1153 "read_comp_unit_head: dwarf from non elf file");
1154 cu_header
->signed_addr_p
= signed_addr
;
1158 /* Build the partial symbol table by doing a quick pass through the
1159 .debug_info and .debug_abbrev sections. */
1162 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1164 /* Instead of reading this into a big buffer, we should probably use
1165 mmap() on architectures that support it. (FIXME) */
1166 bfd
*abfd
= objfile
->obfd
;
1167 char *info_ptr
, *abbrev_ptr
;
1168 char *beg_of_comp_unit
;
1169 struct partial_die_info comp_unit_die
;
1170 struct partial_symtab
*pst
;
1171 struct cleanup
*back_to
;
1172 CORE_ADDR lowpc
, highpc
, baseaddr
;
1174 info_ptr
= dwarf_info_buffer
;
1175 abbrev_ptr
= dwarf_abbrev_buffer
;
1177 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1178 the partial symbol scan, like attribute values.
1180 We could reduce our peak memory consumption during partial symbol
1181 table construction by freeing stuff from this obstack more often
1182 --- say, after processing each compilation unit, or each die ---
1183 but it turns out that this saves almost nothing. For an
1184 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1185 on dwarf2_tmp_obstack. Some investigation showed:
1187 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1188 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1189 all fixed-length values not requiring dynamic allocation.
1191 2) 30% of the attributes used the form DW_FORM_string. For
1192 DW_FORM_string, read_attribute simply hands back a pointer to
1193 the null-terminated string in dwarf_info_buffer, so no dynamic
1194 allocation is needed there either.
1196 3) The remaining 1% of the attributes all used DW_FORM_block1.
1197 75% of those were DW_AT_frame_base location lists for
1198 functions; the rest were DW_AT_location attributes, probably
1199 for the global variables.
1201 Anyway, what this all means is that the memory the dwarf2
1202 reader uses as temporary space reading partial symbols is about
1203 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1205 obstack_init (&dwarf2_tmp_obstack
);
1206 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1208 /* Since the objects we're extracting from dwarf_info_buffer vary in
1209 length, only the individual functions to extract them (like
1210 read_comp_unit_head and read_partial_die) can really know whether
1211 the buffer is large enough to hold another complete object.
1213 At the moment, they don't actually check that. If
1214 dwarf_info_buffer holds just one extra byte after the last
1215 compilation unit's dies, then read_comp_unit_head will happily
1216 read off the end of the buffer. read_partial_die is similarly
1217 casual. Those functions should be fixed.
1219 For this loop condition, simply checking whether there's any data
1220 left at all should be sufficient. */
1221 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1223 struct cleanup
*back_to_inner
;
1224 struct dwarf2_cu cu
;
1225 beg_of_comp_unit
= info_ptr
;
1227 cu
.objfile
= objfile
;
1228 info_ptr
= read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1230 if (cu
.header
.version
!= 2)
1232 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
));
1235 if (cu
.header
.abbrev_offset
>= dwarf_abbrev_size
)
1237 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6) [in module %s]",
1238 (long) cu
.header
.abbrev_offset
,
1239 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1240 bfd_get_filename (abfd
));
1243 if (beg_of_comp_unit
+ cu
.header
.length
+ cu
.header
.initial_length_size
1244 > dwarf_info_buffer
+ dwarf_info_size
)
1246 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0) [in module %s]",
1247 (long) cu
.header
.length
,
1248 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1249 bfd_get_filename (abfd
));
1252 /* Complete the cu_header */
1253 cu
.header
.offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1254 cu
.header
.first_die_ptr
= info_ptr
;
1255 cu
.header
.cu_head_ptr
= beg_of_comp_unit
;
1257 cu
.list_in_scope
= &file_symbols
;
1259 /* Read the abbrevs for this compilation unit into a table */
1260 dwarf2_read_abbrevs (abfd
, &cu
);
1261 back_to_inner
= make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1263 /* Read the compilation unit die */
1264 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1267 /* Set the language we're debugging */
1268 set_cu_language (comp_unit_die
.language
, &cu
);
1270 /* Allocate a new partial symbol table structure */
1271 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1272 comp_unit_die
.name
? comp_unit_die
.name
: "",
1273 comp_unit_die
.lowpc
,
1274 objfile
->global_psymbols
.next
,
1275 objfile
->static_psymbols
.next
);
1277 pst
->read_symtab_private
= (char *)
1278 obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct dwarf2_pinfo
));
1279 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1280 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1281 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1282 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1283 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1284 DWARF_LINE_SIZE (pst
) = dwarf_line_size
;
1285 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1286 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1287 DWARF_MACINFO_BUFFER (pst
) = dwarf_macinfo_buffer
;
1288 DWARF_MACINFO_SIZE (pst
) = dwarf_macinfo_size
;
1289 DWARF_RANGES_BUFFER (pst
) = dwarf_ranges_buffer
;
1290 DWARF_RANGES_SIZE (pst
) = dwarf_ranges_size
;
1291 DWARF_LOC_BUFFER (pst
) = dwarf_loc_buffer
;
1292 DWARF_LOC_SIZE (pst
) = dwarf_loc_size
;
1293 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1295 /* Store the function that reads in the rest of the symbol table */
1296 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1298 /* Check if comp unit has_children.
1299 If so, read the rest of the partial symbols from this comp unit.
1300 If not, there's no more debug_info for this comp unit. */
1301 if (comp_unit_die
.has_children
)
1303 lowpc
= ((CORE_ADDR
) -1);
1304 highpc
= ((CORE_ADDR
) 0);
1306 info_ptr
= scan_partial_symbols (info_ptr
, &lowpc
, &highpc
,
1309 /* If we didn't find a lowpc, set it to highpc to avoid
1310 complaints from `maint check'. */
1311 if (lowpc
== ((CORE_ADDR
) -1))
1314 /* If the compilation unit didn't have an explicit address range,
1315 then use the information extracted from its child dies. */
1316 if (! comp_unit_die
.has_pc_info
)
1318 comp_unit_die
.lowpc
= lowpc
;
1319 comp_unit_die
.highpc
= highpc
;
1322 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1323 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1325 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1326 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1327 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1328 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1329 sort_pst_symbols (pst
);
1331 /* If there is already a psymtab or symtab for a file of this
1332 name, remove it. (If there is a symtab, more drastic things
1333 also happen.) This happens in VxWorks. */
1334 free_named_symtabs (pst
->filename
);
1336 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1337 + cu
.header
.initial_length_size
;
1339 do_cleanups (back_to_inner
);
1341 do_cleanups (back_to
);
1344 /* Read in all interesting dies to the end of the compilation unit or
1345 to the end of the current namespace. NAMESPACE is NULL if we
1346 haven't yet encountered any DW_TAG_namespace entries; otherwise,
1347 it's the name of the current namespace. In particular, it's the
1348 empty string if we're currently in the global namespace but have
1349 previously encountered a DW_TAG_namespace. */
1352 scan_partial_symbols (char *info_ptr
, CORE_ADDR
*lowpc
,
1353 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
1354 const char *namespace)
1356 struct objfile
*objfile
= cu
->objfile
;
1357 bfd
*abfd
= objfile
->obfd
;
1358 struct partial_die_info pdi
;
1360 /* Now, march along the PDI's, descending into ones which have
1361 interesting children but skipping the children of the other ones,
1362 until we reach the end of the compilation unit. */
1366 /* This flag tells whether or not info_ptr has gotten updated
1368 int info_ptr_updated
= 0;
1370 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu
);
1372 /* Anonymous namespaces have no name but have interesting
1373 children, so we need to look at them. Ditto for anonymous
1376 if (pdi
.name
!= NULL
|| pdi
.tag
== DW_TAG_namespace
1377 || pdi
.tag
== DW_TAG_enumeration_type
)
1381 case DW_TAG_subprogram
:
1382 if (pdi
.has_pc_info
)
1384 if (pdi
.lowpc
< *lowpc
)
1388 if (pdi
.highpc
> *highpc
)
1390 *highpc
= pdi
.highpc
;
1392 if (!pdi
.is_declaration
)
1394 add_partial_symbol (&pdi
, cu
, namespace);
1398 case DW_TAG_variable
:
1399 case DW_TAG_typedef
:
1400 case DW_TAG_union_type
:
1401 if (!pdi
.is_declaration
)
1403 add_partial_symbol (&pdi
, cu
, namespace);
1406 case DW_TAG_class_type
:
1407 case DW_TAG_structure_type
:
1408 if (!pdi
.is_declaration
)
1410 info_ptr
= add_partial_structure (&pdi
, info_ptr
, cu
,
1412 info_ptr_updated
= 1;
1415 case DW_TAG_enumeration_type
:
1416 if (!pdi
.is_declaration
)
1418 info_ptr
= add_partial_enumeration (&pdi
, info_ptr
, cu
,
1420 info_ptr_updated
= 1;
1423 case DW_TAG_base_type
:
1424 case DW_TAG_subrange_type
:
1425 /* File scope base type definitions are added to the partial
1427 add_partial_symbol (&pdi
, cu
, namespace);
1429 case DW_TAG_namespace
:
1430 /* We've hit a DW_TAG_namespace entry, so we know this
1431 file has been compiled using a compiler that
1432 generates them; update NAMESPACE to reflect that. */
1433 if (namespace == NULL
)
1435 info_ptr
= add_partial_namespace (&pdi
, info_ptr
, lowpc
, highpc
,
1437 info_ptr_updated
= 1;
1447 /* If the die has a sibling, skip to the sibling, unless another
1448 function has already updated info_ptr for us. */
1450 /* NOTE: carlton/2003-06-16: This is a bit hackish, but whether
1451 or not we want to update this depends on enough stuff (not
1452 only pdi.tag but also whether or not pdi.name is NULL) that
1453 this seems like the easiest way to handle the issue. */
1455 if (!info_ptr_updated
)
1456 info_ptr
= locate_pdi_sibling (&pdi
, info_ptr
, abfd
, cu
);
1463 add_partial_symbol (struct partial_die_info
*pdi
,
1464 struct dwarf2_cu
*cu
, const char *namespace)
1466 struct objfile
*objfile
= cu
->objfile
;
1468 char *actual_name
= pdi
->name
;
1469 const struct partial_symbol
*psym
= NULL
;
1472 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1474 /* If we're not in the global namespace and if the namespace name
1475 isn't encoded in a mangled actual_name, add it. */
1477 if (pdi_needs_namespace (pdi
->tag
, namespace))
1479 actual_name
= alloca (strlen (pdi
->name
) + 2 + strlen (namespace) + 1);
1480 strcpy (actual_name
, namespace);
1481 strcat (actual_name
, "::");
1482 strcat (actual_name
, pdi
->name
);
1487 case DW_TAG_subprogram
:
1488 if (pdi
->is_external
)
1490 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1491 mst_text, objfile); */
1492 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1493 VAR_DOMAIN
, LOC_BLOCK
,
1494 &objfile
->global_psymbols
,
1495 0, pdi
->lowpc
+ baseaddr
,
1496 cu
->language
, objfile
);
1500 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1501 mst_file_text, objfile); */
1502 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1503 VAR_DOMAIN
, LOC_BLOCK
,
1504 &objfile
->static_psymbols
,
1505 0, pdi
->lowpc
+ baseaddr
,
1506 cu
->language
, objfile
);
1509 case DW_TAG_variable
:
1510 if (pdi
->is_external
)
1513 Don't enter into the minimal symbol tables as there is
1514 a minimal symbol table entry from the ELF symbols already.
1515 Enter into partial symbol table if it has a location
1516 descriptor or a type.
1517 If the location descriptor is missing, new_symbol will create
1518 a LOC_UNRESOLVED symbol, the address of the variable will then
1519 be determined from the minimal symbol table whenever the variable
1521 The address for the partial symbol table entry is not
1522 used by GDB, but it comes in handy for debugging partial symbol
1526 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1527 if (pdi
->locdesc
|| pdi
->has_type
)
1528 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1529 VAR_DOMAIN
, LOC_STATIC
,
1530 &objfile
->global_psymbols
,
1532 cu
->language
, objfile
);
1536 /* Static Variable. Skip symbols without location descriptors. */
1537 if (pdi
->locdesc
== NULL
)
1539 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1540 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
1541 mst_file_data, objfile); */
1542 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1543 VAR_DOMAIN
, LOC_STATIC
,
1544 &objfile
->static_psymbols
,
1546 cu
->language
, objfile
);
1549 case DW_TAG_typedef
:
1550 case DW_TAG_base_type
:
1551 case DW_TAG_subrange_type
:
1552 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1553 VAR_DOMAIN
, LOC_TYPEDEF
,
1554 &objfile
->static_psymbols
,
1555 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1557 case DW_TAG_class_type
:
1558 case DW_TAG_structure_type
:
1559 case DW_TAG_union_type
:
1560 case DW_TAG_enumeration_type
:
1561 /* Skip aggregate types without children, these are external
1563 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
1564 static vs. global. */
1565 if (pdi
->has_children
== 0)
1567 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1568 STRUCT_DOMAIN
, LOC_TYPEDEF
,
1569 cu
->language
== language_cplus
1570 ? &objfile
->global_psymbols
1571 : &objfile
->static_psymbols
,
1572 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1574 if (cu
->language
== language_cplus
)
1576 /* For C++, these implicitly act as typedefs as well. */
1577 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1578 VAR_DOMAIN
, LOC_TYPEDEF
,
1579 &objfile
->global_psymbols
,
1580 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1583 case DW_TAG_enumerator
:
1584 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1585 VAR_DOMAIN
, LOC_CONST
,
1586 cu
->language
== language_cplus
1587 ? &objfile
->global_psymbols
1588 : &objfile
->static_psymbols
,
1589 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1595 /* Check to see if we should scan the name for possible namespace
1596 info. Only do this if this is C++, if we don't have namespace
1597 debugging info in the file, if the psym is of an appropriate type
1598 (otherwise we'll have psym == NULL), and if we actually had a
1599 mangled name to begin with. */
1601 if (cu
->language
== language_cplus
1602 && namespace == NULL
1604 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
1605 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
1609 /* Determine whether a die of type TAG living in the C++ namespace
1610 NAMESPACE needs to have the name of the namespace prepended to the
1611 name listed in the die. */
1614 pdi_needs_namespace (enum dwarf_tag tag
, const char *namespace)
1616 if (namespace == NULL
|| namespace[0] == '\0')
1621 case DW_TAG_typedef
:
1622 case DW_TAG_class_type
:
1623 case DW_TAG_structure_type
:
1624 case DW_TAG_union_type
:
1625 case DW_TAG_enumeration_type
:
1626 case DW_TAG_enumerator
:
1633 /* Read a partial die corresponding to a namespace; also, add a symbol
1634 corresponding to that namespace to the symbol table. NAMESPACE is
1635 the name of the enclosing namespace. */
1638 add_partial_namespace (struct partial_die_info
*pdi
, char *info_ptr
,
1639 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1640 struct dwarf2_cu
*cu
, const char *namespace)
1642 struct objfile
*objfile
= cu
->objfile
;
1643 const char *new_name
= pdi
->name
;
1646 /* Calculate the full name of the namespace that we just entered. */
1648 if (new_name
== NULL
)
1649 new_name
= "(anonymous namespace)";
1650 full_name
= alloca (strlen (namespace) + 2 + strlen (new_name
) + 1);
1651 strcpy (full_name
, namespace);
1652 if (*namespace != '\0')
1653 strcat (full_name
, "::");
1654 strcat (full_name
, new_name
);
1656 /* FIXME: carlton/2003-10-07: We can't just replace this by a call
1657 to add_partial_symbol, because we don't have a way to pass in the
1658 full name to that function; that might be a flaw in
1659 add_partial_symbol's interface. */
1661 add_psymbol_to_list (full_name
, strlen (full_name
),
1662 VAR_DOMAIN
, LOC_TYPEDEF
,
1663 &objfile
->global_psymbols
,
1664 0, 0, cu
->language
, objfile
);
1666 /* Now scan partial symbols in that namespace. */
1668 if (pdi
->has_children
)
1669 info_ptr
= scan_partial_symbols (info_ptr
, lowpc
, highpc
, cu
, full_name
);
1674 /* Read a partial die corresponding to a class or structure. */
1677 add_partial_structure (struct partial_die_info
*struct_pdi
, char *info_ptr
,
1678 struct dwarf2_cu
*cu
,
1679 const char *namespace)
1681 bfd
*abfd
= cu
->objfile
->obfd
;
1682 char *actual_class_name
= NULL
;
1684 if (cu
->language
== language_cplus
1685 && (namespace == NULL
|| namespace[0] == '\0')
1686 && struct_pdi
->name
!= NULL
1687 && struct_pdi
->has_children
)
1689 /* See if we can figure out if the class lives in a namespace
1690 (or is nested within another class.) We do this by looking
1691 for a member function; its demangled name will contain
1692 namespace info, if there is any. */
1694 /* NOTE: carlton/2003-10-07: Getting the info this way changes
1695 what template types look like, because the demangler
1696 frequently doesn't give the same name as the debug info. We
1697 could fix this by only using the demangled name to get the
1698 prefix (but see comment in read_structure_scope). */
1700 /* FIXME: carlton/2004-01-23: If NAMESPACE equals "", we have
1701 the appropriate debug information, so it would be nice to be
1702 able to avoid this hack. But NAMESPACE may not be the
1703 namespace where this class was defined: NAMESPACE reflects
1704 where STRUCT_PDI occurs in the tree of dies, but because of
1705 DW_AT_specification, that may not actually tell us where the
1706 class is defined. (See the comment in read_func_scope for an
1707 example of how this could occur.)
1709 Unfortunately, our current partial symtab data structures are
1710 completely unable to deal with DW_AT_specification. So, for
1711 now, the best thing to do is to get nesting information from
1712 places other than the tree structure of dies if there's any
1713 chance that a DW_AT_specification is involved. :-( */
1715 char *next_child
= info_ptr
;
1719 struct partial_die_info child_pdi
;
1721 next_child
= read_partial_die (&child_pdi
, abfd
, next_child
,
1725 if (child_pdi
.tag
== DW_TAG_subprogram
)
1727 actual_class_name
= class_name_from_physname (child_pdi
.name
);
1728 if (actual_class_name
!= NULL
)
1729 struct_pdi
->name
= actual_class_name
;
1734 next_child
= locate_pdi_sibling (&child_pdi
, next_child
,
1740 add_partial_symbol (struct_pdi
, cu
, namespace);
1741 xfree (actual_class_name
);
1743 return locate_pdi_sibling (struct_pdi
, info_ptr
, abfd
, cu
);
1746 /* Read a partial die corresponding to an enumeration type. */
1749 add_partial_enumeration (struct partial_die_info
*enum_pdi
, char *info_ptr
,
1750 struct dwarf2_cu
*cu
, const char *namespace)
1752 struct objfile
*objfile
= cu
->objfile
;
1753 bfd
*abfd
= objfile
->obfd
;
1754 struct partial_die_info pdi
;
1756 if (enum_pdi
->name
!= NULL
)
1757 add_partial_symbol (enum_pdi
, cu
, namespace);
1761 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu
);
1764 if (pdi
.tag
!= DW_TAG_enumerator
|| pdi
.name
== NULL
)
1765 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
1767 add_partial_symbol (&pdi
, cu
, namespace);
1773 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
1774 Return the corresponding abbrev, or NULL if the number is zero (indicating
1775 an empty DIE). In either case *BYTES_READ will be set to the length of
1776 the initial number. */
1778 static struct abbrev_info
*
1779 peek_die_abbrev (char *info_ptr
, int *bytes_read
, struct dwarf2_cu
*cu
)
1781 bfd
*abfd
= cu
->objfile
->obfd
;
1782 unsigned int abbrev_number
;
1783 struct abbrev_info
*abbrev
;
1785 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
1787 if (abbrev_number
== 0)
1790 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
1793 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number
,
1794 bfd_get_filename (abfd
));
1800 /* Scan the debug information for CU starting at INFO_PTR. Returns a
1801 pointer to the end of a series of DIEs, terminated by an empty
1802 DIE. Any children of the skipped DIEs will also be skipped. */
1805 skip_children (char *info_ptr
, struct dwarf2_cu
*cu
)
1807 struct abbrev_info
*abbrev
;
1808 unsigned int bytes_read
;
1812 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1814 return info_ptr
+ bytes_read
;
1816 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
1820 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
1821 should point just after the initial uleb128 of a DIE, and the
1822 abbrev corresponding to that skipped uleb128 should be passed in
1823 ABBREV. Returns a pointer to this DIE's sibling, skipping any
1827 skip_one_die (char *info_ptr
, struct abbrev_info
*abbrev
,
1828 struct dwarf2_cu
*cu
)
1830 unsigned int bytes_read
;
1831 struct attribute attr
;
1832 bfd
*abfd
= cu
->objfile
->obfd
;
1833 unsigned int form
, i
;
1835 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
1837 /* The only abbrev we care about is DW_AT_sibling. */
1838 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
1840 read_attribute (&attr
, &abbrev
->attrs
[i
],
1841 abfd
, info_ptr
, cu
);
1842 if (attr
.form
== DW_FORM_ref_addr
)
1843 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
1845 return dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
, cu
);
1848 /* If it isn't DW_AT_sibling, skip this attribute. */
1849 form
= abbrev
->attrs
[i
].form
;
1854 case DW_FORM_ref_addr
:
1855 info_ptr
+= cu
->header
.addr_size
;
1874 case DW_FORM_string
:
1875 read_string (abfd
, info_ptr
, &bytes_read
);
1876 info_ptr
+= bytes_read
;
1879 info_ptr
+= cu
->header
.offset_size
;
1882 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
1883 info_ptr
+= bytes_read
;
1885 case DW_FORM_block1
:
1886 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
1888 case DW_FORM_block2
:
1889 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
1891 case DW_FORM_block4
:
1892 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
1896 case DW_FORM_ref_udata
:
1897 info_ptr
= skip_leb128 (abfd
, info_ptr
);
1899 case DW_FORM_indirect
:
1900 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
1901 info_ptr
+= bytes_read
;
1902 /* We need to continue parsing from here, so just go back to
1904 goto skip_attribute
;
1907 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
1908 dwarf_form_name (form
),
1909 bfd_get_filename (abfd
));
1913 if (abbrev
->has_children
)
1914 return skip_children (info_ptr
, cu
);
1919 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
1920 the next DIE after ORIG_PDI. */
1923 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, char *info_ptr
,
1924 bfd
*abfd
, struct dwarf2_cu
*cu
)
1926 /* Do we know the sibling already? */
1928 if (orig_pdi
->sibling
)
1929 return orig_pdi
->sibling
;
1931 /* Are there any children to deal with? */
1933 if (!orig_pdi
->has_children
)
1936 /* Skip the children the long way. */
1938 return skip_children (info_ptr
, cu
);
1941 /* Expand this partial symbol table into a full symbol table. */
1944 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1946 /* FIXME: This is barely more than a stub. */
1951 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1957 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1958 gdb_flush (gdb_stdout
);
1961 psymtab_to_symtab_1 (pst
);
1963 /* Finish up the debug error message. */
1965 printf_filtered ("done.\n");
1971 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1973 struct objfile
*objfile
= pst
->objfile
;
1974 bfd
*abfd
= objfile
->obfd
;
1975 struct dwarf2_cu cu
;
1976 struct die_info
*dies
;
1977 unsigned long offset
;
1978 CORE_ADDR lowpc
, highpc
;
1979 struct die_info
*child_die
;
1981 struct symtab
*symtab
;
1982 struct cleanup
*back_to
;
1983 struct attribute
*attr
;
1986 /* Set local variables from the partial symbol table info. */
1987 offset
= DWARF_INFO_OFFSET (pst
);
1988 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1989 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1990 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1991 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1992 dwarf_line_size
= DWARF_LINE_SIZE (pst
);
1993 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1994 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1995 dwarf_macinfo_buffer
= DWARF_MACINFO_BUFFER (pst
);
1996 dwarf_macinfo_size
= DWARF_MACINFO_SIZE (pst
);
1997 dwarf_ranges_buffer
= DWARF_RANGES_BUFFER (pst
);
1998 dwarf_ranges_size
= DWARF_RANGES_SIZE (pst
);
1999 dwarf_loc_buffer
= DWARF_LOC_BUFFER (pst
);
2000 dwarf_loc_size
= DWARF_LOC_SIZE (pst
);
2001 info_ptr
= dwarf_info_buffer
+ offset
;
2002 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2004 /* We're in the global namespace. */
2005 processing_current_prefix
= "";
2007 obstack_init (&dwarf2_tmp_obstack
);
2008 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
2011 make_cleanup (really_free_pendings
, NULL
);
2013 cu
.objfile
= objfile
;
2015 /* read in the comp_unit header */
2016 info_ptr
= read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
2018 /* Read the abbrevs for this compilation unit */
2019 dwarf2_read_abbrevs (abfd
, &cu
);
2020 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2022 cu
.header
.offset
= offset
;
2024 cu
.list_in_scope
= &file_symbols
;
2026 dies
= read_comp_unit (info_ptr
, abfd
, &cu
);
2028 make_cleanup_free_die_list (dies
);
2030 /* Find the base address of the compilation unit for range lists and
2031 location lists. It will normally be specified by DW_AT_low_pc.
2032 In DWARF-3 draft 4, the base address could be overridden by
2033 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2034 compilation units with discontinuous ranges. */
2036 cu
.header
.base_known
= 0;
2037 cu
.header
.base_address
= 0;
2039 attr
= dwarf2_attr (dies
, DW_AT_entry_pc
, &cu
);
2042 cu
.header
.base_address
= DW_ADDR (attr
);
2043 cu
.header
.base_known
= 1;
2047 attr
= dwarf2_attr (dies
, DW_AT_low_pc
, &cu
);
2050 cu
.header
.base_address
= DW_ADDR (attr
);
2051 cu
.header
.base_known
= 1;
2055 /* Do line number decoding in read_file_scope () */
2056 process_die (dies
, &cu
);
2058 /* Some compilers don't define a DW_AT_high_pc attribute for the
2059 compilation unit. If the DW_AT_high_pc is missing, synthesize
2060 it, by scanning the DIE's below the compilation unit. */
2061 get_scope_pc_bounds (dies
, &lowpc
, &highpc
, &cu
);
2063 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2065 /* Set symtab language to language from DW_AT_language.
2066 If the compilation is from a C file generated by language preprocessors,
2067 do not set the language if it was already deduced by start_subfile. */
2069 && !(cu
.language
== language_c
&& symtab
->language
!= language_c
))
2071 symtab
->language
= cu
.language
;
2073 pst
->symtab
= symtab
;
2076 do_cleanups (back_to
);
2079 /* Process a die and its children. */
2082 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2086 case DW_TAG_padding
:
2088 case DW_TAG_compile_unit
:
2089 read_file_scope (die
, cu
);
2091 case DW_TAG_subprogram
:
2092 read_subroutine_type (die
, cu
);
2093 read_func_scope (die
, cu
);
2095 case DW_TAG_inlined_subroutine
:
2096 /* FIXME: These are ignored for now.
2097 They could be used to set breakpoints on all inlined instances
2098 of a function and make GDB `next' properly over inlined functions. */
2100 case DW_TAG_lexical_block
:
2101 case DW_TAG_try_block
:
2102 case DW_TAG_catch_block
:
2103 read_lexical_block_scope (die
, cu
);
2105 case DW_TAG_class_type
:
2106 case DW_TAG_structure_type
:
2107 case DW_TAG_union_type
:
2108 read_structure_scope (die
, cu
);
2110 case DW_TAG_enumeration_type
:
2111 read_enumeration (die
, cu
);
2113 case DW_TAG_subroutine_type
:
2114 read_subroutine_type (die
, cu
);
2116 case DW_TAG_array_type
:
2117 read_array_type (die
, cu
);
2119 case DW_TAG_pointer_type
:
2120 read_tag_pointer_type (die
, cu
);
2122 case DW_TAG_ptr_to_member_type
:
2123 read_tag_ptr_to_member_type (die
, cu
);
2125 case DW_TAG_reference_type
:
2126 read_tag_reference_type (die
, cu
);
2128 case DW_TAG_string_type
:
2129 read_tag_string_type (die
, cu
);
2131 case DW_TAG_base_type
:
2132 read_base_type (die
, cu
);
2133 if (dwarf2_attr (die
, DW_AT_name
, cu
))
2135 /* Add a typedef symbol for the base type definition. */
2136 new_symbol (die
, die
->type
, cu
);
2139 case DW_TAG_subrange_type
:
2140 read_subrange_type (die
, cu
);
2141 if (dwarf2_attr (die
, DW_AT_name
, cu
))
2143 /* Add a typedef symbol for the base type definition. */
2144 new_symbol (die
, die
->type
, cu
);
2147 case DW_TAG_common_block
:
2148 read_common_block (die
, cu
);
2150 case DW_TAG_common_inclusion
:
2152 case DW_TAG_namespace
:
2153 processing_has_namespace_info
= 1;
2154 read_namespace (die
, cu
);
2156 case DW_TAG_imported_declaration
:
2157 case DW_TAG_imported_module
:
2158 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2159 information contained in these. DW_TAG_imported_declaration
2160 dies shouldn't have children; DW_TAG_imported_module dies
2161 shouldn't in the C++ case, but conceivably could in the
2162 Fortran case, so we'll have to replace this gdb_assert if
2163 Fortran compilers start generating that info. */
2164 processing_has_namespace_info
= 1;
2165 gdb_assert (die
->child
== NULL
);
2168 new_symbol (die
, NULL
, cu
);
2174 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2176 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2180 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2182 struct objfile
*objfile
= cu
->objfile
;
2183 struct comp_unit_head
*cu_header
= &cu
->header
;
2184 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2185 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2186 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2187 struct attribute
*attr
;
2188 char *name
= "<unknown>";
2189 char *comp_dir
= NULL
;
2190 struct die_info
*child_die
;
2191 bfd
*abfd
= objfile
->obfd
;
2192 struct line_header
*line_header
= 0;
2195 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2197 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2199 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2200 from finish_block. */
2201 if (lowpc
== ((CORE_ADDR
) -1))
2206 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2209 name
= DW_STRING (attr
);
2211 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2214 comp_dir
= DW_STRING (attr
);
2217 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2218 directory, get rid of it. */
2219 char *cp
= strchr (comp_dir
, ':');
2221 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2226 if (objfile
->ei
.entry_point
>= lowpc
&&
2227 objfile
->ei
.entry_point
< highpc
)
2229 objfile
->ei
.deprecated_entry_file_lowpc
= lowpc
;
2230 objfile
->ei
.deprecated_entry_file_highpc
= highpc
;
2233 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2236 set_cu_language (DW_UNSND (attr
), cu
);
2239 /* We assume that we're processing GCC output. */
2240 processing_gcc_compilation
= 2;
2242 /* FIXME:Do something here. */
2243 if (dip
->at_producer
!= NULL
)
2245 handle_producer (dip
->at_producer
);
2249 /* The compilation unit may be in a different language or objfile,
2250 zero out all remembered fundamental types. */
2251 memset (cu
->ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
2253 start_symtab (name
, comp_dir
, lowpc
);
2254 record_debugformat ("DWARF 2");
2256 initialize_cu_func_list (cu
);
2258 /* Process all dies in compilation unit. */
2259 if (die
->child
!= NULL
)
2261 child_die
= die
->child
;
2262 while (child_die
&& child_die
->tag
)
2264 process_die (child_die
, cu
);
2265 child_die
= sibling_die (child_die
);
2269 /* Decode line number information if present. */
2270 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2273 unsigned int line_offset
= DW_UNSND (attr
);
2274 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2277 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
2278 (void *) line_header
);
2279 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
);
2283 /* Decode macro information, if present. Dwarf 2 macro information
2284 refers to information in the line number info statement program
2285 header, so we can only read it if we've read the header
2287 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2288 if (attr
&& line_header
)
2290 unsigned int macro_offset
= DW_UNSND (attr
);
2291 dwarf_decode_macros (line_header
, macro_offset
,
2292 comp_dir
, abfd
, cu
);
2294 do_cleanups (back_to
);
2298 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2299 struct dwarf2_cu
*cu
)
2301 struct function_range
*thisfn
;
2303 thisfn
= (struct function_range
*)
2304 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct function_range
));
2305 thisfn
->name
= name
;
2306 thisfn
->lowpc
= lowpc
;
2307 thisfn
->highpc
= highpc
;
2308 thisfn
->seen_line
= 0;
2309 thisfn
->next
= NULL
;
2311 if (cu
->last_fn
== NULL
)
2312 cu
->first_fn
= thisfn
;
2314 cu
->last_fn
->next
= thisfn
;
2316 cu
->last_fn
= thisfn
;
2320 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2322 struct objfile
*objfile
= cu
->objfile
;
2323 struct context_stack
*new;
2326 struct die_info
*child_die
;
2327 struct attribute
*attr
;
2329 const char *previous_prefix
= processing_current_prefix
;
2330 struct cleanup
*back_to
= NULL
;
2333 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2335 name
= dwarf2_linkage_name (die
, cu
);
2337 /* Ignore functions with missing or empty names and functions with
2338 missing or invalid low and high pc attributes. */
2339 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2342 if (cu
->language
== language_cplus
)
2344 struct die_info
*spec_die
= die_specification (die
, cu
);
2346 /* NOTE: carlton/2004-01-23: We have to be careful in the
2347 presence of DW_AT_specification. For example, with GCC 3.4,
2352 // Definition of N::foo.
2356 then we'll have a tree of DIEs like this:
2358 1: DW_TAG_compile_unit
2359 2: DW_TAG_namespace // N
2360 3: DW_TAG_subprogram // declaration of N::foo
2361 4: DW_TAG_subprogram // definition of N::foo
2362 DW_AT_specification // refers to die #3
2364 Thus, when processing die #4, we have to pretend that we're
2365 in the context of its DW_AT_specification, namely the contex
2368 if (spec_die
!= NULL
)
2370 char *specification_prefix
= determine_prefix (spec_die
, cu
);
2371 processing_current_prefix
= specification_prefix
;
2372 back_to
= make_cleanup (xfree
, specification_prefix
);
2379 /* Record the function range for dwarf_decode_lines. */
2380 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
2382 if (objfile
->ei
.entry_point
>= lowpc
&&
2383 objfile
->ei
.entry_point
< highpc
)
2385 objfile
->ei
.entry_func_lowpc
= lowpc
;
2386 objfile
->ei
.entry_func_highpc
= highpc
;
2389 new = push_context (0, lowpc
);
2390 new->name
= new_symbol (die
, die
->type
, cu
);
2392 /* If there is a location expression for DW_AT_frame_base, record
2394 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
2396 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
2397 expression is being recorded directly in the function's symbol
2398 and not in a separate frame-base object. I guess this hack is
2399 to avoid adding some sort of frame-base adjunct/annex to the
2400 function's symbol :-(. The problem with doing this is that it
2401 results in a function symbol with a location expression that
2402 has nothing to do with the location of the function, ouch! The
2403 relationship should be: a function's symbol has-a frame base; a
2404 frame-base has-a location expression. */
2405 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
2407 cu
->list_in_scope
= &local_symbols
;
2409 if (die
->child
!= NULL
)
2411 child_die
= die
->child
;
2412 while (child_die
&& child_die
->tag
)
2414 process_die (child_die
, cu
);
2415 child_die
= sibling_die (child_die
);
2419 new = pop_context ();
2420 /* Make a block for the local symbols within. */
2421 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2422 lowpc
, highpc
, objfile
);
2424 /* In C++, we can have functions nested inside functions (e.g., when
2425 a function declares a class that has methods). This means that
2426 when we finish processing a function scope, we may need to go
2427 back to building a containing block's symbol lists. */
2428 local_symbols
= new->locals
;
2429 param_symbols
= new->params
;
2431 /* If we've finished processing a top-level function, subsequent
2432 symbols go in the file symbol list. */
2433 if (outermost_context_p ())
2434 cu
->list_in_scope
= &file_symbols
;
2436 processing_current_prefix
= previous_prefix
;
2437 if (back_to
!= NULL
)
2438 do_cleanups (back_to
);
2441 /* Process all the DIES contained within a lexical block scope. Start
2442 a new scope, process the dies, and then close the scope. */
2445 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2447 struct objfile
*objfile
= cu
->objfile
;
2448 struct context_stack
*new;
2449 CORE_ADDR lowpc
, highpc
;
2450 struct die_info
*child_die
;
2453 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2455 /* Ignore blocks with missing or invalid low and high pc attributes. */
2456 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2457 as multiple lexical blocks? Handling children in a sane way would
2458 be nasty. Might be easier to properly extend generic blocks to
2460 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2465 push_context (0, lowpc
);
2466 if (die
->child
!= NULL
)
2468 child_die
= die
->child
;
2469 while (child_die
&& child_die
->tag
)
2471 process_die (child_die
, cu
);
2472 child_die
= sibling_die (child_die
);
2475 new = pop_context ();
2477 if (local_symbols
!= NULL
)
2479 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
2482 local_symbols
= new->locals
;
2485 /* Get low and high pc attributes from a die. Return 1 if the attributes
2486 are present and valid, otherwise, return 0. Return -1 if the range is
2487 discontinuous, i.e. derived from DW_AT_ranges information. */
2489 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
2490 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
2492 struct objfile
*objfile
= cu
->objfile
;
2493 struct comp_unit_head
*cu_header
= &cu
->header
;
2494 struct attribute
*attr
;
2495 bfd
*obfd
= objfile
->obfd
;
2500 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
2503 high
= DW_ADDR (attr
);
2504 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
2506 low
= DW_ADDR (attr
);
2508 /* Found high w/o low attribute. */
2511 /* Found consecutive range of addresses. */
2516 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
2519 unsigned int addr_size
= cu_header
->addr_size
;
2520 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
2521 /* Value of the DW_AT_ranges attribute is the offset in the
2522 .debug_ranges section. */
2523 unsigned int offset
= DW_UNSND (attr
);
2524 /* Base address selection entry. */
2532 found_base
= cu_header
->base_known
;
2533 base
= cu_header
->base_address
;
2535 if (offset
>= dwarf_ranges_size
)
2537 complaint (&symfile_complaints
,
2538 "Offset %d out of bounds for DW_AT_ranges attribute",
2542 buffer
= dwarf_ranges_buffer
+ offset
;
2544 /* Read in the largest possible address. */
2545 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
2546 if ((marker
& mask
) == mask
)
2548 /* If we found the largest possible address, then
2549 read the base address. */
2550 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2551 buffer
+= 2 * addr_size
;
2552 offset
+= 2 * addr_size
;
2560 CORE_ADDR range_beginning
, range_end
;
2562 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
2563 buffer
+= addr_size
;
2564 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
2565 buffer
+= addr_size
;
2566 offset
+= 2 * addr_size
;
2568 /* An end of list marker is a pair of zero addresses. */
2569 if (range_beginning
== 0 && range_end
== 0)
2570 /* Found the end of list entry. */
2573 /* Each base address selection entry is a pair of 2 values.
2574 The first is the largest possible address, the second is
2575 the base address. Check for a base address here. */
2576 if ((range_beginning
& mask
) == mask
)
2578 /* If we found the largest possible address, then
2579 read the base address. */
2580 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2587 /* We have no valid base address for the ranges
2589 complaint (&symfile_complaints
,
2590 "Invalid .debug_ranges data (no base address)");
2594 range_beginning
+= base
;
2597 /* FIXME: This is recording everything as a low-high
2598 segment of consecutive addresses. We should have a
2599 data structure for discontiguous block ranges
2603 low
= range_beginning
;
2609 if (range_beginning
< low
)
2610 low
= range_beginning
;
2611 if (range_end
> high
)
2617 /* If the first entry is an end-of-list marker, the range
2618 describes an empty scope, i.e. no instructions. */
2628 /* When using the GNU linker, .gnu.linkonce. sections are used to
2629 eliminate duplicate copies of functions and vtables and such.
2630 The linker will arbitrarily choose one and discard the others.
2631 The AT_*_pc values for such functions refer to local labels in
2632 these sections. If the section from that file was discarded, the
2633 labels are not in the output, so the relocs get a value of 0.
2634 If this is a discarded function, mark the pc bounds as invalid,
2635 so that GDB will ignore it. */
2636 if (low
== 0 && (bfd_get_file_flags (obfd
) & HAS_RELOC
) == 0)
2644 /* Get the low and high pc's represented by the scope DIE, and store
2645 them in *LOWPC and *HIGHPC. If the correct values can't be
2646 determined, set *LOWPC to -1 and *HIGHPC to 0. */
2649 get_scope_pc_bounds (struct die_info
*die
,
2650 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2651 struct dwarf2_cu
*cu
)
2653 CORE_ADDR best_low
= (CORE_ADDR
) -1;
2654 CORE_ADDR best_high
= (CORE_ADDR
) 0;
2655 CORE_ADDR current_low
, current_high
;
2657 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
2659 best_low
= current_low
;
2660 best_high
= current_high
;
2664 struct die_info
*child
= die
->child
;
2666 while (child
&& child
->tag
)
2668 switch (child
->tag
) {
2669 case DW_TAG_subprogram
:
2670 if (dwarf2_get_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
))
2672 best_low
= min (best_low
, current_low
);
2673 best_high
= max (best_high
, current_high
);
2676 case DW_TAG_namespace
:
2677 /* FIXME: carlton/2004-01-16: Should we do this for
2678 DW_TAG_class_type/DW_TAG_structure_type, too? I think
2679 that current GCC's always emit the DIEs corresponding
2680 to definitions of methods of classes as children of a
2681 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
2682 the DIEs giving the declarations, which could be
2683 anywhere). But I don't see any reason why the
2684 standards says that they have to be there. */
2685 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
2687 if (current_low
!= ((CORE_ADDR
) -1))
2689 best_low
= min (best_low
, current_low
);
2690 best_high
= max (best_high
, current_high
);
2698 child
= sibling_die (child
);
2703 *highpc
= best_high
;
2706 /* Add an aggregate field to the field list. */
2709 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
2710 struct dwarf2_cu
*cu
)
2712 struct objfile
*objfile
= cu
->objfile
;
2713 struct nextfield
*new_field
;
2714 struct attribute
*attr
;
2716 char *fieldname
= "";
2718 /* Allocate a new field list entry and link it in. */
2719 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2720 make_cleanup (xfree
, new_field
);
2721 memset (new_field
, 0, sizeof (struct nextfield
));
2722 new_field
->next
= fip
->fields
;
2723 fip
->fields
= new_field
;
2726 /* Handle accessibility and virtuality of field.
2727 The default accessibility for members is public, the default
2728 accessibility for inheritance is private. */
2729 if (die
->tag
!= DW_TAG_inheritance
)
2730 new_field
->accessibility
= DW_ACCESS_public
;
2732 new_field
->accessibility
= DW_ACCESS_private
;
2733 new_field
->virtuality
= DW_VIRTUALITY_none
;
2735 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
2737 new_field
->accessibility
= DW_UNSND (attr
);
2738 if (new_field
->accessibility
!= DW_ACCESS_public
)
2739 fip
->non_public_fields
= 1;
2740 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
2742 new_field
->virtuality
= DW_UNSND (attr
);
2744 fp
= &new_field
->field
;
2746 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
2748 /* Data member other than a C++ static data member. */
2750 /* Get type of field. */
2751 fp
->type
= die_type (die
, cu
);
2753 FIELD_STATIC_KIND (*fp
) = 0;
2755 /* Get bit size of field (zero if none). */
2756 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
2759 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
2763 FIELD_BITSIZE (*fp
) = 0;
2766 /* Get bit offset of field. */
2767 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
2770 FIELD_BITPOS (*fp
) =
2771 decode_locdesc (DW_BLOCK (attr
), cu
) * bits_per_byte
;
2774 FIELD_BITPOS (*fp
) = 0;
2775 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
2778 if (BITS_BIG_ENDIAN
)
2780 /* For big endian bits, the DW_AT_bit_offset gives the
2781 additional bit offset from the MSB of the containing
2782 anonymous object to the MSB of the field. We don't
2783 have to do anything special since we don't need to
2784 know the size of the anonymous object. */
2785 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
2789 /* For little endian bits, compute the bit offset to the
2790 MSB of the anonymous object, subtract off the number of
2791 bits from the MSB of the field to the MSB of the
2792 object, and then subtract off the number of bits of
2793 the field itself. The result is the bit offset of
2794 the LSB of the field. */
2796 int bit_offset
= DW_UNSND (attr
);
2798 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
2801 /* The size of the anonymous object containing
2802 the bit field is explicit, so use the
2803 indicated size (in bytes). */
2804 anonymous_size
= DW_UNSND (attr
);
2808 /* The size of the anonymous object containing
2809 the bit field must be inferred from the type
2810 attribute of the data member containing the
2812 anonymous_size
= TYPE_LENGTH (fp
->type
);
2814 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2815 - bit_offset
- FIELD_BITSIZE (*fp
);
2819 /* Get name of field. */
2820 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2821 if (attr
&& DW_STRING (attr
))
2822 fieldname
= DW_STRING (attr
);
2824 /* The name is already allocated along with this objfile, so we don't
2825 need to duplicate it for the type. */
2826 fp
->name
= fieldname
;
2828 /* Change accessibility for artificial fields (e.g. virtual table
2829 pointer or virtual base class pointer) to private. */
2830 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
2832 new_field
->accessibility
= DW_ACCESS_private
;
2833 fip
->non_public_fields
= 1;
2836 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
2838 /* C++ static member. */
2840 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2841 is a declaration, but all versions of G++ as of this writing
2842 (so through at least 3.2.1) incorrectly generate
2843 DW_TAG_variable tags. */
2847 /* Get name of field. */
2848 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2849 if (attr
&& DW_STRING (attr
))
2850 fieldname
= DW_STRING (attr
);
2854 /* Get physical name. */
2855 physname
= dwarf2_linkage_name (die
, cu
);
2857 /* The name is already allocated along with this objfile, so we don't
2858 need to duplicate it for the type. */
2859 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
2860 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2861 FIELD_NAME (*fp
) = fieldname
;
2863 else if (die
->tag
== DW_TAG_inheritance
)
2865 /* C++ base class field. */
2866 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
2868 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
2870 FIELD_BITSIZE (*fp
) = 0;
2871 FIELD_STATIC_KIND (*fp
) = 0;
2872 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2873 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2874 fip
->nbaseclasses
++;
2878 /* Create the vector of fields, and attach it to the type. */
2881 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
2882 struct dwarf2_cu
*cu
)
2884 int nfields
= fip
->nfields
;
2886 /* Record the field count, allocate space for the array of fields,
2887 and create blank accessibility bitfields if necessary. */
2888 TYPE_NFIELDS (type
) = nfields
;
2889 TYPE_FIELDS (type
) = (struct field
*)
2890 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2891 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2893 if (fip
->non_public_fields
)
2895 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2897 TYPE_FIELD_PRIVATE_BITS (type
) =
2898 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2899 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2901 TYPE_FIELD_PROTECTED_BITS (type
) =
2902 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2903 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2905 TYPE_FIELD_IGNORE_BITS (type
) =
2906 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2907 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2910 /* If the type has baseclasses, allocate and clear a bit vector for
2911 TYPE_FIELD_VIRTUAL_BITS. */
2912 if (fip
->nbaseclasses
)
2914 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2917 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2918 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2919 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2920 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2921 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2924 /* Copy the saved-up fields into the field vector. Start from the head
2925 of the list, adding to the tail of the field array, so that they end
2926 up in the same order in the array in which they were added to the list. */
2927 while (nfields
-- > 0)
2929 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2930 switch (fip
->fields
->accessibility
)
2932 case DW_ACCESS_private
:
2933 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2936 case DW_ACCESS_protected
:
2937 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2940 case DW_ACCESS_public
:
2944 /* Unknown accessibility. Complain and treat it as public. */
2946 complaint (&symfile_complaints
, "unsupported accessibility %d",
2947 fip
->fields
->accessibility
);
2951 if (nfields
< fip
->nbaseclasses
)
2953 switch (fip
->fields
->virtuality
)
2955 case DW_VIRTUALITY_virtual
:
2956 case DW_VIRTUALITY_pure_virtual
:
2957 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2961 fip
->fields
= fip
->fields
->next
;
2965 /* Add a member function to the proper fieldlist. */
2968 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2969 struct type
*type
, struct dwarf2_cu
*cu
)
2971 struct objfile
*objfile
= cu
->objfile
;
2972 struct attribute
*attr
;
2973 struct fnfieldlist
*flp
;
2975 struct fn_field
*fnp
;
2978 struct nextfnfield
*new_fnfield
;
2980 /* Get name of member function. */
2981 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2982 if (attr
&& DW_STRING (attr
))
2983 fieldname
= DW_STRING (attr
);
2987 /* Get the mangled name. */
2988 physname
= dwarf2_linkage_name (die
, cu
);
2990 /* Look up member function name in fieldlist. */
2991 for (i
= 0; i
< fip
->nfnfields
; i
++)
2993 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
2997 /* Create new list element if necessary. */
2998 if (i
< fip
->nfnfields
)
2999 flp
= &fip
->fnfieldlists
[i
];
3002 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3004 fip
->fnfieldlists
= (struct fnfieldlist
*)
3005 xrealloc (fip
->fnfieldlists
,
3006 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3007 * sizeof (struct fnfieldlist
));
3008 if (fip
->nfnfields
== 0)
3009 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3011 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3012 flp
->name
= fieldname
;
3018 /* Create a new member function field and chain it to the field list
3020 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3021 make_cleanup (xfree
, new_fnfield
);
3022 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3023 new_fnfield
->next
= flp
->head
;
3024 flp
->head
= new_fnfield
;
3027 /* Fill in the member function field info. */
3028 fnp
= &new_fnfield
->fnfield
;
3029 /* The name is already allocated along with this objfile, so we don't
3030 need to duplicate it for the type. */
3031 fnp
->physname
= physname
? physname
: "";
3032 fnp
->type
= alloc_type (objfile
);
3033 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
3035 int nparams
= TYPE_NFIELDS (die
->type
);
3037 /* TYPE is the domain of this method, and DIE->TYPE is the type
3038 of the method itself (TYPE_CODE_METHOD). */
3039 smash_to_method_type (fnp
->type
, type
,
3040 TYPE_TARGET_TYPE (die
->type
),
3041 TYPE_FIELDS (die
->type
),
3042 TYPE_NFIELDS (die
->type
),
3043 TYPE_VARARGS (die
->type
));
3045 /* Handle static member functions.
3046 Dwarf2 has no clean way to discern C++ static and non-static
3047 member functions. G++ helps GDB by marking the first
3048 parameter for non-static member functions (which is the
3049 this pointer) as artificial. We obtain this information
3050 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3051 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
3052 fnp
->voffset
= VOFFSET_STATIC
;
3055 complaint (&symfile_complaints
, "member function type missing for '%s'",
3058 /* Get fcontext from DW_AT_containing_type if present. */
3059 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3060 fnp
->fcontext
= die_containing_type (die
, cu
);
3062 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3063 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3065 /* Get accessibility. */
3066 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3069 switch (DW_UNSND (attr
))
3071 case DW_ACCESS_private
:
3072 fnp
->is_private
= 1;
3074 case DW_ACCESS_protected
:
3075 fnp
->is_protected
= 1;
3080 /* Check for artificial methods. */
3081 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3082 if (attr
&& DW_UNSND (attr
) != 0)
3083 fnp
->is_artificial
= 1;
3085 /* Get index in virtual function table if it is a virtual member function. */
3086 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3089 /* Support the .debug_loc offsets */
3090 if (attr_form_is_block (attr
))
3092 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3094 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3096 dwarf2_complex_location_expr_complaint ();
3100 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3106 /* Create the vector of member function fields, and attach it to the type. */
3109 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3110 struct dwarf2_cu
*cu
)
3112 struct fnfieldlist
*flp
;
3113 int total_length
= 0;
3116 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3117 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3118 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3120 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3122 struct nextfnfield
*nfp
= flp
->head
;
3123 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3126 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3127 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3128 fn_flp
->fn_fields
= (struct fn_field
*)
3129 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3130 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3131 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3133 total_length
+= flp
->length
;
3136 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3137 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3140 /* Called when we find the DIE that starts a structure or union scope
3141 (definition) to process all dies that define the members of the
3144 NOTE: we need to call struct_type regardless of whether or not the
3145 DIE has an at_name attribute, since it might be an anonymous
3146 structure or union. This gets the type entered into our set of
3149 However, if the structure is incomplete (an opaque struct/union)
3150 then suppress creating a symbol table entry for it since gdb only
3151 wants to find the one with the complete definition. Note that if
3152 it is complete, we just call new_symbol, which does it's own
3153 checking about whether the struct/union is anonymous or not (and
3154 suppresses creating a symbol table entry itself). */
3157 read_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3159 struct objfile
*objfile
= cu
->objfile
;
3161 struct attribute
*attr
;
3163 const char *previous_prefix
= processing_current_prefix
;
3164 struct cleanup
*back_to
= NULL
;
3165 /* This says whether or not we want to try to update the structure's
3166 name to include enclosing namespace/class information, if
3168 int need_to_update_name
= 0;
3170 type
= alloc_type (objfile
);
3172 INIT_CPLUS_SPECIFIC (type
);
3173 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3174 if (attr
&& DW_STRING (attr
))
3176 name
= DW_STRING (attr
);
3178 if (cu
->language
== language_cplus
)
3180 struct die_info
*spec_die
= die_specification (die
, cu
);
3182 if (spec_die
!= NULL
)
3184 char *specification_prefix
= determine_prefix (spec_die
, cu
);
3185 processing_current_prefix
= specification_prefix
;
3186 back_to
= make_cleanup (xfree
, specification_prefix
);
3190 if (processing_has_namespace_info
)
3192 /* FIXME: carlton/2003-11-10: This variable exists only for
3193 const-correctness reasons. When I tried to change
3194 TYPE_TAG_NAME to be a const char *, I ran into a cascade
3195 of changes which would have forced decode_line_1 to take
3197 char *new_prefix
= obconcat (&objfile
->objfile_obstack
,
3198 processing_current_prefix
,
3199 processing_current_prefix
[0] == '\0'
3202 TYPE_TAG_NAME (type
) = new_prefix
;
3203 processing_current_prefix
= new_prefix
;
3207 /* The name is already allocated along with this objfile, so
3208 we don't need to duplicate it for the type. */
3209 TYPE_TAG_NAME (type
) = name
;
3210 need_to_update_name
= (cu
->language
== language_cplus
);
3214 if (die
->tag
== DW_TAG_structure_type
)
3216 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
3218 else if (die
->tag
== DW_TAG_union_type
)
3220 TYPE_CODE (type
) = TYPE_CODE_UNION
;
3224 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
3226 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
3229 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3232 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3236 TYPE_LENGTH (type
) = 0;
3239 /* We need to add the type field to the die immediately so we don't
3240 infinitely recurse when dealing with pointers to the structure
3241 type within the structure itself. */
3244 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
3246 struct field_info fi
;
3247 struct die_info
*child_die
;
3248 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
3250 memset (&fi
, 0, sizeof (struct field_info
));
3252 child_die
= die
->child
;
3254 while (child_die
&& child_die
->tag
)
3256 if (child_die
->tag
== DW_TAG_member
3257 || child_die
->tag
== DW_TAG_variable
)
3259 /* NOTE: carlton/2002-11-05: A C++ static data member
3260 should be a DW_TAG_member that is a declaration, but
3261 all versions of G++ as of this writing (so through at
3262 least 3.2.1) incorrectly generate DW_TAG_variable
3263 tags for them instead. */
3264 dwarf2_add_field (&fi
, child_die
, cu
);
3266 else if (child_die
->tag
== DW_TAG_subprogram
)
3268 /* C++ member function. */
3269 process_die (child_die
, cu
);
3270 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
3271 if (need_to_update_name
)
3273 /* The demangled names of member functions contain
3274 information about enclosing namespaces/classes,
3277 /* FIXME: carlton/2003-11-10: The excessive
3278 demangling here is a bit wasteful, as is the
3279 memory usage for names. */
3281 /* NOTE: carlton/2003-11-10: As commented in
3282 add_partial_structure, the demangler sometimes
3283 prints the type info in a different form from the
3284 debug info. We could solve this by using the
3285 demangled name to get the prefix; if doing so,
3286 however, we'd need to be careful when reading a
3287 class that's nested inside a template class.
3288 That would also cause problems when trying to
3289 determine RTTI information, since we use the
3290 demangler to determine the appropriate class
3292 char *actual_class_name
3293 = class_name_from_physname (dwarf2_linkage_name
3295 if (actual_class_name
!= NULL
3296 && strcmp (actual_class_name
, name
) != 0)
3298 TYPE_TAG_NAME (type
)
3299 = obsavestring (actual_class_name
,
3300 strlen (actual_class_name
),
3301 &objfile
->objfile_obstack
);
3303 xfree (actual_class_name
);
3304 need_to_update_name
= 0;
3307 else if (child_die
->tag
== DW_TAG_inheritance
)
3309 /* C++ base class field. */
3310 dwarf2_add_field (&fi
, child_die
, cu
);
3314 process_die (child_die
, cu
);
3316 child_die
= sibling_die (child_die
);
3319 /* Attach fields and member functions to the type. */
3321 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
3324 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
3326 /* Get the type which refers to the base class (possibly this
3327 class itself) which contains the vtable pointer for the current
3328 class from the DW_AT_containing_type attribute. */
3330 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3332 struct type
*t
= die_containing_type (die
, cu
);
3334 TYPE_VPTR_BASETYPE (type
) = t
;
3337 static const char vptr_name
[] =
3338 {'_', 'v', 'p', 't', 'r', '\0'};
3341 /* Our own class provides vtbl ptr. */
3342 for (i
= TYPE_NFIELDS (t
) - 1;
3343 i
>= TYPE_N_BASECLASSES (t
);
3346 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
3348 if ((strncmp (fieldname
, vptr_name
,
3349 strlen (vptr_name
) - 1)
3351 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
3353 TYPE_VPTR_FIELDNO (type
) = i
;
3358 /* Complain if virtual function table field not found. */
3359 if (i
< TYPE_N_BASECLASSES (t
))
3360 complaint (&symfile_complaints
,
3361 "virtual function table pointer not found when defining class '%s'",
3362 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
3367 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3372 new_symbol (die
, type
, cu
);
3374 do_cleanups (back_to
);
3378 /* No children, must be stub. */
3379 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
3382 processing_current_prefix
= previous_prefix
;
3383 if (back_to
!= NULL
)
3384 do_cleanups (back_to
);
3387 /* Given a pointer to a die which begins an enumeration, process all
3388 the dies that define the members of the enumeration.
3390 This will be much nicer in draft 6 of the DWARF spec when our
3391 members will be dies instead squished into the DW_AT_element_list
3394 NOTE: We reverse the order of the element list. */
3397 read_enumeration (struct die_info
*die
, struct dwarf2_cu
*cu
)
3399 struct objfile
*objfile
= cu
->objfile
;
3400 struct die_info
*child_die
;
3402 struct field
*fields
;
3403 struct attribute
*attr
;
3406 int unsigned_enum
= 1;
3408 type
= alloc_type (objfile
);
3410 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
3411 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3412 if (attr
&& DW_STRING (attr
))
3414 char *name
= DW_STRING (attr
);
3416 if (processing_has_namespace_info
)
3418 TYPE_TAG_NAME (type
) = obconcat (&objfile
->objfile_obstack
,
3419 processing_current_prefix
,
3420 processing_current_prefix
[0] == '\0'
3426 /* The name is already allocated along with this objfile, so
3427 we don't need to duplicate it for the type. */
3428 TYPE_TAG_NAME (type
) = name
;
3432 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3435 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3439 TYPE_LENGTH (type
) = 0;
3444 if (die
->child
!= NULL
)
3446 child_die
= die
->child
;
3447 while (child_die
&& child_die
->tag
)
3449 if (child_die
->tag
!= DW_TAG_enumerator
)
3451 process_die (child_die
, cu
);
3455 attr
= dwarf2_attr (child_die
, DW_AT_name
, cu
);
3458 sym
= new_symbol (child_die
, type
, cu
);
3459 if (SYMBOL_VALUE (sym
) < 0)
3462 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3464 fields
= (struct field
*)
3466 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
3467 * sizeof (struct field
));
3470 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
3471 FIELD_TYPE (fields
[num_fields
]) = NULL
;
3472 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
3473 FIELD_BITSIZE (fields
[num_fields
]) = 0;
3474 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
3480 child_die
= sibling_die (child_die
);
3485 TYPE_NFIELDS (type
) = num_fields
;
3486 TYPE_FIELDS (type
) = (struct field
*)
3487 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
3488 memcpy (TYPE_FIELDS (type
), fields
,
3489 sizeof (struct field
) * num_fields
);
3493 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
3496 new_symbol (die
, type
, cu
);
3499 /* Extract all information from a DW_TAG_array_type DIE and put it in
3500 the DIE's type field. For now, this only handles one dimensional
3504 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3506 struct objfile
*objfile
= cu
->objfile
;
3507 struct die_info
*child_die
;
3508 struct type
*type
= NULL
;
3509 struct type
*element_type
, *range_type
, *index_type
;
3510 struct type
**range_types
= NULL
;
3511 struct attribute
*attr
;
3513 struct cleanup
*back_to
;
3515 /* Return if we've already decoded this type. */
3521 element_type
= die_type (die
, cu
);
3523 /* Irix 6.2 native cc creates array types without children for
3524 arrays with unspecified length. */
3525 if (die
->child
== NULL
)
3527 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
3528 range_type
= create_range_type (NULL
, index_type
, 0, -1);
3529 die
->type
= create_array_type (NULL
, element_type
, range_type
);
3533 back_to
= make_cleanup (null_cleanup
, NULL
);
3534 child_die
= die
->child
;
3535 while (child_die
&& child_die
->tag
)
3537 if (child_die
->tag
== DW_TAG_subrange_type
)
3539 read_subrange_type (child_die
, cu
);
3541 if (child_die
->type
!= NULL
)
3543 /* The range type was succesfully read. Save it for
3544 the array type creation. */
3545 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
3547 range_types
= (struct type
**)
3548 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
3549 * sizeof (struct type
*));
3551 make_cleanup (free_current_contents
, &range_types
);
3553 range_types
[ndim
++] = child_die
->type
;
3556 child_die
= sibling_die (child_die
);
3559 /* Dwarf2 dimensions are output from left to right, create the
3560 necessary array types in backwards order. */
3561 type
= element_type
;
3563 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
3565 /* Understand Dwarf2 support for vector types (like they occur on
3566 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3567 array type. This is not part of the Dwarf2/3 standard yet, but a
3568 custom vendor extension. The main difference between a regular
3569 array and the vector variant is that vectors are passed by value
3571 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
3573 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
3575 do_cleanups (back_to
);
3577 /* Install the type in the die. */
3581 /* First cut: install each common block member as a global variable. */
3584 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
3586 struct die_info
*child_die
;
3587 struct attribute
*attr
;
3589 CORE_ADDR base
= (CORE_ADDR
) 0;
3591 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
3594 /* Support the .debug_loc offsets */
3595 if (attr_form_is_block (attr
))
3597 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
3599 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3601 dwarf2_complex_location_expr_complaint ();
3605 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3606 "common block member");
3609 if (die
->child
!= NULL
)
3611 child_die
= die
->child
;
3612 while (child_die
&& child_die
->tag
)
3614 sym
= new_symbol (child_die
, NULL
, cu
);
3615 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
3618 SYMBOL_VALUE_ADDRESS (sym
) =
3619 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
3620 add_symbol_to_list (sym
, &global_symbols
);
3622 child_die
= sibling_die (child_die
);
3627 /* Read a C++ namespace. */
3630 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
3632 struct objfile
*objfile
= cu
->objfile
;
3633 const char *previous_prefix
= processing_current_prefix
;
3636 struct die_info
*current_die
;
3638 name
= namespace_name (die
, &is_anonymous
, cu
);
3640 /* Now build the name of the current namespace. */
3642 if (previous_prefix
[0] == '\0')
3644 processing_current_prefix
= name
;
3648 /* We need temp_name around because processing_current_prefix
3649 is a const char *. */
3650 char *temp_name
= alloca (strlen (previous_prefix
)
3651 + 2 + strlen(name
) + 1);
3652 strcpy (temp_name
, previous_prefix
);
3653 strcat (temp_name
, "::");
3654 strcat (temp_name
, name
);
3656 processing_current_prefix
= temp_name
;
3659 /* Add a symbol associated to this if we haven't seen the namespace
3660 before. Also, add a using directive if it's an anonymous
3663 if (dwarf2_extension (die
, cu
) == NULL
)
3667 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
3668 this cast will hopefully become unnecessary. */
3669 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
3670 (char *) processing_current_prefix
,
3672 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
3674 new_symbol (die
, type
, cu
);
3677 cp_add_using_directive (processing_current_prefix
,
3678 strlen (previous_prefix
),
3679 strlen (processing_current_prefix
));
3682 if (die
->child
!= NULL
)
3684 struct die_info
*child_die
= die
->child
;
3686 while (child_die
&& child_die
->tag
)
3688 process_die (child_die
, cu
);
3689 child_die
= sibling_die (child_die
);
3693 processing_current_prefix
= previous_prefix
;
3696 /* Return the name of the namespace represented by DIE. Set
3697 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
3701 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
3703 struct die_info
*current_die
;
3704 const char *name
= NULL
;
3706 /* Loop through the extensions until we find a name. */
3708 for (current_die
= die
;
3709 current_die
!= NULL
;
3710 current_die
= dwarf2_extension (die
, cu
))
3712 name
= dwarf2_name (current_die
, cu
);
3717 /* Is it an anonymous namespace? */
3719 *is_anonymous
= (name
== NULL
);
3721 name
= "(anonymous namespace)";
3726 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3727 the user defined type vector. */
3730 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3732 struct comp_unit_head
*cu_header
= &cu
->header
;
3734 struct attribute
*attr_byte_size
;
3735 struct attribute
*attr_address_class
;
3736 int byte_size
, addr_class
;
3743 type
= lookup_pointer_type (die_type (die
, cu
));
3745 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3747 byte_size
= DW_UNSND (attr_byte_size
);
3749 byte_size
= cu_header
->addr_size
;
3751 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
3752 if (attr_address_class
)
3753 addr_class
= DW_UNSND (attr_address_class
);
3755 addr_class
= DW_ADDR_none
;
3757 /* If the pointer size or address class is different than the
3758 default, create a type variant marked as such and set the
3759 length accordingly. */
3760 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
3762 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3766 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
3767 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
3768 type
= make_type_with_address_space (type
, type_flags
);
3770 else if (TYPE_LENGTH (type
) != byte_size
)
3772 complaint (&symfile_complaints
, "invalid pointer size %d", byte_size
);
3775 /* Should we also complain about unhandled address classes? */
3779 TYPE_LENGTH (type
) = byte_size
;
3783 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3784 the user defined type vector. */
3787 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3789 struct objfile
*objfile
= cu
->objfile
;
3791 struct type
*to_type
;
3792 struct type
*domain
;
3799 type
= alloc_type (objfile
);
3800 to_type
= die_type (die
, cu
);
3801 domain
= die_containing_type (die
, cu
);
3802 smash_to_member_type (type
, domain
, to_type
);
3807 /* Extract all information from a DW_TAG_reference_type DIE and add to
3808 the user defined type vector. */
3811 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3813 struct comp_unit_head
*cu_header
= &cu
->header
;
3815 struct attribute
*attr
;
3822 type
= lookup_reference_type (die_type (die
, cu
));
3823 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3826 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3830 TYPE_LENGTH (type
) = cu_header
->addr_size
;
3836 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3838 struct type
*base_type
;
3845 base_type
= die_type (die
, cu
);
3846 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
3850 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3852 struct type
*base_type
;
3859 base_type
= die_type (die
, cu
);
3860 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
3863 /* Extract all information from a DW_TAG_string_type DIE and add to
3864 the user defined type vector. It isn't really a user defined type,
3865 but it behaves like one, with other DIE's using an AT_user_def_type
3866 attribute to reference it. */
3869 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3871 struct objfile
*objfile
= cu
->objfile
;
3872 struct type
*type
, *range_type
, *index_type
, *char_type
;
3873 struct attribute
*attr
;
3874 unsigned int length
;
3881 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
3884 length
= DW_UNSND (attr
);
3888 /* check for the DW_AT_byte_size attribute */
3889 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3892 length
= DW_UNSND (attr
);
3899 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
3900 range_type
= create_range_type (NULL
, index_type
, 1, length
);
3901 if (cu
->language
== language_fortran
)
3903 /* Need to create a unique string type for bounds
3905 type
= create_string_type (0, range_type
);
3909 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
, cu
);
3910 type
= create_string_type (char_type
, range_type
);
3915 /* Handle DIES due to C code like:
3919 int (*funcp)(int a, long l);
3923 ('funcp' generates a DW_TAG_subroutine_type DIE)
3927 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3929 struct type
*type
; /* Type that this function returns */
3930 struct type
*ftype
; /* Function that returns above type */
3931 struct attribute
*attr
;
3933 /* Decode the type that this subroutine returns */
3938 type
= die_type (die
, cu
);
3939 ftype
= lookup_function_type (type
);
3941 /* All functions in C++ have prototypes. */
3942 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
3943 if ((attr
&& (DW_UNSND (attr
) != 0))
3944 || cu
->language
== language_cplus
)
3945 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
3947 if (die
->child
!= NULL
)
3949 struct die_info
*child_die
;
3953 /* Count the number of parameters.
3954 FIXME: GDB currently ignores vararg functions, but knows about
3955 vararg member functions. */
3956 child_die
= die
->child
;
3957 while (child_die
&& child_die
->tag
)
3959 if (child_die
->tag
== DW_TAG_formal_parameter
)
3961 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
3962 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
3963 child_die
= sibling_die (child_die
);
3966 /* Allocate storage for parameters and fill them in. */
3967 TYPE_NFIELDS (ftype
) = nparams
;
3968 TYPE_FIELDS (ftype
) = (struct field
*)
3969 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
3971 child_die
= die
->child
;
3972 while (child_die
&& child_die
->tag
)
3974 if (child_die
->tag
== DW_TAG_formal_parameter
)
3976 /* Dwarf2 has no clean way to discern C++ static and non-static
3977 member functions. G++ helps GDB by marking the first
3978 parameter for non-static member functions (which is the
3979 this pointer) as artificial. We pass this information
3980 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
3981 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
3983 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
3985 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
3986 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
3989 child_die
= sibling_die (child_die
);
3997 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
3999 struct objfile
*objfile
= cu
->objfile
;
4000 struct attribute
*attr
;
4005 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4006 if (attr
&& DW_STRING (attr
))
4008 name
= DW_STRING (attr
);
4010 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
4011 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, cu
);
4015 /* Find a representation of a given base type and install
4016 it in the TYPE field of the die. */
4019 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4021 struct objfile
*objfile
= cu
->objfile
;
4023 struct attribute
*attr
;
4024 int encoding
= 0, size
= 0;
4026 /* If we've already decoded this die, this is a no-op. */
4032 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
4035 encoding
= DW_UNSND (attr
);
4037 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4040 size
= DW_UNSND (attr
);
4042 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4043 if (attr
&& DW_STRING (attr
))
4045 enum type_code code
= TYPE_CODE_INT
;
4050 case DW_ATE_address
:
4051 /* Turn DW_ATE_address into a void * pointer. */
4052 code
= TYPE_CODE_PTR
;
4053 type_flags
|= TYPE_FLAG_UNSIGNED
;
4055 case DW_ATE_boolean
:
4056 code
= TYPE_CODE_BOOL
;
4057 type_flags
|= TYPE_FLAG_UNSIGNED
;
4059 case DW_ATE_complex_float
:
4060 code
= TYPE_CODE_COMPLEX
;
4063 code
= TYPE_CODE_FLT
;
4066 case DW_ATE_signed_char
:
4068 case DW_ATE_unsigned
:
4069 case DW_ATE_unsigned_char
:
4070 type_flags
|= TYPE_FLAG_UNSIGNED
;
4073 complaint (&symfile_complaints
, "unsupported DW_AT_encoding: '%s'",
4074 dwarf_type_encoding_name (encoding
));
4077 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
4078 if (encoding
== DW_ATE_address
)
4079 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
,
4081 else if (encoding
== DW_ATE_complex_float
)
4084 TYPE_TARGET_TYPE (type
)
4085 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
, cu
);
4086 else if (size
== 16)
4087 TYPE_TARGET_TYPE (type
)
4088 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
4090 TYPE_TARGET_TYPE (type
)
4091 = dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
4096 type
= dwarf_base_type (encoding
, size
, cu
);
4101 /* Read the given DW_AT_subrange DIE. */
4104 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4106 struct type
*base_type
;
4107 struct type
*range_type
;
4108 struct attribute
*attr
;
4112 /* If we have already decoded this die, then nothing more to do. */
4116 base_type
= die_type (die
, cu
);
4117 if (base_type
== NULL
)
4119 complaint (&symfile_complaints
,
4120 "DW_AT_type missing from DW_TAG_subrange_type");
4124 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
4125 base_type
= alloc_type (NULL
);
4127 if (cu
->language
== language_fortran
)
4129 /* FORTRAN implies a lower bound of 1, if not given. */
4133 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
4135 low
= dwarf2_get_attr_constant_value (attr
, 0);
4137 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
4140 if (attr
->form
== DW_FORM_block1
)
4142 /* GCC encodes arrays with unspecified or dynamic length
4143 with a DW_FORM_block1 attribute.
4144 FIXME: GDB does not yet know how to handle dynamic
4145 arrays properly, treat them as arrays with unspecified
4148 FIXME: jimb/2003-09-22: GDB does not really know
4149 how to handle arrays of unspecified length
4150 either; we just represent them as zero-length
4151 arrays. Choose an appropriate upper bound given
4152 the lower bound we've computed above. */
4156 high
= dwarf2_get_attr_constant_value (attr
, 1);
4159 range_type
= create_range_type (NULL
, base_type
, low
, high
);
4161 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4162 if (attr
&& DW_STRING (attr
))
4163 TYPE_NAME (range_type
) = DW_STRING (attr
);
4165 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4167 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
4169 die
->type
= range_type
;
4173 /* Read a whole compilation unit into a linked list of dies. */
4175 static struct die_info
*
4176 read_comp_unit (char *info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
4178 /* Reset die reference table; we are
4179 building new ones now. */
4180 dwarf2_empty_hash_tables ();
4182 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
4185 /* Read a single die and all its descendents. Set the die's sibling
4186 field to NULL; set other fields in the die correctly, and set all
4187 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
4188 location of the info_ptr after reading all of those dies. PARENT
4189 is the parent of the die in question. */
4191 static struct die_info
*
4192 read_die_and_children (char *info_ptr
, bfd
*abfd
,
4193 struct dwarf2_cu
*cu
,
4194 char **new_info_ptr
,
4195 struct die_info
*parent
)
4197 struct die_info
*die
;
4201 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
4202 store_in_ref_table (die
->offset
, die
);
4206 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
4212 *new_info_ptr
= cur_ptr
;
4215 die
->sibling
= NULL
;
4216 die
->parent
= parent
;
4220 /* Read a die, all of its descendents, and all of its siblings; set
4221 all of the fields of all of the dies correctly. Arguments are as
4222 in read_die_and_children. */
4224 static struct die_info
*
4225 read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
4226 struct dwarf2_cu
*cu
,
4227 char **new_info_ptr
,
4228 struct die_info
*parent
)
4230 struct die_info
*first_die
, *last_sibling
;
4234 first_die
= last_sibling
= NULL
;
4238 struct die_info
*die
4239 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
4247 last_sibling
->sibling
= die
;
4252 *new_info_ptr
= cur_ptr
;
4262 /* Free a linked list of dies. */
4265 free_die_list (struct die_info
*dies
)
4267 struct die_info
*die
, *next
;
4272 if (die
->child
!= NULL
)
4273 free_die_list (die
->child
);
4274 next
= die
->sibling
;
4282 do_free_die_list_cleanup (void *dies
)
4284 free_die_list (dies
);
4287 static struct cleanup
*
4288 make_cleanup_free_die_list (struct die_info
*dies
)
4290 return make_cleanup (do_free_die_list_cleanup
, dies
);
4294 /* Read the contents of the section at OFFSET and of size SIZE from the
4295 object file specified by OBJFILE into the objfile_obstack and return it. */
4298 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
4300 bfd
*abfd
= objfile
->obfd
;
4302 bfd_size_type size
= bfd_get_section_size_before_reloc (sectp
);
4307 buf
= (char *) obstack_alloc (&objfile
->objfile_obstack
, size
);
4309 = (char *) symfile_relocate_debug_section (abfd
, sectp
, (bfd_byte
*) buf
);
4313 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
4314 || bfd_bread (buf
, size
, abfd
) != size
)
4315 error ("Dwarf Error: Can't read DWARF data from '%s'",
4316 bfd_get_filename (abfd
));
4321 /* In DWARF version 2, the description of the debugging information is
4322 stored in a separate .debug_abbrev section. Before we read any
4323 dies from a section we read in all abbreviations and install them
4327 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
4329 struct comp_unit_head
*cu_header
= &cu
->header
;
4331 struct abbrev_info
*cur_abbrev
;
4332 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
4333 unsigned int abbrev_form
, hash_number
;
4334 struct attr_abbrev
*cur_attrs
;
4335 unsigned int allocated_attrs
;
4337 /* Initialize dwarf2 abbrevs */
4338 obstack_init (&cu
->abbrev_obstack
);
4339 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
4341 * sizeof (struct abbrev_info
*)));
4342 memset (cu
->dwarf2_abbrevs
, 0,
4343 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
4345 abbrev_ptr
= dwarf_abbrev_buffer
+ cu_header
->abbrev_offset
;
4346 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4347 abbrev_ptr
+= bytes_read
;
4349 allocated_attrs
= ATTR_ALLOC_CHUNK
;
4350 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
4352 /* loop until we reach an abbrev number of 0 */
4353 while (abbrev_number
)
4355 cur_abbrev
= dwarf_alloc_abbrev (cu
);
4357 /* read in abbrev header */
4358 cur_abbrev
->number
= abbrev_number
;
4359 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4360 abbrev_ptr
+= bytes_read
;
4361 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
4364 /* now read in declarations */
4365 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4366 abbrev_ptr
+= bytes_read
;
4367 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4368 abbrev_ptr
+= bytes_read
;
4371 if (cur_abbrev
->num_attrs
== allocated_attrs
)
4373 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
4375 = xrealloc (cur_attrs
, (allocated_attrs
4376 * sizeof (struct attr_abbrev
)));
4378 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
4379 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
4380 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4381 abbrev_ptr
+= bytes_read
;
4382 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4383 abbrev_ptr
+= bytes_read
;
4386 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
4387 (cur_abbrev
->num_attrs
4388 * sizeof (struct attr_abbrev
)));
4389 memcpy (cur_abbrev
->attrs
, cur_attrs
,
4390 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
4392 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
4393 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
4394 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
4396 /* Get next abbreviation.
4397 Under Irix6 the abbreviations for a compilation unit are not
4398 always properly terminated with an abbrev number of 0.
4399 Exit loop if we encounter an abbreviation which we have
4400 already read (which means we are about to read the abbreviations
4401 for the next compile unit) or if the end of the abbreviation
4402 table is reached. */
4403 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
4404 >= dwarf_abbrev_size
)
4406 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4407 abbrev_ptr
+= bytes_read
;
4408 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
4415 /* Release the memory used by the abbrev table for a compilation unit. */
4418 dwarf2_free_abbrev_table (void *ptr_to_cu
)
4420 struct dwarf2_cu
*cu
= ptr_to_cu
;
4422 obstack_free (&cu
->abbrev_obstack
, NULL
);
4423 cu
->dwarf2_abbrevs
= NULL
;
4426 /* Lookup an abbrev_info structure in the abbrev hash table. */
4428 static struct abbrev_info
*
4429 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
4431 unsigned int hash_number
;
4432 struct abbrev_info
*abbrev
;
4434 hash_number
= number
% ABBREV_HASH_SIZE
;
4435 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
4439 if (abbrev
->number
== number
)
4442 abbrev
= abbrev
->next
;
4447 /* Read a minimal amount of information into the minimal die structure. */
4450 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
4451 char *info_ptr
, struct dwarf2_cu
*cu
)
4453 unsigned int abbrev_number
, bytes_read
, i
;
4454 struct abbrev_info
*abbrev
;
4455 struct attribute attr
;
4456 struct attribute spec_attr
;
4457 int found_spec_attr
= 0;
4458 int has_low_pc_attr
= 0;
4459 int has_high_pc_attr
= 0;
4461 *part_die
= zeroed_partial_die
;
4462 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4463 info_ptr
+= bytes_read
;
4467 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4470 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number
,
4471 bfd_get_filename (abfd
));
4473 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
4474 part_die
->tag
= abbrev
->tag
;
4475 part_die
->has_children
= abbrev
->has_children
;
4476 part_die
->abbrev
= abbrev_number
;
4478 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4480 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
4482 /* Store the data if it is of an attribute we want to keep in a
4483 partial symbol table. */
4488 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
4489 if (part_die
->name
== NULL
)
4490 part_die
->name
= DW_STRING (&attr
);
4492 case DW_AT_MIPS_linkage_name
:
4493 part_die
->name
= DW_STRING (&attr
);
4496 has_low_pc_attr
= 1;
4497 part_die
->lowpc
= DW_ADDR (&attr
);
4500 has_high_pc_attr
= 1;
4501 part_die
->highpc
= DW_ADDR (&attr
);
4503 case DW_AT_location
:
4504 /* Support the .debug_loc offsets */
4505 if (attr_form_is_block (&attr
))
4507 part_die
->locdesc
= DW_BLOCK (&attr
);
4509 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
4511 dwarf2_complex_location_expr_complaint ();
4515 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4516 "partial symbol information");
4519 case DW_AT_language
:
4520 part_die
->language
= DW_UNSND (&attr
);
4522 case DW_AT_external
:
4523 part_die
->is_external
= DW_UNSND (&attr
);
4525 case DW_AT_declaration
:
4526 part_die
->is_declaration
= DW_UNSND (&attr
);
4529 part_die
->has_type
= 1;
4531 case DW_AT_abstract_origin
:
4532 case DW_AT_specification
:
4533 found_spec_attr
= 1;
4537 /* Ignore absolute siblings, they might point outside of
4538 the current compile unit. */
4539 if (attr
.form
== DW_FORM_ref_addr
)
4540 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
4543 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
, cu
);
4550 /* If we found a reference attribute and the die has no name, try
4551 to find a name in the referred to die. */
4553 if (found_spec_attr
&& part_die
->name
== NULL
)
4555 struct partial_die_info spec_die
;
4558 spec_ptr
= dwarf_info_buffer
4559 + dwarf2_get_ref_die_offset (&spec_attr
, cu
);
4560 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu
);
4563 part_die
->name
= spec_die
.name
;
4565 /* Copy DW_AT_external attribute if it is set. */
4566 if (spec_die
.is_external
)
4567 part_die
->is_external
= spec_die
.is_external
;
4571 /* When using the GNU linker, .gnu.linkonce. sections are used to
4572 eliminate duplicate copies of functions and vtables and such.
4573 The linker will arbitrarily choose one and discard the others.
4574 The AT_*_pc values for such functions refer to local labels in
4575 these sections. If the section from that file was discarded, the
4576 labels are not in the output, so the relocs get a value of 0.
4577 If this is a discarded function, mark the pc bounds as invalid,
4578 so that GDB will ignore it. */
4579 if (has_low_pc_attr
&& has_high_pc_attr
4580 && part_die
->lowpc
< part_die
->highpc
4581 && (part_die
->lowpc
!= 0
4582 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
4583 part_die
->has_pc_info
= 1;
4587 /* Read the die from the .debug_info section buffer. Set DIEP to
4588 point to a newly allocated die with its information, except for its
4589 child, sibling, and parent fields. Set HAS_CHILDREN to tell
4590 whether the die has children or not. */
4593 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
4594 struct dwarf2_cu
*cu
, int *has_children
)
4596 unsigned int abbrev_number
, bytes_read
, i
, offset
;
4597 struct abbrev_info
*abbrev
;
4598 struct die_info
*die
;
4600 offset
= info_ptr
- dwarf_info_buffer
;
4601 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4602 info_ptr
+= bytes_read
;
4605 die
= dwarf_alloc_die ();
4607 die
->abbrev
= abbrev_number
;
4614 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4617 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
4619 bfd_get_filename (abfd
));
4621 die
= dwarf_alloc_die ();
4622 die
->offset
= offset
;
4623 die
->tag
= abbrev
->tag
;
4624 die
->abbrev
= abbrev_number
;
4627 die
->num_attrs
= abbrev
->num_attrs
;
4628 die
->attrs
= (struct attribute
*)
4629 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
4631 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4633 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
4634 abfd
, info_ptr
, cu
);
4638 *has_children
= abbrev
->has_children
;
4642 /* Read an attribute value described by an attribute form. */
4645 read_attribute_value (struct attribute
*attr
, unsigned form
,
4646 bfd
*abfd
, char *info_ptr
,
4647 struct dwarf2_cu
*cu
)
4649 struct comp_unit_head
*cu_header
= &cu
->header
;
4650 unsigned int bytes_read
;
4651 struct dwarf_block
*blk
;
4657 case DW_FORM_ref_addr
:
4658 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
4659 info_ptr
+= bytes_read
;
4661 case DW_FORM_block2
:
4662 blk
= dwarf_alloc_block ();
4663 blk
->size
= read_2_bytes (abfd
, info_ptr
);
4665 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4666 info_ptr
+= blk
->size
;
4667 DW_BLOCK (attr
) = blk
;
4669 case DW_FORM_block4
:
4670 blk
= dwarf_alloc_block ();
4671 blk
->size
= read_4_bytes (abfd
, info_ptr
);
4673 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4674 info_ptr
+= blk
->size
;
4675 DW_BLOCK (attr
) = blk
;
4678 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4682 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4686 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4689 case DW_FORM_string
:
4690 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
4691 info_ptr
+= bytes_read
;
4694 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
4696 info_ptr
+= bytes_read
;
4699 blk
= dwarf_alloc_block ();
4700 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4701 info_ptr
+= bytes_read
;
4702 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4703 info_ptr
+= blk
->size
;
4704 DW_BLOCK (attr
) = blk
;
4706 case DW_FORM_block1
:
4707 blk
= dwarf_alloc_block ();
4708 blk
->size
= read_1_byte (abfd
, info_ptr
);
4710 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4711 info_ptr
+= blk
->size
;
4712 DW_BLOCK (attr
) = blk
;
4715 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4719 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4723 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
4724 info_ptr
+= bytes_read
;
4727 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4728 info_ptr
+= bytes_read
;
4731 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4735 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4739 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4743 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4746 case DW_FORM_ref_udata
:
4747 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4748 info_ptr
+= bytes_read
;
4750 case DW_FORM_indirect
:
4751 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4752 info_ptr
+= bytes_read
;
4753 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
4756 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
4757 dwarf_form_name (form
),
4758 bfd_get_filename (abfd
));
4763 /* Read an attribute described by an abbreviated attribute. */
4766 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
4767 bfd
*abfd
, char *info_ptr
, struct dwarf2_cu
*cu
)
4769 attr
->name
= abbrev
->name
;
4770 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
4773 /* read dwarf information from a buffer */
4776 read_1_byte (bfd
*abfd
, char *buf
)
4778 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4782 read_1_signed_byte (bfd
*abfd
, char *buf
)
4784 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
4788 read_2_bytes (bfd
*abfd
, char *buf
)
4790 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4794 read_2_signed_bytes (bfd
*abfd
, char *buf
)
4796 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4800 read_4_bytes (bfd
*abfd
, char *buf
)
4802 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4806 read_4_signed_bytes (bfd
*abfd
, char *buf
)
4808 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4811 static unsigned long
4812 read_8_bytes (bfd
*abfd
, char *buf
)
4814 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4818 read_address (bfd
*abfd
, char *buf
, struct dwarf2_cu
*cu
, int *bytes_read
)
4820 struct comp_unit_head
*cu_header
= &cu
->header
;
4821 CORE_ADDR retval
= 0;
4823 if (cu_header
->signed_addr_p
)
4825 switch (cu_header
->addr_size
)
4828 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4831 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4834 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
4837 internal_error (__FILE__
, __LINE__
,
4838 "read_address: bad switch, signed [in module %s]",
4839 bfd_get_filename (abfd
));
4844 switch (cu_header
->addr_size
)
4847 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4850 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4853 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4856 internal_error (__FILE__
, __LINE__
,
4857 "read_address: bad switch, unsigned [in module %s]",
4858 bfd_get_filename (abfd
));
4862 *bytes_read
= cu_header
->addr_size
;
4866 /* Read the initial length from a section. The (draft) DWARF 3
4867 specification allows the initial length to take up either 4 bytes
4868 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
4869 bytes describe the length and all offsets will be 8 bytes in length
4872 An older, non-standard 64-bit format is also handled by this
4873 function. The older format in question stores the initial length
4874 as an 8-byte quantity without an escape value. Lengths greater
4875 than 2^32 aren't very common which means that the initial 4 bytes
4876 is almost always zero. Since a length value of zero doesn't make
4877 sense for the 32-bit format, this initial zero can be considered to
4878 be an escape value which indicates the presence of the older 64-bit
4879 format. As written, the code can't detect (old format) lengths
4880 greater than 4GB. If it becomes necessary to handle lengths somewhat
4881 larger than 4GB, we could allow other small values (such as the
4882 non-sensical values of 1, 2, and 3) to also be used as escape values
4883 indicating the presence of the old format.
4885 The value returned via bytes_read should be used to increment
4886 the relevant pointer after calling read_initial_length().
4888 As a side effect, this function sets the fields initial_length_size
4889 and offset_size in cu_header to the values appropriate for the
4890 length field. (The format of the initial length field determines
4891 the width of file offsets to be fetched later with fetch_offset().)
4893 [ Note: read_initial_length() and read_offset() are based on the
4894 document entitled "DWARF Debugging Information Format", revision
4895 3, draft 8, dated November 19, 2001. This document was obtained
4898 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
4900 This document is only a draft and is subject to change. (So beware.)
4902 Details regarding the older, non-standard 64-bit format were
4903 determined empirically by examining 64-bit ELF files produced
4904 by the SGI toolchain on an IRIX 6.5 machine.
4906 - Kevin, July 16, 2002
4910 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
4915 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4917 if (retval
== 0xffffffff)
4919 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
4921 if (cu_header
!= NULL
)
4923 cu_header
->initial_length_size
= 12;
4924 cu_header
->offset_size
= 8;
4927 else if (retval
== 0)
4929 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
4931 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4933 if (cu_header
!= NULL
)
4935 cu_header
->initial_length_size
= 8;
4936 cu_header
->offset_size
= 8;
4942 if (cu_header
!= NULL
)
4944 cu_header
->initial_length_size
= 4;
4945 cu_header
->offset_size
= 4;
4952 /* Read an offset from the data stream. The size of the offset is
4953 given by cu_header->offset_size. */
4956 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
4961 switch (cu_header
->offset_size
)
4964 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4968 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4972 internal_error (__FILE__
, __LINE__
,
4973 "read_offset: bad switch [in module %s]",
4974 bfd_get_filename (abfd
));
4981 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
4983 /* If the size of a host char is 8 bits, we can return a pointer
4984 to the buffer, otherwise we have to copy the data to a buffer
4985 allocated on the temporary obstack. */
4986 gdb_assert (HOST_CHAR_BIT
== 8);
4991 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4993 /* If the size of a host char is 8 bits, we can return a pointer
4994 to the string, otherwise we have to copy the string to a buffer
4995 allocated on the temporary obstack. */
4996 gdb_assert (HOST_CHAR_BIT
== 8);
4999 *bytes_read_ptr
= 1;
5002 *bytes_read_ptr
= strlen (buf
) + 1;
5007 read_indirect_string (bfd
*abfd
, char *buf
,
5008 const struct comp_unit_head
*cu_header
,
5009 unsigned int *bytes_read_ptr
)
5011 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
5012 (int *) bytes_read_ptr
);
5014 if (dwarf_str_buffer
== NULL
)
5016 error ("DW_FORM_strp used without .debug_str section [in module %s]",
5017 bfd_get_filename (abfd
));
5020 if (str_offset
>= dwarf_str_size
)
5022 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
5023 bfd_get_filename (abfd
));
5026 gdb_assert (HOST_CHAR_BIT
== 8);
5027 if (dwarf_str_buffer
[str_offset
] == '\0')
5029 return dwarf_str_buffer
+ str_offset
;
5032 static unsigned long
5033 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5035 unsigned long result
;
5036 unsigned int num_read
;
5046 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5049 result
|= ((unsigned long)(byte
& 127) << shift
);
5050 if ((byte
& 128) == 0)
5056 *bytes_read_ptr
= num_read
;
5061 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5064 int i
, shift
, size
, num_read
;
5074 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5077 result
|= ((long)(byte
& 127) << shift
);
5079 if ((byte
& 128) == 0)
5084 if ((shift
< size
) && (byte
& 0x40))
5086 result
|= -(1 << shift
);
5088 *bytes_read_ptr
= num_read
;
5092 /* Return a pointer to just past the end of an LEB128 number in BUF. */
5095 skip_leb128 (bfd
*abfd
, char *buf
)
5101 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5103 if ((byte
& 128) == 0)
5109 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
5115 cu
->language
= language_c
;
5117 case DW_LANG_C_plus_plus
:
5118 cu
->language
= language_cplus
;
5120 case DW_LANG_Fortran77
:
5121 case DW_LANG_Fortran90
:
5122 case DW_LANG_Fortran95
:
5123 cu
->language
= language_fortran
;
5125 case DW_LANG_Mips_Assembler
:
5126 cu
->language
= language_asm
;
5129 cu
->language
= language_java
;
5133 case DW_LANG_Cobol74
:
5134 case DW_LANG_Cobol85
:
5135 case DW_LANG_Pascal83
:
5136 case DW_LANG_Modula2
:
5138 cu
->language
= language_minimal
;
5141 cu
->language_defn
= language_def (cu
->language
);
5144 /* Return the named attribute or NULL if not there. */
5146 static struct attribute
*
5147 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
5150 struct attribute
*spec
= NULL
;
5152 for (i
= 0; i
< die
->num_attrs
; ++i
)
5154 if (die
->attrs
[i
].name
== name
)
5156 return &die
->attrs
[i
];
5158 if (die
->attrs
[i
].name
== DW_AT_specification
5159 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
5160 spec
= &die
->attrs
[i
];
5164 struct die_info
*ref_die
=
5165 follow_die_ref (dwarf2_get_ref_die_offset (spec
, cu
));
5168 return dwarf2_attr (ref_die
, name
, cu
);
5175 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
5177 return (dwarf2_attr (die
, DW_AT_declaration
, cu
)
5178 && ! dwarf2_attr (die
, DW_AT_specification
, cu
));
5181 /* Return the die giving the specification for DIE, if there is
5184 static struct die_info
*
5185 die_specification (struct die_info
*die
, struct dwarf2_cu
*cu
)
5187 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
, cu
);
5189 if (spec_attr
== NULL
)
5192 return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr
, cu
));
5195 /* Free the line_header structure *LH, and any arrays and strings it
5198 free_line_header (struct line_header
*lh
)
5200 if (lh
->standard_opcode_lengths
)
5201 xfree (lh
->standard_opcode_lengths
);
5203 /* Remember that all the lh->file_names[i].name pointers are
5204 pointers into debug_line_buffer, and don't need to be freed. */
5206 xfree (lh
->file_names
);
5208 /* Similarly for the include directory names. */
5209 if (lh
->include_dirs
)
5210 xfree (lh
->include_dirs
);
5216 /* Add an entry to LH's include directory table. */
5218 add_include_dir (struct line_header
*lh
, char *include_dir
)
5220 /* Grow the array if necessary. */
5221 if (lh
->include_dirs_size
== 0)
5223 lh
->include_dirs_size
= 1; /* for testing */
5224 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
5225 * sizeof (*lh
->include_dirs
));
5227 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
5229 lh
->include_dirs_size
*= 2;
5230 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
5231 (lh
->include_dirs_size
5232 * sizeof (*lh
->include_dirs
)));
5235 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
5239 /* Add an entry to LH's file name table. */
5241 add_file_name (struct line_header
*lh
,
5243 unsigned int dir_index
,
5244 unsigned int mod_time
,
5245 unsigned int length
)
5247 struct file_entry
*fe
;
5249 /* Grow the array if necessary. */
5250 if (lh
->file_names_size
== 0)
5252 lh
->file_names_size
= 1; /* for testing */
5253 lh
->file_names
= xmalloc (lh
->file_names_size
5254 * sizeof (*lh
->file_names
));
5256 else if (lh
->num_file_names
>= lh
->file_names_size
)
5258 lh
->file_names_size
*= 2;
5259 lh
->file_names
= xrealloc (lh
->file_names
,
5260 (lh
->file_names_size
5261 * sizeof (*lh
->file_names
)));
5264 fe
= &lh
->file_names
[lh
->num_file_names
++];
5266 fe
->dir_index
= dir_index
;
5267 fe
->mod_time
= mod_time
;
5268 fe
->length
= length
;
5272 /* Read the statement program header starting at OFFSET in
5273 dwarf_line_buffer, according to the endianness of ABFD. Return a
5274 pointer to a struct line_header, allocated using xmalloc.
5276 NOTE: the strings in the include directory and file name tables of
5277 the returned object point into debug_line_buffer, and must not be
5279 static struct line_header
*
5280 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
5281 struct dwarf2_cu
*cu
)
5283 struct cleanup
*back_to
;
5284 struct line_header
*lh
;
5288 char *cur_dir
, *cur_file
;
5290 if (dwarf_line_buffer
== NULL
)
5292 complaint (&symfile_complaints
, "missing .debug_line section");
5296 /* Make sure that at least there's room for the total_length field. That
5297 could be 12 bytes long, but we're just going to fudge that. */
5298 if (offset
+ 4 >= dwarf_line_size
)
5300 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5304 lh
= xmalloc (sizeof (*lh
));
5305 memset (lh
, 0, sizeof (*lh
));
5306 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
5309 line_ptr
= dwarf_line_buffer
+ offset
;
5311 /* read in the header */
5312 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
5313 line_ptr
+= bytes_read
;
5314 if (line_ptr
+ lh
->total_length
> dwarf_line_buffer
+ dwarf_line_size
)
5316 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5319 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
5320 lh
->version
= read_2_bytes (abfd
, line_ptr
);
5322 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
5323 line_ptr
+= bytes_read
;
5324 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
5326 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
5328 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
5330 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
5332 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
5334 lh
->standard_opcode_lengths
5335 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
5337 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
5338 for (i
= 1; i
< lh
->opcode_base
; ++i
)
5340 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
5344 /* Read directory table */
5345 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
5347 line_ptr
+= bytes_read
;
5348 add_include_dir (lh
, cur_dir
);
5350 line_ptr
+= bytes_read
;
5352 /* Read file name table */
5353 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
5355 unsigned int dir_index
, mod_time
, length
;
5357 line_ptr
+= bytes_read
;
5358 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5359 line_ptr
+= bytes_read
;
5360 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5361 line_ptr
+= bytes_read
;
5362 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5363 line_ptr
+= bytes_read
;
5365 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
5367 line_ptr
+= bytes_read
;
5368 lh
->statement_program_start
= line_ptr
;
5370 if (line_ptr
> dwarf_line_buffer
+ dwarf_line_size
)
5371 complaint (&symfile_complaints
,
5372 "line number info header doesn't fit in `.debug_line' section");
5374 discard_cleanups (back_to
);
5378 /* This function exists to work around a bug in certain compilers
5379 (particularly GCC 2.95), in which the first line number marker of a
5380 function does not show up until after the prologue, right before
5381 the second line number marker. This function shifts ADDRESS down
5382 to the beginning of the function if necessary, and is called on
5383 addresses passed to record_line. */
5386 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
5388 struct function_range
*fn
;
5390 /* Find the function_range containing address. */
5395 cu
->cached_fn
= cu
->first_fn
;
5399 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
5405 while (fn
&& fn
!= cu
->cached_fn
)
5406 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
5416 if (address
!= fn
->lowpc
)
5417 complaint (&symfile_complaints
,
5418 "misplaced first line number at 0x%lx for '%s'",
5419 (unsigned long) address
, fn
->name
);
5424 /* Decode the line number information for the compilation unit whose
5425 line number info is at OFFSET in the .debug_line section.
5426 The compilation directory of the file is passed in COMP_DIR. */
5429 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
5430 struct dwarf2_cu
*cu
)
5434 unsigned int bytes_read
;
5435 unsigned char op_code
, extended_op
, adj_opcode
;
5437 struct objfile
*objfile
= cu
->objfile
;
5439 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5441 line_ptr
= lh
->statement_program_start
;
5442 line_end
= lh
->statement_program_end
;
5444 /* Read the statement sequences until there's nothing left. */
5445 while (line_ptr
< line_end
)
5447 /* state machine registers */
5448 CORE_ADDR address
= 0;
5449 unsigned int file
= 1;
5450 unsigned int line
= 1;
5451 unsigned int column
= 0;
5452 int is_stmt
= lh
->default_is_stmt
;
5453 int basic_block
= 0;
5454 int end_sequence
= 0;
5456 /* Start a subfile for the current file of the state machine. */
5457 if (lh
->num_file_names
>= file
)
5459 /* lh->include_dirs and lh->file_names are 0-based, but the
5460 directory and file name numbers in the statement program
5462 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
5465 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
5468 dwarf2_start_subfile (fe
->name
, dir
);
5471 /* Decode the table. */
5472 while (!end_sequence
)
5474 op_code
= read_1_byte (abfd
, line_ptr
);
5477 if (op_code
>= lh
->opcode_base
)
5478 { /* Special operand. */
5479 adj_opcode
= op_code
- lh
->opcode_base
;
5480 address
+= (adj_opcode
/ lh
->line_range
)
5481 * lh
->minimum_instruction_length
;
5482 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
5483 /* append row to matrix using current values */
5484 record_line (current_subfile
, line
,
5485 check_cu_functions (address
, cu
));
5488 else switch (op_code
)
5490 case DW_LNS_extended_op
:
5491 line_ptr
+= 1; /* ignore length */
5492 extended_op
= read_1_byte (abfd
, line_ptr
);
5494 switch (extended_op
)
5496 case DW_LNE_end_sequence
:
5498 record_line (current_subfile
, 0, address
);
5500 case DW_LNE_set_address
:
5501 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
5502 line_ptr
+= bytes_read
;
5503 address
+= baseaddr
;
5505 case DW_LNE_define_file
:
5508 unsigned int dir_index
, mod_time
, length
;
5510 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
5511 line_ptr
+= bytes_read
;
5513 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5514 line_ptr
+= bytes_read
;
5516 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5517 line_ptr
+= bytes_read
;
5519 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5520 line_ptr
+= bytes_read
;
5521 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
5525 complaint (&symfile_complaints
,
5526 "mangled .debug_line section");
5531 record_line (current_subfile
, line
,
5532 check_cu_functions (address
, cu
));
5535 case DW_LNS_advance_pc
:
5536 address
+= lh
->minimum_instruction_length
5537 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5538 line_ptr
+= bytes_read
;
5540 case DW_LNS_advance_line
:
5541 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
5542 line_ptr
+= bytes_read
;
5544 case DW_LNS_set_file
:
5546 /* lh->include_dirs and lh->file_names are 0-based,
5547 but the directory and file name numbers in the
5548 statement program are 1-based. */
5549 struct file_entry
*fe
;
5551 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5552 line_ptr
+= bytes_read
;
5553 fe
= &lh
->file_names
[file
- 1];
5555 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
5558 dwarf2_start_subfile (fe
->name
, dir
);
5561 case DW_LNS_set_column
:
5562 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5563 line_ptr
+= bytes_read
;
5565 case DW_LNS_negate_stmt
:
5566 is_stmt
= (!is_stmt
);
5568 case DW_LNS_set_basic_block
:
5571 /* Add to the address register of the state machine the
5572 address increment value corresponding to special opcode
5573 255. Ie, this value is scaled by the minimum instruction
5574 length since special opcode 255 would have scaled the
5576 case DW_LNS_const_add_pc
:
5577 address
+= (lh
->minimum_instruction_length
5578 * ((255 - lh
->opcode_base
) / lh
->line_range
));
5580 case DW_LNS_fixed_advance_pc
:
5581 address
+= read_2_bytes (abfd
, line_ptr
);
5585 { /* Unknown standard opcode, ignore it. */
5587 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
5589 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5590 line_ptr
+= bytes_read
;
5598 /* Start a subfile for DWARF. FILENAME is the name of the file and
5599 DIRNAME the name of the source directory which contains FILENAME
5600 or NULL if not known.
5601 This routine tries to keep line numbers from identical absolute and
5602 relative file names in a common subfile.
5604 Using the `list' example from the GDB testsuite, which resides in
5605 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
5606 of /srcdir/list0.c yields the following debugging information for list0.c:
5608 DW_AT_name: /srcdir/list0.c
5609 DW_AT_comp_dir: /compdir
5610 files.files[0].name: list0.h
5611 files.files[0].dir: /srcdir
5612 files.files[1].name: list0.c
5613 files.files[1].dir: /srcdir
5615 The line number information for list0.c has to end up in a single
5616 subfile, so that `break /srcdir/list0.c:1' works as expected. */
5619 dwarf2_start_subfile (char *filename
, char *dirname
)
5621 /* If the filename isn't absolute, try to match an existing subfile
5622 with the full pathname. */
5624 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
5626 struct subfile
*subfile
;
5627 char *fullname
= concat (dirname
, "/", filename
, NULL
);
5629 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
5631 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
5633 current_subfile
= subfile
;
5640 start_subfile (filename
, dirname
);
5644 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
5645 struct dwarf2_cu
*cu
)
5647 struct objfile
*objfile
= cu
->objfile
;
5648 struct comp_unit_head
*cu_header
= &cu
->header
;
5650 /* NOTE drow/2003-01-30: There used to be a comment and some special
5651 code here to turn a symbol with DW_AT_external and a
5652 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
5653 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
5654 with some versions of binutils) where shared libraries could have
5655 relocations against symbols in their debug information - the
5656 minimal symbol would have the right address, but the debug info
5657 would not. It's no longer necessary, because we will explicitly
5658 apply relocations when we read in the debug information now. */
5660 /* A DW_AT_location attribute with no contents indicates that a
5661 variable has been optimized away. */
5662 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
5664 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
5668 /* Handle one degenerate form of location expression specially, to
5669 preserve GDB's previous behavior when section offsets are
5670 specified. If this is just a DW_OP_addr then mark this symbol
5673 if (attr_form_is_block (attr
)
5674 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
5675 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
5679 SYMBOL_VALUE_ADDRESS (sym
) =
5680 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
5681 fixup_symbol_section (sym
, objfile
);
5682 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
5683 SYMBOL_SECTION (sym
));
5684 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5688 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
5689 expression evaluator, and use LOC_COMPUTED only when necessary
5690 (i.e. when the value of a register or memory location is
5691 referenced, or a thread-local block, etc.). Then again, it might
5692 not be worthwhile. I'm assuming that it isn't unless performance
5693 or memory numbers show me otherwise. */
5695 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
5696 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
5699 /* Given a pointer to a DWARF information entry, figure out if we need
5700 to make a symbol table entry for it, and if so, create a new entry
5701 and return a pointer to it.
5702 If TYPE is NULL, determine symbol type from the die, otherwise
5703 used the passed type. */
5705 static struct symbol
*
5706 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
5708 struct objfile
*objfile
= cu
->objfile
;
5709 struct symbol
*sym
= NULL
;
5711 struct attribute
*attr
= NULL
;
5712 struct attribute
*attr2
= NULL
;
5715 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5717 if (die
->tag
!= DW_TAG_namespace
)
5718 name
= dwarf2_linkage_name (die
, cu
);
5720 name
= TYPE_NAME (type
);
5724 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
5725 sizeof (struct symbol
));
5726 OBJSTAT (objfile
, n_syms
++);
5727 memset (sym
, 0, sizeof (struct symbol
));
5729 /* Cache this symbol's name and the name's demangled form (if any). */
5730 SYMBOL_LANGUAGE (sym
) = cu
->language
;
5731 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
5733 /* Default assumptions.
5734 Use the passed type or decode it from the die. */
5735 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5736 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5738 SYMBOL_TYPE (sym
) = type
;
5740 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
5741 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
5744 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
5749 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5752 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
5754 SYMBOL_CLASS (sym
) = LOC_LABEL
;
5756 case DW_TAG_subprogram
:
5757 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
5759 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
5760 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
5761 if (attr2
&& (DW_UNSND (attr2
) != 0))
5763 add_symbol_to_list (sym
, &global_symbols
);
5767 add_symbol_to_list (sym
, cu
->list_in_scope
);
5770 case DW_TAG_variable
:
5771 /* Compilation with minimal debug info may result in variables
5772 with missing type entries. Change the misleading `void' type
5773 to something sensible. */
5774 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
5775 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
5776 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
5777 "<variable, no debug info>",
5779 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
5782 dwarf2_const_value (attr
, sym
, cu
);
5783 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
5784 if (attr2
&& (DW_UNSND (attr2
) != 0))
5785 add_symbol_to_list (sym
, &global_symbols
);
5787 add_symbol_to_list (sym
, cu
->list_in_scope
);
5790 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
5793 var_decode_location (attr
, sym
, cu
);
5794 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
5795 if (attr2
&& (DW_UNSND (attr2
) != 0))
5796 add_symbol_to_list (sym
, &global_symbols
);
5798 add_symbol_to_list (sym
, cu
->list_in_scope
);
5802 /* We do not know the address of this symbol.
5803 If it is an external symbol and we have type information
5804 for it, enter the symbol as a LOC_UNRESOLVED symbol.
5805 The address of the variable will then be determined from
5806 the minimal symbol table whenever the variable is
5808 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
5809 if (attr2
&& (DW_UNSND (attr2
) != 0)
5810 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
5812 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
5813 add_symbol_to_list (sym
, &global_symbols
);
5817 case DW_TAG_formal_parameter
:
5818 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
5821 var_decode_location (attr
, sym
, cu
);
5822 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
5823 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
5824 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
5826 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
5829 dwarf2_const_value (attr
, sym
, cu
);
5831 add_symbol_to_list (sym
, cu
->list_in_scope
);
5833 case DW_TAG_unspecified_parameters
:
5834 /* From varargs functions; gdb doesn't seem to have any
5835 interest in this information, so just ignore it for now.
5838 case DW_TAG_class_type
:
5839 case DW_TAG_structure_type
:
5840 case DW_TAG_union_type
:
5841 case DW_TAG_enumeration_type
:
5842 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5843 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
5845 /* Make sure that the symbol includes appropriate enclosing
5846 classes/namespaces in its name. These are calculated in
5847 read_structure_scope, and the correct name is saved in
5850 if (cu
->language
== language_cplus
)
5852 struct type
*type
= SYMBOL_TYPE (sym
);
5854 if (TYPE_TAG_NAME (type
) != NULL
)
5856 /* FIXME: carlton/2003-11-10: Should this use
5857 SYMBOL_SET_NAMES instead? (The same problem also
5858 arises further down in this function.) */
5859 /* The type's name is already allocated along with
5860 this objfile, so we don't need to duplicate it
5862 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
5867 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
5868 really ever be static objects: otherwise, if you try
5869 to, say, break of a class's method and you're in a file
5870 which doesn't mention that class, it won't work unless
5871 the check for all static symbols in lookup_symbol_aux
5872 saves you. See the OtherFileClass tests in
5873 gdb.c++/namespace.exp. */
5875 struct pending
**list_to_add
;
5877 list_to_add
= (cu
->list_in_scope
== &file_symbols
5878 && cu
->language
== language_cplus
5879 ? &global_symbols
: cu
->list_in_scope
);
5881 add_symbol_to_list (sym
, list_to_add
);
5883 /* The semantics of C++ state that "struct foo { ... }" also
5884 defines a typedef for "foo". Synthesize a typedef symbol so
5885 that "ptype foo" works as expected. */
5886 if (cu
->language
== language_cplus
)
5888 struct symbol
*typedef_sym
= (struct symbol
*)
5889 obstack_alloc (&objfile
->objfile_obstack
,
5890 sizeof (struct symbol
));
5891 *typedef_sym
= *sym
;
5892 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
5893 /* The symbol's name is already allocated along with
5894 this objfile, so we don't need to duplicate it for
5896 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
5897 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NATURAL_NAME (sym
);
5898 add_symbol_to_list (typedef_sym
, list_to_add
);
5902 case DW_TAG_typedef
:
5903 if (processing_has_namespace_info
5904 && processing_current_prefix
[0] != '\0')
5906 SYMBOL_LINKAGE_NAME (sym
) = obconcat (&objfile
->objfile_obstack
,
5907 processing_current_prefix
,
5911 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5912 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5913 add_symbol_to_list (sym
, cu
->list_in_scope
);
5915 case DW_TAG_base_type
:
5916 case DW_TAG_subrange_type
:
5917 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5918 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5919 add_symbol_to_list (sym
, cu
->list_in_scope
);
5921 case DW_TAG_enumerator
:
5922 if (processing_has_namespace_info
5923 && processing_current_prefix
[0] != '\0')
5925 SYMBOL_LINKAGE_NAME (sym
) = obconcat (&objfile
->objfile_obstack
,
5926 processing_current_prefix
,
5930 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
5933 dwarf2_const_value (attr
, sym
, cu
);
5936 /* NOTE: carlton/2003-11-10: See comment above in the
5937 DW_TAG_class_type, etc. block. */
5939 struct pending
**list_to_add
;
5941 list_to_add
= (cu
->list_in_scope
== &file_symbols
5942 && cu
->language
== language_cplus
5943 ? &global_symbols
: cu
->list_in_scope
);
5945 add_symbol_to_list (sym
, list_to_add
);
5948 case DW_TAG_namespace
:
5949 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5950 add_symbol_to_list (sym
, &global_symbols
);
5953 /* Not a tag we recognize. Hopefully we aren't processing
5954 trash data, but since we must specifically ignore things
5955 we don't recognize, there is nothing else we should do at
5957 complaint (&symfile_complaints
, "unsupported tag: '%s'",
5958 dwarf_tag_name (die
->tag
));
5965 /* Copy constant value from an attribute to a symbol. */
5968 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
5969 struct dwarf2_cu
*cu
)
5971 struct objfile
*objfile
= cu
->objfile
;
5972 struct comp_unit_head
*cu_header
= &cu
->header
;
5973 struct dwarf_block
*blk
;
5978 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
5979 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5980 cu_header
->addr_size
,
5981 TYPE_LENGTH (SYMBOL_TYPE
5983 SYMBOL_VALUE_BYTES (sym
) = (char *)
5984 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
5985 /* NOTE: cagney/2003-05-09: In-lined store_address call with
5986 it's body - store_unsigned_integer. */
5987 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
5989 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5991 case DW_FORM_block1
:
5992 case DW_FORM_block2
:
5993 case DW_FORM_block4
:
5995 blk
= DW_BLOCK (attr
);
5996 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
5997 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5999 TYPE_LENGTH (SYMBOL_TYPE
6001 SYMBOL_VALUE_BYTES (sym
) = (char *)
6002 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
6003 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
6004 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
6007 /* The DW_AT_const_value attributes are supposed to carry the
6008 symbol's value "represented as it would be on the target
6009 architecture." By the time we get here, it's already been
6010 converted to host endianness, so we just need to sign- or
6011 zero-extend it as appropriate. */
6013 dwarf2_const_value_data (attr
, sym
, 8);
6016 dwarf2_const_value_data (attr
, sym
, 16);
6019 dwarf2_const_value_data (attr
, sym
, 32);
6022 dwarf2_const_value_data (attr
, sym
, 64);
6026 SYMBOL_VALUE (sym
) = DW_SND (attr
);
6027 SYMBOL_CLASS (sym
) = LOC_CONST
;
6031 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
6032 SYMBOL_CLASS (sym
) = LOC_CONST
;
6036 complaint (&symfile_complaints
,
6037 "unsupported const value attribute form: '%s'",
6038 dwarf_form_name (attr
->form
));
6039 SYMBOL_VALUE (sym
) = 0;
6040 SYMBOL_CLASS (sym
) = LOC_CONST
;
6046 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
6047 or zero-extend it as appropriate for the symbol's type. */
6049 dwarf2_const_value_data (struct attribute
*attr
,
6053 LONGEST l
= DW_UNSND (attr
);
6055 if (bits
< sizeof (l
) * 8)
6057 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
6058 l
&= ((LONGEST
) 1 << bits
) - 1;
6060 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
6063 SYMBOL_VALUE (sym
) = l
;
6064 SYMBOL_CLASS (sym
) = LOC_CONST
;
6068 /* Return the type of the die in question using its DW_AT_type attribute. */
6070 static struct type
*
6071 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6074 struct attribute
*type_attr
;
6075 struct die_info
*type_die
;
6078 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
6081 /* A missing DW_AT_type represents a void type. */
6082 return dwarf2_fundamental_type (cu
->objfile
, FT_VOID
, cu
);
6086 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
6087 type_die
= follow_die_ref (ref
);
6090 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
6091 ref
, cu
->objfile
->name
);
6095 type
= tag_type_to_type (type_die
, cu
);
6098 dump_die (type_die
);
6099 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
6105 /* Return the containing type of the die in question using its
6106 DW_AT_containing_type attribute. */
6108 static struct type
*
6109 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6111 struct type
*type
= NULL
;
6112 struct attribute
*type_attr
;
6113 struct die_info
*type_die
= NULL
;
6116 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
6119 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
6120 type_die
= follow_die_ref (ref
);
6123 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref
,
6127 type
= tag_type_to_type (type_die
, cu
);
6132 dump_die (type_die
);
6133 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
6140 static struct type
*
6141 type_at_offset (unsigned int offset
, struct dwarf2_cu
*cu
)
6143 struct die_info
*die
;
6146 die
= follow_die_ref (offset
);
6149 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
6152 type
= tag_type_to_type (die
, cu
);
6157 static struct type
*
6158 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6166 read_type_die (die
, cu
);
6170 error ("Dwarf Error: Cannot find type of die [in module %s]",
6178 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
6180 char *prefix
= determine_prefix (die
, cu
);
6181 const char *old_prefix
= processing_current_prefix
;
6182 struct cleanup
*back_to
= make_cleanup (xfree
, prefix
);
6183 processing_current_prefix
= prefix
;
6187 case DW_TAG_class_type
:
6188 case DW_TAG_structure_type
:
6189 case DW_TAG_union_type
:
6190 read_structure_scope (die
, cu
);
6192 case DW_TAG_enumeration_type
:
6193 read_enumeration (die
, cu
);
6195 case DW_TAG_subprogram
:
6196 case DW_TAG_subroutine_type
:
6197 read_subroutine_type (die
, cu
);
6199 case DW_TAG_array_type
:
6200 read_array_type (die
, cu
);
6202 case DW_TAG_pointer_type
:
6203 read_tag_pointer_type (die
, cu
);
6205 case DW_TAG_ptr_to_member_type
:
6206 read_tag_ptr_to_member_type (die
, cu
);
6208 case DW_TAG_reference_type
:
6209 read_tag_reference_type (die
, cu
);
6211 case DW_TAG_const_type
:
6212 read_tag_const_type (die
, cu
);
6214 case DW_TAG_volatile_type
:
6215 read_tag_volatile_type (die
, cu
);
6217 case DW_TAG_string_type
:
6218 read_tag_string_type (die
, cu
);
6220 case DW_TAG_typedef
:
6221 read_typedef (die
, cu
);
6223 case DW_TAG_subrange_type
:
6224 read_subrange_type (die
, cu
);
6226 case DW_TAG_base_type
:
6227 read_base_type (die
, cu
);
6230 complaint (&symfile_complaints
, "unexepected tag in read_type_die: '%s'",
6231 dwarf_tag_name (die
->tag
));
6235 processing_current_prefix
= old_prefix
;
6236 do_cleanups (back_to
);
6239 /* Return the name of the namespace/class that DIE is defined within,
6240 or "" if we can't tell. The caller should xfree the result. */
6242 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
6243 therein) for an example of how to use this function to deal with
6244 DW_AT_specification. */
6247 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
6249 char *prefix
= determine_prefix_aux (die
, cu
);
6251 return prefix
? prefix
: xstrdup ("");
6254 /* Return the name of the namespace/class that DIE is defined
6255 within, or NULL if we can't tell. The caller should xfree the
6259 determine_prefix_aux (struct die_info
*die
, struct dwarf2_cu
*cu
)
6261 struct die_info
*parent
;
6263 if (cu
->language
!= language_cplus
)
6266 parent
= die
->parent
;
6270 return (processing_has_namespace_info
? xstrdup ("") : NULL
);
6274 char *parent_prefix
= determine_prefix_aux (parent
, cu
);
6277 switch (parent
->tag
) {
6278 case DW_TAG_namespace
:
6282 retval
= typename_concat (parent_prefix
,
6283 namespace_name (parent
, &dummy
, cu
));
6286 case DW_TAG_class_type
:
6287 case DW_TAG_structure_type
:
6289 if (parent_prefix
!= NULL
)
6291 const char *parent_name
= dwarf2_name (parent
, cu
);
6293 if (parent_name
!= NULL
)
6294 retval
= typename_concat (parent_prefix
, dwarf2_name (parent
, cu
));
6296 /* FIXME: carlton/2003-11-10: I'm not sure what the
6297 best thing to do here is. */
6298 retval
= typename_concat (parent_prefix
,
6299 "<<anonymous class>>");
6302 retval
= class_name (parent
, cu
);
6306 retval
= parent_prefix
;
6310 if (retval
!= parent_prefix
)
6311 xfree (parent_prefix
);
6316 /* Return a newly-allocated string formed by concatenating PREFIX,
6317 "::", and SUFFIX, except that if PREFIX is NULL or the empty
6318 string, just return a copy of SUFFIX. */
6321 typename_concat (const char *prefix
, const char *suffix
)
6323 if (prefix
== NULL
|| prefix
[0] == '\0')
6324 return xstrdup (suffix
);
6327 char *retval
= xmalloc (strlen (prefix
) + 2 + strlen (suffix
) + 1);
6329 strcpy (retval
, prefix
);
6330 strcat (retval
, "::");
6331 strcat (retval
, suffix
);
6337 /* Return a newly-allocated string giving the name of the class given
6341 class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6343 struct die_info
*child
;
6346 for (child
= die
->child
; child
!= NULL
; child
= sibling_die (child
))
6348 if (child
->tag
== DW_TAG_subprogram
)
6349 return class_name_from_physname (dwarf2_linkage_name (child
, cu
));
6352 name
= dwarf2_name (die
, cu
);
6354 return xstrdup (name
);
6356 return xstrdup ("");
6359 static struct type
*
6360 dwarf_base_type (int encoding
, int size
, struct dwarf2_cu
*cu
)
6362 struct objfile
*objfile
= cu
->objfile
;
6364 /* FIXME - this should not produce a new (struct type *)
6365 every time. It should cache base types. */
6369 case DW_ATE_address
:
6370 type
= dwarf2_fundamental_type (objfile
, FT_VOID
, cu
);
6372 case DW_ATE_boolean
:
6373 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
, cu
);
6375 case DW_ATE_complex_float
:
6378 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
, cu
);
6382 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
, cu
);
6388 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
6392 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
6399 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
6402 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
, cu
);
6406 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
6410 case DW_ATE_signed_char
:
6411 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
6413 case DW_ATE_unsigned
:
6417 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
6420 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
, cu
);
6424 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
, cu
);
6428 case DW_ATE_unsigned_char
:
6429 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
6432 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
6439 copy_die (struct die_info
*old_die
)
6441 struct die_info
*new_die
;
6444 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6445 memset (new_die
, 0, sizeof (struct die_info
));
6447 new_die
->tag
= old_die
->tag
;
6448 new_die
->has_children
= old_die
->has_children
;
6449 new_die
->abbrev
= old_die
->abbrev
;
6450 new_die
->offset
= old_die
->offset
;
6451 new_die
->type
= NULL
;
6453 num_attrs
= old_die
->num_attrs
;
6454 new_die
->num_attrs
= num_attrs
;
6455 new_die
->attrs
= (struct attribute
*)
6456 xmalloc (num_attrs
* sizeof (struct attribute
));
6458 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
6460 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
6461 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
6462 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
6465 new_die
->next
= NULL
;
6470 /* Return sibling of die, NULL if no sibling. */
6472 static struct die_info
*
6473 sibling_die (struct die_info
*die
)
6475 return die
->sibling
;
6478 /* Get linkage name of a die, return NULL if not found. */
6481 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6483 struct attribute
*attr
;
6485 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6486 if (attr
&& DW_STRING (attr
))
6487 return DW_STRING (attr
);
6488 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6489 if (attr
&& DW_STRING (attr
))
6490 return DW_STRING (attr
);
6494 /* Get name of a die, return NULL if not found. */
6497 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6499 struct attribute
*attr
;
6501 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6502 if (attr
&& DW_STRING (attr
))
6503 return DW_STRING (attr
);
6507 /* Return the die that this die in an extension of, or NULL if there
6510 static struct die_info
*
6511 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
*cu
)
6513 struct attribute
*attr
;
6514 struct die_info
*extension_die
;
6517 attr
= dwarf2_attr (die
, DW_AT_extension
, cu
);
6521 ref
= dwarf2_get_ref_die_offset (attr
, cu
);
6522 extension_die
= follow_die_ref (ref
);
6525 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
6528 return extension_die
;
6531 /* Convert a DIE tag into its string name. */
6534 dwarf_tag_name (unsigned tag
)
6538 case DW_TAG_padding
:
6539 return "DW_TAG_padding";
6540 case DW_TAG_array_type
:
6541 return "DW_TAG_array_type";
6542 case DW_TAG_class_type
:
6543 return "DW_TAG_class_type";
6544 case DW_TAG_entry_point
:
6545 return "DW_TAG_entry_point";
6546 case DW_TAG_enumeration_type
:
6547 return "DW_TAG_enumeration_type";
6548 case DW_TAG_formal_parameter
:
6549 return "DW_TAG_formal_parameter";
6550 case DW_TAG_imported_declaration
:
6551 return "DW_TAG_imported_declaration";
6553 return "DW_TAG_label";
6554 case DW_TAG_lexical_block
:
6555 return "DW_TAG_lexical_block";
6557 return "DW_TAG_member";
6558 case DW_TAG_pointer_type
:
6559 return "DW_TAG_pointer_type";
6560 case DW_TAG_reference_type
:
6561 return "DW_TAG_reference_type";
6562 case DW_TAG_compile_unit
:
6563 return "DW_TAG_compile_unit";
6564 case DW_TAG_string_type
:
6565 return "DW_TAG_string_type";
6566 case DW_TAG_structure_type
:
6567 return "DW_TAG_structure_type";
6568 case DW_TAG_subroutine_type
:
6569 return "DW_TAG_subroutine_type";
6570 case DW_TAG_typedef
:
6571 return "DW_TAG_typedef";
6572 case DW_TAG_union_type
:
6573 return "DW_TAG_union_type";
6574 case DW_TAG_unspecified_parameters
:
6575 return "DW_TAG_unspecified_parameters";
6576 case DW_TAG_variant
:
6577 return "DW_TAG_variant";
6578 case DW_TAG_common_block
:
6579 return "DW_TAG_common_block";
6580 case DW_TAG_common_inclusion
:
6581 return "DW_TAG_common_inclusion";
6582 case DW_TAG_inheritance
:
6583 return "DW_TAG_inheritance";
6584 case DW_TAG_inlined_subroutine
:
6585 return "DW_TAG_inlined_subroutine";
6587 return "DW_TAG_module";
6588 case DW_TAG_ptr_to_member_type
:
6589 return "DW_TAG_ptr_to_member_type";
6590 case DW_TAG_set_type
:
6591 return "DW_TAG_set_type";
6592 case DW_TAG_subrange_type
:
6593 return "DW_TAG_subrange_type";
6594 case DW_TAG_with_stmt
:
6595 return "DW_TAG_with_stmt";
6596 case DW_TAG_access_declaration
:
6597 return "DW_TAG_access_declaration";
6598 case DW_TAG_base_type
:
6599 return "DW_TAG_base_type";
6600 case DW_TAG_catch_block
:
6601 return "DW_TAG_catch_block";
6602 case DW_TAG_const_type
:
6603 return "DW_TAG_const_type";
6604 case DW_TAG_constant
:
6605 return "DW_TAG_constant";
6606 case DW_TAG_enumerator
:
6607 return "DW_TAG_enumerator";
6608 case DW_TAG_file_type
:
6609 return "DW_TAG_file_type";
6611 return "DW_TAG_friend";
6612 case DW_TAG_namelist
:
6613 return "DW_TAG_namelist";
6614 case DW_TAG_namelist_item
:
6615 return "DW_TAG_namelist_item";
6616 case DW_TAG_packed_type
:
6617 return "DW_TAG_packed_type";
6618 case DW_TAG_subprogram
:
6619 return "DW_TAG_subprogram";
6620 case DW_TAG_template_type_param
:
6621 return "DW_TAG_template_type_param";
6622 case DW_TAG_template_value_param
:
6623 return "DW_TAG_template_value_param";
6624 case DW_TAG_thrown_type
:
6625 return "DW_TAG_thrown_type";
6626 case DW_TAG_try_block
:
6627 return "DW_TAG_try_block";
6628 case DW_TAG_variant_part
:
6629 return "DW_TAG_variant_part";
6630 case DW_TAG_variable
:
6631 return "DW_TAG_variable";
6632 case DW_TAG_volatile_type
:
6633 return "DW_TAG_volatile_type";
6634 case DW_TAG_dwarf_procedure
:
6635 return "DW_TAG_dwarf_procedure";
6636 case DW_TAG_restrict_type
:
6637 return "DW_TAG_restrict_type";
6638 case DW_TAG_interface_type
:
6639 return "DW_TAG_interface_type";
6640 case DW_TAG_namespace
:
6641 return "DW_TAG_namespace";
6642 case DW_TAG_imported_module
:
6643 return "DW_TAG_imported_module";
6644 case DW_TAG_unspecified_type
:
6645 return "DW_TAG_unspecified_type";
6646 case DW_TAG_partial_unit
:
6647 return "DW_TAG_partial_unit";
6648 case DW_TAG_imported_unit
:
6649 return "DW_TAG_imported_unit";
6650 case DW_TAG_MIPS_loop
:
6651 return "DW_TAG_MIPS_loop";
6652 case DW_TAG_format_label
:
6653 return "DW_TAG_format_label";
6654 case DW_TAG_function_template
:
6655 return "DW_TAG_function_template";
6656 case DW_TAG_class_template
:
6657 return "DW_TAG_class_template";
6659 return "DW_TAG_<unknown>";
6663 /* Convert a DWARF attribute code into its string name. */
6666 dwarf_attr_name (unsigned attr
)
6671 return "DW_AT_sibling";
6672 case DW_AT_location
:
6673 return "DW_AT_location";
6675 return "DW_AT_name";
6676 case DW_AT_ordering
:
6677 return "DW_AT_ordering";
6678 case DW_AT_subscr_data
:
6679 return "DW_AT_subscr_data";
6680 case DW_AT_byte_size
:
6681 return "DW_AT_byte_size";
6682 case DW_AT_bit_offset
:
6683 return "DW_AT_bit_offset";
6684 case DW_AT_bit_size
:
6685 return "DW_AT_bit_size";
6686 case DW_AT_element_list
:
6687 return "DW_AT_element_list";
6688 case DW_AT_stmt_list
:
6689 return "DW_AT_stmt_list";
6691 return "DW_AT_low_pc";
6693 return "DW_AT_high_pc";
6694 case DW_AT_language
:
6695 return "DW_AT_language";
6697 return "DW_AT_member";
6699 return "DW_AT_discr";
6700 case DW_AT_discr_value
:
6701 return "DW_AT_discr_value";
6702 case DW_AT_visibility
:
6703 return "DW_AT_visibility";
6705 return "DW_AT_import";
6706 case DW_AT_string_length
:
6707 return "DW_AT_string_length";
6708 case DW_AT_common_reference
:
6709 return "DW_AT_common_reference";
6710 case DW_AT_comp_dir
:
6711 return "DW_AT_comp_dir";
6712 case DW_AT_const_value
:
6713 return "DW_AT_const_value";
6714 case DW_AT_containing_type
:
6715 return "DW_AT_containing_type";
6716 case DW_AT_default_value
:
6717 return "DW_AT_default_value";
6719 return "DW_AT_inline";
6720 case DW_AT_is_optional
:
6721 return "DW_AT_is_optional";
6722 case DW_AT_lower_bound
:
6723 return "DW_AT_lower_bound";
6724 case DW_AT_producer
:
6725 return "DW_AT_producer";
6726 case DW_AT_prototyped
:
6727 return "DW_AT_prototyped";
6728 case DW_AT_return_addr
:
6729 return "DW_AT_return_addr";
6730 case DW_AT_start_scope
:
6731 return "DW_AT_start_scope";
6732 case DW_AT_stride_size
:
6733 return "DW_AT_stride_size";
6734 case DW_AT_upper_bound
:
6735 return "DW_AT_upper_bound";
6736 case DW_AT_abstract_origin
:
6737 return "DW_AT_abstract_origin";
6738 case DW_AT_accessibility
:
6739 return "DW_AT_accessibility";
6740 case DW_AT_address_class
:
6741 return "DW_AT_address_class";
6742 case DW_AT_artificial
:
6743 return "DW_AT_artificial";
6744 case DW_AT_base_types
:
6745 return "DW_AT_base_types";
6746 case DW_AT_calling_convention
:
6747 return "DW_AT_calling_convention";
6749 return "DW_AT_count";
6750 case DW_AT_data_member_location
:
6751 return "DW_AT_data_member_location";
6752 case DW_AT_decl_column
:
6753 return "DW_AT_decl_column";
6754 case DW_AT_decl_file
:
6755 return "DW_AT_decl_file";
6756 case DW_AT_decl_line
:
6757 return "DW_AT_decl_line";
6758 case DW_AT_declaration
:
6759 return "DW_AT_declaration";
6760 case DW_AT_discr_list
:
6761 return "DW_AT_discr_list";
6762 case DW_AT_encoding
:
6763 return "DW_AT_encoding";
6764 case DW_AT_external
:
6765 return "DW_AT_external";
6766 case DW_AT_frame_base
:
6767 return "DW_AT_frame_base";
6769 return "DW_AT_friend";
6770 case DW_AT_identifier_case
:
6771 return "DW_AT_identifier_case";
6772 case DW_AT_macro_info
:
6773 return "DW_AT_macro_info";
6774 case DW_AT_namelist_items
:
6775 return "DW_AT_namelist_items";
6776 case DW_AT_priority
:
6777 return "DW_AT_priority";
6779 return "DW_AT_segment";
6780 case DW_AT_specification
:
6781 return "DW_AT_specification";
6782 case DW_AT_static_link
:
6783 return "DW_AT_static_link";
6785 return "DW_AT_type";
6786 case DW_AT_use_location
:
6787 return "DW_AT_use_location";
6788 case DW_AT_variable_parameter
:
6789 return "DW_AT_variable_parameter";
6790 case DW_AT_virtuality
:
6791 return "DW_AT_virtuality";
6792 case DW_AT_vtable_elem_location
:
6793 return "DW_AT_vtable_elem_location";
6794 case DW_AT_allocated
:
6795 return "DW_AT_allocated";
6796 case DW_AT_associated
:
6797 return "DW_AT_associated";
6798 case DW_AT_data_location
:
6799 return "DW_AT_data_location";
6801 return "DW_AT_stride";
6802 case DW_AT_entry_pc
:
6803 return "DW_AT_entry_pc";
6804 case DW_AT_use_UTF8
:
6805 return "DW_AT_use_UTF8";
6806 case DW_AT_extension
:
6807 return "DW_AT_extension";
6809 return "DW_AT_ranges";
6810 case DW_AT_trampoline
:
6811 return "DW_AT_trampoline";
6812 case DW_AT_call_column
:
6813 return "DW_AT_call_column";
6814 case DW_AT_call_file
:
6815 return "DW_AT_call_file";
6816 case DW_AT_call_line
:
6817 return "DW_AT_call_line";
6819 case DW_AT_MIPS_fde
:
6820 return "DW_AT_MIPS_fde";
6821 case DW_AT_MIPS_loop_begin
:
6822 return "DW_AT_MIPS_loop_begin";
6823 case DW_AT_MIPS_tail_loop_begin
:
6824 return "DW_AT_MIPS_tail_loop_begin";
6825 case DW_AT_MIPS_epilog_begin
:
6826 return "DW_AT_MIPS_epilog_begin";
6827 case DW_AT_MIPS_loop_unroll_factor
:
6828 return "DW_AT_MIPS_loop_unroll_factor";
6829 case DW_AT_MIPS_software_pipeline_depth
:
6830 return "DW_AT_MIPS_software_pipeline_depth";
6832 case DW_AT_MIPS_linkage_name
:
6833 return "DW_AT_MIPS_linkage_name";
6835 case DW_AT_sf_names
:
6836 return "DW_AT_sf_names";
6837 case DW_AT_src_info
:
6838 return "DW_AT_src_info";
6839 case DW_AT_mac_info
:
6840 return "DW_AT_mac_info";
6841 case DW_AT_src_coords
:
6842 return "DW_AT_src_coords";
6843 case DW_AT_body_begin
:
6844 return "DW_AT_body_begin";
6845 case DW_AT_body_end
:
6846 return "DW_AT_body_end";
6847 case DW_AT_GNU_vector
:
6848 return "DW_AT_GNU_vector";
6850 return "DW_AT_<unknown>";
6854 /* Convert a DWARF value form code into its string name. */
6857 dwarf_form_name (unsigned form
)
6862 return "DW_FORM_addr";
6863 case DW_FORM_block2
:
6864 return "DW_FORM_block2";
6865 case DW_FORM_block4
:
6866 return "DW_FORM_block4";
6868 return "DW_FORM_data2";
6870 return "DW_FORM_data4";
6872 return "DW_FORM_data8";
6873 case DW_FORM_string
:
6874 return "DW_FORM_string";
6876 return "DW_FORM_block";
6877 case DW_FORM_block1
:
6878 return "DW_FORM_block1";
6880 return "DW_FORM_data1";
6882 return "DW_FORM_flag";
6884 return "DW_FORM_sdata";
6886 return "DW_FORM_strp";
6888 return "DW_FORM_udata";
6889 case DW_FORM_ref_addr
:
6890 return "DW_FORM_ref_addr";
6892 return "DW_FORM_ref1";
6894 return "DW_FORM_ref2";
6896 return "DW_FORM_ref4";
6898 return "DW_FORM_ref8";
6899 case DW_FORM_ref_udata
:
6900 return "DW_FORM_ref_udata";
6901 case DW_FORM_indirect
:
6902 return "DW_FORM_indirect";
6904 return "DW_FORM_<unknown>";
6908 /* Convert a DWARF stack opcode into its string name. */
6911 dwarf_stack_op_name (unsigned op
)
6916 return "DW_OP_addr";
6918 return "DW_OP_deref";
6920 return "DW_OP_const1u";
6922 return "DW_OP_const1s";
6924 return "DW_OP_const2u";
6926 return "DW_OP_const2s";
6928 return "DW_OP_const4u";
6930 return "DW_OP_const4s";
6932 return "DW_OP_const8u";
6934 return "DW_OP_const8s";
6936 return "DW_OP_constu";
6938 return "DW_OP_consts";
6942 return "DW_OP_drop";
6944 return "DW_OP_over";
6946 return "DW_OP_pick";
6948 return "DW_OP_swap";
6952 return "DW_OP_xderef";
6960 return "DW_OP_minus";
6972 return "DW_OP_plus";
6973 case DW_OP_plus_uconst
:
6974 return "DW_OP_plus_uconst";
6980 return "DW_OP_shra";
6998 return "DW_OP_skip";
7000 return "DW_OP_lit0";
7002 return "DW_OP_lit1";
7004 return "DW_OP_lit2";
7006 return "DW_OP_lit3";
7008 return "DW_OP_lit4";
7010 return "DW_OP_lit5";
7012 return "DW_OP_lit6";
7014 return "DW_OP_lit7";
7016 return "DW_OP_lit8";
7018 return "DW_OP_lit9";
7020 return "DW_OP_lit10";
7022 return "DW_OP_lit11";
7024 return "DW_OP_lit12";
7026 return "DW_OP_lit13";
7028 return "DW_OP_lit14";
7030 return "DW_OP_lit15";
7032 return "DW_OP_lit16";
7034 return "DW_OP_lit17";
7036 return "DW_OP_lit18";
7038 return "DW_OP_lit19";
7040 return "DW_OP_lit20";
7042 return "DW_OP_lit21";
7044 return "DW_OP_lit22";
7046 return "DW_OP_lit23";
7048 return "DW_OP_lit24";
7050 return "DW_OP_lit25";
7052 return "DW_OP_lit26";
7054 return "DW_OP_lit27";
7056 return "DW_OP_lit28";
7058 return "DW_OP_lit29";
7060 return "DW_OP_lit30";
7062 return "DW_OP_lit31";
7064 return "DW_OP_reg0";
7066 return "DW_OP_reg1";
7068 return "DW_OP_reg2";
7070 return "DW_OP_reg3";
7072 return "DW_OP_reg4";
7074 return "DW_OP_reg5";
7076 return "DW_OP_reg6";
7078 return "DW_OP_reg7";
7080 return "DW_OP_reg8";
7082 return "DW_OP_reg9";
7084 return "DW_OP_reg10";
7086 return "DW_OP_reg11";
7088 return "DW_OP_reg12";
7090 return "DW_OP_reg13";
7092 return "DW_OP_reg14";
7094 return "DW_OP_reg15";
7096 return "DW_OP_reg16";
7098 return "DW_OP_reg17";
7100 return "DW_OP_reg18";
7102 return "DW_OP_reg19";
7104 return "DW_OP_reg20";
7106 return "DW_OP_reg21";
7108 return "DW_OP_reg22";
7110 return "DW_OP_reg23";
7112 return "DW_OP_reg24";
7114 return "DW_OP_reg25";
7116 return "DW_OP_reg26";
7118 return "DW_OP_reg27";
7120 return "DW_OP_reg28";
7122 return "DW_OP_reg29";
7124 return "DW_OP_reg30";
7126 return "DW_OP_reg31";
7128 return "DW_OP_breg0";
7130 return "DW_OP_breg1";
7132 return "DW_OP_breg2";
7134 return "DW_OP_breg3";
7136 return "DW_OP_breg4";
7138 return "DW_OP_breg5";
7140 return "DW_OP_breg6";
7142 return "DW_OP_breg7";
7144 return "DW_OP_breg8";
7146 return "DW_OP_breg9";
7148 return "DW_OP_breg10";
7150 return "DW_OP_breg11";
7152 return "DW_OP_breg12";
7154 return "DW_OP_breg13";
7156 return "DW_OP_breg14";
7158 return "DW_OP_breg15";
7160 return "DW_OP_breg16";
7162 return "DW_OP_breg17";
7164 return "DW_OP_breg18";
7166 return "DW_OP_breg19";
7168 return "DW_OP_breg20";
7170 return "DW_OP_breg21";
7172 return "DW_OP_breg22";
7174 return "DW_OP_breg23";
7176 return "DW_OP_breg24";
7178 return "DW_OP_breg25";
7180 return "DW_OP_breg26";
7182 return "DW_OP_breg27";
7184 return "DW_OP_breg28";
7186 return "DW_OP_breg29";
7188 return "DW_OP_breg30";
7190 return "DW_OP_breg31";
7192 return "DW_OP_regx";
7194 return "DW_OP_fbreg";
7196 return "DW_OP_bregx";
7198 return "DW_OP_piece";
7199 case DW_OP_deref_size
:
7200 return "DW_OP_deref_size";
7201 case DW_OP_xderef_size
:
7202 return "DW_OP_xderef_size";
7205 /* DWARF 3 extensions. */
7206 case DW_OP_push_object_address
:
7207 return "DW_OP_push_object_address";
7209 return "DW_OP_call2";
7211 return "DW_OP_call4";
7212 case DW_OP_call_ref
:
7213 return "DW_OP_call_ref";
7214 /* GNU extensions. */
7215 case DW_OP_GNU_push_tls_address
:
7216 return "DW_OP_GNU_push_tls_address";
7218 return "OP_<unknown>";
7223 dwarf_bool_name (unsigned mybool
)
7231 /* Convert a DWARF type code into its string name. */
7234 dwarf_type_encoding_name (unsigned enc
)
7238 case DW_ATE_address
:
7239 return "DW_ATE_address";
7240 case DW_ATE_boolean
:
7241 return "DW_ATE_boolean";
7242 case DW_ATE_complex_float
:
7243 return "DW_ATE_complex_float";
7245 return "DW_ATE_float";
7247 return "DW_ATE_signed";
7248 case DW_ATE_signed_char
:
7249 return "DW_ATE_signed_char";
7250 case DW_ATE_unsigned
:
7251 return "DW_ATE_unsigned";
7252 case DW_ATE_unsigned_char
:
7253 return "DW_ATE_unsigned_char";
7254 case DW_ATE_imaginary_float
:
7255 return "DW_ATE_imaginary_float";
7257 return "DW_ATE_<unknown>";
7261 /* Convert a DWARF call frame info operation to its string name. */
7265 dwarf_cfi_name (unsigned cfi_opc
)
7269 case DW_CFA_advance_loc
:
7270 return "DW_CFA_advance_loc";
7272 return "DW_CFA_offset";
7273 case DW_CFA_restore
:
7274 return "DW_CFA_restore";
7276 return "DW_CFA_nop";
7277 case DW_CFA_set_loc
:
7278 return "DW_CFA_set_loc";
7279 case DW_CFA_advance_loc1
:
7280 return "DW_CFA_advance_loc1";
7281 case DW_CFA_advance_loc2
:
7282 return "DW_CFA_advance_loc2";
7283 case DW_CFA_advance_loc4
:
7284 return "DW_CFA_advance_loc4";
7285 case DW_CFA_offset_extended
:
7286 return "DW_CFA_offset_extended";
7287 case DW_CFA_restore_extended
:
7288 return "DW_CFA_restore_extended";
7289 case DW_CFA_undefined
:
7290 return "DW_CFA_undefined";
7291 case DW_CFA_same_value
:
7292 return "DW_CFA_same_value";
7293 case DW_CFA_register
:
7294 return "DW_CFA_register";
7295 case DW_CFA_remember_state
:
7296 return "DW_CFA_remember_state";
7297 case DW_CFA_restore_state
:
7298 return "DW_CFA_restore_state";
7299 case DW_CFA_def_cfa
:
7300 return "DW_CFA_def_cfa";
7301 case DW_CFA_def_cfa_register
:
7302 return "DW_CFA_def_cfa_register";
7303 case DW_CFA_def_cfa_offset
:
7304 return "DW_CFA_def_cfa_offset";
7307 case DW_CFA_def_cfa_expression
:
7308 return "DW_CFA_def_cfa_expression";
7309 case DW_CFA_expression
:
7310 return "DW_CFA_expression";
7311 case DW_CFA_offset_extended_sf
:
7312 return "DW_CFA_offset_extended_sf";
7313 case DW_CFA_def_cfa_sf
:
7314 return "DW_CFA_def_cfa_sf";
7315 case DW_CFA_def_cfa_offset_sf
:
7316 return "DW_CFA_def_cfa_offset_sf";
7318 /* SGI/MIPS specific */
7319 case DW_CFA_MIPS_advance_loc8
:
7320 return "DW_CFA_MIPS_advance_loc8";
7322 /* GNU extensions */
7323 case DW_CFA_GNU_window_save
:
7324 return "DW_CFA_GNU_window_save";
7325 case DW_CFA_GNU_args_size
:
7326 return "DW_CFA_GNU_args_size";
7327 case DW_CFA_GNU_negative_offset_extended
:
7328 return "DW_CFA_GNU_negative_offset_extended";
7331 return "DW_CFA_<unknown>";
7337 dump_die (struct die_info
*die
)
7341 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
7342 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
7343 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
7344 dwarf_bool_name (die
->child
!= NULL
));
7346 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
7347 for (i
= 0; i
< die
->num_attrs
; ++i
)
7349 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
7350 dwarf_attr_name (die
->attrs
[i
].name
),
7351 dwarf_form_name (die
->attrs
[i
].form
));
7352 switch (die
->attrs
[i
].form
)
7354 case DW_FORM_ref_addr
:
7356 fprintf_unfiltered (gdb_stderr
, "address: ");
7357 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
7359 case DW_FORM_block2
:
7360 case DW_FORM_block4
:
7362 case DW_FORM_block1
:
7363 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
7374 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
7376 case DW_FORM_string
:
7378 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
7379 DW_STRING (&die
->attrs
[i
])
7380 ? DW_STRING (&die
->attrs
[i
]) : "");
7383 if (DW_UNSND (&die
->attrs
[i
]))
7384 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
7386 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
7388 case DW_FORM_indirect
:
7389 /* the reader will have reduced the indirect form to
7390 the "base form" so this form should not occur */
7391 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
7394 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
7395 die
->attrs
[i
].form
);
7397 fprintf_unfiltered (gdb_stderr
, "\n");
7402 dump_die_list (struct die_info
*die
)
7407 if (die
->child
!= NULL
)
7408 dump_die_list (die
->child
);
7409 if (die
->sibling
!= NULL
)
7410 dump_die_list (die
->sibling
);
7415 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
7418 struct die_info
*old
;
7420 h
= (offset
% REF_HASH_SIZE
);
7421 old
= die_ref_table
[h
];
7422 die
->next_ref
= old
;
7423 die_ref_table
[h
] = die
;
7428 dwarf2_empty_hash_tables (void)
7430 memset (die_ref_table
, 0, sizeof (die_ref_table
));
7434 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
7436 unsigned int result
= 0;
7440 case DW_FORM_ref_addr
:
7441 result
= DW_ADDR (attr
);
7447 case DW_FORM_ref_udata
:
7448 result
= cu
->header
.offset
+ DW_UNSND (attr
);
7451 complaint (&symfile_complaints
,
7452 "unsupported die ref attribute form: '%s'",
7453 dwarf_form_name (attr
->form
));
7458 /* Return the constant value held by the given attribute. Return -1
7459 if the value held by the attribute is not constant. */
7462 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
7464 if (attr
->form
== DW_FORM_sdata
)
7465 return DW_SND (attr
);
7466 else if (attr
->form
== DW_FORM_udata
7467 || attr
->form
== DW_FORM_data1
7468 || attr
->form
== DW_FORM_data2
7469 || attr
->form
== DW_FORM_data4
7470 || attr
->form
== DW_FORM_data8
)
7471 return DW_UNSND (attr
);
7474 complaint (&symfile_complaints
, "Attribute value is not a constant (%s)",
7475 dwarf_form_name (attr
->form
));
7476 return default_value
;
7480 static struct die_info
*
7481 follow_die_ref (unsigned int offset
)
7483 struct die_info
*die
;
7486 h
= (offset
% REF_HASH_SIZE
);
7487 die
= die_ref_table
[h
];
7490 if (die
->offset
== offset
)
7494 die
= die
->next_ref
;
7499 static struct type
*
7500 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid,
7501 struct dwarf2_cu
*cu
)
7503 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
7505 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
7506 typeid, objfile
->name
);
7509 /* Look for this particular type in the fundamental type vector. If
7510 one is not found, create and install one appropriate for the
7511 current language and the current target machine. */
7513 if (cu
->ftypes
[typeid] == NULL
)
7515 cu
->ftypes
[typeid] = cu
->language_defn
->la_fund_type (objfile
, typeid);
7518 return (cu
->ftypes
[typeid]);
7521 /* Decode simple location descriptions.
7522 Given a pointer to a dwarf block that defines a location, compute
7523 the location and return the value.
7525 NOTE drow/2003-11-18: This function is called in two situations
7526 now: for the address of static or global variables (partial symbols
7527 only) and for offsets into structures which are expected to be
7528 (more or less) constant. The partial symbol case should go away,
7529 and only the constant case should remain. That will let this
7530 function complain more accurately. A few special modes are allowed
7531 without complaint for global variables (for instance, global
7532 register values and thread-local values).
7534 A location description containing no operations indicates that the
7535 object is optimized out. The return value is 0 for that case.
7536 FIXME drow/2003-11-16: No callers check for this case any more; soon all
7537 callers will only want a very basic result and this can become a
7540 When the result is a register number, the global isreg flag is set,
7541 otherwise it is cleared.
7543 Note that stack[0] is unused except as a default error return.
7544 Note that stack overflow is not yet handled. */
7547 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
7549 struct objfile
*objfile
= cu
->objfile
;
7550 struct comp_unit_head
*cu_header
= &cu
->header
;
7552 int size
= blk
->size
;
7553 char *data
= blk
->data
;
7554 CORE_ADDR stack
[64];
7556 unsigned int bytes_read
, unsnd
;
7601 stack
[++stacki
] = op
- DW_OP_lit0
;
7637 stack
[++stacki
] = op
- DW_OP_reg0
;
7639 dwarf2_complex_location_expr_complaint ();
7644 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
7646 stack
[++stacki
] = unsnd
;
7648 dwarf2_complex_location_expr_complaint ();
7652 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
7658 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
7663 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
7668 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
7673 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
7678 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
7683 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
7688 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
7694 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
7699 stack
[stacki
+ 1] = stack
[stacki
];
7704 stack
[stacki
- 1] += stack
[stacki
];
7708 case DW_OP_plus_uconst
:
7709 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
7714 stack
[stacki
- 1] -= stack
[stacki
];
7719 /* If we're not the last op, then we definitely can't encode
7720 this using GDB's address_class enum. This is valid for partial
7721 global symbols, although the variable's address will be bogus
7724 dwarf2_complex_location_expr_complaint ();
7727 case DW_OP_GNU_push_tls_address
:
7728 /* The top of the stack has the offset from the beginning
7729 of the thread control block at which the variable is located. */
7730 /* Nothing should follow this operator, so the top of stack would
7732 /* This is valid for partial global symbols, but the variable's
7733 address will be bogus in the psymtab. */
7735 dwarf2_complex_location_expr_complaint ();
7739 complaint (&symfile_complaints
, "unsupported stack op: '%s'",
7740 dwarf_stack_op_name (op
));
7741 return (stack
[stacki
]);
7744 return (stack
[stacki
]);
7747 /* memory allocation interface */
7750 dwarf2_free_tmp_obstack (void *ignore
)
7752 obstack_free (&dwarf2_tmp_obstack
, NULL
);
7755 static struct dwarf_block
*
7756 dwarf_alloc_block (void)
7758 struct dwarf_block
*blk
;
7760 blk
= (struct dwarf_block
*)
7761 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
7765 static struct abbrev_info
*
7766 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
7768 struct abbrev_info
*abbrev
;
7770 abbrev
= (struct abbrev_info
*)
7771 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
7772 memset (abbrev
, 0, sizeof (struct abbrev_info
));
7776 static struct die_info
*
7777 dwarf_alloc_die (void)
7779 struct die_info
*die
;
7781 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
7782 memset (die
, 0, sizeof (struct die_info
));
7787 /* Macro support. */
7790 /* Return the full name of file number I in *LH's file name table.
7791 Use COMP_DIR as the name of the current directory of the
7792 compilation. The result is allocated using xmalloc; the caller is
7793 responsible for freeing it. */
7795 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
7797 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7799 if (IS_ABSOLUTE_PATH (fe
->name
))
7800 return xstrdup (fe
->name
);
7808 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7814 dir_len
= strlen (dir
);
7815 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
7816 strcpy (full_name
, dir
);
7817 full_name
[dir_len
] = '/';
7818 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
7822 return xstrdup (fe
->name
);
7827 static struct macro_source_file
*
7828 macro_start_file (int file
, int line
,
7829 struct macro_source_file
*current_file
,
7830 const char *comp_dir
,
7831 struct line_header
*lh
, struct objfile
*objfile
)
7833 /* The full name of this source file. */
7834 char *full_name
= file_full_name (file
, lh
, comp_dir
);
7836 /* We don't create a macro table for this compilation unit
7837 at all until we actually get a filename. */
7838 if (! pending_macros
)
7839 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
7840 objfile
->macro_cache
);
7843 /* If we have no current file, then this must be the start_file
7844 directive for the compilation unit's main source file. */
7845 current_file
= macro_set_main (pending_macros
, full_name
);
7847 current_file
= macro_include (current_file
, line
, full_name
);
7851 return current_file
;
7855 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
7856 followed by a null byte. */
7858 copy_string (const char *buf
, int len
)
7860 char *s
= xmalloc (len
+ 1);
7861 memcpy (s
, buf
, len
);
7869 consume_improper_spaces (const char *p
, const char *body
)
7873 complaint (&symfile_complaints
,
7874 "macro definition contains spaces in formal argument list:\n`%s'",
7886 parse_macro_definition (struct macro_source_file
*file
, int line
,
7891 /* The body string takes one of two forms. For object-like macro
7892 definitions, it should be:
7894 <macro name> " " <definition>
7896 For function-like macro definitions, it should be:
7898 <macro name> "() " <definition>
7900 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
7902 Spaces may appear only where explicitly indicated, and in the
7905 The Dwarf 2 spec says that an object-like macro's name is always
7906 followed by a space, but versions of GCC around March 2002 omit
7907 the space when the macro's definition is the empty string.
7909 The Dwarf 2 spec says that there should be no spaces between the
7910 formal arguments in a function-like macro's formal argument list,
7911 but versions of GCC around March 2002 include spaces after the
7915 /* Find the extent of the macro name. The macro name is terminated
7916 by either a space or null character (for an object-like macro) or
7917 an opening paren (for a function-like macro). */
7918 for (p
= body
; *p
; p
++)
7919 if (*p
== ' ' || *p
== '(')
7922 if (*p
== ' ' || *p
== '\0')
7924 /* It's an object-like macro. */
7925 int name_len
= p
- body
;
7926 char *name
= copy_string (body
, name_len
);
7927 const char *replacement
;
7930 replacement
= body
+ name_len
+ 1;
7933 dwarf2_macro_malformed_definition_complaint (body
);
7934 replacement
= body
+ name_len
;
7937 macro_define_object (file
, line
, name
, replacement
);
7943 /* It's a function-like macro. */
7944 char *name
= copy_string (body
, p
- body
);
7947 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
7951 p
= consume_improper_spaces (p
, body
);
7953 /* Parse the formal argument list. */
7954 while (*p
&& *p
!= ')')
7956 /* Find the extent of the current argument name. */
7957 const char *arg_start
= p
;
7959 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
7962 if (! *p
|| p
== arg_start
)
7963 dwarf2_macro_malformed_definition_complaint (body
);
7966 /* Make sure argv has room for the new argument. */
7967 if (argc
>= argv_size
)
7970 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
7973 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
7976 p
= consume_improper_spaces (p
, body
);
7978 /* Consume the comma, if present. */
7983 p
= consume_improper_spaces (p
, body
);
7992 /* Perfectly formed definition, no complaints. */
7993 macro_define_function (file
, line
, name
,
7994 argc
, (const char **) argv
,
7996 else if (*p
== '\0')
7998 /* Complain, but do define it. */
7999 dwarf2_macro_malformed_definition_complaint (body
);
8000 macro_define_function (file
, line
, name
,
8001 argc
, (const char **) argv
,
8005 /* Just complain. */
8006 dwarf2_macro_malformed_definition_complaint (body
);
8009 /* Just complain. */
8010 dwarf2_macro_malformed_definition_complaint (body
);
8016 for (i
= 0; i
< argc
; i
++)
8022 dwarf2_macro_malformed_definition_complaint (body
);
8027 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
8028 char *comp_dir
, bfd
*abfd
,
8029 struct dwarf2_cu
*cu
)
8031 char *mac_ptr
, *mac_end
;
8032 struct macro_source_file
*current_file
= 0;
8034 if (dwarf_macinfo_buffer
== NULL
)
8036 complaint (&symfile_complaints
, "missing .debug_macinfo section");
8040 mac_ptr
= dwarf_macinfo_buffer
+ offset
;
8041 mac_end
= dwarf_macinfo_buffer
+ dwarf_macinfo_size
;
8045 enum dwarf_macinfo_record_type macinfo_type
;
8047 /* Do we at least have room for a macinfo type byte? */
8048 if (mac_ptr
>= mac_end
)
8050 dwarf2_macros_too_long_complaint ();
8054 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
8057 switch (macinfo_type
)
8059 /* A zero macinfo type indicates the end of the macro
8064 case DW_MACINFO_define
:
8065 case DW_MACINFO_undef
:
8071 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8072 mac_ptr
+= bytes_read
;
8073 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
8074 mac_ptr
+= bytes_read
;
8077 complaint (&symfile_complaints
,
8078 "debug info gives macro %s outside of any file: %s",
8080 DW_MACINFO_define
? "definition" : macinfo_type
==
8081 DW_MACINFO_undef
? "undefinition" :
8082 "something-or-other", body
);
8085 if (macinfo_type
== DW_MACINFO_define
)
8086 parse_macro_definition (current_file
, line
, body
);
8087 else if (macinfo_type
== DW_MACINFO_undef
)
8088 macro_undef (current_file
, line
, body
);
8093 case DW_MACINFO_start_file
:
8098 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8099 mac_ptr
+= bytes_read
;
8100 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8101 mac_ptr
+= bytes_read
;
8103 current_file
= macro_start_file (file
, line
,
8104 current_file
, comp_dir
,
8109 case DW_MACINFO_end_file
:
8111 complaint (&symfile_complaints
,
8112 "macro debug info has an unmatched `close_file' directive");
8115 current_file
= current_file
->included_by
;
8118 enum dwarf_macinfo_record_type next_type
;
8120 /* GCC circa March 2002 doesn't produce the zero
8121 type byte marking the end of the compilation
8122 unit. Complain if it's not there, but exit no
8125 /* Do we at least have room for a macinfo type byte? */
8126 if (mac_ptr
>= mac_end
)
8128 dwarf2_macros_too_long_complaint ();
8132 /* We don't increment mac_ptr here, so this is just
8134 next_type
= read_1_byte (abfd
, mac_ptr
);
8136 complaint (&symfile_complaints
,
8137 "no terminating 0-type entry for macros in `.debug_macinfo' section");
8144 case DW_MACINFO_vendor_ext
:
8150 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8151 mac_ptr
+= bytes_read
;
8152 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
8153 mac_ptr
+= bytes_read
;
8155 /* We don't recognize any vendor extensions. */
8162 /* Check if the attribute's form is a DW_FORM_block*
8163 if so return true else false. */
8165 attr_form_is_block (struct attribute
*attr
)
8167 return (attr
== NULL
? 0 :
8168 attr
->form
== DW_FORM_block1
8169 || attr
->form
== DW_FORM_block2
8170 || attr
->form
== DW_FORM_block4
8171 || attr
->form
== DW_FORM_block
);
8175 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
8176 struct dwarf2_cu
*cu
)
8178 if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
8180 struct dwarf2_loclist_baton
*baton
;
8182 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
8183 sizeof (struct dwarf2_loclist_baton
));
8184 baton
->objfile
= cu
->objfile
;
8186 /* We don't know how long the location list is, but make sure we
8187 don't run off the edge of the section. */
8188 baton
->size
= dwarf_loc_size
- DW_UNSND (attr
);
8189 baton
->data
= dwarf_loc_buffer
+ DW_UNSND (attr
);
8190 baton
->base_address
= cu
->header
.base_address
;
8191 if (cu
->header
.base_known
== 0)
8192 complaint (&symfile_complaints
,
8193 "Location list used without specifying the CU base address.");
8195 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
8196 SYMBOL_LOCATION_BATON (sym
) = baton
;
8200 struct dwarf2_locexpr_baton
*baton
;
8202 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
8203 sizeof (struct dwarf2_locexpr_baton
));
8204 baton
->objfile
= cu
->objfile
;
8206 if (attr_form_is_block (attr
))
8208 /* Note that we're just copying the block's data pointer
8209 here, not the actual data. We're still pointing into the
8210 dwarf_info_buffer for SYM's objfile; right now we never
8211 release that buffer, but when we do clean up properly
8212 this may need to change. */
8213 baton
->size
= DW_BLOCK (attr
)->size
;
8214 baton
->data
= DW_BLOCK (attr
)->data
;
8218 dwarf2_invalid_attrib_class_complaint ("location description",
8219 SYMBOL_NATURAL_NAME (sym
));
8224 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
8225 SYMBOL_LOCATION_BATON (sym
) = baton
;