1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009
5 Free Software Foundation, Inc.
7 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
8 Inc. with support from Florida State University (under contract
9 with the Ada Joint Program Office), and Silicon Graphics, Inc.
10 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
11 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
14 This file is part of GDB.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>. */
34 #include "elf/dwarf2.h"
37 #include "expression.h"
38 #include "filenames.h" /* for DOSish file names */
41 #include "complaints.h"
43 #include "dwarf2expr.h"
44 #include "dwarf2loc.h"
45 #include "cp-support.h"
52 #include "gdb_string.h"
53 #include "gdb_assert.h"
54 #include <sys/types.h>
59 /* A note on memory usage for this file.
61 At the present time, this code reads the debug info sections into
62 the objfile's objfile_obstack. A definite improvement for startup
63 time, on platforms which do not emit relocations for debug
64 sections, would be to use mmap instead. The object's complete
65 debug information is loaded into memory, partly to simplify
66 absolute DIE references.
68 Whether using obstacks or mmap, the sections should remain loaded
69 until the objfile is released, and pointers into the section data
70 can be used for any other data associated to the objfile (symbol
71 names, type names, location expressions to name a few). */
74 /* .debug_info header for a compilation unit
75 Because of alignment constraints, this structure has padding and cannot
76 be mapped directly onto the beginning of the .debug_info section. */
77 typedef struct comp_unit_header
79 unsigned int length
; /* length of the .debug_info
81 unsigned short version
; /* version number -- 2 for DWARF
83 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
84 unsigned char addr_size
; /* byte size of an address -- 4 */
87 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
90 /* .debug_pubnames header
91 Because of alignment constraints, this structure has padding and cannot
92 be mapped directly onto the beginning of the .debug_info section. */
93 typedef struct pubnames_header
95 unsigned int length
; /* length of the .debug_pubnames
97 unsigned char version
; /* version number -- 2 for DWARF
99 unsigned int info_offset
; /* offset into .debug_info section */
100 unsigned int info_size
; /* byte size of .debug_info section
104 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
106 /* .debug_pubnames header
107 Because of alignment constraints, this structure has padding and cannot
108 be mapped directly onto the beginning of the .debug_info section. */
109 typedef struct aranges_header
111 unsigned int length
; /* byte len of the .debug_aranges
113 unsigned short version
; /* version number -- 2 for DWARF
115 unsigned int info_offset
; /* offset into .debug_info section */
116 unsigned char addr_size
; /* byte size of an address */
117 unsigned char seg_size
; /* byte size of segment descriptor */
120 #define _ACTUAL_ARANGES_HEADER_SIZE 12
122 /* .debug_line statement program prologue
123 Because of alignment constraints, this structure has padding and cannot
124 be mapped directly onto the beginning of the .debug_info section. */
125 typedef struct statement_prologue
127 unsigned int total_length
; /* byte length of the statement
129 unsigned short version
; /* version number -- 2 for DWARF
131 unsigned int prologue_length
; /* # bytes between prologue &
133 unsigned char minimum_instruction_length
; /* byte size of
135 unsigned char default_is_stmt
; /* initial value of is_stmt
138 unsigned char line_range
;
139 unsigned char opcode_base
; /* number assigned to first special
141 unsigned char *standard_opcode_lengths
;
145 /* When non-zero, dump DIEs after they are read in. */
146 static int dwarf2_die_debug
= 0;
148 /* When set, the file that we're processing is known to have debugging
149 info for C++ namespaces. GCC 3.3.x did not produce this information,
150 but later versions do. */
152 static int processing_has_namespace_info
;
154 static const struct objfile_data
*dwarf2_objfile_data_key
;
156 struct dwarf2_per_objfile
158 /* Sizes of debugging sections. */
159 unsigned int info_size
;
160 unsigned int abbrev_size
;
161 unsigned int line_size
;
162 unsigned int pubnames_size
;
163 unsigned int aranges_size
;
164 unsigned int loc_size
;
165 unsigned int macinfo_size
;
166 unsigned int str_size
;
167 unsigned int ranges_size
;
168 unsigned int frame_size
;
169 unsigned int eh_frame_size
;
171 /* Loaded data from the sections. */
172 gdb_byte
*info_buffer
;
173 gdb_byte
*abbrev_buffer
;
174 gdb_byte
*line_buffer
;
175 gdb_byte
*str_buffer
;
176 gdb_byte
*macinfo_buffer
;
177 gdb_byte
*ranges_buffer
;
178 gdb_byte
*loc_buffer
;
180 /* A list of all the compilation units. This is used to locate
181 the target compilation unit of a particular reference. */
182 struct dwarf2_per_cu_data
**all_comp_units
;
184 /* The number of compilation units in ALL_COMP_UNITS. */
187 /* A chain of compilation units that are currently read in, so that
188 they can be freed later. */
189 struct dwarf2_per_cu_data
*read_in_chain
;
191 /* A flag indicating wether this objfile has a section loaded at a
193 int has_section_at_zero
;
196 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
198 static asection
*dwarf_info_section
;
199 static asection
*dwarf_abbrev_section
;
200 static asection
*dwarf_line_section
;
201 static asection
*dwarf_pubnames_section
;
202 static asection
*dwarf_aranges_section
;
203 static asection
*dwarf_loc_section
;
204 static asection
*dwarf_macinfo_section
;
205 static asection
*dwarf_str_section
;
206 static asection
*dwarf_ranges_section
;
207 asection
*dwarf_frame_section
;
208 asection
*dwarf_eh_frame_section
;
210 /* names of the debugging sections */
212 /* Note that if the debugging section has been compressed, it might
213 have a name like .zdebug_info. */
215 #define INFO_SECTION "debug_info"
216 #define ABBREV_SECTION "debug_abbrev"
217 #define LINE_SECTION "debug_line"
218 #define PUBNAMES_SECTION "debug_pubnames"
219 #define ARANGES_SECTION "debug_aranges"
220 #define LOC_SECTION "debug_loc"
221 #define MACINFO_SECTION "debug_macinfo"
222 #define STR_SECTION "debug_str"
223 #define RANGES_SECTION "debug_ranges"
224 #define FRAME_SECTION "debug_frame"
225 #define EH_FRAME_SECTION "eh_frame"
227 /* local data types */
229 /* We hold several abbreviation tables in memory at the same time. */
230 #ifndef ABBREV_HASH_SIZE
231 #define ABBREV_HASH_SIZE 121
234 /* The data in a compilation unit header, after target2host
235 translation, looks like this. */
236 struct comp_unit_head
240 unsigned char addr_size
;
241 unsigned char signed_addr_p
;
242 unsigned int abbrev_offset
;
244 /* Size of file offsets; either 4 or 8. */
245 unsigned int offset_size
;
247 /* Size of the length field; either 4 or 12. */
248 unsigned int initial_length_size
;
250 /* Offset to the first byte of this compilation unit header in the
251 .debug_info section, for resolving relative reference dies. */
254 /* Offset to first die in this cu from the start of the cu.
255 This will be the first byte following the compilation unit header. */
256 unsigned int first_die_offset
;
259 /* Internal state when decoding a particular compilation unit. */
262 /* The objfile containing this compilation unit. */
263 struct objfile
*objfile
;
265 /* The header of the compilation unit. */
266 struct comp_unit_head header
;
268 /* Base address of this compilation unit. */
269 CORE_ADDR base_address
;
271 /* Non-zero if base_address has been set. */
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 /* DWARF abbreviation table associated with this compilation unit. */
294 struct abbrev_info
**dwarf2_abbrevs
;
296 /* Storage for the abbrev table. */
297 struct obstack abbrev_obstack
;
299 /* Hash table holding all the loaded partial DIEs. */
302 /* `.debug_ranges' offset for this `DW_TAG_compile_unit' DIE. */
303 unsigned int ranges_offset
;
305 /* Storage for things with the same lifetime as this read-in compilation
306 unit, including partial DIEs. */
307 struct obstack comp_unit_obstack
;
309 /* When multiple dwarf2_cu structures are living in memory, this field
310 chains them all together, so that they can be released efficiently.
311 We will probably also want a generation counter so that most-recently-used
312 compilation units are cached... */
313 struct dwarf2_per_cu_data
*read_in_chain
;
315 /* Backchain to our per_cu entry if the tree has been built. */
316 struct dwarf2_per_cu_data
*per_cu
;
318 /* Pointer to the die -> type map. Although it is stored
319 permanently in per_cu, we copy it here to avoid double
323 /* How many compilation units ago was this CU last referenced? */
326 /* A hash table of die offsets for following references. */
329 /* Full DIEs if read in. */
330 struct die_info
*dies
;
332 /* A set of pointers to dwarf2_per_cu_data objects for compilation
333 units referenced by this one. Only set during full symbol processing;
334 partial symbol tables do not have dependencies. */
337 /* Header data from the line table, during full symbol processing. */
338 struct line_header
*line_header
;
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;
353 /* Field `ranges_offset' is filled in; flag as the value may be zero. */
354 unsigned int has_ranges_offset
: 1;
357 /* Persistent data held for a compilation unit, even when not
358 processing it. We put a pointer to this structure in the
359 read_symtab_private field of the psymtab. If we encounter
360 inter-compilation-unit references, we also maintain a sorted
361 list of all compilation units. */
363 struct dwarf2_per_cu_data
365 /* The start offset and length of this compilation unit. 2**30-1
366 bytes should suffice to store the length of any compilation unit
367 - if it doesn't, GDB will fall over anyway.
368 NOTE: Unlike comp_unit_head.length, this length includes
369 initial_length_size. */
371 unsigned int length
: 30;
373 /* Flag indicating this compilation unit will be read in before
374 any of the current compilation units are processed. */
375 unsigned int queued
: 1;
377 /* This flag will be set if we need to load absolutely all DIEs
378 for this compilation unit, instead of just the ones we think
379 are interesting. It gets set if we look for a DIE in the
380 hash table and don't find it. */
381 unsigned int load_all_dies
: 1;
383 /* Set iff currently read in. */
384 struct dwarf2_cu
*cu
;
386 /* If full symbols for this CU have been read in, then this field
387 holds a map of DIE offsets to types. It isn't always possible
388 to reconstruct this information later, so we have to preserve
392 /* The partial symbol table associated with this compilation unit,
393 or NULL for partial units (which do not have an associated
395 struct partial_symtab
*psymtab
;
398 /* The line number information for a compilation unit (found in the
399 .debug_line section) begins with a "statement program header",
400 which contains the following information. */
403 unsigned int total_length
;
404 unsigned short version
;
405 unsigned int header_length
;
406 unsigned char minimum_instruction_length
;
407 unsigned char default_is_stmt
;
409 unsigned char line_range
;
410 unsigned char opcode_base
;
412 /* standard_opcode_lengths[i] is the number of operands for the
413 standard opcode whose value is i. This means that
414 standard_opcode_lengths[0] is unused, and the last meaningful
415 element is standard_opcode_lengths[opcode_base - 1]. */
416 unsigned char *standard_opcode_lengths
;
418 /* The include_directories table. NOTE! These strings are not
419 allocated with xmalloc; instead, they are pointers into
420 debug_line_buffer. If you try to free them, `free' will get
422 unsigned int num_include_dirs
, include_dirs_size
;
425 /* The file_names table. NOTE! These strings are not allocated
426 with xmalloc; instead, they are pointers into debug_line_buffer.
427 Don't try to free them directly. */
428 unsigned int num_file_names
, file_names_size
;
432 unsigned int dir_index
;
433 unsigned int mod_time
;
435 int included_p
; /* Non-zero if referenced by the Line Number Program. */
436 struct symtab
*symtab
; /* The associated symbol table, if any. */
439 /* The start and end of the statement program following this
440 header. These point into dwarf2_per_objfile->line_buffer. */
441 gdb_byte
*statement_program_start
, *statement_program_end
;
444 /* When we construct a partial symbol table entry we only
445 need this much information. */
446 struct partial_die_info
448 /* Offset of this DIE. */
451 /* DWARF-2 tag for this DIE. */
452 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
454 /* Language code associated with this DIE. This is only used
455 for the compilation unit DIE. */
456 unsigned int language
: 8;
458 /* Assorted flags describing the data found in this DIE. */
459 unsigned int has_children
: 1;
460 unsigned int is_external
: 1;
461 unsigned int is_declaration
: 1;
462 unsigned int has_type
: 1;
463 unsigned int has_specification
: 1;
464 unsigned int has_stmt_list
: 1;
465 unsigned int has_pc_info
: 1;
467 /* Flag set if the SCOPE field of this structure has been
469 unsigned int scope_set
: 1;
471 /* Flag set if the DIE has a byte_size attribute. */
472 unsigned int has_byte_size
: 1;
474 /* The name of this DIE. Normally the value of DW_AT_name, but
475 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
480 /* The scope to prepend to our children. This is generally
481 allocated on the comp_unit_obstack, so will disappear
482 when this compilation unit leaves the cache. */
485 /* The location description associated with this DIE, if any. */
486 struct dwarf_block
*locdesc
;
488 /* If HAS_PC_INFO, the PC range associated with this DIE. */
492 /* Pointer into the info_buffer pointing at the target of
493 DW_AT_sibling, if any. */
496 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
497 DW_AT_specification (or DW_AT_abstract_origin or
499 unsigned int spec_offset
;
501 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
502 unsigned int line_offset
;
504 /* Pointers to this DIE's parent, first child, and next sibling,
506 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
509 /* This data structure holds the information of an abbrev. */
512 unsigned int number
; /* number identifying abbrev */
513 enum dwarf_tag tag
; /* dwarf tag */
514 unsigned short has_children
; /* boolean */
515 unsigned short num_attrs
; /* number of attributes */
516 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
517 struct abbrev_info
*next
; /* next in chain */
522 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
523 ENUM_BITFIELD(dwarf_form
) form
: 16;
526 /* Additional GDB-specific attribute forms. */
529 /* A string which has been updated to GDB's internal
530 representation (e.g. converted to canonical form) and does not
531 need to be updated again. */
532 GDB_FORM_cached_string
= 0xff
535 /* Attributes have a name and a value */
538 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
539 ENUM_BITFIELD(dwarf_form
) form
: 16;
543 struct dwarf_block
*blk
;
551 /* This data structure holds a complete die structure. */
554 /* DWARF-2 tag for this DIE. */
555 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
557 /* Number of attributes */
558 unsigned short num_attrs
;
563 /* Offset in .debug_info section */
566 /* The dies in a compilation unit form an n-ary tree. PARENT
567 points to this die's parent; CHILD points to the first child of
568 this node; and all the children of a given node are chained
569 together via their SIBLING fields, terminated by a die whose
571 struct die_info
*child
; /* Its first child, if any. */
572 struct die_info
*sibling
; /* Its next sibling, if any. */
573 struct die_info
*parent
; /* Its parent, if any. */
575 /* An array of attributes, with NUM_ATTRS elements. There may be
576 zero, but it's not common and zero-sized arrays are not
577 sufficiently portable C. */
578 struct attribute attrs
[1];
581 struct function_range
584 CORE_ADDR lowpc
, highpc
;
586 struct function_range
*next
;
589 /* Get at parts of an attribute structure */
591 #define DW_STRING(attr) ((attr)->u.str)
592 #define DW_UNSND(attr) ((attr)->u.unsnd)
593 #define DW_BLOCK(attr) ((attr)->u.blk)
594 #define DW_SND(attr) ((attr)->u.snd)
595 #define DW_ADDR(attr) ((attr)->u.addr)
597 /* Blocks are a bunch of untyped bytes. */
604 #ifndef ATTR_ALLOC_CHUNK
605 #define ATTR_ALLOC_CHUNK 4
608 /* Allocate fields for structs, unions and enums in this size. */
609 #ifndef DW_FIELD_ALLOC_CHUNK
610 #define DW_FIELD_ALLOC_CHUNK 4
613 /* A zeroed version of a partial die for initialization purposes. */
614 static struct partial_die_info zeroed_partial_die
;
616 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
617 but this would require a corresponding change in unpack_field_as_long
619 static int bits_per_byte
= 8;
621 /* The routines that read and process dies for a C struct or C++ class
622 pass lists of data member fields and lists of member function fields
623 in an instance of a field_info structure, as defined below. */
626 /* List of data member and baseclasses fields. */
629 struct nextfield
*next
;
636 /* Number of fields. */
639 /* Number of baseclasses. */
642 /* Set if the accesibility of one of the fields is not public. */
643 int non_public_fields
;
645 /* Member function fields array, entries are allocated in the order they
646 are encountered in the object file. */
649 struct nextfnfield
*next
;
650 struct fn_field fnfield
;
654 /* Member function fieldlist array, contains name of possibly overloaded
655 member function, number of overloaded member functions and a pointer
656 to the head of the member function field chain. */
661 struct nextfnfield
*head
;
665 /* Number of entries in the fnfieldlists array. */
669 /* One item on the queue of compilation units to read in full symbols
671 struct dwarf2_queue_item
673 struct dwarf2_per_cu_data
*per_cu
;
674 struct dwarf2_queue_item
*next
;
677 /* The current queue. */
678 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
680 /* Loaded secondary compilation units are kept in memory until they
681 have not been referenced for the processing of this many
682 compilation units. Set this to zero to disable caching. Cache
683 sizes of up to at least twenty will improve startup time for
684 typical inter-CU-reference binaries, at an obvious memory cost. */
685 static int dwarf2_max_cache_age
= 5;
687 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
688 struct cmd_list_element
*c
, const char *value
)
690 fprintf_filtered (file
, _("\
691 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
696 /* Various complaints about symbol reading that don't abort the process */
699 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
701 complaint (&symfile_complaints
,
702 _("statement list doesn't fit in .debug_line section"));
706 dwarf2_debug_line_missing_file_complaint (void)
708 complaint (&symfile_complaints
,
709 _(".debug_line section has line data without a file"));
713 dwarf2_debug_line_missing_end_sequence_complaint (void)
715 complaint (&symfile_complaints
,
716 _(".debug_line section has line program sequence without an end"));
720 dwarf2_complex_location_expr_complaint (void)
722 complaint (&symfile_complaints
, _("location expression too complex"));
726 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
729 complaint (&symfile_complaints
,
730 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
735 dwarf2_macros_too_long_complaint (void)
737 complaint (&symfile_complaints
,
738 _("macro info runs off end of `.debug_macinfo' section"));
742 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
744 complaint (&symfile_complaints
,
745 _("macro debug info contains a malformed macro definition:\n`%s'"),
750 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
752 complaint (&symfile_complaints
,
753 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
756 /* local function prototypes */
758 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
761 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
764 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
767 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
768 struct partial_die_info
*,
769 struct partial_symtab
*);
771 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
773 static void scan_partial_symbols (struct partial_die_info
*,
774 CORE_ADDR
*, CORE_ADDR
*,
775 int, struct dwarf2_cu
*);
777 static void add_partial_symbol (struct partial_die_info
*,
780 static int pdi_needs_namespace (enum dwarf_tag tag
);
782 static void add_partial_namespace (struct partial_die_info
*pdi
,
783 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
784 int need_pc
, struct dwarf2_cu
*cu
);
786 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
787 CORE_ADDR
*highpc
, int need_pc
,
788 struct dwarf2_cu
*cu
);
790 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
791 struct dwarf2_cu
*cu
);
793 static void add_partial_subprogram (struct partial_die_info
*pdi
,
794 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
795 int need_pc
, struct dwarf2_cu
*cu
);
797 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
800 struct dwarf2_cu
*cu
);
802 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
804 static void psymtab_to_symtab_1 (struct partial_symtab
*);
806 gdb_byte
*dwarf2_read_section (struct objfile
*, asection
*);
808 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
810 static void dwarf2_free_abbrev_table (void *);
812 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
815 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
818 static struct partial_die_info
*load_partial_dies (bfd
*, gdb_byte
*, int,
821 static gdb_byte
*read_partial_die (struct partial_die_info
*,
822 struct abbrev_info
*abbrev
, unsigned int,
823 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
825 static struct partial_die_info
*find_partial_die (unsigned int,
828 static void fixup_partial_die (struct partial_die_info
*,
831 static gdb_byte
*read_full_die (struct die_info
**, bfd
*, gdb_byte
*,
832 struct dwarf2_cu
*, int *);
834 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
835 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
837 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
838 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
840 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
842 static int read_1_signed_byte (bfd
*, gdb_byte
*);
844 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
846 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
848 static unsigned long read_8_bytes (bfd
*, gdb_byte
*);
850 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
853 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
855 static LONGEST read_checked_initial_length_and_offset
856 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
857 unsigned int *, unsigned int *);
859 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
862 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
864 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
866 static char *read_string (bfd
*, gdb_byte
*, unsigned int *);
868 static char *read_indirect_string (bfd
*, gdb_byte
*,
869 const struct comp_unit_head
*,
872 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
874 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
876 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
878 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
880 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
883 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
884 struct dwarf2_cu
*cu
);
886 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
888 static struct die_info
*die_specification (struct die_info
*die
,
889 struct dwarf2_cu
**);
891 static void free_line_header (struct line_header
*lh
);
893 static void add_file_name (struct line_header
*, char *, unsigned int,
894 unsigned int, unsigned int);
896 static struct line_header
*(dwarf_decode_line_header
897 (unsigned int offset
,
898 bfd
*abfd
, struct dwarf2_cu
*cu
));
900 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
901 struct dwarf2_cu
*, struct partial_symtab
*);
903 static void dwarf2_start_subfile (char *, char *, char *);
905 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
908 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
911 static void dwarf2_const_value_data (struct attribute
*attr
,
915 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
917 static struct type
*die_containing_type (struct die_info
*,
920 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
922 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
924 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
926 static char *typename_concat (struct obstack
*,
931 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
933 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
935 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
937 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
938 struct dwarf2_cu
*, struct partial_symtab
*);
940 static int dwarf2_get_pc_bounds (struct die_info
*,
941 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
943 static void get_scope_pc_bounds (struct die_info
*,
944 CORE_ADDR
*, CORE_ADDR
*,
947 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
948 CORE_ADDR
, struct dwarf2_cu
*);
950 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
953 static void dwarf2_attach_fields_to_type (struct field_info
*,
954 struct type
*, struct dwarf2_cu
*);
956 static void dwarf2_add_member_fn (struct field_info
*,
957 struct die_info
*, struct type
*,
960 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
961 struct type
*, struct dwarf2_cu
*);
963 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
965 static const char *determine_class_name (struct die_info
*die
,
966 struct dwarf2_cu
*cu
);
968 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
970 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
972 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
974 static const char *namespace_name (struct die_info
*die
,
975 int *is_anonymous
, struct dwarf2_cu
*);
977 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
979 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
981 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
984 static struct die_info
*read_comp_unit (gdb_byte
*, bfd
*, struct dwarf2_cu
*);
986 static struct die_info
*read_die_and_children_1 (gdb_byte
*info_ptr
, bfd
*abfd
,
988 gdb_byte
**new_info_ptr
,
989 struct die_info
*parent
);
991 static struct die_info
*read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
993 gdb_byte
**new_info_ptr
,
994 struct die_info
*parent
);
996 static struct die_info
*read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
998 gdb_byte
**new_info_ptr
,
999 struct die_info
*parent
);
1001 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1003 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
1005 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1008 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1010 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1011 struct dwarf2_cu
**);
1013 static char *dwarf_tag_name (unsigned int);
1015 static char *dwarf_attr_name (unsigned int);
1017 static char *dwarf_form_name (unsigned int);
1019 static char *dwarf_stack_op_name (unsigned int);
1021 static char *dwarf_bool_name (unsigned int);
1023 static char *dwarf_type_encoding_name (unsigned int);
1026 static char *dwarf_cfi_name (unsigned int);
1029 static struct die_info
*sibling_die (struct die_info
*);
1031 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1033 static void dump_die_for_error (struct die_info
*);
1035 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1038 /*static*/ void dump_die (struct die_info
*, int max_level
);
1040 static void store_in_ref_table (struct die_info
*,
1041 struct dwarf2_cu
*);
1043 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1045 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
1047 static struct die_info
*follow_die_ref (struct die_info
*,
1049 struct dwarf2_cu
**);
1051 /* memory allocation interface */
1053 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1055 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1057 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1059 static void initialize_cu_func_list (struct dwarf2_cu
*);
1061 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1062 struct dwarf2_cu
*);
1064 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1065 char *, bfd
*, struct dwarf2_cu
*);
1067 static int attr_form_is_block (struct attribute
*);
1069 static int attr_form_is_section_offset (struct attribute
*);
1071 static int attr_form_is_constant (struct attribute
*);
1073 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1075 struct dwarf2_cu
*cu
);
1077 static gdb_byte
*skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
1078 struct dwarf2_cu
*cu
);
1080 static void free_stack_comp_unit (void *);
1082 static hashval_t
partial_die_hash (const void *item
);
1084 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1086 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1087 (unsigned int offset
, struct objfile
*objfile
);
1089 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1090 (unsigned int offset
, struct objfile
*objfile
);
1092 static void free_one_comp_unit (void *);
1094 static void free_cached_comp_units (void *);
1096 static void age_cached_comp_units (void);
1098 static void free_one_cached_comp_unit (void *);
1100 static struct type
*set_die_type (struct die_info
*, struct type
*,
1101 struct dwarf2_cu
*);
1103 static void create_all_comp_units (struct objfile
*);
1105 static struct dwarf2_cu
*load_full_comp_unit (struct dwarf2_per_cu_data
*,
1108 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1110 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1111 struct dwarf2_per_cu_data
*);
1113 static void dwarf2_mark (struct dwarf2_cu
*);
1115 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1117 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1119 /* Try to locate the sections we need for DWARF 2 debugging
1120 information and return true if we have enough to do something. */
1123 dwarf2_has_info (struct objfile
*objfile
)
1125 struct dwarf2_per_objfile
*data
;
1127 /* Initialize per-objfile state. */
1128 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1129 memset (data
, 0, sizeof (*data
));
1130 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1131 dwarf2_per_objfile
= data
;
1133 dwarf_info_section
= 0;
1134 dwarf_abbrev_section
= 0;
1135 dwarf_line_section
= 0;
1136 dwarf_str_section
= 0;
1137 dwarf_macinfo_section
= 0;
1138 dwarf_frame_section
= 0;
1139 dwarf_eh_frame_section
= 0;
1140 dwarf_ranges_section
= 0;
1141 dwarf_loc_section
= 0;
1143 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1144 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
1147 /* When loading sections, we can either look for ".<name>", or for
1148 * ".z<name>", which indicates a compressed section. */
1151 section_is_p (asection
*sectp
, const char *name
)
1153 return ((sectp
->name
[0] == '.'
1154 && strcmp (sectp
->name
+ 1, name
) == 0)
1155 || (sectp
->name
[0] == '.' && sectp
->name
[1] == 'z'
1156 && strcmp (sectp
->name
+ 2, name
) == 0));
1159 /* This function is mapped across the sections and remembers the
1160 offset and size of each of the debugging sections we are interested
1164 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1166 if (section_is_p (sectp
, INFO_SECTION
))
1168 dwarf2_per_objfile
->info_size
= bfd_get_section_size (sectp
);
1169 dwarf_info_section
= sectp
;
1171 else if (section_is_p (sectp
, ABBREV_SECTION
))
1173 dwarf2_per_objfile
->abbrev_size
= bfd_get_section_size (sectp
);
1174 dwarf_abbrev_section
= sectp
;
1176 else if (section_is_p (sectp
, LINE_SECTION
))
1178 dwarf2_per_objfile
->line_size
= bfd_get_section_size (sectp
);
1179 dwarf_line_section
= sectp
;
1181 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1183 dwarf2_per_objfile
->pubnames_size
= bfd_get_section_size (sectp
);
1184 dwarf_pubnames_section
= sectp
;
1186 else if (section_is_p (sectp
, ARANGES_SECTION
))
1188 dwarf2_per_objfile
->aranges_size
= bfd_get_section_size (sectp
);
1189 dwarf_aranges_section
= sectp
;
1191 else if (section_is_p (sectp
, LOC_SECTION
))
1193 dwarf2_per_objfile
->loc_size
= bfd_get_section_size (sectp
);
1194 dwarf_loc_section
= sectp
;
1196 else if (section_is_p (sectp
, MACINFO_SECTION
))
1198 dwarf2_per_objfile
->macinfo_size
= bfd_get_section_size (sectp
);
1199 dwarf_macinfo_section
= sectp
;
1201 else if (section_is_p (sectp
, STR_SECTION
))
1203 dwarf2_per_objfile
->str_size
= bfd_get_section_size (sectp
);
1204 dwarf_str_section
= sectp
;
1206 else if (section_is_p (sectp
, FRAME_SECTION
))
1208 dwarf2_per_objfile
->frame_size
= bfd_get_section_size (sectp
);
1209 dwarf_frame_section
= sectp
;
1211 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1213 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1214 if (aflag
& SEC_HAS_CONTENTS
)
1216 dwarf2_per_objfile
->eh_frame_size
= bfd_get_section_size (sectp
);
1217 dwarf_eh_frame_section
= sectp
;
1220 else if (section_is_p (sectp
, RANGES_SECTION
))
1222 dwarf2_per_objfile
->ranges_size
= bfd_get_section_size (sectp
);
1223 dwarf_ranges_section
= sectp
;
1226 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1227 && bfd_section_vma (abfd
, sectp
) == 0)
1228 dwarf2_per_objfile
->has_section_at_zero
= 1;
1231 /* This function is called after decompressing a section, so
1232 dwarf2_per_objfile can record its new, uncompressed size. */
1235 dwarf2_resize_section (asection
*sectp
, bfd_size_type new_size
)
1237 if (section_is_p (sectp
, INFO_SECTION
))
1238 dwarf2_per_objfile
->info_size
= new_size
;
1239 else if (section_is_p (sectp
, ABBREV_SECTION
))
1240 dwarf2_per_objfile
->abbrev_size
= new_size
;
1241 else if (section_is_p (sectp
, LINE_SECTION
))
1242 dwarf2_per_objfile
->line_size
= new_size
;
1243 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1244 dwarf2_per_objfile
->pubnames_size
= new_size
;
1245 else if (section_is_p (sectp
, ARANGES_SECTION
))
1246 dwarf2_per_objfile
->aranges_size
= new_size
;
1247 else if (section_is_p (sectp
, LOC_SECTION
))
1248 dwarf2_per_objfile
->loc_size
= new_size
;
1249 else if (section_is_p (sectp
, MACINFO_SECTION
))
1250 dwarf2_per_objfile
->macinfo_size
= new_size
;
1251 else if (section_is_p (sectp
, STR_SECTION
))
1252 dwarf2_per_objfile
->str_size
= new_size
;
1253 else if (section_is_p (sectp
, FRAME_SECTION
))
1254 dwarf2_per_objfile
->frame_size
= new_size
;
1255 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1256 dwarf2_per_objfile
->eh_frame_size
= new_size
;
1257 else if (section_is_p (sectp
, RANGES_SECTION
))
1258 dwarf2_per_objfile
->ranges_size
= new_size
;
1260 internal_error (__FILE__
, __LINE__
,
1261 _("dwarf2_resize_section: missing section_is_p check: %s"),
1265 /* Build a partial symbol table. */
1268 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1270 /* We definitely need the .debug_info and .debug_abbrev sections */
1272 dwarf2_per_objfile
->info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1273 dwarf2_per_objfile
->abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1275 if (dwarf_line_section
)
1276 dwarf2_per_objfile
->line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1278 dwarf2_per_objfile
->line_buffer
= NULL
;
1280 if (dwarf_str_section
)
1281 dwarf2_per_objfile
->str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1283 dwarf2_per_objfile
->str_buffer
= NULL
;
1285 if (dwarf_macinfo_section
)
1286 dwarf2_per_objfile
->macinfo_buffer
= dwarf2_read_section (objfile
,
1287 dwarf_macinfo_section
);
1289 dwarf2_per_objfile
->macinfo_buffer
= NULL
;
1291 if (dwarf_ranges_section
)
1292 dwarf2_per_objfile
->ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1294 dwarf2_per_objfile
->ranges_buffer
= NULL
;
1296 if (dwarf_loc_section
)
1297 dwarf2_per_objfile
->loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1299 dwarf2_per_objfile
->loc_buffer
= NULL
;
1302 || (objfile
->global_psymbols
.size
== 0
1303 && objfile
->static_psymbols
.size
== 0))
1305 init_psymbol_list (objfile
, 1024);
1309 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1311 /* Things are significantly easier if we have .debug_aranges and
1312 .debug_pubnames sections */
1314 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1318 /* only test this case for now */
1320 /* In this case we have to work a bit harder */
1321 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1326 /* Build the partial symbol table from the information in the
1327 .debug_pubnames and .debug_aranges sections. */
1330 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1332 bfd
*abfd
= objfile
->obfd
;
1333 char *aranges_buffer
, *pubnames_buffer
;
1334 char *aranges_ptr
, *pubnames_ptr
;
1335 unsigned int entry_length
, version
, info_offset
, info_size
;
1337 pubnames_buffer
= dwarf2_read_section (objfile
,
1338 dwarf_pubnames_section
);
1339 pubnames_ptr
= pubnames_buffer
;
1340 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames_size
)
1342 unsigned int bytes_read
;
1344 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &bytes_read
);
1345 pubnames_ptr
+= bytes_read
;
1346 version
= read_1_byte (abfd
, pubnames_ptr
);
1348 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1350 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1354 aranges_buffer
= dwarf2_read_section (objfile
,
1355 dwarf_aranges_section
);
1360 /* Return TRUE if OFFSET is within CU_HEADER. */
1363 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
1365 unsigned int bottom
= cu_header
->offset
;
1366 unsigned int top
= (cu_header
->offset
1368 + cu_header
->initial_length_size
);
1369 return (offset
>= bottom
&& offset
< top
);
1372 /* Read in the comp unit header information from the debug_info at
1376 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1377 gdb_byte
*info_ptr
, bfd
*abfd
)
1380 unsigned int bytes_read
;
1382 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
1383 cu_header
->initial_length_size
= bytes_read
;
1384 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
1385 info_ptr
+= bytes_read
;
1386 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1388 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1390 info_ptr
+= bytes_read
;
1391 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1393 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1394 if (signed_addr
< 0)
1395 internal_error (__FILE__
, __LINE__
,
1396 _("read_comp_unit_head: dwarf from non elf file"));
1397 cu_header
->signed_addr_p
= signed_addr
;
1403 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1406 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1408 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1410 if (header
->version
!= 2 && header
->version
!= 3)
1411 error (_("Dwarf Error: wrong version in compilation unit header "
1412 "(is %d, should be %d) [in module %s]"), header
->version
,
1413 2, bfd_get_filename (abfd
));
1415 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev_size
)
1416 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1417 "(offset 0x%lx + 6) [in module %s]"),
1418 (long) header
->abbrev_offset
,
1419 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1420 bfd_get_filename (abfd
));
1422 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1423 > dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1424 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1425 "(offset 0x%lx + 0) [in module %s]"),
1426 (long) header
->length
,
1427 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1428 bfd_get_filename (abfd
));
1433 /* Allocate a new partial symtab for file named NAME and mark this new
1434 partial symtab as being an include of PST. */
1437 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1438 struct objfile
*objfile
)
1440 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1442 subpst
->section_offsets
= pst
->section_offsets
;
1443 subpst
->textlow
= 0;
1444 subpst
->texthigh
= 0;
1446 subpst
->dependencies
= (struct partial_symtab
**)
1447 obstack_alloc (&objfile
->objfile_obstack
,
1448 sizeof (struct partial_symtab
*));
1449 subpst
->dependencies
[0] = pst
;
1450 subpst
->number_of_dependencies
= 1;
1452 subpst
->globals_offset
= 0;
1453 subpst
->n_global_syms
= 0;
1454 subpst
->statics_offset
= 0;
1455 subpst
->n_static_syms
= 0;
1456 subpst
->symtab
= NULL
;
1457 subpst
->read_symtab
= pst
->read_symtab
;
1460 /* No private part is necessary for include psymtabs. This property
1461 can be used to differentiate between such include psymtabs and
1462 the regular ones. */
1463 subpst
->read_symtab_private
= NULL
;
1466 /* Read the Line Number Program data and extract the list of files
1467 included by the source file represented by PST. Build an include
1468 partial symtab for each of these included files.
1470 This procedure assumes that there *is* a Line Number Program in
1471 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1472 before calling this procedure. */
1475 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1476 struct partial_die_info
*pdi
,
1477 struct partial_symtab
*pst
)
1479 struct objfile
*objfile
= cu
->objfile
;
1480 bfd
*abfd
= objfile
->obfd
;
1481 struct line_header
*lh
;
1483 lh
= dwarf_decode_line_header (pdi
->line_offset
, abfd
, cu
);
1485 return; /* No linetable, so no includes. */
1487 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1489 free_line_header (lh
);
1493 /* Build the partial symbol table by doing a quick pass through the
1494 .debug_info and .debug_abbrev sections. */
1497 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1499 /* Instead of reading this into a big buffer, we should probably use
1500 mmap() on architectures that support it. (FIXME) */
1501 bfd
*abfd
= objfile
->obfd
;
1503 gdb_byte
*beg_of_comp_unit
;
1504 struct partial_die_info comp_unit_die
;
1505 struct partial_symtab
*pst
;
1506 struct cleanup
*back_to
;
1509 info_ptr
= dwarf2_per_objfile
->info_buffer
;
1511 /* Any cached compilation units will be linked by the per-objfile
1512 read_in_chain. Make sure to free them when we're done. */
1513 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1515 create_all_comp_units (objfile
);
1517 objfile
->psymtabs_addrmap
= addrmap_create_mutable
1518 (&objfile
->objfile_obstack
);
1520 /* Since the objects we're extracting from .debug_info vary in
1521 length, only the individual functions to extract them (like
1522 read_comp_unit_head and load_partial_die) can really know whether
1523 the buffer is large enough to hold another complete object.
1525 At the moment, they don't actually check that. If .debug_info
1526 holds just one extra byte after the last compilation unit's dies,
1527 then read_comp_unit_head will happily read off the end of the
1528 buffer. read_partial_die is similarly casual. Those functions
1531 For this loop condition, simply checking whether there's any data
1532 left at all should be sufficient. */
1533 while (info_ptr
< (dwarf2_per_objfile
->info_buffer
1534 + dwarf2_per_objfile
->info_size
))
1536 struct cleanup
*back_to_inner
;
1537 struct dwarf2_cu cu
;
1538 struct abbrev_info
*abbrev
;
1539 unsigned int bytes_read
;
1540 struct dwarf2_per_cu_data
*this_cu
;
1542 beg_of_comp_unit
= info_ptr
;
1544 memset (&cu
, 0, sizeof (cu
));
1546 obstack_init (&cu
.comp_unit_obstack
);
1548 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1550 cu
.objfile
= objfile
;
1551 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1553 /* Complete the cu_header */
1554 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1555 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1557 cu
.list_in_scope
= &file_symbols
;
1559 /* Read the abbrevs for this compilation unit into a table */
1560 dwarf2_read_abbrevs (abfd
, &cu
);
1561 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1563 this_cu
= dwarf2_find_comp_unit (cu
.header
.offset
, objfile
);
1565 /* Read the compilation unit die */
1566 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, &cu
);
1567 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1568 abfd
, info_ptr
, &cu
);
1570 if (comp_unit_die
.tag
== DW_TAG_partial_unit
)
1572 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1573 + cu
.header
.initial_length_size
);
1574 do_cleanups (back_to_inner
);
1578 /* Set the language we're debugging */
1579 set_cu_language (comp_unit_die
.language
, &cu
);
1581 /* Allocate a new partial symbol table structure */
1582 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1583 comp_unit_die
.name
? comp_unit_die
.name
: "",
1584 /* TEXTLOW and TEXTHIGH are set below. */
1586 objfile
->global_psymbols
.next
,
1587 objfile
->static_psymbols
.next
);
1589 if (comp_unit_die
.dirname
)
1590 pst
->dirname
= obsavestring (comp_unit_die
.dirname
,
1591 strlen (comp_unit_die
.dirname
),
1592 &objfile
->objfile_obstack
);
1594 pst
->read_symtab_private
= (char *) this_cu
;
1596 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1598 /* Store the function that reads in the rest of the symbol table */
1599 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1601 /* If this compilation unit was already read in, free the
1602 cached copy in order to read it in again. This is
1603 necessary because we skipped some symbols when we first
1604 read in the compilation unit (see load_partial_dies).
1605 This problem could be avoided, but the benefit is
1607 if (this_cu
->cu
!= NULL
)
1608 free_one_cached_comp_unit (this_cu
->cu
);
1610 cu
.per_cu
= this_cu
;
1612 /* Note that this is a pointer to our stack frame, being
1613 added to a global data structure. It will be cleaned up
1614 in free_stack_comp_unit when we finish with this
1615 compilation unit. */
1618 this_cu
->psymtab
= pst
;
1620 /* Possibly set the default values of LOWPC and HIGHPC from
1622 if (cu
.has_ranges_offset
)
1624 if (dwarf2_ranges_read (cu
.ranges_offset
, &comp_unit_die
.lowpc
,
1625 &comp_unit_die
.highpc
, &cu
, pst
))
1626 comp_unit_die
.has_pc_info
= 1;
1628 else if (comp_unit_die
.has_pc_info
1629 && comp_unit_die
.lowpc
< comp_unit_die
.highpc
)
1630 /* Store the contiguous range if it is not empty; it can be empty for
1631 CUs with no code. */
1632 addrmap_set_empty (objfile
->psymtabs_addrmap
,
1633 comp_unit_die
.lowpc
+ baseaddr
,
1634 comp_unit_die
.highpc
+ baseaddr
- 1, pst
);
1636 /* Check if comp unit has_children.
1637 If so, read the rest of the partial symbols from this comp unit.
1638 If not, there's no more debug_info for this comp unit. */
1639 if (comp_unit_die
.has_children
)
1641 struct partial_die_info
*first_die
;
1642 CORE_ADDR lowpc
, highpc
;
1644 lowpc
= ((CORE_ADDR
) -1);
1645 highpc
= ((CORE_ADDR
) 0);
1647 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1649 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
1650 ! comp_unit_die
.has_pc_info
, &cu
);
1652 /* If we didn't find a lowpc, set it to highpc to avoid
1653 complaints from `maint check'. */
1654 if (lowpc
== ((CORE_ADDR
) -1))
1657 /* If the compilation unit didn't have an explicit address range,
1658 then use the information extracted from its child dies. */
1659 if (! comp_unit_die
.has_pc_info
)
1661 comp_unit_die
.lowpc
= lowpc
;
1662 comp_unit_die
.highpc
= highpc
;
1665 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1666 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1668 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1669 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1670 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1671 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1672 sort_pst_symbols (pst
);
1674 /* If there is already a psymtab or symtab for a file of this
1675 name, remove it. (If there is a symtab, more drastic things
1676 also happen.) This happens in VxWorks. */
1677 free_named_symtabs (pst
->filename
);
1679 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1680 + cu
.header
.initial_length_size
;
1682 if (comp_unit_die
.has_stmt_list
)
1684 /* Get the list of files included in the current compilation unit,
1685 and build a psymtab for each of them. */
1686 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1689 do_cleanups (back_to_inner
);
1692 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
1693 &objfile
->objfile_obstack
);
1695 do_cleanups (back_to
);
1698 /* Load the DIEs for a secondary CU into memory. */
1701 load_comp_unit (struct dwarf2_per_cu_data
*this_cu
, struct objfile
*objfile
)
1703 bfd
*abfd
= objfile
->obfd
;
1704 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
1705 struct partial_die_info comp_unit_die
;
1706 struct dwarf2_cu
*cu
;
1707 struct abbrev_info
*abbrev
;
1708 unsigned int bytes_read
;
1709 struct cleanup
*back_to
;
1711 info_ptr
= dwarf2_per_objfile
->info_buffer
+ this_cu
->offset
;
1712 beg_of_comp_unit
= info_ptr
;
1714 cu
= xmalloc (sizeof (struct dwarf2_cu
));
1715 memset (cu
, 0, sizeof (struct dwarf2_cu
));
1717 obstack_init (&cu
->comp_unit_obstack
);
1719 cu
->objfile
= objfile
;
1720 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
1722 /* Complete the cu_header. */
1723 cu
->header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1724 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1726 /* Read the abbrevs for this compilation unit into a table. */
1727 dwarf2_read_abbrevs (abfd
, cu
);
1728 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
1730 /* Read the compilation unit die. */
1731 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1732 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1733 abfd
, info_ptr
, cu
);
1735 /* Set the language we're debugging. */
1736 set_cu_language (comp_unit_die
.language
, cu
);
1738 /* Link this compilation unit into the compilation unit tree. */
1740 cu
->per_cu
= this_cu
;
1741 cu
->type_hash
= cu
->per_cu
->type_hash
;
1743 /* Check if comp unit has_children.
1744 If so, read the rest of the partial symbols from this comp unit.
1745 If not, there's no more debug_info for this comp unit. */
1746 if (comp_unit_die
.has_children
)
1747 load_partial_dies (abfd
, info_ptr
, 0, cu
);
1749 do_cleanups (back_to
);
1752 /* Create a list of all compilation units in OBJFILE. We do this only
1753 if an inter-comp-unit reference is found; presumably if there is one,
1754 there will be many, and one will occur early in the .debug_info section.
1755 So there's no point in building this list incrementally. */
1758 create_all_comp_units (struct objfile
*objfile
)
1762 struct dwarf2_per_cu_data
**all_comp_units
;
1763 gdb_byte
*info_ptr
= dwarf2_per_objfile
->info_buffer
;
1767 all_comp_units
= xmalloc (n_allocated
1768 * sizeof (struct dwarf2_per_cu_data
*));
1770 while (info_ptr
< dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1772 unsigned int length
, initial_length_size
;
1773 gdb_byte
*beg_of_comp_unit
;
1774 struct dwarf2_per_cu_data
*this_cu
;
1775 unsigned int offset
;
1777 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
1779 /* Read just enough information to find out where the next
1780 compilation unit is. */
1781 length
= read_initial_length (objfile
->obfd
, info_ptr
,
1782 &initial_length_size
);
1784 /* Save the compilation unit for later lookup. */
1785 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
1786 sizeof (struct dwarf2_per_cu_data
));
1787 memset (this_cu
, 0, sizeof (*this_cu
));
1788 this_cu
->offset
= offset
;
1789 this_cu
->length
= length
+ initial_length_size
;
1791 if (n_comp_units
== n_allocated
)
1794 all_comp_units
= xrealloc (all_comp_units
,
1796 * sizeof (struct dwarf2_per_cu_data
*));
1798 all_comp_units
[n_comp_units
++] = this_cu
;
1800 info_ptr
= info_ptr
+ this_cu
->length
;
1803 dwarf2_per_objfile
->all_comp_units
1804 = obstack_alloc (&objfile
->objfile_obstack
,
1805 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1806 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
1807 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1808 xfree (all_comp_units
);
1809 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
1812 /* Process all loaded DIEs for compilation unit CU, starting at
1813 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
1814 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
1815 DW_AT_ranges). If NEED_PC is set, then this function will set
1816 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
1817 and record the covered ranges in the addrmap. */
1820 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1821 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
1823 struct objfile
*objfile
= cu
->objfile
;
1824 bfd
*abfd
= objfile
->obfd
;
1825 struct partial_die_info
*pdi
;
1827 /* Now, march along the PDI's, descending into ones which have
1828 interesting children but skipping the children of the other ones,
1829 until we reach the end of the compilation unit. */
1835 fixup_partial_die (pdi
, cu
);
1837 /* Anonymous namespaces have no name but have interesting
1838 children, so we need to look at them. Ditto for anonymous
1841 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1842 || pdi
->tag
== DW_TAG_enumeration_type
)
1846 case DW_TAG_subprogram
:
1847 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
1849 case DW_TAG_variable
:
1850 case DW_TAG_typedef
:
1851 case DW_TAG_union_type
:
1852 if (!pdi
->is_declaration
)
1854 add_partial_symbol (pdi
, cu
);
1857 case DW_TAG_class_type
:
1858 case DW_TAG_interface_type
:
1859 case DW_TAG_structure_type
:
1860 if (!pdi
->is_declaration
)
1862 add_partial_symbol (pdi
, cu
);
1865 case DW_TAG_enumeration_type
:
1866 if (!pdi
->is_declaration
)
1867 add_partial_enumeration (pdi
, cu
);
1869 case DW_TAG_base_type
:
1870 case DW_TAG_subrange_type
:
1871 /* File scope base type definitions are added to the partial
1873 add_partial_symbol (pdi
, cu
);
1875 case DW_TAG_namespace
:
1876 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
1879 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
1886 /* If the die has a sibling, skip to the sibling. */
1888 pdi
= pdi
->die_sibling
;
1892 /* Functions used to compute the fully scoped name of a partial DIE.
1894 Normally, this is simple. For C++, the parent DIE's fully scoped
1895 name is concatenated with "::" and the partial DIE's name. For
1896 Java, the same thing occurs except that "." is used instead of "::".
1897 Enumerators are an exception; they use the scope of their parent
1898 enumeration type, i.e. the name of the enumeration type is not
1899 prepended to the enumerator.
1901 There are two complexities. One is DW_AT_specification; in this
1902 case "parent" means the parent of the target of the specification,
1903 instead of the direct parent of the DIE. The other is compilers
1904 which do not emit DW_TAG_namespace; in this case we try to guess
1905 the fully qualified name of structure types from their members'
1906 linkage names. This must be done using the DIE's children rather
1907 than the children of any DW_AT_specification target. We only need
1908 to do this for structures at the top level, i.e. if the target of
1909 any DW_AT_specification (if any; otherwise the DIE itself) does not
1912 /* Compute the scope prefix associated with PDI's parent, in
1913 compilation unit CU. The result will be allocated on CU's
1914 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1915 field. NULL is returned if no prefix is necessary. */
1917 partial_die_parent_scope (struct partial_die_info
*pdi
,
1918 struct dwarf2_cu
*cu
)
1920 char *grandparent_scope
;
1921 struct partial_die_info
*parent
, *real_pdi
;
1923 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1924 then this means the parent of the specification DIE. */
1927 while (real_pdi
->has_specification
)
1928 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
1930 parent
= real_pdi
->die_parent
;
1934 if (parent
->scope_set
)
1935 return parent
->scope
;
1937 fixup_partial_die (parent
, cu
);
1939 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
1941 if (parent
->tag
== DW_TAG_namespace
1942 || parent
->tag
== DW_TAG_structure_type
1943 || parent
->tag
== DW_TAG_class_type
1944 || parent
->tag
== DW_TAG_interface_type
1945 || parent
->tag
== DW_TAG_union_type
)
1947 if (grandparent_scope
== NULL
)
1948 parent
->scope
= parent
->name
;
1950 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
1953 else if (parent
->tag
== DW_TAG_enumeration_type
)
1954 /* Enumerators should not get the name of the enumeration as a prefix. */
1955 parent
->scope
= grandparent_scope
;
1958 /* FIXME drow/2004-04-01: What should we be doing with
1959 function-local names? For partial symbols, we should probably be
1961 complaint (&symfile_complaints
,
1962 _("unhandled containing DIE tag %d for DIE at %d"),
1963 parent
->tag
, pdi
->offset
);
1964 parent
->scope
= grandparent_scope
;
1967 parent
->scope_set
= 1;
1968 return parent
->scope
;
1971 /* Return the fully scoped name associated with PDI, from compilation unit
1972 CU. The result will be allocated with malloc. */
1974 partial_die_full_name (struct partial_die_info
*pdi
,
1975 struct dwarf2_cu
*cu
)
1979 parent_scope
= partial_die_parent_scope (pdi
, cu
);
1980 if (parent_scope
== NULL
)
1983 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
1987 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
1989 struct objfile
*objfile
= cu
->objfile
;
1991 char *actual_name
= NULL
;
1992 const char *my_prefix
;
1993 const struct partial_symbol
*psym
= NULL
;
1995 int built_actual_name
= 0;
1997 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1999 if (pdi_needs_namespace (pdi
->tag
))
2001 actual_name
= partial_die_full_name (pdi
, cu
);
2003 built_actual_name
= 1;
2006 if (actual_name
== NULL
)
2007 actual_name
= pdi
->name
;
2011 case DW_TAG_subprogram
:
2012 if (pdi
->is_external
|| cu
->language
== language_ada
)
2014 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
2015 of the global scope. But in Ada, we want to be able to access
2016 nested procedures globally. So all Ada subprograms are stored
2017 in the global scope. */
2018 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2019 mst_text, objfile); */
2020 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2021 VAR_DOMAIN
, LOC_BLOCK
,
2022 &objfile
->global_psymbols
,
2023 0, pdi
->lowpc
+ baseaddr
,
2024 cu
->language
, objfile
);
2028 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2029 mst_file_text, objfile); */
2030 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2031 VAR_DOMAIN
, LOC_BLOCK
,
2032 &objfile
->static_psymbols
,
2033 0, pdi
->lowpc
+ baseaddr
,
2034 cu
->language
, objfile
);
2037 case DW_TAG_variable
:
2038 if (pdi
->is_external
)
2041 Don't enter into the minimal symbol tables as there is
2042 a minimal symbol table entry from the ELF symbols already.
2043 Enter into partial symbol table if it has a location
2044 descriptor or a type.
2045 If the location descriptor is missing, new_symbol will create
2046 a LOC_UNRESOLVED symbol, the address of the variable will then
2047 be determined from the minimal symbol table whenever the variable
2049 The address for the partial symbol table entry is not
2050 used by GDB, but it comes in handy for debugging partial symbol
2054 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2055 if (pdi
->locdesc
|| pdi
->has_type
)
2056 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2057 VAR_DOMAIN
, LOC_STATIC
,
2058 &objfile
->global_psymbols
,
2060 cu
->language
, objfile
);
2064 /* Static Variable. Skip symbols without location descriptors. */
2065 if (pdi
->locdesc
== NULL
)
2067 if (built_actual_name
)
2068 xfree (actual_name
);
2071 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2072 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2073 mst_file_data, objfile); */
2074 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2075 VAR_DOMAIN
, LOC_STATIC
,
2076 &objfile
->static_psymbols
,
2078 cu
->language
, objfile
);
2081 case DW_TAG_typedef
:
2082 case DW_TAG_base_type
:
2083 case DW_TAG_subrange_type
:
2084 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2085 VAR_DOMAIN
, LOC_TYPEDEF
,
2086 &objfile
->static_psymbols
,
2087 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2089 case DW_TAG_namespace
:
2090 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2091 VAR_DOMAIN
, LOC_TYPEDEF
,
2092 &objfile
->global_psymbols
,
2093 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2095 case DW_TAG_class_type
:
2096 case DW_TAG_interface_type
:
2097 case DW_TAG_structure_type
:
2098 case DW_TAG_union_type
:
2099 case DW_TAG_enumeration_type
:
2100 /* Skip external references. The DWARF standard says in the section
2101 about "Structure, Union, and Class Type Entries": "An incomplete
2102 structure, union or class type is represented by a structure,
2103 union or class entry that does not have a byte size attribute
2104 and that has a DW_AT_declaration attribute." */
2105 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2107 if (built_actual_name
)
2108 xfree (actual_name
);
2112 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2113 static vs. global. */
2114 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2115 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2116 (cu
->language
== language_cplus
2117 || cu
->language
== language_java
)
2118 ? &objfile
->global_psymbols
2119 : &objfile
->static_psymbols
,
2120 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2123 case DW_TAG_enumerator
:
2124 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2125 VAR_DOMAIN
, LOC_CONST
,
2126 (cu
->language
== language_cplus
2127 || cu
->language
== language_java
)
2128 ? &objfile
->global_psymbols
2129 : &objfile
->static_psymbols
,
2130 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2136 /* Check to see if we should scan the name for possible namespace
2137 info. Only do this if this is C++, if we don't have namespace
2138 debugging info in the file, if the psym is of an appropriate type
2139 (otherwise we'll have psym == NULL), and if we actually had a
2140 mangled name to begin with. */
2142 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2143 cases which do not set PSYM above? */
2145 if (cu
->language
== language_cplus
2146 && cu
->has_namespace_info
== 0
2148 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
2149 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
2152 if (built_actual_name
)
2153 xfree (actual_name
);
2156 /* Determine whether a die of type TAG living in a C++ class or
2157 namespace needs to have the name of the scope prepended to the
2158 name listed in the die. */
2161 pdi_needs_namespace (enum dwarf_tag tag
)
2165 case DW_TAG_namespace
:
2166 case DW_TAG_typedef
:
2167 case DW_TAG_class_type
:
2168 case DW_TAG_interface_type
:
2169 case DW_TAG_structure_type
:
2170 case DW_TAG_union_type
:
2171 case DW_TAG_enumeration_type
:
2172 case DW_TAG_enumerator
:
2179 /* Read a partial die corresponding to a namespace; also, add a symbol
2180 corresponding to that namespace to the symbol table. NAMESPACE is
2181 the name of the enclosing namespace. */
2184 add_partial_namespace (struct partial_die_info
*pdi
,
2185 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2186 int need_pc
, struct dwarf2_cu
*cu
)
2188 struct objfile
*objfile
= cu
->objfile
;
2190 /* Add a symbol for the namespace. */
2192 add_partial_symbol (pdi
, cu
);
2194 /* Now scan partial symbols in that namespace. */
2196 if (pdi
->has_children
)
2197 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2200 /* Read a partial die corresponding to a Fortran module. */
2203 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
2204 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
2206 /* Now scan partial symbols in that module.
2208 FIXME: Support the separate Fortran module namespaces. */
2210 if (pdi
->has_children
)
2211 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2214 /* Read a partial die corresponding to a subprogram and create a partial
2215 symbol for that subprogram. When the CU language allows it, this
2216 routine also defines a partial symbol for each nested subprogram
2217 that this subprogram contains.
2219 DIE my also be a lexical block, in which case we simply search
2220 recursively for suprograms defined inside that lexical block.
2221 Again, this is only performed when the CU language allows this
2222 type of definitions. */
2225 add_partial_subprogram (struct partial_die_info
*pdi
,
2226 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2227 int need_pc
, struct dwarf2_cu
*cu
)
2229 if (pdi
->tag
== DW_TAG_subprogram
)
2231 if (pdi
->has_pc_info
)
2233 if (pdi
->lowpc
< *lowpc
)
2234 *lowpc
= pdi
->lowpc
;
2235 if (pdi
->highpc
> *highpc
)
2236 *highpc
= pdi
->highpc
;
2240 struct objfile
*objfile
= cu
->objfile
;
2242 baseaddr
= ANOFFSET (objfile
->section_offsets
,
2243 SECT_OFF_TEXT (objfile
));
2244 addrmap_set_empty (objfile
->psymtabs_addrmap
,
2245 pdi
->lowpc
, pdi
->highpc
- 1,
2246 cu
->per_cu
->psymtab
);
2248 if (!pdi
->is_declaration
)
2249 add_partial_symbol (pdi
, cu
);
2253 if (! pdi
->has_children
)
2256 if (cu
->language
== language_ada
)
2258 pdi
= pdi
->die_child
;
2261 fixup_partial_die (pdi
, cu
);
2262 if (pdi
->tag
== DW_TAG_subprogram
2263 || pdi
->tag
== DW_TAG_lexical_block
)
2264 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
2265 pdi
= pdi
->die_sibling
;
2270 /* See if we can figure out if the class lives in a namespace. We do
2271 this by looking for a member function; its demangled name will
2272 contain namespace info, if there is any. */
2275 guess_structure_name (struct partial_die_info
*struct_pdi
,
2276 struct dwarf2_cu
*cu
)
2278 if ((cu
->language
== language_cplus
2279 || cu
->language
== language_java
)
2280 && cu
->has_namespace_info
== 0
2281 && struct_pdi
->has_children
)
2283 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2284 what template types look like, because the demangler
2285 frequently doesn't give the same name as the debug info. We
2286 could fix this by only using the demangled name to get the
2287 prefix (but see comment in read_structure_type). */
2289 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
2290 struct partial_die_info
*real_pdi
;
2292 /* If this DIE (this DIE's specification, if any) has a parent, then
2293 we should not do this. We'll prepend the parent's fully qualified
2294 name when we create the partial symbol. */
2296 real_pdi
= struct_pdi
;
2297 while (real_pdi
->has_specification
)
2298 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2300 if (real_pdi
->die_parent
!= NULL
)
2303 while (child_pdi
!= NULL
)
2305 if (child_pdi
->tag
== DW_TAG_subprogram
)
2307 char *actual_class_name
2308 = language_class_name_from_physname (cu
->language_defn
,
2310 if (actual_class_name
!= NULL
)
2313 = obsavestring (actual_class_name
,
2314 strlen (actual_class_name
),
2315 &cu
->comp_unit_obstack
);
2316 xfree (actual_class_name
);
2321 child_pdi
= child_pdi
->die_sibling
;
2326 /* Read a partial die corresponding to an enumeration type. */
2329 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2330 struct dwarf2_cu
*cu
)
2332 struct objfile
*objfile
= cu
->objfile
;
2333 bfd
*abfd
= objfile
->obfd
;
2334 struct partial_die_info
*pdi
;
2336 if (enum_pdi
->name
!= NULL
)
2337 add_partial_symbol (enum_pdi
, cu
);
2339 pdi
= enum_pdi
->die_child
;
2342 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2343 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2345 add_partial_symbol (pdi
, cu
);
2346 pdi
= pdi
->die_sibling
;
2350 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2351 Return the corresponding abbrev, or NULL if the number is zero (indicating
2352 an empty DIE). In either case *BYTES_READ will be set to the length of
2353 the initial number. */
2355 static struct abbrev_info
*
2356 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2357 struct dwarf2_cu
*cu
)
2359 bfd
*abfd
= cu
->objfile
->obfd
;
2360 unsigned int abbrev_number
;
2361 struct abbrev_info
*abbrev
;
2363 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2365 if (abbrev_number
== 0)
2368 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2371 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2372 bfd_get_filename (abfd
));
2378 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2379 pointer to the end of a series of DIEs, terminated by an empty
2380 DIE. Any children of the skipped DIEs will also be skipped. */
2383 skip_children (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2385 struct abbrev_info
*abbrev
;
2386 unsigned int bytes_read
;
2390 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2392 return info_ptr
+ bytes_read
;
2394 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
2398 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2399 should point just after the initial uleb128 of a DIE, and the
2400 abbrev corresponding to that skipped uleb128 should be passed in
2401 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2405 skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
2406 struct dwarf2_cu
*cu
)
2408 unsigned int bytes_read
;
2409 struct attribute attr
;
2410 bfd
*abfd
= cu
->objfile
->obfd
;
2411 unsigned int form
, i
;
2413 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2415 /* The only abbrev we care about is DW_AT_sibling. */
2416 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2418 read_attribute (&attr
, &abbrev
->attrs
[i
],
2419 abfd
, info_ptr
, cu
);
2420 if (attr
.form
== DW_FORM_ref_addr
)
2421 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2423 return dwarf2_per_objfile
->info_buffer
2424 + dwarf2_get_ref_die_offset (&attr
);
2427 /* If it isn't DW_AT_sibling, skip this attribute. */
2428 form
= abbrev
->attrs
[i
].form
;
2433 case DW_FORM_ref_addr
:
2434 info_ptr
+= cu
->header
.addr_size
;
2453 case DW_FORM_string
:
2454 read_string (abfd
, info_ptr
, &bytes_read
);
2455 info_ptr
+= bytes_read
;
2458 info_ptr
+= cu
->header
.offset_size
;
2461 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2462 info_ptr
+= bytes_read
;
2464 case DW_FORM_block1
:
2465 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2467 case DW_FORM_block2
:
2468 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2470 case DW_FORM_block4
:
2471 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2475 case DW_FORM_ref_udata
:
2476 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2478 case DW_FORM_indirect
:
2479 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2480 info_ptr
+= bytes_read
;
2481 /* We need to continue parsing from here, so just go back to
2483 goto skip_attribute
;
2486 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2487 dwarf_form_name (form
),
2488 bfd_get_filename (abfd
));
2492 if (abbrev
->has_children
)
2493 return skip_children (info_ptr
, cu
);
2498 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2499 the next DIE after ORIG_PDI. */
2502 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, gdb_byte
*info_ptr
,
2503 bfd
*abfd
, struct dwarf2_cu
*cu
)
2505 /* Do we know the sibling already? */
2507 if (orig_pdi
->sibling
)
2508 return orig_pdi
->sibling
;
2510 /* Are there any children to deal with? */
2512 if (!orig_pdi
->has_children
)
2515 /* Skip the children the long way. */
2517 return skip_children (info_ptr
, cu
);
2520 /* Expand this partial symbol table into a full symbol table. */
2523 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2525 /* FIXME: This is barely more than a stub. */
2530 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2536 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2537 gdb_flush (gdb_stdout
);
2540 /* Restore our global data. */
2541 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2542 dwarf2_objfile_data_key
);
2544 psymtab_to_symtab_1 (pst
);
2546 /* Finish up the debug error message. */
2548 printf_filtered (_("done.\n"));
2553 /* Add PER_CU to the queue. */
2556 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2558 struct dwarf2_queue_item
*item
;
2561 item
= xmalloc (sizeof (*item
));
2562 item
->per_cu
= per_cu
;
2565 if (dwarf2_queue
== NULL
)
2566 dwarf2_queue
= item
;
2568 dwarf2_queue_tail
->next
= item
;
2570 dwarf2_queue_tail
= item
;
2572 /* Either PER_CU is the CU we want to process, or we're following a reference
2573 pointing into PER_CU. Either way, we need its DIEs now. */
2574 load_full_comp_unit (item
->per_cu
, objfile
);
2575 item
->per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
2576 dwarf2_per_objfile
->read_in_chain
= item
->per_cu
;
2579 /* Process the queue. */
2582 process_queue (struct objfile
*objfile
)
2584 struct dwarf2_queue_item
*item
, *next_item
;
2586 /* The queue starts out with one item, but following a DIE reference
2587 may load a new CU, adding it to the end of the queue. */
2588 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2590 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2591 process_full_comp_unit (item
->per_cu
);
2593 item
->per_cu
->queued
= 0;
2594 next_item
= item
->next
;
2598 dwarf2_queue_tail
= NULL
;
2601 /* Free all allocated queue entries. This function only releases anything if
2602 an error was thrown; if the queue was processed then it would have been
2603 freed as we went along. */
2606 dwarf2_release_queue (void *dummy
)
2608 struct dwarf2_queue_item
*item
, *last
;
2610 item
= dwarf2_queue
;
2613 /* Anything still marked queued is likely to be in an
2614 inconsistent state, so discard it. */
2615 if (item
->per_cu
->queued
)
2617 if (item
->per_cu
->cu
!= NULL
)
2618 free_one_cached_comp_unit (item
->per_cu
->cu
);
2619 item
->per_cu
->queued
= 0;
2627 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2630 /* Read in full symbols for PST, and anything it depends on. */
2633 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2635 struct dwarf2_per_cu_data
*per_cu
;
2636 struct cleanup
*back_to
;
2639 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2640 if (!pst
->dependencies
[i
]->readin
)
2642 /* Inform about additional files that need to be read in. */
2645 /* FIXME: i18n: Need to make this a single string. */
2646 fputs_filtered (" ", gdb_stdout
);
2648 fputs_filtered ("and ", gdb_stdout
);
2650 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2651 wrap_here (""); /* Flush output */
2652 gdb_flush (gdb_stdout
);
2654 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2657 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
2661 /* It's an include file, no symbols to read for it.
2662 Everything is in the parent symtab. */
2667 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2669 queue_comp_unit (per_cu
, pst
->objfile
);
2671 process_queue (pst
->objfile
);
2673 /* Age the cache, releasing compilation units that have not
2674 been used recently. */
2675 age_cached_comp_units ();
2677 do_cleanups (back_to
);
2680 /* Load the DIEs associated with PST and PER_CU into memory. */
2682 static struct dwarf2_cu
*
2683 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2685 bfd
*abfd
= objfile
->obfd
;
2686 struct dwarf2_cu
*cu
;
2687 unsigned int offset
;
2689 struct cleanup
*back_to
, *free_cu_cleanup
;
2690 struct attribute
*attr
;
2693 /* Set local variables from the partial symbol table info. */
2694 offset
= per_cu
->offset
;
2696 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2698 cu
= xmalloc (sizeof (struct dwarf2_cu
));
2699 memset (cu
, 0, sizeof (struct dwarf2_cu
));
2701 /* If an error occurs while loading, release our storage. */
2702 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
2704 cu
->objfile
= objfile
;
2706 /* read in the comp_unit header */
2707 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
2709 /* Read the abbrevs for this compilation unit */
2710 dwarf2_read_abbrevs (abfd
, cu
);
2711 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2713 cu
->header
.offset
= offset
;
2715 cu
->per_cu
= per_cu
;
2717 cu
->type_hash
= per_cu
->type_hash
;
2719 /* We use this obstack for block values in dwarf_alloc_block. */
2720 obstack_init (&cu
->comp_unit_obstack
);
2722 cu
->dies
= read_comp_unit (info_ptr
, abfd
, cu
);
2724 /* We try not to read any attributes in this function, because not
2725 all objfiles needed for references have been loaded yet, and symbol
2726 table processing isn't initialized. But we have to set the CU language,
2727 or we won't be able to build types correctly. */
2728 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
2730 set_cu_language (DW_UNSND (attr
), cu
);
2732 set_cu_language (language_minimal
, cu
);
2734 do_cleanups (back_to
);
2736 /* We've successfully allocated this compilation unit. Let our caller
2737 clean it up when finished with it. */
2738 discard_cleanups (free_cu_cleanup
);
2743 /* Generate full symbol information for PST and CU, whose DIEs have
2744 already been loaded into memory. */
2747 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2749 struct partial_symtab
*pst
= per_cu
->psymtab
;
2750 struct dwarf2_cu
*cu
= per_cu
->cu
;
2751 struct objfile
*objfile
= pst
->objfile
;
2752 bfd
*abfd
= objfile
->obfd
;
2753 CORE_ADDR lowpc
, highpc
;
2754 struct symtab
*symtab
;
2755 struct cleanup
*back_to
;
2756 struct attribute
*attr
;
2759 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2762 back_to
= make_cleanup (really_free_pendings
, NULL
);
2764 cu
->list_in_scope
= &file_symbols
;
2766 /* Find the base address of the compilation unit for range lists and
2767 location lists. It will normally be specified by DW_AT_low_pc.
2768 In DWARF-3 draft 4, the base address could be overridden by
2769 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2770 compilation units with discontinuous ranges. */
2773 cu
->base_address
= 0;
2775 attr
= dwarf2_attr (cu
->dies
, DW_AT_entry_pc
, cu
);
2778 cu
->base_address
= DW_ADDR (attr
);
2783 attr
= dwarf2_attr (cu
->dies
, DW_AT_low_pc
, cu
);
2786 cu
->base_address
= DW_ADDR (attr
);
2791 /* Do line number decoding in read_file_scope () */
2792 process_die (cu
->dies
, cu
);
2794 /* Some compilers don't define a DW_AT_high_pc attribute for the
2795 compilation unit. If the DW_AT_high_pc is missing, synthesize
2796 it, by scanning the DIE's below the compilation unit. */
2797 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
2799 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2801 /* Set symtab language to language from DW_AT_language.
2802 If the compilation is from a C file generated by language preprocessors,
2803 do not set the language if it was already deduced by start_subfile. */
2805 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
2807 symtab
->language
= cu
->language
;
2809 pst
->symtab
= symtab
;
2812 do_cleanups (back_to
);
2815 /* Process a die and its children. */
2818 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2822 case DW_TAG_padding
:
2824 case DW_TAG_compile_unit
:
2825 read_file_scope (die
, cu
);
2827 case DW_TAG_subprogram
:
2828 read_func_scope (die
, cu
);
2830 case DW_TAG_inlined_subroutine
:
2831 /* FIXME: These are ignored for now.
2832 They could be used to set breakpoints on all inlined instances
2833 of a function and make GDB `next' properly over inlined functions. */
2835 case DW_TAG_lexical_block
:
2836 case DW_TAG_try_block
:
2837 case DW_TAG_catch_block
:
2838 read_lexical_block_scope (die
, cu
);
2840 case DW_TAG_class_type
:
2841 case DW_TAG_interface_type
:
2842 case DW_TAG_structure_type
:
2843 case DW_TAG_union_type
:
2844 process_structure_scope (die
, cu
);
2846 case DW_TAG_enumeration_type
:
2847 process_enumeration_scope (die
, cu
);
2850 /* These dies have a type, but processing them does not create
2851 a symbol or recurse to process the children. Therefore we can
2852 read them on-demand through read_type_die. */
2853 case DW_TAG_subroutine_type
:
2854 case DW_TAG_set_type
:
2855 case DW_TAG_array_type
:
2856 case DW_TAG_pointer_type
:
2857 case DW_TAG_ptr_to_member_type
:
2858 case DW_TAG_reference_type
:
2859 case DW_TAG_string_type
:
2862 case DW_TAG_base_type
:
2863 case DW_TAG_subrange_type
:
2864 case DW_TAG_typedef
:
2865 /* Add a typedef symbol for the type definition, if it has a
2867 new_symbol (die
, read_type_die (die
, cu
), cu
);
2869 case DW_TAG_common_block
:
2870 read_common_block (die
, cu
);
2872 case DW_TAG_common_inclusion
:
2874 case DW_TAG_namespace
:
2875 processing_has_namespace_info
= 1;
2876 read_namespace (die
, cu
);
2879 read_module (die
, cu
);
2881 case DW_TAG_imported_declaration
:
2882 case DW_TAG_imported_module
:
2883 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2884 information contained in these. DW_TAG_imported_declaration
2885 dies shouldn't have children; DW_TAG_imported_module dies
2886 shouldn't in the C++ case, but conceivably could in the
2888 processing_has_namespace_info
= 1;
2889 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
2890 dwarf_tag_name (die
->tag
));
2893 new_symbol (die
, NULL
, cu
);
2898 /* Return the fully qualified name of DIE, based on its DW_AT_name.
2899 If scope qualifiers are appropriate they will be added. The result
2900 will be allocated on the objfile_obstack, or NULL if the DIE does
2904 dwarf2_full_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
2906 struct attribute
*attr
;
2907 char *prefix
, *name
;
2908 struct ui_file
*buf
= NULL
;
2910 name
= dwarf2_name (die
, cu
);
2914 /* These are the only languages we know how to qualify names in. */
2915 if (cu
->language
!= language_cplus
2916 && cu
->language
!= language_java
)
2919 /* If no prefix is necessary for this type of DIE, return the
2920 unqualified name. The other three tags listed could be handled
2921 in pdi_needs_namespace, but that requires broader changes. */
2922 if (!pdi_needs_namespace (die
->tag
)
2923 && die
->tag
!= DW_TAG_subprogram
2924 && die
->tag
!= DW_TAG_variable
2925 && die
->tag
!= DW_TAG_member
)
2928 prefix
= determine_prefix (die
, cu
);
2929 if (*prefix
!= '\0')
2930 name
= typename_concat (&cu
->objfile
->objfile_obstack
, prefix
,
2937 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2939 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2943 free_cu_line_header (void *arg
)
2945 struct dwarf2_cu
*cu
= arg
;
2947 free_line_header (cu
->line_header
);
2948 cu
->line_header
= NULL
;
2952 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2954 struct objfile
*objfile
= cu
->objfile
;
2955 struct comp_unit_head
*cu_header
= &cu
->header
;
2956 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2957 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2958 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2959 struct attribute
*attr
;
2961 char *comp_dir
= NULL
;
2962 struct die_info
*child_die
;
2963 bfd
*abfd
= objfile
->obfd
;
2964 struct line_header
*line_header
= 0;
2967 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2969 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2971 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2972 from finish_block. */
2973 if (lowpc
== ((CORE_ADDR
) -1))
2978 /* Find the filename. Do not use dwarf2_name here, since the filename
2979 is not a source language identifier. */
2980 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2983 name
= DW_STRING (attr
);
2986 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2988 comp_dir
= DW_STRING (attr
);
2989 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
2991 comp_dir
= ldirname (name
);
2992 if (comp_dir
!= NULL
)
2993 make_cleanup (xfree
, comp_dir
);
2995 if (comp_dir
!= NULL
)
2997 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2998 directory, get rid of it. */
2999 char *cp
= strchr (comp_dir
, ':');
3001 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
3008 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
3011 set_cu_language (DW_UNSND (attr
), cu
);
3014 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
3016 cu
->producer
= DW_STRING (attr
);
3018 /* We assume that we're processing GCC output. */
3019 processing_gcc_compilation
= 2;
3021 processing_has_namespace_info
= 0;
3023 start_symtab (name
, comp_dir
, lowpc
);
3024 record_debugformat ("DWARF 2");
3025 record_producer (cu
->producer
);
3027 initialize_cu_func_list (cu
);
3029 /* Decode line number information if present. We do this before
3030 processing child DIEs, so that the line header table is available
3031 for DW_AT_decl_file. */
3032 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3035 unsigned int line_offset
= DW_UNSND (attr
);
3036 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3039 cu
->line_header
= line_header
;
3040 make_cleanup (free_cu_line_header
, cu
);
3041 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
3045 /* Process all dies in compilation unit. */
3046 if (die
->child
!= NULL
)
3048 child_die
= die
->child
;
3049 while (child_die
&& child_die
->tag
)
3051 process_die (child_die
, cu
);
3052 child_die
= sibling_die (child_die
);
3056 /* Decode macro information, if present. Dwarf 2 macro information
3057 refers to information in the line number info statement program
3058 header, so we can only read it if we've read the header
3060 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
3061 if (attr
&& line_header
)
3063 unsigned int macro_offset
= DW_UNSND (attr
);
3064 dwarf_decode_macros (line_header
, macro_offset
,
3065 comp_dir
, abfd
, cu
);
3067 do_cleanups (back_to
);
3071 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
3072 struct dwarf2_cu
*cu
)
3074 struct function_range
*thisfn
;
3076 thisfn
= (struct function_range
*)
3077 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
3078 thisfn
->name
= name
;
3079 thisfn
->lowpc
= lowpc
;
3080 thisfn
->highpc
= highpc
;
3081 thisfn
->seen_line
= 0;
3082 thisfn
->next
= NULL
;
3084 if (cu
->last_fn
== NULL
)
3085 cu
->first_fn
= thisfn
;
3087 cu
->last_fn
->next
= thisfn
;
3089 cu
->last_fn
= thisfn
;
3093 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3095 struct objfile
*objfile
= cu
->objfile
;
3096 struct context_stack
*new;
3099 struct die_info
*child_die
;
3100 struct attribute
*attr
;
3103 struct block
*block
;
3105 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3107 name
= dwarf2_linkage_name (die
, cu
);
3109 /* Ignore functions with missing or empty names and functions with
3110 missing or invalid low and high pc attributes. */
3111 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3117 /* Record the function range for dwarf_decode_lines. */
3118 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
3120 new = push_context (0, lowpc
);
3121 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
3123 /* If there is a location expression for DW_AT_frame_base, record
3125 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3127 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3128 expression is being recorded directly in the function's symbol
3129 and not in a separate frame-base object. I guess this hack is
3130 to avoid adding some sort of frame-base adjunct/annex to the
3131 function's symbol :-(. The problem with doing this is that it
3132 results in a function symbol with a location expression that
3133 has nothing to do with the location of the function, ouch! The
3134 relationship should be: a function's symbol has-a frame base; a
3135 frame-base has-a location expression. */
3136 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3138 cu
->list_in_scope
= &local_symbols
;
3140 if (die
->child
!= NULL
)
3142 child_die
= die
->child
;
3143 while (child_die
&& child_die
->tag
)
3145 process_die (child_die
, cu
);
3146 child_die
= sibling_die (child_die
);
3150 new = pop_context ();
3151 /* Make a block for the local symbols within. */
3152 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3153 lowpc
, highpc
, objfile
);
3155 /* For C++, set the block's scope. */
3156 if (cu
->language
== language_cplus
)
3157 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
3158 determine_prefix (die
, cu
),
3159 processing_has_namespace_info
);
3161 /* If we have address ranges, record them. */
3162 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3164 /* In C++, we can have functions nested inside functions (e.g., when
3165 a function declares a class that has methods). This means that
3166 when we finish processing a function scope, we may need to go
3167 back to building a containing block's symbol lists. */
3168 local_symbols
= new->locals
;
3169 param_symbols
= new->params
;
3171 /* If we've finished processing a top-level function, subsequent
3172 symbols go in the file symbol list. */
3173 if (outermost_context_p ())
3174 cu
->list_in_scope
= &file_symbols
;
3177 /* Process all the DIES contained within a lexical block scope. Start
3178 a new scope, process the dies, and then close the scope. */
3181 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3183 struct objfile
*objfile
= cu
->objfile
;
3184 struct context_stack
*new;
3185 CORE_ADDR lowpc
, highpc
;
3186 struct die_info
*child_die
;
3189 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3191 /* Ignore blocks with missing or invalid low and high pc attributes. */
3192 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3193 as multiple lexical blocks? Handling children in a sane way would
3194 be nasty. Might be easier to properly extend generic blocks to
3196 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3201 push_context (0, lowpc
);
3202 if (die
->child
!= NULL
)
3204 child_die
= die
->child
;
3205 while (child_die
&& child_die
->tag
)
3207 process_die (child_die
, cu
);
3208 child_die
= sibling_die (child_die
);
3211 new = pop_context ();
3213 if (local_symbols
!= NULL
)
3216 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3219 /* Note that recording ranges after traversing children, as we
3220 do here, means that recording a parent's ranges entails
3221 walking across all its children's ranges as they appear in
3222 the address map, which is quadratic behavior.
3224 It would be nicer to record the parent's ranges before
3225 traversing its children, simply overriding whatever you find
3226 there. But since we don't even decide whether to create a
3227 block until after we've traversed its children, that's hard
3229 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3231 local_symbols
= new->locals
;
3234 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3235 Return 1 if the attributes are present and valid, otherwise, return 0.
3236 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3239 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
3240 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
3241 struct partial_symtab
*ranges_pst
)
3243 struct objfile
*objfile
= cu
->objfile
;
3244 struct comp_unit_head
*cu_header
= &cu
->header
;
3245 bfd
*obfd
= objfile
->obfd
;
3246 unsigned int addr_size
= cu_header
->addr_size
;
3247 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3248 /* Base address selection entry. */
3259 found_base
= cu
->base_known
;
3260 base
= cu
->base_address
;
3262 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3264 complaint (&symfile_complaints
,
3265 _("Offset %d out of bounds for DW_AT_ranges attribute"),
3269 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3271 /* Read in the largest possible address. */
3272 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
3273 if ((marker
& mask
) == mask
)
3275 /* If we found the largest possible address, then
3276 read the base address. */
3277 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3278 buffer
+= 2 * addr_size
;
3279 offset
+= 2 * addr_size
;
3285 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3289 CORE_ADDR range_beginning
, range_end
;
3291 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
3292 buffer
+= addr_size
;
3293 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
3294 buffer
+= addr_size
;
3295 offset
+= 2 * addr_size
;
3297 /* An end of list marker is a pair of zero addresses. */
3298 if (range_beginning
== 0 && range_end
== 0)
3299 /* Found the end of list entry. */
3302 /* Each base address selection entry is a pair of 2 values.
3303 The first is the largest possible address, the second is
3304 the base address. Check for a base address here. */
3305 if ((range_beginning
& mask
) == mask
)
3307 /* If we found the largest possible address, then
3308 read the base address. */
3309 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3316 /* We have no valid base address for the ranges
3318 complaint (&symfile_complaints
,
3319 _("Invalid .debug_ranges data (no base address)"));
3323 range_beginning
+= base
;
3326 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
3327 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3328 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
3331 /* FIXME: This is recording everything as a low-high
3332 segment of consecutive addresses. We should have a
3333 data structure for discontiguous block ranges
3337 low
= range_beginning
;
3343 if (range_beginning
< low
)
3344 low
= range_beginning
;
3345 if (range_end
> high
)
3351 /* If the first entry is an end-of-list marker, the range
3352 describes an empty scope, i.e. no instructions. */
3358 *high_return
= high
;
3362 /* Get low and high pc attributes from a die. Return 1 if the attributes
3363 are present and valid, otherwise, return 0. Return -1 if the range is
3364 discontinuous, i.e. derived from DW_AT_ranges information. */
3366 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
3367 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
3369 struct attribute
*attr
;
3374 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3377 high
= DW_ADDR (attr
);
3378 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3380 low
= DW_ADDR (attr
);
3382 /* Found high w/o low attribute. */
3385 /* Found consecutive range of addresses. */
3390 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3393 /* Value of the DW_AT_ranges attribute is the offset in the
3394 .debug_ranges section. */
3395 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, NULL
))
3397 /* Found discontinuous range of addresses. */
3405 /* When using the GNU linker, .gnu.linkonce. sections are used to
3406 eliminate duplicate copies of functions and vtables and such.
3407 The linker will arbitrarily choose one and discard the others.
3408 The AT_*_pc values for such functions refer to local labels in
3409 these sections. If the section from that file was discarded, the
3410 labels are not in the output, so the relocs get a value of 0.
3411 If this is a discarded function, mark the pc bounds as invalid,
3412 so that GDB will ignore it. */
3413 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3421 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
3422 its low and high PC addresses. Do nothing if these addresses could not
3423 be determined. Otherwise, set LOWPC to the low address if it is smaller,
3424 and HIGHPC to the high address if greater than HIGHPC. */
3427 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
3428 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3429 struct dwarf2_cu
*cu
)
3431 CORE_ADDR low
, high
;
3432 struct die_info
*child
= die
->child
;
3434 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
))
3436 *lowpc
= min (*lowpc
, low
);
3437 *highpc
= max (*highpc
, high
);
3440 /* If the language does not allow nested subprograms (either inside
3441 subprograms or lexical blocks), we're done. */
3442 if (cu
->language
!= language_ada
)
3445 /* Check all the children of the given DIE. If it contains nested
3446 subprograms, then check their pc bounds. Likewise, we need to
3447 check lexical blocks as well, as they may also contain subprogram
3449 while (child
&& child
->tag
)
3451 if (child
->tag
== DW_TAG_subprogram
3452 || child
->tag
== DW_TAG_lexical_block
)
3453 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
3454 child
= sibling_die (child
);
3458 /* Get the low and high pc's represented by the scope DIE, and store
3459 them in *LOWPC and *HIGHPC. If the correct values can't be
3460 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3463 get_scope_pc_bounds (struct die_info
*die
,
3464 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3465 struct dwarf2_cu
*cu
)
3467 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3468 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3469 CORE_ADDR current_low
, current_high
;
3471 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3473 best_low
= current_low
;
3474 best_high
= current_high
;
3478 struct die_info
*child
= die
->child
;
3480 while (child
&& child
->tag
)
3482 switch (child
->tag
) {
3483 case DW_TAG_subprogram
:
3484 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
3486 case DW_TAG_namespace
:
3487 /* FIXME: carlton/2004-01-16: Should we do this for
3488 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3489 that current GCC's always emit the DIEs corresponding
3490 to definitions of methods of classes as children of a
3491 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3492 the DIEs giving the declarations, which could be
3493 anywhere). But I don't see any reason why the
3494 standards says that they have to be there. */
3495 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3497 if (current_low
!= ((CORE_ADDR
) -1))
3499 best_low
= min (best_low
, current_low
);
3500 best_high
= max (best_high
, current_high
);
3508 child
= sibling_die (child
);
3513 *highpc
= best_high
;
3516 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
3519 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
3520 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
3522 struct attribute
*attr
;
3524 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3527 CORE_ADDR high
= DW_ADDR (attr
);
3528 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3531 CORE_ADDR low
= DW_ADDR (attr
);
3532 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
3536 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3539 bfd
*obfd
= cu
->objfile
->obfd
;
3541 /* The value of the DW_AT_ranges attribute is the offset of the
3542 address range list in the .debug_ranges section. */
3543 unsigned long offset
= DW_UNSND (attr
);
3544 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3546 /* For some target architectures, but not others, the
3547 read_address function sign-extends the addresses it returns.
3548 To recognize base address selection entries, we need a
3550 unsigned int addr_size
= cu
->header
.addr_size
;
3551 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3553 /* The base address, to which the next pair is relative. Note
3554 that this 'base' is a DWARF concept: most entries in a range
3555 list are relative, to reduce the number of relocs against the
3556 debugging information. This is separate from this function's
3557 'baseaddr' argument, which GDB uses to relocate debugging
3558 information from a shared library based on the address at
3559 which the library was loaded. */
3560 CORE_ADDR base
= cu
->base_address
;
3561 int base_known
= cu
->base_known
;
3563 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3565 complaint (&symfile_complaints
,
3566 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
3573 unsigned int bytes_read
;
3574 CORE_ADDR start
, end
;
3576 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3577 buffer
+= bytes_read
;
3578 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3579 buffer
+= bytes_read
;
3581 /* Did we find the end of the range list? */
3582 if (start
== 0 && end
== 0)
3585 /* Did we find a base address selection entry? */
3586 else if ((start
& base_select_mask
) == base_select_mask
)
3592 /* We found an ordinary address range. */
3597 complaint (&symfile_complaints
,
3598 _("Invalid .debug_ranges data (no base address)"));
3602 record_block_range (block
,
3603 baseaddr
+ base
+ start
,
3604 baseaddr
+ base
+ end
- 1);
3610 /* Add an aggregate field to the field list. */
3613 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3614 struct dwarf2_cu
*cu
)
3616 struct objfile
*objfile
= cu
->objfile
;
3617 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3618 struct nextfield
*new_field
;
3619 struct attribute
*attr
;
3621 char *fieldname
= "";
3623 /* Allocate a new field list entry and link it in. */
3624 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3625 make_cleanup (xfree
, new_field
);
3626 memset (new_field
, 0, sizeof (struct nextfield
));
3627 new_field
->next
= fip
->fields
;
3628 fip
->fields
= new_field
;
3631 /* Handle accessibility and virtuality of field.
3632 The default accessibility for members is public, the default
3633 accessibility for inheritance is private. */
3634 if (die
->tag
!= DW_TAG_inheritance
)
3635 new_field
->accessibility
= DW_ACCESS_public
;
3637 new_field
->accessibility
= DW_ACCESS_private
;
3638 new_field
->virtuality
= DW_VIRTUALITY_none
;
3640 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3642 new_field
->accessibility
= DW_UNSND (attr
);
3643 if (new_field
->accessibility
!= DW_ACCESS_public
)
3644 fip
->non_public_fields
= 1;
3645 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3647 new_field
->virtuality
= DW_UNSND (attr
);
3649 fp
= &new_field
->field
;
3651 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3653 /* Data member other than a C++ static data member. */
3655 /* Get type of field. */
3656 fp
->type
= die_type (die
, cu
);
3658 SET_FIELD_BITPOS (*fp
, 0);
3660 /* Get bit size of field (zero if none). */
3661 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3664 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3668 FIELD_BITSIZE (*fp
) = 0;
3671 /* Get bit offset of field. */
3672 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3677 if (attr_form_is_section_offset (attr
))
3679 dwarf2_complex_location_expr_complaint ();
3682 else if (attr_form_is_constant (attr
))
3683 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
3685 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
3687 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
3689 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3692 if (gdbarch_bits_big_endian (gdbarch
))
3694 /* For big endian bits, the DW_AT_bit_offset gives the
3695 additional bit offset from the MSB of the containing
3696 anonymous object to the MSB of the field. We don't
3697 have to do anything special since we don't need to
3698 know the size of the anonymous object. */
3699 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3703 /* For little endian bits, compute the bit offset to the
3704 MSB of the anonymous object, subtract off the number of
3705 bits from the MSB of the field to the MSB of the
3706 object, and then subtract off the number of bits of
3707 the field itself. The result is the bit offset of
3708 the LSB of the field. */
3710 int bit_offset
= DW_UNSND (attr
);
3712 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3715 /* The size of the anonymous object containing
3716 the bit field is explicit, so use the
3717 indicated size (in bytes). */
3718 anonymous_size
= DW_UNSND (attr
);
3722 /* The size of the anonymous object containing
3723 the bit field must be inferred from the type
3724 attribute of the data member containing the
3726 anonymous_size
= TYPE_LENGTH (fp
->type
);
3728 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
3729 - bit_offset
- FIELD_BITSIZE (*fp
);
3733 /* Get name of field. */
3734 fieldname
= dwarf2_name (die
, cu
);
3735 if (fieldname
== NULL
)
3738 /* The name is already allocated along with this objfile, so we don't
3739 need to duplicate it for the type. */
3740 fp
->name
= fieldname
;
3742 /* Change accessibility for artificial fields (e.g. virtual table
3743 pointer or virtual base class pointer) to private. */
3744 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
3746 new_field
->accessibility
= DW_ACCESS_private
;
3747 fip
->non_public_fields
= 1;
3750 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
3752 /* C++ static member. */
3754 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3755 is a declaration, but all versions of G++ as of this writing
3756 (so through at least 3.2.1) incorrectly generate
3757 DW_TAG_variable tags. */
3761 /* Get name of field. */
3762 fieldname
= dwarf2_name (die
, cu
);
3763 if (fieldname
== NULL
)
3766 /* Get physical name. */
3767 physname
= dwarf2_linkage_name (die
, cu
);
3769 /* The name is already allocated along with this objfile, so we don't
3770 need to duplicate it for the type. */
3771 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
3772 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3773 FIELD_NAME (*fp
) = fieldname
;
3775 else if (die
->tag
== DW_TAG_inheritance
)
3777 /* C++ base class field. */
3778 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3780 SET_FIELD_BITPOS (*fp
, decode_locdesc (DW_BLOCK (attr
), cu
)
3782 FIELD_BITSIZE (*fp
) = 0;
3783 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3784 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
3785 fip
->nbaseclasses
++;
3789 /* Create the vector of fields, and attach it to the type. */
3792 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3793 struct dwarf2_cu
*cu
)
3795 int nfields
= fip
->nfields
;
3797 /* Record the field count, allocate space for the array of fields,
3798 and create blank accessibility bitfields if necessary. */
3799 TYPE_NFIELDS (type
) = nfields
;
3800 TYPE_FIELDS (type
) = (struct field
*)
3801 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3802 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3804 if (fip
->non_public_fields
)
3806 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3808 TYPE_FIELD_PRIVATE_BITS (type
) =
3809 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3810 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3812 TYPE_FIELD_PROTECTED_BITS (type
) =
3813 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3814 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3816 TYPE_FIELD_IGNORE_BITS (type
) =
3817 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3818 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3821 /* If the type has baseclasses, allocate and clear a bit vector for
3822 TYPE_FIELD_VIRTUAL_BITS. */
3823 if (fip
->nbaseclasses
)
3825 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3826 unsigned char *pointer
;
3828 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3829 pointer
= TYPE_ALLOC (type
, num_bytes
);
3830 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
3831 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3832 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3835 /* Copy the saved-up fields into the field vector. Start from the head
3836 of the list, adding to the tail of the field array, so that they end
3837 up in the same order in the array in which they were added to the list. */
3838 while (nfields
-- > 0)
3840 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3841 switch (fip
->fields
->accessibility
)
3843 case DW_ACCESS_private
:
3844 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3847 case DW_ACCESS_protected
:
3848 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3851 case DW_ACCESS_public
:
3855 /* Unknown accessibility. Complain and treat it as public. */
3857 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
3858 fip
->fields
->accessibility
);
3862 if (nfields
< fip
->nbaseclasses
)
3864 switch (fip
->fields
->virtuality
)
3866 case DW_VIRTUALITY_virtual
:
3867 case DW_VIRTUALITY_pure_virtual
:
3868 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3872 fip
->fields
= fip
->fields
->next
;
3876 /* Add a member function to the proper fieldlist. */
3879 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3880 struct type
*type
, struct dwarf2_cu
*cu
)
3882 struct objfile
*objfile
= cu
->objfile
;
3883 struct attribute
*attr
;
3884 struct fnfieldlist
*flp
;
3886 struct fn_field
*fnp
;
3889 struct nextfnfield
*new_fnfield
;
3890 struct type
*this_type
;
3892 /* Get name of member function. */
3893 fieldname
= dwarf2_name (die
, cu
);
3894 if (fieldname
== NULL
)
3897 /* Get the mangled name. */
3898 physname
= dwarf2_linkage_name (die
, cu
);
3900 /* Look up member function name in fieldlist. */
3901 for (i
= 0; i
< fip
->nfnfields
; i
++)
3903 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3907 /* Create new list element if necessary. */
3908 if (i
< fip
->nfnfields
)
3909 flp
= &fip
->fnfieldlists
[i
];
3912 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3914 fip
->fnfieldlists
= (struct fnfieldlist
*)
3915 xrealloc (fip
->fnfieldlists
,
3916 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3917 * sizeof (struct fnfieldlist
));
3918 if (fip
->nfnfields
== 0)
3919 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3921 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3922 flp
->name
= fieldname
;
3928 /* Create a new member function field and chain it to the field list
3930 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3931 make_cleanup (xfree
, new_fnfield
);
3932 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3933 new_fnfield
->next
= flp
->head
;
3934 flp
->head
= new_fnfield
;
3937 /* Fill in the member function field info. */
3938 fnp
= &new_fnfield
->fnfield
;
3939 /* The name is already allocated along with this objfile, so we don't
3940 need to duplicate it for the type. */
3941 fnp
->physname
= physname
? physname
: "";
3942 fnp
->type
= alloc_type (objfile
);
3943 this_type
= read_type_die (die
, cu
);
3944 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
3946 int nparams
= TYPE_NFIELDS (this_type
);
3948 /* TYPE is the domain of this method, and THIS_TYPE is the type
3949 of the method itself (TYPE_CODE_METHOD). */
3950 smash_to_method_type (fnp
->type
, type
,
3951 TYPE_TARGET_TYPE (this_type
),
3952 TYPE_FIELDS (this_type
),
3953 TYPE_NFIELDS (this_type
),
3954 TYPE_VARARGS (this_type
));
3956 /* Handle static member functions.
3957 Dwarf2 has no clean way to discern C++ static and non-static
3958 member functions. G++ helps GDB by marking the first
3959 parameter for non-static member functions (which is the
3960 this pointer) as artificial. We obtain this information
3961 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3962 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
3963 fnp
->voffset
= VOFFSET_STATIC
;
3966 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
3969 /* Get fcontext from DW_AT_containing_type if present. */
3970 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3971 fnp
->fcontext
= die_containing_type (die
, cu
);
3973 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3974 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3976 /* Get accessibility. */
3977 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3980 switch (DW_UNSND (attr
))
3982 case DW_ACCESS_private
:
3983 fnp
->is_private
= 1;
3985 case DW_ACCESS_protected
:
3986 fnp
->is_protected
= 1;
3991 /* Check for artificial methods. */
3992 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3993 if (attr
&& DW_UNSND (attr
) != 0)
3994 fnp
->is_artificial
= 1;
3996 /* Get index in virtual function table if it is a virtual member function. */
3997 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
4000 /* Support the .debug_loc offsets */
4001 if (attr_form_is_block (attr
))
4003 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
4005 else if (attr_form_is_section_offset (attr
))
4007 dwarf2_complex_location_expr_complaint ();
4011 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
4017 /* Create the vector of member function fields, and attach it to the type. */
4020 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
4021 struct dwarf2_cu
*cu
)
4023 struct fnfieldlist
*flp
;
4024 int total_length
= 0;
4027 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4028 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
4029 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
4031 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
4033 struct nextfnfield
*nfp
= flp
->head
;
4034 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
4037 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
4038 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
4039 fn_flp
->fn_fields
= (struct fn_field
*)
4040 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
4041 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
4042 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
4044 total_length
+= flp
->length
;
4047 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
4048 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
4051 /* Returns non-zero if NAME is the name of a vtable member in CU's
4052 language, zero otherwise. */
4054 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
4056 static const char vptr
[] = "_vptr";
4057 static const char vtable
[] = "vtable";
4059 /* Look for the C++ and Java forms of the vtable. */
4060 if ((cu
->language
== language_java
4061 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
4062 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
4063 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
4069 /* GCC outputs unnamed structures that are really pointers to member
4070 functions, with the ABI-specified layout. If DIE (from CU) describes
4071 such a structure, set its type, and return nonzero. Otherwise return
4074 GCC shouldn't do this; it should just output pointer to member DIEs.
4075 This is GCC PR debug/28767. */
4077 static struct type
*
4078 quirk_gcc_member_function_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
)
4080 struct objfile
*objfile
= cu
->objfile
;
4082 struct die_info
*pfn_die
, *delta_die
;
4083 struct attribute
*pfn_name
, *delta_name
;
4084 struct type
*pfn_type
, *domain_type
;
4086 /* Check for a structure with no name and two children. */
4087 if (die
->tag
!= DW_TAG_structure_type
4088 || dwarf2_attr (die
, DW_AT_name
, cu
) != NULL
4089 || die
->child
== NULL
4090 || die
->child
->sibling
== NULL
4091 || (die
->child
->sibling
->sibling
!= NULL
4092 && die
->child
->sibling
->sibling
->tag
!= DW_TAG_padding
))
4095 /* Check for __pfn and __delta members. */
4096 pfn_die
= die
->child
;
4097 pfn_name
= dwarf2_attr (pfn_die
, DW_AT_name
, cu
);
4098 if (pfn_die
->tag
!= DW_TAG_member
4100 || DW_STRING (pfn_name
) == NULL
4101 || strcmp ("__pfn", DW_STRING (pfn_name
)) != 0)
4104 delta_die
= pfn_die
->sibling
;
4105 delta_name
= dwarf2_attr (delta_die
, DW_AT_name
, cu
);
4106 if (delta_die
->tag
!= DW_TAG_member
4107 || delta_name
== NULL
4108 || DW_STRING (delta_name
) == NULL
4109 || strcmp ("__delta", DW_STRING (delta_name
)) != 0)
4112 /* Find the type of the method. */
4113 pfn_type
= die_type (pfn_die
, cu
);
4114 if (pfn_type
== NULL
4115 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
4116 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
4119 /* Look for the "this" argument. */
4120 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
4121 if (TYPE_NFIELDS (pfn_type
) == 0
4122 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
4125 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
4126 type
= alloc_type (objfile
);
4127 smash_to_method_type (type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
4128 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
4129 TYPE_VARARGS (pfn_type
));
4130 type
= lookup_methodptr_type (type
);
4131 return set_die_type (die
, type
, cu
);
4134 /* Called when we find the DIE that starts a structure or union scope
4135 (definition) to process all dies that define the members of the
4138 NOTE: we need to call struct_type regardless of whether or not the
4139 DIE has an at_name attribute, since it might be an anonymous
4140 structure or union. This gets the type entered into our set of
4143 However, if the structure is incomplete (an opaque struct/union)
4144 then suppress creating a symbol table entry for it since gdb only
4145 wants to find the one with the complete definition. Note that if
4146 it is complete, we just call new_symbol, which does it's own
4147 checking about whether the struct/union is anonymous or not (and
4148 suppresses creating a symbol table entry itself). */
4150 static struct type
*
4151 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4153 struct objfile
*objfile
= cu
->objfile
;
4155 struct attribute
*attr
;
4157 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4159 type
= quirk_gcc_member_function_pointer (die
, cu
);
4163 type
= alloc_type (objfile
);
4164 INIT_CPLUS_SPECIFIC (type
);
4165 name
= dwarf2_name (die
, cu
);
4168 if (cu
->language
== language_cplus
4169 || cu
->language
== language_java
)
4171 const char *new_prefix
= determine_class_name (die
, cu
);
4172 TYPE_TAG_NAME (type
) = (char *) new_prefix
;
4176 /* The name is already allocated along with this objfile, so
4177 we don't need to duplicate it for the type. */
4178 TYPE_TAG_NAME (type
) = name
;
4182 if (die
->tag
== DW_TAG_structure_type
)
4184 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
4186 else if (die
->tag
== DW_TAG_union_type
)
4188 TYPE_CODE (type
) = TYPE_CODE_UNION
;
4192 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
4194 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
4197 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4200 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4204 TYPE_LENGTH (type
) = 0;
4207 TYPE_STUB_SUPPORTED (type
) = 1;
4208 if (die_is_declaration (die
, cu
))
4209 TYPE_STUB (type
) = 1;
4211 /* We need to add the type field to the die immediately so we don't
4212 infinitely recurse when dealing with pointers to the structure
4213 type within the structure itself. */
4214 set_die_type (die
, type
, cu
);
4216 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
4218 struct field_info fi
;
4219 struct die_info
*child_die
;
4221 memset (&fi
, 0, sizeof (struct field_info
));
4223 child_die
= die
->child
;
4225 while (child_die
&& child_die
->tag
)
4227 if (child_die
->tag
== DW_TAG_member
4228 || child_die
->tag
== DW_TAG_variable
)
4230 /* NOTE: carlton/2002-11-05: A C++ static data member
4231 should be a DW_TAG_member that is a declaration, but
4232 all versions of G++ as of this writing (so through at
4233 least 3.2.1) incorrectly generate DW_TAG_variable
4234 tags for them instead. */
4235 dwarf2_add_field (&fi
, child_die
, cu
);
4237 else if (child_die
->tag
== DW_TAG_subprogram
)
4239 /* C++ member function. */
4240 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
4242 else if (child_die
->tag
== DW_TAG_inheritance
)
4244 /* C++ base class field. */
4245 dwarf2_add_field (&fi
, child_die
, cu
);
4247 child_die
= sibling_die (child_die
);
4250 /* Attach fields and member functions to the type. */
4252 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
4255 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
4257 /* Get the type which refers to the base class (possibly this
4258 class itself) which contains the vtable pointer for the current
4259 class from the DW_AT_containing_type attribute. */
4261 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4263 struct type
*t
= die_containing_type (die
, cu
);
4265 TYPE_VPTR_BASETYPE (type
) = t
;
4270 /* Our own class provides vtbl ptr. */
4271 for (i
= TYPE_NFIELDS (t
) - 1;
4272 i
>= TYPE_N_BASECLASSES (t
);
4275 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
4277 if (is_vtable_name (fieldname
, cu
))
4279 TYPE_VPTR_FIELDNO (type
) = i
;
4284 /* Complain if virtual function table field not found. */
4285 if (i
< TYPE_N_BASECLASSES (t
))
4286 complaint (&symfile_complaints
,
4287 _("virtual function table pointer not found when defining class '%s'"),
4288 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
4293 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
4296 else if (cu
->producer
4297 && strncmp (cu
->producer
,
4298 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
4300 /* The IBM XLC compiler does not provide direct indication
4301 of the containing type, but the vtable pointer is
4302 always named __vfp. */
4306 for (i
= TYPE_NFIELDS (type
) - 1;
4307 i
>= TYPE_N_BASECLASSES (type
);
4310 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
4312 TYPE_VPTR_FIELDNO (type
) = i
;
4313 TYPE_VPTR_BASETYPE (type
) = type
;
4321 do_cleanups (back_to
);
4326 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4328 struct objfile
*objfile
= cu
->objfile
;
4329 struct die_info
*child_die
= die
->child
;
4330 struct type
*this_type
;
4332 this_type
= get_die_type (die
, cu
);
4333 if (this_type
== NULL
)
4334 this_type
= read_structure_type (die
, cu
);
4336 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
4337 snapshots) has been known to create a die giving a declaration
4338 for a class that has, as a child, a die giving a definition for a
4339 nested class. So we have to process our children even if the
4340 current die is a declaration. Normally, of course, a declaration
4341 won't have any children at all. */
4343 while (child_die
!= NULL
&& child_die
->tag
)
4345 if (child_die
->tag
== DW_TAG_member
4346 || child_die
->tag
== DW_TAG_variable
4347 || child_die
->tag
== DW_TAG_inheritance
)
4352 process_die (child_die
, cu
);
4354 child_die
= sibling_die (child_die
);
4357 /* Do not consider external references. According to the DWARF standard,
4358 these DIEs are identified by the fact that they have no byte_size
4359 attribute, and a declaration attribute. */
4360 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
4361 || !die_is_declaration (die
, cu
))
4362 new_symbol (die
, this_type
, cu
);
4365 /* Given a DW_AT_enumeration_type die, set its type. We do not
4366 complete the type's fields yet, or create any symbols. */
4368 static struct type
*
4369 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4371 struct objfile
*objfile
= cu
->objfile
;
4373 struct attribute
*attr
;
4376 type
= alloc_type (objfile
);
4378 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4379 name
= dwarf2_full_name (die
, cu
);
4381 TYPE_TAG_NAME (type
) = (char *) name
;
4383 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4386 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4390 TYPE_LENGTH (type
) = 0;
4393 /* The enumeration DIE can be incomplete. In Ada, any type can be
4394 declared as private in the package spec, and then defined only
4395 inside the package body. Such types are known as Taft Amendment
4396 Types. When another package uses such a type, an incomplete DIE
4397 may be generated by the compiler. */
4398 if (die_is_declaration (die
, cu
))
4399 TYPE_STUB (type
) = 1;
4401 return set_die_type (die
, type
, cu
);
4404 /* Determine the name of the type represented by DIE, which should be
4405 a named C++ or Java compound type. Return the name in question,
4406 allocated on the objfile obstack. */
4409 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
4411 const char *new_prefix
= NULL
;
4413 /* If we don't have namespace debug info, guess the name by trying
4414 to demangle the names of members, just like we did in
4415 guess_structure_name. */
4416 if (!processing_has_namespace_info
)
4418 struct die_info
*child
;
4420 for (child
= die
->child
;
4421 child
!= NULL
&& child
->tag
!= 0;
4422 child
= sibling_die (child
))
4424 if (child
->tag
== DW_TAG_subprogram
)
4427 = language_class_name_from_physname (cu
->language_defn
,
4431 if (phys_prefix
!= NULL
)
4434 = obsavestring (phys_prefix
, strlen (phys_prefix
),
4435 &cu
->objfile
->objfile_obstack
);
4436 xfree (phys_prefix
);
4443 if (new_prefix
== NULL
)
4444 new_prefix
= dwarf2_full_name (die
, cu
);
4449 /* Given a pointer to a die which begins an enumeration, process all
4450 the dies that define the members of the enumeration, and create the
4451 symbol for the enumeration type.
4453 NOTE: We reverse the order of the element list. */
4456 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4458 struct objfile
*objfile
= cu
->objfile
;
4459 struct die_info
*child_die
;
4460 struct field
*fields
;
4463 int unsigned_enum
= 1;
4465 struct type
*this_type
;
4469 this_type
= get_die_type (die
, cu
);
4470 if (this_type
== NULL
)
4471 this_type
= read_enumeration_type (die
, cu
);
4472 if (die
->child
!= NULL
)
4474 child_die
= die
->child
;
4475 while (child_die
&& child_die
->tag
)
4477 if (child_die
->tag
!= DW_TAG_enumerator
)
4479 process_die (child_die
, cu
);
4483 name
= dwarf2_name (child_die
, cu
);
4486 sym
= new_symbol (child_die
, this_type
, cu
);
4487 if (SYMBOL_VALUE (sym
) < 0)
4490 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4492 fields
= (struct field
*)
4494 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
4495 * sizeof (struct field
));
4498 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
4499 FIELD_TYPE (fields
[num_fields
]) = NULL
;
4500 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
4501 FIELD_BITSIZE (fields
[num_fields
]) = 0;
4507 child_die
= sibling_die (child_die
);
4512 TYPE_NFIELDS (this_type
) = num_fields
;
4513 TYPE_FIELDS (this_type
) = (struct field
*)
4514 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
4515 memcpy (TYPE_FIELDS (this_type
), fields
,
4516 sizeof (struct field
) * num_fields
);
4520 TYPE_UNSIGNED (this_type
) = 1;
4523 new_symbol (die
, this_type
, cu
);
4526 /* Extract all information from a DW_TAG_array_type DIE and put it in
4527 the DIE's type field. For now, this only handles one dimensional
4530 static struct type
*
4531 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4533 struct objfile
*objfile
= cu
->objfile
;
4534 struct die_info
*child_die
;
4535 struct type
*type
= NULL
;
4536 struct type
*element_type
, *range_type
, *index_type
;
4537 struct type
**range_types
= NULL
;
4538 struct attribute
*attr
;
4540 struct cleanup
*back_to
;
4543 element_type
= die_type (die
, cu
);
4545 /* Irix 6.2 native cc creates array types without children for
4546 arrays with unspecified length. */
4547 if (die
->child
== NULL
)
4549 index_type
= builtin_type_int32
;
4550 range_type
= create_range_type (NULL
, index_type
, 0, -1);
4551 type
= create_array_type (NULL
, element_type
, range_type
);
4552 return set_die_type (die
, type
, cu
);
4555 back_to
= make_cleanup (null_cleanup
, NULL
);
4556 child_die
= die
->child
;
4557 while (child_die
&& child_die
->tag
)
4559 if (child_die
->tag
== DW_TAG_subrange_type
)
4561 struct type
*child_type
= read_type_die (child_die
, cu
);
4562 if (child_type
!= NULL
)
4564 /* The range type was succesfully read. Save it for
4565 the array type creation. */
4566 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
4568 range_types
= (struct type
**)
4569 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
4570 * sizeof (struct type
*));
4572 make_cleanup (free_current_contents
, &range_types
);
4574 range_types
[ndim
++] = child_type
;
4577 child_die
= sibling_die (child_die
);
4580 /* Dwarf2 dimensions are output from left to right, create the
4581 necessary array types in backwards order. */
4583 type
= element_type
;
4585 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
4589 type
= create_array_type (NULL
, type
, range_types
[i
++]);
4594 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
4597 /* Understand Dwarf2 support for vector types (like they occur on
4598 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4599 array type. This is not part of the Dwarf2/3 standard yet, but a
4600 custom vendor extension. The main difference between a regular
4601 array and the vector variant is that vectors are passed by value
4603 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4605 make_vector_type (type
);
4607 name
= dwarf2_name (die
, cu
);
4609 TYPE_NAME (type
) = name
;
4611 do_cleanups (back_to
);
4613 /* Install the type in the die. */
4614 return set_die_type (die
, type
, cu
);
4617 static enum dwarf_array_dim_ordering
4618 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4620 struct attribute
*attr
;
4622 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4624 if (attr
) return DW_SND (attr
);
4627 GNU F77 is a special case, as at 08/2004 array type info is the
4628 opposite order to the dwarf2 specification, but data is still
4629 laid out as per normal fortran.
4631 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4635 if (cu
->language
== language_fortran
&&
4636 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4638 return DW_ORD_row_major
;
4641 switch (cu
->language_defn
->la_array_ordering
)
4643 case array_column_major
:
4644 return DW_ORD_col_major
;
4645 case array_row_major
:
4647 return DW_ORD_row_major
;
4651 /* Extract all information from a DW_TAG_set_type DIE and put it in
4652 the DIE's type field. */
4654 static struct type
*
4655 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4657 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
4659 return set_die_type (die
, set_type
, cu
);
4662 /* First cut: install each common block member as a global variable. */
4665 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4667 struct die_info
*child_die
;
4668 struct attribute
*attr
;
4670 CORE_ADDR base
= (CORE_ADDR
) 0;
4672 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4675 /* Support the .debug_loc offsets */
4676 if (attr_form_is_block (attr
))
4678 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4680 else if (attr_form_is_section_offset (attr
))
4682 dwarf2_complex_location_expr_complaint ();
4686 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4687 "common block member");
4690 if (die
->child
!= NULL
)
4692 child_die
= die
->child
;
4693 while (child_die
&& child_die
->tag
)
4695 sym
= new_symbol (child_die
, NULL
, cu
);
4696 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4699 SYMBOL_VALUE_ADDRESS (sym
) =
4700 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4701 add_symbol_to_list (sym
, &global_symbols
);
4703 child_die
= sibling_die (child_die
);
4708 /* Create a type for a C++ namespace. */
4710 static struct type
*
4711 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4713 struct objfile
*objfile
= cu
->objfile
;
4714 const char *previous_prefix
, *name
;
4718 /* For extensions, reuse the type of the original namespace. */
4719 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
4721 struct die_info
*ext_die
;
4722 struct dwarf2_cu
*ext_cu
= cu
;
4723 ext_die
= dwarf2_extension (die
, &ext_cu
);
4724 type
= read_type_die (ext_die
, ext_cu
);
4725 return set_die_type (die
, type
, cu
);
4728 name
= namespace_name (die
, &is_anonymous
, cu
);
4730 /* Now build the name of the current namespace. */
4732 previous_prefix
= determine_prefix (die
, cu
);
4733 if (previous_prefix
[0] != '\0')
4734 name
= typename_concat (&objfile
->objfile_obstack
,
4735 previous_prefix
, name
, cu
);
4737 /* Create the type. */
4738 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
4740 TYPE_NAME (type
) = (char *) name
;
4741 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4743 set_die_type (die
, type
, cu
);
4748 /* Read a C++ namespace. */
4751 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4753 struct objfile
*objfile
= cu
->objfile
;
4757 /* Add a symbol associated to this if we haven't seen the namespace
4758 before. Also, add a using directive if it's an anonymous
4761 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
4765 type
= read_type_die (die
, cu
);
4766 new_symbol (die
, type
, cu
);
4768 name
= namespace_name (die
, &is_anonymous
, cu
);
4771 const char *previous_prefix
= determine_prefix (die
, cu
);
4772 cp_add_using_directive (TYPE_NAME (type
),
4773 strlen (previous_prefix
),
4774 strlen (TYPE_NAME (type
)));
4778 if (die
->child
!= NULL
)
4780 struct die_info
*child_die
= die
->child
;
4782 while (child_die
&& child_die
->tag
)
4784 process_die (child_die
, cu
);
4785 child_die
= sibling_die (child_die
);
4790 /* Read a Fortran module. */
4793 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
4795 struct die_info
*child_die
= die
->child
;
4797 /* FIXME: Support the separate Fortran module namespaces. */
4799 while (child_die
&& child_die
->tag
)
4801 process_die (child_die
, cu
);
4802 child_die
= sibling_die (child_die
);
4806 /* Return the name of the namespace represented by DIE. Set
4807 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4811 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
4813 struct die_info
*current_die
;
4814 const char *name
= NULL
;
4816 /* Loop through the extensions until we find a name. */
4818 for (current_die
= die
;
4819 current_die
!= NULL
;
4820 current_die
= dwarf2_extension (die
, &cu
))
4822 name
= dwarf2_name (current_die
, cu
);
4827 /* Is it an anonymous namespace? */
4829 *is_anonymous
= (name
== NULL
);
4831 name
= "(anonymous namespace)";
4836 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4837 the user defined type vector. */
4839 static struct type
*
4840 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4842 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
4843 struct comp_unit_head
*cu_header
= &cu
->header
;
4845 struct attribute
*attr_byte_size
;
4846 struct attribute
*attr_address_class
;
4847 int byte_size
, addr_class
;
4849 type
= lookup_pointer_type (die_type (die
, cu
));
4851 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4853 byte_size
= DW_UNSND (attr_byte_size
);
4855 byte_size
= cu_header
->addr_size
;
4857 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
4858 if (attr_address_class
)
4859 addr_class
= DW_UNSND (attr_address_class
);
4861 addr_class
= DW_ADDR_none
;
4863 /* If the pointer size or address class is different than the
4864 default, create a type variant marked as such and set the
4865 length accordingly. */
4866 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
4868 if (gdbarch_address_class_type_flags_p (gdbarch
))
4872 type_flags
= gdbarch_address_class_type_flags
4873 (gdbarch
, byte_size
, addr_class
);
4874 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
4876 type
= make_type_with_address_space (type
, type_flags
);
4878 else if (TYPE_LENGTH (type
) != byte_size
)
4880 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
4883 /* Should we also complain about unhandled address classes? */
4887 TYPE_LENGTH (type
) = byte_size
;
4888 return set_die_type (die
, type
, cu
);
4891 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4892 the user defined type vector. */
4894 static struct type
*
4895 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4897 struct objfile
*objfile
= cu
->objfile
;
4899 struct type
*to_type
;
4900 struct type
*domain
;
4902 to_type
= die_type (die
, cu
);
4903 domain
= die_containing_type (die
, cu
);
4905 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
4906 type
= lookup_methodptr_type (to_type
);
4908 type
= lookup_memberptr_type (to_type
, domain
);
4910 return set_die_type (die
, type
, cu
);
4913 /* Extract all information from a DW_TAG_reference_type DIE and add to
4914 the user defined type vector. */
4916 static struct type
*
4917 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4919 struct comp_unit_head
*cu_header
= &cu
->header
;
4921 struct attribute
*attr
;
4923 type
= lookup_reference_type (die_type (die
, cu
));
4924 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4927 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4931 TYPE_LENGTH (type
) = cu_header
->addr_size
;
4933 return set_die_type (die
, type
, cu
);
4936 static struct type
*
4937 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4939 struct type
*base_type
, *cv_type
;
4941 base_type
= die_type (die
, cu
);
4942 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
4943 return set_die_type (die
, cv_type
, cu
);
4946 static struct type
*
4947 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4949 struct type
*base_type
, *cv_type
;
4951 base_type
= die_type (die
, cu
);
4952 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
4953 return set_die_type (die
, cv_type
, cu
);
4956 /* Extract all information from a DW_TAG_string_type DIE and add to
4957 the user defined type vector. It isn't really a user defined type,
4958 but it behaves like one, with other DIE's using an AT_user_def_type
4959 attribute to reference it. */
4961 static struct type
*
4962 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4964 struct objfile
*objfile
= cu
->objfile
;
4965 struct type
*type
, *range_type
, *index_type
, *char_type
;
4966 struct attribute
*attr
;
4967 unsigned int length
;
4969 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4972 length
= DW_UNSND (attr
);
4976 /* check for the DW_AT_byte_size attribute */
4977 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4980 length
= DW_UNSND (attr
);
4988 index_type
= builtin_type_int32
;
4989 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4990 type
= create_string_type (NULL
, range_type
);
4992 return set_die_type (die
, type
, cu
);
4995 /* Handle DIES due to C code like:
4999 int (*funcp)(int a, long l);
5003 ('funcp' generates a DW_TAG_subroutine_type DIE)
5006 static struct type
*
5007 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5009 struct type
*type
; /* Type that this function returns */
5010 struct type
*ftype
; /* Function that returns above type */
5011 struct attribute
*attr
;
5013 type
= die_type (die
, cu
);
5014 ftype
= make_function_type (type
, (struct type
**) 0);
5016 /* All functions in C++, Pascal and Java have prototypes. */
5017 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
5018 if ((attr
&& (DW_UNSND (attr
) != 0))
5019 || cu
->language
== language_cplus
5020 || cu
->language
== language_java
5021 || cu
->language
== language_pascal
)
5022 TYPE_PROTOTYPED (ftype
) = 1;
5024 /* Store the calling convention in the type if it's available in
5025 the subroutine die. Otherwise set the calling convention to
5026 the default value DW_CC_normal. */
5027 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
5028 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
5030 if (die
->child
!= NULL
)
5032 struct die_info
*child_die
;
5036 /* Count the number of parameters.
5037 FIXME: GDB currently ignores vararg functions, but knows about
5038 vararg member functions. */
5039 child_die
= die
->child
;
5040 while (child_die
&& child_die
->tag
)
5042 if (child_die
->tag
== DW_TAG_formal_parameter
)
5044 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
5045 TYPE_VARARGS (ftype
) = 1;
5046 child_die
= sibling_die (child_die
);
5049 /* Allocate storage for parameters and fill them in. */
5050 TYPE_NFIELDS (ftype
) = nparams
;
5051 TYPE_FIELDS (ftype
) = (struct field
*)
5052 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
5054 child_die
= die
->child
;
5055 while (child_die
&& child_die
->tag
)
5057 if (child_die
->tag
== DW_TAG_formal_parameter
)
5059 /* Dwarf2 has no clean way to discern C++ static and non-static
5060 member functions. G++ helps GDB by marking the first
5061 parameter for non-static member functions (which is the
5062 this pointer) as artificial. We pass this information
5063 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
5064 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
5066 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
5068 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
5069 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
5072 child_die
= sibling_die (child_die
);
5076 return set_die_type (die
, ftype
, cu
);
5079 static struct type
*
5080 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
5082 struct objfile
*objfile
= cu
->objfile
;
5083 struct attribute
*attr
;
5084 const char *name
= NULL
;
5085 struct type
*this_type
;
5087 name
= dwarf2_full_name (die
, cu
);
5088 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
5089 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
5090 TYPE_NAME (this_type
) = (char *) name
;
5091 set_die_type (die
, this_type
, cu
);
5092 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
5096 /* Find a representation of a given base type and install
5097 it in the TYPE field of the die. */
5099 static struct type
*
5100 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5102 struct objfile
*objfile
= cu
->objfile
;
5104 struct attribute
*attr
;
5105 int encoding
= 0, size
= 0;
5107 enum type_code code
= TYPE_CODE_INT
;
5109 struct type
*target_type
= NULL
;
5111 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
5114 encoding
= DW_UNSND (attr
);
5116 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5119 size
= DW_UNSND (attr
);
5121 name
= dwarf2_name (die
, cu
);
5124 complaint (&symfile_complaints
,
5125 _("DW_AT_name missing from DW_TAG_base_type"));
5130 case DW_ATE_address
:
5131 /* Turn DW_ATE_address into a void * pointer. */
5132 code
= TYPE_CODE_PTR
;
5133 type_flags
|= TYPE_FLAG_UNSIGNED
;
5134 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
5136 case DW_ATE_boolean
:
5137 code
= TYPE_CODE_BOOL
;
5138 type_flags
|= TYPE_FLAG_UNSIGNED
;
5140 case DW_ATE_complex_float
:
5141 code
= TYPE_CODE_COMPLEX
;
5142 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
5144 case DW_ATE_decimal_float
:
5145 code
= TYPE_CODE_DECFLOAT
;
5148 code
= TYPE_CODE_FLT
;
5152 case DW_ATE_unsigned
:
5153 type_flags
|= TYPE_FLAG_UNSIGNED
;
5155 case DW_ATE_signed_char
:
5156 if (cu
->language
== language_ada
|| cu
->language
== language_m2
5157 || cu
->language
== language_pascal
)
5158 code
= TYPE_CODE_CHAR
;
5160 case DW_ATE_unsigned_char
:
5161 if (cu
->language
== language_ada
|| cu
->language
== language_m2
5162 || cu
->language
== language_pascal
)
5163 code
= TYPE_CODE_CHAR
;
5164 type_flags
|= TYPE_FLAG_UNSIGNED
;
5167 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
5168 dwarf_type_encoding_name (encoding
));
5172 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
5173 TYPE_NAME (type
) = name
;
5174 TYPE_TARGET_TYPE (type
) = target_type
;
5176 if (name
&& strcmp (name
, "char") == 0)
5177 TYPE_NOSIGN (type
) = 1;
5179 return set_die_type (die
, type
, cu
);
5182 /* Read the given DW_AT_subrange DIE. */
5184 static struct type
*
5185 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5187 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5188 struct type
*base_type
;
5189 struct type
*range_type
;
5190 struct attribute
*attr
;
5195 base_type
= die_type (die
, cu
);
5196 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
5198 complaint (&symfile_complaints
,
5199 _("DW_AT_type missing from DW_TAG_subrange_type"));
5201 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
5202 0, NULL
, cu
->objfile
);
5205 if (cu
->language
== language_fortran
)
5207 /* FORTRAN implies a lower bound of 1, if not given. */
5211 /* FIXME: For variable sized arrays either of these could be
5212 a variable rather than a constant value. We'll allow it,
5213 but we don't know how to handle it. */
5214 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
5216 low
= dwarf2_get_attr_constant_value (attr
, 0);
5218 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
5221 if (attr
->form
== DW_FORM_block1
)
5223 /* GCC encodes arrays with unspecified or dynamic length
5224 with a DW_FORM_block1 attribute.
5225 FIXME: GDB does not yet know how to handle dynamic
5226 arrays properly, treat them as arrays with unspecified
5229 FIXME: jimb/2003-09-22: GDB does not really know
5230 how to handle arrays of unspecified length
5231 either; we just represent them as zero-length
5232 arrays. Choose an appropriate upper bound given
5233 the lower bound we've computed above. */
5237 high
= dwarf2_get_attr_constant_value (attr
, 1);
5240 range_type
= create_range_type (NULL
, base_type
, low
, high
);
5242 name
= dwarf2_name (die
, cu
);
5244 TYPE_NAME (range_type
) = name
;
5246 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5248 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
5250 return set_die_type (die
, range_type
, cu
);
5253 static struct type
*
5254 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5258 /* For now, we only support the C meaning of an unspecified type: void. */
5260 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
5261 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
5263 return set_die_type (die
, type
, cu
);
5266 /* Trivial hash function for die_info: the hash value of a DIE
5267 is its offset in .debug_info for this objfile. */
5270 die_hash (const void *item
)
5272 const struct die_info
*die
= item
;
5276 /* Trivial comparison function for die_info structures: two DIEs
5277 are equal if they have the same offset. */
5280 die_eq (const void *item_lhs
, const void *item_rhs
)
5282 const struct die_info
*die_lhs
= item_lhs
;
5283 const struct die_info
*die_rhs
= item_rhs
;
5284 return die_lhs
->offset
== die_rhs
->offset
;
5287 /* Read a whole compilation unit into a linked list of dies. */
5289 static struct die_info
*
5290 read_comp_unit (gdb_byte
*info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
5293 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5297 &cu
->comp_unit_obstack
,
5298 hashtab_obstack_allocate
,
5299 dummy_obstack_deallocate
);
5301 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
5304 /* Main entry point for reading a DIE and all children.
5305 Read the DIE and dump it if requested. */
5307 static struct die_info
*
5308 read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
5309 struct dwarf2_cu
*cu
,
5310 gdb_byte
**new_info_ptr
,
5311 struct die_info
*parent
)
5313 struct die_info
*result
= read_die_and_children_1 (info_ptr
, abfd
, cu
,
5314 new_info_ptr
, parent
);
5316 if (dwarf2_die_debug
)
5318 fprintf_unfiltered (gdb_stdlog
, "Read die from .debug_info:\n");
5319 dump_die (result
, dwarf2_die_debug
);
5325 /* Read a single die and all its descendents. Set the die's sibling
5326 field to NULL; set other fields in the die correctly, and set all
5327 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
5328 location of the info_ptr after reading all of those dies. PARENT
5329 is the parent of the die in question. */
5331 static struct die_info
*
5332 read_die_and_children_1 (gdb_byte
*info_ptr
, bfd
*abfd
,
5333 struct dwarf2_cu
*cu
,
5334 gdb_byte
**new_info_ptr
,
5335 struct die_info
*parent
)
5337 struct die_info
*die
;
5341 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
5344 *new_info_ptr
= cur_ptr
;
5347 store_in_ref_table (die
, cu
);
5351 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
5357 *new_info_ptr
= cur_ptr
;
5360 die
->sibling
= NULL
;
5361 die
->parent
= parent
;
5365 /* Read a die, all of its descendents, and all of its siblings; set
5366 all of the fields of all of the dies correctly. Arguments are as
5367 in read_die_and_children. */
5369 static struct die_info
*
5370 read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
5371 struct dwarf2_cu
*cu
,
5372 gdb_byte
**new_info_ptr
,
5373 struct die_info
*parent
)
5375 struct die_info
*first_die
, *last_sibling
;
5379 first_die
= last_sibling
= NULL
;
5383 struct die_info
*die
5384 = read_die_and_children_1 (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
5388 *new_info_ptr
= cur_ptr
;
5395 last_sibling
->sibling
= die
;
5401 /* Decompress a section that was compressed using zlib. Store the
5402 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
5405 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
5406 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
5408 bfd
*abfd
= objfile
->obfd
;
5410 error (_("Support for zlib-compressed DWARF data (from '%s') "
5411 "is disabled in this copy of GDB"),
5412 bfd_get_filename (abfd
));
5414 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
5415 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
5416 bfd_size_type uncompressed_size
;
5417 gdb_byte
*uncompressed_buffer
;
5420 int header_size
= 12;
5422 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5423 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
5424 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5425 bfd_get_filename (abfd
));
5427 /* Read the zlib header. In this case, it should be "ZLIB" followed
5428 by the uncompressed section size, 8 bytes in big-endian order. */
5429 if (compressed_size
< header_size
5430 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
5431 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
5432 bfd_get_filename (abfd
));
5433 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
5434 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
5435 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
5436 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
5437 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
5438 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
5439 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
5440 uncompressed_size
+= compressed_buffer
[11];
5442 /* It is possible the section consists of several compressed
5443 buffers concatenated together, so we uncompress in a loop. */
5447 strm
.avail_in
= compressed_size
- header_size
;
5448 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
5449 strm
.avail_out
= uncompressed_size
;
5450 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
5452 rc
= inflateInit (&strm
);
5453 while (strm
.avail_in
> 0)
5456 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
5457 bfd_get_filename (abfd
), rc
);
5458 strm
.next_out
= ((Bytef
*) uncompressed_buffer
5459 + (uncompressed_size
- strm
.avail_out
));
5460 rc
= inflate (&strm
, Z_FINISH
);
5461 if (rc
!= Z_STREAM_END
)
5462 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
5463 bfd_get_filename (abfd
), rc
);
5464 rc
= inflateReset (&strm
);
5466 rc
= inflateEnd (&strm
);
5468 || strm
.avail_out
!= 0)
5469 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
5470 bfd_get_filename (abfd
), rc
);
5472 xfree (compressed_buffer
);
5473 *outbuf
= uncompressed_buffer
;
5474 *outsize
= uncompressed_size
;
5479 /* Read the contents of the section at OFFSET and of size SIZE from the
5480 object file specified by OBJFILE into the objfile_obstack and return it.
5481 If the section is compressed, uncompress it before returning. */
5484 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
5486 bfd
*abfd
= objfile
->obfd
;
5487 gdb_byte
*buf
, *retbuf
;
5488 bfd_size_type size
= bfd_get_section_size (sectp
);
5489 unsigned char header
[4];
5494 /* Check if the file has a 4-byte header indicating compression. */
5495 if (size
> sizeof (header
)
5496 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
5497 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
5499 /* Upon decompression, update the buffer and its size. */
5500 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
5502 zlib_decompress_section (objfile
, sectp
, &buf
, &size
);
5503 dwarf2_resize_section (sectp
, size
);
5508 /* If we get here, we are a normal, not-compressed section. */
5509 buf
= obstack_alloc (&objfile
->objfile_obstack
, size
);
5510 /* When debugging .o files, we may need to apply relocations; see
5511 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
5512 We never compress sections in .o files, so we only need to
5513 try this when the section is not compressed. */
5514 retbuf
= symfile_relocate_debug_section (abfd
, sectp
, buf
);
5518 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5519 || bfd_bread (buf
, size
, abfd
) != size
)
5520 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5521 bfd_get_filename (abfd
));
5526 /* In DWARF version 2, the description of the debugging information is
5527 stored in a separate .debug_abbrev section. Before we read any
5528 dies from a section we read in all abbreviations and install them
5529 in a hash table. This function also sets flags in CU describing
5530 the data found in the abbrev table. */
5533 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
5535 struct comp_unit_head
*cu_header
= &cu
->header
;
5536 gdb_byte
*abbrev_ptr
;
5537 struct abbrev_info
*cur_abbrev
;
5538 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
5539 unsigned int abbrev_form
, hash_number
;
5540 struct attr_abbrev
*cur_attrs
;
5541 unsigned int allocated_attrs
;
5543 /* Initialize dwarf2 abbrevs */
5544 obstack_init (&cu
->abbrev_obstack
);
5545 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
5547 * sizeof (struct abbrev_info
*)));
5548 memset (cu
->dwarf2_abbrevs
, 0,
5549 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
5551 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
5552 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5553 abbrev_ptr
+= bytes_read
;
5555 allocated_attrs
= ATTR_ALLOC_CHUNK
;
5556 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
5558 /* loop until we reach an abbrev number of 0 */
5559 while (abbrev_number
)
5561 cur_abbrev
= dwarf_alloc_abbrev (cu
);
5563 /* read in abbrev header */
5564 cur_abbrev
->number
= abbrev_number
;
5565 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5566 abbrev_ptr
+= bytes_read
;
5567 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
5570 if (cur_abbrev
->tag
== DW_TAG_namespace
)
5571 cu
->has_namespace_info
= 1;
5573 /* now read in declarations */
5574 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5575 abbrev_ptr
+= bytes_read
;
5576 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5577 abbrev_ptr
+= bytes_read
;
5580 if (cur_abbrev
->num_attrs
== allocated_attrs
)
5582 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
5584 = xrealloc (cur_attrs
, (allocated_attrs
5585 * sizeof (struct attr_abbrev
)));
5588 /* Record whether this compilation unit might have
5589 inter-compilation-unit references. If we don't know what form
5590 this attribute will have, then it might potentially be a
5591 DW_FORM_ref_addr, so we conservatively expect inter-CU
5594 if (abbrev_form
== DW_FORM_ref_addr
5595 || abbrev_form
== DW_FORM_indirect
)
5596 cu
->has_form_ref_addr
= 1;
5598 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
5599 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
5600 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5601 abbrev_ptr
+= bytes_read
;
5602 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5603 abbrev_ptr
+= bytes_read
;
5606 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
5607 (cur_abbrev
->num_attrs
5608 * sizeof (struct attr_abbrev
)));
5609 memcpy (cur_abbrev
->attrs
, cur_attrs
,
5610 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
5612 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
5613 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
5614 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
5616 /* Get next abbreviation.
5617 Under Irix6 the abbreviations for a compilation unit are not
5618 always properly terminated with an abbrev number of 0.
5619 Exit loop if we encounter an abbreviation which we have
5620 already read (which means we are about to read the abbreviations
5621 for the next compile unit) or if the end of the abbreviation
5622 table is reached. */
5623 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
5624 >= dwarf2_per_objfile
->abbrev_size
)
5626 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5627 abbrev_ptr
+= bytes_read
;
5628 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
5635 /* Release the memory used by the abbrev table for a compilation unit. */
5638 dwarf2_free_abbrev_table (void *ptr_to_cu
)
5640 struct dwarf2_cu
*cu
= ptr_to_cu
;
5642 obstack_free (&cu
->abbrev_obstack
, NULL
);
5643 cu
->dwarf2_abbrevs
= NULL
;
5646 /* Lookup an abbrev_info structure in the abbrev hash table. */
5648 static struct abbrev_info
*
5649 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
5651 unsigned int hash_number
;
5652 struct abbrev_info
*abbrev
;
5654 hash_number
= number
% ABBREV_HASH_SIZE
;
5655 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
5659 if (abbrev
->number
== number
)
5662 abbrev
= abbrev
->next
;
5667 /* Returns nonzero if TAG represents a type that we might generate a partial
5671 is_type_tag_for_partial (int tag
)
5676 /* Some types that would be reasonable to generate partial symbols for,
5677 that we don't at present. */
5678 case DW_TAG_array_type
:
5679 case DW_TAG_file_type
:
5680 case DW_TAG_ptr_to_member_type
:
5681 case DW_TAG_set_type
:
5682 case DW_TAG_string_type
:
5683 case DW_TAG_subroutine_type
:
5685 case DW_TAG_base_type
:
5686 case DW_TAG_class_type
:
5687 case DW_TAG_interface_type
:
5688 case DW_TAG_enumeration_type
:
5689 case DW_TAG_structure_type
:
5690 case DW_TAG_subrange_type
:
5691 case DW_TAG_typedef
:
5692 case DW_TAG_union_type
:
5699 /* Load all DIEs that are interesting for partial symbols into memory. */
5701 static struct partial_die_info
*
5702 load_partial_dies (bfd
*abfd
, gdb_byte
*info_ptr
, int building_psymtab
,
5703 struct dwarf2_cu
*cu
)
5705 struct partial_die_info
*part_die
;
5706 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
5707 struct abbrev_info
*abbrev
;
5708 unsigned int bytes_read
;
5709 unsigned int load_all
= 0;
5711 int nesting_level
= 1;
5716 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
5720 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5724 &cu
->comp_unit_obstack
,
5725 hashtab_obstack_allocate
,
5726 dummy_obstack_deallocate
);
5728 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5729 sizeof (struct partial_die_info
));
5733 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5735 /* A NULL abbrev means the end of a series of children. */
5738 if (--nesting_level
== 0)
5740 /* PART_DIE was probably the last thing allocated on the
5741 comp_unit_obstack, so we could call obstack_free
5742 here. We don't do that because the waste is small,
5743 and will be cleaned up when we're done with this
5744 compilation unit. This way, we're also more robust
5745 against other users of the comp_unit_obstack. */
5748 info_ptr
+= bytes_read
;
5749 last_die
= parent_die
;
5750 parent_die
= parent_die
->die_parent
;
5754 /* Check whether this DIE is interesting enough to save. Normally
5755 we would not be interested in members here, but there may be
5756 later variables referencing them via DW_AT_specification (for
5759 && !is_type_tag_for_partial (abbrev
->tag
)
5760 && abbrev
->tag
!= DW_TAG_enumerator
5761 && abbrev
->tag
!= DW_TAG_subprogram
5762 && abbrev
->tag
!= DW_TAG_lexical_block
5763 && abbrev
->tag
!= DW_TAG_variable
5764 && abbrev
->tag
!= DW_TAG_namespace
5765 && abbrev
->tag
!= DW_TAG_member
)
5767 /* Otherwise we skip to the next sibling, if any. */
5768 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5772 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5773 abfd
, info_ptr
, cu
);
5775 /* This two-pass algorithm for processing partial symbols has a
5776 high cost in cache pressure. Thus, handle some simple cases
5777 here which cover the majority of C partial symbols. DIEs
5778 which neither have specification tags in them, nor could have
5779 specification tags elsewhere pointing at them, can simply be
5780 processed and discarded.
5782 This segment is also optional; scan_partial_symbols and
5783 add_partial_symbol will handle these DIEs if we chain
5784 them in normally. When compilers which do not emit large
5785 quantities of duplicate debug information are more common,
5786 this code can probably be removed. */
5788 /* Any complete simple types at the top level (pretty much all
5789 of them, for a language without namespaces), can be processed
5791 if (parent_die
== NULL
5792 && part_die
->has_specification
== 0
5793 && part_die
->is_declaration
== 0
5794 && (part_die
->tag
== DW_TAG_typedef
5795 || part_die
->tag
== DW_TAG_base_type
5796 || part_die
->tag
== DW_TAG_subrange_type
))
5798 if (building_psymtab
&& part_die
->name
!= NULL
)
5799 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5800 VAR_DOMAIN
, LOC_TYPEDEF
,
5801 &cu
->objfile
->static_psymbols
,
5802 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5803 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5807 /* If we're at the second level, and we're an enumerator, and
5808 our parent has no specification (meaning possibly lives in a
5809 namespace elsewhere), then we can add the partial symbol now
5810 instead of queueing it. */
5811 if (part_die
->tag
== DW_TAG_enumerator
5812 && parent_die
!= NULL
5813 && parent_die
->die_parent
== NULL
5814 && parent_die
->tag
== DW_TAG_enumeration_type
5815 && parent_die
->has_specification
== 0)
5817 if (part_die
->name
== NULL
)
5818 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5819 else if (building_psymtab
)
5820 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5821 VAR_DOMAIN
, LOC_CONST
,
5822 (cu
->language
== language_cplus
5823 || cu
->language
== language_java
)
5824 ? &cu
->objfile
->global_psymbols
5825 : &cu
->objfile
->static_psymbols
,
5826 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5828 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5832 /* We'll save this DIE so link it in. */
5833 part_die
->die_parent
= parent_die
;
5834 part_die
->die_sibling
= NULL
;
5835 part_die
->die_child
= NULL
;
5837 if (last_die
&& last_die
== parent_die
)
5838 last_die
->die_child
= part_die
;
5840 last_die
->die_sibling
= part_die
;
5842 last_die
= part_die
;
5844 if (first_die
== NULL
)
5845 first_die
= part_die
;
5847 /* Maybe add the DIE to the hash table. Not all DIEs that we
5848 find interesting need to be in the hash table, because we
5849 also have the parent/sibling/child chains; only those that we
5850 might refer to by offset later during partial symbol reading.
5852 For now this means things that might have be the target of a
5853 DW_AT_specification, DW_AT_abstract_origin, or
5854 DW_AT_extension. DW_AT_extension will refer only to
5855 namespaces; DW_AT_abstract_origin refers to functions (and
5856 many things under the function DIE, but we do not recurse
5857 into function DIEs during partial symbol reading) and
5858 possibly variables as well; DW_AT_specification refers to
5859 declarations. Declarations ought to have the DW_AT_declaration
5860 flag. It happens that GCC forgets to put it in sometimes, but
5861 only for functions, not for types.
5863 Adding more things than necessary to the hash table is harmless
5864 except for the performance cost. Adding too few will result in
5865 wasted time in find_partial_die, when we reread the compilation
5866 unit with load_all_dies set. */
5869 || abbrev
->tag
== DW_TAG_subprogram
5870 || abbrev
->tag
== DW_TAG_variable
5871 || abbrev
->tag
== DW_TAG_namespace
5872 || part_die
->is_declaration
)
5876 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
5877 part_die
->offset
, INSERT
);
5881 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5882 sizeof (struct partial_die_info
));
5884 /* For some DIEs we want to follow their children (if any). For C
5885 we have no reason to follow the children of structures; for other
5886 languages we have to, both so that we can get at method physnames
5887 to infer fully qualified class names, and for DW_AT_specification.
5889 For Ada, we need to scan the children of subprograms and lexical
5890 blocks as well because Ada allows the definition of nested
5891 entities that could be interesting for the debugger, such as
5892 nested subprograms for instance. */
5893 if (last_die
->has_children
5895 || last_die
->tag
== DW_TAG_namespace
5896 || last_die
->tag
== DW_TAG_enumeration_type
5897 || (cu
->language
!= language_c
5898 && (last_die
->tag
== DW_TAG_class_type
5899 || last_die
->tag
== DW_TAG_interface_type
5900 || last_die
->tag
== DW_TAG_structure_type
5901 || last_die
->tag
== DW_TAG_union_type
))
5902 || (cu
->language
== language_ada
5903 && (last_die
->tag
== DW_TAG_subprogram
5904 || last_die
->tag
== DW_TAG_lexical_block
))))
5907 parent_die
= last_die
;
5911 /* Otherwise we skip to the next sibling, if any. */
5912 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
5914 /* Back to the top, do it again. */
5918 /* Read a minimal amount of information into the minimal die structure. */
5921 read_partial_die (struct partial_die_info
*part_die
,
5922 struct abbrev_info
*abbrev
,
5923 unsigned int abbrev_len
, bfd
*abfd
,
5924 gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
5926 unsigned int bytes_read
, i
;
5927 struct attribute attr
;
5928 int has_low_pc_attr
= 0;
5929 int has_high_pc_attr
= 0;
5930 CORE_ADDR base_address
= 0;
5934 base_address_low_pc
,
5935 /* Overrides BASE_ADDRESS_LOW_PC. */
5936 base_address_entry_pc
5938 base_address_type
= base_address_none
;
5940 memset (part_die
, 0, sizeof (struct partial_die_info
));
5942 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5944 info_ptr
+= abbrev_len
;
5949 part_die
->tag
= abbrev
->tag
;
5950 part_die
->has_children
= abbrev
->has_children
;
5952 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5954 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
5956 /* Store the data if it is of an attribute we want to keep in a
5957 partial symbol table. */
5961 switch (part_die
->tag
)
5963 case DW_TAG_compile_unit
:
5964 /* Compilation units have a DW_AT_name that is a filename, not
5965 a source language identifier. */
5966 case DW_TAG_enumeration_type
:
5967 case DW_TAG_enumerator
:
5968 /* These tags always have simple identifiers already; no need
5969 to canonicalize them. */
5970 part_die
->name
= DW_STRING (&attr
);
5974 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
5975 &cu
->comp_unit_obstack
);
5979 case DW_AT_comp_dir
:
5980 if (part_die
->dirname
== NULL
)
5981 part_die
->dirname
= DW_STRING (&attr
);
5983 case DW_AT_MIPS_linkage_name
:
5984 part_die
->name
= DW_STRING (&attr
);
5987 has_low_pc_attr
= 1;
5988 part_die
->lowpc
= DW_ADDR (&attr
);
5989 if (part_die
->tag
== DW_TAG_compile_unit
5990 && base_address_type
< base_address_low_pc
)
5992 base_address
= DW_ADDR (&attr
);
5993 base_address_type
= base_address_low_pc
;
5997 has_high_pc_attr
= 1;
5998 part_die
->highpc
= DW_ADDR (&attr
);
6000 case DW_AT_entry_pc
:
6001 if (part_die
->tag
== DW_TAG_compile_unit
6002 && base_address_type
< base_address_entry_pc
)
6004 base_address
= DW_ADDR (&attr
);
6005 base_address_type
= base_address_entry_pc
;
6009 if (part_die
->tag
== DW_TAG_compile_unit
)
6011 cu
->ranges_offset
= DW_UNSND (&attr
);
6012 cu
->has_ranges_offset
= 1;
6015 case DW_AT_location
:
6016 /* Support the .debug_loc offsets */
6017 if (attr_form_is_block (&attr
))
6019 part_die
->locdesc
= DW_BLOCK (&attr
);
6021 else if (attr_form_is_section_offset (&attr
))
6023 dwarf2_complex_location_expr_complaint ();
6027 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
6028 "partial symbol information");
6031 case DW_AT_language
:
6032 part_die
->language
= DW_UNSND (&attr
);
6034 case DW_AT_external
:
6035 part_die
->is_external
= DW_UNSND (&attr
);
6037 case DW_AT_declaration
:
6038 part_die
->is_declaration
= DW_UNSND (&attr
);
6041 part_die
->has_type
= 1;
6043 case DW_AT_abstract_origin
:
6044 case DW_AT_specification
:
6045 case DW_AT_extension
:
6046 part_die
->has_specification
= 1;
6047 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
6050 /* Ignore absolute siblings, they might point outside of
6051 the current compile unit. */
6052 if (attr
.form
== DW_FORM_ref_addr
)
6053 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
6055 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
6056 + dwarf2_get_ref_die_offset (&attr
);
6058 case DW_AT_stmt_list
:
6059 part_die
->has_stmt_list
= 1;
6060 part_die
->line_offset
= DW_UNSND (&attr
);
6062 case DW_AT_byte_size
:
6063 part_die
->has_byte_size
= 1;
6065 case DW_AT_calling_convention
:
6066 /* DWARF doesn't provide a way to identify a program's source-level
6067 entry point. DW_AT_calling_convention attributes are only meant
6068 to describe functions' calling conventions.
6070 However, because it's a necessary piece of information in
6071 Fortran, and because DW_CC_program is the only piece of debugging
6072 information whose definition refers to a 'main program' at all,
6073 several compilers have begun marking Fortran main programs with
6074 DW_CC_program --- even when those functions use the standard
6075 calling conventions.
6077 So until DWARF specifies a way to provide this information and
6078 compilers pick up the new representation, we'll support this
6080 if (DW_UNSND (&attr
) == DW_CC_program
6081 && cu
->language
== language_fortran
)
6082 set_main_name (part_die
->name
);
6089 /* When using the GNU linker, .gnu.linkonce. sections are used to
6090 eliminate duplicate copies of functions and vtables and such.
6091 The linker will arbitrarily choose one and discard the others.
6092 The AT_*_pc values for such functions refer to local labels in
6093 these sections. If the section from that file was discarded, the
6094 labels are not in the output, so the relocs get a value of 0.
6095 If this is a discarded function, mark the pc bounds as invalid,
6096 so that GDB will ignore it. */
6097 if (has_low_pc_attr
&& has_high_pc_attr
6098 && part_die
->lowpc
< part_die
->highpc
6099 && (part_die
->lowpc
!= 0
6100 || dwarf2_per_objfile
->has_section_at_zero
))
6101 part_die
->has_pc_info
= 1;
6103 if (base_address_type
!= base_address_none
&& !cu
->base_known
)
6105 gdb_assert (part_die
->tag
== DW_TAG_compile_unit
);
6107 cu
->base_address
= base_address
;
6113 /* Find a cached partial DIE at OFFSET in CU. */
6115 static struct partial_die_info
*
6116 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
6118 struct partial_die_info
*lookup_die
= NULL
;
6119 struct partial_die_info part_die
;
6121 part_die
.offset
= offset
;
6122 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
6127 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
6129 static struct partial_die_info
*
6130 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
6132 struct dwarf2_per_cu_data
*per_cu
= NULL
;
6133 struct partial_die_info
*pd
= NULL
;
6135 if (offset_in_cu_p (&cu
->header
, offset
))
6137 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6142 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
6144 if (per_cu
->cu
== NULL
)
6146 load_comp_unit (per_cu
, cu
->objfile
);
6147 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6148 dwarf2_per_objfile
->read_in_chain
= per_cu
;
6151 per_cu
->cu
->last_used
= 0;
6152 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6154 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
6156 struct cleanup
*back_to
;
6157 struct partial_die_info comp_unit_die
;
6158 struct abbrev_info
*abbrev
;
6159 unsigned int bytes_read
;
6162 per_cu
->load_all_dies
= 1;
6164 /* Re-read the DIEs. */
6165 back_to
= make_cleanup (null_cleanup
, 0);
6166 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
6168 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
6169 back_to
= make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
6171 info_ptr
= (dwarf2_per_objfile
->info_buffer
6172 + per_cu
->cu
->header
.offset
6173 + per_cu
->cu
->header
.first_die_offset
);
6174 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
6175 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
6176 per_cu
->cu
->objfile
->obfd
, info_ptr
,
6178 if (comp_unit_die
.has_children
)
6179 load_partial_dies (per_cu
->cu
->objfile
->obfd
, info_ptr
, 0, per_cu
->cu
);
6180 do_cleanups (back_to
);
6182 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6186 internal_error (__FILE__
, __LINE__
,
6187 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
6188 offset
, bfd_get_filename (cu
->objfile
->obfd
));
6192 /* Adjust PART_DIE before generating a symbol for it. This function
6193 may set the is_external flag or change the DIE's name. */
6196 fixup_partial_die (struct partial_die_info
*part_die
,
6197 struct dwarf2_cu
*cu
)
6199 /* If we found a reference attribute and the DIE has no name, try
6200 to find a name in the referred to DIE. */
6202 if (part_die
->name
== NULL
&& part_die
->has_specification
)
6204 struct partial_die_info
*spec_die
;
6206 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
6208 fixup_partial_die (spec_die
, cu
);
6212 part_die
->name
= spec_die
->name
;
6214 /* Copy DW_AT_external attribute if it is set. */
6215 if (spec_die
->is_external
)
6216 part_die
->is_external
= spec_die
->is_external
;
6220 /* Set default names for some unnamed DIEs. */
6221 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
6222 || part_die
->tag
== DW_TAG_class_type
))
6223 part_die
->name
= "(anonymous class)";
6225 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
6226 part_die
->name
= "(anonymous namespace)";
6228 if (part_die
->tag
== DW_TAG_structure_type
6229 || part_die
->tag
== DW_TAG_class_type
6230 || part_die
->tag
== DW_TAG_union_type
)
6231 guess_structure_name (part_die
, cu
);
6234 /* Read the die from the .debug_info section buffer. Set DIEP to
6235 point to a newly allocated die with its information, except for its
6236 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6237 whether the die has children or not. */
6240 read_full_die (struct die_info
**diep
, bfd
*abfd
, gdb_byte
*info_ptr
,
6241 struct dwarf2_cu
*cu
, int *has_children
)
6243 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6244 struct abbrev_info
*abbrev
;
6245 struct die_info
*die
;
6247 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
6248 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6249 info_ptr
+= bytes_read
;
6257 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6260 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6262 bfd_get_filename (abfd
));
6264 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
6265 die
->offset
= offset
;
6266 die
->tag
= abbrev
->tag
;
6267 die
->abbrev
= abbrev_number
;
6269 die
->num_attrs
= abbrev
->num_attrs
;
6271 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6272 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6273 abfd
, info_ptr
, cu
);
6276 *has_children
= abbrev
->has_children
;
6280 /* Read an attribute value described by an attribute form. */
6283 read_attribute_value (struct attribute
*attr
, unsigned form
,
6284 bfd
*abfd
, gdb_byte
*info_ptr
,
6285 struct dwarf2_cu
*cu
)
6287 struct comp_unit_head
*cu_header
= &cu
->header
;
6288 unsigned int bytes_read
;
6289 struct dwarf_block
*blk
;
6295 case DW_FORM_ref_addr
:
6296 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6297 info_ptr
+= bytes_read
;
6299 case DW_FORM_block2
:
6300 blk
= dwarf_alloc_block (cu
);
6301 blk
->size
= read_2_bytes (abfd
, info_ptr
);
6303 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6304 info_ptr
+= blk
->size
;
6305 DW_BLOCK (attr
) = blk
;
6307 case DW_FORM_block4
:
6308 blk
= dwarf_alloc_block (cu
);
6309 blk
->size
= read_4_bytes (abfd
, info_ptr
);
6311 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6312 info_ptr
+= blk
->size
;
6313 DW_BLOCK (attr
) = blk
;
6316 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
6320 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
6324 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
6327 case DW_FORM_string
:
6328 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
6329 info_ptr
+= bytes_read
;
6332 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
6334 info_ptr
+= bytes_read
;
6337 blk
= dwarf_alloc_block (cu
);
6338 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6339 info_ptr
+= bytes_read
;
6340 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6341 info_ptr
+= blk
->size
;
6342 DW_BLOCK (attr
) = blk
;
6344 case DW_FORM_block1
:
6345 blk
= dwarf_alloc_block (cu
);
6346 blk
->size
= read_1_byte (abfd
, info_ptr
);
6348 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6349 info_ptr
+= blk
->size
;
6350 DW_BLOCK (attr
) = blk
;
6353 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6357 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6361 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
6362 info_ptr
+= bytes_read
;
6365 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6366 info_ptr
+= bytes_read
;
6369 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
6373 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
6377 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
6381 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
6384 case DW_FORM_ref_udata
:
6385 DW_ADDR (attr
) = (cu
->header
.offset
6386 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
6387 info_ptr
+= bytes_read
;
6389 case DW_FORM_indirect
:
6390 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6391 info_ptr
+= bytes_read
;
6392 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
6395 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
6396 dwarf_form_name (form
),
6397 bfd_get_filename (abfd
));
6400 /* We have seen instances where the compiler tried to emit a byte
6401 size attribute of -1 which ended up being encoded as an unsigned
6402 0xffffffff. Although 0xffffffff is technically a valid size value,
6403 an object of this size seems pretty unlikely so we can relatively
6404 safely treat these cases as if the size attribute was invalid and
6405 treat them as zero by default. */
6406 if (attr
->name
== DW_AT_byte_size
6407 && form
== DW_FORM_data4
6408 && DW_UNSND (attr
) >= 0xffffffff)
6411 (&symfile_complaints
,
6412 _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"),
6414 DW_UNSND (attr
) = 0;
6420 /* Read an attribute described by an abbreviated attribute. */
6423 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
6424 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6426 attr
->name
= abbrev
->name
;
6427 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
6430 /* read dwarf information from a buffer */
6433 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
6435 return bfd_get_8 (abfd
, buf
);
6439 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
6441 return bfd_get_signed_8 (abfd
, buf
);
6445 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
6447 return bfd_get_16 (abfd
, buf
);
6451 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6453 return bfd_get_signed_16 (abfd
, buf
);
6457 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
6459 return bfd_get_32 (abfd
, buf
);
6463 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6465 return bfd_get_signed_32 (abfd
, buf
);
6468 static unsigned long
6469 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
6471 return bfd_get_64 (abfd
, buf
);
6475 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
6476 unsigned int *bytes_read
)
6478 struct comp_unit_head
*cu_header
= &cu
->header
;
6479 CORE_ADDR retval
= 0;
6481 if (cu_header
->signed_addr_p
)
6483 switch (cu_header
->addr_size
)
6486 retval
= bfd_get_signed_16 (abfd
, buf
);
6489 retval
= bfd_get_signed_32 (abfd
, buf
);
6492 retval
= bfd_get_signed_64 (abfd
, buf
);
6495 internal_error (__FILE__
, __LINE__
,
6496 _("read_address: bad switch, signed [in module %s]"),
6497 bfd_get_filename (abfd
));
6502 switch (cu_header
->addr_size
)
6505 retval
= bfd_get_16 (abfd
, buf
);
6508 retval
= bfd_get_32 (abfd
, buf
);
6511 retval
= bfd_get_64 (abfd
, buf
);
6514 internal_error (__FILE__
, __LINE__
,
6515 _("read_address: bad switch, unsigned [in module %s]"),
6516 bfd_get_filename (abfd
));
6520 *bytes_read
= cu_header
->addr_size
;
6524 /* Read the initial length from a section. The (draft) DWARF 3
6525 specification allows the initial length to take up either 4 bytes
6526 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
6527 bytes describe the length and all offsets will be 8 bytes in length
6530 An older, non-standard 64-bit format is also handled by this
6531 function. The older format in question stores the initial length
6532 as an 8-byte quantity without an escape value. Lengths greater
6533 than 2^32 aren't very common which means that the initial 4 bytes
6534 is almost always zero. Since a length value of zero doesn't make
6535 sense for the 32-bit format, this initial zero can be considered to
6536 be an escape value which indicates the presence of the older 64-bit
6537 format. As written, the code can't detect (old format) lengths
6538 greater than 4GB. If it becomes necessary to handle lengths
6539 somewhat larger than 4GB, we could allow other small values (such
6540 as the non-sensical values of 1, 2, and 3) to also be used as
6541 escape values indicating the presence of the old format.
6543 The value returned via bytes_read should be used to increment the
6544 relevant pointer after calling read_initial_length().
6546 [ Note: read_initial_length() and read_offset() are based on the
6547 document entitled "DWARF Debugging Information Format", revision
6548 3, draft 8, dated November 19, 2001. This document was obtained
6551 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
6553 This document is only a draft and is subject to change. (So beware.)
6555 Details regarding the older, non-standard 64-bit format were
6556 determined empirically by examining 64-bit ELF files produced by
6557 the SGI toolchain on an IRIX 6.5 machine.
6559 - Kevin, July 16, 2002
6563 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
6565 LONGEST length
= bfd_get_32 (abfd
, buf
);
6567 if (length
== 0xffffffff)
6569 length
= bfd_get_64 (abfd
, buf
+ 4);
6572 else if (length
== 0)
6574 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
6575 length
= bfd_get_64 (abfd
, buf
);
6586 /* Cover function for read_initial_length.
6587 Returns the length of the object at BUF, and stores the size of the
6588 initial length in *BYTES_READ and stores the size that offsets will be in
6590 If the initial length size is not equivalent to that specified in
6591 CU_HEADER then issue a complaint.
6592 This is useful when reading non-comp-unit headers. */
6595 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
6596 const struct comp_unit_head
*cu_header
,
6597 unsigned int *bytes_read
,
6598 unsigned int *offset_size
)
6600 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
6602 gdb_assert (cu_header
->initial_length_size
== 4
6603 || cu_header
->initial_length_size
== 8
6604 || cu_header
->initial_length_size
== 12);
6606 if (cu_header
->initial_length_size
!= *bytes_read
)
6607 complaint (&symfile_complaints
,
6608 _("intermixed 32-bit and 64-bit DWARF sections"));
6610 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
6614 /* Read an offset from the data stream. The size of the offset is
6615 given by cu_header->offset_size. */
6618 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
6619 unsigned int *bytes_read
)
6621 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
6622 *bytes_read
= cu_header
->offset_size
;
6626 /* Read an offset from the data stream. */
6629 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
6633 switch (offset_size
)
6636 retval
= bfd_get_32 (abfd
, buf
);
6639 retval
= bfd_get_64 (abfd
, buf
);
6642 internal_error (__FILE__
, __LINE__
,
6643 _("read_offset_1: bad switch [in module %s]"),
6644 bfd_get_filename (abfd
));
6651 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
6653 /* If the size of a host char is 8 bits, we can return a pointer
6654 to the buffer, otherwise we have to copy the data to a buffer
6655 allocated on the temporary obstack. */
6656 gdb_assert (HOST_CHAR_BIT
== 8);
6661 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6663 /* If the size of a host char is 8 bits, we can return a pointer
6664 to the string, otherwise we have to copy the string to a buffer
6665 allocated on the temporary obstack. */
6666 gdb_assert (HOST_CHAR_BIT
== 8);
6669 *bytes_read_ptr
= 1;
6672 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
6673 return (char *) buf
;
6677 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
6678 const struct comp_unit_head
*cu_header
,
6679 unsigned int *bytes_read_ptr
)
6681 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
6683 if (dwarf2_per_objfile
->str_buffer
== NULL
)
6685 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
6686 bfd_get_filename (abfd
));
6689 if (str_offset
>= dwarf2_per_objfile
->str_size
)
6691 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
6692 bfd_get_filename (abfd
));
6695 gdb_assert (HOST_CHAR_BIT
== 8);
6696 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
6698 return (char *) (dwarf2_per_objfile
->str_buffer
+ str_offset
);
6701 static unsigned long
6702 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6704 unsigned long result
;
6705 unsigned int num_read
;
6715 byte
= bfd_get_8 (abfd
, buf
);
6718 result
|= ((unsigned long)(byte
& 127) << shift
);
6719 if ((byte
& 128) == 0)
6725 *bytes_read_ptr
= num_read
;
6730 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6733 int i
, shift
, num_read
;
6742 byte
= bfd_get_8 (abfd
, buf
);
6745 result
|= ((long)(byte
& 127) << shift
);
6747 if ((byte
& 128) == 0)
6752 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
6753 result
|= -(((long)1) << shift
);
6754 *bytes_read_ptr
= num_read
;
6758 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6761 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
6767 byte
= bfd_get_8 (abfd
, buf
);
6769 if ((byte
& 128) == 0)
6775 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
6781 cu
->language
= language_c
;
6783 case DW_LANG_C_plus_plus
:
6784 cu
->language
= language_cplus
;
6786 case DW_LANG_Fortran77
:
6787 case DW_LANG_Fortran90
:
6788 case DW_LANG_Fortran95
:
6789 cu
->language
= language_fortran
;
6791 case DW_LANG_Mips_Assembler
:
6792 cu
->language
= language_asm
;
6795 cu
->language
= language_java
;
6799 cu
->language
= language_ada
;
6801 case DW_LANG_Modula2
:
6802 cu
->language
= language_m2
;
6804 case DW_LANG_Pascal83
:
6805 cu
->language
= language_pascal
;
6808 cu
->language
= language_objc
;
6810 case DW_LANG_Cobol74
:
6811 case DW_LANG_Cobol85
:
6813 cu
->language
= language_minimal
;
6816 cu
->language_defn
= language_def (cu
->language
);
6819 /* Return the named attribute or NULL if not there. */
6821 static struct attribute
*
6822 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
6825 struct attribute
*spec
= NULL
;
6827 for (i
= 0; i
< die
->num_attrs
; ++i
)
6829 if (die
->attrs
[i
].name
== name
)
6830 return &die
->attrs
[i
];
6831 if (die
->attrs
[i
].name
== DW_AT_specification
6832 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
6833 spec
= &die
->attrs
[i
];
6838 die
= follow_die_ref (die
, spec
, &cu
);
6839 return dwarf2_attr (die
, name
, cu
);
6845 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6846 and holds a non-zero value. This function should only be used for
6847 DW_FORM_flag attributes. */
6850 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
6852 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
6854 return (attr
&& DW_UNSND (attr
));
6858 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
6860 /* A DIE is a declaration if it has a DW_AT_declaration attribute
6861 which value is non-zero. However, we have to be careful with
6862 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
6863 (via dwarf2_flag_true_p) follows this attribute. So we may
6864 end up accidently finding a declaration attribute that belongs
6865 to a different DIE referenced by the specification attribute,
6866 even though the given DIE does not have a declaration attribute. */
6867 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
6868 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
6871 /* Return the die giving the specification for DIE, if there is
6872 one. *SPEC_CU is the CU containing DIE on input, and the CU
6873 containing the return value on output. */
6875 static struct die_info
*
6876 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
6878 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
6881 if (spec_attr
== NULL
)
6884 return follow_die_ref (die
, spec_attr
, spec_cu
);
6887 /* Free the line_header structure *LH, and any arrays and strings it
6890 free_line_header (struct line_header
*lh
)
6892 if (lh
->standard_opcode_lengths
)
6893 xfree (lh
->standard_opcode_lengths
);
6895 /* Remember that all the lh->file_names[i].name pointers are
6896 pointers into debug_line_buffer, and don't need to be freed. */
6898 xfree (lh
->file_names
);
6900 /* Similarly for the include directory names. */
6901 if (lh
->include_dirs
)
6902 xfree (lh
->include_dirs
);
6908 /* Add an entry to LH's include directory table. */
6910 add_include_dir (struct line_header
*lh
, char *include_dir
)
6912 /* Grow the array if necessary. */
6913 if (lh
->include_dirs_size
== 0)
6915 lh
->include_dirs_size
= 1; /* for testing */
6916 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
6917 * sizeof (*lh
->include_dirs
));
6919 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
6921 lh
->include_dirs_size
*= 2;
6922 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
6923 (lh
->include_dirs_size
6924 * sizeof (*lh
->include_dirs
)));
6927 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
6931 /* Add an entry to LH's file name table. */
6933 add_file_name (struct line_header
*lh
,
6935 unsigned int dir_index
,
6936 unsigned int mod_time
,
6937 unsigned int length
)
6939 struct file_entry
*fe
;
6941 /* Grow the array if necessary. */
6942 if (lh
->file_names_size
== 0)
6944 lh
->file_names_size
= 1; /* for testing */
6945 lh
->file_names
= xmalloc (lh
->file_names_size
6946 * sizeof (*lh
->file_names
));
6948 else if (lh
->num_file_names
>= lh
->file_names_size
)
6950 lh
->file_names_size
*= 2;
6951 lh
->file_names
= xrealloc (lh
->file_names
,
6952 (lh
->file_names_size
6953 * sizeof (*lh
->file_names
)));
6956 fe
= &lh
->file_names
[lh
->num_file_names
++];
6958 fe
->dir_index
= dir_index
;
6959 fe
->mod_time
= mod_time
;
6960 fe
->length
= length
;
6966 /* Read the statement program header starting at OFFSET in
6967 .debug_line, according to the endianness of ABFD. Return a pointer
6968 to a struct line_header, allocated using xmalloc.
6970 NOTE: the strings in the include directory and file name tables of
6971 the returned object point into debug_line_buffer, and must not be
6973 static struct line_header
*
6974 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
6975 struct dwarf2_cu
*cu
)
6977 struct cleanup
*back_to
;
6978 struct line_header
*lh
;
6980 unsigned int bytes_read
, offset_size
;
6982 char *cur_dir
, *cur_file
;
6984 if (dwarf2_per_objfile
->line_buffer
== NULL
)
6986 complaint (&symfile_complaints
, _("missing .debug_line section"));
6990 /* Make sure that at least there's room for the total_length field.
6991 That could be 12 bytes long, but we're just going to fudge that. */
6992 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
6994 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6998 lh
= xmalloc (sizeof (*lh
));
6999 memset (lh
, 0, sizeof (*lh
));
7000 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
7003 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
7005 /* Read in the header. */
7007 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
7008 &bytes_read
, &offset_size
);
7009 line_ptr
+= bytes_read
;
7010 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
7011 + dwarf2_per_objfile
->line_size
))
7013 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7016 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
7017 lh
->version
= read_2_bytes (abfd
, line_ptr
);
7019 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
7020 line_ptr
+= offset_size
;
7021 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
7023 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
7025 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
7027 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
7029 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
7031 lh
->standard_opcode_lengths
7032 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
7034 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
7035 for (i
= 1; i
< lh
->opcode_base
; ++i
)
7037 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
7041 /* Read directory table. */
7042 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7044 line_ptr
+= bytes_read
;
7045 add_include_dir (lh
, cur_dir
);
7047 line_ptr
+= bytes_read
;
7049 /* Read file name table. */
7050 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7052 unsigned int dir_index
, mod_time
, length
;
7054 line_ptr
+= bytes_read
;
7055 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7056 line_ptr
+= bytes_read
;
7057 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7058 line_ptr
+= bytes_read
;
7059 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7060 line_ptr
+= bytes_read
;
7062 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7064 line_ptr
+= bytes_read
;
7065 lh
->statement_program_start
= line_ptr
;
7067 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
7068 + dwarf2_per_objfile
->line_size
))
7069 complaint (&symfile_complaints
,
7070 _("line number info header doesn't fit in `.debug_line' section"));
7072 discard_cleanups (back_to
);
7076 /* This function exists to work around a bug in certain compilers
7077 (particularly GCC 2.95), in which the first line number marker of a
7078 function does not show up until after the prologue, right before
7079 the second line number marker. This function shifts ADDRESS down
7080 to the beginning of the function if necessary, and is called on
7081 addresses passed to record_line. */
7084 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
7086 struct function_range
*fn
;
7088 /* Find the function_range containing address. */
7093 cu
->cached_fn
= cu
->first_fn
;
7097 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7103 while (fn
&& fn
!= cu
->cached_fn
)
7104 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7114 if (address
!= fn
->lowpc
)
7115 complaint (&symfile_complaints
,
7116 _("misplaced first line number at 0x%lx for '%s'"),
7117 (unsigned long) address
, fn
->name
);
7122 /* Decode the Line Number Program (LNP) for the given line_header
7123 structure and CU. The actual information extracted and the type
7124 of structures created from the LNP depends on the value of PST.
7126 1. If PST is NULL, then this procedure uses the data from the program
7127 to create all necessary symbol tables, and their linetables.
7128 The compilation directory of the file is passed in COMP_DIR,
7129 and must not be NULL.
7131 2. If PST is not NULL, this procedure reads the program to determine
7132 the list of files included by the unit represented by PST, and
7133 builds all the associated partial symbol tables. In this case,
7134 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
7135 is not used to compute the full name of the symtab, and therefore
7136 omitting it when building the partial symtab does not introduce
7137 the potential for inconsistency - a partial symtab and its associated
7138 symbtab having a different fullname -). */
7141 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
7142 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
7144 gdb_byte
*line_ptr
, *extended_end
;
7146 unsigned int bytes_read
, extended_len
;
7147 unsigned char op_code
, extended_op
, adj_opcode
;
7149 struct objfile
*objfile
= cu
->objfile
;
7150 const int decode_for_pst_p
= (pst
!= NULL
);
7151 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
7153 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7155 line_ptr
= lh
->statement_program_start
;
7156 line_end
= lh
->statement_program_end
;
7158 /* Read the statement sequences until there's nothing left. */
7159 while (line_ptr
< line_end
)
7161 /* state machine registers */
7162 CORE_ADDR address
= 0;
7163 unsigned int file
= 1;
7164 unsigned int line
= 1;
7165 unsigned int column
= 0;
7166 int is_stmt
= lh
->default_is_stmt
;
7167 int basic_block
= 0;
7168 int end_sequence
= 0;
7170 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
7172 /* Start a subfile for the current file of the state machine. */
7173 /* lh->include_dirs and lh->file_names are 0-based, but the
7174 directory and file name numbers in the statement program
7176 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7180 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7182 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7185 /* Decode the table. */
7186 while (!end_sequence
)
7188 op_code
= read_1_byte (abfd
, line_ptr
);
7190 if (line_ptr
> line_end
)
7192 dwarf2_debug_line_missing_end_sequence_complaint ();
7196 if (op_code
>= lh
->opcode_base
)
7198 /* Special operand. */
7199 adj_opcode
= op_code
- lh
->opcode_base
;
7200 address
+= (adj_opcode
/ lh
->line_range
)
7201 * lh
->minimum_instruction_length
;
7202 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
7203 if (lh
->num_file_names
< file
|| file
== 0)
7204 dwarf2_debug_line_missing_file_complaint ();
7207 lh
->file_names
[file
- 1].included_p
= 1;
7208 if (!decode_for_pst_p
)
7210 if (last_subfile
!= current_subfile
)
7213 record_line (last_subfile
, 0, address
);
7214 last_subfile
= current_subfile
;
7216 /* Append row to matrix using current values. */
7217 record_line (current_subfile
, line
,
7218 check_cu_functions (address
, cu
));
7223 else switch (op_code
)
7225 case DW_LNS_extended_op
:
7226 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7227 line_ptr
+= bytes_read
;
7228 extended_end
= line_ptr
+ extended_len
;
7229 extended_op
= read_1_byte (abfd
, line_ptr
);
7231 switch (extended_op
)
7233 case DW_LNE_end_sequence
:
7236 case DW_LNE_set_address
:
7237 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
7238 line_ptr
+= bytes_read
;
7239 address
+= baseaddr
;
7241 case DW_LNE_define_file
:
7244 unsigned int dir_index
, mod_time
, length
;
7246 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
7247 line_ptr
+= bytes_read
;
7249 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7250 line_ptr
+= bytes_read
;
7252 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7253 line_ptr
+= bytes_read
;
7255 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7256 line_ptr
+= bytes_read
;
7257 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7261 complaint (&symfile_complaints
,
7262 _("mangled .debug_line section"));
7265 /* Make sure that we parsed the extended op correctly. If e.g.
7266 we expected a different address size than the producer used,
7267 we may have read the wrong number of bytes. */
7268 if (line_ptr
!= extended_end
)
7270 complaint (&symfile_complaints
,
7271 _("mangled .debug_line section"));
7276 if (lh
->num_file_names
< file
|| file
== 0)
7277 dwarf2_debug_line_missing_file_complaint ();
7280 lh
->file_names
[file
- 1].included_p
= 1;
7281 if (!decode_for_pst_p
)
7283 if (last_subfile
!= current_subfile
)
7286 record_line (last_subfile
, 0, address
);
7287 last_subfile
= current_subfile
;
7289 record_line (current_subfile
, line
,
7290 check_cu_functions (address
, cu
));
7295 case DW_LNS_advance_pc
:
7296 address
+= lh
->minimum_instruction_length
7297 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7298 line_ptr
+= bytes_read
;
7300 case DW_LNS_advance_line
:
7301 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
7302 line_ptr
+= bytes_read
;
7304 case DW_LNS_set_file
:
7306 /* The arrays lh->include_dirs and lh->file_names are
7307 0-based, but the directory and file name numbers in
7308 the statement program are 1-based. */
7309 struct file_entry
*fe
;
7312 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7313 line_ptr
+= bytes_read
;
7314 if (lh
->num_file_names
< file
|| file
== 0)
7315 dwarf2_debug_line_missing_file_complaint ();
7318 fe
= &lh
->file_names
[file
- 1];
7320 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7321 if (!decode_for_pst_p
)
7323 last_subfile
= current_subfile
;
7324 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7329 case DW_LNS_set_column
:
7330 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7331 line_ptr
+= bytes_read
;
7333 case DW_LNS_negate_stmt
:
7334 is_stmt
= (!is_stmt
);
7336 case DW_LNS_set_basic_block
:
7339 /* Add to the address register of the state machine the
7340 address increment value corresponding to special opcode
7341 255. I.e., this value is scaled by the minimum
7342 instruction length since special opcode 255 would have
7343 scaled the the increment. */
7344 case DW_LNS_const_add_pc
:
7345 address
+= (lh
->minimum_instruction_length
7346 * ((255 - lh
->opcode_base
) / lh
->line_range
));
7348 case DW_LNS_fixed_advance_pc
:
7349 address
+= read_2_bytes (abfd
, line_ptr
);
7354 /* Unknown standard opcode, ignore it. */
7357 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
7359 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7360 line_ptr
+= bytes_read
;
7365 if (lh
->num_file_names
< file
|| file
== 0)
7366 dwarf2_debug_line_missing_file_complaint ();
7369 lh
->file_names
[file
- 1].included_p
= 1;
7370 if (!decode_for_pst_p
)
7371 record_line (current_subfile
, 0, address
);
7375 if (decode_for_pst_p
)
7379 /* Now that we're done scanning the Line Header Program, we can
7380 create the psymtab of each included file. */
7381 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
7382 if (lh
->file_names
[file_index
].included_p
== 1)
7384 const struct file_entry fe
= lh
->file_names
[file_index
];
7385 char *include_name
= fe
.name
;
7386 char *dir_name
= NULL
;
7387 char *pst_filename
= pst
->filename
;
7390 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
7392 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
7394 include_name
= concat (dir_name
, SLASH_STRING
,
7395 include_name
, (char *)NULL
);
7396 make_cleanup (xfree
, include_name
);
7399 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
7401 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
7402 pst_filename
, (char *)NULL
);
7403 make_cleanup (xfree
, pst_filename
);
7406 if (strcmp (include_name
, pst_filename
) != 0)
7407 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
7412 /* Make sure a symtab is created for every file, even files
7413 which contain only variables (i.e. no code with associated
7417 struct file_entry
*fe
;
7419 for (i
= 0; i
< lh
->num_file_names
; i
++)
7422 fe
= &lh
->file_names
[i
];
7424 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7425 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7427 /* Skip the main file; we don't need it, and it must be
7428 allocated last, so that it will show up before the
7429 non-primary symtabs in the objfile's symtab list. */
7430 if (current_subfile
== first_subfile
)
7433 if (current_subfile
->symtab
== NULL
)
7434 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7436 fe
->symtab
= current_subfile
->symtab
;
7441 /* Start a subfile for DWARF. FILENAME is the name of the file and
7442 DIRNAME the name of the source directory which contains FILENAME
7443 or NULL if not known. COMP_DIR is the compilation directory for the
7444 linetable's compilation unit or NULL if not known.
7445 This routine tries to keep line numbers from identical absolute and
7446 relative file names in a common subfile.
7448 Using the `list' example from the GDB testsuite, which resides in
7449 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
7450 of /srcdir/list0.c yields the following debugging information for list0.c:
7452 DW_AT_name: /srcdir/list0.c
7453 DW_AT_comp_dir: /compdir
7454 files.files[0].name: list0.h
7455 files.files[0].dir: /srcdir
7456 files.files[1].name: list0.c
7457 files.files[1].dir: /srcdir
7459 The line number information for list0.c has to end up in a single
7460 subfile, so that `break /srcdir/list0.c:1' works as expected.
7461 start_subfile will ensure that this happens provided that we pass the
7462 concatenation of files.files[1].dir and files.files[1].name as the
7466 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
7470 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
7471 `start_symtab' will always pass the contents of DW_AT_comp_dir as
7472 second argument to start_subfile. To be consistent, we do the
7473 same here. In order not to lose the line information directory,
7474 we concatenate it to the filename when it makes sense.
7475 Note that the Dwarf3 standard says (speaking of filenames in line
7476 information): ``The directory index is ignored for file names
7477 that represent full path names''. Thus ignoring dirname in the
7478 `else' branch below isn't an issue. */
7480 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
7481 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
7483 fullname
= filename
;
7485 start_subfile (fullname
, comp_dir
);
7487 if (fullname
!= filename
)
7492 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
7493 struct dwarf2_cu
*cu
)
7495 struct objfile
*objfile
= cu
->objfile
;
7496 struct comp_unit_head
*cu_header
= &cu
->header
;
7498 /* NOTE drow/2003-01-30: There used to be a comment and some special
7499 code here to turn a symbol with DW_AT_external and a
7500 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
7501 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
7502 with some versions of binutils) where shared libraries could have
7503 relocations against symbols in their debug information - the
7504 minimal symbol would have the right address, but the debug info
7505 would not. It's no longer necessary, because we will explicitly
7506 apply relocations when we read in the debug information now. */
7508 /* A DW_AT_location attribute with no contents indicates that a
7509 variable has been optimized away. */
7510 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
7512 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7516 /* Handle one degenerate form of location expression specially, to
7517 preserve GDB's previous behavior when section offsets are
7518 specified. If this is just a DW_OP_addr then mark this symbol
7521 if (attr_form_is_block (attr
)
7522 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
7523 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
7527 SYMBOL_VALUE_ADDRESS (sym
) =
7528 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
7529 SYMBOL_CLASS (sym
) = LOC_STATIC
;
7530 fixup_symbol_section (sym
, objfile
);
7531 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
7532 SYMBOL_SECTION (sym
));
7536 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
7537 expression evaluator, and use LOC_COMPUTED only when necessary
7538 (i.e. when the value of a register or memory location is
7539 referenced, or a thread-local block, etc.). Then again, it might
7540 not be worthwhile. I'm assuming that it isn't unless performance
7541 or memory numbers show me otherwise. */
7543 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
7544 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
7547 /* Given a pointer to a DWARF information entry, figure out if we need
7548 to make a symbol table entry for it, and if so, create a new entry
7549 and return a pointer to it.
7550 If TYPE is NULL, determine symbol type from the die, otherwise
7551 used the passed type. */
7553 static struct symbol
*
7554 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
7556 struct objfile
*objfile
= cu
->objfile
;
7557 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7558 struct symbol
*sym
= NULL
;
7560 struct attribute
*attr
= NULL
;
7561 struct attribute
*attr2
= NULL
;
7564 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7566 if (die
->tag
!= DW_TAG_namespace
)
7567 name
= dwarf2_linkage_name (die
, cu
);
7569 name
= TYPE_NAME (type
);
7573 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
7574 sizeof (struct symbol
));
7575 OBJSTAT (objfile
, n_syms
++);
7576 memset (sym
, 0, sizeof (struct symbol
));
7578 /* Cache this symbol's name and the name's demangled form (if any). */
7579 SYMBOL_LANGUAGE (sym
) = cu
->language
;
7580 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
7582 /* Default assumptions.
7583 Use the passed type or decode it from the die. */
7584 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7585 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7587 SYMBOL_TYPE (sym
) = type
;
7589 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
7590 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
7593 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
7596 attr
= dwarf2_attr (die
, DW_AT_decl_file
, cu
);
7599 int file_index
= DW_UNSND (attr
);
7600 if (cu
->line_header
== NULL
7601 || file_index
> cu
->line_header
->num_file_names
)
7602 complaint (&symfile_complaints
,
7603 _("file index out of range"));
7604 else if (file_index
> 0)
7606 struct file_entry
*fe
;
7607 fe
= &cu
->line_header
->file_names
[file_index
- 1];
7608 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
7615 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7618 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
7620 SYMBOL_CLASS (sym
) = LOC_LABEL
;
7622 case DW_TAG_subprogram
:
7623 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7625 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
7626 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7627 if ((attr2
&& (DW_UNSND (attr2
) != 0))
7628 || cu
->language
== language_ada
)
7630 /* Subprograms marked external are stored as a global symbol.
7631 Ada subprograms, whether marked external or not, are always
7632 stored as a global symbol, because we want to be able to
7633 access them globally. For instance, we want to be able
7634 to break on a nested subprogram without having to
7635 specify the context. */
7636 add_symbol_to_list (sym
, &global_symbols
);
7640 add_symbol_to_list (sym
, cu
->list_in_scope
);
7643 case DW_TAG_variable
:
7644 /* Compilation with minimal debug info may result in variables
7645 with missing type entries. Change the misleading `void' type
7646 to something sensible. */
7647 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
7649 = builtin_type (gdbarch
)->nodebug_data_symbol
;
7651 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7654 dwarf2_const_value (attr
, sym
, cu
);
7655 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7656 if (attr2
&& (DW_UNSND (attr2
) != 0))
7657 add_symbol_to_list (sym
, &global_symbols
);
7659 add_symbol_to_list (sym
, cu
->list_in_scope
);
7662 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7665 var_decode_location (attr
, sym
, cu
);
7666 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7667 if (attr2
&& (DW_UNSND (attr2
) != 0))
7668 add_symbol_to_list (sym
, &global_symbols
);
7670 add_symbol_to_list (sym
, cu
->list_in_scope
);
7674 /* We do not know the address of this symbol.
7675 If it is an external symbol and we have type information
7676 for it, enter the symbol as a LOC_UNRESOLVED symbol.
7677 The address of the variable will then be determined from
7678 the minimal symbol table whenever the variable is
7680 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7681 if (attr2
&& (DW_UNSND (attr2
) != 0)
7682 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
7684 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
7685 add_symbol_to_list (sym
, &global_symbols
);
7687 else if (!die_is_declaration (die
, cu
))
7689 /* Use the default LOC_OPTIMIZED_OUT class. */
7690 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
7691 add_symbol_to_list (sym
, cu
->list_in_scope
);
7695 case DW_TAG_formal_parameter
:
7696 SYMBOL_IS_ARGUMENT (sym
) = 1;
7697 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7700 var_decode_location (attr
, sym
, cu
);
7702 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7705 dwarf2_const_value (attr
, sym
, cu
);
7707 add_symbol_to_list (sym
, cu
->list_in_scope
);
7709 case DW_TAG_unspecified_parameters
:
7710 /* From varargs functions; gdb doesn't seem to have any
7711 interest in this information, so just ignore it for now.
7714 case DW_TAG_class_type
:
7715 case DW_TAG_interface_type
:
7716 case DW_TAG_structure_type
:
7717 case DW_TAG_union_type
:
7718 case DW_TAG_set_type
:
7719 case DW_TAG_enumeration_type
:
7720 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7721 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7723 /* Make sure that the symbol includes appropriate enclosing
7724 classes/namespaces in its name. These are calculated in
7725 read_structure_type, and the correct name is saved in
7728 if (cu
->language
== language_cplus
7729 || cu
->language
== language_java
)
7731 struct type
*type
= SYMBOL_TYPE (sym
);
7733 if (TYPE_TAG_NAME (type
) != NULL
)
7735 /* FIXME: carlton/2003-11-10: Should this use
7736 SYMBOL_SET_NAMES instead? (The same problem also
7737 arises further down in this function.) */
7738 /* The type's name is already allocated along with
7739 this objfile, so we don't need to duplicate it
7741 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
7746 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
7747 really ever be static objects: otherwise, if you try
7748 to, say, break of a class's method and you're in a file
7749 which doesn't mention that class, it won't work unless
7750 the check for all static symbols in lookup_symbol_aux
7751 saves you. See the OtherFileClass tests in
7752 gdb.c++/namespace.exp. */
7754 struct pending
**list_to_add
;
7756 list_to_add
= (cu
->list_in_scope
== &file_symbols
7757 && (cu
->language
== language_cplus
7758 || cu
->language
== language_java
)
7759 ? &global_symbols
: cu
->list_in_scope
);
7761 add_symbol_to_list (sym
, list_to_add
);
7763 /* The semantics of C++ state that "struct foo { ... }" also
7764 defines a typedef for "foo". A Java class declaration also
7765 defines a typedef for the class. */
7766 if (cu
->language
== language_cplus
7767 || cu
->language
== language_java
7768 || cu
->language
== language_ada
)
7770 /* The symbol's name is already allocated along with
7771 this objfile, so we don't need to duplicate it for
7773 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
7774 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
7778 case DW_TAG_typedef
:
7779 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7780 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7781 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7782 add_symbol_to_list (sym
, cu
->list_in_scope
);
7784 case DW_TAG_base_type
:
7785 case DW_TAG_subrange_type
:
7786 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7787 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7788 add_symbol_to_list (sym
, cu
->list_in_scope
);
7790 case DW_TAG_enumerator
:
7791 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7792 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7795 dwarf2_const_value (attr
, sym
, cu
);
7798 /* NOTE: carlton/2003-11-10: See comment above in the
7799 DW_TAG_class_type, etc. block. */
7801 struct pending
**list_to_add
;
7803 list_to_add
= (cu
->list_in_scope
== &file_symbols
7804 && (cu
->language
== language_cplus
7805 || cu
->language
== language_java
)
7806 ? &global_symbols
: cu
->list_in_scope
);
7808 add_symbol_to_list (sym
, list_to_add
);
7811 case DW_TAG_namespace
:
7812 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7813 add_symbol_to_list (sym
, &global_symbols
);
7816 /* Not a tag we recognize. Hopefully we aren't processing
7817 trash data, but since we must specifically ignore things
7818 we don't recognize, there is nothing else we should do at
7820 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
7821 dwarf_tag_name (die
->tag
));
7825 /* For the benefit of old versions of GCC, check for anonymous
7826 namespaces based on the demangled name. */
7827 if (!processing_has_namespace_info
7828 && cu
->language
== language_cplus
7829 && dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
) != NULL
)
7830 cp_scan_for_anonymous_namespaces (sym
);
7835 /* Copy constant value from an attribute to a symbol. */
7838 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
7839 struct dwarf2_cu
*cu
)
7841 struct objfile
*objfile
= cu
->objfile
;
7842 struct comp_unit_head
*cu_header
= &cu
->header
;
7843 struct dwarf_block
*blk
;
7848 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
7849 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7850 cu_header
->addr_size
,
7851 TYPE_LENGTH (SYMBOL_TYPE
7853 SYMBOL_VALUE_BYTES (sym
) =
7854 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
7855 /* NOTE: cagney/2003-05-09: In-lined store_address call with
7856 it's body - store_unsigned_integer. */
7857 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
7859 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7862 /* DW_STRING is already allocated on the obstack, point directly
7864 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
7865 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7867 case DW_FORM_block1
:
7868 case DW_FORM_block2
:
7869 case DW_FORM_block4
:
7871 blk
= DW_BLOCK (attr
);
7872 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
7873 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7875 TYPE_LENGTH (SYMBOL_TYPE
7877 SYMBOL_VALUE_BYTES (sym
) =
7878 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
7879 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
7880 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7883 /* The DW_AT_const_value attributes are supposed to carry the
7884 symbol's value "represented as it would be on the target
7885 architecture." By the time we get here, it's already been
7886 converted to host endianness, so we just need to sign- or
7887 zero-extend it as appropriate. */
7889 dwarf2_const_value_data (attr
, sym
, 8);
7892 dwarf2_const_value_data (attr
, sym
, 16);
7895 dwarf2_const_value_data (attr
, sym
, 32);
7898 dwarf2_const_value_data (attr
, sym
, 64);
7902 SYMBOL_VALUE (sym
) = DW_SND (attr
);
7903 SYMBOL_CLASS (sym
) = LOC_CONST
;
7907 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
7908 SYMBOL_CLASS (sym
) = LOC_CONST
;
7912 complaint (&symfile_complaints
,
7913 _("unsupported const value attribute form: '%s'"),
7914 dwarf_form_name (attr
->form
));
7915 SYMBOL_VALUE (sym
) = 0;
7916 SYMBOL_CLASS (sym
) = LOC_CONST
;
7922 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
7923 or zero-extend it as appropriate for the symbol's type. */
7925 dwarf2_const_value_data (struct attribute
*attr
,
7929 LONGEST l
= DW_UNSND (attr
);
7931 if (bits
< sizeof (l
) * 8)
7933 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
7934 l
&= ((LONGEST
) 1 << bits
) - 1;
7936 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
7939 SYMBOL_VALUE (sym
) = l
;
7940 SYMBOL_CLASS (sym
) = LOC_CONST
;
7944 /* Return the type of the die in question using its DW_AT_type attribute. */
7946 static struct type
*
7947 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7949 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7951 struct attribute
*type_attr
;
7952 struct die_info
*type_die
;
7954 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
7957 /* A missing DW_AT_type represents a void type. */
7958 return builtin_type (gdbarch
)->builtin_void
;
7961 type_die
= follow_die_ref (die
, type_attr
, &cu
);
7963 type
= tag_type_to_type (type_die
, cu
);
7966 dump_die_for_error (type_die
);
7967 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
7973 /* Return the containing type of the die in question using its
7974 DW_AT_containing_type attribute. */
7976 static struct type
*
7977 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7979 struct type
*type
= NULL
;
7980 struct attribute
*type_attr
;
7981 struct die_info
*type_die
= NULL
;
7983 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
7986 type_die
= follow_die_ref (die
, type_attr
, &cu
);
7987 type
= tag_type_to_type (type_die
, cu
);
7992 dump_die_for_error (type_die
);
7993 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
7999 static struct type
*
8000 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8002 struct type
*this_type
;
8004 this_type
= read_type_die (die
, cu
);
8007 dump_die_for_error (die
);
8008 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
8014 static struct type
*
8015 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8017 struct type
*this_type
;
8019 this_type
= get_die_type (die
, cu
);
8025 case DW_TAG_class_type
:
8026 case DW_TAG_interface_type
:
8027 case DW_TAG_structure_type
:
8028 case DW_TAG_union_type
:
8029 this_type
= read_structure_type (die
, cu
);
8031 case DW_TAG_enumeration_type
:
8032 this_type
= read_enumeration_type (die
, cu
);
8034 case DW_TAG_subprogram
:
8035 case DW_TAG_subroutine_type
:
8036 this_type
= read_subroutine_type (die
, cu
);
8038 case DW_TAG_array_type
:
8039 this_type
= read_array_type (die
, cu
);
8041 case DW_TAG_set_type
:
8042 this_type
= read_set_type (die
, cu
);
8044 case DW_TAG_pointer_type
:
8045 this_type
= read_tag_pointer_type (die
, cu
);
8047 case DW_TAG_ptr_to_member_type
:
8048 this_type
= read_tag_ptr_to_member_type (die
, cu
);
8050 case DW_TAG_reference_type
:
8051 this_type
= read_tag_reference_type (die
, cu
);
8053 case DW_TAG_const_type
:
8054 this_type
= read_tag_const_type (die
, cu
);
8056 case DW_TAG_volatile_type
:
8057 this_type
= read_tag_volatile_type (die
, cu
);
8059 case DW_TAG_string_type
:
8060 this_type
= read_tag_string_type (die
, cu
);
8062 case DW_TAG_typedef
:
8063 this_type
= read_typedef (die
, cu
);
8065 case DW_TAG_subrange_type
:
8066 this_type
= read_subrange_type (die
, cu
);
8068 case DW_TAG_base_type
:
8069 this_type
= read_base_type (die
, cu
);
8071 case DW_TAG_unspecified_type
:
8072 this_type
= read_unspecified_type (die
, cu
);
8074 case DW_TAG_namespace
:
8075 this_type
= read_namespace_type (die
, cu
);
8078 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
8079 dwarf_tag_name (die
->tag
));
8086 /* Return the name of the namespace/class that DIE is defined within,
8087 or "" if we can't tell. The caller should not xfree the result.
8089 For example, if we're within the method foo() in the following
8099 then determine_prefix on foo's die will return "N::C". */
8102 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
8104 struct die_info
*parent
, *spec_die
;
8105 struct dwarf2_cu
*spec_cu
;
8106 struct type
*parent_type
;
8108 if (cu
->language
!= language_cplus
8109 && cu
->language
!= language_java
)
8112 /* We have to be careful in the presence of DW_AT_specification.
8113 For example, with GCC 3.4, given the code
8117 // Definition of N::foo.
8121 then we'll have a tree of DIEs like this:
8123 1: DW_TAG_compile_unit
8124 2: DW_TAG_namespace // N
8125 3: DW_TAG_subprogram // declaration of N::foo
8126 4: DW_TAG_subprogram // definition of N::foo
8127 DW_AT_specification // refers to die #3
8129 Thus, when processing die #4, we have to pretend that we're in
8130 the context of its DW_AT_specification, namely the contex of die
8133 spec_die
= die_specification (die
, &spec_cu
);
8134 if (spec_die
== NULL
)
8135 parent
= die
->parent
;
8138 parent
= spec_die
->parent
;
8145 switch (parent
->tag
)
8147 case DW_TAG_namespace
:
8148 parent_type
= read_type_die (parent
, cu
);
8149 /* We give a name to even anonymous namespaces. */
8150 return TYPE_TAG_NAME (parent_type
);
8151 case DW_TAG_class_type
:
8152 case DW_TAG_interface_type
:
8153 case DW_TAG_structure_type
:
8154 case DW_TAG_union_type
:
8155 parent_type
= read_type_die (parent
, cu
);
8156 if (TYPE_TAG_NAME (parent_type
) != NULL
)
8157 return TYPE_TAG_NAME (parent_type
);
8159 /* An anonymous structure is only allowed non-static data
8160 members; no typedefs, no member functions, et cetera.
8161 So it does not need a prefix. */
8164 return determine_prefix (parent
, cu
);
8168 /* Return a newly-allocated string formed by concatenating PREFIX and
8169 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
8170 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
8171 perform an obconcat, otherwise allocate storage for the result. The CU argument
8172 is used to determine the language and hence, the appropriate separator. */
8174 #define MAX_SEP_LEN 2 /* sizeof ("::") */
8177 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
8178 struct dwarf2_cu
*cu
)
8182 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
8184 else if (cu
->language
== language_java
)
8196 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
8197 strcpy (retval
, prefix
);
8198 strcat (retval
, sep
);
8199 strcat (retval
, suffix
);
8204 /* We have an obstack. */
8205 return obconcat (obs
, prefix
, sep
, suffix
);
8209 /* Return sibling of die, NULL if no sibling. */
8211 static struct die_info
*
8212 sibling_die (struct die_info
*die
)
8214 return die
->sibling
;
8217 /* Get linkage name of a die, return NULL if not found. */
8220 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8222 struct attribute
*attr
;
8224 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8225 if (attr
&& DW_STRING (attr
))
8226 return DW_STRING (attr
);
8227 return dwarf2_name (die
, cu
);
8230 /* Get name of a die, return NULL if not found. */
8233 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
8234 struct obstack
*obstack
)
8236 if (name
&& cu
->language
== language_cplus
)
8238 char *canon_name
= cp_canonicalize_string (name
);
8240 if (canon_name
!= NULL
)
8242 if (strcmp (canon_name
, name
) != 0)
8243 name
= obsavestring (canon_name
, strlen (canon_name
),
8252 /* Get name of a die, return NULL if not found. */
8255 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8257 struct attribute
*attr
;
8259 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8260 if (!attr
|| !DW_STRING (attr
))
8265 case DW_TAG_compile_unit
:
8266 /* Compilation units have a DW_AT_name that is a filename, not
8267 a source language identifier. */
8268 case DW_TAG_enumeration_type
:
8269 case DW_TAG_enumerator
:
8270 /* These tags always have simple identifiers already; no need
8271 to canonicalize them. */
8272 return DW_STRING (attr
);
8274 if (attr
->form
!= GDB_FORM_cached_string
)
8277 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
8278 &cu
->objfile
->objfile_obstack
);
8279 attr
->form
= GDB_FORM_cached_string
;
8281 return DW_STRING (attr
);
8285 /* Return the die that this die in an extension of, or NULL if there
8286 is none. *EXT_CU is the CU containing DIE on input, and the CU
8287 containing the return value on output. */
8289 static struct die_info
*
8290 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
8292 struct attribute
*attr
;
8294 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
8298 return follow_die_ref (die
, attr
, ext_cu
);
8301 /* Convert a DIE tag into its string name. */
8304 dwarf_tag_name (unsigned tag
)
8308 case DW_TAG_padding
:
8309 return "DW_TAG_padding";
8310 case DW_TAG_array_type
:
8311 return "DW_TAG_array_type";
8312 case DW_TAG_class_type
:
8313 return "DW_TAG_class_type";
8314 case DW_TAG_entry_point
:
8315 return "DW_TAG_entry_point";
8316 case DW_TAG_enumeration_type
:
8317 return "DW_TAG_enumeration_type";
8318 case DW_TAG_formal_parameter
:
8319 return "DW_TAG_formal_parameter";
8320 case DW_TAG_imported_declaration
:
8321 return "DW_TAG_imported_declaration";
8323 return "DW_TAG_label";
8324 case DW_TAG_lexical_block
:
8325 return "DW_TAG_lexical_block";
8327 return "DW_TAG_member";
8328 case DW_TAG_pointer_type
:
8329 return "DW_TAG_pointer_type";
8330 case DW_TAG_reference_type
:
8331 return "DW_TAG_reference_type";
8332 case DW_TAG_compile_unit
:
8333 return "DW_TAG_compile_unit";
8334 case DW_TAG_string_type
:
8335 return "DW_TAG_string_type";
8336 case DW_TAG_structure_type
:
8337 return "DW_TAG_structure_type";
8338 case DW_TAG_subroutine_type
:
8339 return "DW_TAG_subroutine_type";
8340 case DW_TAG_typedef
:
8341 return "DW_TAG_typedef";
8342 case DW_TAG_union_type
:
8343 return "DW_TAG_union_type";
8344 case DW_TAG_unspecified_parameters
:
8345 return "DW_TAG_unspecified_parameters";
8346 case DW_TAG_variant
:
8347 return "DW_TAG_variant";
8348 case DW_TAG_common_block
:
8349 return "DW_TAG_common_block";
8350 case DW_TAG_common_inclusion
:
8351 return "DW_TAG_common_inclusion";
8352 case DW_TAG_inheritance
:
8353 return "DW_TAG_inheritance";
8354 case DW_TAG_inlined_subroutine
:
8355 return "DW_TAG_inlined_subroutine";
8357 return "DW_TAG_module";
8358 case DW_TAG_ptr_to_member_type
:
8359 return "DW_TAG_ptr_to_member_type";
8360 case DW_TAG_set_type
:
8361 return "DW_TAG_set_type";
8362 case DW_TAG_subrange_type
:
8363 return "DW_TAG_subrange_type";
8364 case DW_TAG_with_stmt
:
8365 return "DW_TAG_with_stmt";
8366 case DW_TAG_access_declaration
:
8367 return "DW_TAG_access_declaration";
8368 case DW_TAG_base_type
:
8369 return "DW_TAG_base_type";
8370 case DW_TAG_catch_block
:
8371 return "DW_TAG_catch_block";
8372 case DW_TAG_const_type
:
8373 return "DW_TAG_const_type";
8374 case DW_TAG_constant
:
8375 return "DW_TAG_constant";
8376 case DW_TAG_enumerator
:
8377 return "DW_TAG_enumerator";
8378 case DW_TAG_file_type
:
8379 return "DW_TAG_file_type";
8381 return "DW_TAG_friend";
8382 case DW_TAG_namelist
:
8383 return "DW_TAG_namelist";
8384 case DW_TAG_namelist_item
:
8385 return "DW_TAG_namelist_item";
8386 case DW_TAG_packed_type
:
8387 return "DW_TAG_packed_type";
8388 case DW_TAG_subprogram
:
8389 return "DW_TAG_subprogram";
8390 case DW_TAG_template_type_param
:
8391 return "DW_TAG_template_type_param";
8392 case DW_TAG_template_value_param
:
8393 return "DW_TAG_template_value_param";
8394 case DW_TAG_thrown_type
:
8395 return "DW_TAG_thrown_type";
8396 case DW_TAG_try_block
:
8397 return "DW_TAG_try_block";
8398 case DW_TAG_variant_part
:
8399 return "DW_TAG_variant_part";
8400 case DW_TAG_variable
:
8401 return "DW_TAG_variable";
8402 case DW_TAG_volatile_type
:
8403 return "DW_TAG_volatile_type";
8404 case DW_TAG_dwarf_procedure
:
8405 return "DW_TAG_dwarf_procedure";
8406 case DW_TAG_restrict_type
:
8407 return "DW_TAG_restrict_type";
8408 case DW_TAG_interface_type
:
8409 return "DW_TAG_interface_type";
8410 case DW_TAG_namespace
:
8411 return "DW_TAG_namespace";
8412 case DW_TAG_imported_module
:
8413 return "DW_TAG_imported_module";
8414 case DW_TAG_unspecified_type
:
8415 return "DW_TAG_unspecified_type";
8416 case DW_TAG_partial_unit
:
8417 return "DW_TAG_partial_unit";
8418 case DW_TAG_imported_unit
:
8419 return "DW_TAG_imported_unit";
8420 case DW_TAG_condition
:
8421 return "DW_TAG_condition";
8422 case DW_TAG_shared_type
:
8423 return "DW_TAG_shared_type";
8424 case DW_TAG_MIPS_loop
:
8425 return "DW_TAG_MIPS_loop";
8426 case DW_TAG_HP_array_descriptor
:
8427 return "DW_TAG_HP_array_descriptor";
8428 case DW_TAG_format_label
:
8429 return "DW_TAG_format_label";
8430 case DW_TAG_function_template
:
8431 return "DW_TAG_function_template";
8432 case DW_TAG_class_template
:
8433 return "DW_TAG_class_template";
8434 case DW_TAG_GNU_BINCL
:
8435 return "DW_TAG_GNU_BINCL";
8436 case DW_TAG_GNU_EINCL
:
8437 return "DW_TAG_GNU_EINCL";
8438 case DW_TAG_upc_shared_type
:
8439 return "DW_TAG_upc_shared_type";
8440 case DW_TAG_upc_strict_type
:
8441 return "DW_TAG_upc_strict_type";
8442 case DW_TAG_upc_relaxed_type
:
8443 return "DW_TAG_upc_relaxed_type";
8444 case DW_TAG_PGI_kanji_type
:
8445 return "DW_TAG_PGI_kanji_type";
8446 case DW_TAG_PGI_interface_block
:
8447 return "DW_TAG_PGI_interface_block";
8449 return "DW_TAG_<unknown>";
8453 /* Convert a DWARF attribute code into its string name. */
8456 dwarf_attr_name (unsigned attr
)
8461 return "DW_AT_sibling";
8462 case DW_AT_location
:
8463 return "DW_AT_location";
8465 return "DW_AT_name";
8466 case DW_AT_ordering
:
8467 return "DW_AT_ordering";
8468 case DW_AT_subscr_data
:
8469 return "DW_AT_subscr_data";
8470 case DW_AT_byte_size
:
8471 return "DW_AT_byte_size";
8472 case DW_AT_bit_offset
:
8473 return "DW_AT_bit_offset";
8474 case DW_AT_bit_size
:
8475 return "DW_AT_bit_size";
8476 case DW_AT_element_list
:
8477 return "DW_AT_element_list";
8478 case DW_AT_stmt_list
:
8479 return "DW_AT_stmt_list";
8481 return "DW_AT_low_pc";
8483 return "DW_AT_high_pc";
8484 case DW_AT_language
:
8485 return "DW_AT_language";
8487 return "DW_AT_member";
8489 return "DW_AT_discr";
8490 case DW_AT_discr_value
:
8491 return "DW_AT_discr_value";
8492 case DW_AT_visibility
:
8493 return "DW_AT_visibility";
8495 return "DW_AT_import";
8496 case DW_AT_string_length
:
8497 return "DW_AT_string_length";
8498 case DW_AT_common_reference
:
8499 return "DW_AT_common_reference";
8500 case DW_AT_comp_dir
:
8501 return "DW_AT_comp_dir";
8502 case DW_AT_const_value
:
8503 return "DW_AT_const_value";
8504 case DW_AT_containing_type
:
8505 return "DW_AT_containing_type";
8506 case DW_AT_default_value
:
8507 return "DW_AT_default_value";
8509 return "DW_AT_inline";
8510 case DW_AT_is_optional
:
8511 return "DW_AT_is_optional";
8512 case DW_AT_lower_bound
:
8513 return "DW_AT_lower_bound";
8514 case DW_AT_producer
:
8515 return "DW_AT_producer";
8516 case DW_AT_prototyped
:
8517 return "DW_AT_prototyped";
8518 case DW_AT_return_addr
:
8519 return "DW_AT_return_addr";
8520 case DW_AT_start_scope
:
8521 return "DW_AT_start_scope";
8522 case DW_AT_bit_stride
:
8523 return "DW_AT_bit_stride";
8524 case DW_AT_upper_bound
:
8525 return "DW_AT_upper_bound";
8526 case DW_AT_abstract_origin
:
8527 return "DW_AT_abstract_origin";
8528 case DW_AT_accessibility
:
8529 return "DW_AT_accessibility";
8530 case DW_AT_address_class
:
8531 return "DW_AT_address_class";
8532 case DW_AT_artificial
:
8533 return "DW_AT_artificial";
8534 case DW_AT_base_types
:
8535 return "DW_AT_base_types";
8536 case DW_AT_calling_convention
:
8537 return "DW_AT_calling_convention";
8539 return "DW_AT_count";
8540 case DW_AT_data_member_location
:
8541 return "DW_AT_data_member_location";
8542 case DW_AT_decl_column
:
8543 return "DW_AT_decl_column";
8544 case DW_AT_decl_file
:
8545 return "DW_AT_decl_file";
8546 case DW_AT_decl_line
:
8547 return "DW_AT_decl_line";
8548 case DW_AT_declaration
:
8549 return "DW_AT_declaration";
8550 case DW_AT_discr_list
:
8551 return "DW_AT_discr_list";
8552 case DW_AT_encoding
:
8553 return "DW_AT_encoding";
8554 case DW_AT_external
:
8555 return "DW_AT_external";
8556 case DW_AT_frame_base
:
8557 return "DW_AT_frame_base";
8559 return "DW_AT_friend";
8560 case DW_AT_identifier_case
:
8561 return "DW_AT_identifier_case";
8562 case DW_AT_macro_info
:
8563 return "DW_AT_macro_info";
8564 case DW_AT_namelist_items
:
8565 return "DW_AT_namelist_items";
8566 case DW_AT_priority
:
8567 return "DW_AT_priority";
8569 return "DW_AT_segment";
8570 case DW_AT_specification
:
8571 return "DW_AT_specification";
8572 case DW_AT_static_link
:
8573 return "DW_AT_static_link";
8575 return "DW_AT_type";
8576 case DW_AT_use_location
:
8577 return "DW_AT_use_location";
8578 case DW_AT_variable_parameter
:
8579 return "DW_AT_variable_parameter";
8580 case DW_AT_virtuality
:
8581 return "DW_AT_virtuality";
8582 case DW_AT_vtable_elem_location
:
8583 return "DW_AT_vtable_elem_location";
8584 /* DWARF 3 values. */
8585 case DW_AT_allocated
:
8586 return "DW_AT_allocated";
8587 case DW_AT_associated
:
8588 return "DW_AT_associated";
8589 case DW_AT_data_location
:
8590 return "DW_AT_data_location";
8591 case DW_AT_byte_stride
:
8592 return "DW_AT_byte_stride";
8593 case DW_AT_entry_pc
:
8594 return "DW_AT_entry_pc";
8595 case DW_AT_use_UTF8
:
8596 return "DW_AT_use_UTF8";
8597 case DW_AT_extension
:
8598 return "DW_AT_extension";
8600 return "DW_AT_ranges";
8601 case DW_AT_trampoline
:
8602 return "DW_AT_trampoline";
8603 case DW_AT_call_column
:
8604 return "DW_AT_call_column";
8605 case DW_AT_call_file
:
8606 return "DW_AT_call_file";
8607 case DW_AT_call_line
:
8608 return "DW_AT_call_line";
8609 case DW_AT_description
:
8610 return "DW_AT_description";
8611 case DW_AT_binary_scale
:
8612 return "DW_AT_binary_scale";
8613 case DW_AT_decimal_scale
:
8614 return "DW_AT_decimal_scale";
8616 return "DW_AT_small";
8617 case DW_AT_decimal_sign
:
8618 return "DW_AT_decimal_sign";
8619 case DW_AT_digit_count
:
8620 return "DW_AT_digit_count";
8621 case DW_AT_picture_string
:
8622 return "DW_AT_picture_string";
8624 return "DW_AT_mutable";
8625 case DW_AT_threads_scaled
:
8626 return "DW_AT_threads_scaled";
8627 case DW_AT_explicit
:
8628 return "DW_AT_explicit";
8629 case DW_AT_object_pointer
:
8630 return "DW_AT_object_pointer";
8631 case DW_AT_endianity
:
8632 return "DW_AT_endianity";
8633 case DW_AT_elemental
:
8634 return "DW_AT_elemental";
8636 return "DW_AT_pure";
8637 case DW_AT_recursive
:
8638 return "DW_AT_recursive";
8639 /* SGI/MIPS extensions. */
8640 #ifdef MIPS /* collides with DW_AT_HP_block_index */
8641 case DW_AT_MIPS_fde
:
8642 return "DW_AT_MIPS_fde";
8644 case DW_AT_MIPS_loop_begin
:
8645 return "DW_AT_MIPS_loop_begin";
8646 case DW_AT_MIPS_tail_loop_begin
:
8647 return "DW_AT_MIPS_tail_loop_begin";
8648 case DW_AT_MIPS_epilog_begin
:
8649 return "DW_AT_MIPS_epilog_begin";
8650 case DW_AT_MIPS_loop_unroll_factor
:
8651 return "DW_AT_MIPS_loop_unroll_factor";
8652 case DW_AT_MIPS_software_pipeline_depth
:
8653 return "DW_AT_MIPS_software_pipeline_depth";
8654 case DW_AT_MIPS_linkage_name
:
8655 return "DW_AT_MIPS_linkage_name";
8656 case DW_AT_MIPS_stride
:
8657 return "DW_AT_MIPS_stride";
8658 case DW_AT_MIPS_abstract_name
:
8659 return "DW_AT_MIPS_abstract_name";
8660 case DW_AT_MIPS_clone_origin
:
8661 return "DW_AT_MIPS_clone_origin";
8662 case DW_AT_MIPS_has_inlines
:
8663 return "DW_AT_MIPS_has_inlines";
8664 /* HP extensions. */
8665 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
8666 case DW_AT_HP_block_index
:
8667 return "DW_AT_HP_block_index";
8669 case DW_AT_HP_unmodifiable
:
8670 return "DW_AT_HP_unmodifiable";
8671 case DW_AT_HP_actuals_stmt_list
:
8672 return "DW_AT_HP_actuals_stmt_list";
8673 case DW_AT_HP_proc_per_section
:
8674 return "DW_AT_HP_proc_per_section";
8675 case DW_AT_HP_raw_data_ptr
:
8676 return "DW_AT_HP_raw_data_ptr";
8677 case DW_AT_HP_pass_by_reference
:
8678 return "DW_AT_HP_pass_by_reference";
8679 case DW_AT_HP_opt_level
:
8680 return "DW_AT_HP_opt_level";
8681 case DW_AT_HP_prof_version_id
:
8682 return "DW_AT_HP_prof_version_id";
8683 case DW_AT_HP_opt_flags
:
8684 return "DW_AT_HP_opt_flags";
8685 case DW_AT_HP_cold_region_low_pc
:
8686 return "DW_AT_HP_cold_region_low_pc";
8687 case DW_AT_HP_cold_region_high_pc
:
8688 return "DW_AT_HP_cold_region_high_pc";
8689 case DW_AT_HP_all_variables_modifiable
:
8690 return "DW_AT_HP_all_variables_modifiable";
8691 case DW_AT_HP_linkage_name
:
8692 return "DW_AT_HP_linkage_name";
8693 case DW_AT_HP_prof_flags
:
8694 return "DW_AT_HP_prof_flags";
8695 /* GNU extensions. */
8696 case DW_AT_sf_names
:
8697 return "DW_AT_sf_names";
8698 case DW_AT_src_info
:
8699 return "DW_AT_src_info";
8700 case DW_AT_mac_info
:
8701 return "DW_AT_mac_info";
8702 case DW_AT_src_coords
:
8703 return "DW_AT_src_coords";
8704 case DW_AT_body_begin
:
8705 return "DW_AT_body_begin";
8706 case DW_AT_body_end
:
8707 return "DW_AT_body_end";
8708 case DW_AT_GNU_vector
:
8709 return "DW_AT_GNU_vector";
8710 /* VMS extensions. */
8711 case DW_AT_VMS_rtnbeg_pd_address
:
8712 return "DW_AT_VMS_rtnbeg_pd_address";
8713 /* UPC extension. */
8714 case DW_AT_upc_threads_scaled
:
8715 return "DW_AT_upc_threads_scaled";
8716 /* PGI (STMicroelectronics) extensions. */
8717 case DW_AT_PGI_lbase
:
8718 return "DW_AT_PGI_lbase";
8719 case DW_AT_PGI_soffset
:
8720 return "DW_AT_PGI_soffset";
8721 case DW_AT_PGI_lstride
:
8722 return "DW_AT_PGI_lstride";
8724 return "DW_AT_<unknown>";
8728 /* Convert a DWARF value form code into its string name. */
8731 dwarf_form_name (unsigned form
)
8736 return "DW_FORM_addr";
8737 case DW_FORM_block2
:
8738 return "DW_FORM_block2";
8739 case DW_FORM_block4
:
8740 return "DW_FORM_block4";
8742 return "DW_FORM_data2";
8744 return "DW_FORM_data4";
8746 return "DW_FORM_data8";
8747 case DW_FORM_string
:
8748 return "DW_FORM_string";
8750 return "DW_FORM_block";
8751 case DW_FORM_block1
:
8752 return "DW_FORM_block1";
8754 return "DW_FORM_data1";
8756 return "DW_FORM_flag";
8758 return "DW_FORM_sdata";
8760 return "DW_FORM_strp";
8762 return "DW_FORM_udata";
8763 case DW_FORM_ref_addr
:
8764 return "DW_FORM_ref_addr";
8766 return "DW_FORM_ref1";
8768 return "DW_FORM_ref2";
8770 return "DW_FORM_ref4";
8772 return "DW_FORM_ref8";
8773 case DW_FORM_ref_udata
:
8774 return "DW_FORM_ref_udata";
8775 case DW_FORM_indirect
:
8776 return "DW_FORM_indirect";
8777 case GDB_FORM_cached_string
:
8778 return "GDB_FORM_cached_string";
8780 return "DW_FORM_<unknown>";
8784 /* Convert a DWARF stack opcode into its string name. */
8787 dwarf_stack_op_name (unsigned op
)
8792 return "DW_OP_addr";
8794 return "DW_OP_deref";
8796 return "DW_OP_const1u";
8798 return "DW_OP_const1s";
8800 return "DW_OP_const2u";
8802 return "DW_OP_const2s";
8804 return "DW_OP_const4u";
8806 return "DW_OP_const4s";
8808 return "DW_OP_const8u";
8810 return "DW_OP_const8s";
8812 return "DW_OP_constu";
8814 return "DW_OP_consts";
8818 return "DW_OP_drop";
8820 return "DW_OP_over";
8822 return "DW_OP_pick";
8824 return "DW_OP_swap";
8828 return "DW_OP_xderef";
8836 return "DW_OP_minus";
8848 return "DW_OP_plus";
8849 case DW_OP_plus_uconst
:
8850 return "DW_OP_plus_uconst";
8856 return "DW_OP_shra";
8874 return "DW_OP_skip";
8876 return "DW_OP_lit0";
8878 return "DW_OP_lit1";
8880 return "DW_OP_lit2";
8882 return "DW_OP_lit3";
8884 return "DW_OP_lit4";
8886 return "DW_OP_lit5";
8888 return "DW_OP_lit6";
8890 return "DW_OP_lit7";
8892 return "DW_OP_lit8";
8894 return "DW_OP_lit9";
8896 return "DW_OP_lit10";
8898 return "DW_OP_lit11";
8900 return "DW_OP_lit12";
8902 return "DW_OP_lit13";
8904 return "DW_OP_lit14";
8906 return "DW_OP_lit15";
8908 return "DW_OP_lit16";
8910 return "DW_OP_lit17";
8912 return "DW_OP_lit18";
8914 return "DW_OP_lit19";
8916 return "DW_OP_lit20";
8918 return "DW_OP_lit21";
8920 return "DW_OP_lit22";
8922 return "DW_OP_lit23";
8924 return "DW_OP_lit24";
8926 return "DW_OP_lit25";
8928 return "DW_OP_lit26";
8930 return "DW_OP_lit27";
8932 return "DW_OP_lit28";
8934 return "DW_OP_lit29";
8936 return "DW_OP_lit30";
8938 return "DW_OP_lit31";
8940 return "DW_OP_reg0";
8942 return "DW_OP_reg1";
8944 return "DW_OP_reg2";
8946 return "DW_OP_reg3";
8948 return "DW_OP_reg4";
8950 return "DW_OP_reg5";
8952 return "DW_OP_reg6";
8954 return "DW_OP_reg7";
8956 return "DW_OP_reg8";
8958 return "DW_OP_reg9";
8960 return "DW_OP_reg10";
8962 return "DW_OP_reg11";
8964 return "DW_OP_reg12";
8966 return "DW_OP_reg13";
8968 return "DW_OP_reg14";
8970 return "DW_OP_reg15";
8972 return "DW_OP_reg16";
8974 return "DW_OP_reg17";
8976 return "DW_OP_reg18";
8978 return "DW_OP_reg19";
8980 return "DW_OP_reg20";
8982 return "DW_OP_reg21";
8984 return "DW_OP_reg22";
8986 return "DW_OP_reg23";
8988 return "DW_OP_reg24";
8990 return "DW_OP_reg25";
8992 return "DW_OP_reg26";
8994 return "DW_OP_reg27";
8996 return "DW_OP_reg28";
8998 return "DW_OP_reg29";
9000 return "DW_OP_reg30";
9002 return "DW_OP_reg31";
9004 return "DW_OP_breg0";
9006 return "DW_OP_breg1";
9008 return "DW_OP_breg2";
9010 return "DW_OP_breg3";
9012 return "DW_OP_breg4";
9014 return "DW_OP_breg5";
9016 return "DW_OP_breg6";
9018 return "DW_OP_breg7";
9020 return "DW_OP_breg8";
9022 return "DW_OP_breg9";
9024 return "DW_OP_breg10";
9026 return "DW_OP_breg11";
9028 return "DW_OP_breg12";
9030 return "DW_OP_breg13";
9032 return "DW_OP_breg14";
9034 return "DW_OP_breg15";
9036 return "DW_OP_breg16";
9038 return "DW_OP_breg17";
9040 return "DW_OP_breg18";
9042 return "DW_OP_breg19";
9044 return "DW_OP_breg20";
9046 return "DW_OP_breg21";
9048 return "DW_OP_breg22";
9050 return "DW_OP_breg23";
9052 return "DW_OP_breg24";
9054 return "DW_OP_breg25";
9056 return "DW_OP_breg26";
9058 return "DW_OP_breg27";
9060 return "DW_OP_breg28";
9062 return "DW_OP_breg29";
9064 return "DW_OP_breg30";
9066 return "DW_OP_breg31";
9068 return "DW_OP_regx";
9070 return "DW_OP_fbreg";
9072 return "DW_OP_bregx";
9074 return "DW_OP_piece";
9075 case DW_OP_deref_size
:
9076 return "DW_OP_deref_size";
9077 case DW_OP_xderef_size
:
9078 return "DW_OP_xderef_size";
9081 /* DWARF 3 extensions. */
9082 case DW_OP_push_object_address
:
9083 return "DW_OP_push_object_address";
9085 return "DW_OP_call2";
9087 return "DW_OP_call4";
9088 case DW_OP_call_ref
:
9089 return "DW_OP_call_ref";
9090 /* GNU extensions. */
9091 case DW_OP_form_tls_address
:
9092 return "DW_OP_form_tls_address";
9093 case DW_OP_call_frame_cfa
:
9094 return "DW_OP_call_frame_cfa";
9095 case DW_OP_bit_piece
:
9096 return "DW_OP_bit_piece";
9097 case DW_OP_GNU_push_tls_address
:
9098 return "DW_OP_GNU_push_tls_address";
9099 case DW_OP_GNU_uninit
:
9100 return "DW_OP_GNU_uninit";
9101 /* HP extensions. */
9102 case DW_OP_HP_is_value
:
9103 return "DW_OP_HP_is_value";
9104 case DW_OP_HP_fltconst4
:
9105 return "DW_OP_HP_fltconst4";
9106 case DW_OP_HP_fltconst8
:
9107 return "DW_OP_HP_fltconst8";
9108 case DW_OP_HP_mod_range
:
9109 return "DW_OP_HP_mod_range";
9110 case DW_OP_HP_unmod_range
:
9111 return "DW_OP_HP_unmod_range";
9113 return "DW_OP_HP_tls";
9115 return "OP_<unknown>";
9120 dwarf_bool_name (unsigned mybool
)
9128 /* Convert a DWARF type code into its string name. */
9131 dwarf_type_encoding_name (unsigned enc
)
9136 return "DW_ATE_void";
9137 case DW_ATE_address
:
9138 return "DW_ATE_address";
9139 case DW_ATE_boolean
:
9140 return "DW_ATE_boolean";
9141 case DW_ATE_complex_float
:
9142 return "DW_ATE_complex_float";
9144 return "DW_ATE_float";
9146 return "DW_ATE_signed";
9147 case DW_ATE_signed_char
:
9148 return "DW_ATE_signed_char";
9149 case DW_ATE_unsigned
:
9150 return "DW_ATE_unsigned";
9151 case DW_ATE_unsigned_char
:
9152 return "DW_ATE_unsigned_char";
9154 case DW_ATE_imaginary_float
:
9155 return "DW_ATE_imaginary_float";
9156 case DW_ATE_packed_decimal
:
9157 return "DW_ATE_packed_decimal";
9158 case DW_ATE_numeric_string
:
9159 return "DW_ATE_numeric_string";
9161 return "DW_ATE_edited";
9162 case DW_ATE_signed_fixed
:
9163 return "DW_ATE_signed_fixed";
9164 case DW_ATE_unsigned_fixed
:
9165 return "DW_ATE_unsigned_fixed";
9166 case DW_ATE_decimal_float
:
9167 return "DW_ATE_decimal_float";
9168 /* HP extensions. */
9169 case DW_ATE_HP_float80
:
9170 return "DW_ATE_HP_float80";
9171 case DW_ATE_HP_complex_float80
:
9172 return "DW_ATE_HP_complex_float80";
9173 case DW_ATE_HP_float128
:
9174 return "DW_ATE_HP_float128";
9175 case DW_ATE_HP_complex_float128
:
9176 return "DW_ATE_HP_complex_float128";
9177 case DW_ATE_HP_floathpintel
:
9178 return "DW_ATE_HP_floathpintel";
9179 case DW_ATE_HP_imaginary_float80
:
9180 return "DW_ATE_HP_imaginary_float80";
9181 case DW_ATE_HP_imaginary_float128
:
9182 return "DW_ATE_HP_imaginary_float128";
9184 return "DW_ATE_<unknown>";
9188 /* Convert a DWARF call frame info operation to its string name. */
9192 dwarf_cfi_name (unsigned cfi_opc
)
9196 case DW_CFA_advance_loc
:
9197 return "DW_CFA_advance_loc";
9199 return "DW_CFA_offset";
9200 case DW_CFA_restore
:
9201 return "DW_CFA_restore";
9203 return "DW_CFA_nop";
9204 case DW_CFA_set_loc
:
9205 return "DW_CFA_set_loc";
9206 case DW_CFA_advance_loc1
:
9207 return "DW_CFA_advance_loc1";
9208 case DW_CFA_advance_loc2
:
9209 return "DW_CFA_advance_loc2";
9210 case DW_CFA_advance_loc4
:
9211 return "DW_CFA_advance_loc4";
9212 case DW_CFA_offset_extended
:
9213 return "DW_CFA_offset_extended";
9214 case DW_CFA_restore_extended
:
9215 return "DW_CFA_restore_extended";
9216 case DW_CFA_undefined
:
9217 return "DW_CFA_undefined";
9218 case DW_CFA_same_value
:
9219 return "DW_CFA_same_value";
9220 case DW_CFA_register
:
9221 return "DW_CFA_register";
9222 case DW_CFA_remember_state
:
9223 return "DW_CFA_remember_state";
9224 case DW_CFA_restore_state
:
9225 return "DW_CFA_restore_state";
9226 case DW_CFA_def_cfa
:
9227 return "DW_CFA_def_cfa";
9228 case DW_CFA_def_cfa_register
:
9229 return "DW_CFA_def_cfa_register";
9230 case DW_CFA_def_cfa_offset
:
9231 return "DW_CFA_def_cfa_offset";
9233 case DW_CFA_def_cfa_expression
:
9234 return "DW_CFA_def_cfa_expression";
9235 case DW_CFA_expression
:
9236 return "DW_CFA_expression";
9237 case DW_CFA_offset_extended_sf
:
9238 return "DW_CFA_offset_extended_sf";
9239 case DW_CFA_def_cfa_sf
:
9240 return "DW_CFA_def_cfa_sf";
9241 case DW_CFA_def_cfa_offset_sf
:
9242 return "DW_CFA_def_cfa_offset_sf";
9243 case DW_CFA_val_offset
:
9244 return "DW_CFA_val_offset";
9245 case DW_CFA_val_offset_sf
:
9246 return "DW_CFA_val_offset_sf";
9247 case DW_CFA_val_expression
:
9248 return "DW_CFA_val_expression";
9249 /* SGI/MIPS specific. */
9250 case DW_CFA_MIPS_advance_loc8
:
9251 return "DW_CFA_MIPS_advance_loc8";
9252 /* GNU extensions. */
9253 case DW_CFA_GNU_window_save
:
9254 return "DW_CFA_GNU_window_save";
9255 case DW_CFA_GNU_args_size
:
9256 return "DW_CFA_GNU_args_size";
9257 case DW_CFA_GNU_negative_offset_extended
:
9258 return "DW_CFA_GNU_negative_offset_extended";
9260 return "DW_CFA_<unknown>";
9266 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
9270 print_spaces (indent
, f
);
9271 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
9272 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
9274 if (die
->parent
!= NULL
)
9276 print_spaces (indent
, f
);
9277 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
9278 die
->parent
->offset
);
9281 print_spaces (indent
, f
);
9282 fprintf_unfiltered (f
, " has children: %s\n",
9283 dwarf_bool_name (die
->child
!= NULL
));
9285 print_spaces (indent
, f
);
9286 fprintf_unfiltered (f
, " attributes:\n");
9288 for (i
= 0; i
< die
->num_attrs
; ++i
)
9290 print_spaces (indent
, f
);
9291 fprintf_unfiltered (f
, " %s (%s) ",
9292 dwarf_attr_name (die
->attrs
[i
].name
),
9293 dwarf_form_name (die
->attrs
[i
].form
));
9295 switch (die
->attrs
[i
].form
)
9297 case DW_FORM_ref_addr
:
9299 fprintf_unfiltered (f
, "address: ");
9300 fputs_filtered (paddress (DW_ADDR (&die
->attrs
[i
])), f
);
9302 case DW_FORM_block2
:
9303 case DW_FORM_block4
:
9305 case DW_FORM_block1
:
9306 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
9311 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
9312 (long) (DW_ADDR (&die
->attrs
[i
])));
9320 fprintf_unfiltered (f
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
9322 case DW_FORM_string
:
9324 case GDB_FORM_cached_string
:
9325 fprintf_unfiltered (f
, "string: \"%s\"",
9326 DW_STRING (&die
->attrs
[i
])
9327 ? DW_STRING (&die
->attrs
[i
]) : "");
9330 if (DW_UNSND (&die
->attrs
[i
]))
9331 fprintf_unfiltered (f
, "flag: TRUE");
9333 fprintf_unfiltered (f
, "flag: FALSE");
9335 case DW_FORM_indirect
:
9336 /* the reader will have reduced the indirect form to
9337 the "base form" so this form should not occur */
9338 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
9341 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
9342 die
->attrs
[i
].form
);
9345 fprintf_unfiltered (f
, "\n");
9350 dump_die_for_error (struct die_info
*die
)
9352 dump_die_shallow (gdb_stderr
, 0, die
);
9356 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
9358 int indent
= level
* 4;
9360 gdb_assert (die
!= NULL
);
9362 if (level
>= max_level
)
9365 dump_die_shallow (f
, indent
, die
);
9367 if (die
->child
!= NULL
)
9369 print_spaces (indent
, f
);
9370 fprintf_unfiltered (f
, " Children:");
9371 if (level
+ 1 < max_level
)
9373 fprintf_unfiltered (f
, "\n");
9374 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
9378 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
9382 if (die
->sibling
!= NULL
&& level
> 0)
9384 dump_die_1 (f
, level
, max_level
, die
->sibling
);
9388 /* This is called from the pdie macro in gdbinit.in.
9389 It's not static so gcc will keep a copy callable from gdb. */
9392 dump_die (struct die_info
*die
, int max_level
)
9394 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
9398 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
9402 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
9408 dwarf2_get_ref_die_offset (struct attribute
*attr
)
9410 unsigned int result
= 0;
9414 case DW_FORM_ref_addr
:
9419 case DW_FORM_ref_udata
:
9420 result
= DW_ADDR (attr
);
9423 complaint (&symfile_complaints
,
9424 _("unsupported die ref attribute form: '%s'"),
9425 dwarf_form_name (attr
->form
));
9430 /* Return the constant value held by the given attribute. Return -1
9431 if the value held by the attribute is not constant. */
9434 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
9436 if (attr
->form
== DW_FORM_sdata
)
9437 return DW_SND (attr
);
9438 else if (attr
->form
== DW_FORM_udata
9439 || attr
->form
== DW_FORM_data1
9440 || attr
->form
== DW_FORM_data2
9441 || attr
->form
== DW_FORM_data4
9442 || attr
->form
== DW_FORM_data8
)
9443 return DW_UNSND (attr
);
9446 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
9447 dwarf_form_name (attr
->form
));
9448 return default_value
;
9452 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
9453 unit and add it to our queue. */
9456 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
9457 struct dwarf2_per_cu_data
*per_cu
)
9459 /* Mark the dependence relation so that we don't flush PER_CU
9461 dwarf2_add_dependence (this_cu
, per_cu
);
9463 /* If it's already on the queue, we have nothing to do. */
9467 /* If the compilation unit is already loaded, just mark it as
9469 if (per_cu
->cu
!= NULL
)
9471 per_cu
->cu
->last_used
= 0;
9475 /* Add it to the queue. */
9476 queue_comp_unit (per_cu
, this_cu
->objfile
);
9479 static struct die_info
*
9480 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
9481 struct dwarf2_cu
**ref_cu
)
9483 struct die_info
*die
;
9484 unsigned int offset
;
9485 struct die_info temp_die
;
9486 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
9488 offset
= dwarf2_get_ref_die_offset (attr
);
9490 if (! offset_in_cu_p (&cu
->header
, offset
))
9492 struct dwarf2_per_cu_data
*per_cu
;
9493 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9495 /* If necessary, add it to the queue and load its DIEs. */
9496 maybe_queue_comp_unit (cu
, per_cu
);
9498 target_cu
= per_cu
->cu
;
9503 *ref_cu
= target_cu
;
9504 temp_die
.offset
= offset
;
9505 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
9509 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
9510 "at 0x%lx [in module %s]"),
9511 (long) offset
, (long) src_die
->offset
, cu
->objfile
->name
);
9514 /* Decode simple location descriptions.
9515 Given a pointer to a dwarf block that defines a location, compute
9516 the location and return the value.
9518 NOTE drow/2003-11-18: This function is called in two situations
9519 now: for the address of static or global variables (partial symbols
9520 only) and for offsets into structures which are expected to be
9521 (more or less) constant. The partial symbol case should go away,
9522 and only the constant case should remain. That will let this
9523 function complain more accurately. A few special modes are allowed
9524 without complaint for global variables (for instance, global
9525 register values and thread-local values).
9527 A location description containing no operations indicates that the
9528 object is optimized out. The return value is 0 for that case.
9529 FIXME drow/2003-11-16: No callers check for this case any more; soon all
9530 callers will only want a very basic result and this can become a
9533 Note that stack[0] is unused except as a default error return.
9534 Note that stack overflow is not yet handled. */
9537 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
9539 struct objfile
*objfile
= cu
->objfile
;
9540 struct comp_unit_head
*cu_header
= &cu
->header
;
9542 int size
= blk
->size
;
9543 gdb_byte
*data
= blk
->data
;
9544 CORE_ADDR stack
[64];
9546 unsigned int bytes_read
, unsnd
;
9590 stack
[++stacki
] = op
- DW_OP_lit0
;
9625 stack
[++stacki
] = op
- DW_OP_reg0
;
9627 dwarf2_complex_location_expr_complaint ();
9631 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9633 stack
[++stacki
] = unsnd
;
9635 dwarf2_complex_location_expr_complaint ();
9639 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
9645 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
9650 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
9655 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
9660 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
9665 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
9670 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
9675 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
9681 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
9686 stack
[stacki
+ 1] = stack
[stacki
];
9691 stack
[stacki
- 1] += stack
[stacki
];
9695 case DW_OP_plus_uconst
:
9696 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9701 stack
[stacki
- 1] -= stack
[stacki
];
9706 /* If we're not the last op, then we definitely can't encode
9707 this using GDB's address_class enum. This is valid for partial
9708 global symbols, although the variable's address will be bogus
9711 dwarf2_complex_location_expr_complaint ();
9714 case DW_OP_GNU_push_tls_address
:
9715 /* The top of the stack has the offset from the beginning
9716 of the thread control block at which the variable is located. */
9717 /* Nothing should follow this operator, so the top of stack would
9719 /* This is valid for partial global symbols, but the variable's
9720 address will be bogus in the psymtab. */
9722 dwarf2_complex_location_expr_complaint ();
9725 case DW_OP_GNU_uninit
:
9729 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
9730 dwarf_stack_op_name (op
));
9731 return (stack
[stacki
]);
9734 return (stack
[stacki
]);
9737 /* memory allocation interface */
9739 static struct dwarf_block
*
9740 dwarf_alloc_block (struct dwarf2_cu
*cu
)
9742 struct dwarf_block
*blk
;
9744 blk
= (struct dwarf_block
*)
9745 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
9749 static struct abbrev_info
*
9750 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
9752 struct abbrev_info
*abbrev
;
9754 abbrev
= (struct abbrev_info
*)
9755 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
9756 memset (abbrev
, 0, sizeof (struct abbrev_info
));
9760 static struct die_info
*
9761 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
9763 struct die_info
*die
;
9764 size_t size
= sizeof (struct die_info
);
9767 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
9769 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
9770 memset (die
, 0, sizeof (struct die_info
));
9775 /* Macro support. */
9778 /* Return the full name of file number I in *LH's file name table.
9779 Use COMP_DIR as the name of the current directory of the
9780 compilation. The result is allocated using xmalloc; the caller is
9781 responsible for freeing it. */
9783 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
9785 /* Is the file number a valid index into the line header's file name
9786 table? Remember that file numbers start with one, not zero. */
9787 if (1 <= file
&& file
<= lh
->num_file_names
)
9789 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9791 if (IS_ABSOLUTE_PATH (fe
->name
))
9792 return xstrdup (fe
->name
);
9800 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9806 dir_len
= strlen (dir
);
9807 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
9808 strcpy (full_name
, dir
);
9809 full_name
[dir_len
] = '/';
9810 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
9814 return xstrdup (fe
->name
);
9819 /* The compiler produced a bogus file number. We can at least
9820 record the macro definitions made in the file, even if we
9821 won't be able to find the file by name. */
9823 sprintf (fake_name
, "<bad macro file number %d>", file
);
9825 complaint (&symfile_complaints
,
9826 _("bad file number in macro information (%d)"),
9829 return xstrdup (fake_name
);
9834 static struct macro_source_file
*
9835 macro_start_file (int file
, int line
,
9836 struct macro_source_file
*current_file
,
9837 const char *comp_dir
,
9838 struct line_header
*lh
, struct objfile
*objfile
)
9840 /* The full name of this source file. */
9841 char *full_name
= file_full_name (file
, lh
, comp_dir
);
9843 /* We don't create a macro table for this compilation unit
9844 at all until we actually get a filename. */
9845 if (! pending_macros
)
9846 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
9847 objfile
->macro_cache
);
9850 /* If we have no current file, then this must be the start_file
9851 directive for the compilation unit's main source file. */
9852 current_file
= macro_set_main (pending_macros
, full_name
);
9854 current_file
= macro_include (current_file
, line
, full_name
);
9858 return current_file
;
9862 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
9863 followed by a null byte. */
9865 copy_string (const char *buf
, int len
)
9867 char *s
= xmalloc (len
+ 1);
9868 memcpy (s
, buf
, len
);
9876 consume_improper_spaces (const char *p
, const char *body
)
9880 complaint (&symfile_complaints
,
9881 _("macro definition contains spaces in formal argument list:\n`%s'"),
9893 parse_macro_definition (struct macro_source_file
*file
, int line
,
9898 /* The body string takes one of two forms. For object-like macro
9899 definitions, it should be:
9901 <macro name> " " <definition>
9903 For function-like macro definitions, it should be:
9905 <macro name> "() " <definition>
9907 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
9909 Spaces may appear only where explicitly indicated, and in the
9912 The Dwarf 2 spec says that an object-like macro's name is always
9913 followed by a space, but versions of GCC around March 2002 omit
9914 the space when the macro's definition is the empty string.
9916 The Dwarf 2 spec says that there should be no spaces between the
9917 formal arguments in a function-like macro's formal argument list,
9918 but versions of GCC around March 2002 include spaces after the
9922 /* Find the extent of the macro name. The macro name is terminated
9923 by either a space or null character (for an object-like macro) or
9924 an opening paren (for a function-like macro). */
9925 for (p
= body
; *p
; p
++)
9926 if (*p
== ' ' || *p
== '(')
9929 if (*p
== ' ' || *p
== '\0')
9931 /* It's an object-like macro. */
9932 int name_len
= p
- body
;
9933 char *name
= copy_string (body
, name_len
);
9934 const char *replacement
;
9937 replacement
= body
+ name_len
+ 1;
9940 dwarf2_macro_malformed_definition_complaint (body
);
9941 replacement
= body
+ name_len
;
9944 macro_define_object (file
, line
, name
, replacement
);
9950 /* It's a function-like macro. */
9951 char *name
= copy_string (body
, p
- body
);
9954 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
9958 p
= consume_improper_spaces (p
, body
);
9960 /* Parse the formal argument list. */
9961 while (*p
&& *p
!= ')')
9963 /* Find the extent of the current argument name. */
9964 const char *arg_start
= p
;
9966 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
9969 if (! *p
|| p
== arg_start
)
9970 dwarf2_macro_malformed_definition_complaint (body
);
9973 /* Make sure argv has room for the new argument. */
9974 if (argc
>= argv_size
)
9977 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
9980 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
9983 p
= consume_improper_spaces (p
, body
);
9985 /* Consume the comma, if present. */
9990 p
= consume_improper_spaces (p
, body
);
9999 /* Perfectly formed definition, no complaints. */
10000 macro_define_function (file
, line
, name
,
10001 argc
, (const char **) argv
,
10003 else if (*p
== '\0')
10005 /* Complain, but do define it. */
10006 dwarf2_macro_malformed_definition_complaint (body
);
10007 macro_define_function (file
, line
, name
,
10008 argc
, (const char **) argv
,
10012 /* Just complain. */
10013 dwarf2_macro_malformed_definition_complaint (body
);
10016 /* Just complain. */
10017 dwarf2_macro_malformed_definition_complaint (body
);
10023 for (i
= 0; i
< argc
; i
++)
10029 dwarf2_macro_malformed_definition_complaint (body
);
10034 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
10035 char *comp_dir
, bfd
*abfd
,
10036 struct dwarf2_cu
*cu
)
10038 gdb_byte
*mac_ptr
, *mac_end
;
10039 struct macro_source_file
*current_file
= 0;
10040 enum dwarf_macinfo_record_type macinfo_type
;
10041 int at_commandline
;
10043 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
10045 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
10049 /* First pass: Find the name of the base filename.
10050 This filename is needed in order to process all macros whose definition
10051 (or undefinition) comes from the command line. These macros are defined
10052 before the first DW_MACINFO_start_file entry, and yet still need to be
10053 associated to the base file.
10055 To determine the base file name, we scan the macro definitions until we
10056 reach the first DW_MACINFO_start_file entry. We then initialize
10057 CURRENT_FILE accordingly so that any macro definition found before the
10058 first DW_MACINFO_start_file can still be associated to the base file. */
10060 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
10061 mac_end
= dwarf2_per_objfile
->macinfo_buffer
10062 + dwarf2_per_objfile
->macinfo_size
;
10066 /* Do we at least have room for a macinfo type byte? */
10067 if (mac_ptr
>= mac_end
)
10069 /* Complaint is printed during the second pass as GDB will probably
10070 stop the first pass earlier upon finding DW_MACINFO_start_file. */
10074 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
10077 switch (macinfo_type
)
10079 /* A zero macinfo type indicates the end of the macro
10084 case DW_MACINFO_define
:
10085 case DW_MACINFO_undef
:
10086 /* Only skip the data by MAC_PTR. */
10088 unsigned int bytes_read
;
10090 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10091 mac_ptr
+= bytes_read
;
10092 read_string (abfd
, mac_ptr
, &bytes_read
);
10093 mac_ptr
+= bytes_read
;
10097 case DW_MACINFO_start_file
:
10099 unsigned int bytes_read
;
10102 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10103 mac_ptr
+= bytes_read
;
10104 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10105 mac_ptr
+= bytes_read
;
10107 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
10112 case DW_MACINFO_end_file
:
10113 /* No data to skip by MAC_PTR. */
10116 case DW_MACINFO_vendor_ext
:
10117 /* Only skip the data by MAC_PTR. */
10119 unsigned int bytes_read
;
10121 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10122 mac_ptr
+= bytes_read
;
10123 read_string (abfd
, mac_ptr
, &bytes_read
);
10124 mac_ptr
+= bytes_read
;
10131 } while (macinfo_type
!= 0 && current_file
== NULL
);
10133 /* Second pass: Process all entries.
10135 Use the AT_COMMAND_LINE flag to determine whether we are still processing
10136 command-line macro definitions/undefinitions. This flag is unset when we
10137 reach the first DW_MACINFO_start_file entry. */
10139 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
10141 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
10142 GDB is still reading the definitions from command line. First
10143 DW_MACINFO_start_file will need to be ignored as it was already executed
10144 to create CURRENT_FILE for the main source holding also the command line
10145 definitions. On first met DW_MACINFO_start_file this flag is reset to
10146 normally execute all the remaining DW_MACINFO_start_file macinfos. */
10148 at_commandline
= 1;
10152 /* Do we at least have room for a macinfo type byte? */
10153 if (mac_ptr
>= mac_end
)
10155 dwarf2_macros_too_long_complaint ();
10159 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
10162 switch (macinfo_type
)
10164 /* A zero macinfo type indicates the end of the macro
10169 case DW_MACINFO_define
:
10170 case DW_MACINFO_undef
:
10172 unsigned int bytes_read
;
10176 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10177 mac_ptr
+= bytes_read
;
10178 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
10179 mac_ptr
+= bytes_read
;
10181 if (! current_file
)
10183 /* DWARF violation as no main source is present. */
10184 complaint (&symfile_complaints
,
10185 _("debug info with no main source gives macro %s "
10188 DW_MACINFO_define
? _("definition") : macinfo_type
==
10189 DW_MACINFO_undef
? _("undefinition") :
10190 "something-or-other", line
, body
);
10193 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
10194 complaint (&symfile_complaints
,
10195 _("debug info gives %s macro %s with %s line %d: %s"),
10196 at_commandline
? _("command-line") : _("in-file"),
10198 DW_MACINFO_define
? _("definition") : macinfo_type
==
10199 DW_MACINFO_undef
? _("undefinition") :
10200 "something-or-other",
10201 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
10203 if (macinfo_type
== DW_MACINFO_define
)
10204 parse_macro_definition (current_file
, line
, body
);
10205 else if (macinfo_type
== DW_MACINFO_undef
)
10206 macro_undef (current_file
, line
, body
);
10210 case DW_MACINFO_start_file
:
10212 unsigned int bytes_read
;
10215 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10216 mac_ptr
+= bytes_read
;
10217 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10218 mac_ptr
+= bytes_read
;
10220 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
10221 complaint (&symfile_complaints
,
10222 _("debug info gives source %d included "
10223 "from %s at %s line %d"),
10224 file
, at_commandline
? _("command-line") : _("file"),
10225 line
== 0 ? _("zero") : _("non-zero"), line
);
10227 if (at_commandline
)
10229 /* This DW_MACINFO_start_file was executed in the pass one. */
10230 at_commandline
= 0;
10233 current_file
= macro_start_file (file
, line
,
10234 current_file
, comp_dir
,
10239 case DW_MACINFO_end_file
:
10240 if (! current_file
)
10241 complaint (&symfile_complaints
,
10242 _("macro debug info has an unmatched `close_file' directive"));
10245 current_file
= current_file
->included_by
;
10246 if (! current_file
)
10248 enum dwarf_macinfo_record_type next_type
;
10250 /* GCC circa March 2002 doesn't produce the zero
10251 type byte marking the end of the compilation
10252 unit. Complain if it's not there, but exit no
10255 /* Do we at least have room for a macinfo type byte? */
10256 if (mac_ptr
>= mac_end
)
10258 dwarf2_macros_too_long_complaint ();
10262 /* We don't increment mac_ptr here, so this is just
10264 next_type
= read_1_byte (abfd
, mac_ptr
);
10265 if (next_type
!= 0)
10266 complaint (&symfile_complaints
,
10267 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
10274 case DW_MACINFO_vendor_ext
:
10276 unsigned int bytes_read
;
10280 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10281 mac_ptr
+= bytes_read
;
10282 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
10283 mac_ptr
+= bytes_read
;
10285 /* We don't recognize any vendor extensions. */
10289 } while (macinfo_type
!= 0);
10292 /* Check if the attribute's form is a DW_FORM_block*
10293 if so return true else false. */
10295 attr_form_is_block (struct attribute
*attr
)
10297 return (attr
== NULL
? 0 :
10298 attr
->form
== DW_FORM_block1
10299 || attr
->form
== DW_FORM_block2
10300 || attr
->form
== DW_FORM_block4
10301 || attr
->form
== DW_FORM_block
);
10304 /* Return non-zero if ATTR's value is a section offset --- classes
10305 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
10306 You may use DW_UNSND (attr) to retrieve such offsets.
10308 Section 7.5.4, "Attribute Encodings", explains that no attribute
10309 may have a value that belongs to more than one of these classes; it
10310 would be ambiguous if we did, because we use the same forms for all
10313 attr_form_is_section_offset (struct attribute
*attr
)
10315 return (attr
->form
== DW_FORM_data4
10316 || attr
->form
== DW_FORM_data8
);
10320 /* Return non-zero if ATTR's value falls in the 'constant' class, or
10321 zero otherwise. When this function returns true, you can apply
10322 dwarf2_get_attr_constant_value to it.
10324 However, note that for some attributes you must check
10325 attr_form_is_section_offset before using this test. DW_FORM_data4
10326 and DW_FORM_data8 are members of both the constant class, and of
10327 the classes that contain offsets into other debug sections
10328 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
10329 that, if an attribute's can be either a constant or one of the
10330 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
10331 taken as section offsets, not constants. */
10333 attr_form_is_constant (struct attribute
*attr
)
10335 switch (attr
->form
)
10337 case DW_FORM_sdata
:
10338 case DW_FORM_udata
:
10339 case DW_FORM_data1
:
10340 case DW_FORM_data2
:
10341 case DW_FORM_data4
:
10342 case DW_FORM_data8
:
10350 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
10351 struct dwarf2_cu
*cu
)
10353 if (attr_form_is_section_offset (attr
)
10354 /* ".debug_loc" may not exist at all, or the offset may be outside
10355 the section. If so, fall through to the complaint in the
10357 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc_size
)
10359 struct dwarf2_loclist_baton
*baton
;
10361 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
10362 sizeof (struct dwarf2_loclist_baton
));
10363 baton
->per_cu
= cu
->per_cu
;
10364 gdb_assert (baton
->per_cu
);
10366 /* We don't know how long the location list is, but make sure we
10367 don't run off the edge of the section. */
10368 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
10369 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
10370 baton
->base_address
= cu
->base_address
;
10371 if (cu
->base_known
== 0)
10372 complaint (&symfile_complaints
,
10373 _("Location list used without specifying the CU base address."));
10375 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
10376 SYMBOL_LOCATION_BATON (sym
) = baton
;
10380 struct dwarf2_locexpr_baton
*baton
;
10382 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
10383 sizeof (struct dwarf2_locexpr_baton
));
10384 baton
->per_cu
= cu
->per_cu
;
10385 gdb_assert (baton
->per_cu
);
10387 if (attr_form_is_block (attr
))
10389 /* Note that we're just copying the block's data pointer
10390 here, not the actual data. We're still pointing into the
10391 info_buffer for SYM's objfile; right now we never release
10392 that buffer, but when we do clean up properly this may
10394 baton
->size
= DW_BLOCK (attr
)->size
;
10395 baton
->data
= DW_BLOCK (attr
)->data
;
10399 dwarf2_invalid_attrib_class_complaint ("location description",
10400 SYMBOL_NATURAL_NAME (sym
));
10402 baton
->data
= NULL
;
10405 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
10406 SYMBOL_LOCATION_BATON (sym
) = baton
;
10410 /* Return the OBJFILE associated with the compilation unit CU. */
10413 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
10415 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10417 /* Return the master objfile, so that we can report and look up the
10418 correct file containing this variable. */
10419 if (objfile
->separate_debug_objfile_backlink
)
10420 objfile
= objfile
->separate_debug_objfile_backlink
;
10425 /* Return the address size given in the compilation unit header for CU. */
10428 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
10431 return per_cu
->cu
->header
.addr_size
;
10434 /* If the CU is not currently read in, we re-read its header. */
10435 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10436 struct dwarf2_per_objfile
*per_objfile
10437 = objfile_data (objfile
, dwarf2_objfile_data_key
);
10438 gdb_byte
*info_ptr
= per_objfile
->info_buffer
+ per_cu
->offset
;
10440 struct comp_unit_head cu_header
;
10441 memset (&cu_header
, 0, sizeof cu_header
);
10442 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
10443 return cu_header
.addr_size
;
10447 /* Locate the compilation unit from CU's objfile which contains the
10448 DIE at OFFSET. Raises an error on failure. */
10450 static struct dwarf2_per_cu_data
*
10451 dwarf2_find_containing_comp_unit (unsigned int offset
,
10452 struct objfile
*objfile
)
10454 struct dwarf2_per_cu_data
*this_cu
;
10458 high
= dwarf2_per_objfile
->n_comp_units
- 1;
10461 int mid
= low
+ (high
- low
) / 2;
10462 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
10467 gdb_assert (low
== high
);
10468 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
10471 error (_("Dwarf Error: could not find partial DIE containing "
10472 "offset 0x%lx [in module %s]"),
10473 (long) offset
, bfd_get_filename (objfile
->obfd
));
10475 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
10476 return dwarf2_per_objfile
->all_comp_units
[low
-1];
10480 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
10481 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
10482 && offset
>= this_cu
->offset
+ this_cu
->length
)
10483 error (_("invalid dwarf2 offset %u"), offset
);
10484 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
10489 /* Locate the compilation unit from OBJFILE which is located at exactly
10490 OFFSET. Raises an error on failure. */
10492 static struct dwarf2_per_cu_data
*
10493 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
10495 struct dwarf2_per_cu_data
*this_cu
;
10496 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10497 if (this_cu
->offset
!= offset
)
10498 error (_("no compilation unit with offset %u."), offset
);
10502 /* Release one cached compilation unit, CU. We unlink it from the tree
10503 of compilation units, but we don't remove it from the read_in_chain;
10504 the caller is responsible for that. */
10507 free_one_comp_unit (void *data
)
10509 struct dwarf2_cu
*cu
= data
;
10511 if (cu
->per_cu
!= NULL
)
10512 cu
->per_cu
->cu
= NULL
;
10515 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10520 /* This cleanup function is passed the address of a dwarf2_cu on the stack
10521 when we're finished with it. We can't free the pointer itself, but be
10522 sure to unlink it from the cache. Also release any associated storage
10523 and perform cache maintenance.
10525 Only used during partial symbol parsing. */
10528 free_stack_comp_unit (void *data
)
10530 struct dwarf2_cu
*cu
= data
;
10532 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10533 cu
->partial_dies
= NULL
;
10535 if (cu
->per_cu
!= NULL
)
10537 /* This compilation unit is on the stack in our caller, so we
10538 should not xfree it. Just unlink it. */
10539 cu
->per_cu
->cu
= NULL
;
10542 /* If we had a per-cu pointer, then we may have other compilation
10543 units loaded, so age them now. */
10544 age_cached_comp_units ();
10548 /* Free all cached compilation units. */
10551 free_cached_comp_units (void *data
)
10553 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10555 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10556 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10557 while (per_cu
!= NULL
)
10559 struct dwarf2_per_cu_data
*next_cu
;
10561 next_cu
= per_cu
->cu
->read_in_chain
;
10563 free_one_comp_unit (per_cu
->cu
);
10564 *last_chain
= next_cu
;
10570 /* Increase the age counter on each cached compilation unit, and free
10571 any that are too old. */
10574 age_cached_comp_units (void)
10576 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10578 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
10579 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10580 while (per_cu
!= NULL
)
10582 per_cu
->cu
->last_used
++;
10583 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
10584 dwarf2_mark (per_cu
->cu
);
10585 per_cu
= per_cu
->cu
->read_in_chain
;
10588 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10589 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10590 while (per_cu
!= NULL
)
10592 struct dwarf2_per_cu_data
*next_cu
;
10594 next_cu
= per_cu
->cu
->read_in_chain
;
10596 if (!per_cu
->cu
->mark
)
10598 free_one_comp_unit (per_cu
->cu
);
10599 *last_chain
= next_cu
;
10602 last_chain
= &per_cu
->cu
->read_in_chain
;
10608 /* Remove a single compilation unit from the cache. */
10611 free_one_cached_comp_unit (void *target_cu
)
10613 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10615 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10616 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10617 while (per_cu
!= NULL
)
10619 struct dwarf2_per_cu_data
*next_cu
;
10621 next_cu
= per_cu
->cu
->read_in_chain
;
10623 if (per_cu
->cu
== target_cu
)
10625 free_one_comp_unit (per_cu
->cu
);
10626 *last_chain
= next_cu
;
10630 last_chain
= &per_cu
->cu
->read_in_chain
;
10636 /* Release all extra memory associated with OBJFILE. */
10639 dwarf2_free_objfile (struct objfile
*objfile
)
10641 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
10643 if (dwarf2_per_objfile
== NULL
)
10646 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
10647 free_cached_comp_units (NULL
);
10649 /* Everything else should be on the objfile obstack. */
10652 /* A pair of DIE offset and GDB type pointer. We store these
10653 in a hash table separate from the DIEs, and preserve them
10654 when the DIEs are flushed out of cache. */
10656 struct dwarf2_offset_and_type
10658 unsigned int offset
;
10662 /* Hash function for a dwarf2_offset_and_type. */
10665 offset_and_type_hash (const void *item
)
10667 const struct dwarf2_offset_and_type
*ofs
= item
;
10668 return ofs
->offset
;
10671 /* Equality function for a dwarf2_offset_and_type. */
10674 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
10676 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
10677 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
10678 return ofs_lhs
->offset
== ofs_rhs
->offset
;
10681 /* Set the type associated with DIE to TYPE. Save it in CU's hash
10682 table if necessary. For convenience, return TYPE. */
10684 static struct type
*
10685 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10687 struct dwarf2_offset_and_type
**slot
, ofs
;
10689 if (cu
->type_hash
== NULL
)
10691 gdb_assert (cu
->per_cu
!= NULL
);
10692 cu
->per_cu
->type_hash
10693 = htab_create_alloc_ex (cu
->header
.length
/ 24,
10694 offset_and_type_hash
,
10695 offset_and_type_eq
,
10697 &cu
->objfile
->objfile_obstack
,
10698 hashtab_obstack_allocate
,
10699 dummy_obstack_deallocate
);
10700 cu
->type_hash
= cu
->per_cu
->type_hash
;
10703 ofs
.offset
= die
->offset
;
10705 slot
= (struct dwarf2_offset_and_type
**)
10706 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
10707 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
10712 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
10713 not have a saved type. */
10715 static struct type
*
10716 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10718 struct dwarf2_offset_and_type
*slot
, ofs
;
10719 htab_t type_hash
= cu
->type_hash
;
10721 if (type_hash
== NULL
)
10724 ofs
.offset
= die
->offset
;
10725 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
10732 /* Set the mark field in CU and in every other compilation unit in the
10733 cache that we must keep because we are keeping CU. */
10735 /* Add a dependence relationship from CU to REF_PER_CU. */
10738 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
10739 struct dwarf2_per_cu_data
*ref_per_cu
)
10743 if (cu
->dependencies
== NULL
)
10745 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
10746 NULL
, &cu
->comp_unit_obstack
,
10747 hashtab_obstack_allocate
,
10748 dummy_obstack_deallocate
);
10750 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
10752 *slot
= ref_per_cu
;
10755 /* Set the mark field in CU and in every other compilation unit in the
10756 cache that we must keep because we are keeping CU. */
10759 dwarf2_mark_helper (void **slot
, void *data
)
10761 struct dwarf2_per_cu_data
*per_cu
;
10763 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
10764 if (per_cu
->cu
->mark
)
10766 per_cu
->cu
->mark
= 1;
10768 if (per_cu
->cu
->dependencies
!= NULL
)
10769 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10775 dwarf2_mark (struct dwarf2_cu
*cu
)
10780 if (cu
->dependencies
!= NULL
)
10781 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10785 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
10789 per_cu
->cu
->mark
= 0;
10790 per_cu
= per_cu
->cu
->read_in_chain
;
10794 /* Trivial hash function for partial_die_info: the hash value of a DIE
10795 is its offset in .debug_info for this objfile. */
10798 partial_die_hash (const void *item
)
10800 const struct partial_die_info
*part_die
= item
;
10801 return part_die
->offset
;
10804 /* Trivial comparison function for partial_die_info structures: two DIEs
10805 are equal if they have the same offset. */
10808 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
10810 const struct partial_die_info
*part_die_lhs
= item_lhs
;
10811 const struct partial_die_info
*part_die_rhs
= item_rhs
;
10812 return part_die_lhs
->offset
== part_die_rhs
->offset
;
10815 static struct cmd_list_element
*set_dwarf2_cmdlist
;
10816 static struct cmd_list_element
*show_dwarf2_cmdlist
;
10819 set_dwarf2_cmd (char *args
, int from_tty
)
10821 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
10825 show_dwarf2_cmd (char *args
, int from_tty
)
10827 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
10830 void _initialize_dwarf2_read (void);
10833 _initialize_dwarf2_read (void)
10835 dwarf2_objfile_data_key
= register_objfile_data ();
10837 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
10838 Set DWARF 2 specific variables.\n\
10839 Configure DWARF 2 variables such as the cache size"),
10840 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
10841 0/*allow-unknown*/, &maintenance_set_cmdlist
);
10843 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
10844 Show DWARF 2 specific variables\n\
10845 Show DWARF 2 variables such as the cache size"),
10846 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
10847 0/*allow-unknown*/, &maintenance_show_cmdlist
);
10849 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
10850 &dwarf2_max_cache_age
, _("\
10851 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
10852 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
10853 A higher limit means that cached compilation units will be stored\n\
10854 in memory longer, and more total memory will be used. Zero disables\n\
10855 caching, which can slow down startup."),
10857 show_dwarf2_max_cache_age
,
10858 &set_dwarf2_cmdlist
,
10859 &show_dwarf2_cmdlist
);
10861 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
10862 Set debugging of the dwarf2 DIE reader."), _("\
10863 Show debugging of the dwarf2 DIE reader."), _("\
10864 When enabled (non-zero), DIEs are dumped after they are read in.\n\
10865 The value is the maximum depth to print."),
10868 &setdebuglist
, &showdebuglist
);