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 void set_cu_language (unsigned int, struct dwarf2_cu
*);
739 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
742 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
744 static struct die_info
*die_specification (struct die_info
*die
,
747 static void free_line_header (struct line_header
*lh
);
749 static struct line_header
*(dwarf_decode_line_header
750 (unsigned int offset
,
751 bfd
*abfd
, struct dwarf2_cu
*cu
));
753 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
756 static void dwarf2_start_subfile (char *, char *);
758 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
761 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
764 static void dwarf2_const_value_data (struct attribute
*attr
,
768 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
770 static struct type
*die_containing_type (struct die_info
*,
774 static struct type
*type_at_offset (unsigned int, struct objfile
*);
777 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
779 static void read_type_die (struct die_info
*, struct dwarf2_cu
*);
781 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
783 static char *determine_prefix_aux (struct die_info
*die
, struct dwarf2_cu
*);
785 static char *typename_concat (const char *prefix
, const char *suffix
);
787 static char *class_name (struct die_info
*die
, struct dwarf2_cu
*);
789 static void read_typedef (struct die_info
*, struct dwarf2_cu
*);
791 static void read_base_type (struct die_info
*, struct dwarf2_cu
*);
793 static void read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
795 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
797 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
799 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
801 static int dwarf2_get_pc_bounds (struct die_info
*,
802 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
804 static void get_scope_pc_bounds (struct die_info
*,
805 CORE_ADDR
*, CORE_ADDR
*,
808 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
811 static void dwarf2_attach_fields_to_type (struct field_info
*,
812 struct type
*, struct dwarf2_cu
*);
814 static void dwarf2_add_member_fn (struct field_info
*,
815 struct die_info
*, struct type
*,
818 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
819 struct type
*, struct dwarf2_cu
*);
821 static void read_structure_scope (struct die_info
*, struct dwarf2_cu
*);
823 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
825 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
827 static const char *namespace_name (struct die_info
*die
,
828 int *is_anonymous
, struct dwarf2_cu
*);
830 static void read_enumeration (struct die_info
*, struct dwarf2_cu
*);
832 static struct type
*dwarf_base_type (int, int, struct dwarf2_cu
*);
834 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
836 static void read_array_type (struct die_info
*, struct dwarf2_cu
*);
838 static void read_tag_pointer_type (struct die_info
*, struct dwarf2_cu
*);
840 static void read_tag_ptr_to_member_type (struct die_info
*,
843 static void read_tag_reference_type (struct die_info
*, struct dwarf2_cu
*);
845 static void read_tag_const_type (struct die_info
*, struct dwarf2_cu
*);
847 static void read_tag_volatile_type (struct die_info
*, struct dwarf2_cu
*);
849 static void read_tag_string_type (struct die_info
*, struct dwarf2_cu
*);
851 static void read_subroutine_type (struct die_info
*, struct dwarf2_cu
*);
853 static struct die_info
*read_comp_unit (char *, bfd
*, struct dwarf2_cu
*);
855 static struct die_info
*read_die_and_children (char *info_ptr
, bfd
*abfd
,
858 struct die_info
*parent
);
860 static struct die_info
*read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
863 struct die_info
*parent
);
865 static void free_die_list (struct die_info
*);
867 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
869 static void process_die (struct die_info
*, struct dwarf2_cu
*);
871 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
873 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
875 static struct die_info
*dwarf2_extension (struct die_info
*die
,
878 static char *dwarf_tag_name (unsigned int);
880 static char *dwarf_attr_name (unsigned int);
882 static char *dwarf_form_name (unsigned int);
884 static char *dwarf_stack_op_name (unsigned int);
886 static char *dwarf_bool_name (unsigned int);
888 static char *dwarf_type_encoding_name (unsigned int);
891 static char *dwarf_cfi_name (unsigned int);
893 struct die_info
*copy_die (struct die_info
*);
896 static struct die_info
*sibling_die (struct die_info
*);
898 static void dump_die (struct die_info
*);
900 static void dump_die_list (struct die_info
*);
902 static void store_in_ref_table (unsigned int, struct die_info
*);
904 static void dwarf2_empty_hash_tables (void);
906 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*,
909 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
911 static struct die_info
*follow_die_ref (unsigned int);
913 static struct type
*dwarf2_fundamental_type (struct objfile
*, int,
916 /* memory allocation interface */
918 static void dwarf2_free_tmp_obstack (void *);
920 static struct dwarf_block
*dwarf_alloc_block (void);
922 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
924 static struct die_info
*dwarf_alloc_die (void);
926 static void initialize_cu_func_list (struct dwarf2_cu
*);
928 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
931 static void dwarf_decode_macros (struct line_header
*, unsigned int,
932 char *, bfd
*, struct dwarf2_cu
*);
934 static int attr_form_is_block (struct attribute
*);
937 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
938 struct dwarf2_cu
*cu
);
940 /* Try to locate the sections we need for DWARF 2 debugging
941 information and return true if we have enough to do something. */
944 dwarf2_has_info (bfd
*abfd
)
946 dwarf_info_section
= 0;
947 dwarf_abbrev_section
= 0;
948 dwarf_line_section
= 0;
949 dwarf_str_section
= 0;
950 dwarf_macinfo_section
= 0;
951 dwarf_frame_section
= 0;
952 dwarf_eh_frame_section
= 0;
953 dwarf_ranges_section
= 0;
954 dwarf_loc_section
= 0;
956 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
957 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
960 /* This function is mapped across the sections and remembers the
961 offset and size of each of the debugging sections we are interested
965 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, void *ignore_ptr
)
967 if (strcmp (sectp
->name
, INFO_SECTION
) == 0)
969 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
970 dwarf_info_section
= sectp
;
972 else if (strcmp (sectp
->name
, ABBREV_SECTION
) == 0)
974 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
975 dwarf_abbrev_section
= sectp
;
977 else if (strcmp (sectp
->name
, LINE_SECTION
) == 0)
979 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
980 dwarf_line_section
= sectp
;
982 else if (strcmp (sectp
->name
, PUBNAMES_SECTION
) == 0)
984 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
985 dwarf_pubnames_section
= sectp
;
987 else if (strcmp (sectp
->name
, ARANGES_SECTION
) == 0)
989 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
990 dwarf_aranges_section
= sectp
;
992 else if (strcmp (sectp
->name
, LOC_SECTION
) == 0)
994 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
995 dwarf_loc_section
= sectp
;
997 else if (strcmp (sectp
->name
, MACINFO_SECTION
) == 0)
999 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
1000 dwarf_macinfo_section
= sectp
;
1002 else if (strcmp (sectp
->name
, STR_SECTION
) == 0)
1004 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
1005 dwarf_str_section
= sectp
;
1007 else if (strcmp (sectp
->name
, FRAME_SECTION
) == 0)
1009 dwarf_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1010 dwarf_frame_section
= sectp
;
1012 else if (strcmp (sectp
->name
, EH_FRAME_SECTION
) == 0)
1014 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1015 if (aflag
& SEC_HAS_CONTENTS
)
1017 dwarf_eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1018 dwarf_eh_frame_section
= sectp
;
1021 else if (strcmp (sectp
->name
, RANGES_SECTION
) == 0)
1023 dwarf_ranges_size
= bfd_get_section_size_before_reloc (sectp
);
1024 dwarf_ranges_section
= sectp
;
1028 /* Build a partial symbol table. */
1031 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1034 /* We definitely need the .debug_info and .debug_abbrev sections */
1036 dwarf_info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1037 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1039 if (dwarf_line_section
)
1040 dwarf_line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1042 dwarf_line_buffer
= NULL
;
1044 if (dwarf_str_section
)
1045 dwarf_str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1047 dwarf_str_buffer
= NULL
;
1049 if (dwarf_macinfo_section
)
1050 dwarf_macinfo_buffer
= dwarf2_read_section (objfile
,
1051 dwarf_macinfo_section
);
1053 dwarf_macinfo_buffer
= NULL
;
1055 if (dwarf_ranges_section
)
1056 dwarf_ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1058 dwarf_ranges_buffer
= NULL
;
1060 if (dwarf_loc_section
)
1061 dwarf_loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1063 dwarf_loc_buffer
= NULL
;
1066 || (objfile
->global_psymbols
.size
== 0
1067 && objfile
->static_psymbols
.size
== 0))
1069 init_psymbol_list (objfile
, 1024);
1073 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1075 /* Things are significantly easier if we have .debug_aranges and
1076 .debug_pubnames sections */
1078 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1082 /* only test this case for now */
1084 /* In this case we have to work a bit harder */
1085 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1090 /* Build the partial symbol table from the information in the
1091 .debug_pubnames and .debug_aranges sections. */
1094 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1096 bfd
*abfd
= objfile
->obfd
;
1097 char *aranges_buffer
, *pubnames_buffer
;
1098 char *aranges_ptr
, *pubnames_ptr
;
1099 unsigned int entry_length
, version
, info_offset
, info_size
;
1101 pubnames_buffer
= dwarf2_read_section (objfile
,
1102 dwarf_pubnames_section
);
1103 pubnames_ptr
= pubnames_buffer
;
1104 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
1106 struct comp_unit_head cu_header
;
1109 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1111 pubnames_ptr
+= bytes_read
;
1112 version
= read_1_byte (abfd
, pubnames_ptr
);
1114 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1116 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1120 aranges_buffer
= dwarf2_read_section (objfile
,
1121 dwarf_aranges_section
);
1126 /* Read in the comp unit header information from the debug_info at
1130 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1131 char *info_ptr
, bfd
*abfd
)
1135 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1137 info_ptr
+= bytes_read
;
1138 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1140 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1142 info_ptr
+= bytes_read
;
1143 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1145 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1146 if (signed_addr
< 0)
1147 internal_error (__FILE__
, __LINE__
,
1148 "read_comp_unit_head: dwarf from non elf file");
1149 cu_header
->signed_addr_p
= signed_addr
;
1153 /* Build the partial symbol table by doing a quick pass through the
1154 .debug_info and .debug_abbrev sections. */
1157 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1159 /* Instead of reading this into a big buffer, we should probably use
1160 mmap() on architectures that support it. (FIXME) */
1161 bfd
*abfd
= objfile
->obfd
;
1162 char *info_ptr
, *abbrev_ptr
;
1163 char *beg_of_comp_unit
;
1164 struct partial_die_info comp_unit_die
;
1165 struct partial_symtab
*pst
;
1166 struct cleanup
*back_to
;
1167 CORE_ADDR lowpc
, highpc
, baseaddr
;
1169 info_ptr
= dwarf_info_buffer
;
1170 abbrev_ptr
= dwarf_abbrev_buffer
;
1172 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1173 the partial symbol scan, like attribute values.
1175 We could reduce our peak memory consumption during partial symbol
1176 table construction by freeing stuff from this obstack more often
1177 --- say, after processing each compilation unit, or each die ---
1178 but it turns out that this saves almost nothing. For an
1179 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1180 on dwarf2_tmp_obstack. Some investigation showed:
1182 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1183 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1184 all fixed-length values not requiring dynamic allocation.
1186 2) 30% of the attributes used the form DW_FORM_string. For
1187 DW_FORM_string, read_attribute simply hands back a pointer to
1188 the null-terminated string in dwarf_info_buffer, so no dynamic
1189 allocation is needed there either.
1191 3) The remaining 1% of the attributes all used DW_FORM_block1.
1192 75% of those were DW_AT_frame_base location lists for
1193 functions; the rest were DW_AT_location attributes, probably
1194 for the global variables.
1196 Anyway, what this all means is that the memory the dwarf2
1197 reader uses as temporary space reading partial symbols is about
1198 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1200 obstack_init (&dwarf2_tmp_obstack
);
1201 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1203 /* Since the objects we're extracting from dwarf_info_buffer vary in
1204 length, only the individual functions to extract them (like
1205 read_comp_unit_head and read_partial_die) can really know whether
1206 the buffer is large enough to hold another complete object.
1208 At the moment, they don't actually check that. If
1209 dwarf_info_buffer holds just one extra byte after the last
1210 compilation unit's dies, then read_comp_unit_head will happily
1211 read off the end of the buffer. read_partial_die is similarly
1212 casual. Those functions should be fixed.
1214 For this loop condition, simply checking whether there's any data
1215 left at all should be sufficient. */
1216 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1218 struct cleanup
*back_to_inner
;
1219 struct dwarf2_cu cu
;
1220 beg_of_comp_unit
= info_ptr
;
1222 cu
.objfile
= objfile
;
1223 info_ptr
= read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1225 if (cu
.header
.version
!= 2)
1227 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
));
1230 if (cu
.header
.abbrev_offset
>= dwarf_abbrev_size
)
1232 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6) [in module %s]",
1233 (long) cu
.header
.abbrev_offset
,
1234 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1235 bfd_get_filename (abfd
));
1238 if (beg_of_comp_unit
+ cu
.header
.length
+ cu
.header
.initial_length_size
1239 > dwarf_info_buffer
+ dwarf_info_size
)
1241 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0) [in module %s]",
1242 (long) cu
.header
.length
,
1243 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1244 bfd_get_filename (abfd
));
1247 /* Complete the cu_header */
1248 cu
.header
.offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1249 cu
.header
.first_die_ptr
= info_ptr
;
1250 cu
.header
.cu_head_ptr
= beg_of_comp_unit
;
1252 cu
.list_in_scope
= &file_symbols
;
1254 /* Read the abbrevs for this compilation unit into a table */
1255 dwarf2_read_abbrevs (abfd
, &cu
);
1256 back_to_inner
= make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1258 /* Read the compilation unit die */
1259 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1262 /* Set the language we're debugging */
1263 set_cu_language (comp_unit_die
.language
, &cu
);
1265 /* Allocate a new partial symbol table structure */
1266 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1267 comp_unit_die
.name
? comp_unit_die
.name
: "",
1268 comp_unit_die
.lowpc
,
1269 objfile
->global_psymbols
.next
,
1270 objfile
->static_psymbols
.next
);
1272 pst
->read_symtab_private
= (char *)
1273 obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct dwarf2_pinfo
));
1274 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1275 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1276 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1277 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1278 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1279 DWARF_LINE_SIZE (pst
) = dwarf_line_size
;
1280 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1281 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1282 DWARF_MACINFO_BUFFER (pst
) = dwarf_macinfo_buffer
;
1283 DWARF_MACINFO_SIZE (pst
) = dwarf_macinfo_size
;
1284 DWARF_RANGES_BUFFER (pst
) = dwarf_ranges_buffer
;
1285 DWARF_RANGES_SIZE (pst
) = dwarf_ranges_size
;
1286 DWARF_LOC_BUFFER (pst
) = dwarf_loc_buffer
;
1287 DWARF_LOC_SIZE (pst
) = dwarf_loc_size
;
1288 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1290 /* Store the function that reads in the rest of the symbol table */
1291 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1293 /* Check if comp unit has_children.
1294 If so, read the rest of the partial symbols from this comp unit.
1295 If not, there's no more debug_info for this comp unit. */
1296 if (comp_unit_die
.has_children
)
1298 lowpc
= ((CORE_ADDR
) -1);
1299 highpc
= ((CORE_ADDR
) 0);
1301 info_ptr
= scan_partial_symbols (info_ptr
, &lowpc
, &highpc
,
1304 /* If we didn't find a lowpc, set it to highpc to avoid
1305 complaints from `maint check'. */
1306 if (lowpc
== ((CORE_ADDR
) -1))
1309 /* If the compilation unit didn't have an explicit address range,
1310 then use the information extracted from its child dies. */
1311 if (! comp_unit_die
.has_pc_info
)
1313 comp_unit_die
.lowpc
= lowpc
;
1314 comp_unit_die
.highpc
= highpc
;
1317 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1318 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1320 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1321 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1322 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1323 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1324 sort_pst_symbols (pst
);
1326 /* If there is already a psymtab or symtab for a file of this
1327 name, remove it. (If there is a symtab, more drastic things
1328 also happen.) This happens in VxWorks. */
1329 free_named_symtabs (pst
->filename
);
1331 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1332 + cu
.header
.initial_length_size
;
1334 do_cleanups (back_to_inner
);
1336 do_cleanups (back_to
);
1339 /* Read in all interesting dies to the end of the compilation unit or
1340 to the end of the current namespace. NAMESPACE is NULL if we
1341 haven't yet encountered any DW_TAG_namespace entries; otherwise,
1342 it's the name of the current namespace. In particular, it's the
1343 empty string if we're currently in the global namespace but have
1344 previously encountered a DW_TAG_namespace. */
1347 scan_partial_symbols (char *info_ptr
, CORE_ADDR
*lowpc
,
1348 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
1349 const char *namespace)
1351 struct objfile
*objfile
= cu
->objfile
;
1352 bfd
*abfd
= objfile
->obfd
;
1353 struct partial_die_info pdi
;
1355 /* Now, march along the PDI's, descending into ones which have
1356 interesting children but skipping the children of the other ones,
1357 until we reach the end of the compilation unit. */
1361 /* This flag tells whether or not info_ptr has gotten updated
1363 int info_ptr_updated
= 0;
1365 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu
);
1367 /* Anonymous namespaces have no name but have interesting
1368 children, so we need to look at them. Ditto for anonymous
1371 if (pdi
.name
!= NULL
|| pdi
.tag
== DW_TAG_namespace
1372 || pdi
.tag
== DW_TAG_enumeration_type
)
1376 case DW_TAG_subprogram
:
1377 if (pdi
.has_pc_info
)
1379 if (pdi
.lowpc
< *lowpc
)
1383 if (pdi
.highpc
> *highpc
)
1385 *highpc
= pdi
.highpc
;
1387 if (!pdi
.is_declaration
)
1389 add_partial_symbol (&pdi
, cu
, namespace);
1393 case DW_TAG_variable
:
1394 case DW_TAG_typedef
:
1395 case DW_TAG_union_type
:
1396 if (!pdi
.is_declaration
)
1398 add_partial_symbol (&pdi
, cu
, namespace);
1401 case DW_TAG_class_type
:
1402 case DW_TAG_structure_type
:
1403 if (!pdi
.is_declaration
)
1405 info_ptr
= add_partial_structure (&pdi
, info_ptr
, cu
,
1407 info_ptr_updated
= 1;
1410 case DW_TAG_enumeration_type
:
1411 if (!pdi
.is_declaration
)
1413 info_ptr
= add_partial_enumeration (&pdi
, info_ptr
, cu
,
1415 info_ptr_updated
= 1;
1418 case DW_TAG_base_type
:
1419 case DW_TAG_subrange_type
:
1420 /* File scope base type definitions are added to the partial
1422 add_partial_symbol (&pdi
, cu
, namespace);
1424 case DW_TAG_namespace
:
1425 /* We've hit a DW_TAG_namespace entry, so we know this
1426 file has been compiled using a compiler that
1427 generates them; update NAMESPACE to reflect that. */
1428 if (namespace == NULL
)
1430 info_ptr
= add_partial_namespace (&pdi
, info_ptr
, lowpc
, highpc
,
1432 info_ptr_updated
= 1;
1442 /* If the die has a sibling, skip to the sibling, unless another
1443 function has already updated info_ptr for us. */
1445 /* NOTE: carlton/2003-06-16: This is a bit hackish, but whether
1446 or not we want to update this depends on enough stuff (not
1447 only pdi.tag but also whether or not pdi.name is NULL) that
1448 this seems like the easiest way to handle the issue. */
1450 if (!info_ptr_updated
)
1451 info_ptr
= locate_pdi_sibling (&pdi
, info_ptr
, abfd
, cu
);
1458 add_partial_symbol (struct partial_die_info
*pdi
,
1459 struct dwarf2_cu
*cu
, const char *namespace)
1461 struct objfile
*objfile
= cu
->objfile
;
1463 char *actual_name
= pdi
->name
;
1464 const struct partial_symbol
*psym
= NULL
;
1467 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1469 /* If we're not in the global namespace and if the namespace name
1470 isn't encoded in a mangled actual_name, add it. */
1472 if (pdi_needs_namespace (pdi
->tag
, namespace))
1474 actual_name
= alloca (strlen (pdi
->name
) + 2 + strlen (namespace) + 1);
1475 strcpy (actual_name
, namespace);
1476 strcat (actual_name
, "::");
1477 strcat (actual_name
, pdi
->name
);
1482 case DW_TAG_subprogram
:
1483 if (pdi
->is_external
)
1485 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1486 mst_text, objfile); */
1487 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1488 VAR_DOMAIN
, LOC_BLOCK
,
1489 &objfile
->global_psymbols
,
1490 0, pdi
->lowpc
+ baseaddr
,
1491 cu
->language
, objfile
);
1495 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1496 mst_file_text, objfile); */
1497 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1498 VAR_DOMAIN
, LOC_BLOCK
,
1499 &objfile
->static_psymbols
,
1500 0, pdi
->lowpc
+ baseaddr
,
1501 cu
->language
, objfile
);
1504 case DW_TAG_variable
:
1505 if (pdi
->is_external
)
1508 Don't enter into the minimal symbol tables as there is
1509 a minimal symbol table entry from the ELF symbols already.
1510 Enter into partial symbol table if it has a location
1511 descriptor or a type.
1512 If the location descriptor is missing, new_symbol will create
1513 a LOC_UNRESOLVED symbol, the address of the variable will then
1514 be determined from the minimal symbol table whenever the variable
1516 The address for the partial symbol table entry is not
1517 used by GDB, but it comes in handy for debugging partial symbol
1521 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1522 if (pdi
->locdesc
|| pdi
->has_type
)
1523 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1524 VAR_DOMAIN
, LOC_STATIC
,
1525 &objfile
->global_psymbols
,
1527 cu
->language
, objfile
);
1531 /* Static Variable. Skip symbols without location descriptors. */
1532 if (pdi
->locdesc
== NULL
)
1534 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1535 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
1536 mst_file_data, objfile); */
1537 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1538 VAR_DOMAIN
, LOC_STATIC
,
1539 &objfile
->static_psymbols
,
1541 cu
->language
, objfile
);
1544 case DW_TAG_typedef
:
1545 case DW_TAG_base_type
:
1546 case DW_TAG_subrange_type
:
1547 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1548 VAR_DOMAIN
, LOC_TYPEDEF
,
1549 &objfile
->static_psymbols
,
1550 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1552 case DW_TAG_class_type
:
1553 case DW_TAG_structure_type
:
1554 case DW_TAG_union_type
:
1555 case DW_TAG_enumeration_type
:
1556 /* Skip aggregate types without children, these are external
1558 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
1559 static vs. global. */
1560 if (pdi
->has_children
== 0)
1562 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1563 STRUCT_DOMAIN
, LOC_TYPEDEF
,
1564 cu
->language
== language_cplus
1565 ? &objfile
->global_psymbols
1566 : &objfile
->static_psymbols
,
1567 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1569 if (cu
->language
== language_cplus
)
1571 /* For C++, these implicitly act as typedefs as well. */
1572 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1573 VAR_DOMAIN
, LOC_TYPEDEF
,
1574 &objfile
->global_psymbols
,
1575 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1578 case DW_TAG_enumerator
:
1579 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1580 VAR_DOMAIN
, LOC_CONST
,
1581 cu
->language
== language_cplus
1582 ? &objfile
->global_psymbols
1583 : &objfile
->static_psymbols
,
1584 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1590 /* Check to see if we should scan the name for possible namespace
1591 info. Only do this if this is C++, if we don't have namespace
1592 debugging info in the file, if the psym is of an appropriate type
1593 (otherwise we'll have psym == NULL), and if we actually had a
1594 mangled name to begin with. */
1596 if (cu
->language
== language_cplus
1597 && namespace == NULL
1599 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
1600 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
1604 /* Determine whether a die of type TAG living in the C++ namespace
1605 NAMESPACE needs to have the name of the namespace prepended to the
1606 name listed in the die. */
1609 pdi_needs_namespace (enum dwarf_tag tag
, const char *namespace)
1611 if (namespace == NULL
|| namespace[0] == '\0')
1616 case DW_TAG_typedef
:
1617 case DW_TAG_class_type
:
1618 case DW_TAG_structure_type
:
1619 case DW_TAG_union_type
:
1620 case DW_TAG_enumeration_type
:
1621 case DW_TAG_enumerator
:
1628 /* Read a partial die corresponding to a namespace; also, add a symbol
1629 corresponding to that namespace to the symbol table. NAMESPACE is
1630 the name of the enclosing namespace. */
1633 add_partial_namespace (struct partial_die_info
*pdi
, char *info_ptr
,
1634 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1635 struct dwarf2_cu
*cu
, const char *namespace)
1637 struct objfile
*objfile
= cu
->objfile
;
1638 const char *new_name
= pdi
->name
;
1641 /* Calculate the full name of the namespace that we just entered. */
1643 if (new_name
== NULL
)
1644 new_name
= "(anonymous namespace)";
1645 full_name
= alloca (strlen (namespace) + 2 + strlen (new_name
) + 1);
1646 strcpy (full_name
, namespace);
1647 if (*namespace != '\0')
1648 strcat (full_name
, "::");
1649 strcat (full_name
, new_name
);
1651 /* FIXME: carlton/2003-10-07: We can't just replace this by a call
1652 to add_partial_symbol, because we don't have a way to pass in the
1653 full name to that function; that might be a flaw in
1654 add_partial_symbol's interface. */
1656 add_psymbol_to_list (full_name
, strlen (full_name
),
1657 VAR_DOMAIN
, LOC_TYPEDEF
,
1658 &objfile
->global_psymbols
,
1659 0, 0, cu
->language
, objfile
);
1661 /* Now scan partial symbols in that namespace. */
1663 if (pdi
->has_children
)
1664 info_ptr
= scan_partial_symbols (info_ptr
, lowpc
, highpc
, cu
, full_name
);
1669 /* Read a partial die corresponding to a class or structure. */
1672 add_partial_structure (struct partial_die_info
*struct_pdi
, char *info_ptr
,
1673 struct dwarf2_cu
*cu
,
1674 const char *namespace)
1676 bfd
*abfd
= cu
->objfile
->obfd
;
1677 char *actual_class_name
= NULL
;
1679 if (cu
->language
== language_cplus
1680 && (namespace == NULL
|| namespace[0] == '\0')
1681 && struct_pdi
->name
!= NULL
1682 && struct_pdi
->has_children
)
1684 /* See if we can figure out if the class lives in a namespace
1685 (or is nested within another class.) We do this by looking
1686 for a member function; its demangled name will contain
1687 namespace info, if there is any. */
1689 /* NOTE: carlton/2003-10-07: Getting the info this way changes
1690 what template types look like, because the demangler
1691 frequently doesn't give the same name as the debug info. We
1692 could fix this by only using the demangled name to get the
1693 prefix (but see comment in read_structure_scope). */
1695 /* FIXME: carlton/2004-01-23: If NAMESPACE equals "", we have
1696 the appropriate debug information, so it would be nice to be
1697 able to avoid this hack. But NAMESPACE may not be the
1698 namespace where this class was defined: NAMESPACE reflects
1699 where STRUCT_PDI occurs in the tree of dies, but because of
1700 DW_AT_specification, that may not actually tell us where the
1701 class is defined. (See the comment in read_func_scope for an
1702 example of how this could occur.)
1704 Unfortunately, our current partial symtab data structures are
1705 completely unable to deal with DW_AT_specification. So, for
1706 now, the best thing to do is to get nesting information from
1707 places other than the tree structure of dies if there's any
1708 chance that a DW_AT_specification is involved. :-( */
1710 char *next_child
= info_ptr
;
1714 struct partial_die_info child_pdi
;
1716 next_child
= read_partial_die (&child_pdi
, abfd
, next_child
,
1720 if (child_pdi
.tag
== DW_TAG_subprogram
)
1722 actual_class_name
= class_name_from_physname (child_pdi
.name
);
1723 if (actual_class_name
!= NULL
)
1724 struct_pdi
->name
= actual_class_name
;
1729 next_child
= locate_pdi_sibling (&child_pdi
, next_child
,
1735 add_partial_symbol (struct_pdi
, cu
, namespace);
1736 xfree (actual_class_name
);
1738 return locate_pdi_sibling (struct_pdi
, info_ptr
, abfd
, cu
);
1741 /* Read a partial die corresponding to an enumeration type. */
1744 add_partial_enumeration (struct partial_die_info
*enum_pdi
, char *info_ptr
,
1745 struct dwarf2_cu
*cu
, const char *namespace)
1747 struct objfile
*objfile
= cu
->objfile
;
1748 bfd
*abfd
= objfile
->obfd
;
1749 struct partial_die_info pdi
;
1751 if (enum_pdi
->name
!= NULL
)
1752 add_partial_symbol (enum_pdi
, cu
, namespace);
1756 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu
);
1759 if (pdi
.tag
!= DW_TAG_enumerator
|| pdi
.name
== NULL
)
1760 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
1762 add_partial_symbol (&pdi
, cu
, namespace);
1768 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the next DIE
1772 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, char *info_ptr
,
1773 bfd
*abfd
, struct dwarf2_cu
*cu
)
1775 /* Do we know the sibling already? */
1777 if (orig_pdi
->sibling
)
1778 return orig_pdi
->sibling
;
1780 /* Are there any children to deal with? */
1782 if (!orig_pdi
->has_children
)
1785 /* Okay, we don't know the sibling, but we have children that we
1786 want to skip. So read children until we run into one without a
1787 tag; return whatever follows it. */
1791 struct partial_die_info pdi
;
1793 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu
);
1798 info_ptr
= locate_pdi_sibling (&pdi
, info_ptr
, abfd
, cu
);
1802 /* Expand this partial symbol table into a full symbol table. */
1805 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1807 /* FIXME: This is barely more than a stub. */
1812 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1818 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1819 gdb_flush (gdb_stdout
);
1822 psymtab_to_symtab_1 (pst
);
1824 /* Finish up the debug error message. */
1826 printf_filtered ("done.\n");
1832 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1834 struct objfile
*objfile
= pst
->objfile
;
1835 bfd
*abfd
= objfile
->obfd
;
1836 struct dwarf2_cu cu
;
1837 struct die_info
*dies
;
1838 unsigned long offset
;
1839 CORE_ADDR lowpc
, highpc
;
1840 struct die_info
*child_die
;
1842 struct symtab
*symtab
;
1843 struct cleanup
*back_to
;
1844 struct attribute
*attr
;
1847 /* Set local variables from the partial symbol table info. */
1848 offset
= DWARF_INFO_OFFSET (pst
);
1849 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1850 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1851 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1852 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1853 dwarf_line_size
= DWARF_LINE_SIZE (pst
);
1854 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1855 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1856 dwarf_macinfo_buffer
= DWARF_MACINFO_BUFFER (pst
);
1857 dwarf_macinfo_size
= DWARF_MACINFO_SIZE (pst
);
1858 dwarf_ranges_buffer
= DWARF_RANGES_BUFFER (pst
);
1859 dwarf_ranges_size
= DWARF_RANGES_SIZE (pst
);
1860 dwarf_loc_buffer
= DWARF_LOC_BUFFER (pst
);
1861 dwarf_loc_size
= DWARF_LOC_SIZE (pst
);
1862 info_ptr
= dwarf_info_buffer
+ offset
;
1863 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1865 /* We're in the global namespace. */
1866 processing_current_prefix
= "";
1868 obstack_init (&dwarf2_tmp_obstack
);
1869 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1872 make_cleanup (really_free_pendings
, NULL
);
1874 cu
.objfile
= objfile
;
1876 /* read in the comp_unit header */
1877 info_ptr
= read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1879 /* Read the abbrevs for this compilation unit */
1880 dwarf2_read_abbrevs (abfd
, &cu
);
1881 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1883 cu
.header
.offset
= offset
;
1885 cu
.list_in_scope
= &file_symbols
;
1887 dies
= read_comp_unit (info_ptr
, abfd
, &cu
);
1889 make_cleanup_free_die_list (dies
);
1891 /* Find the base address of the compilation unit for range lists and
1892 location lists. It will normally be specified by DW_AT_low_pc.
1893 In DWARF-3 draft 4, the base address could be overridden by
1894 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1895 compilation units with discontinuous ranges. */
1897 cu
.header
.base_known
= 0;
1898 cu
.header
.base_address
= 0;
1900 attr
= dwarf2_attr (dies
, DW_AT_entry_pc
, &cu
);
1903 cu
.header
.base_address
= DW_ADDR (attr
);
1904 cu
.header
.base_known
= 1;
1908 attr
= dwarf2_attr (dies
, DW_AT_low_pc
, &cu
);
1911 cu
.header
.base_address
= DW_ADDR (attr
);
1912 cu
.header
.base_known
= 1;
1916 /* Do line number decoding in read_file_scope () */
1917 process_die (dies
, &cu
);
1919 /* Some compilers don't define a DW_AT_high_pc attribute for the
1920 compilation unit. If the DW_AT_high_pc is missing, synthesize
1921 it, by scanning the DIE's below the compilation unit. */
1922 get_scope_pc_bounds (dies
, &lowpc
, &highpc
, &cu
);
1924 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1926 /* Set symtab language to language from DW_AT_language.
1927 If the compilation is from a C file generated by language preprocessors,
1928 do not set the language if it was already deduced by start_subfile. */
1930 && !(cu
.language
== language_c
&& symtab
->language
!= language_c
))
1932 symtab
->language
= cu
.language
;
1934 pst
->symtab
= symtab
;
1937 do_cleanups (back_to
);
1940 /* Process a die and its children. */
1943 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
1947 case DW_TAG_padding
:
1949 case DW_TAG_compile_unit
:
1950 read_file_scope (die
, cu
);
1952 case DW_TAG_subprogram
:
1953 read_subroutine_type (die
, cu
);
1954 read_func_scope (die
, cu
);
1956 case DW_TAG_inlined_subroutine
:
1957 /* FIXME: These are ignored for now.
1958 They could be used to set breakpoints on all inlined instances
1959 of a function and make GDB `next' properly over inlined functions. */
1961 case DW_TAG_lexical_block
:
1962 case DW_TAG_try_block
:
1963 case DW_TAG_catch_block
:
1964 read_lexical_block_scope (die
, cu
);
1966 case DW_TAG_class_type
:
1967 case DW_TAG_structure_type
:
1968 case DW_TAG_union_type
:
1969 read_structure_scope (die
, cu
);
1971 case DW_TAG_enumeration_type
:
1972 read_enumeration (die
, cu
);
1974 case DW_TAG_subroutine_type
:
1975 read_subroutine_type (die
, cu
);
1977 case DW_TAG_array_type
:
1978 read_array_type (die
, cu
);
1980 case DW_TAG_pointer_type
:
1981 read_tag_pointer_type (die
, cu
);
1983 case DW_TAG_ptr_to_member_type
:
1984 read_tag_ptr_to_member_type (die
, cu
);
1986 case DW_TAG_reference_type
:
1987 read_tag_reference_type (die
, cu
);
1989 case DW_TAG_string_type
:
1990 read_tag_string_type (die
, cu
);
1992 case DW_TAG_base_type
:
1993 read_base_type (die
, cu
);
1994 if (dwarf2_attr (die
, DW_AT_name
, cu
))
1996 /* Add a typedef symbol for the base type definition. */
1997 new_symbol (die
, die
->type
, cu
);
2000 case DW_TAG_subrange_type
:
2001 read_subrange_type (die
, cu
);
2002 if (dwarf2_attr (die
, DW_AT_name
, cu
))
2004 /* Add a typedef symbol for the base type definition. */
2005 new_symbol (die
, die
->type
, cu
);
2008 case DW_TAG_common_block
:
2009 read_common_block (die
, cu
);
2011 case DW_TAG_common_inclusion
:
2013 case DW_TAG_namespace
:
2014 processing_has_namespace_info
= 1;
2015 read_namespace (die
, cu
);
2017 case DW_TAG_imported_declaration
:
2018 case DW_TAG_imported_module
:
2019 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2020 information contained in these. DW_TAG_imported_declaration
2021 dies shouldn't have children; DW_TAG_imported_module dies
2022 shouldn't in the C++ case, but conceivably could in the
2023 Fortran case, so we'll have to replace this gdb_assert if
2024 Fortran compilers start generating that info. */
2025 processing_has_namespace_info
= 1;
2026 gdb_assert (die
->child
== NULL
);
2029 new_symbol (die
, NULL
, cu
);
2035 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2037 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2041 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2043 struct objfile
*objfile
= cu
->objfile
;
2044 struct comp_unit_head
*cu_header
= &cu
->header
;
2045 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2046 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2047 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2048 struct attribute
*attr
;
2049 char *name
= "<unknown>";
2050 char *comp_dir
= NULL
;
2051 struct die_info
*child_die
;
2052 bfd
*abfd
= objfile
->obfd
;
2053 struct line_header
*line_header
= 0;
2056 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2058 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2060 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2061 from finish_block. */
2062 if (lowpc
== ((CORE_ADDR
) -1))
2067 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2070 name
= DW_STRING (attr
);
2072 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2075 comp_dir
= DW_STRING (attr
);
2078 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2079 directory, get rid of it. */
2080 char *cp
= strchr (comp_dir
, ':');
2082 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2087 if (objfile
->ei
.entry_point
>= lowpc
&&
2088 objfile
->ei
.entry_point
< highpc
)
2090 objfile
->ei
.deprecated_entry_file_lowpc
= lowpc
;
2091 objfile
->ei
.deprecated_entry_file_highpc
= highpc
;
2094 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2097 set_cu_language (DW_UNSND (attr
), cu
);
2100 /* We assume that we're processing GCC output. */
2101 processing_gcc_compilation
= 2;
2103 /* FIXME:Do something here. */
2104 if (dip
->at_producer
!= NULL
)
2106 handle_producer (dip
->at_producer
);
2110 /* The compilation unit may be in a different language or objfile,
2111 zero out all remembered fundamental types. */
2112 memset (cu
->ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
2114 start_symtab (name
, comp_dir
, lowpc
);
2115 record_debugformat ("DWARF 2");
2117 initialize_cu_func_list (cu
);
2119 /* Process all dies in compilation unit. */
2120 if (die
->child
!= NULL
)
2122 child_die
= die
->child
;
2123 while (child_die
&& child_die
->tag
)
2125 process_die (child_die
, cu
);
2126 child_die
= sibling_die (child_die
);
2130 /* Decode line number information if present. */
2131 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2134 unsigned int line_offset
= DW_UNSND (attr
);
2135 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2138 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
2139 (void *) line_header
);
2140 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
);
2144 /* Decode macro information, if present. Dwarf 2 macro information
2145 refers to information in the line number info statement program
2146 header, so we can only read it if we've read the header
2148 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2149 if (attr
&& line_header
)
2151 unsigned int macro_offset
= DW_UNSND (attr
);
2152 dwarf_decode_macros (line_header
, macro_offset
,
2153 comp_dir
, abfd
, cu
);
2155 do_cleanups (back_to
);
2159 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2160 struct dwarf2_cu
*cu
)
2162 struct function_range
*thisfn
;
2164 thisfn
= (struct function_range
*)
2165 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct function_range
));
2166 thisfn
->name
= name
;
2167 thisfn
->lowpc
= lowpc
;
2168 thisfn
->highpc
= highpc
;
2169 thisfn
->seen_line
= 0;
2170 thisfn
->next
= NULL
;
2172 if (cu
->last_fn
== NULL
)
2173 cu
->first_fn
= thisfn
;
2175 cu
->last_fn
->next
= thisfn
;
2177 cu
->last_fn
= thisfn
;
2181 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2183 struct objfile
*objfile
= cu
->objfile
;
2184 struct context_stack
*new;
2187 struct die_info
*child_die
;
2188 struct attribute
*attr
;
2190 const char *previous_prefix
= processing_current_prefix
;
2191 struct cleanup
*back_to
= NULL
;
2194 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2196 name
= dwarf2_linkage_name (die
, cu
);
2198 /* Ignore functions with missing or empty names and functions with
2199 missing or invalid low and high pc attributes. */
2200 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2203 if (cu
->language
== language_cplus
)
2205 struct die_info
*spec_die
= die_specification (die
, cu
);
2207 /* NOTE: carlton/2004-01-23: We have to be careful in the
2208 presence of DW_AT_specification. For example, with GCC 3.4,
2213 // Definition of N::foo.
2217 then we'll have a tree of DIEs like this:
2219 1: DW_TAG_compile_unit
2220 2: DW_TAG_namespace // N
2221 3: DW_TAG_subprogram // declaration of N::foo
2222 4: DW_TAG_subprogram // definition of N::foo
2223 DW_AT_specification // refers to die #3
2225 Thus, when processing die #4, we have to pretend that we're
2226 in the context of its DW_AT_specification, namely the contex
2229 if (spec_die
!= NULL
)
2231 char *specification_prefix
= determine_prefix (spec_die
, cu
);
2232 processing_current_prefix
= specification_prefix
;
2233 back_to
= make_cleanup (xfree
, specification_prefix
);
2240 /* Record the function range for dwarf_decode_lines. */
2241 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
2243 if (objfile
->ei
.entry_point
>= lowpc
&&
2244 objfile
->ei
.entry_point
< highpc
)
2246 objfile
->ei
.entry_func_lowpc
= lowpc
;
2247 objfile
->ei
.entry_func_highpc
= highpc
;
2250 new = push_context (0, lowpc
);
2251 new->name
= new_symbol (die
, die
->type
, cu
);
2253 /* If there is a location expression for DW_AT_frame_base, record
2255 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
2257 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
2258 expression is being recorded directly in the function's symbol
2259 and not in a separate frame-base object. I guess this hack is
2260 to avoid adding some sort of frame-base adjunct/annex to the
2261 function's symbol :-(. The problem with doing this is that it
2262 results in a function symbol with a location expression that
2263 has nothing to do with the location of the function, ouch! The
2264 relationship should be: a function's symbol has-a frame base; a
2265 frame-base has-a location expression. */
2266 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
2268 cu
->list_in_scope
= &local_symbols
;
2270 if (die
->child
!= NULL
)
2272 child_die
= die
->child
;
2273 while (child_die
&& child_die
->tag
)
2275 process_die (child_die
, cu
);
2276 child_die
= sibling_die (child_die
);
2280 new = pop_context ();
2281 /* Make a block for the local symbols within. */
2282 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2283 lowpc
, highpc
, objfile
);
2285 /* In C++, we can have functions nested inside functions (e.g., when
2286 a function declares a class that has methods). This means that
2287 when we finish processing a function scope, we may need to go
2288 back to building a containing block's symbol lists. */
2289 local_symbols
= new->locals
;
2290 param_symbols
= new->params
;
2292 /* If we've finished processing a top-level function, subsequent
2293 symbols go in the file symbol list. */
2294 if (outermost_context_p ())
2295 cu
->list_in_scope
= &file_symbols
;
2297 processing_current_prefix
= previous_prefix
;
2298 if (back_to
!= NULL
)
2299 do_cleanups (back_to
);
2302 /* Process all the DIES contained within a lexical block scope. Start
2303 a new scope, process the dies, and then close the scope. */
2306 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2308 struct objfile
*objfile
= cu
->objfile
;
2309 struct context_stack
*new;
2310 CORE_ADDR lowpc
, highpc
;
2311 struct die_info
*child_die
;
2314 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2316 /* Ignore blocks with missing or invalid low and high pc attributes. */
2317 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2318 as multiple lexical blocks? Handling children in a sane way would
2319 be nasty. Might be easier to properly extend generic blocks to
2321 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2326 push_context (0, lowpc
);
2327 if (die
->child
!= NULL
)
2329 child_die
= die
->child
;
2330 while (child_die
&& child_die
->tag
)
2332 process_die (child_die
, cu
);
2333 child_die
= sibling_die (child_die
);
2336 new = pop_context ();
2338 if (local_symbols
!= NULL
)
2340 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
2343 local_symbols
= new->locals
;
2346 /* Get low and high pc attributes from a die. Return 1 if the attributes
2347 are present and valid, otherwise, return 0. Return -1 if the range is
2348 discontinuous, i.e. derived from DW_AT_ranges information. */
2350 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
2351 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
2353 struct objfile
*objfile
= cu
->objfile
;
2354 struct comp_unit_head
*cu_header
= &cu
->header
;
2355 struct attribute
*attr
;
2356 bfd
*obfd
= objfile
->obfd
;
2361 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
2364 high
= DW_ADDR (attr
);
2365 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
2367 low
= DW_ADDR (attr
);
2369 /* Found high w/o low attribute. */
2372 /* Found consecutive range of addresses. */
2377 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
2380 unsigned int addr_size
= cu_header
->addr_size
;
2381 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
2382 /* Value of the DW_AT_ranges attribute is the offset in the
2383 .debug_ranges section. */
2384 unsigned int offset
= DW_UNSND (attr
);
2385 /* Base address selection entry. */
2393 found_base
= cu_header
->base_known
;
2394 base
= cu_header
->base_address
;
2396 if (offset
>= dwarf_ranges_size
)
2398 complaint (&symfile_complaints
,
2399 "Offset %d out of bounds for DW_AT_ranges attribute",
2403 buffer
= dwarf_ranges_buffer
+ offset
;
2405 /* Read in the largest possible address. */
2406 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
2407 if ((marker
& mask
) == mask
)
2409 /* If we found the largest possible address, then
2410 read the base address. */
2411 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2412 buffer
+= 2 * addr_size
;
2413 offset
+= 2 * addr_size
;
2421 CORE_ADDR range_beginning
, range_end
;
2423 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
2424 buffer
+= addr_size
;
2425 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
2426 buffer
+= addr_size
;
2427 offset
+= 2 * addr_size
;
2429 /* An end of list marker is a pair of zero addresses. */
2430 if (range_beginning
== 0 && range_end
== 0)
2431 /* Found the end of list entry. */
2434 /* Each base address selection entry is a pair of 2 values.
2435 The first is the largest possible address, the second is
2436 the base address. Check for a base address here. */
2437 if ((range_beginning
& mask
) == mask
)
2439 /* If we found the largest possible address, then
2440 read the base address. */
2441 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2448 /* We have no valid base address for the ranges
2450 complaint (&symfile_complaints
,
2451 "Invalid .debug_ranges data (no base address)");
2455 range_beginning
+= base
;
2458 /* FIXME: This is recording everything as a low-high
2459 segment of consecutive addresses. We should have a
2460 data structure for discontiguous block ranges
2464 low
= range_beginning
;
2470 if (range_beginning
< low
)
2471 low
= range_beginning
;
2472 if (range_end
> high
)
2478 /* If the first entry is an end-of-list marker, the range
2479 describes an empty scope, i.e. no instructions. */
2489 /* When using the GNU linker, .gnu.linkonce. sections are used to
2490 eliminate duplicate copies of functions and vtables and such.
2491 The linker will arbitrarily choose one and discard the others.
2492 The AT_*_pc values for such functions refer to local labels in
2493 these sections. If the section from that file was discarded, the
2494 labels are not in the output, so the relocs get a value of 0.
2495 If this is a discarded function, mark the pc bounds as invalid,
2496 so that GDB will ignore it. */
2497 if (low
== 0 && (bfd_get_file_flags (obfd
) & HAS_RELOC
) == 0)
2505 /* Get the low and high pc's represented by the scope DIE, and store
2506 them in *LOWPC and *HIGHPC. If the correct values can't be
2507 determined, set *LOWPC to -1 and *HIGHPC to 0. */
2510 get_scope_pc_bounds (struct die_info
*die
,
2511 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2512 struct dwarf2_cu
*cu
)
2514 CORE_ADDR best_low
= (CORE_ADDR
) -1;
2515 CORE_ADDR best_high
= (CORE_ADDR
) 0;
2516 CORE_ADDR current_low
, current_high
;
2518 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
2520 best_low
= current_low
;
2521 best_high
= current_high
;
2525 struct die_info
*child
= die
->child
;
2527 while (child
&& child
->tag
)
2529 switch (child
->tag
) {
2530 case DW_TAG_subprogram
:
2531 if (dwarf2_get_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
))
2533 best_low
= min (best_low
, current_low
);
2534 best_high
= max (best_high
, current_high
);
2537 case DW_TAG_namespace
:
2538 /* FIXME: carlton/2004-01-16: Should we do this for
2539 DW_TAG_class_type/DW_TAG_structure_type, too? I think
2540 that current GCC's always emit the DIEs corresponding
2541 to definitions of methods of classes as children of a
2542 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
2543 the DIEs giving the declarations, which could be
2544 anywhere). But I don't see any reason why the
2545 standards says that they have to be there. */
2546 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
2548 if (current_low
!= ((CORE_ADDR
) -1))
2550 best_low
= min (best_low
, current_low
);
2551 best_high
= max (best_high
, current_high
);
2559 child
= sibling_die (child
);
2564 *highpc
= best_high
;
2567 /* Add an aggregate field to the field list. */
2570 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
2571 struct dwarf2_cu
*cu
)
2573 struct objfile
*objfile
= cu
->objfile
;
2574 struct nextfield
*new_field
;
2575 struct attribute
*attr
;
2577 char *fieldname
= "";
2579 /* Allocate a new field list entry and link it in. */
2580 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2581 make_cleanup (xfree
, new_field
);
2582 memset (new_field
, 0, sizeof (struct nextfield
));
2583 new_field
->next
= fip
->fields
;
2584 fip
->fields
= new_field
;
2587 /* Handle accessibility and virtuality of field.
2588 The default accessibility for members is public, the default
2589 accessibility for inheritance is private. */
2590 if (die
->tag
!= DW_TAG_inheritance
)
2591 new_field
->accessibility
= DW_ACCESS_public
;
2593 new_field
->accessibility
= DW_ACCESS_private
;
2594 new_field
->virtuality
= DW_VIRTUALITY_none
;
2596 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
2598 new_field
->accessibility
= DW_UNSND (attr
);
2599 if (new_field
->accessibility
!= DW_ACCESS_public
)
2600 fip
->non_public_fields
= 1;
2601 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
2603 new_field
->virtuality
= DW_UNSND (attr
);
2605 fp
= &new_field
->field
;
2607 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
2609 /* Data member other than a C++ static data member. */
2611 /* Get type of field. */
2612 fp
->type
= die_type (die
, cu
);
2614 FIELD_STATIC_KIND (*fp
) = 0;
2616 /* Get bit size of field (zero if none). */
2617 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
2620 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
2624 FIELD_BITSIZE (*fp
) = 0;
2627 /* Get bit offset of field. */
2628 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
2631 FIELD_BITPOS (*fp
) =
2632 decode_locdesc (DW_BLOCK (attr
), cu
) * bits_per_byte
;
2635 FIELD_BITPOS (*fp
) = 0;
2636 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
2639 if (BITS_BIG_ENDIAN
)
2641 /* For big endian bits, the DW_AT_bit_offset gives the
2642 additional bit offset from the MSB of the containing
2643 anonymous object to the MSB of the field. We don't
2644 have to do anything special since we don't need to
2645 know the size of the anonymous object. */
2646 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
2650 /* For little endian bits, compute the bit offset to the
2651 MSB of the anonymous object, subtract off the number of
2652 bits from the MSB of the field to the MSB of the
2653 object, and then subtract off the number of bits of
2654 the field itself. The result is the bit offset of
2655 the LSB of the field. */
2657 int bit_offset
= DW_UNSND (attr
);
2659 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
2662 /* The size of the anonymous object containing
2663 the bit field is explicit, so use the
2664 indicated size (in bytes). */
2665 anonymous_size
= DW_UNSND (attr
);
2669 /* The size of the anonymous object containing
2670 the bit field must be inferred from the type
2671 attribute of the data member containing the
2673 anonymous_size
= TYPE_LENGTH (fp
->type
);
2675 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2676 - bit_offset
- FIELD_BITSIZE (*fp
);
2680 /* Get name of field. */
2681 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2682 if (attr
&& DW_STRING (attr
))
2683 fieldname
= DW_STRING (attr
);
2685 /* The name is already allocated along with this objfile, so we don't
2686 need to duplicate it for the type. */
2687 fp
->name
= fieldname
;
2689 /* Change accessibility for artificial fields (e.g. virtual table
2690 pointer or virtual base class pointer) to private. */
2691 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
2693 new_field
->accessibility
= DW_ACCESS_private
;
2694 fip
->non_public_fields
= 1;
2697 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
2699 /* C++ static member. */
2701 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2702 is a declaration, but all versions of G++ as of this writing
2703 (so through at least 3.2.1) incorrectly generate
2704 DW_TAG_variable tags. */
2708 /* Get name of field. */
2709 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2710 if (attr
&& DW_STRING (attr
))
2711 fieldname
= DW_STRING (attr
);
2715 /* Get physical name. */
2716 physname
= dwarf2_linkage_name (die
, cu
);
2718 /* The name is already allocated along with this objfile, so we don't
2719 need to duplicate it for the type. */
2720 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
2721 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2722 FIELD_NAME (*fp
) = fieldname
;
2724 else if (die
->tag
== DW_TAG_inheritance
)
2726 /* C++ base class field. */
2727 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
2729 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
2731 FIELD_BITSIZE (*fp
) = 0;
2732 FIELD_STATIC_KIND (*fp
) = 0;
2733 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2734 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2735 fip
->nbaseclasses
++;
2739 /* Create the vector of fields, and attach it to the type. */
2742 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
2743 struct dwarf2_cu
*cu
)
2745 int nfields
= fip
->nfields
;
2747 /* Record the field count, allocate space for the array of fields,
2748 and create blank accessibility bitfields if necessary. */
2749 TYPE_NFIELDS (type
) = nfields
;
2750 TYPE_FIELDS (type
) = (struct field
*)
2751 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2752 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2754 if (fip
->non_public_fields
)
2756 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2758 TYPE_FIELD_PRIVATE_BITS (type
) =
2759 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2760 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2762 TYPE_FIELD_PROTECTED_BITS (type
) =
2763 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2764 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2766 TYPE_FIELD_IGNORE_BITS (type
) =
2767 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2768 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2771 /* If the type has baseclasses, allocate and clear a bit vector for
2772 TYPE_FIELD_VIRTUAL_BITS. */
2773 if (fip
->nbaseclasses
)
2775 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2778 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2779 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2780 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2781 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2782 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2785 /* Copy the saved-up fields into the field vector. Start from the head
2786 of the list, adding to the tail of the field array, so that they end
2787 up in the same order in the array in which they were added to the list. */
2788 while (nfields
-- > 0)
2790 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2791 switch (fip
->fields
->accessibility
)
2793 case DW_ACCESS_private
:
2794 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2797 case DW_ACCESS_protected
:
2798 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2801 case DW_ACCESS_public
:
2805 /* Unknown accessibility. Complain and treat it as public. */
2807 complaint (&symfile_complaints
, "unsupported accessibility %d",
2808 fip
->fields
->accessibility
);
2812 if (nfields
< fip
->nbaseclasses
)
2814 switch (fip
->fields
->virtuality
)
2816 case DW_VIRTUALITY_virtual
:
2817 case DW_VIRTUALITY_pure_virtual
:
2818 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2822 fip
->fields
= fip
->fields
->next
;
2826 /* Add a member function to the proper fieldlist. */
2829 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2830 struct type
*type
, struct dwarf2_cu
*cu
)
2832 struct objfile
*objfile
= cu
->objfile
;
2833 struct attribute
*attr
;
2834 struct fnfieldlist
*flp
;
2836 struct fn_field
*fnp
;
2839 struct nextfnfield
*new_fnfield
;
2841 /* Get name of member function. */
2842 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2843 if (attr
&& DW_STRING (attr
))
2844 fieldname
= DW_STRING (attr
);
2848 /* Get the mangled name. */
2849 physname
= dwarf2_linkage_name (die
, cu
);
2851 /* Look up member function name in fieldlist. */
2852 for (i
= 0; i
< fip
->nfnfields
; i
++)
2854 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
2858 /* Create new list element if necessary. */
2859 if (i
< fip
->nfnfields
)
2860 flp
= &fip
->fnfieldlists
[i
];
2863 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2865 fip
->fnfieldlists
= (struct fnfieldlist
*)
2866 xrealloc (fip
->fnfieldlists
,
2867 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2868 * sizeof (struct fnfieldlist
));
2869 if (fip
->nfnfields
== 0)
2870 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2872 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2873 flp
->name
= fieldname
;
2879 /* Create a new member function field and chain it to the field list
2881 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2882 make_cleanup (xfree
, new_fnfield
);
2883 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2884 new_fnfield
->next
= flp
->head
;
2885 flp
->head
= new_fnfield
;
2888 /* Fill in the member function field info. */
2889 fnp
= &new_fnfield
->fnfield
;
2890 /* The name is already allocated along with this objfile, so we don't
2891 need to duplicate it for the type. */
2892 fnp
->physname
= physname
? physname
: "";
2893 fnp
->type
= alloc_type (objfile
);
2894 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2896 int nparams
= TYPE_NFIELDS (die
->type
);
2898 /* TYPE is the domain of this method, and DIE->TYPE is the type
2899 of the method itself (TYPE_CODE_METHOD). */
2900 smash_to_method_type (fnp
->type
, type
,
2901 TYPE_TARGET_TYPE (die
->type
),
2902 TYPE_FIELDS (die
->type
),
2903 TYPE_NFIELDS (die
->type
),
2904 TYPE_VARARGS (die
->type
));
2906 /* Handle static member functions.
2907 Dwarf2 has no clean way to discern C++ static and non-static
2908 member functions. G++ helps GDB by marking the first
2909 parameter for non-static member functions (which is the
2910 this pointer) as artificial. We obtain this information
2911 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2912 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2913 fnp
->voffset
= VOFFSET_STATIC
;
2916 complaint (&symfile_complaints
, "member function type missing for '%s'",
2919 /* Get fcontext from DW_AT_containing_type if present. */
2920 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
2921 fnp
->fcontext
= die_containing_type (die
, cu
);
2923 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2924 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2926 /* Get accessibility. */
2927 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
2930 switch (DW_UNSND (attr
))
2932 case DW_ACCESS_private
:
2933 fnp
->is_private
= 1;
2935 case DW_ACCESS_protected
:
2936 fnp
->is_protected
= 1;
2941 /* Check for artificial methods. */
2942 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
2943 if (attr
&& DW_UNSND (attr
) != 0)
2944 fnp
->is_artificial
= 1;
2946 /* Get index in virtual function table if it is a virtual member function. */
2947 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
2950 /* Support the .debug_loc offsets */
2951 if (attr_form_is_block (attr
))
2953 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
2955 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
2957 dwarf2_complex_location_expr_complaint ();
2961 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
2967 /* Create the vector of member function fields, and attach it to the type. */
2970 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2971 struct dwarf2_cu
*cu
)
2973 struct fnfieldlist
*flp
;
2974 int total_length
= 0;
2977 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2978 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2979 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2981 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2983 struct nextfnfield
*nfp
= flp
->head
;
2984 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2987 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2988 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2989 fn_flp
->fn_fields
= (struct fn_field
*)
2990 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2991 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2992 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2994 total_length
+= flp
->length
;
2997 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2998 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3001 /* Called when we find the DIE that starts a structure or union scope
3002 (definition) to process all dies that define the members of the
3005 NOTE: we need to call struct_type regardless of whether or not the
3006 DIE has an at_name attribute, since it might be an anonymous
3007 structure or union. This gets the type entered into our set of
3010 However, if the structure is incomplete (an opaque struct/union)
3011 then suppress creating a symbol table entry for it since gdb only
3012 wants to find the one with the complete definition. Note that if
3013 it is complete, we just call new_symbol, which does it's own
3014 checking about whether the struct/union is anonymous or not (and
3015 suppresses creating a symbol table entry itself). */
3018 read_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3020 struct objfile
*objfile
= cu
->objfile
;
3022 struct attribute
*attr
;
3024 const char *previous_prefix
= processing_current_prefix
;
3025 struct cleanup
*back_to
= NULL
;
3026 /* This says whether or not we want to try to update the structure's
3027 name to include enclosing namespace/class information, if
3029 int need_to_update_name
= 0;
3031 type
= alloc_type (objfile
);
3033 INIT_CPLUS_SPECIFIC (type
);
3034 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3035 if (attr
&& DW_STRING (attr
))
3037 name
= DW_STRING (attr
);
3039 if (cu
->language
== language_cplus
)
3041 struct die_info
*spec_die
= die_specification (die
, cu
);
3043 if (spec_die
!= NULL
)
3045 char *specification_prefix
= determine_prefix (spec_die
, cu
);
3046 processing_current_prefix
= specification_prefix
;
3047 back_to
= make_cleanup (xfree
, specification_prefix
);
3051 if (processing_has_namespace_info
)
3053 /* FIXME: carlton/2003-11-10: This variable exists only for
3054 const-correctness reasons. When I tried to change
3055 TYPE_TAG_NAME to be a const char *, I ran into a cascade
3056 of changes which would have forced decode_line_1 to take
3058 char *new_prefix
= obconcat (&objfile
->objfile_obstack
,
3059 processing_current_prefix
,
3060 processing_current_prefix
[0] == '\0'
3063 TYPE_TAG_NAME (type
) = new_prefix
;
3064 processing_current_prefix
= new_prefix
;
3068 /* The name is already allocated along with this objfile, so
3069 we don't need to duplicate it for the type. */
3070 TYPE_TAG_NAME (type
) = name
;
3071 need_to_update_name
= (cu
->language
== language_cplus
);
3075 if (die
->tag
== DW_TAG_structure_type
)
3077 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
3079 else if (die
->tag
== DW_TAG_union_type
)
3081 TYPE_CODE (type
) = TYPE_CODE_UNION
;
3085 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
3087 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
3090 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3093 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3097 TYPE_LENGTH (type
) = 0;
3100 /* We need to add the type field to the die immediately so we don't
3101 infinitely recurse when dealing with pointers to the structure
3102 type within the structure itself. */
3105 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
3107 struct field_info fi
;
3108 struct die_info
*child_die
;
3109 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
3111 memset (&fi
, 0, sizeof (struct field_info
));
3113 child_die
= die
->child
;
3115 while (child_die
&& child_die
->tag
)
3117 if (child_die
->tag
== DW_TAG_member
3118 || child_die
->tag
== DW_TAG_variable
)
3120 /* NOTE: carlton/2002-11-05: A C++ static data member
3121 should be a DW_TAG_member that is a declaration, but
3122 all versions of G++ as of this writing (so through at
3123 least 3.2.1) incorrectly generate DW_TAG_variable
3124 tags for them instead. */
3125 dwarf2_add_field (&fi
, child_die
, cu
);
3127 else if (child_die
->tag
== DW_TAG_subprogram
)
3129 /* C++ member function. */
3130 process_die (child_die
, cu
);
3131 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
3132 if (need_to_update_name
)
3134 /* The demangled names of member functions contain
3135 information about enclosing namespaces/classes,
3138 /* FIXME: carlton/2003-11-10: The excessive
3139 demangling here is a bit wasteful, as is the
3140 memory usage for names. */
3142 /* NOTE: carlton/2003-11-10: As commented in
3143 add_partial_structure, the demangler sometimes
3144 prints the type info in a different form from the
3145 debug info. We could solve this by using the
3146 demangled name to get the prefix; if doing so,
3147 however, we'd need to be careful when reading a
3148 class that's nested inside a template class.
3149 That would also cause problems when trying to
3150 determine RTTI information, since we use the
3151 demangler to determine the appropriate class
3153 char *actual_class_name
3154 = class_name_from_physname (dwarf2_linkage_name
3156 if (actual_class_name
!= NULL
3157 && strcmp (actual_class_name
, name
) != 0)
3159 TYPE_TAG_NAME (type
)
3160 = obsavestring (actual_class_name
,
3161 strlen (actual_class_name
),
3162 &objfile
->objfile_obstack
);
3164 xfree (actual_class_name
);
3165 need_to_update_name
= 0;
3168 else if (child_die
->tag
== DW_TAG_inheritance
)
3170 /* C++ base class field. */
3171 dwarf2_add_field (&fi
, child_die
, cu
);
3175 process_die (child_die
, cu
);
3177 child_die
= sibling_die (child_die
);
3180 /* Attach fields and member functions to the type. */
3182 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
3185 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
3187 /* Get the type which refers to the base class (possibly this
3188 class itself) which contains the vtable pointer for the current
3189 class from the DW_AT_containing_type attribute. */
3191 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3193 struct type
*t
= die_containing_type (die
, cu
);
3195 TYPE_VPTR_BASETYPE (type
) = t
;
3198 static const char vptr_name
[] =
3199 {'_', 'v', 'p', 't', 'r', '\0'};
3202 /* Our own class provides vtbl ptr. */
3203 for (i
= TYPE_NFIELDS (t
) - 1;
3204 i
>= TYPE_N_BASECLASSES (t
);
3207 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
3209 if ((strncmp (fieldname
, vptr_name
,
3210 strlen (vptr_name
) - 1)
3212 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
3214 TYPE_VPTR_FIELDNO (type
) = i
;
3219 /* Complain if virtual function table field not found. */
3220 if (i
< TYPE_N_BASECLASSES (t
))
3221 complaint (&symfile_complaints
,
3222 "virtual function table pointer not found when defining class '%s'",
3223 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
3228 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3233 new_symbol (die
, type
, cu
);
3235 do_cleanups (back_to
);
3239 /* No children, must be stub. */
3240 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
3243 processing_current_prefix
= previous_prefix
;
3244 if (back_to
!= NULL
)
3245 do_cleanups (back_to
);
3248 /* Given a pointer to a die which begins an enumeration, process all
3249 the dies that define the members of the enumeration.
3251 This will be much nicer in draft 6 of the DWARF spec when our
3252 members will be dies instead squished into the DW_AT_element_list
3255 NOTE: We reverse the order of the element list. */
3258 read_enumeration (struct die_info
*die
, struct dwarf2_cu
*cu
)
3260 struct objfile
*objfile
= cu
->objfile
;
3261 struct die_info
*child_die
;
3263 struct field
*fields
;
3264 struct attribute
*attr
;
3267 int unsigned_enum
= 1;
3269 type
= alloc_type (objfile
);
3271 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
3272 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3273 if (attr
&& DW_STRING (attr
))
3275 char *name
= DW_STRING (attr
);
3277 if (processing_has_namespace_info
)
3279 TYPE_TAG_NAME (type
) = obconcat (&objfile
->objfile_obstack
,
3280 processing_current_prefix
,
3281 processing_current_prefix
[0] == '\0'
3287 /* The name is already allocated along with this objfile, so
3288 we don't need to duplicate it for the type. */
3289 TYPE_TAG_NAME (type
) = name
;
3293 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3296 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3300 TYPE_LENGTH (type
) = 0;
3305 if (die
->child
!= NULL
)
3307 child_die
= die
->child
;
3308 while (child_die
&& child_die
->tag
)
3310 if (child_die
->tag
!= DW_TAG_enumerator
)
3312 process_die (child_die
, cu
);
3316 attr
= dwarf2_attr (child_die
, DW_AT_name
, cu
);
3319 sym
= new_symbol (child_die
, type
, cu
);
3320 if (SYMBOL_VALUE (sym
) < 0)
3323 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3325 fields
= (struct field
*)
3327 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
3328 * sizeof (struct field
));
3331 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
3332 FIELD_TYPE (fields
[num_fields
]) = NULL
;
3333 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
3334 FIELD_BITSIZE (fields
[num_fields
]) = 0;
3335 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
3341 child_die
= sibling_die (child_die
);
3346 TYPE_NFIELDS (type
) = num_fields
;
3347 TYPE_FIELDS (type
) = (struct field
*)
3348 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
3349 memcpy (TYPE_FIELDS (type
), fields
,
3350 sizeof (struct field
) * num_fields
);
3354 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
3357 new_symbol (die
, type
, cu
);
3360 /* Extract all information from a DW_TAG_array_type DIE and put it in
3361 the DIE's type field. For now, this only handles one dimensional
3365 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3367 struct objfile
*objfile
= cu
->objfile
;
3368 struct die_info
*child_die
;
3369 struct type
*type
= NULL
;
3370 struct type
*element_type
, *range_type
, *index_type
;
3371 struct type
**range_types
= NULL
;
3372 struct attribute
*attr
;
3374 struct cleanup
*back_to
;
3376 /* Return if we've already decoded this type. */
3382 element_type
= die_type (die
, cu
);
3384 /* Irix 6.2 native cc creates array types without children for
3385 arrays with unspecified length. */
3386 if (die
->child
== NULL
)
3388 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
3389 range_type
= create_range_type (NULL
, index_type
, 0, -1);
3390 die
->type
= create_array_type (NULL
, element_type
, range_type
);
3394 back_to
= make_cleanup (null_cleanup
, NULL
);
3395 child_die
= die
->child
;
3396 while (child_die
&& child_die
->tag
)
3398 if (child_die
->tag
== DW_TAG_subrange_type
)
3400 read_subrange_type (child_die
, cu
);
3402 if (child_die
->type
!= NULL
)
3404 /* The range type was succesfully read. Save it for
3405 the array type creation. */
3406 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
3408 range_types
= (struct type
**)
3409 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
3410 * sizeof (struct type
*));
3412 make_cleanup (free_current_contents
, &range_types
);
3414 range_types
[ndim
++] = child_die
->type
;
3417 child_die
= sibling_die (child_die
);
3420 /* Dwarf2 dimensions are output from left to right, create the
3421 necessary array types in backwards order. */
3422 type
= element_type
;
3424 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
3426 /* Understand Dwarf2 support for vector types (like they occur on
3427 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3428 array type. This is not part of the Dwarf2/3 standard yet, but a
3429 custom vendor extension. The main difference between a regular
3430 array and the vector variant is that vectors are passed by value
3432 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
3434 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
3436 do_cleanups (back_to
);
3438 /* Install the type in the die. */
3442 /* First cut: install each common block member as a global variable. */
3445 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
3447 struct die_info
*child_die
;
3448 struct attribute
*attr
;
3450 CORE_ADDR base
= (CORE_ADDR
) 0;
3452 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
3455 /* Support the .debug_loc offsets */
3456 if (attr_form_is_block (attr
))
3458 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
3460 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3462 dwarf2_complex_location_expr_complaint ();
3466 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3467 "common block member");
3470 if (die
->child
!= NULL
)
3472 child_die
= die
->child
;
3473 while (child_die
&& child_die
->tag
)
3475 sym
= new_symbol (child_die
, NULL
, cu
);
3476 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
3479 SYMBOL_VALUE_ADDRESS (sym
) =
3480 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
3481 add_symbol_to_list (sym
, &global_symbols
);
3483 child_die
= sibling_die (child_die
);
3488 /* Read a C++ namespace. */
3491 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
3493 struct objfile
*objfile
= cu
->objfile
;
3494 const char *previous_prefix
= processing_current_prefix
;
3497 struct die_info
*current_die
;
3499 name
= namespace_name (die
, &is_anonymous
, cu
);
3501 /* Now build the name of the current namespace. */
3503 if (previous_prefix
[0] == '\0')
3505 processing_current_prefix
= name
;
3509 /* We need temp_name around because processing_current_prefix
3510 is a const char *. */
3511 char *temp_name
= alloca (strlen (previous_prefix
)
3512 + 2 + strlen(name
) + 1);
3513 strcpy (temp_name
, previous_prefix
);
3514 strcat (temp_name
, "::");
3515 strcat (temp_name
, name
);
3517 processing_current_prefix
= temp_name
;
3520 /* Add a symbol associated to this if we haven't seen the namespace
3521 before. Also, add a using directive if it's an anonymous
3524 if (dwarf2_extension (die
, cu
) == NULL
)
3528 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
3529 this cast will hopefully become unnecessary. */
3530 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
3531 (char *) processing_current_prefix
,
3533 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
3535 new_symbol (die
, type
, cu
);
3538 cp_add_using_directive (processing_current_prefix
,
3539 strlen (previous_prefix
),
3540 strlen (processing_current_prefix
));
3543 if (die
->child
!= NULL
)
3545 struct die_info
*child_die
= die
->child
;
3547 while (child_die
&& child_die
->tag
)
3549 process_die (child_die
, cu
);
3550 child_die
= sibling_die (child_die
);
3554 processing_current_prefix
= previous_prefix
;
3557 /* Return the name of the namespace represented by DIE. Set
3558 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
3562 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
3564 struct die_info
*current_die
;
3565 const char *name
= NULL
;
3567 /* Loop through the extensions until we find a name. */
3569 for (current_die
= die
;
3570 current_die
!= NULL
;
3571 current_die
= dwarf2_extension (die
, cu
))
3573 name
= dwarf2_name (current_die
, cu
);
3578 /* Is it an anonymous namespace? */
3580 *is_anonymous
= (name
== NULL
);
3582 name
= "(anonymous namespace)";
3587 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3588 the user defined type vector. */
3591 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3593 struct comp_unit_head
*cu_header
= &cu
->header
;
3595 struct attribute
*attr_byte_size
;
3596 struct attribute
*attr_address_class
;
3597 int byte_size
, addr_class
;
3604 type
= lookup_pointer_type (die_type (die
, cu
));
3606 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3608 byte_size
= DW_UNSND (attr_byte_size
);
3610 byte_size
= cu_header
->addr_size
;
3612 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
3613 if (attr_address_class
)
3614 addr_class
= DW_UNSND (attr_address_class
);
3616 addr_class
= DW_ADDR_none
;
3618 /* If the pointer size or address class is different than the
3619 default, create a type variant marked as such and set the
3620 length accordingly. */
3621 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
3623 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3627 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
3628 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
3629 type
= make_type_with_address_space (type
, type_flags
);
3631 else if (TYPE_LENGTH (type
) != byte_size
)
3633 complaint (&symfile_complaints
, "invalid pointer size %d", byte_size
);
3636 /* Should we also complain about unhandled address classes? */
3640 TYPE_LENGTH (type
) = byte_size
;
3644 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3645 the user defined type vector. */
3648 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3650 struct objfile
*objfile
= cu
->objfile
;
3652 struct type
*to_type
;
3653 struct type
*domain
;
3660 type
= alloc_type (objfile
);
3661 to_type
= die_type (die
, cu
);
3662 domain
= die_containing_type (die
, cu
);
3663 smash_to_member_type (type
, domain
, to_type
);
3668 /* Extract all information from a DW_TAG_reference_type DIE and add to
3669 the user defined type vector. */
3672 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3674 struct comp_unit_head
*cu_header
= &cu
->header
;
3676 struct attribute
*attr
;
3683 type
= lookup_reference_type (die_type (die
, cu
));
3684 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3687 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3691 TYPE_LENGTH (type
) = cu_header
->addr_size
;
3697 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3699 struct type
*base_type
;
3706 base_type
= die_type (die
, cu
);
3707 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
3711 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3713 struct type
*base_type
;
3720 base_type
= die_type (die
, cu
);
3721 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
3724 /* Extract all information from a DW_TAG_string_type DIE and add to
3725 the user defined type vector. It isn't really a user defined type,
3726 but it behaves like one, with other DIE's using an AT_user_def_type
3727 attribute to reference it. */
3730 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3732 struct objfile
*objfile
= cu
->objfile
;
3733 struct type
*type
, *range_type
, *index_type
, *char_type
;
3734 struct attribute
*attr
;
3735 unsigned int length
;
3742 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
3745 length
= DW_UNSND (attr
);
3749 /* check for the DW_AT_byte_size attribute */
3750 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3753 length
= DW_UNSND (attr
);
3760 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
3761 range_type
= create_range_type (NULL
, index_type
, 1, length
);
3762 if (cu
->language
== language_fortran
)
3764 /* Need to create a unique string type for bounds
3766 type
= create_string_type (0, range_type
);
3770 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
, cu
);
3771 type
= create_string_type (char_type
, range_type
);
3776 /* Handle DIES due to C code like:
3780 int (*funcp)(int a, long l);
3784 ('funcp' generates a DW_TAG_subroutine_type DIE)
3788 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3790 struct type
*type
; /* Type that this function returns */
3791 struct type
*ftype
; /* Function that returns above type */
3792 struct attribute
*attr
;
3794 /* Decode the type that this subroutine returns */
3799 type
= die_type (die
, cu
);
3800 ftype
= lookup_function_type (type
);
3802 /* All functions in C++ have prototypes. */
3803 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
3804 if ((attr
&& (DW_UNSND (attr
) != 0))
3805 || cu
->language
== language_cplus
)
3806 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
3808 if (die
->child
!= NULL
)
3810 struct die_info
*child_die
;
3814 /* Count the number of parameters.
3815 FIXME: GDB currently ignores vararg functions, but knows about
3816 vararg member functions. */
3817 child_die
= die
->child
;
3818 while (child_die
&& child_die
->tag
)
3820 if (child_die
->tag
== DW_TAG_formal_parameter
)
3822 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
3823 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
3824 child_die
= sibling_die (child_die
);
3827 /* Allocate storage for parameters and fill them in. */
3828 TYPE_NFIELDS (ftype
) = nparams
;
3829 TYPE_FIELDS (ftype
) = (struct field
*)
3830 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
3832 child_die
= die
->child
;
3833 while (child_die
&& child_die
->tag
)
3835 if (child_die
->tag
== DW_TAG_formal_parameter
)
3837 /* Dwarf2 has no clean way to discern C++ static and non-static
3838 member functions. G++ helps GDB by marking the first
3839 parameter for non-static member functions (which is the
3840 this pointer) as artificial. We pass this information
3841 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
3842 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
3844 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
3846 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
3847 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
3850 child_die
= sibling_die (child_die
);
3858 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
3860 struct objfile
*objfile
= cu
->objfile
;
3861 struct attribute
*attr
;
3866 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3867 if (attr
&& DW_STRING (attr
))
3869 name
= DW_STRING (attr
);
3871 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
3872 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, cu
);
3876 /* Find a representation of a given base type and install
3877 it in the TYPE field of the die. */
3880 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3882 struct objfile
*objfile
= cu
->objfile
;
3884 struct attribute
*attr
;
3885 int encoding
= 0, size
= 0;
3887 /* If we've already decoded this die, this is a no-op. */
3893 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
3896 encoding
= DW_UNSND (attr
);
3898 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3901 size
= DW_UNSND (attr
);
3903 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3904 if (attr
&& DW_STRING (attr
))
3906 enum type_code code
= TYPE_CODE_INT
;
3911 case DW_ATE_address
:
3912 /* Turn DW_ATE_address into a void * pointer. */
3913 code
= TYPE_CODE_PTR
;
3914 type_flags
|= TYPE_FLAG_UNSIGNED
;
3916 case DW_ATE_boolean
:
3917 code
= TYPE_CODE_BOOL
;
3918 type_flags
|= TYPE_FLAG_UNSIGNED
;
3920 case DW_ATE_complex_float
:
3921 code
= TYPE_CODE_COMPLEX
;
3924 code
= TYPE_CODE_FLT
;
3927 case DW_ATE_signed_char
:
3929 case DW_ATE_unsigned
:
3930 case DW_ATE_unsigned_char
:
3931 type_flags
|= TYPE_FLAG_UNSIGNED
;
3934 complaint (&symfile_complaints
, "unsupported DW_AT_encoding: '%s'",
3935 dwarf_type_encoding_name (encoding
));
3938 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
3939 if (encoding
== DW_ATE_address
)
3940 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
,
3942 else if (encoding
== DW_ATE_complex_float
)
3945 TYPE_TARGET_TYPE (type
)
3946 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
, cu
);
3947 else if (size
== 16)
3948 TYPE_TARGET_TYPE (type
)
3949 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
3951 TYPE_TARGET_TYPE (type
)
3952 = dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
3957 type
= dwarf_base_type (encoding
, size
, cu
);
3962 /* Read the given DW_AT_subrange DIE. */
3965 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3967 struct type
*base_type
;
3968 struct type
*range_type
;
3969 struct attribute
*attr
;
3973 /* If we have already decoded this die, then nothing more to do. */
3977 base_type
= die_type (die
, cu
);
3978 if (base_type
== NULL
)
3980 complaint (&symfile_complaints
,
3981 "DW_AT_type missing from DW_TAG_subrange_type");
3985 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
3986 base_type
= alloc_type (NULL
);
3988 if (cu
->language
== language_fortran
)
3990 /* FORTRAN implies a lower bound of 1, if not given. */
3994 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
3996 low
= dwarf2_get_attr_constant_value (attr
, 0);
3998 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
4001 if (attr
->form
== DW_FORM_block1
)
4003 /* GCC encodes arrays with unspecified or dynamic length
4004 with a DW_FORM_block1 attribute.
4005 FIXME: GDB does not yet know how to handle dynamic
4006 arrays properly, treat them as arrays with unspecified
4009 FIXME: jimb/2003-09-22: GDB does not really know
4010 how to handle arrays of unspecified length
4011 either; we just represent them as zero-length
4012 arrays. Choose an appropriate upper bound given
4013 the lower bound we've computed above. */
4017 high
= dwarf2_get_attr_constant_value (attr
, 1);
4020 range_type
= create_range_type (NULL
, base_type
, low
, high
);
4022 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4023 if (attr
&& DW_STRING (attr
))
4024 TYPE_NAME (range_type
) = DW_STRING (attr
);
4026 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4028 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
4030 die
->type
= range_type
;
4034 /* Read a whole compilation unit into a linked list of dies. */
4036 static struct die_info
*
4037 read_comp_unit (char *info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
4039 /* Reset die reference table; we are
4040 building new ones now. */
4041 dwarf2_empty_hash_tables ();
4043 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
4046 /* Read a single die and all its descendents. Set the die's sibling
4047 field to NULL; set other fields in the die correctly, and set all
4048 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
4049 location of the info_ptr after reading all of those dies. PARENT
4050 is the parent of the die in question. */
4052 static struct die_info
*
4053 read_die_and_children (char *info_ptr
, bfd
*abfd
,
4054 struct dwarf2_cu
*cu
,
4055 char **new_info_ptr
,
4056 struct die_info
*parent
)
4058 struct die_info
*die
;
4062 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
4063 store_in_ref_table (die
->offset
, die
);
4067 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
4073 *new_info_ptr
= cur_ptr
;
4076 die
->sibling
= NULL
;
4077 die
->parent
= parent
;
4081 /* Read a die, all of its descendents, and all of its siblings; set
4082 all of the fields of all of the dies correctly. Arguments are as
4083 in read_die_and_children. */
4085 static struct die_info
*
4086 read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
4087 struct dwarf2_cu
*cu
,
4088 char **new_info_ptr
,
4089 struct die_info
*parent
)
4091 struct die_info
*first_die
, *last_sibling
;
4095 first_die
= last_sibling
= NULL
;
4099 struct die_info
*die
4100 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
4108 last_sibling
->sibling
= die
;
4113 *new_info_ptr
= cur_ptr
;
4123 /* Free a linked list of dies. */
4126 free_die_list (struct die_info
*dies
)
4128 struct die_info
*die
, *next
;
4133 if (die
->child
!= NULL
)
4134 free_die_list (die
->child
);
4135 next
= die
->sibling
;
4143 do_free_die_list_cleanup (void *dies
)
4145 free_die_list (dies
);
4148 static struct cleanup
*
4149 make_cleanup_free_die_list (struct die_info
*dies
)
4151 return make_cleanup (do_free_die_list_cleanup
, dies
);
4155 /* Read the contents of the section at OFFSET and of size SIZE from the
4156 object file specified by OBJFILE into the objfile_obstack and return it. */
4159 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
4161 bfd
*abfd
= objfile
->obfd
;
4163 bfd_size_type size
= bfd_get_section_size_before_reloc (sectp
);
4168 buf
= (char *) obstack_alloc (&objfile
->objfile_obstack
, size
);
4170 = (char *) symfile_relocate_debug_section (abfd
, sectp
, (bfd_byte
*) buf
);
4174 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
4175 || bfd_bread (buf
, size
, abfd
) != size
)
4176 error ("Dwarf Error: Can't read DWARF data from '%s'",
4177 bfd_get_filename (abfd
));
4182 /* In DWARF version 2, the description of the debugging information is
4183 stored in a separate .debug_abbrev section. Before we read any
4184 dies from a section we read in all abbreviations and install them
4188 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
4190 struct comp_unit_head
*cu_header
= &cu
->header
;
4192 struct abbrev_info
*cur_abbrev
;
4193 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
4194 unsigned int abbrev_form
, hash_number
;
4195 struct attr_abbrev
*cur_attrs
;
4196 unsigned int allocated_attrs
;
4198 /* Initialize dwarf2 abbrevs */
4199 obstack_init (&cu
->abbrev_obstack
);
4200 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
4202 * sizeof (struct abbrev_info
*)));
4203 memset (cu
->dwarf2_abbrevs
, 0,
4204 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
4206 abbrev_ptr
= dwarf_abbrev_buffer
+ cu_header
->abbrev_offset
;
4207 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4208 abbrev_ptr
+= bytes_read
;
4210 allocated_attrs
= ATTR_ALLOC_CHUNK
;
4211 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
4213 /* loop until we reach an abbrev number of 0 */
4214 while (abbrev_number
)
4216 cur_abbrev
= dwarf_alloc_abbrev (cu
);
4218 /* read in abbrev header */
4219 cur_abbrev
->number
= abbrev_number
;
4220 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4221 abbrev_ptr
+= bytes_read
;
4222 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
4225 /* now read in declarations */
4226 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4227 abbrev_ptr
+= bytes_read
;
4228 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4229 abbrev_ptr
+= bytes_read
;
4232 if (cur_abbrev
->num_attrs
== allocated_attrs
)
4234 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
4236 = xrealloc (cur_attrs
, (allocated_attrs
4237 * sizeof (struct attr_abbrev
)));
4239 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
4240 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
4241 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4242 abbrev_ptr
+= bytes_read
;
4243 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4244 abbrev_ptr
+= bytes_read
;
4247 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
4248 (cur_abbrev
->num_attrs
4249 * sizeof (struct attr_abbrev
)));
4250 memcpy (cur_abbrev
->attrs
, cur_attrs
,
4251 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
4253 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
4254 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
4255 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
4257 /* Get next abbreviation.
4258 Under Irix6 the abbreviations for a compilation unit are not
4259 always properly terminated with an abbrev number of 0.
4260 Exit loop if we encounter an abbreviation which we have
4261 already read (which means we are about to read the abbreviations
4262 for the next compile unit) or if the end of the abbreviation
4263 table is reached. */
4264 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
4265 >= dwarf_abbrev_size
)
4267 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4268 abbrev_ptr
+= bytes_read
;
4269 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
4276 /* Release the memory used by the abbrev table for a compilation unit. */
4279 dwarf2_free_abbrev_table (void *ptr_to_cu
)
4281 struct dwarf2_cu
*cu
= ptr_to_cu
;
4283 obstack_free (&cu
->abbrev_obstack
, NULL
);
4284 cu
->dwarf2_abbrevs
= NULL
;
4287 /* Lookup an abbrev_info structure in the abbrev hash table. */
4289 static struct abbrev_info
*
4290 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
4292 unsigned int hash_number
;
4293 struct abbrev_info
*abbrev
;
4295 hash_number
= number
% ABBREV_HASH_SIZE
;
4296 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
4300 if (abbrev
->number
== number
)
4303 abbrev
= abbrev
->next
;
4308 /* Read a minimal amount of information into the minimal die structure. */
4311 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
4312 char *info_ptr
, struct dwarf2_cu
*cu
)
4314 unsigned int abbrev_number
, bytes_read
, i
;
4315 struct abbrev_info
*abbrev
;
4316 struct attribute attr
;
4317 struct attribute spec_attr
;
4318 int found_spec_attr
= 0;
4319 int has_low_pc_attr
= 0;
4320 int has_high_pc_attr
= 0;
4322 *part_die
= zeroed_partial_die
;
4323 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4324 info_ptr
+= bytes_read
;
4328 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4331 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number
,
4332 bfd_get_filename (abfd
));
4334 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
4335 part_die
->tag
= abbrev
->tag
;
4336 part_die
->has_children
= abbrev
->has_children
;
4337 part_die
->abbrev
= abbrev_number
;
4339 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4341 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
4343 /* Store the data if it is of an attribute we want to keep in a
4344 partial symbol table. */
4349 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
4350 if (part_die
->name
== NULL
)
4351 part_die
->name
= DW_STRING (&attr
);
4353 case DW_AT_MIPS_linkage_name
:
4354 part_die
->name
= DW_STRING (&attr
);
4357 has_low_pc_attr
= 1;
4358 part_die
->lowpc
= DW_ADDR (&attr
);
4361 has_high_pc_attr
= 1;
4362 part_die
->highpc
= DW_ADDR (&attr
);
4364 case DW_AT_location
:
4365 /* Support the .debug_loc offsets */
4366 if (attr_form_is_block (&attr
))
4368 part_die
->locdesc
= DW_BLOCK (&attr
);
4370 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
4372 dwarf2_complex_location_expr_complaint ();
4376 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4377 "partial symbol information");
4380 case DW_AT_language
:
4381 part_die
->language
= DW_UNSND (&attr
);
4383 case DW_AT_external
:
4384 part_die
->is_external
= DW_UNSND (&attr
);
4386 case DW_AT_declaration
:
4387 part_die
->is_declaration
= DW_UNSND (&attr
);
4390 part_die
->has_type
= 1;
4392 case DW_AT_abstract_origin
:
4393 case DW_AT_specification
:
4394 found_spec_attr
= 1;
4398 /* Ignore absolute siblings, they might point outside of
4399 the current compile unit. */
4400 if (attr
.form
== DW_FORM_ref_addr
)
4401 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
4404 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
, cu
);
4411 /* If we found a reference attribute and the die has no name, try
4412 to find a name in the referred to die. */
4414 if (found_spec_attr
&& part_die
->name
== NULL
)
4416 struct partial_die_info spec_die
;
4419 spec_ptr
= dwarf_info_buffer
4420 + dwarf2_get_ref_die_offset (&spec_attr
, cu
);
4421 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu
);
4424 part_die
->name
= spec_die
.name
;
4426 /* Copy DW_AT_external attribute if it is set. */
4427 if (spec_die
.is_external
)
4428 part_die
->is_external
= spec_die
.is_external
;
4432 /* When using the GNU linker, .gnu.linkonce. sections are used to
4433 eliminate duplicate copies of functions and vtables and such.
4434 The linker will arbitrarily choose one and discard the others.
4435 The AT_*_pc values for such functions refer to local labels in
4436 these sections. If the section from that file was discarded, the
4437 labels are not in the output, so the relocs get a value of 0.
4438 If this is a discarded function, mark the pc bounds as invalid,
4439 so that GDB will ignore it. */
4440 if (has_low_pc_attr
&& has_high_pc_attr
4441 && part_die
->lowpc
< part_die
->highpc
4442 && (part_die
->lowpc
!= 0
4443 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
4444 part_die
->has_pc_info
= 1;
4448 /* Read the die from the .debug_info section buffer. Set DIEP to
4449 point to a newly allocated die with its information, except for its
4450 child, sibling, and parent fields. Set HAS_CHILDREN to tell
4451 whether the die has children or not. */
4454 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
4455 struct dwarf2_cu
*cu
, int *has_children
)
4457 unsigned int abbrev_number
, bytes_read
, i
, offset
;
4458 struct abbrev_info
*abbrev
;
4459 struct die_info
*die
;
4461 offset
= info_ptr
- dwarf_info_buffer
;
4462 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4463 info_ptr
+= bytes_read
;
4466 die
= dwarf_alloc_die ();
4468 die
->abbrev
= abbrev_number
;
4475 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4478 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
4480 bfd_get_filename (abfd
));
4482 die
= dwarf_alloc_die ();
4483 die
->offset
= offset
;
4484 die
->tag
= abbrev
->tag
;
4485 die
->abbrev
= abbrev_number
;
4488 die
->num_attrs
= abbrev
->num_attrs
;
4489 die
->attrs
= (struct attribute
*)
4490 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
4492 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4494 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
4495 abfd
, info_ptr
, cu
);
4499 *has_children
= abbrev
->has_children
;
4503 /* Read an attribute value described by an attribute form. */
4506 read_attribute_value (struct attribute
*attr
, unsigned form
,
4507 bfd
*abfd
, char *info_ptr
,
4508 struct dwarf2_cu
*cu
)
4510 struct comp_unit_head
*cu_header
= &cu
->header
;
4511 unsigned int bytes_read
;
4512 struct dwarf_block
*blk
;
4518 case DW_FORM_ref_addr
:
4519 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
4520 info_ptr
+= bytes_read
;
4522 case DW_FORM_block2
:
4523 blk
= dwarf_alloc_block ();
4524 blk
->size
= read_2_bytes (abfd
, info_ptr
);
4526 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4527 info_ptr
+= blk
->size
;
4528 DW_BLOCK (attr
) = blk
;
4530 case DW_FORM_block4
:
4531 blk
= dwarf_alloc_block ();
4532 blk
->size
= read_4_bytes (abfd
, info_ptr
);
4534 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4535 info_ptr
+= blk
->size
;
4536 DW_BLOCK (attr
) = blk
;
4539 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4543 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4547 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4550 case DW_FORM_string
:
4551 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
4552 info_ptr
+= bytes_read
;
4555 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
4557 info_ptr
+= bytes_read
;
4560 blk
= dwarf_alloc_block ();
4561 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4562 info_ptr
+= bytes_read
;
4563 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4564 info_ptr
+= blk
->size
;
4565 DW_BLOCK (attr
) = blk
;
4567 case DW_FORM_block1
:
4568 blk
= dwarf_alloc_block ();
4569 blk
->size
= read_1_byte (abfd
, info_ptr
);
4571 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4572 info_ptr
+= blk
->size
;
4573 DW_BLOCK (attr
) = blk
;
4576 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4580 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4584 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
4585 info_ptr
+= bytes_read
;
4588 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4589 info_ptr
+= bytes_read
;
4592 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4596 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4600 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4604 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4607 case DW_FORM_ref_udata
:
4608 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4609 info_ptr
+= bytes_read
;
4611 case DW_FORM_indirect
:
4612 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4613 info_ptr
+= bytes_read
;
4614 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
4617 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
4618 dwarf_form_name (form
),
4619 bfd_get_filename (abfd
));
4624 /* Read an attribute described by an abbreviated attribute. */
4627 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
4628 bfd
*abfd
, char *info_ptr
, struct dwarf2_cu
*cu
)
4630 attr
->name
= abbrev
->name
;
4631 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
4634 /* read dwarf information from a buffer */
4637 read_1_byte (bfd
*abfd
, char *buf
)
4639 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4643 read_1_signed_byte (bfd
*abfd
, char *buf
)
4645 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
4649 read_2_bytes (bfd
*abfd
, char *buf
)
4651 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4655 read_2_signed_bytes (bfd
*abfd
, char *buf
)
4657 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4661 read_4_bytes (bfd
*abfd
, char *buf
)
4663 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4667 read_4_signed_bytes (bfd
*abfd
, char *buf
)
4669 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4672 static unsigned long
4673 read_8_bytes (bfd
*abfd
, char *buf
)
4675 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4679 read_address (bfd
*abfd
, char *buf
, struct dwarf2_cu
*cu
, int *bytes_read
)
4681 struct comp_unit_head
*cu_header
= &cu
->header
;
4682 CORE_ADDR retval
= 0;
4684 if (cu_header
->signed_addr_p
)
4686 switch (cu_header
->addr_size
)
4689 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4692 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4695 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
4698 internal_error (__FILE__
, __LINE__
,
4699 "read_address: bad switch, signed [in module %s]",
4700 bfd_get_filename (abfd
));
4705 switch (cu_header
->addr_size
)
4708 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4711 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4714 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4717 internal_error (__FILE__
, __LINE__
,
4718 "read_address: bad switch, unsigned [in module %s]",
4719 bfd_get_filename (abfd
));
4723 *bytes_read
= cu_header
->addr_size
;
4727 /* Read the initial length from a section. The (draft) DWARF 3
4728 specification allows the initial length to take up either 4 bytes
4729 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
4730 bytes describe the length and all offsets will be 8 bytes in length
4733 An older, non-standard 64-bit format is also handled by this
4734 function. The older format in question stores the initial length
4735 as an 8-byte quantity without an escape value. Lengths greater
4736 than 2^32 aren't very common which means that the initial 4 bytes
4737 is almost always zero. Since a length value of zero doesn't make
4738 sense for the 32-bit format, this initial zero can be considered to
4739 be an escape value which indicates the presence of the older 64-bit
4740 format. As written, the code can't detect (old format) lengths
4741 greater than 4GB. If it becomes necessary to handle lengths somewhat
4742 larger than 4GB, we could allow other small values (such as the
4743 non-sensical values of 1, 2, and 3) to also be used as escape values
4744 indicating the presence of the old format.
4746 The value returned via bytes_read should be used to increment
4747 the relevant pointer after calling read_initial_length().
4749 As a side effect, this function sets the fields initial_length_size
4750 and offset_size in cu_header to the values appropriate for the
4751 length field. (The format of the initial length field determines
4752 the width of file offsets to be fetched later with fetch_offset().)
4754 [ Note: read_initial_length() and read_offset() are based on the
4755 document entitled "DWARF Debugging Information Format", revision
4756 3, draft 8, dated November 19, 2001. This document was obtained
4759 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
4761 This document is only a draft and is subject to change. (So beware.)
4763 Details regarding the older, non-standard 64-bit format were
4764 determined empirically by examining 64-bit ELF files produced
4765 by the SGI toolchain on an IRIX 6.5 machine.
4767 - Kevin, July 16, 2002
4771 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
4776 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4778 if (retval
== 0xffffffff)
4780 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
4782 if (cu_header
!= NULL
)
4784 cu_header
->initial_length_size
= 12;
4785 cu_header
->offset_size
= 8;
4788 else if (retval
== 0)
4790 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
4792 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4794 if (cu_header
!= NULL
)
4796 cu_header
->initial_length_size
= 8;
4797 cu_header
->offset_size
= 8;
4803 if (cu_header
!= NULL
)
4805 cu_header
->initial_length_size
= 4;
4806 cu_header
->offset_size
= 4;
4813 /* Read an offset from the data stream. The size of the offset is
4814 given by cu_header->offset_size. */
4817 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
4822 switch (cu_header
->offset_size
)
4825 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4829 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4833 internal_error (__FILE__
, __LINE__
,
4834 "read_offset: bad switch [in module %s]",
4835 bfd_get_filename (abfd
));
4842 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
4844 /* If the size of a host char is 8 bits, we can return a pointer
4845 to the buffer, otherwise we have to copy the data to a buffer
4846 allocated on the temporary obstack. */
4847 gdb_assert (HOST_CHAR_BIT
== 8);
4852 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4854 /* If the size of a host char is 8 bits, we can return a pointer
4855 to the string, otherwise we have to copy the string to a buffer
4856 allocated on the temporary obstack. */
4857 gdb_assert (HOST_CHAR_BIT
== 8);
4860 *bytes_read_ptr
= 1;
4863 *bytes_read_ptr
= strlen (buf
) + 1;
4868 read_indirect_string (bfd
*abfd
, char *buf
,
4869 const struct comp_unit_head
*cu_header
,
4870 unsigned int *bytes_read_ptr
)
4872 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
4873 (int *) bytes_read_ptr
);
4875 if (dwarf_str_buffer
== NULL
)
4877 error ("DW_FORM_strp used without .debug_str section [in module %s]",
4878 bfd_get_filename (abfd
));
4881 if (str_offset
>= dwarf_str_size
)
4883 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
4884 bfd_get_filename (abfd
));
4887 gdb_assert (HOST_CHAR_BIT
== 8);
4888 if (dwarf_str_buffer
[str_offset
] == '\0')
4890 return dwarf_str_buffer
+ str_offset
;
4893 static unsigned long
4894 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4896 unsigned long result
;
4897 unsigned int num_read
;
4907 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4910 result
|= ((unsigned long)(byte
& 127) << shift
);
4911 if ((byte
& 128) == 0)
4917 *bytes_read_ptr
= num_read
;
4922 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4925 int i
, shift
, size
, num_read
;
4935 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4938 result
|= ((long)(byte
& 127) << shift
);
4940 if ((byte
& 128) == 0)
4945 if ((shift
< size
) && (byte
& 0x40))
4947 result
|= -(1 << shift
);
4949 *bytes_read_ptr
= num_read
;
4954 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
4960 cu
->language
= language_c
;
4962 case DW_LANG_C_plus_plus
:
4963 cu
->language
= language_cplus
;
4965 case DW_LANG_Fortran77
:
4966 case DW_LANG_Fortran90
:
4967 case DW_LANG_Fortran95
:
4968 cu
->language
= language_fortran
;
4970 case DW_LANG_Mips_Assembler
:
4971 cu
->language
= language_asm
;
4974 cu
->language
= language_java
;
4978 case DW_LANG_Cobol74
:
4979 case DW_LANG_Cobol85
:
4980 case DW_LANG_Pascal83
:
4981 case DW_LANG_Modula2
:
4983 cu
->language
= language_minimal
;
4986 cu
->language_defn
= language_def (cu
->language
);
4989 /* Return the named attribute or NULL if not there. */
4991 static struct attribute
*
4992 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
4995 struct attribute
*spec
= NULL
;
4997 for (i
= 0; i
< die
->num_attrs
; ++i
)
4999 if (die
->attrs
[i
].name
== name
)
5001 return &die
->attrs
[i
];
5003 if (die
->attrs
[i
].name
== DW_AT_specification
5004 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
5005 spec
= &die
->attrs
[i
];
5009 struct die_info
*ref_die
=
5010 follow_die_ref (dwarf2_get_ref_die_offset (spec
, cu
));
5013 return dwarf2_attr (ref_die
, name
, cu
);
5020 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
5022 return (dwarf2_attr (die
, DW_AT_declaration
, cu
)
5023 && ! dwarf2_attr (die
, DW_AT_specification
, cu
));
5026 /* Return the die giving the specification for DIE, if there is
5029 static struct die_info
*
5030 die_specification (struct die_info
*die
, struct dwarf2_cu
*cu
)
5032 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
, cu
);
5034 if (spec_attr
== NULL
)
5037 return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr
, cu
));
5040 /* Free the line_header structure *LH, and any arrays and strings it
5043 free_line_header (struct line_header
*lh
)
5045 if (lh
->standard_opcode_lengths
)
5046 xfree (lh
->standard_opcode_lengths
);
5048 /* Remember that all the lh->file_names[i].name pointers are
5049 pointers into debug_line_buffer, and don't need to be freed. */
5051 xfree (lh
->file_names
);
5053 /* Similarly for the include directory names. */
5054 if (lh
->include_dirs
)
5055 xfree (lh
->include_dirs
);
5061 /* Add an entry to LH's include directory table. */
5063 add_include_dir (struct line_header
*lh
, char *include_dir
)
5065 /* Grow the array if necessary. */
5066 if (lh
->include_dirs_size
== 0)
5068 lh
->include_dirs_size
= 1; /* for testing */
5069 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
5070 * sizeof (*lh
->include_dirs
));
5072 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
5074 lh
->include_dirs_size
*= 2;
5075 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
5076 (lh
->include_dirs_size
5077 * sizeof (*lh
->include_dirs
)));
5080 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
5084 /* Add an entry to LH's file name table. */
5086 add_file_name (struct line_header
*lh
,
5088 unsigned int dir_index
,
5089 unsigned int mod_time
,
5090 unsigned int length
)
5092 struct file_entry
*fe
;
5094 /* Grow the array if necessary. */
5095 if (lh
->file_names_size
== 0)
5097 lh
->file_names_size
= 1; /* for testing */
5098 lh
->file_names
= xmalloc (lh
->file_names_size
5099 * sizeof (*lh
->file_names
));
5101 else if (lh
->num_file_names
>= lh
->file_names_size
)
5103 lh
->file_names_size
*= 2;
5104 lh
->file_names
= xrealloc (lh
->file_names
,
5105 (lh
->file_names_size
5106 * sizeof (*lh
->file_names
)));
5109 fe
= &lh
->file_names
[lh
->num_file_names
++];
5111 fe
->dir_index
= dir_index
;
5112 fe
->mod_time
= mod_time
;
5113 fe
->length
= length
;
5117 /* Read the statement program header starting at OFFSET in
5118 dwarf_line_buffer, according to the endianness of ABFD. Return a
5119 pointer to a struct line_header, allocated using xmalloc.
5121 NOTE: the strings in the include directory and file name tables of
5122 the returned object point into debug_line_buffer, and must not be
5124 static struct line_header
*
5125 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
5126 struct dwarf2_cu
*cu
)
5128 struct cleanup
*back_to
;
5129 struct line_header
*lh
;
5133 char *cur_dir
, *cur_file
;
5135 if (dwarf_line_buffer
== NULL
)
5137 complaint (&symfile_complaints
, "missing .debug_line section");
5141 /* Make sure that at least there's room for the total_length field. That
5142 could be 12 bytes long, but we're just going to fudge that. */
5143 if (offset
+ 4 >= dwarf_line_size
)
5145 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5149 lh
= xmalloc (sizeof (*lh
));
5150 memset (lh
, 0, sizeof (*lh
));
5151 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
5154 line_ptr
= dwarf_line_buffer
+ offset
;
5156 /* read in the header */
5157 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
5158 line_ptr
+= bytes_read
;
5159 if (line_ptr
+ lh
->total_length
> dwarf_line_buffer
+ dwarf_line_size
)
5161 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5164 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
5165 lh
->version
= read_2_bytes (abfd
, line_ptr
);
5167 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
5168 line_ptr
+= bytes_read
;
5169 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
5171 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
5173 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
5175 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
5177 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
5179 lh
->standard_opcode_lengths
5180 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
5182 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
5183 for (i
= 1; i
< lh
->opcode_base
; ++i
)
5185 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
5189 /* Read directory table */
5190 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
5192 line_ptr
+= bytes_read
;
5193 add_include_dir (lh
, cur_dir
);
5195 line_ptr
+= bytes_read
;
5197 /* Read file name table */
5198 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
5200 unsigned int dir_index
, mod_time
, length
;
5202 line_ptr
+= bytes_read
;
5203 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5204 line_ptr
+= bytes_read
;
5205 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5206 line_ptr
+= bytes_read
;
5207 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5208 line_ptr
+= bytes_read
;
5210 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
5212 line_ptr
+= bytes_read
;
5213 lh
->statement_program_start
= line_ptr
;
5215 if (line_ptr
> dwarf_line_buffer
+ dwarf_line_size
)
5216 complaint (&symfile_complaints
,
5217 "line number info header doesn't fit in `.debug_line' section");
5219 discard_cleanups (back_to
);
5223 /* This function exists to work around a bug in certain compilers
5224 (particularly GCC 2.95), in which the first line number marker of a
5225 function does not show up until after the prologue, right before
5226 the second line number marker. This function shifts ADDRESS down
5227 to the beginning of the function if necessary, and is called on
5228 addresses passed to record_line. */
5231 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
5233 struct function_range
*fn
;
5235 /* Find the function_range containing address. */
5240 cu
->cached_fn
= cu
->first_fn
;
5244 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
5250 while (fn
&& fn
!= cu
->cached_fn
)
5251 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
5261 if (address
!= fn
->lowpc
)
5262 complaint (&symfile_complaints
,
5263 "misplaced first line number at 0x%lx for '%s'",
5264 (unsigned long) address
, fn
->name
);
5269 /* Decode the line number information for the compilation unit whose
5270 line number info is at OFFSET in the .debug_line section.
5271 The compilation directory of the file is passed in COMP_DIR. */
5274 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
5275 struct dwarf2_cu
*cu
)
5279 unsigned int bytes_read
;
5280 unsigned char op_code
, extended_op
, adj_opcode
;
5282 struct objfile
*objfile
= cu
->objfile
;
5284 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5286 line_ptr
= lh
->statement_program_start
;
5287 line_end
= lh
->statement_program_end
;
5289 /* Read the statement sequences until there's nothing left. */
5290 while (line_ptr
< line_end
)
5292 /* state machine registers */
5293 CORE_ADDR address
= 0;
5294 unsigned int file
= 1;
5295 unsigned int line
= 1;
5296 unsigned int column
= 0;
5297 int is_stmt
= lh
->default_is_stmt
;
5298 int basic_block
= 0;
5299 int end_sequence
= 0;
5301 /* Start a subfile for the current file of the state machine. */
5302 if (lh
->num_file_names
>= file
)
5304 /* lh->include_dirs and lh->file_names are 0-based, but the
5305 directory and file name numbers in the statement program
5307 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
5310 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
5313 dwarf2_start_subfile (fe
->name
, dir
);
5316 /* Decode the table. */
5317 while (!end_sequence
)
5319 op_code
= read_1_byte (abfd
, line_ptr
);
5322 if (op_code
>= lh
->opcode_base
)
5323 { /* Special operand. */
5324 adj_opcode
= op_code
- lh
->opcode_base
;
5325 address
+= (adj_opcode
/ lh
->line_range
)
5326 * lh
->minimum_instruction_length
;
5327 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
5328 /* append row to matrix using current values */
5329 record_line (current_subfile
, line
,
5330 check_cu_functions (address
, cu
));
5333 else switch (op_code
)
5335 case DW_LNS_extended_op
:
5336 line_ptr
+= 1; /* ignore length */
5337 extended_op
= read_1_byte (abfd
, line_ptr
);
5339 switch (extended_op
)
5341 case DW_LNE_end_sequence
:
5343 record_line (current_subfile
, 0, address
);
5345 case DW_LNE_set_address
:
5346 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
5347 line_ptr
+= bytes_read
;
5348 address
+= baseaddr
;
5350 case DW_LNE_define_file
:
5353 unsigned int dir_index
, mod_time
, length
;
5355 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
5356 line_ptr
+= bytes_read
;
5358 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5359 line_ptr
+= bytes_read
;
5361 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5362 line_ptr
+= bytes_read
;
5364 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5365 line_ptr
+= bytes_read
;
5366 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
5370 complaint (&symfile_complaints
,
5371 "mangled .debug_line section");
5376 record_line (current_subfile
, line
,
5377 check_cu_functions (address
, cu
));
5380 case DW_LNS_advance_pc
:
5381 address
+= lh
->minimum_instruction_length
5382 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5383 line_ptr
+= bytes_read
;
5385 case DW_LNS_advance_line
:
5386 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
5387 line_ptr
+= bytes_read
;
5389 case DW_LNS_set_file
:
5391 /* lh->include_dirs and lh->file_names are 0-based,
5392 but the directory and file name numbers in the
5393 statement program are 1-based. */
5394 struct file_entry
*fe
;
5396 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5397 line_ptr
+= bytes_read
;
5398 fe
= &lh
->file_names
[file
- 1];
5400 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
5403 dwarf2_start_subfile (fe
->name
, dir
);
5406 case DW_LNS_set_column
:
5407 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5408 line_ptr
+= bytes_read
;
5410 case DW_LNS_negate_stmt
:
5411 is_stmt
= (!is_stmt
);
5413 case DW_LNS_set_basic_block
:
5416 /* Add to the address register of the state machine the
5417 address increment value corresponding to special opcode
5418 255. Ie, this value is scaled by the minimum instruction
5419 length since special opcode 255 would have scaled the
5421 case DW_LNS_const_add_pc
:
5422 address
+= (lh
->minimum_instruction_length
5423 * ((255 - lh
->opcode_base
) / lh
->line_range
));
5425 case DW_LNS_fixed_advance_pc
:
5426 address
+= read_2_bytes (abfd
, line_ptr
);
5430 { /* Unknown standard opcode, ignore it. */
5432 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
5434 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5435 line_ptr
+= bytes_read
;
5443 /* Start a subfile for DWARF. FILENAME is the name of the file and
5444 DIRNAME the name of the source directory which contains FILENAME
5445 or NULL if not known.
5446 This routine tries to keep line numbers from identical absolute and
5447 relative file names in a common subfile.
5449 Using the `list' example from the GDB testsuite, which resides in
5450 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
5451 of /srcdir/list0.c yields the following debugging information for list0.c:
5453 DW_AT_name: /srcdir/list0.c
5454 DW_AT_comp_dir: /compdir
5455 files.files[0].name: list0.h
5456 files.files[0].dir: /srcdir
5457 files.files[1].name: list0.c
5458 files.files[1].dir: /srcdir
5460 The line number information for list0.c has to end up in a single
5461 subfile, so that `break /srcdir/list0.c:1' works as expected. */
5464 dwarf2_start_subfile (char *filename
, char *dirname
)
5466 /* If the filename isn't absolute, try to match an existing subfile
5467 with the full pathname. */
5469 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
5471 struct subfile
*subfile
;
5472 char *fullname
= concat (dirname
, "/", filename
, NULL
);
5474 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
5476 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
5478 current_subfile
= subfile
;
5485 start_subfile (filename
, dirname
);
5489 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
5490 struct dwarf2_cu
*cu
)
5492 struct objfile
*objfile
= cu
->objfile
;
5493 struct comp_unit_head
*cu_header
= &cu
->header
;
5495 /* NOTE drow/2003-01-30: There used to be a comment and some special
5496 code here to turn a symbol with DW_AT_external and a
5497 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
5498 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
5499 with some versions of binutils) where shared libraries could have
5500 relocations against symbols in their debug information - the
5501 minimal symbol would have the right address, but the debug info
5502 would not. It's no longer necessary, because we will explicitly
5503 apply relocations when we read in the debug information now. */
5505 /* A DW_AT_location attribute with no contents indicates that a
5506 variable has been optimized away. */
5507 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
5509 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
5513 /* Handle one degenerate form of location expression specially, to
5514 preserve GDB's previous behavior when section offsets are
5515 specified. If this is just a DW_OP_addr then mark this symbol
5518 if (attr_form_is_block (attr
)
5519 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
5520 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
5524 SYMBOL_VALUE_ADDRESS (sym
) =
5525 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
5526 fixup_symbol_section (sym
, objfile
);
5527 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
5528 SYMBOL_SECTION (sym
));
5529 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5533 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
5534 expression evaluator, and use LOC_COMPUTED only when necessary
5535 (i.e. when the value of a register or memory location is
5536 referenced, or a thread-local block, etc.). Then again, it might
5537 not be worthwhile. I'm assuming that it isn't unless performance
5538 or memory numbers show me otherwise. */
5540 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
5541 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
5544 /* Given a pointer to a DWARF information entry, figure out if we need
5545 to make a symbol table entry for it, and if so, create a new entry
5546 and return a pointer to it.
5547 If TYPE is NULL, determine symbol type from the die, otherwise
5548 used the passed type. */
5550 static struct symbol
*
5551 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
5553 struct objfile
*objfile
= cu
->objfile
;
5554 struct symbol
*sym
= NULL
;
5556 struct attribute
*attr
= NULL
;
5557 struct attribute
*attr2
= NULL
;
5560 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5562 if (die
->tag
!= DW_TAG_namespace
)
5563 name
= dwarf2_linkage_name (die
, cu
);
5565 name
= TYPE_NAME (type
);
5569 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
5570 sizeof (struct symbol
));
5571 OBJSTAT (objfile
, n_syms
++);
5572 memset (sym
, 0, sizeof (struct symbol
));
5574 /* Cache this symbol's name and the name's demangled form (if any). */
5575 SYMBOL_LANGUAGE (sym
) = cu
->language
;
5576 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
5578 /* Default assumptions.
5579 Use the passed type or decode it from the die. */
5580 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5581 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5583 SYMBOL_TYPE (sym
) = type
;
5585 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
5586 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
5589 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
5594 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5597 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
5599 SYMBOL_CLASS (sym
) = LOC_LABEL
;
5601 case DW_TAG_subprogram
:
5602 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
5604 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
5605 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
5606 if (attr2
&& (DW_UNSND (attr2
) != 0))
5608 add_symbol_to_list (sym
, &global_symbols
);
5612 add_symbol_to_list (sym
, cu
->list_in_scope
);
5615 case DW_TAG_variable
:
5616 /* Compilation with minimal debug info may result in variables
5617 with missing type entries. Change the misleading `void' type
5618 to something sensible. */
5619 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
5620 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
5621 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
5622 "<variable, no debug info>",
5624 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
5627 dwarf2_const_value (attr
, sym
, cu
);
5628 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
5629 if (attr2
&& (DW_UNSND (attr2
) != 0))
5630 add_symbol_to_list (sym
, &global_symbols
);
5632 add_symbol_to_list (sym
, cu
->list_in_scope
);
5635 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
5638 var_decode_location (attr
, sym
, cu
);
5639 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
5640 if (attr2
&& (DW_UNSND (attr2
) != 0))
5641 add_symbol_to_list (sym
, &global_symbols
);
5643 add_symbol_to_list (sym
, cu
->list_in_scope
);
5647 /* We do not know the address of this symbol.
5648 If it is an external symbol and we have type information
5649 for it, enter the symbol as a LOC_UNRESOLVED symbol.
5650 The address of the variable will then be determined from
5651 the minimal symbol table whenever the variable is
5653 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
5654 if (attr2
&& (DW_UNSND (attr2
) != 0)
5655 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
5657 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
5658 add_symbol_to_list (sym
, &global_symbols
);
5662 case DW_TAG_formal_parameter
:
5663 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
5666 var_decode_location (attr
, sym
, cu
);
5667 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
5668 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
5669 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
5671 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
5674 dwarf2_const_value (attr
, sym
, cu
);
5676 add_symbol_to_list (sym
, cu
->list_in_scope
);
5678 case DW_TAG_unspecified_parameters
:
5679 /* From varargs functions; gdb doesn't seem to have any
5680 interest in this information, so just ignore it for now.
5683 case DW_TAG_class_type
:
5684 case DW_TAG_structure_type
:
5685 case DW_TAG_union_type
:
5686 case DW_TAG_enumeration_type
:
5687 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5688 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
5690 /* Make sure that the symbol includes appropriate enclosing
5691 classes/namespaces in its name. These are calculated in
5692 read_structure_scope, and the correct name is saved in
5695 if (cu
->language
== language_cplus
)
5697 struct type
*type
= SYMBOL_TYPE (sym
);
5699 if (TYPE_TAG_NAME (type
) != NULL
)
5701 /* FIXME: carlton/2003-11-10: Should this use
5702 SYMBOL_SET_NAMES instead? (The same problem also
5703 arises further down in this function.) */
5704 /* The type's name is already allocated along with
5705 this objfile, so we don't need to duplicate it
5707 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
5712 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
5713 really ever be static objects: otherwise, if you try
5714 to, say, break of a class's method and you're in a file
5715 which doesn't mention that class, it won't work unless
5716 the check for all static symbols in lookup_symbol_aux
5717 saves you. See the OtherFileClass tests in
5718 gdb.c++/namespace.exp. */
5720 struct pending
**list_to_add
;
5722 list_to_add
= (cu
->list_in_scope
== &file_symbols
5723 && cu
->language
== language_cplus
5724 ? &global_symbols
: cu
->list_in_scope
);
5726 add_symbol_to_list (sym
, list_to_add
);
5728 /* The semantics of C++ state that "struct foo { ... }" also
5729 defines a typedef for "foo". Synthesize a typedef symbol so
5730 that "ptype foo" works as expected. */
5731 if (cu
->language
== language_cplus
)
5733 struct symbol
*typedef_sym
= (struct symbol
*)
5734 obstack_alloc (&objfile
->objfile_obstack
,
5735 sizeof (struct symbol
));
5736 *typedef_sym
= *sym
;
5737 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
5738 /* The symbol's name is already allocated along with
5739 this objfile, so we don't need to duplicate it for
5741 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
5742 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NATURAL_NAME (sym
);
5743 add_symbol_to_list (typedef_sym
, list_to_add
);
5747 case DW_TAG_typedef
:
5748 if (processing_has_namespace_info
5749 && processing_current_prefix
[0] != '\0')
5751 SYMBOL_LINKAGE_NAME (sym
) = obconcat (&objfile
->objfile_obstack
,
5752 processing_current_prefix
,
5756 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5757 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5758 add_symbol_to_list (sym
, cu
->list_in_scope
);
5760 case DW_TAG_base_type
:
5761 case DW_TAG_subrange_type
:
5762 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5763 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5764 add_symbol_to_list (sym
, cu
->list_in_scope
);
5766 case DW_TAG_enumerator
:
5767 if (processing_has_namespace_info
5768 && processing_current_prefix
[0] != '\0')
5770 SYMBOL_LINKAGE_NAME (sym
) = obconcat (&objfile
->objfile_obstack
,
5771 processing_current_prefix
,
5775 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
5778 dwarf2_const_value (attr
, sym
, cu
);
5781 /* NOTE: carlton/2003-11-10: See comment above in the
5782 DW_TAG_class_type, etc. block. */
5784 struct pending
**list_to_add
;
5786 list_to_add
= (cu
->list_in_scope
== &file_symbols
5787 && cu
->language
== language_cplus
5788 ? &global_symbols
: cu
->list_in_scope
);
5790 add_symbol_to_list (sym
, list_to_add
);
5793 case DW_TAG_namespace
:
5794 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5795 add_symbol_to_list (sym
, &global_symbols
);
5798 /* Not a tag we recognize. Hopefully we aren't processing
5799 trash data, but since we must specifically ignore things
5800 we don't recognize, there is nothing else we should do at
5802 complaint (&symfile_complaints
, "unsupported tag: '%s'",
5803 dwarf_tag_name (die
->tag
));
5810 /* Copy constant value from an attribute to a symbol. */
5813 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
5814 struct dwarf2_cu
*cu
)
5816 struct objfile
*objfile
= cu
->objfile
;
5817 struct comp_unit_head
*cu_header
= &cu
->header
;
5818 struct dwarf_block
*blk
;
5823 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
5824 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5825 cu_header
->addr_size
,
5826 TYPE_LENGTH (SYMBOL_TYPE
5828 SYMBOL_VALUE_BYTES (sym
) = (char *)
5829 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
5830 /* NOTE: cagney/2003-05-09: In-lined store_address call with
5831 it's body - store_unsigned_integer. */
5832 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
5834 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5836 case DW_FORM_block1
:
5837 case DW_FORM_block2
:
5838 case DW_FORM_block4
:
5840 blk
= DW_BLOCK (attr
);
5841 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
5842 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5844 TYPE_LENGTH (SYMBOL_TYPE
5846 SYMBOL_VALUE_BYTES (sym
) = (char *)
5847 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
5848 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
5849 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5852 /* The DW_AT_const_value attributes are supposed to carry the
5853 symbol's value "represented as it would be on the target
5854 architecture." By the time we get here, it's already been
5855 converted to host endianness, so we just need to sign- or
5856 zero-extend it as appropriate. */
5858 dwarf2_const_value_data (attr
, sym
, 8);
5861 dwarf2_const_value_data (attr
, sym
, 16);
5864 dwarf2_const_value_data (attr
, sym
, 32);
5867 dwarf2_const_value_data (attr
, sym
, 64);
5871 SYMBOL_VALUE (sym
) = DW_SND (attr
);
5872 SYMBOL_CLASS (sym
) = LOC_CONST
;
5876 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
5877 SYMBOL_CLASS (sym
) = LOC_CONST
;
5881 complaint (&symfile_complaints
,
5882 "unsupported const value attribute form: '%s'",
5883 dwarf_form_name (attr
->form
));
5884 SYMBOL_VALUE (sym
) = 0;
5885 SYMBOL_CLASS (sym
) = LOC_CONST
;
5891 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
5892 or zero-extend it as appropriate for the symbol's type. */
5894 dwarf2_const_value_data (struct attribute
*attr
,
5898 LONGEST l
= DW_UNSND (attr
);
5900 if (bits
< sizeof (l
) * 8)
5902 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
5903 l
&= ((LONGEST
) 1 << bits
) - 1;
5905 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
5908 SYMBOL_VALUE (sym
) = l
;
5909 SYMBOL_CLASS (sym
) = LOC_CONST
;
5913 /* Return the type of the die in question using its DW_AT_type attribute. */
5915 static struct type
*
5916 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5919 struct attribute
*type_attr
;
5920 struct die_info
*type_die
;
5923 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
5926 /* A missing DW_AT_type represents a void type. */
5927 return dwarf2_fundamental_type (cu
->objfile
, FT_VOID
, cu
);
5931 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
5932 type_die
= follow_die_ref (ref
);
5935 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
5936 ref
, cu
->objfile
->name
);
5940 type
= tag_type_to_type (type_die
, cu
);
5943 dump_die (type_die
);
5944 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
5950 /* Return the containing type of the die in question using its
5951 DW_AT_containing_type attribute. */
5953 static struct type
*
5954 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5956 struct type
*type
= NULL
;
5957 struct attribute
*type_attr
;
5958 struct die_info
*type_die
= NULL
;
5961 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
5964 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
5965 type_die
= follow_die_ref (ref
);
5968 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref
,
5972 type
= tag_type_to_type (type_die
, cu
);
5977 dump_die (type_die
);
5978 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
5985 static struct type
*
5986 type_at_offset (unsigned int offset
, struct dwarf2_cu
*cu
)
5988 struct die_info
*die
;
5991 die
= follow_die_ref (offset
);
5994 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
5997 type
= tag_type_to_type (die
, cu
);
6002 static struct type
*
6003 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6011 read_type_die (die
, cu
);
6015 error ("Dwarf Error: Cannot find type of die [in module %s]",
6023 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
6025 char *prefix
= determine_prefix (die
, cu
);
6026 const char *old_prefix
= processing_current_prefix
;
6027 struct cleanup
*back_to
= make_cleanup (xfree
, prefix
);
6028 processing_current_prefix
= prefix
;
6032 case DW_TAG_class_type
:
6033 case DW_TAG_structure_type
:
6034 case DW_TAG_union_type
:
6035 read_structure_scope (die
, cu
);
6037 case DW_TAG_enumeration_type
:
6038 read_enumeration (die
, cu
);
6040 case DW_TAG_subprogram
:
6041 case DW_TAG_subroutine_type
:
6042 read_subroutine_type (die
, cu
);
6044 case DW_TAG_array_type
:
6045 read_array_type (die
, cu
);
6047 case DW_TAG_pointer_type
:
6048 read_tag_pointer_type (die
, cu
);
6050 case DW_TAG_ptr_to_member_type
:
6051 read_tag_ptr_to_member_type (die
, cu
);
6053 case DW_TAG_reference_type
:
6054 read_tag_reference_type (die
, cu
);
6056 case DW_TAG_const_type
:
6057 read_tag_const_type (die
, cu
);
6059 case DW_TAG_volatile_type
:
6060 read_tag_volatile_type (die
, cu
);
6062 case DW_TAG_string_type
:
6063 read_tag_string_type (die
, cu
);
6065 case DW_TAG_typedef
:
6066 read_typedef (die
, cu
);
6068 case DW_TAG_subrange_type
:
6069 read_subrange_type (die
, cu
);
6071 case DW_TAG_base_type
:
6072 read_base_type (die
, cu
);
6075 complaint (&symfile_complaints
, "unexepected tag in read_type_die: '%s'",
6076 dwarf_tag_name (die
->tag
));
6080 processing_current_prefix
= old_prefix
;
6081 do_cleanups (back_to
);
6084 /* Return the name of the namespace/class that DIE is defined within,
6085 or "" if we can't tell. The caller should xfree the result. */
6087 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
6088 therein) for an example of how to use this function to deal with
6089 DW_AT_specification. */
6092 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
6094 char *prefix
= determine_prefix_aux (die
, cu
);
6096 return prefix
? prefix
: xstrdup ("");
6099 /* Return the name of the namespace/class that DIE is defined
6100 within, or NULL if we can't tell. The caller should xfree the
6104 determine_prefix_aux (struct die_info
*die
, struct dwarf2_cu
*cu
)
6106 struct die_info
*parent
;
6108 if (cu
->language
!= language_cplus
)
6111 parent
= die
->parent
;
6115 return (processing_has_namespace_info
? xstrdup ("") : NULL
);
6119 char *parent_prefix
= determine_prefix_aux (parent
, cu
);
6122 switch (parent
->tag
) {
6123 case DW_TAG_namespace
:
6127 retval
= typename_concat (parent_prefix
,
6128 namespace_name (parent
, &dummy
, cu
));
6131 case DW_TAG_class_type
:
6132 case DW_TAG_structure_type
:
6134 if (parent_prefix
!= NULL
)
6136 const char *parent_name
= dwarf2_name (parent
, cu
);
6138 if (parent_name
!= NULL
)
6139 retval
= typename_concat (parent_prefix
, dwarf2_name (parent
, cu
));
6141 /* FIXME: carlton/2003-11-10: I'm not sure what the
6142 best thing to do here is. */
6143 retval
= typename_concat (parent_prefix
,
6144 "<<anonymous class>>");
6147 retval
= class_name (parent
, cu
);
6151 retval
= parent_prefix
;
6155 if (retval
!= parent_prefix
)
6156 xfree (parent_prefix
);
6161 /* Return a newly-allocated string formed by concatenating PREFIX,
6162 "::", and SUFFIX, except that if PREFIX is NULL or the empty
6163 string, just return a copy of SUFFIX. */
6166 typename_concat (const char *prefix
, const char *suffix
)
6168 if (prefix
== NULL
|| prefix
[0] == '\0')
6169 return xstrdup (suffix
);
6172 char *retval
= xmalloc (strlen (prefix
) + 2 + strlen (suffix
) + 1);
6174 strcpy (retval
, prefix
);
6175 strcat (retval
, "::");
6176 strcat (retval
, suffix
);
6182 /* Return a newly-allocated string giving the name of the class given
6186 class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6188 struct die_info
*child
;
6191 for (child
= die
->child
; child
!= NULL
; child
= sibling_die (child
))
6193 if (child
->tag
== DW_TAG_subprogram
)
6194 return class_name_from_physname (dwarf2_linkage_name (child
, cu
));
6197 name
= dwarf2_name (die
, cu
);
6199 return xstrdup (name
);
6201 return xstrdup ("");
6204 static struct type
*
6205 dwarf_base_type (int encoding
, int size
, struct dwarf2_cu
*cu
)
6207 struct objfile
*objfile
= cu
->objfile
;
6209 /* FIXME - this should not produce a new (struct type *)
6210 every time. It should cache base types. */
6214 case DW_ATE_address
:
6215 type
= dwarf2_fundamental_type (objfile
, FT_VOID
, cu
);
6217 case DW_ATE_boolean
:
6218 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
, cu
);
6220 case DW_ATE_complex_float
:
6223 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
, cu
);
6227 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
, cu
);
6233 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
6237 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
6244 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
6247 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
, cu
);
6251 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
6255 case DW_ATE_signed_char
:
6256 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
6258 case DW_ATE_unsigned
:
6262 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
6265 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
, cu
);
6269 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
, cu
);
6273 case DW_ATE_unsigned_char
:
6274 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
6277 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
6284 copy_die (struct die_info
*old_die
)
6286 struct die_info
*new_die
;
6289 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6290 memset (new_die
, 0, sizeof (struct die_info
));
6292 new_die
->tag
= old_die
->tag
;
6293 new_die
->has_children
= old_die
->has_children
;
6294 new_die
->abbrev
= old_die
->abbrev
;
6295 new_die
->offset
= old_die
->offset
;
6296 new_die
->type
= NULL
;
6298 num_attrs
= old_die
->num_attrs
;
6299 new_die
->num_attrs
= num_attrs
;
6300 new_die
->attrs
= (struct attribute
*)
6301 xmalloc (num_attrs
* sizeof (struct attribute
));
6303 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
6305 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
6306 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
6307 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
6310 new_die
->next
= NULL
;
6315 /* Return sibling of die, NULL if no sibling. */
6317 static struct die_info
*
6318 sibling_die (struct die_info
*die
)
6320 return die
->sibling
;
6323 /* Get linkage name of a die, return NULL if not found. */
6326 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6328 struct attribute
*attr
;
6330 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6331 if (attr
&& DW_STRING (attr
))
6332 return DW_STRING (attr
);
6333 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6334 if (attr
&& DW_STRING (attr
))
6335 return DW_STRING (attr
);
6339 /* Get name of a die, return NULL if not found. */
6342 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6344 struct attribute
*attr
;
6346 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6347 if (attr
&& DW_STRING (attr
))
6348 return DW_STRING (attr
);
6352 /* Return the die that this die in an extension of, or NULL if there
6355 static struct die_info
*
6356 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
*cu
)
6358 struct attribute
*attr
;
6359 struct die_info
*extension_die
;
6362 attr
= dwarf2_attr (die
, DW_AT_extension
, cu
);
6366 ref
= dwarf2_get_ref_die_offset (attr
, cu
);
6367 extension_die
= follow_die_ref (ref
);
6370 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
6373 return extension_die
;
6376 /* Convert a DIE tag into its string name. */
6379 dwarf_tag_name (unsigned tag
)
6383 case DW_TAG_padding
:
6384 return "DW_TAG_padding";
6385 case DW_TAG_array_type
:
6386 return "DW_TAG_array_type";
6387 case DW_TAG_class_type
:
6388 return "DW_TAG_class_type";
6389 case DW_TAG_entry_point
:
6390 return "DW_TAG_entry_point";
6391 case DW_TAG_enumeration_type
:
6392 return "DW_TAG_enumeration_type";
6393 case DW_TAG_formal_parameter
:
6394 return "DW_TAG_formal_parameter";
6395 case DW_TAG_imported_declaration
:
6396 return "DW_TAG_imported_declaration";
6398 return "DW_TAG_label";
6399 case DW_TAG_lexical_block
:
6400 return "DW_TAG_lexical_block";
6402 return "DW_TAG_member";
6403 case DW_TAG_pointer_type
:
6404 return "DW_TAG_pointer_type";
6405 case DW_TAG_reference_type
:
6406 return "DW_TAG_reference_type";
6407 case DW_TAG_compile_unit
:
6408 return "DW_TAG_compile_unit";
6409 case DW_TAG_string_type
:
6410 return "DW_TAG_string_type";
6411 case DW_TAG_structure_type
:
6412 return "DW_TAG_structure_type";
6413 case DW_TAG_subroutine_type
:
6414 return "DW_TAG_subroutine_type";
6415 case DW_TAG_typedef
:
6416 return "DW_TAG_typedef";
6417 case DW_TAG_union_type
:
6418 return "DW_TAG_union_type";
6419 case DW_TAG_unspecified_parameters
:
6420 return "DW_TAG_unspecified_parameters";
6421 case DW_TAG_variant
:
6422 return "DW_TAG_variant";
6423 case DW_TAG_common_block
:
6424 return "DW_TAG_common_block";
6425 case DW_TAG_common_inclusion
:
6426 return "DW_TAG_common_inclusion";
6427 case DW_TAG_inheritance
:
6428 return "DW_TAG_inheritance";
6429 case DW_TAG_inlined_subroutine
:
6430 return "DW_TAG_inlined_subroutine";
6432 return "DW_TAG_module";
6433 case DW_TAG_ptr_to_member_type
:
6434 return "DW_TAG_ptr_to_member_type";
6435 case DW_TAG_set_type
:
6436 return "DW_TAG_set_type";
6437 case DW_TAG_subrange_type
:
6438 return "DW_TAG_subrange_type";
6439 case DW_TAG_with_stmt
:
6440 return "DW_TAG_with_stmt";
6441 case DW_TAG_access_declaration
:
6442 return "DW_TAG_access_declaration";
6443 case DW_TAG_base_type
:
6444 return "DW_TAG_base_type";
6445 case DW_TAG_catch_block
:
6446 return "DW_TAG_catch_block";
6447 case DW_TAG_const_type
:
6448 return "DW_TAG_const_type";
6449 case DW_TAG_constant
:
6450 return "DW_TAG_constant";
6451 case DW_TAG_enumerator
:
6452 return "DW_TAG_enumerator";
6453 case DW_TAG_file_type
:
6454 return "DW_TAG_file_type";
6456 return "DW_TAG_friend";
6457 case DW_TAG_namelist
:
6458 return "DW_TAG_namelist";
6459 case DW_TAG_namelist_item
:
6460 return "DW_TAG_namelist_item";
6461 case DW_TAG_packed_type
:
6462 return "DW_TAG_packed_type";
6463 case DW_TAG_subprogram
:
6464 return "DW_TAG_subprogram";
6465 case DW_TAG_template_type_param
:
6466 return "DW_TAG_template_type_param";
6467 case DW_TAG_template_value_param
:
6468 return "DW_TAG_template_value_param";
6469 case DW_TAG_thrown_type
:
6470 return "DW_TAG_thrown_type";
6471 case DW_TAG_try_block
:
6472 return "DW_TAG_try_block";
6473 case DW_TAG_variant_part
:
6474 return "DW_TAG_variant_part";
6475 case DW_TAG_variable
:
6476 return "DW_TAG_variable";
6477 case DW_TAG_volatile_type
:
6478 return "DW_TAG_volatile_type";
6479 case DW_TAG_dwarf_procedure
:
6480 return "DW_TAG_dwarf_procedure";
6481 case DW_TAG_restrict_type
:
6482 return "DW_TAG_restrict_type";
6483 case DW_TAG_interface_type
:
6484 return "DW_TAG_interface_type";
6485 case DW_TAG_namespace
:
6486 return "DW_TAG_namespace";
6487 case DW_TAG_imported_module
:
6488 return "DW_TAG_imported_module";
6489 case DW_TAG_unspecified_type
:
6490 return "DW_TAG_unspecified_type";
6491 case DW_TAG_partial_unit
:
6492 return "DW_TAG_partial_unit";
6493 case DW_TAG_imported_unit
:
6494 return "DW_TAG_imported_unit";
6495 case DW_TAG_MIPS_loop
:
6496 return "DW_TAG_MIPS_loop";
6497 case DW_TAG_format_label
:
6498 return "DW_TAG_format_label";
6499 case DW_TAG_function_template
:
6500 return "DW_TAG_function_template";
6501 case DW_TAG_class_template
:
6502 return "DW_TAG_class_template";
6504 return "DW_TAG_<unknown>";
6508 /* Convert a DWARF attribute code into its string name. */
6511 dwarf_attr_name (unsigned attr
)
6516 return "DW_AT_sibling";
6517 case DW_AT_location
:
6518 return "DW_AT_location";
6520 return "DW_AT_name";
6521 case DW_AT_ordering
:
6522 return "DW_AT_ordering";
6523 case DW_AT_subscr_data
:
6524 return "DW_AT_subscr_data";
6525 case DW_AT_byte_size
:
6526 return "DW_AT_byte_size";
6527 case DW_AT_bit_offset
:
6528 return "DW_AT_bit_offset";
6529 case DW_AT_bit_size
:
6530 return "DW_AT_bit_size";
6531 case DW_AT_element_list
:
6532 return "DW_AT_element_list";
6533 case DW_AT_stmt_list
:
6534 return "DW_AT_stmt_list";
6536 return "DW_AT_low_pc";
6538 return "DW_AT_high_pc";
6539 case DW_AT_language
:
6540 return "DW_AT_language";
6542 return "DW_AT_member";
6544 return "DW_AT_discr";
6545 case DW_AT_discr_value
:
6546 return "DW_AT_discr_value";
6547 case DW_AT_visibility
:
6548 return "DW_AT_visibility";
6550 return "DW_AT_import";
6551 case DW_AT_string_length
:
6552 return "DW_AT_string_length";
6553 case DW_AT_common_reference
:
6554 return "DW_AT_common_reference";
6555 case DW_AT_comp_dir
:
6556 return "DW_AT_comp_dir";
6557 case DW_AT_const_value
:
6558 return "DW_AT_const_value";
6559 case DW_AT_containing_type
:
6560 return "DW_AT_containing_type";
6561 case DW_AT_default_value
:
6562 return "DW_AT_default_value";
6564 return "DW_AT_inline";
6565 case DW_AT_is_optional
:
6566 return "DW_AT_is_optional";
6567 case DW_AT_lower_bound
:
6568 return "DW_AT_lower_bound";
6569 case DW_AT_producer
:
6570 return "DW_AT_producer";
6571 case DW_AT_prototyped
:
6572 return "DW_AT_prototyped";
6573 case DW_AT_return_addr
:
6574 return "DW_AT_return_addr";
6575 case DW_AT_start_scope
:
6576 return "DW_AT_start_scope";
6577 case DW_AT_stride_size
:
6578 return "DW_AT_stride_size";
6579 case DW_AT_upper_bound
:
6580 return "DW_AT_upper_bound";
6581 case DW_AT_abstract_origin
:
6582 return "DW_AT_abstract_origin";
6583 case DW_AT_accessibility
:
6584 return "DW_AT_accessibility";
6585 case DW_AT_address_class
:
6586 return "DW_AT_address_class";
6587 case DW_AT_artificial
:
6588 return "DW_AT_artificial";
6589 case DW_AT_base_types
:
6590 return "DW_AT_base_types";
6591 case DW_AT_calling_convention
:
6592 return "DW_AT_calling_convention";
6594 return "DW_AT_count";
6595 case DW_AT_data_member_location
:
6596 return "DW_AT_data_member_location";
6597 case DW_AT_decl_column
:
6598 return "DW_AT_decl_column";
6599 case DW_AT_decl_file
:
6600 return "DW_AT_decl_file";
6601 case DW_AT_decl_line
:
6602 return "DW_AT_decl_line";
6603 case DW_AT_declaration
:
6604 return "DW_AT_declaration";
6605 case DW_AT_discr_list
:
6606 return "DW_AT_discr_list";
6607 case DW_AT_encoding
:
6608 return "DW_AT_encoding";
6609 case DW_AT_external
:
6610 return "DW_AT_external";
6611 case DW_AT_frame_base
:
6612 return "DW_AT_frame_base";
6614 return "DW_AT_friend";
6615 case DW_AT_identifier_case
:
6616 return "DW_AT_identifier_case";
6617 case DW_AT_macro_info
:
6618 return "DW_AT_macro_info";
6619 case DW_AT_namelist_items
:
6620 return "DW_AT_namelist_items";
6621 case DW_AT_priority
:
6622 return "DW_AT_priority";
6624 return "DW_AT_segment";
6625 case DW_AT_specification
:
6626 return "DW_AT_specification";
6627 case DW_AT_static_link
:
6628 return "DW_AT_static_link";
6630 return "DW_AT_type";
6631 case DW_AT_use_location
:
6632 return "DW_AT_use_location";
6633 case DW_AT_variable_parameter
:
6634 return "DW_AT_variable_parameter";
6635 case DW_AT_virtuality
:
6636 return "DW_AT_virtuality";
6637 case DW_AT_vtable_elem_location
:
6638 return "DW_AT_vtable_elem_location";
6639 case DW_AT_allocated
:
6640 return "DW_AT_allocated";
6641 case DW_AT_associated
:
6642 return "DW_AT_associated";
6643 case DW_AT_data_location
:
6644 return "DW_AT_data_location";
6646 return "DW_AT_stride";
6647 case DW_AT_entry_pc
:
6648 return "DW_AT_entry_pc";
6649 case DW_AT_use_UTF8
:
6650 return "DW_AT_use_UTF8";
6651 case DW_AT_extension
:
6652 return "DW_AT_extension";
6654 return "DW_AT_ranges";
6655 case DW_AT_trampoline
:
6656 return "DW_AT_trampoline";
6657 case DW_AT_call_column
:
6658 return "DW_AT_call_column";
6659 case DW_AT_call_file
:
6660 return "DW_AT_call_file";
6661 case DW_AT_call_line
:
6662 return "DW_AT_call_line";
6664 case DW_AT_MIPS_fde
:
6665 return "DW_AT_MIPS_fde";
6666 case DW_AT_MIPS_loop_begin
:
6667 return "DW_AT_MIPS_loop_begin";
6668 case DW_AT_MIPS_tail_loop_begin
:
6669 return "DW_AT_MIPS_tail_loop_begin";
6670 case DW_AT_MIPS_epilog_begin
:
6671 return "DW_AT_MIPS_epilog_begin";
6672 case DW_AT_MIPS_loop_unroll_factor
:
6673 return "DW_AT_MIPS_loop_unroll_factor";
6674 case DW_AT_MIPS_software_pipeline_depth
:
6675 return "DW_AT_MIPS_software_pipeline_depth";
6677 case DW_AT_MIPS_linkage_name
:
6678 return "DW_AT_MIPS_linkage_name";
6680 case DW_AT_sf_names
:
6681 return "DW_AT_sf_names";
6682 case DW_AT_src_info
:
6683 return "DW_AT_src_info";
6684 case DW_AT_mac_info
:
6685 return "DW_AT_mac_info";
6686 case DW_AT_src_coords
:
6687 return "DW_AT_src_coords";
6688 case DW_AT_body_begin
:
6689 return "DW_AT_body_begin";
6690 case DW_AT_body_end
:
6691 return "DW_AT_body_end";
6692 case DW_AT_GNU_vector
:
6693 return "DW_AT_GNU_vector";
6695 return "DW_AT_<unknown>";
6699 /* Convert a DWARF value form code into its string name. */
6702 dwarf_form_name (unsigned form
)
6707 return "DW_FORM_addr";
6708 case DW_FORM_block2
:
6709 return "DW_FORM_block2";
6710 case DW_FORM_block4
:
6711 return "DW_FORM_block4";
6713 return "DW_FORM_data2";
6715 return "DW_FORM_data4";
6717 return "DW_FORM_data8";
6718 case DW_FORM_string
:
6719 return "DW_FORM_string";
6721 return "DW_FORM_block";
6722 case DW_FORM_block1
:
6723 return "DW_FORM_block1";
6725 return "DW_FORM_data1";
6727 return "DW_FORM_flag";
6729 return "DW_FORM_sdata";
6731 return "DW_FORM_strp";
6733 return "DW_FORM_udata";
6734 case DW_FORM_ref_addr
:
6735 return "DW_FORM_ref_addr";
6737 return "DW_FORM_ref1";
6739 return "DW_FORM_ref2";
6741 return "DW_FORM_ref4";
6743 return "DW_FORM_ref8";
6744 case DW_FORM_ref_udata
:
6745 return "DW_FORM_ref_udata";
6746 case DW_FORM_indirect
:
6747 return "DW_FORM_indirect";
6749 return "DW_FORM_<unknown>";
6753 /* Convert a DWARF stack opcode into its string name. */
6756 dwarf_stack_op_name (unsigned op
)
6761 return "DW_OP_addr";
6763 return "DW_OP_deref";
6765 return "DW_OP_const1u";
6767 return "DW_OP_const1s";
6769 return "DW_OP_const2u";
6771 return "DW_OP_const2s";
6773 return "DW_OP_const4u";
6775 return "DW_OP_const4s";
6777 return "DW_OP_const8u";
6779 return "DW_OP_const8s";
6781 return "DW_OP_constu";
6783 return "DW_OP_consts";
6787 return "DW_OP_drop";
6789 return "DW_OP_over";
6791 return "DW_OP_pick";
6793 return "DW_OP_swap";
6797 return "DW_OP_xderef";
6805 return "DW_OP_minus";
6817 return "DW_OP_plus";
6818 case DW_OP_plus_uconst
:
6819 return "DW_OP_plus_uconst";
6825 return "DW_OP_shra";
6843 return "DW_OP_skip";
6845 return "DW_OP_lit0";
6847 return "DW_OP_lit1";
6849 return "DW_OP_lit2";
6851 return "DW_OP_lit3";
6853 return "DW_OP_lit4";
6855 return "DW_OP_lit5";
6857 return "DW_OP_lit6";
6859 return "DW_OP_lit7";
6861 return "DW_OP_lit8";
6863 return "DW_OP_lit9";
6865 return "DW_OP_lit10";
6867 return "DW_OP_lit11";
6869 return "DW_OP_lit12";
6871 return "DW_OP_lit13";
6873 return "DW_OP_lit14";
6875 return "DW_OP_lit15";
6877 return "DW_OP_lit16";
6879 return "DW_OP_lit17";
6881 return "DW_OP_lit18";
6883 return "DW_OP_lit19";
6885 return "DW_OP_lit20";
6887 return "DW_OP_lit21";
6889 return "DW_OP_lit22";
6891 return "DW_OP_lit23";
6893 return "DW_OP_lit24";
6895 return "DW_OP_lit25";
6897 return "DW_OP_lit26";
6899 return "DW_OP_lit27";
6901 return "DW_OP_lit28";
6903 return "DW_OP_lit29";
6905 return "DW_OP_lit30";
6907 return "DW_OP_lit31";
6909 return "DW_OP_reg0";
6911 return "DW_OP_reg1";
6913 return "DW_OP_reg2";
6915 return "DW_OP_reg3";
6917 return "DW_OP_reg4";
6919 return "DW_OP_reg5";
6921 return "DW_OP_reg6";
6923 return "DW_OP_reg7";
6925 return "DW_OP_reg8";
6927 return "DW_OP_reg9";
6929 return "DW_OP_reg10";
6931 return "DW_OP_reg11";
6933 return "DW_OP_reg12";
6935 return "DW_OP_reg13";
6937 return "DW_OP_reg14";
6939 return "DW_OP_reg15";
6941 return "DW_OP_reg16";
6943 return "DW_OP_reg17";
6945 return "DW_OP_reg18";
6947 return "DW_OP_reg19";
6949 return "DW_OP_reg20";
6951 return "DW_OP_reg21";
6953 return "DW_OP_reg22";
6955 return "DW_OP_reg23";
6957 return "DW_OP_reg24";
6959 return "DW_OP_reg25";
6961 return "DW_OP_reg26";
6963 return "DW_OP_reg27";
6965 return "DW_OP_reg28";
6967 return "DW_OP_reg29";
6969 return "DW_OP_reg30";
6971 return "DW_OP_reg31";
6973 return "DW_OP_breg0";
6975 return "DW_OP_breg1";
6977 return "DW_OP_breg2";
6979 return "DW_OP_breg3";
6981 return "DW_OP_breg4";
6983 return "DW_OP_breg5";
6985 return "DW_OP_breg6";
6987 return "DW_OP_breg7";
6989 return "DW_OP_breg8";
6991 return "DW_OP_breg9";
6993 return "DW_OP_breg10";
6995 return "DW_OP_breg11";
6997 return "DW_OP_breg12";
6999 return "DW_OP_breg13";
7001 return "DW_OP_breg14";
7003 return "DW_OP_breg15";
7005 return "DW_OP_breg16";
7007 return "DW_OP_breg17";
7009 return "DW_OP_breg18";
7011 return "DW_OP_breg19";
7013 return "DW_OP_breg20";
7015 return "DW_OP_breg21";
7017 return "DW_OP_breg22";
7019 return "DW_OP_breg23";
7021 return "DW_OP_breg24";
7023 return "DW_OP_breg25";
7025 return "DW_OP_breg26";
7027 return "DW_OP_breg27";
7029 return "DW_OP_breg28";
7031 return "DW_OP_breg29";
7033 return "DW_OP_breg30";
7035 return "DW_OP_breg31";
7037 return "DW_OP_regx";
7039 return "DW_OP_fbreg";
7041 return "DW_OP_bregx";
7043 return "DW_OP_piece";
7044 case DW_OP_deref_size
:
7045 return "DW_OP_deref_size";
7046 case DW_OP_xderef_size
:
7047 return "DW_OP_xderef_size";
7050 /* DWARF 3 extensions. */
7051 case DW_OP_push_object_address
:
7052 return "DW_OP_push_object_address";
7054 return "DW_OP_call2";
7056 return "DW_OP_call4";
7057 case DW_OP_call_ref
:
7058 return "DW_OP_call_ref";
7059 /* GNU extensions. */
7060 case DW_OP_GNU_push_tls_address
:
7061 return "DW_OP_GNU_push_tls_address";
7063 return "OP_<unknown>";
7068 dwarf_bool_name (unsigned mybool
)
7076 /* Convert a DWARF type code into its string name. */
7079 dwarf_type_encoding_name (unsigned enc
)
7083 case DW_ATE_address
:
7084 return "DW_ATE_address";
7085 case DW_ATE_boolean
:
7086 return "DW_ATE_boolean";
7087 case DW_ATE_complex_float
:
7088 return "DW_ATE_complex_float";
7090 return "DW_ATE_float";
7092 return "DW_ATE_signed";
7093 case DW_ATE_signed_char
:
7094 return "DW_ATE_signed_char";
7095 case DW_ATE_unsigned
:
7096 return "DW_ATE_unsigned";
7097 case DW_ATE_unsigned_char
:
7098 return "DW_ATE_unsigned_char";
7099 case DW_ATE_imaginary_float
:
7100 return "DW_ATE_imaginary_float";
7102 return "DW_ATE_<unknown>";
7106 /* Convert a DWARF call frame info operation to its string name. */
7110 dwarf_cfi_name (unsigned cfi_opc
)
7114 case DW_CFA_advance_loc
:
7115 return "DW_CFA_advance_loc";
7117 return "DW_CFA_offset";
7118 case DW_CFA_restore
:
7119 return "DW_CFA_restore";
7121 return "DW_CFA_nop";
7122 case DW_CFA_set_loc
:
7123 return "DW_CFA_set_loc";
7124 case DW_CFA_advance_loc1
:
7125 return "DW_CFA_advance_loc1";
7126 case DW_CFA_advance_loc2
:
7127 return "DW_CFA_advance_loc2";
7128 case DW_CFA_advance_loc4
:
7129 return "DW_CFA_advance_loc4";
7130 case DW_CFA_offset_extended
:
7131 return "DW_CFA_offset_extended";
7132 case DW_CFA_restore_extended
:
7133 return "DW_CFA_restore_extended";
7134 case DW_CFA_undefined
:
7135 return "DW_CFA_undefined";
7136 case DW_CFA_same_value
:
7137 return "DW_CFA_same_value";
7138 case DW_CFA_register
:
7139 return "DW_CFA_register";
7140 case DW_CFA_remember_state
:
7141 return "DW_CFA_remember_state";
7142 case DW_CFA_restore_state
:
7143 return "DW_CFA_restore_state";
7144 case DW_CFA_def_cfa
:
7145 return "DW_CFA_def_cfa";
7146 case DW_CFA_def_cfa_register
:
7147 return "DW_CFA_def_cfa_register";
7148 case DW_CFA_def_cfa_offset
:
7149 return "DW_CFA_def_cfa_offset";
7152 case DW_CFA_def_cfa_expression
:
7153 return "DW_CFA_def_cfa_expression";
7154 case DW_CFA_expression
:
7155 return "DW_CFA_expression";
7156 case DW_CFA_offset_extended_sf
:
7157 return "DW_CFA_offset_extended_sf";
7158 case DW_CFA_def_cfa_sf
:
7159 return "DW_CFA_def_cfa_sf";
7160 case DW_CFA_def_cfa_offset_sf
:
7161 return "DW_CFA_def_cfa_offset_sf";
7163 /* SGI/MIPS specific */
7164 case DW_CFA_MIPS_advance_loc8
:
7165 return "DW_CFA_MIPS_advance_loc8";
7167 /* GNU extensions */
7168 case DW_CFA_GNU_window_save
:
7169 return "DW_CFA_GNU_window_save";
7170 case DW_CFA_GNU_args_size
:
7171 return "DW_CFA_GNU_args_size";
7172 case DW_CFA_GNU_negative_offset_extended
:
7173 return "DW_CFA_GNU_negative_offset_extended";
7176 return "DW_CFA_<unknown>";
7182 dump_die (struct die_info
*die
)
7186 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
7187 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
7188 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
7189 dwarf_bool_name (die
->child
!= NULL
));
7191 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
7192 for (i
= 0; i
< die
->num_attrs
; ++i
)
7194 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
7195 dwarf_attr_name (die
->attrs
[i
].name
),
7196 dwarf_form_name (die
->attrs
[i
].form
));
7197 switch (die
->attrs
[i
].form
)
7199 case DW_FORM_ref_addr
:
7201 fprintf_unfiltered (gdb_stderr
, "address: ");
7202 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
7204 case DW_FORM_block2
:
7205 case DW_FORM_block4
:
7207 case DW_FORM_block1
:
7208 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
7219 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
7221 case DW_FORM_string
:
7223 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
7224 DW_STRING (&die
->attrs
[i
])
7225 ? DW_STRING (&die
->attrs
[i
]) : "");
7228 if (DW_UNSND (&die
->attrs
[i
]))
7229 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
7231 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
7233 case DW_FORM_indirect
:
7234 /* the reader will have reduced the indirect form to
7235 the "base form" so this form should not occur */
7236 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
7239 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
7240 die
->attrs
[i
].form
);
7242 fprintf_unfiltered (gdb_stderr
, "\n");
7247 dump_die_list (struct die_info
*die
)
7252 if (die
->child
!= NULL
)
7253 dump_die_list (die
->child
);
7254 if (die
->sibling
!= NULL
)
7255 dump_die_list (die
->sibling
);
7260 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
7263 struct die_info
*old
;
7265 h
= (offset
% REF_HASH_SIZE
);
7266 old
= die_ref_table
[h
];
7267 die
->next_ref
= old
;
7268 die_ref_table
[h
] = die
;
7273 dwarf2_empty_hash_tables (void)
7275 memset (die_ref_table
, 0, sizeof (die_ref_table
));
7279 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
7281 unsigned int result
= 0;
7285 case DW_FORM_ref_addr
:
7286 result
= DW_ADDR (attr
);
7292 case DW_FORM_ref_udata
:
7293 result
= cu
->header
.offset
+ DW_UNSND (attr
);
7296 complaint (&symfile_complaints
,
7297 "unsupported die ref attribute form: '%s'",
7298 dwarf_form_name (attr
->form
));
7303 /* Return the constant value held by the given attribute. Return -1
7304 if the value held by the attribute is not constant. */
7307 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
7309 if (attr
->form
== DW_FORM_sdata
)
7310 return DW_SND (attr
);
7311 else if (attr
->form
== DW_FORM_udata
7312 || attr
->form
== DW_FORM_data1
7313 || attr
->form
== DW_FORM_data2
7314 || attr
->form
== DW_FORM_data4
7315 || attr
->form
== DW_FORM_data8
)
7316 return DW_UNSND (attr
);
7319 complaint (&symfile_complaints
, "Attribute value is not a constant (%s)",
7320 dwarf_form_name (attr
->form
));
7321 return default_value
;
7325 static struct die_info
*
7326 follow_die_ref (unsigned int offset
)
7328 struct die_info
*die
;
7331 h
= (offset
% REF_HASH_SIZE
);
7332 die
= die_ref_table
[h
];
7335 if (die
->offset
== offset
)
7339 die
= die
->next_ref
;
7344 static struct type
*
7345 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid,
7346 struct dwarf2_cu
*cu
)
7348 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
7350 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
7351 typeid, objfile
->name
);
7354 /* Look for this particular type in the fundamental type vector. If
7355 one is not found, create and install one appropriate for the
7356 current language and the current target machine. */
7358 if (cu
->ftypes
[typeid] == NULL
)
7360 cu
->ftypes
[typeid] = cu
->language_defn
->la_fund_type (objfile
, typeid);
7363 return (cu
->ftypes
[typeid]);
7366 /* Decode simple location descriptions.
7367 Given a pointer to a dwarf block that defines a location, compute
7368 the location and return the value.
7370 NOTE drow/2003-11-18: This function is called in two situations
7371 now: for the address of static or global variables (partial symbols
7372 only) and for offsets into structures which are expected to be
7373 (more or less) constant. The partial symbol case should go away,
7374 and only the constant case should remain. That will let this
7375 function complain more accurately. A few special modes are allowed
7376 without complaint for global variables (for instance, global
7377 register values and thread-local values).
7379 A location description containing no operations indicates that the
7380 object is optimized out. The return value is 0 for that case.
7381 FIXME drow/2003-11-16: No callers check for this case any more; soon all
7382 callers will only want a very basic result and this can become a
7385 When the result is a register number, the global isreg flag is set,
7386 otherwise it is cleared.
7388 Note that stack[0] is unused except as a default error return.
7389 Note that stack overflow is not yet handled. */
7392 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
7394 struct objfile
*objfile
= cu
->objfile
;
7395 struct comp_unit_head
*cu_header
= &cu
->header
;
7397 int size
= blk
->size
;
7398 char *data
= blk
->data
;
7399 CORE_ADDR stack
[64];
7401 unsigned int bytes_read
, unsnd
;
7446 stack
[++stacki
] = op
- DW_OP_lit0
;
7482 stack
[++stacki
] = op
- DW_OP_reg0
;
7484 dwarf2_complex_location_expr_complaint ();
7489 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
7491 stack
[++stacki
] = unsnd
;
7493 dwarf2_complex_location_expr_complaint ();
7497 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
7503 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
7508 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
7513 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
7518 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
7523 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
7528 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
7533 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
7539 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
7544 stack
[stacki
+ 1] = stack
[stacki
];
7549 stack
[stacki
- 1] += stack
[stacki
];
7553 case DW_OP_plus_uconst
:
7554 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
7559 stack
[stacki
- 1] -= stack
[stacki
];
7564 /* If we're not the last op, then we definitely can't encode
7565 this using GDB's address_class enum. This is valid for partial
7566 global symbols, although the variable's address will be bogus
7569 dwarf2_complex_location_expr_complaint ();
7572 case DW_OP_GNU_push_tls_address
:
7573 /* The top of the stack has the offset from the beginning
7574 of the thread control block at which the variable is located. */
7575 /* Nothing should follow this operator, so the top of stack would
7577 /* This is valid for partial global symbols, but the variable's
7578 address will be bogus in the psymtab. */
7580 dwarf2_complex_location_expr_complaint ();
7584 complaint (&symfile_complaints
, "unsupported stack op: '%s'",
7585 dwarf_stack_op_name (op
));
7586 return (stack
[stacki
]);
7589 return (stack
[stacki
]);
7592 /* memory allocation interface */
7595 dwarf2_free_tmp_obstack (void *ignore
)
7597 obstack_free (&dwarf2_tmp_obstack
, NULL
);
7600 static struct dwarf_block
*
7601 dwarf_alloc_block (void)
7603 struct dwarf_block
*blk
;
7605 blk
= (struct dwarf_block
*)
7606 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
7610 static struct abbrev_info
*
7611 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
7613 struct abbrev_info
*abbrev
;
7615 abbrev
= (struct abbrev_info
*)
7616 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
7617 memset (abbrev
, 0, sizeof (struct abbrev_info
));
7621 static struct die_info
*
7622 dwarf_alloc_die (void)
7624 struct die_info
*die
;
7626 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
7627 memset (die
, 0, sizeof (struct die_info
));
7632 /* Macro support. */
7635 /* Return the full name of file number I in *LH's file name table.
7636 Use COMP_DIR as the name of the current directory of the
7637 compilation. The result is allocated using xmalloc; the caller is
7638 responsible for freeing it. */
7640 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
7642 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7644 if (IS_ABSOLUTE_PATH (fe
->name
))
7645 return xstrdup (fe
->name
);
7653 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7659 dir_len
= strlen (dir
);
7660 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
7661 strcpy (full_name
, dir
);
7662 full_name
[dir_len
] = '/';
7663 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
7667 return xstrdup (fe
->name
);
7672 static struct macro_source_file
*
7673 macro_start_file (int file
, int line
,
7674 struct macro_source_file
*current_file
,
7675 const char *comp_dir
,
7676 struct line_header
*lh
, struct objfile
*objfile
)
7678 /* The full name of this source file. */
7679 char *full_name
= file_full_name (file
, lh
, comp_dir
);
7681 /* We don't create a macro table for this compilation unit
7682 at all until we actually get a filename. */
7683 if (! pending_macros
)
7684 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
7685 objfile
->macro_cache
);
7688 /* If we have no current file, then this must be the start_file
7689 directive for the compilation unit's main source file. */
7690 current_file
= macro_set_main (pending_macros
, full_name
);
7692 current_file
= macro_include (current_file
, line
, full_name
);
7696 return current_file
;
7700 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
7701 followed by a null byte. */
7703 copy_string (const char *buf
, int len
)
7705 char *s
= xmalloc (len
+ 1);
7706 memcpy (s
, buf
, len
);
7714 consume_improper_spaces (const char *p
, const char *body
)
7718 complaint (&symfile_complaints
,
7719 "macro definition contains spaces in formal argument list:\n`%s'",
7731 parse_macro_definition (struct macro_source_file
*file
, int line
,
7736 /* The body string takes one of two forms. For object-like macro
7737 definitions, it should be:
7739 <macro name> " " <definition>
7741 For function-like macro definitions, it should be:
7743 <macro name> "() " <definition>
7745 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
7747 Spaces may appear only where explicitly indicated, and in the
7750 The Dwarf 2 spec says that an object-like macro's name is always
7751 followed by a space, but versions of GCC around March 2002 omit
7752 the space when the macro's definition is the empty string.
7754 The Dwarf 2 spec says that there should be no spaces between the
7755 formal arguments in a function-like macro's formal argument list,
7756 but versions of GCC around March 2002 include spaces after the
7760 /* Find the extent of the macro name. The macro name is terminated
7761 by either a space or null character (for an object-like macro) or
7762 an opening paren (for a function-like macro). */
7763 for (p
= body
; *p
; p
++)
7764 if (*p
== ' ' || *p
== '(')
7767 if (*p
== ' ' || *p
== '\0')
7769 /* It's an object-like macro. */
7770 int name_len
= p
- body
;
7771 char *name
= copy_string (body
, name_len
);
7772 const char *replacement
;
7775 replacement
= body
+ name_len
+ 1;
7778 dwarf2_macro_malformed_definition_complaint (body
);
7779 replacement
= body
+ name_len
;
7782 macro_define_object (file
, line
, name
, replacement
);
7788 /* It's a function-like macro. */
7789 char *name
= copy_string (body
, p
- body
);
7792 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
7796 p
= consume_improper_spaces (p
, body
);
7798 /* Parse the formal argument list. */
7799 while (*p
&& *p
!= ')')
7801 /* Find the extent of the current argument name. */
7802 const char *arg_start
= p
;
7804 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
7807 if (! *p
|| p
== arg_start
)
7808 dwarf2_macro_malformed_definition_complaint (body
);
7811 /* Make sure argv has room for the new argument. */
7812 if (argc
>= argv_size
)
7815 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
7818 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
7821 p
= consume_improper_spaces (p
, body
);
7823 /* Consume the comma, if present. */
7828 p
= consume_improper_spaces (p
, body
);
7837 /* Perfectly formed definition, no complaints. */
7838 macro_define_function (file
, line
, name
,
7839 argc
, (const char **) argv
,
7841 else if (*p
== '\0')
7843 /* Complain, but do define it. */
7844 dwarf2_macro_malformed_definition_complaint (body
);
7845 macro_define_function (file
, line
, name
,
7846 argc
, (const char **) argv
,
7850 /* Just complain. */
7851 dwarf2_macro_malformed_definition_complaint (body
);
7854 /* Just complain. */
7855 dwarf2_macro_malformed_definition_complaint (body
);
7861 for (i
= 0; i
< argc
; i
++)
7867 dwarf2_macro_malformed_definition_complaint (body
);
7872 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
7873 char *comp_dir
, bfd
*abfd
,
7874 struct dwarf2_cu
*cu
)
7876 char *mac_ptr
, *mac_end
;
7877 struct macro_source_file
*current_file
= 0;
7879 if (dwarf_macinfo_buffer
== NULL
)
7881 complaint (&symfile_complaints
, "missing .debug_macinfo section");
7885 mac_ptr
= dwarf_macinfo_buffer
+ offset
;
7886 mac_end
= dwarf_macinfo_buffer
+ dwarf_macinfo_size
;
7890 enum dwarf_macinfo_record_type macinfo_type
;
7892 /* Do we at least have room for a macinfo type byte? */
7893 if (mac_ptr
>= mac_end
)
7895 dwarf2_macros_too_long_complaint ();
7899 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
7902 switch (macinfo_type
)
7904 /* A zero macinfo type indicates the end of the macro
7909 case DW_MACINFO_define
:
7910 case DW_MACINFO_undef
:
7916 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7917 mac_ptr
+= bytes_read
;
7918 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
7919 mac_ptr
+= bytes_read
;
7922 complaint (&symfile_complaints
,
7923 "debug info gives macro %s outside of any file: %s",
7925 DW_MACINFO_define
? "definition" : macinfo_type
==
7926 DW_MACINFO_undef
? "undefinition" :
7927 "something-or-other", body
);
7930 if (macinfo_type
== DW_MACINFO_define
)
7931 parse_macro_definition (current_file
, line
, body
);
7932 else if (macinfo_type
== DW_MACINFO_undef
)
7933 macro_undef (current_file
, line
, body
);
7938 case DW_MACINFO_start_file
:
7943 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7944 mac_ptr
+= bytes_read
;
7945 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7946 mac_ptr
+= bytes_read
;
7948 current_file
= macro_start_file (file
, line
,
7949 current_file
, comp_dir
,
7954 case DW_MACINFO_end_file
:
7956 complaint (&symfile_complaints
,
7957 "macro debug info has an unmatched `close_file' directive");
7960 current_file
= current_file
->included_by
;
7963 enum dwarf_macinfo_record_type next_type
;
7965 /* GCC circa March 2002 doesn't produce the zero
7966 type byte marking the end of the compilation
7967 unit. Complain if it's not there, but exit no
7970 /* Do we at least have room for a macinfo type byte? */
7971 if (mac_ptr
>= mac_end
)
7973 dwarf2_macros_too_long_complaint ();
7977 /* We don't increment mac_ptr here, so this is just
7979 next_type
= read_1_byte (abfd
, mac_ptr
);
7981 complaint (&symfile_complaints
,
7982 "no terminating 0-type entry for macros in `.debug_macinfo' section");
7989 case DW_MACINFO_vendor_ext
:
7995 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7996 mac_ptr
+= bytes_read
;
7997 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
7998 mac_ptr
+= bytes_read
;
8000 /* We don't recognize any vendor extensions. */
8007 /* Check if the attribute's form is a DW_FORM_block*
8008 if so return true else false. */
8010 attr_form_is_block (struct attribute
*attr
)
8012 return (attr
== NULL
? 0 :
8013 attr
->form
== DW_FORM_block1
8014 || attr
->form
== DW_FORM_block2
8015 || attr
->form
== DW_FORM_block4
8016 || attr
->form
== DW_FORM_block
);
8020 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
8021 struct dwarf2_cu
*cu
)
8023 if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
8025 struct dwarf2_loclist_baton
*baton
;
8027 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
8028 sizeof (struct dwarf2_loclist_baton
));
8029 baton
->objfile
= cu
->objfile
;
8031 /* We don't know how long the location list is, but make sure we
8032 don't run off the edge of the section. */
8033 baton
->size
= dwarf_loc_size
- DW_UNSND (attr
);
8034 baton
->data
= dwarf_loc_buffer
+ DW_UNSND (attr
);
8035 baton
->base_address
= cu
->header
.base_address
;
8036 if (cu
->header
.base_known
== 0)
8037 complaint (&symfile_complaints
,
8038 "Location list used without specifying the CU base address.");
8040 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
8041 SYMBOL_LOCATION_BATON (sym
) = baton
;
8045 struct dwarf2_locexpr_baton
*baton
;
8047 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
8048 sizeof (struct dwarf2_locexpr_baton
));
8049 baton
->objfile
= cu
->objfile
;
8051 if (attr_form_is_block (attr
))
8053 /* Note that we're just copying the block's data pointer
8054 here, not the actual data. We're still pointing into the
8055 dwarf_info_buffer for SYM's objfile; right now we never
8056 release that buffer, but when we do clean up properly
8057 this may need to change. */
8058 baton
->size
= DW_BLOCK (attr
)->size
;
8059 baton
->data
= DW_BLOCK (attr
)->data
;
8063 dwarf2_invalid_attrib_class_complaint ("location description",
8064 SYMBOL_NATURAL_NAME (sym
));
8069 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
8070 SYMBOL_LOCATION_BATON (sym
) = baton
;