1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 Free Software Foundation, Inc.
6 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
7 Inc. with support from Florida State University (under contract
8 with the Ada Joint Program Office), and Silicon Graphics, Inc.
9 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
10 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
11 support in dwarfread.c
13 This file is part of GDB.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or (at
18 your option) any later version.
20 This program is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. */
35 #include "elf/dwarf2.h"
38 #include "expression.h"
39 #include "filenames.h" /* for DOSish file names */
42 #include "complaints.h"
44 #include "dwarf2expr.h"
45 #include "dwarf2loc.h"
46 #include "cp-support.h"
49 #include "gdb_string.h"
50 #include "gdb_assert.h"
51 #include <sys/types.h>
53 /* A note on memory usage for this file.
55 At the present time, this code reads the debug info sections into
56 the objfile's objfile_obstack. A definite improvement for startup
57 time, on platforms which do not emit relocations for debug
58 sections, would be to use mmap instead. The object's complete
59 debug information is loaded into memory, partly to simplify
60 absolute DIE references.
62 Whether using obstacks or mmap, the sections should remain loaded
63 until the objfile is released, and pointers into the section data
64 can be used for any other data associated to the objfile (symbol
65 names, type names, location expressions to name a few). */
67 #ifndef DWARF2_REG_TO_REGNUM
68 #define DWARF2_REG_TO_REGNUM(REG) (REG)
72 /* .debug_info header for a compilation unit
73 Because of alignment constraints, this structure has padding and cannot
74 be mapped directly onto the beginning of the .debug_info section. */
75 typedef struct comp_unit_header
77 unsigned int length
; /* length of the .debug_info
79 unsigned short version
; /* version number -- 2 for DWARF
81 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
82 unsigned char addr_size
; /* byte size of an address -- 4 */
85 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
88 /* .debug_pubnames header
89 Because of alignment constraints, this structure has padding and cannot
90 be mapped directly onto the beginning of the .debug_info section. */
91 typedef struct pubnames_header
93 unsigned int length
; /* length of the .debug_pubnames
95 unsigned char version
; /* version number -- 2 for DWARF
97 unsigned int info_offset
; /* offset into .debug_info section */
98 unsigned int info_size
; /* byte size of .debug_info section
102 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
104 /* .debug_pubnames header
105 Because of alignment constraints, this structure has padding and cannot
106 be mapped directly onto the beginning of the .debug_info section. */
107 typedef struct aranges_header
109 unsigned int length
; /* byte len of the .debug_aranges
111 unsigned short version
; /* version number -- 2 for DWARF
113 unsigned int info_offset
; /* offset into .debug_info section */
114 unsigned char addr_size
; /* byte size of an address */
115 unsigned char seg_size
; /* byte size of segment descriptor */
118 #define _ACTUAL_ARANGES_HEADER_SIZE 12
120 /* .debug_line statement program prologue
121 Because of alignment constraints, this structure has padding and cannot
122 be mapped directly onto the beginning of the .debug_info section. */
123 typedef struct statement_prologue
125 unsigned int total_length
; /* byte length of the statement
127 unsigned short version
; /* version number -- 2 for DWARF
129 unsigned int prologue_length
; /* # bytes between prologue &
131 unsigned char minimum_instruction_length
; /* byte size of
133 unsigned char default_is_stmt
; /* initial value of is_stmt
136 unsigned char line_range
;
137 unsigned char opcode_base
; /* number assigned to first special
139 unsigned char *standard_opcode_lengths
;
143 /* offsets and sizes of debugging sections */
145 static unsigned int dwarf_info_size
;
146 static unsigned int dwarf_abbrev_size
;
147 static unsigned int dwarf_line_size
;
148 static unsigned int dwarf_pubnames_size
;
149 static unsigned int dwarf_aranges_size
;
150 static unsigned int dwarf_loc_size
;
151 static unsigned int dwarf_macinfo_size
;
152 static unsigned int dwarf_str_size
;
153 static unsigned int dwarf_ranges_size
;
154 unsigned int dwarf_frame_size
;
155 unsigned int dwarf_eh_frame_size
;
157 static asection
*dwarf_info_section
;
158 static asection
*dwarf_abbrev_section
;
159 static asection
*dwarf_line_section
;
160 static asection
*dwarf_pubnames_section
;
161 static asection
*dwarf_aranges_section
;
162 static asection
*dwarf_loc_section
;
163 static asection
*dwarf_macinfo_section
;
164 static asection
*dwarf_str_section
;
165 static asection
*dwarf_ranges_section
;
166 asection
*dwarf_frame_section
;
167 asection
*dwarf_eh_frame_section
;
169 /* names of the debugging sections */
171 #define INFO_SECTION ".debug_info"
172 #define ABBREV_SECTION ".debug_abbrev"
173 #define LINE_SECTION ".debug_line"
174 #define PUBNAMES_SECTION ".debug_pubnames"
175 #define ARANGES_SECTION ".debug_aranges"
176 #define LOC_SECTION ".debug_loc"
177 #define MACINFO_SECTION ".debug_macinfo"
178 #define STR_SECTION ".debug_str"
179 #define RANGES_SECTION ".debug_ranges"
180 #define FRAME_SECTION ".debug_frame"
181 #define EH_FRAME_SECTION ".eh_frame"
183 /* local data types */
185 /* We hold several abbreviation tables in memory at the same time. */
186 #ifndef ABBREV_HASH_SIZE
187 #define ABBREV_HASH_SIZE 121
190 /* The data in a compilation unit header, after target2host
191 translation, looks like this. */
192 struct comp_unit_head
194 unsigned long length
;
196 unsigned int abbrev_offset
;
197 unsigned char addr_size
;
198 unsigned char signed_addr_p
;
199 unsigned int offset_size
; /* size of file offsets; either 4 or 8 */
200 unsigned int initial_length_size
; /* size of the length field; either
203 /* Offset to the first byte of this compilation unit header in the
204 * .debug_info section, for resolving relative reference dies. */
208 /* Pointer to this compilation unit header in the .debug_info
213 /* Pointer to the first die of this compilatio unit. This will
214 * be the first byte following the compilation unit header. */
218 /* Pointer to the next compilation unit header in the program. */
220 struct comp_unit_head
*next
;
222 /* Base address of this compilation unit. */
224 CORE_ADDR base_address
;
226 /* Non-zero if base_address has been set. */
231 /* Internal state when decoding a particular compilation unit. */
234 /* The objfile containing this compilation unit. */
235 struct objfile
*objfile
;
237 /* The header of the compilation unit.
239 FIXME drow/2003-11-10: Some of the things from the comp_unit_head
240 should logically be moved to the dwarf2_cu structure. */
241 struct comp_unit_head header
;
243 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
245 /* The language we are debugging. */
246 enum language language
;
247 const struct language_defn
*language_defn
;
249 /* The generic symbol table building routines have separate lists for
250 file scope symbols and all all other scopes (local scopes). So
251 we need to select the right one to pass to add_symbol_to_list().
252 We do it by keeping a pointer to the correct list in list_in_scope.
254 FIXME: The original dwarf code just treated the file scope as the
255 first local scope, and all other local scopes as nested local
256 scopes, and worked fine. Check to see if we really need to
257 distinguish these in buildsym.c. */
258 struct pending
**list_in_scope
;
260 /* Maintain an array of referenced fundamental types for the current
261 compilation unit being read. For DWARF version 1, we have to construct
262 the fundamental types on the fly, since no information about the
263 fundamental types is supplied. Each such fundamental type is created by
264 calling a language dependent routine to create the type, and then a
265 pointer to that type is then placed in the array at the index specified
266 by it's FT_<TYPENAME> value. The array has a fixed size set by the
267 FT_NUM_MEMBERS compile time constant, which is the number of predefined
268 fundamental types gdb knows how to construct. */
269 struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
271 /* DWARF abbreviation table associated with this compilation unit. */
272 struct abbrev_info
**dwarf2_abbrevs
;
274 /* Storage for the abbrev table. */
275 struct obstack abbrev_obstack
;
278 /* The line number information for a compilation unit (found in the
279 .debug_line section) begins with a "statement program header",
280 which contains the following information. */
283 unsigned int total_length
;
284 unsigned short version
;
285 unsigned int header_length
;
286 unsigned char minimum_instruction_length
;
287 unsigned char default_is_stmt
;
289 unsigned char line_range
;
290 unsigned char opcode_base
;
292 /* standard_opcode_lengths[i] is the number of operands for the
293 standard opcode whose value is i. This means that
294 standard_opcode_lengths[0] is unused, and the last meaningful
295 element is standard_opcode_lengths[opcode_base - 1]. */
296 unsigned char *standard_opcode_lengths
;
298 /* The include_directories table. NOTE! These strings are not
299 allocated with xmalloc; instead, they are pointers into
300 debug_line_buffer. If you try to free them, `free' will get
302 unsigned int num_include_dirs
, include_dirs_size
;
305 /* The file_names table. NOTE! These strings are not allocated
306 with xmalloc; instead, they are pointers into debug_line_buffer.
307 Don't try to free them directly. */
308 unsigned int num_file_names
, file_names_size
;
312 unsigned int dir_index
;
313 unsigned int mod_time
;
317 /* The start and end of the statement program following this
318 header. These point into dwarf_line_buffer. */
319 char *statement_program_start
, *statement_program_end
;
322 /* When we construct a partial symbol table entry we only
323 need this much information. */
324 struct partial_die_info
327 unsigned char has_children
;
328 unsigned char is_external
;
329 unsigned char is_declaration
;
330 unsigned char has_type
;
337 struct dwarf_block
*locdesc
;
338 unsigned int language
;
342 /* This data structure holds the information of an abbrev. */
345 unsigned int number
; /* number identifying abbrev */
346 enum dwarf_tag tag
; /* dwarf tag */
347 unsigned short has_children
; /* boolean */
348 unsigned short num_attrs
; /* number of attributes */
349 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
350 struct abbrev_info
*next
; /* next in chain */
355 enum dwarf_attribute name
;
356 enum dwarf_form form
;
359 /* This data structure holds a complete die structure. */
362 enum dwarf_tag tag
; /* Tag indicating type of die */
363 unsigned int abbrev
; /* Abbrev number */
364 unsigned int offset
; /* Offset in .debug_info section */
365 unsigned int num_attrs
; /* Number of attributes */
366 struct attribute
*attrs
; /* An array of attributes */
367 struct die_info
*next_ref
; /* Next die in ref hash table */
369 /* The dies in a compilation unit form an n-ary tree. PARENT
370 points to this die's parent; CHILD points to the first child of
371 this node; and all the children of a given node are chained
372 together via their SIBLING fields, terminated by a die whose
374 struct die_info
*child
; /* Its first child, if any. */
375 struct die_info
*sibling
; /* Its next sibling, if any. */
376 struct die_info
*parent
; /* Its parent, if any. */
378 struct type
*type
; /* Cached type information */
381 /* Attributes have a name and a value */
384 enum dwarf_attribute name
;
385 enum dwarf_form form
;
389 struct dwarf_block
*blk
;
397 struct function_range
400 CORE_ADDR lowpc
, highpc
;
402 struct function_range
*next
;
405 /* Get at parts of an attribute structure */
407 #define DW_STRING(attr) ((attr)->u.str)
408 #define DW_UNSND(attr) ((attr)->u.unsnd)
409 #define DW_BLOCK(attr) ((attr)->u.blk)
410 #define DW_SND(attr) ((attr)->u.snd)
411 #define DW_ADDR(attr) ((attr)->u.addr)
413 /* Blocks are a bunch of untyped bytes. */
420 #ifndef ATTR_ALLOC_CHUNK
421 #define ATTR_ALLOC_CHUNK 4
424 /* A hash table of die offsets for following references. */
425 #ifndef REF_HASH_SIZE
426 #define REF_HASH_SIZE 1021
429 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
431 /* Obstack for allocating temporary storage used during symbol reading. */
432 static struct obstack dwarf2_tmp_obstack
;
434 /* Allocate fields for structs, unions and enums in this size. */
435 #ifndef DW_FIELD_ALLOC_CHUNK
436 #define DW_FIELD_ALLOC_CHUNK 4
439 /* Actually data from the sections. */
440 static char *dwarf_info_buffer
;
441 static char *dwarf_abbrev_buffer
;
442 static char *dwarf_line_buffer
;
443 static char *dwarf_str_buffer
;
444 static char *dwarf_macinfo_buffer
;
445 static char *dwarf_ranges_buffer
;
446 static char *dwarf_loc_buffer
;
448 /* A zeroed version of a partial die for initialization purposes. */
449 static struct partial_die_info zeroed_partial_die
;
451 /* FIXME: decode_locdesc sets these variables to describe the location
452 to the caller. These ought to be a structure or something. If
453 none of the flags are set, the object lives at the address returned
454 by decode_locdesc. */
456 static int isreg
; /* Object lives in register.
457 decode_locdesc's return value is
458 the register number. */
460 /* We put a pointer to this structure in the read_symtab_private field
463 Most of the information in this structure is related to an entire
464 object file and could be passed via the sym_private field of the
465 objfile. It is possible to have both dwarf2 and some other form
466 of debug symbols in one object file. */
470 /* Pointer to start of dwarf info buffer for the objfile. */
472 char *dwarf_info_buffer
;
474 /* Offset in dwarf_info_buffer for this compilation unit. */
476 unsigned long dwarf_info_offset
;
478 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
480 char *dwarf_abbrev_buffer
;
482 /* Size of dwarf abbreviation section for the objfile. */
484 unsigned int dwarf_abbrev_size
;
486 /* Pointer to start of dwarf line buffer for the objfile. */
488 char *dwarf_line_buffer
;
490 /* Size of dwarf_line_buffer, in bytes. */
492 unsigned int dwarf_line_size
;
494 /* Pointer to start of dwarf string buffer for the objfile. */
496 char *dwarf_str_buffer
;
498 /* Size of dwarf string section for the objfile. */
500 unsigned int dwarf_str_size
;
502 /* Pointer to start of dwarf macro buffer for the objfile. */
504 char *dwarf_macinfo_buffer
;
506 /* Size of dwarf macinfo section for the objfile. */
508 unsigned int dwarf_macinfo_size
;
510 /* Pointer to start of dwarf ranges buffer for the objfile. */
512 char *dwarf_ranges_buffer
;
514 /* Size of dwarf ranges buffer for the objfile. */
516 unsigned int dwarf_ranges_size
;
518 /* Pointer to start of dwarf locations buffer for the objfile. */
520 char *dwarf_loc_buffer
;
522 /* Size of dwarf locations buffer for the objfile. */
524 unsigned int dwarf_loc_size
;
527 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
528 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
529 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
530 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
531 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
532 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
533 #define DWARF_LINE_SIZE(p) (PST_PRIVATE(p)->dwarf_line_size)
534 #define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer)
535 #define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size)
536 #define DWARF_MACINFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_macinfo_buffer)
537 #define DWARF_MACINFO_SIZE(p) (PST_PRIVATE(p)->dwarf_macinfo_size)
538 #define DWARF_RANGES_BUFFER(p) (PST_PRIVATE(p)->dwarf_ranges_buffer)
539 #define DWARF_RANGES_SIZE(p) (PST_PRIVATE(p)->dwarf_ranges_size)
540 #define DWARF_LOC_BUFFER(p) (PST_PRIVATE(p)->dwarf_loc_buffer)
541 #define DWARF_LOC_SIZE(p) (PST_PRIVATE(p)->dwarf_loc_size)
543 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
544 but this would require a corresponding change in unpack_field_as_long
546 static int bits_per_byte
= 8;
548 /* The routines that read and process dies for a C struct or C++ class
549 pass lists of data member fields and lists of member function fields
550 in an instance of a field_info structure, as defined below. */
553 /* List of data member and baseclasses fields. */
556 struct nextfield
*next
;
563 /* Number of fields. */
566 /* Number of baseclasses. */
569 /* Set if the accesibility of one of the fields is not public. */
570 int non_public_fields
;
572 /* Member function fields array, entries are allocated in the order they
573 are encountered in the object file. */
576 struct nextfnfield
*next
;
577 struct fn_field fnfield
;
581 /* Member function fieldlist array, contains name of possibly overloaded
582 member function, number of overloaded member functions and a pointer
583 to the head of the member function field chain. */
588 struct nextfnfield
*head
;
592 /* Number of entries in the fnfieldlists array. */
596 /* Various complaints about symbol reading that don't abort the process */
599 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
601 complaint (&symfile_complaints
,
602 "statement list doesn't fit in .debug_line section");
606 dwarf2_complex_location_expr_complaint (void)
608 complaint (&symfile_complaints
, "location expression too complex");
612 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
615 complaint (&symfile_complaints
,
616 "const value length mismatch for '%s', got %d, expected %d", arg1
,
621 dwarf2_macros_too_long_complaint (void)
623 complaint (&symfile_complaints
,
624 "macro info runs off end of `.debug_macinfo' section");
628 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
630 complaint (&symfile_complaints
,
631 "macro debug info contains a malformed macro definition:\n`%s'",
636 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
638 complaint (&symfile_complaints
,
639 "invalid attribute class or form for '%s' in '%s'", arg1
, arg2
);
642 /* local function prototypes */
644 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
647 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
650 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
652 static char *scan_partial_symbols (char *, CORE_ADDR
*, CORE_ADDR
*,
654 const char *namespace);
656 static void add_partial_symbol (struct partial_die_info
*, struct dwarf2_cu
*,
657 const char *namespace);
659 static int pdi_needs_namespace (enum dwarf_tag tag
, const char *namespace);
661 static char *add_partial_namespace (struct partial_die_info
*pdi
,
663 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
664 struct dwarf2_cu
*cu
,
665 const char *namespace);
667 static char *add_partial_structure (struct partial_die_info
*struct_pdi
,
669 struct dwarf2_cu
*cu
,
670 const char *namespace);
672 static char *add_partial_enumeration (struct partial_die_info
*enum_pdi
,
674 struct dwarf2_cu
*cu
,
675 const char *namespace);
677 static char *locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
680 struct dwarf2_cu
*cu
);
682 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
684 static void psymtab_to_symtab_1 (struct partial_symtab
*);
686 char *dwarf2_read_section (struct objfile
*, asection
*);
688 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
690 static void dwarf2_free_abbrev_table (void *);
692 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
695 static char *read_partial_die (struct partial_die_info
*,
696 bfd
*, char *, struct dwarf2_cu
*);
698 static char *read_full_die (struct die_info
**, bfd
*, char *,
699 struct dwarf2_cu
*, int *);
701 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
702 bfd
*, char *, struct dwarf2_cu
*);
704 static char *read_attribute_value (struct attribute
*, unsigned,
705 bfd
*, char *, struct dwarf2_cu
*);
707 static unsigned int read_1_byte (bfd
*, char *);
709 static int read_1_signed_byte (bfd
*, char *);
711 static unsigned int read_2_bytes (bfd
*, char *);
713 static unsigned int read_4_bytes (bfd
*, char *);
715 static unsigned long read_8_bytes (bfd
*, char *);
717 static CORE_ADDR
read_address (bfd
*, char *ptr
, struct dwarf2_cu
*,
720 static LONGEST
read_initial_length (bfd
*, char *,
721 struct comp_unit_head
*, int *bytes_read
);
723 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
726 static char *read_n_bytes (bfd
*, char *, unsigned int);
728 static char *read_string (bfd
*, char *, unsigned int *);
730 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
733 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
735 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
737 static char *skip_leb128 (bfd
*, char *);
739 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
741 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
744 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
746 static struct die_info
*die_specification (struct die_info
*die
,
749 static void free_line_header (struct line_header
*lh
);
751 static struct line_header
*(dwarf_decode_line_header
752 (unsigned int offset
,
753 bfd
*abfd
, struct dwarf2_cu
*cu
));
755 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
758 static void dwarf2_start_subfile (char *, char *);
760 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
763 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
766 static void dwarf2_const_value_data (struct attribute
*attr
,
770 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
772 static struct type
*die_containing_type (struct die_info
*,
776 static struct type
*type_at_offset (unsigned int, struct objfile
*);
779 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
781 static void read_type_die (struct die_info
*, struct dwarf2_cu
*);
783 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
785 static char *typename_concat (const char *prefix
, const char *suffix
);
787 static void read_typedef (struct die_info
*, struct dwarf2_cu
*);
789 static void read_base_type (struct die_info
*, struct dwarf2_cu
*);
791 static void read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
793 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
795 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
797 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
799 static int dwarf2_get_pc_bounds (struct die_info
*,
800 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
802 static void get_scope_pc_bounds (struct die_info
*,
803 CORE_ADDR
*, CORE_ADDR
*,
806 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
809 static void dwarf2_attach_fields_to_type (struct field_info
*,
810 struct type
*, struct dwarf2_cu
*);
812 static void dwarf2_add_member_fn (struct field_info
*,
813 struct die_info
*, struct type
*,
816 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
817 struct type
*, struct dwarf2_cu
*);
819 static void read_structure_type (struct die_info
*, struct dwarf2_cu
*);
821 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
823 static char *determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
825 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
827 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
829 static const char *namespace_name (struct die_info
*die
,
830 int *is_anonymous
, struct dwarf2_cu
*);
832 static void read_enumeration_type (struct die_info
*, struct dwarf2_cu
*);
834 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
836 static struct type
*dwarf_base_type (int, int, struct dwarf2_cu
*);
838 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
840 static void read_array_type (struct die_info
*, struct dwarf2_cu
*);
842 static void read_tag_pointer_type (struct die_info
*, struct dwarf2_cu
*);
844 static void read_tag_ptr_to_member_type (struct die_info
*,
847 static void read_tag_reference_type (struct die_info
*, struct dwarf2_cu
*);
849 static void read_tag_const_type (struct die_info
*, struct dwarf2_cu
*);
851 static void read_tag_volatile_type (struct die_info
*, struct dwarf2_cu
*);
853 static void read_tag_string_type (struct die_info
*, struct dwarf2_cu
*);
855 static void read_subroutine_type (struct die_info
*, struct dwarf2_cu
*);
857 static struct die_info
*read_comp_unit (char *, bfd
*, struct dwarf2_cu
*);
859 static struct die_info
*read_die_and_children (char *info_ptr
, bfd
*abfd
,
862 struct die_info
*parent
);
864 static struct die_info
*read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
867 struct die_info
*parent
);
869 static void free_die_list (struct die_info
*);
871 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
873 static void process_die (struct die_info
*, struct dwarf2_cu
*);
875 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
877 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
879 static struct die_info
*dwarf2_extension (struct die_info
*die
,
882 static char *dwarf_tag_name (unsigned int);
884 static char *dwarf_attr_name (unsigned int);
886 static char *dwarf_form_name (unsigned int);
888 static char *dwarf_stack_op_name (unsigned int);
890 static char *dwarf_bool_name (unsigned int);
892 static char *dwarf_type_encoding_name (unsigned int);
895 static char *dwarf_cfi_name (unsigned int);
897 struct die_info
*copy_die (struct die_info
*);
900 static struct die_info
*sibling_die (struct die_info
*);
902 static void dump_die (struct die_info
*);
904 static void dump_die_list (struct die_info
*);
906 static void store_in_ref_table (unsigned int, struct die_info
*);
908 static void dwarf2_empty_hash_tables (void);
910 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*,
913 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
915 static struct die_info
*follow_die_ref (unsigned int);
917 static struct type
*dwarf2_fundamental_type (struct objfile
*, int,
920 /* memory allocation interface */
922 static void dwarf2_free_tmp_obstack (void *);
924 static struct dwarf_block
*dwarf_alloc_block (void);
926 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
928 static struct die_info
*dwarf_alloc_die (void);
930 static void initialize_cu_func_list (struct dwarf2_cu
*);
932 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
935 static void dwarf_decode_macros (struct line_header
*, unsigned int,
936 char *, bfd
*, struct dwarf2_cu
*);
938 static int attr_form_is_block (struct attribute
*);
941 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
942 struct dwarf2_cu
*cu
);
944 static char *skip_one_die (char *info_ptr
, struct abbrev_info
*abbrev
,
945 struct dwarf2_cu
*cu
);
947 /* Try to locate the sections we need for DWARF 2 debugging
948 information and return true if we have enough to do something. */
951 dwarf2_has_info (bfd
*abfd
)
953 dwarf_info_section
= 0;
954 dwarf_abbrev_section
= 0;
955 dwarf_line_section
= 0;
956 dwarf_str_section
= 0;
957 dwarf_macinfo_section
= 0;
958 dwarf_frame_section
= 0;
959 dwarf_eh_frame_section
= 0;
960 dwarf_ranges_section
= 0;
961 dwarf_loc_section
= 0;
963 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
964 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
967 /* This function is mapped across the sections and remembers the
968 offset and size of each of the debugging sections we are interested
972 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, void *ignore_ptr
)
974 if (strcmp (sectp
->name
, INFO_SECTION
) == 0)
976 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
977 dwarf_info_section
= sectp
;
979 else if (strcmp (sectp
->name
, ABBREV_SECTION
) == 0)
981 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
982 dwarf_abbrev_section
= sectp
;
984 else if (strcmp (sectp
->name
, LINE_SECTION
) == 0)
986 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
987 dwarf_line_section
= sectp
;
989 else if (strcmp (sectp
->name
, PUBNAMES_SECTION
) == 0)
991 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
992 dwarf_pubnames_section
= sectp
;
994 else if (strcmp (sectp
->name
, ARANGES_SECTION
) == 0)
996 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
997 dwarf_aranges_section
= sectp
;
999 else if (strcmp (sectp
->name
, LOC_SECTION
) == 0)
1001 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
1002 dwarf_loc_section
= sectp
;
1004 else if (strcmp (sectp
->name
, MACINFO_SECTION
) == 0)
1006 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
1007 dwarf_macinfo_section
= sectp
;
1009 else if (strcmp (sectp
->name
, STR_SECTION
) == 0)
1011 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
1012 dwarf_str_section
= sectp
;
1014 else if (strcmp (sectp
->name
, FRAME_SECTION
) == 0)
1016 dwarf_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1017 dwarf_frame_section
= sectp
;
1019 else if (strcmp (sectp
->name
, EH_FRAME_SECTION
) == 0)
1021 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1022 if (aflag
& SEC_HAS_CONTENTS
)
1024 dwarf_eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1025 dwarf_eh_frame_section
= sectp
;
1028 else if (strcmp (sectp
->name
, RANGES_SECTION
) == 0)
1030 dwarf_ranges_size
= bfd_get_section_size_before_reloc (sectp
);
1031 dwarf_ranges_section
= sectp
;
1035 /* Build a partial symbol table. */
1038 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1041 /* We definitely need the .debug_info and .debug_abbrev sections */
1043 dwarf_info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1044 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1046 if (dwarf_line_section
)
1047 dwarf_line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1049 dwarf_line_buffer
= NULL
;
1051 if (dwarf_str_section
)
1052 dwarf_str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1054 dwarf_str_buffer
= NULL
;
1056 if (dwarf_macinfo_section
)
1057 dwarf_macinfo_buffer
= dwarf2_read_section (objfile
,
1058 dwarf_macinfo_section
);
1060 dwarf_macinfo_buffer
= NULL
;
1062 if (dwarf_ranges_section
)
1063 dwarf_ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1065 dwarf_ranges_buffer
= NULL
;
1067 if (dwarf_loc_section
)
1068 dwarf_loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1070 dwarf_loc_buffer
= NULL
;
1073 || (objfile
->global_psymbols
.size
== 0
1074 && objfile
->static_psymbols
.size
== 0))
1076 init_psymbol_list (objfile
, 1024);
1080 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1082 /* Things are significantly easier if we have .debug_aranges and
1083 .debug_pubnames sections */
1085 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1089 /* only test this case for now */
1091 /* In this case we have to work a bit harder */
1092 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1097 /* Build the partial symbol table from the information in the
1098 .debug_pubnames and .debug_aranges sections. */
1101 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1103 bfd
*abfd
= objfile
->obfd
;
1104 char *aranges_buffer
, *pubnames_buffer
;
1105 char *aranges_ptr
, *pubnames_ptr
;
1106 unsigned int entry_length
, version
, info_offset
, info_size
;
1108 pubnames_buffer
= dwarf2_read_section (objfile
,
1109 dwarf_pubnames_section
);
1110 pubnames_ptr
= pubnames_buffer
;
1111 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
1113 struct comp_unit_head cu_header
;
1116 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1118 pubnames_ptr
+= bytes_read
;
1119 version
= read_1_byte (abfd
, pubnames_ptr
);
1121 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1123 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1127 aranges_buffer
= dwarf2_read_section (objfile
,
1128 dwarf_aranges_section
);
1133 /* Read in the comp unit header information from the debug_info at
1137 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1138 char *info_ptr
, bfd
*abfd
)
1142 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1144 info_ptr
+= bytes_read
;
1145 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1147 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1149 info_ptr
+= bytes_read
;
1150 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1152 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1153 if (signed_addr
< 0)
1154 internal_error (__FILE__
, __LINE__
,
1155 "read_comp_unit_head: dwarf from non elf file");
1156 cu_header
->signed_addr_p
= signed_addr
;
1160 /* Build the partial symbol table by doing a quick pass through the
1161 .debug_info and .debug_abbrev sections. */
1164 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1166 /* Instead of reading this into a big buffer, we should probably use
1167 mmap() on architectures that support it. (FIXME) */
1168 bfd
*abfd
= objfile
->obfd
;
1169 char *info_ptr
, *abbrev_ptr
;
1170 char *beg_of_comp_unit
;
1171 struct partial_die_info comp_unit_die
;
1172 struct partial_symtab
*pst
;
1173 struct cleanup
*back_to
;
1174 CORE_ADDR lowpc
, highpc
, baseaddr
;
1176 info_ptr
= dwarf_info_buffer
;
1177 abbrev_ptr
= dwarf_abbrev_buffer
;
1179 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1180 the partial symbol scan, like attribute values.
1182 We could reduce our peak memory consumption during partial symbol
1183 table construction by freeing stuff from this obstack more often
1184 --- say, after processing each compilation unit, or each die ---
1185 but it turns out that this saves almost nothing. For an
1186 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1187 on dwarf2_tmp_obstack. Some investigation showed:
1189 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1190 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1191 all fixed-length values not requiring dynamic allocation.
1193 2) 30% of the attributes used the form DW_FORM_string. For
1194 DW_FORM_string, read_attribute simply hands back a pointer to
1195 the null-terminated string in dwarf_info_buffer, so no dynamic
1196 allocation is needed there either.
1198 3) The remaining 1% of the attributes all used DW_FORM_block1.
1199 75% of those were DW_AT_frame_base location lists for
1200 functions; the rest were DW_AT_location attributes, probably
1201 for the global variables.
1203 Anyway, what this all means is that the memory the dwarf2
1204 reader uses as temporary space reading partial symbols is about
1205 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1207 obstack_init (&dwarf2_tmp_obstack
);
1208 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1210 /* Since the objects we're extracting from dwarf_info_buffer vary in
1211 length, only the individual functions to extract them (like
1212 read_comp_unit_head and read_partial_die) can really know whether
1213 the buffer is large enough to hold another complete object.
1215 At the moment, they don't actually check that. If
1216 dwarf_info_buffer holds just one extra byte after the last
1217 compilation unit's dies, then read_comp_unit_head will happily
1218 read off the end of the buffer. read_partial_die is similarly
1219 casual. Those functions should be fixed.
1221 For this loop condition, simply checking whether there's any data
1222 left at all should be sufficient. */
1223 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1225 struct cleanup
*back_to_inner
;
1226 struct dwarf2_cu cu
;
1227 beg_of_comp_unit
= info_ptr
;
1229 cu
.objfile
= objfile
;
1230 info_ptr
= read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1232 if (cu
.header
.version
!= 2)
1234 error ("Dwarf Error: wrong version in compilation unit header (is %d, should be %d) [in module %s]", cu
.header
.version
, 2, bfd_get_filename (abfd
));
1237 if (cu
.header
.abbrev_offset
>= dwarf_abbrev_size
)
1239 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6) [in module %s]",
1240 (long) cu
.header
.abbrev_offset
,
1241 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1242 bfd_get_filename (abfd
));
1245 if (beg_of_comp_unit
+ cu
.header
.length
+ cu
.header
.initial_length_size
1246 > dwarf_info_buffer
+ dwarf_info_size
)
1248 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0) [in module %s]",
1249 (long) cu
.header
.length
,
1250 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1251 bfd_get_filename (abfd
));
1254 /* Complete the cu_header */
1255 cu
.header
.offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1256 cu
.header
.first_die_ptr
= info_ptr
;
1257 cu
.header
.cu_head_ptr
= beg_of_comp_unit
;
1259 cu
.list_in_scope
= &file_symbols
;
1261 /* Read the abbrevs for this compilation unit into a table */
1262 dwarf2_read_abbrevs (abfd
, &cu
);
1263 back_to_inner
= make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1265 /* Read the compilation unit die */
1266 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1269 /* Set the language we're debugging */
1270 set_cu_language (comp_unit_die
.language
, &cu
);
1272 /* Allocate a new partial symbol table structure */
1273 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1274 comp_unit_die
.name
? comp_unit_die
.name
: "",
1275 comp_unit_die
.lowpc
,
1276 objfile
->global_psymbols
.next
,
1277 objfile
->static_psymbols
.next
);
1279 pst
->read_symtab_private
= (char *)
1280 obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct dwarf2_pinfo
));
1281 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1282 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1283 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1284 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1285 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1286 DWARF_LINE_SIZE (pst
) = dwarf_line_size
;
1287 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1288 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1289 DWARF_MACINFO_BUFFER (pst
) = dwarf_macinfo_buffer
;
1290 DWARF_MACINFO_SIZE (pst
) = dwarf_macinfo_size
;
1291 DWARF_RANGES_BUFFER (pst
) = dwarf_ranges_buffer
;
1292 DWARF_RANGES_SIZE (pst
) = dwarf_ranges_size
;
1293 DWARF_LOC_BUFFER (pst
) = dwarf_loc_buffer
;
1294 DWARF_LOC_SIZE (pst
) = dwarf_loc_size
;
1295 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1297 /* Store the function that reads in the rest of the symbol table */
1298 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1300 /* Check if comp unit has_children.
1301 If so, read the rest of the partial symbols from this comp unit.
1302 If not, there's no more debug_info for this comp unit. */
1303 if (comp_unit_die
.has_children
)
1305 lowpc
= ((CORE_ADDR
) -1);
1306 highpc
= ((CORE_ADDR
) 0);
1308 info_ptr
= scan_partial_symbols (info_ptr
, &lowpc
, &highpc
,
1311 /* If we didn't find a lowpc, set it to highpc to avoid
1312 complaints from `maint check'. */
1313 if (lowpc
== ((CORE_ADDR
) -1))
1316 /* If the compilation unit didn't have an explicit address range,
1317 then use the information extracted from its child dies. */
1318 if (! comp_unit_die
.has_pc_info
)
1320 comp_unit_die
.lowpc
= lowpc
;
1321 comp_unit_die
.highpc
= highpc
;
1324 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1325 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1327 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1328 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1329 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1330 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1331 sort_pst_symbols (pst
);
1333 /* If there is already a psymtab or symtab for a file of this
1334 name, remove it. (If there is a symtab, more drastic things
1335 also happen.) This happens in VxWorks. */
1336 free_named_symtabs (pst
->filename
);
1338 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1339 + cu
.header
.initial_length_size
;
1341 do_cleanups (back_to_inner
);
1343 do_cleanups (back_to
);
1346 /* Read in all interesting dies to the end of the compilation unit or
1347 to the end of the current namespace. NAMESPACE is NULL if we
1348 haven't yet encountered any DW_TAG_namespace entries; otherwise,
1349 it's the name of the current namespace. In particular, it's the
1350 empty string if we're currently in the global namespace but have
1351 previously encountered a DW_TAG_namespace. */
1354 scan_partial_symbols (char *info_ptr
, CORE_ADDR
*lowpc
,
1355 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
1356 const char *namespace)
1358 struct objfile
*objfile
= cu
->objfile
;
1359 bfd
*abfd
= objfile
->obfd
;
1360 struct partial_die_info pdi
;
1362 /* Now, march along the PDI's, descending into ones which have
1363 interesting children but skipping the children of the other ones,
1364 until we reach the end of the compilation unit. */
1368 /* This flag tells whether or not info_ptr has gotten updated
1370 int info_ptr_updated
= 0;
1372 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu
);
1374 /* Anonymous namespaces have no name but have interesting
1375 children, so we need to look at them. Ditto for anonymous
1378 if (pdi
.name
!= NULL
|| pdi
.tag
== DW_TAG_namespace
1379 || pdi
.tag
== DW_TAG_enumeration_type
)
1383 case DW_TAG_subprogram
:
1384 if (pdi
.has_pc_info
)
1386 if (pdi
.lowpc
< *lowpc
)
1390 if (pdi
.highpc
> *highpc
)
1392 *highpc
= pdi
.highpc
;
1394 if (!pdi
.is_declaration
)
1396 add_partial_symbol (&pdi
, cu
, namespace);
1400 case DW_TAG_variable
:
1401 case DW_TAG_typedef
:
1402 case DW_TAG_union_type
:
1403 if (!pdi
.is_declaration
)
1405 add_partial_symbol (&pdi
, cu
, namespace);
1408 case DW_TAG_class_type
:
1409 case DW_TAG_structure_type
:
1410 if (!pdi
.is_declaration
)
1412 info_ptr
= add_partial_structure (&pdi
, info_ptr
, cu
,
1414 info_ptr_updated
= 1;
1417 case DW_TAG_enumeration_type
:
1418 if (!pdi
.is_declaration
)
1420 info_ptr
= add_partial_enumeration (&pdi
, info_ptr
, cu
,
1422 info_ptr_updated
= 1;
1425 case DW_TAG_base_type
:
1426 case DW_TAG_subrange_type
:
1427 /* File scope base type definitions are added to the partial
1429 add_partial_symbol (&pdi
, cu
, namespace);
1431 case DW_TAG_namespace
:
1432 /* We've hit a DW_TAG_namespace entry, so we know this
1433 file has been compiled using a compiler that
1434 generates them; update NAMESPACE to reflect that. */
1435 if (namespace == NULL
)
1437 info_ptr
= add_partial_namespace (&pdi
, info_ptr
, lowpc
, highpc
,
1439 info_ptr_updated
= 1;
1449 /* If the die has a sibling, skip to the sibling, unless another
1450 function has already updated info_ptr for us. */
1452 /* NOTE: carlton/2003-06-16: This is a bit hackish, but whether
1453 or not we want to update this depends on enough stuff (not
1454 only pdi.tag but also whether or not pdi.name is NULL) that
1455 this seems like the easiest way to handle the issue. */
1457 if (!info_ptr_updated
)
1458 info_ptr
= locate_pdi_sibling (&pdi
, info_ptr
, abfd
, cu
);
1465 add_partial_symbol (struct partial_die_info
*pdi
,
1466 struct dwarf2_cu
*cu
, const char *namespace)
1468 struct objfile
*objfile
= cu
->objfile
;
1470 char *actual_name
= pdi
->name
;
1471 const struct partial_symbol
*psym
= NULL
;
1474 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1476 /* If we're not in the global namespace and if the namespace name
1477 isn't encoded in a mangled actual_name, add it. */
1479 if (pdi_needs_namespace (pdi
->tag
, namespace))
1481 actual_name
= alloca (strlen (pdi
->name
) + 2 + strlen (namespace) + 1);
1482 strcpy (actual_name
, namespace);
1483 strcat (actual_name
, "::");
1484 strcat (actual_name
, pdi
->name
);
1489 case DW_TAG_subprogram
:
1490 if (pdi
->is_external
)
1492 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1493 mst_text, objfile); */
1494 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1495 VAR_DOMAIN
, LOC_BLOCK
,
1496 &objfile
->global_psymbols
,
1497 0, pdi
->lowpc
+ baseaddr
,
1498 cu
->language
, objfile
);
1502 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1503 mst_file_text, objfile); */
1504 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1505 VAR_DOMAIN
, LOC_BLOCK
,
1506 &objfile
->static_psymbols
,
1507 0, pdi
->lowpc
+ baseaddr
,
1508 cu
->language
, objfile
);
1511 case DW_TAG_variable
:
1512 if (pdi
->is_external
)
1515 Don't enter into the minimal symbol tables as there is
1516 a minimal symbol table entry from the ELF symbols already.
1517 Enter into partial symbol table if it has a location
1518 descriptor or a type.
1519 If the location descriptor is missing, new_symbol will create
1520 a LOC_UNRESOLVED symbol, the address of the variable will then
1521 be determined from the minimal symbol table whenever the variable
1523 The address for the partial symbol table entry is not
1524 used by GDB, but it comes in handy for debugging partial symbol
1528 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1529 if (pdi
->locdesc
|| pdi
->has_type
)
1530 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1531 VAR_DOMAIN
, LOC_STATIC
,
1532 &objfile
->global_psymbols
,
1534 cu
->language
, objfile
);
1538 /* Static Variable. Skip symbols without location descriptors. */
1539 if (pdi
->locdesc
== NULL
)
1541 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1542 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
1543 mst_file_data, objfile); */
1544 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1545 VAR_DOMAIN
, LOC_STATIC
,
1546 &objfile
->static_psymbols
,
1548 cu
->language
, objfile
);
1551 case DW_TAG_typedef
:
1552 case DW_TAG_base_type
:
1553 case DW_TAG_subrange_type
:
1554 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1555 VAR_DOMAIN
, LOC_TYPEDEF
,
1556 &objfile
->static_psymbols
,
1557 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1559 case DW_TAG_class_type
:
1560 case DW_TAG_structure_type
:
1561 case DW_TAG_union_type
:
1562 case DW_TAG_enumeration_type
:
1563 /* Skip aggregate types without children, these are external
1565 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
1566 static vs. global. */
1567 if (pdi
->has_children
== 0)
1569 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1570 STRUCT_DOMAIN
, LOC_TYPEDEF
,
1571 cu
->language
== language_cplus
1572 ? &objfile
->global_psymbols
1573 : &objfile
->static_psymbols
,
1574 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1576 if (cu
->language
== language_cplus
)
1578 /* For C++, these implicitly act as typedefs as well. */
1579 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1580 VAR_DOMAIN
, LOC_TYPEDEF
,
1581 &objfile
->global_psymbols
,
1582 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1585 case DW_TAG_enumerator
:
1586 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1587 VAR_DOMAIN
, LOC_CONST
,
1588 cu
->language
== language_cplus
1589 ? &objfile
->global_psymbols
1590 : &objfile
->static_psymbols
,
1591 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1597 /* Check to see if we should scan the name for possible namespace
1598 info. Only do this if this is C++, if we don't have namespace
1599 debugging info in the file, if the psym is of an appropriate type
1600 (otherwise we'll have psym == NULL), and if we actually had a
1601 mangled name to begin with. */
1603 if (cu
->language
== language_cplus
1604 && namespace == NULL
1606 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
1607 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
1611 /* Determine whether a die of type TAG living in the C++ namespace
1612 NAMESPACE needs to have the name of the namespace prepended to the
1613 name listed in the die. */
1616 pdi_needs_namespace (enum dwarf_tag tag
, const char *namespace)
1618 if (namespace == NULL
|| namespace[0] == '\0')
1623 case DW_TAG_typedef
:
1624 case DW_TAG_class_type
:
1625 case DW_TAG_structure_type
:
1626 case DW_TAG_union_type
:
1627 case DW_TAG_enumeration_type
:
1628 case DW_TAG_enumerator
:
1635 /* Read a partial die corresponding to a namespace; also, add a symbol
1636 corresponding to that namespace to the symbol table. NAMESPACE is
1637 the name of the enclosing namespace. */
1640 add_partial_namespace (struct partial_die_info
*pdi
, char *info_ptr
,
1641 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1642 struct dwarf2_cu
*cu
, const char *namespace)
1644 struct objfile
*objfile
= cu
->objfile
;
1645 const char *new_name
= pdi
->name
;
1648 /* Calculate the full name of the namespace that we just entered. */
1650 if (new_name
== NULL
)
1651 new_name
= "(anonymous namespace)";
1652 full_name
= alloca (strlen (namespace) + 2 + strlen (new_name
) + 1);
1653 strcpy (full_name
, namespace);
1654 if (*namespace != '\0')
1655 strcat (full_name
, "::");
1656 strcat (full_name
, new_name
);
1658 /* FIXME: carlton/2003-10-07: We can't just replace this by a call
1659 to add_partial_symbol, because we don't have a way to pass in the
1660 full name to that function; that might be a flaw in
1661 add_partial_symbol's interface. */
1663 add_psymbol_to_list (full_name
, strlen (full_name
),
1664 VAR_DOMAIN
, LOC_TYPEDEF
,
1665 &objfile
->global_psymbols
,
1666 0, 0, cu
->language
, objfile
);
1668 /* Now scan partial symbols in that namespace. */
1670 if (pdi
->has_children
)
1671 info_ptr
= scan_partial_symbols (info_ptr
, lowpc
, highpc
, cu
, full_name
);
1676 /* Read a partial die corresponding to a class or structure. */
1679 add_partial_structure (struct partial_die_info
*struct_pdi
, char *info_ptr
,
1680 struct dwarf2_cu
*cu
,
1681 const char *namespace)
1683 bfd
*abfd
= cu
->objfile
->obfd
;
1684 char *actual_class_name
= NULL
;
1686 if (cu
->language
== language_cplus
1687 && (namespace == NULL
|| namespace[0] == '\0')
1688 && struct_pdi
->name
!= NULL
1689 && struct_pdi
->has_children
)
1691 /* See if we can figure out if the class lives in a namespace
1692 (or is nested within another class.) We do this by looking
1693 for a member function; its demangled name will contain
1694 namespace info, if there is any. */
1696 /* NOTE: carlton/2003-10-07: Getting the info this way changes
1697 what template types look like, because the demangler
1698 frequently doesn't give the same name as the debug info. We
1699 could fix this by only using the demangled name to get the
1700 prefix (but see comment in read_structure_type). */
1702 /* FIXME: carlton/2004-01-23: If NAMESPACE equals "", we have
1703 the appropriate debug information, so it would be nice to be
1704 able to avoid this hack. But NAMESPACE may not be the
1705 namespace where this class was defined: NAMESPACE reflects
1706 where STRUCT_PDI occurs in the tree of dies, but because of
1707 DW_AT_specification, that may not actually tell us where the
1708 class is defined. (See the comment in read_func_scope for an
1709 example of how this could occur.)
1711 Unfortunately, our current partial symtab data structures are
1712 completely unable to deal with DW_AT_specification. So, for
1713 now, the best thing to do is to get nesting information from
1714 places other than the tree structure of dies if there's any
1715 chance that a DW_AT_specification is involved. :-( */
1717 char *next_child
= info_ptr
;
1721 struct partial_die_info child_pdi
;
1723 next_child
= read_partial_die (&child_pdi
, abfd
, next_child
,
1727 if (child_pdi
.tag
== DW_TAG_subprogram
)
1729 actual_class_name
= class_name_from_physname (child_pdi
.name
);
1730 if (actual_class_name
!= NULL
)
1731 struct_pdi
->name
= actual_class_name
;
1736 next_child
= locate_pdi_sibling (&child_pdi
, next_child
,
1742 add_partial_symbol (struct_pdi
, cu
, namespace);
1743 xfree (actual_class_name
);
1745 return locate_pdi_sibling (struct_pdi
, info_ptr
, abfd
, cu
);
1748 /* Read a partial die corresponding to an enumeration type. */
1751 add_partial_enumeration (struct partial_die_info
*enum_pdi
, char *info_ptr
,
1752 struct dwarf2_cu
*cu
, const char *namespace)
1754 struct objfile
*objfile
= cu
->objfile
;
1755 bfd
*abfd
= objfile
->obfd
;
1756 struct partial_die_info pdi
;
1758 if (enum_pdi
->name
!= NULL
)
1759 add_partial_symbol (enum_pdi
, cu
, namespace);
1763 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu
);
1766 if (pdi
.tag
!= DW_TAG_enumerator
|| pdi
.name
== NULL
)
1767 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
1769 add_partial_symbol (&pdi
, cu
, namespace);
1775 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
1776 Return the corresponding abbrev, or NULL if the number is zero (indicating
1777 an empty DIE). In either case *BYTES_READ will be set to the length of
1778 the initial number. */
1780 static struct abbrev_info
*
1781 peek_die_abbrev (char *info_ptr
, int *bytes_read
, struct dwarf2_cu
*cu
)
1783 bfd
*abfd
= cu
->objfile
->obfd
;
1784 unsigned int abbrev_number
;
1785 struct abbrev_info
*abbrev
;
1787 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
1789 if (abbrev_number
== 0)
1792 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
1795 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number
,
1796 bfd_get_filename (abfd
));
1802 /* Scan the debug information for CU starting at INFO_PTR. Returns a
1803 pointer to the end of a series of DIEs, terminated by an empty
1804 DIE. Any children of the skipped DIEs will also be skipped. */
1807 skip_children (char *info_ptr
, struct dwarf2_cu
*cu
)
1809 struct abbrev_info
*abbrev
;
1810 unsigned int bytes_read
;
1814 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1816 return info_ptr
+ bytes_read
;
1818 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
1822 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
1823 should point just after the initial uleb128 of a DIE, and the
1824 abbrev corresponding to that skipped uleb128 should be passed in
1825 ABBREV. Returns a pointer to this DIE's sibling, skipping any
1829 skip_one_die (char *info_ptr
, struct abbrev_info
*abbrev
,
1830 struct dwarf2_cu
*cu
)
1832 unsigned int bytes_read
;
1833 struct attribute attr
;
1834 bfd
*abfd
= cu
->objfile
->obfd
;
1835 unsigned int form
, i
;
1837 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
1839 /* The only abbrev we care about is DW_AT_sibling. */
1840 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
1842 read_attribute (&attr
, &abbrev
->attrs
[i
],
1843 abfd
, info_ptr
, cu
);
1844 if (attr
.form
== DW_FORM_ref_addr
)
1845 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
1847 return dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
, cu
);
1850 /* If it isn't DW_AT_sibling, skip this attribute. */
1851 form
= abbrev
->attrs
[i
].form
;
1856 case DW_FORM_ref_addr
:
1857 info_ptr
+= cu
->header
.addr_size
;
1876 case DW_FORM_string
:
1877 read_string (abfd
, info_ptr
, &bytes_read
);
1878 info_ptr
+= bytes_read
;
1881 info_ptr
+= cu
->header
.offset_size
;
1884 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
1885 info_ptr
+= bytes_read
;
1887 case DW_FORM_block1
:
1888 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
1890 case DW_FORM_block2
:
1891 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
1893 case DW_FORM_block4
:
1894 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
1898 case DW_FORM_ref_udata
:
1899 info_ptr
= skip_leb128 (abfd
, info_ptr
);
1901 case DW_FORM_indirect
:
1902 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
1903 info_ptr
+= bytes_read
;
1904 /* We need to continue parsing from here, so just go back to
1906 goto skip_attribute
;
1909 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
1910 dwarf_form_name (form
),
1911 bfd_get_filename (abfd
));
1915 if (abbrev
->has_children
)
1916 return skip_children (info_ptr
, cu
);
1921 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
1922 the next DIE after ORIG_PDI. */
1925 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, char *info_ptr
,
1926 bfd
*abfd
, struct dwarf2_cu
*cu
)
1928 /* Do we know the sibling already? */
1930 if (orig_pdi
->sibling
)
1931 return orig_pdi
->sibling
;
1933 /* Are there any children to deal with? */
1935 if (!orig_pdi
->has_children
)
1938 /* Skip the children the long way. */
1940 return skip_children (info_ptr
, cu
);
1943 /* Expand this partial symbol table into a full symbol table. */
1946 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1948 /* FIXME: This is barely more than a stub. */
1953 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1959 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1960 gdb_flush (gdb_stdout
);
1963 psymtab_to_symtab_1 (pst
);
1965 /* Finish up the debug error message. */
1967 printf_filtered ("done.\n");
1973 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1975 struct objfile
*objfile
= pst
->objfile
;
1976 bfd
*abfd
= objfile
->obfd
;
1977 struct dwarf2_cu cu
;
1978 struct die_info
*dies
;
1979 unsigned long offset
;
1980 CORE_ADDR lowpc
, highpc
;
1981 struct die_info
*child_die
;
1983 struct symtab
*symtab
;
1984 struct cleanup
*back_to
;
1985 struct attribute
*attr
;
1988 /* Set local variables from the partial symbol table info. */
1989 offset
= DWARF_INFO_OFFSET (pst
);
1990 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1991 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1992 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1993 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1994 dwarf_line_size
= DWARF_LINE_SIZE (pst
);
1995 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1996 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1997 dwarf_macinfo_buffer
= DWARF_MACINFO_BUFFER (pst
);
1998 dwarf_macinfo_size
= DWARF_MACINFO_SIZE (pst
);
1999 dwarf_ranges_buffer
= DWARF_RANGES_BUFFER (pst
);
2000 dwarf_ranges_size
= DWARF_RANGES_SIZE (pst
);
2001 dwarf_loc_buffer
= DWARF_LOC_BUFFER (pst
);
2002 dwarf_loc_size
= DWARF_LOC_SIZE (pst
);
2003 info_ptr
= dwarf_info_buffer
+ offset
;
2004 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2006 /* We're in the global namespace. */
2007 processing_current_prefix
= "";
2009 obstack_init (&dwarf2_tmp_obstack
);
2010 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
2013 make_cleanup (really_free_pendings
, NULL
);
2015 cu
.objfile
= objfile
;
2017 /* read in the comp_unit header */
2018 info_ptr
= read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
2020 /* Read the abbrevs for this compilation unit */
2021 dwarf2_read_abbrevs (abfd
, &cu
);
2022 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2024 cu
.header
.offset
= offset
;
2026 cu
.list_in_scope
= &file_symbols
;
2028 dies
= read_comp_unit (info_ptr
, abfd
, &cu
);
2030 make_cleanup_free_die_list (dies
);
2032 /* Find the base address of the compilation unit for range lists and
2033 location lists. It will normally be specified by DW_AT_low_pc.
2034 In DWARF-3 draft 4, the base address could be overridden by
2035 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2036 compilation units with discontinuous ranges. */
2038 cu
.header
.base_known
= 0;
2039 cu
.header
.base_address
= 0;
2041 attr
= dwarf2_attr (dies
, DW_AT_entry_pc
, &cu
);
2044 cu
.header
.base_address
= DW_ADDR (attr
);
2045 cu
.header
.base_known
= 1;
2049 attr
= dwarf2_attr (dies
, DW_AT_low_pc
, &cu
);
2052 cu
.header
.base_address
= DW_ADDR (attr
);
2053 cu
.header
.base_known
= 1;
2057 /* Do line number decoding in read_file_scope () */
2058 process_die (dies
, &cu
);
2060 /* Some compilers don't define a DW_AT_high_pc attribute for the
2061 compilation unit. If the DW_AT_high_pc is missing, synthesize
2062 it, by scanning the DIE's below the compilation unit. */
2063 get_scope_pc_bounds (dies
, &lowpc
, &highpc
, &cu
);
2065 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2067 /* Set symtab language to language from DW_AT_language.
2068 If the compilation is from a C file generated by language preprocessors,
2069 do not set the language if it was already deduced by start_subfile. */
2071 && !(cu
.language
== language_c
&& symtab
->language
!= language_c
))
2073 symtab
->language
= cu
.language
;
2075 pst
->symtab
= symtab
;
2078 do_cleanups (back_to
);
2081 /* Process a die and its children. */
2084 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2088 case DW_TAG_padding
:
2090 case DW_TAG_compile_unit
:
2091 read_file_scope (die
, cu
);
2093 case DW_TAG_subprogram
:
2094 read_subroutine_type (die
, cu
);
2095 read_func_scope (die
, cu
);
2097 case DW_TAG_inlined_subroutine
:
2098 /* FIXME: These are ignored for now.
2099 They could be used to set breakpoints on all inlined instances
2100 of a function and make GDB `next' properly over inlined functions. */
2102 case DW_TAG_lexical_block
:
2103 case DW_TAG_try_block
:
2104 case DW_TAG_catch_block
:
2105 read_lexical_block_scope (die
, cu
);
2107 case DW_TAG_class_type
:
2108 case DW_TAG_structure_type
:
2109 case DW_TAG_union_type
:
2110 read_structure_type (die
, cu
);
2111 process_structure_scope (die
, cu
);
2113 case DW_TAG_enumeration_type
:
2114 read_enumeration_type (die
, cu
);
2115 process_enumeration_scope (die
, cu
);
2118 /* FIXME drow/2004-03-14: These initialize die->type, but do not create
2119 a symbol or process any children. Therefore it doesn't do anything
2120 that won't be done on-demand by read_type_die. */
2121 case DW_TAG_subroutine_type
:
2122 read_subroutine_type (die
, cu
);
2124 case DW_TAG_array_type
:
2125 read_array_type (die
, cu
);
2127 case DW_TAG_pointer_type
:
2128 read_tag_pointer_type (die
, cu
);
2130 case DW_TAG_ptr_to_member_type
:
2131 read_tag_ptr_to_member_type (die
, cu
);
2133 case DW_TAG_reference_type
:
2134 read_tag_reference_type (die
, cu
);
2136 case DW_TAG_string_type
:
2137 read_tag_string_type (die
, cu
);
2141 case DW_TAG_base_type
:
2142 read_base_type (die
, cu
);
2143 /* Add a typedef symbol for the type definition, if it has a
2145 new_symbol (die
, die
->type
, cu
);
2147 case DW_TAG_subrange_type
:
2148 read_subrange_type (die
, cu
);
2149 /* Add a typedef symbol for the type definition, if it has a
2151 new_symbol (die
, die
->type
, cu
);
2153 case DW_TAG_common_block
:
2154 read_common_block (die
, cu
);
2156 case DW_TAG_common_inclusion
:
2158 case DW_TAG_namespace
:
2159 processing_has_namespace_info
= 1;
2160 read_namespace (die
, cu
);
2162 case DW_TAG_imported_declaration
:
2163 case DW_TAG_imported_module
:
2164 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2165 information contained in these. DW_TAG_imported_declaration
2166 dies shouldn't have children; DW_TAG_imported_module dies
2167 shouldn't in the C++ case, but conceivably could in the
2168 Fortran case, so we'll have to replace this gdb_assert if
2169 Fortran compilers start generating that info. */
2170 processing_has_namespace_info
= 1;
2171 gdb_assert (die
->child
== NULL
);
2174 new_symbol (die
, NULL
, cu
);
2180 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2182 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2186 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2188 struct objfile
*objfile
= cu
->objfile
;
2189 struct comp_unit_head
*cu_header
= &cu
->header
;
2190 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2191 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2192 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2193 struct attribute
*attr
;
2194 char *name
= "<unknown>";
2195 char *comp_dir
= NULL
;
2196 struct die_info
*child_die
;
2197 bfd
*abfd
= objfile
->obfd
;
2198 struct line_header
*line_header
= 0;
2201 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2203 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2205 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2206 from finish_block. */
2207 if (lowpc
== ((CORE_ADDR
) -1))
2212 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2215 name
= DW_STRING (attr
);
2217 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2220 comp_dir
= DW_STRING (attr
);
2223 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2224 directory, get rid of it. */
2225 char *cp
= strchr (comp_dir
, ':');
2227 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2232 if (objfile
->ei
.entry_point
>= lowpc
&&
2233 objfile
->ei
.entry_point
< highpc
)
2235 objfile
->ei
.deprecated_entry_file_lowpc
= lowpc
;
2236 objfile
->ei
.deprecated_entry_file_highpc
= highpc
;
2239 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2242 set_cu_language (DW_UNSND (attr
), cu
);
2245 /* We assume that we're processing GCC output. */
2246 processing_gcc_compilation
= 2;
2248 /* FIXME:Do something here. */
2249 if (dip
->at_producer
!= NULL
)
2251 handle_producer (dip
->at_producer
);
2255 /* The compilation unit may be in a different language or objfile,
2256 zero out all remembered fundamental types. */
2257 memset (cu
->ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
2259 start_symtab (name
, comp_dir
, lowpc
);
2260 record_debugformat ("DWARF 2");
2262 initialize_cu_func_list (cu
);
2264 /* Process all dies in compilation unit. */
2265 if (die
->child
!= NULL
)
2267 child_die
= die
->child
;
2268 while (child_die
&& child_die
->tag
)
2270 process_die (child_die
, cu
);
2271 child_die
= sibling_die (child_die
);
2275 /* Decode line number information if present. */
2276 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2279 unsigned int line_offset
= DW_UNSND (attr
);
2280 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2283 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
2284 (void *) line_header
);
2285 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
);
2289 /* Decode macro information, if present. Dwarf 2 macro information
2290 refers to information in the line number info statement program
2291 header, so we can only read it if we've read the header
2293 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2294 if (attr
&& line_header
)
2296 unsigned int macro_offset
= DW_UNSND (attr
);
2297 dwarf_decode_macros (line_header
, macro_offset
,
2298 comp_dir
, abfd
, cu
);
2300 do_cleanups (back_to
);
2304 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2305 struct dwarf2_cu
*cu
)
2307 struct function_range
*thisfn
;
2309 thisfn
= (struct function_range
*)
2310 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct function_range
));
2311 thisfn
->name
= name
;
2312 thisfn
->lowpc
= lowpc
;
2313 thisfn
->highpc
= highpc
;
2314 thisfn
->seen_line
= 0;
2315 thisfn
->next
= NULL
;
2317 if (cu
->last_fn
== NULL
)
2318 cu
->first_fn
= thisfn
;
2320 cu
->last_fn
->next
= thisfn
;
2322 cu
->last_fn
= thisfn
;
2326 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2328 struct objfile
*objfile
= cu
->objfile
;
2329 struct context_stack
*new;
2332 struct die_info
*child_die
;
2333 struct attribute
*attr
;
2335 const char *previous_prefix
= processing_current_prefix
;
2336 struct cleanup
*back_to
= NULL
;
2339 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2341 name
= dwarf2_linkage_name (die
, cu
);
2343 /* Ignore functions with missing or empty names and functions with
2344 missing or invalid low and high pc attributes. */
2345 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2348 if (cu
->language
== language_cplus
)
2350 struct die_info
*spec_die
= die_specification (die
, cu
);
2352 /* NOTE: carlton/2004-01-23: We have to be careful in the
2353 presence of DW_AT_specification. For example, with GCC 3.4,
2358 // Definition of N::foo.
2362 then we'll have a tree of DIEs like this:
2364 1: DW_TAG_compile_unit
2365 2: DW_TAG_namespace // N
2366 3: DW_TAG_subprogram // declaration of N::foo
2367 4: DW_TAG_subprogram // definition of N::foo
2368 DW_AT_specification // refers to die #3
2370 Thus, when processing die #4, we have to pretend that we're
2371 in the context of its DW_AT_specification, namely the contex
2374 if (spec_die
!= NULL
)
2376 char *specification_prefix
= determine_prefix (spec_die
, cu
);
2377 processing_current_prefix
= specification_prefix
;
2378 back_to
= make_cleanup (xfree
, specification_prefix
);
2385 /* Record the function range for dwarf_decode_lines. */
2386 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
2388 if (objfile
->ei
.entry_point
>= lowpc
&&
2389 objfile
->ei
.entry_point
< highpc
)
2391 objfile
->ei
.entry_func_lowpc
= lowpc
;
2392 objfile
->ei
.entry_func_highpc
= highpc
;
2395 new = push_context (0, lowpc
);
2396 new->name
= new_symbol (die
, die
->type
, cu
);
2398 /* If there is a location expression for DW_AT_frame_base, record
2400 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
2402 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
2403 expression is being recorded directly in the function's symbol
2404 and not in a separate frame-base object. I guess this hack is
2405 to avoid adding some sort of frame-base adjunct/annex to the
2406 function's symbol :-(. The problem with doing this is that it
2407 results in a function symbol with a location expression that
2408 has nothing to do with the location of the function, ouch! The
2409 relationship should be: a function's symbol has-a frame base; a
2410 frame-base has-a location expression. */
2411 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
2413 cu
->list_in_scope
= &local_symbols
;
2415 if (die
->child
!= NULL
)
2417 child_die
= die
->child
;
2418 while (child_die
&& child_die
->tag
)
2420 process_die (child_die
, cu
);
2421 child_die
= sibling_die (child_die
);
2425 new = pop_context ();
2426 /* Make a block for the local symbols within. */
2427 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2428 lowpc
, highpc
, objfile
);
2430 /* In C++, we can have functions nested inside functions (e.g., when
2431 a function declares a class that has methods). This means that
2432 when we finish processing a function scope, we may need to go
2433 back to building a containing block's symbol lists. */
2434 local_symbols
= new->locals
;
2435 param_symbols
= new->params
;
2437 /* If we've finished processing a top-level function, subsequent
2438 symbols go in the file symbol list. */
2439 if (outermost_context_p ())
2440 cu
->list_in_scope
= &file_symbols
;
2442 processing_current_prefix
= previous_prefix
;
2443 if (back_to
!= NULL
)
2444 do_cleanups (back_to
);
2447 /* Process all the DIES contained within a lexical block scope. Start
2448 a new scope, process the dies, and then close the scope. */
2451 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2453 struct objfile
*objfile
= cu
->objfile
;
2454 struct context_stack
*new;
2455 CORE_ADDR lowpc
, highpc
;
2456 struct die_info
*child_die
;
2459 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2461 /* Ignore blocks with missing or invalid low and high pc attributes. */
2462 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2463 as multiple lexical blocks? Handling children in a sane way would
2464 be nasty. Might be easier to properly extend generic blocks to
2466 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2471 push_context (0, lowpc
);
2472 if (die
->child
!= NULL
)
2474 child_die
= die
->child
;
2475 while (child_die
&& child_die
->tag
)
2477 process_die (child_die
, cu
);
2478 child_die
= sibling_die (child_die
);
2481 new = pop_context ();
2483 if (local_symbols
!= NULL
)
2485 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
2488 local_symbols
= new->locals
;
2491 /* Get low and high pc attributes from a die. Return 1 if the attributes
2492 are present and valid, otherwise, return 0. Return -1 if the range is
2493 discontinuous, i.e. derived from DW_AT_ranges information. */
2495 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
2496 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
2498 struct objfile
*objfile
= cu
->objfile
;
2499 struct comp_unit_head
*cu_header
= &cu
->header
;
2500 struct attribute
*attr
;
2501 bfd
*obfd
= objfile
->obfd
;
2506 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
2509 high
= DW_ADDR (attr
);
2510 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
2512 low
= DW_ADDR (attr
);
2514 /* Found high w/o low attribute. */
2517 /* Found consecutive range of addresses. */
2522 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
2525 unsigned int addr_size
= cu_header
->addr_size
;
2526 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
2527 /* Value of the DW_AT_ranges attribute is the offset in the
2528 .debug_ranges section. */
2529 unsigned int offset
= DW_UNSND (attr
);
2530 /* Base address selection entry. */
2538 found_base
= cu_header
->base_known
;
2539 base
= cu_header
->base_address
;
2541 if (offset
>= dwarf_ranges_size
)
2543 complaint (&symfile_complaints
,
2544 "Offset %d out of bounds for DW_AT_ranges attribute",
2548 buffer
= dwarf_ranges_buffer
+ offset
;
2550 /* Read in the largest possible address. */
2551 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
2552 if ((marker
& mask
) == mask
)
2554 /* If we found the largest possible address, then
2555 read the base address. */
2556 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2557 buffer
+= 2 * addr_size
;
2558 offset
+= 2 * addr_size
;
2566 CORE_ADDR range_beginning
, range_end
;
2568 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
2569 buffer
+= addr_size
;
2570 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
2571 buffer
+= addr_size
;
2572 offset
+= 2 * addr_size
;
2574 /* An end of list marker is a pair of zero addresses. */
2575 if (range_beginning
== 0 && range_end
== 0)
2576 /* Found the end of list entry. */
2579 /* Each base address selection entry is a pair of 2 values.
2580 The first is the largest possible address, the second is
2581 the base address. Check for a base address here. */
2582 if ((range_beginning
& mask
) == mask
)
2584 /* If we found the largest possible address, then
2585 read the base address. */
2586 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2593 /* We have no valid base address for the ranges
2595 complaint (&symfile_complaints
,
2596 "Invalid .debug_ranges data (no base address)");
2600 range_beginning
+= base
;
2603 /* FIXME: This is recording everything as a low-high
2604 segment of consecutive addresses. We should have a
2605 data structure for discontiguous block ranges
2609 low
= range_beginning
;
2615 if (range_beginning
< low
)
2616 low
= range_beginning
;
2617 if (range_end
> high
)
2623 /* If the first entry is an end-of-list marker, the range
2624 describes an empty scope, i.e. no instructions. */
2634 /* When using the GNU linker, .gnu.linkonce. sections are used to
2635 eliminate duplicate copies of functions and vtables and such.
2636 The linker will arbitrarily choose one and discard the others.
2637 The AT_*_pc values for such functions refer to local labels in
2638 these sections. If the section from that file was discarded, the
2639 labels are not in the output, so the relocs get a value of 0.
2640 If this is a discarded function, mark the pc bounds as invalid,
2641 so that GDB will ignore it. */
2642 if (low
== 0 && (bfd_get_file_flags (obfd
) & HAS_RELOC
) == 0)
2650 /* Get the low and high pc's represented by the scope DIE, and store
2651 them in *LOWPC and *HIGHPC. If the correct values can't be
2652 determined, set *LOWPC to -1 and *HIGHPC to 0. */
2655 get_scope_pc_bounds (struct die_info
*die
,
2656 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2657 struct dwarf2_cu
*cu
)
2659 CORE_ADDR best_low
= (CORE_ADDR
) -1;
2660 CORE_ADDR best_high
= (CORE_ADDR
) 0;
2661 CORE_ADDR current_low
, current_high
;
2663 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
2665 best_low
= current_low
;
2666 best_high
= current_high
;
2670 struct die_info
*child
= die
->child
;
2672 while (child
&& child
->tag
)
2674 switch (child
->tag
) {
2675 case DW_TAG_subprogram
:
2676 if (dwarf2_get_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
))
2678 best_low
= min (best_low
, current_low
);
2679 best_high
= max (best_high
, current_high
);
2682 case DW_TAG_namespace
:
2683 /* FIXME: carlton/2004-01-16: Should we do this for
2684 DW_TAG_class_type/DW_TAG_structure_type, too? I think
2685 that current GCC's always emit the DIEs corresponding
2686 to definitions of methods of classes as children of a
2687 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
2688 the DIEs giving the declarations, which could be
2689 anywhere). But I don't see any reason why the
2690 standards says that they have to be there. */
2691 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
2693 if (current_low
!= ((CORE_ADDR
) -1))
2695 best_low
= min (best_low
, current_low
);
2696 best_high
= max (best_high
, current_high
);
2704 child
= sibling_die (child
);
2709 *highpc
= best_high
;
2712 /* Add an aggregate field to the field list. */
2715 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
2716 struct dwarf2_cu
*cu
)
2718 struct objfile
*objfile
= cu
->objfile
;
2719 struct nextfield
*new_field
;
2720 struct attribute
*attr
;
2722 char *fieldname
= "";
2724 /* Allocate a new field list entry and link it in. */
2725 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2726 make_cleanup (xfree
, new_field
);
2727 memset (new_field
, 0, sizeof (struct nextfield
));
2728 new_field
->next
= fip
->fields
;
2729 fip
->fields
= new_field
;
2732 /* Handle accessibility and virtuality of field.
2733 The default accessibility for members is public, the default
2734 accessibility for inheritance is private. */
2735 if (die
->tag
!= DW_TAG_inheritance
)
2736 new_field
->accessibility
= DW_ACCESS_public
;
2738 new_field
->accessibility
= DW_ACCESS_private
;
2739 new_field
->virtuality
= DW_VIRTUALITY_none
;
2741 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
2743 new_field
->accessibility
= DW_UNSND (attr
);
2744 if (new_field
->accessibility
!= DW_ACCESS_public
)
2745 fip
->non_public_fields
= 1;
2746 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
2748 new_field
->virtuality
= DW_UNSND (attr
);
2750 fp
= &new_field
->field
;
2752 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
2754 /* Data member other than a C++ static data member. */
2756 /* Get type of field. */
2757 fp
->type
= die_type (die
, cu
);
2759 FIELD_STATIC_KIND (*fp
) = 0;
2761 /* Get bit size of field (zero if none). */
2762 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
2765 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
2769 FIELD_BITSIZE (*fp
) = 0;
2772 /* Get bit offset of field. */
2773 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
2776 FIELD_BITPOS (*fp
) =
2777 decode_locdesc (DW_BLOCK (attr
), cu
) * bits_per_byte
;
2780 FIELD_BITPOS (*fp
) = 0;
2781 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
2784 if (BITS_BIG_ENDIAN
)
2786 /* For big endian bits, the DW_AT_bit_offset gives the
2787 additional bit offset from the MSB of the containing
2788 anonymous object to the MSB of the field. We don't
2789 have to do anything special since we don't need to
2790 know the size of the anonymous object. */
2791 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
2795 /* For little endian bits, compute the bit offset to the
2796 MSB of the anonymous object, subtract off the number of
2797 bits from the MSB of the field to the MSB of the
2798 object, and then subtract off the number of bits of
2799 the field itself. The result is the bit offset of
2800 the LSB of the field. */
2802 int bit_offset
= DW_UNSND (attr
);
2804 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
2807 /* The size of the anonymous object containing
2808 the bit field is explicit, so use the
2809 indicated size (in bytes). */
2810 anonymous_size
= DW_UNSND (attr
);
2814 /* The size of the anonymous object containing
2815 the bit field must be inferred from the type
2816 attribute of the data member containing the
2818 anonymous_size
= TYPE_LENGTH (fp
->type
);
2820 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2821 - bit_offset
- FIELD_BITSIZE (*fp
);
2825 /* Get name of field. */
2826 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2827 if (attr
&& DW_STRING (attr
))
2828 fieldname
= DW_STRING (attr
);
2830 /* The name is already allocated along with this objfile, so we don't
2831 need to duplicate it for the type. */
2832 fp
->name
= fieldname
;
2834 /* Change accessibility for artificial fields (e.g. virtual table
2835 pointer or virtual base class pointer) to private. */
2836 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
2838 new_field
->accessibility
= DW_ACCESS_private
;
2839 fip
->non_public_fields
= 1;
2842 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
2844 /* C++ static member. */
2846 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2847 is a declaration, but all versions of G++ as of this writing
2848 (so through at least 3.2.1) incorrectly generate
2849 DW_TAG_variable tags. */
2853 /* Get name of field. */
2854 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2855 if (attr
&& DW_STRING (attr
))
2856 fieldname
= DW_STRING (attr
);
2860 /* Get physical name. */
2861 physname
= dwarf2_linkage_name (die
, cu
);
2863 /* The name is already allocated along with this objfile, so we don't
2864 need to duplicate it for the type. */
2865 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
2866 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2867 FIELD_NAME (*fp
) = fieldname
;
2869 else if (die
->tag
== DW_TAG_inheritance
)
2871 /* C++ base class field. */
2872 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
2874 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
2876 FIELD_BITSIZE (*fp
) = 0;
2877 FIELD_STATIC_KIND (*fp
) = 0;
2878 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2879 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2880 fip
->nbaseclasses
++;
2884 /* Create the vector of fields, and attach it to the type. */
2887 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
2888 struct dwarf2_cu
*cu
)
2890 int nfields
= fip
->nfields
;
2892 /* Record the field count, allocate space for the array of fields,
2893 and create blank accessibility bitfields if necessary. */
2894 TYPE_NFIELDS (type
) = nfields
;
2895 TYPE_FIELDS (type
) = (struct field
*)
2896 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2897 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2899 if (fip
->non_public_fields
)
2901 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2903 TYPE_FIELD_PRIVATE_BITS (type
) =
2904 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2905 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2907 TYPE_FIELD_PROTECTED_BITS (type
) =
2908 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2909 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2911 TYPE_FIELD_IGNORE_BITS (type
) =
2912 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2913 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2916 /* If the type has baseclasses, allocate and clear a bit vector for
2917 TYPE_FIELD_VIRTUAL_BITS. */
2918 if (fip
->nbaseclasses
)
2920 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2923 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2924 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2925 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2926 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2927 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2930 /* Copy the saved-up fields into the field vector. Start from the head
2931 of the list, adding to the tail of the field array, so that they end
2932 up in the same order in the array in which they were added to the list. */
2933 while (nfields
-- > 0)
2935 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2936 switch (fip
->fields
->accessibility
)
2938 case DW_ACCESS_private
:
2939 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2942 case DW_ACCESS_protected
:
2943 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2946 case DW_ACCESS_public
:
2950 /* Unknown accessibility. Complain and treat it as public. */
2952 complaint (&symfile_complaints
, "unsupported accessibility %d",
2953 fip
->fields
->accessibility
);
2957 if (nfields
< fip
->nbaseclasses
)
2959 switch (fip
->fields
->virtuality
)
2961 case DW_VIRTUALITY_virtual
:
2962 case DW_VIRTUALITY_pure_virtual
:
2963 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2967 fip
->fields
= fip
->fields
->next
;
2971 /* Add a member function to the proper fieldlist. */
2974 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2975 struct type
*type
, struct dwarf2_cu
*cu
)
2977 struct objfile
*objfile
= cu
->objfile
;
2978 struct attribute
*attr
;
2979 struct fnfieldlist
*flp
;
2981 struct fn_field
*fnp
;
2984 struct nextfnfield
*new_fnfield
;
2986 /* Get name of member function. */
2987 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2988 if (attr
&& DW_STRING (attr
))
2989 fieldname
= DW_STRING (attr
);
2993 /* Get the mangled name. */
2994 physname
= dwarf2_linkage_name (die
, cu
);
2996 /* Look up member function name in fieldlist. */
2997 for (i
= 0; i
< fip
->nfnfields
; i
++)
2999 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3003 /* Create new list element if necessary. */
3004 if (i
< fip
->nfnfields
)
3005 flp
= &fip
->fnfieldlists
[i
];
3008 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3010 fip
->fnfieldlists
= (struct fnfieldlist
*)
3011 xrealloc (fip
->fnfieldlists
,
3012 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3013 * sizeof (struct fnfieldlist
));
3014 if (fip
->nfnfields
== 0)
3015 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3017 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3018 flp
->name
= fieldname
;
3024 /* Create a new member function field and chain it to the field list
3026 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3027 make_cleanup (xfree
, new_fnfield
);
3028 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3029 new_fnfield
->next
= flp
->head
;
3030 flp
->head
= new_fnfield
;
3033 /* Fill in the member function field info. */
3034 fnp
= &new_fnfield
->fnfield
;
3035 /* The name is already allocated along with this objfile, so we don't
3036 need to duplicate it for the type. */
3037 fnp
->physname
= physname
? physname
: "";
3038 fnp
->type
= alloc_type (objfile
);
3039 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
3041 int nparams
= TYPE_NFIELDS (die
->type
);
3043 /* TYPE is the domain of this method, and DIE->TYPE is the type
3044 of the method itself (TYPE_CODE_METHOD). */
3045 smash_to_method_type (fnp
->type
, type
,
3046 TYPE_TARGET_TYPE (die
->type
),
3047 TYPE_FIELDS (die
->type
),
3048 TYPE_NFIELDS (die
->type
),
3049 TYPE_VARARGS (die
->type
));
3051 /* Handle static member functions.
3052 Dwarf2 has no clean way to discern C++ static and non-static
3053 member functions. G++ helps GDB by marking the first
3054 parameter for non-static member functions (which is the
3055 this pointer) as artificial. We obtain this information
3056 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3057 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
3058 fnp
->voffset
= VOFFSET_STATIC
;
3061 complaint (&symfile_complaints
, "member function type missing for '%s'",
3064 /* Get fcontext from DW_AT_containing_type if present. */
3065 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3066 fnp
->fcontext
= die_containing_type (die
, cu
);
3068 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3069 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3071 /* Get accessibility. */
3072 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3075 switch (DW_UNSND (attr
))
3077 case DW_ACCESS_private
:
3078 fnp
->is_private
= 1;
3080 case DW_ACCESS_protected
:
3081 fnp
->is_protected
= 1;
3086 /* Check for artificial methods. */
3087 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3088 if (attr
&& DW_UNSND (attr
) != 0)
3089 fnp
->is_artificial
= 1;
3091 /* Get index in virtual function table if it is a virtual member function. */
3092 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3095 /* Support the .debug_loc offsets */
3096 if (attr_form_is_block (attr
))
3098 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3100 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3102 dwarf2_complex_location_expr_complaint ();
3106 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3112 /* Create the vector of member function fields, and attach it to the type. */
3115 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3116 struct dwarf2_cu
*cu
)
3118 struct fnfieldlist
*flp
;
3119 int total_length
= 0;
3122 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3123 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3124 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3126 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3128 struct nextfnfield
*nfp
= flp
->head
;
3129 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3132 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3133 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3134 fn_flp
->fn_fields
= (struct fn_field
*)
3135 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3136 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3137 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3139 total_length
+= flp
->length
;
3142 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3143 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3146 /* Called when we find the DIE that starts a structure or union scope
3147 (definition) to process all dies that define the members of the
3150 NOTE: we need to call struct_type regardless of whether or not the
3151 DIE has an at_name attribute, since it might be an anonymous
3152 structure or union. This gets the type entered into our set of
3155 However, if the structure is incomplete (an opaque struct/union)
3156 then suppress creating a symbol table entry for it since gdb only
3157 wants to find the one with the complete definition. Note that if
3158 it is complete, we just call new_symbol, which does it's own
3159 checking about whether the struct/union is anonymous or not (and
3160 suppresses creating a symbol table entry itself). */
3163 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3165 struct objfile
*objfile
= cu
->objfile
;
3167 struct attribute
*attr
;
3168 const char *previous_prefix
= processing_current_prefix
;
3169 struct cleanup
*back_to
= NULL
;
3174 type
= alloc_type (objfile
);
3176 INIT_CPLUS_SPECIFIC (type
);
3177 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3178 if (attr
&& DW_STRING (attr
))
3180 if (cu
->language
== language_cplus
)
3182 char *new_prefix
= determine_class_name (die
, cu
);
3183 TYPE_TAG_NAME (type
) = obsavestring (new_prefix
,
3184 strlen (new_prefix
),
3185 &objfile
->objfile_obstack
);
3186 back_to
= make_cleanup (xfree
, new_prefix
);
3187 processing_current_prefix
= new_prefix
;
3191 /* The name is already allocated along with this objfile, so
3192 we don't need to duplicate it for the type. */
3193 TYPE_TAG_NAME (type
) = DW_STRING (attr
);
3197 if (die
->tag
== DW_TAG_structure_type
)
3199 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
3201 else if (die
->tag
== DW_TAG_union_type
)
3203 TYPE_CODE (type
) = TYPE_CODE_UNION
;
3207 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
3209 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
3212 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3215 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3219 TYPE_LENGTH (type
) = 0;
3222 /* We need to add the type field to the die immediately so we don't
3223 infinitely recurse when dealing with pointers to the structure
3224 type within the structure itself. */
3227 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
3229 struct field_info fi
;
3230 struct die_info
*child_die
;
3231 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
3233 memset (&fi
, 0, sizeof (struct field_info
));
3235 child_die
= die
->child
;
3237 while (child_die
&& child_die
->tag
)
3239 if (child_die
->tag
== DW_TAG_member
3240 || child_die
->tag
== DW_TAG_variable
)
3242 /* NOTE: carlton/2002-11-05: A C++ static data member
3243 should be a DW_TAG_member that is a declaration, but
3244 all versions of G++ as of this writing (so through at
3245 least 3.2.1) incorrectly generate DW_TAG_variable
3246 tags for them instead. */
3247 dwarf2_add_field (&fi
, child_die
, cu
);
3249 else if (child_die
->tag
== DW_TAG_subprogram
)
3251 /* C++ member function. */
3252 read_type_die (child_die
, cu
);
3253 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
3255 else if (child_die
->tag
== DW_TAG_inheritance
)
3257 /* C++ base class field. */
3258 dwarf2_add_field (&fi
, child_die
, cu
);
3260 child_die
= sibling_die (child_die
);
3263 /* Attach fields and member functions to the type. */
3265 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
3268 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
3270 /* Get the type which refers to the base class (possibly this
3271 class itself) which contains the vtable pointer for the current
3272 class from the DW_AT_containing_type attribute. */
3274 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3276 struct type
*t
= die_containing_type (die
, cu
);
3278 TYPE_VPTR_BASETYPE (type
) = t
;
3281 static const char vptr_name
[] =
3282 {'_', 'v', 'p', 't', 'r', '\0'};
3285 /* Our own class provides vtbl ptr. */
3286 for (i
= TYPE_NFIELDS (t
) - 1;
3287 i
>= TYPE_N_BASECLASSES (t
);
3290 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
3292 if ((strncmp (fieldname
, vptr_name
,
3293 strlen (vptr_name
) - 1)
3295 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
3297 TYPE_VPTR_FIELDNO (type
) = i
;
3302 /* Complain if virtual function table field not found. */
3303 if (i
< TYPE_N_BASECLASSES (t
))
3304 complaint (&symfile_complaints
,
3305 "virtual function table pointer not found when defining class '%s'",
3306 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
3311 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3316 do_cleanups (back_to
);
3320 /* No children, must be stub. */
3321 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
3324 processing_current_prefix
= previous_prefix
;
3325 if (back_to
!= NULL
)
3326 do_cleanups (back_to
);
3330 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3332 struct objfile
*objfile
= cu
->objfile
;
3333 const char *previous_prefix
= processing_current_prefix
;
3334 struct die_info
*child_die
= die
->child
;
3336 if (TYPE_TAG_NAME (die
->type
) != NULL
)
3337 processing_current_prefix
= TYPE_TAG_NAME (die
->type
);
3339 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
3340 snapshots) has been known to create a die giving a declaration
3341 for a class that has, as a child, a die giving a definition for a
3342 nested class. So we have to process our children even if the
3343 current die is a declaration. Normally, of course, a declaration
3344 won't have any children at all. */
3346 while (child_die
!= NULL
&& child_die
->tag
)
3348 if (child_die
->tag
== DW_TAG_member
3349 || child_die
->tag
== DW_TAG_variable
3350 || child_die
->tag
== DW_TAG_inheritance
)
3355 process_die (child_die
, cu
);
3357 child_die
= sibling_die (child_die
);
3360 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
3361 new_symbol (die
, die
->type
, cu
);
3363 processing_current_prefix
= previous_prefix
;
3366 /* Given a DW_AT_enumeration_type die, set its type. We do not
3367 complete the type's fields yet, or create any symbols. */
3370 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3372 struct objfile
*objfile
= cu
->objfile
;
3374 struct attribute
*attr
;
3379 type
= alloc_type (objfile
);
3381 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
3382 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3383 if (attr
&& DW_STRING (attr
))
3385 char *name
= DW_STRING (attr
);
3387 if (processing_has_namespace_info
)
3389 TYPE_TAG_NAME (type
) = obconcat (&objfile
->objfile_obstack
,
3390 processing_current_prefix
,
3391 processing_current_prefix
[0] == '\0'
3397 /* The name is already allocated along with this objfile, so
3398 we don't need to duplicate it for the type. */
3399 TYPE_TAG_NAME (type
) = name
;
3403 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3406 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3410 TYPE_LENGTH (type
) = 0;
3416 /* Determine the name of the type represented by DIE, which should be
3417 a named C++ compound type. Return the name in question; the caller
3418 is responsible for xfree()'ing it. */
3421 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
3423 struct cleanup
*back_to
= NULL
;
3424 struct die_info
*spec_die
= die_specification (die
, cu
);
3425 char *new_prefix
= NULL
;
3427 /* If this is the definition of a class that is declared by another
3428 die, then processing_current_prefix may not be accurate; see
3429 read_func_scope for a similar example. */
3430 if (spec_die
!= NULL
)
3432 char *specification_prefix
= determine_prefix (spec_die
, cu
);
3433 processing_current_prefix
= specification_prefix
;
3434 back_to
= make_cleanup (xfree
, specification_prefix
);
3437 /* If we don't have namespace debug info, guess the name by trying
3438 to demangle the names of members, just like we did in
3439 add_partial_structure. */
3440 if (!processing_has_namespace_info
)
3442 struct die_info
*child
;
3444 for (child
= die
->child
;
3445 child
!= NULL
&& child
->tag
!= 0;
3446 child
= sibling_die (child
))
3448 if (child
->tag
== DW_TAG_subprogram
)
3450 new_prefix
= class_name_from_physname (dwarf2_linkage_name
3453 if (new_prefix
!= NULL
)
3459 if (new_prefix
== NULL
)
3461 const char *name
= dwarf2_name (die
, cu
);
3462 new_prefix
= typename_concat (processing_current_prefix
,
3463 name
? name
: "<<anonymous>>");
3466 if (back_to
!= NULL
)
3467 do_cleanups (back_to
);
3472 /* Given a pointer to a die which begins an enumeration, process all
3473 the dies that define the members of the enumeration, and create the
3474 symbol for the enumeration type.
3476 NOTE: We reverse the order of the element list. */
3479 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3481 struct objfile
*objfile
= cu
->objfile
;
3482 struct die_info
*child_die
;
3483 struct field
*fields
;
3484 struct attribute
*attr
;
3487 int unsigned_enum
= 1;
3491 if (die
->child
!= NULL
)
3493 child_die
= die
->child
;
3494 while (child_die
&& child_die
->tag
)
3496 if (child_die
->tag
!= DW_TAG_enumerator
)
3498 process_die (child_die
, cu
);
3502 attr
= dwarf2_attr (child_die
, DW_AT_name
, cu
);
3505 sym
= new_symbol (child_die
, die
->type
, cu
);
3506 if (SYMBOL_VALUE (sym
) < 0)
3509 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3511 fields
= (struct field
*)
3513 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
3514 * sizeof (struct field
));
3517 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
3518 FIELD_TYPE (fields
[num_fields
]) = NULL
;
3519 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
3520 FIELD_BITSIZE (fields
[num_fields
]) = 0;
3521 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
3527 child_die
= sibling_die (child_die
);
3532 TYPE_NFIELDS (die
->type
) = num_fields
;
3533 TYPE_FIELDS (die
->type
) = (struct field
*)
3534 TYPE_ALLOC (die
->type
, sizeof (struct field
) * num_fields
);
3535 memcpy (TYPE_FIELDS (die
->type
), fields
,
3536 sizeof (struct field
) * num_fields
);
3540 TYPE_FLAGS (die
->type
) |= TYPE_FLAG_UNSIGNED
;
3543 new_symbol (die
, die
->type
, cu
);
3546 /* Extract all information from a DW_TAG_array_type DIE and put it in
3547 the DIE's type field. For now, this only handles one dimensional
3551 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3553 struct objfile
*objfile
= cu
->objfile
;
3554 struct die_info
*child_die
;
3555 struct type
*type
= NULL
;
3556 struct type
*element_type
, *range_type
, *index_type
;
3557 struct type
**range_types
= NULL
;
3558 struct attribute
*attr
;
3560 struct cleanup
*back_to
;
3562 /* Return if we've already decoded this type. */
3568 element_type
= die_type (die
, cu
);
3570 /* Irix 6.2 native cc creates array types without children for
3571 arrays with unspecified length. */
3572 if (die
->child
== NULL
)
3574 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
3575 range_type
= create_range_type (NULL
, index_type
, 0, -1);
3576 die
->type
= create_array_type (NULL
, element_type
, range_type
);
3580 back_to
= make_cleanup (null_cleanup
, NULL
);
3581 child_die
= die
->child
;
3582 while (child_die
&& child_die
->tag
)
3584 if (child_die
->tag
== DW_TAG_subrange_type
)
3586 read_subrange_type (child_die
, cu
);
3588 if (child_die
->type
!= NULL
)
3590 /* The range type was succesfully read. Save it for
3591 the array type creation. */
3592 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
3594 range_types
= (struct type
**)
3595 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
3596 * sizeof (struct type
*));
3598 make_cleanup (free_current_contents
, &range_types
);
3600 range_types
[ndim
++] = child_die
->type
;
3603 child_die
= sibling_die (child_die
);
3606 /* Dwarf2 dimensions are output from left to right, create the
3607 necessary array types in backwards order. */
3608 type
= element_type
;
3610 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
3612 /* Understand Dwarf2 support for vector types (like they occur on
3613 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3614 array type. This is not part of the Dwarf2/3 standard yet, but a
3615 custom vendor extension. The main difference between a regular
3616 array and the vector variant is that vectors are passed by value
3618 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
3620 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
3622 do_cleanups (back_to
);
3624 /* Install the type in the die. */
3628 /* First cut: install each common block member as a global variable. */
3631 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
3633 struct die_info
*child_die
;
3634 struct attribute
*attr
;
3636 CORE_ADDR base
= (CORE_ADDR
) 0;
3638 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
3641 /* Support the .debug_loc offsets */
3642 if (attr_form_is_block (attr
))
3644 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
3646 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3648 dwarf2_complex_location_expr_complaint ();
3652 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3653 "common block member");
3656 if (die
->child
!= NULL
)
3658 child_die
= die
->child
;
3659 while (child_die
&& child_die
->tag
)
3661 sym
= new_symbol (child_die
, NULL
, cu
);
3662 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
3665 SYMBOL_VALUE_ADDRESS (sym
) =
3666 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
3667 add_symbol_to_list (sym
, &global_symbols
);
3669 child_die
= sibling_die (child_die
);
3674 /* Read a C++ namespace. */
3677 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
3679 struct objfile
*objfile
= cu
->objfile
;
3680 const char *previous_prefix
= processing_current_prefix
;
3683 struct die_info
*current_die
;
3685 name
= namespace_name (die
, &is_anonymous
, cu
);
3687 /* Now build the name of the current namespace. */
3689 if (previous_prefix
[0] == '\0')
3691 processing_current_prefix
= name
;
3695 /* We need temp_name around because processing_current_prefix
3696 is a const char *. */
3697 char *temp_name
= alloca (strlen (previous_prefix
)
3698 + 2 + strlen(name
) + 1);
3699 strcpy (temp_name
, previous_prefix
);
3700 strcat (temp_name
, "::");
3701 strcat (temp_name
, name
);
3703 processing_current_prefix
= temp_name
;
3706 /* Add a symbol associated to this if we haven't seen the namespace
3707 before. Also, add a using directive if it's an anonymous
3710 if (dwarf2_extension (die
, cu
) == NULL
)
3714 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
3715 this cast will hopefully become unnecessary. */
3716 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
3717 (char *) processing_current_prefix
,
3719 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
3721 new_symbol (die
, type
, cu
);
3725 cp_add_using_directive (processing_current_prefix
,
3726 strlen (previous_prefix
),
3727 strlen (processing_current_prefix
));
3730 if (die
->child
!= NULL
)
3732 struct die_info
*child_die
= die
->child
;
3734 while (child_die
&& child_die
->tag
)
3736 process_die (child_die
, cu
);
3737 child_die
= sibling_die (child_die
);
3741 processing_current_prefix
= previous_prefix
;
3744 /* Return the name of the namespace represented by DIE. Set
3745 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
3749 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
3751 struct die_info
*current_die
;
3752 const char *name
= NULL
;
3754 /* Loop through the extensions until we find a name. */
3756 for (current_die
= die
;
3757 current_die
!= NULL
;
3758 current_die
= dwarf2_extension (die
, cu
))
3760 name
= dwarf2_name (current_die
, cu
);
3765 /* Is it an anonymous namespace? */
3767 *is_anonymous
= (name
== NULL
);
3769 name
= "(anonymous namespace)";
3774 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3775 the user defined type vector. */
3778 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3780 struct comp_unit_head
*cu_header
= &cu
->header
;
3782 struct attribute
*attr_byte_size
;
3783 struct attribute
*attr_address_class
;
3784 int byte_size
, addr_class
;
3791 type
= lookup_pointer_type (die_type (die
, cu
));
3793 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3795 byte_size
= DW_UNSND (attr_byte_size
);
3797 byte_size
= cu_header
->addr_size
;
3799 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
3800 if (attr_address_class
)
3801 addr_class
= DW_UNSND (attr_address_class
);
3803 addr_class
= DW_ADDR_none
;
3805 /* If the pointer size or address class is different than the
3806 default, create a type variant marked as such and set the
3807 length accordingly. */
3808 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
3810 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3814 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
3815 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
3816 type
= make_type_with_address_space (type
, type_flags
);
3818 else if (TYPE_LENGTH (type
) != byte_size
)
3820 complaint (&symfile_complaints
, "invalid pointer size %d", byte_size
);
3823 /* Should we also complain about unhandled address classes? */
3827 TYPE_LENGTH (type
) = byte_size
;
3831 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3832 the user defined type vector. */
3835 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3837 struct objfile
*objfile
= cu
->objfile
;
3839 struct type
*to_type
;
3840 struct type
*domain
;
3847 type
= alloc_type (objfile
);
3848 to_type
= die_type (die
, cu
);
3849 domain
= die_containing_type (die
, cu
);
3850 smash_to_member_type (type
, domain
, to_type
);
3855 /* Extract all information from a DW_TAG_reference_type DIE and add to
3856 the user defined type vector. */
3859 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3861 struct comp_unit_head
*cu_header
= &cu
->header
;
3863 struct attribute
*attr
;
3870 type
= lookup_reference_type (die_type (die
, cu
));
3871 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3874 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3878 TYPE_LENGTH (type
) = cu_header
->addr_size
;
3884 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3886 struct type
*base_type
;
3893 base_type
= die_type (die
, cu
);
3894 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
3898 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3900 struct type
*base_type
;
3907 base_type
= die_type (die
, cu
);
3908 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
3911 /* Extract all information from a DW_TAG_string_type DIE and add to
3912 the user defined type vector. It isn't really a user defined type,
3913 but it behaves like one, with other DIE's using an AT_user_def_type
3914 attribute to reference it. */
3917 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3919 struct objfile
*objfile
= cu
->objfile
;
3920 struct type
*type
, *range_type
, *index_type
, *char_type
;
3921 struct attribute
*attr
;
3922 unsigned int length
;
3929 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
3932 length
= DW_UNSND (attr
);
3936 /* check for the DW_AT_byte_size attribute */
3937 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3940 length
= DW_UNSND (attr
);
3947 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
3948 range_type
= create_range_type (NULL
, index_type
, 1, length
);
3949 if (cu
->language
== language_fortran
)
3951 /* Need to create a unique string type for bounds
3953 type
= create_string_type (0, range_type
);
3957 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
, cu
);
3958 type
= create_string_type (char_type
, range_type
);
3963 /* Handle DIES due to C code like:
3967 int (*funcp)(int a, long l);
3971 ('funcp' generates a DW_TAG_subroutine_type DIE)
3975 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3977 struct type
*type
; /* Type that this function returns */
3978 struct type
*ftype
; /* Function that returns above type */
3979 struct attribute
*attr
;
3981 /* Decode the type that this subroutine returns */
3986 type
= die_type (die
, cu
);
3987 ftype
= lookup_function_type (type
);
3989 /* All functions in C++ have prototypes. */
3990 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
3991 if ((attr
&& (DW_UNSND (attr
) != 0))
3992 || cu
->language
== language_cplus
)
3993 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
3995 if (die
->child
!= NULL
)
3997 struct die_info
*child_die
;
4001 /* Count the number of parameters.
4002 FIXME: GDB currently ignores vararg functions, but knows about
4003 vararg member functions. */
4004 child_die
= die
->child
;
4005 while (child_die
&& child_die
->tag
)
4007 if (child_die
->tag
== DW_TAG_formal_parameter
)
4009 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4010 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
4011 child_die
= sibling_die (child_die
);
4014 /* Allocate storage for parameters and fill them in. */
4015 TYPE_NFIELDS (ftype
) = nparams
;
4016 TYPE_FIELDS (ftype
) = (struct field
*)
4017 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
4019 child_die
= die
->child
;
4020 while (child_die
&& child_die
->tag
)
4022 if (child_die
->tag
== DW_TAG_formal_parameter
)
4024 /* Dwarf2 has no clean way to discern C++ static and non-static
4025 member functions. G++ helps GDB by marking the first
4026 parameter for non-static member functions (which is the
4027 this pointer) as artificial. We pass this information
4028 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4029 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
4031 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
4033 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
4034 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
4037 child_die
= sibling_die (child_die
);
4045 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
4047 struct objfile
*objfile
= cu
->objfile
;
4048 struct attribute
*attr
;
4053 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4054 if (attr
&& DW_STRING (attr
))
4056 name
= DW_STRING (attr
);
4058 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
4059 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, cu
);
4063 /* Find a representation of a given base type and install
4064 it in the TYPE field of the die. */
4067 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4069 struct objfile
*objfile
= cu
->objfile
;
4071 struct attribute
*attr
;
4072 int encoding
= 0, size
= 0;
4074 /* If we've already decoded this die, this is a no-op. */
4080 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
4083 encoding
= DW_UNSND (attr
);
4085 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4088 size
= DW_UNSND (attr
);
4090 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4091 if (attr
&& DW_STRING (attr
))
4093 enum type_code code
= TYPE_CODE_INT
;
4098 case DW_ATE_address
:
4099 /* Turn DW_ATE_address into a void * pointer. */
4100 code
= TYPE_CODE_PTR
;
4101 type_flags
|= TYPE_FLAG_UNSIGNED
;
4103 case DW_ATE_boolean
:
4104 code
= TYPE_CODE_BOOL
;
4105 type_flags
|= TYPE_FLAG_UNSIGNED
;
4107 case DW_ATE_complex_float
:
4108 code
= TYPE_CODE_COMPLEX
;
4111 code
= TYPE_CODE_FLT
;
4114 case DW_ATE_signed_char
:
4116 case DW_ATE_unsigned
:
4117 case DW_ATE_unsigned_char
:
4118 type_flags
|= TYPE_FLAG_UNSIGNED
;
4121 complaint (&symfile_complaints
, "unsupported DW_AT_encoding: '%s'",
4122 dwarf_type_encoding_name (encoding
));
4125 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
4126 if (encoding
== DW_ATE_address
)
4127 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
,
4129 else if (encoding
== DW_ATE_complex_float
)
4132 TYPE_TARGET_TYPE (type
)
4133 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
, cu
);
4134 else if (size
== 16)
4135 TYPE_TARGET_TYPE (type
)
4136 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
4138 TYPE_TARGET_TYPE (type
)
4139 = dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
4144 type
= dwarf_base_type (encoding
, size
, cu
);
4149 /* Read the given DW_AT_subrange DIE. */
4152 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4154 struct type
*base_type
;
4155 struct type
*range_type
;
4156 struct attribute
*attr
;
4160 /* If we have already decoded this die, then nothing more to do. */
4164 base_type
= die_type (die
, cu
);
4165 if (base_type
== NULL
)
4167 complaint (&symfile_complaints
,
4168 "DW_AT_type missing from DW_TAG_subrange_type");
4172 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
4173 base_type
= alloc_type (NULL
);
4175 if (cu
->language
== language_fortran
)
4177 /* FORTRAN implies a lower bound of 1, if not given. */
4181 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
4183 low
= dwarf2_get_attr_constant_value (attr
, 0);
4185 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
4188 if (attr
->form
== DW_FORM_block1
)
4190 /* GCC encodes arrays with unspecified or dynamic length
4191 with a DW_FORM_block1 attribute.
4192 FIXME: GDB does not yet know how to handle dynamic
4193 arrays properly, treat them as arrays with unspecified
4196 FIXME: jimb/2003-09-22: GDB does not really know
4197 how to handle arrays of unspecified length
4198 either; we just represent them as zero-length
4199 arrays. Choose an appropriate upper bound given
4200 the lower bound we've computed above. */
4204 high
= dwarf2_get_attr_constant_value (attr
, 1);
4207 range_type
= create_range_type (NULL
, base_type
, low
, high
);
4209 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4210 if (attr
&& DW_STRING (attr
))
4211 TYPE_NAME (range_type
) = DW_STRING (attr
);
4213 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4215 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
4217 die
->type
= range_type
;
4221 /* Read a whole compilation unit into a linked list of dies. */
4223 static struct die_info
*
4224 read_comp_unit (char *info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
4226 /* Reset die reference table; we are
4227 building new ones now. */
4228 dwarf2_empty_hash_tables ();
4230 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
4233 /* Read a single die and all its descendents. Set the die's sibling
4234 field to NULL; set other fields in the die correctly, and set all
4235 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
4236 location of the info_ptr after reading all of those dies. PARENT
4237 is the parent of the die in question. */
4239 static struct die_info
*
4240 read_die_and_children (char *info_ptr
, bfd
*abfd
,
4241 struct dwarf2_cu
*cu
,
4242 char **new_info_ptr
,
4243 struct die_info
*parent
)
4245 struct die_info
*die
;
4249 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
4250 store_in_ref_table (die
->offset
, die
);
4254 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
4260 *new_info_ptr
= cur_ptr
;
4263 die
->sibling
= NULL
;
4264 die
->parent
= parent
;
4268 /* Read a die, all of its descendents, and all of its siblings; set
4269 all of the fields of all of the dies correctly. Arguments are as
4270 in read_die_and_children. */
4272 static struct die_info
*
4273 read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
4274 struct dwarf2_cu
*cu
,
4275 char **new_info_ptr
,
4276 struct die_info
*parent
)
4278 struct die_info
*first_die
, *last_sibling
;
4282 first_die
= last_sibling
= NULL
;
4286 struct die_info
*die
4287 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
4295 last_sibling
->sibling
= die
;
4300 *new_info_ptr
= cur_ptr
;
4310 /* Free a linked list of dies. */
4313 free_die_list (struct die_info
*dies
)
4315 struct die_info
*die
, *next
;
4320 if (die
->child
!= NULL
)
4321 free_die_list (die
->child
);
4322 next
= die
->sibling
;
4330 do_free_die_list_cleanup (void *dies
)
4332 free_die_list (dies
);
4335 static struct cleanup
*
4336 make_cleanup_free_die_list (struct die_info
*dies
)
4338 return make_cleanup (do_free_die_list_cleanup
, dies
);
4342 /* Read the contents of the section at OFFSET and of size SIZE from the
4343 object file specified by OBJFILE into the objfile_obstack and return it. */
4346 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
4348 bfd
*abfd
= objfile
->obfd
;
4350 bfd_size_type size
= bfd_get_section_size_before_reloc (sectp
);
4355 buf
= (char *) obstack_alloc (&objfile
->objfile_obstack
, size
);
4357 = (char *) symfile_relocate_debug_section (abfd
, sectp
, (bfd_byte
*) buf
);
4361 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
4362 || bfd_bread (buf
, size
, abfd
) != size
)
4363 error ("Dwarf Error: Can't read DWARF data from '%s'",
4364 bfd_get_filename (abfd
));
4369 /* In DWARF version 2, the description of the debugging information is
4370 stored in a separate .debug_abbrev section. Before we read any
4371 dies from a section we read in all abbreviations and install them
4375 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
4377 struct comp_unit_head
*cu_header
= &cu
->header
;
4379 struct abbrev_info
*cur_abbrev
;
4380 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
4381 unsigned int abbrev_form
, hash_number
;
4382 struct attr_abbrev
*cur_attrs
;
4383 unsigned int allocated_attrs
;
4385 /* Initialize dwarf2 abbrevs */
4386 obstack_init (&cu
->abbrev_obstack
);
4387 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
4389 * sizeof (struct abbrev_info
*)));
4390 memset (cu
->dwarf2_abbrevs
, 0,
4391 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
4393 abbrev_ptr
= dwarf_abbrev_buffer
+ cu_header
->abbrev_offset
;
4394 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4395 abbrev_ptr
+= bytes_read
;
4397 allocated_attrs
= ATTR_ALLOC_CHUNK
;
4398 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
4400 /* loop until we reach an abbrev number of 0 */
4401 while (abbrev_number
)
4403 cur_abbrev
= dwarf_alloc_abbrev (cu
);
4405 /* read in abbrev header */
4406 cur_abbrev
->number
= abbrev_number
;
4407 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4408 abbrev_ptr
+= bytes_read
;
4409 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
4412 /* now read in declarations */
4413 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4414 abbrev_ptr
+= bytes_read
;
4415 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4416 abbrev_ptr
+= bytes_read
;
4419 if (cur_abbrev
->num_attrs
== allocated_attrs
)
4421 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
4423 = xrealloc (cur_attrs
, (allocated_attrs
4424 * sizeof (struct attr_abbrev
)));
4426 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
4427 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
4428 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4429 abbrev_ptr
+= bytes_read
;
4430 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4431 abbrev_ptr
+= bytes_read
;
4434 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
4435 (cur_abbrev
->num_attrs
4436 * sizeof (struct attr_abbrev
)));
4437 memcpy (cur_abbrev
->attrs
, cur_attrs
,
4438 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
4440 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
4441 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
4442 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
4444 /* Get next abbreviation.
4445 Under Irix6 the abbreviations for a compilation unit are not
4446 always properly terminated with an abbrev number of 0.
4447 Exit loop if we encounter an abbreviation which we have
4448 already read (which means we are about to read the abbreviations
4449 for the next compile unit) or if the end of the abbreviation
4450 table is reached. */
4451 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
4452 >= dwarf_abbrev_size
)
4454 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4455 abbrev_ptr
+= bytes_read
;
4456 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
4463 /* Release the memory used by the abbrev table for a compilation unit. */
4466 dwarf2_free_abbrev_table (void *ptr_to_cu
)
4468 struct dwarf2_cu
*cu
= ptr_to_cu
;
4470 obstack_free (&cu
->abbrev_obstack
, NULL
);
4471 cu
->dwarf2_abbrevs
= NULL
;
4474 /* Lookup an abbrev_info structure in the abbrev hash table. */
4476 static struct abbrev_info
*
4477 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
4479 unsigned int hash_number
;
4480 struct abbrev_info
*abbrev
;
4482 hash_number
= number
% ABBREV_HASH_SIZE
;
4483 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
4487 if (abbrev
->number
== number
)
4490 abbrev
= abbrev
->next
;
4495 /* Read a minimal amount of information into the minimal die structure. */
4498 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
4499 char *info_ptr
, struct dwarf2_cu
*cu
)
4501 unsigned int abbrev_number
, bytes_read
, i
;
4502 struct abbrev_info
*abbrev
;
4503 struct attribute attr
;
4504 struct attribute spec_attr
;
4505 int found_spec_attr
= 0;
4506 int has_low_pc_attr
= 0;
4507 int has_high_pc_attr
= 0;
4509 *part_die
= zeroed_partial_die
;
4510 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4511 info_ptr
+= bytes_read
;
4515 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4518 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number
,
4519 bfd_get_filename (abfd
));
4521 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
4522 part_die
->tag
= abbrev
->tag
;
4523 part_die
->has_children
= abbrev
->has_children
;
4524 part_die
->abbrev
= abbrev_number
;
4526 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4528 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
4530 /* Store the data if it is of an attribute we want to keep in a
4531 partial symbol table. */
4536 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
4537 if (part_die
->name
== NULL
)
4538 part_die
->name
= DW_STRING (&attr
);
4540 case DW_AT_MIPS_linkage_name
:
4541 part_die
->name
= DW_STRING (&attr
);
4544 has_low_pc_attr
= 1;
4545 part_die
->lowpc
= DW_ADDR (&attr
);
4548 has_high_pc_attr
= 1;
4549 part_die
->highpc
= DW_ADDR (&attr
);
4551 case DW_AT_location
:
4552 /* Support the .debug_loc offsets */
4553 if (attr_form_is_block (&attr
))
4555 part_die
->locdesc
= DW_BLOCK (&attr
);
4557 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
4559 dwarf2_complex_location_expr_complaint ();
4563 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4564 "partial symbol information");
4567 case DW_AT_language
:
4568 part_die
->language
= DW_UNSND (&attr
);
4570 case DW_AT_external
:
4571 part_die
->is_external
= DW_UNSND (&attr
);
4573 case DW_AT_declaration
:
4574 part_die
->is_declaration
= DW_UNSND (&attr
);
4577 part_die
->has_type
= 1;
4579 case DW_AT_abstract_origin
:
4580 case DW_AT_specification
:
4581 found_spec_attr
= 1;
4585 /* Ignore absolute siblings, they might point outside of
4586 the current compile unit. */
4587 if (attr
.form
== DW_FORM_ref_addr
)
4588 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
4591 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
, cu
);
4598 /* If we found a reference attribute and the die has no name, try
4599 to find a name in the referred to die. */
4601 if (found_spec_attr
&& part_die
->name
== NULL
)
4603 struct partial_die_info spec_die
;
4606 spec_ptr
= dwarf_info_buffer
4607 + dwarf2_get_ref_die_offset (&spec_attr
, cu
);
4608 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu
);
4611 part_die
->name
= spec_die
.name
;
4613 /* Copy DW_AT_external attribute if it is set. */
4614 if (spec_die
.is_external
)
4615 part_die
->is_external
= spec_die
.is_external
;
4619 /* When using the GNU linker, .gnu.linkonce. sections are used to
4620 eliminate duplicate copies of functions and vtables and such.
4621 The linker will arbitrarily choose one and discard the others.
4622 The AT_*_pc values for such functions refer to local labels in
4623 these sections. If the section from that file was discarded, the
4624 labels are not in the output, so the relocs get a value of 0.
4625 If this is a discarded function, mark the pc bounds as invalid,
4626 so that GDB will ignore it. */
4627 if (has_low_pc_attr
&& has_high_pc_attr
4628 && part_die
->lowpc
< part_die
->highpc
4629 && (part_die
->lowpc
!= 0
4630 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
4631 part_die
->has_pc_info
= 1;
4635 /* Read the die from the .debug_info section buffer. Set DIEP to
4636 point to a newly allocated die with its information, except for its
4637 child, sibling, and parent fields. Set HAS_CHILDREN to tell
4638 whether the die has children or not. */
4641 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
4642 struct dwarf2_cu
*cu
, int *has_children
)
4644 unsigned int abbrev_number
, bytes_read
, i
, offset
;
4645 struct abbrev_info
*abbrev
;
4646 struct die_info
*die
;
4648 offset
= info_ptr
- dwarf_info_buffer
;
4649 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4650 info_ptr
+= bytes_read
;
4653 die
= dwarf_alloc_die ();
4655 die
->abbrev
= abbrev_number
;
4662 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4665 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
4667 bfd_get_filename (abfd
));
4669 die
= dwarf_alloc_die ();
4670 die
->offset
= offset
;
4671 die
->tag
= abbrev
->tag
;
4672 die
->abbrev
= abbrev_number
;
4675 die
->num_attrs
= abbrev
->num_attrs
;
4676 die
->attrs
= (struct attribute
*)
4677 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
4679 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4681 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
4682 abfd
, info_ptr
, cu
);
4686 *has_children
= abbrev
->has_children
;
4690 /* Read an attribute value described by an attribute form. */
4693 read_attribute_value (struct attribute
*attr
, unsigned form
,
4694 bfd
*abfd
, char *info_ptr
,
4695 struct dwarf2_cu
*cu
)
4697 struct comp_unit_head
*cu_header
= &cu
->header
;
4698 unsigned int bytes_read
;
4699 struct dwarf_block
*blk
;
4705 case DW_FORM_ref_addr
:
4706 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
4707 info_ptr
+= bytes_read
;
4709 case DW_FORM_block2
:
4710 blk
= dwarf_alloc_block ();
4711 blk
->size
= read_2_bytes (abfd
, info_ptr
);
4713 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4714 info_ptr
+= blk
->size
;
4715 DW_BLOCK (attr
) = blk
;
4717 case DW_FORM_block4
:
4718 blk
= dwarf_alloc_block ();
4719 blk
->size
= read_4_bytes (abfd
, info_ptr
);
4721 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4722 info_ptr
+= blk
->size
;
4723 DW_BLOCK (attr
) = blk
;
4726 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4730 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4734 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4737 case DW_FORM_string
:
4738 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
4739 info_ptr
+= bytes_read
;
4742 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
4744 info_ptr
+= bytes_read
;
4747 blk
= dwarf_alloc_block ();
4748 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4749 info_ptr
+= bytes_read
;
4750 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4751 info_ptr
+= blk
->size
;
4752 DW_BLOCK (attr
) = blk
;
4754 case DW_FORM_block1
:
4755 blk
= dwarf_alloc_block ();
4756 blk
->size
= read_1_byte (abfd
, info_ptr
);
4758 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4759 info_ptr
+= blk
->size
;
4760 DW_BLOCK (attr
) = blk
;
4763 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4767 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4771 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
4772 info_ptr
+= bytes_read
;
4775 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4776 info_ptr
+= bytes_read
;
4779 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4783 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4787 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4791 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4794 case DW_FORM_ref_udata
:
4795 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4796 info_ptr
+= bytes_read
;
4798 case DW_FORM_indirect
:
4799 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4800 info_ptr
+= bytes_read
;
4801 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
4804 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
4805 dwarf_form_name (form
),
4806 bfd_get_filename (abfd
));
4811 /* Read an attribute described by an abbreviated attribute. */
4814 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
4815 bfd
*abfd
, char *info_ptr
, struct dwarf2_cu
*cu
)
4817 attr
->name
= abbrev
->name
;
4818 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
4821 /* read dwarf information from a buffer */
4824 read_1_byte (bfd
*abfd
, char *buf
)
4826 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4830 read_1_signed_byte (bfd
*abfd
, char *buf
)
4832 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
4836 read_2_bytes (bfd
*abfd
, char *buf
)
4838 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4842 read_2_signed_bytes (bfd
*abfd
, char *buf
)
4844 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4848 read_4_bytes (bfd
*abfd
, char *buf
)
4850 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4854 read_4_signed_bytes (bfd
*abfd
, char *buf
)
4856 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4859 static unsigned long
4860 read_8_bytes (bfd
*abfd
, char *buf
)
4862 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4866 read_address (bfd
*abfd
, char *buf
, struct dwarf2_cu
*cu
, int *bytes_read
)
4868 struct comp_unit_head
*cu_header
= &cu
->header
;
4869 CORE_ADDR retval
= 0;
4871 if (cu_header
->signed_addr_p
)
4873 switch (cu_header
->addr_size
)
4876 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4879 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4882 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
4885 internal_error (__FILE__
, __LINE__
,
4886 "read_address: bad switch, signed [in module %s]",
4887 bfd_get_filename (abfd
));
4892 switch (cu_header
->addr_size
)
4895 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4898 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4901 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4904 internal_error (__FILE__
, __LINE__
,
4905 "read_address: bad switch, unsigned [in module %s]",
4906 bfd_get_filename (abfd
));
4910 *bytes_read
= cu_header
->addr_size
;
4914 /* Read the initial length from a section. The (draft) DWARF 3
4915 specification allows the initial length to take up either 4 bytes
4916 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
4917 bytes describe the length and all offsets will be 8 bytes in length
4920 An older, non-standard 64-bit format is also handled by this
4921 function. The older format in question stores the initial length
4922 as an 8-byte quantity without an escape value. Lengths greater
4923 than 2^32 aren't very common which means that the initial 4 bytes
4924 is almost always zero. Since a length value of zero doesn't make
4925 sense for the 32-bit format, this initial zero can be considered to
4926 be an escape value which indicates the presence of the older 64-bit
4927 format. As written, the code can't detect (old format) lengths
4928 greater than 4GB. If it becomes necessary to handle lengths somewhat
4929 larger than 4GB, we could allow other small values (such as the
4930 non-sensical values of 1, 2, and 3) to also be used as escape values
4931 indicating the presence of the old format.
4933 The value returned via bytes_read should be used to increment
4934 the relevant pointer after calling read_initial_length().
4936 As a side effect, this function sets the fields initial_length_size
4937 and offset_size in cu_header to the values appropriate for the
4938 length field. (The format of the initial length field determines
4939 the width of file offsets to be fetched later with fetch_offset().)
4941 [ Note: read_initial_length() and read_offset() are based on the
4942 document entitled "DWARF Debugging Information Format", revision
4943 3, draft 8, dated November 19, 2001. This document was obtained
4946 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
4948 This document is only a draft and is subject to change. (So beware.)
4950 Details regarding the older, non-standard 64-bit format were
4951 determined empirically by examining 64-bit ELF files produced
4952 by the SGI toolchain on an IRIX 6.5 machine.
4954 - Kevin, July 16, 2002
4958 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
4963 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4965 if (retval
== 0xffffffff)
4967 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
4969 if (cu_header
!= NULL
)
4971 cu_header
->initial_length_size
= 12;
4972 cu_header
->offset_size
= 8;
4975 else if (retval
== 0)
4977 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
4979 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4981 if (cu_header
!= NULL
)
4983 cu_header
->initial_length_size
= 8;
4984 cu_header
->offset_size
= 8;
4990 if (cu_header
!= NULL
)
4992 cu_header
->initial_length_size
= 4;
4993 cu_header
->offset_size
= 4;
5000 /* Read an offset from the data stream. The size of the offset is
5001 given by cu_header->offset_size. */
5004 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
5009 switch (cu_header
->offset_size
)
5012 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5016 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5020 internal_error (__FILE__
, __LINE__
,
5021 "read_offset: bad switch [in module %s]",
5022 bfd_get_filename (abfd
));
5029 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
5031 /* If the size of a host char is 8 bits, we can return a pointer
5032 to the buffer, otherwise we have to copy the data to a buffer
5033 allocated on the temporary obstack. */
5034 gdb_assert (HOST_CHAR_BIT
== 8);
5039 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5041 /* If the size of a host char is 8 bits, we can return a pointer
5042 to the string, otherwise we have to copy the string to a buffer
5043 allocated on the temporary obstack. */
5044 gdb_assert (HOST_CHAR_BIT
== 8);
5047 *bytes_read_ptr
= 1;
5050 *bytes_read_ptr
= strlen (buf
) + 1;
5055 read_indirect_string (bfd
*abfd
, char *buf
,
5056 const struct comp_unit_head
*cu_header
,
5057 unsigned int *bytes_read_ptr
)
5059 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
5060 (int *) bytes_read_ptr
);
5062 if (dwarf_str_buffer
== NULL
)
5064 error ("DW_FORM_strp used without .debug_str section [in module %s]",
5065 bfd_get_filename (abfd
));
5068 if (str_offset
>= dwarf_str_size
)
5070 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
5071 bfd_get_filename (abfd
));
5074 gdb_assert (HOST_CHAR_BIT
== 8);
5075 if (dwarf_str_buffer
[str_offset
] == '\0')
5077 return dwarf_str_buffer
+ str_offset
;
5080 static unsigned long
5081 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5083 unsigned long result
;
5084 unsigned int num_read
;
5094 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5097 result
|= ((unsigned long)(byte
& 127) << shift
);
5098 if ((byte
& 128) == 0)
5104 *bytes_read_ptr
= num_read
;
5109 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5112 int i
, shift
, size
, num_read
;
5122 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5125 result
|= ((long)(byte
& 127) << shift
);
5127 if ((byte
& 128) == 0)
5132 if ((shift
< size
) && (byte
& 0x40))
5134 result
|= -(1 << shift
);
5136 *bytes_read_ptr
= num_read
;
5140 /* Return a pointer to just past the end of an LEB128 number in BUF. */
5143 skip_leb128 (bfd
*abfd
, char *buf
)
5149 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5151 if ((byte
& 128) == 0)
5157 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
5163 cu
->language
= language_c
;
5165 case DW_LANG_C_plus_plus
:
5166 cu
->language
= language_cplus
;
5168 case DW_LANG_Fortran77
:
5169 case DW_LANG_Fortran90
:
5170 case DW_LANG_Fortran95
:
5171 cu
->language
= language_fortran
;
5173 case DW_LANG_Mips_Assembler
:
5174 cu
->language
= language_asm
;
5177 cu
->language
= language_java
;
5181 case DW_LANG_Cobol74
:
5182 case DW_LANG_Cobol85
:
5183 case DW_LANG_Pascal83
:
5184 case DW_LANG_Modula2
:
5186 cu
->language
= language_minimal
;
5189 cu
->language_defn
= language_def (cu
->language
);
5192 /* Return the named attribute or NULL if not there. */
5194 static struct attribute
*
5195 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
5198 struct attribute
*spec
= NULL
;
5200 for (i
= 0; i
< die
->num_attrs
; ++i
)
5202 if (die
->attrs
[i
].name
== name
)
5204 return &die
->attrs
[i
];
5206 if (die
->attrs
[i
].name
== DW_AT_specification
5207 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
5208 spec
= &die
->attrs
[i
];
5212 struct die_info
*ref_die
=
5213 follow_die_ref (dwarf2_get_ref_die_offset (spec
, cu
));
5216 return dwarf2_attr (ref_die
, name
, cu
);
5223 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
5225 return (dwarf2_attr (die
, DW_AT_declaration
, cu
)
5226 && ! dwarf2_attr (die
, DW_AT_specification
, cu
));
5229 /* Return the die giving the specification for DIE, if there is
5232 static struct die_info
*
5233 die_specification (struct die_info
*die
, struct dwarf2_cu
*cu
)
5235 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
, cu
);
5237 if (spec_attr
== NULL
)
5240 return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr
, cu
));
5243 /* Free the line_header structure *LH, and any arrays and strings it
5246 free_line_header (struct line_header
*lh
)
5248 if (lh
->standard_opcode_lengths
)
5249 xfree (lh
->standard_opcode_lengths
);
5251 /* Remember that all the lh->file_names[i].name pointers are
5252 pointers into debug_line_buffer, and don't need to be freed. */
5254 xfree (lh
->file_names
);
5256 /* Similarly for the include directory names. */
5257 if (lh
->include_dirs
)
5258 xfree (lh
->include_dirs
);
5264 /* Add an entry to LH's include directory table. */
5266 add_include_dir (struct line_header
*lh
, char *include_dir
)
5268 /* Grow the array if necessary. */
5269 if (lh
->include_dirs_size
== 0)
5271 lh
->include_dirs_size
= 1; /* for testing */
5272 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
5273 * sizeof (*lh
->include_dirs
));
5275 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
5277 lh
->include_dirs_size
*= 2;
5278 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
5279 (lh
->include_dirs_size
5280 * sizeof (*lh
->include_dirs
)));
5283 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
5287 /* Add an entry to LH's file name table. */
5289 add_file_name (struct line_header
*lh
,
5291 unsigned int dir_index
,
5292 unsigned int mod_time
,
5293 unsigned int length
)
5295 struct file_entry
*fe
;
5297 /* Grow the array if necessary. */
5298 if (lh
->file_names_size
== 0)
5300 lh
->file_names_size
= 1; /* for testing */
5301 lh
->file_names
= xmalloc (lh
->file_names_size
5302 * sizeof (*lh
->file_names
));
5304 else if (lh
->num_file_names
>= lh
->file_names_size
)
5306 lh
->file_names_size
*= 2;
5307 lh
->file_names
= xrealloc (lh
->file_names
,
5308 (lh
->file_names_size
5309 * sizeof (*lh
->file_names
)));
5312 fe
= &lh
->file_names
[lh
->num_file_names
++];
5314 fe
->dir_index
= dir_index
;
5315 fe
->mod_time
= mod_time
;
5316 fe
->length
= length
;
5320 /* Read the statement program header starting at OFFSET in
5321 dwarf_line_buffer, according to the endianness of ABFD. Return a
5322 pointer to a struct line_header, allocated using xmalloc.
5324 NOTE: the strings in the include directory and file name tables of
5325 the returned object point into debug_line_buffer, and must not be
5327 static struct line_header
*
5328 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
5329 struct dwarf2_cu
*cu
)
5331 struct cleanup
*back_to
;
5332 struct line_header
*lh
;
5336 char *cur_dir
, *cur_file
;
5338 if (dwarf_line_buffer
== NULL
)
5340 complaint (&symfile_complaints
, "missing .debug_line section");
5344 /* Make sure that at least there's room for the total_length field. That
5345 could be 12 bytes long, but we're just going to fudge that. */
5346 if (offset
+ 4 >= dwarf_line_size
)
5348 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5352 lh
= xmalloc (sizeof (*lh
));
5353 memset (lh
, 0, sizeof (*lh
));
5354 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
5357 line_ptr
= dwarf_line_buffer
+ offset
;
5359 /* read in the header */
5360 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
5361 line_ptr
+= bytes_read
;
5362 if (line_ptr
+ lh
->total_length
> dwarf_line_buffer
+ dwarf_line_size
)
5364 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5367 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
5368 lh
->version
= read_2_bytes (abfd
, line_ptr
);
5370 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
5371 line_ptr
+= bytes_read
;
5372 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
5374 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
5376 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
5378 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
5380 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
5382 lh
->standard_opcode_lengths
5383 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
5385 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
5386 for (i
= 1; i
< lh
->opcode_base
; ++i
)
5388 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
5392 /* Read directory table */
5393 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
5395 line_ptr
+= bytes_read
;
5396 add_include_dir (lh
, cur_dir
);
5398 line_ptr
+= bytes_read
;
5400 /* Read file name table */
5401 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
5403 unsigned int dir_index
, mod_time
, length
;
5405 line_ptr
+= bytes_read
;
5406 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5407 line_ptr
+= bytes_read
;
5408 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5409 line_ptr
+= bytes_read
;
5410 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5411 line_ptr
+= bytes_read
;
5413 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
5415 line_ptr
+= bytes_read
;
5416 lh
->statement_program_start
= line_ptr
;
5418 if (line_ptr
> dwarf_line_buffer
+ dwarf_line_size
)
5419 complaint (&symfile_complaints
,
5420 "line number info header doesn't fit in `.debug_line' section");
5422 discard_cleanups (back_to
);
5426 /* This function exists to work around a bug in certain compilers
5427 (particularly GCC 2.95), in which the first line number marker of a
5428 function does not show up until after the prologue, right before
5429 the second line number marker. This function shifts ADDRESS down
5430 to the beginning of the function if necessary, and is called on
5431 addresses passed to record_line. */
5434 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
5436 struct function_range
*fn
;
5438 /* Find the function_range containing address. */
5443 cu
->cached_fn
= cu
->first_fn
;
5447 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
5453 while (fn
&& fn
!= cu
->cached_fn
)
5454 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
5464 if (address
!= fn
->lowpc
)
5465 complaint (&symfile_complaints
,
5466 "misplaced first line number at 0x%lx for '%s'",
5467 (unsigned long) address
, fn
->name
);
5472 /* Decode the line number information for the compilation unit whose
5473 line number info is at OFFSET in the .debug_line section.
5474 The compilation directory of the file is passed in COMP_DIR. */
5477 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
5478 struct dwarf2_cu
*cu
)
5482 unsigned int bytes_read
;
5483 unsigned char op_code
, extended_op
, adj_opcode
;
5485 struct objfile
*objfile
= cu
->objfile
;
5487 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5489 line_ptr
= lh
->statement_program_start
;
5490 line_end
= lh
->statement_program_end
;
5492 /* Read the statement sequences until there's nothing left. */
5493 while (line_ptr
< line_end
)
5495 /* state machine registers */
5496 CORE_ADDR address
= 0;
5497 unsigned int file
= 1;
5498 unsigned int line
= 1;
5499 unsigned int column
= 0;
5500 int is_stmt
= lh
->default_is_stmt
;
5501 int basic_block
= 0;
5502 int end_sequence
= 0;
5504 /* Start a subfile for the current file of the state machine. */
5505 if (lh
->num_file_names
>= file
)
5507 /* lh->include_dirs and lh->file_names are 0-based, but the
5508 directory and file name numbers in the statement program
5510 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
5513 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
5516 dwarf2_start_subfile (fe
->name
, dir
);
5519 /* Decode the table. */
5520 while (!end_sequence
)
5522 op_code
= read_1_byte (abfd
, line_ptr
);
5525 if (op_code
>= lh
->opcode_base
)
5526 { /* Special operand. */
5527 adj_opcode
= op_code
- lh
->opcode_base
;
5528 address
+= (adj_opcode
/ lh
->line_range
)
5529 * lh
->minimum_instruction_length
;
5530 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
5531 /* append row to matrix using current values */
5532 record_line (current_subfile
, line
,
5533 check_cu_functions (address
, cu
));
5536 else switch (op_code
)
5538 case DW_LNS_extended_op
:
5539 line_ptr
+= 1; /* ignore length */
5540 extended_op
= read_1_byte (abfd
, line_ptr
);
5542 switch (extended_op
)
5544 case DW_LNE_end_sequence
:
5546 record_line (current_subfile
, 0, address
);
5548 case DW_LNE_set_address
:
5549 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
5550 line_ptr
+= bytes_read
;
5551 address
+= baseaddr
;
5553 case DW_LNE_define_file
:
5556 unsigned int dir_index
, mod_time
, length
;
5558 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
5559 line_ptr
+= bytes_read
;
5561 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5562 line_ptr
+= bytes_read
;
5564 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5565 line_ptr
+= bytes_read
;
5567 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5568 line_ptr
+= bytes_read
;
5569 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
5573 complaint (&symfile_complaints
,
5574 "mangled .debug_line section");
5579 record_line (current_subfile
, line
,
5580 check_cu_functions (address
, cu
));
5583 case DW_LNS_advance_pc
:
5584 address
+= lh
->minimum_instruction_length
5585 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5586 line_ptr
+= bytes_read
;
5588 case DW_LNS_advance_line
:
5589 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
5590 line_ptr
+= bytes_read
;
5592 case DW_LNS_set_file
:
5594 /* lh->include_dirs and lh->file_names are 0-based,
5595 but the directory and file name numbers in the
5596 statement program are 1-based. */
5597 struct file_entry
*fe
;
5599 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5600 line_ptr
+= bytes_read
;
5601 fe
= &lh
->file_names
[file
- 1];
5603 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
5606 dwarf2_start_subfile (fe
->name
, dir
);
5609 case DW_LNS_set_column
:
5610 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5611 line_ptr
+= bytes_read
;
5613 case DW_LNS_negate_stmt
:
5614 is_stmt
= (!is_stmt
);
5616 case DW_LNS_set_basic_block
:
5619 /* Add to the address register of the state machine the
5620 address increment value corresponding to special opcode
5621 255. Ie, this value is scaled by the minimum instruction
5622 length since special opcode 255 would have scaled the
5624 case DW_LNS_const_add_pc
:
5625 address
+= (lh
->minimum_instruction_length
5626 * ((255 - lh
->opcode_base
) / lh
->line_range
));
5628 case DW_LNS_fixed_advance_pc
:
5629 address
+= read_2_bytes (abfd
, line_ptr
);
5633 { /* Unknown standard opcode, ignore it. */
5635 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
5637 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5638 line_ptr
+= bytes_read
;
5646 /* Start a subfile for DWARF. FILENAME is the name of the file and
5647 DIRNAME the name of the source directory which contains FILENAME
5648 or NULL if not known.
5649 This routine tries to keep line numbers from identical absolute and
5650 relative file names in a common subfile.
5652 Using the `list' example from the GDB testsuite, which resides in
5653 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
5654 of /srcdir/list0.c yields the following debugging information for list0.c:
5656 DW_AT_name: /srcdir/list0.c
5657 DW_AT_comp_dir: /compdir
5658 files.files[0].name: list0.h
5659 files.files[0].dir: /srcdir
5660 files.files[1].name: list0.c
5661 files.files[1].dir: /srcdir
5663 The line number information for list0.c has to end up in a single
5664 subfile, so that `break /srcdir/list0.c:1' works as expected. */
5667 dwarf2_start_subfile (char *filename
, char *dirname
)
5669 /* If the filename isn't absolute, try to match an existing subfile
5670 with the full pathname. */
5672 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
5674 struct subfile
*subfile
;
5675 char *fullname
= concat (dirname
, "/", filename
, NULL
);
5677 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
5679 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
5681 current_subfile
= subfile
;
5688 start_subfile (filename
, dirname
);
5692 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
5693 struct dwarf2_cu
*cu
)
5695 struct objfile
*objfile
= cu
->objfile
;
5696 struct comp_unit_head
*cu_header
= &cu
->header
;
5698 /* NOTE drow/2003-01-30: There used to be a comment and some special
5699 code here to turn a symbol with DW_AT_external and a
5700 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
5701 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
5702 with some versions of binutils) where shared libraries could have
5703 relocations against symbols in their debug information - the
5704 minimal symbol would have the right address, but the debug info
5705 would not. It's no longer necessary, because we will explicitly
5706 apply relocations when we read in the debug information now. */
5708 /* A DW_AT_location attribute with no contents indicates that a
5709 variable has been optimized away. */
5710 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
5712 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
5716 /* Handle one degenerate form of location expression specially, to
5717 preserve GDB's previous behavior when section offsets are
5718 specified. If this is just a DW_OP_addr then mark this symbol
5721 if (attr_form_is_block (attr
)
5722 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
5723 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
5727 SYMBOL_VALUE_ADDRESS (sym
) =
5728 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
5729 fixup_symbol_section (sym
, objfile
);
5730 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
5731 SYMBOL_SECTION (sym
));
5732 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5736 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
5737 expression evaluator, and use LOC_COMPUTED only when necessary
5738 (i.e. when the value of a register or memory location is
5739 referenced, or a thread-local block, etc.). Then again, it might
5740 not be worthwhile. I'm assuming that it isn't unless performance
5741 or memory numbers show me otherwise. */
5743 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
5744 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
5747 /* Given a pointer to a DWARF information entry, figure out if we need
5748 to make a symbol table entry for it, and if so, create a new entry
5749 and return a pointer to it.
5750 If TYPE is NULL, determine symbol type from the die, otherwise
5751 used the passed type. */
5753 static struct symbol
*
5754 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
5756 struct objfile
*objfile
= cu
->objfile
;
5757 struct symbol
*sym
= NULL
;
5759 struct attribute
*attr
= NULL
;
5760 struct attribute
*attr2
= NULL
;
5763 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5765 if (die
->tag
!= DW_TAG_namespace
)
5766 name
= dwarf2_linkage_name (die
, cu
);
5768 name
= TYPE_NAME (type
);
5772 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
5773 sizeof (struct symbol
));
5774 OBJSTAT (objfile
, n_syms
++);
5775 memset (sym
, 0, sizeof (struct symbol
));
5777 /* Cache this symbol's name and the name's demangled form (if any). */
5778 SYMBOL_LANGUAGE (sym
) = cu
->language
;
5779 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
5781 /* Default assumptions.
5782 Use the passed type or decode it from the die. */
5783 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5784 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5786 SYMBOL_TYPE (sym
) = type
;
5788 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
5789 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
5792 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
5797 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5800 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
5802 SYMBOL_CLASS (sym
) = LOC_LABEL
;
5804 case DW_TAG_subprogram
:
5805 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
5807 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
5808 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
5809 if (attr2
&& (DW_UNSND (attr2
) != 0))
5811 add_symbol_to_list (sym
, &global_symbols
);
5815 add_symbol_to_list (sym
, cu
->list_in_scope
);
5818 case DW_TAG_variable
:
5819 /* Compilation with minimal debug info may result in variables
5820 with missing type entries. Change the misleading `void' type
5821 to something sensible. */
5822 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
5823 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
5824 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
5825 "<variable, no debug info>",
5827 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
5830 dwarf2_const_value (attr
, sym
, cu
);
5831 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
5832 if (attr2
&& (DW_UNSND (attr2
) != 0))
5833 add_symbol_to_list (sym
, &global_symbols
);
5835 add_symbol_to_list (sym
, cu
->list_in_scope
);
5838 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
5841 var_decode_location (attr
, sym
, cu
);
5842 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
5843 if (attr2
&& (DW_UNSND (attr2
) != 0))
5844 add_symbol_to_list (sym
, &global_symbols
);
5846 add_symbol_to_list (sym
, cu
->list_in_scope
);
5850 /* We do not know the address of this symbol.
5851 If it is an external symbol and we have type information
5852 for it, enter the symbol as a LOC_UNRESOLVED symbol.
5853 The address of the variable will then be determined from
5854 the minimal symbol table whenever the variable is
5856 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
5857 if (attr2
&& (DW_UNSND (attr2
) != 0)
5858 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
5860 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
5861 add_symbol_to_list (sym
, &global_symbols
);
5865 case DW_TAG_formal_parameter
:
5866 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
5869 var_decode_location (attr
, sym
, cu
);
5870 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
5871 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
5872 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
5874 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
5877 dwarf2_const_value (attr
, sym
, cu
);
5879 add_symbol_to_list (sym
, cu
->list_in_scope
);
5881 case DW_TAG_unspecified_parameters
:
5882 /* From varargs functions; gdb doesn't seem to have any
5883 interest in this information, so just ignore it for now.
5886 case DW_TAG_class_type
:
5887 case DW_TAG_structure_type
:
5888 case DW_TAG_union_type
:
5889 case DW_TAG_enumeration_type
:
5890 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5891 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
5893 /* Make sure that the symbol includes appropriate enclosing
5894 classes/namespaces in its name. These are calculated in
5895 read_structure_type, and the correct name is saved in
5898 if (cu
->language
== language_cplus
)
5900 struct type
*type
= SYMBOL_TYPE (sym
);
5902 if (TYPE_TAG_NAME (type
) != NULL
)
5904 /* FIXME: carlton/2003-11-10: Should this use
5905 SYMBOL_SET_NAMES instead? (The same problem also
5906 arises further down in this function.) */
5907 /* The type's name is already allocated along with
5908 this objfile, so we don't need to duplicate it
5910 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
5915 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
5916 really ever be static objects: otherwise, if you try
5917 to, say, break of a class's method and you're in a file
5918 which doesn't mention that class, it won't work unless
5919 the check for all static symbols in lookup_symbol_aux
5920 saves you. See the OtherFileClass tests in
5921 gdb.c++/namespace.exp. */
5923 struct pending
**list_to_add
;
5925 list_to_add
= (cu
->list_in_scope
== &file_symbols
5926 && cu
->language
== language_cplus
5927 ? &global_symbols
: cu
->list_in_scope
);
5929 add_symbol_to_list (sym
, list_to_add
);
5931 /* The semantics of C++ state that "struct foo { ... }" also
5932 defines a typedef for "foo". Synthesize a typedef symbol so
5933 that "ptype foo" works as expected. */
5934 if (cu
->language
== language_cplus
)
5936 struct symbol
*typedef_sym
= (struct symbol
*)
5937 obstack_alloc (&objfile
->objfile_obstack
,
5938 sizeof (struct symbol
));
5939 *typedef_sym
= *sym
;
5940 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
5941 /* The symbol's name is already allocated along with
5942 this objfile, so we don't need to duplicate it for
5944 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
5945 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NATURAL_NAME (sym
);
5946 add_symbol_to_list (typedef_sym
, list_to_add
);
5950 case DW_TAG_typedef
:
5951 if (processing_has_namespace_info
5952 && processing_current_prefix
[0] != '\0')
5954 SYMBOL_LINKAGE_NAME (sym
) = obconcat (&objfile
->objfile_obstack
,
5955 processing_current_prefix
,
5959 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5960 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5961 add_symbol_to_list (sym
, cu
->list_in_scope
);
5963 case DW_TAG_base_type
:
5964 case DW_TAG_subrange_type
:
5965 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5966 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5967 add_symbol_to_list (sym
, cu
->list_in_scope
);
5969 case DW_TAG_enumerator
:
5970 if (processing_has_namespace_info
5971 && processing_current_prefix
[0] != '\0')
5973 SYMBOL_LINKAGE_NAME (sym
) = obconcat (&objfile
->objfile_obstack
,
5974 processing_current_prefix
,
5978 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
5981 dwarf2_const_value (attr
, sym
, cu
);
5984 /* NOTE: carlton/2003-11-10: See comment above in the
5985 DW_TAG_class_type, etc. block. */
5987 struct pending
**list_to_add
;
5989 list_to_add
= (cu
->list_in_scope
== &file_symbols
5990 && cu
->language
== language_cplus
5991 ? &global_symbols
: cu
->list_in_scope
);
5993 add_symbol_to_list (sym
, list_to_add
);
5996 case DW_TAG_namespace
:
5997 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5998 add_symbol_to_list (sym
, &global_symbols
);
6001 /* Not a tag we recognize. Hopefully we aren't processing
6002 trash data, but since we must specifically ignore things
6003 we don't recognize, there is nothing else we should do at
6005 complaint (&symfile_complaints
, "unsupported tag: '%s'",
6006 dwarf_tag_name (die
->tag
));
6013 /* Copy constant value from an attribute to a symbol. */
6016 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
6017 struct dwarf2_cu
*cu
)
6019 struct objfile
*objfile
= cu
->objfile
;
6020 struct comp_unit_head
*cu_header
= &cu
->header
;
6021 struct dwarf_block
*blk
;
6026 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
6027 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
6028 cu_header
->addr_size
,
6029 TYPE_LENGTH (SYMBOL_TYPE
6031 SYMBOL_VALUE_BYTES (sym
) = (char *)
6032 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
6033 /* NOTE: cagney/2003-05-09: In-lined store_address call with
6034 it's body - store_unsigned_integer. */
6035 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
6037 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
6039 case DW_FORM_block1
:
6040 case DW_FORM_block2
:
6041 case DW_FORM_block4
:
6043 blk
= DW_BLOCK (attr
);
6044 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
6045 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
6047 TYPE_LENGTH (SYMBOL_TYPE
6049 SYMBOL_VALUE_BYTES (sym
) = (char *)
6050 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
6051 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
6052 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
6055 /* The DW_AT_const_value attributes are supposed to carry the
6056 symbol's value "represented as it would be on the target
6057 architecture." By the time we get here, it's already been
6058 converted to host endianness, so we just need to sign- or
6059 zero-extend it as appropriate. */
6061 dwarf2_const_value_data (attr
, sym
, 8);
6064 dwarf2_const_value_data (attr
, sym
, 16);
6067 dwarf2_const_value_data (attr
, sym
, 32);
6070 dwarf2_const_value_data (attr
, sym
, 64);
6074 SYMBOL_VALUE (sym
) = DW_SND (attr
);
6075 SYMBOL_CLASS (sym
) = LOC_CONST
;
6079 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
6080 SYMBOL_CLASS (sym
) = LOC_CONST
;
6084 complaint (&symfile_complaints
,
6085 "unsupported const value attribute form: '%s'",
6086 dwarf_form_name (attr
->form
));
6087 SYMBOL_VALUE (sym
) = 0;
6088 SYMBOL_CLASS (sym
) = LOC_CONST
;
6094 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
6095 or zero-extend it as appropriate for the symbol's type. */
6097 dwarf2_const_value_data (struct attribute
*attr
,
6101 LONGEST l
= DW_UNSND (attr
);
6103 if (bits
< sizeof (l
) * 8)
6105 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
6106 l
&= ((LONGEST
) 1 << bits
) - 1;
6108 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
6111 SYMBOL_VALUE (sym
) = l
;
6112 SYMBOL_CLASS (sym
) = LOC_CONST
;
6116 /* Return the type of the die in question using its DW_AT_type attribute. */
6118 static struct type
*
6119 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6122 struct attribute
*type_attr
;
6123 struct die_info
*type_die
;
6126 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
6129 /* A missing DW_AT_type represents a void type. */
6130 return dwarf2_fundamental_type (cu
->objfile
, FT_VOID
, cu
);
6134 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
6135 type_die
= follow_die_ref (ref
);
6138 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
6139 ref
, cu
->objfile
->name
);
6143 type
= tag_type_to_type (type_die
, cu
);
6146 dump_die (type_die
);
6147 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
6153 /* Return the containing type of the die in question using its
6154 DW_AT_containing_type attribute. */
6156 static struct type
*
6157 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6159 struct type
*type
= NULL
;
6160 struct attribute
*type_attr
;
6161 struct die_info
*type_die
= NULL
;
6164 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
6167 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
6168 type_die
= follow_die_ref (ref
);
6171 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref
,
6175 type
= tag_type_to_type (type_die
, cu
);
6180 dump_die (type_die
);
6181 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
6188 static struct type
*
6189 type_at_offset (unsigned int offset
, struct dwarf2_cu
*cu
)
6191 struct die_info
*die
;
6194 die
= follow_die_ref (offset
);
6197 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
6200 type
= tag_type_to_type (die
, cu
);
6205 static struct type
*
6206 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6214 read_type_die (die
, cu
);
6218 error ("Dwarf Error: Cannot find type of die [in module %s]",
6226 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
6228 char *prefix
= determine_prefix (die
, cu
);
6229 const char *old_prefix
= processing_current_prefix
;
6230 struct cleanup
*back_to
= make_cleanup (xfree
, prefix
);
6231 processing_current_prefix
= prefix
;
6235 case DW_TAG_class_type
:
6236 case DW_TAG_structure_type
:
6237 case DW_TAG_union_type
:
6238 read_structure_type (die
, cu
);
6240 case DW_TAG_enumeration_type
:
6241 read_enumeration_type (die
, cu
);
6243 case DW_TAG_subprogram
:
6244 case DW_TAG_subroutine_type
:
6245 read_subroutine_type (die
, cu
);
6247 case DW_TAG_array_type
:
6248 read_array_type (die
, cu
);
6250 case DW_TAG_pointer_type
:
6251 read_tag_pointer_type (die
, cu
);
6253 case DW_TAG_ptr_to_member_type
:
6254 read_tag_ptr_to_member_type (die
, cu
);
6256 case DW_TAG_reference_type
:
6257 read_tag_reference_type (die
, cu
);
6259 case DW_TAG_const_type
:
6260 read_tag_const_type (die
, cu
);
6262 case DW_TAG_volatile_type
:
6263 read_tag_volatile_type (die
, cu
);
6265 case DW_TAG_string_type
:
6266 read_tag_string_type (die
, cu
);
6268 case DW_TAG_typedef
:
6269 read_typedef (die
, cu
);
6271 case DW_TAG_subrange_type
:
6272 read_subrange_type (die
, cu
);
6274 case DW_TAG_base_type
:
6275 read_base_type (die
, cu
);
6278 complaint (&symfile_complaints
, "unexepected tag in read_type_die: '%s'",
6279 dwarf_tag_name (die
->tag
));
6283 processing_current_prefix
= old_prefix
;
6284 do_cleanups (back_to
);
6287 /* Return the name of the namespace/class that DIE is defined within,
6288 or "" if we can't tell. The caller should xfree the result. */
6290 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
6291 therein) for an example of how to use this function to deal with
6292 DW_AT_specification. */
6295 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
6297 struct die_info
*parent
;
6299 if (cu
->language
!= language_cplus
)
6302 parent
= die
->parent
;
6306 return xstrdup ("");
6310 switch (parent
->tag
) {
6311 case DW_TAG_namespace
:
6313 /* FIXME: carlton/2004-03-05: Should I follow extension dies
6314 before doing this check? */
6315 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
6317 return xstrdup (TYPE_TAG_NAME (parent
->type
));
6322 char *parent_prefix
= determine_prefix (parent
, cu
);
6323 char *retval
= typename_concat (parent_prefix
,
6324 namespace_name (parent
, &dummy
,
6326 xfree (parent_prefix
);
6331 case DW_TAG_class_type
:
6332 case DW_TAG_structure_type
:
6334 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
6336 return xstrdup (TYPE_TAG_NAME (parent
->type
));
6340 const char *old_prefix
= processing_current_prefix
;
6341 char *new_prefix
= determine_prefix (parent
, cu
);
6344 processing_current_prefix
= new_prefix
;
6345 retval
= determine_class_name (parent
, cu
);
6346 processing_current_prefix
= old_prefix
;
6353 return determine_prefix (parent
, cu
);
6358 /* Return a newly-allocated string formed by concatenating PREFIX,
6359 "::", and SUFFIX, except that if PREFIX is NULL or the empty
6360 string, just return a copy of SUFFIX. */
6363 typename_concat (const char *prefix
, const char *suffix
)
6365 if (prefix
== NULL
|| prefix
[0] == '\0')
6366 return xstrdup (suffix
);
6369 char *retval
= xmalloc (strlen (prefix
) + 2 + strlen (suffix
) + 1);
6371 strcpy (retval
, prefix
);
6372 strcat (retval
, "::");
6373 strcat (retval
, suffix
);
6379 static struct type
*
6380 dwarf_base_type (int encoding
, int size
, struct dwarf2_cu
*cu
)
6382 struct objfile
*objfile
= cu
->objfile
;
6384 /* FIXME - this should not produce a new (struct type *)
6385 every time. It should cache base types. */
6389 case DW_ATE_address
:
6390 type
= dwarf2_fundamental_type (objfile
, FT_VOID
, cu
);
6392 case DW_ATE_boolean
:
6393 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
, cu
);
6395 case DW_ATE_complex_float
:
6398 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
, cu
);
6402 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
, cu
);
6408 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
6412 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
6419 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
6422 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
, cu
);
6426 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
6430 case DW_ATE_signed_char
:
6431 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
6433 case DW_ATE_unsigned
:
6437 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
6440 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
, cu
);
6444 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
, cu
);
6448 case DW_ATE_unsigned_char
:
6449 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
6452 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
6459 copy_die (struct die_info
*old_die
)
6461 struct die_info
*new_die
;
6464 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6465 memset (new_die
, 0, sizeof (struct die_info
));
6467 new_die
->tag
= old_die
->tag
;
6468 new_die
->has_children
= old_die
->has_children
;
6469 new_die
->abbrev
= old_die
->abbrev
;
6470 new_die
->offset
= old_die
->offset
;
6471 new_die
->type
= NULL
;
6473 num_attrs
= old_die
->num_attrs
;
6474 new_die
->num_attrs
= num_attrs
;
6475 new_die
->attrs
= (struct attribute
*)
6476 xmalloc (num_attrs
* sizeof (struct attribute
));
6478 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
6480 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
6481 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
6482 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
6485 new_die
->next
= NULL
;
6490 /* Return sibling of die, NULL if no sibling. */
6492 static struct die_info
*
6493 sibling_die (struct die_info
*die
)
6495 return die
->sibling
;
6498 /* Get linkage name of a die, return NULL if not found. */
6501 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6503 struct attribute
*attr
;
6505 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6506 if (attr
&& DW_STRING (attr
))
6507 return DW_STRING (attr
);
6508 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6509 if (attr
&& DW_STRING (attr
))
6510 return DW_STRING (attr
);
6514 /* Get name of a die, return NULL if not found. */
6517 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6519 struct attribute
*attr
;
6521 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6522 if (attr
&& DW_STRING (attr
))
6523 return DW_STRING (attr
);
6527 /* Return the die that this die in an extension of, or NULL if there
6530 static struct die_info
*
6531 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
*cu
)
6533 struct attribute
*attr
;
6534 struct die_info
*extension_die
;
6537 attr
= dwarf2_attr (die
, DW_AT_extension
, cu
);
6541 ref
= dwarf2_get_ref_die_offset (attr
, cu
);
6542 extension_die
= follow_die_ref (ref
);
6545 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
6548 return extension_die
;
6551 /* Convert a DIE tag into its string name. */
6554 dwarf_tag_name (unsigned tag
)
6558 case DW_TAG_padding
:
6559 return "DW_TAG_padding";
6560 case DW_TAG_array_type
:
6561 return "DW_TAG_array_type";
6562 case DW_TAG_class_type
:
6563 return "DW_TAG_class_type";
6564 case DW_TAG_entry_point
:
6565 return "DW_TAG_entry_point";
6566 case DW_TAG_enumeration_type
:
6567 return "DW_TAG_enumeration_type";
6568 case DW_TAG_formal_parameter
:
6569 return "DW_TAG_formal_parameter";
6570 case DW_TAG_imported_declaration
:
6571 return "DW_TAG_imported_declaration";
6573 return "DW_TAG_label";
6574 case DW_TAG_lexical_block
:
6575 return "DW_TAG_lexical_block";
6577 return "DW_TAG_member";
6578 case DW_TAG_pointer_type
:
6579 return "DW_TAG_pointer_type";
6580 case DW_TAG_reference_type
:
6581 return "DW_TAG_reference_type";
6582 case DW_TAG_compile_unit
:
6583 return "DW_TAG_compile_unit";
6584 case DW_TAG_string_type
:
6585 return "DW_TAG_string_type";
6586 case DW_TAG_structure_type
:
6587 return "DW_TAG_structure_type";
6588 case DW_TAG_subroutine_type
:
6589 return "DW_TAG_subroutine_type";
6590 case DW_TAG_typedef
:
6591 return "DW_TAG_typedef";
6592 case DW_TAG_union_type
:
6593 return "DW_TAG_union_type";
6594 case DW_TAG_unspecified_parameters
:
6595 return "DW_TAG_unspecified_parameters";
6596 case DW_TAG_variant
:
6597 return "DW_TAG_variant";
6598 case DW_TAG_common_block
:
6599 return "DW_TAG_common_block";
6600 case DW_TAG_common_inclusion
:
6601 return "DW_TAG_common_inclusion";
6602 case DW_TAG_inheritance
:
6603 return "DW_TAG_inheritance";
6604 case DW_TAG_inlined_subroutine
:
6605 return "DW_TAG_inlined_subroutine";
6607 return "DW_TAG_module";
6608 case DW_TAG_ptr_to_member_type
:
6609 return "DW_TAG_ptr_to_member_type";
6610 case DW_TAG_set_type
:
6611 return "DW_TAG_set_type";
6612 case DW_TAG_subrange_type
:
6613 return "DW_TAG_subrange_type";
6614 case DW_TAG_with_stmt
:
6615 return "DW_TAG_with_stmt";
6616 case DW_TAG_access_declaration
:
6617 return "DW_TAG_access_declaration";
6618 case DW_TAG_base_type
:
6619 return "DW_TAG_base_type";
6620 case DW_TAG_catch_block
:
6621 return "DW_TAG_catch_block";
6622 case DW_TAG_const_type
:
6623 return "DW_TAG_const_type";
6624 case DW_TAG_constant
:
6625 return "DW_TAG_constant";
6626 case DW_TAG_enumerator
:
6627 return "DW_TAG_enumerator";
6628 case DW_TAG_file_type
:
6629 return "DW_TAG_file_type";
6631 return "DW_TAG_friend";
6632 case DW_TAG_namelist
:
6633 return "DW_TAG_namelist";
6634 case DW_TAG_namelist_item
:
6635 return "DW_TAG_namelist_item";
6636 case DW_TAG_packed_type
:
6637 return "DW_TAG_packed_type";
6638 case DW_TAG_subprogram
:
6639 return "DW_TAG_subprogram";
6640 case DW_TAG_template_type_param
:
6641 return "DW_TAG_template_type_param";
6642 case DW_TAG_template_value_param
:
6643 return "DW_TAG_template_value_param";
6644 case DW_TAG_thrown_type
:
6645 return "DW_TAG_thrown_type";
6646 case DW_TAG_try_block
:
6647 return "DW_TAG_try_block";
6648 case DW_TAG_variant_part
:
6649 return "DW_TAG_variant_part";
6650 case DW_TAG_variable
:
6651 return "DW_TAG_variable";
6652 case DW_TAG_volatile_type
:
6653 return "DW_TAG_volatile_type";
6654 case DW_TAG_dwarf_procedure
:
6655 return "DW_TAG_dwarf_procedure";
6656 case DW_TAG_restrict_type
:
6657 return "DW_TAG_restrict_type";
6658 case DW_TAG_interface_type
:
6659 return "DW_TAG_interface_type";
6660 case DW_TAG_namespace
:
6661 return "DW_TAG_namespace";
6662 case DW_TAG_imported_module
:
6663 return "DW_TAG_imported_module";
6664 case DW_TAG_unspecified_type
:
6665 return "DW_TAG_unspecified_type";
6666 case DW_TAG_partial_unit
:
6667 return "DW_TAG_partial_unit";
6668 case DW_TAG_imported_unit
:
6669 return "DW_TAG_imported_unit";
6670 case DW_TAG_MIPS_loop
:
6671 return "DW_TAG_MIPS_loop";
6672 case DW_TAG_format_label
:
6673 return "DW_TAG_format_label";
6674 case DW_TAG_function_template
:
6675 return "DW_TAG_function_template";
6676 case DW_TAG_class_template
:
6677 return "DW_TAG_class_template";
6679 return "DW_TAG_<unknown>";
6683 /* Convert a DWARF attribute code into its string name. */
6686 dwarf_attr_name (unsigned attr
)
6691 return "DW_AT_sibling";
6692 case DW_AT_location
:
6693 return "DW_AT_location";
6695 return "DW_AT_name";
6696 case DW_AT_ordering
:
6697 return "DW_AT_ordering";
6698 case DW_AT_subscr_data
:
6699 return "DW_AT_subscr_data";
6700 case DW_AT_byte_size
:
6701 return "DW_AT_byte_size";
6702 case DW_AT_bit_offset
:
6703 return "DW_AT_bit_offset";
6704 case DW_AT_bit_size
:
6705 return "DW_AT_bit_size";
6706 case DW_AT_element_list
:
6707 return "DW_AT_element_list";
6708 case DW_AT_stmt_list
:
6709 return "DW_AT_stmt_list";
6711 return "DW_AT_low_pc";
6713 return "DW_AT_high_pc";
6714 case DW_AT_language
:
6715 return "DW_AT_language";
6717 return "DW_AT_member";
6719 return "DW_AT_discr";
6720 case DW_AT_discr_value
:
6721 return "DW_AT_discr_value";
6722 case DW_AT_visibility
:
6723 return "DW_AT_visibility";
6725 return "DW_AT_import";
6726 case DW_AT_string_length
:
6727 return "DW_AT_string_length";
6728 case DW_AT_common_reference
:
6729 return "DW_AT_common_reference";
6730 case DW_AT_comp_dir
:
6731 return "DW_AT_comp_dir";
6732 case DW_AT_const_value
:
6733 return "DW_AT_const_value";
6734 case DW_AT_containing_type
:
6735 return "DW_AT_containing_type";
6736 case DW_AT_default_value
:
6737 return "DW_AT_default_value";
6739 return "DW_AT_inline";
6740 case DW_AT_is_optional
:
6741 return "DW_AT_is_optional";
6742 case DW_AT_lower_bound
:
6743 return "DW_AT_lower_bound";
6744 case DW_AT_producer
:
6745 return "DW_AT_producer";
6746 case DW_AT_prototyped
:
6747 return "DW_AT_prototyped";
6748 case DW_AT_return_addr
:
6749 return "DW_AT_return_addr";
6750 case DW_AT_start_scope
:
6751 return "DW_AT_start_scope";
6752 case DW_AT_stride_size
:
6753 return "DW_AT_stride_size";
6754 case DW_AT_upper_bound
:
6755 return "DW_AT_upper_bound";
6756 case DW_AT_abstract_origin
:
6757 return "DW_AT_abstract_origin";
6758 case DW_AT_accessibility
:
6759 return "DW_AT_accessibility";
6760 case DW_AT_address_class
:
6761 return "DW_AT_address_class";
6762 case DW_AT_artificial
:
6763 return "DW_AT_artificial";
6764 case DW_AT_base_types
:
6765 return "DW_AT_base_types";
6766 case DW_AT_calling_convention
:
6767 return "DW_AT_calling_convention";
6769 return "DW_AT_count";
6770 case DW_AT_data_member_location
:
6771 return "DW_AT_data_member_location";
6772 case DW_AT_decl_column
:
6773 return "DW_AT_decl_column";
6774 case DW_AT_decl_file
:
6775 return "DW_AT_decl_file";
6776 case DW_AT_decl_line
:
6777 return "DW_AT_decl_line";
6778 case DW_AT_declaration
:
6779 return "DW_AT_declaration";
6780 case DW_AT_discr_list
:
6781 return "DW_AT_discr_list";
6782 case DW_AT_encoding
:
6783 return "DW_AT_encoding";
6784 case DW_AT_external
:
6785 return "DW_AT_external";
6786 case DW_AT_frame_base
:
6787 return "DW_AT_frame_base";
6789 return "DW_AT_friend";
6790 case DW_AT_identifier_case
:
6791 return "DW_AT_identifier_case";
6792 case DW_AT_macro_info
:
6793 return "DW_AT_macro_info";
6794 case DW_AT_namelist_items
:
6795 return "DW_AT_namelist_items";
6796 case DW_AT_priority
:
6797 return "DW_AT_priority";
6799 return "DW_AT_segment";
6800 case DW_AT_specification
:
6801 return "DW_AT_specification";
6802 case DW_AT_static_link
:
6803 return "DW_AT_static_link";
6805 return "DW_AT_type";
6806 case DW_AT_use_location
:
6807 return "DW_AT_use_location";
6808 case DW_AT_variable_parameter
:
6809 return "DW_AT_variable_parameter";
6810 case DW_AT_virtuality
:
6811 return "DW_AT_virtuality";
6812 case DW_AT_vtable_elem_location
:
6813 return "DW_AT_vtable_elem_location";
6814 case DW_AT_allocated
:
6815 return "DW_AT_allocated";
6816 case DW_AT_associated
:
6817 return "DW_AT_associated";
6818 case DW_AT_data_location
:
6819 return "DW_AT_data_location";
6821 return "DW_AT_stride";
6822 case DW_AT_entry_pc
:
6823 return "DW_AT_entry_pc";
6824 case DW_AT_use_UTF8
:
6825 return "DW_AT_use_UTF8";
6826 case DW_AT_extension
:
6827 return "DW_AT_extension";
6829 return "DW_AT_ranges";
6830 case DW_AT_trampoline
:
6831 return "DW_AT_trampoline";
6832 case DW_AT_call_column
:
6833 return "DW_AT_call_column";
6834 case DW_AT_call_file
:
6835 return "DW_AT_call_file";
6836 case DW_AT_call_line
:
6837 return "DW_AT_call_line";
6839 case DW_AT_MIPS_fde
:
6840 return "DW_AT_MIPS_fde";
6841 case DW_AT_MIPS_loop_begin
:
6842 return "DW_AT_MIPS_loop_begin";
6843 case DW_AT_MIPS_tail_loop_begin
:
6844 return "DW_AT_MIPS_tail_loop_begin";
6845 case DW_AT_MIPS_epilog_begin
:
6846 return "DW_AT_MIPS_epilog_begin";
6847 case DW_AT_MIPS_loop_unroll_factor
:
6848 return "DW_AT_MIPS_loop_unroll_factor";
6849 case DW_AT_MIPS_software_pipeline_depth
:
6850 return "DW_AT_MIPS_software_pipeline_depth";
6852 case DW_AT_MIPS_linkage_name
:
6853 return "DW_AT_MIPS_linkage_name";
6855 case DW_AT_sf_names
:
6856 return "DW_AT_sf_names";
6857 case DW_AT_src_info
:
6858 return "DW_AT_src_info";
6859 case DW_AT_mac_info
:
6860 return "DW_AT_mac_info";
6861 case DW_AT_src_coords
:
6862 return "DW_AT_src_coords";
6863 case DW_AT_body_begin
:
6864 return "DW_AT_body_begin";
6865 case DW_AT_body_end
:
6866 return "DW_AT_body_end";
6867 case DW_AT_GNU_vector
:
6868 return "DW_AT_GNU_vector";
6870 return "DW_AT_<unknown>";
6874 /* Convert a DWARF value form code into its string name. */
6877 dwarf_form_name (unsigned form
)
6882 return "DW_FORM_addr";
6883 case DW_FORM_block2
:
6884 return "DW_FORM_block2";
6885 case DW_FORM_block4
:
6886 return "DW_FORM_block4";
6888 return "DW_FORM_data2";
6890 return "DW_FORM_data4";
6892 return "DW_FORM_data8";
6893 case DW_FORM_string
:
6894 return "DW_FORM_string";
6896 return "DW_FORM_block";
6897 case DW_FORM_block1
:
6898 return "DW_FORM_block1";
6900 return "DW_FORM_data1";
6902 return "DW_FORM_flag";
6904 return "DW_FORM_sdata";
6906 return "DW_FORM_strp";
6908 return "DW_FORM_udata";
6909 case DW_FORM_ref_addr
:
6910 return "DW_FORM_ref_addr";
6912 return "DW_FORM_ref1";
6914 return "DW_FORM_ref2";
6916 return "DW_FORM_ref4";
6918 return "DW_FORM_ref8";
6919 case DW_FORM_ref_udata
:
6920 return "DW_FORM_ref_udata";
6921 case DW_FORM_indirect
:
6922 return "DW_FORM_indirect";
6924 return "DW_FORM_<unknown>";
6928 /* Convert a DWARF stack opcode into its string name. */
6931 dwarf_stack_op_name (unsigned op
)
6936 return "DW_OP_addr";
6938 return "DW_OP_deref";
6940 return "DW_OP_const1u";
6942 return "DW_OP_const1s";
6944 return "DW_OP_const2u";
6946 return "DW_OP_const2s";
6948 return "DW_OP_const4u";
6950 return "DW_OP_const4s";
6952 return "DW_OP_const8u";
6954 return "DW_OP_const8s";
6956 return "DW_OP_constu";
6958 return "DW_OP_consts";
6962 return "DW_OP_drop";
6964 return "DW_OP_over";
6966 return "DW_OP_pick";
6968 return "DW_OP_swap";
6972 return "DW_OP_xderef";
6980 return "DW_OP_minus";
6992 return "DW_OP_plus";
6993 case DW_OP_plus_uconst
:
6994 return "DW_OP_plus_uconst";
7000 return "DW_OP_shra";
7018 return "DW_OP_skip";
7020 return "DW_OP_lit0";
7022 return "DW_OP_lit1";
7024 return "DW_OP_lit2";
7026 return "DW_OP_lit3";
7028 return "DW_OP_lit4";
7030 return "DW_OP_lit5";
7032 return "DW_OP_lit6";
7034 return "DW_OP_lit7";
7036 return "DW_OP_lit8";
7038 return "DW_OP_lit9";
7040 return "DW_OP_lit10";
7042 return "DW_OP_lit11";
7044 return "DW_OP_lit12";
7046 return "DW_OP_lit13";
7048 return "DW_OP_lit14";
7050 return "DW_OP_lit15";
7052 return "DW_OP_lit16";
7054 return "DW_OP_lit17";
7056 return "DW_OP_lit18";
7058 return "DW_OP_lit19";
7060 return "DW_OP_lit20";
7062 return "DW_OP_lit21";
7064 return "DW_OP_lit22";
7066 return "DW_OP_lit23";
7068 return "DW_OP_lit24";
7070 return "DW_OP_lit25";
7072 return "DW_OP_lit26";
7074 return "DW_OP_lit27";
7076 return "DW_OP_lit28";
7078 return "DW_OP_lit29";
7080 return "DW_OP_lit30";
7082 return "DW_OP_lit31";
7084 return "DW_OP_reg0";
7086 return "DW_OP_reg1";
7088 return "DW_OP_reg2";
7090 return "DW_OP_reg3";
7092 return "DW_OP_reg4";
7094 return "DW_OP_reg5";
7096 return "DW_OP_reg6";
7098 return "DW_OP_reg7";
7100 return "DW_OP_reg8";
7102 return "DW_OP_reg9";
7104 return "DW_OP_reg10";
7106 return "DW_OP_reg11";
7108 return "DW_OP_reg12";
7110 return "DW_OP_reg13";
7112 return "DW_OP_reg14";
7114 return "DW_OP_reg15";
7116 return "DW_OP_reg16";
7118 return "DW_OP_reg17";
7120 return "DW_OP_reg18";
7122 return "DW_OP_reg19";
7124 return "DW_OP_reg20";
7126 return "DW_OP_reg21";
7128 return "DW_OP_reg22";
7130 return "DW_OP_reg23";
7132 return "DW_OP_reg24";
7134 return "DW_OP_reg25";
7136 return "DW_OP_reg26";
7138 return "DW_OP_reg27";
7140 return "DW_OP_reg28";
7142 return "DW_OP_reg29";
7144 return "DW_OP_reg30";
7146 return "DW_OP_reg31";
7148 return "DW_OP_breg0";
7150 return "DW_OP_breg1";
7152 return "DW_OP_breg2";
7154 return "DW_OP_breg3";
7156 return "DW_OP_breg4";
7158 return "DW_OP_breg5";
7160 return "DW_OP_breg6";
7162 return "DW_OP_breg7";
7164 return "DW_OP_breg8";
7166 return "DW_OP_breg9";
7168 return "DW_OP_breg10";
7170 return "DW_OP_breg11";
7172 return "DW_OP_breg12";
7174 return "DW_OP_breg13";
7176 return "DW_OP_breg14";
7178 return "DW_OP_breg15";
7180 return "DW_OP_breg16";
7182 return "DW_OP_breg17";
7184 return "DW_OP_breg18";
7186 return "DW_OP_breg19";
7188 return "DW_OP_breg20";
7190 return "DW_OP_breg21";
7192 return "DW_OP_breg22";
7194 return "DW_OP_breg23";
7196 return "DW_OP_breg24";
7198 return "DW_OP_breg25";
7200 return "DW_OP_breg26";
7202 return "DW_OP_breg27";
7204 return "DW_OP_breg28";
7206 return "DW_OP_breg29";
7208 return "DW_OP_breg30";
7210 return "DW_OP_breg31";
7212 return "DW_OP_regx";
7214 return "DW_OP_fbreg";
7216 return "DW_OP_bregx";
7218 return "DW_OP_piece";
7219 case DW_OP_deref_size
:
7220 return "DW_OP_deref_size";
7221 case DW_OP_xderef_size
:
7222 return "DW_OP_xderef_size";
7225 /* DWARF 3 extensions. */
7226 case DW_OP_push_object_address
:
7227 return "DW_OP_push_object_address";
7229 return "DW_OP_call2";
7231 return "DW_OP_call4";
7232 case DW_OP_call_ref
:
7233 return "DW_OP_call_ref";
7234 /* GNU extensions. */
7235 case DW_OP_GNU_push_tls_address
:
7236 return "DW_OP_GNU_push_tls_address";
7238 return "OP_<unknown>";
7243 dwarf_bool_name (unsigned mybool
)
7251 /* Convert a DWARF type code into its string name. */
7254 dwarf_type_encoding_name (unsigned enc
)
7258 case DW_ATE_address
:
7259 return "DW_ATE_address";
7260 case DW_ATE_boolean
:
7261 return "DW_ATE_boolean";
7262 case DW_ATE_complex_float
:
7263 return "DW_ATE_complex_float";
7265 return "DW_ATE_float";
7267 return "DW_ATE_signed";
7268 case DW_ATE_signed_char
:
7269 return "DW_ATE_signed_char";
7270 case DW_ATE_unsigned
:
7271 return "DW_ATE_unsigned";
7272 case DW_ATE_unsigned_char
:
7273 return "DW_ATE_unsigned_char";
7274 case DW_ATE_imaginary_float
:
7275 return "DW_ATE_imaginary_float";
7277 return "DW_ATE_<unknown>";
7281 /* Convert a DWARF call frame info operation to its string name. */
7285 dwarf_cfi_name (unsigned cfi_opc
)
7289 case DW_CFA_advance_loc
:
7290 return "DW_CFA_advance_loc";
7292 return "DW_CFA_offset";
7293 case DW_CFA_restore
:
7294 return "DW_CFA_restore";
7296 return "DW_CFA_nop";
7297 case DW_CFA_set_loc
:
7298 return "DW_CFA_set_loc";
7299 case DW_CFA_advance_loc1
:
7300 return "DW_CFA_advance_loc1";
7301 case DW_CFA_advance_loc2
:
7302 return "DW_CFA_advance_loc2";
7303 case DW_CFA_advance_loc4
:
7304 return "DW_CFA_advance_loc4";
7305 case DW_CFA_offset_extended
:
7306 return "DW_CFA_offset_extended";
7307 case DW_CFA_restore_extended
:
7308 return "DW_CFA_restore_extended";
7309 case DW_CFA_undefined
:
7310 return "DW_CFA_undefined";
7311 case DW_CFA_same_value
:
7312 return "DW_CFA_same_value";
7313 case DW_CFA_register
:
7314 return "DW_CFA_register";
7315 case DW_CFA_remember_state
:
7316 return "DW_CFA_remember_state";
7317 case DW_CFA_restore_state
:
7318 return "DW_CFA_restore_state";
7319 case DW_CFA_def_cfa
:
7320 return "DW_CFA_def_cfa";
7321 case DW_CFA_def_cfa_register
:
7322 return "DW_CFA_def_cfa_register";
7323 case DW_CFA_def_cfa_offset
:
7324 return "DW_CFA_def_cfa_offset";
7327 case DW_CFA_def_cfa_expression
:
7328 return "DW_CFA_def_cfa_expression";
7329 case DW_CFA_expression
:
7330 return "DW_CFA_expression";
7331 case DW_CFA_offset_extended_sf
:
7332 return "DW_CFA_offset_extended_sf";
7333 case DW_CFA_def_cfa_sf
:
7334 return "DW_CFA_def_cfa_sf";
7335 case DW_CFA_def_cfa_offset_sf
:
7336 return "DW_CFA_def_cfa_offset_sf";
7338 /* SGI/MIPS specific */
7339 case DW_CFA_MIPS_advance_loc8
:
7340 return "DW_CFA_MIPS_advance_loc8";
7342 /* GNU extensions */
7343 case DW_CFA_GNU_window_save
:
7344 return "DW_CFA_GNU_window_save";
7345 case DW_CFA_GNU_args_size
:
7346 return "DW_CFA_GNU_args_size";
7347 case DW_CFA_GNU_negative_offset_extended
:
7348 return "DW_CFA_GNU_negative_offset_extended";
7351 return "DW_CFA_<unknown>";
7357 dump_die (struct die_info
*die
)
7361 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
7362 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
7363 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
7364 dwarf_bool_name (die
->child
!= NULL
));
7366 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
7367 for (i
= 0; i
< die
->num_attrs
; ++i
)
7369 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
7370 dwarf_attr_name (die
->attrs
[i
].name
),
7371 dwarf_form_name (die
->attrs
[i
].form
));
7372 switch (die
->attrs
[i
].form
)
7374 case DW_FORM_ref_addr
:
7376 fprintf_unfiltered (gdb_stderr
, "address: ");
7377 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
7379 case DW_FORM_block2
:
7380 case DW_FORM_block4
:
7382 case DW_FORM_block1
:
7383 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
7394 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
7396 case DW_FORM_string
:
7398 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
7399 DW_STRING (&die
->attrs
[i
])
7400 ? DW_STRING (&die
->attrs
[i
]) : "");
7403 if (DW_UNSND (&die
->attrs
[i
]))
7404 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
7406 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
7408 case DW_FORM_indirect
:
7409 /* the reader will have reduced the indirect form to
7410 the "base form" so this form should not occur */
7411 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
7414 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
7415 die
->attrs
[i
].form
);
7417 fprintf_unfiltered (gdb_stderr
, "\n");
7422 dump_die_list (struct die_info
*die
)
7427 if (die
->child
!= NULL
)
7428 dump_die_list (die
->child
);
7429 if (die
->sibling
!= NULL
)
7430 dump_die_list (die
->sibling
);
7435 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
7438 struct die_info
*old
;
7440 h
= (offset
% REF_HASH_SIZE
);
7441 old
= die_ref_table
[h
];
7442 die
->next_ref
= old
;
7443 die_ref_table
[h
] = die
;
7448 dwarf2_empty_hash_tables (void)
7450 memset (die_ref_table
, 0, sizeof (die_ref_table
));
7454 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
7456 unsigned int result
= 0;
7460 case DW_FORM_ref_addr
:
7461 result
= DW_ADDR (attr
);
7467 case DW_FORM_ref_udata
:
7468 result
= cu
->header
.offset
+ DW_UNSND (attr
);
7471 complaint (&symfile_complaints
,
7472 "unsupported die ref attribute form: '%s'",
7473 dwarf_form_name (attr
->form
));
7478 /* Return the constant value held by the given attribute. Return -1
7479 if the value held by the attribute is not constant. */
7482 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
7484 if (attr
->form
== DW_FORM_sdata
)
7485 return DW_SND (attr
);
7486 else if (attr
->form
== DW_FORM_udata
7487 || attr
->form
== DW_FORM_data1
7488 || attr
->form
== DW_FORM_data2
7489 || attr
->form
== DW_FORM_data4
7490 || attr
->form
== DW_FORM_data8
)
7491 return DW_UNSND (attr
);
7494 complaint (&symfile_complaints
, "Attribute value is not a constant (%s)",
7495 dwarf_form_name (attr
->form
));
7496 return default_value
;
7500 static struct die_info
*
7501 follow_die_ref (unsigned int offset
)
7503 struct die_info
*die
;
7506 h
= (offset
% REF_HASH_SIZE
);
7507 die
= die_ref_table
[h
];
7510 if (die
->offset
== offset
)
7514 die
= die
->next_ref
;
7519 static struct type
*
7520 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid,
7521 struct dwarf2_cu
*cu
)
7523 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
7525 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
7526 typeid, objfile
->name
);
7529 /* Look for this particular type in the fundamental type vector. If
7530 one is not found, create and install one appropriate for the
7531 current language and the current target machine. */
7533 if (cu
->ftypes
[typeid] == NULL
)
7535 cu
->ftypes
[typeid] = cu
->language_defn
->la_fund_type (objfile
, typeid);
7538 return (cu
->ftypes
[typeid]);
7541 /* Decode simple location descriptions.
7542 Given a pointer to a dwarf block that defines a location, compute
7543 the location and return the value.
7545 NOTE drow/2003-11-18: This function is called in two situations
7546 now: for the address of static or global variables (partial symbols
7547 only) and for offsets into structures which are expected to be
7548 (more or less) constant. The partial symbol case should go away,
7549 and only the constant case should remain. That will let this
7550 function complain more accurately. A few special modes are allowed
7551 without complaint for global variables (for instance, global
7552 register values and thread-local values).
7554 A location description containing no operations indicates that the
7555 object is optimized out. The return value is 0 for that case.
7556 FIXME drow/2003-11-16: No callers check for this case any more; soon all
7557 callers will only want a very basic result and this can become a
7560 When the result is a register number, the global isreg flag is set,
7561 otherwise it is cleared.
7563 Note that stack[0] is unused except as a default error return.
7564 Note that stack overflow is not yet handled. */
7567 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
7569 struct objfile
*objfile
= cu
->objfile
;
7570 struct comp_unit_head
*cu_header
= &cu
->header
;
7572 int size
= blk
->size
;
7573 char *data
= blk
->data
;
7574 CORE_ADDR stack
[64];
7576 unsigned int bytes_read
, unsnd
;
7621 stack
[++stacki
] = op
- DW_OP_lit0
;
7657 stack
[++stacki
] = op
- DW_OP_reg0
;
7659 dwarf2_complex_location_expr_complaint ();
7664 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
7666 stack
[++stacki
] = unsnd
;
7668 dwarf2_complex_location_expr_complaint ();
7672 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
7678 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
7683 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
7688 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
7693 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
7698 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
7703 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
7708 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
7714 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
7719 stack
[stacki
+ 1] = stack
[stacki
];
7724 stack
[stacki
- 1] += stack
[stacki
];
7728 case DW_OP_plus_uconst
:
7729 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
7734 stack
[stacki
- 1] -= stack
[stacki
];
7739 /* If we're not the last op, then we definitely can't encode
7740 this using GDB's address_class enum. This is valid for partial
7741 global symbols, although the variable's address will be bogus
7744 dwarf2_complex_location_expr_complaint ();
7747 case DW_OP_GNU_push_tls_address
:
7748 /* The top of the stack has the offset from the beginning
7749 of the thread control block at which the variable is located. */
7750 /* Nothing should follow this operator, so the top of stack would
7752 /* This is valid for partial global symbols, but the variable's
7753 address will be bogus in the psymtab. */
7755 dwarf2_complex_location_expr_complaint ();
7759 complaint (&symfile_complaints
, "unsupported stack op: '%s'",
7760 dwarf_stack_op_name (op
));
7761 return (stack
[stacki
]);
7764 return (stack
[stacki
]);
7767 /* memory allocation interface */
7770 dwarf2_free_tmp_obstack (void *ignore
)
7772 obstack_free (&dwarf2_tmp_obstack
, NULL
);
7775 static struct dwarf_block
*
7776 dwarf_alloc_block (void)
7778 struct dwarf_block
*blk
;
7780 blk
= (struct dwarf_block
*)
7781 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
7785 static struct abbrev_info
*
7786 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
7788 struct abbrev_info
*abbrev
;
7790 abbrev
= (struct abbrev_info
*)
7791 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
7792 memset (abbrev
, 0, sizeof (struct abbrev_info
));
7796 static struct die_info
*
7797 dwarf_alloc_die (void)
7799 struct die_info
*die
;
7801 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
7802 memset (die
, 0, sizeof (struct die_info
));
7807 /* Macro support. */
7810 /* Return the full name of file number I in *LH's file name table.
7811 Use COMP_DIR as the name of the current directory of the
7812 compilation. The result is allocated using xmalloc; the caller is
7813 responsible for freeing it. */
7815 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
7817 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7819 if (IS_ABSOLUTE_PATH (fe
->name
))
7820 return xstrdup (fe
->name
);
7828 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7834 dir_len
= strlen (dir
);
7835 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
7836 strcpy (full_name
, dir
);
7837 full_name
[dir_len
] = '/';
7838 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
7842 return xstrdup (fe
->name
);
7847 static struct macro_source_file
*
7848 macro_start_file (int file
, int line
,
7849 struct macro_source_file
*current_file
,
7850 const char *comp_dir
,
7851 struct line_header
*lh
, struct objfile
*objfile
)
7853 /* The full name of this source file. */
7854 char *full_name
= file_full_name (file
, lh
, comp_dir
);
7856 /* We don't create a macro table for this compilation unit
7857 at all until we actually get a filename. */
7858 if (! pending_macros
)
7859 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
7860 objfile
->macro_cache
);
7863 /* If we have no current file, then this must be the start_file
7864 directive for the compilation unit's main source file. */
7865 current_file
= macro_set_main (pending_macros
, full_name
);
7867 current_file
= macro_include (current_file
, line
, full_name
);
7871 return current_file
;
7875 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
7876 followed by a null byte. */
7878 copy_string (const char *buf
, int len
)
7880 char *s
= xmalloc (len
+ 1);
7881 memcpy (s
, buf
, len
);
7889 consume_improper_spaces (const char *p
, const char *body
)
7893 complaint (&symfile_complaints
,
7894 "macro definition contains spaces in formal argument list:\n`%s'",
7906 parse_macro_definition (struct macro_source_file
*file
, int line
,
7911 /* The body string takes one of two forms. For object-like macro
7912 definitions, it should be:
7914 <macro name> " " <definition>
7916 For function-like macro definitions, it should be:
7918 <macro name> "() " <definition>
7920 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
7922 Spaces may appear only where explicitly indicated, and in the
7925 The Dwarf 2 spec says that an object-like macro's name is always
7926 followed by a space, but versions of GCC around March 2002 omit
7927 the space when the macro's definition is the empty string.
7929 The Dwarf 2 spec says that there should be no spaces between the
7930 formal arguments in a function-like macro's formal argument list,
7931 but versions of GCC around March 2002 include spaces after the
7935 /* Find the extent of the macro name. The macro name is terminated
7936 by either a space or null character (for an object-like macro) or
7937 an opening paren (for a function-like macro). */
7938 for (p
= body
; *p
; p
++)
7939 if (*p
== ' ' || *p
== '(')
7942 if (*p
== ' ' || *p
== '\0')
7944 /* It's an object-like macro. */
7945 int name_len
= p
- body
;
7946 char *name
= copy_string (body
, name_len
);
7947 const char *replacement
;
7950 replacement
= body
+ name_len
+ 1;
7953 dwarf2_macro_malformed_definition_complaint (body
);
7954 replacement
= body
+ name_len
;
7957 macro_define_object (file
, line
, name
, replacement
);
7963 /* It's a function-like macro. */
7964 char *name
= copy_string (body
, p
- body
);
7967 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
7971 p
= consume_improper_spaces (p
, body
);
7973 /* Parse the formal argument list. */
7974 while (*p
&& *p
!= ')')
7976 /* Find the extent of the current argument name. */
7977 const char *arg_start
= p
;
7979 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
7982 if (! *p
|| p
== arg_start
)
7983 dwarf2_macro_malformed_definition_complaint (body
);
7986 /* Make sure argv has room for the new argument. */
7987 if (argc
>= argv_size
)
7990 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
7993 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
7996 p
= consume_improper_spaces (p
, body
);
7998 /* Consume the comma, if present. */
8003 p
= consume_improper_spaces (p
, body
);
8012 /* Perfectly formed definition, no complaints. */
8013 macro_define_function (file
, line
, name
,
8014 argc
, (const char **) argv
,
8016 else if (*p
== '\0')
8018 /* Complain, but do define it. */
8019 dwarf2_macro_malformed_definition_complaint (body
);
8020 macro_define_function (file
, line
, name
,
8021 argc
, (const char **) argv
,
8025 /* Just complain. */
8026 dwarf2_macro_malformed_definition_complaint (body
);
8029 /* Just complain. */
8030 dwarf2_macro_malformed_definition_complaint (body
);
8036 for (i
= 0; i
< argc
; i
++)
8042 dwarf2_macro_malformed_definition_complaint (body
);
8047 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
8048 char *comp_dir
, bfd
*abfd
,
8049 struct dwarf2_cu
*cu
)
8051 char *mac_ptr
, *mac_end
;
8052 struct macro_source_file
*current_file
= 0;
8054 if (dwarf_macinfo_buffer
== NULL
)
8056 complaint (&symfile_complaints
, "missing .debug_macinfo section");
8060 mac_ptr
= dwarf_macinfo_buffer
+ offset
;
8061 mac_end
= dwarf_macinfo_buffer
+ dwarf_macinfo_size
;
8065 enum dwarf_macinfo_record_type macinfo_type
;
8067 /* Do we at least have room for a macinfo type byte? */
8068 if (mac_ptr
>= mac_end
)
8070 dwarf2_macros_too_long_complaint ();
8074 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
8077 switch (macinfo_type
)
8079 /* A zero macinfo type indicates the end of the macro
8084 case DW_MACINFO_define
:
8085 case DW_MACINFO_undef
:
8091 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8092 mac_ptr
+= bytes_read
;
8093 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
8094 mac_ptr
+= bytes_read
;
8097 complaint (&symfile_complaints
,
8098 "debug info gives macro %s outside of any file: %s",
8100 DW_MACINFO_define
? "definition" : macinfo_type
==
8101 DW_MACINFO_undef
? "undefinition" :
8102 "something-or-other", body
);
8105 if (macinfo_type
== DW_MACINFO_define
)
8106 parse_macro_definition (current_file
, line
, body
);
8107 else if (macinfo_type
== DW_MACINFO_undef
)
8108 macro_undef (current_file
, line
, body
);
8113 case DW_MACINFO_start_file
:
8118 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8119 mac_ptr
+= bytes_read
;
8120 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8121 mac_ptr
+= bytes_read
;
8123 current_file
= macro_start_file (file
, line
,
8124 current_file
, comp_dir
,
8129 case DW_MACINFO_end_file
:
8131 complaint (&symfile_complaints
,
8132 "macro debug info has an unmatched `close_file' directive");
8135 current_file
= current_file
->included_by
;
8138 enum dwarf_macinfo_record_type next_type
;
8140 /* GCC circa March 2002 doesn't produce the zero
8141 type byte marking the end of the compilation
8142 unit. Complain if it's not there, but exit no
8145 /* Do we at least have room for a macinfo type byte? */
8146 if (mac_ptr
>= mac_end
)
8148 dwarf2_macros_too_long_complaint ();
8152 /* We don't increment mac_ptr here, so this is just
8154 next_type
= read_1_byte (abfd
, mac_ptr
);
8156 complaint (&symfile_complaints
,
8157 "no terminating 0-type entry for macros in `.debug_macinfo' section");
8164 case DW_MACINFO_vendor_ext
:
8170 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8171 mac_ptr
+= bytes_read
;
8172 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
8173 mac_ptr
+= bytes_read
;
8175 /* We don't recognize any vendor extensions. */
8182 /* Check if the attribute's form is a DW_FORM_block*
8183 if so return true else false. */
8185 attr_form_is_block (struct attribute
*attr
)
8187 return (attr
== NULL
? 0 :
8188 attr
->form
== DW_FORM_block1
8189 || attr
->form
== DW_FORM_block2
8190 || attr
->form
== DW_FORM_block4
8191 || attr
->form
== DW_FORM_block
);
8195 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
8196 struct dwarf2_cu
*cu
)
8198 if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
8200 struct dwarf2_loclist_baton
*baton
;
8202 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
8203 sizeof (struct dwarf2_loclist_baton
));
8204 baton
->objfile
= cu
->objfile
;
8206 /* We don't know how long the location list is, but make sure we
8207 don't run off the edge of the section. */
8208 baton
->size
= dwarf_loc_size
- DW_UNSND (attr
);
8209 baton
->data
= dwarf_loc_buffer
+ DW_UNSND (attr
);
8210 baton
->base_address
= cu
->header
.base_address
;
8211 if (cu
->header
.base_known
== 0)
8212 complaint (&symfile_complaints
,
8213 "Location list used without specifying the CU base address.");
8215 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
8216 SYMBOL_LOCATION_BATON (sym
) = baton
;
8220 struct dwarf2_locexpr_baton
*baton
;
8222 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
8223 sizeof (struct dwarf2_locexpr_baton
));
8224 baton
->objfile
= cu
->objfile
;
8226 if (attr_form_is_block (attr
))
8228 /* Note that we're just copying the block's data pointer
8229 here, not the actual data. We're still pointing into the
8230 dwarf_info_buffer for SYM's objfile; right now we never
8231 release that buffer, but when we do clean up properly
8232 this may need to change. */
8233 baton
->size
= DW_BLOCK (attr
)->size
;
8234 baton
->data
= DW_BLOCK (attr
)->data
;
8238 dwarf2_invalid_attrib_class_complaint ("location description",
8239 SYMBOL_NATURAL_NAME (sym
));
8244 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
8245 SYMBOL_LOCATION_BATON (sym
) = baton
;