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"
52 #include "gdb_string.h"
53 #include "gdb_assert.h"
54 #include <sys/types.h>
56 /* A note on memory usage for this file.
58 At the present time, this code reads the debug info sections into
59 the objfile's objfile_obstack. A definite improvement for startup
60 time, on platforms which do not emit relocations for debug
61 sections, would be to use mmap instead. The object's complete
62 debug information is loaded into memory, partly to simplify
63 absolute DIE references.
65 Whether using obstacks or mmap, the sections should remain loaded
66 until the objfile is released, and pointers into the section data
67 can be used for any other data associated to the objfile (symbol
68 names, type names, location expressions to name a few). */
70 #ifndef DWARF2_REG_TO_REGNUM
71 #define DWARF2_REG_TO_REGNUM(REG) (REG)
75 /* .debug_info header for a compilation unit
76 Because of alignment constraints, this structure has padding and cannot
77 be mapped directly onto the beginning of the .debug_info section. */
78 typedef struct comp_unit_header
80 unsigned int length
; /* length of the .debug_info
82 unsigned short version
; /* version number -- 2 for DWARF
84 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
85 unsigned char addr_size
; /* byte size of an address -- 4 */
88 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
91 /* .debug_pubnames header
92 Because of alignment constraints, this structure has padding and cannot
93 be mapped directly onto the beginning of the .debug_info section. */
94 typedef struct pubnames_header
96 unsigned int length
; /* length of the .debug_pubnames
98 unsigned char version
; /* version number -- 2 for DWARF
100 unsigned int info_offset
; /* offset into .debug_info section */
101 unsigned int info_size
; /* byte size of .debug_info section
105 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
107 /* .debug_pubnames header
108 Because of alignment constraints, this structure has padding and cannot
109 be mapped directly onto the beginning of the .debug_info section. */
110 typedef struct aranges_header
112 unsigned int length
; /* byte len of the .debug_aranges
114 unsigned short version
; /* version number -- 2 for DWARF
116 unsigned int info_offset
; /* offset into .debug_info section */
117 unsigned char addr_size
; /* byte size of an address */
118 unsigned char seg_size
; /* byte size of segment descriptor */
121 #define _ACTUAL_ARANGES_HEADER_SIZE 12
123 /* .debug_line statement program prologue
124 Because of alignment constraints, this structure has padding and cannot
125 be mapped directly onto the beginning of the .debug_info section. */
126 typedef struct statement_prologue
128 unsigned int total_length
; /* byte length of the statement
130 unsigned short version
; /* version number -- 2 for DWARF
132 unsigned int prologue_length
; /* # bytes between prologue &
134 unsigned char minimum_instruction_length
; /* byte size of
136 unsigned char default_is_stmt
; /* initial value of is_stmt
139 unsigned char line_range
;
140 unsigned char opcode_base
; /* number assigned to first special
142 unsigned char *standard_opcode_lengths
;
146 static const struct objfile_data
*dwarf2_objfile_data_key
;
148 struct dwarf2_per_objfile
150 /* Sizes of debugging sections. */
151 unsigned int info_size
;
152 unsigned int abbrev_size
;
153 unsigned int line_size
;
154 unsigned int pubnames_size
;
155 unsigned int aranges_size
;
156 unsigned int loc_size
;
157 unsigned int macinfo_size
;
158 unsigned int str_size
;
159 unsigned int ranges_size
;
160 unsigned int frame_size
;
161 unsigned int eh_frame_size
;
163 /* Loaded data from the sections. */
168 char *macinfo_buffer
;
172 /* A list of all the compilation units. This is used to locate
173 the target compilation unit of a particular reference. */
174 struct dwarf2_per_cu_data
**all_comp_units
;
176 /* The number of compilation units in ALL_COMP_UNITS. */
179 /* A chain of compilation units that are currently read in, so that
180 they can be freed later. */
181 struct dwarf2_per_cu_data
*read_in_chain
;
184 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
186 static asection
*dwarf_info_section
;
187 static asection
*dwarf_abbrev_section
;
188 static asection
*dwarf_line_section
;
189 static asection
*dwarf_pubnames_section
;
190 static asection
*dwarf_aranges_section
;
191 static asection
*dwarf_loc_section
;
192 static asection
*dwarf_macinfo_section
;
193 static asection
*dwarf_str_section
;
194 static asection
*dwarf_ranges_section
;
195 asection
*dwarf_frame_section
;
196 asection
*dwarf_eh_frame_section
;
198 /* names of the debugging sections */
200 #define INFO_SECTION ".debug_info"
201 #define ABBREV_SECTION ".debug_abbrev"
202 #define LINE_SECTION ".debug_line"
203 #define PUBNAMES_SECTION ".debug_pubnames"
204 #define ARANGES_SECTION ".debug_aranges"
205 #define LOC_SECTION ".debug_loc"
206 #define MACINFO_SECTION ".debug_macinfo"
207 #define STR_SECTION ".debug_str"
208 #define RANGES_SECTION ".debug_ranges"
209 #define FRAME_SECTION ".debug_frame"
210 #define EH_FRAME_SECTION ".eh_frame"
212 /* local data types */
214 /* We hold several abbreviation tables in memory at the same time. */
215 #ifndef ABBREV_HASH_SIZE
216 #define ABBREV_HASH_SIZE 121
219 /* The data in a compilation unit header, after target2host
220 translation, looks like this. */
221 struct comp_unit_head
223 unsigned long length
;
225 unsigned int abbrev_offset
;
226 unsigned char addr_size
;
227 unsigned char signed_addr_p
;
229 /* Size of file offsets; either 4 or 8. */
230 unsigned int offset_size
;
232 /* Size of the length field; either 4 or 12. */
233 unsigned int initial_length_size
;
235 /* Offset to the first byte of this compilation unit header in the
236 .debug_info section, for resolving relative reference dies. */
239 /* Pointer to this compilation unit header in the .debug_info
243 /* Pointer to the first die of this compilation unit. This will be
244 the first byte following the compilation unit header. */
247 /* Pointer to the next compilation unit header in the program. */
248 struct comp_unit_head
*next
;
250 /* Base address of this compilation unit. */
251 CORE_ADDR base_address
;
253 /* Non-zero if base_address has been set. */
257 /* Fixed size for the DIE hash table. */
258 #ifndef REF_HASH_SIZE
259 #define REF_HASH_SIZE 1021
262 /* Internal state when decoding a particular compilation unit. */
265 /* The objfile containing this compilation unit. */
266 struct objfile
*objfile
;
268 /* The header of the compilation unit.
270 FIXME drow/2003-11-10: Some of the things from the comp_unit_head
271 should logically be moved to the dwarf2_cu structure. */
272 struct comp_unit_head header
;
274 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
276 /* The language we are debugging. */
277 enum language language
;
278 const struct language_defn
*language_defn
;
280 const char *producer
;
282 /* The generic symbol table building routines have separate lists for
283 file scope symbols and all all other scopes (local scopes). So
284 we need to select the right one to pass to add_symbol_to_list().
285 We do it by keeping a pointer to the correct list in list_in_scope.
287 FIXME: The original dwarf code just treated the file scope as the
288 first local scope, and all other local scopes as nested local
289 scopes, and worked fine. Check to see if we really need to
290 distinguish these in buildsym.c. */
291 struct pending
**list_in_scope
;
293 /* Maintain an array of referenced fundamental types for the current
294 compilation unit being read. For DWARF version 1, we have to construct
295 the fundamental types on the fly, since no information about the
296 fundamental types is supplied. Each such fundamental type is created by
297 calling a language dependent routine to create the type, and then a
298 pointer to that type is then placed in the array at the index specified
299 by it's FT_<TYPENAME> value. The array has a fixed size set by the
300 FT_NUM_MEMBERS compile time constant, which is the number of predefined
301 fundamental types gdb knows how to construct. */
302 struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
304 /* DWARF abbreviation table associated with this compilation unit. */
305 struct abbrev_info
**dwarf2_abbrevs
;
307 /* Storage for the abbrev table. */
308 struct obstack abbrev_obstack
;
310 /* Hash table holding all the loaded partial DIEs. */
313 /* Storage for things with the same lifetime as this read-in compilation
314 unit, including partial DIEs. */
315 struct obstack comp_unit_obstack
;
317 /* When multiple dwarf2_cu structures are living in memory, this field
318 chains them all together, so that they can be released efficiently.
319 We will probably also want a generation counter so that most-recently-used
320 compilation units are cached... */
321 struct dwarf2_per_cu_data
*read_in_chain
;
323 /* Backchain to our per_cu entry if the tree has been built. */
324 struct dwarf2_per_cu_data
*per_cu
;
326 /* How many compilation units ago was this CU last referenced? */
329 /* A hash table of die offsets for following references. */
330 struct die_info
*die_ref_table
[REF_HASH_SIZE
];
332 /* Full DIEs if read in. */
333 struct die_info
*dies
;
335 /* A set of pointers to dwarf2_per_cu_data objects for compilation
336 units referenced by this one. Only set during full symbol processing;
337 partial symbol tables do not have dependencies. */
340 /* Mark used when releasing cached dies. */
341 unsigned int mark
: 1;
343 /* This flag will be set if this compilation unit might include
344 inter-compilation-unit references. */
345 unsigned int has_form_ref_addr
: 1;
347 /* This flag will be set if this compilation unit includes any
348 DW_TAG_namespace DIEs. If we know that there are explicit
349 DIEs for namespaces, we don't need to try to infer them
350 from mangled names. */
351 unsigned int has_namespace_info
: 1;
354 /* Persistent data held for a compilation unit, even when not
355 processing it. We put a pointer to this structure in the
356 read_symtab_private field of the psymtab. If we encounter
357 inter-compilation-unit references, we also maintain a sorted
358 list of all compilation units. */
360 struct dwarf2_per_cu_data
362 /* The start offset and length of this compilation unit. 2**31-1
363 bytes should suffice to store the length of any compilation unit
364 - if it doesn't, GDB will fall over anyway. */
365 unsigned long offset
;
366 unsigned long length
: 31;
368 /* Flag indicating this compilation unit will be read in before
369 any of the current compilation units are processed. */
370 unsigned long queued
: 1;
372 /* Set iff currently read in. */
373 struct dwarf2_cu
*cu
;
375 /* If full symbols for this CU have been read in, then this field
376 holds a map of DIE offsets to types. It isn't always possible
377 to reconstruct this information later, so we have to preserve
381 /* The partial symbol table associated with this compilation unit. */
382 struct partial_symtab
*psymtab
;
385 /* The line number information for a compilation unit (found in the
386 .debug_line section) begins with a "statement program header",
387 which contains the following information. */
390 unsigned int total_length
;
391 unsigned short version
;
392 unsigned int header_length
;
393 unsigned char minimum_instruction_length
;
394 unsigned char default_is_stmt
;
396 unsigned char line_range
;
397 unsigned char opcode_base
;
399 /* standard_opcode_lengths[i] is the number of operands for the
400 standard opcode whose value is i. This means that
401 standard_opcode_lengths[0] is unused, and the last meaningful
402 element is standard_opcode_lengths[opcode_base - 1]. */
403 unsigned char *standard_opcode_lengths
;
405 /* The include_directories table. NOTE! These strings are not
406 allocated with xmalloc; instead, they are pointers into
407 debug_line_buffer. If you try to free them, `free' will get
409 unsigned int num_include_dirs
, include_dirs_size
;
412 /* The file_names table. NOTE! These strings are not allocated
413 with xmalloc; instead, they are pointers into debug_line_buffer.
414 Don't try to free them directly. */
415 unsigned int num_file_names
, file_names_size
;
419 unsigned int dir_index
;
420 unsigned int mod_time
;
422 int included_p
; /* Non-zero if referenced by the Line Number Program. */
425 /* The start and end of the statement program following this
426 header. These point into dwarf2_per_objfile->line_buffer. */
427 char *statement_program_start
, *statement_program_end
;
430 /* When we construct a partial symbol table entry we only
431 need this much information. */
432 struct partial_die_info
434 /* Offset of this DIE. */
437 /* DWARF-2 tag for this DIE. */
438 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
440 /* Language code associated with this DIE. This is only used
441 for the compilation unit DIE. */
442 unsigned int language
: 8;
444 /* Assorted flags describing the data found in this DIE. */
445 unsigned int has_children
: 1;
446 unsigned int is_external
: 1;
447 unsigned int is_declaration
: 1;
448 unsigned int has_type
: 1;
449 unsigned int has_specification
: 1;
450 unsigned int has_stmt_list
: 1;
451 unsigned int has_pc_info
: 1;
453 /* Flag set if the SCOPE field of this structure has been
455 unsigned int scope_set
: 1;
457 /* The name of this DIE. Normally the value of DW_AT_name, but
458 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
463 /* The scope to prepend to our children. This is generally
464 allocated on the comp_unit_obstack, so will disappear
465 when this compilation unit leaves the cache. */
468 /* The location description associated with this DIE, if any. */
469 struct dwarf_block
*locdesc
;
471 /* If HAS_PC_INFO, the PC range associated with this DIE. */
475 /* Pointer into the info_buffer pointing at the target of
476 DW_AT_sibling, if any. */
479 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
480 DW_AT_specification (or DW_AT_abstract_origin or
482 unsigned int spec_offset
;
484 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
485 unsigned int line_offset
;
487 /* Pointers to this DIE's parent, first child, and next sibling,
489 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
492 /* This data structure holds the information of an abbrev. */
495 unsigned int number
; /* number identifying abbrev */
496 enum dwarf_tag tag
; /* dwarf tag */
497 unsigned short has_children
; /* boolean */
498 unsigned short num_attrs
; /* number of attributes */
499 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
500 struct abbrev_info
*next
; /* next in chain */
505 enum dwarf_attribute name
;
506 enum dwarf_form form
;
509 /* This data structure holds a complete die structure. */
512 enum dwarf_tag tag
; /* Tag indicating type of die */
513 unsigned int abbrev
; /* Abbrev number */
514 unsigned int offset
; /* Offset in .debug_info section */
515 unsigned int num_attrs
; /* Number of attributes */
516 struct attribute
*attrs
; /* An array of attributes */
517 struct die_info
*next_ref
; /* Next die in ref hash table */
519 /* The dies in a compilation unit form an n-ary tree. PARENT
520 points to this die's parent; CHILD points to the first child of
521 this node; and all the children of a given node are chained
522 together via their SIBLING fields, terminated by a die whose
524 struct die_info
*child
; /* Its first child, if any. */
525 struct die_info
*sibling
; /* Its next sibling, if any. */
526 struct die_info
*parent
; /* Its parent, if any. */
528 struct type
*type
; /* Cached type information */
531 /* Attributes have a name and a value */
534 enum dwarf_attribute name
;
535 enum dwarf_form form
;
539 struct dwarf_block
*blk
;
547 struct function_range
550 CORE_ADDR lowpc
, highpc
;
552 struct function_range
*next
;
555 /* Get at parts of an attribute structure */
557 #define DW_STRING(attr) ((attr)->u.str)
558 #define DW_UNSND(attr) ((attr)->u.unsnd)
559 #define DW_BLOCK(attr) ((attr)->u.blk)
560 #define DW_SND(attr) ((attr)->u.snd)
561 #define DW_ADDR(attr) ((attr)->u.addr)
563 /* Blocks are a bunch of untyped bytes. */
570 #ifndef ATTR_ALLOC_CHUNK
571 #define ATTR_ALLOC_CHUNK 4
574 /* Allocate fields for structs, unions and enums in this size. */
575 #ifndef DW_FIELD_ALLOC_CHUNK
576 #define DW_FIELD_ALLOC_CHUNK 4
579 /* A zeroed version of a partial die for initialization purposes. */
580 static struct partial_die_info zeroed_partial_die
;
582 /* FIXME: decode_locdesc sets these variables to describe the location
583 to the caller. These ought to be a structure or something. If
584 none of the flags are set, the object lives at the address returned
585 by decode_locdesc. */
587 static int isreg
; /* Object lives in register.
588 decode_locdesc's return value is
589 the register number. */
591 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
592 but this would require a corresponding change in unpack_field_as_long
594 static int bits_per_byte
= 8;
596 /* The routines that read and process dies for a C struct or C++ class
597 pass lists of data member fields and lists of member function fields
598 in an instance of a field_info structure, as defined below. */
601 /* List of data member and baseclasses fields. */
604 struct nextfield
*next
;
611 /* Number of fields. */
614 /* Number of baseclasses. */
617 /* Set if the accesibility of one of the fields is not public. */
618 int non_public_fields
;
620 /* Member function fields array, entries are allocated in the order they
621 are encountered in the object file. */
624 struct nextfnfield
*next
;
625 struct fn_field fnfield
;
629 /* Member function fieldlist array, contains name of possibly overloaded
630 member function, number of overloaded member functions and a pointer
631 to the head of the member function field chain. */
636 struct nextfnfield
*head
;
640 /* Number of entries in the fnfieldlists array. */
644 /* One item on the queue of compilation units to read in full symbols
646 struct dwarf2_queue_item
648 struct dwarf2_per_cu_data
*per_cu
;
649 struct dwarf2_queue_item
*next
;
652 /* The current queue. */
653 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
655 /* Loaded secondary compilation units are kept in memory until they
656 have not been referenced for the processing of this many
657 compilation units. Set this to zero to disable caching. Cache
658 sizes of up to at least twenty will improve startup time for
659 typical inter-CU-reference binaries, at an obvious memory cost. */
660 static int dwarf2_max_cache_age
= 5;
662 /* Various complaints about symbol reading that don't abort the process */
665 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
667 complaint (&symfile_complaints
,
668 "statement list doesn't fit in .debug_line section");
672 dwarf2_complex_location_expr_complaint (void)
674 complaint (&symfile_complaints
, "location expression too complex");
678 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
681 complaint (&symfile_complaints
,
682 "const value length mismatch for '%s', got %d, expected %d", arg1
,
687 dwarf2_macros_too_long_complaint (void)
689 complaint (&symfile_complaints
,
690 "macro info runs off end of `.debug_macinfo' section");
694 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
696 complaint (&symfile_complaints
,
697 "macro debug info contains a malformed macro definition:\n`%s'",
702 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
704 complaint (&symfile_complaints
,
705 "invalid attribute class or form for '%s' in '%s'", arg1
, arg2
);
708 /* local function prototypes */
710 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
713 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
716 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
719 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
720 struct partial_die_info
*,
721 struct partial_symtab
*);
723 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
725 static void scan_partial_symbols (struct partial_die_info
*,
726 CORE_ADDR
*, CORE_ADDR
*,
729 static void add_partial_symbol (struct partial_die_info
*,
732 static int pdi_needs_namespace (enum dwarf_tag tag
);
734 static void add_partial_namespace (struct partial_die_info
*pdi
,
735 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
736 struct dwarf2_cu
*cu
);
738 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
739 struct dwarf2_cu
*cu
);
741 static char *locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
744 struct dwarf2_cu
*cu
);
746 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
748 static void psymtab_to_symtab_1 (struct partial_symtab
*);
750 char *dwarf2_read_section (struct objfile
*, asection
*);
752 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
754 static void dwarf2_free_abbrev_table (void *);
756 static struct abbrev_info
*peek_die_abbrev (char *, int *, struct dwarf2_cu
*);
758 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
761 static struct partial_die_info
*load_partial_dies (bfd
*, char *, int,
764 static char *read_partial_die (struct partial_die_info
*,
765 struct abbrev_info
*abbrev
, unsigned int,
766 bfd
*, char *, struct dwarf2_cu
*);
768 static struct partial_die_info
*find_partial_die (unsigned long,
771 static void fixup_partial_die (struct partial_die_info
*,
774 static char *read_full_die (struct die_info
**, bfd
*, char *,
775 struct dwarf2_cu
*, int *);
777 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
778 bfd
*, char *, struct dwarf2_cu
*);
780 static char *read_attribute_value (struct attribute
*, unsigned,
781 bfd
*, char *, struct dwarf2_cu
*);
783 static unsigned int read_1_byte (bfd
*, char *);
785 static int read_1_signed_byte (bfd
*, char *);
787 static unsigned int read_2_bytes (bfd
*, char *);
789 static unsigned int read_4_bytes (bfd
*, char *);
791 static unsigned long read_8_bytes (bfd
*, char *);
793 static CORE_ADDR
read_address (bfd
*, char *ptr
, struct dwarf2_cu
*,
796 static LONGEST
read_initial_length (bfd
*, char *,
797 struct comp_unit_head
*, int *bytes_read
);
799 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
802 static char *read_n_bytes (bfd
*, char *, unsigned int);
804 static char *read_string (bfd
*, char *, unsigned int *);
806 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
809 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
811 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
813 static char *skip_leb128 (bfd
*, char *);
815 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
817 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
820 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
821 struct dwarf2_cu
*cu
);
823 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
825 static struct die_info
*die_specification (struct die_info
*die
,
828 static void free_line_header (struct line_header
*lh
);
830 static void add_file_name (struct line_header
*, char *, unsigned int,
831 unsigned int, unsigned int);
833 static struct line_header
*(dwarf_decode_line_header
834 (unsigned int offset
,
835 bfd
*abfd
, struct dwarf2_cu
*cu
));
837 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
838 struct dwarf2_cu
*, struct partial_symtab
*);
840 static void dwarf2_start_subfile (char *, char *);
842 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
845 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
848 static void dwarf2_const_value_data (struct attribute
*attr
,
852 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
854 static struct type
*die_containing_type (struct die_info
*,
857 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
859 static void read_type_die (struct die_info
*, struct dwarf2_cu
*);
861 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
863 static char *typename_concat (struct obstack
*, const char *prefix
, const char *suffix
,
866 static void read_typedef (struct die_info
*, struct dwarf2_cu
*);
868 static void read_base_type (struct die_info
*, struct dwarf2_cu
*);
870 static void read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
872 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
874 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
876 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
878 static int dwarf2_get_pc_bounds (struct die_info
*,
879 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
881 static void get_scope_pc_bounds (struct die_info
*,
882 CORE_ADDR
*, CORE_ADDR
*,
885 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
888 static void dwarf2_attach_fields_to_type (struct field_info
*,
889 struct type
*, struct dwarf2_cu
*);
891 static void dwarf2_add_member_fn (struct field_info
*,
892 struct die_info
*, struct type
*,
895 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
896 struct type
*, struct dwarf2_cu
*);
898 static void read_structure_type (struct die_info
*, struct dwarf2_cu
*);
900 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
902 static char *determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
904 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
906 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
908 static const char *namespace_name (struct die_info
*die
,
909 int *is_anonymous
, struct dwarf2_cu
*);
911 static void read_enumeration_type (struct die_info
*, struct dwarf2_cu
*);
913 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
915 static struct type
*dwarf_base_type (int, int, struct dwarf2_cu
*);
917 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
919 static void read_array_type (struct die_info
*, struct dwarf2_cu
*);
921 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
924 static void read_tag_pointer_type (struct die_info
*, struct dwarf2_cu
*);
926 static void read_tag_ptr_to_member_type (struct die_info
*,
929 static void read_tag_reference_type (struct die_info
*, struct dwarf2_cu
*);
931 static void read_tag_const_type (struct die_info
*, struct dwarf2_cu
*);
933 static void read_tag_volatile_type (struct die_info
*, struct dwarf2_cu
*);
935 static void read_tag_string_type (struct die_info
*, struct dwarf2_cu
*);
937 static void read_subroutine_type (struct die_info
*, struct dwarf2_cu
*);
939 static struct die_info
*read_comp_unit (char *, bfd
*, struct dwarf2_cu
*);
941 static struct die_info
*read_die_and_children (char *info_ptr
, bfd
*abfd
,
944 struct die_info
*parent
);
946 static struct die_info
*read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
949 struct die_info
*parent
);
951 static void free_die_list (struct die_info
*);
953 static void process_die (struct die_info
*, struct dwarf2_cu
*);
955 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
957 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
959 static struct die_info
*dwarf2_extension (struct die_info
*die
,
962 static char *dwarf_tag_name (unsigned int);
964 static char *dwarf_attr_name (unsigned int);
966 static char *dwarf_form_name (unsigned int);
968 static char *dwarf_stack_op_name (unsigned int);
970 static char *dwarf_bool_name (unsigned int);
972 static char *dwarf_type_encoding_name (unsigned int);
975 static char *dwarf_cfi_name (unsigned int);
977 struct die_info
*copy_die (struct die_info
*);
980 static struct die_info
*sibling_die (struct die_info
*);
982 static void dump_die (struct die_info
*);
984 static void dump_die_list (struct die_info
*);
986 static void store_in_ref_table (unsigned int, struct die_info
*,
989 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*,
992 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
994 static struct die_info
*follow_die_ref (struct die_info
*,
998 static struct type
*dwarf2_fundamental_type (struct objfile
*, int,
1001 /* memory allocation interface */
1003 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1005 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1007 static struct die_info
*dwarf_alloc_die (void);
1009 static void initialize_cu_func_list (struct dwarf2_cu
*);
1011 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1012 struct dwarf2_cu
*);
1014 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1015 char *, bfd
*, struct dwarf2_cu
*);
1017 static int attr_form_is_block (struct attribute
*);
1020 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
1021 struct dwarf2_cu
*cu
);
1023 static char *skip_one_die (char *info_ptr
, struct abbrev_info
*abbrev
,
1024 struct dwarf2_cu
*cu
);
1026 static void free_stack_comp_unit (void *);
1028 static void *hashtab_obstack_allocate (void *data
, size_t size
, size_t count
);
1030 static void dummy_obstack_deallocate (void *object
, void *data
);
1032 static hashval_t
partial_die_hash (const void *item
);
1034 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1036 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1037 (unsigned long offset
, struct objfile
*objfile
);
1039 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1040 (unsigned long offset
, struct objfile
*objfile
);
1042 static void free_one_comp_unit (void *);
1044 static void free_cached_comp_units (void *);
1046 static void age_cached_comp_units (void);
1048 static void free_one_cached_comp_unit (void *);
1050 static void set_die_type (struct die_info
*, struct type
*,
1051 struct dwarf2_cu
*);
1053 static void reset_die_and_siblings_types (struct die_info
*,
1054 struct dwarf2_cu
*);
1056 static void create_all_comp_units (struct objfile
*);
1058 static struct dwarf2_cu
*load_full_comp_unit (struct dwarf2_per_cu_data
*);
1060 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1062 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1063 struct dwarf2_per_cu_data
*);
1065 static void dwarf2_mark (struct dwarf2_cu
*);
1067 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1069 /* Try to locate the sections we need for DWARF 2 debugging
1070 information and return true if we have enough to do something. */
1073 dwarf2_has_info (struct objfile
*objfile
)
1075 struct dwarf2_per_objfile
*data
;
1077 /* Initialize per-objfile state. */
1078 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1079 memset (data
, 0, sizeof (*data
));
1080 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1081 dwarf2_per_objfile
= data
;
1083 dwarf_info_section
= 0;
1084 dwarf_abbrev_section
= 0;
1085 dwarf_line_section
= 0;
1086 dwarf_str_section
= 0;
1087 dwarf_macinfo_section
= 0;
1088 dwarf_frame_section
= 0;
1089 dwarf_eh_frame_section
= 0;
1090 dwarf_ranges_section
= 0;
1091 dwarf_loc_section
= 0;
1093 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1094 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
1097 /* This function is mapped across the sections and remembers the
1098 offset and size of each of the debugging sections we are interested
1102 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, void *ignore_ptr
)
1104 if (strcmp (sectp
->name
, INFO_SECTION
) == 0)
1106 dwarf2_per_objfile
->info_size
= bfd_get_section_size (sectp
);
1107 dwarf_info_section
= sectp
;
1109 else if (strcmp (sectp
->name
, ABBREV_SECTION
) == 0)
1111 dwarf2_per_objfile
->abbrev_size
= bfd_get_section_size (sectp
);
1112 dwarf_abbrev_section
= sectp
;
1114 else if (strcmp (sectp
->name
, LINE_SECTION
) == 0)
1116 dwarf2_per_objfile
->line_size
= bfd_get_section_size (sectp
);
1117 dwarf_line_section
= sectp
;
1119 else if (strcmp (sectp
->name
, PUBNAMES_SECTION
) == 0)
1121 dwarf2_per_objfile
->pubnames_size
= bfd_get_section_size (sectp
);
1122 dwarf_pubnames_section
= sectp
;
1124 else if (strcmp (sectp
->name
, ARANGES_SECTION
) == 0)
1126 dwarf2_per_objfile
->aranges_size
= bfd_get_section_size (sectp
);
1127 dwarf_aranges_section
= sectp
;
1129 else if (strcmp (sectp
->name
, LOC_SECTION
) == 0)
1131 dwarf2_per_objfile
->loc_size
= bfd_get_section_size (sectp
);
1132 dwarf_loc_section
= sectp
;
1134 else if (strcmp (sectp
->name
, MACINFO_SECTION
) == 0)
1136 dwarf2_per_objfile
->macinfo_size
= bfd_get_section_size (sectp
);
1137 dwarf_macinfo_section
= sectp
;
1139 else if (strcmp (sectp
->name
, STR_SECTION
) == 0)
1141 dwarf2_per_objfile
->str_size
= bfd_get_section_size (sectp
);
1142 dwarf_str_section
= sectp
;
1144 else if (strcmp (sectp
->name
, FRAME_SECTION
) == 0)
1146 dwarf2_per_objfile
->frame_size
= bfd_get_section_size (sectp
);
1147 dwarf_frame_section
= sectp
;
1149 else if (strcmp (sectp
->name
, EH_FRAME_SECTION
) == 0)
1151 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1152 if (aflag
& SEC_HAS_CONTENTS
)
1154 dwarf2_per_objfile
->eh_frame_size
= bfd_get_section_size (sectp
);
1155 dwarf_eh_frame_section
= sectp
;
1158 else if (strcmp (sectp
->name
, RANGES_SECTION
) == 0)
1160 dwarf2_per_objfile
->ranges_size
= bfd_get_section_size (sectp
);
1161 dwarf_ranges_section
= sectp
;
1165 /* Build a partial symbol table. */
1168 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1170 /* We definitely need the .debug_info and .debug_abbrev sections */
1172 dwarf2_per_objfile
->info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1173 dwarf2_per_objfile
->abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1175 if (dwarf_line_section
)
1176 dwarf2_per_objfile
->line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1178 dwarf2_per_objfile
->line_buffer
= NULL
;
1180 if (dwarf_str_section
)
1181 dwarf2_per_objfile
->str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1183 dwarf2_per_objfile
->str_buffer
= NULL
;
1185 if (dwarf_macinfo_section
)
1186 dwarf2_per_objfile
->macinfo_buffer
= dwarf2_read_section (objfile
,
1187 dwarf_macinfo_section
);
1189 dwarf2_per_objfile
->macinfo_buffer
= NULL
;
1191 if (dwarf_ranges_section
)
1192 dwarf2_per_objfile
->ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1194 dwarf2_per_objfile
->ranges_buffer
= NULL
;
1196 if (dwarf_loc_section
)
1197 dwarf2_per_objfile
->loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1199 dwarf2_per_objfile
->loc_buffer
= NULL
;
1202 || (objfile
->global_psymbols
.size
== 0
1203 && objfile
->static_psymbols
.size
== 0))
1205 init_psymbol_list (objfile
, 1024);
1209 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1211 /* Things are significantly easier if we have .debug_aranges and
1212 .debug_pubnames sections */
1214 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1218 /* only test this case for now */
1220 /* In this case we have to work a bit harder */
1221 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1226 /* Build the partial symbol table from the information in the
1227 .debug_pubnames and .debug_aranges sections. */
1230 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1232 bfd
*abfd
= objfile
->obfd
;
1233 char *aranges_buffer
, *pubnames_buffer
;
1234 char *aranges_ptr
, *pubnames_ptr
;
1235 unsigned int entry_length
, version
, info_offset
, info_size
;
1237 pubnames_buffer
= dwarf2_read_section (objfile
,
1238 dwarf_pubnames_section
);
1239 pubnames_ptr
= pubnames_buffer
;
1240 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames_size
)
1242 struct comp_unit_head cu_header
;
1245 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1247 pubnames_ptr
+= bytes_read
;
1248 version
= read_1_byte (abfd
, pubnames_ptr
);
1250 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1252 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1256 aranges_buffer
= dwarf2_read_section (objfile
,
1257 dwarf_aranges_section
);
1262 /* Read in the comp unit header information from the debug_info at
1266 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1267 char *info_ptr
, bfd
*abfd
)
1271 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1273 info_ptr
+= bytes_read
;
1274 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1276 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1278 info_ptr
+= bytes_read
;
1279 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1281 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1282 if (signed_addr
< 0)
1283 internal_error (__FILE__
, __LINE__
,
1284 "read_comp_unit_head: dwarf from non elf file");
1285 cu_header
->signed_addr_p
= signed_addr
;
1290 partial_read_comp_unit_head (struct comp_unit_head
*header
, char *info_ptr
,
1293 char *beg_of_comp_unit
= info_ptr
;
1295 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1297 if (header
->version
!= 2)
1298 error ("Dwarf Error: wrong version in compilation unit header "
1299 "(is %d, should be %d) [in module %s]", header
->version
,
1300 2, bfd_get_filename (abfd
));
1302 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev_size
)
1303 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1304 "(offset 0x%lx + 6) [in module %s]",
1305 (long) header
->abbrev_offset
,
1306 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1307 bfd_get_filename (abfd
));
1309 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1310 > dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1311 error ("Dwarf Error: bad length (0x%lx) in compilation unit header "
1312 "(offset 0x%lx + 0) [in module %s]",
1313 (long) header
->length
,
1314 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1315 bfd_get_filename (abfd
));
1320 /* Allocate a new partial symtab for file named NAME and mark this new
1321 partial symtab as being an include of PST. */
1324 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1325 struct objfile
*objfile
)
1327 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1329 subpst
->section_offsets
= pst
->section_offsets
;
1330 subpst
->textlow
= 0;
1331 subpst
->texthigh
= 0;
1333 subpst
->dependencies
= (struct partial_symtab
**)
1334 obstack_alloc (&objfile
->objfile_obstack
,
1335 sizeof (struct partial_symtab
*));
1336 subpst
->dependencies
[0] = pst
;
1337 subpst
->number_of_dependencies
= 1;
1339 subpst
->globals_offset
= 0;
1340 subpst
->n_global_syms
= 0;
1341 subpst
->statics_offset
= 0;
1342 subpst
->n_static_syms
= 0;
1343 subpst
->symtab
= NULL
;
1344 subpst
->read_symtab
= pst
->read_symtab
;
1347 /* No private part is necessary for include psymtabs. This property
1348 can be used to differentiate between such include psymtabs and
1349 the regular ones. */
1350 subpst
->read_symtab_private
= NULL
;
1353 /* Read the Line Number Program data and extract the list of files
1354 included by the source file represented by PST. Build an include
1355 partial symtab for each of these included files.
1357 This procedure assumes that there *is* a Line Number Program in
1358 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1359 before calling this procedure. */
1362 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1363 struct partial_die_info
*pdi
,
1364 struct partial_symtab
*pst
)
1366 struct objfile
*objfile
= cu
->objfile
;
1367 bfd
*abfd
= objfile
->obfd
;
1368 struct line_header
*lh
;
1370 lh
= dwarf_decode_line_header (pdi
->line_offset
, abfd
, cu
);
1372 return; /* No linetable, so no includes. */
1374 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1376 free_line_header (lh
);
1380 /* Build the partial symbol table by doing a quick pass through the
1381 .debug_info and .debug_abbrev sections. */
1384 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1386 /* Instead of reading this into a big buffer, we should probably use
1387 mmap() on architectures that support it. (FIXME) */
1388 bfd
*abfd
= objfile
->obfd
;
1390 char *beg_of_comp_unit
;
1391 struct partial_die_info comp_unit_die
;
1392 struct partial_symtab
*pst
;
1393 struct cleanup
*back_to
;
1394 CORE_ADDR lowpc
, highpc
, baseaddr
;
1396 info_ptr
= dwarf2_per_objfile
->info_buffer
;
1398 /* Any cached compilation units will be linked by the per-objfile
1399 read_in_chain. Make sure to free them when we're done. */
1400 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1402 create_all_comp_units (objfile
);
1404 /* Since the objects we're extracting from .debug_info vary in
1405 length, only the individual functions to extract them (like
1406 read_comp_unit_head and load_partial_die) can really know whether
1407 the buffer is large enough to hold another complete object.
1409 At the moment, they don't actually check that. If .debug_info
1410 holds just one extra byte after the last compilation unit's dies,
1411 then read_comp_unit_head will happily read off the end of the
1412 buffer. read_partial_die is similarly casual. Those functions
1415 For this loop condition, simply checking whether there's any data
1416 left at all should be sufficient. */
1417 while (info_ptr
< (dwarf2_per_objfile
->info_buffer
1418 + dwarf2_per_objfile
->info_size
))
1420 struct cleanup
*back_to_inner
;
1421 struct dwarf2_cu cu
;
1422 struct abbrev_info
*abbrev
;
1423 unsigned int bytes_read
;
1424 struct dwarf2_per_cu_data
*this_cu
;
1426 beg_of_comp_unit
= info_ptr
;
1428 memset (&cu
, 0, sizeof (cu
));
1430 obstack_init (&cu
.comp_unit_obstack
);
1432 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1434 cu
.objfile
= objfile
;
1435 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1437 /* Complete the cu_header */
1438 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1439 cu
.header
.first_die_ptr
= info_ptr
;
1440 cu
.header
.cu_head_ptr
= beg_of_comp_unit
;
1442 cu
.list_in_scope
= &file_symbols
;
1444 /* Read the abbrevs for this compilation unit into a table */
1445 dwarf2_read_abbrevs (abfd
, &cu
);
1446 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1448 this_cu
= dwarf2_find_comp_unit (cu
.header
.offset
, objfile
);
1450 /* Read the compilation unit die */
1451 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, &cu
);
1452 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1453 abfd
, info_ptr
, &cu
);
1455 /* Set the language we're debugging */
1456 set_cu_language (comp_unit_die
.language
, &cu
);
1458 /* Allocate a new partial symbol table structure */
1459 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1460 comp_unit_die
.name
? comp_unit_die
.name
: "",
1461 comp_unit_die
.lowpc
,
1462 objfile
->global_psymbols
.next
,
1463 objfile
->static_psymbols
.next
);
1465 if (comp_unit_die
.dirname
)
1466 pst
->dirname
= xstrdup (comp_unit_die
.dirname
);
1468 pst
->read_symtab_private
= (char *) this_cu
;
1470 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1472 /* Store the function that reads in the rest of the symbol table */
1473 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1475 /* If this compilation unit was already read in, free the
1476 cached copy in order to read it in again. This is
1477 necessary because we skipped some symbols when we first
1478 read in the compilation unit (see load_partial_dies).
1479 This problem could be avoided, but the benefit is
1481 if (this_cu
->cu
!= NULL
)
1482 free_one_cached_comp_unit (this_cu
->cu
);
1484 cu
.per_cu
= this_cu
;
1486 /* Note that this is a pointer to our stack frame, being
1487 added to a global data structure. It will be cleaned up
1488 in free_stack_comp_unit when we finish with this
1489 compilation unit. */
1492 this_cu
->psymtab
= pst
;
1494 /* Check if comp unit has_children.
1495 If so, read the rest of the partial symbols from this comp unit.
1496 If not, there's no more debug_info for this comp unit. */
1497 if (comp_unit_die
.has_children
)
1499 struct partial_die_info
*first_die
;
1501 lowpc
= ((CORE_ADDR
) -1);
1502 highpc
= ((CORE_ADDR
) 0);
1504 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1506 scan_partial_symbols (first_die
, &lowpc
, &highpc
, &cu
);
1508 /* If we didn't find a lowpc, set it to highpc to avoid
1509 complaints from `maint check'. */
1510 if (lowpc
== ((CORE_ADDR
) -1))
1513 /* If the compilation unit didn't have an explicit address range,
1514 then use the information extracted from its child dies. */
1515 if (! comp_unit_die
.has_pc_info
)
1517 comp_unit_die
.lowpc
= lowpc
;
1518 comp_unit_die
.highpc
= highpc
;
1521 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1522 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1524 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1525 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1526 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1527 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1528 sort_pst_symbols (pst
);
1530 /* If there is already a psymtab or symtab for a file of this
1531 name, remove it. (If there is a symtab, more drastic things
1532 also happen.) This happens in VxWorks. */
1533 free_named_symtabs (pst
->filename
);
1535 if (comp_unit_die
.has_stmt_list
)
1537 /* Get the list of files included in the current compilation unit,
1538 and build a psymtab for each of them. */
1539 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1542 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1543 + cu
.header
.initial_length_size
;
1545 do_cleanups (back_to_inner
);
1547 do_cleanups (back_to
);
1550 /* Load the DIEs for a secondary CU into memory. */
1553 load_comp_unit (struct dwarf2_per_cu_data
*this_cu
, struct objfile
*objfile
)
1555 bfd
*abfd
= objfile
->obfd
;
1556 char *info_ptr
, *beg_of_comp_unit
;
1557 struct partial_die_info comp_unit_die
;
1558 struct dwarf2_cu
*cu
;
1559 struct abbrev_info
*abbrev
;
1560 unsigned int bytes_read
;
1561 struct cleanup
*back_to
;
1563 info_ptr
= dwarf2_per_objfile
->info_buffer
+ this_cu
->offset
;
1564 beg_of_comp_unit
= info_ptr
;
1566 cu
= xmalloc (sizeof (struct dwarf2_cu
));
1567 memset (cu
, 0, sizeof (struct dwarf2_cu
));
1569 obstack_init (&cu
->comp_unit_obstack
);
1571 cu
->objfile
= objfile
;
1572 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
1574 /* Complete the cu_header. */
1575 cu
->header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1576 cu
->header
.first_die_ptr
= info_ptr
;
1577 cu
->header
.cu_head_ptr
= beg_of_comp_unit
;
1579 /* Read the abbrevs for this compilation unit into a table. */
1580 dwarf2_read_abbrevs (abfd
, cu
);
1581 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
1583 /* Read the compilation unit die. */
1584 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1585 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1586 abfd
, info_ptr
, cu
);
1588 /* Set the language we're debugging. */
1589 set_cu_language (comp_unit_die
.language
, cu
);
1591 /* Link this compilation unit into the compilation unit tree. */
1593 cu
->per_cu
= this_cu
;
1595 /* Check if comp unit has_children.
1596 If so, read the rest of the partial symbols from this comp unit.
1597 If not, there's no more debug_info for this comp unit. */
1598 if (comp_unit_die
.has_children
)
1599 load_partial_dies (abfd
, info_ptr
, 0, cu
);
1601 do_cleanups (back_to
);
1604 /* Create a list of all compilation units in OBJFILE. We do this only
1605 if an inter-comp-unit reference is found; presumably if there is one,
1606 there will be many, and one will occur early in the .debug_info section.
1607 So there's no point in building this list incrementally. */
1610 create_all_comp_units (struct objfile
*objfile
)
1614 struct dwarf2_per_cu_data
**all_comp_units
;
1615 char *info_ptr
= dwarf2_per_objfile
->info_buffer
;
1619 all_comp_units
= xmalloc (n_allocated
1620 * sizeof (struct dwarf2_per_cu_data
*));
1622 while (info_ptr
< dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1624 struct comp_unit_head cu_header
;
1625 char *beg_of_comp_unit
;
1626 struct dwarf2_per_cu_data
*this_cu
;
1627 unsigned long offset
;
1630 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
1632 /* Read just enough information to find out where the next
1633 compilation unit is. */
1634 cu_header
.length
= read_initial_length (objfile
->obfd
, info_ptr
,
1635 &cu_header
, &bytes_read
);
1637 /* Save the compilation unit for later lookup. */
1638 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
1639 sizeof (struct dwarf2_per_cu_data
));
1640 memset (this_cu
, 0, sizeof (*this_cu
));
1641 this_cu
->offset
= offset
;
1642 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
1644 if (n_comp_units
== n_allocated
)
1647 all_comp_units
= xrealloc (all_comp_units
,
1649 * sizeof (struct dwarf2_per_cu_data
*));
1651 all_comp_units
[n_comp_units
++] = this_cu
;
1653 info_ptr
= info_ptr
+ this_cu
->length
;
1656 dwarf2_per_objfile
->all_comp_units
1657 = obstack_alloc (&objfile
->objfile_obstack
,
1658 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1659 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
1660 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1661 xfree (all_comp_units
);
1662 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
1665 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1666 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1670 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1671 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
1673 struct objfile
*objfile
= cu
->objfile
;
1674 bfd
*abfd
= objfile
->obfd
;
1675 struct partial_die_info
*pdi
;
1677 /* Now, march along the PDI's, descending into ones which have
1678 interesting children but skipping the children of the other ones,
1679 until we reach the end of the compilation unit. */
1685 fixup_partial_die (pdi
, cu
);
1687 /* Anonymous namespaces have no name but have interesting
1688 children, so we need to look at them. Ditto for anonymous
1691 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1692 || pdi
->tag
== DW_TAG_enumeration_type
)
1696 case DW_TAG_subprogram
:
1697 if (pdi
->has_pc_info
)
1699 if (pdi
->lowpc
< *lowpc
)
1701 *lowpc
= pdi
->lowpc
;
1703 if (pdi
->highpc
> *highpc
)
1705 *highpc
= pdi
->highpc
;
1707 if (!pdi
->is_declaration
)
1709 add_partial_symbol (pdi
, cu
);
1713 case DW_TAG_variable
:
1714 case DW_TAG_typedef
:
1715 case DW_TAG_union_type
:
1716 if (!pdi
->is_declaration
)
1718 add_partial_symbol (pdi
, cu
);
1721 case DW_TAG_class_type
:
1722 case DW_TAG_structure_type
:
1723 if (!pdi
->is_declaration
)
1725 add_partial_symbol (pdi
, cu
);
1728 case DW_TAG_enumeration_type
:
1729 if (!pdi
->is_declaration
)
1730 add_partial_enumeration (pdi
, cu
);
1732 case DW_TAG_base_type
:
1733 case DW_TAG_subrange_type
:
1734 /* File scope base type definitions are added to the partial
1736 add_partial_symbol (pdi
, cu
);
1738 case DW_TAG_namespace
:
1739 add_partial_namespace (pdi
, lowpc
, highpc
, cu
);
1746 /* If the die has a sibling, skip to the sibling. */
1748 pdi
= pdi
->die_sibling
;
1752 /* Functions used to compute the fully scoped name of a partial DIE.
1754 Normally, this is simple. For C++, the parent DIE's fully scoped
1755 name is concatenated with "::" and the partial DIE's name. For
1756 Java, the same thing occurs except that "." is used instead of "::".
1757 Enumerators are an exception; they use the scope of their parent
1758 enumeration type, i.e. the name of the enumeration type is not
1759 prepended to the enumerator.
1761 There are two complexities. One is DW_AT_specification; in this
1762 case "parent" means the parent of the target of the specification,
1763 instead of the direct parent of the DIE. The other is compilers
1764 which do not emit DW_TAG_namespace; in this case we try to guess
1765 the fully qualified name of structure types from their members'
1766 linkage names. This must be done using the DIE's children rather
1767 than the children of any DW_AT_specification target. We only need
1768 to do this for structures at the top level, i.e. if the target of
1769 any DW_AT_specification (if any; otherwise the DIE itself) does not
1772 /* Compute the scope prefix associated with PDI's parent, in
1773 compilation unit CU. The result will be allocated on CU's
1774 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1775 field. NULL is returned if no prefix is necessary. */
1777 partial_die_parent_scope (struct partial_die_info
*pdi
,
1778 struct dwarf2_cu
*cu
)
1780 char *grandparent_scope
;
1781 struct partial_die_info
*parent
, *real_pdi
;
1783 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1784 then this means the parent of the specification DIE. */
1787 while (real_pdi
->has_specification
)
1788 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
1790 parent
= real_pdi
->die_parent
;
1794 if (parent
->scope_set
)
1795 return parent
->scope
;
1797 fixup_partial_die (parent
, cu
);
1799 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
1801 if (parent
->tag
== DW_TAG_namespace
1802 || parent
->tag
== DW_TAG_structure_type
1803 || parent
->tag
== DW_TAG_class_type
1804 || parent
->tag
== DW_TAG_union_type
)
1806 if (grandparent_scope
== NULL
)
1807 parent
->scope
= parent
->name
;
1809 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
1812 else if (parent
->tag
== DW_TAG_enumeration_type
)
1813 /* Enumerators should not get the name of the enumeration as a prefix. */
1814 parent
->scope
= grandparent_scope
;
1817 /* FIXME drow/2004-04-01: What should we be doing with
1818 function-local names? For partial symbols, we should probably be
1820 complaint (&symfile_complaints
,
1821 "unhandled containing DIE tag %d for DIE at %d",
1822 parent
->tag
, pdi
->offset
);
1823 parent
->scope
= grandparent_scope
;
1826 parent
->scope_set
= 1;
1827 return parent
->scope
;
1830 /* Return the fully scoped name associated with PDI, from compilation unit
1831 CU. The result will be allocated with malloc. */
1833 partial_die_full_name (struct partial_die_info
*pdi
,
1834 struct dwarf2_cu
*cu
)
1838 parent_scope
= partial_die_parent_scope (pdi
, cu
);
1839 if (parent_scope
== NULL
)
1842 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
1846 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
1848 struct objfile
*objfile
= cu
->objfile
;
1851 const char *my_prefix
;
1852 const struct partial_symbol
*psym
= NULL
;
1854 int built_actual_name
= 0;
1856 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1860 if (pdi_needs_namespace (pdi
->tag
))
1862 actual_name
= partial_die_full_name (pdi
, cu
);
1864 built_actual_name
= 1;
1867 if (actual_name
== NULL
)
1868 actual_name
= pdi
->name
;
1872 case DW_TAG_subprogram
:
1873 if (pdi
->is_external
)
1875 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1876 mst_text, objfile); */
1877 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1878 VAR_DOMAIN
, LOC_BLOCK
,
1879 &objfile
->global_psymbols
,
1880 0, pdi
->lowpc
+ baseaddr
,
1881 cu
->language
, objfile
);
1885 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1886 mst_file_text, objfile); */
1887 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1888 VAR_DOMAIN
, LOC_BLOCK
,
1889 &objfile
->static_psymbols
,
1890 0, pdi
->lowpc
+ baseaddr
,
1891 cu
->language
, objfile
);
1894 case DW_TAG_variable
:
1895 if (pdi
->is_external
)
1898 Don't enter into the minimal symbol tables as there is
1899 a minimal symbol table entry from the ELF symbols already.
1900 Enter into partial symbol table if it has a location
1901 descriptor or a type.
1902 If the location descriptor is missing, new_symbol will create
1903 a LOC_UNRESOLVED symbol, the address of the variable will then
1904 be determined from the minimal symbol table whenever the variable
1906 The address for the partial symbol table entry is not
1907 used by GDB, but it comes in handy for debugging partial symbol
1911 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1912 if (pdi
->locdesc
|| pdi
->has_type
)
1913 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1914 VAR_DOMAIN
, LOC_STATIC
,
1915 &objfile
->global_psymbols
,
1917 cu
->language
, objfile
);
1921 /* Static Variable. Skip symbols without location descriptors. */
1922 if (pdi
->locdesc
== NULL
)
1924 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1925 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
1926 mst_file_data, objfile); */
1927 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1928 VAR_DOMAIN
, LOC_STATIC
,
1929 &objfile
->static_psymbols
,
1931 cu
->language
, objfile
);
1934 case DW_TAG_typedef
:
1935 case DW_TAG_base_type
:
1936 case DW_TAG_subrange_type
:
1937 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1938 VAR_DOMAIN
, LOC_TYPEDEF
,
1939 &objfile
->static_psymbols
,
1940 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1942 case DW_TAG_namespace
:
1943 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1944 VAR_DOMAIN
, LOC_TYPEDEF
,
1945 &objfile
->global_psymbols
,
1946 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1948 case DW_TAG_class_type
:
1949 case DW_TAG_structure_type
:
1950 case DW_TAG_union_type
:
1951 case DW_TAG_enumeration_type
:
1952 /* Skip aggregate types without children, these are external
1954 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
1955 static vs. global. */
1956 if (pdi
->has_children
== 0)
1958 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1959 STRUCT_DOMAIN
, LOC_TYPEDEF
,
1960 (cu
->language
== language_cplus
1961 || cu
->language
== language_java
)
1962 ? &objfile
->global_psymbols
1963 : &objfile
->static_psymbols
,
1964 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1966 if (cu
->language
== language_cplus
1967 || cu
->language
== language_java
)
1969 /* For C++ and Java, these implicitly act as typedefs as well. */
1970 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1971 VAR_DOMAIN
, LOC_TYPEDEF
,
1972 &objfile
->global_psymbols
,
1973 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1976 case DW_TAG_enumerator
:
1977 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1978 VAR_DOMAIN
, LOC_CONST
,
1979 (cu
->language
== language_cplus
1980 || cu
->language
== language_java
)
1981 ? &objfile
->global_psymbols
1982 : &objfile
->static_psymbols
,
1983 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1989 /* Check to see if we should scan the name for possible namespace
1990 info. Only do this if this is C++, if we don't have namespace
1991 debugging info in the file, if the psym is of an appropriate type
1992 (otherwise we'll have psym == NULL), and if we actually had a
1993 mangled name to begin with. */
1995 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
1996 cases which do not set PSYM above? */
1998 if (cu
->language
== language_cplus
1999 && cu
->has_namespace_info
== 0
2001 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
2002 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
2005 if (built_actual_name
)
2006 xfree (actual_name
);
2009 /* Determine whether a die of type TAG living in a C++ class or
2010 namespace needs to have the name of the scope prepended to the
2011 name listed in the die. */
2014 pdi_needs_namespace (enum dwarf_tag tag
)
2018 case DW_TAG_namespace
:
2019 case DW_TAG_typedef
:
2020 case DW_TAG_class_type
:
2021 case DW_TAG_structure_type
:
2022 case DW_TAG_union_type
:
2023 case DW_TAG_enumeration_type
:
2024 case DW_TAG_enumerator
:
2031 /* Read a partial die corresponding to a namespace; also, add a symbol
2032 corresponding to that namespace to the symbol table. NAMESPACE is
2033 the name of the enclosing namespace. */
2036 add_partial_namespace (struct partial_die_info
*pdi
,
2037 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2038 struct dwarf2_cu
*cu
)
2040 struct objfile
*objfile
= cu
->objfile
;
2042 /* Add a symbol for the namespace. */
2044 add_partial_symbol (pdi
, cu
);
2046 /* Now scan partial symbols in that namespace. */
2048 if (pdi
->has_children
)
2049 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, cu
);
2052 /* See if we can figure out if the class lives in a namespace. We do
2053 this by looking for a member function; its demangled name will
2054 contain namespace info, if there is any. */
2057 guess_structure_name (struct partial_die_info
*struct_pdi
,
2058 struct dwarf2_cu
*cu
)
2060 if ((cu
->language
== language_cplus
2061 || cu
->language
== language_java
)
2062 && cu
->has_namespace_info
== 0
2063 && struct_pdi
->has_children
)
2065 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2066 what template types look like, because the demangler
2067 frequently doesn't give the same name as the debug info. We
2068 could fix this by only using the demangled name to get the
2069 prefix (but see comment in read_structure_type). */
2071 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
2072 struct partial_die_info
*real_pdi
;
2074 /* If this DIE (this DIE's specification, if any) has a parent, then
2075 we should not do this. We'll prepend the parent's fully qualified
2076 name when we create the partial symbol. */
2078 real_pdi
= struct_pdi
;
2079 while (real_pdi
->has_specification
)
2080 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2082 if (real_pdi
->die_parent
!= NULL
)
2085 while (child_pdi
!= NULL
)
2087 if (child_pdi
->tag
== DW_TAG_subprogram
)
2089 char *actual_class_name
2090 = language_class_name_from_physname (cu
->language_defn
,
2092 if (actual_class_name
!= NULL
)
2095 = obsavestring (actual_class_name
,
2096 strlen (actual_class_name
),
2097 &cu
->comp_unit_obstack
);
2098 xfree (actual_class_name
);
2103 child_pdi
= child_pdi
->die_sibling
;
2108 /* Read a partial die corresponding to an enumeration type. */
2111 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2112 struct dwarf2_cu
*cu
)
2114 struct objfile
*objfile
= cu
->objfile
;
2115 bfd
*abfd
= objfile
->obfd
;
2116 struct partial_die_info
*pdi
;
2118 if (enum_pdi
->name
!= NULL
)
2119 add_partial_symbol (enum_pdi
, cu
);
2121 pdi
= enum_pdi
->die_child
;
2124 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2125 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
2127 add_partial_symbol (pdi
, cu
);
2128 pdi
= pdi
->die_sibling
;
2132 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2133 Return the corresponding abbrev, or NULL if the number is zero (indicating
2134 an empty DIE). In either case *BYTES_READ will be set to the length of
2135 the initial number. */
2137 static struct abbrev_info
*
2138 peek_die_abbrev (char *info_ptr
, int *bytes_read
, struct dwarf2_cu
*cu
)
2140 bfd
*abfd
= cu
->objfile
->obfd
;
2141 unsigned int abbrev_number
;
2142 struct abbrev_info
*abbrev
;
2144 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2146 if (abbrev_number
== 0)
2149 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2152 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number
,
2153 bfd_get_filename (abfd
));
2159 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2160 pointer to the end of a series of DIEs, terminated by an empty
2161 DIE. Any children of the skipped DIEs will also be skipped. */
2164 skip_children (char *info_ptr
, struct dwarf2_cu
*cu
)
2166 struct abbrev_info
*abbrev
;
2167 unsigned int bytes_read
;
2171 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2173 return info_ptr
+ bytes_read
;
2175 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
2179 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2180 should point just after the initial uleb128 of a DIE, and the
2181 abbrev corresponding to that skipped uleb128 should be passed in
2182 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2186 skip_one_die (char *info_ptr
, struct abbrev_info
*abbrev
,
2187 struct dwarf2_cu
*cu
)
2189 unsigned int bytes_read
;
2190 struct attribute attr
;
2191 bfd
*abfd
= cu
->objfile
->obfd
;
2192 unsigned int form
, i
;
2194 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2196 /* The only abbrev we care about is DW_AT_sibling. */
2197 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2199 read_attribute (&attr
, &abbrev
->attrs
[i
],
2200 abfd
, info_ptr
, cu
);
2201 if (attr
.form
== DW_FORM_ref_addr
)
2202 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
2204 return dwarf2_per_objfile
->info_buffer
2205 + dwarf2_get_ref_die_offset (&attr
, cu
);
2208 /* If it isn't DW_AT_sibling, skip this attribute. */
2209 form
= abbrev
->attrs
[i
].form
;
2214 case DW_FORM_ref_addr
:
2215 info_ptr
+= cu
->header
.addr_size
;
2234 case DW_FORM_string
:
2235 read_string (abfd
, info_ptr
, &bytes_read
);
2236 info_ptr
+= bytes_read
;
2239 info_ptr
+= cu
->header
.offset_size
;
2242 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2243 info_ptr
+= bytes_read
;
2245 case DW_FORM_block1
:
2246 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2248 case DW_FORM_block2
:
2249 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2251 case DW_FORM_block4
:
2252 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2256 case DW_FORM_ref_udata
:
2257 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2259 case DW_FORM_indirect
:
2260 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2261 info_ptr
+= bytes_read
;
2262 /* We need to continue parsing from here, so just go back to
2264 goto skip_attribute
;
2267 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
2268 dwarf_form_name (form
),
2269 bfd_get_filename (abfd
));
2273 if (abbrev
->has_children
)
2274 return skip_children (info_ptr
, cu
);
2279 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2280 the next DIE after ORIG_PDI. */
2283 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, char *info_ptr
,
2284 bfd
*abfd
, struct dwarf2_cu
*cu
)
2286 /* Do we know the sibling already? */
2288 if (orig_pdi
->sibling
)
2289 return orig_pdi
->sibling
;
2291 /* Are there any children to deal with? */
2293 if (!orig_pdi
->has_children
)
2296 /* Skip the children the long way. */
2298 return skip_children (info_ptr
, cu
);
2301 /* Expand this partial symbol table into a full symbol table. */
2304 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2306 /* FIXME: This is barely more than a stub. */
2311 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
2317 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
2318 gdb_flush (gdb_stdout
);
2321 /* Restore our global data. */
2322 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2323 dwarf2_objfile_data_key
);
2325 psymtab_to_symtab_1 (pst
);
2327 /* Finish up the debug error message. */
2329 printf_filtered ("done.\n");
2334 /* Add PER_CU to the queue. */
2337 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2339 struct dwarf2_queue_item
*item
;
2342 item
= xmalloc (sizeof (*item
));
2343 item
->per_cu
= per_cu
;
2346 if (dwarf2_queue
== NULL
)
2347 dwarf2_queue
= item
;
2349 dwarf2_queue_tail
->next
= item
;
2351 dwarf2_queue_tail
= item
;
2354 /* Process the queue. */
2357 process_queue (struct objfile
*objfile
)
2359 struct dwarf2_queue_item
*item
, *next_item
;
2361 /* Initially, there is just one item on the queue. Load its DIEs,
2362 and the DIEs of any other compilation units it requires,
2365 for (item
= dwarf2_queue
; item
!= NULL
; item
= item
->next
)
2367 /* Read in this compilation unit. This may add new items to
2368 the end of the queue. */
2369 load_full_comp_unit (item
->per_cu
);
2371 item
->per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
2372 dwarf2_per_objfile
->read_in_chain
= item
->per_cu
;
2374 /* If this compilation unit has already had full symbols created,
2375 reset the TYPE fields in each DIE. */
2376 if (item
->per_cu
->psymtab
->readin
)
2377 reset_die_and_siblings_types (item
->per_cu
->cu
->dies
,
2381 /* Now everything left on the queue needs to be read in. Process
2382 them, one at a time, removing from the queue as we finish. */
2383 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2385 if (!item
->per_cu
->psymtab
->readin
)
2386 process_full_comp_unit (item
->per_cu
);
2388 item
->per_cu
->queued
= 0;
2389 next_item
= item
->next
;
2393 dwarf2_queue_tail
= NULL
;
2396 /* Free all allocated queue entries. This function only releases anything if
2397 an error was thrown; if the queue was processed then it would have been
2398 freed as we went along. */
2401 dwarf2_release_queue (void *dummy
)
2403 struct dwarf2_queue_item
*item
, *last
;
2405 item
= dwarf2_queue
;
2408 /* Anything still marked queued is likely to be in an
2409 inconsistent state, so discard it. */
2410 if (item
->per_cu
->queued
)
2412 if (item
->per_cu
->cu
!= NULL
)
2413 free_one_cached_comp_unit (item
->per_cu
->cu
);
2414 item
->per_cu
->queued
= 0;
2422 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2425 /* Read in full symbols for PST, and anything it depends on. */
2428 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2430 struct dwarf2_per_cu_data
*per_cu
;
2431 struct cleanup
*back_to
;
2434 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2435 if (!pst
->dependencies
[i
]->readin
)
2437 /* Inform about additional files that need to be read in. */
2440 fputs_filtered (" ", gdb_stdout
);
2442 fputs_filtered ("and ", gdb_stdout
);
2444 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2445 wrap_here (""); /* Flush output */
2446 gdb_flush (gdb_stdout
);
2448 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2451 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
2455 /* It's an include file, no symbols to read for it.
2456 Everything is in the parent symtab. */
2461 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2463 queue_comp_unit (per_cu
);
2465 process_queue (pst
->objfile
);
2467 /* Age the cache, releasing compilation units that have not
2468 been used recently. */
2469 age_cached_comp_units ();
2471 do_cleanups (back_to
);
2474 /* Load the DIEs associated with PST and PER_CU into memory. */
2476 static struct dwarf2_cu
*
2477 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2479 struct partial_symtab
*pst
= per_cu
->psymtab
;
2480 bfd
*abfd
= pst
->objfile
->obfd
;
2481 struct dwarf2_cu
*cu
;
2482 unsigned long offset
;
2484 struct cleanup
*back_to
, *free_cu_cleanup
;
2485 struct attribute
*attr
;
2488 /* Set local variables from the partial symbol table info. */
2489 offset
= per_cu
->offset
;
2491 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2493 cu
= xmalloc (sizeof (struct dwarf2_cu
));
2494 memset (cu
, 0, sizeof (struct dwarf2_cu
));
2496 /* If an error occurs while loading, release our storage. */
2497 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
2499 cu
->objfile
= pst
->objfile
;
2501 /* read in the comp_unit header */
2502 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
2504 /* Read the abbrevs for this compilation unit */
2505 dwarf2_read_abbrevs (abfd
, cu
);
2506 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2508 cu
->header
.offset
= offset
;
2510 cu
->per_cu
= per_cu
;
2513 /* We use this obstack for block values in dwarf_alloc_block. */
2514 obstack_init (&cu
->comp_unit_obstack
);
2516 cu
->dies
= read_comp_unit (info_ptr
, abfd
, cu
);
2518 /* We try not to read any attributes in this function, because not
2519 all objfiles needed for references have been loaded yet, and symbol
2520 table processing isn't initialized. But we have to set the CU language,
2521 or we won't be able to build types correctly. */
2522 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
2524 set_cu_language (DW_UNSND (attr
), cu
);
2526 set_cu_language (language_minimal
, cu
);
2528 do_cleanups (back_to
);
2530 /* We've successfully allocated this compilation unit. Let our caller
2531 clean it up when finished with it. */
2532 discard_cleanups (free_cu_cleanup
);
2537 /* Generate full symbol information for PST and CU, whose DIEs have
2538 already been loaded into memory. */
2541 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2543 struct partial_symtab
*pst
= per_cu
->psymtab
;
2544 struct dwarf2_cu
*cu
= per_cu
->cu
;
2545 struct objfile
*objfile
= pst
->objfile
;
2546 bfd
*abfd
= objfile
->obfd
;
2547 CORE_ADDR lowpc
, highpc
;
2548 struct symtab
*symtab
;
2549 struct cleanup
*back_to
;
2550 struct attribute
*attr
;
2553 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2555 /* We're in the global namespace. */
2556 processing_current_prefix
= "";
2559 back_to
= make_cleanup (really_free_pendings
, NULL
);
2561 cu
->list_in_scope
= &file_symbols
;
2563 /* Find the base address of the compilation unit for range lists and
2564 location lists. It will normally be specified by DW_AT_low_pc.
2565 In DWARF-3 draft 4, the base address could be overridden by
2566 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2567 compilation units with discontinuous ranges. */
2569 cu
->header
.base_known
= 0;
2570 cu
->header
.base_address
= 0;
2572 attr
= dwarf2_attr (cu
->dies
, DW_AT_entry_pc
, cu
);
2575 cu
->header
.base_address
= DW_ADDR (attr
);
2576 cu
->header
.base_known
= 1;
2580 attr
= dwarf2_attr (cu
->dies
, DW_AT_low_pc
, cu
);
2583 cu
->header
.base_address
= DW_ADDR (attr
);
2584 cu
->header
.base_known
= 1;
2588 /* Do line number decoding in read_file_scope () */
2589 process_die (cu
->dies
, cu
);
2591 /* Some compilers don't define a DW_AT_high_pc attribute for the
2592 compilation unit. If the DW_AT_high_pc is missing, synthesize
2593 it, by scanning the DIE's below the compilation unit. */
2594 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
2596 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2598 /* Set symtab language to language from DW_AT_language.
2599 If the compilation is from a C file generated by language preprocessors,
2600 do not set the language if it was already deduced by start_subfile. */
2602 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
2604 symtab
->language
= cu
->language
;
2606 pst
->symtab
= symtab
;
2609 do_cleanups (back_to
);
2612 /* Process a die and its children. */
2615 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2619 case DW_TAG_padding
:
2621 case DW_TAG_compile_unit
:
2622 read_file_scope (die
, cu
);
2624 case DW_TAG_subprogram
:
2625 read_subroutine_type (die
, cu
);
2626 read_func_scope (die
, cu
);
2628 case DW_TAG_inlined_subroutine
:
2629 /* FIXME: These are ignored for now.
2630 They could be used to set breakpoints on all inlined instances
2631 of a function and make GDB `next' properly over inlined functions. */
2633 case DW_TAG_lexical_block
:
2634 case DW_TAG_try_block
:
2635 case DW_TAG_catch_block
:
2636 read_lexical_block_scope (die
, cu
);
2638 case DW_TAG_class_type
:
2639 case DW_TAG_structure_type
:
2640 case DW_TAG_union_type
:
2641 read_structure_type (die
, cu
);
2642 process_structure_scope (die
, cu
);
2644 case DW_TAG_enumeration_type
:
2645 read_enumeration_type (die
, cu
);
2646 process_enumeration_scope (die
, cu
);
2649 /* FIXME drow/2004-03-14: These initialize die->type, but do not create
2650 a symbol or process any children. Therefore it doesn't do anything
2651 that won't be done on-demand by read_type_die. */
2652 case DW_TAG_subroutine_type
:
2653 read_subroutine_type (die
, cu
);
2655 case DW_TAG_array_type
:
2656 read_array_type (die
, cu
);
2658 case DW_TAG_pointer_type
:
2659 read_tag_pointer_type (die
, cu
);
2661 case DW_TAG_ptr_to_member_type
:
2662 read_tag_ptr_to_member_type (die
, cu
);
2664 case DW_TAG_reference_type
:
2665 read_tag_reference_type (die
, cu
);
2667 case DW_TAG_string_type
:
2668 read_tag_string_type (die
, cu
);
2672 case DW_TAG_base_type
:
2673 read_base_type (die
, cu
);
2674 /* Add a typedef symbol for the type definition, if it has a
2676 new_symbol (die
, die
->type
, cu
);
2678 case DW_TAG_subrange_type
:
2679 read_subrange_type (die
, cu
);
2680 /* Add a typedef symbol for the type definition, if it has a
2682 new_symbol (die
, die
->type
, cu
);
2684 case DW_TAG_common_block
:
2685 read_common_block (die
, cu
);
2687 case DW_TAG_common_inclusion
:
2689 case DW_TAG_namespace
:
2690 processing_has_namespace_info
= 1;
2691 read_namespace (die
, cu
);
2693 case DW_TAG_imported_declaration
:
2694 case DW_TAG_imported_module
:
2695 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2696 information contained in these. DW_TAG_imported_declaration
2697 dies shouldn't have children; DW_TAG_imported_module dies
2698 shouldn't in the C++ case, but conceivably could in the
2699 Fortran case, so we'll have to replace this gdb_assert if
2700 Fortran compilers start generating that info. */
2701 processing_has_namespace_info
= 1;
2702 gdb_assert (die
->child
== NULL
);
2705 new_symbol (die
, NULL
, cu
);
2711 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2713 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2717 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2719 struct objfile
*objfile
= cu
->objfile
;
2720 struct comp_unit_head
*cu_header
= &cu
->header
;
2721 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2722 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2723 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2724 struct attribute
*attr
;
2725 char *name
= "<unknown>";
2726 char *comp_dir
= NULL
;
2727 struct die_info
*child_die
;
2728 bfd
*abfd
= objfile
->obfd
;
2729 struct line_header
*line_header
= 0;
2732 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2734 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2736 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2737 from finish_block. */
2738 if (lowpc
== ((CORE_ADDR
) -1))
2743 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2746 name
= DW_STRING (attr
);
2748 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2751 comp_dir
= DW_STRING (attr
);
2754 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2755 directory, get rid of it. */
2756 char *cp
= strchr (comp_dir
, ':');
2758 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2763 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2766 set_cu_language (DW_UNSND (attr
), cu
);
2769 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
2771 cu
->producer
= DW_STRING (attr
);
2773 /* We assume that we're processing GCC output. */
2774 processing_gcc_compilation
= 2;
2776 /* FIXME:Do something here. */
2777 if (dip
->at_producer
!= NULL
)
2779 handle_producer (dip
->at_producer
);
2783 /* The compilation unit may be in a different language or objfile,
2784 zero out all remembered fundamental types. */
2785 memset (cu
->ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
2787 start_symtab (name
, comp_dir
, lowpc
);
2788 record_debugformat ("DWARF 2");
2790 initialize_cu_func_list (cu
);
2792 /* Process all dies in compilation unit. */
2793 if (die
->child
!= NULL
)
2795 child_die
= die
->child
;
2796 while (child_die
&& child_die
->tag
)
2798 process_die (child_die
, cu
);
2799 child_die
= sibling_die (child_die
);
2803 /* Decode line number information if present. */
2804 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2807 unsigned int line_offset
= DW_UNSND (attr
);
2808 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2811 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
2812 (void *) line_header
);
2813 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
2817 /* Decode macro information, if present. Dwarf 2 macro information
2818 refers to information in the line number info statement program
2819 header, so we can only read it if we've read the header
2821 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2822 if (attr
&& line_header
)
2824 unsigned int macro_offset
= DW_UNSND (attr
);
2825 dwarf_decode_macros (line_header
, macro_offset
,
2826 comp_dir
, abfd
, cu
);
2828 do_cleanups (back_to
);
2832 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2833 struct dwarf2_cu
*cu
)
2835 struct function_range
*thisfn
;
2837 thisfn
= (struct function_range
*)
2838 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
2839 thisfn
->name
= name
;
2840 thisfn
->lowpc
= lowpc
;
2841 thisfn
->highpc
= highpc
;
2842 thisfn
->seen_line
= 0;
2843 thisfn
->next
= NULL
;
2845 if (cu
->last_fn
== NULL
)
2846 cu
->first_fn
= thisfn
;
2848 cu
->last_fn
->next
= thisfn
;
2850 cu
->last_fn
= thisfn
;
2854 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2856 struct objfile
*objfile
= cu
->objfile
;
2857 struct context_stack
*new;
2860 struct die_info
*child_die
;
2861 struct attribute
*attr
;
2863 const char *previous_prefix
= processing_current_prefix
;
2864 struct cleanup
*back_to
= NULL
;
2867 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2869 name
= dwarf2_linkage_name (die
, cu
);
2871 /* Ignore functions with missing or empty names and functions with
2872 missing or invalid low and high pc attributes. */
2873 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2876 if (cu
->language
== language_cplus
2877 || cu
->language
== language_java
)
2879 struct die_info
*spec_die
= die_specification (die
, cu
);
2881 /* NOTE: carlton/2004-01-23: We have to be careful in the
2882 presence of DW_AT_specification. For example, with GCC 3.4,
2887 // Definition of N::foo.
2891 then we'll have a tree of DIEs like this:
2893 1: DW_TAG_compile_unit
2894 2: DW_TAG_namespace // N
2895 3: DW_TAG_subprogram // declaration of N::foo
2896 4: DW_TAG_subprogram // definition of N::foo
2897 DW_AT_specification // refers to die #3
2899 Thus, when processing die #4, we have to pretend that we're
2900 in the context of its DW_AT_specification, namely the contex
2903 if (spec_die
!= NULL
)
2905 char *specification_prefix
= determine_prefix (spec_die
, cu
);
2906 processing_current_prefix
= specification_prefix
;
2907 back_to
= make_cleanup (xfree
, specification_prefix
);
2914 /* Record the function range for dwarf_decode_lines. */
2915 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
2917 new = push_context (0, lowpc
);
2918 new->name
= new_symbol (die
, die
->type
, cu
);
2920 /* If there is a location expression for DW_AT_frame_base, record
2922 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
2924 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
2925 expression is being recorded directly in the function's symbol
2926 and not in a separate frame-base object. I guess this hack is
2927 to avoid adding some sort of frame-base adjunct/annex to the
2928 function's symbol :-(. The problem with doing this is that it
2929 results in a function symbol with a location expression that
2930 has nothing to do with the location of the function, ouch! The
2931 relationship should be: a function's symbol has-a frame base; a
2932 frame-base has-a location expression. */
2933 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
2935 cu
->list_in_scope
= &local_symbols
;
2937 if (die
->child
!= NULL
)
2939 child_die
= die
->child
;
2940 while (child_die
&& child_die
->tag
)
2942 process_die (child_die
, cu
);
2943 child_die
= sibling_die (child_die
);
2947 new = pop_context ();
2948 /* Make a block for the local symbols within. */
2949 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2950 lowpc
, highpc
, objfile
);
2952 /* In C++, we can have functions nested inside functions (e.g., when
2953 a function declares a class that has methods). This means that
2954 when we finish processing a function scope, we may need to go
2955 back to building a containing block's symbol lists. */
2956 local_symbols
= new->locals
;
2957 param_symbols
= new->params
;
2959 /* If we've finished processing a top-level function, subsequent
2960 symbols go in the file symbol list. */
2961 if (outermost_context_p ())
2962 cu
->list_in_scope
= &file_symbols
;
2964 processing_current_prefix
= previous_prefix
;
2965 if (back_to
!= NULL
)
2966 do_cleanups (back_to
);
2969 /* Process all the DIES contained within a lexical block scope. Start
2970 a new scope, process the dies, and then close the scope. */
2973 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2975 struct objfile
*objfile
= cu
->objfile
;
2976 struct context_stack
*new;
2977 CORE_ADDR lowpc
, highpc
;
2978 struct die_info
*child_die
;
2981 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2983 /* Ignore blocks with missing or invalid low and high pc attributes. */
2984 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2985 as multiple lexical blocks? Handling children in a sane way would
2986 be nasty. Might be easier to properly extend generic blocks to
2988 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2993 push_context (0, lowpc
);
2994 if (die
->child
!= NULL
)
2996 child_die
= die
->child
;
2997 while (child_die
&& child_die
->tag
)
2999 process_die (child_die
, cu
);
3000 child_die
= sibling_die (child_die
);
3003 new = pop_context ();
3005 if (local_symbols
!= NULL
)
3007 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3010 local_symbols
= new->locals
;
3013 /* Get low and high pc attributes from a die. Return 1 if the attributes
3014 are present and valid, otherwise, return 0. Return -1 if the range is
3015 discontinuous, i.e. derived from DW_AT_ranges information. */
3017 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
3018 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
3020 struct objfile
*objfile
= cu
->objfile
;
3021 struct comp_unit_head
*cu_header
= &cu
->header
;
3022 struct attribute
*attr
;
3023 bfd
*obfd
= objfile
->obfd
;
3028 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3031 high
= DW_ADDR (attr
);
3032 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3034 low
= DW_ADDR (attr
);
3036 /* Found high w/o low attribute. */
3039 /* Found consecutive range of addresses. */
3044 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3047 unsigned int addr_size
= cu_header
->addr_size
;
3048 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3049 /* Value of the DW_AT_ranges attribute is the offset in the
3050 .debug_ranges section. */
3051 unsigned int offset
= DW_UNSND (attr
);
3052 /* Base address selection entry. */
3060 found_base
= cu_header
->base_known
;
3061 base
= cu_header
->base_address
;
3063 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3065 complaint (&symfile_complaints
,
3066 "Offset %d out of bounds for DW_AT_ranges attribute",
3070 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3072 /* Read in the largest possible address. */
3073 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
3074 if ((marker
& mask
) == mask
)
3076 /* If we found the largest possible address, then
3077 read the base address. */
3078 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3079 buffer
+= 2 * addr_size
;
3080 offset
+= 2 * addr_size
;
3088 CORE_ADDR range_beginning
, range_end
;
3090 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
3091 buffer
+= addr_size
;
3092 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
3093 buffer
+= addr_size
;
3094 offset
+= 2 * addr_size
;
3096 /* An end of list marker is a pair of zero addresses. */
3097 if (range_beginning
== 0 && range_end
== 0)
3098 /* Found the end of list entry. */
3101 /* Each base address selection entry is a pair of 2 values.
3102 The first is the largest possible address, the second is
3103 the base address. Check for a base address here. */
3104 if ((range_beginning
& mask
) == mask
)
3106 /* If we found the largest possible address, then
3107 read the base address. */
3108 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3115 /* We have no valid base address for the ranges
3117 complaint (&symfile_complaints
,
3118 "Invalid .debug_ranges data (no base address)");
3122 range_beginning
+= base
;
3125 /* FIXME: This is recording everything as a low-high
3126 segment of consecutive addresses. We should have a
3127 data structure for discontiguous block ranges
3131 low
= range_beginning
;
3137 if (range_beginning
< low
)
3138 low
= range_beginning
;
3139 if (range_end
> high
)
3145 /* If the first entry is an end-of-list marker, the range
3146 describes an empty scope, i.e. no instructions. */
3156 /* When using the GNU linker, .gnu.linkonce. sections are used to
3157 eliminate duplicate copies of functions and vtables and such.
3158 The linker will arbitrarily choose one and discard the others.
3159 The AT_*_pc values for such functions refer to local labels in
3160 these sections. If the section from that file was discarded, the
3161 labels are not in the output, so the relocs get a value of 0.
3162 If this is a discarded function, mark the pc bounds as invalid,
3163 so that GDB will ignore it. */
3164 if (low
== 0 && (bfd_get_file_flags (obfd
) & HAS_RELOC
) == 0)
3172 /* Get the low and high pc's represented by the scope DIE, and store
3173 them in *LOWPC and *HIGHPC. If the correct values can't be
3174 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3177 get_scope_pc_bounds (struct die_info
*die
,
3178 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3179 struct dwarf2_cu
*cu
)
3181 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3182 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3183 CORE_ADDR current_low
, current_high
;
3185 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3187 best_low
= current_low
;
3188 best_high
= current_high
;
3192 struct die_info
*child
= die
->child
;
3194 while (child
&& child
->tag
)
3196 switch (child
->tag
) {
3197 case DW_TAG_subprogram
:
3198 if (dwarf2_get_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
))
3200 best_low
= min (best_low
, current_low
);
3201 best_high
= max (best_high
, current_high
);
3204 case DW_TAG_namespace
:
3205 /* FIXME: carlton/2004-01-16: Should we do this for
3206 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3207 that current GCC's always emit the DIEs corresponding
3208 to definitions of methods of classes as children of a
3209 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3210 the DIEs giving the declarations, which could be
3211 anywhere). But I don't see any reason why the
3212 standards says that they have to be there. */
3213 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3215 if (current_low
!= ((CORE_ADDR
) -1))
3217 best_low
= min (best_low
, current_low
);
3218 best_high
= max (best_high
, current_high
);
3226 child
= sibling_die (child
);
3231 *highpc
= best_high
;
3234 /* Add an aggregate field to the field list. */
3237 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3238 struct dwarf2_cu
*cu
)
3240 struct objfile
*objfile
= cu
->objfile
;
3241 struct nextfield
*new_field
;
3242 struct attribute
*attr
;
3244 char *fieldname
= "";
3246 /* Allocate a new field list entry and link it in. */
3247 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3248 make_cleanup (xfree
, new_field
);
3249 memset (new_field
, 0, sizeof (struct nextfield
));
3250 new_field
->next
= fip
->fields
;
3251 fip
->fields
= new_field
;
3254 /* Handle accessibility and virtuality of field.
3255 The default accessibility for members is public, the default
3256 accessibility for inheritance is private. */
3257 if (die
->tag
!= DW_TAG_inheritance
)
3258 new_field
->accessibility
= DW_ACCESS_public
;
3260 new_field
->accessibility
= DW_ACCESS_private
;
3261 new_field
->virtuality
= DW_VIRTUALITY_none
;
3263 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3265 new_field
->accessibility
= DW_UNSND (attr
);
3266 if (new_field
->accessibility
!= DW_ACCESS_public
)
3267 fip
->non_public_fields
= 1;
3268 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3270 new_field
->virtuality
= DW_UNSND (attr
);
3272 fp
= &new_field
->field
;
3274 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3276 /* Data member other than a C++ static data member. */
3278 /* Get type of field. */
3279 fp
->type
= die_type (die
, cu
);
3281 FIELD_STATIC_KIND (*fp
) = 0;
3283 /* Get bit size of field (zero if none). */
3284 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3287 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3291 FIELD_BITSIZE (*fp
) = 0;
3294 /* Get bit offset of field. */
3295 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3298 FIELD_BITPOS (*fp
) =
3299 decode_locdesc (DW_BLOCK (attr
), cu
) * bits_per_byte
;
3302 FIELD_BITPOS (*fp
) = 0;
3303 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3306 if (BITS_BIG_ENDIAN
)
3308 /* For big endian bits, the DW_AT_bit_offset gives the
3309 additional bit offset from the MSB of the containing
3310 anonymous object to the MSB of the field. We don't
3311 have to do anything special since we don't need to
3312 know the size of the anonymous object. */
3313 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3317 /* For little endian bits, compute the bit offset to the
3318 MSB of the anonymous object, subtract off the number of
3319 bits from the MSB of the field to the MSB of the
3320 object, and then subtract off the number of bits of
3321 the field itself. The result is the bit offset of
3322 the LSB of the field. */
3324 int bit_offset
= DW_UNSND (attr
);
3326 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3329 /* The size of the anonymous object containing
3330 the bit field is explicit, so use the
3331 indicated size (in bytes). */
3332 anonymous_size
= DW_UNSND (attr
);
3336 /* The size of the anonymous object containing
3337 the bit field must be inferred from the type
3338 attribute of the data member containing the
3340 anonymous_size
= TYPE_LENGTH (fp
->type
);
3342 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
3343 - bit_offset
- FIELD_BITSIZE (*fp
);
3347 /* Get name of field. */
3348 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3349 if (attr
&& DW_STRING (attr
))
3350 fieldname
= DW_STRING (attr
);
3352 /* The name is already allocated along with this objfile, so we don't
3353 need to duplicate it for the type. */
3354 fp
->name
= fieldname
;
3356 /* Change accessibility for artificial fields (e.g. virtual table
3357 pointer or virtual base class pointer) to private. */
3358 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
3360 new_field
->accessibility
= DW_ACCESS_private
;
3361 fip
->non_public_fields
= 1;
3364 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
3366 /* C++ static member. */
3368 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3369 is a declaration, but all versions of G++ as of this writing
3370 (so through at least 3.2.1) incorrectly generate
3371 DW_TAG_variable tags. */
3375 /* Get name of field. */
3376 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3377 if (attr
&& DW_STRING (attr
))
3378 fieldname
= DW_STRING (attr
);
3382 /* Get physical name. */
3383 physname
= dwarf2_linkage_name (die
, cu
);
3385 /* The name is already allocated along with this objfile, so we don't
3386 need to duplicate it for the type. */
3387 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
3388 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3389 FIELD_NAME (*fp
) = fieldname
;
3391 else if (die
->tag
== DW_TAG_inheritance
)
3393 /* C++ base class field. */
3394 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3396 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
3398 FIELD_BITSIZE (*fp
) = 0;
3399 FIELD_STATIC_KIND (*fp
) = 0;
3400 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3401 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
3402 fip
->nbaseclasses
++;
3406 /* Create the vector of fields, and attach it to the type. */
3409 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3410 struct dwarf2_cu
*cu
)
3412 int nfields
= fip
->nfields
;
3414 /* Record the field count, allocate space for the array of fields,
3415 and create blank accessibility bitfields if necessary. */
3416 TYPE_NFIELDS (type
) = nfields
;
3417 TYPE_FIELDS (type
) = (struct field
*)
3418 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3419 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3421 if (fip
->non_public_fields
)
3423 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3425 TYPE_FIELD_PRIVATE_BITS (type
) =
3426 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3427 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3429 TYPE_FIELD_PROTECTED_BITS (type
) =
3430 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3431 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3433 TYPE_FIELD_IGNORE_BITS (type
) =
3434 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3435 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3438 /* If the type has baseclasses, allocate and clear a bit vector for
3439 TYPE_FIELD_VIRTUAL_BITS. */
3440 if (fip
->nbaseclasses
)
3442 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3445 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3446 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
3447 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
3448 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3449 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3452 /* Copy the saved-up fields into the field vector. Start from the head
3453 of the list, adding to the tail of the field array, so that they end
3454 up in the same order in the array in which they were added to the list. */
3455 while (nfields
-- > 0)
3457 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3458 switch (fip
->fields
->accessibility
)
3460 case DW_ACCESS_private
:
3461 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3464 case DW_ACCESS_protected
:
3465 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3468 case DW_ACCESS_public
:
3472 /* Unknown accessibility. Complain and treat it as public. */
3474 complaint (&symfile_complaints
, "unsupported accessibility %d",
3475 fip
->fields
->accessibility
);
3479 if (nfields
< fip
->nbaseclasses
)
3481 switch (fip
->fields
->virtuality
)
3483 case DW_VIRTUALITY_virtual
:
3484 case DW_VIRTUALITY_pure_virtual
:
3485 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3489 fip
->fields
= fip
->fields
->next
;
3493 /* Add a member function to the proper fieldlist. */
3496 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3497 struct type
*type
, struct dwarf2_cu
*cu
)
3499 struct objfile
*objfile
= cu
->objfile
;
3500 struct attribute
*attr
;
3501 struct fnfieldlist
*flp
;
3503 struct fn_field
*fnp
;
3506 struct nextfnfield
*new_fnfield
;
3508 /* Get name of member function. */
3509 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3510 if (attr
&& DW_STRING (attr
))
3511 fieldname
= DW_STRING (attr
);
3515 /* Get the mangled name. */
3516 physname
= dwarf2_linkage_name (die
, cu
);
3518 /* Look up member function name in fieldlist. */
3519 for (i
= 0; i
< fip
->nfnfields
; i
++)
3521 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3525 /* Create new list element if necessary. */
3526 if (i
< fip
->nfnfields
)
3527 flp
= &fip
->fnfieldlists
[i
];
3530 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3532 fip
->fnfieldlists
= (struct fnfieldlist
*)
3533 xrealloc (fip
->fnfieldlists
,
3534 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3535 * sizeof (struct fnfieldlist
));
3536 if (fip
->nfnfields
== 0)
3537 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3539 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3540 flp
->name
= fieldname
;
3546 /* Create a new member function field and chain it to the field list
3548 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3549 make_cleanup (xfree
, new_fnfield
);
3550 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3551 new_fnfield
->next
= flp
->head
;
3552 flp
->head
= new_fnfield
;
3555 /* Fill in the member function field info. */
3556 fnp
= &new_fnfield
->fnfield
;
3557 /* The name is already allocated along with this objfile, so we don't
3558 need to duplicate it for the type. */
3559 fnp
->physname
= physname
? physname
: "";
3560 fnp
->type
= alloc_type (objfile
);
3561 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
3563 int nparams
= TYPE_NFIELDS (die
->type
);
3565 /* TYPE is the domain of this method, and DIE->TYPE is the type
3566 of the method itself (TYPE_CODE_METHOD). */
3567 smash_to_method_type (fnp
->type
, type
,
3568 TYPE_TARGET_TYPE (die
->type
),
3569 TYPE_FIELDS (die
->type
),
3570 TYPE_NFIELDS (die
->type
),
3571 TYPE_VARARGS (die
->type
));
3573 /* Handle static member functions.
3574 Dwarf2 has no clean way to discern C++ static and non-static
3575 member functions. G++ helps GDB by marking the first
3576 parameter for non-static member functions (which is the
3577 this pointer) as artificial. We obtain this information
3578 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3579 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
3580 fnp
->voffset
= VOFFSET_STATIC
;
3583 complaint (&symfile_complaints
, "member function type missing for '%s'",
3586 /* Get fcontext from DW_AT_containing_type if present. */
3587 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3588 fnp
->fcontext
= die_containing_type (die
, cu
);
3590 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3591 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3593 /* Get accessibility. */
3594 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3597 switch (DW_UNSND (attr
))
3599 case DW_ACCESS_private
:
3600 fnp
->is_private
= 1;
3602 case DW_ACCESS_protected
:
3603 fnp
->is_protected
= 1;
3608 /* Check for artificial methods. */
3609 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3610 if (attr
&& DW_UNSND (attr
) != 0)
3611 fnp
->is_artificial
= 1;
3613 /* Get index in virtual function table if it is a virtual member function. */
3614 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3617 /* Support the .debug_loc offsets */
3618 if (attr_form_is_block (attr
))
3620 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3622 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3624 dwarf2_complex_location_expr_complaint ();
3628 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3634 /* Create the vector of member function fields, and attach it to the type. */
3637 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3638 struct dwarf2_cu
*cu
)
3640 struct fnfieldlist
*flp
;
3641 int total_length
= 0;
3644 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3645 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3646 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3648 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3650 struct nextfnfield
*nfp
= flp
->head
;
3651 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3654 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3655 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3656 fn_flp
->fn_fields
= (struct fn_field
*)
3657 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3658 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3659 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3661 total_length
+= flp
->length
;
3664 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3665 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3669 /* Returns non-zero if NAME is the name of a vtable member in CU's
3670 language, zero otherwise. */
3672 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
3674 static const char vptr
[] = "_vptr";
3675 static const char vtable
[] = "vtable";
3677 /* Look for the C++ and Java forms of the vtable. */
3678 if ((cu
->language
== language_java
3679 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
3680 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
3681 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
3688 /* Called when we find the DIE that starts a structure or union scope
3689 (definition) to process all dies that define the members of the
3692 NOTE: we need to call struct_type regardless of whether or not the
3693 DIE has an at_name attribute, since it might be an anonymous
3694 structure or union. This gets the type entered into our set of
3697 However, if the structure is incomplete (an opaque struct/union)
3698 then suppress creating a symbol table entry for it since gdb only
3699 wants to find the one with the complete definition. Note that if
3700 it is complete, we just call new_symbol, which does it's own
3701 checking about whether the struct/union is anonymous or not (and
3702 suppresses creating a symbol table entry itself). */
3705 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3707 struct objfile
*objfile
= cu
->objfile
;
3709 struct attribute
*attr
;
3710 const char *previous_prefix
= processing_current_prefix
;
3711 struct cleanup
*back_to
= NULL
;
3716 type
= alloc_type (objfile
);
3718 INIT_CPLUS_SPECIFIC (type
);
3719 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3720 if (attr
&& DW_STRING (attr
))
3722 if (cu
->language
== language_cplus
3723 || cu
->language
== language_java
)
3725 char *new_prefix
= determine_class_name (die
, cu
);
3726 TYPE_TAG_NAME (type
) = obsavestring (new_prefix
,
3727 strlen (new_prefix
),
3728 &objfile
->objfile_obstack
);
3729 back_to
= make_cleanup (xfree
, new_prefix
);
3730 processing_current_prefix
= new_prefix
;
3734 /* The name is already allocated along with this objfile, so
3735 we don't need to duplicate it for the type. */
3736 TYPE_TAG_NAME (type
) = DW_STRING (attr
);
3740 if (die
->tag
== DW_TAG_structure_type
)
3742 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
3744 else if (die
->tag
== DW_TAG_union_type
)
3746 TYPE_CODE (type
) = TYPE_CODE_UNION
;
3750 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
3752 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
3755 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3758 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3762 TYPE_LENGTH (type
) = 0;
3765 if (die_is_declaration (die
, cu
))
3766 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
3768 /* We need to add the type field to the die immediately so we don't
3769 infinitely recurse when dealing with pointers to the structure
3770 type within the structure itself. */
3771 set_die_type (die
, type
, cu
);
3773 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
3775 struct field_info fi
;
3776 struct die_info
*child_die
;
3777 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
3779 memset (&fi
, 0, sizeof (struct field_info
));
3781 child_die
= die
->child
;
3783 while (child_die
&& child_die
->tag
)
3785 if (child_die
->tag
== DW_TAG_member
3786 || child_die
->tag
== DW_TAG_variable
)
3788 /* NOTE: carlton/2002-11-05: A C++ static data member
3789 should be a DW_TAG_member that is a declaration, but
3790 all versions of G++ as of this writing (so through at
3791 least 3.2.1) incorrectly generate DW_TAG_variable
3792 tags for them instead. */
3793 dwarf2_add_field (&fi
, child_die
, cu
);
3795 else if (child_die
->tag
== DW_TAG_subprogram
)
3797 /* C++ member function. */
3798 read_type_die (child_die
, cu
);
3799 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
3801 else if (child_die
->tag
== DW_TAG_inheritance
)
3803 /* C++ base class field. */
3804 dwarf2_add_field (&fi
, child_die
, cu
);
3806 child_die
= sibling_die (child_die
);
3809 /* Attach fields and member functions to the type. */
3811 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
3814 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
3816 /* Get the type which refers to the base class (possibly this
3817 class itself) which contains the vtable pointer for the current
3818 class from the DW_AT_containing_type attribute. */
3820 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3822 struct type
*t
= die_containing_type (die
, cu
);
3824 TYPE_VPTR_BASETYPE (type
) = t
;
3829 /* Our own class provides vtbl ptr. */
3830 for (i
= TYPE_NFIELDS (t
) - 1;
3831 i
>= TYPE_N_BASECLASSES (t
);
3834 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
3836 if (is_vtable_name (fieldname
, cu
))
3838 TYPE_VPTR_FIELDNO (type
) = i
;
3843 /* Complain if virtual function table field not found. */
3844 if (i
< TYPE_N_BASECLASSES (t
))
3845 complaint (&symfile_complaints
,
3846 "virtual function table pointer not found when defining class '%s'",
3847 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
3852 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3857 do_cleanups (back_to
);
3860 processing_current_prefix
= previous_prefix
;
3861 if (back_to
!= NULL
)
3862 do_cleanups (back_to
);
3866 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3868 struct objfile
*objfile
= cu
->objfile
;
3869 const char *previous_prefix
= processing_current_prefix
;
3870 struct die_info
*child_die
= die
->child
;
3872 if (TYPE_TAG_NAME (die
->type
) != NULL
)
3873 processing_current_prefix
= TYPE_TAG_NAME (die
->type
);
3875 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
3876 snapshots) has been known to create a die giving a declaration
3877 for a class that has, as a child, a die giving a definition for a
3878 nested class. So we have to process our children even if the
3879 current die is a declaration. Normally, of course, a declaration
3880 won't have any children at all. */
3882 while (child_die
!= NULL
&& child_die
->tag
)
3884 if (child_die
->tag
== DW_TAG_member
3885 || child_die
->tag
== DW_TAG_variable
3886 || child_die
->tag
== DW_TAG_inheritance
)
3891 process_die (child_die
, cu
);
3893 child_die
= sibling_die (child_die
);
3896 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
3897 new_symbol (die
, die
->type
, cu
);
3899 processing_current_prefix
= previous_prefix
;
3902 /* Given a DW_AT_enumeration_type die, set its type. We do not
3903 complete the type's fields yet, or create any symbols. */
3906 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3908 struct objfile
*objfile
= cu
->objfile
;
3910 struct attribute
*attr
;
3915 type
= alloc_type (objfile
);
3917 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
3918 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3919 if (attr
&& DW_STRING (attr
))
3921 char *name
= DW_STRING (attr
);
3923 if (processing_has_namespace_info
)
3925 TYPE_TAG_NAME (type
) = typename_concat (&objfile
->objfile_obstack
,
3926 processing_current_prefix
,
3931 /* The name is already allocated along with this objfile, so
3932 we don't need to duplicate it for the type. */
3933 TYPE_TAG_NAME (type
) = name
;
3937 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3940 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3944 TYPE_LENGTH (type
) = 0;
3947 set_die_type (die
, type
, cu
);
3950 /* Determine the name of the type represented by DIE, which should be
3951 a named C++ or Java compound type. Return the name in question; the caller
3952 is responsible for xfree()'ing it. */
3955 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
3957 struct cleanup
*back_to
= NULL
;
3958 struct die_info
*spec_die
= die_specification (die
, cu
);
3959 char *new_prefix
= NULL
;
3961 /* If this is the definition of a class that is declared by another
3962 die, then processing_current_prefix may not be accurate; see
3963 read_func_scope for a similar example. */
3964 if (spec_die
!= NULL
)
3966 char *specification_prefix
= determine_prefix (spec_die
, cu
);
3967 processing_current_prefix
= specification_prefix
;
3968 back_to
= make_cleanup (xfree
, specification_prefix
);
3971 /* If we don't have namespace debug info, guess the name by trying
3972 to demangle the names of members, just like we did in
3973 guess_structure_name. */
3974 if (!processing_has_namespace_info
)
3976 struct die_info
*child
;
3978 for (child
= die
->child
;
3979 child
!= NULL
&& child
->tag
!= 0;
3980 child
= sibling_die (child
))
3982 if (child
->tag
== DW_TAG_subprogram
)
3985 = language_class_name_from_physname (cu
->language_defn
,
3989 if (new_prefix
!= NULL
)
3995 if (new_prefix
== NULL
)
3997 const char *name
= dwarf2_name (die
, cu
);
3998 new_prefix
= typename_concat (NULL
, processing_current_prefix
,
3999 name
? name
: "<<anonymous>>",
4003 if (back_to
!= NULL
)
4004 do_cleanups (back_to
);
4009 /* Given a pointer to a die which begins an enumeration, process all
4010 the dies that define the members of the enumeration, and create the
4011 symbol for the enumeration type.
4013 NOTE: We reverse the order of the element list. */
4016 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4018 struct objfile
*objfile
= cu
->objfile
;
4019 struct die_info
*child_die
;
4020 struct field
*fields
;
4021 struct attribute
*attr
;
4024 int unsigned_enum
= 1;
4028 if (die
->child
!= NULL
)
4030 child_die
= die
->child
;
4031 while (child_die
&& child_die
->tag
)
4033 if (child_die
->tag
!= DW_TAG_enumerator
)
4035 process_die (child_die
, cu
);
4039 attr
= dwarf2_attr (child_die
, DW_AT_name
, cu
);
4042 sym
= new_symbol (child_die
, die
->type
, cu
);
4043 if (SYMBOL_VALUE (sym
) < 0)
4046 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4048 fields
= (struct field
*)
4050 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
4051 * sizeof (struct field
));
4054 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
4055 FIELD_TYPE (fields
[num_fields
]) = NULL
;
4056 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
4057 FIELD_BITSIZE (fields
[num_fields
]) = 0;
4058 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
4064 child_die
= sibling_die (child_die
);
4069 TYPE_NFIELDS (die
->type
) = num_fields
;
4070 TYPE_FIELDS (die
->type
) = (struct field
*)
4071 TYPE_ALLOC (die
->type
, sizeof (struct field
) * num_fields
);
4072 memcpy (TYPE_FIELDS (die
->type
), fields
,
4073 sizeof (struct field
) * num_fields
);
4077 TYPE_FLAGS (die
->type
) |= TYPE_FLAG_UNSIGNED
;
4080 new_symbol (die
, die
->type
, cu
);
4083 /* Extract all information from a DW_TAG_array_type DIE and put it in
4084 the DIE's type field. For now, this only handles one dimensional
4088 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4090 struct objfile
*objfile
= cu
->objfile
;
4091 struct die_info
*child_die
;
4092 struct type
*type
= NULL
;
4093 struct type
*element_type
, *range_type
, *index_type
;
4094 struct type
**range_types
= NULL
;
4095 struct attribute
*attr
;
4097 struct cleanup
*back_to
;
4099 /* Return if we've already decoded this type. */
4105 element_type
= die_type (die
, cu
);
4107 /* Irix 6.2 native cc creates array types without children for
4108 arrays with unspecified length. */
4109 if (die
->child
== NULL
)
4111 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
4112 range_type
= create_range_type (NULL
, index_type
, 0, -1);
4113 set_die_type (die
, create_array_type (NULL
, element_type
, range_type
),
4118 back_to
= make_cleanup (null_cleanup
, NULL
);
4119 child_die
= die
->child
;
4120 while (child_die
&& child_die
->tag
)
4122 if (child_die
->tag
== DW_TAG_subrange_type
)
4124 read_subrange_type (child_die
, cu
);
4126 if (child_die
->type
!= NULL
)
4128 /* The range type was succesfully read. Save it for
4129 the array type creation. */
4130 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
4132 range_types
= (struct type
**)
4133 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
4134 * sizeof (struct type
*));
4136 make_cleanup (free_current_contents
, &range_types
);
4138 range_types
[ndim
++] = child_die
->type
;
4141 child_die
= sibling_die (child_die
);
4144 /* Dwarf2 dimensions are output from left to right, create the
4145 necessary array types in backwards order. */
4147 type
= element_type
;
4149 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
4153 type
= create_array_type (NULL
, type
, range_types
[i
++]);
4158 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
4161 /* Understand Dwarf2 support for vector types (like they occur on
4162 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4163 array type. This is not part of the Dwarf2/3 standard yet, but a
4164 custom vendor extension. The main difference between a regular
4165 array and the vector variant is that vectors are passed by value
4167 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4169 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
4171 do_cleanups (back_to
);
4173 /* Install the type in the die. */
4174 set_die_type (die
, type
, cu
);
4177 static enum dwarf_array_dim_ordering
4178 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4180 struct attribute
*attr
;
4182 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4184 if (attr
) return DW_SND (attr
);
4187 GNU F77 is a special case, as at 08/2004 array type info is the
4188 opposite order to the dwarf2 specification, but data is still
4189 laid out as per normal fortran.
4191 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4195 if (cu
->language
== language_fortran
&&
4196 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4198 return DW_ORD_row_major
;
4201 switch (cu
->language_defn
->la_array_ordering
)
4203 case array_column_major
:
4204 return DW_ORD_col_major
;
4205 case array_row_major
:
4207 return DW_ORD_row_major
;
4212 /* First cut: install each common block member as a global variable. */
4215 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4217 struct die_info
*child_die
;
4218 struct attribute
*attr
;
4220 CORE_ADDR base
= (CORE_ADDR
) 0;
4222 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4225 /* Support the .debug_loc offsets */
4226 if (attr_form_is_block (attr
))
4228 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4230 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
4232 dwarf2_complex_location_expr_complaint ();
4236 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4237 "common block member");
4240 if (die
->child
!= NULL
)
4242 child_die
= die
->child
;
4243 while (child_die
&& child_die
->tag
)
4245 sym
= new_symbol (child_die
, NULL
, cu
);
4246 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4249 SYMBOL_VALUE_ADDRESS (sym
) =
4250 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4251 add_symbol_to_list (sym
, &global_symbols
);
4253 child_die
= sibling_die (child_die
);
4258 /* Read a C++ namespace. */
4261 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4263 struct objfile
*objfile
= cu
->objfile
;
4264 const char *previous_prefix
= processing_current_prefix
;
4267 struct die_info
*current_die
;
4268 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4270 name
= namespace_name (die
, &is_anonymous
, cu
);
4272 /* Now build the name of the current namespace. */
4274 if (previous_prefix
[0] == '\0')
4276 processing_current_prefix
= name
;
4280 char *temp_name
= typename_concat (NULL
, previous_prefix
, name
, cu
);
4281 make_cleanup (xfree
, temp_name
);
4282 processing_current_prefix
= temp_name
;
4285 /* Add a symbol associated to this if we haven't seen the namespace
4286 before. Also, add a using directive if it's an anonymous
4289 if (dwarf2_extension (die
, cu
) == NULL
)
4293 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
4294 this cast will hopefully become unnecessary. */
4295 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
4296 (char *) processing_current_prefix
,
4298 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4300 new_symbol (die
, type
, cu
);
4301 set_die_type (die
, type
, cu
);
4304 cp_add_using_directive (processing_current_prefix
,
4305 strlen (previous_prefix
),
4306 strlen (processing_current_prefix
));
4309 if (die
->child
!= NULL
)
4311 struct die_info
*child_die
= die
->child
;
4313 while (child_die
&& child_die
->tag
)
4315 process_die (child_die
, cu
);
4316 child_die
= sibling_die (child_die
);
4320 processing_current_prefix
= previous_prefix
;
4321 do_cleanups (back_to
);
4324 /* Return the name of the namespace represented by DIE. Set
4325 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4329 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
4331 struct die_info
*current_die
;
4332 const char *name
= NULL
;
4334 /* Loop through the extensions until we find a name. */
4336 for (current_die
= die
;
4337 current_die
!= NULL
;
4338 current_die
= dwarf2_extension (die
, cu
))
4340 name
= dwarf2_name (current_die
, cu
);
4345 /* Is it an anonymous namespace? */
4347 *is_anonymous
= (name
== NULL
);
4349 name
= "(anonymous namespace)";
4354 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4355 the user defined type vector. */
4358 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4360 struct comp_unit_head
*cu_header
= &cu
->header
;
4362 struct attribute
*attr_byte_size
;
4363 struct attribute
*attr_address_class
;
4364 int byte_size
, addr_class
;
4371 type
= lookup_pointer_type (die_type (die
, cu
));
4373 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4375 byte_size
= DW_UNSND (attr_byte_size
);
4377 byte_size
= cu_header
->addr_size
;
4379 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
4380 if (attr_address_class
)
4381 addr_class
= DW_UNSND (attr_address_class
);
4383 addr_class
= DW_ADDR_none
;
4385 /* If the pointer size or address class is different than the
4386 default, create a type variant marked as such and set the
4387 length accordingly. */
4388 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
4390 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
4394 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
4395 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
4396 type
= make_type_with_address_space (type
, type_flags
);
4398 else if (TYPE_LENGTH (type
) != byte_size
)
4400 complaint (&symfile_complaints
, "invalid pointer size %d", byte_size
);
4403 /* Should we also complain about unhandled address classes? */
4407 TYPE_LENGTH (type
) = byte_size
;
4408 set_die_type (die
, type
, cu
);
4411 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4412 the user defined type vector. */
4415 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4417 struct objfile
*objfile
= cu
->objfile
;
4419 struct type
*to_type
;
4420 struct type
*domain
;
4427 type
= alloc_type (objfile
);
4428 to_type
= die_type (die
, cu
);
4429 domain
= die_containing_type (die
, cu
);
4430 smash_to_member_type (type
, domain
, to_type
);
4432 set_die_type (die
, type
, cu
);
4435 /* Extract all information from a DW_TAG_reference_type DIE and add to
4436 the user defined type vector. */
4439 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4441 struct comp_unit_head
*cu_header
= &cu
->header
;
4443 struct attribute
*attr
;
4450 type
= lookup_reference_type (die_type (die
, cu
));
4451 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4454 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4458 TYPE_LENGTH (type
) = cu_header
->addr_size
;
4460 set_die_type (die
, type
, cu
);
4464 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4466 struct type
*base_type
;
4473 base_type
= die_type (die
, cu
);
4474 set_die_type (die
, make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0),
4479 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4481 struct type
*base_type
;
4488 base_type
= die_type (die
, cu
);
4489 set_die_type (die
, make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0),
4493 /* Extract all information from a DW_TAG_string_type DIE and add to
4494 the user defined type vector. It isn't really a user defined type,
4495 but it behaves like one, with other DIE's using an AT_user_def_type
4496 attribute to reference it. */
4499 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4501 struct objfile
*objfile
= cu
->objfile
;
4502 struct type
*type
, *range_type
, *index_type
, *char_type
;
4503 struct attribute
*attr
;
4504 unsigned int length
;
4511 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4514 length
= DW_UNSND (attr
);
4518 /* check for the DW_AT_byte_size attribute */
4519 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4522 length
= DW_UNSND (attr
);
4529 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
4530 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4531 if (cu
->language
== language_fortran
)
4533 /* Need to create a unique string type for bounds
4535 type
= create_string_type (0, range_type
);
4539 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
, cu
);
4540 type
= create_string_type (char_type
, range_type
);
4542 set_die_type (die
, type
, cu
);
4545 /* Handle DIES due to C code like:
4549 int (*funcp)(int a, long l);
4553 ('funcp' generates a DW_TAG_subroutine_type DIE)
4557 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4559 struct type
*type
; /* Type that this function returns */
4560 struct type
*ftype
; /* Function that returns above type */
4561 struct attribute
*attr
;
4563 /* Decode the type that this subroutine returns */
4568 type
= die_type (die
, cu
);
4569 ftype
= make_function_type (type
, (struct type
**) 0);
4571 /* All functions in C++ and Java have prototypes. */
4572 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4573 if ((attr
&& (DW_UNSND (attr
) != 0))
4574 || cu
->language
== language_cplus
4575 || cu
->language
== language_java
)
4576 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
4578 if (die
->child
!= NULL
)
4580 struct die_info
*child_die
;
4584 /* Count the number of parameters.
4585 FIXME: GDB currently ignores vararg functions, but knows about
4586 vararg member functions. */
4587 child_die
= die
->child
;
4588 while (child_die
&& child_die
->tag
)
4590 if (child_die
->tag
== DW_TAG_formal_parameter
)
4592 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4593 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
4594 child_die
= sibling_die (child_die
);
4597 /* Allocate storage for parameters and fill them in. */
4598 TYPE_NFIELDS (ftype
) = nparams
;
4599 TYPE_FIELDS (ftype
) = (struct field
*)
4600 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
4602 child_die
= die
->child
;
4603 while (child_die
&& child_die
->tag
)
4605 if (child_die
->tag
== DW_TAG_formal_parameter
)
4607 /* Dwarf2 has no clean way to discern C++ static and non-static
4608 member functions. G++ helps GDB by marking the first
4609 parameter for non-static member functions (which is the
4610 this pointer) as artificial. We pass this information
4611 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4612 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
4614 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
4616 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
4617 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
4620 child_die
= sibling_die (child_die
);
4624 set_die_type (die
, ftype
, cu
);
4628 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
4630 struct objfile
*objfile
= cu
->objfile
;
4631 struct attribute
*attr
;
4636 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4637 if (attr
&& DW_STRING (attr
))
4639 name
= DW_STRING (attr
);
4641 set_die_type (die
, init_type (TYPE_CODE_TYPEDEF
, 0,
4642 TYPE_FLAG_TARGET_STUB
, name
, objfile
),
4644 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, cu
);
4648 /* Find a representation of a given base type and install
4649 it in the TYPE field of the die. */
4652 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4654 struct objfile
*objfile
= cu
->objfile
;
4656 struct attribute
*attr
;
4657 int encoding
= 0, size
= 0;
4659 /* If we've already decoded this die, this is a no-op. */
4665 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
4668 encoding
= DW_UNSND (attr
);
4670 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4673 size
= DW_UNSND (attr
);
4675 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4676 if (attr
&& DW_STRING (attr
))
4678 enum type_code code
= TYPE_CODE_INT
;
4683 case DW_ATE_address
:
4684 /* Turn DW_ATE_address into a void * pointer. */
4685 code
= TYPE_CODE_PTR
;
4686 type_flags
|= TYPE_FLAG_UNSIGNED
;
4688 case DW_ATE_boolean
:
4689 code
= TYPE_CODE_BOOL
;
4690 type_flags
|= TYPE_FLAG_UNSIGNED
;
4692 case DW_ATE_complex_float
:
4693 code
= TYPE_CODE_COMPLEX
;
4696 code
= TYPE_CODE_FLT
;
4699 case DW_ATE_signed_char
:
4701 case DW_ATE_unsigned
:
4702 case DW_ATE_unsigned_char
:
4703 type_flags
|= TYPE_FLAG_UNSIGNED
;
4706 complaint (&symfile_complaints
, "unsupported DW_AT_encoding: '%s'",
4707 dwarf_type_encoding_name (encoding
));
4710 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
4711 if (encoding
== DW_ATE_address
)
4712 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
,
4714 else if (encoding
== DW_ATE_complex_float
)
4717 TYPE_TARGET_TYPE (type
)
4718 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
, cu
);
4719 else if (size
== 16)
4720 TYPE_TARGET_TYPE (type
)
4721 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
4723 TYPE_TARGET_TYPE (type
)
4724 = dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
4729 type
= dwarf_base_type (encoding
, size
, cu
);
4731 set_die_type (die
, type
, cu
);
4734 /* Read the given DW_AT_subrange DIE. */
4737 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4739 struct type
*base_type
;
4740 struct type
*range_type
;
4741 struct attribute
*attr
;
4745 /* If we have already decoded this die, then nothing more to do. */
4749 base_type
= die_type (die
, cu
);
4750 if (base_type
== NULL
)
4752 complaint (&symfile_complaints
,
4753 "DW_AT_type missing from DW_TAG_subrange_type");
4757 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
4758 base_type
= alloc_type (NULL
);
4760 if (cu
->language
== language_fortran
)
4762 /* FORTRAN implies a lower bound of 1, if not given. */
4766 /* FIXME: For variable sized arrays either of these could be
4767 a variable rather than a constant value. We'll allow it,
4768 but we don't know how to handle it. */
4769 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
4771 low
= dwarf2_get_attr_constant_value (attr
, 0);
4773 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
4776 if (attr
->form
== DW_FORM_block1
)
4778 /* GCC encodes arrays with unspecified or dynamic length
4779 with a DW_FORM_block1 attribute.
4780 FIXME: GDB does not yet know how to handle dynamic
4781 arrays properly, treat them as arrays with unspecified
4784 FIXME: jimb/2003-09-22: GDB does not really know
4785 how to handle arrays of unspecified length
4786 either; we just represent them as zero-length
4787 arrays. Choose an appropriate upper bound given
4788 the lower bound we've computed above. */
4792 high
= dwarf2_get_attr_constant_value (attr
, 1);
4795 range_type
= create_range_type (NULL
, base_type
, low
, high
);
4797 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4798 if (attr
&& DW_STRING (attr
))
4799 TYPE_NAME (range_type
) = DW_STRING (attr
);
4801 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4803 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
4805 set_die_type (die
, range_type
, cu
);
4809 /* Read a whole compilation unit into a linked list of dies. */
4811 static struct die_info
*
4812 read_comp_unit (char *info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
4814 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
4817 /* Read a single die and all its descendents. Set the die's sibling
4818 field to NULL; set other fields in the die correctly, and set all
4819 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
4820 location of the info_ptr after reading all of those dies. PARENT
4821 is the parent of the die in question. */
4823 static struct die_info
*
4824 read_die_and_children (char *info_ptr
, bfd
*abfd
,
4825 struct dwarf2_cu
*cu
,
4826 char **new_info_ptr
,
4827 struct die_info
*parent
)
4829 struct die_info
*die
;
4833 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
4834 store_in_ref_table (die
->offset
, die
, cu
);
4838 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
4844 *new_info_ptr
= cur_ptr
;
4847 die
->sibling
= NULL
;
4848 die
->parent
= parent
;
4852 /* Read a die, all of its descendents, and all of its siblings; set
4853 all of the fields of all of the dies correctly. Arguments are as
4854 in read_die_and_children. */
4856 static struct die_info
*
4857 read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
4858 struct dwarf2_cu
*cu
,
4859 char **new_info_ptr
,
4860 struct die_info
*parent
)
4862 struct die_info
*first_die
, *last_sibling
;
4866 first_die
= last_sibling
= NULL
;
4870 struct die_info
*die
4871 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
4879 last_sibling
->sibling
= die
;
4884 *new_info_ptr
= cur_ptr
;
4894 /* Free a linked list of dies. */
4897 free_die_list (struct die_info
*dies
)
4899 struct die_info
*die
, *next
;
4904 if (die
->child
!= NULL
)
4905 free_die_list (die
->child
);
4906 next
= die
->sibling
;
4913 /* Read the contents of the section at OFFSET and of size SIZE from the
4914 object file specified by OBJFILE into the objfile_obstack and return it. */
4917 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
4919 bfd
*abfd
= objfile
->obfd
;
4921 bfd_size_type size
= bfd_get_section_size (sectp
);
4926 buf
= (char *) obstack_alloc (&objfile
->objfile_obstack
, size
);
4928 = (char *) symfile_relocate_debug_section (abfd
, sectp
, (bfd_byte
*) buf
);
4932 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
4933 || bfd_bread (buf
, size
, abfd
) != size
)
4934 error ("Dwarf Error: Can't read DWARF data from '%s'",
4935 bfd_get_filename (abfd
));
4940 /* In DWARF version 2, the description of the debugging information is
4941 stored in a separate .debug_abbrev section. Before we read any
4942 dies from a section we read in all abbreviations and install them
4943 in a hash table. This function also sets flags in CU describing
4944 the data found in the abbrev table. */
4947 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
4949 struct comp_unit_head
*cu_header
= &cu
->header
;
4951 struct abbrev_info
*cur_abbrev
;
4952 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
4953 unsigned int abbrev_form
, hash_number
;
4954 struct attr_abbrev
*cur_attrs
;
4955 unsigned int allocated_attrs
;
4957 /* Initialize dwarf2 abbrevs */
4958 obstack_init (&cu
->abbrev_obstack
);
4959 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
4961 * sizeof (struct abbrev_info
*)));
4962 memset (cu
->dwarf2_abbrevs
, 0,
4963 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
4965 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
4966 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4967 abbrev_ptr
+= bytes_read
;
4969 allocated_attrs
= ATTR_ALLOC_CHUNK
;
4970 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
4972 /* loop until we reach an abbrev number of 0 */
4973 while (abbrev_number
)
4975 cur_abbrev
= dwarf_alloc_abbrev (cu
);
4977 /* read in abbrev header */
4978 cur_abbrev
->number
= abbrev_number
;
4979 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4980 abbrev_ptr
+= bytes_read
;
4981 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
4984 if (cur_abbrev
->tag
== DW_TAG_namespace
)
4985 cu
->has_namespace_info
= 1;
4987 /* now read in declarations */
4988 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4989 abbrev_ptr
+= bytes_read
;
4990 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4991 abbrev_ptr
+= bytes_read
;
4994 if (cur_abbrev
->num_attrs
== allocated_attrs
)
4996 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
4998 = xrealloc (cur_attrs
, (allocated_attrs
4999 * sizeof (struct attr_abbrev
)));
5002 /* Record whether this compilation unit might have
5003 inter-compilation-unit references. If we don't know what form
5004 this attribute will have, then it might potentially be a
5005 DW_FORM_ref_addr, so we conservatively expect inter-CU
5008 if (abbrev_form
== DW_FORM_ref_addr
5009 || abbrev_form
== DW_FORM_indirect
)
5010 cu
->has_form_ref_addr
= 1;
5012 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
5013 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
5014 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5015 abbrev_ptr
+= bytes_read
;
5016 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5017 abbrev_ptr
+= bytes_read
;
5020 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
5021 (cur_abbrev
->num_attrs
5022 * sizeof (struct attr_abbrev
)));
5023 memcpy (cur_abbrev
->attrs
, cur_attrs
,
5024 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
5026 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
5027 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
5028 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
5030 /* Get next abbreviation.
5031 Under Irix6 the abbreviations for a compilation unit are not
5032 always properly terminated with an abbrev number of 0.
5033 Exit loop if we encounter an abbreviation which we have
5034 already read (which means we are about to read the abbreviations
5035 for the next compile unit) or if the end of the abbreviation
5036 table is reached. */
5037 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
5038 >= dwarf2_per_objfile
->abbrev_size
)
5040 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5041 abbrev_ptr
+= bytes_read
;
5042 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
5049 /* Release the memory used by the abbrev table for a compilation unit. */
5052 dwarf2_free_abbrev_table (void *ptr_to_cu
)
5054 struct dwarf2_cu
*cu
= ptr_to_cu
;
5056 obstack_free (&cu
->abbrev_obstack
, NULL
);
5057 cu
->dwarf2_abbrevs
= NULL
;
5060 /* Lookup an abbrev_info structure in the abbrev hash table. */
5062 static struct abbrev_info
*
5063 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
5065 unsigned int hash_number
;
5066 struct abbrev_info
*abbrev
;
5068 hash_number
= number
% ABBREV_HASH_SIZE
;
5069 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
5073 if (abbrev
->number
== number
)
5076 abbrev
= abbrev
->next
;
5081 /* Returns nonzero if TAG represents a type that we might generate a partial
5085 is_type_tag_for_partial (int tag
)
5090 /* Some types that would be reasonable to generate partial symbols for,
5091 that we don't at present. */
5092 case DW_TAG_array_type
:
5093 case DW_TAG_file_type
:
5094 case DW_TAG_ptr_to_member_type
:
5095 case DW_TAG_set_type
:
5096 case DW_TAG_string_type
:
5097 case DW_TAG_subroutine_type
:
5099 case DW_TAG_base_type
:
5100 case DW_TAG_class_type
:
5101 case DW_TAG_enumeration_type
:
5102 case DW_TAG_structure_type
:
5103 case DW_TAG_subrange_type
:
5104 case DW_TAG_typedef
:
5105 case DW_TAG_union_type
:
5112 /* Load all DIEs that are interesting for partial symbols into memory. */
5114 static struct partial_die_info
*
5115 load_partial_dies (bfd
*abfd
, char *info_ptr
, int building_psymtab
,
5116 struct dwarf2_cu
*cu
)
5118 struct partial_die_info
*part_die
;
5119 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
5120 struct abbrev_info
*abbrev
;
5121 unsigned int bytes_read
;
5123 int nesting_level
= 1;
5129 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5133 &cu
->comp_unit_obstack
,
5134 hashtab_obstack_allocate
,
5135 dummy_obstack_deallocate
);
5137 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5138 sizeof (struct partial_die_info
));
5142 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5144 /* A NULL abbrev means the end of a series of children. */
5147 if (--nesting_level
== 0)
5149 /* PART_DIE was probably the last thing allocated on the
5150 comp_unit_obstack, so we could call obstack_free
5151 here. We don't do that because the waste is small,
5152 and will be cleaned up when we're done with this
5153 compilation unit. This way, we're also more robust
5154 against other users of the comp_unit_obstack. */
5157 info_ptr
+= bytes_read
;
5158 last_die
= parent_die
;
5159 parent_die
= parent_die
->die_parent
;
5163 /* Check whether this DIE is interesting enough to save. */
5164 if (!is_type_tag_for_partial (abbrev
->tag
)
5165 && abbrev
->tag
!= DW_TAG_enumerator
5166 && abbrev
->tag
!= DW_TAG_subprogram
5167 && abbrev
->tag
!= DW_TAG_variable
5168 && abbrev
->tag
!= DW_TAG_namespace
)
5170 /* Otherwise we skip to the next sibling, if any. */
5171 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5175 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5176 abfd
, info_ptr
, cu
);
5178 /* This two-pass algorithm for processing partial symbols has a
5179 high cost in cache pressure. Thus, handle some simple cases
5180 here which cover the majority of C partial symbols. DIEs
5181 which neither have specification tags in them, nor could have
5182 specification tags elsewhere pointing at them, can simply be
5183 processed and discarded.
5185 This segment is also optional; scan_partial_symbols and
5186 add_partial_symbol will handle these DIEs if we chain
5187 them in normally. When compilers which do not emit large
5188 quantities of duplicate debug information are more common,
5189 this code can probably be removed. */
5191 /* Any complete simple types at the top level (pretty much all
5192 of them, for a language without namespaces), can be processed
5194 if (parent_die
== NULL
5195 && part_die
->has_specification
== 0
5196 && part_die
->is_declaration
== 0
5197 && (part_die
->tag
== DW_TAG_typedef
5198 || part_die
->tag
== DW_TAG_base_type
5199 || part_die
->tag
== DW_TAG_subrange_type
))
5201 if (building_psymtab
&& part_die
->name
!= NULL
)
5202 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5203 VAR_DOMAIN
, LOC_TYPEDEF
,
5204 &cu
->objfile
->static_psymbols
,
5205 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5206 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5210 /* If we're at the second level, and we're an enumerator, and
5211 our parent has no specification (meaning possibly lives in a
5212 namespace elsewhere), then we can add the partial symbol now
5213 instead of queueing it. */
5214 if (part_die
->tag
== DW_TAG_enumerator
5215 && parent_die
!= NULL
5216 && parent_die
->die_parent
== NULL
5217 && parent_die
->tag
== DW_TAG_enumeration_type
5218 && parent_die
->has_specification
== 0)
5220 if (part_die
->name
== NULL
)
5221 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
5222 else if (building_psymtab
)
5223 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5224 VAR_DOMAIN
, LOC_CONST
,
5225 (cu
->language
== language_cplus
5226 || cu
->language
== language_java
)
5227 ? &cu
->objfile
->global_psymbols
5228 : &cu
->objfile
->static_psymbols
,
5229 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5231 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5235 /* We'll save this DIE so link it in. */
5236 part_die
->die_parent
= parent_die
;
5237 part_die
->die_sibling
= NULL
;
5238 part_die
->die_child
= NULL
;
5240 if (last_die
&& last_die
== parent_die
)
5241 last_die
->die_child
= part_die
;
5243 last_die
->die_sibling
= part_die
;
5245 last_die
= part_die
;
5247 if (first_die
== NULL
)
5248 first_die
= part_die
;
5250 /* Maybe add the DIE to the hash table. Not all DIEs that we
5251 find interesting need to be in the hash table, because we
5252 also have the parent/sibling/child chains; only those that we
5253 might refer to by offset later during partial symbol reading.
5255 For now this means things that might have be the target of a
5256 DW_AT_specification, DW_AT_abstract_origin, or
5257 DW_AT_extension. DW_AT_extension will refer only to
5258 namespaces; DW_AT_abstract_origin refers to functions (and
5259 many things under the function DIE, but we do not recurse
5260 into function DIEs during partial symbol reading) and
5261 possibly variables as well; DW_AT_specification refers to
5262 declarations. Declarations ought to have the DW_AT_declaration
5263 flag. It happens that GCC forgets to put it in sometimes, but
5264 only for functions, not for types.
5266 Adding more things than necessary to the hash table is harmless
5267 except for the performance cost. Adding too few will result in
5268 internal errors in find_partial_die. */
5270 if (abbrev
->tag
== DW_TAG_subprogram
5271 || abbrev
->tag
== DW_TAG_variable
5272 || abbrev
->tag
== DW_TAG_namespace
5273 || part_die
->is_declaration
)
5277 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
5278 part_die
->offset
, INSERT
);
5282 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5283 sizeof (struct partial_die_info
));
5285 /* For some DIEs we want to follow their children (if any). For C
5286 we have no reason to follow the children of structures; for other
5287 languages we have to, both so that we can get at method physnames
5288 to infer fully qualified class names, and for DW_AT_specification. */
5289 if (last_die
->has_children
5290 && (last_die
->tag
== DW_TAG_namespace
5291 || last_die
->tag
== DW_TAG_enumeration_type
5292 || (cu
->language
!= language_c
5293 && (last_die
->tag
== DW_TAG_class_type
5294 || last_die
->tag
== DW_TAG_structure_type
5295 || last_die
->tag
== DW_TAG_union_type
))))
5298 parent_die
= last_die
;
5302 /* Otherwise we skip to the next sibling, if any. */
5303 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
5305 /* Back to the top, do it again. */
5309 /* Read a minimal amount of information into the minimal die structure. */
5312 read_partial_die (struct partial_die_info
*part_die
,
5313 struct abbrev_info
*abbrev
,
5314 unsigned int abbrev_len
, bfd
*abfd
,
5315 char *info_ptr
, struct dwarf2_cu
*cu
)
5317 unsigned int bytes_read
, i
;
5318 struct attribute attr
;
5319 int has_low_pc_attr
= 0;
5320 int has_high_pc_attr
= 0;
5322 memset (part_die
, 0, sizeof (struct partial_die_info
));
5324 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5326 info_ptr
+= abbrev_len
;
5331 part_die
->tag
= abbrev
->tag
;
5332 part_die
->has_children
= abbrev
->has_children
;
5334 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5336 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
5338 /* Store the data if it is of an attribute we want to keep in a
5339 partial symbol table. */
5344 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
5345 if (part_die
->name
== NULL
)
5346 part_die
->name
= DW_STRING (&attr
);
5348 case DW_AT_comp_dir
:
5349 if (part_die
->dirname
== NULL
)
5350 part_die
->dirname
= DW_STRING (&attr
);
5352 case DW_AT_MIPS_linkage_name
:
5353 part_die
->name
= DW_STRING (&attr
);
5356 has_low_pc_attr
= 1;
5357 part_die
->lowpc
= DW_ADDR (&attr
);
5360 has_high_pc_attr
= 1;
5361 part_die
->highpc
= DW_ADDR (&attr
);
5363 case DW_AT_location
:
5364 /* Support the .debug_loc offsets */
5365 if (attr_form_is_block (&attr
))
5367 part_die
->locdesc
= DW_BLOCK (&attr
);
5369 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
5371 dwarf2_complex_location_expr_complaint ();
5375 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5376 "partial symbol information");
5379 case DW_AT_language
:
5380 part_die
->language
= DW_UNSND (&attr
);
5382 case DW_AT_external
:
5383 part_die
->is_external
= DW_UNSND (&attr
);
5385 case DW_AT_declaration
:
5386 part_die
->is_declaration
= DW_UNSND (&attr
);
5389 part_die
->has_type
= 1;
5391 case DW_AT_abstract_origin
:
5392 case DW_AT_specification
:
5393 case DW_AT_extension
:
5394 part_die
->has_specification
= 1;
5395 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
, cu
);
5398 /* Ignore absolute siblings, they might point outside of
5399 the current compile unit. */
5400 if (attr
.form
== DW_FORM_ref_addr
)
5401 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
5403 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
5404 + dwarf2_get_ref_die_offset (&attr
, cu
);
5406 case DW_AT_stmt_list
:
5407 part_die
->has_stmt_list
= 1;
5408 part_die
->line_offset
= DW_UNSND (&attr
);
5415 /* When using the GNU linker, .gnu.linkonce. sections are used to
5416 eliminate duplicate copies of functions and vtables and such.
5417 The linker will arbitrarily choose one and discard the others.
5418 The AT_*_pc values for such functions refer to local labels in
5419 these sections. If the section from that file was discarded, the
5420 labels are not in the output, so the relocs get a value of 0.
5421 If this is a discarded function, mark the pc bounds as invalid,
5422 so that GDB will ignore it. */
5423 if (has_low_pc_attr
&& has_high_pc_attr
5424 && part_die
->lowpc
< part_die
->highpc
5425 && (part_die
->lowpc
!= 0
5426 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
5427 part_die
->has_pc_info
= 1;
5431 /* Find a cached partial DIE at OFFSET in CU. */
5433 static struct partial_die_info
*
5434 find_partial_die_in_comp_unit (unsigned long offset
, struct dwarf2_cu
*cu
)
5436 struct partial_die_info
*lookup_die
= NULL
;
5437 struct partial_die_info part_die
;
5439 part_die
.offset
= offset
;
5440 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
5442 if (lookup_die
== NULL
)
5443 internal_error (__FILE__
, __LINE__
,
5444 "could not find partial DIE in cache\n");
5449 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
5451 static struct partial_die_info
*
5452 find_partial_die (unsigned long offset
, struct dwarf2_cu
*cu
)
5454 struct dwarf2_per_cu_data
*per_cu
;
5456 if (offset
>= cu
->header
.offset
5457 && offset
< cu
->header
.offset
+ cu
->header
.length
)
5458 return find_partial_die_in_comp_unit (offset
, cu
);
5460 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
5462 if (per_cu
->cu
== NULL
)
5464 load_comp_unit (per_cu
, cu
->objfile
);
5465 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5466 dwarf2_per_objfile
->read_in_chain
= per_cu
;
5469 per_cu
->cu
->last_used
= 0;
5470 return find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
5473 /* Adjust PART_DIE before generating a symbol for it. This function
5474 may set the is_external flag or change the DIE's name. */
5477 fixup_partial_die (struct partial_die_info
*part_die
,
5478 struct dwarf2_cu
*cu
)
5480 /* If we found a reference attribute and the DIE has no name, try
5481 to find a name in the referred to DIE. */
5483 if (part_die
->name
== NULL
&& part_die
->has_specification
)
5485 struct partial_die_info
*spec_die
;
5487 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
5489 fixup_partial_die (spec_die
, cu
);
5493 part_die
->name
= spec_die
->name
;
5495 /* Copy DW_AT_external attribute if it is set. */
5496 if (spec_die
->is_external
)
5497 part_die
->is_external
= spec_die
->is_external
;
5501 /* Set default names for some unnamed DIEs. */
5502 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
5503 || part_die
->tag
== DW_TAG_class_type
))
5504 part_die
->name
= "(anonymous class)";
5506 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
5507 part_die
->name
= "(anonymous namespace)";
5509 if (part_die
->tag
== DW_TAG_structure_type
5510 || part_die
->tag
== DW_TAG_class_type
5511 || part_die
->tag
== DW_TAG_union_type
)
5512 guess_structure_name (part_die
, cu
);
5515 /* Read the die from the .debug_info section buffer. Set DIEP to
5516 point to a newly allocated die with its information, except for its
5517 child, sibling, and parent fields. Set HAS_CHILDREN to tell
5518 whether the die has children or not. */
5521 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
5522 struct dwarf2_cu
*cu
, int *has_children
)
5524 unsigned int abbrev_number
, bytes_read
, i
, offset
;
5525 struct abbrev_info
*abbrev
;
5526 struct die_info
*die
;
5528 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5529 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5530 info_ptr
+= bytes_read
;
5533 die
= dwarf_alloc_die ();
5535 die
->abbrev
= abbrev_number
;
5542 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
5545 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
5547 bfd_get_filename (abfd
));
5549 die
= dwarf_alloc_die ();
5550 die
->offset
= offset
;
5551 die
->tag
= abbrev
->tag
;
5552 die
->abbrev
= abbrev_number
;
5555 die
->num_attrs
= abbrev
->num_attrs
;
5556 die
->attrs
= (struct attribute
*)
5557 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
5559 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5561 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
5562 abfd
, info_ptr
, cu
);
5564 /* If this attribute is an absolute reference to a different
5565 compilation unit, make sure that compilation unit is loaded
5567 if (die
->attrs
[i
].form
== DW_FORM_ref_addr
5568 && (DW_ADDR (&die
->attrs
[i
]) < cu
->header
.offset
5569 || (DW_ADDR (&die
->attrs
[i
])
5570 >= cu
->header
.offset
+ cu
->header
.length
)))
5572 struct dwarf2_per_cu_data
*per_cu
;
5573 per_cu
= dwarf2_find_containing_comp_unit (DW_ADDR (&die
->attrs
[i
]),
5576 /* Mark the dependence relation so that we don't flush PER_CU
5578 dwarf2_add_dependence (cu
, per_cu
);
5580 /* If it's already on the queue, we have nothing to do. */
5584 /* If the compilation unit is already loaded, just mark it as
5586 if (per_cu
->cu
!= NULL
)
5588 per_cu
->cu
->last_used
= 0;
5592 /* Add it to the queue. */
5593 queue_comp_unit (per_cu
);
5598 *has_children
= abbrev
->has_children
;
5602 /* Read an attribute value described by an attribute form. */
5605 read_attribute_value (struct attribute
*attr
, unsigned form
,
5606 bfd
*abfd
, char *info_ptr
,
5607 struct dwarf2_cu
*cu
)
5609 struct comp_unit_head
*cu_header
= &cu
->header
;
5610 unsigned int bytes_read
;
5611 struct dwarf_block
*blk
;
5617 case DW_FORM_ref_addr
:
5618 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
5619 info_ptr
+= bytes_read
;
5621 case DW_FORM_block2
:
5622 blk
= dwarf_alloc_block (cu
);
5623 blk
->size
= read_2_bytes (abfd
, info_ptr
);
5625 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5626 info_ptr
+= blk
->size
;
5627 DW_BLOCK (attr
) = blk
;
5629 case DW_FORM_block4
:
5630 blk
= dwarf_alloc_block (cu
);
5631 blk
->size
= read_4_bytes (abfd
, info_ptr
);
5633 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5634 info_ptr
+= blk
->size
;
5635 DW_BLOCK (attr
) = blk
;
5638 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
5642 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
5646 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
5649 case DW_FORM_string
:
5650 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
5651 info_ptr
+= bytes_read
;
5654 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
5656 info_ptr
+= bytes_read
;
5659 blk
= dwarf_alloc_block (cu
);
5660 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5661 info_ptr
+= bytes_read
;
5662 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5663 info_ptr
+= blk
->size
;
5664 DW_BLOCK (attr
) = blk
;
5666 case DW_FORM_block1
:
5667 blk
= dwarf_alloc_block (cu
);
5668 blk
->size
= read_1_byte (abfd
, info_ptr
);
5670 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5671 info_ptr
+= blk
->size
;
5672 DW_BLOCK (attr
) = blk
;
5675 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5679 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5683 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
5684 info_ptr
+= bytes_read
;
5687 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5688 info_ptr
+= bytes_read
;
5691 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
5695 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
5699 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
5703 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
5706 case DW_FORM_ref_udata
:
5707 DW_ADDR (attr
) = (cu
->header
.offset
5708 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
5709 info_ptr
+= bytes_read
;
5711 case DW_FORM_indirect
:
5712 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5713 info_ptr
+= bytes_read
;
5714 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
5717 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
5718 dwarf_form_name (form
),
5719 bfd_get_filename (abfd
));
5724 /* Read an attribute described by an abbreviated attribute. */
5727 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
5728 bfd
*abfd
, char *info_ptr
, struct dwarf2_cu
*cu
)
5730 attr
->name
= abbrev
->name
;
5731 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
5734 /* read dwarf information from a buffer */
5737 read_1_byte (bfd
*abfd
, char *buf
)
5739 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5743 read_1_signed_byte (bfd
*abfd
, char *buf
)
5745 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
5749 read_2_bytes (bfd
*abfd
, char *buf
)
5751 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
5755 read_2_signed_bytes (bfd
*abfd
, char *buf
)
5757 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
5761 read_4_bytes (bfd
*abfd
, char *buf
)
5763 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5767 read_4_signed_bytes (bfd
*abfd
, char *buf
)
5769 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
5772 static unsigned long
5773 read_8_bytes (bfd
*abfd
, char *buf
)
5775 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5779 read_address (bfd
*abfd
, char *buf
, struct dwarf2_cu
*cu
, int *bytes_read
)
5781 struct comp_unit_head
*cu_header
= &cu
->header
;
5782 CORE_ADDR retval
= 0;
5784 if (cu_header
->signed_addr_p
)
5786 switch (cu_header
->addr_size
)
5789 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
5792 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
5795 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
5798 internal_error (__FILE__
, __LINE__
,
5799 "read_address: bad switch, signed [in module %s]",
5800 bfd_get_filename (abfd
));
5805 switch (cu_header
->addr_size
)
5808 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
5811 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5814 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5817 internal_error (__FILE__
, __LINE__
,
5818 "read_address: bad switch, unsigned [in module %s]",
5819 bfd_get_filename (abfd
));
5823 *bytes_read
= cu_header
->addr_size
;
5827 /* Read the initial length from a section. The (draft) DWARF 3
5828 specification allows the initial length to take up either 4 bytes
5829 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
5830 bytes describe the length and all offsets will be 8 bytes in length
5833 An older, non-standard 64-bit format is also handled by this
5834 function. The older format in question stores the initial length
5835 as an 8-byte quantity without an escape value. Lengths greater
5836 than 2^32 aren't very common which means that the initial 4 bytes
5837 is almost always zero. Since a length value of zero doesn't make
5838 sense for the 32-bit format, this initial zero can be considered to
5839 be an escape value which indicates the presence of the older 64-bit
5840 format. As written, the code can't detect (old format) lengths
5841 greater than 4GB. If it becomes necessary to handle lengths somewhat
5842 larger than 4GB, we could allow other small values (such as the
5843 non-sensical values of 1, 2, and 3) to also be used as escape values
5844 indicating the presence of the old format.
5846 The value returned via bytes_read should be used to increment
5847 the relevant pointer after calling read_initial_length().
5849 As a side effect, this function sets the fields initial_length_size
5850 and offset_size in cu_header to the values appropriate for the
5851 length field. (The format of the initial length field determines
5852 the width of file offsets to be fetched later with fetch_offset().)
5854 [ Note: read_initial_length() and read_offset() are based on the
5855 document entitled "DWARF Debugging Information Format", revision
5856 3, draft 8, dated November 19, 2001. This document was obtained
5859 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
5861 This document is only a draft and is subject to change. (So beware.)
5863 Details regarding the older, non-standard 64-bit format were
5864 determined empirically by examining 64-bit ELF files produced
5865 by the SGI toolchain on an IRIX 6.5 machine.
5867 - Kevin, July 16, 2002
5871 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
5876 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5878 if (retval
== 0xffffffff)
5880 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
5882 if (cu_header
!= NULL
)
5884 cu_header
->initial_length_size
= 12;
5885 cu_header
->offset_size
= 8;
5888 else if (retval
== 0)
5890 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
5892 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5894 if (cu_header
!= NULL
)
5896 cu_header
->initial_length_size
= 8;
5897 cu_header
->offset_size
= 8;
5903 if (cu_header
!= NULL
)
5905 cu_header
->initial_length_size
= 4;
5906 cu_header
->offset_size
= 4;
5913 /* Read an offset from the data stream. The size of the offset is
5914 given by cu_header->offset_size. */
5917 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
5922 switch (cu_header
->offset_size
)
5925 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5929 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5933 internal_error (__FILE__
, __LINE__
,
5934 "read_offset: bad switch [in module %s]",
5935 bfd_get_filename (abfd
));
5942 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
5944 /* If the size of a host char is 8 bits, we can return a pointer
5945 to the buffer, otherwise we have to copy the data to a buffer
5946 allocated on the temporary obstack. */
5947 gdb_assert (HOST_CHAR_BIT
== 8);
5952 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5954 /* If the size of a host char is 8 bits, we can return a pointer
5955 to the string, otherwise we have to copy the string to a buffer
5956 allocated on the temporary obstack. */
5957 gdb_assert (HOST_CHAR_BIT
== 8);
5960 *bytes_read_ptr
= 1;
5963 *bytes_read_ptr
= strlen (buf
) + 1;
5968 read_indirect_string (bfd
*abfd
, char *buf
,
5969 const struct comp_unit_head
*cu_header
,
5970 unsigned int *bytes_read_ptr
)
5972 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
5973 (int *) bytes_read_ptr
);
5975 if (dwarf2_per_objfile
->str_buffer
== NULL
)
5977 error ("DW_FORM_strp used without .debug_str section [in module %s]",
5978 bfd_get_filename (abfd
));
5981 if (str_offset
>= dwarf2_per_objfile
->str_size
)
5983 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
5984 bfd_get_filename (abfd
));
5987 gdb_assert (HOST_CHAR_BIT
== 8);
5988 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
5990 return dwarf2_per_objfile
->str_buffer
+ str_offset
;
5993 static unsigned long
5994 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5996 unsigned long result
;
5997 unsigned int num_read
;
6007 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
6010 result
|= ((unsigned long)(byte
& 127) << shift
);
6011 if ((byte
& 128) == 0)
6017 *bytes_read_ptr
= num_read
;
6022 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
6025 int i
, shift
, size
, num_read
;
6035 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
6038 result
|= ((long)(byte
& 127) << shift
);
6040 if ((byte
& 128) == 0)
6045 if ((shift
< size
) && (byte
& 0x40))
6047 result
|= -(1 << shift
);
6049 *bytes_read_ptr
= num_read
;
6053 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6056 skip_leb128 (bfd
*abfd
, char *buf
)
6062 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
6064 if ((byte
& 128) == 0)
6070 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
6076 cu
->language
= language_c
;
6078 case DW_LANG_C_plus_plus
:
6079 cu
->language
= language_cplus
;
6081 case DW_LANG_Fortran77
:
6082 case DW_LANG_Fortran90
:
6083 case DW_LANG_Fortran95
:
6084 cu
->language
= language_fortran
;
6086 case DW_LANG_Mips_Assembler
:
6087 cu
->language
= language_asm
;
6090 cu
->language
= language_java
;
6094 cu
->language
= language_ada
;
6096 case DW_LANG_Cobol74
:
6097 case DW_LANG_Cobol85
:
6098 case DW_LANG_Pascal83
:
6099 case DW_LANG_Modula2
:
6101 cu
->language
= language_minimal
;
6104 cu
->language_defn
= language_def (cu
->language
);
6107 /* Return the named attribute or NULL if not there. */
6109 static struct attribute
*
6110 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
6113 struct attribute
*spec
= NULL
;
6115 for (i
= 0; i
< die
->num_attrs
; ++i
)
6117 if (die
->attrs
[i
].name
== name
)
6118 return &die
->attrs
[i
];
6119 if (die
->attrs
[i
].name
== DW_AT_specification
6120 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
6121 spec
= &die
->attrs
[i
];
6125 return dwarf2_attr (follow_die_ref (die
, spec
, cu
), name
, cu
);
6130 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6131 and holds a non-zero value. This function should only be used for
6132 DW_FORM_flag attributes. */
6135 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
6137 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
6139 return (attr
&& DW_UNSND (attr
));
6143 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
6145 /* A DIE is a declaration if it has a DW_AT_declaration attribute
6146 which value is non-zero. However, we have to be careful with
6147 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
6148 (via dwarf2_flag_true_p) follows this attribute. So we may
6149 end up accidently finding a declaration attribute that belongs
6150 to a different DIE referenced by the specification attribute,
6151 even though the given DIE does not have a declaration attribute. */
6152 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
6153 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
6156 /* Return the die giving the specification for DIE, if there is
6159 static struct die_info
*
6160 die_specification (struct die_info
*die
, struct dwarf2_cu
*cu
)
6162 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
, cu
);
6164 if (spec_attr
== NULL
)
6167 return follow_die_ref (die
, spec_attr
, cu
);
6170 /* Free the line_header structure *LH, and any arrays and strings it
6173 free_line_header (struct line_header
*lh
)
6175 if (lh
->standard_opcode_lengths
)
6176 xfree (lh
->standard_opcode_lengths
);
6178 /* Remember that all the lh->file_names[i].name pointers are
6179 pointers into debug_line_buffer, and don't need to be freed. */
6181 xfree (lh
->file_names
);
6183 /* Similarly for the include directory names. */
6184 if (lh
->include_dirs
)
6185 xfree (lh
->include_dirs
);
6191 /* Add an entry to LH's include directory table. */
6193 add_include_dir (struct line_header
*lh
, char *include_dir
)
6195 /* Grow the array if necessary. */
6196 if (lh
->include_dirs_size
== 0)
6198 lh
->include_dirs_size
= 1; /* for testing */
6199 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
6200 * sizeof (*lh
->include_dirs
));
6202 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
6204 lh
->include_dirs_size
*= 2;
6205 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
6206 (lh
->include_dirs_size
6207 * sizeof (*lh
->include_dirs
)));
6210 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
6214 /* Add an entry to LH's file name table. */
6216 add_file_name (struct line_header
*lh
,
6218 unsigned int dir_index
,
6219 unsigned int mod_time
,
6220 unsigned int length
)
6222 struct file_entry
*fe
;
6224 /* Grow the array if necessary. */
6225 if (lh
->file_names_size
== 0)
6227 lh
->file_names_size
= 1; /* for testing */
6228 lh
->file_names
= xmalloc (lh
->file_names_size
6229 * sizeof (*lh
->file_names
));
6231 else if (lh
->num_file_names
>= lh
->file_names_size
)
6233 lh
->file_names_size
*= 2;
6234 lh
->file_names
= xrealloc (lh
->file_names
,
6235 (lh
->file_names_size
6236 * sizeof (*lh
->file_names
)));
6239 fe
= &lh
->file_names
[lh
->num_file_names
++];
6241 fe
->dir_index
= dir_index
;
6242 fe
->mod_time
= mod_time
;
6243 fe
->length
= length
;
6248 /* Read the statement program header starting at OFFSET in
6249 .debug_line, according to the endianness of ABFD. Return a pointer
6250 to a struct line_header, allocated using xmalloc.
6252 NOTE: the strings in the include directory and file name tables of
6253 the returned object point into debug_line_buffer, and must not be
6255 static struct line_header
*
6256 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
6257 struct dwarf2_cu
*cu
)
6259 struct cleanup
*back_to
;
6260 struct line_header
*lh
;
6264 char *cur_dir
, *cur_file
;
6266 if (dwarf2_per_objfile
->line_buffer
== NULL
)
6268 complaint (&symfile_complaints
, "missing .debug_line section");
6272 /* Make sure that at least there's room for the total_length field.
6273 That could be 12 bytes long, but we're just going to fudge that. */
6274 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
6276 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6280 lh
= xmalloc (sizeof (*lh
));
6281 memset (lh
, 0, sizeof (*lh
));
6282 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
6285 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
6287 /* Read in the header. */
6288 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
6289 line_ptr
+= bytes_read
;
6290 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
6291 + dwarf2_per_objfile
->line_size
))
6293 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6296 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
6297 lh
->version
= read_2_bytes (abfd
, line_ptr
);
6299 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6300 line_ptr
+= bytes_read
;
6301 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
6303 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
6305 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
6307 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
6309 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
6311 lh
->standard_opcode_lengths
6312 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
6314 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
6315 for (i
= 1; i
< lh
->opcode_base
; ++i
)
6317 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
6321 /* Read directory table. */
6322 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6324 line_ptr
+= bytes_read
;
6325 add_include_dir (lh
, cur_dir
);
6327 line_ptr
+= bytes_read
;
6329 /* Read file name table. */
6330 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6332 unsigned int dir_index
, mod_time
, length
;
6334 line_ptr
+= bytes_read
;
6335 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6336 line_ptr
+= bytes_read
;
6337 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6338 line_ptr
+= bytes_read
;
6339 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6340 line_ptr
+= bytes_read
;
6342 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6344 line_ptr
+= bytes_read
;
6345 lh
->statement_program_start
= line_ptr
;
6347 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
6348 + dwarf2_per_objfile
->line_size
))
6349 complaint (&symfile_complaints
,
6350 "line number info header doesn't fit in `.debug_line' section");
6352 discard_cleanups (back_to
);
6356 /* This function exists to work around a bug in certain compilers
6357 (particularly GCC 2.95), in which the first line number marker of a
6358 function does not show up until after the prologue, right before
6359 the second line number marker. This function shifts ADDRESS down
6360 to the beginning of the function if necessary, and is called on
6361 addresses passed to record_line. */
6364 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
6366 struct function_range
*fn
;
6368 /* Find the function_range containing address. */
6373 cu
->cached_fn
= cu
->first_fn
;
6377 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6383 while (fn
&& fn
!= cu
->cached_fn
)
6384 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6394 if (address
!= fn
->lowpc
)
6395 complaint (&symfile_complaints
,
6396 "misplaced first line number at 0x%lx for '%s'",
6397 (unsigned long) address
, fn
->name
);
6402 /* Decode the Line Number Program (LNP) for the given line_header
6403 structure and CU. The actual information extracted and the type
6404 of structures created from the LNP depends on the value of PST.
6406 1. If PST is NULL, then this procedure uses the data from the program
6407 to create all necessary symbol tables, and their linetables.
6408 The compilation directory of the file is passed in COMP_DIR,
6409 and must not be NULL.
6411 2. If PST is not NULL, this procedure reads the program to determine
6412 the list of files included by the unit represented by PST, and
6413 builds all the associated partial symbol tables. In this case,
6414 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
6415 is not used to compute the full name of the symtab, and therefore
6416 omitting it when building the partial symtab does not introduce
6417 the potential for inconsistency - a partial symtab and its associated
6418 symbtab having a different fullname -). */
6421 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
6422 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
6426 unsigned int bytes_read
;
6427 unsigned char op_code
, extended_op
, adj_opcode
;
6429 struct objfile
*objfile
= cu
->objfile
;
6430 const int decode_for_pst_p
= (pst
!= NULL
);
6432 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6434 line_ptr
= lh
->statement_program_start
;
6435 line_end
= lh
->statement_program_end
;
6437 /* Read the statement sequences until there's nothing left. */
6438 while (line_ptr
< line_end
)
6440 /* state machine registers */
6441 CORE_ADDR address
= 0;
6442 unsigned int file
= 1;
6443 unsigned int line
= 1;
6444 unsigned int column
= 0;
6445 int is_stmt
= lh
->default_is_stmt
;
6446 int basic_block
= 0;
6447 int end_sequence
= 0;
6449 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
6451 /* Start a subfile for the current file of the state machine. */
6452 /* lh->include_dirs and lh->file_names are 0-based, but the
6453 directory and file name numbers in the statement program
6455 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
6459 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6462 dwarf2_start_subfile (fe
->name
, dir
);
6465 /* Decode the table. */
6466 while (!end_sequence
)
6468 op_code
= read_1_byte (abfd
, line_ptr
);
6471 if (op_code
>= lh
->opcode_base
)
6473 /* Special operand. */
6474 adj_opcode
= op_code
- lh
->opcode_base
;
6475 address
+= (adj_opcode
/ lh
->line_range
)
6476 * lh
->minimum_instruction_length
;
6477 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
6478 lh
->file_names
[file
- 1].included_p
= 1;
6479 if (!decode_for_pst_p
)
6481 /* Append row to matrix using current values. */
6482 record_line (current_subfile
, line
,
6483 check_cu_functions (address
, cu
));
6487 else switch (op_code
)
6489 case DW_LNS_extended_op
:
6490 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6491 line_ptr
+= bytes_read
;
6492 extended_op
= read_1_byte (abfd
, line_ptr
);
6494 switch (extended_op
)
6496 case DW_LNE_end_sequence
:
6498 lh
->file_names
[file
- 1].included_p
= 1;
6499 if (!decode_for_pst_p
)
6500 record_line (current_subfile
, 0, address
);
6502 case DW_LNE_set_address
:
6503 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
6504 line_ptr
+= bytes_read
;
6505 address
+= baseaddr
;
6507 case DW_LNE_define_file
:
6510 unsigned int dir_index
, mod_time
, length
;
6512 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
6513 line_ptr
+= bytes_read
;
6515 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6516 line_ptr
+= bytes_read
;
6518 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6519 line_ptr
+= bytes_read
;
6521 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6522 line_ptr
+= bytes_read
;
6523 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6527 complaint (&symfile_complaints
,
6528 "mangled .debug_line section");
6533 lh
->file_names
[file
- 1].included_p
= 1;
6534 if (!decode_for_pst_p
)
6535 record_line (current_subfile
, line
,
6536 check_cu_functions (address
, cu
));
6539 case DW_LNS_advance_pc
:
6540 address
+= lh
->minimum_instruction_length
6541 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6542 line_ptr
+= bytes_read
;
6544 case DW_LNS_advance_line
:
6545 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
6546 line_ptr
+= bytes_read
;
6548 case DW_LNS_set_file
:
6550 /* The arrays lh->include_dirs and lh->file_names are
6551 0-based, but the directory and file name numbers in
6552 the statement program are 1-based. */
6553 struct file_entry
*fe
;
6556 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6557 line_ptr
+= bytes_read
;
6558 fe
= &lh
->file_names
[file
- 1];
6560 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6563 if (!decode_for_pst_p
)
6564 dwarf2_start_subfile (fe
->name
, dir
);
6567 case DW_LNS_set_column
:
6568 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6569 line_ptr
+= bytes_read
;
6571 case DW_LNS_negate_stmt
:
6572 is_stmt
= (!is_stmt
);
6574 case DW_LNS_set_basic_block
:
6577 /* Add to the address register of the state machine the
6578 address increment value corresponding to special opcode
6579 255. I.e., this value is scaled by the minimum
6580 instruction length since special opcode 255 would have
6581 scaled the the increment. */
6582 case DW_LNS_const_add_pc
:
6583 address
+= (lh
->minimum_instruction_length
6584 * ((255 - lh
->opcode_base
) / lh
->line_range
));
6586 case DW_LNS_fixed_advance_pc
:
6587 address
+= read_2_bytes (abfd
, line_ptr
);
6592 /* Unknown standard opcode, ignore it. */
6595 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
6597 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6598 line_ptr
+= bytes_read
;
6605 if (decode_for_pst_p
)
6609 /* Now that we're done scanning the Line Header Program, we can
6610 create the psymtab of each included file. */
6611 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
6612 if (lh
->file_names
[file_index
].included_p
== 1)
6614 char *include_name
= lh
->file_names
[file_index
].name
;
6616 if (strcmp (include_name
, pst
->filename
) != 0)
6617 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
6622 /* Start a subfile for DWARF. FILENAME is the name of the file and
6623 DIRNAME the name of the source directory which contains FILENAME
6624 or NULL if not known.
6625 This routine tries to keep line numbers from identical absolute and
6626 relative file names in a common subfile.
6628 Using the `list' example from the GDB testsuite, which resides in
6629 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
6630 of /srcdir/list0.c yields the following debugging information for list0.c:
6632 DW_AT_name: /srcdir/list0.c
6633 DW_AT_comp_dir: /compdir
6634 files.files[0].name: list0.h
6635 files.files[0].dir: /srcdir
6636 files.files[1].name: list0.c
6637 files.files[1].dir: /srcdir
6639 The line number information for list0.c has to end up in a single
6640 subfile, so that `break /srcdir/list0.c:1' works as expected. */
6643 dwarf2_start_subfile (char *filename
, char *dirname
)
6645 /* If the filename isn't absolute, try to match an existing subfile
6646 with the full pathname. */
6648 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
6650 struct subfile
*subfile
;
6651 char *fullname
= concat (dirname
, "/", filename
, NULL
);
6653 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
6655 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
6657 current_subfile
= subfile
;
6664 start_subfile (filename
, dirname
);
6668 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
6669 struct dwarf2_cu
*cu
)
6671 struct objfile
*objfile
= cu
->objfile
;
6672 struct comp_unit_head
*cu_header
= &cu
->header
;
6674 /* NOTE drow/2003-01-30: There used to be a comment and some special
6675 code here to turn a symbol with DW_AT_external and a
6676 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
6677 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
6678 with some versions of binutils) where shared libraries could have
6679 relocations against symbols in their debug information - the
6680 minimal symbol would have the right address, but the debug info
6681 would not. It's no longer necessary, because we will explicitly
6682 apply relocations when we read in the debug information now. */
6684 /* A DW_AT_location attribute with no contents indicates that a
6685 variable has been optimized away. */
6686 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
6688 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
6692 /* Handle one degenerate form of location expression specially, to
6693 preserve GDB's previous behavior when section offsets are
6694 specified. If this is just a DW_OP_addr then mark this symbol
6697 if (attr_form_is_block (attr
)
6698 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
6699 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
6703 SYMBOL_VALUE_ADDRESS (sym
) =
6704 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
6705 fixup_symbol_section (sym
, objfile
);
6706 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
6707 SYMBOL_SECTION (sym
));
6708 SYMBOL_CLASS (sym
) = LOC_STATIC
;
6712 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
6713 expression evaluator, and use LOC_COMPUTED only when necessary
6714 (i.e. when the value of a register or memory location is
6715 referenced, or a thread-local block, etc.). Then again, it might
6716 not be worthwhile. I'm assuming that it isn't unless performance
6717 or memory numbers show me otherwise. */
6719 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
6720 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
6723 /* Given a pointer to a DWARF information entry, figure out if we need
6724 to make a symbol table entry for it, and if so, create a new entry
6725 and return a pointer to it.
6726 If TYPE is NULL, determine symbol type from the die, otherwise
6727 used the passed type. */
6729 static struct symbol
*
6730 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
6732 struct objfile
*objfile
= cu
->objfile
;
6733 struct symbol
*sym
= NULL
;
6735 struct attribute
*attr
= NULL
;
6736 struct attribute
*attr2
= NULL
;
6739 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6741 if (die
->tag
!= DW_TAG_namespace
)
6742 name
= dwarf2_linkage_name (die
, cu
);
6744 name
= TYPE_NAME (type
);
6748 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
6749 sizeof (struct symbol
));
6750 OBJSTAT (objfile
, n_syms
++);
6751 memset (sym
, 0, sizeof (struct symbol
));
6753 /* Cache this symbol's name and the name's demangled form (if any). */
6754 SYMBOL_LANGUAGE (sym
) = cu
->language
;
6755 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
6757 /* Default assumptions.
6758 Use the passed type or decode it from the die. */
6759 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6760 SYMBOL_CLASS (sym
) = LOC_STATIC
;
6762 SYMBOL_TYPE (sym
) = type
;
6764 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
6765 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
6768 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
6773 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6776 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
6778 SYMBOL_CLASS (sym
) = LOC_LABEL
;
6780 case DW_TAG_subprogram
:
6781 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
6783 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
6784 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6785 if (attr2
&& (DW_UNSND (attr2
) != 0))
6787 add_symbol_to_list (sym
, &global_symbols
);
6791 add_symbol_to_list (sym
, cu
->list_in_scope
);
6794 case DW_TAG_variable
:
6795 /* Compilation with minimal debug info may result in variables
6796 with missing type entries. Change the misleading `void' type
6797 to something sensible. */
6798 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
6799 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
6800 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
6801 "<variable, no debug info>",
6803 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6806 dwarf2_const_value (attr
, sym
, cu
);
6807 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6808 if (attr2
&& (DW_UNSND (attr2
) != 0))
6809 add_symbol_to_list (sym
, &global_symbols
);
6811 add_symbol_to_list (sym
, cu
->list_in_scope
);
6814 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
6817 var_decode_location (attr
, sym
, cu
);
6818 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6819 if (attr2
&& (DW_UNSND (attr2
) != 0))
6820 add_symbol_to_list (sym
, &global_symbols
);
6822 add_symbol_to_list (sym
, cu
->list_in_scope
);
6826 /* We do not know the address of this symbol.
6827 If it is an external symbol and we have type information
6828 for it, enter the symbol as a LOC_UNRESOLVED symbol.
6829 The address of the variable will then be determined from
6830 the minimal symbol table whenever the variable is
6832 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6833 if (attr2
&& (DW_UNSND (attr2
) != 0)
6834 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
6836 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
6837 add_symbol_to_list (sym
, &global_symbols
);
6841 case DW_TAG_formal_parameter
:
6842 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
6845 var_decode_location (attr
, sym
, cu
);
6846 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
6847 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
6848 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
6850 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6853 dwarf2_const_value (attr
, sym
, cu
);
6855 add_symbol_to_list (sym
, cu
->list_in_scope
);
6857 case DW_TAG_unspecified_parameters
:
6858 /* From varargs functions; gdb doesn't seem to have any
6859 interest in this information, so just ignore it for now.
6862 case DW_TAG_class_type
:
6863 case DW_TAG_structure_type
:
6864 case DW_TAG_union_type
:
6865 case DW_TAG_enumeration_type
:
6866 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6867 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
6869 /* Make sure that the symbol includes appropriate enclosing
6870 classes/namespaces in its name. These are calculated in
6871 read_structure_type, and the correct name is saved in
6874 if (cu
->language
== language_cplus
6875 || cu
->language
== language_java
)
6877 struct type
*type
= SYMBOL_TYPE (sym
);
6879 if (TYPE_TAG_NAME (type
) != NULL
)
6881 /* FIXME: carlton/2003-11-10: Should this use
6882 SYMBOL_SET_NAMES instead? (The same problem also
6883 arises further down in this function.) */
6884 /* The type's name is already allocated along with
6885 this objfile, so we don't need to duplicate it
6887 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
6892 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
6893 really ever be static objects: otherwise, if you try
6894 to, say, break of a class's method and you're in a file
6895 which doesn't mention that class, it won't work unless
6896 the check for all static symbols in lookup_symbol_aux
6897 saves you. See the OtherFileClass tests in
6898 gdb.c++/namespace.exp. */
6900 struct pending
**list_to_add
;
6902 list_to_add
= (cu
->list_in_scope
== &file_symbols
6903 && (cu
->language
== language_cplus
6904 || cu
->language
== language_java
)
6905 ? &global_symbols
: cu
->list_in_scope
);
6907 add_symbol_to_list (sym
, list_to_add
);
6909 /* The semantics of C++ state that "struct foo { ... }" also
6910 defines a typedef for "foo". A Java class declaration also
6911 defines a typedef for the class. Synthesize a typedef symbol
6912 so that "ptype foo" works as expected. */
6913 if (cu
->language
== language_cplus
6914 || cu
->language
== language_java
)
6916 struct symbol
*typedef_sym
= (struct symbol
*)
6917 obstack_alloc (&objfile
->objfile_obstack
,
6918 sizeof (struct symbol
));
6919 *typedef_sym
= *sym
;
6920 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
6921 /* The symbol's name is already allocated along with
6922 this objfile, so we don't need to duplicate it for
6924 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
6925 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NATURAL_NAME (sym
);
6926 add_symbol_to_list (typedef_sym
, list_to_add
);
6930 case DW_TAG_typedef
:
6931 if (processing_has_namespace_info
6932 && processing_current_prefix
[0] != '\0')
6934 SYMBOL_LINKAGE_NAME (sym
) = typename_concat (&objfile
->objfile_obstack
,
6935 processing_current_prefix
,
6938 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6939 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6940 add_symbol_to_list (sym
, cu
->list_in_scope
);
6942 case DW_TAG_base_type
:
6943 case DW_TAG_subrange_type
:
6944 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6945 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6946 add_symbol_to_list (sym
, cu
->list_in_scope
);
6948 case DW_TAG_enumerator
:
6949 if (processing_has_namespace_info
6950 && processing_current_prefix
[0] != '\0')
6952 SYMBOL_LINKAGE_NAME (sym
) = typename_concat (&objfile
->objfile_obstack
,
6953 processing_current_prefix
,
6956 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6959 dwarf2_const_value (attr
, sym
, cu
);
6962 /* NOTE: carlton/2003-11-10: See comment above in the
6963 DW_TAG_class_type, etc. block. */
6965 struct pending
**list_to_add
;
6967 list_to_add
= (cu
->list_in_scope
== &file_symbols
6968 && (cu
->language
== language_cplus
6969 || cu
->language
== language_java
)
6970 ? &global_symbols
: cu
->list_in_scope
);
6972 add_symbol_to_list (sym
, list_to_add
);
6975 case DW_TAG_namespace
:
6976 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6977 add_symbol_to_list (sym
, &global_symbols
);
6980 /* Not a tag we recognize. Hopefully we aren't processing
6981 trash data, but since we must specifically ignore things
6982 we don't recognize, there is nothing else we should do at
6984 complaint (&symfile_complaints
, "unsupported tag: '%s'",
6985 dwarf_tag_name (die
->tag
));
6992 /* Copy constant value from an attribute to a symbol. */
6995 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
6996 struct dwarf2_cu
*cu
)
6998 struct objfile
*objfile
= cu
->objfile
;
6999 struct comp_unit_head
*cu_header
= &cu
->header
;
7000 struct dwarf_block
*blk
;
7005 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
7006 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
7007 cu_header
->addr_size
,
7008 TYPE_LENGTH (SYMBOL_TYPE
7010 SYMBOL_VALUE_BYTES (sym
) = (char *)
7011 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
7012 /* NOTE: cagney/2003-05-09: In-lined store_address call with
7013 it's body - store_unsigned_integer. */
7014 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
7016 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7018 case DW_FORM_block1
:
7019 case DW_FORM_block2
:
7020 case DW_FORM_block4
:
7022 blk
= DW_BLOCK (attr
);
7023 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
7024 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
7026 TYPE_LENGTH (SYMBOL_TYPE
7028 SYMBOL_VALUE_BYTES (sym
) = (char *)
7029 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
7030 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
7031 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7034 /* The DW_AT_const_value attributes are supposed to carry the
7035 symbol's value "represented as it would be on the target
7036 architecture." By the time we get here, it's already been
7037 converted to host endianness, so we just need to sign- or
7038 zero-extend it as appropriate. */
7040 dwarf2_const_value_data (attr
, sym
, 8);
7043 dwarf2_const_value_data (attr
, sym
, 16);
7046 dwarf2_const_value_data (attr
, sym
, 32);
7049 dwarf2_const_value_data (attr
, sym
, 64);
7053 SYMBOL_VALUE (sym
) = DW_SND (attr
);
7054 SYMBOL_CLASS (sym
) = LOC_CONST
;
7058 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
7059 SYMBOL_CLASS (sym
) = LOC_CONST
;
7063 complaint (&symfile_complaints
,
7064 "unsupported const value attribute form: '%s'",
7065 dwarf_form_name (attr
->form
));
7066 SYMBOL_VALUE (sym
) = 0;
7067 SYMBOL_CLASS (sym
) = LOC_CONST
;
7073 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
7074 or zero-extend it as appropriate for the symbol's type. */
7076 dwarf2_const_value_data (struct attribute
*attr
,
7080 LONGEST l
= DW_UNSND (attr
);
7082 if (bits
< sizeof (l
) * 8)
7084 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
7085 l
&= ((LONGEST
) 1 << bits
) - 1;
7087 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
7090 SYMBOL_VALUE (sym
) = l
;
7091 SYMBOL_CLASS (sym
) = LOC_CONST
;
7095 /* Return the type of the die in question using its DW_AT_type attribute. */
7097 static struct type
*
7098 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7101 struct attribute
*type_attr
;
7102 struct die_info
*type_die
;
7104 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
7107 /* A missing DW_AT_type represents a void type. */
7108 return dwarf2_fundamental_type (cu
->objfile
, FT_VOID
, cu
);
7111 type_die
= follow_die_ref (die
, type_attr
, cu
);
7113 type
= tag_type_to_type (type_die
, cu
);
7116 dump_die (type_die
);
7117 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
7123 /* Return the containing type of the die in question using its
7124 DW_AT_containing_type attribute. */
7126 static struct type
*
7127 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7129 struct type
*type
= NULL
;
7130 struct attribute
*type_attr
;
7131 struct die_info
*type_die
= NULL
;
7133 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
7136 type_die
= follow_die_ref (die
, type_attr
, cu
);
7137 type
= tag_type_to_type (type_die
, cu
);
7142 dump_die (type_die
);
7143 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
7149 static struct type
*
7150 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7158 read_type_die (die
, cu
);
7162 error ("Dwarf Error: Cannot find type of die [in module %s]",
7170 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7172 char *prefix
= determine_prefix (die
, cu
);
7173 const char *old_prefix
= processing_current_prefix
;
7174 struct cleanup
*back_to
= make_cleanup (xfree
, prefix
);
7175 processing_current_prefix
= prefix
;
7179 case DW_TAG_class_type
:
7180 case DW_TAG_structure_type
:
7181 case DW_TAG_union_type
:
7182 read_structure_type (die
, cu
);
7184 case DW_TAG_enumeration_type
:
7185 read_enumeration_type (die
, cu
);
7187 case DW_TAG_subprogram
:
7188 case DW_TAG_subroutine_type
:
7189 read_subroutine_type (die
, cu
);
7191 case DW_TAG_array_type
:
7192 read_array_type (die
, cu
);
7194 case DW_TAG_pointer_type
:
7195 read_tag_pointer_type (die
, cu
);
7197 case DW_TAG_ptr_to_member_type
:
7198 read_tag_ptr_to_member_type (die
, cu
);
7200 case DW_TAG_reference_type
:
7201 read_tag_reference_type (die
, cu
);
7203 case DW_TAG_const_type
:
7204 read_tag_const_type (die
, cu
);
7206 case DW_TAG_volatile_type
:
7207 read_tag_volatile_type (die
, cu
);
7209 case DW_TAG_string_type
:
7210 read_tag_string_type (die
, cu
);
7212 case DW_TAG_typedef
:
7213 read_typedef (die
, cu
);
7215 case DW_TAG_subrange_type
:
7216 read_subrange_type (die
, cu
);
7218 case DW_TAG_base_type
:
7219 read_base_type (die
, cu
);
7222 complaint (&symfile_complaints
, "unexepected tag in read_type_die: '%s'",
7223 dwarf_tag_name (die
->tag
));
7227 processing_current_prefix
= old_prefix
;
7228 do_cleanups (back_to
);
7231 /* Return the name of the namespace/class that DIE is defined within,
7232 or "" if we can't tell. The caller should xfree the result. */
7234 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
7235 therein) for an example of how to use this function to deal with
7236 DW_AT_specification. */
7239 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
7241 struct die_info
*parent
;
7243 if (cu
->language
!= language_cplus
7244 && cu
->language
!= language_java
)
7247 parent
= die
->parent
;
7251 return xstrdup ("");
7255 switch (parent
->tag
) {
7256 case DW_TAG_namespace
:
7258 /* FIXME: carlton/2004-03-05: Should I follow extension dies
7259 before doing this check? */
7260 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
7262 return xstrdup (TYPE_TAG_NAME (parent
->type
));
7267 char *parent_prefix
= determine_prefix (parent
, cu
);
7268 char *retval
= typename_concat (NULL
, parent_prefix
,
7269 namespace_name (parent
, &dummy
,
7272 xfree (parent_prefix
);
7277 case DW_TAG_class_type
:
7278 case DW_TAG_structure_type
:
7280 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
7282 return xstrdup (TYPE_TAG_NAME (parent
->type
));
7286 const char *old_prefix
= processing_current_prefix
;
7287 char *new_prefix
= determine_prefix (parent
, cu
);
7290 processing_current_prefix
= new_prefix
;
7291 retval
= determine_class_name (parent
, cu
);
7292 processing_current_prefix
= old_prefix
;
7299 return determine_prefix (parent
, cu
);
7304 /* Return a newly-allocated string formed by concatenating PREFIX and
7305 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
7306 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
7307 perform an obconcat, otherwise allocate storage for the result. The CU argument
7308 is used to determine the language and hence, the appropriate separator. */
7310 #define MAX_SEP_LEN 2 /* sizeof ("::") */
7313 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
7314 struct dwarf2_cu
*cu
)
7318 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
7320 else if (cu
->language
== language_java
)
7327 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
7332 strcpy (retval
, prefix
);
7333 strcat (retval
, sep
);
7336 strcat (retval
, suffix
);
7342 /* We have an obstack. */
7343 return obconcat (obs
, prefix
, sep
, suffix
);
7347 static struct type
*
7348 dwarf_base_type (int encoding
, int size
, struct dwarf2_cu
*cu
)
7350 struct objfile
*objfile
= cu
->objfile
;
7352 /* FIXME - this should not produce a new (struct type *)
7353 every time. It should cache base types. */
7357 case DW_ATE_address
:
7358 type
= dwarf2_fundamental_type (objfile
, FT_VOID
, cu
);
7360 case DW_ATE_boolean
:
7361 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
, cu
);
7363 case DW_ATE_complex_float
:
7366 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
, cu
);
7370 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
, cu
);
7376 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
7380 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
7387 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
7390 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
, cu
);
7394 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
7398 case DW_ATE_signed_char
:
7399 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
7401 case DW_ATE_unsigned
:
7405 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
7408 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
, cu
);
7412 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
, cu
);
7416 case DW_ATE_unsigned_char
:
7417 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
7420 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
7427 copy_die (struct die_info
*old_die
)
7429 struct die_info
*new_die
;
7432 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
7433 memset (new_die
, 0, sizeof (struct die_info
));
7435 new_die
->tag
= old_die
->tag
;
7436 new_die
->has_children
= old_die
->has_children
;
7437 new_die
->abbrev
= old_die
->abbrev
;
7438 new_die
->offset
= old_die
->offset
;
7439 new_die
->type
= NULL
;
7441 num_attrs
= old_die
->num_attrs
;
7442 new_die
->num_attrs
= num_attrs
;
7443 new_die
->attrs
= (struct attribute
*)
7444 xmalloc (num_attrs
* sizeof (struct attribute
));
7446 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
7448 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
7449 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
7450 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
7453 new_die
->next
= NULL
;
7458 /* Return sibling of die, NULL if no sibling. */
7460 static struct die_info
*
7461 sibling_die (struct die_info
*die
)
7463 return die
->sibling
;
7466 /* Get linkage name of a die, return NULL if not found. */
7469 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
7471 struct attribute
*attr
;
7473 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7474 if (attr
&& DW_STRING (attr
))
7475 return DW_STRING (attr
);
7476 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7477 if (attr
&& DW_STRING (attr
))
7478 return DW_STRING (attr
);
7482 /* Get name of a die, return NULL if not found. */
7485 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
7487 struct attribute
*attr
;
7489 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7490 if (attr
&& DW_STRING (attr
))
7491 return DW_STRING (attr
);
7495 /* Return the die that this die in an extension of, or NULL if there
7498 static struct die_info
*
7499 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
*cu
)
7501 struct attribute
*attr
;
7503 attr
= dwarf2_attr (die
, DW_AT_extension
, cu
);
7507 return follow_die_ref (die
, attr
, cu
);
7510 /* Convert a DIE tag into its string name. */
7513 dwarf_tag_name (unsigned tag
)
7517 case DW_TAG_padding
:
7518 return "DW_TAG_padding";
7519 case DW_TAG_array_type
:
7520 return "DW_TAG_array_type";
7521 case DW_TAG_class_type
:
7522 return "DW_TAG_class_type";
7523 case DW_TAG_entry_point
:
7524 return "DW_TAG_entry_point";
7525 case DW_TAG_enumeration_type
:
7526 return "DW_TAG_enumeration_type";
7527 case DW_TAG_formal_parameter
:
7528 return "DW_TAG_formal_parameter";
7529 case DW_TAG_imported_declaration
:
7530 return "DW_TAG_imported_declaration";
7532 return "DW_TAG_label";
7533 case DW_TAG_lexical_block
:
7534 return "DW_TAG_lexical_block";
7536 return "DW_TAG_member";
7537 case DW_TAG_pointer_type
:
7538 return "DW_TAG_pointer_type";
7539 case DW_TAG_reference_type
:
7540 return "DW_TAG_reference_type";
7541 case DW_TAG_compile_unit
:
7542 return "DW_TAG_compile_unit";
7543 case DW_TAG_string_type
:
7544 return "DW_TAG_string_type";
7545 case DW_TAG_structure_type
:
7546 return "DW_TAG_structure_type";
7547 case DW_TAG_subroutine_type
:
7548 return "DW_TAG_subroutine_type";
7549 case DW_TAG_typedef
:
7550 return "DW_TAG_typedef";
7551 case DW_TAG_union_type
:
7552 return "DW_TAG_union_type";
7553 case DW_TAG_unspecified_parameters
:
7554 return "DW_TAG_unspecified_parameters";
7555 case DW_TAG_variant
:
7556 return "DW_TAG_variant";
7557 case DW_TAG_common_block
:
7558 return "DW_TAG_common_block";
7559 case DW_TAG_common_inclusion
:
7560 return "DW_TAG_common_inclusion";
7561 case DW_TAG_inheritance
:
7562 return "DW_TAG_inheritance";
7563 case DW_TAG_inlined_subroutine
:
7564 return "DW_TAG_inlined_subroutine";
7566 return "DW_TAG_module";
7567 case DW_TAG_ptr_to_member_type
:
7568 return "DW_TAG_ptr_to_member_type";
7569 case DW_TAG_set_type
:
7570 return "DW_TAG_set_type";
7571 case DW_TAG_subrange_type
:
7572 return "DW_TAG_subrange_type";
7573 case DW_TAG_with_stmt
:
7574 return "DW_TAG_with_stmt";
7575 case DW_TAG_access_declaration
:
7576 return "DW_TAG_access_declaration";
7577 case DW_TAG_base_type
:
7578 return "DW_TAG_base_type";
7579 case DW_TAG_catch_block
:
7580 return "DW_TAG_catch_block";
7581 case DW_TAG_const_type
:
7582 return "DW_TAG_const_type";
7583 case DW_TAG_constant
:
7584 return "DW_TAG_constant";
7585 case DW_TAG_enumerator
:
7586 return "DW_TAG_enumerator";
7587 case DW_TAG_file_type
:
7588 return "DW_TAG_file_type";
7590 return "DW_TAG_friend";
7591 case DW_TAG_namelist
:
7592 return "DW_TAG_namelist";
7593 case DW_TAG_namelist_item
:
7594 return "DW_TAG_namelist_item";
7595 case DW_TAG_packed_type
:
7596 return "DW_TAG_packed_type";
7597 case DW_TAG_subprogram
:
7598 return "DW_TAG_subprogram";
7599 case DW_TAG_template_type_param
:
7600 return "DW_TAG_template_type_param";
7601 case DW_TAG_template_value_param
:
7602 return "DW_TAG_template_value_param";
7603 case DW_TAG_thrown_type
:
7604 return "DW_TAG_thrown_type";
7605 case DW_TAG_try_block
:
7606 return "DW_TAG_try_block";
7607 case DW_TAG_variant_part
:
7608 return "DW_TAG_variant_part";
7609 case DW_TAG_variable
:
7610 return "DW_TAG_variable";
7611 case DW_TAG_volatile_type
:
7612 return "DW_TAG_volatile_type";
7613 case DW_TAG_dwarf_procedure
:
7614 return "DW_TAG_dwarf_procedure";
7615 case DW_TAG_restrict_type
:
7616 return "DW_TAG_restrict_type";
7617 case DW_TAG_interface_type
:
7618 return "DW_TAG_interface_type";
7619 case DW_TAG_namespace
:
7620 return "DW_TAG_namespace";
7621 case DW_TAG_imported_module
:
7622 return "DW_TAG_imported_module";
7623 case DW_TAG_unspecified_type
:
7624 return "DW_TAG_unspecified_type";
7625 case DW_TAG_partial_unit
:
7626 return "DW_TAG_partial_unit";
7627 case DW_TAG_imported_unit
:
7628 return "DW_TAG_imported_unit";
7629 case DW_TAG_MIPS_loop
:
7630 return "DW_TAG_MIPS_loop";
7631 case DW_TAG_format_label
:
7632 return "DW_TAG_format_label";
7633 case DW_TAG_function_template
:
7634 return "DW_TAG_function_template";
7635 case DW_TAG_class_template
:
7636 return "DW_TAG_class_template";
7638 return "DW_TAG_<unknown>";
7642 /* Convert a DWARF attribute code into its string name. */
7645 dwarf_attr_name (unsigned attr
)
7650 return "DW_AT_sibling";
7651 case DW_AT_location
:
7652 return "DW_AT_location";
7654 return "DW_AT_name";
7655 case DW_AT_ordering
:
7656 return "DW_AT_ordering";
7657 case DW_AT_subscr_data
:
7658 return "DW_AT_subscr_data";
7659 case DW_AT_byte_size
:
7660 return "DW_AT_byte_size";
7661 case DW_AT_bit_offset
:
7662 return "DW_AT_bit_offset";
7663 case DW_AT_bit_size
:
7664 return "DW_AT_bit_size";
7665 case DW_AT_element_list
:
7666 return "DW_AT_element_list";
7667 case DW_AT_stmt_list
:
7668 return "DW_AT_stmt_list";
7670 return "DW_AT_low_pc";
7672 return "DW_AT_high_pc";
7673 case DW_AT_language
:
7674 return "DW_AT_language";
7676 return "DW_AT_member";
7678 return "DW_AT_discr";
7679 case DW_AT_discr_value
:
7680 return "DW_AT_discr_value";
7681 case DW_AT_visibility
:
7682 return "DW_AT_visibility";
7684 return "DW_AT_import";
7685 case DW_AT_string_length
:
7686 return "DW_AT_string_length";
7687 case DW_AT_common_reference
:
7688 return "DW_AT_common_reference";
7689 case DW_AT_comp_dir
:
7690 return "DW_AT_comp_dir";
7691 case DW_AT_const_value
:
7692 return "DW_AT_const_value";
7693 case DW_AT_containing_type
:
7694 return "DW_AT_containing_type";
7695 case DW_AT_default_value
:
7696 return "DW_AT_default_value";
7698 return "DW_AT_inline";
7699 case DW_AT_is_optional
:
7700 return "DW_AT_is_optional";
7701 case DW_AT_lower_bound
:
7702 return "DW_AT_lower_bound";
7703 case DW_AT_producer
:
7704 return "DW_AT_producer";
7705 case DW_AT_prototyped
:
7706 return "DW_AT_prototyped";
7707 case DW_AT_return_addr
:
7708 return "DW_AT_return_addr";
7709 case DW_AT_start_scope
:
7710 return "DW_AT_start_scope";
7711 case DW_AT_stride_size
:
7712 return "DW_AT_stride_size";
7713 case DW_AT_upper_bound
:
7714 return "DW_AT_upper_bound";
7715 case DW_AT_abstract_origin
:
7716 return "DW_AT_abstract_origin";
7717 case DW_AT_accessibility
:
7718 return "DW_AT_accessibility";
7719 case DW_AT_address_class
:
7720 return "DW_AT_address_class";
7721 case DW_AT_artificial
:
7722 return "DW_AT_artificial";
7723 case DW_AT_base_types
:
7724 return "DW_AT_base_types";
7725 case DW_AT_calling_convention
:
7726 return "DW_AT_calling_convention";
7728 return "DW_AT_count";
7729 case DW_AT_data_member_location
:
7730 return "DW_AT_data_member_location";
7731 case DW_AT_decl_column
:
7732 return "DW_AT_decl_column";
7733 case DW_AT_decl_file
:
7734 return "DW_AT_decl_file";
7735 case DW_AT_decl_line
:
7736 return "DW_AT_decl_line";
7737 case DW_AT_declaration
:
7738 return "DW_AT_declaration";
7739 case DW_AT_discr_list
:
7740 return "DW_AT_discr_list";
7741 case DW_AT_encoding
:
7742 return "DW_AT_encoding";
7743 case DW_AT_external
:
7744 return "DW_AT_external";
7745 case DW_AT_frame_base
:
7746 return "DW_AT_frame_base";
7748 return "DW_AT_friend";
7749 case DW_AT_identifier_case
:
7750 return "DW_AT_identifier_case";
7751 case DW_AT_macro_info
:
7752 return "DW_AT_macro_info";
7753 case DW_AT_namelist_items
:
7754 return "DW_AT_namelist_items";
7755 case DW_AT_priority
:
7756 return "DW_AT_priority";
7758 return "DW_AT_segment";
7759 case DW_AT_specification
:
7760 return "DW_AT_specification";
7761 case DW_AT_static_link
:
7762 return "DW_AT_static_link";
7764 return "DW_AT_type";
7765 case DW_AT_use_location
:
7766 return "DW_AT_use_location";
7767 case DW_AT_variable_parameter
:
7768 return "DW_AT_variable_parameter";
7769 case DW_AT_virtuality
:
7770 return "DW_AT_virtuality";
7771 case DW_AT_vtable_elem_location
:
7772 return "DW_AT_vtable_elem_location";
7773 case DW_AT_allocated
:
7774 return "DW_AT_allocated";
7775 case DW_AT_associated
:
7776 return "DW_AT_associated";
7777 case DW_AT_data_location
:
7778 return "DW_AT_data_location";
7780 return "DW_AT_stride";
7781 case DW_AT_entry_pc
:
7782 return "DW_AT_entry_pc";
7783 case DW_AT_use_UTF8
:
7784 return "DW_AT_use_UTF8";
7785 case DW_AT_extension
:
7786 return "DW_AT_extension";
7788 return "DW_AT_ranges";
7789 case DW_AT_trampoline
:
7790 return "DW_AT_trampoline";
7791 case DW_AT_call_column
:
7792 return "DW_AT_call_column";
7793 case DW_AT_call_file
:
7794 return "DW_AT_call_file";
7795 case DW_AT_call_line
:
7796 return "DW_AT_call_line";
7798 case DW_AT_MIPS_fde
:
7799 return "DW_AT_MIPS_fde";
7800 case DW_AT_MIPS_loop_begin
:
7801 return "DW_AT_MIPS_loop_begin";
7802 case DW_AT_MIPS_tail_loop_begin
:
7803 return "DW_AT_MIPS_tail_loop_begin";
7804 case DW_AT_MIPS_epilog_begin
:
7805 return "DW_AT_MIPS_epilog_begin";
7806 case DW_AT_MIPS_loop_unroll_factor
:
7807 return "DW_AT_MIPS_loop_unroll_factor";
7808 case DW_AT_MIPS_software_pipeline_depth
:
7809 return "DW_AT_MIPS_software_pipeline_depth";
7811 case DW_AT_MIPS_linkage_name
:
7812 return "DW_AT_MIPS_linkage_name";
7814 case DW_AT_sf_names
:
7815 return "DW_AT_sf_names";
7816 case DW_AT_src_info
:
7817 return "DW_AT_src_info";
7818 case DW_AT_mac_info
:
7819 return "DW_AT_mac_info";
7820 case DW_AT_src_coords
:
7821 return "DW_AT_src_coords";
7822 case DW_AT_body_begin
:
7823 return "DW_AT_body_begin";
7824 case DW_AT_body_end
:
7825 return "DW_AT_body_end";
7826 case DW_AT_GNU_vector
:
7827 return "DW_AT_GNU_vector";
7829 return "DW_AT_<unknown>";
7833 /* Convert a DWARF value form code into its string name. */
7836 dwarf_form_name (unsigned form
)
7841 return "DW_FORM_addr";
7842 case DW_FORM_block2
:
7843 return "DW_FORM_block2";
7844 case DW_FORM_block4
:
7845 return "DW_FORM_block4";
7847 return "DW_FORM_data2";
7849 return "DW_FORM_data4";
7851 return "DW_FORM_data8";
7852 case DW_FORM_string
:
7853 return "DW_FORM_string";
7855 return "DW_FORM_block";
7856 case DW_FORM_block1
:
7857 return "DW_FORM_block1";
7859 return "DW_FORM_data1";
7861 return "DW_FORM_flag";
7863 return "DW_FORM_sdata";
7865 return "DW_FORM_strp";
7867 return "DW_FORM_udata";
7868 case DW_FORM_ref_addr
:
7869 return "DW_FORM_ref_addr";
7871 return "DW_FORM_ref1";
7873 return "DW_FORM_ref2";
7875 return "DW_FORM_ref4";
7877 return "DW_FORM_ref8";
7878 case DW_FORM_ref_udata
:
7879 return "DW_FORM_ref_udata";
7880 case DW_FORM_indirect
:
7881 return "DW_FORM_indirect";
7883 return "DW_FORM_<unknown>";
7887 /* Convert a DWARF stack opcode into its string name. */
7890 dwarf_stack_op_name (unsigned op
)
7895 return "DW_OP_addr";
7897 return "DW_OP_deref";
7899 return "DW_OP_const1u";
7901 return "DW_OP_const1s";
7903 return "DW_OP_const2u";
7905 return "DW_OP_const2s";
7907 return "DW_OP_const4u";
7909 return "DW_OP_const4s";
7911 return "DW_OP_const8u";
7913 return "DW_OP_const8s";
7915 return "DW_OP_constu";
7917 return "DW_OP_consts";
7921 return "DW_OP_drop";
7923 return "DW_OP_over";
7925 return "DW_OP_pick";
7927 return "DW_OP_swap";
7931 return "DW_OP_xderef";
7939 return "DW_OP_minus";
7951 return "DW_OP_plus";
7952 case DW_OP_plus_uconst
:
7953 return "DW_OP_plus_uconst";
7959 return "DW_OP_shra";
7977 return "DW_OP_skip";
7979 return "DW_OP_lit0";
7981 return "DW_OP_lit1";
7983 return "DW_OP_lit2";
7985 return "DW_OP_lit3";
7987 return "DW_OP_lit4";
7989 return "DW_OP_lit5";
7991 return "DW_OP_lit6";
7993 return "DW_OP_lit7";
7995 return "DW_OP_lit8";
7997 return "DW_OP_lit9";
7999 return "DW_OP_lit10";
8001 return "DW_OP_lit11";
8003 return "DW_OP_lit12";
8005 return "DW_OP_lit13";
8007 return "DW_OP_lit14";
8009 return "DW_OP_lit15";
8011 return "DW_OP_lit16";
8013 return "DW_OP_lit17";
8015 return "DW_OP_lit18";
8017 return "DW_OP_lit19";
8019 return "DW_OP_lit20";
8021 return "DW_OP_lit21";
8023 return "DW_OP_lit22";
8025 return "DW_OP_lit23";
8027 return "DW_OP_lit24";
8029 return "DW_OP_lit25";
8031 return "DW_OP_lit26";
8033 return "DW_OP_lit27";
8035 return "DW_OP_lit28";
8037 return "DW_OP_lit29";
8039 return "DW_OP_lit30";
8041 return "DW_OP_lit31";
8043 return "DW_OP_reg0";
8045 return "DW_OP_reg1";
8047 return "DW_OP_reg2";
8049 return "DW_OP_reg3";
8051 return "DW_OP_reg4";
8053 return "DW_OP_reg5";
8055 return "DW_OP_reg6";
8057 return "DW_OP_reg7";
8059 return "DW_OP_reg8";
8061 return "DW_OP_reg9";
8063 return "DW_OP_reg10";
8065 return "DW_OP_reg11";
8067 return "DW_OP_reg12";
8069 return "DW_OP_reg13";
8071 return "DW_OP_reg14";
8073 return "DW_OP_reg15";
8075 return "DW_OP_reg16";
8077 return "DW_OP_reg17";
8079 return "DW_OP_reg18";
8081 return "DW_OP_reg19";
8083 return "DW_OP_reg20";
8085 return "DW_OP_reg21";
8087 return "DW_OP_reg22";
8089 return "DW_OP_reg23";
8091 return "DW_OP_reg24";
8093 return "DW_OP_reg25";
8095 return "DW_OP_reg26";
8097 return "DW_OP_reg27";
8099 return "DW_OP_reg28";
8101 return "DW_OP_reg29";
8103 return "DW_OP_reg30";
8105 return "DW_OP_reg31";
8107 return "DW_OP_breg0";
8109 return "DW_OP_breg1";
8111 return "DW_OP_breg2";
8113 return "DW_OP_breg3";
8115 return "DW_OP_breg4";
8117 return "DW_OP_breg5";
8119 return "DW_OP_breg6";
8121 return "DW_OP_breg7";
8123 return "DW_OP_breg8";
8125 return "DW_OP_breg9";
8127 return "DW_OP_breg10";
8129 return "DW_OP_breg11";
8131 return "DW_OP_breg12";
8133 return "DW_OP_breg13";
8135 return "DW_OP_breg14";
8137 return "DW_OP_breg15";
8139 return "DW_OP_breg16";
8141 return "DW_OP_breg17";
8143 return "DW_OP_breg18";
8145 return "DW_OP_breg19";
8147 return "DW_OP_breg20";
8149 return "DW_OP_breg21";
8151 return "DW_OP_breg22";
8153 return "DW_OP_breg23";
8155 return "DW_OP_breg24";
8157 return "DW_OP_breg25";
8159 return "DW_OP_breg26";
8161 return "DW_OP_breg27";
8163 return "DW_OP_breg28";
8165 return "DW_OP_breg29";
8167 return "DW_OP_breg30";
8169 return "DW_OP_breg31";
8171 return "DW_OP_regx";
8173 return "DW_OP_fbreg";
8175 return "DW_OP_bregx";
8177 return "DW_OP_piece";
8178 case DW_OP_deref_size
:
8179 return "DW_OP_deref_size";
8180 case DW_OP_xderef_size
:
8181 return "DW_OP_xderef_size";
8184 /* DWARF 3 extensions. */
8185 case DW_OP_push_object_address
:
8186 return "DW_OP_push_object_address";
8188 return "DW_OP_call2";
8190 return "DW_OP_call4";
8191 case DW_OP_call_ref
:
8192 return "DW_OP_call_ref";
8193 /* GNU extensions. */
8194 case DW_OP_GNU_push_tls_address
:
8195 return "DW_OP_GNU_push_tls_address";
8197 return "OP_<unknown>";
8202 dwarf_bool_name (unsigned mybool
)
8210 /* Convert a DWARF type code into its string name. */
8213 dwarf_type_encoding_name (unsigned enc
)
8217 case DW_ATE_address
:
8218 return "DW_ATE_address";
8219 case DW_ATE_boolean
:
8220 return "DW_ATE_boolean";
8221 case DW_ATE_complex_float
:
8222 return "DW_ATE_complex_float";
8224 return "DW_ATE_float";
8226 return "DW_ATE_signed";
8227 case DW_ATE_signed_char
:
8228 return "DW_ATE_signed_char";
8229 case DW_ATE_unsigned
:
8230 return "DW_ATE_unsigned";
8231 case DW_ATE_unsigned_char
:
8232 return "DW_ATE_unsigned_char";
8233 case DW_ATE_imaginary_float
:
8234 return "DW_ATE_imaginary_float";
8236 return "DW_ATE_<unknown>";
8240 /* Convert a DWARF call frame info operation to its string name. */
8244 dwarf_cfi_name (unsigned cfi_opc
)
8248 case DW_CFA_advance_loc
:
8249 return "DW_CFA_advance_loc";
8251 return "DW_CFA_offset";
8252 case DW_CFA_restore
:
8253 return "DW_CFA_restore";
8255 return "DW_CFA_nop";
8256 case DW_CFA_set_loc
:
8257 return "DW_CFA_set_loc";
8258 case DW_CFA_advance_loc1
:
8259 return "DW_CFA_advance_loc1";
8260 case DW_CFA_advance_loc2
:
8261 return "DW_CFA_advance_loc2";
8262 case DW_CFA_advance_loc4
:
8263 return "DW_CFA_advance_loc4";
8264 case DW_CFA_offset_extended
:
8265 return "DW_CFA_offset_extended";
8266 case DW_CFA_restore_extended
:
8267 return "DW_CFA_restore_extended";
8268 case DW_CFA_undefined
:
8269 return "DW_CFA_undefined";
8270 case DW_CFA_same_value
:
8271 return "DW_CFA_same_value";
8272 case DW_CFA_register
:
8273 return "DW_CFA_register";
8274 case DW_CFA_remember_state
:
8275 return "DW_CFA_remember_state";
8276 case DW_CFA_restore_state
:
8277 return "DW_CFA_restore_state";
8278 case DW_CFA_def_cfa
:
8279 return "DW_CFA_def_cfa";
8280 case DW_CFA_def_cfa_register
:
8281 return "DW_CFA_def_cfa_register";
8282 case DW_CFA_def_cfa_offset
:
8283 return "DW_CFA_def_cfa_offset";
8286 case DW_CFA_def_cfa_expression
:
8287 return "DW_CFA_def_cfa_expression";
8288 case DW_CFA_expression
:
8289 return "DW_CFA_expression";
8290 case DW_CFA_offset_extended_sf
:
8291 return "DW_CFA_offset_extended_sf";
8292 case DW_CFA_def_cfa_sf
:
8293 return "DW_CFA_def_cfa_sf";
8294 case DW_CFA_def_cfa_offset_sf
:
8295 return "DW_CFA_def_cfa_offset_sf";
8297 /* SGI/MIPS specific */
8298 case DW_CFA_MIPS_advance_loc8
:
8299 return "DW_CFA_MIPS_advance_loc8";
8301 /* GNU extensions */
8302 case DW_CFA_GNU_window_save
:
8303 return "DW_CFA_GNU_window_save";
8304 case DW_CFA_GNU_args_size
:
8305 return "DW_CFA_GNU_args_size";
8306 case DW_CFA_GNU_negative_offset_extended
:
8307 return "DW_CFA_GNU_negative_offset_extended";
8310 return "DW_CFA_<unknown>";
8316 dump_die (struct die_info
*die
)
8320 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
8321 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
8322 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
8323 dwarf_bool_name (die
->child
!= NULL
));
8325 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
8326 for (i
= 0; i
< die
->num_attrs
; ++i
)
8328 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
8329 dwarf_attr_name (die
->attrs
[i
].name
),
8330 dwarf_form_name (die
->attrs
[i
].form
));
8331 switch (die
->attrs
[i
].form
)
8333 case DW_FORM_ref_addr
:
8335 fprintf_unfiltered (gdb_stderr
, "address: ");
8336 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
8338 case DW_FORM_block2
:
8339 case DW_FORM_block4
:
8341 case DW_FORM_block1
:
8342 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
8347 fprintf_unfiltered (gdb_stderr
, "constant ref: %ld (adjusted)",
8348 (long) (DW_ADDR (&die
->attrs
[i
])));
8356 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
8358 case DW_FORM_string
:
8360 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
8361 DW_STRING (&die
->attrs
[i
])
8362 ? DW_STRING (&die
->attrs
[i
]) : "");
8365 if (DW_UNSND (&die
->attrs
[i
]))
8366 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
8368 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
8370 case DW_FORM_indirect
:
8371 /* the reader will have reduced the indirect form to
8372 the "base form" so this form should not occur */
8373 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
8376 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
8377 die
->attrs
[i
].form
);
8379 fprintf_unfiltered (gdb_stderr
, "\n");
8384 dump_die_list (struct die_info
*die
)
8389 if (die
->child
!= NULL
)
8390 dump_die_list (die
->child
);
8391 if (die
->sibling
!= NULL
)
8392 dump_die_list (die
->sibling
);
8397 store_in_ref_table (unsigned int offset
, struct die_info
*die
,
8398 struct dwarf2_cu
*cu
)
8401 struct die_info
*old
;
8403 h
= (offset
% REF_HASH_SIZE
);
8404 old
= cu
->die_ref_table
[h
];
8405 die
->next_ref
= old
;
8406 cu
->die_ref_table
[h
] = die
;
8410 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
8412 unsigned int result
= 0;
8416 case DW_FORM_ref_addr
:
8421 case DW_FORM_ref_udata
:
8422 result
= DW_ADDR (attr
);
8425 complaint (&symfile_complaints
,
8426 "unsupported die ref attribute form: '%s'",
8427 dwarf_form_name (attr
->form
));
8432 /* Return the constant value held by the given attribute. Return -1
8433 if the value held by the attribute is not constant. */
8436 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
8438 if (attr
->form
== DW_FORM_sdata
)
8439 return DW_SND (attr
);
8440 else if (attr
->form
== DW_FORM_udata
8441 || attr
->form
== DW_FORM_data1
8442 || attr
->form
== DW_FORM_data2
8443 || attr
->form
== DW_FORM_data4
8444 || attr
->form
== DW_FORM_data8
)
8445 return DW_UNSND (attr
);
8448 complaint (&symfile_complaints
, "Attribute value is not a constant (%s)",
8449 dwarf_form_name (attr
->form
));
8450 return default_value
;
8454 static struct die_info
*
8455 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
8456 struct dwarf2_cu
*cu
)
8458 struct die_info
*die
;
8459 unsigned int offset
;
8461 struct die_info temp_die
;
8462 struct dwarf2_cu
*target_cu
;
8464 offset
= dwarf2_get_ref_die_offset (attr
, cu
);
8466 if (DW_ADDR (attr
) < cu
->header
.offset
8467 || DW_ADDR (attr
) >= cu
->header
.offset
+ cu
->header
.length
)
8469 struct dwarf2_per_cu_data
*per_cu
;
8470 per_cu
= dwarf2_find_containing_comp_unit (DW_ADDR (attr
),
8472 target_cu
= per_cu
->cu
;
8477 h
= (offset
% REF_HASH_SIZE
);
8478 die
= target_cu
->die_ref_table
[h
];
8481 if (die
->offset
== offset
)
8483 die
= die
->next_ref
;
8486 error ("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
8487 "at 0x%lx [in module %s]",
8488 (long) src_die
->offset
, (long) offset
, cu
->objfile
->name
);
8493 static struct type
*
8494 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid,
8495 struct dwarf2_cu
*cu
)
8497 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
8499 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
8500 typeid, objfile
->name
);
8503 /* Look for this particular type in the fundamental type vector. If
8504 one is not found, create and install one appropriate for the
8505 current language and the current target machine. */
8507 if (cu
->ftypes
[typeid] == NULL
)
8509 cu
->ftypes
[typeid] = cu
->language_defn
->la_fund_type (objfile
, typeid);
8512 return (cu
->ftypes
[typeid]);
8515 /* Decode simple location descriptions.
8516 Given a pointer to a dwarf block that defines a location, compute
8517 the location and return the value.
8519 NOTE drow/2003-11-18: This function is called in two situations
8520 now: for the address of static or global variables (partial symbols
8521 only) and for offsets into structures which are expected to be
8522 (more or less) constant. The partial symbol case should go away,
8523 and only the constant case should remain. That will let this
8524 function complain more accurately. A few special modes are allowed
8525 without complaint for global variables (for instance, global
8526 register values and thread-local values).
8528 A location description containing no operations indicates that the
8529 object is optimized out. The return value is 0 for that case.
8530 FIXME drow/2003-11-16: No callers check for this case any more; soon all
8531 callers will only want a very basic result and this can become a
8534 When the result is a register number, the global isreg flag is set,
8535 otherwise it is cleared.
8537 Note that stack[0] is unused except as a default error return.
8538 Note that stack overflow is not yet handled. */
8541 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
8543 struct objfile
*objfile
= cu
->objfile
;
8544 struct comp_unit_head
*cu_header
= &cu
->header
;
8546 int size
= blk
->size
;
8547 char *data
= blk
->data
;
8548 CORE_ADDR stack
[64];
8550 unsigned int bytes_read
, unsnd
;
8595 stack
[++stacki
] = op
- DW_OP_lit0
;
8631 stack
[++stacki
] = op
- DW_OP_reg0
;
8633 dwarf2_complex_location_expr_complaint ();
8638 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
8640 stack
[++stacki
] = unsnd
;
8642 dwarf2_complex_location_expr_complaint ();
8646 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
8652 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
8657 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
8662 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
8667 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
8672 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
8677 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
8682 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
8688 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
8693 stack
[stacki
+ 1] = stack
[stacki
];
8698 stack
[stacki
- 1] += stack
[stacki
];
8702 case DW_OP_plus_uconst
:
8703 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
8708 stack
[stacki
- 1] -= stack
[stacki
];
8713 /* If we're not the last op, then we definitely can't encode
8714 this using GDB's address_class enum. This is valid for partial
8715 global symbols, although the variable's address will be bogus
8718 dwarf2_complex_location_expr_complaint ();
8721 case DW_OP_GNU_push_tls_address
:
8722 /* The top of the stack has the offset from the beginning
8723 of the thread control block at which the variable is located. */
8724 /* Nothing should follow this operator, so the top of stack would
8726 /* This is valid for partial global symbols, but the variable's
8727 address will be bogus in the psymtab. */
8729 dwarf2_complex_location_expr_complaint ();
8733 complaint (&symfile_complaints
, "unsupported stack op: '%s'",
8734 dwarf_stack_op_name (op
));
8735 return (stack
[stacki
]);
8738 return (stack
[stacki
]);
8741 /* memory allocation interface */
8743 static struct dwarf_block
*
8744 dwarf_alloc_block (struct dwarf2_cu
*cu
)
8746 struct dwarf_block
*blk
;
8748 blk
= (struct dwarf_block
*)
8749 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
8753 static struct abbrev_info
*
8754 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
8756 struct abbrev_info
*abbrev
;
8758 abbrev
= (struct abbrev_info
*)
8759 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
8760 memset (abbrev
, 0, sizeof (struct abbrev_info
));
8764 static struct die_info
*
8765 dwarf_alloc_die (void)
8767 struct die_info
*die
;
8769 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
8770 memset (die
, 0, sizeof (struct die_info
));
8775 /* Macro support. */
8778 /* Return the full name of file number I in *LH's file name table.
8779 Use COMP_DIR as the name of the current directory of the
8780 compilation. The result is allocated using xmalloc; the caller is
8781 responsible for freeing it. */
8783 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
8785 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
8787 if (IS_ABSOLUTE_PATH (fe
->name
))
8788 return xstrdup (fe
->name
);
8796 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8802 dir_len
= strlen (dir
);
8803 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
8804 strcpy (full_name
, dir
);
8805 full_name
[dir_len
] = '/';
8806 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
8810 return xstrdup (fe
->name
);
8815 static struct macro_source_file
*
8816 macro_start_file (int file
, int line
,
8817 struct macro_source_file
*current_file
,
8818 const char *comp_dir
,
8819 struct line_header
*lh
, struct objfile
*objfile
)
8821 /* The full name of this source file. */
8822 char *full_name
= file_full_name (file
, lh
, comp_dir
);
8824 /* We don't create a macro table for this compilation unit
8825 at all until we actually get a filename. */
8826 if (! pending_macros
)
8827 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
8828 objfile
->macro_cache
);
8831 /* If we have no current file, then this must be the start_file
8832 directive for the compilation unit's main source file. */
8833 current_file
= macro_set_main (pending_macros
, full_name
);
8835 current_file
= macro_include (current_file
, line
, full_name
);
8839 return current_file
;
8843 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
8844 followed by a null byte. */
8846 copy_string (const char *buf
, int len
)
8848 char *s
= xmalloc (len
+ 1);
8849 memcpy (s
, buf
, len
);
8857 consume_improper_spaces (const char *p
, const char *body
)
8861 complaint (&symfile_complaints
,
8862 "macro definition contains spaces in formal argument list:\n`%s'",
8874 parse_macro_definition (struct macro_source_file
*file
, int line
,
8879 /* The body string takes one of two forms. For object-like macro
8880 definitions, it should be:
8882 <macro name> " " <definition>
8884 For function-like macro definitions, it should be:
8886 <macro name> "() " <definition>
8888 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
8890 Spaces may appear only where explicitly indicated, and in the
8893 The Dwarf 2 spec says that an object-like macro's name is always
8894 followed by a space, but versions of GCC around March 2002 omit
8895 the space when the macro's definition is the empty string.
8897 The Dwarf 2 spec says that there should be no spaces between the
8898 formal arguments in a function-like macro's formal argument list,
8899 but versions of GCC around March 2002 include spaces after the
8903 /* Find the extent of the macro name. The macro name is terminated
8904 by either a space or null character (for an object-like macro) or
8905 an opening paren (for a function-like macro). */
8906 for (p
= body
; *p
; p
++)
8907 if (*p
== ' ' || *p
== '(')
8910 if (*p
== ' ' || *p
== '\0')
8912 /* It's an object-like macro. */
8913 int name_len
= p
- body
;
8914 char *name
= copy_string (body
, name_len
);
8915 const char *replacement
;
8918 replacement
= body
+ name_len
+ 1;
8921 dwarf2_macro_malformed_definition_complaint (body
);
8922 replacement
= body
+ name_len
;
8925 macro_define_object (file
, line
, name
, replacement
);
8931 /* It's a function-like macro. */
8932 char *name
= copy_string (body
, p
- body
);
8935 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
8939 p
= consume_improper_spaces (p
, body
);
8941 /* Parse the formal argument list. */
8942 while (*p
&& *p
!= ')')
8944 /* Find the extent of the current argument name. */
8945 const char *arg_start
= p
;
8947 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
8950 if (! *p
|| p
== arg_start
)
8951 dwarf2_macro_malformed_definition_complaint (body
);
8954 /* Make sure argv has room for the new argument. */
8955 if (argc
>= argv_size
)
8958 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
8961 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
8964 p
= consume_improper_spaces (p
, body
);
8966 /* Consume the comma, if present. */
8971 p
= consume_improper_spaces (p
, body
);
8980 /* Perfectly formed definition, no complaints. */
8981 macro_define_function (file
, line
, name
,
8982 argc
, (const char **) argv
,
8984 else if (*p
== '\0')
8986 /* Complain, but do define it. */
8987 dwarf2_macro_malformed_definition_complaint (body
);
8988 macro_define_function (file
, line
, name
,
8989 argc
, (const char **) argv
,
8993 /* Just complain. */
8994 dwarf2_macro_malformed_definition_complaint (body
);
8997 /* Just complain. */
8998 dwarf2_macro_malformed_definition_complaint (body
);
9004 for (i
= 0; i
< argc
; i
++)
9010 dwarf2_macro_malformed_definition_complaint (body
);
9015 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
9016 char *comp_dir
, bfd
*abfd
,
9017 struct dwarf2_cu
*cu
)
9019 char *mac_ptr
, *mac_end
;
9020 struct macro_source_file
*current_file
= 0;
9022 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
9024 complaint (&symfile_complaints
, "missing .debug_macinfo section");
9028 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
9029 mac_end
= dwarf2_per_objfile
->macinfo_buffer
9030 + dwarf2_per_objfile
->macinfo_size
;
9034 enum dwarf_macinfo_record_type macinfo_type
;
9036 /* Do we at least have room for a macinfo type byte? */
9037 if (mac_ptr
>= mac_end
)
9039 dwarf2_macros_too_long_complaint ();
9043 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
9046 switch (macinfo_type
)
9048 /* A zero macinfo type indicates the end of the macro
9053 case DW_MACINFO_define
:
9054 case DW_MACINFO_undef
:
9060 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9061 mac_ptr
+= bytes_read
;
9062 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
9063 mac_ptr
+= bytes_read
;
9066 complaint (&symfile_complaints
,
9067 "debug info gives macro %s outside of any file: %s",
9069 DW_MACINFO_define
? "definition" : macinfo_type
==
9070 DW_MACINFO_undef
? "undefinition" :
9071 "something-or-other", body
);
9074 if (macinfo_type
== DW_MACINFO_define
)
9075 parse_macro_definition (current_file
, line
, body
);
9076 else if (macinfo_type
== DW_MACINFO_undef
)
9077 macro_undef (current_file
, line
, body
);
9082 case DW_MACINFO_start_file
:
9087 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9088 mac_ptr
+= bytes_read
;
9089 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9090 mac_ptr
+= bytes_read
;
9092 current_file
= macro_start_file (file
, line
,
9093 current_file
, comp_dir
,
9098 case DW_MACINFO_end_file
:
9100 complaint (&symfile_complaints
,
9101 "macro debug info has an unmatched `close_file' directive");
9104 current_file
= current_file
->included_by
;
9107 enum dwarf_macinfo_record_type next_type
;
9109 /* GCC circa March 2002 doesn't produce the zero
9110 type byte marking the end of the compilation
9111 unit. Complain if it's not there, but exit no
9114 /* Do we at least have room for a macinfo type byte? */
9115 if (mac_ptr
>= mac_end
)
9117 dwarf2_macros_too_long_complaint ();
9121 /* We don't increment mac_ptr here, so this is just
9123 next_type
= read_1_byte (abfd
, mac_ptr
);
9125 complaint (&symfile_complaints
,
9126 "no terminating 0-type entry for macros in `.debug_macinfo' section");
9133 case DW_MACINFO_vendor_ext
:
9139 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9140 mac_ptr
+= bytes_read
;
9141 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
9142 mac_ptr
+= bytes_read
;
9144 /* We don't recognize any vendor extensions. */
9151 /* Check if the attribute's form is a DW_FORM_block*
9152 if so return true else false. */
9154 attr_form_is_block (struct attribute
*attr
)
9156 return (attr
== NULL
? 0 :
9157 attr
->form
== DW_FORM_block1
9158 || attr
->form
== DW_FORM_block2
9159 || attr
->form
== DW_FORM_block4
9160 || attr
->form
== DW_FORM_block
);
9164 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
9165 struct dwarf2_cu
*cu
)
9167 if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
9169 struct dwarf2_loclist_baton
*baton
;
9171 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9172 sizeof (struct dwarf2_loclist_baton
));
9173 baton
->objfile
= cu
->objfile
;
9175 /* We don't know how long the location list is, but make sure we
9176 don't run off the edge of the section. */
9177 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
9178 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
9179 baton
->base_address
= cu
->header
.base_address
;
9180 if (cu
->header
.base_known
== 0)
9181 complaint (&symfile_complaints
,
9182 "Location list used without specifying the CU base address.");
9184 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
9185 SYMBOL_LOCATION_BATON (sym
) = baton
;
9189 struct dwarf2_locexpr_baton
*baton
;
9191 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9192 sizeof (struct dwarf2_locexpr_baton
));
9193 baton
->objfile
= cu
->objfile
;
9195 if (attr_form_is_block (attr
))
9197 /* Note that we're just copying the block's data pointer
9198 here, not the actual data. We're still pointing into the
9199 info_buffer for SYM's objfile; right now we never release
9200 that buffer, but when we do clean up properly this may
9202 baton
->size
= DW_BLOCK (attr
)->size
;
9203 baton
->data
= DW_BLOCK (attr
)->data
;
9207 dwarf2_invalid_attrib_class_complaint ("location description",
9208 SYMBOL_NATURAL_NAME (sym
));
9213 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
9214 SYMBOL_LOCATION_BATON (sym
) = baton
;
9218 /* Locate the compilation unit from CU's objfile which contains the
9219 DIE at OFFSET. Raises an error on failure. */
9221 static struct dwarf2_per_cu_data
*
9222 dwarf2_find_containing_comp_unit (unsigned long offset
,
9223 struct objfile
*objfile
)
9225 struct dwarf2_per_cu_data
*this_cu
;
9229 high
= dwarf2_per_objfile
->n_comp_units
- 1;
9232 int mid
= low
+ (high
- low
) / 2;
9233 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
9238 gdb_assert (low
== high
);
9239 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
9242 error ("Dwarf Error: could not find partial DIE containing "
9243 "offset 0x%lx [in module %s]",
9244 (long) offset
, bfd_get_filename (objfile
->obfd
));
9246 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
9247 return dwarf2_per_objfile
->all_comp_units
[low
-1];
9251 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
9252 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
9253 && offset
>= this_cu
->offset
+ this_cu
->length
)
9254 error ("invalid dwarf2 offset %ld", offset
);
9255 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
9260 /* Locate the compilation unit from OBJFILE which is located at exactly
9261 OFFSET. Raises an error on failure. */
9263 static struct dwarf2_per_cu_data
*
9264 dwarf2_find_comp_unit (unsigned long offset
, struct objfile
*objfile
)
9266 struct dwarf2_per_cu_data
*this_cu
;
9267 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
9268 if (this_cu
->offset
!= offset
)
9269 error ("no compilation unit with offset %ld\n", offset
);
9273 /* Release one cached compilation unit, CU. We unlink it from the tree
9274 of compilation units, but we don't remove it from the read_in_chain;
9275 the caller is responsible for that. */
9278 free_one_comp_unit (void *data
)
9280 struct dwarf2_cu
*cu
= data
;
9282 if (cu
->per_cu
!= NULL
)
9283 cu
->per_cu
->cu
= NULL
;
9286 obstack_free (&cu
->comp_unit_obstack
, NULL
);
9288 free_die_list (cu
->dies
);
9293 /* This cleanup function is passed the address of a dwarf2_cu on the stack
9294 when we're finished with it. We can't free the pointer itself, but be
9295 sure to unlink it from the cache. Also release any associated storage
9296 and perform cache maintenance.
9298 Only used during partial symbol parsing. */
9301 free_stack_comp_unit (void *data
)
9303 struct dwarf2_cu
*cu
= data
;
9305 obstack_free (&cu
->comp_unit_obstack
, NULL
);
9306 cu
->partial_dies
= NULL
;
9308 if (cu
->per_cu
!= NULL
)
9310 /* This compilation unit is on the stack in our caller, so we
9311 should not xfree it. Just unlink it. */
9312 cu
->per_cu
->cu
= NULL
;
9315 /* If we had a per-cu pointer, then we may have other compilation
9316 units loaded, so age them now. */
9317 age_cached_comp_units ();
9321 /* Free all cached compilation units. */
9324 free_cached_comp_units (void *data
)
9326 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
9328 per_cu
= dwarf2_per_objfile
->read_in_chain
;
9329 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
9330 while (per_cu
!= NULL
)
9332 struct dwarf2_per_cu_data
*next_cu
;
9334 next_cu
= per_cu
->cu
->read_in_chain
;
9336 free_one_comp_unit (per_cu
->cu
);
9337 *last_chain
= next_cu
;
9343 /* Increase the age counter on each cached compilation unit, and free
9344 any that are too old. */
9347 age_cached_comp_units (void)
9349 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
9351 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
9352 per_cu
= dwarf2_per_objfile
->read_in_chain
;
9353 while (per_cu
!= NULL
)
9355 per_cu
->cu
->last_used
++;
9356 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
9357 dwarf2_mark (per_cu
->cu
);
9358 per_cu
= per_cu
->cu
->read_in_chain
;
9361 per_cu
= dwarf2_per_objfile
->read_in_chain
;
9362 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
9363 while (per_cu
!= NULL
)
9365 struct dwarf2_per_cu_data
*next_cu
;
9367 next_cu
= per_cu
->cu
->read_in_chain
;
9369 if (!per_cu
->cu
->mark
)
9371 free_one_comp_unit (per_cu
->cu
);
9372 *last_chain
= next_cu
;
9375 last_chain
= &per_cu
->cu
->read_in_chain
;
9381 /* Remove a single compilation unit from the cache. */
9384 free_one_cached_comp_unit (void *target_cu
)
9386 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
9388 per_cu
= dwarf2_per_objfile
->read_in_chain
;
9389 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
9390 while (per_cu
!= NULL
)
9392 struct dwarf2_per_cu_data
*next_cu
;
9394 next_cu
= per_cu
->cu
->read_in_chain
;
9396 if (per_cu
->cu
== target_cu
)
9398 free_one_comp_unit (per_cu
->cu
);
9399 *last_chain
= next_cu
;
9403 last_chain
= &per_cu
->cu
->read_in_chain
;
9409 /* A pair of DIE offset and GDB type pointer. We store these
9410 in a hash table separate from the DIEs, and preserve them
9411 when the DIEs are flushed out of cache. */
9413 struct dwarf2_offset_and_type
9415 unsigned int offset
;
9419 /* Hash function for a dwarf2_offset_and_type. */
9422 offset_and_type_hash (const void *item
)
9424 const struct dwarf2_offset_and_type
*ofs
= item
;
9428 /* Equality function for a dwarf2_offset_and_type. */
9431 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
9433 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
9434 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
9435 return ofs_lhs
->offset
== ofs_rhs
->offset
;
9438 /* Set the type associated with DIE to TYPE. Save it in CU's hash
9439 table if necessary. */
9442 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
9444 struct dwarf2_offset_and_type
**slot
, ofs
;
9448 if (cu
->per_cu
== NULL
)
9451 if (cu
->per_cu
->type_hash
== NULL
)
9452 cu
->per_cu
->type_hash
9453 = htab_create_alloc_ex (cu
->header
.length
/ 24,
9454 offset_and_type_hash
,
9457 &cu
->objfile
->objfile_obstack
,
9458 hashtab_obstack_allocate
,
9459 dummy_obstack_deallocate
);
9461 ofs
.offset
= die
->offset
;
9463 slot
= (struct dwarf2_offset_and_type
**)
9464 htab_find_slot_with_hash (cu
->per_cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
9465 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
9469 /* Find the type for DIE in TYPE_HASH, or return NULL if DIE does not
9470 have a saved type. */
9472 static struct type
*
9473 get_die_type (struct die_info
*die
, htab_t type_hash
)
9475 struct dwarf2_offset_and_type
*slot
, ofs
;
9477 ofs
.offset
= die
->offset
;
9478 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
9485 /* Restore the types of the DIE tree starting at START_DIE from the hash
9486 table saved in CU. */
9489 reset_die_and_siblings_types (struct die_info
*start_die
, struct dwarf2_cu
*cu
)
9491 struct die_info
*die
;
9493 if (cu
->per_cu
->type_hash
== NULL
)
9496 for (die
= start_die
; die
!= NULL
; die
= die
->sibling
)
9498 die
->type
= get_die_type (die
, cu
->per_cu
->type_hash
);
9499 if (die
->child
!= NULL
)
9500 reset_die_and_siblings_types (die
->child
, cu
);
9504 /* Set the mark field in CU and in every other compilation unit in the
9505 cache that we must keep because we are keeping CU. */
9507 /* Add a dependence relationship from CU to REF_PER_CU. */
9510 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
9511 struct dwarf2_per_cu_data
*ref_per_cu
)
9515 if (cu
->dependencies
== NULL
)
9517 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
9518 NULL
, &cu
->comp_unit_obstack
,
9519 hashtab_obstack_allocate
,
9520 dummy_obstack_deallocate
);
9522 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
9527 /* Set the mark field in CU and in every other compilation unit in the
9528 cache that we must keep because we are keeping CU. */
9531 dwarf2_mark_helper (void **slot
, void *data
)
9533 struct dwarf2_per_cu_data
*per_cu
;
9535 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
9536 if (per_cu
->cu
->mark
)
9538 per_cu
->cu
->mark
= 1;
9540 if (per_cu
->cu
->dependencies
!= NULL
)
9541 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
9547 dwarf2_mark (struct dwarf2_cu
*cu
)
9552 if (cu
->dependencies
!= NULL
)
9553 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
9557 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
9561 per_cu
->cu
->mark
= 0;
9562 per_cu
= per_cu
->cu
->read_in_chain
;
9566 /* Allocation function for the libiberty hash table which uses an
9570 hashtab_obstack_allocate (void *data
, size_t size
, size_t count
)
9572 unsigned int total
= size
* count
;
9573 void *ptr
= obstack_alloc ((struct obstack
*) data
, total
);
9574 memset (ptr
, 0, total
);
9578 /* Trivial deallocation function for the libiberty splay tree and hash
9579 table - don't deallocate anything. Rely on later deletion of the
9583 dummy_obstack_deallocate (void *object
, void *data
)
9588 /* Trivial hash function for partial_die_info: the hash value of a DIE
9589 is its offset in .debug_info for this objfile. */
9592 partial_die_hash (const void *item
)
9594 const struct partial_die_info
*part_die
= item
;
9595 return part_die
->offset
;
9598 /* Trivial comparison function for partial_die_info structures: two DIEs
9599 are equal if they have the same offset. */
9602 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
9604 const struct partial_die_info
*part_die_lhs
= item_lhs
;
9605 const struct partial_die_info
*part_die_rhs
= item_rhs
;
9606 return part_die_lhs
->offset
== part_die_rhs
->offset
;
9609 static struct cmd_list_element
*set_dwarf2_cmdlist
;
9610 static struct cmd_list_element
*show_dwarf2_cmdlist
;
9613 set_dwarf2_cmd (char *args
, int from_tty
)
9615 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
9619 show_dwarf2_cmd (char *args
, int from_tty
)
9621 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
9624 void _initialize_dwarf2_read (void);
9627 _initialize_dwarf2_read (void)
9629 dwarf2_objfile_data_key
= register_objfile_data ();
9631 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
,
9632 "Set DWARF 2 specific variables.\n"
9633 "Configure DWARF 2 variables such as the cache size",
9634 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
9635 0/*allow-unknown*/, &maintenance_set_cmdlist
);
9637 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
,
9638 "Show DWARF 2 specific variables\n"
9639 "Show DWARF 2 variables such as the cache size",
9640 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
9641 0/*allow-unknown*/, &maintenance_show_cmdlist
);
9643 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
9644 &dwarf2_max_cache_age
,
9645 "Set the upper bound on the age of cached "
9646 "dwarf2 compilation units.",
9647 "Show the upper bound on the age of cached "
9648 "dwarf2 compilation units.",
9649 "A higher limit means that cached "
9650 "compilation units will be stored\n"
9651 "in memory longer, and more total memory will "
9652 "be used. Zero disables\n"
9653 "caching, which can slow down startup.",
9654 "The upper bound on the age of cached "
9655 "dwarf2 compilation units is %d.",
9656 NULL
, NULL
, &set_dwarf2_cmdlist
,
9657 &show_dwarf2_cmdlist
);