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
;
3092 /* qsort helper for inherit_abstract_dies. */
3095 unsigned_int_compar (const void *ap
, const void *bp
)
3097 unsigned int a
= *(unsigned int *) ap
;
3098 unsigned int b
= *(unsigned int *) bp
;
3100 return (a
> b
) - (b
> a
);
3103 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
3104 Inherit only the children of the DW_AT_abstract_origin DIE not being already
3105 referenced by DW_AT_abstract_origin from the children of the current DIE. */
3108 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
3110 struct die_info
*child_die
;
3111 unsigned die_children_count
;
3112 /* CU offsets which were referenced by children of the current DIE. */
3114 unsigned *offsets_end
, *offsetp
;
3115 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
3116 struct die_info
*origin_die
;
3117 /* Iterator of the ORIGIN_DIE children. */
3118 struct die_info
*origin_child_die
;
3119 struct cleanup
*cleanups
;
3120 struct attribute
*attr
;
3122 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
3126 origin_die
= follow_die_ref (die
, attr
, &cu
);
3127 if (die
->tag
!= origin_die
->tag
)
3128 complaint (&symfile_complaints
,
3129 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
3130 die
->offset
, origin_die
->offset
);
3132 child_die
= die
->child
;
3133 die_children_count
= 0;
3134 while (child_die
&& child_die
->tag
)
3136 child_die
= sibling_die (child_die
);
3137 die_children_count
++;
3139 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
3140 cleanups
= make_cleanup (xfree
, offsets
);
3142 offsets_end
= offsets
;
3143 child_die
= die
->child
;
3144 while (child_die
&& child_die
->tag
)
3146 attr
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
3147 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
3148 counterpart may exist. */
3151 struct die_info
*child_origin_die
;
3153 child_origin_die
= follow_die_ref (child_die
, attr
, &cu
);
3154 if (child_die
->tag
!= child_origin_die
->tag
)
3155 complaint (&symfile_complaints
,
3156 _("Child DIE 0x%x and its abstract origin 0x%x have "
3157 "different tags"), child_die
->offset
,
3158 child_origin_die
->offset
);
3159 *offsets_end
++ = child_origin_die
->offset
;
3161 child_die
= sibling_die (child_die
);
3163 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
3164 unsigned_int_compar
);
3165 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
3166 if (offsetp
[-1] == *offsetp
)
3167 complaint (&symfile_complaints
, _("Multiple children of DIE 0x%x refer "
3168 "to DIE 0x%x as their abstract origin"),
3169 die
->offset
, *offsetp
);
3172 origin_child_die
= origin_die
->child
;
3173 while (origin_child_die
&& origin_child_die
->tag
)
3175 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
3176 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
3178 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
3180 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
3181 process_die (origin_child_die
, cu
);
3183 origin_child_die
= sibling_die (origin_child_die
);
3186 do_cleanups (cleanups
);
3190 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3192 struct objfile
*objfile
= cu
->objfile
;
3193 struct context_stack
*new;
3196 struct die_info
*child_die
;
3197 struct attribute
*attr
;
3200 struct block
*block
;
3202 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3204 name
= dwarf2_linkage_name (die
, cu
);
3206 /* Ignore functions with missing or empty names and functions with
3207 missing or invalid low and high pc attributes. */
3208 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3214 /* Record the function range for dwarf_decode_lines. */
3215 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
3217 new = push_context (0, lowpc
);
3218 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
3220 /* If there is a location expression for DW_AT_frame_base, record
3222 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3224 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3225 expression is being recorded directly in the function's symbol
3226 and not in a separate frame-base object. I guess this hack is
3227 to avoid adding some sort of frame-base adjunct/annex to the
3228 function's symbol :-(. The problem with doing this is that it
3229 results in a function symbol with a location expression that
3230 has nothing to do with the location of the function, ouch! The
3231 relationship should be: a function's symbol has-a frame base; a
3232 frame-base has-a location expression. */
3233 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3235 cu
->list_in_scope
= &local_symbols
;
3237 if (die
->child
!= NULL
)
3239 child_die
= die
->child
;
3240 while (child_die
&& child_die
->tag
)
3242 process_die (child_die
, cu
);
3243 child_die
= sibling_die (child_die
);
3247 inherit_abstract_dies (die
, cu
);
3249 new = pop_context ();
3250 /* Make a block for the local symbols within. */
3251 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3252 lowpc
, highpc
, objfile
);
3254 /* For C++, set the block's scope. */
3255 if (cu
->language
== language_cplus
)
3256 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
3257 determine_prefix (die
, cu
),
3258 processing_has_namespace_info
);
3260 /* If we have address ranges, record them. */
3261 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3263 /* In C++, we can have functions nested inside functions (e.g., when
3264 a function declares a class that has methods). This means that
3265 when we finish processing a function scope, we may need to go
3266 back to building a containing block's symbol lists. */
3267 local_symbols
= new->locals
;
3268 param_symbols
= new->params
;
3270 /* If we've finished processing a top-level function, subsequent
3271 symbols go in the file symbol list. */
3272 if (outermost_context_p ())
3273 cu
->list_in_scope
= &file_symbols
;
3276 /* Process all the DIES contained within a lexical block scope. Start
3277 a new scope, process the dies, and then close the scope. */
3280 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3282 struct objfile
*objfile
= cu
->objfile
;
3283 struct context_stack
*new;
3284 CORE_ADDR lowpc
, highpc
;
3285 struct die_info
*child_die
;
3288 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3290 /* Ignore blocks with missing or invalid low and high pc attributes. */
3291 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3292 as multiple lexical blocks? Handling children in a sane way would
3293 be nasty. Might be easier to properly extend generic blocks to
3295 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3300 push_context (0, lowpc
);
3301 if (die
->child
!= NULL
)
3303 child_die
= die
->child
;
3304 while (child_die
&& child_die
->tag
)
3306 process_die (child_die
, cu
);
3307 child_die
= sibling_die (child_die
);
3310 new = pop_context ();
3312 if (local_symbols
!= NULL
)
3315 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3318 /* Note that recording ranges after traversing children, as we
3319 do here, means that recording a parent's ranges entails
3320 walking across all its children's ranges as they appear in
3321 the address map, which is quadratic behavior.
3323 It would be nicer to record the parent's ranges before
3324 traversing its children, simply overriding whatever you find
3325 there. But since we don't even decide whether to create a
3326 block until after we've traversed its children, that's hard
3328 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3330 local_symbols
= new->locals
;
3333 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3334 Return 1 if the attributes are present and valid, otherwise, return 0.
3335 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3338 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
3339 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
3340 struct partial_symtab
*ranges_pst
)
3342 struct objfile
*objfile
= cu
->objfile
;
3343 struct comp_unit_head
*cu_header
= &cu
->header
;
3344 bfd
*obfd
= objfile
->obfd
;
3345 unsigned int addr_size
= cu_header
->addr_size
;
3346 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3347 /* Base address selection entry. */
3358 found_base
= cu
->base_known
;
3359 base
= cu
->base_address
;
3361 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3363 complaint (&symfile_complaints
,
3364 _("Offset %d out of bounds for DW_AT_ranges attribute"),
3368 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3370 /* Read in the largest possible address. */
3371 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
3372 if ((marker
& mask
) == mask
)
3374 /* If we found the largest possible address, then
3375 read the base address. */
3376 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3377 buffer
+= 2 * addr_size
;
3378 offset
+= 2 * addr_size
;
3384 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3388 CORE_ADDR range_beginning
, range_end
;
3390 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
3391 buffer
+= addr_size
;
3392 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
3393 buffer
+= addr_size
;
3394 offset
+= 2 * addr_size
;
3396 /* An end of list marker is a pair of zero addresses. */
3397 if (range_beginning
== 0 && range_end
== 0)
3398 /* Found the end of list entry. */
3401 /* Each base address selection entry is a pair of 2 values.
3402 The first is the largest possible address, the second is
3403 the base address. Check for a base address here. */
3404 if ((range_beginning
& mask
) == mask
)
3406 /* If we found the largest possible address, then
3407 read the base address. */
3408 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3415 /* We have no valid base address for the ranges
3417 complaint (&symfile_complaints
,
3418 _("Invalid .debug_ranges data (no base address)"));
3422 range_beginning
+= base
;
3425 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
3426 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3427 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
3430 /* FIXME: This is recording everything as a low-high
3431 segment of consecutive addresses. We should have a
3432 data structure for discontiguous block ranges
3436 low
= range_beginning
;
3442 if (range_beginning
< low
)
3443 low
= range_beginning
;
3444 if (range_end
> high
)
3450 /* If the first entry is an end-of-list marker, the range
3451 describes an empty scope, i.e. no instructions. */
3457 *high_return
= high
;
3461 /* Get low and high pc attributes from a die. Return 1 if the attributes
3462 are present and valid, otherwise, return 0. Return -1 if the range is
3463 discontinuous, i.e. derived from DW_AT_ranges information. */
3465 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
3466 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
3468 struct attribute
*attr
;
3473 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3476 high
= DW_ADDR (attr
);
3477 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3479 low
= DW_ADDR (attr
);
3481 /* Found high w/o low attribute. */
3484 /* Found consecutive range of addresses. */
3489 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3492 /* Value of the DW_AT_ranges attribute is the offset in the
3493 .debug_ranges section. */
3494 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, NULL
))
3496 /* Found discontinuous range of addresses. */
3504 /* When using the GNU linker, .gnu.linkonce. sections are used to
3505 eliminate duplicate copies of functions and vtables and such.
3506 The linker will arbitrarily choose one and discard the others.
3507 The AT_*_pc values for such functions refer to local labels in
3508 these sections. If the section from that file was discarded, the
3509 labels are not in the output, so the relocs get a value of 0.
3510 If this is a discarded function, mark the pc bounds as invalid,
3511 so that GDB will ignore it. */
3512 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3520 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
3521 its low and high PC addresses. Do nothing if these addresses could not
3522 be determined. Otherwise, set LOWPC to the low address if it is smaller,
3523 and HIGHPC to the high address if greater than HIGHPC. */
3526 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
3527 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3528 struct dwarf2_cu
*cu
)
3530 CORE_ADDR low
, high
;
3531 struct die_info
*child
= die
->child
;
3533 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
))
3535 *lowpc
= min (*lowpc
, low
);
3536 *highpc
= max (*highpc
, high
);
3539 /* If the language does not allow nested subprograms (either inside
3540 subprograms or lexical blocks), we're done. */
3541 if (cu
->language
!= language_ada
)
3544 /* Check all the children of the given DIE. If it contains nested
3545 subprograms, then check their pc bounds. Likewise, we need to
3546 check lexical blocks as well, as they may also contain subprogram
3548 while (child
&& child
->tag
)
3550 if (child
->tag
== DW_TAG_subprogram
3551 || child
->tag
== DW_TAG_lexical_block
)
3552 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
3553 child
= sibling_die (child
);
3557 /* Get the low and high pc's represented by the scope DIE, and store
3558 them in *LOWPC and *HIGHPC. If the correct values can't be
3559 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3562 get_scope_pc_bounds (struct die_info
*die
,
3563 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3564 struct dwarf2_cu
*cu
)
3566 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3567 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3568 CORE_ADDR current_low
, current_high
;
3570 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3572 best_low
= current_low
;
3573 best_high
= current_high
;
3577 struct die_info
*child
= die
->child
;
3579 while (child
&& child
->tag
)
3581 switch (child
->tag
) {
3582 case DW_TAG_subprogram
:
3583 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
3585 case DW_TAG_namespace
:
3586 /* FIXME: carlton/2004-01-16: Should we do this for
3587 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3588 that current GCC's always emit the DIEs corresponding
3589 to definitions of methods of classes as children of a
3590 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3591 the DIEs giving the declarations, which could be
3592 anywhere). But I don't see any reason why the
3593 standards says that they have to be there. */
3594 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3596 if (current_low
!= ((CORE_ADDR
) -1))
3598 best_low
= min (best_low
, current_low
);
3599 best_high
= max (best_high
, current_high
);
3607 child
= sibling_die (child
);
3612 *highpc
= best_high
;
3615 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
3618 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
3619 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
3621 struct attribute
*attr
;
3623 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3626 CORE_ADDR high
= DW_ADDR (attr
);
3627 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3630 CORE_ADDR low
= DW_ADDR (attr
);
3631 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
3635 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3638 bfd
*obfd
= cu
->objfile
->obfd
;
3640 /* The value of the DW_AT_ranges attribute is the offset of the
3641 address range list in the .debug_ranges section. */
3642 unsigned long offset
= DW_UNSND (attr
);
3643 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3645 /* For some target architectures, but not others, the
3646 read_address function sign-extends the addresses it returns.
3647 To recognize base address selection entries, we need a
3649 unsigned int addr_size
= cu
->header
.addr_size
;
3650 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3652 /* The base address, to which the next pair is relative. Note
3653 that this 'base' is a DWARF concept: most entries in a range
3654 list are relative, to reduce the number of relocs against the
3655 debugging information. This is separate from this function's
3656 'baseaddr' argument, which GDB uses to relocate debugging
3657 information from a shared library based on the address at
3658 which the library was loaded. */
3659 CORE_ADDR base
= cu
->base_address
;
3660 int base_known
= cu
->base_known
;
3662 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3664 complaint (&symfile_complaints
,
3665 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
3672 unsigned int bytes_read
;
3673 CORE_ADDR start
, end
;
3675 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3676 buffer
+= bytes_read
;
3677 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3678 buffer
+= bytes_read
;
3680 /* Did we find the end of the range list? */
3681 if (start
== 0 && end
== 0)
3684 /* Did we find a base address selection entry? */
3685 else if ((start
& base_select_mask
) == base_select_mask
)
3691 /* We found an ordinary address range. */
3696 complaint (&symfile_complaints
,
3697 _("Invalid .debug_ranges data (no base address)"));
3701 record_block_range (block
,
3702 baseaddr
+ base
+ start
,
3703 baseaddr
+ base
+ end
- 1);
3709 /* Add an aggregate field to the field list. */
3712 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3713 struct dwarf2_cu
*cu
)
3715 struct objfile
*objfile
= cu
->objfile
;
3716 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3717 struct nextfield
*new_field
;
3718 struct attribute
*attr
;
3720 char *fieldname
= "";
3722 /* Allocate a new field list entry and link it in. */
3723 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3724 make_cleanup (xfree
, new_field
);
3725 memset (new_field
, 0, sizeof (struct nextfield
));
3726 new_field
->next
= fip
->fields
;
3727 fip
->fields
= new_field
;
3730 /* Handle accessibility and virtuality of field.
3731 The default accessibility for members is public, the default
3732 accessibility for inheritance is private. */
3733 if (die
->tag
!= DW_TAG_inheritance
)
3734 new_field
->accessibility
= DW_ACCESS_public
;
3736 new_field
->accessibility
= DW_ACCESS_private
;
3737 new_field
->virtuality
= DW_VIRTUALITY_none
;
3739 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3741 new_field
->accessibility
= DW_UNSND (attr
);
3742 if (new_field
->accessibility
!= DW_ACCESS_public
)
3743 fip
->non_public_fields
= 1;
3744 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3746 new_field
->virtuality
= DW_UNSND (attr
);
3748 fp
= &new_field
->field
;
3750 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3752 /* Data member other than a C++ static data member. */
3754 /* Get type of field. */
3755 fp
->type
= die_type (die
, cu
);
3757 SET_FIELD_BITPOS (*fp
, 0);
3759 /* Get bit size of field (zero if none). */
3760 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3763 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3767 FIELD_BITSIZE (*fp
) = 0;
3770 /* Get bit offset of field. */
3771 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3776 if (attr_form_is_section_offset (attr
))
3778 dwarf2_complex_location_expr_complaint ();
3781 else if (attr_form_is_constant (attr
))
3782 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
3784 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
3786 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
3788 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3791 if (gdbarch_bits_big_endian (gdbarch
))
3793 /* For big endian bits, the DW_AT_bit_offset gives the
3794 additional bit offset from the MSB of the containing
3795 anonymous object to the MSB of the field. We don't
3796 have to do anything special since we don't need to
3797 know the size of the anonymous object. */
3798 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3802 /* For little endian bits, compute the bit offset to the
3803 MSB of the anonymous object, subtract off the number of
3804 bits from the MSB of the field to the MSB of the
3805 object, and then subtract off the number of bits of
3806 the field itself. The result is the bit offset of
3807 the LSB of the field. */
3809 int bit_offset
= DW_UNSND (attr
);
3811 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3814 /* The size of the anonymous object containing
3815 the bit field is explicit, so use the
3816 indicated size (in bytes). */
3817 anonymous_size
= DW_UNSND (attr
);
3821 /* The size of the anonymous object containing
3822 the bit field must be inferred from the type
3823 attribute of the data member containing the
3825 anonymous_size
= TYPE_LENGTH (fp
->type
);
3827 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
3828 - bit_offset
- FIELD_BITSIZE (*fp
);
3832 /* Get name of field. */
3833 fieldname
= dwarf2_name (die
, cu
);
3834 if (fieldname
== NULL
)
3837 /* The name is already allocated along with this objfile, so we don't
3838 need to duplicate it for the type. */
3839 fp
->name
= fieldname
;
3841 /* Change accessibility for artificial fields (e.g. virtual table
3842 pointer or virtual base class pointer) to private. */
3843 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
3845 new_field
->accessibility
= DW_ACCESS_private
;
3846 fip
->non_public_fields
= 1;
3849 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
3851 /* C++ static member. */
3853 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3854 is a declaration, but all versions of G++ as of this writing
3855 (so through at least 3.2.1) incorrectly generate
3856 DW_TAG_variable tags. */
3860 /* Get name of field. */
3861 fieldname
= dwarf2_name (die
, cu
);
3862 if (fieldname
== NULL
)
3865 /* Get physical name. */
3866 physname
= dwarf2_linkage_name (die
, cu
);
3868 /* The name is already allocated along with this objfile, so we don't
3869 need to duplicate it for the type. */
3870 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
3871 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3872 FIELD_NAME (*fp
) = fieldname
;
3874 else if (die
->tag
== DW_TAG_inheritance
)
3876 /* C++ base class field. */
3877 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3879 SET_FIELD_BITPOS (*fp
, decode_locdesc (DW_BLOCK (attr
), cu
)
3881 FIELD_BITSIZE (*fp
) = 0;
3882 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3883 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
3884 fip
->nbaseclasses
++;
3888 /* Create the vector of fields, and attach it to the type. */
3891 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3892 struct dwarf2_cu
*cu
)
3894 int nfields
= fip
->nfields
;
3896 /* Record the field count, allocate space for the array of fields,
3897 and create blank accessibility bitfields if necessary. */
3898 TYPE_NFIELDS (type
) = nfields
;
3899 TYPE_FIELDS (type
) = (struct field
*)
3900 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3901 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3903 if (fip
->non_public_fields
)
3905 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3907 TYPE_FIELD_PRIVATE_BITS (type
) =
3908 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3909 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3911 TYPE_FIELD_PROTECTED_BITS (type
) =
3912 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3913 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3915 TYPE_FIELD_IGNORE_BITS (type
) =
3916 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3917 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3920 /* If the type has baseclasses, allocate and clear a bit vector for
3921 TYPE_FIELD_VIRTUAL_BITS. */
3922 if (fip
->nbaseclasses
)
3924 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3925 unsigned char *pointer
;
3927 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3928 pointer
= TYPE_ALLOC (type
, num_bytes
);
3929 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
3930 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3931 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3934 /* Copy the saved-up fields into the field vector. Start from the head
3935 of the list, adding to the tail of the field array, so that they end
3936 up in the same order in the array in which they were added to the list. */
3937 while (nfields
-- > 0)
3939 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3940 switch (fip
->fields
->accessibility
)
3942 case DW_ACCESS_private
:
3943 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3946 case DW_ACCESS_protected
:
3947 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3950 case DW_ACCESS_public
:
3954 /* Unknown accessibility. Complain and treat it as public. */
3956 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
3957 fip
->fields
->accessibility
);
3961 if (nfields
< fip
->nbaseclasses
)
3963 switch (fip
->fields
->virtuality
)
3965 case DW_VIRTUALITY_virtual
:
3966 case DW_VIRTUALITY_pure_virtual
:
3967 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3971 fip
->fields
= fip
->fields
->next
;
3975 /* Add a member function to the proper fieldlist. */
3978 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3979 struct type
*type
, struct dwarf2_cu
*cu
)
3981 struct objfile
*objfile
= cu
->objfile
;
3982 struct attribute
*attr
;
3983 struct fnfieldlist
*flp
;
3985 struct fn_field
*fnp
;
3988 struct nextfnfield
*new_fnfield
;
3989 struct type
*this_type
;
3991 /* Get name of member function. */
3992 fieldname
= dwarf2_name (die
, cu
);
3993 if (fieldname
== NULL
)
3996 /* Get the mangled name. */
3997 physname
= dwarf2_linkage_name (die
, cu
);
3999 /* Look up member function name in fieldlist. */
4000 for (i
= 0; i
< fip
->nfnfields
; i
++)
4002 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
4006 /* Create new list element if necessary. */
4007 if (i
< fip
->nfnfields
)
4008 flp
= &fip
->fnfieldlists
[i
];
4011 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4013 fip
->fnfieldlists
= (struct fnfieldlist
*)
4014 xrealloc (fip
->fnfieldlists
,
4015 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
4016 * sizeof (struct fnfieldlist
));
4017 if (fip
->nfnfields
== 0)
4018 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
4020 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
4021 flp
->name
= fieldname
;
4027 /* Create a new member function field and chain it to the field list
4029 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
4030 make_cleanup (xfree
, new_fnfield
);
4031 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
4032 new_fnfield
->next
= flp
->head
;
4033 flp
->head
= new_fnfield
;
4036 /* Fill in the member function field info. */
4037 fnp
= &new_fnfield
->fnfield
;
4038 /* The name is already allocated along with this objfile, so we don't
4039 need to duplicate it for the type. */
4040 fnp
->physname
= physname
? physname
: "";
4041 fnp
->type
= alloc_type (objfile
);
4042 this_type
= read_type_die (die
, cu
);
4043 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
4045 int nparams
= TYPE_NFIELDS (this_type
);
4047 /* TYPE is the domain of this method, and THIS_TYPE is the type
4048 of the method itself (TYPE_CODE_METHOD). */
4049 smash_to_method_type (fnp
->type
, type
,
4050 TYPE_TARGET_TYPE (this_type
),
4051 TYPE_FIELDS (this_type
),
4052 TYPE_NFIELDS (this_type
),
4053 TYPE_VARARGS (this_type
));
4055 /* Handle static member functions.
4056 Dwarf2 has no clean way to discern C++ static and non-static
4057 member functions. G++ helps GDB by marking the first
4058 parameter for non-static member functions (which is the
4059 this pointer) as artificial. We obtain this information
4060 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
4061 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
4062 fnp
->voffset
= VOFFSET_STATIC
;
4065 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
4068 /* Get fcontext from DW_AT_containing_type if present. */
4069 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4070 fnp
->fcontext
= die_containing_type (die
, cu
);
4072 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
4073 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
4075 /* Get accessibility. */
4076 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
4079 switch (DW_UNSND (attr
))
4081 case DW_ACCESS_private
:
4082 fnp
->is_private
= 1;
4084 case DW_ACCESS_protected
:
4085 fnp
->is_protected
= 1;
4090 /* Check for artificial methods. */
4091 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
4092 if (attr
&& DW_UNSND (attr
) != 0)
4093 fnp
->is_artificial
= 1;
4095 /* Get index in virtual function table if it is a virtual member function. */
4096 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
4099 /* Support the .debug_loc offsets */
4100 if (attr_form_is_block (attr
))
4102 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
4104 else if (attr_form_is_section_offset (attr
))
4106 dwarf2_complex_location_expr_complaint ();
4110 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
4116 /* Create the vector of member function fields, and attach it to the type. */
4119 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
4120 struct dwarf2_cu
*cu
)
4122 struct fnfieldlist
*flp
;
4123 int total_length
= 0;
4126 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4127 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
4128 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
4130 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
4132 struct nextfnfield
*nfp
= flp
->head
;
4133 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
4136 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
4137 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
4138 fn_flp
->fn_fields
= (struct fn_field
*)
4139 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
4140 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
4141 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
4143 total_length
+= flp
->length
;
4146 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
4147 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
4150 /* Returns non-zero if NAME is the name of a vtable member in CU's
4151 language, zero otherwise. */
4153 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
4155 static const char vptr
[] = "_vptr";
4156 static const char vtable
[] = "vtable";
4158 /* Look for the C++ and Java forms of the vtable. */
4159 if ((cu
->language
== language_java
4160 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
4161 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
4162 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
4168 /* GCC outputs unnamed structures that are really pointers to member
4169 functions, with the ABI-specified layout. If DIE (from CU) describes
4170 such a structure, set its type, and return nonzero. Otherwise return
4173 GCC shouldn't do this; it should just output pointer to member DIEs.
4174 This is GCC PR debug/28767. */
4176 static struct type
*
4177 quirk_gcc_member_function_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
)
4179 struct objfile
*objfile
= cu
->objfile
;
4181 struct die_info
*pfn_die
, *delta_die
;
4182 struct attribute
*pfn_name
, *delta_name
;
4183 struct type
*pfn_type
, *domain_type
;
4185 /* Check for a structure with no name and two children. */
4186 if (die
->tag
!= DW_TAG_structure_type
4187 || dwarf2_attr (die
, DW_AT_name
, cu
) != NULL
4188 || die
->child
== NULL
4189 || die
->child
->sibling
== NULL
4190 || (die
->child
->sibling
->sibling
!= NULL
4191 && die
->child
->sibling
->sibling
->tag
!= DW_TAG_padding
))
4194 /* Check for __pfn and __delta members. */
4195 pfn_die
= die
->child
;
4196 pfn_name
= dwarf2_attr (pfn_die
, DW_AT_name
, cu
);
4197 if (pfn_die
->tag
!= DW_TAG_member
4199 || DW_STRING (pfn_name
) == NULL
4200 || strcmp ("__pfn", DW_STRING (pfn_name
)) != 0)
4203 delta_die
= pfn_die
->sibling
;
4204 delta_name
= dwarf2_attr (delta_die
, DW_AT_name
, cu
);
4205 if (delta_die
->tag
!= DW_TAG_member
4206 || delta_name
== NULL
4207 || DW_STRING (delta_name
) == NULL
4208 || strcmp ("__delta", DW_STRING (delta_name
)) != 0)
4211 /* Find the type of the method. */
4212 pfn_type
= die_type (pfn_die
, cu
);
4213 if (pfn_type
== NULL
4214 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
4215 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
4218 /* Look for the "this" argument. */
4219 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
4220 if (TYPE_NFIELDS (pfn_type
) == 0
4221 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
4224 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
4225 type
= alloc_type (objfile
);
4226 smash_to_method_type (type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
4227 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
4228 TYPE_VARARGS (pfn_type
));
4229 type
= lookup_methodptr_type (type
);
4230 return set_die_type (die
, type
, cu
);
4233 /* Called when we find the DIE that starts a structure or union scope
4234 (definition) to process all dies that define the members of the
4237 NOTE: we need to call struct_type regardless of whether or not the
4238 DIE has an at_name attribute, since it might be an anonymous
4239 structure or union. This gets the type entered into our set of
4242 However, if the structure is incomplete (an opaque struct/union)
4243 then suppress creating a symbol table entry for it since gdb only
4244 wants to find the one with the complete definition. Note that if
4245 it is complete, we just call new_symbol, which does it's own
4246 checking about whether the struct/union is anonymous or not (and
4247 suppresses creating a symbol table entry itself). */
4249 static struct type
*
4250 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4252 struct objfile
*objfile
= cu
->objfile
;
4254 struct attribute
*attr
;
4256 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4258 type
= quirk_gcc_member_function_pointer (die
, cu
);
4262 type
= alloc_type (objfile
);
4263 INIT_CPLUS_SPECIFIC (type
);
4264 name
= dwarf2_name (die
, cu
);
4267 if (cu
->language
== language_cplus
4268 || cu
->language
== language_java
)
4270 const char *new_prefix
= determine_class_name (die
, cu
);
4271 TYPE_TAG_NAME (type
) = (char *) new_prefix
;
4275 /* The name is already allocated along with this objfile, so
4276 we don't need to duplicate it for the type. */
4277 TYPE_TAG_NAME (type
) = name
;
4281 if (die
->tag
== DW_TAG_structure_type
)
4283 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
4285 else if (die
->tag
== DW_TAG_union_type
)
4287 TYPE_CODE (type
) = TYPE_CODE_UNION
;
4291 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
4293 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
4296 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4299 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4303 TYPE_LENGTH (type
) = 0;
4306 TYPE_STUB_SUPPORTED (type
) = 1;
4307 if (die_is_declaration (die
, cu
))
4308 TYPE_STUB (type
) = 1;
4310 /* We need to add the type field to the die immediately so we don't
4311 infinitely recurse when dealing with pointers to the structure
4312 type within the structure itself. */
4313 set_die_type (die
, type
, cu
);
4315 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
4317 struct field_info fi
;
4318 struct die_info
*child_die
;
4320 memset (&fi
, 0, sizeof (struct field_info
));
4322 child_die
= die
->child
;
4324 while (child_die
&& child_die
->tag
)
4326 if (child_die
->tag
== DW_TAG_member
4327 || child_die
->tag
== DW_TAG_variable
)
4329 /* NOTE: carlton/2002-11-05: A C++ static data member
4330 should be a DW_TAG_member that is a declaration, but
4331 all versions of G++ as of this writing (so through at
4332 least 3.2.1) incorrectly generate DW_TAG_variable
4333 tags for them instead. */
4334 dwarf2_add_field (&fi
, child_die
, cu
);
4336 else if (child_die
->tag
== DW_TAG_subprogram
)
4338 /* C++ member function. */
4339 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
4341 else if (child_die
->tag
== DW_TAG_inheritance
)
4343 /* C++ base class field. */
4344 dwarf2_add_field (&fi
, child_die
, cu
);
4346 child_die
= sibling_die (child_die
);
4349 /* Attach fields and member functions to the type. */
4351 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
4354 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
4356 /* Get the type which refers to the base class (possibly this
4357 class itself) which contains the vtable pointer for the current
4358 class from the DW_AT_containing_type attribute. */
4360 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4362 struct type
*t
= die_containing_type (die
, cu
);
4364 TYPE_VPTR_BASETYPE (type
) = t
;
4369 /* Our own class provides vtbl ptr. */
4370 for (i
= TYPE_NFIELDS (t
) - 1;
4371 i
>= TYPE_N_BASECLASSES (t
);
4374 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
4376 if (is_vtable_name (fieldname
, cu
))
4378 TYPE_VPTR_FIELDNO (type
) = i
;
4383 /* Complain if virtual function table field not found. */
4384 if (i
< TYPE_N_BASECLASSES (t
))
4385 complaint (&symfile_complaints
,
4386 _("virtual function table pointer not found when defining class '%s'"),
4387 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
4392 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
4395 else if (cu
->producer
4396 && strncmp (cu
->producer
,
4397 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
4399 /* The IBM XLC compiler does not provide direct indication
4400 of the containing type, but the vtable pointer is
4401 always named __vfp. */
4405 for (i
= TYPE_NFIELDS (type
) - 1;
4406 i
>= TYPE_N_BASECLASSES (type
);
4409 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
4411 TYPE_VPTR_FIELDNO (type
) = i
;
4412 TYPE_VPTR_BASETYPE (type
) = type
;
4420 do_cleanups (back_to
);
4425 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4427 struct objfile
*objfile
= cu
->objfile
;
4428 struct die_info
*child_die
= die
->child
;
4429 struct type
*this_type
;
4431 this_type
= get_die_type (die
, cu
);
4432 if (this_type
== NULL
)
4433 this_type
= read_structure_type (die
, cu
);
4435 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
4436 snapshots) has been known to create a die giving a declaration
4437 for a class that has, as a child, a die giving a definition for a
4438 nested class. So we have to process our children even if the
4439 current die is a declaration. Normally, of course, a declaration
4440 won't have any children at all. */
4442 while (child_die
!= NULL
&& child_die
->tag
)
4444 if (child_die
->tag
== DW_TAG_member
4445 || child_die
->tag
== DW_TAG_variable
4446 || child_die
->tag
== DW_TAG_inheritance
)
4451 process_die (child_die
, cu
);
4453 child_die
= sibling_die (child_die
);
4456 /* Do not consider external references. According to the DWARF standard,
4457 these DIEs are identified by the fact that they have no byte_size
4458 attribute, and a declaration attribute. */
4459 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
4460 || !die_is_declaration (die
, cu
))
4461 new_symbol (die
, this_type
, cu
);
4464 /* Given a DW_AT_enumeration_type die, set its type. We do not
4465 complete the type's fields yet, or create any symbols. */
4467 static struct type
*
4468 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4470 struct objfile
*objfile
= cu
->objfile
;
4472 struct attribute
*attr
;
4475 type
= alloc_type (objfile
);
4477 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4478 name
= dwarf2_full_name (die
, cu
);
4480 TYPE_TAG_NAME (type
) = (char *) name
;
4482 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4485 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4489 TYPE_LENGTH (type
) = 0;
4492 /* The enumeration DIE can be incomplete. In Ada, any type can be
4493 declared as private in the package spec, and then defined only
4494 inside the package body. Such types are known as Taft Amendment
4495 Types. When another package uses such a type, an incomplete DIE
4496 may be generated by the compiler. */
4497 if (die_is_declaration (die
, cu
))
4498 TYPE_STUB (type
) = 1;
4500 return set_die_type (die
, type
, cu
);
4503 /* Determine the name of the type represented by DIE, which should be
4504 a named C++ or Java compound type. Return the name in question,
4505 allocated on the objfile obstack. */
4508 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
4510 const char *new_prefix
= NULL
;
4512 /* If we don't have namespace debug info, guess the name by trying
4513 to demangle the names of members, just like we did in
4514 guess_structure_name. */
4515 if (!processing_has_namespace_info
)
4517 struct die_info
*child
;
4519 for (child
= die
->child
;
4520 child
!= NULL
&& child
->tag
!= 0;
4521 child
= sibling_die (child
))
4523 if (child
->tag
== DW_TAG_subprogram
)
4526 = language_class_name_from_physname (cu
->language_defn
,
4530 if (phys_prefix
!= NULL
)
4533 = obsavestring (phys_prefix
, strlen (phys_prefix
),
4534 &cu
->objfile
->objfile_obstack
);
4535 xfree (phys_prefix
);
4542 if (new_prefix
== NULL
)
4543 new_prefix
= dwarf2_full_name (die
, cu
);
4548 /* Given a pointer to a die which begins an enumeration, process all
4549 the dies that define the members of the enumeration, and create the
4550 symbol for the enumeration type.
4552 NOTE: We reverse the order of the element list. */
4555 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4557 struct objfile
*objfile
= cu
->objfile
;
4558 struct die_info
*child_die
;
4559 struct field
*fields
;
4562 int unsigned_enum
= 1;
4564 struct type
*this_type
;
4568 this_type
= get_die_type (die
, cu
);
4569 if (this_type
== NULL
)
4570 this_type
= read_enumeration_type (die
, cu
);
4571 if (die
->child
!= NULL
)
4573 child_die
= die
->child
;
4574 while (child_die
&& child_die
->tag
)
4576 if (child_die
->tag
!= DW_TAG_enumerator
)
4578 process_die (child_die
, cu
);
4582 name
= dwarf2_name (child_die
, cu
);
4585 sym
= new_symbol (child_die
, this_type
, cu
);
4586 if (SYMBOL_VALUE (sym
) < 0)
4589 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4591 fields
= (struct field
*)
4593 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
4594 * sizeof (struct field
));
4597 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
4598 FIELD_TYPE (fields
[num_fields
]) = NULL
;
4599 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
4600 FIELD_BITSIZE (fields
[num_fields
]) = 0;
4606 child_die
= sibling_die (child_die
);
4611 TYPE_NFIELDS (this_type
) = num_fields
;
4612 TYPE_FIELDS (this_type
) = (struct field
*)
4613 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
4614 memcpy (TYPE_FIELDS (this_type
), fields
,
4615 sizeof (struct field
) * num_fields
);
4619 TYPE_UNSIGNED (this_type
) = 1;
4622 new_symbol (die
, this_type
, cu
);
4625 /* Extract all information from a DW_TAG_array_type DIE and put it in
4626 the DIE's type field. For now, this only handles one dimensional
4629 static struct type
*
4630 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4632 struct objfile
*objfile
= cu
->objfile
;
4633 struct die_info
*child_die
;
4634 struct type
*type
= NULL
;
4635 struct type
*element_type
, *range_type
, *index_type
;
4636 struct type
**range_types
= NULL
;
4637 struct attribute
*attr
;
4639 struct cleanup
*back_to
;
4642 element_type
= die_type (die
, cu
);
4644 /* Irix 6.2 native cc creates array types without children for
4645 arrays with unspecified length. */
4646 if (die
->child
== NULL
)
4648 index_type
= builtin_type_int32
;
4649 range_type
= create_range_type (NULL
, index_type
, 0, -1);
4650 type
= create_array_type (NULL
, element_type
, range_type
);
4651 return set_die_type (die
, type
, cu
);
4654 back_to
= make_cleanup (null_cleanup
, NULL
);
4655 child_die
= die
->child
;
4656 while (child_die
&& child_die
->tag
)
4658 if (child_die
->tag
== DW_TAG_subrange_type
)
4660 struct type
*child_type
= read_type_die (child_die
, cu
);
4661 if (child_type
!= NULL
)
4663 /* The range type was succesfully read. Save it for
4664 the array type creation. */
4665 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
4667 range_types
= (struct type
**)
4668 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
4669 * sizeof (struct type
*));
4671 make_cleanup (free_current_contents
, &range_types
);
4673 range_types
[ndim
++] = child_type
;
4676 child_die
= sibling_die (child_die
);
4679 /* Dwarf2 dimensions are output from left to right, create the
4680 necessary array types in backwards order. */
4682 type
= element_type
;
4684 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
4688 type
= create_array_type (NULL
, type
, range_types
[i
++]);
4693 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
4696 /* Understand Dwarf2 support for vector types (like they occur on
4697 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4698 array type. This is not part of the Dwarf2/3 standard yet, but a
4699 custom vendor extension. The main difference between a regular
4700 array and the vector variant is that vectors are passed by value
4702 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4704 make_vector_type (type
);
4706 name
= dwarf2_name (die
, cu
);
4708 TYPE_NAME (type
) = name
;
4710 do_cleanups (back_to
);
4712 /* Install the type in the die. */
4713 return set_die_type (die
, type
, cu
);
4716 static enum dwarf_array_dim_ordering
4717 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4719 struct attribute
*attr
;
4721 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4723 if (attr
) return DW_SND (attr
);
4726 GNU F77 is a special case, as at 08/2004 array type info is the
4727 opposite order to the dwarf2 specification, but data is still
4728 laid out as per normal fortran.
4730 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4734 if (cu
->language
== language_fortran
&&
4735 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4737 return DW_ORD_row_major
;
4740 switch (cu
->language_defn
->la_array_ordering
)
4742 case array_column_major
:
4743 return DW_ORD_col_major
;
4744 case array_row_major
:
4746 return DW_ORD_row_major
;
4750 /* Extract all information from a DW_TAG_set_type DIE and put it in
4751 the DIE's type field. */
4753 static struct type
*
4754 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4756 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
4758 return set_die_type (die
, set_type
, cu
);
4761 /* First cut: install each common block member as a global variable. */
4764 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4766 struct die_info
*child_die
;
4767 struct attribute
*attr
;
4769 CORE_ADDR base
= (CORE_ADDR
) 0;
4771 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4774 /* Support the .debug_loc offsets */
4775 if (attr_form_is_block (attr
))
4777 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4779 else if (attr_form_is_section_offset (attr
))
4781 dwarf2_complex_location_expr_complaint ();
4785 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4786 "common block member");
4789 if (die
->child
!= NULL
)
4791 child_die
= die
->child
;
4792 while (child_die
&& child_die
->tag
)
4794 sym
= new_symbol (child_die
, NULL
, cu
);
4795 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4798 SYMBOL_VALUE_ADDRESS (sym
) =
4799 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4800 add_symbol_to_list (sym
, &global_symbols
);
4802 child_die
= sibling_die (child_die
);
4807 /* Create a type for a C++ namespace. */
4809 static struct type
*
4810 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4812 struct objfile
*objfile
= cu
->objfile
;
4813 const char *previous_prefix
, *name
;
4817 /* For extensions, reuse the type of the original namespace. */
4818 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
4820 struct die_info
*ext_die
;
4821 struct dwarf2_cu
*ext_cu
= cu
;
4822 ext_die
= dwarf2_extension (die
, &ext_cu
);
4823 type
= read_type_die (ext_die
, ext_cu
);
4824 return set_die_type (die
, type
, cu
);
4827 name
= namespace_name (die
, &is_anonymous
, cu
);
4829 /* Now build the name of the current namespace. */
4831 previous_prefix
= determine_prefix (die
, cu
);
4832 if (previous_prefix
[0] != '\0')
4833 name
= typename_concat (&objfile
->objfile_obstack
,
4834 previous_prefix
, name
, cu
);
4836 /* Create the type. */
4837 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
4839 TYPE_NAME (type
) = (char *) name
;
4840 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4842 set_die_type (die
, type
, cu
);
4847 /* Read a C++ namespace. */
4850 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4852 struct objfile
*objfile
= cu
->objfile
;
4856 /* Add a symbol associated to this if we haven't seen the namespace
4857 before. Also, add a using directive if it's an anonymous
4860 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
4864 type
= read_type_die (die
, cu
);
4865 new_symbol (die
, type
, cu
);
4867 name
= namespace_name (die
, &is_anonymous
, cu
);
4870 const char *previous_prefix
= determine_prefix (die
, cu
);
4871 cp_add_using_directive (TYPE_NAME (type
),
4872 strlen (previous_prefix
),
4873 strlen (TYPE_NAME (type
)));
4877 if (die
->child
!= NULL
)
4879 struct die_info
*child_die
= die
->child
;
4881 while (child_die
&& child_die
->tag
)
4883 process_die (child_die
, cu
);
4884 child_die
= sibling_die (child_die
);
4889 /* Read a Fortran module. */
4892 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
4894 struct die_info
*child_die
= die
->child
;
4896 /* FIXME: Support the separate Fortran module namespaces. */
4898 while (child_die
&& child_die
->tag
)
4900 process_die (child_die
, cu
);
4901 child_die
= sibling_die (child_die
);
4905 /* Return the name of the namespace represented by DIE. Set
4906 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4910 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
4912 struct die_info
*current_die
;
4913 const char *name
= NULL
;
4915 /* Loop through the extensions until we find a name. */
4917 for (current_die
= die
;
4918 current_die
!= NULL
;
4919 current_die
= dwarf2_extension (die
, &cu
))
4921 name
= dwarf2_name (current_die
, cu
);
4926 /* Is it an anonymous namespace? */
4928 *is_anonymous
= (name
== NULL
);
4930 name
= "(anonymous namespace)";
4935 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4936 the user defined type vector. */
4938 static struct type
*
4939 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4941 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
4942 struct comp_unit_head
*cu_header
= &cu
->header
;
4944 struct attribute
*attr_byte_size
;
4945 struct attribute
*attr_address_class
;
4946 int byte_size
, addr_class
;
4948 type
= lookup_pointer_type (die_type (die
, cu
));
4950 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4952 byte_size
= DW_UNSND (attr_byte_size
);
4954 byte_size
= cu_header
->addr_size
;
4956 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
4957 if (attr_address_class
)
4958 addr_class
= DW_UNSND (attr_address_class
);
4960 addr_class
= DW_ADDR_none
;
4962 /* If the pointer size or address class is different than the
4963 default, create a type variant marked as such and set the
4964 length accordingly. */
4965 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
4967 if (gdbarch_address_class_type_flags_p (gdbarch
))
4971 type_flags
= gdbarch_address_class_type_flags
4972 (gdbarch
, byte_size
, addr_class
);
4973 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
4975 type
= make_type_with_address_space (type
, type_flags
);
4977 else if (TYPE_LENGTH (type
) != byte_size
)
4979 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
4982 /* Should we also complain about unhandled address classes? */
4986 TYPE_LENGTH (type
) = byte_size
;
4987 return set_die_type (die
, type
, cu
);
4990 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4991 the user defined type vector. */
4993 static struct type
*
4994 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4996 struct objfile
*objfile
= cu
->objfile
;
4998 struct type
*to_type
;
4999 struct type
*domain
;
5001 to_type
= die_type (die
, cu
);
5002 domain
= die_containing_type (die
, cu
);
5004 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
5005 type
= lookup_methodptr_type (to_type
);
5007 type
= lookup_memberptr_type (to_type
, domain
);
5009 return set_die_type (die
, type
, cu
);
5012 /* Extract all information from a DW_TAG_reference_type DIE and add to
5013 the user defined type vector. */
5015 static struct type
*
5016 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5018 struct comp_unit_head
*cu_header
= &cu
->header
;
5020 struct attribute
*attr
;
5022 type
= lookup_reference_type (die_type (die
, cu
));
5023 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5026 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5030 TYPE_LENGTH (type
) = cu_header
->addr_size
;
5032 return set_die_type (die
, type
, cu
);
5035 static struct type
*
5036 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5038 struct type
*base_type
, *cv_type
;
5040 base_type
= die_type (die
, cu
);
5041 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
5042 return set_die_type (die
, cv_type
, cu
);
5045 static struct type
*
5046 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5048 struct type
*base_type
, *cv_type
;
5050 base_type
= die_type (die
, cu
);
5051 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
5052 return set_die_type (die
, cv_type
, cu
);
5055 /* Extract all information from a DW_TAG_string_type DIE and add to
5056 the user defined type vector. It isn't really a user defined type,
5057 but it behaves like one, with other DIE's using an AT_user_def_type
5058 attribute to reference it. */
5060 static struct type
*
5061 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5063 struct objfile
*objfile
= cu
->objfile
;
5064 struct type
*type
, *range_type
, *index_type
, *char_type
;
5065 struct attribute
*attr
;
5066 unsigned int length
;
5068 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
5071 length
= DW_UNSND (attr
);
5075 /* check for the DW_AT_byte_size attribute */
5076 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5079 length
= DW_UNSND (attr
);
5087 index_type
= builtin_type_int32
;
5088 range_type
= create_range_type (NULL
, index_type
, 1, length
);
5089 type
= create_string_type (NULL
, range_type
);
5091 return set_die_type (die
, type
, cu
);
5094 /* Handle DIES due to C code like:
5098 int (*funcp)(int a, long l);
5102 ('funcp' generates a DW_TAG_subroutine_type DIE)
5105 static struct type
*
5106 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5108 struct type
*type
; /* Type that this function returns */
5109 struct type
*ftype
; /* Function that returns above type */
5110 struct attribute
*attr
;
5112 type
= die_type (die
, cu
);
5113 ftype
= make_function_type (type
, (struct type
**) 0, cu
->objfile
);
5115 /* All functions in C++, Pascal and Java have prototypes. */
5116 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
5117 if ((attr
&& (DW_UNSND (attr
) != 0))
5118 || cu
->language
== language_cplus
5119 || cu
->language
== language_java
5120 || cu
->language
== language_pascal
)
5121 TYPE_PROTOTYPED (ftype
) = 1;
5123 /* Store the calling convention in the type if it's available in
5124 the subroutine die. Otherwise set the calling convention to
5125 the default value DW_CC_normal. */
5126 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
5127 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
5129 if (die
->child
!= NULL
)
5131 struct die_info
*child_die
;
5135 /* Count the number of parameters.
5136 FIXME: GDB currently ignores vararg functions, but knows about
5137 vararg member functions. */
5138 child_die
= die
->child
;
5139 while (child_die
&& child_die
->tag
)
5141 if (child_die
->tag
== DW_TAG_formal_parameter
)
5143 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
5144 TYPE_VARARGS (ftype
) = 1;
5145 child_die
= sibling_die (child_die
);
5148 /* Allocate storage for parameters and fill them in. */
5149 TYPE_NFIELDS (ftype
) = nparams
;
5150 TYPE_FIELDS (ftype
) = (struct field
*)
5151 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
5153 child_die
= die
->child
;
5154 while (child_die
&& child_die
->tag
)
5156 if (child_die
->tag
== DW_TAG_formal_parameter
)
5158 /* Dwarf2 has no clean way to discern C++ static and non-static
5159 member functions. G++ helps GDB by marking the first
5160 parameter for non-static member functions (which is the
5161 this pointer) as artificial. We pass this information
5162 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
5163 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
5165 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
5167 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
5168 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
5171 child_die
= sibling_die (child_die
);
5175 return set_die_type (die
, ftype
, cu
);
5178 static struct type
*
5179 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
5181 struct objfile
*objfile
= cu
->objfile
;
5182 struct attribute
*attr
;
5183 const char *name
= NULL
;
5184 struct type
*this_type
;
5186 name
= dwarf2_full_name (die
, cu
);
5187 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
5188 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
5189 TYPE_NAME (this_type
) = (char *) name
;
5190 set_die_type (die
, this_type
, cu
);
5191 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
5195 /* Find a representation of a given base type and install
5196 it in the TYPE field of the die. */
5198 static struct type
*
5199 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5201 struct objfile
*objfile
= cu
->objfile
;
5203 struct attribute
*attr
;
5204 int encoding
= 0, size
= 0;
5206 enum type_code code
= TYPE_CODE_INT
;
5208 struct type
*target_type
= NULL
;
5210 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
5213 encoding
= DW_UNSND (attr
);
5215 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5218 size
= DW_UNSND (attr
);
5220 name
= dwarf2_name (die
, cu
);
5223 complaint (&symfile_complaints
,
5224 _("DW_AT_name missing from DW_TAG_base_type"));
5229 case DW_ATE_address
:
5230 /* Turn DW_ATE_address into a void * pointer. */
5231 code
= TYPE_CODE_PTR
;
5232 type_flags
|= TYPE_FLAG_UNSIGNED
;
5233 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
5235 case DW_ATE_boolean
:
5236 code
= TYPE_CODE_BOOL
;
5237 type_flags
|= TYPE_FLAG_UNSIGNED
;
5239 case DW_ATE_complex_float
:
5240 code
= TYPE_CODE_COMPLEX
;
5241 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
5243 case DW_ATE_decimal_float
:
5244 code
= TYPE_CODE_DECFLOAT
;
5247 code
= TYPE_CODE_FLT
;
5251 case DW_ATE_unsigned
:
5252 type_flags
|= TYPE_FLAG_UNSIGNED
;
5254 case DW_ATE_signed_char
:
5255 if (cu
->language
== language_ada
|| cu
->language
== language_m2
5256 || cu
->language
== language_pascal
)
5257 code
= TYPE_CODE_CHAR
;
5259 case DW_ATE_unsigned_char
:
5260 if (cu
->language
== language_ada
|| cu
->language
== language_m2
5261 || cu
->language
== language_pascal
)
5262 code
= TYPE_CODE_CHAR
;
5263 type_flags
|= TYPE_FLAG_UNSIGNED
;
5266 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
5267 dwarf_type_encoding_name (encoding
));
5271 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
5272 TYPE_NAME (type
) = name
;
5273 TYPE_TARGET_TYPE (type
) = target_type
;
5275 if (name
&& strcmp (name
, "char") == 0)
5276 TYPE_NOSIGN (type
) = 1;
5278 return set_die_type (die
, type
, cu
);
5281 /* Read the given DW_AT_subrange DIE. */
5283 static struct type
*
5284 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5286 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5287 struct type
*base_type
;
5288 struct type
*range_type
;
5289 struct attribute
*attr
;
5294 base_type
= die_type (die
, cu
);
5295 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
5297 complaint (&symfile_complaints
,
5298 _("DW_AT_type missing from DW_TAG_subrange_type"));
5300 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
5301 0, NULL
, cu
->objfile
);
5304 if (cu
->language
== language_fortran
)
5306 /* FORTRAN implies a lower bound of 1, if not given. */
5310 /* FIXME: For variable sized arrays either of these could be
5311 a variable rather than a constant value. We'll allow it,
5312 but we don't know how to handle it. */
5313 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
5315 low
= dwarf2_get_attr_constant_value (attr
, 0);
5317 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
5320 if (attr
->form
== DW_FORM_block1
)
5322 /* GCC encodes arrays with unspecified or dynamic length
5323 with a DW_FORM_block1 attribute.
5324 FIXME: GDB does not yet know how to handle dynamic
5325 arrays properly, treat them as arrays with unspecified
5328 FIXME: jimb/2003-09-22: GDB does not really know
5329 how to handle arrays of unspecified length
5330 either; we just represent them as zero-length
5331 arrays. Choose an appropriate upper bound given
5332 the lower bound we've computed above. */
5336 high
= dwarf2_get_attr_constant_value (attr
, 1);
5339 range_type
= create_range_type (NULL
, base_type
, low
, high
);
5341 name
= dwarf2_name (die
, cu
);
5343 TYPE_NAME (range_type
) = name
;
5345 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5347 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
5349 return set_die_type (die
, range_type
, cu
);
5352 static struct type
*
5353 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5357 /* For now, we only support the C meaning of an unspecified type: void. */
5359 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
5360 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
5362 return set_die_type (die
, type
, cu
);
5365 /* Trivial hash function for die_info: the hash value of a DIE
5366 is its offset in .debug_info for this objfile. */
5369 die_hash (const void *item
)
5371 const struct die_info
*die
= item
;
5375 /* Trivial comparison function for die_info structures: two DIEs
5376 are equal if they have the same offset. */
5379 die_eq (const void *item_lhs
, const void *item_rhs
)
5381 const struct die_info
*die_lhs
= item_lhs
;
5382 const struct die_info
*die_rhs
= item_rhs
;
5383 return die_lhs
->offset
== die_rhs
->offset
;
5386 /* Read a whole compilation unit into a linked list of dies. */
5388 static struct die_info
*
5389 read_comp_unit (gdb_byte
*info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
5392 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5396 &cu
->comp_unit_obstack
,
5397 hashtab_obstack_allocate
,
5398 dummy_obstack_deallocate
);
5400 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
5403 /* Main entry point for reading a DIE and all children.
5404 Read the DIE and dump it if requested. */
5406 static struct die_info
*
5407 read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
5408 struct dwarf2_cu
*cu
,
5409 gdb_byte
**new_info_ptr
,
5410 struct die_info
*parent
)
5412 struct die_info
*result
= read_die_and_children_1 (info_ptr
, abfd
, cu
,
5413 new_info_ptr
, parent
);
5415 if (dwarf2_die_debug
)
5417 fprintf_unfiltered (gdb_stdlog
, "Read die from .debug_info:\n");
5418 dump_die (result
, dwarf2_die_debug
);
5424 /* Read a single die and all its descendents. Set the die's sibling
5425 field to NULL; set other fields in the die correctly, and set all
5426 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
5427 location of the info_ptr after reading all of those dies. PARENT
5428 is the parent of the die in question. */
5430 static struct die_info
*
5431 read_die_and_children_1 (gdb_byte
*info_ptr
, bfd
*abfd
,
5432 struct dwarf2_cu
*cu
,
5433 gdb_byte
**new_info_ptr
,
5434 struct die_info
*parent
)
5436 struct die_info
*die
;
5440 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
5443 *new_info_ptr
= cur_ptr
;
5446 store_in_ref_table (die
, cu
);
5450 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
5456 *new_info_ptr
= cur_ptr
;
5459 die
->sibling
= NULL
;
5460 die
->parent
= parent
;
5464 /* Read a die, all of its descendents, and all of its siblings; set
5465 all of the fields of all of the dies correctly. Arguments are as
5466 in read_die_and_children. */
5468 static struct die_info
*
5469 read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
5470 struct dwarf2_cu
*cu
,
5471 gdb_byte
**new_info_ptr
,
5472 struct die_info
*parent
)
5474 struct die_info
*first_die
, *last_sibling
;
5478 first_die
= last_sibling
= NULL
;
5482 struct die_info
*die
5483 = read_die_and_children_1 (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
5487 *new_info_ptr
= cur_ptr
;
5494 last_sibling
->sibling
= die
;
5500 /* Decompress a section that was compressed using zlib. Store the
5501 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
5504 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
5505 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
5507 bfd
*abfd
= objfile
->obfd
;
5509 error (_("Support for zlib-compressed DWARF data (from '%s') "
5510 "is disabled in this copy of GDB"),
5511 bfd_get_filename (abfd
));
5513 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
5514 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
5515 bfd_size_type uncompressed_size
;
5516 gdb_byte
*uncompressed_buffer
;
5519 int header_size
= 12;
5521 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5522 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
5523 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5524 bfd_get_filename (abfd
));
5526 /* Read the zlib header. In this case, it should be "ZLIB" followed
5527 by the uncompressed section size, 8 bytes in big-endian order. */
5528 if (compressed_size
< header_size
5529 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
5530 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
5531 bfd_get_filename (abfd
));
5532 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
5533 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
5534 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
5535 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
5536 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
5537 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
5538 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
5539 uncompressed_size
+= compressed_buffer
[11];
5541 /* It is possible the section consists of several compressed
5542 buffers concatenated together, so we uncompress in a loop. */
5546 strm
.avail_in
= compressed_size
- header_size
;
5547 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
5548 strm
.avail_out
= uncompressed_size
;
5549 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
5551 rc
= inflateInit (&strm
);
5552 while (strm
.avail_in
> 0)
5555 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
5556 bfd_get_filename (abfd
), rc
);
5557 strm
.next_out
= ((Bytef
*) uncompressed_buffer
5558 + (uncompressed_size
- strm
.avail_out
));
5559 rc
= inflate (&strm
, Z_FINISH
);
5560 if (rc
!= Z_STREAM_END
)
5561 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
5562 bfd_get_filename (abfd
), rc
);
5563 rc
= inflateReset (&strm
);
5565 rc
= inflateEnd (&strm
);
5567 || strm
.avail_out
!= 0)
5568 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
5569 bfd_get_filename (abfd
), rc
);
5571 xfree (compressed_buffer
);
5572 *outbuf
= uncompressed_buffer
;
5573 *outsize
= uncompressed_size
;
5578 /* Read the contents of the section at OFFSET and of size SIZE from the
5579 object file specified by OBJFILE into the objfile_obstack and return it.
5580 If the section is compressed, uncompress it before returning. */
5583 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
5585 bfd
*abfd
= objfile
->obfd
;
5586 gdb_byte
*buf
, *retbuf
;
5587 bfd_size_type size
= bfd_get_section_size (sectp
);
5588 unsigned char header
[4];
5593 /* Check if the file has a 4-byte header indicating compression. */
5594 if (size
> sizeof (header
)
5595 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
5596 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
5598 /* Upon decompression, update the buffer and its size. */
5599 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
5601 zlib_decompress_section (objfile
, sectp
, &buf
, &size
);
5602 dwarf2_resize_section (sectp
, size
);
5607 /* If we get here, we are a normal, not-compressed section. */
5608 buf
= obstack_alloc (&objfile
->objfile_obstack
, size
);
5609 /* When debugging .o files, we may need to apply relocations; see
5610 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
5611 We never compress sections in .o files, so we only need to
5612 try this when the section is not compressed. */
5613 retbuf
= symfile_relocate_debug_section (abfd
, sectp
, buf
);
5617 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5618 || bfd_bread (buf
, size
, abfd
) != size
)
5619 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5620 bfd_get_filename (abfd
));
5625 /* In DWARF version 2, the description of the debugging information is
5626 stored in a separate .debug_abbrev section. Before we read any
5627 dies from a section we read in all abbreviations and install them
5628 in a hash table. This function also sets flags in CU describing
5629 the data found in the abbrev table. */
5632 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
5634 struct comp_unit_head
*cu_header
= &cu
->header
;
5635 gdb_byte
*abbrev_ptr
;
5636 struct abbrev_info
*cur_abbrev
;
5637 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
5638 unsigned int abbrev_form
, hash_number
;
5639 struct attr_abbrev
*cur_attrs
;
5640 unsigned int allocated_attrs
;
5642 /* Initialize dwarf2 abbrevs */
5643 obstack_init (&cu
->abbrev_obstack
);
5644 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
5646 * sizeof (struct abbrev_info
*)));
5647 memset (cu
->dwarf2_abbrevs
, 0,
5648 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
5650 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
5651 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5652 abbrev_ptr
+= bytes_read
;
5654 allocated_attrs
= ATTR_ALLOC_CHUNK
;
5655 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
5657 /* loop until we reach an abbrev number of 0 */
5658 while (abbrev_number
)
5660 cur_abbrev
= dwarf_alloc_abbrev (cu
);
5662 /* read in abbrev header */
5663 cur_abbrev
->number
= abbrev_number
;
5664 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5665 abbrev_ptr
+= bytes_read
;
5666 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
5669 if (cur_abbrev
->tag
== DW_TAG_namespace
)
5670 cu
->has_namespace_info
= 1;
5672 /* now read in declarations */
5673 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5674 abbrev_ptr
+= bytes_read
;
5675 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5676 abbrev_ptr
+= bytes_read
;
5679 if (cur_abbrev
->num_attrs
== allocated_attrs
)
5681 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
5683 = xrealloc (cur_attrs
, (allocated_attrs
5684 * sizeof (struct attr_abbrev
)));
5687 /* Record whether this compilation unit might have
5688 inter-compilation-unit references. If we don't know what form
5689 this attribute will have, then it might potentially be a
5690 DW_FORM_ref_addr, so we conservatively expect inter-CU
5693 if (abbrev_form
== DW_FORM_ref_addr
5694 || abbrev_form
== DW_FORM_indirect
)
5695 cu
->has_form_ref_addr
= 1;
5697 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
5698 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
5699 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5700 abbrev_ptr
+= bytes_read
;
5701 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5702 abbrev_ptr
+= bytes_read
;
5705 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
5706 (cur_abbrev
->num_attrs
5707 * sizeof (struct attr_abbrev
)));
5708 memcpy (cur_abbrev
->attrs
, cur_attrs
,
5709 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
5711 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
5712 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
5713 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
5715 /* Get next abbreviation.
5716 Under Irix6 the abbreviations for a compilation unit are not
5717 always properly terminated with an abbrev number of 0.
5718 Exit loop if we encounter an abbreviation which we have
5719 already read (which means we are about to read the abbreviations
5720 for the next compile unit) or if the end of the abbreviation
5721 table is reached. */
5722 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
5723 >= dwarf2_per_objfile
->abbrev_size
)
5725 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5726 abbrev_ptr
+= bytes_read
;
5727 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
5734 /* Release the memory used by the abbrev table for a compilation unit. */
5737 dwarf2_free_abbrev_table (void *ptr_to_cu
)
5739 struct dwarf2_cu
*cu
= ptr_to_cu
;
5741 obstack_free (&cu
->abbrev_obstack
, NULL
);
5742 cu
->dwarf2_abbrevs
= NULL
;
5745 /* Lookup an abbrev_info structure in the abbrev hash table. */
5747 static struct abbrev_info
*
5748 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
5750 unsigned int hash_number
;
5751 struct abbrev_info
*abbrev
;
5753 hash_number
= number
% ABBREV_HASH_SIZE
;
5754 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
5758 if (abbrev
->number
== number
)
5761 abbrev
= abbrev
->next
;
5766 /* Returns nonzero if TAG represents a type that we might generate a partial
5770 is_type_tag_for_partial (int tag
)
5775 /* Some types that would be reasonable to generate partial symbols for,
5776 that we don't at present. */
5777 case DW_TAG_array_type
:
5778 case DW_TAG_file_type
:
5779 case DW_TAG_ptr_to_member_type
:
5780 case DW_TAG_set_type
:
5781 case DW_TAG_string_type
:
5782 case DW_TAG_subroutine_type
:
5784 case DW_TAG_base_type
:
5785 case DW_TAG_class_type
:
5786 case DW_TAG_interface_type
:
5787 case DW_TAG_enumeration_type
:
5788 case DW_TAG_structure_type
:
5789 case DW_TAG_subrange_type
:
5790 case DW_TAG_typedef
:
5791 case DW_TAG_union_type
:
5798 /* Load all DIEs that are interesting for partial symbols into memory. */
5800 static struct partial_die_info
*
5801 load_partial_dies (bfd
*abfd
, gdb_byte
*info_ptr
, int building_psymtab
,
5802 struct dwarf2_cu
*cu
)
5804 struct partial_die_info
*part_die
;
5805 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
5806 struct abbrev_info
*abbrev
;
5807 unsigned int bytes_read
;
5808 unsigned int load_all
= 0;
5810 int nesting_level
= 1;
5815 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
5819 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5823 &cu
->comp_unit_obstack
,
5824 hashtab_obstack_allocate
,
5825 dummy_obstack_deallocate
);
5827 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5828 sizeof (struct partial_die_info
));
5832 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5834 /* A NULL abbrev means the end of a series of children. */
5837 if (--nesting_level
== 0)
5839 /* PART_DIE was probably the last thing allocated on the
5840 comp_unit_obstack, so we could call obstack_free
5841 here. We don't do that because the waste is small,
5842 and will be cleaned up when we're done with this
5843 compilation unit. This way, we're also more robust
5844 against other users of the comp_unit_obstack. */
5847 info_ptr
+= bytes_read
;
5848 last_die
= parent_die
;
5849 parent_die
= parent_die
->die_parent
;
5853 /* Check whether this DIE is interesting enough to save. Normally
5854 we would not be interested in members here, but there may be
5855 later variables referencing them via DW_AT_specification (for
5858 && !is_type_tag_for_partial (abbrev
->tag
)
5859 && abbrev
->tag
!= DW_TAG_enumerator
5860 && abbrev
->tag
!= DW_TAG_subprogram
5861 && abbrev
->tag
!= DW_TAG_lexical_block
5862 && abbrev
->tag
!= DW_TAG_variable
5863 && abbrev
->tag
!= DW_TAG_namespace
5864 && abbrev
->tag
!= DW_TAG_member
)
5866 /* Otherwise we skip to the next sibling, if any. */
5867 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5871 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5872 abfd
, info_ptr
, cu
);
5874 /* This two-pass algorithm for processing partial symbols has a
5875 high cost in cache pressure. Thus, handle some simple cases
5876 here which cover the majority of C partial symbols. DIEs
5877 which neither have specification tags in them, nor could have
5878 specification tags elsewhere pointing at them, can simply be
5879 processed and discarded.
5881 This segment is also optional; scan_partial_symbols and
5882 add_partial_symbol will handle these DIEs if we chain
5883 them in normally. When compilers which do not emit large
5884 quantities of duplicate debug information are more common,
5885 this code can probably be removed. */
5887 /* Any complete simple types at the top level (pretty much all
5888 of them, for a language without namespaces), can be processed
5890 if (parent_die
== NULL
5891 && part_die
->has_specification
== 0
5892 && part_die
->is_declaration
== 0
5893 && (part_die
->tag
== DW_TAG_typedef
5894 || part_die
->tag
== DW_TAG_base_type
5895 || part_die
->tag
== DW_TAG_subrange_type
))
5897 if (building_psymtab
&& part_die
->name
!= NULL
)
5898 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5899 VAR_DOMAIN
, LOC_TYPEDEF
,
5900 &cu
->objfile
->static_psymbols
,
5901 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5902 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5906 /* If we're at the second level, and we're an enumerator, and
5907 our parent has no specification (meaning possibly lives in a
5908 namespace elsewhere), then we can add the partial symbol now
5909 instead of queueing it. */
5910 if (part_die
->tag
== DW_TAG_enumerator
5911 && parent_die
!= NULL
5912 && parent_die
->die_parent
== NULL
5913 && parent_die
->tag
== DW_TAG_enumeration_type
5914 && parent_die
->has_specification
== 0)
5916 if (part_die
->name
== NULL
)
5917 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5918 else if (building_psymtab
)
5919 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5920 VAR_DOMAIN
, LOC_CONST
,
5921 (cu
->language
== language_cplus
5922 || cu
->language
== language_java
)
5923 ? &cu
->objfile
->global_psymbols
5924 : &cu
->objfile
->static_psymbols
,
5925 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5927 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5931 /* We'll save this DIE so link it in. */
5932 part_die
->die_parent
= parent_die
;
5933 part_die
->die_sibling
= NULL
;
5934 part_die
->die_child
= NULL
;
5936 if (last_die
&& last_die
== parent_die
)
5937 last_die
->die_child
= part_die
;
5939 last_die
->die_sibling
= part_die
;
5941 last_die
= part_die
;
5943 if (first_die
== NULL
)
5944 first_die
= part_die
;
5946 /* Maybe add the DIE to the hash table. Not all DIEs that we
5947 find interesting need to be in the hash table, because we
5948 also have the parent/sibling/child chains; only those that we
5949 might refer to by offset later during partial symbol reading.
5951 For now this means things that might have be the target of a
5952 DW_AT_specification, DW_AT_abstract_origin, or
5953 DW_AT_extension. DW_AT_extension will refer only to
5954 namespaces; DW_AT_abstract_origin refers to functions (and
5955 many things under the function DIE, but we do not recurse
5956 into function DIEs during partial symbol reading) and
5957 possibly variables as well; DW_AT_specification refers to
5958 declarations. Declarations ought to have the DW_AT_declaration
5959 flag. It happens that GCC forgets to put it in sometimes, but
5960 only for functions, not for types.
5962 Adding more things than necessary to the hash table is harmless
5963 except for the performance cost. Adding too few will result in
5964 wasted time in find_partial_die, when we reread the compilation
5965 unit with load_all_dies set. */
5968 || abbrev
->tag
== DW_TAG_subprogram
5969 || abbrev
->tag
== DW_TAG_variable
5970 || abbrev
->tag
== DW_TAG_namespace
5971 || part_die
->is_declaration
)
5975 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
5976 part_die
->offset
, INSERT
);
5980 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5981 sizeof (struct partial_die_info
));
5983 /* For some DIEs we want to follow their children (if any). For C
5984 we have no reason to follow the children of structures; for other
5985 languages we have to, both so that we can get at method physnames
5986 to infer fully qualified class names, and for DW_AT_specification.
5988 For Ada, we need to scan the children of subprograms and lexical
5989 blocks as well because Ada allows the definition of nested
5990 entities that could be interesting for the debugger, such as
5991 nested subprograms for instance. */
5992 if (last_die
->has_children
5994 || last_die
->tag
== DW_TAG_namespace
5995 || last_die
->tag
== DW_TAG_enumeration_type
5996 || (cu
->language
!= language_c
5997 && (last_die
->tag
== DW_TAG_class_type
5998 || last_die
->tag
== DW_TAG_interface_type
5999 || last_die
->tag
== DW_TAG_structure_type
6000 || last_die
->tag
== DW_TAG_union_type
))
6001 || (cu
->language
== language_ada
6002 && (last_die
->tag
== DW_TAG_subprogram
6003 || last_die
->tag
== DW_TAG_lexical_block
))))
6006 parent_die
= last_die
;
6010 /* Otherwise we skip to the next sibling, if any. */
6011 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
6013 /* Back to the top, do it again. */
6017 /* Read a minimal amount of information into the minimal die structure. */
6020 read_partial_die (struct partial_die_info
*part_die
,
6021 struct abbrev_info
*abbrev
,
6022 unsigned int abbrev_len
, bfd
*abfd
,
6023 gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6025 unsigned int bytes_read
, i
;
6026 struct attribute attr
;
6027 int has_low_pc_attr
= 0;
6028 int has_high_pc_attr
= 0;
6029 CORE_ADDR base_address
= 0;
6033 base_address_low_pc
,
6034 /* Overrides BASE_ADDRESS_LOW_PC. */
6035 base_address_entry_pc
6037 base_address_type
= base_address_none
;
6039 memset (part_die
, 0, sizeof (struct partial_die_info
));
6041 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
6043 info_ptr
+= abbrev_len
;
6048 part_die
->tag
= abbrev
->tag
;
6049 part_die
->has_children
= abbrev
->has_children
;
6051 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6053 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
6055 /* Store the data if it is of an attribute we want to keep in a
6056 partial symbol table. */
6060 switch (part_die
->tag
)
6062 case DW_TAG_compile_unit
:
6063 /* Compilation units have a DW_AT_name that is a filename, not
6064 a source language identifier. */
6065 case DW_TAG_enumeration_type
:
6066 case DW_TAG_enumerator
:
6067 /* These tags always have simple identifiers already; no need
6068 to canonicalize them. */
6069 part_die
->name
= DW_STRING (&attr
);
6073 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
6074 &cu
->comp_unit_obstack
);
6078 case DW_AT_comp_dir
:
6079 if (part_die
->dirname
== NULL
)
6080 part_die
->dirname
= DW_STRING (&attr
);
6082 case DW_AT_MIPS_linkage_name
:
6083 part_die
->name
= DW_STRING (&attr
);
6086 has_low_pc_attr
= 1;
6087 part_die
->lowpc
= DW_ADDR (&attr
);
6088 if (part_die
->tag
== DW_TAG_compile_unit
6089 && base_address_type
< base_address_low_pc
)
6091 base_address
= DW_ADDR (&attr
);
6092 base_address_type
= base_address_low_pc
;
6096 has_high_pc_attr
= 1;
6097 part_die
->highpc
= DW_ADDR (&attr
);
6099 case DW_AT_entry_pc
:
6100 if (part_die
->tag
== DW_TAG_compile_unit
6101 && base_address_type
< base_address_entry_pc
)
6103 base_address
= DW_ADDR (&attr
);
6104 base_address_type
= base_address_entry_pc
;
6108 if (part_die
->tag
== DW_TAG_compile_unit
)
6110 cu
->ranges_offset
= DW_UNSND (&attr
);
6111 cu
->has_ranges_offset
= 1;
6114 case DW_AT_location
:
6115 /* Support the .debug_loc offsets */
6116 if (attr_form_is_block (&attr
))
6118 part_die
->locdesc
= DW_BLOCK (&attr
);
6120 else if (attr_form_is_section_offset (&attr
))
6122 dwarf2_complex_location_expr_complaint ();
6126 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
6127 "partial symbol information");
6130 case DW_AT_language
:
6131 part_die
->language
= DW_UNSND (&attr
);
6133 case DW_AT_external
:
6134 part_die
->is_external
= DW_UNSND (&attr
);
6136 case DW_AT_declaration
:
6137 part_die
->is_declaration
= DW_UNSND (&attr
);
6140 part_die
->has_type
= 1;
6142 case DW_AT_abstract_origin
:
6143 case DW_AT_specification
:
6144 case DW_AT_extension
:
6145 part_die
->has_specification
= 1;
6146 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
6149 /* Ignore absolute siblings, they might point outside of
6150 the current compile unit. */
6151 if (attr
.form
== DW_FORM_ref_addr
)
6152 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
6154 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
6155 + dwarf2_get_ref_die_offset (&attr
);
6157 case DW_AT_stmt_list
:
6158 part_die
->has_stmt_list
= 1;
6159 part_die
->line_offset
= DW_UNSND (&attr
);
6161 case DW_AT_byte_size
:
6162 part_die
->has_byte_size
= 1;
6164 case DW_AT_calling_convention
:
6165 /* DWARF doesn't provide a way to identify a program's source-level
6166 entry point. DW_AT_calling_convention attributes are only meant
6167 to describe functions' calling conventions.
6169 However, because it's a necessary piece of information in
6170 Fortran, and because DW_CC_program is the only piece of debugging
6171 information whose definition refers to a 'main program' at all,
6172 several compilers have begun marking Fortran main programs with
6173 DW_CC_program --- even when those functions use the standard
6174 calling conventions.
6176 So until DWARF specifies a way to provide this information and
6177 compilers pick up the new representation, we'll support this
6179 if (DW_UNSND (&attr
) == DW_CC_program
6180 && cu
->language
== language_fortran
)
6181 set_main_name (part_die
->name
);
6188 /* When using the GNU linker, .gnu.linkonce. sections are used to
6189 eliminate duplicate copies of functions and vtables and such.
6190 The linker will arbitrarily choose one and discard the others.
6191 The AT_*_pc values for such functions refer to local labels in
6192 these sections. If the section from that file was discarded, the
6193 labels are not in the output, so the relocs get a value of 0.
6194 If this is a discarded function, mark the pc bounds as invalid,
6195 so that GDB will ignore it. */
6196 if (has_low_pc_attr
&& has_high_pc_attr
6197 && part_die
->lowpc
< part_die
->highpc
6198 && (part_die
->lowpc
!= 0
6199 || dwarf2_per_objfile
->has_section_at_zero
))
6200 part_die
->has_pc_info
= 1;
6202 if (base_address_type
!= base_address_none
&& !cu
->base_known
)
6204 gdb_assert (part_die
->tag
== DW_TAG_compile_unit
);
6206 cu
->base_address
= base_address
;
6212 /* Find a cached partial DIE at OFFSET in CU. */
6214 static struct partial_die_info
*
6215 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
6217 struct partial_die_info
*lookup_die
= NULL
;
6218 struct partial_die_info part_die
;
6220 part_die
.offset
= offset
;
6221 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
6226 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
6228 static struct partial_die_info
*
6229 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
6231 struct dwarf2_per_cu_data
*per_cu
= NULL
;
6232 struct partial_die_info
*pd
= NULL
;
6234 if (offset_in_cu_p (&cu
->header
, offset
))
6236 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6241 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
6243 if (per_cu
->cu
== NULL
)
6245 load_comp_unit (per_cu
, cu
->objfile
);
6246 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6247 dwarf2_per_objfile
->read_in_chain
= per_cu
;
6250 per_cu
->cu
->last_used
= 0;
6251 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6253 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
6255 struct cleanup
*back_to
;
6256 struct partial_die_info comp_unit_die
;
6257 struct abbrev_info
*abbrev
;
6258 unsigned int bytes_read
;
6261 per_cu
->load_all_dies
= 1;
6263 /* Re-read the DIEs. */
6264 back_to
= make_cleanup (null_cleanup
, 0);
6265 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
6267 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
6268 back_to
= make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
6270 info_ptr
= (dwarf2_per_objfile
->info_buffer
6271 + per_cu
->cu
->header
.offset
6272 + per_cu
->cu
->header
.first_die_offset
);
6273 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
6274 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
6275 per_cu
->cu
->objfile
->obfd
, info_ptr
,
6277 if (comp_unit_die
.has_children
)
6278 load_partial_dies (per_cu
->cu
->objfile
->obfd
, info_ptr
, 0, per_cu
->cu
);
6279 do_cleanups (back_to
);
6281 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6285 internal_error (__FILE__
, __LINE__
,
6286 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
6287 offset
, bfd_get_filename (cu
->objfile
->obfd
));
6291 /* Adjust PART_DIE before generating a symbol for it. This function
6292 may set the is_external flag or change the DIE's name. */
6295 fixup_partial_die (struct partial_die_info
*part_die
,
6296 struct dwarf2_cu
*cu
)
6298 /* If we found a reference attribute and the DIE has no name, try
6299 to find a name in the referred to DIE. */
6301 if (part_die
->name
== NULL
&& part_die
->has_specification
)
6303 struct partial_die_info
*spec_die
;
6305 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
6307 fixup_partial_die (spec_die
, cu
);
6311 part_die
->name
= spec_die
->name
;
6313 /* Copy DW_AT_external attribute if it is set. */
6314 if (spec_die
->is_external
)
6315 part_die
->is_external
= spec_die
->is_external
;
6319 /* Set default names for some unnamed DIEs. */
6320 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
6321 || part_die
->tag
== DW_TAG_class_type
))
6322 part_die
->name
= "(anonymous class)";
6324 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
6325 part_die
->name
= "(anonymous namespace)";
6327 if (part_die
->tag
== DW_TAG_structure_type
6328 || part_die
->tag
== DW_TAG_class_type
6329 || part_die
->tag
== DW_TAG_union_type
)
6330 guess_structure_name (part_die
, cu
);
6333 /* Read the die from the .debug_info section buffer. Set DIEP to
6334 point to a newly allocated die with its information, except for its
6335 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6336 whether the die has children or not. */
6339 read_full_die (struct die_info
**diep
, bfd
*abfd
, gdb_byte
*info_ptr
,
6340 struct dwarf2_cu
*cu
, int *has_children
)
6342 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6343 struct abbrev_info
*abbrev
;
6344 struct die_info
*die
;
6346 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
6347 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6348 info_ptr
+= bytes_read
;
6356 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6359 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6361 bfd_get_filename (abfd
));
6363 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
6364 die
->offset
= offset
;
6365 die
->tag
= abbrev
->tag
;
6366 die
->abbrev
= abbrev_number
;
6368 die
->num_attrs
= abbrev
->num_attrs
;
6370 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6371 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6372 abfd
, info_ptr
, cu
);
6375 *has_children
= abbrev
->has_children
;
6379 /* Read an attribute value described by an attribute form. */
6382 read_attribute_value (struct attribute
*attr
, unsigned form
,
6383 bfd
*abfd
, gdb_byte
*info_ptr
,
6384 struct dwarf2_cu
*cu
)
6386 struct comp_unit_head
*cu_header
= &cu
->header
;
6387 unsigned int bytes_read
;
6388 struct dwarf_block
*blk
;
6394 case DW_FORM_ref_addr
:
6395 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6396 info_ptr
+= bytes_read
;
6398 case DW_FORM_block2
:
6399 blk
= dwarf_alloc_block (cu
);
6400 blk
->size
= read_2_bytes (abfd
, info_ptr
);
6402 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6403 info_ptr
+= blk
->size
;
6404 DW_BLOCK (attr
) = blk
;
6406 case DW_FORM_block4
:
6407 blk
= dwarf_alloc_block (cu
);
6408 blk
->size
= read_4_bytes (abfd
, info_ptr
);
6410 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6411 info_ptr
+= blk
->size
;
6412 DW_BLOCK (attr
) = blk
;
6415 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
6419 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
6423 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
6426 case DW_FORM_string
:
6427 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
6428 info_ptr
+= bytes_read
;
6431 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
6433 info_ptr
+= bytes_read
;
6436 blk
= dwarf_alloc_block (cu
);
6437 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6438 info_ptr
+= bytes_read
;
6439 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6440 info_ptr
+= blk
->size
;
6441 DW_BLOCK (attr
) = blk
;
6443 case DW_FORM_block1
:
6444 blk
= dwarf_alloc_block (cu
);
6445 blk
->size
= read_1_byte (abfd
, info_ptr
);
6447 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6448 info_ptr
+= blk
->size
;
6449 DW_BLOCK (attr
) = blk
;
6452 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6456 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6460 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
6461 info_ptr
+= bytes_read
;
6464 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6465 info_ptr
+= bytes_read
;
6468 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
6472 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
6476 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
6480 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
6483 case DW_FORM_ref_udata
:
6484 DW_ADDR (attr
) = (cu
->header
.offset
6485 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
6486 info_ptr
+= bytes_read
;
6488 case DW_FORM_indirect
:
6489 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6490 info_ptr
+= bytes_read
;
6491 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
6494 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
6495 dwarf_form_name (form
),
6496 bfd_get_filename (abfd
));
6499 /* We have seen instances where the compiler tried to emit a byte
6500 size attribute of -1 which ended up being encoded as an unsigned
6501 0xffffffff. Although 0xffffffff is technically a valid size value,
6502 an object of this size seems pretty unlikely so we can relatively
6503 safely treat these cases as if the size attribute was invalid and
6504 treat them as zero by default. */
6505 if (attr
->name
== DW_AT_byte_size
6506 && form
== DW_FORM_data4
6507 && DW_UNSND (attr
) >= 0xffffffff)
6510 (&symfile_complaints
,
6511 _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"),
6513 DW_UNSND (attr
) = 0;
6519 /* Read an attribute described by an abbreviated attribute. */
6522 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
6523 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6525 attr
->name
= abbrev
->name
;
6526 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
6529 /* read dwarf information from a buffer */
6532 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
6534 return bfd_get_8 (abfd
, buf
);
6538 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
6540 return bfd_get_signed_8 (abfd
, buf
);
6544 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
6546 return bfd_get_16 (abfd
, buf
);
6550 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6552 return bfd_get_signed_16 (abfd
, buf
);
6556 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
6558 return bfd_get_32 (abfd
, buf
);
6562 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6564 return bfd_get_signed_32 (abfd
, buf
);
6567 static unsigned long
6568 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
6570 return bfd_get_64 (abfd
, buf
);
6574 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
6575 unsigned int *bytes_read
)
6577 struct comp_unit_head
*cu_header
= &cu
->header
;
6578 CORE_ADDR retval
= 0;
6580 if (cu_header
->signed_addr_p
)
6582 switch (cu_header
->addr_size
)
6585 retval
= bfd_get_signed_16 (abfd
, buf
);
6588 retval
= bfd_get_signed_32 (abfd
, buf
);
6591 retval
= bfd_get_signed_64 (abfd
, buf
);
6594 internal_error (__FILE__
, __LINE__
,
6595 _("read_address: bad switch, signed [in module %s]"),
6596 bfd_get_filename (abfd
));
6601 switch (cu_header
->addr_size
)
6604 retval
= bfd_get_16 (abfd
, buf
);
6607 retval
= bfd_get_32 (abfd
, buf
);
6610 retval
= bfd_get_64 (abfd
, buf
);
6613 internal_error (__FILE__
, __LINE__
,
6614 _("read_address: bad switch, unsigned [in module %s]"),
6615 bfd_get_filename (abfd
));
6619 *bytes_read
= cu_header
->addr_size
;
6623 /* Read the initial length from a section. The (draft) DWARF 3
6624 specification allows the initial length to take up either 4 bytes
6625 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
6626 bytes describe the length and all offsets will be 8 bytes in length
6629 An older, non-standard 64-bit format is also handled by this
6630 function. The older format in question stores the initial length
6631 as an 8-byte quantity without an escape value. Lengths greater
6632 than 2^32 aren't very common which means that the initial 4 bytes
6633 is almost always zero. Since a length value of zero doesn't make
6634 sense for the 32-bit format, this initial zero can be considered to
6635 be an escape value which indicates the presence of the older 64-bit
6636 format. As written, the code can't detect (old format) lengths
6637 greater than 4GB. If it becomes necessary to handle lengths
6638 somewhat larger than 4GB, we could allow other small values (such
6639 as the non-sensical values of 1, 2, and 3) to also be used as
6640 escape values indicating the presence of the old format.
6642 The value returned via bytes_read should be used to increment the
6643 relevant pointer after calling read_initial_length().
6645 [ Note: read_initial_length() and read_offset() are based on the
6646 document entitled "DWARF Debugging Information Format", revision
6647 3, draft 8, dated November 19, 2001. This document was obtained
6650 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
6652 This document is only a draft and is subject to change. (So beware.)
6654 Details regarding the older, non-standard 64-bit format were
6655 determined empirically by examining 64-bit ELF files produced by
6656 the SGI toolchain on an IRIX 6.5 machine.
6658 - Kevin, July 16, 2002
6662 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
6664 LONGEST length
= bfd_get_32 (abfd
, buf
);
6666 if (length
== 0xffffffff)
6668 length
= bfd_get_64 (abfd
, buf
+ 4);
6671 else if (length
== 0)
6673 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
6674 length
= bfd_get_64 (abfd
, buf
);
6685 /* Cover function for read_initial_length.
6686 Returns the length of the object at BUF, and stores the size of the
6687 initial length in *BYTES_READ and stores the size that offsets will be in
6689 If the initial length size is not equivalent to that specified in
6690 CU_HEADER then issue a complaint.
6691 This is useful when reading non-comp-unit headers. */
6694 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
6695 const struct comp_unit_head
*cu_header
,
6696 unsigned int *bytes_read
,
6697 unsigned int *offset_size
)
6699 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
6701 gdb_assert (cu_header
->initial_length_size
== 4
6702 || cu_header
->initial_length_size
== 8
6703 || cu_header
->initial_length_size
== 12);
6705 if (cu_header
->initial_length_size
!= *bytes_read
)
6706 complaint (&symfile_complaints
,
6707 _("intermixed 32-bit and 64-bit DWARF sections"));
6709 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
6713 /* Read an offset from the data stream. The size of the offset is
6714 given by cu_header->offset_size. */
6717 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
6718 unsigned int *bytes_read
)
6720 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
6721 *bytes_read
= cu_header
->offset_size
;
6725 /* Read an offset from the data stream. */
6728 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
6732 switch (offset_size
)
6735 retval
= bfd_get_32 (abfd
, buf
);
6738 retval
= bfd_get_64 (abfd
, buf
);
6741 internal_error (__FILE__
, __LINE__
,
6742 _("read_offset_1: bad switch [in module %s]"),
6743 bfd_get_filename (abfd
));
6750 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
6752 /* If the size of a host char is 8 bits, we can return a pointer
6753 to the buffer, otherwise we have to copy the data to a buffer
6754 allocated on the temporary obstack. */
6755 gdb_assert (HOST_CHAR_BIT
== 8);
6760 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6762 /* If the size of a host char is 8 bits, we can return a pointer
6763 to the string, otherwise we have to copy the string to a buffer
6764 allocated on the temporary obstack. */
6765 gdb_assert (HOST_CHAR_BIT
== 8);
6768 *bytes_read_ptr
= 1;
6771 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
6772 return (char *) buf
;
6776 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
6777 const struct comp_unit_head
*cu_header
,
6778 unsigned int *bytes_read_ptr
)
6780 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
6782 if (dwarf2_per_objfile
->str_buffer
== NULL
)
6784 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
6785 bfd_get_filename (abfd
));
6788 if (str_offset
>= dwarf2_per_objfile
->str_size
)
6790 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
6791 bfd_get_filename (abfd
));
6794 gdb_assert (HOST_CHAR_BIT
== 8);
6795 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
6797 return (char *) (dwarf2_per_objfile
->str_buffer
+ str_offset
);
6800 static unsigned long
6801 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6803 unsigned long result
;
6804 unsigned int num_read
;
6814 byte
= bfd_get_8 (abfd
, buf
);
6817 result
|= ((unsigned long)(byte
& 127) << shift
);
6818 if ((byte
& 128) == 0)
6824 *bytes_read_ptr
= num_read
;
6829 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6832 int i
, shift
, num_read
;
6841 byte
= bfd_get_8 (abfd
, buf
);
6844 result
|= ((long)(byte
& 127) << shift
);
6846 if ((byte
& 128) == 0)
6851 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
6852 result
|= -(((long)1) << shift
);
6853 *bytes_read_ptr
= num_read
;
6857 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6860 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
6866 byte
= bfd_get_8 (abfd
, buf
);
6868 if ((byte
& 128) == 0)
6874 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
6881 cu
->language
= language_c
;
6883 case DW_LANG_C_plus_plus
:
6884 cu
->language
= language_cplus
;
6886 case DW_LANG_Fortran77
:
6887 case DW_LANG_Fortran90
:
6888 case DW_LANG_Fortran95
:
6889 cu
->language
= language_fortran
;
6891 case DW_LANG_Mips_Assembler
:
6892 cu
->language
= language_asm
;
6895 cu
->language
= language_java
;
6899 cu
->language
= language_ada
;
6901 case DW_LANG_Modula2
:
6902 cu
->language
= language_m2
;
6904 case DW_LANG_Pascal83
:
6905 cu
->language
= language_pascal
;
6908 cu
->language
= language_objc
;
6910 case DW_LANG_Cobol74
:
6911 case DW_LANG_Cobol85
:
6913 cu
->language
= language_minimal
;
6916 cu
->language_defn
= language_def (cu
->language
);
6919 /* Return the named attribute or NULL if not there. */
6921 static struct attribute
*
6922 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
6925 struct attribute
*spec
= NULL
;
6927 for (i
= 0; i
< die
->num_attrs
; ++i
)
6929 if (die
->attrs
[i
].name
== name
)
6930 return &die
->attrs
[i
];
6931 if (die
->attrs
[i
].name
== DW_AT_specification
6932 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
6933 spec
= &die
->attrs
[i
];
6938 die
= follow_die_ref (die
, spec
, &cu
);
6939 return dwarf2_attr (die
, name
, cu
);
6945 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6946 and holds a non-zero value. This function should only be used for
6947 DW_FORM_flag attributes. */
6950 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
6952 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
6954 return (attr
&& DW_UNSND (attr
));
6958 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
6960 /* A DIE is a declaration if it has a DW_AT_declaration attribute
6961 which value is non-zero. However, we have to be careful with
6962 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
6963 (via dwarf2_flag_true_p) follows this attribute. So we may
6964 end up accidently finding a declaration attribute that belongs
6965 to a different DIE referenced by the specification attribute,
6966 even though the given DIE does not have a declaration attribute. */
6967 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
6968 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
6971 /* Return the die giving the specification for DIE, if there is
6972 one. *SPEC_CU is the CU containing DIE on input, and the CU
6973 containing the return value on output. */
6975 static struct die_info
*
6976 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
6978 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
6981 if (spec_attr
== NULL
)
6984 return follow_die_ref (die
, spec_attr
, spec_cu
);
6987 /* Free the line_header structure *LH, and any arrays and strings it
6990 free_line_header (struct line_header
*lh
)
6992 if (lh
->standard_opcode_lengths
)
6993 xfree (lh
->standard_opcode_lengths
);
6995 /* Remember that all the lh->file_names[i].name pointers are
6996 pointers into debug_line_buffer, and don't need to be freed. */
6998 xfree (lh
->file_names
);
7000 /* Similarly for the include directory names. */
7001 if (lh
->include_dirs
)
7002 xfree (lh
->include_dirs
);
7008 /* Add an entry to LH's include directory table. */
7010 add_include_dir (struct line_header
*lh
, char *include_dir
)
7012 /* Grow the array if necessary. */
7013 if (lh
->include_dirs_size
== 0)
7015 lh
->include_dirs_size
= 1; /* for testing */
7016 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
7017 * sizeof (*lh
->include_dirs
));
7019 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
7021 lh
->include_dirs_size
*= 2;
7022 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
7023 (lh
->include_dirs_size
7024 * sizeof (*lh
->include_dirs
)));
7027 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
7031 /* Add an entry to LH's file name table. */
7033 add_file_name (struct line_header
*lh
,
7035 unsigned int dir_index
,
7036 unsigned int mod_time
,
7037 unsigned int length
)
7039 struct file_entry
*fe
;
7041 /* Grow the array if necessary. */
7042 if (lh
->file_names_size
== 0)
7044 lh
->file_names_size
= 1; /* for testing */
7045 lh
->file_names
= xmalloc (lh
->file_names_size
7046 * sizeof (*lh
->file_names
));
7048 else if (lh
->num_file_names
>= lh
->file_names_size
)
7050 lh
->file_names_size
*= 2;
7051 lh
->file_names
= xrealloc (lh
->file_names
,
7052 (lh
->file_names_size
7053 * sizeof (*lh
->file_names
)));
7056 fe
= &lh
->file_names
[lh
->num_file_names
++];
7058 fe
->dir_index
= dir_index
;
7059 fe
->mod_time
= mod_time
;
7060 fe
->length
= length
;
7066 /* Read the statement program header starting at OFFSET in
7067 .debug_line, according to the endianness of ABFD. Return a pointer
7068 to a struct line_header, allocated using xmalloc.
7070 NOTE: the strings in the include directory and file name tables of
7071 the returned object point into debug_line_buffer, and must not be
7073 static struct line_header
*
7074 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
7075 struct dwarf2_cu
*cu
)
7077 struct cleanup
*back_to
;
7078 struct line_header
*lh
;
7080 unsigned int bytes_read
, offset_size
;
7082 char *cur_dir
, *cur_file
;
7084 if (dwarf2_per_objfile
->line_buffer
== NULL
)
7086 complaint (&symfile_complaints
, _("missing .debug_line section"));
7090 /* Make sure that at least there's room for the total_length field.
7091 That could be 12 bytes long, but we're just going to fudge that. */
7092 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
7094 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7098 lh
= xmalloc (sizeof (*lh
));
7099 memset (lh
, 0, sizeof (*lh
));
7100 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
7103 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
7105 /* Read in the header. */
7107 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
7108 &bytes_read
, &offset_size
);
7109 line_ptr
+= bytes_read
;
7110 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
7111 + dwarf2_per_objfile
->line_size
))
7113 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7116 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
7117 lh
->version
= read_2_bytes (abfd
, line_ptr
);
7119 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
7120 line_ptr
+= offset_size
;
7121 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
7123 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
7125 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
7127 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
7129 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
7131 lh
->standard_opcode_lengths
7132 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
7134 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
7135 for (i
= 1; i
< lh
->opcode_base
; ++i
)
7137 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
7141 /* Read directory table. */
7142 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7144 line_ptr
+= bytes_read
;
7145 add_include_dir (lh
, cur_dir
);
7147 line_ptr
+= bytes_read
;
7149 /* Read file name table. */
7150 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7152 unsigned int dir_index
, mod_time
, length
;
7154 line_ptr
+= bytes_read
;
7155 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7156 line_ptr
+= bytes_read
;
7157 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7158 line_ptr
+= bytes_read
;
7159 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7160 line_ptr
+= bytes_read
;
7162 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7164 line_ptr
+= bytes_read
;
7165 lh
->statement_program_start
= line_ptr
;
7167 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
7168 + dwarf2_per_objfile
->line_size
))
7169 complaint (&symfile_complaints
,
7170 _("line number info header doesn't fit in `.debug_line' section"));
7172 discard_cleanups (back_to
);
7176 /* This function exists to work around a bug in certain compilers
7177 (particularly GCC 2.95), in which the first line number marker of a
7178 function does not show up until after the prologue, right before
7179 the second line number marker. This function shifts ADDRESS down
7180 to the beginning of the function if necessary, and is called on
7181 addresses passed to record_line. */
7184 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
7186 struct function_range
*fn
;
7188 /* Find the function_range containing address. */
7193 cu
->cached_fn
= cu
->first_fn
;
7197 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7203 while (fn
&& fn
!= cu
->cached_fn
)
7204 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7214 if (address
!= fn
->lowpc
)
7215 complaint (&symfile_complaints
,
7216 _("misplaced first line number at 0x%lx for '%s'"),
7217 (unsigned long) address
, fn
->name
);
7222 /* Decode the Line Number Program (LNP) for the given line_header
7223 structure and CU. The actual information extracted and the type
7224 of structures created from the LNP depends on the value of PST.
7226 1. If PST is NULL, then this procedure uses the data from the program
7227 to create all necessary symbol tables, and their linetables.
7228 The compilation directory of the file is passed in COMP_DIR,
7229 and must not be NULL.
7231 2. If PST is not NULL, this procedure reads the program to determine
7232 the list of files included by the unit represented by PST, and
7233 builds all the associated partial symbol tables. In this case,
7234 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
7235 is not used to compute the full name of the symtab, and therefore
7236 omitting it when building the partial symtab does not introduce
7237 the potential for inconsistency - a partial symtab and its associated
7238 symbtab having a different fullname -). */
7241 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
7242 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
7244 gdb_byte
*line_ptr
, *extended_end
;
7246 unsigned int bytes_read
, extended_len
;
7247 unsigned char op_code
, extended_op
, adj_opcode
;
7249 struct objfile
*objfile
= cu
->objfile
;
7250 const int decode_for_pst_p
= (pst
!= NULL
);
7251 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
7253 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7255 line_ptr
= lh
->statement_program_start
;
7256 line_end
= lh
->statement_program_end
;
7258 /* Read the statement sequences until there's nothing left. */
7259 while (line_ptr
< line_end
)
7261 /* state machine registers */
7262 CORE_ADDR address
= 0;
7263 unsigned int file
= 1;
7264 unsigned int line
= 1;
7265 unsigned int column
= 0;
7266 int is_stmt
= lh
->default_is_stmt
;
7267 int basic_block
= 0;
7268 int end_sequence
= 0;
7270 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
7272 /* Start a subfile for the current file of the state machine. */
7273 /* lh->include_dirs and lh->file_names are 0-based, but the
7274 directory and file name numbers in the statement program
7276 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7280 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7282 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7285 /* Decode the table. */
7286 while (!end_sequence
)
7288 op_code
= read_1_byte (abfd
, line_ptr
);
7290 if (line_ptr
> line_end
)
7292 dwarf2_debug_line_missing_end_sequence_complaint ();
7296 if (op_code
>= lh
->opcode_base
)
7298 /* Special operand. */
7299 adj_opcode
= op_code
- lh
->opcode_base
;
7300 address
+= (adj_opcode
/ lh
->line_range
)
7301 * lh
->minimum_instruction_length
;
7302 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
7303 if (lh
->num_file_names
< file
|| file
== 0)
7304 dwarf2_debug_line_missing_file_complaint ();
7307 lh
->file_names
[file
- 1].included_p
= 1;
7308 if (!decode_for_pst_p
)
7310 if (last_subfile
!= current_subfile
)
7313 record_line (last_subfile
, 0, address
);
7314 last_subfile
= current_subfile
;
7316 /* Append row to matrix using current values. */
7317 record_line (current_subfile
, line
,
7318 check_cu_functions (address
, cu
));
7323 else switch (op_code
)
7325 case DW_LNS_extended_op
:
7326 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7327 line_ptr
+= bytes_read
;
7328 extended_end
= line_ptr
+ extended_len
;
7329 extended_op
= read_1_byte (abfd
, line_ptr
);
7331 switch (extended_op
)
7333 case DW_LNE_end_sequence
:
7336 case DW_LNE_set_address
:
7337 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
7338 line_ptr
+= bytes_read
;
7339 address
+= baseaddr
;
7341 case DW_LNE_define_file
:
7344 unsigned int dir_index
, mod_time
, length
;
7346 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
7347 line_ptr
+= bytes_read
;
7349 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7350 line_ptr
+= bytes_read
;
7352 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7353 line_ptr
+= bytes_read
;
7355 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7356 line_ptr
+= bytes_read
;
7357 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7360 case DW_LNE_set_discriminator
:
7361 /* The discriminator is not interesting to the debugger;
7363 line_ptr
= extended_end
;
7366 complaint (&symfile_complaints
,
7367 _("mangled .debug_line section"));
7370 /* Make sure that we parsed the extended op correctly. If e.g.
7371 we expected a different address size than the producer used,
7372 we may have read the wrong number of bytes. */
7373 if (line_ptr
!= extended_end
)
7375 complaint (&symfile_complaints
,
7376 _("mangled .debug_line section"));
7381 if (lh
->num_file_names
< file
|| file
== 0)
7382 dwarf2_debug_line_missing_file_complaint ();
7385 lh
->file_names
[file
- 1].included_p
= 1;
7386 if (!decode_for_pst_p
)
7388 if (last_subfile
!= current_subfile
)
7391 record_line (last_subfile
, 0, address
);
7392 last_subfile
= current_subfile
;
7394 record_line (current_subfile
, line
,
7395 check_cu_functions (address
, cu
));
7400 case DW_LNS_advance_pc
:
7401 address
+= lh
->minimum_instruction_length
7402 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7403 line_ptr
+= bytes_read
;
7405 case DW_LNS_advance_line
:
7406 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
7407 line_ptr
+= bytes_read
;
7409 case DW_LNS_set_file
:
7411 /* The arrays lh->include_dirs and lh->file_names are
7412 0-based, but the directory and file name numbers in
7413 the statement program are 1-based. */
7414 struct file_entry
*fe
;
7417 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7418 line_ptr
+= bytes_read
;
7419 if (lh
->num_file_names
< file
|| file
== 0)
7420 dwarf2_debug_line_missing_file_complaint ();
7423 fe
= &lh
->file_names
[file
- 1];
7425 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7426 if (!decode_for_pst_p
)
7428 last_subfile
= current_subfile
;
7429 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7434 case DW_LNS_set_column
:
7435 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7436 line_ptr
+= bytes_read
;
7438 case DW_LNS_negate_stmt
:
7439 is_stmt
= (!is_stmt
);
7441 case DW_LNS_set_basic_block
:
7444 /* Add to the address register of the state machine the
7445 address increment value corresponding to special opcode
7446 255. I.e., this value is scaled by the minimum
7447 instruction length since special opcode 255 would have
7448 scaled the the increment. */
7449 case DW_LNS_const_add_pc
:
7450 address
+= (lh
->minimum_instruction_length
7451 * ((255 - lh
->opcode_base
) / lh
->line_range
));
7453 case DW_LNS_fixed_advance_pc
:
7454 address
+= read_2_bytes (abfd
, line_ptr
);
7459 /* Unknown standard opcode, ignore it. */
7462 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
7464 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7465 line_ptr
+= bytes_read
;
7470 if (lh
->num_file_names
< file
|| file
== 0)
7471 dwarf2_debug_line_missing_file_complaint ();
7474 lh
->file_names
[file
- 1].included_p
= 1;
7475 if (!decode_for_pst_p
)
7476 record_line (current_subfile
, 0, address
);
7480 if (decode_for_pst_p
)
7484 /* Now that we're done scanning the Line Header Program, we can
7485 create the psymtab of each included file. */
7486 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
7487 if (lh
->file_names
[file_index
].included_p
== 1)
7489 const struct file_entry fe
= lh
->file_names
[file_index
];
7490 char *include_name
= fe
.name
;
7491 char *dir_name
= NULL
;
7492 char *pst_filename
= pst
->filename
;
7495 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
7497 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
7499 include_name
= concat (dir_name
, SLASH_STRING
,
7500 include_name
, (char *)NULL
);
7501 make_cleanup (xfree
, include_name
);
7504 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
7506 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
7507 pst_filename
, (char *)NULL
);
7508 make_cleanup (xfree
, pst_filename
);
7511 if (strcmp (include_name
, pst_filename
) != 0)
7512 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
7517 /* Make sure a symtab is created for every file, even files
7518 which contain only variables (i.e. no code with associated
7522 struct file_entry
*fe
;
7524 for (i
= 0; i
< lh
->num_file_names
; i
++)
7527 fe
= &lh
->file_names
[i
];
7529 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7530 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7532 /* Skip the main file; we don't need it, and it must be
7533 allocated last, so that it will show up before the
7534 non-primary symtabs in the objfile's symtab list. */
7535 if (current_subfile
== first_subfile
)
7538 if (current_subfile
->symtab
== NULL
)
7539 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7541 fe
->symtab
= current_subfile
->symtab
;
7546 /* Start a subfile for DWARF. FILENAME is the name of the file and
7547 DIRNAME the name of the source directory which contains FILENAME
7548 or NULL if not known. COMP_DIR is the compilation directory for the
7549 linetable's compilation unit or NULL if not known.
7550 This routine tries to keep line numbers from identical absolute and
7551 relative file names in a common subfile.
7553 Using the `list' example from the GDB testsuite, which resides in
7554 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
7555 of /srcdir/list0.c yields the following debugging information for list0.c:
7557 DW_AT_name: /srcdir/list0.c
7558 DW_AT_comp_dir: /compdir
7559 files.files[0].name: list0.h
7560 files.files[0].dir: /srcdir
7561 files.files[1].name: list0.c
7562 files.files[1].dir: /srcdir
7564 The line number information for list0.c has to end up in a single
7565 subfile, so that `break /srcdir/list0.c:1' works as expected.
7566 start_subfile will ensure that this happens provided that we pass the
7567 concatenation of files.files[1].dir and files.files[1].name as the
7571 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
7575 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
7576 `start_symtab' will always pass the contents of DW_AT_comp_dir as
7577 second argument to start_subfile. To be consistent, we do the
7578 same here. In order not to lose the line information directory,
7579 we concatenate it to the filename when it makes sense.
7580 Note that the Dwarf3 standard says (speaking of filenames in line
7581 information): ``The directory index is ignored for file names
7582 that represent full path names''. Thus ignoring dirname in the
7583 `else' branch below isn't an issue. */
7585 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
7586 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
7588 fullname
= filename
;
7590 start_subfile (fullname
, comp_dir
);
7592 if (fullname
!= filename
)
7597 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
7598 struct dwarf2_cu
*cu
)
7600 struct objfile
*objfile
= cu
->objfile
;
7601 struct comp_unit_head
*cu_header
= &cu
->header
;
7603 /* NOTE drow/2003-01-30: There used to be a comment and some special
7604 code here to turn a symbol with DW_AT_external and a
7605 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
7606 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
7607 with some versions of binutils) where shared libraries could have
7608 relocations against symbols in their debug information - the
7609 minimal symbol would have the right address, but the debug info
7610 would not. It's no longer necessary, because we will explicitly
7611 apply relocations when we read in the debug information now. */
7613 /* A DW_AT_location attribute with no contents indicates that a
7614 variable has been optimized away. */
7615 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
7617 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7621 /* Handle one degenerate form of location expression specially, to
7622 preserve GDB's previous behavior when section offsets are
7623 specified. If this is just a DW_OP_addr then mark this symbol
7626 if (attr_form_is_block (attr
)
7627 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
7628 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
7632 SYMBOL_VALUE_ADDRESS (sym
) =
7633 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
7634 SYMBOL_CLASS (sym
) = LOC_STATIC
;
7635 fixup_symbol_section (sym
, objfile
);
7636 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
7637 SYMBOL_SECTION (sym
));
7641 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
7642 expression evaluator, and use LOC_COMPUTED only when necessary
7643 (i.e. when the value of a register or memory location is
7644 referenced, or a thread-local block, etc.). Then again, it might
7645 not be worthwhile. I'm assuming that it isn't unless performance
7646 or memory numbers show me otherwise. */
7648 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
7649 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
7652 /* Given a pointer to a DWARF information entry, figure out if we need
7653 to make a symbol table entry for it, and if so, create a new entry
7654 and return a pointer to it.
7655 If TYPE is NULL, determine symbol type from the die, otherwise
7656 used the passed type. */
7658 static struct symbol
*
7659 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
7661 struct objfile
*objfile
= cu
->objfile
;
7662 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7663 struct symbol
*sym
= NULL
;
7665 struct attribute
*attr
= NULL
;
7666 struct attribute
*attr2
= NULL
;
7669 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7671 if (die
->tag
!= DW_TAG_namespace
)
7672 name
= dwarf2_linkage_name (die
, cu
);
7674 name
= TYPE_NAME (type
);
7678 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
7679 sizeof (struct symbol
));
7680 OBJSTAT (objfile
, n_syms
++);
7681 memset (sym
, 0, sizeof (struct symbol
));
7683 /* Cache this symbol's name and the name's demangled form (if any). */
7684 SYMBOL_LANGUAGE (sym
) = cu
->language
;
7685 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
7687 /* Default assumptions.
7688 Use the passed type or decode it from the die. */
7689 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7690 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7692 SYMBOL_TYPE (sym
) = type
;
7694 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
7695 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
7698 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
7701 attr
= dwarf2_attr (die
, DW_AT_decl_file
, cu
);
7704 int file_index
= DW_UNSND (attr
);
7705 if (cu
->line_header
== NULL
7706 || file_index
> cu
->line_header
->num_file_names
)
7707 complaint (&symfile_complaints
,
7708 _("file index out of range"));
7709 else if (file_index
> 0)
7711 struct file_entry
*fe
;
7712 fe
= &cu
->line_header
->file_names
[file_index
- 1];
7713 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
7720 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7723 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
7725 SYMBOL_CLASS (sym
) = LOC_LABEL
;
7727 case DW_TAG_subprogram
:
7728 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7730 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
7731 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7732 if ((attr2
&& (DW_UNSND (attr2
) != 0))
7733 || cu
->language
== language_ada
)
7735 /* Subprograms marked external are stored as a global symbol.
7736 Ada subprograms, whether marked external or not, are always
7737 stored as a global symbol, because we want to be able to
7738 access them globally. For instance, we want to be able
7739 to break on a nested subprogram without having to
7740 specify the context. */
7741 add_symbol_to_list (sym
, &global_symbols
);
7745 add_symbol_to_list (sym
, cu
->list_in_scope
);
7748 case DW_TAG_variable
:
7749 /* Compilation with minimal debug info may result in variables
7750 with missing type entries. Change the misleading `void' type
7751 to something sensible. */
7752 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
7754 = builtin_type (gdbarch
)->nodebug_data_symbol
;
7756 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7759 dwarf2_const_value (attr
, sym
, cu
);
7760 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7761 if (attr2
&& (DW_UNSND (attr2
) != 0))
7762 add_symbol_to_list (sym
, &global_symbols
);
7764 add_symbol_to_list (sym
, cu
->list_in_scope
);
7767 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7770 var_decode_location (attr
, sym
, cu
);
7771 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7772 if (attr2
&& (DW_UNSND (attr2
) != 0))
7773 add_symbol_to_list (sym
, &global_symbols
);
7775 add_symbol_to_list (sym
, cu
->list_in_scope
);
7779 /* We do not know the address of this symbol.
7780 If it is an external symbol and we have type information
7781 for it, enter the symbol as a LOC_UNRESOLVED symbol.
7782 The address of the variable will then be determined from
7783 the minimal symbol table whenever the variable is
7785 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7786 if (attr2
&& (DW_UNSND (attr2
) != 0)
7787 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
7789 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
7790 add_symbol_to_list (sym
, cu
->list_in_scope
);
7792 else if (!die_is_declaration (die
, cu
))
7794 /* Use the default LOC_OPTIMIZED_OUT class. */
7795 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
7796 add_symbol_to_list (sym
, cu
->list_in_scope
);
7800 case DW_TAG_formal_parameter
:
7801 SYMBOL_IS_ARGUMENT (sym
) = 1;
7802 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7805 var_decode_location (attr
, sym
, cu
);
7807 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7810 dwarf2_const_value (attr
, sym
, cu
);
7812 add_symbol_to_list (sym
, cu
->list_in_scope
);
7814 case DW_TAG_unspecified_parameters
:
7815 /* From varargs functions; gdb doesn't seem to have any
7816 interest in this information, so just ignore it for now.
7819 case DW_TAG_class_type
:
7820 case DW_TAG_interface_type
:
7821 case DW_TAG_structure_type
:
7822 case DW_TAG_union_type
:
7823 case DW_TAG_set_type
:
7824 case DW_TAG_enumeration_type
:
7825 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7826 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7828 /* Make sure that the symbol includes appropriate enclosing
7829 classes/namespaces in its name. These are calculated in
7830 read_structure_type, and the correct name is saved in
7833 if (cu
->language
== language_cplus
7834 || cu
->language
== language_java
)
7836 struct type
*type
= SYMBOL_TYPE (sym
);
7838 if (TYPE_TAG_NAME (type
) != NULL
)
7840 /* FIXME: carlton/2003-11-10: Should this use
7841 SYMBOL_SET_NAMES instead? (The same problem also
7842 arises further down in this function.) */
7843 /* The type's name is already allocated along with
7844 this objfile, so we don't need to duplicate it
7846 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
7851 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
7852 really ever be static objects: otherwise, if you try
7853 to, say, break of a class's method and you're in a file
7854 which doesn't mention that class, it won't work unless
7855 the check for all static symbols in lookup_symbol_aux
7856 saves you. See the OtherFileClass tests in
7857 gdb.c++/namespace.exp. */
7859 struct pending
**list_to_add
;
7861 list_to_add
= (cu
->list_in_scope
== &file_symbols
7862 && (cu
->language
== language_cplus
7863 || cu
->language
== language_java
)
7864 ? &global_symbols
: cu
->list_in_scope
);
7866 add_symbol_to_list (sym
, list_to_add
);
7868 /* The semantics of C++ state that "struct foo { ... }" also
7869 defines a typedef for "foo". A Java class declaration also
7870 defines a typedef for the class. */
7871 if (cu
->language
== language_cplus
7872 || cu
->language
== language_java
7873 || cu
->language
== language_ada
)
7875 /* The symbol's name is already allocated along with
7876 this objfile, so we don't need to duplicate it for
7878 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
7879 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
7883 case DW_TAG_typedef
:
7884 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7885 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7886 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7887 add_symbol_to_list (sym
, cu
->list_in_scope
);
7889 case DW_TAG_base_type
:
7890 case DW_TAG_subrange_type
:
7891 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7892 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7893 add_symbol_to_list (sym
, cu
->list_in_scope
);
7895 case DW_TAG_enumerator
:
7896 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7897 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7900 dwarf2_const_value (attr
, sym
, cu
);
7903 /* NOTE: carlton/2003-11-10: See comment above in the
7904 DW_TAG_class_type, etc. block. */
7906 struct pending
**list_to_add
;
7908 list_to_add
= (cu
->list_in_scope
== &file_symbols
7909 && (cu
->language
== language_cplus
7910 || cu
->language
== language_java
)
7911 ? &global_symbols
: cu
->list_in_scope
);
7913 add_symbol_to_list (sym
, list_to_add
);
7916 case DW_TAG_namespace
:
7917 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7918 add_symbol_to_list (sym
, &global_symbols
);
7921 /* Not a tag we recognize. Hopefully we aren't processing
7922 trash data, but since we must specifically ignore things
7923 we don't recognize, there is nothing else we should do at
7925 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
7926 dwarf_tag_name (die
->tag
));
7930 /* For the benefit of old versions of GCC, check for anonymous
7931 namespaces based on the demangled name. */
7932 if (!processing_has_namespace_info
7933 && cu
->language
== language_cplus
7934 && dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
) != NULL
)
7935 cp_scan_for_anonymous_namespaces (sym
);
7940 /* Copy constant value from an attribute to a symbol. */
7943 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
7944 struct dwarf2_cu
*cu
)
7946 struct objfile
*objfile
= cu
->objfile
;
7947 struct comp_unit_head
*cu_header
= &cu
->header
;
7948 struct dwarf_block
*blk
;
7953 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
7954 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7955 cu_header
->addr_size
,
7956 TYPE_LENGTH (SYMBOL_TYPE
7958 SYMBOL_VALUE_BYTES (sym
) =
7959 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
7960 /* NOTE: cagney/2003-05-09: In-lined store_address call with
7961 it's body - store_unsigned_integer. */
7962 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
7964 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7966 case DW_FORM_string
:
7968 /* DW_STRING is already allocated on the obstack, point directly
7970 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
7971 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7973 case DW_FORM_block1
:
7974 case DW_FORM_block2
:
7975 case DW_FORM_block4
:
7977 blk
= DW_BLOCK (attr
);
7978 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
7979 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7981 TYPE_LENGTH (SYMBOL_TYPE
7983 SYMBOL_VALUE_BYTES (sym
) =
7984 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
7985 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
7986 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7989 /* The DW_AT_const_value attributes are supposed to carry the
7990 symbol's value "represented as it would be on the target
7991 architecture." By the time we get here, it's already been
7992 converted to host endianness, so we just need to sign- or
7993 zero-extend it as appropriate. */
7995 dwarf2_const_value_data (attr
, sym
, 8);
7998 dwarf2_const_value_data (attr
, sym
, 16);
8001 dwarf2_const_value_data (attr
, sym
, 32);
8004 dwarf2_const_value_data (attr
, sym
, 64);
8008 SYMBOL_VALUE (sym
) = DW_SND (attr
);
8009 SYMBOL_CLASS (sym
) = LOC_CONST
;
8013 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
8014 SYMBOL_CLASS (sym
) = LOC_CONST
;
8018 complaint (&symfile_complaints
,
8019 _("unsupported const value attribute form: '%s'"),
8020 dwarf_form_name (attr
->form
));
8021 SYMBOL_VALUE (sym
) = 0;
8022 SYMBOL_CLASS (sym
) = LOC_CONST
;
8028 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
8029 or zero-extend it as appropriate for the symbol's type. */
8031 dwarf2_const_value_data (struct attribute
*attr
,
8035 LONGEST l
= DW_UNSND (attr
);
8037 if (bits
< sizeof (l
) * 8)
8039 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
8040 l
&= ((LONGEST
) 1 << bits
) - 1;
8042 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
8045 SYMBOL_VALUE (sym
) = l
;
8046 SYMBOL_CLASS (sym
) = LOC_CONST
;
8050 /* Return the type of the die in question using its DW_AT_type attribute. */
8052 static struct type
*
8053 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8055 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
8057 struct attribute
*type_attr
;
8058 struct die_info
*type_die
;
8060 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
8063 /* A missing DW_AT_type represents a void type. */
8064 return builtin_type (gdbarch
)->builtin_void
;
8067 type_die
= follow_die_ref (die
, type_attr
, &cu
);
8069 type
= tag_type_to_type (type_die
, cu
);
8072 dump_die_for_error (type_die
);
8073 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
8079 /* Return the containing type of the die in question using its
8080 DW_AT_containing_type attribute. */
8082 static struct type
*
8083 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8085 struct type
*type
= NULL
;
8086 struct attribute
*type_attr
;
8087 struct die_info
*type_die
= NULL
;
8089 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
8092 type_die
= follow_die_ref (die
, type_attr
, &cu
);
8093 type
= tag_type_to_type (type_die
, cu
);
8098 dump_die_for_error (type_die
);
8099 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
8105 static struct type
*
8106 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8108 struct type
*this_type
;
8110 this_type
= read_type_die (die
, cu
);
8113 dump_die_for_error (die
);
8114 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
8120 static struct type
*
8121 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8123 struct type
*this_type
;
8125 this_type
= get_die_type (die
, cu
);
8131 case DW_TAG_class_type
:
8132 case DW_TAG_interface_type
:
8133 case DW_TAG_structure_type
:
8134 case DW_TAG_union_type
:
8135 this_type
= read_structure_type (die
, cu
);
8137 case DW_TAG_enumeration_type
:
8138 this_type
= read_enumeration_type (die
, cu
);
8140 case DW_TAG_subprogram
:
8141 case DW_TAG_subroutine_type
:
8142 this_type
= read_subroutine_type (die
, cu
);
8144 case DW_TAG_array_type
:
8145 this_type
= read_array_type (die
, cu
);
8147 case DW_TAG_set_type
:
8148 this_type
= read_set_type (die
, cu
);
8150 case DW_TAG_pointer_type
:
8151 this_type
= read_tag_pointer_type (die
, cu
);
8153 case DW_TAG_ptr_to_member_type
:
8154 this_type
= read_tag_ptr_to_member_type (die
, cu
);
8156 case DW_TAG_reference_type
:
8157 this_type
= read_tag_reference_type (die
, cu
);
8159 case DW_TAG_const_type
:
8160 this_type
= read_tag_const_type (die
, cu
);
8162 case DW_TAG_volatile_type
:
8163 this_type
= read_tag_volatile_type (die
, cu
);
8165 case DW_TAG_string_type
:
8166 this_type
= read_tag_string_type (die
, cu
);
8168 case DW_TAG_typedef
:
8169 this_type
= read_typedef (die
, cu
);
8171 case DW_TAG_subrange_type
:
8172 this_type
= read_subrange_type (die
, cu
);
8174 case DW_TAG_base_type
:
8175 this_type
= read_base_type (die
, cu
);
8177 case DW_TAG_unspecified_type
:
8178 this_type
= read_unspecified_type (die
, cu
);
8180 case DW_TAG_namespace
:
8181 this_type
= read_namespace_type (die
, cu
);
8184 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
8185 dwarf_tag_name (die
->tag
));
8192 /* Return the name of the namespace/class that DIE is defined within,
8193 or "" if we can't tell. The caller should not xfree the result.
8195 For example, if we're within the method foo() in the following
8205 then determine_prefix on foo's die will return "N::C". */
8208 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
8210 struct die_info
*parent
, *spec_die
;
8211 struct dwarf2_cu
*spec_cu
;
8212 struct type
*parent_type
;
8214 if (cu
->language
!= language_cplus
8215 && cu
->language
!= language_java
)
8218 /* We have to be careful in the presence of DW_AT_specification.
8219 For example, with GCC 3.4, given the code
8223 // Definition of N::foo.
8227 then we'll have a tree of DIEs like this:
8229 1: DW_TAG_compile_unit
8230 2: DW_TAG_namespace // N
8231 3: DW_TAG_subprogram // declaration of N::foo
8232 4: DW_TAG_subprogram // definition of N::foo
8233 DW_AT_specification // refers to die #3
8235 Thus, when processing die #4, we have to pretend that we're in
8236 the context of its DW_AT_specification, namely the contex of die
8239 spec_die
= die_specification (die
, &spec_cu
);
8240 if (spec_die
== NULL
)
8241 parent
= die
->parent
;
8244 parent
= spec_die
->parent
;
8251 switch (parent
->tag
)
8253 case DW_TAG_namespace
:
8254 parent_type
= read_type_die (parent
, cu
);
8255 /* We give a name to even anonymous namespaces. */
8256 return TYPE_TAG_NAME (parent_type
);
8257 case DW_TAG_class_type
:
8258 case DW_TAG_interface_type
:
8259 case DW_TAG_structure_type
:
8260 case DW_TAG_union_type
:
8261 parent_type
= read_type_die (parent
, cu
);
8262 if (TYPE_TAG_NAME (parent_type
) != NULL
)
8263 return TYPE_TAG_NAME (parent_type
);
8265 /* An anonymous structure is only allowed non-static data
8266 members; no typedefs, no member functions, et cetera.
8267 So it does not need a prefix. */
8270 return determine_prefix (parent
, cu
);
8274 /* Return a newly-allocated string formed by concatenating PREFIX and
8275 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
8276 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
8277 perform an obconcat, otherwise allocate storage for the result. The CU argument
8278 is used to determine the language and hence, the appropriate separator. */
8280 #define MAX_SEP_LEN 2 /* sizeof ("::") */
8283 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
8284 struct dwarf2_cu
*cu
)
8288 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
8290 else if (cu
->language
== language_java
)
8302 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
8303 strcpy (retval
, prefix
);
8304 strcat (retval
, sep
);
8305 strcat (retval
, suffix
);
8310 /* We have an obstack. */
8311 return obconcat (obs
, prefix
, sep
, suffix
);
8315 /* Return sibling of die, NULL if no sibling. */
8317 static struct die_info
*
8318 sibling_die (struct die_info
*die
)
8320 return die
->sibling
;
8323 /* Get linkage name of a die, return NULL if not found. */
8326 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8328 struct attribute
*attr
;
8330 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8331 if (attr
&& DW_STRING (attr
))
8332 return DW_STRING (attr
);
8333 return dwarf2_name (die
, cu
);
8336 /* Get name of a die, return NULL if not found. */
8339 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
8340 struct obstack
*obstack
)
8342 if (name
&& cu
->language
== language_cplus
)
8344 char *canon_name
= cp_canonicalize_string (name
);
8346 if (canon_name
!= NULL
)
8348 if (strcmp (canon_name
, name
) != 0)
8349 name
= obsavestring (canon_name
, strlen (canon_name
),
8358 /* Get name of a die, return NULL if not found. */
8361 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8363 struct attribute
*attr
;
8365 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8366 if (!attr
|| !DW_STRING (attr
))
8371 case DW_TAG_compile_unit
:
8372 /* Compilation units have a DW_AT_name that is a filename, not
8373 a source language identifier. */
8374 case DW_TAG_enumeration_type
:
8375 case DW_TAG_enumerator
:
8376 /* These tags always have simple identifiers already; no need
8377 to canonicalize them. */
8378 return DW_STRING (attr
);
8380 if (attr
->form
!= GDB_FORM_cached_string
)
8383 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
8384 &cu
->objfile
->objfile_obstack
);
8385 attr
->form
= GDB_FORM_cached_string
;
8387 return DW_STRING (attr
);
8391 /* Return the die that this die in an extension of, or NULL if there
8392 is none. *EXT_CU is the CU containing DIE on input, and the CU
8393 containing the return value on output. */
8395 static struct die_info
*
8396 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
8398 struct attribute
*attr
;
8400 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
8404 return follow_die_ref (die
, attr
, ext_cu
);
8407 /* Convert a DIE tag into its string name. */
8410 dwarf_tag_name (unsigned tag
)
8414 case DW_TAG_padding
:
8415 return "DW_TAG_padding";
8416 case DW_TAG_array_type
:
8417 return "DW_TAG_array_type";
8418 case DW_TAG_class_type
:
8419 return "DW_TAG_class_type";
8420 case DW_TAG_entry_point
:
8421 return "DW_TAG_entry_point";
8422 case DW_TAG_enumeration_type
:
8423 return "DW_TAG_enumeration_type";
8424 case DW_TAG_formal_parameter
:
8425 return "DW_TAG_formal_parameter";
8426 case DW_TAG_imported_declaration
:
8427 return "DW_TAG_imported_declaration";
8429 return "DW_TAG_label";
8430 case DW_TAG_lexical_block
:
8431 return "DW_TAG_lexical_block";
8433 return "DW_TAG_member";
8434 case DW_TAG_pointer_type
:
8435 return "DW_TAG_pointer_type";
8436 case DW_TAG_reference_type
:
8437 return "DW_TAG_reference_type";
8438 case DW_TAG_compile_unit
:
8439 return "DW_TAG_compile_unit";
8440 case DW_TAG_string_type
:
8441 return "DW_TAG_string_type";
8442 case DW_TAG_structure_type
:
8443 return "DW_TAG_structure_type";
8444 case DW_TAG_subroutine_type
:
8445 return "DW_TAG_subroutine_type";
8446 case DW_TAG_typedef
:
8447 return "DW_TAG_typedef";
8448 case DW_TAG_union_type
:
8449 return "DW_TAG_union_type";
8450 case DW_TAG_unspecified_parameters
:
8451 return "DW_TAG_unspecified_parameters";
8452 case DW_TAG_variant
:
8453 return "DW_TAG_variant";
8454 case DW_TAG_common_block
:
8455 return "DW_TAG_common_block";
8456 case DW_TAG_common_inclusion
:
8457 return "DW_TAG_common_inclusion";
8458 case DW_TAG_inheritance
:
8459 return "DW_TAG_inheritance";
8460 case DW_TAG_inlined_subroutine
:
8461 return "DW_TAG_inlined_subroutine";
8463 return "DW_TAG_module";
8464 case DW_TAG_ptr_to_member_type
:
8465 return "DW_TAG_ptr_to_member_type";
8466 case DW_TAG_set_type
:
8467 return "DW_TAG_set_type";
8468 case DW_TAG_subrange_type
:
8469 return "DW_TAG_subrange_type";
8470 case DW_TAG_with_stmt
:
8471 return "DW_TAG_with_stmt";
8472 case DW_TAG_access_declaration
:
8473 return "DW_TAG_access_declaration";
8474 case DW_TAG_base_type
:
8475 return "DW_TAG_base_type";
8476 case DW_TAG_catch_block
:
8477 return "DW_TAG_catch_block";
8478 case DW_TAG_const_type
:
8479 return "DW_TAG_const_type";
8480 case DW_TAG_constant
:
8481 return "DW_TAG_constant";
8482 case DW_TAG_enumerator
:
8483 return "DW_TAG_enumerator";
8484 case DW_TAG_file_type
:
8485 return "DW_TAG_file_type";
8487 return "DW_TAG_friend";
8488 case DW_TAG_namelist
:
8489 return "DW_TAG_namelist";
8490 case DW_TAG_namelist_item
:
8491 return "DW_TAG_namelist_item";
8492 case DW_TAG_packed_type
:
8493 return "DW_TAG_packed_type";
8494 case DW_TAG_subprogram
:
8495 return "DW_TAG_subprogram";
8496 case DW_TAG_template_type_param
:
8497 return "DW_TAG_template_type_param";
8498 case DW_TAG_template_value_param
:
8499 return "DW_TAG_template_value_param";
8500 case DW_TAG_thrown_type
:
8501 return "DW_TAG_thrown_type";
8502 case DW_TAG_try_block
:
8503 return "DW_TAG_try_block";
8504 case DW_TAG_variant_part
:
8505 return "DW_TAG_variant_part";
8506 case DW_TAG_variable
:
8507 return "DW_TAG_variable";
8508 case DW_TAG_volatile_type
:
8509 return "DW_TAG_volatile_type";
8510 case DW_TAG_dwarf_procedure
:
8511 return "DW_TAG_dwarf_procedure";
8512 case DW_TAG_restrict_type
:
8513 return "DW_TAG_restrict_type";
8514 case DW_TAG_interface_type
:
8515 return "DW_TAG_interface_type";
8516 case DW_TAG_namespace
:
8517 return "DW_TAG_namespace";
8518 case DW_TAG_imported_module
:
8519 return "DW_TAG_imported_module";
8520 case DW_TAG_unspecified_type
:
8521 return "DW_TAG_unspecified_type";
8522 case DW_TAG_partial_unit
:
8523 return "DW_TAG_partial_unit";
8524 case DW_TAG_imported_unit
:
8525 return "DW_TAG_imported_unit";
8526 case DW_TAG_condition
:
8527 return "DW_TAG_condition";
8528 case DW_TAG_shared_type
:
8529 return "DW_TAG_shared_type";
8530 case DW_TAG_MIPS_loop
:
8531 return "DW_TAG_MIPS_loop";
8532 case DW_TAG_HP_array_descriptor
:
8533 return "DW_TAG_HP_array_descriptor";
8534 case DW_TAG_format_label
:
8535 return "DW_TAG_format_label";
8536 case DW_TAG_function_template
:
8537 return "DW_TAG_function_template";
8538 case DW_TAG_class_template
:
8539 return "DW_TAG_class_template";
8540 case DW_TAG_GNU_BINCL
:
8541 return "DW_TAG_GNU_BINCL";
8542 case DW_TAG_GNU_EINCL
:
8543 return "DW_TAG_GNU_EINCL";
8544 case DW_TAG_upc_shared_type
:
8545 return "DW_TAG_upc_shared_type";
8546 case DW_TAG_upc_strict_type
:
8547 return "DW_TAG_upc_strict_type";
8548 case DW_TAG_upc_relaxed_type
:
8549 return "DW_TAG_upc_relaxed_type";
8550 case DW_TAG_PGI_kanji_type
:
8551 return "DW_TAG_PGI_kanji_type";
8552 case DW_TAG_PGI_interface_block
:
8553 return "DW_TAG_PGI_interface_block";
8555 return "DW_TAG_<unknown>";
8559 /* Convert a DWARF attribute code into its string name. */
8562 dwarf_attr_name (unsigned attr
)
8567 return "DW_AT_sibling";
8568 case DW_AT_location
:
8569 return "DW_AT_location";
8571 return "DW_AT_name";
8572 case DW_AT_ordering
:
8573 return "DW_AT_ordering";
8574 case DW_AT_subscr_data
:
8575 return "DW_AT_subscr_data";
8576 case DW_AT_byte_size
:
8577 return "DW_AT_byte_size";
8578 case DW_AT_bit_offset
:
8579 return "DW_AT_bit_offset";
8580 case DW_AT_bit_size
:
8581 return "DW_AT_bit_size";
8582 case DW_AT_element_list
:
8583 return "DW_AT_element_list";
8584 case DW_AT_stmt_list
:
8585 return "DW_AT_stmt_list";
8587 return "DW_AT_low_pc";
8589 return "DW_AT_high_pc";
8590 case DW_AT_language
:
8591 return "DW_AT_language";
8593 return "DW_AT_member";
8595 return "DW_AT_discr";
8596 case DW_AT_discr_value
:
8597 return "DW_AT_discr_value";
8598 case DW_AT_visibility
:
8599 return "DW_AT_visibility";
8601 return "DW_AT_import";
8602 case DW_AT_string_length
:
8603 return "DW_AT_string_length";
8604 case DW_AT_common_reference
:
8605 return "DW_AT_common_reference";
8606 case DW_AT_comp_dir
:
8607 return "DW_AT_comp_dir";
8608 case DW_AT_const_value
:
8609 return "DW_AT_const_value";
8610 case DW_AT_containing_type
:
8611 return "DW_AT_containing_type";
8612 case DW_AT_default_value
:
8613 return "DW_AT_default_value";
8615 return "DW_AT_inline";
8616 case DW_AT_is_optional
:
8617 return "DW_AT_is_optional";
8618 case DW_AT_lower_bound
:
8619 return "DW_AT_lower_bound";
8620 case DW_AT_producer
:
8621 return "DW_AT_producer";
8622 case DW_AT_prototyped
:
8623 return "DW_AT_prototyped";
8624 case DW_AT_return_addr
:
8625 return "DW_AT_return_addr";
8626 case DW_AT_start_scope
:
8627 return "DW_AT_start_scope";
8628 case DW_AT_bit_stride
:
8629 return "DW_AT_bit_stride";
8630 case DW_AT_upper_bound
:
8631 return "DW_AT_upper_bound";
8632 case DW_AT_abstract_origin
:
8633 return "DW_AT_abstract_origin";
8634 case DW_AT_accessibility
:
8635 return "DW_AT_accessibility";
8636 case DW_AT_address_class
:
8637 return "DW_AT_address_class";
8638 case DW_AT_artificial
:
8639 return "DW_AT_artificial";
8640 case DW_AT_base_types
:
8641 return "DW_AT_base_types";
8642 case DW_AT_calling_convention
:
8643 return "DW_AT_calling_convention";
8645 return "DW_AT_count";
8646 case DW_AT_data_member_location
:
8647 return "DW_AT_data_member_location";
8648 case DW_AT_decl_column
:
8649 return "DW_AT_decl_column";
8650 case DW_AT_decl_file
:
8651 return "DW_AT_decl_file";
8652 case DW_AT_decl_line
:
8653 return "DW_AT_decl_line";
8654 case DW_AT_declaration
:
8655 return "DW_AT_declaration";
8656 case DW_AT_discr_list
:
8657 return "DW_AT_discr_list";
8658 case DW_AT_encoding
:
8659 return "DW_AT_encoding";
8660 case DW_AT_external
:
8661 return "DW_AT_external";
8662 case DW_AT_frame_base
:
8663 return "DW_AT_frame_base";
8665 return "DW_AT_friend";
8666 case DW_AT_identifier_case
:
8667 return "DW_AT_identifier_case";
8668 case DW_AT_macro_info
:
8669 return "DW_AT_macro_info";
8670 case DW_AT_namelist_items
:
8671 return "DW_AT_namelist_items";
8672 case DW_AT_priority
:
8673 return "DW_AT_priority";
8675 return "DW_AT_segment";
8676 case DW_AT_specification
:
8677 return "DW_AT_specification";
8678 case DW_AT_static_link
:
8679 return "DW_AT_static_link";
8681 return "DW_AT_type";
8682 case DW_AT_use_location
:
8683 return "DW_AT_use_location";
8684 case DW_AT_variable_parameter
:
8685 return "DW_AT_variable_parameter";
8686 case DW_AT_virtuality
:
8687 return "DW_AT_virtuality";
8688 case DW_AT_vtable_elem_location
:
8689 return "DW_AT_vtable_elem_location";
8690 /* DWARF 3 values. */
8691 case DW_AT_allocated
:
8692 return "DW_AT_allocated";
8693 case DW_AT_associated
:
8694 return "DW_AT_associated";
8695 case DW_AT_data_location
:
8696 return "DW_AT_data_location";
8697 case DW_AT_byte_stride
:
8698 return "DW_AT_byte_stride";
8699 case DW_AT_entry_pc
:
8700 return "DW_AT_entry_pc";
8701 case DW_AT_use_UTF8
:
8702 return "DW_AT_use_UTF8";
8703 case DW_AT_extension
:
8704 return "DW_AT_extension";
8706 return "DW_AT_ranges";
8707 case DW_AT_trampoline
:
8708 return "DW_AT_trampoline";
8709 case DW_AT_call_column
:
8710 return "DW_AT_call_column";
8711 case DW_AT_call_file
:
8712 return "DW_AT_call_file";
8713 case DW_AT_call_line
:
8714 return "DW_AT_call_line";
8715 case DW_AT_description
:
8716 return "DW_AT_description";
8717 case DW_AT_binary_scale
:
8718 return "DW_AT_binary_scale";
8719 case DW_AT_decimal_scale
:
8720 return "DW_AT_decimal_scale";
8722 return "DW_AT_small";
8723 case DW_AT_decimal_sign
:
8724 return "DW_AT_decimal_sign";
8725 case DW_AT_digit_count
:
8726 return "DW_AT_digit_count";
8727 case DW_AT_picture_string
:
8728 return "DW_AT_picture_string";
8730 return "DW_AT_mutable";
8731 case DW_AT_threads_scaled
:
8732 return "DW_AT_threads_scaled";
8733 case DW_AT_explicit
:
8734 return "DW_AT_explicit";
8735 case DW_AT_object_pointer
:
8736 return "DW_AT_object_pointer";
8737 case DW_AT_endianity
:
8738 return "DW_AT_endianity";
8739 case DW_AT_elemental
:
8740 return "DW_AT_elemental";
8742 return "DW_AT_pure";
8743 case DW_AT_recursive
:
8744 return "DW_AT_recursive";
8745 /* SGI/MIPS extensions. */
8746 #ifdef MIPS /* collides with DW_AT_HP_block_index */
8747 case DW_AT_MIPS_fde
:
8748 return "DW_AT_MIPS_fde";
8750 case DW_AT_MIPS_loop_begin
:
8751 return "DW_AT_MIPS_loop_begin";
8752 case DW_AT_MIPS_tail_loop_begin
:
8753 return "DW_AT_MIPS_tail_loop_begin";
8754 case DW_AT_MIPS_epilog_begin
:
8755 return "DW_AT_MIPS_epilog_begin";
8756 case DW_AT_MIPS_loop_unroll_factor
:
8757 return "DW_AT_MIPS_loop_unroll_factor";
8758 case DW_AT_MIPS_software_pipeline_depth
:
8759 return "DW_AT_MIPS_software_pipeline_depth";
8760 case DW_AT_MIPS_linkage_name
:
8761 return "DW_AT_MIPS_linkage_name";
8762 case DW_AT_MIPS_stride
:
8763 return "DW_AT_MIPS_stride";
8764 case DW_AT_MIPS_abstract_name
:
8765 return "DW_AT_MIPS_abstract_name";
8766 case DW_AT_MIPS_clone_origin
:
8767 return "DW_AT_MIPS_clone_origin";
8768 case DW_AT_MIPS_has_inlines
:
8769 return "DW_AT_MIPS_has_inlines";
8770 /* HP extensions. */
8771 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
8772 case DW_AT_HP_block_index
:
8773 return "DW_AT_HP_block_index";
8775 case DW_AT_HP_unmodifiable
:
8776 return "DW_AT_HP_unmodifiable";
8777 case DW_AT_HP_actuals_stmt_list
:
8778 return "DW_AT_HP_actuals_stmt_list";
8779 case DW_AT_HP_proc_per_section
:
8780 return "DW_AT_HP_proc_per_section";
8781 case DW_AT_HP_raw_data_ptr
:
8782 return "DW_AT_HP_raw_data_ptr";
8783 case DW_AT_HP_pass_by_reference
:
8784 return "DW_AT_HP_pass_by_reference";
8785 case DW_AT_HP_opt_level
:
8786 return "DW_AT_HP_opt_level";
8787 case DW_AT_HP_prof_version_id
:
8788 return "DW_AT_HP_prof_version_id";
8789 case DW_AT_HP_opt_flags
:
8790 return "DW_AT_HP_opt_flags";
8791 case DW_AT_HP_cold_region_low_pc
:
8792 return "DW_AT_HP_cold_region_low_pc";
8793 case DW_AT_HP_cold_region_high_pc
:
8794 return "DW_AT_HP_cold_region_high_pc";
8795 case DW_AT_HP_all_variables_modifiable
:
8796 return "DW_AT_HP_all_variables_modifiable";
8797 case DW_AT_HP_linkage_name
:
8798 return "DW_AT_HP_linkage_name";
8799 case DW_AT_HP_prof_flags
:
8800 return "DW_AT_HP_prof_flags";
8801 /* GNU extensions. */
8802 case DW_AT_sf_names
:
8803 return "DW_AT_sf_names";
8804 case DW_AT_src_info
:
8805 return "DW_AT_src_info";
8806 case DW_AT_mac_info
:
8807 return "DW_AT_mac_info";
8808 case DW_AT_src_coords
:
8809 return "DW_AT_src_coords";
8810 case DW_AT_body_begin
:
8811 return "DW_AT_body_begin";
8812 case DW_AT_body_end
:
8813 return "DW_AT_body_end";
8814 case DW_AT_GNU_vector
:
8815 return "DW_AT_GNU_vector";
8816 /* VMS extensions. */
8817 case DW_AT_VMS_rtnbeg_pd_address
:
8818 return "DW_AT_VMS_rtnbeg_pd_address";
8819 /* UPC extension. */
8820 case DW_AT_upc_threads_scaled
:
8821 return "DW_AT_upc_threads_scaled";
8822 /* PGI (STMicroelectronics) extensions. */
8823 case DW_AT_PGI_lbase
:
8824 return "DW_AT_PGI_lbase";
8825 case DW_AT_PGI_soffset
:
8826 return "DW_AT_PGI_soffset";
8827 case DW_AT_PGI_lstride
:
8828 return "DW_AT_PGI_lstride";
8830 return "DW_AT_<unknown>";
8834 /* Convert a DWARF value form code into its string name. */
8837 dwarf_form_name (unsigned form
)
8842 return "DW_FORM_addr";
8843 case DW_FORM_block2
:
8844 return "DW_FORM_block2";
8845 case DW_FORM_block4
:
8846 return "DW_FORM_block4";
8848 return "DW_FORM_data2";
8850 return "DW_FORM_data4";
8852 return "DW_FORM_data8";
8853 case DW_FORM_string
:
8854 return "DW_FORM_string";
8856 return "DW_FORM_block";
8857 case DW_FORM_block1
:
8858 return "DW_FORM_block1";
8860 return "DW_FORM_data1";
8862 return "DW_FORM_flag";
8864 return "DW_FORM_sdata";
8866 return "DW_FORM_strp";
8868 return "DW_FORM_udata";
8869 case DW_FORM_ref_addr
:
8870 return "DW_FORM_ref_addr";
8872 return "DW_FORM_ref1";
8874 return "DW_FORM_ref2";
8876 return "DW_FORM_ref4";
8878 return "DW_FORM_ref8";
8879 case DW_FORM_ref_udata
:
8880 return "DW_FORM_ref_udata";
8881 case DW_FORM_indirect
:
8882 return "DW_FORM_indirect";
8883 case GDB_FORM_cached_string
:
8884 return "GDB_FORM_cached_string";
8886 return "DW_FORM_<unknown>";
8890 /* Convert a DWARF stack opcode into its string name. */
8893 dwarf_stack_op_name (unsigned op
)
8898 return "DW_OP_addr";
8900 return "DW_OP_deref";
8902 return "DW_OP_const1u";
8904 return "DW_OP_const1s";
8906 return "DW_OP_const2u";
8908 return "DW_OP_const2s";
8910 return "DW_OP_const4u";
8912 return "DW_OP_const4s";
8914 return "DW_OP_const8u";
8916 return "DW_OP_const8s";
8918 return "DW_OP_constu";
8920 return "DW_OP_consts";
8924 return "DW_OP_drop";
8926 return "DW_OP_over";
8928 return "DW_OP_pick";
8930 return "DW_OP_swap";
8934 return "DW_OP_xderef";
8942 return "DW_OP_minus";
8954 return "DW_OP_plus";
8955 case DW_OP_plus_uconst
:
8956 return "DW_OP_plus_uconst";
8962 return "DW_OP_shra";
8980 return "DW_OP_skip";
8982 return "DW_OP_lit0";
8984 return "DW_OP_lit1";
8986 return "DW_OP_lit2";
8988 return "DW_OP_lit3";
8990 return "DW_OP_lit4";
8992 return "DW_OP_lit5";
8994 return "DW_OP_lit6";
8996 return "DW_OP_lit7";
8998 return "DW_OP_lit8";
9000 return "DW_OP_lit9";
9002 return "DW_OP_lit10";
9004 return "DW_OP_lit11";
9006 return "DW_OP_lit12";
9008 return "DW_OP_lit13";
9010 return "DW_OP_lit14";
9012 return "DW_OP_lit15";
9014 return "DW_OP_lit16";
9016 return "DW_OP_lit17";
9018 return "DW_OP_lit18";
9020 return "DW_OP_lit19";
9022 return "DW_OP_lit20";
9024 return "DW_OP_lit21";
9026 return "DW_OP_lit22";
9028 return "DW_OP_lit23";
9030 return "DW_OP_lit24";
9032 return "DW_OP_lit25";
9034 return "DW_OP_lit26";
9036 return "DW_OP_lit27";
9038 return "DW_OP_lit28";
9040 return "DW_OP_lit29";
9042 return "DW_OP_lit30";
9044 return "DW_OP_lit31";
9046 return "DW_OP_reg0";
9048 return "DW_OP_reg1";
9050 return "DW_OP_reg2";
9052 return "DW_OP_reg3";
9054 return "DW_OP_reg4";
9056 return "DW_OP_reg5";
9058 return "DW_OP_reg6";
9060 return "DW_OP_reg7";
9062 return "DW_OP_reg8";
9064 return "DW_OP_reg9";
9066 return "DW_OP_reg10";
9068 return "DW_OP_reg11";
9070 return "DW_OP_reg12";
9072 return "DW_OP_reg13";
9074 return "DW_OP_reg14";
9076 return "DW_OP_reg15";
9078 return "DW_OP_reg16";
9080 return "DW_OP_reg17";
9082 return "DW_OP_reg18";
9084 return "DW_OP_reg19";
9086 return "DW_OP_reg20";
9088 return "DW_OP_reg21";
9090 return "DW_OP_reg22";
9092 return "DW_OP_reg23";
9094 return "DW_OP_reg24";
9096 return "DW_OP_reg25";
9098 return "DW_OP_reg26";
9100 return "DW_OP_reg27";
9102 return "DW_OP_reg28";
9104 return "DW_OP_reg29";
9106 return "DW_OP_reg30";
9108 return "DW_OP_reg31";
9110 return "DW_OP_breg0";
9112 return "DW_OP_breg1";
9114 return "DW_OP_breg2";
9116 return "DW_OP_breg3";
9118 return "DW_OP_breg4";
9120 return "DW_OP_breg5";
9122 return "DW_OP_breg6";
9124 return "DW_OP_breg7";
9126 return "DW_OP_breg8";
9128 return "DW_OP_breg9";
9130 return "DW_OP_breg10";
9132 return "DW_OP_breg11";
9134 return "DW_OP_breg12";
9136 return "DW_OP_breg13";
9138 return "DW_OP_breg14";
9140 return "DW_OP_breg15";
9142 return "DW_OP_breg16";
9144 return "DW_OP_breg17";
9146 return "DW_OP_breg18";
9148 return "DW_OP_breg19";
9150 return "DW_OP_breg20";
9152 return "DW_OP_breg21";
9154 return "DW_OP_breg22";
9156 return "DW_OP_breg23";
9158 return "DW_OP_breg24";
9160 return "DW_OP_breg25";
9162 return "DW_OP_breg26";
9164 return "DW_OP_breg27";
9166 return "DW_OP_breg28";
9168 return "DW_OP_breg29";
9170 return "DW_OP_breg30";
9172 return "DW_OP_breg31";
9174 return "DW_OP_regx";
9176 return "DW_OP_fbreg";
9178 return "DW_OP_bregx";
9180 return "DW_OP_piece";
9181 case DW_OP_deref_size
:
9182 return "DW_OP_deref_size";
9183 case DW_OP_xderef_size
:
9184 return "DW_OP_xderef_size";
9187 /* DWARF 3 extensions. */
9188 case DW_OP_push_object_address
:
9189 return "DW_OP_push_object_address";
9191 return "DW_OP_call2";
9193 return "DW_OP_call4";
9194 case DW_OP_call_ref
:
9195 return "DW_OP_call_ref";
9196 /* GNU extensions. */
9197 case DW_OP_form_tls_address
:
9198 return "DW_OP_form_tls_address";
9199 case DW_OP_call_frame_cfa
:
9200 return "DW_OP_call_frame_cfa";
9201 case DW_OP_bit_piece
:
9202 return "DW_OP_bit_piece";
9203 case DW_OP_GNU_push_tls_address
:
9204 return "DW_OP_GNU_push_tls_address";
9205 case DW_OP_GNU_uninit
:
9206 return "DW_OP_GNU_uninit";
9207 /* HP extensions. */
9208 case DW_OP_HP_is_value
:
9209 return "DW_OP_HP_is_value";
9210 case DW_OP_HP_fltconst4
:
9211 return "DW_OP_HP_fltconst4";
9212 case DW_OP_HP_fltconst8
:
9213 return "DW_OP_HP_fltconst8";
9214 case DW_OP_HP_mod_range
:
9215 return "DW_OP_HP_mod_range";
9216 case DW_OP_HP_unmod_range
:
9217 return "DW_OP_HP_unmod_range";
9219 return "DW_OP_HP_tls";
9221 return "OP_<unknown>";
9226 dwarf_bool_name (unsigned mybool
)
9234 /* Convert a DWARF type code into its string name. */
9237 dwarf_type_encoding_name (unsigned enc
)
9242 return "DW_ATE_void";
9243 case DW_ATE_address
:
9244 return "DW_ATE_address";
9245 case DW_ATE_boolean
:
9246 return "DW_ATE_boolean";
9247 case DW_ATE_complex_float
:
9248 return "DW_ATE_complex_float";
9250 return "DW_ATE_float";
9252 return "DW_ATE_signed";
9253 case DW_ATE_signed_char
:
9254 return "DW_ATE_signed_char";
9255 case DW_ATE_unsigned
:
9256 return "DW_ATE_unsigned";
9257 case DW_ATE_unsigned_char
:
9258 return "DW_ATE_unsigned_char";
9260 case DW_ATE_imaginary_float
:
9261 return "DW_ATE_imaginary_float";
9262 case DW_ATE_packed_decimal
:
9263 return "DW_ATE_packed_decimal";
9264 case DW_ATE_numeric_string
:
9265 return "DW_ATE_numeric_string";
9267 return "DW_ATE_edited";
9268 case DW_ATE_signed_fixed
:
9269 return "DW_ATE_signed_fixed";
9270 case DW_ATE_unsigned_fixed
:
9271 return "DW_ATE_unsigned_fixed";
9272 case DW_ATE_decimal_float
:
9273 return "DW_ATE_decimal_float";
9274 /* HP extensions. */
9275 case DW_ATE_HP_float80
:
9276 return "DW_ATE_HP_float80";
9277 case DW_ATE_HP_complex_float80
:
9278 return "DW_ATE_HP_complex_float80";
9279 case DW_ATE_HP_float128
:
9280 return "DW_ATE_HP_float128";
9281 case DW_ATE_HP_complex_float128
:
9282 return "DW_ATE_HP_complex_float128";
9283 case DW_ATE_HP_floathpintel
:
9284 return "DW_ATE_HP_floathpintel";
9285 case DW_ATE_HP_imaginary_float80
:
9286 return "DW_ATE_HP_imaginary_float80";
9287 case DW_ATE_HP_imaginary_float128
:
9288 return "DW_ATE_HP_imaginary_float128";
9290 return "DW_ATE_<unknown>";
9294 /* Convert a DWARF call frame info operation to its string name. */
9298 dwarf_cfi_name (unsigned cfi_opc
)
9302 case DW_CFA_advance_loc
:
9303 return "DW_CFA_advance_loc";
9305 return "DW_CFA_offset";
9306 case DW_CFA_restore
:
9307 return "DW_CFA_restore";
9309 return "DW_CFA_nop";
9310 case DW_CFA_set_loc
:
9311 return "DW_CFA_set_loc";
9312 case DW_CFA_advance_loc1
:
9313 return "DW_CFA_advance_loc1";
9314 case DW_CFA_advance_loc2
:
9315 return "DW_CFA_advance_loc2";
9316 case DW_CFA_advance_loc4
:
9317 return "DW_CFA_advance_loc4";
9318 case DW_CFA_offset_extended
:
9319 return "DW_CFA_offset_extended";
9320 case DW_CFA_restore_extended
:
9321 return "DW_CFA_restore_extended";
9322 case DW_CFA_undefined
:
9323 return "DW_CFA_undefined";
9324 case DW_CFA_same_value
:
9325 return "DW_CFA_same_value";
9326 case DW_CFA_register
:
9327 return "DW_CFA_register";
9328 case DW_CFA_remember_state
:
9329 return "DW_CFA_remember_state";
9330 case DW_CFA_restore_state
:
9331 return "DW_CFA_restore_state";
9332 case DW_CFA_def_cfa
:
9333 return "DW_CFA_def_cfa";
9334 case DW_CFA_def_cfa_register
:
9335 return "DW_CFA_def_cfa_register";
9336 case DW_CFA_def_cfa_offset
:
9337 return "DW_CFA_def_cfa_offset";
9339 case DW_CFA_def_cfa_expression
:
9340 return "DW_CFA_def_cfa_expression";
9341 case DW_CFA_expression
:
9342 return "DW_CFA_expression";
9343 case DW_CFA_offset_extended_sf
:
9344 return "DW_CFA_offset_extended_sf";
9345 case DW_CFA_def_cfa_sf
:
9346 return "DW_CFA_def_cfa_sf";
9347 case DW_CFA_def_cfa_offset_sf
:
9348 return "DW_CFA_def_cfa_offset_sf";
9349 case DW_CFA_val_offset
:
9350 return "DW_CFA_val_offset";
9351 case DW_CFA_val_offset_sf
:
9352 return "DW_CFA_val_offset_sf";
9353 case DW_CFA_val_expression
:
9354 return "DW_CFA_val_expression";
9355 /* SGI/MIPS specific. */
9356 case DW_CFA_MIPS_advance_loc8
:
9357 return "DW_CFA_MIPS_advance_loc8";
9358 /* GNU extensions. */
9359 case DW_CFA_GNU_window_save
:
9360 return "DW_CFA_GNU_window_save";
9361 case DW_CFA_GNU_args_size
:
9362 return "DW_CFA_GNU_args_size";
9363 case DW_CFA_GNU_negative_offset_extended
:
9364 return "DW_CFA_GNU_negative_offset_extended";
9366 return "DW_CFA_<unknown>";
9372 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
9376 print_spaces (indent
, f
);
9377 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
9378 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
9380 if (die
->parent
!= NULL
)
9382 print_spaces (indent
, f
);
9383 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
9384 die
->parent
->offset
);
9387 print_spaces (indent
, f
);
9388 fprintf_unfiltered (f
, " has children: %s\n",
9389 dwarf_bool_name (die
->child
!= NULL
));
9391 print_spaces (indent
, f
);
9392 fprintf_unfiltered (f
, " attributes:\n");
9394 for (i
= 0; i
< die
->num_attrs
; ++i
)
9396 print_spaces (indent
, f
);
9397 fprintf_unfiltered (f
, " %s (%s) ",
9398 dwarf_attr_name (die
->attrs
[i
].name
),
9399 dwarf_form_name (die
->attrs
[i
].form
));
9401 switch (die
->attrs
[i
].form
)
9403 case DW_FORM_ref_addr
:
9405 fprintf_unfiltered (f
, "address: ");
9406 fputs_filtered (paddress (DW_ADDR (&die
->attrs
[i
])), f
);
9408 case DW_FORM_block2
:
9409 case DW_FORM_block4
:
9411 case DW_FORM_block1
:
9412 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
9417 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
9418 (long) (DW_ADDR (&die
->attrs
[i
])));
9426 fprintf_unfiltered (f
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
9428 case DW_FORM_string
:
9430 case GDB_FORM_cached_string
:
9431 fprintf_unfiltered (f
, "string: \"%s\"",
9432 DW_STRING (&die
->attrs
[i
])
9433 ? DW_STRING (&die
->attrs
[i
]) : "");
9436 if (DW_UNSND (&die
->attrs
[i
]))
9437 fprintf_unfiltered (f
, "flag: TRUE");
9439 fprintf_unfiltered (f
, "flag: FALSE");
9441 case DW_FORM_indirect
:
9442 /* the reader will have reduced the indirect form to
9443 the "base form" so this form should not occur */
9444 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
9447 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
9448 die
->attrs
[i
].form
);
9451 fprintf_unfiltered (f
, "\n");
9456 dump_die_for_error (struct die_info
*die
)
9458 dump_die_shallow (gdb_stderr
, 0, die
);
9462 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
9464 int indent
= level
* 4;
9466 gdb_assert (die
!= NULL
);
9468 if (level
>= max_level
)
9471 dump_die_shallow (f
, indent
, die
);
9473 if (die
->child
!= NULL
)
9475 print_spaces (indent
, f
);
9476 fprintf_unfiltered (f
, " Children:");
9477 if (level
+ 1 < max_level
)
9479 fprintf_unfiltered (f
, "\n");
9480 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
9484 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
9488 if (die
->sibling
!= NULL
&& level
> 0)
9490 dump_die_1 (f
, level
, max_level
, die
->sibling
);
9494 /* This is called from the pdie macro in gdbinit.in.
9495 It's not static so gcc will keep a copy callable from gdb. */
9498 dump_die (struct die_info
*die
, int max_level
)
9500 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
9504 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
9508 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
9514 dwarf2_get_ref_die_offset (struct attribute
*attr
)
9516 unsigned int result
= 0;
9520 case DW_FORM_ref_addr
:
9525 case DW_FORM_ref_udata
:
9526 result
= DW_ADDR (attr
);
9529 complaint (&symfile_complaints
,
9530 _("unsupported die ref attribute form: '%s'"),
9531 dwarf_form_name (attr
->form
));
9536 /* Return the constant value held by the given attribute. Return -1
9537 if the value held by the attribute is not constant. */
9540 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
9542 if (attr
->form
== DW_FORM_sdata
)
9543 return DW_SND (attr
);
9544 else if (attr
->form
== DW_FORM_udata
9545 || attr
->form
== DW_FORM_data1
9546 || attr
->form
== DW_FORM_data2
9547 || attr
->form
== DW_FORM_data4
9548 || attr
->form
== DW_FORM_data8
)
9549 return DW_UNSND (attr
);
9552 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
9553 dwarf_form_name (attr
->form
));
9554 return default_value
;
9558 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
9559 unit and add it to our queue. */
9562 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
9563 struct dwarf2_per_cu_data
*per_cu
)
9565 /* Mark the dependence relation so that we don't flush PER_CU
9567 dwarf2_add_dependence (this_cu
, per_cu
);
9569 /* If it's already on the queue, we have nothing to do. */
9573 /* If the compilation unit is already loaded, just mark it as
9575 if (per_cu
->cu
!= NULL
)
9577 per_cu
->cu
->last_used
= 0;
9581 /* Add it to the queue. */
9582 queue_comp_unit (per_cu
, this_cu
->objfile
);
9585 /* Follow reference attribute ATTR of SRC_DIE.
9586 On entry *REF_CU is the CU of SRC_DIE.
9587 On exit *REF_CU is the CU of the result. */
9589 static struct die_info
*
9590 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
9591 struct dwarf2_cu
**ref_cu
)
9593 struct die_info
*die
;
9594 unsigned int offset
;
9595 struct die_info temp_die
;
9596 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
9598 offset
= dwarf2_get_ref_die_offset (attr
);
9600 if (! offset_in_cu_p (&cu
->header
, offset
))
9602 struct dwarf2_per_cu_data
*per_cu
;
9603 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9605 /* If necessary, add it to the queue and load its DIEs. */
9606 maybe_queue_comp_unit (cu
, per_cu
);
9608 target_cu
= per_cu
->cu
;
9613 *ref_cu
= target_cu
;
9614 temp_die
.offset
= offset
;
9615 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
9619 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
9620 "at 0x%lx [in module %s]"),
9621 (long) offset
, (long) src_die
->offset
, cu
->objfile
->name
);
9624 /* Decode simple location descriptions.
9625 Given a pointer to a dwarf block that defines a location, compute
9626 the location and return the value.
9628 NOTE drow/2003-11-18: This function is called in two situations
9629 now: for the address of static or global variables (partial symbols
9630 only) and for offsets into structures which are expected to be
9631 (more or less) constant. The partial symbol case should go away,
9632 and only the constant case should remain. That will let this
9633 function complain more accurately. A few special modes are allowed
9634 without complaint for global variables (for instance, global
9635 register values and thread-local values).
9637 A location description containing no operations indicates that the
9638 object is optimized out. The return value is 0 for that case.
9639 FIXME drow/2003-11-16: No callers check for this case any more; soon all
9640 callers will only want a very basic result and this can become a
9643 Note that stack[0] is unused except as a default error return.
9644 Note that stack overflow is not yet handled. */
9647 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
9649 struct objfile
*objfile
= cu
->objfile
;
9650 struct comp_unit_head
*cu_header
= &cu
->header
;
9652 int size
= blk
->size
;
9653 gdb_byte
*data
= blk
->data
;
9654 CORE_ADDR stack
[64];
9656 unsigned int bytes_read
, unsnd
;
9700 stack
[++stacki
] = op
- DW_OP_lit0
;
9735 stack
[++stacki
] = op
- DW_OP_reg0
;
9737 dwarf2_complex_location_expr_complaint ();
9741 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9743 stack
[++stacki
] = unsnd
;
9745 dwarf2_complex_location_expr_complaint ();
9749 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
9755 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
9760 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
9765 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
9770 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
9775 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
9780 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
9785 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
9791 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
9796 stack
[stacki
+ 1] = stack
[stacki
];
9801 stack
[stacki
- 1] += stack
[stacki
];
9805 case DW_OP_plus_uconst
:
9806 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9811 stack
[stacki
- 1] -= stack
[stacki
];
9816 /* If we're not the last op, then we definitely can't encode
9817 this using GDB's address_class enum. This is valid for partial
9818 global symbols, although the variable's address will be bogus
9821 dwarf2_complex_location_expr_complaint ();
9824 case DW_OP_GNU_push_tls_address
:
9825 /* The top of the stack has the offset from the beginning
9826 of the thread control block at which the variable is located. */
9827 /* Nothing should follow this operator, so the top of stack would
9829 /* This is valid for partial global symbols, but the variable's
9830 address will be bogus in the psymtab. */
9832 dwarf2_complex_location_expr_complaint ();
9835 case DW_OP_GNU_uninit
:
9839 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
9840 dwarf_stack_op_name (op
));
9841 return (stack
[stacki
]);
9844 return (stack
[stacki
]);
9847 /* memory allocation interface */
9849 static struct dwarf_block
*
9850 dwarf_alloc_block (struct dwarf2_cu
*cu
)
9852 struct dwarf_block
*blk
;
9854 blk
= (struct dwarf_block
*)
9855 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
9859 static struct abbrev_info
*
9860 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
9862 struct abbrev_info
*abbrev
;
9864 abbrev
= (struct abbrev_info
*)
9865 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
9866 memset (abbrev
, 0, sizeof (struct abbrev_info
));
9870 static struct die_info
*
9871 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
9873 struct die_info
*die
;
9874 size_t size
= sizeof (struct die_info
);
9877 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
9879 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
9880 memset (die
, 0, sizeof (struct die_info
));
9885 /* Macro support. */
9888 /* Return the full name of file number I in *LH's file name table.
9889 Use COMP_DIR as the name of the current directory of the
9890 compilation. The result is allocated using xmalloc; the caller is
9891 responsible for freeing it. */
9893 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
9895 /* Is the file number a valid index into the line header's file name
9896 table? Remember that file numbers start with one, not zero. */
9897 if (1 <= file
&& file
<= lh
->num_file_names
)
9899 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9901 if (IS_ABSOLUTE_PATH (fe
->name
))
9902 return xstrdup (fe
->name
);
9910 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9916 dir_len
= strlen (dir
);
9917 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
9918 strcpy (full_name
, dir
);
9919 full_name
[dir_len
] = '/';
9920 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
9924 return xstrdup (fe
->name
);
9929 /* The compiler produced a bogus file number. We can at least
9930 record the macro definitions made in the file, even if we
9931 won't be able to find the file by name. */
9933 sprintf (fake_name
, "<bad macro file number %d>", file
);
9935 complaint (&symfile_complaints
,
9936 _("bad file number in macro information (%d)"),
9939 return xstrdup (fake_name
);
9944 static struct macro_source_file
*
9945 macro_start_file (int file
, int line
,
9946 struct macro_source_file
*current_file
,
9947 const char *comp_dir
,
9948 struct line_header
*lh
, struct objfile
*objfile
)
9950 /* The full name of this source file. */
9951 char *full_name
= file_full_name (file
, lh
, comp_dir
);
9953 /* We don't create a macro table for this compilation unit
9954 at all until we actually get a filename. */
9955 if (! pending_macros
)
9956 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
9957 objfile
->macro_cache
);
9960 /* If we have no current file, then this must be the start_file
9961 directive for the compilation unit's main source file. */
9962 current_file
= macro_set_main (pending_macros
, full_name
);
9964 current_file
= macro_include (current_file
, line
, full_name
);
9968 return current_file
;
9972 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
9973 followed by a null byte. */
9975 copy_string (const char *buf
, int len
)
9977 char *s
= xmalloc (len
+ 1);
9978 memcpy (s
, buf
, len
);
9986 consume_improper_spaces (const char *p
, const char *body
)
9990 complaint (&symfile_complaints
,
9991 _("macro definition contains spaces in formal argument list:\n`%s'"),
10003 parse_macro_definition (struct macro_source_file
*file
, int line
,
10008 /* The body string takes one of two forms. For object-like macro
10009 definitions, it should be:
10011 <macro name> " " <definition>
10013 For function-like macro definitions, it should be:
10015 <macro name> "() " <definition>
10017 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
10019 Spaces may appear only where explicitly indicated, and in the
10022 The Dwarf 2 spec says that an object-like macro's name is always
10023 followed by a space, but versions of GCC around March 2002 omit
10024 the space when the macro's definition is the empty string.
10026 The Dwarf 2 spec says that there should be no spaces between the
10027 formal arguments in a function-like macro's formal argument list,
10028 but versions of GCC around March 2002 include spaces after the
10032 /* Find the extent of the macro name. The macro name is terminated
10033 by either a space or null character (for an object-like macro) or
10034 an opening paren (for a function-like macro). */
10035 for (p
= body
; *p
; p
++)
10036 if (*p
== ' ' || *p
== '(')
10039 if (*p
== ' ' || *p
== '\0')
10041 /* It's an object-like macro. */
10042 int name_len
= p
- body
;
10043 char *name
= copy_string (body
, name_len
);
10044 const char *replacement
;
10047 replacement
= body
+ name_len
+ 1;
10050 dwarf2_macro_malformed_definition_complaint (body
);
10051 replacement
= body
+ name_len
;
10054 macro_define_object (file
, line
, name
, replacement
);
10058 else if (*p
== '(')
10060 /* It's a function-like macro. */
10061 char *name
= copy_string (body
, p
- body
);
10064 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
10068 p
= consume_improper_spaces (p
, body
);
10070 /* Parse the formal argument list. */
10071 while (*p
&& *p
!= ')')
10073 /* Find the extent of the current argument name. */
10074 const char *arg_start
= p
;
10076 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
10079 if (! *p
|| p
== arg_start
)
10080 dwarf2_macro_malformed_definition_complaint (body
);
10083 /* Make sure argv has room for the new argument. */
10084 if (argc
>= argv_size
)
10087 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
10090 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
10093 p
= consume_improper_spaces (p
, body
);
10095 /* Consume the comma, if present. */
10100 p
= consume_improper_spaces (p
, body
);
10109 /* Perfectly formed definition, no complaints. */
10110 macro_define_function (file
, line
, name
,
10111 argc
, (const char **) argv
,
10113 else if (*p
== '\0')
10115 /* Complain, but do define it. */
10116 dwarf2_macro_malformed_definition_complaint (body
);
10117 macro_define_function (file
, line
, name
,
10118 argc
, (const char **) argv
,
10122 /* Just complain. */
10123 dwarf2_macro_malformed_definition_complaint (body
);
10126 /* Just complain. */
10127 dwarf2_macro_malformed_definition_complaint (body
);
10133 for (i
= 0; i
< argc
; i
++)
10139 dwarf2_macro_malformed_definition_complaint (body
);
10144 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
10145 char *comp_dir
, bfd
*abfd
,
10146 struct dwarf2_cu
*cu
)
10148 gdb_byte
*mac_ptr
, *mac_end
;
10149 struct macro_source_file
*current_file
= 0;
10150 enum dwarf_macinfo_record_type macinfo_type
;
10151 int at_commandline
;
10153 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
10155 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
10159 /* First pass: Find the name of the base filename.
10160 This filename is needed in order to process all macros whose definition
10161 (or undefinition) comes from the command line. These macros are defined
10162 before the first DW_MACINFO_start_file entry, and yet still need to be
10163 associated to the base file.
10165 To determine the base file name, we scan the macro definitions until we
10166 reach the first DW_MACINFO_start_file entry. We then initialize
10167 CURRENT_FILE accordingly so that any macro definition found before the
10168 first DW_MACINFO_start_file can still be associated to the base file. */
10170 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
10171 mac_end
= dwarf2_per_objfile
->macinfo_buffer
10172 + dwarf2_per_objfile
->macinfo_size
;
10176 /* Do we at least have room for a macinfo type byte? */
10177 if (mac_ptr
>= mac_end
)
10179 /* Complaint is printed during the second pass as GDB will probably
10180 stop the first pass earlier upon finding DW_MACINFO_start_file. */
10184 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
10187 switch (macinfo_type
)
10189 /* A zero macinfo type indicates the end of the macro
10194 case DW_MACINFO_define
:
10195 case DW_MACINFO_undef
:
10196 /* Only skip the data by MAC_PTR. */
10198 unsigned int bytes_read
;
10200 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10201 mac_ptr
+= bytes_read
;
10202 read_string (abfd
, mac_ptr
, &bytes_read
);
10203 mac_ptr
+= bytes_read
;
10207 case DW_MACINFO_start_file
:
10209 unsigned int bytes_read
;
10212 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10213 mac_ptr
+= bytes_read
;
10214 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10215 mac_ptr
+= bytes_read
;
10217 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
10222 case DW_MACINFO_end_file
:
10223 /* No data to skip by MAC_PTR. */
10226 case DW_MACINFO_vendor_ext
:
10227 /* Only skip the data by MAC_PTR. */
10229 unsigned int bytes_read
;
10231 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10232 mac_ptr
+= bytes_read
;
10233 read_string (abfd
, mac_ptr
, &bytes_read
);
10234 mac_ptr
+= bytes_read
;
10241 } while (macinfo_type
!= 0 && current_file
== NULL
);
10243 /* Second pass: Process all entries.
10245 Use the AT_COMMAND_LINE flag to determine whether we are still processing
10246 command-line macro definitions/undefinitions. This flag is unset when we
10247 reach the first DW_MACINFO_start_file entry. */
10249 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
10251 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
10252 GDB is still reading the definitions from command line. First
10253 DW_MACINFO_start_file will need to be ignored as it was already executed
10254 to create CURRENT_FILE for the main source holding also the command line
10255 definitions. On first met DW_MACINFO_start_file this flag is reset to
10256 normally execute all the remaining DW_MACINFO_start_file macinfos. */
10258 at_commandline
= 1;
10262 /* Do we at least have room for a macinfo type byte? */
10263 if (mac_ptr
>= mac_end
)
10265 dwarf2_macros_too_long_complaint ();
10269 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
10272 switch (macinfo_type
)
10274 /* A zero macinfo type indicates the end of the macro
10279 case DW_MACINFO_define
:
10280 case DW_MACINFO_undef
:
10282 unsigned int bytes_read
;
10286 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10287 mac_ptr
+= bytes_read
;
10288 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
10289 mac_ptr
+= bytes_read
;
10291 if (! current_file
)
10293 /* DWARF violation as no main source is present. */
10294 complaint (&symfile_complaints
,
10295 _("debug info with no main source gives macro %s "
10298 DW_MACINFO_define
? _("definition") : macinfo_type
==
10299 DW_MACINFO_undef
? _("undefinition") :
10300 "something-or-other", line
, body
);
10303 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
10304 complaint (&symfile_complaints
,
10305 _("debug info gives %s macro %s with %s line %d: %s"),
10306 at_commandline
? _("command-line") : _("in-file"),
10308 DW_MACINFO_define
? _("definition") : macinfo_type
==
10309 DW_MACINFO_undef
? _("undefinition") :
10310 "something-or-other",
10311 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
10313 if (macinfo_type
== DW_MACINFO_define
)
10314 parse_macro_definition (current_file
, line
, body
);
10315 else if (macinfo_type
== DW_MACINFO_undef
)
10316 macro_undef (current_file
, line
, body
);
10320 case DW_MACINFO_start_file
:
10322 unsigned int bytes_read
;
10325 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10326 mac_ptr
+= bytes_read
;
10327 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10328 mac_ptr
+= bytes_read
;
10330 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
10331 complaint (&symfile_complaints
,
10332 _("debug info gives source %d included "
10333 "from %s at %s line %d"),
10334 file
, at_commandline
? _("command-line") : _("file"),
10335 line
== 0 ? _("zero") : _("non-zero"), line
);
10337 if (at_commandline
)
10339 /* This DW_MACINFO_start_file was executed in the pass one. */
10340 at_commandline
= 0;
10343 current_file
= macro_start_file (file
, line
,
10344 current_file
, comp_dir
,
10349 case DW_MACINFO_end_file
:
10350 if (! current_file
)
10351 complaint (&symfile_complaints
,
10352 _("macro debug info has an unmatched `close_file' directive"));
10355 current_file
= current_file
->included_by
;
10356 if (! current_file
)
10358 enum dwarf_macinfo_record_type next_type
;
10360 /* GCC circa March 2002 doesn't produce the zero
10361 type byte marking the end of the compilation
10362 unit. Complain if it's not there, but exit no
10365 /* Do we at least have room for a macinfo type byte? */
10366 if (mac_ptr
>= mac_end
)
10368 dwarf2_macros_too_long_complaint ();
10372 /* We don't increment mac_ptr here, so this is just
10374 next_type
= read_1_byte (abfd
, mac_ptr
);
10375 if (next_type
!= 0)
10376 complaint (&symfile_complaints
,
10377 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
10384 case DW_MACINFO_vendor_ext
:
10386 unsigned int bytes_read
;
10390 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10391 mac_ptr
+= bytes_read
;
10392 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
10393 mac_ptr
+= bytes_read
;
10395 /* We don't recognize any vendor extensions. */
10399 } while (macinfo_type
!= 0);
10402 /* Check if the attribute's form is a DW_FORM_block*
10403 if so return true else false. */
10405 attr_form_is_block (struct attribute
*attr
)
10407 return (attr
== NULL
? 0 :
10408 attr
->form
== DW_FORM_block1
10409 || attr
->form
== DW_FORM_block2
10410 || attr
->form
== DW_FORM_block4
10411 || attr
->form
== DW_FORM_block
);
10414 /* Return non-zero if ATTR's value is a section offset --- classes
10415 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
10416 You may use DW_UNSND (attr) to retrieve such offsets.
10418 Section 7.5.4, "Attribute Encodings", explains that no attribute
10419 may have a value that belongs to more than one of these classes; it
10420 would be ambiguous if we did, because we use the same forms for all
10423 attr_form_is_section_offset (struct attribute
*attr
)
10425 return (attr
->form
== DW_FORM_data4
10426 || attr
->form
== DW_FORM_data8
);
10430 /* Return non-zero if ATTR's value falls in the 'constant' class, or
10431 zero otherwise. When this function returns true, you can apply
10432 dwarf2_get_attr_constant_value to it.
10434 However, note that for some attributes you must check
10435 attr_form_is_section_offset before using this test. DW_FORM_data4
10436 and DW_FORM_data8 are members of both the constant class, and of
10437 the classes that contain offsets into other debug sections
10438 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
10439 that, if an attribute's can be either a constant or one of the
10440 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
10441 taken as section offsets, not constants. */
10443 attr_form_is_constant (struct attribute
*attr
)
10445 switch (attr
->form
)
10447 case DW_FORM_sdata
:
10448 case DW_FORM_udata
:
10449 case DW_FORM_data1
:
10450 case DW_FORM_data2
:
10451 case DW_FORM_data4
:
10452 case DW_FORM_data8
:
10460 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
10461 struct dwarf2_cu
*cu
)
10463 if (attr_form_is_section_offset (attr
)
10464 /* ".debug_loc" may not exist at all, or the offset may be outside
10465 the section. If so, fall through to the complaint in the
10467 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc_size
)
10469 struct dwarf2_loclist_baton
*baton
;
10471 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
10472 sizeof (struct dwarf2_loclist_baton
));
10473 baton
->per_cu
= cu
->per_cu
;
10474 gdb_assert (baton
->per_cu
);
10476 /* We don't know how long the location list is, but make sure we
10477 don't run off the edge of the section. */
10478 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
10479 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
10480 baton
->base_address
= cu
->base_address
;
10481 if (cu
->base_known
== 0)
10482 complaint (&symfile_complaints
,
10483 _("Location list used without specifying the CU base address."));
10485 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
10486 SYMBOL_LOCATION_BATON (sym
) = baton
;
10490 struct dwarf2_locexpr_baton
*baton
;
10492 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
10493 sizeof (struct dwarf2_locexpr_baton
));
10494 baton
->per_cu
= cu
->per_cu
;
10495 gdb_assert (baton
->per_cu
);
10497 if (attr_form_is_block (attr
))
10499 /* Note that we're just copying the block's data pointer
10500 here, not the actual data. We're still pointing into the
10501 info_buffer for SYM's objfile; right now we never release
10502 that buffer, but when we do clean up properly this may
10504 baton
->size
= DW_BLOCK (attr
)->size
;
10505 baton
->data
= DW_BLOCK (attr
)->data
;
10509 dwarf2_invalid_attrib_class_complaint ("location description",
10510 SYMBOL_NATURAL_NAME (sym
));
10512 baton
->data
= NULL
;
10515 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
10516 SYMBOL_LOCATION_BATON (sym
) = baton
;
10520 /* Return the OBJFILE associated with the compilation unit CU. */
10523 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
10525 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10527 /* Return the master objfile, so that we can report and look up the
10528 correct file containing this variable. */
10529 if (objfile
->separate_debug_objfile_backlink
)
10530 objfile
= objfile
->separate_debug_objfile_backlink
;
10535 /* Return the address size given in the compilation unit header for CU. */
10538 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
10541 return per_cu
->cu
->header
.addr_size
;
10544 /* If the CU is not currently read in, we re-read its header. */
10545 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10546 struct dwarf2_per_objfile
*per_objfile
10547 = objfile_data (objfile
, dwarf2_objfile_data_key
);
10548 gdb_byte
*info_ptr
= per_objfile
->info_buffer
+ per_cu
->offset
;
10550 struct comp_unit_head cu_header
;
10551 memset (&cu_header
, 0, sizeof cu_header
);
10552 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
10553 return cu_header
.addr_size
;
10557 /* Locate the compilation unit from CU's objfile which contains the
10558 DIE at OFFSET. Raises an error on failure. */
10560 static struct dwarf2_per_cu_data
*
10561 dwarf2_find_containing_comp_unit (unsigned int offset
,
10562 struct objfile
*objfile
)
10564 struct dwarf2_per_cu_data
*this_cu
;
10568 high
= dwarf2_per_objfile
->n_comp_units
- 1;
10571 int mid
= low
+ (high
- low
) / 2;
10572 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
10577 gdb_assert (low
== high
);
10578 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
10581 error (_("Dwarf Error: could not find partial DIE containing "
10582 "offset 0x%lx [in module %s]"),
10583 (long) offset
, bfd_get_filename (objfile
->obfd
));
10585 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
10586 return dwarf2_per_objfile
->all_comp_units
[low
-1];
10590 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
10591 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
10592 && offset
>= this_cu
->offset
+ this_cu
->length
)
10593 error (_("invalid dwarf2 offset %u"), offset
);
10594 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
10599 /* Locate the compilation unit from OBJFILE which is located at exactly
10600 OFFSET. Raises an error on failure. */
10602 static struct dwarf2_per_cu_data
*
10603 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
10605 struct dwarf2_per_cu_data
*this_cu
;
10606 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10607 if (this_cu
->offset
!= offset
)
10608 error (_("no compilation unit with offset %u."), offset
);
10612 /* Release one cached compilation unit, CU. We unlink it from the tree
10613 of compilation units, but we don't remove it from the read_in_chain;
10614 the caller is responsible for that. */
10617 free_one_comp_unit (void *data
)
10619 struct dwarf2_cu
*cu
= data
;
10621 if (cu
->per_cu
!= NULL
)
10622 cu
->per_cu
->cu
= NULL
;
10625 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10630 /* This cleanup function is passed the address of a dwarf2_cu on the stack
10631 when we're finished with it. We can't free the pointer itself, but be
10632 sure to unlink it from the cache. Also release any associated storage
10633 and perform cache maintenance.
10635 Only used during partial symbol parsing. */
10638 free_stack_comp_unit (void *data
)
10640 struct dwarf2_cu
*cu
= data
;
10642 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10643 cu
->partial_dies
= NULL
;
10645 if (cu
->per_cu
!= NULL
)
10647 /* This compilation unit is on the stack in our caller, so we
10648 should not xfree it. Just unlink it. */
10649 cu
->per_cu
->cu
= NULL
;
10652 /* If we had a per-cu pointer, then we may have other compilation
10653 units loaded, so age them now. */
10654 age_cached_comp_units ();
10658 /* Free all cached compilation units. */
10661 free_cached_comp_units (void *data
)
10663 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10665 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10666 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10667 while (per_cu
!= NULL
)
10669 struct dwarf2_per_cu_data
*next_cu
;
10671 next_cu
= per_cu
->cu
->read_in_chain
;
10673 free_one_comp_unit (per_cu
->cu
);
10674 *last_chain
= next_cu
;
10680 /* Increase the age counter on each cached compilation unit, and free
10681 any that are too old. */
10684 age_cached_comp_units (void)
10686 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10688 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
10689 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10690 while (per_cu
!= NULL
)
10692 per_cu
->cu
->last_used
++;
10693 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
10694 dwarf2_mark (per_cu
->cu
);
10695 per_cu
= per_cu
->cu
->read_in_chain
;
10698 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10699 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10700 while (per_cu
!= NULL
)
10702 struct dwarf2_per_cu_data
*next_cu
;
10704 next_cu
= per_cu
->cu
->read_in_chain
;
10706 if (!per_cu
->cu
->mark
)
10708 free_one_comp_unit (per_cu
->cu
);
10709 *last_chain
= next_cu
;
10712 last_chain
= &per_cu
->cu
->read_in_chain
;
10718 /* Remove a single compilation unit from the cache. */
10721 free_one_cached_comp_unit (void *target_cu
)
10723 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10725 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10726 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10727 while (per_cu
!= NULL
)
10729 struct dwarf2_per_cu_data
*next_cu
;
10731 next_cu
= per_cu
->cu
->read_in_chain
;
10733 if (per_cu
->cu
== target_cu
)
10735 free_one_comp_unit (per_cu
->cu
);
10736 *last_chain
= next_cu
;
10740 last_chain
= &per_cu
->cu
->read_in_chain
;
10746 /* Release all extra memory associated with OBJFILE. */
10749 dwarf2_free_objfile (struct objfile
*objfile
)
10751 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
10753 if (dwarf2_per_objfile
== NULL
)
10756 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
10757 free_cached_comp_units (NULL
);
10759 /* Everything else should be on the objfile obstack. */
10762 /* A pair of DIE offset and GDB type pointer. We store these
10763 in a hash table separate from the DIEs, and preserve them
10764 when the DIEs are flushed out of cache. */
10766 struct dwarf2_offset_and_type
10768 unsigned int offset
;
10772 /* Hash function for a dwarf2_offset_and_type. */
10775 offset_and_type_hash (const void *item
)
10777 const struct dwarf2_offset_and_type
*ofs
= item
;
10778 return ofs
->offset
;
10781 /* Equality function for a dwarf2_offset_and_type. */
10784 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
10786 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
10787 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
10788 return ofs_lhs
->offset
== ofs_rhs
->offset
;
10791 /* Set the type associated with DIE to TYPE. Save it in CU's hash
10792 table if necessary. For convenience, return TYPE. */
10794 static struct type
*
10795 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10797 struct dwarf2_offset_and_type
**slot
, ofs
;
10799 if (cu
->type_hash
== NULL
)
10801 gdb_assert (cu
->per_cu
!= NULL
);
10802 cu
->per_cu
->type_hash
10803 = htab_create_alloc_ex (cu
->header
.length
/ 24,
10804 offset_and_type_hash
,
10805 offset_and_type_eq
,
10807 &cu
->objfile
->objfile_obstack
,
10808 hashtab_obstack_allocate
,
10809 dummy_obstack_deallocate
);
10810 cu
->type_hash
= cu
->per_cu
->type_hash
;
10813 ofs
.offset
= die
->offset
;
10815 slot
= (struct dwarf2_offset_and_type
**)
10816 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
10817 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
10822 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
10823 not have a saved type. */
10825 static struct type
*
10826 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10828 struct dwarf2_offset_and_type
*slot
, ofs
;
10829 htab_t type_hash
= cu
->type_hash
;
10831 if (type_hash
== NULL
)
10834 ofs
.offset
= die
->offset
;
10835 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
10842 /* Add a dependence relationship from CU to REF_PER_CU. */
10845 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
10846 struct dwarf2_per_cu_data
*ref_per_cu
)
10850 if (cu
->dependencies
== NULL
)
10852 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
10853 NULL
, &cu
->comp_unit_obstack
,
10854 hashtab_obstack_allocate
,
10855 dummy_obstack_deallocate
);
10857 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
10859 *slot
= ref_per_cu
;
10862 /* Subroutine of dwarf2_mark to pass to htab_traverse.
10863 Set the mark field in every compilation unit in the
10864 cache that we must keep because we are keeping CU. */
10867 dwarf2_mark_helper (void **slot
, void *data
)
10869 struct dwarf2_per_cu_data
*per_cu
;
10871 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
10872 if (per_cu
->cu
->mark
)
10874 per_cu
->cu
->mark
= 1;
10876 if (per_cu
->cu
->dependencies
!= NULL
)
10877 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10882 /* Set the mark field in CU and in every other compilation unit in the
10883 cache that we must keep because we are keeping CU. */
10886 dwarf2_mark (struct dwarf2_cu
*cu
)
10891 if (cu
->dependencies
!= NULL
)
10892 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10896 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
10900 per_cu
->cu
->mark
= 0;
10901 per_cu
= per_cu
->cu
->read_in_chain
;
10905 /* Trivial hash function for partial_die_info: the hash value of a DIE
10906 is its offset in .debug_info for this objfile. */
10909 partial_die_hash (const void *item
)
10911 const struct partial_die_info
*part_die
= item
;
10912 return part_die
->offset
;
10915 /* Trivial comparison function for partial_die_info structures: two DIEs
10916 are equal if they have the same offset. */
10919 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
10921 const struct partial_die_info
*part_die_lhs
= item_lhs
;
10922 const struct partial_die_info
*part_die_rhs
= item_rhs
;
10923 return part_die_lhs
->offset
== part_die_rhs
->offset
;
10926 static struct cmd_list_element
*set_dwarf2_cmdlist
;
10927 static struct cmd_list_element
*show_dwarf2_cmdlist
;
10930 set_dwarf2_cmd (char *args
, int from_tty
)
10932 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
10936 show_dwarf2_cmd (char *args
, int from_tty
)
10938 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
10941 void _initialize_dwarf2_read (void);
10944 _initialize_dwarf2_read (void)
10946 dwarf2_objfile_data_key
= register_objfile_data ();
10948 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
10949 Set DWARF 2 specific variables.\n\
10950 Configure DWARF 2 variables such as the cache size"),
10951 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
10952 0/*allow-unknown*/, &maintenance_set_cmdlist
);
10954 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
10955 Show DWARF 2 specific variables\n\
10956 Show DWARF 2 variables such as the cache size"),
10957 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
10958 0/*allow-unknown*/, &maintenance_show_cmdlist
);
10960 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
10961 &dwarf2_max_cache_age
, _("\
10962 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
10963 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
10964 A higher limit means that cached compilation units will be stored\n\
10965 in memory longer, and more total memory will be used. Zero disables\n\
10966 caching, which can slow down startup."),
10968 show_dwarf2_max_cache_age
,
10969 &set_dwarf2_cmdlist
,
10970 &show_dwarf2_cmdlist
);
10972 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
10973 Set debugging of the dwarf2 DIE reader."), _("\
10974 Show debugging of the dwarf2 DIE reader."), _("\
10975 When enabled (non-zero), DIEs are dumped after they are read in.\n\
10976 The value is the maximum depth to print."),
10979 &setdebuglist
, &showdebuglist
);